* Remove the structure from the map, free it, and clean up after it. * @param s The structure to remove. */
| 1303 | * @param s The structure to remove. |
| 1304 | */ |
| 1305 | void Structure_Remove(Structure *s) |
| 1306 | { |
| 1307 | const StructureInfo *si; |
| 1308 | uint16 packed; |
| 1309 | uint16 i; |
| 1310 | House *h; |
| 1311 | |
| 1312 | if (s == NULL) return; |
| 1313 | |
| 1314 | si = &g_table_structureInfo[s->o.type]; |
| 1315 | packed = Tile_PackTile(s->o.position); |
| 1316 | |
| 1317 | for (i = 0; i < g_table_structure_layoutTileCount[si->layout]; i++) { |
| 1318 | Tile *t; |
| 1319 | uint16 curPacked = packed + g_table_structure_layoutTiles[si->layout][i]; |
| 1320 | |
| 1321 | Animation_Stop_ByTile(curPacked); |
| 1322 | |
| 1323 | t = &g_map[curPacked]; |
| 1324 | t->hasStructure = false; |
| 1325 | |
| 1326 | if (g_debugScenario) { |
| 1327 | t->groundTileID = g_mapTileID[curPacked] & 0x1FF; |
| 1328 | t->overlayTileID = 0; |
| 1329 | } |
| 1330 | } |
| 1331 | |
| 1332 | if (!g_debugScenario) { |
| 1333 | Animation_Start(g_table_animation_structure[0], s->o.position, si->layout, s->o.houseID, (uint8)si->iconGroup); |
| 1334 | } |
| 1335 | |
| 1336 | h = House_Get_ByIndex(s->o.houseID); |
| 1337 | |
| 1338 | for (i = 0; i < 5; i++) { |
| 1339 | if (h->ai_structureRebuild[i][0] != 0) continue; |
| 1340 | h->ai_structureRebuild[i][0] = s->o.type; |
| 1341 | h->ai_structureRebuild[i][1] = packed; |
| 1342 | break; |
| 1343 | } |
| 1344 | |
| 1345 | Structure_Free(s); |
| 1346 | Structure_UntargetMe(s); |
| 1347 | |
| 1348 | h->structuresBuilt = Structure_GetStructuresBuilt(h); |
| 1349 | |
| 1350 | House_UpdateCreditsStorage(s->o.houseID); |
| 1351 | |
| 1352 | if (g_debugScenario) return; |
| 1353 | |
| 1354 | switch (s->o.type) { |
| 1355 | case STRUCTURE_WINDTRAP: |
| 1356 | House_CalculatePowerAndCredit(h); |
| 1357 | break; |
| 1358 | |
| 1359 | case STRUCTURE_OUTPOST: |
| 1360 | House_UpdateRadarState(h); |
| 1361 | break; |
| 1362 |
no test coverage detected