Skip to content

Commit

Permalink
if you give a monkey an instrument, it will begin playing the donkey …
Browse files Browse the repository at this point in the history
…kong theme (tgstation#61726)
  • Loading branch information
tralezab committed Sep 27, 2021
1 parent 6b53159 commit d9ede13
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 8 deletions.
9 changes: 8 additions & 1 deletion code/__DEFINES/ai.dm
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@
//Generic BB keys
#define BB_CURRENT_MIN_MOVE_DISTANCE "min_move_distance"

//for songs

///song datum blackboard, set by instrument subtrees
#define BB_SONG_DATUM "BB_SONG_DATUM"
///song lines blackboard, set by default on controllers
#define BB_SONG_LINES "song_lines"


// Monkey AI controller blackboard keys

#define BB_MONKEY_AGGRESSIVE "BB_monkey_aggressive"
Expand All @@ -53,7 +61,6 @@
#define BB_MONKEY_RECRUIT_COOLDOWN "BB_monkey_recruit_cooldown"
#define BB_MONKEY_NEXT_HUNGRY "BB_monkey_next_hungry"


///Haunted item controller defines

///Chance for haunted item to haunt someone
Expand Down
6 changes: 6 additions & 0 deletions code/__DEFINES/song.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#define MUSICIAN_HEARCHECK_MINDELAY 4
#define MUSIC_MAXLINES 1000
#define MUSIC_MAXLINECHARS 300

///it's what monkeys play!
#define MONKEY_SONG "BPM: 200\nC4/0,14,C,A4-F2,F3,A3,F-F2,A-F,F4,G4,F,D4-Bb2-G2\nD3,G3,D-G2,G3-G2,D,D4-G3,D,B4-B2,G,B3,G-B2,B3-B2\nG4,A4,G,E4-C3,E3,G3,E-C,G-C,E,E4-G,E,C5-E-A3,C4\nA-E3,C,E4-C3,A4-C4,B4-A3-A2,C5-C4,D5-F-B3,D4,B-F3\nD,F4-D3,D4,F-B-B2,G4-D,A4-C-F3,F,C/2,B3/2,A3-C3/2\nB/2,C4,E-C3,F4,G-C,F-F3,F-C,C4/2,B/2,A-A2/2,G3/2\nF/I"
Original file line number Diff line number Diff line change
Expand Up @@ -280,4 +280,29 @@
living_pawn.say(speech, forced = "AI Controller")
finish_action(controller, TRUE)

//song behaviors

/datum/ai_behavior/setup_instrument

/datum/ai_behavior/setup_instrument/perform(delta_time, datum/ai_controller/controller, song_datum_key, song_lines_key)
. = ..()

var/datum/song/song = controller.blackboard[song_datum_key]
var/song_lines = controller.blackboard[song_lines_key]

//just in case- it won't do anything if the instrument isn't playing
song.stop_playing()
song.ParseSong(song_lines)
song.repeat = 10
song.volume = song.max_volume - 10
finish_action(controller, TRUE)

/datum/ai_behavior/play_instrument

/datum/ai_behavior/play_instrument/perform(delta_time, datum/ai_controller/controller, song_datum_key)
. = ..()

var/datum/song/song = controller.blackboard[song_datum_key]

song.start_playing(controller.pawn)
finish_action(controller, TRUE)
16 changes: 16 additions & 0 deletions code/datums/ai/generic/generic_subtrees.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/datum/ai_planning_subtree/play_instrument/SelectBehaviors(datum/ai_controller/monkey/controller, delta_time)
var/mob/living/living_pawn = controller.pawn
var/obj/item/instrument/song_player = locate(/obj/item/instrument) in living_pawn.held_items
if(!song_player)
controller.blackboard[BB_SONG_DATUM] = null
return //we can't play a song since we do not have an instrument

controller.blackboard[BB_SONG_DATUM] = song_player.song

var/list/donkey_kong_lines = splittext(MONKEY_SONG, "\n")
popleft(donkey_kong_lines) //remove BPM as it is parsed out
if(!compare_list(song_player.song.lines, donkey_kong_lines) || !song_player.song.repeat)
controller.queue_behavior(/datum/ai_behavior/setup_instrument, BB_SONG_DATUM, BB_SONG_LINES)

if(!song_player.song.playing) //we may stop playing if we weren't playing before, were setting up dk theme, or ran out of repeats (also causing setup behavior)
controller.queue_behavior(/datum/ai_behavior/play_instrument, BB_SONG_DATUM)
9 changes: 7 additions & 2 deletions code/datums/ai/monkey/monkey_controller.dm
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ have ways of interacting with a specific mob and control it.

/datum/ai_controller/monkey
movement_delay = 0.4 SECONDS
planning_subtrees = list(/datum/ai_planning_subtree/monkey_tree)
planning_subtrees = list(
/datum/ai_planning_subtree/monkey_tree,
//the monkey tree is mostly combat related, if it isn't busy with that then it may do instrument related things
/datum/ai_planning_subtree/play_instrument,
)
blackboard = list(
BB_MONKEY_AGGRESSIVE = FALSE,
BB_MONKEY_BEST_FORCE_FOUND = 0,
Expand All @@ -19,7 +23,8 @@ have ways of interacting with a specific mob and control it.
BB_MONKEY_CURRENT_ATTACK_TARGET = null,
BB_MONKEY_GUN_NEURONS_ACTIVATED = FALSE,
BB_MONKEY_GUN_WORKED = TRUE,
BB_MONKEY_NEXT_HUNGRY = 0
BB_MONKEY_NEXT_HUNGRY = 0,
BB_SONG_LINES = MONKEY_SONG,
)
var/static/list/loc_connections = list(
COMSIG_ATOM_ENTERED = .proc/on_entered,
Expand Down
4 changes: 0 additions & 4 deletions code/modules/instruments/songs/_song.dm
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
#define MUSICIAN_HEARCHECK_MINDELAY 4
#define MUSIC_MAXLINES 1000
#define MUSIC_MAXLINECHARS 300

/**
* # Song datum
*
Expand Down
4 changes: 3 additions & 1 deletion tgstation.dme
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@
#include "code\__DEFINES\shuttles.dm"
#include "code\__DEFINES\sight.dm"
#include "code\__DEFINES\skills.dm"
#include "code\__DEFINES\song.dm"
#include "code\__DEFINES\sound.dm"
#include "code\__DEFINES\space.dm"
#include "code\__DEFINES\spaceman_dmm.dm"
Expand Down Expand Up @@ -474,7 +475,6 @@
#include "code\datums\ai\_ai_controller.dm"
#include "code\datums\ai\_ai_planning_subtree.dm"
#include "code\datums\ai\_item_behaviors.dm"
#include "code\datums\ai\generic_actions.dm"
#include "code\datums\ai\telegraph_effects.dm"
#include "code\datums\ai\bane\bane_behaviors.dm"
#include "code\datums\ai\bane\bane_controller.dm"
Expand All @@ -494,6 +494,8 @@
#include "code\datums\ai\dog\dog_behaviors.dm"
#include "code\datums\ai\dog\dog_controller.dm"
#include "code\datums\ai\dog\dog_subtrees.dm"
#include "code\datums\ai\generic\generic_behaviors.dm"
#include "code\datums\ai\generic\generic_subtrees.dm"
#include "code\datums\ai\hauntium\haunted_controller.dm"
#include "code\datums\ai\hauntium\hauntium_subtrees.dm"
#include "code\datums\ai\hunting_behavior\hunting_behaviors.dm"
Expand Down

0 comments on commit d9ede13

Please sign in to comment.