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

       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_local.h File Reference

The local AI header file. More...

#include <vector>
#include "upgrade_structs.h"
#include "unit.h"

Go to the source code of this file.

Classes

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

Defines

#define AI_MAX_FORCES   10
 How many forces are supported.
#define AI_MAX_ATTACKING_FORCES   30
 Attacking forces.

Enumerations

enum  AiForceRole { AiForceRoleAttack, AiForceRoleDefend }

Functions

void AiAddUnitTypeRequest (CUnitType *type, int count)
 < Add unit-type request to resource manager
void AiResourceManager (void)
 Ask the ai to explore around x,y.
void AiExplore (int x, int y, int exploreMask)
 Make two unittypes be considered equals.
void AiNewUnitTypeEquiv (CUnitType *a, CUnitType *b)
 Remove any equivalence between unittypes.
void AiResetUnitTypeEquiv (void)
 Finds all equivalents units to a given one.
int AiFindUnitTypeEquiv (const CUnitType *i, int *result)
 Finds all available equivalents units to a given one, in the prefered order.
int AiFindAvailableUnitTypeEquiv (const CUnitType *i, int *result)
int AiFindBuildingPlace (const CUnit *worker, const CUnitType *type, int *dx, int *dy)
 < Find nice building place
void AiCleanForces (void)
 < Cleanup units in force
void AiAssignToForce (CUnit *unit)
 Assign a free units to a force.
void AiAssignFreeUnitsToForce (void)
 Attack with force at position.
void AiAttackWithForceAt (int force, int x, int y)
 Attack with force.
void AiAttackWithForce (int force)
 Periodic called force manager handler.
void AiForceManager (void)
int AiPlanAttack (AiForce *force)
 < Plan the an attack
void AiSendExplorers (void)
 Enemy units in distance.
int AiEnemyUnitsInDistance (const CPlayer *player, const CUnitType *type, int x, int y, unsigned range)
void AiCheckMagic (void)
 < Check for magic

Variables

std::vector< CAiType * > AiTypes
 List of all AI types.
AiHelper AiHelpers
 AI helper variables.
int UnitTypeEquivs [UnitTypeMax+1]
 equivalence between unittypes
PlayerAiAiPlayer
 Current AI player.


Detailed Description

The local AI header file.

Definition in file ai_local.h.


Define Documentation

#define AI_MAX_ATTACKING_FORCES   30

#define AI_MAX_FORCES   10


Enumeration Type Documentation

Roles for forces

Enumerator:
AiForceRoleAttack  Force should attack.
AiForceRoleDefend  Force should defend.

Definition at line 95 of file ai_local.h.


Function Documentation

void AiAddUnitTypeRequest ( CUnitType type,
int  count 
)

< Add unit-type request to resource manager

Periodic called resource manager handler

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

void AiAssignFreeUnitsToForce ( void   ) 

Attack with force at position.

Assign free units to force.

Definition at line 334 of file ai_force.cpp.

References AI_MAX_ATTACKING_FORCES, AiAssignToForce(), AiCleanForces(), AiPlayer, PlayerAi::Force, int(), PlayerAi::Player, CPlayer::TotalNumUnits, UnitMax, AiForce::Units, and CPlayer::Units.

Referenced by AiForceManager(), and CclAiForce().

void AiAssignToForce ( CUnit unit  ) 

Assign a free units to a force.

Ai assign unit to force.

Parameters:
unit Unit to assign to force.

Definition at line 310 of file ai_force.cpp.

References AI_MAX_FORCES, AiCheckBelongsToForce(), AiPlayer, AiForce::Attacking, AiForce::Defending, PlayerAi::Force, CUnit::RefsIncrease(), CUnit::Type, and AiForce::Units.

Referenced by AiAssignFreeUnitsToForce(), and AiTrainingComplete().

void AiAttackWithForce ( int  force  ) 

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

Attack with force.

Attack at position with force.

Parameters:
force Force number to attack with.
x X tile map position to be attacked.
y Y tile map position to be attacked.

Definition at line 376 of file ai_force.cpp.

References AiCleanForce(), AiPlayer, AiForce::Attacking, CUnitType::CanAttack, CommandAttack(), CommandMove(), FlushCommands, PlayerAi::Force, int(), CUnit::Type, AiForce::Units, and CUnit::Wait.

Referenced by AiHelpMe().

void AiCheckMagic ( void   ) 

< Check for magic

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

Definition at line 55 of file ai_magic.cpp.

References AiPlayer, AutoCastSpell(), CUnitType::CanCastSpell, PlayerAi::Player, SpellIsAvailable(), SpellTypeTable, CPlayer::TotalNumUnits, CUnit::Type, and CPlayer::Units.

Referenced by AiEachSecond().

void AiCleanForces ( void   ) 

< Cleanup units in force

Assign a new unit to a force

Cleanup units in forces.

Definition at line 249 of file ai_force.cpp.

References AI_MAX_ATTACKING_FORCES, and AiCleanForce().

Referenced by AiAssignFreeUnitsToForce(), AiTrainingComplete(), and CclAiWaitForce().

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

int AiFindAvailableUnitTypeEquiv ( const CUnitType unittype,
int *  usableTypes 
)

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

Parameters:
unittype The unittype to find equivalence for
usableTypes int array which will hold the result. (Size UnitTypeMax+1)
Returns:
the number of unittype found

Definition at line 137 of file ai_force.cpp.

References AiFindUnitTypeEquiv(), AiPlayer, CPlayer::Index, PlayerAi::Player, and UnitTypes.

Referenced by AiMakeUnit().

int AiFindBuildingPlace ( const CUnit worker,
const CUnitType type,
int *  dx,
int *  dy 
)

< Find nice building place

Find free building place.

Parameters:
worker Worker to build building.
type Type of building.
dx Pointer for X position returned.
dy Pointer for Y 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.

Definition at line 298 of file ai_building.cpp.

References _C_, AiFindBuildingPlace2(), DebugPrint, CUnitType::Ident, CUnitType::Name, CUnit::X, and CUnit::Y.

Referenced by AiBuildBuilding().

int AiFindUnitTypeEquiv ( const CUnitType unittype,
int *  result 
)

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

Find All unittypes equivalent to a given one

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

Definition at line 108 of file ai_force.cpp.

References CUnitType::Slot, UnitTypeEquivs, and UnitTypeMax.

Referenced by AiFindAvailableUnitTypeEquiv(), AiReduceMadeInBuilt(), and AiRemoveFromBuilt().

void AiForceManager ( void   ) 

Entry point of force manager, perodic called.

Todo:
FIXME: is this really needed anymore

Definition at line 565 of file ai_force.cpp.

References AI_MAX_ATTACKING_FORCES, AiAssignFreeUnitsToForce(), AiCleanForce(), AiForceAttacks(), AiPlayer, AiForce::Attacking, AttackUnitsInReactRange(), CUnitType::CanAttack, DebugPrint, AiForce::Defending, PlayerAi::Force, int(), CUnit::Type, and AiForce::Units.

Referenced by AiEachSecond().

void AiNewUnitTypeEquiv ( CUnitType a,
CUnitType b 
)

Remove any equivalence between unittypes.

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

Parameters:
a the first unittype
b the second unittype

Definition at line 75 of file ai_force.cpp.

References CUnitType::Slot, UnitTypeEquivs, and UnitTypeMax.

Referenced by CclDefineAiHelper().

int AiPlanAttack ( AiForce force  ) 

< Plan the an attack

Send explorers around the map

Plan an attack with a force. We know, that we must use a transporter.

Parameters:
force Pointer on the force.
Returns:
True if target found, false otherwise.
Todo:
Perfect planning. Only works for water transporter!
Todo:
transporter are more selective now (flag with unittypeland). We must manage it.

Definition at line 375 of file ai_plan.cpp.

References _C_, AiFindTarget(), AiMarkWaterTransporter(), AiPlayer, CUnitType::CanTransport, CreateMatrix(), DebugPrint, PlayerAi::Force, AiForce::GoalX, AiForce::GoalY, CPlayer::Index, int(), CUnit::IsIdle(), AiForce::MustTransport, PlayerAi::Player, CUnit::RefsIncrease(), AiForce::State, CPlayer::TotalNumUnits, CUnit::Type, UnitNumber, CPlayer::Units, AiForce::Units, CUnitType::UnitType, UnitTypeLand, and y.

Referenced by AiAttackWithForce().

void AiResetUnitTypeEquiv ( void   ) 

Finds all equivalents units to a given one.

Remove any equivalence between unittypes

Definition at line 62 of file ai_force.cpp.

References UnitTypeEquivs, and UnitTypeMax.

Referenced by FreeAi(), and InitAiModule().

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

void AiSendExplorers ( void   ) 


Variable Documentation

AI helper variables.

Definition at line 155 of file ai.cpp.

Referenced by AiCountUnitBuilders(), AiMakeUnit(), AiRepairUnit(), CclAiWait(), and CclDefineAiHelper().

std::vector<CAiType *> AiTypes

List of all AI types.

Definition at line 154 of file ai.cpp.

Referenced by AiInit(), CclDefineAi(), CclDefineAiPlayer(), and FreeAi().

int UnitTypeEquivs[UnitTypeMax+1]

equivalence between unittypes

Definition at line 52 of file ai_force.cpp.

Referenced by AiCheckBelongsToForce(), AiCleanForce(), AiFindUnitTypeEquiv(), AiNewUnitTypeEquiv(), AiResetUnitTypeEquiv(), and CclAiForce().


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