____ _ __
/ __ )____ _____ | | / /___ ___________
/ __ / __ \/ ___/ | | /| / / __ `/ ___/ ___/
/ /_/ / /_/ (__ ) | |/ |/ / /_/ / / (__ )
/_____/\____/____/ |__/|__/\__,_/_/ /____/
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"
#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_local.h"
#include "iolib.h"
Go to the source code of this file.
Functions | |
| static void | AiExecuteScript (void) |
| static void | AiCheckUnits (void) |
| static void | SaveAiPlayer (CFile *file, int plynr, PlayerAi *ai) |
| static void | SaveAiPlayers (CFile *file) |
| void | SaveAi (CFile *file) |
| Save the AI state. | |
| void | AiInit (CPlayer *player) |
| Init AI for this player. | |
| void | InitAiModule (void) |
| Init AI global structures. | |
| void | CleanAi (void) |
| Cleanup the AI module. | |
| void | FreeAi () |
| Free the AI resources. | |
| 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 needs more farms. | |
| void | AiWorkComplete (CUnit *unit, CUnit *what) |
| Called if AI unit can't build. | |
| void | AiCanNotBuild (CUnit *unit, const CUnitType *what) |
| Called if AI unit can't reach building place. | |
| void | AiCanNotReach (CUnit *unit, const CUnitType *what) |
| Called if an AI unit can't move. | |
| static void | AiMoveUnitInTheWay (CUnit *unit) |
| void | AiCanNotMove (CUnit *unit) |
| Called if AI unit has completed training. | |
| void | AiNeedMoreSupply (const CUnit *unit, const CUnitType *what) |
| Called if AI unit has completed work. | |
| void | AiTrainingComplete (CUnit *unit, CUnit *what) |
| void | AiEachCycle (CPlayer *player) |
| Called each game cycle. | |
| void | AiEachSecond (CPlayer *player) |
| Called each second. | |
Variables | |
| int | AiSleepCycles |
| Ai sleeps # cycles. | |
| std::vector< CAiType * > | AiTypes |
| List of all AI types. | |
| AiHelper | AiHelpers |
| AI helper variables. | |
| PlayerAi * | AiPlayer |
| Current AI player. | |
Definition in file ai.cpp.
Called if AI unit can't reach building place.
Called if building can't be build.
| unit | Pointer to unit what builds the building. | |
| what | Pointer to unit-type. |
Definition at line 769 of file ai.cpp.
References _C_, CPlayer::Ai, AiReduceMadeInBuilt(), Assert, DebugPrint, CUnitType::Ident, CPlayer::Index, CUnit::Player, PlayerPerson, CPlayer::Type, CUnit::Type, UnitNumber, CUnit::X, and CUnit::Y.
Referenced by CheckCanBuild(), and StartBuilding().
| void AiCanNotMove | ( | CUnit * | unit | ) |
Called if AI unit has completed training.
Called if a unit can't move. Try to move unit in the way
| unit | Pointer to unit what builds the building. |
Definition at line 924 of file ai.cpp.
References CPlayer::Ai, AiMoveUnitInTheWay(), CUnit::Orders, PlaceReachable(), CUnit::Player, CUnit::Type, CUnitType::UnitType, and UnitTypeFly.
Referenced by DoActionMove().
Called if an AI unit can't move.
Called if building place can't be reached.
| unit | Pointer to unit what builds the building. | |
| what | Pointer to unit-type. |
Definition at line 785 of file ai.cpp.
References CPlayer::Ai, AiReduceMadeInBuilt(), Assert, CUnit::Player, PlayerPerson, and CPlayer::Type.
Referenced by MoveToLocation().
| static void AiCheckUnits | ( | void | ) | [static] |
Check if everything is fine, send new requests to resource manager.
Definition at line 181 of file ai.cpp.
References AI_MAX_ATTACKING_FORCES, AI_MAX_FORCES, AiAddUnitTypeRequest(), AiForce::Attacking, AiForce::Completed, AiForce::Defending, AiHelper::Equiv, PlayerAi::Force, int(), PlayerAi::Player, CUnitType::Slot, AiUnitType::Type, AiBuildQueue::Type, AiForce::Units, PlayerAi::UnitTypeBuilt, UnitTypeMax, PlayerAi::UnitTypeRequests, AiForce::UnitTypes, CPlayer::UnitTypesCount, AiUnitType::Want, and AiBuildQueue::Want.
Referenced by AiEachSecond().
| void AiEachCycle | ( | CPlayer * | player | ) |
Called each game cycle.
This is called for each player, each game cycle.
| player | The player structure pointer. |
Definition at line 996 of file ai.cpp.
References CPlayer::Ai, COrder::Goal, int(), AiTransportRequest::Order, CUnit::RefsDecrease(), PlayerAi::TransportRequests, and AiTransportRequest::Unit.
Referenced by PlayersEachCycle().
| void AiEachSecond | ( | CPlayer * | player | ) |
Called each second.
This is called for each player each second.
| player | The player structure pointer. |
Definition at line 1015 of file ai.cpp.
References CPlayer::Ai, AiCheckMagic(), AiCheckUnits(), AiExecuteScript(), AiForceManager(), AiResourceManager(), AiSendExplorers(), CYCLES_PER_SECOND, GameCycle, and PlayerAi::LastExplorationGameCycle.
Referenced by PlayersEachSecond().
| static void AiExecuteScript | ( | void | ) | [static] |
Execute the AI Script.
Definition at line 166 of file ai.cpp.
References Lua, LuaCall(), and PlayerAi::Script.
Referenced by AiEachSecond().
< Called if AI unit is attacked
Called if a Unit is Attacked
| attacker | Pointer to attacker unit. | |
| defender | Pointer to unit that is being attacked. |
Definition at line 646 of file ai.cpp.
References _C_, CPlayer::Ai, AI_MAX_ATTACKING_FORCES, AiAttackWithForceAt(), AiForce::Attacking, CUnitType::CanAttack, DebugPrint, AiForce::Defending, PlayerAi::Force, CUnitType::Ident, CPlayer::Index, int(), CUnit::Player, CUnit::Type, UnitNumber, AiForce::Units, CUnitType::UnitType, UnitTypeFly, CUnit::X, and CUnit::Y.
Referenced by HitUnit().
| void AiInit | ( | CPlayer * | player | ) |
Init AI for this player.
Setup all at start.
| player | The player structure pointer. |
Definition at line 423 of file ai.cpp.
References _C_, CPlayer::Ai, CPlayer::AiName, PlayerAi::AiType, AiTypes, CAiType::Class, DebugPrint, Exit(), CPlayer::Index, int(), PlayerAi::Player, CAiType::Script, and PlayerAi::Script.
Referenced by HandleCheats(), and PlayersInitAi().
| static void AiMoveUnitInTheWay | ( | CUnit * | unit | ) | [static] |
Try to move a unit that's in the way
Definition at line 794 of file ai.cpp.
References CPlayer::Ai, CPlayer::Allied, CanMove(), CommandMove(), FlushCommands, GameCycle, CPlayer::Index, CMap::Info, CUnit::IsIdle(), CUnit::IsUnusable(), PlayerAi::LastCanNotMoveGameCycle, Map, CMapInfo::MapHeight, CMapInfo::MapWidth, NumUnits, CUnit::Player, SyncRand(), CUnitType::TileHeight, CUnitType::TileWidth, CUnit::Type, Units, CUnitType::UnitType, CUnit::X, CUnit::Y, and y.
Referenced by AiCanNotMove().
Called if AI unit has completed work.
Called if the AI needs more farms.
| unit | Point to unit. | |
| what | Pointer to unit-type. |
Definition at line 964 of file ai.cpp.
References CPlayer::Ai, Assert, PlayerAi::NeedSupply, CUnit::Player, PlayerPerson, and CPlayer::Type.
Referenced by HandleActionTrain().
Reduce made unit-type from build list.
| pai | Computer AI player. | |
| type | Unit-type which is now available. |
Definition at line 614 of file ai.cpp.
References AiFindUnitTypeEquiv(), AiReduceMadeInBuilt2(), Assert, AiHelper::Equiv, int(), CUnitType::Slot, UnitTypeMax, and UnitTypes.
Referenced by AiCanNotBuild(), AiCanNotReach(), and AiUnitKilled().
Reduce made unit-type from build list.
| pai | Computer AI player. | |
| type | Unit-type which is now available. |
Definition at line 595 of file ai.cpp.
References PlayerAi::UnitTypeBuilt.
Referenced by AiReduceMadeInBuilt().
Remove unit-type from build list.
| pai | Computer AI player. | |
| type | Unit-type which is now available. |
Definition at line 560 of file ai.cpp.
References AiFindUnitTypeEquiv(), AiRemoveFromBuilt2(), Assert, DebugPrint, PlayerAi::Player, ThisPlayer, UnitTypeMax, and UnitTypes.
Referenced by AiTrainingComplete(), and AiWorkComplete().
Remove unit-type from build list.
| pai | Computer AI player. | |
| type | Unit-type which is now available. |
Definition at line 537 of file ai.cpp.
References Assert, and PlayerAi::UnitTypeBuilt.
Referenced by AiRemoveFromBuilt().
Called if training of a unit is completed.
| unit | Pointer to unit making. | |
| what | Pointer to new ready trained unit. |
Definition at line 976 of file ai.cpp.
References _C_, CPlayer::Ai, AiAssignToForce(), AiCleanForces(), AiRemoveFromBuilt(), Assert, DebugPrint, CUnitType::Ident, CPlayer::Index, CUnit::Player, PlayerPerson, CPlayer::Type, CUnit::Type, UnitNumber, CUnit::X, and CUnit::Y.
Referenced by HandleActionTrain().
| void AiUnitKilled | ( | CUnit * | unit | ) |
Called if AI needs more farms.
Called if a unit is killed.
| unit | Pointer to unit. |
Definition at line 708 of file ai.cpp.
References _C_, CPlayer::Ai, AiReduceMadeInBuilt(), Assert, DebugPrint, CUnitType::Ident, CPlayer::Index, CUnit::Orders, CUnit::Player, PlayerPerson, CPlayer::Type, CUnit::Type, UnitActionAttack, UnitActionBuild, UnitActionBuilt, UnitActionMove, UnitActionStill, and UnitNumber.
Referenced by UnitLost().
Called if AI unit can't build.
Called if work complete (Buildings).
| unit | Pointer to unit that builds the building. | |
| what | Pointer to unit building that was built. |
Definition at line 748 of file ai.cpp.
References _C_, CPlayer::Ai, AiRemoveFromBuilt(), Assert, DebugPrint, CUnitType::Ident, CPlayer::Index, CUnit::Player, PlayerPerson, CPlayer::Type, CUnit::Type, UnitNumber, CUnit::X, and CUnit::Y.
Referenced by HandleActionBuilt().
| void CleanAi | ( | void | ) |
Cleanup the AI module.
Cleanup the AI in order to enable to restart a game.
Definition at line 486 of file ai.cpp.
References CPlayer::Ai, PlayerMax, and Players.
Referenced by CleanGame(), and FreeAi().
| void FreeAi | ( | void | ) |
Free the AI resources.
Free all AI resources.
Definition at line 500 of file ai.cpp.
References AiResetUnitTypeEquiv(), AiTypes, AiHelper::Build, CleanAi(), AiHelper::Equiv, int(), AiHelper::Repair, AiHelper::Train, and AiHelper::UnitLimit.
Referenced by CleanModules().
| void InitAiModule | ( | void | ) |
Init AI global structures.
Initialize global structures of the AI
Definition at line 477 of file ai.cpp.
References AiResetUnitTypeEquiv().
Referenced by InitModules(), and main().
| void SaveAi | ( | CFile * | file | ) |
Save the AI state.
Save state of AI to file.
| file | Output file. |
Definition at line 409 of file ai.cpp.
References DebugPrint, CFile::printf(), and SaveAiPlayers().
Referenced by SaveGame().
Save state of player AI.
| file | Output file. | |
| plynr | Player number. | |
| ai | Player AI. |
Definition at line 271 of file ai.cpp.
References AI_MAX_ATTACKING_FORCES, AiForceRoleAttack, AiForceRoleDefend, PlayerAi::AiType, AiForce::Attacking, AiForce::Completed, DefaultResourceNames, AiForce::Defending, PlayerAi::FirstExplorationRequest, PlayerAi::Force, AiForce::GoalX, AiForce::GoalY, CUnitType::Ident, int(), PlayerAi::LastCanNotMoveGameCycle, PlayerAi::LastExplorationGameCycle, PlayerAi::LastRepairBuilding, AiBuildQueue::Made, AiExplorationRequest::Mask, MaxCosts, AiForce::MustTransport, CAiType::Name, PlayerAi::Needed, PlayerAi::NeededMask, PlayerAi::NeedSupply, AiTransportRequest::Order, CFile::printf(), AiForce::Role, SaveOrder(), PlayerAi::Script, PlayerAi::ScriptDebug, PlayerAi::SleepCycles, AiForce::State, PlayerAi::TransportRequests, PlayerAi::TriedRepairWorkers, AiBuildQueue::Type, CUnit::Type, AiUnitType::Type, AiTransportRequest::Unit, UnitMax, UnitNumber, AiForce::Units, PlayerAi::UnitTypeBuilt, PlayerAi::UnitTypeRequests, AiForce::UnitTypes, AiBuildQueue::Want, AiUnitType::Want, AiExplorationRequest::X, and AiExplorationRequest::Y.
Referenced by SaveAiPlayers().
| static void SaveAiPlayers | ( | CFile * | file | ) | [static] |
AI helper variables.
Definition at line 155 of file ai.cpp.
Referenced by AiCountUnitBuilders(), AiMakeUnit(), AiRepairUnit(), CclAiWait(), and CclDefineAiHelper().
Current AI player.
Definition at line 157 of file ai.cpp.
Referenced by AiAddUnitTypeRequest(), AiAssignFreeUnitsToForce(), AiAssignToForce(), AiAttackWithForce(), AiAttackWithForceAt(), AiBuildBuilding(), AiCheckBelongsToForce(), AiCheckCosts(), AiCheckingWork(), AiCheckMagic(), AiCheckRepair(), AiCleanForce(), AiCollectResources(), AiCountUnitBuilders(), AiExplore(), AiFindAvailableUnitTypeEquiv(), AiForceManager(), AiMakeUnit(), AiPlanAttack(), AiRepairBuilding(), AiRepairUnit(), AiResourceManager(), AiSendExplorers(), AiTrainUnit(), CclAiCheckForce(), CclAiDebug(), CclAiDump(), CclAiForce(), CclAiForceRole(), CclAiPlayer(), CclAiSleep(), CclAiWait(), CclAiWaitForce(), FindInUnitTypeRequests(), and InsertUnitTypeRequests().
| int AiSleepCycles |
Ai sleeps # cycles.
Definition at line 152 of file ai.cpp.
Referenced by CclAiGetSleepCycles(), and main().
List of all AI types.
Definition at line 154 of file ai.cpp.
Referenced by AiInit(), CclDefineAi(), CclDefineAiPlayer(), and FreeAi().
1.5.6