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

Classes
ai_local.h File Reference
#include <vector>
#include "upgrade_structs.h"
#include "unit_cache.h"
#include "vec2i.h"

Go to the source code of this file.

Classes

class  CAiType
 
class  AiRequestType
 
class  AiUnitType
 
class  AiForce
 
class  AiForceManager
 
class  AiBuildQueue
 
class  AiExplorationRequest
 
class  PlayerAi
 
class  AiHelper
 

ai_local.h - The local AI header file.

#define AI_WAIT_ON_RALLY_POINT   60
 
#define AI_MAX_FORCES   50
 
#define AI_MAX_FORCE_INTERNAL   (AI_MAX_FORCES / 2)
 
enum  AiForceRole { AiForceRoleDefault = 0, AiForceRoleAttack = 0, AiForceRoleDefend }
 
enum  AiForceAttackingState {
  AiForceAttackingState_Free = -1, AiForceAttackingState_Waiting = 0, AiForceAttackingState_Boarding, AiForceAttackingState_GoingToRallyPoint,
  AiForceAttackingState_AttackingWithTransporter, AiForceAttackingState_Attacking
}
 
std::vector< CAiType * > AiTypes
 Ai sleeps # cycles. More...
 
AiHelper AiHelpers
 List of all AI types. More...
 
int UnitTypeEquivs [UnitTypeMax+1]
 AI helper variables. More...
 
PlayerAiAiPlayer
 equivalence between unittypes More...
 
void AiAddUnitTypeRequest (CUnitType &type, int count)
 Current AI player. More...
 
void AiAddUpgradeToRequest (CUnitType &type)
 Add upgrade-to request to resource manager. More...
 
void AiAddResearchRequest (CUpgrade *upgrade)
 Add research request to resource manager. More...
 
void AiResourceManager ()
 Periodic called resource manager handler. More...
 
void AiExplore (const Vec2i &pos, int exploreMask)
 Ask the ai to explore around pos. More...
 
void AiNewUnitTypeEquiv (const CUnitType &a, const CUnitType &b)
 Make two unittypes be considered equals. More...
 
void AiResetUnitTypeEquiv ()
 Remove any equivalence between unittypes. More...
 
int AiFindUnitTypeEquiv (const CUnitType &type, int *result)
 Finds all equivalents units to a given one. More...
 
int AiFindAvailableUnitTypeEquiv (const CUnitType &type, int *result)
 Finds all available equivalents units to a given one, in the preferred order. More...
 
int AiGetBuildRequestsCount (const PlayerAi &pai, int(&counter)[UnitTypeMax])
 
void AiNewDepotRequest (CUnit &worker)
 
CUnitAiGetSuitableDepot (const CUnit &worker, const CUnit &oldDepot, CUnit **resUnit)
 
bool AiFindBuildingPlace (const CUnit &worker, const CUnitType &type, const Vec2i &nearPos, Vec2i *resultPos)
 Find nice building place. More...
 
void AiRemoveDeadUnitInForces ()
 Cleanup units in force. More...
 
bool AiAssignToForce (CUnit &unit)
 Assign a new unit to a force. More...
 
void AiAssignFreeUnitsToForce (int force=-1)
 Assign a free units to a force. More...
 
void AiAttackWithForceAt (unsigned int force, int x, int y)
 Attack with force at position. More...
 
void AiAttackWithForce (unsigned int force)
 Attack with force. More...
 
void AiAttackWithForces (int *forces)
 Attack with forces in array. More...
 
void AiForceManager ()
 Periodic called force manager handler. More...
 
int AiFindWall (AiForce *force)
 Find a wall to attack. More...
 
void AiSendExplorers ()
 
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...
 
void AiCheckMagic ()
 Check for magic. More...
 

Macro Definition Documentation

◆ AI_MAX_FORCE_INTERNAL

#define AI_MAX_FORCE_INTERNAL   (AI_MAX_FORCES / 2)

◆ AI_MAX_FORCES

#define AI_MAX_FORCES   50

◆ AI_WAIT_ON_RALLY_POINT

#define AI_WAIT_ON_RALLY_POINT   60

Enumeration Type Documentation

◆ AiForceAttackingState

Enumerator
AiForceAttackingState_Free 
AiForceAttackingState_Waiting 
AiForceAttackingState_Boarding 
AiForceAttackingState_GoingToRallyPoint 
AiForceAttackingState_AttackingWithTransporter 
AiForceAttackingState_Attacking 

◆ AiForceRole

Roles for forces

Enumerator
AiForceRoleDefault 
AiForceRoleAttack 

So default is attacking.

AiForceRoleDefend 

Force should attack.

Force should defend

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

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

◆ AiAssignFreeUnitsToForce()

void AiAssignFreeUnitsToForce ( int  force)

Assign a free units to a force.

Assign free units to force.

◆ AiAssignToForce()

bool AiAssignToForce ( CUnit unit)

Assign a new unit to a force.

Ai assign unit to force.

Parameters
unitUnit to assign to force.

◆ AiAttackWithForce()

void AiAttackWithForce ( unsigned int  force)

Attack with force.

Attack opponent with force.

Parameters
forceForce number to attack with.

◆ AiAttackWithForceAt()

void AiAttackWithForceAt ( unsigned int  force,
int  x,
int  y 
)

Attack with force at position.

Attack at position with force.

Parameters
forceForce number to attack with.
xX tile map position to be attacked.
yY tile map position to be attacked.

◆ AiAttackWithForces()

void AiAttackWithForces ( int *  forces)

Attack with forces in array.

Attack opponent with forces. Merge forces in array into one attack force and attack with it Merge is make because units in one force help each other during attack

Parameters
forcesArray with Force numbers to attack with (array should be finished with -1).

◆ AiCheckMagic()

void AiCheckMagic ( )

Check for magic.

Check what computer units can do with magic. In fact, turn on autocast for AI.

◆ AiEnemyUnitsInDistance()

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

◆ 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 )

◆ AiFindAvailableUnitTypeEquiv()

int AiFindAvailableUnitTypeEquiv ( const CUnitType unittype,
int *  usableTypes 
)

Finds all available equivalents units to a given one, in the preferred order.

Find All unittypes equivalent to a given one, and which are available UnitType are returned in the preferred order (ie palladin >> knight...)

Parameters
unittypeThe unittype to find equivalence for
usableTypesint array which will hold the result. (Size UnitTypeMax+1)
Returns
the number of unittype found

◆ AiFindBuildingPlace()

bool AiFindBuildingPlace ( const CUnit worker,
const CUnitType type,
const Vec2i nearPos,
Vec2i resultPos 
)

Find nice building place.

Find free building place.

Parameters
workerWorker to build building.
typeType of building.
nearPosStart search near nearPos position (or worker->X if nearPos is invalid).
resultPosPointer for position returned.
Returns
True if place found, false if no found.
Todo:
Better and faster way to find building place of oil platforms Special routines for special buildings.

◆ AiFindUnitTypeEquiv()

int AiFindUnitTypeEquiv ( const CUnitType unittype,
int *  result 
)

Finds all equivalents units to a given one.

Find All unittypes equivalent to a given one

Parameters
unittypethe unittype to find equivalence for
resultint array which will hold the result. (Size UnitTypeMax+1)
Returns
the number of unittype found

◆ AiFindWall()

int AiFindWall ( AiForce force)

Find a wall to attack.

Find possible walls to target.

Parameters
forceAttack force.
Returns
True if wall found.

◆ AiForceManager()

Periodic called force manager handler.

Entry point of force manager, periodic called.

◆ 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.

◆ AiNewDepotRequest()

void AiNewDepotRequest ( CUnit worker)

◆ AiNewUnitTypeEquiv()

void AiNewUnitTypeEquiv ( const CUnitType a,
const CUnitType b 
)

Make two unittypes be considered equals.

Make two unittypes equivalents from the AI's point of vue

Parameters
athe first unittype
bthe second unittype

◆ AiRemoveDeadUnitInForces()

void AiRemoveDeadUnitInForces ( )

Cleanup units in force.

Cleanup units in forces.

◆ AiResetUnitTypeEquiv()

void AiResetUnitTypeEquiv ( )

Remove any equivalence between unittypes.

Remove any equivalence between unittypes.

Remove any equivalence between unittypes

◆ AiResourceManager()

void AiResourceManager ( )

Periodic called resource manager handler.

Entry point of resource manager, periodically called.

◆ AiSendExplorers()

void AiSendExplorers ( )

Plan the an attack Send explorers around the map

Respond to ExplorationRequests

Variable Documentation

◆ AiHelpers

AiHelper AiHelpers

List of all AI types.

◆ AiPlayer

PlayerAi* AiPlayer

equivalence between unittypes

equivalence between unittypes

◆ AiTypes

std::vector<CAiType *> AiTypes

Ai sleeps # cycles.

◆ UnitTypeEquivs

int UnitTypeEquivs[UnitTypeMax+1]

AI helper variables.

(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.