$treeview $search $mathjax
Stratagus  2.2.7
$projectbrief
$projectbrief
$searchbox
-->
         _________ __                 __
        /   _____//  |_____________ _/  |______     ____  __ __  ______
        \_____  \\   __\_  __ \__  \\   __\__  \   / ___\|  |  \/  ___/
        /        \|  |  |  | \// __ \|  |  / __ \_/ /_/  >  |  /\___ \
       /_______  /|__|  |__|  (____  /__| (____  /\___  /|____//____  >
               \/                  \/          \//_____/            \/
    ______________________                           ______________________
                          T H E   W A R   B E G I N S
                   Stratagus - A free fantasy real time strategy game engine

src/ai/ai_resource.cpp File Reference

#include "stratagus.h"
#include "ai_local.h"
#include "action/action_build.h"
#include "action/action_repair.h"
#include "action/action_resource.h"
#include "commands.h"
#include "depend.h"
#include "map.h"
#include "pathfinder.h"
#include "player.h"
#include "unit.h"
#include "unit_find.h"
#include "unittype.h"
#include "upgrade.h"

Classes

class  IsAEnemyUnitOf
class  IsAEnemyUnitWhichCanCounterAttackOf
struct  cnode

ai_resource.cpp - AI resource manager.

#define COLLECT_RESOURCES_INTERVAL   4
static int AiMakeUnit (CUnitType &type, const Vec2i &nearPos)
static int AiCheckCosts (const int *costs)
static int AiCheckSupply (const PlayerAi &pai, const CUnitType &type)
static int AiCheckUnitTypeCosts (const CUnitType &type)
int AiEnemyUnitsInDistance (const CPlayer &player, const CUnitType *type, const Vec2i &pos, unsigned range)
int AiEnemyUnitsInDistance (const CUnit &unit, unsigned range)
static bool IsAlreadyWorking (const CUnit &unit)
static int AiBuildBuilding (const CUnitType &type, CUnitType &building, const Vec2i &nearPos)
static bool AiRequestedTypeAllowed (const CPlayer &player, const CUnitType &type)
static bool cnode_cmp (const cnode &lhs, const cnode &rhs)
int AiGetBuildRequestsCount (const PlayerAi &pai, int(&counter)[UnitTypeMax])
CUnitFindDepositNearLoc (CPlayer &p, const Vec2i &pos, int range, int resource)
void AiNewDepotRequest (CUnit &worker)
static bool AiRequestSupply ()
static bool AiTrainUnit (const CUnitType &type, CUnitType &what)
static bool AiResearchUpgrade (const CUnitType &type, CUpgrade &what)
void AiAddResearchRequest (CUpgrade *upgrade)
 Add research request to resource manager.
static bool AiUpgradeTo (const CUnitType &type, CUnitType &what)
void AiAddUpgradeToRequest (CUnitType &type)
 Add upgrade-to request to resource manager.
static void AiCheckingWork ()
static int AiAssignHarvesterFromTerrain (CUnit &unit, int resource)
static int AiAssignHarvesterFromUnit (CUnit &unit, int resource)
static int AiAssignHarvester (CUnit &unit, int resource)
static bool CmpWorkers (const CUnit *lhs, const CUnit *rhs)
static void AiCollectResources ()
static bool IsReadyToRepair (const CUnit &unit)
static bool AiRepairBuilding (const CPlayer &player, const CUnitType &type, CUnit &building)
static int AiRepairUnit (CUnit &unit)
static void AiCheckRepair ()
void AiAddUnitTypeRequest (CUnitType &type, int count)
 Current AI player.
void AiExplore (const Vec2i &pos, int mask)
void AiResourceManager ()
 Periodic called resource manager handler.

Define Documentation

#define COLLECT_RESOURCES_INTERVAL   4


Function Documentation

void AiAddResearchRequest ( CUpgrade upgrade  ) 

Add research request to resource manager.

Check if the research can be done.

Parameters:
upgrade Upgrade to research

void AiAddUnitTypeRequest ( CUnitType type,
int  count 
)

Current AI player.

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.

void AiAddUpgradeToRequest ( CUnitType type  ) 

Add upgrade-to request to resource manager.

Check if the upgrade-to can be done.

Parameters:
type FIXME: docu

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

Assign worker to gather a certain resource.

Parameters:
unit pointer to the unit.
resource resource identification.
Returns:
1 if the worker was assigned, 0 otherwise.

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

Assign worker to gather a certain resource from terrain.

Parameters:
unit pointer to the unit.
resource resource identification.
Returns:
1 if the worker was assigned, 0 otherwise.

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

Assign worker to gather a certain resource from Unit.

Parameters:
unit pointer to the unit.
resource resource identification.
Returns:
1 if the worker was assigned, 0 otherwise.

static int AiBuildBuilding ( const CUnitType type,
CUnitType building,
const Vec2i nearPos 
) [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.

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.

static void AiCheckingWork (  )  [static]

Check what must be built / trained.

static void AiCheckRepair (  )  [static]

Check if there's a unit that should be repaired.

static int AiCheckSupply ( const PlayerAi pai,
const CUnitType type 
) [static]

Check if the AI player needs food.

It counts buildings in progress and units in training queues.

Parameters:
pai AI player.
type Unit-type that should be build.
Returns:
True if enought, false otherwise.
Todo:
The number of food currently trained can be stored global for faster use.

static int AiCheckUnitTypeCosts ( const CUnitType type  )  [static]

Check if the costs for an 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.

static void AiCollectResources (  )  [static]

Assign workers to collect resources.

If we have a shortage of a resource, let many workers collecting this. If no shortage, split workers to all resources.

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.

int AiEnemyUnitsInDistance ( const CPlayer player,
const CUnitType type,
const Vec2i pos,
unsigned  range 
)

Enemy units in distance.

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

void AiExplore ( const Vec2i pos,
int  mask 
)

Mark that a zone is requiring exploration.

Parameters:
pos Pos of the zone
mask Mask to explore ( land/sea/air )

int AiGetBuildRequestsCount ( const PlayerAi pai,
int(&)  counter[UnitTypeMax] 
)

static int AiMakeUnit ( CUnitType typeToMake,
const Vec2i nearPos 
) [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.

void AiNewDepotRequest ( CUnit worker  ) 

static bool AiRepairBuilding ( const CPlayer player,
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..

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.

static bool AiRequestedTypeAllowed ( const CPlayer player,
const CUnitType type 
) [static]

static bool AiRequestSupply (  )  [static]

Build new units to reduce the food shortage.

static bool AiResearchUpgrade ( const CUnitType type,
CUpgrade what 
) [static]

Check if we can research the upgrade.

Parameters:
type Unit that can research the upgrade.
what What should be researched.
Returns:
True if made, false if can't be made.
Note:
We must check if the dependencies are fulfilled.

void AiResourceManager (  ) 

Periodic called resource manager handler.

Entry point of resource manager, periodically called.

static bool 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.

static bool AiUpgradeTo ( const CUnitType type,
CUnitType what 
) [static]

Check if we can upgrade to unit-type.

Parameters:
type Unit that can upgrade to unit-type
what To what should be upgraded.
Returns:
True if made, false if can't be made.
Note:
We must check if the dependencies are fulfilled.

static bool CmpWorkers ( const CUnit lhs,
const CUnit rhs 
) [static]

static bool cnode_cmp ( const cnode lhs,
const cnode rhs 
) [static]

CUnit* FindDepositNearLoc ( CPlayer p,
const Vec2i pos,
int  range,
int  resource 
)

static bool IsAlreadyWorking ( const CUnit unit  )  [static]

static bool IsReadyToRepair ( const CUnit unit  )  [static]

(C) Copyright 1998-2012 by The Stratagus Project under the GNU General Public License.
All trademarks and copyrights on this page are owned by their respective owners.