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

Method checkBuildRoomDefault

source/rooms/RoomManager.cpp:54–110  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

52}
53
54void RoomFactory::checkBuildRoomDefault(GameMap* gameMap, RoomType type, const InputManager& inputManager, InputCommand& inputCommand) const
55{
56 Player* player = gameMap->getLocalPlayer();
57 int32_t pricePerTarget = RoomManager::costPerTile(type);
58 int32_t playerGold = static_cast<int32_t>(player->getSeat()->getGold());
59 if(inputManager.mCommandState == InputCommandState::infoOnly)
60 {
61 if(playerGold < pricePerTarget)
62 {
63 std::string txt = formatBuildRoom(type, pricePerTarget);
64 inputCommand.displayText(Ogre::ColourValue::Red, txt);
65 }
66 else
67 {
68 std::string txt = formatBuildRoom(type, pricePerTarget);
69 inputCommand.displayText(Ogre::ColourValue::White, txt);
70 }
71 inputCommand.selectSquaredTiles(inputManager.mXPos, inputManager.mYPos, inputManager.mXPos,
72 inputManager.mYPos);
73 return;
74 }
75
76 std::vector<Tile*> buildableTiles = gameMap->getBuildableTilesForPlayerInArea(inputManager.mXPos,
77 inputManager.mYPos, inputManager.mLStartDragX, inputManager.mLStartDragY, player);
78
79 if(inputManager.mCommandState == InputCommandState::building)
80 inputCommand.selectTiles(buildableTiles);
81
82 if(buildableTiles.empty())
83 {
84 std::string txt = formatBuildRoom(type, 0);
85 inputCommand.displayText(Ogre::ColourValue::White, txt);
86 return;
87 }
88
89 int32_t priceTotal = static_cast<int32_t>(buildableTiles.size()) * pricePerTarget;
90 if(playerGold < priceTotal)
91 {
92 std::string txt = formatBuildRoom(type, priceTotal);
93 inputCommand.displayText(Ogre::ColourValue::Red, txt);
94 return;
95 }
96
97 std::string txt = formatBuildRoom(type, priceTotal);
98 inputCommand.displayText(Ogre::ColourValue::White, txt);
99
100 if(inputManager.mCommandState != InputCommandState::validated)
101 return;
102
103 ClientNotification *clientNotification = RoomManager::createRoomClientNotification(type);
104 uint32_t nbTiles = buildableTiles.size();
105 clientNotification->mPacket << nbTiles;
106 for(Tile* tile : buildableTiles)
107 gameMap->tileToPacket(clientNotification->mPacket, tile);
108
109 ODClient::getSingleton().queueClientNotification(clientNotification);
110}
111

Callers

nothing calls this directly

Calls 9

getLocalPlayerMethod · 0.80
getGoldMethod · 0.80
tileToPacketMethod · 0.80
getSeatMethod · 0.45
displayTextMethod · 0.45
selectSquaredTilesMethod · 0.45
selectTilesMethod · 0.45

Tested by

no test coverage detected