mirror of
https://github.com/ParadiseSS13/Paradise.git
synced 2026-07-10 14:44:05 +01:00
Basic mobs targeting, attacks, and pig migration. (#28987)
* Basic mobs targeting, attacks, and pig migration. * run updatepaths * fix duplicate macro def * Update code/datums/ai/basic_mobs/basic_ai_behaviors/basic_attacking.dm Co-authored-by: Burzah <116982774+Burzah@users.noreply.github.com> Signed-off-by: warriorstar-orion <orion@snowfrost.garden> --------- Signed-off-by: warriorstar-orion <orion@snowfrost.garden> Co-authored-by: Burzah <116982774+Burzah@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
5da3694877
commit
efc8adb6dd
@@ -0,0 +1,25 @@
|
||||
/// Try to escape from your current target, without performing any other actions.
|
||||
/datum/ai_planning_subtree/flee_target
|
||||
/// Behaviour to execute in order to flee
|
||||
var/flee_behaviour = /datum/ai_behavior/run_away_from_target
|
||||
/// Blackboard key in which to store selected target
|
||||
var/target_key = BB_BASIC_MOB_CURRENT_TARGET
|
||||
/// Blackboard key in which to store selected target's hiding place
|
||||
var/hiding_place_key = BB_BASIC_MOB_CURRENT_TARGET_HIDING_LOCATION
|
||||
|
||||
/datum/ai_planning_subtree/flee_target/select_behaviors(datum/ai_controller/controller, seconds_per_tick)
|
||||
. = ..()
|
||||
var/atom/flee_from = controller.blackboard[target_key]
|
||||
if(!should_flee(controller, flee_from))
|
||||
return
|
||||
var/flee_distance = controller.blackboard[BB_BASIC_MOB_FLEE_DISTANCE] || DEFAULT_BASIC_FLEE_DISTANCE
|
||||
if(get_dist(controller.pawn, flee_from) >= flee_distance)
|
||||
return
|
||||
|
||||
controller.queue_behavior(flee_behaviour, target_key, hiding_place_key)
|
||||
return SUBTREE_RETURN_FINISH_PLANNING //we gotta get out of here.
|
||||
|
||||
/datum/ai_planning_subtree/flee_target/proc/should_flee(datum/ai_controller/controller, atom/flee_from)
|
||||
if(controller.blackboard[BB_BASIC_MOB_STOP_FLEEING] || QDELETED(flee_from))
|
||||
return FALSE
|
||||
return TRUE
|
||||
@@ -53,11 +53,3 @@
|
||||
if(length(speak_verbs))
|
||||
speak_verb = pick(speak_verbs)
|
||||
controller.queue_behavior(/datum/ai_behavior/perform_speech, pick(speak), sound_to_play, speak_verb)
|
||||
|
||||
/datum/ai_planning_subtree/random_speech/cow
|
||||
speech_chance = 2
|
||||
speak = list("Moo?", "Moo", "MOOOOOO")
|
||||
speak_verbs = list("moos", "moos hauntingly")
|
||||
sound = list('sound/creatures/cow.ogg')
|
||||
emote_hear = list("brays.")
|
||||
emote_see = list("shakes her head.")
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
/datum/ai_planning_subtree/basic_melee_attack_subtree
|
||||
/// What do we do in order to attack someone?
|
||||
var/datum/ai_behavior/basic_melee_attack/melee_attack_behavior = /datum/ai_behavior/basic_melee_attack
|
||||
/// Is this the last thing we do? (if we set a movement target, this will usually be yes)
|
||||
var/end_planning = TRUE
|
||||
|
||||
/datum/ai_planning_subtree/basic_melee_attack_subtree/select_behaviors(datum/ai_controller/controller, seconds_per_tick)
|
||||
. = ..()
|
||||
if(!controller.blackboard_key_exists(BB_BASIC_MOB_CURRENT_TARGET))
|
||||
return
|
||||
controller.queue_behavior(melee_attack_behavior, BB_BASIC_MOB_CURRENT_TARGET, BB_TARGETING_STRATEGY, BB_BASIC_MOB_CURRENT_TARGET_HIDING_LOCATION)
|
||||
if(end_planning)
|
||||
return SUBTREE_RETURN_FINISH_PLANNING // we are going into battle...no distractions.
|
||||
@@ -0,0 +1,25 @@
|
||||
/// Find the nearest thing which we assume is hostile and set it as the flee target
|
||||
/datum/ai_planning_subtree/simple_find_nearest_target_to_flee
|
||||
|
||||
/datum/ai_planning_subtree/simple_find_nearest_target_to_flee/select_behaviors(datum/ai_controller/controller, seconds_per_tick)
|
||||
. = ..()
|
||||
if(controller.blackboard[BB_BASIC_MOB_STOP_FLEEING])
|
||||
return
|
||||
controller.queue_behavior(/datum/ai_behavior/find_potential_targets/nearest, BB_BASIC_MOB_CURRENT_TARGET, BB_TARGETING_STRATEGY, BB_BASIC_MOB_CURRENT_TARGET_HIDING_LOCATION)
|
||||
|
||||
/// Find the nearest thing on our list of 'things which have done damage to me' and set it as the flee target
|
||||
/datum/ai_planning_subtree/find_nearest_thing_which_attacked_me_to_flee
|
||||
///the targeting strategy we use
|
||||
var/targeting_key = BB_TARGETING_STRATEGY
|
||||
///what key should we set the target as
|
||||
var/target_key = BB_BASIC_MOB_CURRENT_TARGET
|
||||
|
||||
/datum/ai_planning_subtree/find_nearest_thing_which_attacked_me_to_flee/select_behaviors(datum/ai_controller/controller, seconds_per_tick)
|
||||
. = ..()
|
||||
if(controller.blackboard[BB_BASIC_MOB_STOP_FLEEING])
|
||||
return
|
||||
controller.queue_behavior(/datum/ai_behavior/target_from_retaliate_list/nearest, BB_BASIC_MOB_RETALIATE_LIST, target_key, targeting_key, BB_BASIC_MOB_CURRENT_TARGET_HIDING_LOCATION)
|
||||
|
||||
/datum/ai_planning_subtree/find_nearest_thing_which_attacked_me_to_flee/from_flee_key
|
||||
target_key = BB_BASIC_MOB_FLEE_TARGET
|
||||
targeting_key = BB_FLEE_TARGETING_STRATEGY
|
||||
@@ -0,0 +1,80 @@
|
||||
/// Sets the BB target to a mob which you can see and who has recently attacked you
|
||||
/datum/ai_planning_subtree/target_retaliate
|
||||
operational_datums = list(/datum/element/ai_retaliate, /datum/component/ai_retaliate_advanced)
|
||||
/// Blackboard key which tells us how to select valid targets
|
||||
var/targeting_strategy_key = BB_TARGETING_STRATEGY
|
||||
/// Blackboard key in which to store selected target
|
||||
var/target_key = BB_BASIC_MOB_CURRENT_TARGET
|
||||
/// Blackboard key in which to store selected target's hiding place
|
||||
var/hiding_place_key = BB_BASIC_MOB_CURRENT_TARGET_HIDING_LOCATION
|
||||
/// do we check for faction?
|
||||
var/check_faction = FALSE
|
||||
|
||||
/datum/ai_planning_subtree/target_retaliate/select_behaviors(datum/ai_controller/controller, seconds_per_tick)
|
||||
controller.queue_behavior(/datum/ai_behavior/target_from_retaliate_list, BB_BASIC_MOB_RETALIATE_LIST, target_key, targeting_strategy_key, hiding_place_key, check_faction)
|
||||
|
||||
/datum/ai_planning_subtree/target_retaliate/check_faction
|
||||
check_faction = TRUE
|
||||
|
||||
/// Places a mob which you can see and who has recently attacked you into some 'run away from this' AI keys
|
||||
/// Can use a different targeting strategy than you use to select attack targets
|
||||
/// Not required if fleeing is the only target behaviour or uses the same target datum
|
||||
/datum/ai_planning_subtree/target_retaliate/to_flee
|
||||
targeting_strategy_key = BB_FLEE_TARGETING_STRATEGY
|
||||
target_key = BB_BASIC_MOB_FLEE_TARGET
|
||||
hiding_place_key = BB_BASIC_MOB_FLEE_TARGET_HIDING_LOCATION
|
||||
|
||||
/**
|
||||
* Picks a target from a provided list of atoms who have been pissing you off
|
||||
* You will probably need /datum/element/ai_retaliate to take advantage of this unless you're populating the blackboard yourself
|
||||
*/
|
||||
/datum/ai_behavior/target_from_retaliate_list
|
||||
action_cooldown = 2 SECONDS
|
||||
/// How far can we see stuff?
|
||||
var/vision_range = 9
|
||||
|
||||
/datum/ai_behavior/target_from_retaliate_list/perform(seconds_per_tick, datum/ai_controller/controller, shitlist_key, target_key, targeting_strategy_key, hiding_location_key, check_faction)
|
||||
var/mob/living/living_mob = controller.pawn
|
||||
var/datum/targeting_strategy/targeting_strategy = GET_TARGETING_STRATEGY(controller.blackboard[targeting_strategy_key])
|
||||
if(!targeting_strategy)
|
||||
. = AI_BEHAVIOR_DELAY
|
||||
CRASH("No target datum was supplied in the blackboard for [controller.pawn]")
|
||||
|
||||
var/list/shitlist = controller.blackboard[shitlist_key]
|
||||
var/atom/existing_target = controller.blackboard[target_key]
|
||||
|
||||
if(!check_faction)
|
||||
controller.set_blackboard_key(BB_TEMPORARILY_IGNORE_FACTION, TRUE)
|
||||
|
||||
if(!QDELETED(existing_target) && (locate(existing_target) in shitlist) && targeting_strategy.can_attack(living_mob, existing_target, vision_range))
|
||||
return AI_BEHAVIOR_DELAY | AI_BEHAVIOR_SUCCEEDED
|
||||
|
||||
var/list/enemies_list = list()
|
||||
for(var/mob/living/potential_target as anything in shitlist)
|
||||
if(!targeting_strategy.can_attack(living_mob, potential_target, vision_range))
|
||||
continue
|
||||
enemies_list += potential_target
|
||||
|
||||
if(!length(enemies_list))
|
||||
return AI_BEHAVIOR_DELAY | AI_BEHAVIOR_FAILED
|
||||
|
||||
var/atom/new_target = pick_final_target(controller, enemies_list)
|
||||
controller.set_blackboard_key(target_key, new_target)
|
||||
|
||||
var/atom/potential_hiding_location = targeting_strategy.find_hidden_mobs(living_mob, new_target)
|
||||
|
||||
if(potential_hiding_location) //If they're hiding inside of something, we need to know so we can go for that instead initially.
|
||||
controller.set_blackboard_key(hiding_location_key, potential_hiding_location)
|
||||
|
||||
return AI_BEHAVIOR_DELAY | AI_BEHAVIOR_SUCCEEDED
|
||||
|
||||
/// Returns the desired final target from the filtered list of enemies
|
||||
/datum/ai_behavior/target_from_retaliate_list/proc/pick_final_target(datum/ai_controller/controller, list/enemies_list)
|
||||
return pick(enemies_list)
|
||||
|
||||
/datum/ai_behavior/target_from_retaliate_list/finish_action(datum/ai_controller/controller, succeeded, shitlist_key, target_key, targeting_strategy_key, hiding_location_key, check_faction)
|
||||
. = ..()
|
||||
if(succeeded || check_faction)
|
||||
return
|
||||
var/usually_ignores_faction = controller.blackboard[BB_ALWAYS_IGNORE_FACTION] || FALSE
|
||||
controller.set_blackboard_key(BB_TEMPORARILY_IGNORE_FACTION, usually_ignores_faction)
|
||||
Reference in New Issue
Block a user