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

Classes
ai_resource.cpp File Reference
#include "settings.h"
#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 "tileset.h"
#include "unit.h"
#include "unit_find.h"
#include "unittype.h"
#include "upgrade.h"
#include "network.h"

Classes

class  IsAEnemyUnitOf< ignoreVisibility >
 
class  IsAEnemyUnitWhichCanCounterAttackOf< ignoreVisibility >
 
struct  cnode
 
class  IsAWorker
 
class  CompareDepotsByDistance
 

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)
 
bool AiEnemyUnitsInDistance (const CPlayer &player, const CUnitType *type, const Vec2i &pos, unsigned range)
 Check if there are enemy units in a given range (optionally of type) More...
 
bool 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)
 
CUnitAiGetSuitableDepot (const CUnit &worker, const CUnit &oldDepot, CUnit **resUnit)
 
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. More...
 
static bool AiUpgradeTo (const CUnitType &type, CUnitType &what)
 
void AiAddUpgradeToRequest (CUnitType &type)
 Add upgrade-to request to resource manager. More...
 
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. More...
 
void AiExplore (const Vec2i &pos, int mask)
 Ask the ai to explore around pos. More...
 
void AiResourceManager ()
 Periodic called resource manager handler. More...
 

Macro Definition Documentation

◆ COLLECT_RESOURCES_INTERVAL

#define COLLECT_RESOURCES_INTERVAL   4

Function Documentation

◆ AiAddResearchRequest()

void AiAddResearchRequest ( CUpgrade upgrade)

Add research request to resource manager.

Check if the research can be done.

Parameters
upgradeUpgrade to research

◆ AiAddUnitTypeRequest()

void AiAddUnitTypeRequest ( CUnitType type,
int  count 
)

Current AI player.

Add unit-type request to resource manager.

Parameters
typeUnit type requested.
countHow many units.
Todo:
FIXME: should store the end of list and not search it.

◆ AiAddUpgradeToRequest()

void AiAddUpgradeToRequest ( CUnitType type)

Add upgrade-to request to resource manager.

Check if the upgrade-to can be done.

Parameters
typeFIXME: docu

◆ AiAssignHarvester()

static int AiAssignHarvester ( CUnit unit,
int  resource 
)
static

Assign worker to gather a certain resource.

Parameters
unitpointer to the unit.
resourceresource identification.
Returns
1 if the worker was assigned, 0 otherwise.

◆ AiAssignHarvesterFromTerrain()

static int AiAssignHarvesterFromTerrain ( CUnit unit,
int  resource 
)
static

Assign worker to gather a certain resource from terrain.

Parameters
unitpointer to the unit.
resourceresource identification.
Returns
1 if the worker was assigned, 0 otherwise.

◆ AiAssignHarvesterFromUnit()

static int AiAssignHarvesterFromUnit ( CUnit unit,
int  resource 
)
static

Assign worker to gather a certain resource from Unit.

Parameters
unitpointer to the unit.
resourceresource identification.
Returns
1 if the worker was assigned, 0 otherwise.

◆ AiBuildBuilding()

static int AiBuildBuilding ( const CUnitType type,
CUnitType building,
const Vec2i nearPos 
)
static

Check if we can build the building.

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

◆ AiCheckCosts()

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
costsCosts for something.
Returns
A bit field of the missing costs.

◆ AiCheckingWork()

static void AiCheckingWork ( )
static

Check what must be built / trained.

◆ AiCheckRepair()

static void AiCheckRepair ( )
static

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

◆ AiCheckSupply()

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
paiAI player.
typeUnit-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.

◆ AiCheckUnitTypeCosts()

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
typeUnit-type to check the costs for.
Returns
A bit field of the missing costs.

◆ AiCollectResources()

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.

◆ AiEnemyUnitsInDistance() [1/2]

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

Check if there are enemy units in a given range (optionally of type)

Check if there are enemy units in a given range.

Parameters
playerFind enemies of this player
typeOptional unit type to check if enemy can target this
poslocation
rangeDistance range to look.
Returns
If there are any enemy units in the range

◆ AiEnemyUnitsInDistance() [2/2]

bool AiEnemyUnitsInDistance ( const CUnit unit,
unsigned  range 
)

Check if there are enemy units in a given range.

Parameters
unitFind in distance for this unit.
rangeDistance range to look.
Returns
If there are any enemy units in the range

◆ AiExplore()

void AiExplore ( const Vec2i pos,
int  mask 
)

Ask the ai to explore around pos.

Mark that a zone is requiring exploration.

Parameters
posPos of the zone
maskMask to explore ( land/sea/air )

◆ AiGetBuildRequestsCount()

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

◆ AiGetSuitableDepot()

CUnit* AiGetSuitableDepot ( const CUnit worker,
const CUnit oldDepot,
CUnit **  resUnit 
)

Get a suitable depot for better resource harvesting.

Parameters
workerWorker itself.
oldDepotOld assigned depot.
resUnitResource to harvest from, if succeed
Returns
new depot if found, NULL otherwise.

◆ AiMakeUnit()

static int AiMakeUnit ( CUnitType typeToMake,
const Vec2i nearPos 
)
static

Check if we can make a unit-type.

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

◆ AiNewDepotRequest()

void AiNewDepotRequest ( CUnit worker)

◆ AiRepairBuilding()

static bool AiRepairBuilding ( const CPlayer player,
const CUnitType type,
CUnit building 
)
static

Check if we can repair the building.

Parameters
typeUnit that can repair the building.
buildingBuilding to be repaired.
Returns
True if can repair, false if can't repair..

◆ AiRepairUnit()

static int AiRepairUnit ( CUnit unit)
static

Check if we can repair this unit.

Parameters
unitUnit that must be repaired.
Returns
True if made, false if can't be made.

◆ AiRequestedTypeAllowed()

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

◆ AiRequestSupply()

static bool AiRequestSupply ( )
static

Build new units to reduce the food shortage.

◆ AiResearchUpgrade()

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

Check if we can research the upgrade.

Parameters
typeUnit that can research the upgrade.
whatWhat should be researched.
Returns
True if made, false if can't be made.
Note
We must check if the dependencies are fulfilled.

◆ AiResourceManager()

void AiResourceManager ( )

Periodic called resource manager handler.

Entry point of resource manager, periodically called.

◆ AiTrainUnit()

static bool AiTrainUnit ( const CUnitType type,
CUnitType what 
)
static

Check if we can train the unit.

Parameters
typeUnit that can train the unit.
whatWhat to be trained.
Returns
True if made, false if can't be made.
Note
We must check if the dependencies are fulfilled.

◆ AiUpgradeTo()

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

Check if we can upgrade to unit-type.

Parameters
typeUnit that can upgrade to unit-type
whatTo what should be upgraded.
Returns
True if made, false if can't be made.

◆ CmpWorkers()

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

◆ cnode_cmp()

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

◆ FindDepositNearLoc()

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

◆ IsAlreadyWorking()

static bool IsAlreadyWorking ( const CUnit unit)
static

◆ IsReadyToRepair()

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.