* Handle tile being on fire. * @param pos Position of the fire. * * @todo Needs a notion of iterative neighbour tiles computing. * @todo Use a getFromMap()-like function here. * @todo Extract constants of fire station effectiveness from here. */
| 1278 | * @todo Extract constants of fire station effectiveness from here. |
| 1279 | */ |
| 1280 | void Micropolis::doFire(const Position &pos) |
| 1281 | { |
| 1282 | static const short DX[4] = { -1, 0, 1, 0 }; |
| 1283 | static const short DY[4] = { 0, -1, 0, 1 }; |
| 1284 | |
| 1285 | // Try to set neighbouring tiles on fire as well |
| 1286 | for (short z = 0; z < 4; z++) { |
| 1287 | |
| 1288 | if ((getRandom16() & 7) == 0) { |
| 1289 | |
| 1290 | short xTem = pos.posX + DX[z]; |
| 1291 | short yTem = pos.posY + DY[z]; |
| 1292 | |
| 1293 | if (testBounds(xTem, yTem)) { |
| 1294 | |
| 1295 | MapValue c = map[xTem][yTem]; |
| 1296 | if (!(c & BURNBIT)) { |
| 1297 | continue; |
| 1298 | } |
| 1299 | |
| 1300 | if (c & ZONEBIT) { |
| 1301 | // Neighbour is a zone and burnable |
| 1302 | fireZone(Position(xTem, yTem), c); |
| 1303 | |
| 1304 | if ((c & LOMASK) > IZB) { /* Explode */ |
| 1305 | makeExplosionAt(xTem *16 + 8, yTem * 16 + 8); |
| 1306 | } |
| 1307 | } |
| 1308 | |
| 1309 | map[xTem][yTem] = randomFire(); |
| 1310 | } |
| 1311 | } |
| 1312 | } |
| 1313 | |
| 1314 | // Compute likelyhood of fire running out of fuel |
| 1315 | short rate = 10; // Likelyhood of extinguishing (bigger means less chance) |
| 1316 | short z = fireStationEffectMap.worldGet(pos.posX, pos.posY); |
| 1317 | |
| 1318 | if (z > 0) { |
| 1319 | rate = 3; |
| 1320 | if (z > 20) { |
| 1321 | rate = 2; |
| 1322 | } |
| 1323 | if (z > 100) { |
| 1324 | rate = 1; |
| 1325 | } |
| 1326 | } |
| 1327 | |
| 1328 | // Decide whether to put out the fire. |
| 1329 | if (getRandom(rate) == 0) { |
| 1330 | map[pos.posX][pos.posY] = randomRubble(); |
| 1331 | } |
| 1332 | } |
| 1333 | |
| 1334 | |
| 1335 | /** |
nothing calls this directly
no test coverage detected