* Do an amount of damage. * @param relative The relative position of which part of armor and/or bodypart is hit. * @param power The amount of damage to inflict. * @param type The type of damage being inflicted. * @param ignoreArmor Should the damage ignore armor resistance? * @return damage done after adjustment */
| 878 | * @return damage done after adjustment |
| 879 | */ |
| 880 | int BattleUnit::damage(const Position &relative, int power, ItemDamageType type, bool ignoreArmor) |
| 881 | { |
| 882 | UnitSide side = SIDE_FRONT; |
| 883 | UnitBodyPart bodypart = BODYPART_TORSO; |
| 884 | |
| 885 | if (power <= 0) |
| 886 | { |
| 887 | return 0; |
| 888 | } |
| 889 | |
| 890 | power = (int)floor(power * _armor->getDamageModifier(type)); |
| 891 | |
| 892 | if (type == DT_SMOKE) type = DT_STUN; // smoke doesn't do real damage, but stun damage |
| 893 | |
| 894 | if (!ignoreArmor) |
| 895 | { |
| 896 | if (relative == Position(0, 0, 0)) |
| 897 | { |
| 898 | side = SIDE_UNDER; |
| 899 | } |
| 900 | else |
| 901 | { |
| 902 | int relativeDirection; |
| 903 | const int abs_x = abs(relative.x); |
| 904 | const int abs_y = abs(relative.y); |
| 905 | if (abs_y > abs_x * 2) |
| 906 | relativeDirection = 8 + 4 * (relative.y > 0); |
| 907 | else if (abs_x > abs_y * 2) |
| 908 | relativeDirection = 10 + 4 * (relative.x < 0); |
| 909 | else |
| 910 | { |
| 911 | if (relative.x < 0) |
| 912 | { |
| 913 | if (relative.y > 0) |
| 914 | relativeDirection = 13; |
| 915 | else |
| 916 | relativeDirection = 15; |
| 917 | } |
| 918 | else |
| 919 | { |
| 920 | if (relative.y > 0) |
| 921 | relativeDirection = 11; |
| 922 | else |
| 923 | relativeDirection = 9; |
| 924 | } |
| 925 | } |
| 926 | |
| 927 | switch((relativeDirection - _direction) % 8) |
| 928 | { |
| 929 | case 0: side = SIDE_FRONT; break; |
| 930 | case 1: side = RNG::generate(0,2) < 2 ? SIDE_FRONT:SIDE_RIGHT; break; |
| 931 | case 2: side = SIDE_RIGHT; break; |
| 932 | case 3: side = RNG::generate(0,2) < 2 ? SIDE_REAR:SIDE_RIGHT; break; |
| 933 | case 4: side = SIDE_REAR; break; |
| 934 | case 5: side = RNG::generate(0,2) < 2 ? SIDE_REAR:SIDE_LEFT; break; |
| 935 | case 6: side = SIDE_LEFT; break; |
| 936 | case 7: side = RNG::generate(0,2) < 2 ? SIDE_FRONT:SIDE_LEFT; break; |
| 937 | } |
nothing calls this directly
no test coverage detected