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

Method checkBuildTrap

source/traps/TrapDoor.cpp:65–129  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

63 }
64
65 virtual void checkBuildTrap(GameMap* gameMap, const InputManager& inputManager, InputCommand& inputCommand) const
66 {
67 Player* player = gameMap->getLocalPlayer();
68 TrapType type = TrapType::doorWooden;
69 // We only allow 1 tile for door trap
70 Tile* tile = gameMap->getTile(inputManager.mXPos, inputManager.mYPos);
71 if(tile == nullptr)
72 {
73 inputCommand.unselectAllTiles();
74 return;
75 }
76
77 int32_t pricePerTarget = TrapManager::costPerTile(type);
78 int32_t playerGold = static_cast<int32_t>(player->getSeat()->getGold());
79 if(inputManager.mCommandState == InputCommandState::infoOnly)
80 {
81 if(playerGold < pricePerTarget)
82 {
83 std::string txt = formatBuildTrap(type, pricePerTarget);
84 inputCommand.displayText(Ogre::ColourValue::Red, txt);
85 }
86 else
87 {
88 std::string txt = formatBuildTrap(type, pricePerTarget);
89 inputCommand.displayText(Ogre::ColourValue::White, txt);
90 }
91 inputCommand.selectSquaredTiles(inputManager.mXPos, inputManager.mYPos, inputManager.mXPos,
92 inputManager.mYPos);
93 return;
94 }
95
96 if(inputManager.mCommandState == InputCommandState::building)
97 {
98 std::vector<Tile*> tiles;
99 tiles.push_back(tile);
100 inputCommand.selectTiles(tiles);
101 if(!tile->isBuildableUpon(player->getSeat()) ||
102 !TrapDoor::canDoorBeOnTile(gameMap, tile))
103 {
104 inputCommand.displayText(Ogre::ColourValue::Red, "Cannot place door on this tile");
105 }
106 else if(playerGold < pricePerTarget)
107 {
108 std::string txt = formatBuildTrap(type, pricePerTarget);
109 inputCommand.displayText(Ogre::ColourValue::Red, txt);
110 }
111 else
112 {
113 std::string txt = formatBuildTrap(type, pricePerTarget);
114 inputCommand.displayText(Ogre::ColourValue::White, txt);
115 }
116 return;
117 }
118
119 if(!tile->isBuildableUpon(player->getSeat()) ||
120 !TrapDoor::canDoorBeOnTile(gameMap, tile))
121 {
122 return;

Callers

nothing calls this directly

Calls 11

getLocalPlayerMethod · 0.80
getGoldMethod · 0.80
isBuildableUponMethod · 0.80
tileToPacketMethod · 0.80
getTileMethod · 0.45
unselectAllTilesMethod · 0.45
getSeatMethod · 0.45
displayTextMethod · 0.45
selectSquaredTilesMethod · 0.45
selectTilesMethod · 0.45

Tested by

no test coverage detected