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

Method buildTrapDefaultEditor

source/traps/TrapManager.cpp:232–277  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

230}
231
232bool TrapFactory::buildTrapDefaultEditor(GameMap* gameMap, Trap* trap, ODPacket& packet) const
233{
234 int32_t seatId;
235 OD_ASSERT_TRUE(packet >> seatId);
236 Seat* seatTrap = gameMap->getSeatById(seatId);
237 if(seatTrap == nullptr)
238 {
239 OD_LOG_ERR("seatId=" + Helper::toString(seatId));
240 return false;
241 }
242
243 std::vector<Tile*> tiles;
244 uint32_t nbTiles;
245 OD_ASSERT_TRUE(packet >> nbTiles);
246
247 while(nbTiles > 0)
248 {
249 --nbTiles;
250 Tile* tile = gameMap->tileFromPacket(packet);
251 if(tile == nullptr)
252 {
253 OD_LOG_ERR("unexpected null tile");
254 return false;
255 }
256
257 // If the tile is not buildable, we change it
258 if(tile->getCoveringBuilding() != nullptr)
259 {
260 OD_LOG_ERR("tile=" + Tile::displayAsString(tile) + ", seatId=" + Helper::toString(seatId));
261 continue;
262 }
263
264 tiles.push_back(tile);
265 if((tile->getType() != TileType::gold) &&
266 (tile->getType() != TileType::dirt))
267 {
268 tile->setType(TileType::dirt);
269 }
270 tile->setFullness(0.0);
271 tile->claimTile(seatTrap);
272 tile->computeTileVisual();
273 }
274
275
276 return buildTrapDefault(gameMap, trap, seatTrap, tiles);
277}
278
279void TrapManager::registerFactory(const TrapFactory* factory)
280{

Callers

nothing calls this directly

Calls 9

getSeatByIdMethod · 0.80
tileFromPacketMethod · 0.80
getCoveringBuildingMethod · 0.80
setTypeMethod · 0.80
setFullnessMethod · 0.80
claimTileMethod · 0.80
computeTileVisualMethod · 0.80
toStringFunction · 0.50
getTypeMethod · 0.45

Tested by

no test coverage detected