Files
Bubberstation/code/datums/elements/sideway_movement.dm
SkyratBot e0ab5a3328 [MIRROR] Converting crabs to basic mobs [MDB IGNORE] (#22710)
* Converting crabs to basic mobs (#77109)

## About The Pull Request
Exactly what it reads on the tin. As a bonus, they will flee from
attacking targets, hunt tiny critters (crabs are now small-sized) and
actually move sideways (it's an element that covers both client and
basic movement)

## Why It's Good For The Game
Another simple to basic mob refactor.

## Changelog

🆑
refactor: Crabs refactored into basic mobs. They now hunt tiny critters
and flee from attackers.
fix: Fixed crabs not crab-walking.
/🆑

* Converting crabs to basic mobs

* UpdatePaths

* More path changes

* Update simple_animal_freeze.dm

---------

Co-authored-by: Ghom <42542238+Ghommie@users.noreply.github.com>
Co-authored-by: Giz <13398309+vinylspiders@users.noreply.github.com>
2023-07-27 18:05:51 -04:00

28 lines
1.2 KiB
Plaintext

///A simple element that forces the mob to face a perpendicular direction when moving, like crabs.
/datum/element/sideway_movement
/datum/element/sideway_movement/Attach(atom/movable/target)
. = ..()
if(!ismovable(target))
return ELEMENT_INCOMPATIBLE
RegisterSignal(target, COMSIG_MOB_CLIENT_MOVED, PROC_REF(on_client_move))
RegisterSignal(target, COMSIG_MOVABLE_MOVED_FROM_LOOP, PROC_REF(on_moved_from_loop))
/datum/element/sideway_movement/proc/on_client_move(atom/movable/source, direction, old_dir)
SIGNAL_HANDLER
on_move(source, direction, old_dir)
/datum/element/sideway_movement/proc/on_moved_from_loop(atom/movable/source, datum/move_loop/loop, old_dir, direction)
SIGNAL_HANDLER
if(!CHECK_MOVE_LOOP_FLAGS(source, MOVEMENT_LOOP_OUTSIDE_CONTROL|MOVEMENT_LOOP_NO_DIR_UPDATE))
on_move(source, direction, old_dir)
///retain the old dir unless walking straight ahead or backward, in which case rotate the dir left or right by a 90°
/datum/element/sideway_movement/proc/on_move(atom/movable/source, direction, old_dir)
if(!source.set_dir_on_move)
return
var/new_dir = old_dir
if(direction == old_dir || direction == REVERSE_DIR(old_dir))
new_dir = angle2dir(dir2angle(direction) + pick(90, -90))
source.setDir(new_dir)