|
BWAPI
|
00001 #pragma once 00002 00003 #include "defines.h" 00004 00005 class Environment 00006 { 00007 Player* _player; 00008 00009 TilePositionMap _validPositions; 00010 MapSectorMap _mapSectors; 00011 QuadrantMap _quadrants; 00012 int _quadrantWidth; 00013 int _quadrantHeight; 00014 00015 TaskSet _tasks; 00016 AgentMap _agents; 00017 UnitMemoryMap _unitMemories; 00018 00019 int _reservedMinerals; 00020 int _reservedGas; 00021 int _reservedSupply; 00022 00023 int _requiredMinerals; 00024 int _requiredGas; 00025 int _requiredSupply; 00026 00027 int _requiredWorkers; 00028 int _requiredMineralWorkers; 00029 int _requiredGasWorkers; 00030 00031 UnitTypeCountMap _unitTypeDeaths; 00032 int _totalDeaths; 00033 00034 PlannedBuildingSet _plannedBuildings; 00035 00036 TaskTargetMap _taskTargets; 00037 00038 int _nextTaskId; 00039 00040 bool _hasEconomy; 00041 bool _hasAttackers; 00042 00043 public: 00044 Environment(); 00045 virtual ~Environment(void); 00046 00047 int getNextTaskId(); 00048 00049 Player* getPlayer(); 00050 00051 MapSectorMap* getMapSectors(); 00052 MapSectorSet getMapSectorsInQuadrant(Quadrant* quadrant); 00053 00054 QuadrantMap* getQuadrants(); 00055 Quadrant* getQuadrant(int i, int j); 00056 Quadrant* getQuadrant(TilePosition pos); 00057 Quadrant* getQuadrant(MapSector* sector); 00058 void resetQuadrants(); 00059 00060 void addTask(Task *task); 00061 void removeTask(Task *task); 00062 TaskSet* getTasks(); 00063 00064 void incUnitTypeDeaths(UnitType type); 00065 int getUnitTypeDeaths(UnitType type); 00066 int getTotalDeaths(); 00067 00068 bool containsAgent(Unit *unit); 00069 void addAgent(Unit *unit); 00070 void removeAgent(Unit *unit); 00071 00072 void addUnitMemory(Unit *unit); 00073 void removeUnitMemory(Unit *unit); 00074 UnitMemory* getUnitMemory(Unit *unit); 00075 00076 UnitMemorySet getEnemyMemories(); 00077 00078 AgentMap* getAgents(); 00079 00080 void initialize(); 00081 void refresh(); 00082 00083 void refreshMemoryUnits(); 00084 00085 UnitMemorySet getMemoriesInRadius(Position pos, int radius); 00086 00087 TilePositionMap getValidPositions(); 00088 void generateValidPositions(); 00089 TilePosition getBestPosition(UnitType type, Position idealPos); 00090 TilePosition getBestPosition(TileBox box, Position idealPos, UnitType type = UnitTypes::None); 00091 TilePosition getBestCommandPosition(); 00092 00093 Position getBestOpenSpace(Position idealPos); 00094 00095 //bool areTilesConnected(TilePosition source, TilePosition destination); 00096 00097 void reserveMinerals(int quantity); 00098 void reserveGas(int quantity); 00099 void reserveSupply(int quantity); 00100 00101 int getReservedMinerals(); 00102 int getReservedGas(); 00103 int getReservedSupply(); 00104 00105 void resetReserves(); 00106 00107 void incRequiredMinerals(int quantity); 00108 void incRequiredGas(int quantity); 00109 void incRequiredSupply(int quantity); 00110 00111 void decRequiredMinerals(int quantity); 00112 void decRequiredGas(int quantity); 00113 void decRequiredSupply(int quantity); 00114 00115 int getRequiredMinerals(); 00116 int getRequiredGas(); 00117 int getRequiredSupply(); 00118 00119 int getCurrentMinerals(); 00120 int getCurrentGas(); 00121 int getCurrentSupply(); 00122 int getTotalSupply(); 00123 00124 void purgeTasks(); 00125 void purgeAgents(); 00126 void purgeMapSectors(); 00127 void purgeQuadrants(); 00128 void purgeUnitMemories(); 00129 00130 bool isEnemyUnit(Unit* unit); 00131 00132 void addTaskTarget(Unit* unit, TaskType type); 00133 void removeTaskTargets(Unit* unit); 00134 void removeTaskTarget(Unit* unit, TaskType type); 00135 bool isTaskTarget(Unit* unit, TaskType type); 00136 00137 TaskSet getFilteredTasks(TaskType type); 00138 TaskSet getFilteredTasks(TaskType type, int maxCreationFrame); 00139 TaskSet getFilteredTasksByPriority(TaskType type, double priority); 00140 00141 AgentMap getFilteredAgents(AgentType type, bool finished = true); 00142 AgentMap getFilteredAgents(UnitType type, bool finished = true); 00143 AgentMap getFilteredAgents(TaskType type, bool finished = true); 00144 00145 Agent* getClosestAgent(AgentType type, Position pos); 00146 Agent* getClosestAgent(UnitType type, Position pos); 00147 Agent* getClosestAgent(TaskType type, Position pos); 00148 00149 AgentSet getAgentsInRadius(Position pos, int radius); 00150 00151 void addPlannedBuilding(BuildingSpaceInfo* pBuilding); 00152 void removePlannedBuilding(BuildingSpaceInfo* pBuilding); 00153 PlannedBuildingSet* getPlannedBuildings(); 00154 00155 void incRequiredWorkers(int count); 00156 void decRequiredWorkers(int count); 00157 int getRequiredWorkers(); 00158 int calculateNeededExtraWorkers(); 00159 00160 void incRequiredMineralWorkers(int count); 00161 void decRequiredMineralWorkers(int count); 00162 int getRequiredMineralWorkers(); 00163 00164 void incRequiredGasWorkers(int count); 00165 void decRequiredGasWorkers(int count); 00166 int getRequiredGasWorkers(); 00167 00168 bool hasEconomy(); 00169 bool hasAttackers(); 00170 00171 UnitSet getThreatenedUnits(Unit* enemyUnit); 00172 00173 static bool isUnitCombatValuable(Unit* unit); 00174 static double getUnitCombatValue(Unit* unit); 00175 static double getUnitAirAttackValue(UnitType type); 00176 static double getUnitGroundAttackValue(UnitType type); 00177 static double getUnitTypeValue(UnitType type); 00178 static double getUnitHealthValue(Unit* unit); 00179 static double getUnitHealthValue(UnitMemory* memory); 00180 }; 00181 00182 struct Quadrant 00183 { 00184 Quadrant(TilePosition c) : visited(false), dangerous(false), beingExplored(false), center(c) {} 00185 00186 bool visited; 00187 bool dangerous; 00188 bool beingExplored; 00189 TilePosition center; 00190 }; 00191 00192 struct BuildingSpaceInfo 00193 { 00194 BuildingSpaceInfo(TilePosition p, UnitType t) : tilePosition(p), type(t) {} 00195 00196 TilePosition tilePosition; 00197 UnitType type; 00198 }; 00199 00200 struct TileBox 00201 { 00202 TileBox(UnitType type); 00203 TileBox(int width, int height); 00204 00205 int tileWidth; 00206 int tileHeight; 00207 }; 00208 00209 struct UnitMemory 00210 { 00211 UnitMemory(Unit* u); 00212 00213 bool refresh(); 00214 00215 Unit* unit; 00216 UnitType type; 00217 int knownHitPoints; 00218 int knownShields; 00219 int knownResources; 00220 bool wasLifted; 00221 bool wasDetected; 00222 Position knownPosition; 00223 MapSector* knownSector; 00224 Player* knownPlayer; 00225 bool wasEnemy; 00226 }; 00227
1.7.6.1