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:
warriorstar-orion
2025-04-15 10:45:56 -04:00
committed by GitHub
parent 5da3694877
commit efc8adb6dd
44 changed files with 1190 additions and 69 deletions
@@ -19,6 +19,7 @@ RESTRICT_TYPE(/mob/living/basic)
name = "basic mob"
desc = "If you can see this, make an issue report on GitHub."
healable = TRUE
icon = 'icons/mob/animal.dmi'
var/basic_mob_flags
@@ -110,6 +111,9 @@ RESTRICT_TYPE(/mob/living/basic)
// Attack related vars.
// Unclear how much of this should either be componentized or pulled to /mob/living
/// Sound played when the critter attacks.
var/attack_sound = 'sound/weapons/punch1.ogg'
/// Sound played when the critter is attacked.
var/attacked_sound = 'sound/weapons/punch1.ogg'
/// The amount of damage done to the mob when hand-attacked on harm intent.
var/harm_intent_damage = 3
@@ -117,6 +121,20 @@ RESTRICT_TYPE(/mob/living/basic)
var/list/damage_coeff = list(BRUTE = 1, BURN = 1, TOX = 1, STAMINA = 0, OXY = 1)
/// Minimum force required to deal any damage
var/force_threshold = 0
/// Lower bound of damage done by unarmed melee attacks.
var/melee_damage_lower = 0
/// Upper bound of damage done by unarmed melee attacks.
var/melee_damage_upper = 0
/// How much damage this simple animal does to objects, if any
var/obj_damage = 0
/// Flat armour reduction, occurs after percentage armour penetration.
var/armour_penetration_flat = 0
/// Percentage armour reduction, happens before flat armour reduction.
var/armour_penetration_percentage = 0
/// Damage type of a simple mob's melee attack, should it do damage.
var/melee_damage_type = BRUTE
/// How often can you melee attack?
var/melee_attack_cooldown = 2 SECONDS
/mob/living/basic/Initialize(mapload)
. = ..()
@@ -164,6 +182,25 @@ RESTRICT_TYPE(/mob/living/basic)
/mob/living/basic/proc/valid_respawn_target_for(mob/user)
return FALSE
/mob/living/basic/resolve_unarmed_attack(atom/attack_target, list/modifiers)
melee_attack(attack_target, modifiers)
/mob/living/basic/proc/melee_attack(atom/target, list/modifiers, ignore_cooldown = FALSE)
if(!early_melee_attack(target, modifiers, ignore_cooldown))
return FALSE
var/result = target.attack_basic_mob(src, modifiers)
SEND_SIGNAL(src, COMSIG_HOSTILE_POST_ATTACKINGTARGET, target, result)
return result
/mob/living/basic/proc/early_melee_attack(atom/target, list/modifiers, ignore_cooldown = FALSE)
face_atom(target)
if(!ignore_cooldown)
changeNext_move(melee_attack_cooldown)
if(SEND_SIGNAL(src, COMSIG_HOSTILE_PRE_ATTACKINGTARGET, target, Adjacent(target), modifiers) & COMPONENT_HOSTILE_NO_ATTACK)
return FALSE
return TRUE
/mob/living/basic/handle_environment(datum/gas_mixture/readonly_environment)
SEND_SIGNAL(src, COMSIG_SIMPLEANIMAL_HANDLE_ENVIRONMENT, readonly_environment)
@@ -1,7 +1,30 @@
/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.")
/datum/ai_controller/basic_controller/cow
blackboard = list(
BB_TARGETING_STRATEGY = /datum/targeting_strategy/basic,
BB_BASIC_MOB_TIP_REACTING = FALSE,
BB_BASIC_MOB_TIPPER = null,
)
ai_traits = AI_FLAG_STOP_MOVING_WHEN_PULLED
ai_movement = /datum/ai_movement/basic_avoidance
idle_behavior = /datum/idle_behavior/idle_random_walk
planning_subtrees = list(
/datum/ai_planning_subtree/tip_reaction,
/datum/ai_planning_subtree/find_food,
/datum/ai_planning_subtree/random_speech/cow,
)
/mob/living/basic/cow
name = "cow"
desc = "Known for their milk, just don't tip them over."
icon = 'icons/mob/animal.dmi'
icon_state = "cow"
icon_living = "cow"
icon_dead = "cow_dead"
@@ -1,15 +0,0 @@
/datum/ai_controller/basic_controller/cow
blackboard = list(
BB_TARGETING_STRATEGY = /datum/targeting_strategy/basic,
BB_BASIC_MOB_TIP_REACTING = FALSE,
BB_BASIC_MOB_TIPPER = null,
)
ai_traits = AI_FLAG_STOP_MOVING_WHEN_PULLED
ai_movement = /datum/ai_movement/basic_avoidance
idle_behavior = /datum/idle_behavior/idle_random_walk
planning_subtrees = list(
/datum/ai_planning_subtree/tip_reaction,
/datum/ai_planning_subtree/find_food,
/datum/ai_planning_subtree/random_speech/cow,
)
+50
View File
@@ -0,0 +1,50 @@
/datum/ai_planning_subtree/random_speech/pig
speech_chance = 2
speak = list("oink?", "oink", "OINK")
sound = list(
'sound/creatures/pig/pig1.ogg',
'sound/creatures/pig/pig2.ogg'
)
emote_hear = list("oinks.")
emote_see = list("rolls around.")
/datum/ai_controller/basic_controller/pig
blackboard = list(
BB_TARGETING_STRATEGY = /datum/targeting_strategy/basic,
)
ai_traits = AI_FLAG_STOP_MOVING_WHEN_PULLED
ai_movement = /datum/ai_movement/basic_avoidance
idle_behavior = /datum/idle_behavior/idle_random_walk
planning_subtrees = list(
/datum/ai_planning_subtree/find_nearest_thing_which_attacked_me_to_flee,
/datum/ai_planning_subtree/flee_target,
/datum/ai_planning_subtree/target_retaliate,
/datum/ai_planning_subtree/basic_melee_attack_subtree,
/datum/ai_planning_subtree/random_speech/pig,
)
/mob/living/basic/pig
name = "pig"
desc = "Oink oink."
icon_state = "pig"
icon_living = "pig"
icon_dead = "pig_dead"
ai_controller = /datum/ai_controller/basic_controller/pig
see_in_dark = 6
butcher_results = list(/obj/item/food/meat/ham = 6)
health = 50
maxHealth = 50
melee_damage_lower = 1
melee_damage_upper = 2
mob_biotypes = MOB_ORGANIC | MOB_BEAST
gold_core_spawnable = FRIENDLY_SPAWN
blood_volume = BLOOD_VOLUME_NORMAL
unintelligble_phrases = list("Oink?", "Oink", "OINK")
unintelligble_speak_verbs = list("oinks")
/mob/living/basic/pig/Initialize(mapload)
. = ..()
AddElement(/datum/element/ai_retaliate)
AddElement(/datum/element/ai_flee_while_injured)
AddComponent(/datum/component/footstep, FOOTSTEP_MOB_SHOE)
@@ -717,6 +717,21 @@ emp_act
apply_damage(damage, M.melee_damage_type, affecting, armor)
updatehealth("animal attack")
/mob/living/carbon/human/handle_basic_attack(mob/living/basic/attacker, modifiers)
. = ..()
if(.)
var/damage = rand(attacker.melee_damage_lower, attacker.melee_damage_upper)
if(check_shields(attacker, damage, "[attacker.name]", MELEE_ATTACK, attacker.armour_penetration_flat, attacker.armour_penetration_percentage))
return FALSE
var/dam_zone = pick("head", "chest", "groin", "l_arm", "l_hand", "r_arm", "r_hand", "l_leg", "l_foot", "r_leg", "r_foot")
var/obj/item/organ/external/affecting = get_organ(ran_zone(dam_zone))
if(!affecting)
affecting = get_organ("chest")
affecting.add_autopsy_data(attacker.name, damage) // Add the mob's name to the autopsy data
var/armor = run_armor_check(affecting, MELEE, armour_penetration_flat = attacker.armour_penetration_flat, armour_penetration_percentage = attacker.armour_penetration_percentage)
apply_damage(damage, attacker.melee_damage_type, affecting, armor)
updatehealth("basicmob attack")
/mob/living/carbon/human/attack_slime(mob/living/simple_animal/slime/M)
if(..()) //successful slime attack
var/damage = rand(5, 25)
+20
View File
@@ -339,6 +339,8 @@
return TRUE
/mob/living/attack_animal(mob/living/simple_animal/M)
. = ..()
M.face_atom(src)
if((M.a_intent == INTENT_HELP && M.ckey) || M.melee_damage_upper == 0)
M.custom_emote(EMOTE_VISIBLE, "[M.friendly] [src].")
@@ -355,6 +357,24 @@
add_attack_logs(M, src, "Animal attacked")
return TRUE
// TODO: Probably a bunch of this shit doesn't need to be here but I don't feel
// like sorting it out right now
/mob/living/handle_basic_attack(mob/living/basic/attacker, modifiers)
if((attacker.a_intent == INTENT_HELP && attacker.ckey) || attacker.melee_damage_upper == 0)
attacker.custom_emote(EMOTE_VISIBLE, "[attacker.friendly_verb_continuous] [src].")
return FALSE
if(HAS_TRAIT(attacker, TRAIT_PACIFISM))
to_chat(attacker, "<span class='warning'>You don't want to hurt anyone!</span>")
return FALSE
if(attacker.attack_sound)
playsound(loc, attacker.attack_sound, 50, TRUE, 1)
attacker.do_attack_animation(src)
visible_message("<span class='danger'>[attacker] [attacker.attack_verb_continuous] [src]!</span>", \
"<span class='userdanger'>[attacker] [attacker.attack_verb_continuous] [src]!</span>")
add_attack_logs(attacker, src, "Basicmob attacked")
return TRUE
/mob/living/attack_larva(mob/living/carbon/alien/larva/L)
switch(L.a_intent)
if(INTENT_HELP)
@@ -305,32 +305,6 @@ GLOBAL_VAR_INIT(chicken_count, 0)
/mob/living/simple_animal/chicken/featherbottom/npc_safe(mob/user)
return FALSE
/mob/living/simple_animal/pig
name = "pig"
desc = "Oink oink."
icon_state = "pig"
icon_living = "pig"
icon_dead = "pig_dead"
speak = list("oink?","oink","OINK")
speak_emote = list("oinks")
// emote_hear = list("brays")
emote_see = list("rolls around")
speak_chance = 1
turns_per_move = 5
see_in_dark = 6
butcher_results = list(/obj/item/food/meat/ham = 6)
response_help = "pets"
response_disarm = "gently pushes aside"
response_harm = "kicks"
attacktext = "kicks"
health = 50
maxHealth = 50
can_collar = TRUE
mob_biotypes = MOB_ORGANIC | MOB_BEAST
gold_core_spawnable = FRIENDLY_SPAWN
blood_volume = BLOOD_VOLUME_NORMAL
footstep_type = FOOTSTEP_MOB_SHOE
/mob/living/simple_animal/turkey
name = "turkey"
desc = "Benjamin Franklin would be proud."