MCPcopy Create free account
hub / github.com/OpenDungeons/OpenDungeons / checkTreasury

Method checkTreasury

source/ai/KeeperAI.cpp:116–282  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

114}
115
116bool KeeperAI::checkTreasury()
117{
118 // If the treasury gets destroyed, we don't want the AI to build each turn the
119 // free treasury
120 if(mCooldownCheckTreasury > 0)
121 {
122 --mCooldownCheckTreasury;
123 return false;
124 }
125 mCooldownCheckTreasury = Random::Int(10,30);
126
127 int totalGold = 0;
128 int totalStorage = 0;
129 for(Room* room : mGameMap.getRooms())
130 {
131 if(room->getSeat() != mPlayer.getSeat())
132 continue;
133
134 totalGold += room->getTotalGoldStored();
135 totalStorage += room->getTotalGoldStorage();
136 }
137
138 // We want at least to be allowed to store 3000 gold
139 if(totalStorage >= 3000)
140 return false;
141
142 // The treasury is too small, we try to increase it
143 // A treasury can be built if we have none (in this case, it is free). Otherwise,
144 // we check if we have enough gold
145 if((totalStorage > 0) && (totalGold < RoomManager::costPerTile(RoomType::treasury)))
146 return false;
147
148 Tile* central = getDungeonTemple()->getCentralTile();
149
150 Creature* worker = mGameMap.getWorkerForPathFinding(mPlayer.getSeat());
151 if (worker == nullptr)
152 return false;
153
154 // We try in priority to gold next to an existing treasury
155 std::vector<Room*> treasuriesOwned = mGameMap.getRoomsByTypeAndSeat(RoomType::treasury, mPlayer.getSeat());
156 for(Room* treasury : treasuriesOwned)
157 {
158 for(Tile* tile : treasury->getCoveredTiles())
159 {
160 for(Tile* neigh : tile->getAllNeighbors())
161 {
162 if(neigh->isBuildableUpon(mPlayer.getSeat()) &&
163 mGameMap.pathExists(worker, central, neigh))
164 {
165 std::vector<Tile*> tiles;
166 tiles.push_back(neigh);
167
168 if(!RoomManager::buildRoomOnTiles(&mGameMap, RoomType::treasury, &mPlayer, tiles))
169 return false;
170
171 return true;
172 }
173 }

Callers

nothing calls this directly

Calls 15

IntFunction · 0.85
getCentralTileMethod · 0.80
getRoomsByTypeAndSeatMethod · 0.80
isBuildableUponMethod · 0.80
pathExistsMethod · 0.80
getMapSizeXMethod · 0.80
getMapSizeYMethod · 0.80
getSeatMethod · 0.45
getTotalGoldStoredMethod · 0.45
getTotalGoldStorageMethod · 0.45
getCoveredTilesMethod · 0.45

Tested by

no test coverage detected