66 default_pixel_z = 8
77 layer = ABOVE_HUMAN_LAYER
88 pass_flags = PASS_FLAG_TABLE
9- movement_handlers = list (/ datum / movement_handler/ delay/ insect_swarm)
9+ movement_handlers = list (/ datum / movement_handler/ delay/ insect_swarm = list ( 1 SECOND ) )
1010
1111 // / Current movement target for automove (ie. hive, flowers or victim)
1212 VAR_PRIVATE / atom / move_target
1818 var /swarm_agitation = 0
1919 // / Percentage value; if it drops to 0, the swarm will be destroyed.
2020 var /swarm_intensity = 1
21- // / if more states are added to swarm.dmi, increase this
22- var /const /MAX_SWARM_STATE = 6
2321 // / Cooldown timer for next tick.
2422 VAR_PRIVATE / next_work = 0
2523 // / Time that smoke will wear off.
2624 var /smoked_until = 0
2725
28- / datum / movement_handler/ delay/ insect_swarm
29- delay = 1 SECOND
30-
3126/ datum / movement_handler/ delay/ insect_swarm/ DoMove(direction, mob / mover, is_external)
3227 .. ()
3328 step (host, direction)
4641 if (! istype(owner))
4742 PRINT_STACK_TRACE (" Insect swarm created with invalid hive: '[ owner] '" )
4843 return INITIALIZE_HINT_QDEL
49- color = insect_type. swarm_color
50- icon = insect_type. swarm_icon
44+ update_transform ()
5145 update_swarm ()
5246 LAZYDISTINCTADD (owner. swarms, src )
5347 START_PROCESSING (SSobj, src )
6155 STOP_PROCESSING (SSobj, src )
6256 return .. ()
6357
58+ // Resolves the current swarm amount to a coarser value used for icon state selection.
59+ / obj / effect/ insect_swarm/ proc / get_swarm_state()
60+ return ceil((swarm_intensity / insect_type. max_swarm_intensity) * insect_type. max_swarm_state)
61+
62+ / obj / effect/ insect_swarm/ on_update_icon()
63+ . = .. ()
64+ color = insect_type. swarm_color
65+ icon = insect_type. swarm_icon
66+ icon_state = num2text(get_swarm_state())
67+ if (is_smoked())
68+ icon_state = " [ icon_state] _smoked"
69+
70+ / obj / effect/ insect_swarm/ update_transform()
71+ . = .. ()
72+ // Some icon variation via transform.
73+ if (prob(75 ))
74+ var /matrix /swarm_transform = transform || matrix()
75+ swarm_transform. Turn(pick (90 , 180 , 270 ))
76+ transform = swarm_transform
77+
6478/ obj / effect/ insect_swarm/ proc / update_swarm()
65- icon_state = num2text(ceil((swarm_intensity / insect_type . max_swarm_intensity) * MAX_SWARM_STATE ) )
66- if (icon_state == " 1 " )
79+ update_icon ( )
80+ if (get_swarm_state() == 1 )
6781 SetName (insect_type. name_singular)
6882 desc = insect_type. insect_desc
6983 gender = NEUTER
7286 desc = insect_type. swarm_desc
7387 gender = PLURAL
7488
75- // Some icon variation via transform.
76- if (prob(75 ))
77- var /matrix /swarm_transform = matrix()
78- swarm_transform. Turn(pick (90 , 180 , 270 ))
79-
8089/ obj / effect/ insect_swarm/ proc / is_agitated()
8190 return QDELETED (owner) || (swarm_agitation > 0 && ! is_smoked())
8291
8392/ obj / effect/ insect_swarm/ proc / find_sting_target()
8493 for (var /mob /living/victim in view (7 , src ))
85- if (! victim. simulated || victim. stat || victim. current_posture?. prone)
86- continue
87- if (victim. isSynthetic())
88- continue
89- return victim
94+ if (victim. simulated && ! victim. is_playing_dead())
95+ return victim
9096
9197/ obj / effect/ insect_swarm/ proc / merge( obj / effect/ insect_swarm/ other_swarm)
9298
189195 break
190196 return FALSE
191197
198+ / obj / effect/ insect_swarm/ failed_automove()
199+ .. ()
200+ stop_automove ()
201+ return FALSE
202+
192203/ obj / effect/ insect_swarm/ get_automove_target( datum / automove_metadata/ metadata)
193204 return move_target
194205
195206/ obj / effect/ insect_swarm/ stop_automove()
196- SHOULD_CALL_PARENT (FALSE )
197207 move_target = null
198- // . = ..() // TODO work out why they're not automoving
199- walk (src , 0 )
208+ . = .. ()
209+
210+ / obj / effect/ insect_swarm/ can_do_automated_move(variant_move_delay)
211+ return ! is_smoked()
200212
201213/ obj / effect/ insect_swarm/ start_automove(target, movement_type, datum / automove_metadata/ metadata)
202- SHOULD_CALL_PARENT (FALSE )
203214 move_target = target
204- // . = ..() // TODO work out why they're not automoving
205- if (move_target)
206- walk_to (src , move_target, 0 , 7 )
207- else
208- walk (src , 0 )
215+ . = .. ()
209216
210217/ obj / effect/ insect_swarm/ proc / handle_hive_behavior()
211218
272279 merge (other_swarm)
273280 return
274281
282+ / obj / effect/ insect_swarm/ DoMove(direction, mob / mover, is_external)
283+ . = .. ()
284+ to_world (" swarm tried to move: [ . ] " )
285+
275286/ obj / effect/ insect_swarm/ pollinator
276287 var /pollen = 0
277288
349360 else
350361 start_automove (owner. holder)
351362
352- // TODO: update icon (twitching on ground?)
353- // TODO: lower agitation
354363/ obj / effect/ insect_swarm/ proc / was_smoked(smoke_time = 10 SECONDS )
355364 smoked_until = max(smoked_until, world . time + smoke_time)
365+ swarm_agitation = round(swarm_agitation * 0.75 )
366+ addtimer (CALLBACK (src , TYPE_PROC_REF (/ atom , update_icon), TRUE ), smoke_time, (TIMER_UNIQUE | TIMER_OVERRIDE ))
356367
357368/ obj / effect/ insect_swarm/ proc / is_smoked()
358369 return world . time < smoked_until
0 commit comments