Files
Paradise/code/datums/ai/basic_mobs/basic_subtrees/random_speech.dm
warriorstar-orion c820499f90 Basic mobs core implementation and cow migration. (#28667)
* Basic mobs core implementation and cow migration.

* fix whitespace

* uncomfortable fix for null weirdness

* update updatepaths script number

* lewc review 1

* fix delta

* Update code/datums/ai/basic_mobs/basic_ai_behaviors/tipped_reaction.dm

Co-authored-by: Luc <89928798+lewcc@users.noreply.github.com>
Signed-off-by: warriorstar-orion <orion@snowfrost.garden>

---------

Signed-off-by: warriorstar-orion <orion@snowfrost.garden>
Co-authored-by: Luc <89928798+lewcc@users.noreply.github.com>
2025-04-05 11:35:42 +00:00

64 lines
2.3 KiB
Plaintext

/datum/ai_planning_subtree/random_speech
/// The chance of an emote occurring each second
var/speech_chance = 0
/// Hearable emotes
var/list/emote_hear = list()
/// Unlike speak_emote, the list of things in this variable only show by themselves with no spoken text. IE: Ian barks, Ian yaps
var/list/emote_see = list()
/// Possible lines of speech the AI can have
var/list/speak = list()
/// The sound effects associated with this speech, if any
var/list/sound = list()
/// The possible verbs used to perform the speech, if any. Defaults to "says" elsewhere in code.
var/list/speak_verbs = list()
/datum/ai_planning_subtree/random_speech/New()
. = ..()
if(speak)
speak = string_list(speak)
if(sound)
sound = string_list(sound)
if(emote_hear)
emote_hear = string_list(emote_hear)
if(emote_see)
emote_see = string_list(emote_see)
if(speak_verbs)
speak_verbs = string_list(speak_verbs)
/datum/ai_planning_subtree/random_speech/select_behaviors(datum/ai_controller/controller, seconds_per_tick)
if(!SPT_PROB(speech_chance, seconds_per_tick))
return
speak(controller)
/// Actually perform an action
/datum/ai_planning_subtree/random_speech/proc/speak(datum/ai_controller/controller)
var/audible_emotes_length = length(emote_hear)
var/non_audible_emotes_length = length(emote_see)
var/speak_lines_length = length(speak)
var/total_choices_length = audible_emotes_length + non_audible_emotes_length + speak_lines_length
if(total_choices_length == 0)
return
var/random_number_in_range = rand(1, total_choices_length)
var/sound_to_play = length(sound) > 0 ? pick(sound) : null
if(random_number_in_range <= audible_emotes_length)
controller.queue_behavior(/datum/ai_behavior/perform_emote, pick(emote_hear), sound_to_play)
else if(random_number_in_range <= (audible_emotes_length + non_audible_emotes_length))
controller.queue_behavior(/datum/ai_behavior/perform_emote, pick(emote_see))
else
var/speak_verb = "says"
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.")