forked from tgstation/tgstation
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from san7890/parrot-rework
Parrot rework
- Loading branch information
Showing
35 changed files
with
1,227 additions
and
1,111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/// The maximum number of phrases we can store in our speech buffer | ||
#define MAX_SPEECH_BUFFER_SIZE 500 | ||
/// Tendency we have to ignore radio chatter | ||
#define RADIO_IGNORE_CHANCE 10 | ||
|
||
/// Simple element that will deterministically set a value based on stuff that the source has heard and will then compel the source to repeat it. | ||
/// Requires a valid AI Blackboard. | ||
/datum/component/listen_and_repeat | ||
/// List of things that we start out having in our speech buffer | ||
var/list/desired_phrases = null | ||
/// The AI Blackboard Key we assign the value to. | ||
var/blackboard_key = null | ||
/// Probability we speak | ||
var/speech_probability = null | ||
/// Probabiliy we switch our phrase | ||
var/switch_phrase_probability = null | ||
/// List of things that we've heard and will repeat. | ||
var/list/speech_buffer = null | ||
|
||
/datum/component/listen_and_repeat/Initialize(list/desired_phrases, blackboard_key) | ||
. = ..() | ||
if(!ismovable(parent)) | ||
return COMPONENT_INCOMPATIBLE | ||
|
||
if(!isnull(desired_phrases)) | ||
LAZYADD(speech_buffer, desired_phrases) | ||
|
||
src.blackboard_key = blackboard_key | ||
|
||
RegisterSignal(parent, COMSIG_MOVABLE_PRE_HEAR, PROC_REF(on_hear)) | ||
RegisterSignal(parent, COMSIG_NEEDS_NEW_PHRASE, PROC_REF(set_new_blackboard_phrase)) | ||
RegisterSignal(parent, COMSIG_LIVING_WRITE_MEMORY, PROC_REF(on_write_memory)) | ||
RegisterSignal(parent, COMSIG_MOB_LOGIN, PROC_REF(on_login)) | ||
|
||
/// Called if a client logs in- don't want to be forced speaking while under their control (sadly) | ||
/datum/component/listen_and_repeat/proc/on_login(datum/source) | ||
SIGNAL_HANDLER | ||
qdel(src) | ||
|
||
/// Called when we hear something. | ||
/datum/component/listen_and_repeat/proc/on_hear(datum/source, list/passed_arguments) | ||
SIGNAL_HANDLER | ||
|
||
var/message = passed_arguments[HEARING_RAW_MESSAGE] | ||
var/speaker = passed_arguments[HEARING_SPEAKER] | ||
var/over_radio = !!passed_arguments[HEARING_RADIO_FREQ] | ||
if(speaker == source) // don't parrot ourselves | ||
return | ||
|
||
if(over_radio && prob(RADIO_IGNORE_CHANCE)) | ||
return | ||
|
||
var/number_of_excess_strings = LAZYLEN(speech_buffer) - MAX_SPEECH_BUFFER_SIZE | ||
if(number_of_excess_strings > 0) // only remove if we're overfull | ||
for(var/i in 1 to number_of_excess_strings) | ||
LAZYREMOVE(speech_buffer, pick(speech_buffer)) | ||
|
||
LAZYOR(speech_buffer, html_decode(message)) | ||
|
||
/// Called to set a new value for the blackboard key. | ||
/datum/component/listen_and_repeat/proc/set_new_blackboard_phrase(datum/source) | ||
SIGNAL_HANDLER | ||
var/atom/movable/atom_source = source | ||
var/datum/ai_controller/controller = atom_source.ai_controller | ||
if(!LAZYLEN(speech_buffer)) | ||
controller.clear_blackboard_key(blackboard_key) | ||
return NO_NEW_PHRASE_AVAILABLE | ||
|
||
var/selected_phrase = pick(speech_buffer) | ||
controller.set_blackboard_key(blackboard_key, selected_phrase) | ||
|
||
/// Exports all the speech buffer data to a dedicated blackboard key on the source. | ||
/datum/component/listen_and_repeat/proc/on_write_memory(datum/source, dead, gibbed) | ||
SIGNAL_HANDLER | ||
var/atom/movable/atom_source = source | ||
var/datum/ai_controller/controller = atom_source.ai_controller | ||
if(LAZYLEN(speech_buffer)) // what? well whatever let's just move on | ||
return | ||
|
||
controller.set_blackboard_key(BB_EXPORTABLE_STRING_BUFFER_LIST, speech_buffer.Copy()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.