____ _ __
/ __ )____ _____ | | / /___ ___________
/ __ / __ \/ ___/ | | /| / / __ `/ ___/ ___/
/ /_/ / /_/ (__ ) | |/ |/ / /_/ / / (__ )
/_____/\____/____/ |__/|__/\__,_/_/ /____/
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 "unit.h"
#include "unit_cache.h"
#include "unittype.h"
#include "upgrade.h"
#include "map.h"
#include "pathfinder.h"
#include "ai_local.h"
#include "actions.h"
#include "player.h"
Go to the source code of this file.
Defines | |
| #define | COLLECT_RESOURCES_INTERVAL 4 |
Functions | |
| static int | AiCheckCosts (const int *costs) |
| static int | AiCheckUnitTypeCosts (const CUnitType *type) |
| int | AiEnemyUnitsInDistance (const CPlayer *player, const CUnitType *type, int x, int y, unsigned range) |
| int | AiEnemyUnitsInDistance (const CUnit *unit, unsigned range) |
| static int | AiBuildBuilding (const CUnitType *type, CUnitType *building) |
| static int | AiTrainUnit (const CUnitType *type, CUnitType *what) |
| int | AiCountUnitBuilders (CUnitType *type) |
| static int | AiMakeUnit (CUnitType *type) |
| static void | AiCheckingWork (void) |
| static int | AiAssignHarvester (CUnit *unit, int resource) |
| static void | AiCollectResources (void) |
| static int | AiRepairBuilding (const CUnitType *type, CUnit *building) |
| static int | AiRepairUnit (CUnit *unit) |
| static void | AiCheckRepair (void) |
| void | AiAddUnitTypeRequest (CUnitType *type, int count) |
| < Add unit-type request to resource manager | |
| void | AiExplore (int x, int y, int mask) |
| Make two unittypes be considered equals. | |
| void | AiResourceManager (void) |
| Ask the ai to explore around x,y. | |
Definition in file ai_resource.cpp.
| #define COLLECT_RESOURCES_INTERVAL 4 |
| void AiAddUnitTypeRequest | ( | CUnitType * | type, | |
| int | count | |||
| ) |
< Add unit-type request to resource manager
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().
| static int AiAssignHarvester | ( | CUnit * | unit, | |
| int | resource | |||
| ) | [static] |
Assign worker to gather a resource.
| unit | Unit to be assigned. | |
| resource | Resource to find, -1 for any |
Definition at line 439 of file ai_resource.cpp.
References AiExplore(), Assert, CommandResource(), FlushCommands, MapFieldAirUnit, MapFieldLandUnit, MapFieldSeaUnit, MaxCosts, CUnit::Player, CPlayer::ProductionRate, CUnit::Removed, CPlayer::StoredResources, UnitFindResource(), UnitTypeFly, UnitTypeLand, UnitTypeNaval, UnitTypes, CUnit::X, and CUnit::Y.
Referenced by AiCollectResources().
Check if we can build the building.
| type | Unit that can build the building. | |
| building | Building to be build. |
Definition at line 171 of file ai_resource.cpp.
References AiFindBuildingPlace(), AiPlayer, CommandBuildBuilding(), FindPlayerUnitsByType(), FlushCommands, CUnit::OrderCount, CUnit::Orders, PlayerAi::Player, SyncRand(), UnitActionBuild, UnitActionRepair, UnitMax, and y.
Referenced by AiMakeUnit().
| static int AiCheckCosts | ( | const int * | costs | ) | [static] |
Check if the costs are available for the AI.
Take reserve and already used resources into account.
| costs | Costs for something. |
Definition at line 69 of file ai_resource.cpp.
References AiPlayer, MaxCosts, PlayerAi::Player, CPlayer::ProductionRate, and CPlayer::StoredResources.
Referenced by AiCheckUnitTypeCosts().
| static void AiCheckingWork | ( | void | ) | [static] |
Check what must be built / trained.
Definition at line 376 of file ai_resource.cpp.
References AiCheckUnitTypeCosts(), AiMakeUnit(), AiPlayer, CUnitType::Building, CPlayer::CheckLimits(), GameCycle, AiBuildQueue::Made, PlayerAi::NeededMask, PlayerAi::Player, AiBuildQueue::Type, PlayerAi::UnitTypeBuilt, AiBuildQueue::Wait, and AiBuildQueue::Want.
Referenced by AiResourceManager().
| static void AiCheckRepair | ( | void | ) | [static] |
Check if there's a unit that should be repaired.
Definition at line 720 of file ai_resource.cpp.
References COrder::Action, AiEnemyUnitsInDistance(), AiPlayer, AiRepairUnit(), CUnit::Attacked, CYCLES_PER_SECOND, GameCycle, COrder::Goal, HP_INDEX, PlayerAi::LastRepairBuilding, CVariable::Max, MaxCosts, CUnit::Orders, PlayerAi::Player, CUnitType::ProductionCosts, CPlayer::ProductionRate, CUnitType::RepairHP, SIGHTRANGE_INDEX, CUnit::Stats, CPlayer::StoredResources, CPlayer::TotalNumUnits, CUnit::Type, UnitActionBuilt, UnitActionRepair, UnitNumber, CPlayer::Units, CVariable::Value, CUnit::Variable, and CUnitStats::Variables.
Referenced by AiResourceManager().
| static int AiCheckUnitTypeCosts | ( | const CUnitType * | type | ) | [static] |
Check if the costs for a unit-type are available for the AI.
Take reserve and already used resources into account.
| type | Unit-type to check the costs for. |
Definition at line 92 of file ai_resource.cpp.
References AiCheckCosts(), and CUnitType::ProductionCosts.
Referenced by AiCheckingWork().
| static void AiCollectResources | ( | void | ) | [static] |
Assign workers to collect resources.
Definition at line 503 of file ai_resource.cpp.
References AiAssignHarvester(), AiPlayer, CUnitType::Harvester, int(), PlayerAi::NeededMask, PlayerAi::Player, SyncRand(), CPlayer::TotalNumUnits, CUnit::Type, UnitActionResource, and CPlayer::Units.
Referenced by AiResourceManager().
| int AiCountUnitBuilders | ( | CUnitType * | type | ) |
Return the number of unit which can produce the given unittype.
| type | The unittype we wan't to build |
Definition at line 259 of file ai_resource.cpp.
References _C_, AiHelpers, AiPlayer, AiHelper::Build, CUnitType::Building, DebugPrint, CUnitType::Ident, int(), PlayerAi::Player, CUnitType::Slot, AiHelper::Train, UnitIdAllowed(), and CPlayer::UnitTypesCount.
| int AiEnemyUnitsInDistance | ( | const CUnit * | unit, | |
| unsigned | range | |||
| ) |
Enemy units in distance.
| unit | Find in distance for this unit. | |
| range | Distance range to look. |
Definition at line 155 of file ai_resource.cpp.
References AiEnemyUnitsInDistance(), CUnit::Player, CUnitType::TileHeight, CUnitType::TileWidth, CUnit::Type, CUnit::X, and CUnit::Y.
| 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().
| static int AiMakeUnit | ( | CUnitType * | type | ) | [static] |
Check if we can make a unit-type.
| type | Unit-type that must be made. |
Definition at line 312 of file ai_resource.cpp.
References _C_, AiBuildBuilding(), AiFindAvailableUnitTypeEquiv(), AiHelpers, AiPlayer, AiTrainUnit(), AiHelper::Build, CUnitType::Building, DebugPrint, CUnitType::Ident, int(), PlayerAi::Player, CUnitType::Slot, AiHelper::Train, UnitTypeMax, UnitTypes, and CPlayer::UnitTypesCount.
Referenced by AiCheckingWork().
Check if we can repair the building.
| type | Unit that can repair the building. | |
| building | Building to be repaired. |
Definition at line 580 of file ai_resource.cpp.
References AiPlayer, CommandRepair(), FindPlayerUnitsByType(), FlushCommands, NoUnitP, CUnit::OrderCount, CUnit::Orders, PlayerAi::Player, CUnitType::RepairRange, PlayerAi::TriedRepairWorkers, CUnit::Type, UnitActionResource, UnitActionStill, UnitMax, UnitNumber, UnitReachable(), CUnit::X, and CUnit::Y.
Referenced by AiRepairUnit().
| static int AiRepairUnit | ( | CUnit * | unit | ) | [static] |
Check if we can repair this unit.
| unit | Unit that must be repaired. |
Definition at line 680 of file ai_resource.cpp.
References _C_, AiHelpers, AiPlayer, AiRepairBuilding(), DebugPrint, CUnitType::Ident, int(), PlayerAi::Player, AiHelper::Repair, CUnitType::Slot, CUnit::Type, and CPlayer::UnitTypesCount.
Referenced by AiCheckRepair().
| 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().
Check if we can train the unit.
| type | Unit that can train the unit. | |
| what | What to be trained. |
Definition at line 224 of file ai_resource.cpp.
References AiPlayer, CommandTrainUnit(), FindPlayerUnitsByType(), FlushCommands, CUnit::IsIdle(), PlayerAi::Player, and UnitMax.
Referenced by AiMakeUnit().
1.5.6