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

Method shoot

source/traps/TrapBoulder.cpp:124–165  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

122}
123
124bool TrapBoulder::shoot(Tile* tile)
125{
126 std::vector<Tile*> tiles = tile->getAllNeighbors();
127 for(std::vector<Tile*>::iterator it = tiles.begin(); it != tiles.end();)
128 {
129 Tile* tmpTile = *it;
130 std::vector<Tile*> vecTile;
131 vecTile.push_back(tmpTile);
132
133 if(getGameMap()->getVisibleCreatures(vecTile, getSeat(), true).empty())
134 it = tiles.erase(it);
135 else
136 ++it;
137 }
138 if(tiles.empty())
139 return false;
140
141 // We take a random tile and launch boulder it
142 Tile* tileChosen = tiles[Random::Uint(0, tiles.size() - 1)];
143 // We launch the boulder
144 Ogre::Vector3 direction(static_cast<Ogre::Real>(tileChosen->getX() - tile->getX()),
145 static_cast<Ogre::Real>(tileChosen->getY() - tile->getY()),
146 0);
147 Ogre::Vector3 position;
148 position.x = static_cast<Ogre::Real>(tile->getX());
149 position.y = static_cast<Ogre::Real>(tile->getY());
150 position.z = 0;
151 direction.normalise();
152 MissileBoulder* missile = new MissileBoulder(getGameMap(), getSeat(), getName(), "Boulder",
153 direction, ConfigManager::getSingleton().getTrapConfigDouble("BoulderSpeed"),
154 Random::Double(mMinDamage, mMaxDamage), nullptr, true);
155 missile->addToGameMap();
156 missile->createMesh();
157 missile->setPosition(position);
158 // We don't want the missile to stay idle for 1 turn. Because we are in a doUpkeep context,
159 // we can safely call the missile doUpkeep as we know the engine will not call it the turn
160 // it has been added
161 missile->doUpkeep();
162 missile->setAnimationState("Triggered", true);
163
164 return true;
165}
166
167TrapEntity* TrapBoulder::getTrapEntity(Tile* tile)
168{

Callers

nothing calls this directly

Calls 11

UintFunction · 0.85
DoubleFunction · 0.85
getVisibleCreaturesMethod · 0.80
getTrapConfigDoubleMethod · 0.80
createMeshMethod · 0.80
getXMethod · 0.45
getYMethod · 0.45
addToGameMapMethod · 0.45
setPositionMethod · 0.45
doUpkeepMethod · 0.45
setAnimationStateMethod · 0.45

Tested by

no test coverage detected