MCPcopy Create free account
hub / github.com/OpenApoc/OpenApoc / damage

Method damage

game/state/battle/battleexplosion.cpp:85–180  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

83}
84
85void BattleExplosion::damage(GameState &state, const TileMap &map, Vec3<int> pos, int damage)
86{
87 auto tile = map.getTile(pos);
88 // Explosions with no hazard spawn smoke with half ttl
89 if (!damageType->hazardType)
90 {
91 StateRef<DamageType> dtSmoke = {&state, "DAMAGETYPE_SMOKE"};
92 state.current_battle->placeHazard(state, ownerOrganisation, ownerUnit, dtSmoke, pos,
93 dtSmoke->hazardType->getLifetime(state), damage, 2,
94 false);
95 }
96 // Explosions with no custom explosion doodad spawn hazards when dealing damage
97 else if (!damageType->explosionDoodad)
98 {
99 state.current_battle->placeHazard(state, ownerOrganisation, ownerUnit, damageType, pos,
100 damageType->hazardType->getLifetime(state), damage, 1,
101 false);
102 }
103 // Gas does no direct damage
104 if (damageType->doesImpactDamage())
105 {
106 auto set = tile->ownedObjects;
107 for (auto &obj : set)
108 {
109 if (tile->ownedObjects.find(obj) == tile->ownedObjects.end())
110 {
111 continue;
112 }
113 if (obj->getType() == TileObject::Type::Ground ||
114 obj->getType() == TileObject::Type::Feature ||
115 obj->getType() == TileObject::Type::LeftWall ||
116 obj->getType() == TileObject::Type::RightWall)
117 {
118 auto mp = std::static_pointer_cast<TileObjectBattleMapPart>(obj)->getOwner();
119 switch (damageType->effectType)
120 {
121 case DamageType::EffectType::Fire:
122 // Nothing, map parts are not damaged by fire at explosion time
123 break;
124 default:
125 mp->applyDamage(state, damage, damageType);
126 break;
127 }
128 }
129 else if (obj->getType() == TileObject::Type::Unit)
130 {
131 StateRef<BattleUnit> u = {
132 &state, std::static_pointer_cast<TileObjectBattleUnit>(obj)->getUnit()->id};
133 if (affectedUnits.find(u) != affectedUnits.end())
134 {
135 continue;
136 }
137 affectedUnits.insert(u);
138 // Determine direction of hit
139 Vec3<float> velocity = -position;
140 velocity -= Vec3<float>{0.5f, 0.5f, 0.5f};
141 velocity += u->position;
142 if (velocity.x == 0.0f && velocity.y == 0.0f)

Callers

nothing calls this directly

Calls 13

getTileMethod · 0.80
placeHazardMethod · 0.80
getLifetimeMethod · 0.80
doesImpactDamageMethod · 0.80
endMethod · 0.80
getUnitMethod · 0.80
insertMethod · 0.80
getCurrentHeightMethod · 0.80
determineBodyPartHitMethod · 0.80
getItemMethod · 0.80
getTypeMethod · 0.45
getOwnerMethod · 0.45

Tested by

no test coverage detected