| 926 | } |
| 927 | |
| 928 | void actor::collide(coord_def newpos, const actor *agent, int damage) |
| 929 | { |
| 930 | actor *other = actor_at(newpos); |
| 931 | // TODO: should the first of these check agent? |
| 932 | const bool immune = !could_harm(agent, this); |
| 933 | const bool immune_other = other ? !could_harm(agent, other) |
| 934 | : false; |
| 935 | |
| 936 | ASSERT(this != other); |
| 937 | ASSERT(alive()); |
| 938 | |
| 939 | if (mons_is_projectile(type) |
| 940 | || other && mons_is_projectile(other->type)) |
| 941 | { |
| 942 | return; |
| 943 | } |
| 944 | |
| 945 | if (is_monster() && !immune) |
| 946 | behaviour_event(as_monster(), ME_WHACK, agent); |
| 947 | |
| 948 | const int dam = apply_ac(damage); |
| 949 | |
| 950 | if (other && other->alive()) |
| 951 | { |
| 952 | const int damother = other->apply_ac(damage); |
| 953 | if (you.can_see(*this) || you.can_see(*other)) |
| 954 | { |
| 955 | mprf("%s %s with %s%s", |
| 956 | name(DESC_THE).c_str(), |
| 957 | conj_verb("collide").c_str(), |
| 958 | other->name(DESC_THE).c_str(), |
| 959 | attack_strength_punctuation((dam + damother) / 2).c_str()); |
| 960 | // OK, now do the messaging for protected monsters. |
| 961 | if (immune) |
| 962 | could_harm(agent, this, true, true); |
| 963 | if (immune_other) |
| 964 | could_harm(agent, other, true, true); |
| 965 | } |
| 966 | |
| 967 | if (other->is_monster() && !immune_other) |
| 968 | behaviour_event(other->as_monster(), ME_WHACK, agent); |
| 969 | |
| 970 | const string thisname = name(DESC_A, true); |
| 971 | const string othername = other->name(DESC_A, true); |
| 972 | if (other->alive() && !immune_other) |
| 973 | { |
| 974 | other->hurt(agent, damother, BEAM_MISSILE, KILLED_BY_COLLISION, |
| 975 | othername, thisname); |
| 976 | if (damother && other->is_monster()) |
| 977 | print_wounds(*other->as_monster()); |
| 978 | } |
| 979 | if (alive() && !immune) |
| 980 | { |
| 981 | hurt(agent, dam, BEAM_MISSILE, KILLED_BY_COLLISION, |
| 982 | thisname, othername); |
| 983 | if (dam && is_monster()) |
| 984 | print_wounds(*as_monster()); |
| 985 | } |
no test coverage detected