MCPcopy Create free account
hub / github.com/OpenDUNE/OpenDUNE / Structure_Destroy

Function Structure_Destroy

src/structure.c:979–1029  ·  view source on GitHub ↗

* Handles destroying of a structure. * * @param s The Structure. */

Source from the content-addressed store, hash-verified

977 * @param s The Structure.
978 */
979static 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.

Callers 1

Structure_DamageFunction · 0.85

Calls 8

Structure_RemoveFunction · 0.85
Script_ResetFunction · 0.85
Script_LoadFunction · 0.85
Voice_PlayAtTileFunction · 0.85
Structure_Get_ByIndexFunction · 0.85
Unit_Get_ByIndexFunction · 0.85
Unit_RemoveFunction · 0.85
House_Get_ByIndexFunction · 0.85

Tested by

no test coverage detected