MCPcopy Create free account
hub / github.com/OpenXcom/OpenXcom / hit

Method hit

src/Battlescape/TileEngine.cpp:1000–1091  ·  view source on GitHub ↗

* Handles bullet/weapon hits. * * A bullet/weapon hits a voxel. * @param center Center of the explosion in voxelspace. * @param power Power of the explosion. * @param type The damage type of the explosion. * @param unit The unit that caused the explosion. * @return The Unit that got hit. */

Source from the content-addressed store, hash-verified

998 * @return The Unit that got hit.
999 */
1000BattleUnit *TileEngine::hit(const Position &center, int power, ItemDamageType type, BattleUnit *unit)
1001{
1002 Tile *tile = _save->getTile(Position(center.x/16, center.y/16, center.z/24));
1003 if(!tile)
1004 {
1005 return 0;
1006 }
1007
1008 BattleUnit *bu = tile->getUnit();
1009 int adjustedDamage = 0;
1010 const int part = voxelCheck(center, unit);
1011 if (part >= V_FLOOR && part <= V_OBJECT)
1012 {
1013 // power 25% to 75%
1014 const int rndPower = RNG::generate(power/4, (power*3)/4); //RNG::boxMuller(power, power/6)
1015 if (part == V_OBJECT && _save->getMissionType() == "STR_BASE_DEFENSE")
1016 {
1017 if (rndPower >= tile->getMapData(MapData::O_OBJECT)->getArmor() && tile->getMapData(V_OBJECT)->isBaseModule())
1018 {
1019 _save->getModuleMap()[(center.x/16)/10][(center.y/16)/10].second--;
1020 }
1021 }
1022 if (tile->damage(part, rndPower))
1023 _save->setObjectiveDestroyed(true);
1024 }
1025 else if (part == V_UNIT)
1026 {
1027 int dmgRng = (type == DT_HE || Options::TFTDDamage) ? 50 : 100;
1028 int min = power * (100 - dmgRng) / 100;
1029 int max = power * (100 + dmgRng) / 100;
1030 const int rndPower = RNG::generate(min, max);
1031 int verticaloffset = 0;
1032 if (!bu)
1033 {
1034 // it's possible we have a unit below the actual tile, when he stands on a stairs and sticks his head out to the next tile
1035 Tile *below = _save->getTile(Position(center.x/16, center.y/16, (center.z/24)-1));
1036 if (below)
1037 {
1038 BattleUnit *buBelow = below->getUnit();
1039 if (buBelow)
1040 {
1041 bu = buBelow;
1042 verticaloffset = 24;
1043 }
1044 }
1045 }
1046 if (bu)
1047 {
1048 const int sz = bu->getArmor()->getSize() * 8;
1049 const Position target = bu->getPosition() * Position(16,16,24) + Position(sz,sz, bu->getFloatHeight() - tile->getTerrainLevel());
1050 const Position relative = (center - target) - Position(0,0,verticaloffset);
1051 const int wounds = bu->getFatalWounds();
1052
1053 adjustedDamage = bu->damage(relative, rndPower, type);
1054
1055 // if it's going to bleed to death and it's not a player, give credit for the kill.
1056 if (unit && bu->getFaction() != FACTION_PLAYER && wounds < bu->getFatalWounds())
1057 {

Callers 4

thinkMethod · 0.80
thinkMethod · 0.80
thinkMethod · 0.80
explodeMethod · 0.80

Calls 15

generateFunction · 0.85
getMissionTypeMethod · 0.80
isBaseModuleMethod · 0.80
setObjectiveDestroyedMethod · 0.80
getFatalWoundsMethod · 0.80
getFactionMethod · 0.80
killedByMethod · 0.80
getMoraleModifierMethod · 0.80
moraleChangeMethod · 0.80
isOutMethod · 0.80
getHealthMethod · 0.80
getStunlevelMethod · 0.80

Tested by

no test coverage detected