Skip to content

Commit

Permalink
Merge pull request ParadiseSS13#13583 from Fox-McCloud/swarming-compo…
Browse files Browse the repository at this point in the history
…nent

Adds Swarming Component
  • Loading branch information
variableundefined authored Jun 23, 2020
2 parents 4546c11 + a140787 commit 0bee228
Show file tree
Hide file tree
Showing 14 changed files with 79 additions and 16 deletions.
55 changes: 55 additions & 0 deletions code/datums/components/swarming.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/datum/component/swarming
var/offset_x = 0
var/offset_y = 0
var/is_swarming = FALSE
var/list/swarm_members = list()

/datum/component/swarming/Initialize(max_x = 24, max_y = 24)
if(!ismovableatom(parent))
return COMPONENT_INCOMPATIBLE
offset_x = rand(-max_x, max_x)
offset_y = rand(-max_y, max_y)

RegisterSignal(parent, COMSIG_MOVABLE_CROSSED, .proc/join_swarm)
RegisterSignal(parent, COMSIG_MOVABLE_UNCROSSED, .proc/leave_swarm)

/datum/component/swarming/Destroy()
for(var/other in swarm_members)
var/datum/component/swarming/other_swarm = other
other_swarm.swarm_members -= src
if(!other_swarm.swarm_members.len)
other_swarm.unswarm()
swarm_members = null
return ..()

/datum/component/swarming/proc/join_swarm(datum/source, atom/movable/AM)
var/datum/component/swarming/other_swarm = AM.GetComponent(/datum/component/swarming)
if(!other_swarm)
return
swarm()
swarm_members |= other_swarm
other_swarm.swarm()
other_swarm.swarm_members |= src

/datum/component/swarming/proc/leave_swarm(datum/source, atom/movable/AM)
var/datum/component/swarming/other_swarm = AM.GetComponent(/datum/component/swarming)
if(!other_swarm || !(other_swarm in swarm_members))
return
swarm_members -= other_swarm
if(!swarm_members.len)
unswarm()
other_swarm.swarm_members -= src
if(!other_swarm.swarm_members.len)
other_swarm.unswarm()

/datum/component/swarming/proc/swarm()
var/atom/movable/owner = parent
if(!is_swarming)
is_swarming = TRUE
animate(owner, pixel_x = owner.pixel_x + offset_x, pixel_y = owner.pixel_y + offset_y, time = 2)

/datum/component/swarming/proc/unswarm()
var/atom/movable/owner = parent
if(is_swarming)
animate(owner, pixel_x = owner.pixel_x - offset_x, pixel_y = owner.pixel_y - offset_y, time = 2)
is_swarming = FALSE
11 changes: 5 additions & 6 deletions code/game/atoms_movable.dm
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,9 @@
SEND_SIGNAL(src, COMSIG_MOVABLE_CROSSED, AM)
SEND_SIGNAL(AM, COMSIG_CROSSED_MOVABLE, src)

/atom/movable/Uncrossed(atom/movable/AM)
SEND_SIGNAL(src, COMSIG_MOVABLE_UNCROSSED, AM)

/atom/movable/Bump(atom/A, yes) //the "yes" arg is to differentiate our Bump proc from byond's, without it every Bump() call would become a double Bump().
if(A && yes)
SEND_SIGNAL(src, COMSIG_MOVABLE_BUMP, A)
Expand Down Expand Up @@ -493,18 +496,14 @@
target.fingerprintshidden += fingerprintshidden
target.fingerprintslast = fingerprintslast

/atom/movable/proc/do_attack_animation(atom/A, visual_effect_icon, obj/item/used_item, no_effect, end_pixel_y)
/atom/movable/proc/do_attack_animation(atom/A, visual_effect_icon, obj/item/used_item, no_effect)
if(!no_effect && (visual_effect_icon || used_item))
do_item_attack_animation(A, visual_effect_icon, used_item)

if(A == src)
return //don't do an animation if attacking self
var/pixel_x_diff = 0
var/pixel_y_diff = 0
var/final_pixel_y = initial(pixel_y)
if(end_pixel_y)
final_pixel_y = end_pixel_y

var/direction = get_dir(src, A)
if(direction & NORTH)
pixel_y_diff = 8
Expand All @@ -517,7 +516,7 @@
pixel_x_diff = -8

animate(src, pixel_x = pixel_x + pixel_x_diff, pixel_y = pixel_y + pixel_y_diff, time = 2)
animate(pixel_x = initial(pixel_x), pixel_y = final_pixel_y, time = 2)
animate(pixel_x = pixel_x - pixel_x_diff, pixel_y = pixel_y - pixel_y_diff, time = 2)

/atom/movable/proc/do_item_attack_animation(atom/A, visual_effect_icon, obj/item/used_item)
var/image/I
Expand Down
2 changes: 1 addition & 1 deletion code/game/mecha/mecha.dm
Original file line number Diff line number Diff line change
Expand Up @@ -1456,7 +1456,7 @@

..()

/obj/mecha/do_attack_animation(atom/A, visual_effect_icon, obj/item/used_item, no_effect, end_pixel_y)
/obj/mecha/do_attack_animation(atom/A, visual_effect_icon, obj/item/used_item, no_effect)
if(!no_effect)
if(selected)
used_item = selected
Expand Down
1 change: 1 addition & 0 deletions code/game/objects/effects/spiders.dm
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
pixel_x = rand(6,-6)
pixel_y = rand(6,-6)
START_PROCESSING(SSobj, src)
AddComponent(/datum/component/swarming)

/obj/structure/spider/spiderling/Destroy()
STOP_PROCESSING(SSobj, src)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
playsound(loc, 'sound/weapons/punchmiss.ogg', 25, 1, -1)
visible_message("<span class='danger'>[M] has attempted to disarm [src]!</span>")

/mob/living/carbon/alien/humanoid/do_attack_animation(atom/A, visual_effect_icon, obj/item/used_item, no_effect, end_pixel_y)
/mob/living/carbon/alien/humanoid/do_attack_animation(atom/A, visual_effect_icon, obj/item/used_item, no_effect)
if(!no_effect && !visual_effect_icon)
visual_effect_icon = ATTACK_EFFECT_CLAW
..()
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
step_away(src, user, 15)
return TRUE

/mob/living/carbon/alien/larva/do_attack_animation(atom/A, visual_effect_icon, obj/item/used_item, no_effect, end_pixel_y)
/mob/living/carbon/alien/larva/do_attack_animation(atom/A, visual_effect_icon, obj/item/used_item, no_effect)
if(!no_effect && !visual_effect_icon)
visual_effect_icon = ATTACK_EFFECT_BITE
..()
6 changes: 3 additions & 3 deletions code/modules/mob/living/living.dm
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,8 @@
clear_alert("weightless")
else
throw_alert("weightless", /obj/screen/alert/weightless)
float(!has_gravity)
if(!flying)
float(!has_gravity)

/mob/living/proc/float(on)
if(throwing)
Expand Down Expand Up @@ -825,8 +826,7 @@
spawn_dust()
gib()

/mob/living/do_attack_animation(atom/A, visual_effect_icon, obj/item/used_item, no_effect, end_pixel_y)
end_pixel_y = get_standard_pixel_y_offset(lying)
/mob/living/do_attack_animation(atom/A, visual_effect_icon, obj/item/used_item, no_effect)
if(!used_item)
used_item = get_active_hand()
..()
Expand Down
2 changes: 1 addition & 1 deletion code/modules/mob/living/simple_animal/animal_defense.dm
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
/mob/living/simple_animal/blob_act(obj/structure/blob/B)
adjustBruteLoss(20)

/mob/living/simple_animal/do_attack_animation(atom/A, visual_effect_icon, used_item, no_effect, end_pixel_y)
/mob/living/simple_animal/do_attack_animation(atom/A, visual_effect_icon, used_item, no_effect)
if(!no_effect && !visual_effect_icon && melee_damage_upper)
if(melee_damage_upper < 10)
visual_effect_icon = ATTACK_EFFECT_PUNCH
Expand Down
1 change: 1 addition & 0 deletions code/modules/mob/living/simple_animal/hostile/bees.dm
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
/mob/living/simple_animal/hostile/poison/bees/New()
..()
generate_bee_visuals()
AddComponent(/datum/component/swarming)

/mob/living/simple_animal/hostile/poison/bees/Destroy()
beegent = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
/mob/living/simple_animal/hostile/asteroid/hivelordbrood/Initialize(mapload)
. = ..()
addtimer(CALLBACK(src, .proc/death), 100)
AddComponent(/datum/component/swarming)


/mob/living/simple_animal/hostile/asteroid/hivelordbrood/blood
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@


//Jiggle the whole worm forwards towards the next segment
/mob/living/simple_animal/hostile/spaceWorm/do_attack_animation(atom/A, visual_effect_icon, used_item, no_effect, end_pixel_y)
/mob/living/simple_animal/hostile/spaceWorm/do_attack_animation(atom/A, visual_effect_icon, used_item, no_effect)
..()
if(previousWorm)
previousWorm.do_attack_animation(src)
7 changes: 6 additions & 1 deletion code/modules/mob/living/simple_animal/hostile/syndicate.dm
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,8 @@
icon = 'icons/mob/critter.dmi'
icon_state = "viscerator_attack"
icon_living = "viscerator_attack"
pass_flags = PASSTABLE
pass_flags = PASSTABLE | PASSMOB
a_intent = INTENT_HARM
health = 15
maxHealth = 15
obj_damage = 0
Expand All @@ -365,3 +366,7 @@
gold_core_spawnable = HOSTILE_SPAWN
del_on_death = 1
deathmessage = "is smashed into pieces!"

/mob/living/simple_animal/hostile/viscerator/Initialize(mapload)
. = ..()
AddComponent(/datum/component/swarming)
2 changes: 1 addition & 1 deletion code/modules/mob/living/simple_animal/posessed_object.dm
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
. += "<span class='warning'>[src] appears to be having trouble staying afloat!</span>"


/mob/living/simple_animal/possessed_object/do_attack_animation(atom/A, visual_effect_icon, used_item, no_effect, end_pixel_y)
/mob/living/simple_animal/possessed_object/do_attack_animation(atom/A, visual_effect_icon, used_item, no_effect)
..()
animate_ghostly_presence(src, -1, 20, 1) // Restart the floating animation after the attack animation, as it will be cancelled.

Expand Down
1 change: 1 addition & 0 deletions paradise.dme
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@
#include "code\datums\components\slippery.dm"
#include "code\datums\components\spawner.dm"
#include "code\datums\components\squeak.dm"
#include "code\datums\components\swarming.dm"
#include "code\datums\diseases\_disease.dm"
#include "code\datums\diseases\_MobProcs.dm"
#include "code\datums\diseases\anxiety.dm"
Expand Down

0 comments on commit 0bee228

Please sign in to comment.