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

ai.cpp File Reference
#include "stratagus.h"
#include "ai.h"
#include "ai_local.h"
#include "actions.h"
#include "action/action_attack.h"
#include "commands.h"
#include "iolib.h"
#include "map.h"
#include "pathfinder.h"
#include "player.h"
#include "script.h"
#include "unit.h"
#include "unit_manager.h"
#include "unittype.h"
#include "upgrade.h"

ai.cpp - The computer player AI main file.

int AiSleepCycles
 
std::vector< CAiType * > AiTypes
 Ai sleeps # cycles. More...
 
AiHelper AiHelpers
 List of all AI types. More...
 
PlayerAiAiPlayer
 AI helper variables. More...
 
static void AiExecuteScript ()
 Current AI player. More...
 
static void AiCheckUnits ()
 
static void SaveAiPlayer (CFile &file, int plynr, const PlayerAi &ai)
 
void SaveAi (CFile &file)
 Free the AI resources. More...
 
void AiInit (CPlayer &player)
 Init AI global structures. More...
 
void InitAiModule ()
 Called each second. More...
 
void CleanAi ()
 Init AI for this player. More...
 
void FreeAi ()
 Cleanup the AI module. More...
 
static int AiRemoveFromBuilt2 (PlayerAi *pai, const CUnitType &type)
 
static void AiRemoveFromBuilt (PlayerAi *pai, const CUnitType &type)
 
static bool AiReduceMadeInBuilt2 (PlayerAi &pai, const CUnitType &type)
 
void AiReduceMadeInBuilt (PlayerAi &pai, const CUnitType &type)
 
void AiHelpMe (const CUnit *attacker, CUnit &defender)
 Called if AI unit is attacked. More...
 
void AiUnitKilled (CUnit &unit)
 Called if AI unit is killed. More...
 
void AiWorkComplete (CUnit *unit, CUnit &what)
 Called if AI unit has completed work. More...
 
void AiCanNotBuild (const CUnit &unit, const CUnitType &what)
 Called if AI unit can't build. More...
 
void AiCanNotReach (CUnit &unit, const CUnitType &what)
 Called if AI unit can't reach building place. More...
 
static void AiMoveUnitInTheWay (CUnit &unit)
 
void AiCanNotMove (CUnit &unit)
 Called if an AI unit can't move. More...
 
void AiNeedMoreSupply (const CPlayer &player)
 Called if AI needs more farms. More...
 
void AiTrainingComplete (CUnit &unit, CUnit &what)
 Called if AI unit has completed training. More...
 
void AiUpgradeToComplete (CUnit &unit, const CUnitType &what)
 Called if AI unit has completed upgrade to. More...
 
void AiResearchComplete (CUnit &unit, const CUpgrade *what)
 Called if AI unit has completed research. More...
 
void AiEachCycle (CPlayer &player)
 Ai sleeps # cycles. More...
 
void AiEachSecond (CPlayer &player)
 Called each game cycle. More...
 

Function Documentation

◆ AiCanNotBuild()

void AiCanNotBuild ( const CUnit unit,
const CUnitType what 
)

Called if AI unit can't build.

Called if building can't be build.

Parameters
unitPointer to unit what builds the building.
whatPointer to unit-type.

◆ AiCanNotMove()

void AiCanNotMove ( CUnit unit)

Called if an AI unit can't move.

Called if a unit can't move. Try to move unit in the way

Parameters
unitPointer to unit what builds the building.

◆ AiCanNotReach()

void AiCanNotReach ( CUnit unit,
const CUnitType what 
)

Called if AI unit can't reach building place.

Called if building place can't be reached.

Parameters
unitPointer to unit what builds the building.
whatPointer to unit-type.

◆ AiCheckUnits()

static void AiCheckUnits ( )
static

Check if everything is fine, send new requests to resource manager.

◆ AiEachCycle()

void AiEachCycle ( CPlayer player)

Ai sleeps # cycles.

This is called for each player, each game cycle.

Parameters
playerThe player structure pointer.

◆ AiEachSecond()

void AiEachSecond ( CPlayer player)

Called each game cycle.

This is called for each player each second.

Parameters
playerThe player structure pointer.

◆ AiExecuteScript()

static void AiExecuteScript ( )
static

Current AI player.

Execute the AI Script.

◆ AiHelpMe()

void AiHelpMe ( const CUnit attacker,
CUnit defender 
)

Called if AI unit is attacked.

Called if a Unit is Attacked

Parameters
attackerPointer to attacker unit.
defenderPointer to unit that is being attacked.

◆ AiInit()

void AiInit ( CPlayer player)

Init AI global structures.

Setup all at start.

Parameters
playerThe player structure pointer.

◆ AiMoveUnitInTheWay()

static void AiMoveUnitInTheWay ( CUnit unit)
static

Try to move a unit that's in the way

◆ AiNeedMoreSupply()

void AiNeedMoreSupply ( const CPlayer player)

Called if AI needs more farms.

Called if the AI needs more farms.

Parameters
playerplayer which need supply.

◆ AiReduceMadeInBuilt()

void AiReduceMadeInBuilt ( PlayerAi pai,
const CUnitType type 
)

Reduce made unit-type from build list.

Parameters
paiComputer AI player.
typeUnit-type which is now available.

◆ AiReduceMadeInBuilt2()

static bool AiReduceMadeInBuilt2 ( PlayerAi pai,
const CUnitType type 
)
static

Reduce made unit-type from build list.

Parameters
paiComputer AI player.
typeUnit-type which is now available.
Returns
True if the unit-type could be reduced.

◆ AiRemoveFromBuilt()

static void AiRemoveFromBuilt ( PlayerAi pai,
const CUnitType type 
)
static

Remove unit-type from build list.

Parameters
paiComputer AI player.
typeUnit-type which is now available.

◆ AiRemoveFromBuilt2()

static int AiRemoveFromBuilt2 ( PlayerAi pai,
const CUnitType type 
)
static

Remove unit-type from build list.

Parameters
paiComputer AI player.
typeUnit-type which is now available.
Returns
True, if unit-type was found in list.

◆ AiResearchComplete()

void AiResearchComplete ( CUnit unit,
const CUpgrade what 
)

Called if AI unit has completed research.

Called if reseaching of an unit is completed.

Parameters
unitPointer to unit working.
whatPointer to the new upgrade.

◆ AiTrainingComplete()

void AiTrainingComplete ( CUnit unit,
CUnit what 
)

Called if AI unit has completed training.

Called if training of a unit is completed.

Parameters
unitPointer to unit making.
whatPointer to new ready trained unit.

◆ AiUnitKilled()

void AiUnitKilled ( CUnit unit)

Called if AI unit is killed.

Called if a unit is killed.

Parameters
unitPointer to unit.

◆ AiUpgradeToComplete()

void AiUpgradeToComplete ( CUnit unit,
const CUnitType what 
)

Called if AI unit has completed upgrade to.

Called if upgrading of an unit is completed.

Parameters
unitPointer to unit working.
whatPointer to the new unit-type.

◆ AiWorkComplete()

void AiWorkComplete ( CUnit unit,
CUnit what 
)

Called if AI unit has completed work.

Called if work complete (Buildings).

Parameters
unitPointer to unit that builds the building.
whatPointer to unit building that was built.

◆ CleanAi()

void CleanAi ( )

Init AI for this player.

Cleanup the AI in order to enable to restart a game.

◆ FreeAi()

void FreeAi ( )

Cleanup the AI module.

Free all AI resources.

◆ InitAiModule()

void InitAiModule ( )

Called each second.

Initialize global structures of the AI

◆ SaveAi()

void SaveAi ( CFile file)

Free the AI resources.

Save state of AI to file.

Parameters
fileOutput file.

◆ SaveAiPlayer()

static void SaveAiPlayer ( CFile file,
int  plynr,
const PlayerAi ai 
)
static

Save state of player AI.

Parameters
fileOutput file.
plynrPlayer number.
aiPlayer AI.

Variable Documentation

◆ AiHelpers

AiHelper AiHelpers

List of all AI types.

◆ AiPlayer

PlayerAi* AiPlayer

AI helper variables.

equivalence between unittypes

◆ AiSleepCycles

int AiSleepCycles

◆ AiTypes

std::vector<CAiType *> AiTypes

Ai sleeps # cycles.

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