* Handles destroying of a structure. * * @param s The Structure. */
| 977 | * @param s The Structure. |
| 978 | */ |
| 979 | static void Structure_Destroy(Structure *s) |
| 980 | { |
| 981 | const StructureInfo *si; |
| 982 | uint8 linkedID; |
| 983 | House *h; |
| 984 | |
| 985 | if (s == NULL) return; |
| 986 | |
| 987 | if (g_debugScenario) { |
| 988 | Structure_Remove(s); |
| 989 | return; |
| 990 | } |
| 991 | |
| 992 | s->o.script.variables[0] = 1; |
| 993 | s->o.flags.s.allocated = false; |
| 994 | s->o.flags.s.repairing = false; |
| 995 | s->o.script.delay = 0; |
| 996 | |
| 997 | Script_Reset(&s->o.script, g_scriptStructure); |
| 998 | Script_Load(&s->o.script, s->o.type); |
| 999 | |
| 1000 | Voice_PlayAtTile(44, s->o.position); |
| 1001 | |
| 1002 | linkedID = s->o.linkedID; |
| 1003 | |
| 1004 | if (linkedID != 0xFF) { |
| 1005 | if (s->o.type == STRUCTURE_CONSTRUCTION_YARD) { |
| 1006 | Structure_Destroy(Structure_Get_ByIndex(linkedID)); |
| 1007 | s->o.linkedID = 0xFF; |
| 1008 | } else { |
| 1009 | while (linkedID != 0xFF) { |
| 1010 | Unit *u = Unit_Get_ByIndex(linkedID); |
| 1011 | |
| 1012 | linkedID = u->o.linkedID; |
| 1013 | |
| 1014 | Unit_Remove(u); |
| 1015 | } |
| 1016 | } |
| 1017 | } |
| 1018 | |
| 1019 | h = House_Get_ByIndex(s->o.houseID); |
| 1020 | si = &g_table_structureInfo[s->o.type]; |
| 1021 | |
| 1022 | h->credits -= (h->creditsStorage == 0) ? h->credits : min(h->credits, (h->credits * 256 / h->creditsStorage) * si->creditsStorage / 256); |
| 1023 | |
| 1024 | if (s->o.houseID != g_playerHouseID) h->credits += si->o.buildCredits + (g_campaignID > 7 ? si->o.buildCredits / 2 : 0); |
| 1025 | |
| 1026 | if (s->o.type != STRUCTURE_WINDTRAP) return; |
| 1027 | |
| 1028 | h->windtrapCount--; |
| 1029 | } |
| 1030 | |
| 1031 | /** |
| 1032 | * Damage the structure, and bring the surrounding to an explosion if needed. |
no test coverage detected