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

Function Structure_Damage

src/structure.c:1039–1094  ·  view source on GitHub ↗

* Damage the structure, and bring the surrounding to an explosion if needed. * * @param s The structure to damage. * @param damage The damage to deal to the structure. * @param range The range in which an explosion should be possible. * @return True if and only if the structure is now destroyed. */

Source from the content-addressed store, hash-verified

1037 * @return True if and only if the structure is now destroyed.
1038 */
1039bool Structure_Damage(Structure *s, uint16 damage, uint16 range)
1040{
1041 const StructureInfo *si;
1042
1043 if (s == NULL) return false;
1044 if (damage == 0) return false;
1045 if (s->o.script.variables[0] == 1) return false;
1046
1047 si = &g_table_structureInfo[s->o.type];
1048
1049 if (s->o.hitpoints >= damage) {
1050 s->o.hitpoints -= damage;
1051 } else {
1052 s->o.hitpoints = 0;
1053 }
1054
1055 if (s->o.hitpoints == 0) {
1056 uint16 score;
1057
1058 score = si->o.buildCredits / 100;
1059 if (score < 1) score = 1;
1060
1061 if (House_AreAllied(g_playerHouseID, s->o.houseID)) {
1062 g_scenario.destroyedAllied++;
1063 g_scenario.score -= score;
1064 } else {
1065 g_scenario.destroyedEnemy++;
1066 g_scenario.score += score;
1067 }
1068
1069 Structure_Destroy(s);
1070
1071 if (g_playerHouseID == s->o.houseID) {
1072 uint16 index;
1073
1074 switch (s->o.houseID) {
1075 case HOUSE_HARKONNEN: index = 22; break;
1076 case HOUSE_ATREIDES: index = 23; break;
1077 case HOUSE_ORDOS: index = 24; break;
1078 default: index = 0xFFFF; break;
1079 }
1080
1081 Sound_Output_Feedback(index);
1082 } else {
1083 Sound_Output_Feedback(21);
1084 }
1085
1086 Structure_UntargetMe(s);
1087 return true;
1088 }
1089
1090 if (range == 0) return false;
1091
1092 Map_MakeExplosion(EXPLOSION_IMPACT_LARGE, Tile_AddTileDiff(s->o.position, g_table_structure_layoutTileDiff[si->layout]), 0, 0);
1093 return false;
1094}
1095
1096/**

Callers 5

GameLoop_StructureFunction · 0.85
Map_MakeExplosionFunction · 0.85
Unit_MoveFunction · 0.85
Unit_EnterStructureFunction · 0.85

Calls 6

House_AreAlliedFunction · 0.85
Structure_DestroyFunction · 0.85
Sound_Output_FeedbackFunction · 0.85
Structure_UntargetMeFunction · 0.85
Map_MakeExplosionFunction · 0.85
Tile_AddTileDiffFunction · 0.85

Tested by

no test coverage detected