|
| 1 | +///This component allows something to be when crossed, for example for cockroaches. |
| 2 | +/datum/component/squashable |
| 3 | + ///Chance on crossed to be squashed |
| 4 | + var/squash_chance = 50 |
| 5 | + ///How much brute is applied when mob is squashed |
| 6 | + var/squash_damage = 1 |
| 7 | + ///Squash flags, for extra checks etcetera. |
| 8 | + var/squash_flags = NONE |
| 9 | + ///Special callback to call on squash instead, for things like hauberoach |
| 10 | + var/datum/callback/on_squash_callback |
| 11 | + ///signal list given to connect_loc |
| 12 | + var/static/list/loc_connections = list( |
| 13 | + COMSIG_ATOM_ENTERED = PROC_REF(on_entered), |
| 14 | + ) |
| 15 | + |
| 16 | + |
| 17 | +/datum/component/squashable/Initialize(squash_chance, squash_damage, squash_flags, squash_callback) |
| 18 | + . = ..() |
| 19 | + if(!isliving(parent)) |
| 20 | + return COMPONENT_INCOMPATIBLE |
| 21 | + if(squash_chance) |
| 22 | + src.squash_chance = squash_chance |
| 23 | + if(squash_damage) |
| 24 | + src.squash_damage = squash_damage |
| 25 | + if(squash_flags) |
| 26 | + src.squash_flags = squash_flags |
| 27 | + if(!src.on_squash_callback && squash_callback) |
| 28 | + on_squash_callback = CALLBACK(parent, squash_callback) |
| 29 | + |
| 30 | + AddComponent(/datum/component/connect_loc_behalf, parent, loc_connections) |
| 31 | + |
| 32 | +/datum/component/squashable/Destroy(force) |
| 33 | + on_squash_callback = null |
| 34 | + return ..() |
| 35 | + |
| 36 | +///Handles the squashing of the mob |
| 37 | +/datum/component/squashable/proc/on_entered(turf/source_turf, atom/movable/crossing_movable) |
| 38 | + // SIGNAL_HANDLER -- dont uncomment this |
| 39 | + |
| 40 | + if(parent == crossing_movable) |
| 41 | + return |
| 42 | + |
| 43 | + var/mob/living/parent_as_living = parent |
| 44 | + if((squash_flags & SQUASHED_DONT_SQUASH_IN_CONTENTS) && !isturf(parent_as_living.loc)) |
| 45 | + return |
| 46 | + |
| 47 | + if((squash_flags & SQUASHED_SHOULD_BE_DOWN) && parent_as_living.body_position != LYING_DOWN) |
| 48 | + return |
| 49 | + |
| 50 | + var/should_squash = ((squash_flags & SQUASHED_ALWAYS_IF_DEAD) && parent_as_living.stat == DEAD) || prob(squash_chance) |
| 51 | + |
| 52 | + if(should_squash && on_squash_callback) |
| 53 | + if(on_squash_callback.Invoke(parent_as_living, crossing_movable)) |
| 54 | + return //Everything worked, we're done! |
| 55 | + if(isliving(crossing_movable)) |
| 56 | + var/mob/living/crossing_mob = crossing_movable |
| 57 | + if(crossing_mob.mob_size > MOB_SIZE_SMALL && !(crossing_mob.movement_type & MOVETYPES_NOT_TOUCHING_GROUND)) |
| 58 | + if(HAS_TRAIT(crossing_mob, TRAIT_PACIFISM)) |
| 59 | + crossing_mob.visible_message(span_notice("[crossing_mob] carefully steps over [parent_as_living]."), span_notice("You carefully step over [parent_as_living] to avoid hurting it.")) |
| 60 | + return |
| 61 | + if(should_squash) |
| 62 | + crossing_mob.visible_message(span_notice("[crossing_mob] squashed [parent_as_living]."), span_notice("You squashed [parent_as_living].")) |
| 63 | + Squish(parent_as_living) |
| 64 | + else |
| 65 | + parent_as_living.visible_message(span_notice("[parent_as_living] avoids getting crushed.")) |
| 66 | + else if(isstructure(crossing_movable)) |
| 67 | + if(should_squash) |
| 68 | + crossing_movable.visible_message(span_notice("[parent_as_living] is crushed under [crossing_movable].")) |
| 69 | + Squish(parent_as_living) |
| 70 | + else |
| 71 | + parent_as_living.visible_message(span_notice("[parent_as_living] avoids getting crushed.")) |
| 72 | + |
| 73 | +/datum/component/squashable/proc/Squish(mob/living/target) |
| 74 | + if(squash_flags & SQUASHED_SHOULD_BE_GIBBED) |
| 75 | + target.gib(DROP_ALL_REMAINS) |
| 76 | + else |
| 77 | + target.adjustBruteLoss(squash_damage) |
| 78 | + |
| 79 | +/datum/component/squashable/UnregisterFromParent() |
| 80 | + . = ..() |
| 81 | + qdel(GetComponent(/datum/component/connect_loc_behalf)) |
0 commit comments