MCPcopy Create free account
hub / github.com/OpenXcom/OpenXcom / prepareNewTurn

Method prepareNewTurn

src/Savegame/SavedBattleGame.cpp:1207–1354  ·  view source on GitHub ↗

* Carries out new turn preparations such as fire and smoke spreading. */

Source from the content-addressed store, hash-verified

1205 * Carries out new turn preparations such as fire and smoke spreading.
1206 */
1207void SavedBattleGame::prepareNewTurn()
1208{
1209 std::vector<Tile*> tilesOnFire;
1210 std::vector<Tile*> tilesOnSmoke;
1211
1212 // prepare a list of tiles on fire
1213 for (int i = 0; i < _mapsize_x * _mapsize_y * _mapsize_z; ++i)
1214 {
1215 if (getTiles()[i]->getFire() > 0)
1216 {
1217 tilesOnFire.push_back(getTiles()[i]);
1218 }
1219 }
1220
1221 // first: fires spread
1222 for (std::vector<Tile*>::iterator i = tilesOnFire.begin(); i != tilesOnFire.end(); ++i)
1223 {
1224 // if we haven't added fire here this turn
1225 if ((*i)->getOverlaps() == 0)
1226 {
1227 // reduce the fire timer
1228 (*i)->setFire((*i)->getFire() -1);
1229
1230 // if we're still burning
1231 if ((*i)->getFire())
1232 {
1233 // propegate in four cardinal directions (0, 2, 4, 6)
1234 for (int dir = 0; dir <= 6; dir += 2)
1235 {
1236 Position pos;
1237 Pathfinding::directionToVector(dir, &pos);
1238 Tile *t = getTile((*i)->getPosition() + pos);
1239 // if there's no wall blocking the path of the flames...
1240 if (t && getTileEngine()->horizontalBlockage((*i), t, DT_IN) == 0)
1241 {
1242 // attempt to set this tile on fire
1243 t->ignite((*i)->getSmoke());
1244 }
1245 }
1246 }
1247 // fire has burnt out
1248 else
1249 {
1250 (*i)->setSmoke(0);
1251 // burn this tile, and any object in it, if it's not fireproof/indestructible.
1252 if ((*i)->getMapData(MapData::O_OBJECT))
1253 {
1254 if ((*i)->getMapData(MapData::O_OBJECT)->getFlammable() != 255 && (*i)->getMapData(MapData::O_OBJECT)->getArmor() != 255)
1255 {
1256 if ((*i)->destroy(MapData::O_OBJECT))
1257 {
1258 _objectiveDestroyed = true;
1259 }
1260 if ((*i)->destroy(MapData::O_FLOOR))
1261 {
1262 _objectiveDestroyed = true;
1263 }
1264 }

Callers 1

endTurnMethod · 0.45

Calls 15

getOverlapsMethod · 0.80
horizontalBlockageMethod · 0.80
igniteMethod · 0.80
getSmokeMethod · 0.80
setSmokeMethod · 0.80
getFlammableMethod · 0.80
destroyMethod · 0.80
addSmokeMethod · 0.80
hasNoFloorMethod · 0.80
PositionClass · 0.70
getFireMethod · 0.45

Tested by

no test coverage detected