____                _       __
    / __ )____  _____   | |     / /___ ___________
   / __  / __ \/ ___/   | | /| / / __ `/ ___/ ___/
  / /_/ / /_/ (__  )    | |/ |/ / /_/ / /  (__  )
 /_____/\____/____/     |__/|__/\__,_/_/  /____/

       A futuristic real-time strategy game.
          This file is part of Bos Wars.
(C) Copyright 2001-2007 by the Bos Wars and Stratagus Project. Distributed under the "GNU General Public License"

ai_resource.cpp File Reference

AI resource manager. More...

#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include "stratagus.h"
#include "unit.h"
#include "unit_cache.h"
#include "unittype.h"
#include "upgrade.h"
#include "map.h"
#include "pathfinder.h"
#include "ai_local.h"
#include "actions.h"
#include "player.h"

Go to the source code of this file.

Defines

#define COLLECT_RESOURCES_INTERVAL   4

Functions

static int AiCheckCosts (const int *costs)
static int AiCheckUnitTypeCosts (const CUnitType *type)
int AiEnemyUnitsInDistance (const CPlayer *player, const CUnitType *type, int x, int y, unsigned range)
int AiEnemyUnitsInDistance (const CUnit *unit, unsigned range)
static int AiBuildBuilding (const CUnitType *type, CUnitType *building)
static int AiTrainUnit (const CUnitType *type, CUnitType *what)
int AiCountUnitBuilders (CUnitType *type)
static int AiMakeUnit (CUnitType *type)
static void AiCheckingWork (void)
static int AiAssignHarvester (CUnit *unit, int resource)
static void AiCollectResources (void)
static int AiRepairBuilding (const CUnitType *type, CUnit *building)
static int AiRepairUnit (CUnit *unit)
static void AiCheckRepair (void)
void AiAddUnitTypeRequest (CUnitType *type, int count)
 < Add unit-type request to resource manager
void AiExplore (int x, int y, int mask)
 Make two unittypes be considered equals.
void AiResourceManager (void)
 Ask the ai to explore around x,y.


Detailed Description

AI resource manager.

Definition in file ai_resource.cpp.


Define Documentation

#define COLLECT_RESOURCES_INTERVAL   4

Definition at line 54 of file ai_resource.cpp.

Referenced by AiResourceManager().


Function Documentation

void AiAddUnitTypeRequest ( CUnitType type,
int  count 
)

< Add unit-type request to resource manager

Add unit-type request to resource manager.

Parameters:
type Unit type requested.
count How many units.
Todo:
FIXME: should store the end of list and not search it.

Definition at line 810 of file ai_resource.cpp.

References AiPlayer, AiBuildQueue::Made, AiBuildQueue::Type, PlayerAi::UnitTypeBuilt, and AiBuildQueue::Want.

Referenced by AiCheckUnits().

static int AiAssignHarvester ( CUnit unit,
int  resource 
) [static]

Assign worker to gather a resource.

Parameters:
unit Unit to be assigned.
resource Resource to find, -1 for any
Returns:
1 if the worker was assigned, 0 otherwise.

Definition at line 439 of file ai_resource.cpp.

References AiExplore(), Assert, CommandResource(), FlushCommands, MapFieldAirUnit, MapFieldLandUnit, MapFieldSeaUnit, MaxCosts, CUnit::Player, CPlayer::ProductionRate, CUnit::Removed, CPlayer::StoredResources, UnitFindResource(), UnitTypeFly, UnitTypeLand, UnitTypeNaval, UnitTypes, CUnit::X, and CUnit::Y.

Referenced by AiCollectResources().

static int AiBuildBuilding ( const CUnitType type,
CUnitType building 
) [static]

Check if we can build the building.

Parameters:
type Unit that can build the building.
building Building to be build.
Returns:
True if made, false if can't be made.
Note:
We must check if the dependencies are fulfilled.

Definition at line 171 of file ai_resource.cpp.

References AiFindBuildingPlace(), AiPlayer, CommandBuildBuilding(), FindPlayerUnitsByType(), FlushCommands, CUnit::OrderCount, CUnit::Orders, PlayerAi::Player, SyncRand(), UnitActionBuild, UnitActionRepair, UnitMax, and y.

Referenced by AiMakeUnit().

static int AiCheckCosts ( const int *  costs  )  [static]

Check if the costs are available for the AI.

Take reserve and already used resources into account.

Parameters:
costs Costs for something.
Returns:
A bit field of the missing costs.

Definition at line 69 of file ai_resource.cpp.

References AiPlayer, MaxCosts, PlayerAi::Player, CPlayer::ProductionRate, and CPlayer::StoredResources.

Referenced by AiCheckUnitTypeCosts().

static void AiCheckingWork ( void   )  [static]

static void AiCheckRepair ( void   )  [static]

static int AiCheckUnitTypeCosts ( const CUnitType type  )  [static]

Check if the costs for a unit-type are available for the AI.

Take reserve and already used resources into account.

Parameters:
type Unit-type to check the costs for.
Returns:
A bit field of the missing costs.

Definition at line 92 of file ai_resource.cpp.

References AiCheckCosts(), and CUnitType::ProductionCosts.

Referenced by AiCheckingWork().

static void AiCollectResources ( void   )  [static]

int AiCountUnitBuilders ( CUnitType type  ) 

Return the number of unit which can produce the given unittype.

Parameters:
type The unittype we wan't to build

Definition at line 259 of file ai_resource.cpp.

References _C_, AiHelpers, AiPlayer, AiHelper::Build, CUnitType::Building, DebugPrint, CUnitType::Ident, int(), PlayerAi::Player, CUnitType::Slot, AiHelper::Train, UnitIdAllowed(), and CPlayer::UnitTypesCount.

int AiEnemyUnitsInDistance ( const CUnit unit,
unsigned  range 
)

Enemy units in distance.

Parameters:
unit Find in distance for this unit.
range Distance range to look.
Returns:
Number of enemy units.

Definition at line 155 of file ai_resource.cpp.

References AiEnemyUnitsInDistance(), CUnit::Player, CUnitType::TileHeight, CUnitType::TileWidth, CUnit::Type, CUnit::X, and CUnit::Y.

int AiEnemyUnitsInDistance ( const CPlayer player,
const CUnitType type,
int  x,
int  y,
unsigned  range 
)

Enemy units in distance.

Parameters:
player Find enemies of this player
type Optional unit type to check if enemy can target this
x X location
y Y location
range Distance range to look.
Returns:
Number of enemy units.

Definition at line 108 of file ai_resource.cpp.

References CanTarget(), CPlayer::IsEnemy(), CUnit::Orders, CUnit::Removed, CUnitCache::Select(), CUnit::Type, UnitActionDie, UnitCache, and UnitMax.

Referenced by AiCheckRepair(), AiEnemyUnitsInDistance(), and AiFindBuildingPlace2().

void AiExplore ( int  x,
int  y,
int  mask 
)

Make two unittypes be considered equals.

Mark that a zone is requiring exploration.

Parameters:
x X pos of the zone
y Y pos of the zone
mask Mask to explore ( land/sea/air )

Definition at line 827 of file ai_resource.cpp.

References AiPlayer, PlayerAi::FirstExplorationRequest, AiExplorationRequest::Mask, AiExplorationRequest::X, and AiExplorationRequest::Y.

Referenced by AiAssignHarvester().

static int AiMakeUnit ( CUnitType type  )  [static]

Check if we can make a unit-type.

Parameters:
type Unit-type that must be made.
Returns:
True if made, false if can't be made.
Note:
We must check if the dependencies are fulfilled.

Definition at line 312 of file ai_resource.cpp.

References _C_, AiBuildBuilding(), AiFindAvailableUnitTypeEquiv(), AiHelpers, AiPlayer, AiTrainUnit(), AiHelper::Build, CUnitType::Building, DebugPrint, CUnitType::Ident, int(), PlayerAi::Player, CUnitType::Slot, AiHelper::Train, UnitTypeMax, UnitTypes, and CPlayer::UnitTypesCount.

Referenced by AiCheckingWork().

static int AiRepairBuilding ( const CUnitType type,
CUnit building 
) [static]

Check if we can repair the building.

Parameters:
type Unit that can repair the building.
building Building to be repaired.
Returns:
True if can repair, false if can't repair..

Definition at line 580 of file ai_resource.cpp.

References AiPlayer, CommandRepair(), FindPlayerUnitsByType(), FlushCommands, NoUnitP, CUnit::OrderCount, CUnit::Orders, PlayerAi::Player, CUnitType::RepairRange, PlayerAi::TriedRepairWorkers, CUnit::Type, UnitActionResource, UnitActionStill, UnitMax, UnitNumber, UnitReachable(), CUnit::X, and CUnit::Y.

Referenced by AiRepairUnit().

static int AiRepairUnit ( CUnit unit  )  [static]

Check if we can repair this unit.

Parameters:
unit Unit that must be repaired.
Returns:
True if made, false if can't be made.

Definition at line 680 of file ai_resource.cpp.

References _C_, AiHelpers, AiPlayer, AiRepairBuilding(), DebugPrint, CUnitType::Ident, int(), PlayerAi::Player, AiHelper::Repair, CUnitType::Slot, CUnit::Type, and CPlayer::UnitTypesCount.

Referenced by AiCheckRepair().

void AiResourceManager ( void   ) 

Ask the ai to explore around x,y.

Entry point of resource manager, periodically called.

Definition at line 843 of file ai_resource.cpp.

References AiCheckingWork(), AiCheckRepair(), AiCollectResources(), AiPlayer, COLLECT_RESOURCES_INTERVAL, CYCLES_PER_SECOND, GameCycle, CPlayer::Index, PlayerAi::NeededMask, and PlayerAi::Player.

Referenced by AiEachSecond().

static int AiTrainUnit ( const CUnitType type,
CUnitType what 
) [static]

Check if we can train the unit.

Parameters:
type Unit that can train the unit.
what What to be trained.
Returns:
True if made, false if can't be made.
Note:
We must check if the dependencies are fulfilled.

Definition at line 224 of file ai_resource.cpp.

References AiPlayer, CommandTrainUnit(), FindPlayerUnitsByType(), FlushCommands, CUnit::IsIdle(), PlayerAi::Player, and UnitMax.

Referenced by AiMakeUnit().


Generated on Sat Feb 21 00:28:15 2009 for Bos Wars by  doxygen 1.5.6