Skip to content

Commit effafdc

Browse files
Expanding mob controller handler-directing logic.
1 parent c8875c2 commit effafdc

File tree

6 files changed

+63
-34
lines changed

6 files changed

+63
-34
lines changed

code/datums/ai/_ai.dm

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
*
33
* 1. AI should not implement any bespoke mob logic within the proc it uses
44
* to trigger or respond to game events. It should share entrypoints with
5-
* action performed by players and should respect the same intents, etc.
5+
* actions performed by players and should respect the same intents, etc.
66
* that players have to manage, through the same procs players use. This
77
* should mean that players can be slotted into the pilot seat of any mob,
88
* suspending AI behavior, and should then be able to freely use any of the
@@ -79,6 +79,9 @@
7979
/// How long minimum between scans.
8080
var/target_scan_delay = 1 SECOND
8181

82+
/// Last mob to attempt to handle this mob.
83+
var/weakref/last_handler
84+
8285
/datum/mob_controller/New(var/mob/living/target_body)
8386
body = target_body
8487
if(expected_type && !istype(body, expected_type))
@@ -215,4 +218,21 @@
215218
if(!scary_grabber)
216219
return
217220
if(spooked_by_grab && !is_friend(scary_grabber))
218-
retaliate(scary_grabber)
221+
retaliate(scary_grabber)
222+
223+
// General stubs for when another mob has directed this mob to attack.
224+
/datum/mob_controller/proc/check_handler_can_order(mob/handler, atom/target, intent_flags)
225+
return is_friend(handler)
226+
227+
/datum/mob_controller/proc/process_handler_target(mob/handler, atom/target, intent_flags)
228+
if(!check_handler_can_order(handler, target, intent_flags))
229+
return process_handler_failure(handler, target)
230+
last_handler = weakref(handler)
231+
return TRUE
232+
233+
/datum/mob_controller/proc/process_handler_failure(mob/handler, atom/target)
234+
return FALSE
235+
236+
/datum/mob_controller/proc/process_holder_interaction(mob/handler)
237+
last_handler = weakref(handler)
238+
return body?.attack_hand_with_interaction_checks(handler)

code/datums/ai/hunter.dm

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,51 +36,55 @@
3636
/datum/mob_controller/passive/hunter/get_target(atom/new_target)
3737
if(isnull(hunt_target))
3838
return null
39-
var/mob/living/prey = hunt_target.resolve()
39+
var/atom/prey = hunt_target.resolve()
4040
if(!istype(prey) || QDELETED(prey))
4141
set_target(null)
4242
return null
4343
return prey
4444

4545
/datum/mob_controller/passive/hunter/set_target(atom/new_target)
46-
if(isnull(new_target) || isliving(new_target))
47-
hunt_target = new_target ? weakref(new_target) : null
48-
return TRUE
49-
return FALSE
46+
hunt_target = new_target ? weakref(new_target) : null
47+
return TRUE
5048

5149
/datum/mob_controller/passive/hunter/do_process(time_elapsed)
52-
5350
if(!(. = ..()))
5451
return
55-
5652
if(body.incapacitated() || body.current_posture?.prone || body.buckled || flee_target || !get_target())
5753
return
54+
process_hunting(get_target())
55+
56+
/datum/mob_controller/passive/hunter/proc/process_hunting(atom/target)
5857

59-
var/mob/living/target = get_target()
6058
if(!istype(target) || QDELETED(target) || !(target in view(body)))
6159
set_target(null)
6260
resume_wandering()
63-
return
61+
return FALSE
6462

6563
// Find or pursue the target.
6664
if(!body.Adjacent(target))
6765
stop_wandering()
6866
body.start_automove(target)
69-
return
67+
return FALSE
7068

71-
// Hunt/consume the target.
72-
if(target.stat != DEAD)
73-
try_attack_prey(target)
69+
if(!ismob(target))
70+
return TRUE // Indicates a valid target that this base proc does not handle.
7471

75-
if(QDELETED(target))
72+
// Hunt/consume the target.
73+
. = FALSE // we handle mobs already
74+
var/mob/prey = target
75+
if(prey.stat != DEAD && (!is_friend(prey) || !handle_friend_hunting(prey)))
76+
try_attack_prey(prey)
77+
if(QDELETED(prey))
7678
set_target(null)
7779
resume_wandering()
7880
return
79-
80-
if(target.stat != DEAD)
81+
if(prey.stat != DEAD)
8182
return
82-
8383
// Eat the mob.
8484
set_target(null)
8585
resume_wandering()
86-
consume_prey(target)
86+
consume_prey(prey)
87+
88+
// Stub for hawks to return to their handler and dock with the mothership.
89+
/datum/mob_controller/passive/hunter/proc/handle_friend_hunting(mob/friend)
90+
return FALSE

code/modules/mob/grab/simple/simple_control.dm

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@
3838

3939
// Override these for mobs that will respond to instructions from a rider.
4040
/mob/living/proc/handle_rider_harm_order(mob/user, atom/target, proximity)
41-
return FALSE
41+
return istype(ai) ? ai.process_handler_target(user, target, I_FLAG_HARM) : FALSE
4242

4343
/mob/living/proc/handle_rider_grab_order(mob/user, atom/target, proximity)
44-
return FALSE
44+
return istype(ai) ? ai.process_handler_target(user, target, I_FLAG_GRAB) : FALSE
4545

4646
/mob/living/proc/handle_rider_disarm_order(mob/user, atom/target, proximity)
47-
return FALSE
47+
return istype(ai) ? ai.process_handler_target(user, target, I_FLAG_DISARM) : FALSE
4848

4949
/mob/living/proc/handle_rider_help_order(mob/user, atom/target, proximity)
50-
return FALSE
50+
return istype(ai) ? ai.process_handler_target(user, target, I_FLAG_HELP) : FALSE

code/modules/mob/living/simple_animal/hostile/slug.dm

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,11 @@
3535
/mob/living/simple_animal/hostile/slug/proc/check_friendly_species(var/mob/living/M)
3636
return istype(M) && M.faction == faction
3737

38-
/mob/living/simple_animal/hostile/slug/get_scooped(var/mob/living/target, var/mob/living/initiator)
38+
/mob/living/simple_animal/hostile/slug/get_scooped(mob/living/target, mob/living/initiator, silent = FALSE)
3939
if(target == initiator || check_friendly_species(initiator))
4040
return ..()
41-
to_chat(initiator, SPAN_WARNING("\The [src] wriggles out of your hands before you can pick it up!"))
41+
if(!silent)
42+
to_chat(initiator, SPAN_WARNING("\The [src] wriggles out of your hands before you can pick it up!"))
4243

4344
/mob/living/simple_animal/hostile/slug/proc/attach(var/mob/living/human/H)
4445
var/obj/item/clothing/suit/space/S = H.get_covering_equipped_item_by_zone(BP_CHEST)

code/modules/mob/skills/skillset.dm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ var/global/list/all_skill_verbs
3737
for(var/datum/skill_buff/SB in skill_buffs)
3838
. += SB.buffs[skill_path]
3939

40-
/datum/skillset/proc/obtain_from_mob(mob/mob)
40+
/datum/skillset/proc/obtain_from_mob(mob/living/mob)
4141
if(!istype(mob) || !skills_transferable || !mob.skillset.skills_transferable)
4242
return
4343
skill_list = mob.skillset.skill_list

code/modules/mob_holder/holder_mobs.dm

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
return species.get_holder_color(src)
1212

1313
//Mob procs for scooping up
14-
/mob/living/proc/get_scooped(var/mob/living/target, var/mob/living/initiator)
14+
/mob/living/proc/get_scooped(mob/living/target, mob/living/initiator, silent = FALSE)
1515

1616
if(!holder_type || buckled || LAZYLEN(pinned))
1717
return FALSE
@@ -23,20 +23,24 @@
2323
H.w_class = get_object_size()
2424
if(initiator == src)
2525
if(!target.equip_to_slot_if_possible(H, slot_back_str, del_on_fail=0, disable_warning=1))
26-
to_chat(initiator, SPAN_WARNING("You can't climb onto [target]!"))
26+
if(!silent)
27+
to_chat(initiator, SPAN_WARNING("You can't climb onto [target]!"))
2728
return FALSE
28-
to_chat(target, SPAN_NOTICE("\The [src] clambers onto you!"))
29-
to_chat(initiator, SPAN_NOTICE("You climb up onto \the [target]!"))
29+
if(!silent)
30+
to_chat(target, SPAN_NOTICE("\The [src] clambers onto you!"))
31+
to_chat(initiator, SPAN_NOTICE("You climb up onto \the [target]!"))
3032
else
3133
if(!ai?.scooped_by(initiator))
3234
return FALSE // The AI canceled the scooping.
3335

3436
if(!target.put_in_hands(H))
35-
to_chat(initiator, SPAN_WARNING("Your hands are full!"))
37+
if(!silent)
38+
to_chat(initiator, SPAN_WARNING("Your hands are full!"))
3639
return FALSE
3740

38-
to_chat(initiator, SPAN_NOTICE("You scoop up \the [src]!"))
39-
to_chat(src, SPAN_NOTICE("\The [initiator] scoops you up!"))
41+
if(!silent)
42+
to_chat(initiator, SPAN_NOTICE("You scoop up \the [src]!"))
43+
to_chat(src, SPAN_NOTICE("\The [initiator] scoops you up!"))
4044

4145
forceMove(H)
4246
reset_offsets(0)

0 commit comments

Comments
 (0)