$treeview $search $mathjax
Stratagus  2.2.6
$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.cpp File Reference

#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include "stratagus.h"
#include "player.h"
#include "unit.h"
#include "unittype.h"
#include "upgrade.h"
#include "script.h"
#include "actions.h"
#include "map.h"
#include "pathfinder.h"
#include "ai.h"
#include "ai_local.h"
#include "iolib.h"

ai.cpp - The computer player AI main file.

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

Function Documentation

void AiCanNotBuild ( CUnit unit,
const CUnitType what 
)

Called if AI unit can't build.

Called if building can't be build.

Parameters:
unit Pointer to unit what builds the building.
what Pointer to unit-type.

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:
unit Pointer to unit what builds the building.

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:
unit Pointer to unit what builds the building.
what Pointer to unit-type.

static void AiCheckUnits (  )  [static]

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

void AiEachCycle ( CPlayer player  ) 

Ai sleeps # cycles.

This is called for each player, each game cycle.

Parameters:
player The player structure pointer.

void AiEachSecond ( CPlayer player  ) 

Called each game cycle.

This is called for each player each second.

Parameters:
player The player structure pointer.

static void AiExecuteScript (  )  [static]

Current AI player.

Execute the AI Script.

void AiHelpMe ( const CUnit attacker,
CUnit defender 
)

Called if AI unit is attacked.

Called if a Unit is Attacked

Parameters:
attacker Pointer to attacker unit.
defender Pointer to unit that is being attacked.

void AiInit ( CPlayer player  ) 

Init AI global structures.

Setup all at start.

Parameters:
player The player structure pointer.

static void AiMoveUnitInTheWay ( CUnit unit  )  [static]

Try to move a unit that's in the way

void AiNeedMoreSupply ( const CPlayer player  ) 

Called if AI needs more farms.

Called if the AI needs more farms.

Parameters:
player player which need supply.

static void AiReduceMadeInBuilt ( PlayerAi pai,
const CUnitType type 
) [static]

Reduce made unit-type from build list.

Parameters:
pai Computer AI player.
type Unit-type which is now available.

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

Reduce made unit-type from build list.

Parameters:
pai Computer AI player.
type Unit-type which is now available.
Returns:
True if the unit-type could be reduced.

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

Remove unit-type from build list.

Parameters:
pai Computer AI player.
type Unit-type which is now available.

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

Remove unit-type from build list.

Parameters:
pai Computer AI player.
type Unit-type which is now available.
Returns:
True, if unit-type was found in list.

void AiResearchComplete ( CUnit unit,
const CUpgrade what 
)

Called if AI unit has completed research.

Called if reseaching of an unit is completed.

Parameters:
unit Pointer to unit working.
what Pointer to the new upgrade.

void AiTrainingComplete ( CUnit unit,
CUnit what 
)

Called if AI unit has completed training.

Called if training of a unit is completed.

Parameters:
unit Pointer to unit making.
what Pointer to new ready trained unit.

void AiUnitKilled ( CUnit unit  ) 

Called if AI unit is killed.

Called if a unit is killed.

Parameters:
unit Pointer to unit.

void AiUpgradeToComplete ( CUnit unit,
const CUnitType what 
)

Called if AI unit has completed upgrade to.

Called if upgrading of an unit is completed.

Parameters:
unit Pointer to unit working.
what Pointer to the new unit-type.

void AiWorkComplete ( CUnit unit,
CUnit what 
)

Called if AI unit has completed work.

Called if work complete (Buildings).

Parameters:
unit Pointer to unit that builds the building.
what Pointer to unit building that was built.

void CleanAi (  ) 

Init AI for this player.

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

void FreeAi (  ) 

Cleanup the AI module.

Free all AI resources.

void InitAiModule (  ) 

Called each second.

Initialize global structures of the AI

void SaveAi ( CFile file  ) 

Free the AI resources.

Save state of AI to file.

Parameters:
file Output file.

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

Save state of player AI.

Parameters:
file Output file.
plynr Player number.
ai Player AI.

static void SaveAiPlayers ( CFile file  )  [static]

Save state of player AIs.

Parameters:
file Output file.


Variable Documentation

List of all AI types.

AI helper variables.

equivalence between unittypes

std::vector<CAiType *> AiTypes

Ai sleeps # cycles.

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