____ _ __
/ __ )____ _____ | | / /___ ___________
/ __ / __ \/ ___/ | | /| / / __ `/ ___/ ___/
/ /_/ / /_/ (__ ) | |/ |/ / /_/ / / (__ )
/_____/\____/____/ |__/|__/\__,_/_/ /____/
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 <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 | |
| PlayerAi * | AiPlayer |
| Current AI player. | |
Definition in file ai_local.h.
| #define AI_MAX_ATTACKING_FORCES 30 |
Attacking forces.
Definition at line 201 of file ai_local.h.
Referenced by AiAssignFreeUnitsToForce(), AiAttackWithForce(), AiCheckUnits(), AiCleanForces(), AiForceManager(), AiHelpMe(), and SaveAiPlayer().
| #define AI_MAX_FORCES 10 |
How many forces are supported.
Definition at line 200 of file ai_local.h.
Referenced by AiAssignToForce(), AiAttackWithForce(), AiCheckUnits(), CclAiAttackWithForce(), CclAiCheckForce(), CclAiDump(), CclAiForce(), CclAiForceRole(), and CclAiWaitForce().
| enum AiForceRole |
Roles for forces
Definition at line 95 of file ai_local.h.
| 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.
| type | Unit type requested. | |
| count | How many units. |
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.
| 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 | ) |
Periodic called force manager handler.
Attack opponent with force.
| force | Force number to attack with. |
Definition at line 403 of file ai_force.cpp.
References AI_MAX_ATTACKING_FORCES, AI_MAX_FORCES, AiCleanForce(), AiPlanAttack(), AiPlayer, AiForce::Attacking, AttackUnitsInDistance(), CUnitType::CanAttack, CommandAttack(), CommandMove(), DebugPrint, FlushCommands, PlayerAi::Force, int(), MaxMapWidth, AiForce::Reset(), AiForce::State, CUnit::Type, AiForce::Units, CUnit::Wait, CUnit::X, CUnit::Y, and y.
Referenced by CclAiAttackWithForce().
| void AiAttackWithForceAt | ( | int | force, | |
| int | x, | |||
| int | y | |||
| ) |
Attack with force.
Attack at position with force.
| 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.
| 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. |
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.
| 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... )
| unittype | The unittype to find equivalence for | |
| usableTypes | int array which will hold the result. (Size UnitTypeMax+1) |
Definition at line 137 of file ai_force.cpp.
References AiFindUnitTypeEquiv(), AiPlayer, CPlayer::Index, PlayerAi::Player, and UnitTypes.
Referenced by AiMakeUnit().
< Find nice building place
Find free building place.
| worker | Worker to build building. | |
| type | Type of building. | |
| dx | Pointer for X position returned. | |
| dy | Pointer for Y position returned. |
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
| unittype | the unittype to find equivalence for | |
| result | int array which will hold the result. (Size UnitTypeMax+1) |
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.
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().
Remove any equivalence between unittypes.
Make two unittypes equivalents from the AI's point of vue
| 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.
| force | Pointer on the force. |
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 | ) |
Enemy units in distance.
Respond to ExplorationRequests
Definition at line 464 of file ai_plan.cpp.
References AiPlayer, CanMove(), CommandMove(), PlayerAi::FirstExplorationRequest, FlushCommands, GameCycle, CMap::Info, CMap::IsFieldExplored(), PlayerAi::LastExplorationGameCycle, Map, MapFieldLandUnit, MapFieldSeaUnit, CMapInfo::MapHeight, CMapInfo::MapWidth, AiExplorationRequest::Mask, PlayerAi::Player, SyncRand(), CPlayer::TotalNumUnits, CUnit::Type, CPlayer::Units, CUnitType::UnitType, UnitTypeFly, UnitTypeLand, UnitTypeNaval, AiExplorationRequest::X, AiExplorationRequest::Y, and y.
Referenced by AiEachSecond().
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().
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().
1.5.6