| 114 | } |
| 115 | |
| 116 | bool 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 | } |
nothing calls this directly
no test coverage detected