Skip to content

Commit a0148f4

Browse files
authored
Ai slowdown (#716)
1 parent dfd8c87 commit a0148f4

7 files changed

Lines changed: 61 additions & 17 deletions

File tree

code/__DEFINES/ai/ai_blackboard.dm

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@
4646

4747
///Basic Mob Keys
4848

49+
/// How long to wait before attacking a target in range
50+
#define BB_BASIC_MOB_MELEE_DELAY "BB_basic_melee_delay"
51+
/// Key used to store the time we can actually attack
52+
#define BB_BASIC_MOB_MELEE_COOLDOWN_TIMER "BB_basic_melee_cooldown_timer"
53+
4954
///Targeting subtrees
5055
#define BB_BASIC_MOB_CURRENT_TARGET "BB_basic_current_target"
5156
#define BB_BASIC_MOB_CURRENT_TARGET_HIDING_LOCATION "BB_basic_current_target_hiding_location"

code/datums/ai/_ai_controller.dm

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,32 @@ multiple modular subtrees with behaviors
173173
return FALSE
174174
return TRUE
175175

176+
///Can this pawn interact with objects?
177+
/datum/ai_controller/proc/ai_can_interact()
178+
SHOULD_CALL_PARENT(TRUE)
179+
return !QDELETED(pawn)
180+
181+
///Interact with objects
182+
/datum/ai_controller/proc/ai_interact(target, combat_mode, list/modifiers)
183+
if(!ai_can_interact())
184+
return FALSE
185+
186+
var/atom/final_target = isdatum(target) ? target : blackboard[target] //incase we got a blackboard key instead
187+
188+
if(QDELETED(final_target))
189+
return FALSE
190+
var/params = list2params(modifiers)
191+
var/mob/living/living_pawn = pawn
192+
if(isnull(combat_mode))
193+
living_pawn.ClickOn(final_target, params)
194+
return TRUE
195+
196+
var/old_combat_mode = living_pawn.combat_mode
197+
living_pawn.set_combat_mode(combat_mode)
198+
living_pawn.ClickOn(final_target, params)
199+
living_pawn.set_combat_mode(old_combat_mode)
200+
return TRUE
201+
176202
///Runs any actions that are currently running
177203
/datum/ai_controller/process(seconds_per_tick)
178204

code/datums/ai/basic_mobs/basic_ai_behaviors/basic_attacking.dm

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1+
/// Amount of time to wait before executing attack if not specified
2+
#define DEFAULT_ATTACK_DELAY (0.4 SECONDS)
3+
14
/datum/ai_behavior/basic_melee_attack
25
action_cooldown = 0.2 SECONDS // We gotta check unfortunately often because we're in a race condition with nextmove
3-
behavior_flags = AI_BEHAVIOR_REQUIRE_MOVEMENT | AI_BEHAVIOR_REQUIRE_REACH | AI_BEHAVIOR_CAN_PLAN_DURING_EXECUTION
6+
behavior_flags = AI_BEHAVIOR_REQUIRE_MOVEMENT | AI_BEHAVIOR_MOVE_AND_PERFORM | AI_BEHAVIOR_CAN_PLAN_DURING_EXECUTION
47
///do we finish this action after hitting once?
58
var/terminate_after_action = FALSE
69

710
/datum/ai_behavior/basic_melee_attack/setup(datum/ai_controller/controller, target_key, targeting_strategy_key, hiding_location_key)
811
. = ..()
912
if(!controller.blackboard[targeting_strategy_key])
1013
CRASH("No targeting strategy was supplied in the blackboard for [controller.pawn]")
11-
1214
//Hiding location is priority
1315
var/atom/target = controller.blackboard[hiding_location_key] || controller.blackboard[target_key]
1416
if(QDELETED(target))
@@ -17,34 +19,45 @@
1719
set_movement_target(controller, target)
1820

1921
/datum/ai_behavior/basic_melee_attack/perform(seconds_per_tick, datum/ai_controller/controller, target_key, targeting_strategy_key, hiding_location_key)
22+
var/atom/target = controller.blackboard[target_key]
23+
if (isnull(target))
24+
return AI_BEHAVIOR_DELAY | AI_BEHAVIOR_FAILED
25+
var/atom/movable/movablepawn = controller.pawn
26+
if (!movablepawn.CanReach(target))
27+
controller.clear_blackboard_key(BB_BASIC_MOB_MELEE_COOLDOWN_TIMER)
28+
return AI_BEHAVIOR_INSTANT
29+
30+
var/can_attack_time = controller.blackboard[BB_BASIC_MOB_MELEE_COOLDOWN_TIMER]
31+
if (isnull(can_attack_time))
32+
var/blackboard_delay = controller.blackboard[BB_BASIC_MOB_MELEE_DELAY]
33+
var/attack_delay = isnull(blackboard_delay) ? DEFAULT_ATTACK_DELAY : blackboard_delay
34+
controller.set_blackboard_key(BB_BASIC_MOB_MELEE_COOLDOWN_TIMER, world.time + attack_delay)
35+
return AI_BEHAVIOR_INSTANT
36+
if (can_attack_time > world.time)
37+
return AI_BEHAVIOR_INSTANT
38+
2039
if (isliving(controller.pawn))
2140
var/mob/living/pawn = controller.pawn
2241
if (world.time < pawn.next_move)
2342
return AI_BEHAVIOR_INSTANT
2443

25-
var/mob/living/basic/basic_mob = controller.pawn
26-
//targeting strategy will kill the action if not real anymore
27-
var/atom/target = controller.blackboard[target_key]
2844
var/datum/targeting_strategy/targeting_strategy = GET_TARGETING_STRATEGY(controller.blackboard[targeting_strategy_key])
29-
30-
if(!targeting_strategy.can_attack(basic_mob, target))
45+
if(!targeting_strategy.can_attack(controller.pawn, target))
3146
return AI_BEHAVIOR_DELAY | AI_BEHAVIOR_FAILED
3247

33-
var/hiding_target = targeting_strategy.find_hidden_mobs(basic_mob, target) //If this is valid, theyre hidden in something!
48+
var/hiding_target = targeting_strategy.find_hidden_mobs(controller.pawn, target) //If this is valid, theyre hidden in something!
3449

3550
controller.set_blackboard_key(hiding_location_key, hiding_target)
3651

37-
if(hiding_target) //Slap it!
38-
basic_mob.melee_attack(hiding_target)
39-
else
40-
basic_mob.melee_attack(target)
41-
52+
var/atom/final_target = hiding_target || target
53+
controller.ai_interact(target = final_target, combat_mode = TRUE)
4254
if(terminate_after_action)
4355
return AI_BEHAVIOR_DELAY | AI_BEHAVIOR_SUCCEEDED
4456
return AI_BEHAVIOR_DELAY
4557

4658
/datum/ai_behavior/basic_melee_attack/finish_action(datum/ai_controller/controller, succeeded, target_key, targeting_strategy_key, hiding_location_key)
4759
. = ..()
60+
controller.clear_blackboard_key(BB_BASIC_MOB_MELEE_COOLDOWN_TIMER)
4861
if(!succeeded)
4962
controller.clear_blackboard_key(target_key)
5063

@@ -66,6 +79,8 @@
6679

6780
/datum/ai_behavior/basic_ranged_attack/setup(datum/ai_controller/controller, target_key, targeting_strategy_key, hiding_location_key)
6881
. = ..()
82+
if(HAS_TRAIT(controller.pawn, TRAIT_HANDS_BLOCKED))
83+
return FALSE
6984
var/atom/target = controller.blackboard[hiding_location_key] || controller.blackboard[target_key]
7085
if(QDELETED(target))
7186
return FALSE
@@ -147,3 +162,5 @@
147162

148163
/datum/ai_behavior/basic_ranged_attack/avoid_friendly_fire
149164
avoid_friendly_fire = TRUE
165+
166+
#undef DEFAULT_ATTACK_DELAY

code/modules/mob/living/basic/icemoon/ice_whelp/ice_whelp.dm

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343

4444
AddElement(/datum/element/footstep, FOOTSTEP_MOB_HEAVY)
4545
AddComponent(/datum/component/basic_mob_ability_telegraph)
46-
AddComponent(/datum/component/basic_mob_attack_telegraph, telegraph_duration = 0.6 SECONDS)
4746

4847
RegisterSignal(src, COMSIG_HOSTILE_PRE_ATTACKINGTARGET, PROC_REF(pre_attack))
4948

code/modules/mob/living/basic/icemoon/wolf/wolf.dm

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@
5959
AddElement(/datum/element/ai_flee_while_injured)
6060
AddElement(/datum/element/ai_retaliate)
6161
AddComponent(/datum/component/basic_mob_ability_telegraph)
62-
AddComponent(/datum/component/basic_mob_attack_telegraph, telegraph_duration = 0.6 SECONDS)
6362

6463
if(can_tame)
6564
make_tameable()

code/modules/mob/living/basic/lavaland/basilisk/basilisk.dm

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929

3030
/mob/living/basic/mining/basilisk/Initialize(mapload)
3131
. = ..()
32-
AddComponent(/datum/component/basic_mob_attack_telegraph)
3332
ranged_attacks = AddComponent(/datum/component/ranged_attacks, projectile_type = /obj/projectile/temp/watcher, projectile_sound = 'sound/weapons/pierce.ogg')
3433
RegisterSignal(src, COMSIG_MOVABLE_MOVED, PROC_REF(check_lava))
3534

code/modules/mob/living/basic/lavaland/goliath/goliath.dm

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@
6565
)
6666

6767
AddComponent(/datum/component/ai_target_timer)
68-
AddComponent(/datum/component/basic_mob_attack_telegraph)
6968
AddComponentFrom(INNATE_TRAIT, /datum/component/shovel_hands)
7069
if (tameable)
7170
AddComponent(\

0 commit comments

Comments
 (0)