Merge pull request #9755 from Ghommie/Ghommie-cit331

lentext to length, yet another 513 requirement.
This commit is contained in:
kevinz000
2019-11-12 23:59:31 -07:00
committed by Archie
parent 11515b3b32
commit 625b35b8cb
6 changed files with 5331 additions and 5331 deletions
+796 -796
View File
File diff suppressed because it is too large Load Diff
+368 -368
View File
@@ -1,368 +1,368 @@
// Status display
// (formerly Countdown timer display)
#define CHARS_PER_LINE 5
#define FONT_SIZE "5pt"
#define FONT_COLOR "#09f"
#define FONT_STYLE "Arial Black"
#define SCROLL_SPEED 2
#define SD_BLANK 0 // 0 = Blank
#define SD_EMERGENCY 1 // 1 = Emergency Shuttle timer
#define SD_MESSAGE 2 // 2 = Arbitrary message(s)
#define SD_PICTURE 3 // 3 = alert picture
#define SD_AI_EMOTE 1 // 1 = AI emoticon
#define SD_AI_BSOD 2 // 2 = Blue screen of death
/// Status display which can show images and scrolling text.
/obj/machinery/status_display
name = "status display"
desc = null
icon = 'icons/obj/status_display.dmi'
icon_state = "frame"
density = FALSE
use_power = IDLE_POWER_USE
idle_power_usage = 10
maptext_height = 26
maptext_width = 32
var/message1 = "" // message line 1
var/message2 = "" // message line 2
var/index1 // display index for scrolling messages or 0 if non-scrolling
var/index2
/// Immediately blank the display.
/obj/machinery/status_display/proc/remove_display()
cut_overlays()
if(maptext)
maptext = ""
/// Immediately change the display to the given picture.
/obj/machinery/status_display/proc/set_picture(state)
remove_display()
add_overlay(state)
/// Immediately change the display to the given two lines.
/obj/machinery/status_display/proc/update_display(line1, line2)
var/new_text = {"<div style="font-size:[FONT_SIZE];color:[FONT_COLOR];font:'[FONT_STYLE]';text-align:center;" valign="top">[line1]<br>[line2]</div>"}
if(maptext != new_text)
maptext = new_text
/// Prepare the display to marquee the given two lines.
///
/// Call with no arguments to disable.
/obj/machinery/status_display/proc/set_message(m1, m2)
if(m1)
index1 = (length(m1) > CHARS_PER_LINE)
message1 = m1
else
message1 = ""
index1 = 0
if(m2)
index2 = (length(m2) > CHARS_PER_LINE)
message2 = m2
else
message2 = ""
index2 = 0
// Timed process - performs default marquee action if so needed.
/obj/machinery/status_display/process()
if(stat & NOPOWER)
// No power, no processing.
remove_display()
return PROCESS_KILL
var/line1 = message1
if(index1)
line1 = copytext("[message1]|[message1]", index1, index1+CHARS_PER_LINE)
var/message1_len = length(message1)
index1 += SCROLL_SPEED
if(index1 > message1_len)
index1 -= message1_len
var/line2 = message2
if(index2)
line2 = copytext("[message2]|[message2]", index2, index2+CHARS_PER_LINE)
var/message2_len = length(message2)
index2 += SCROLL_SPEED
if(index2 > message2_len)
index2 -= message2_len
update_display(line1, line2)
if (!index1 && !index2)
// No marquee, no processing.
return PROCESS_KILL
/// Update the display and, if necessary, re-enable processing.
/obj/machinery/status_display/proc/update()
if (process() != PROCESS_KILL)
START_PROCESSING(SSmachines, src)
/obj/machinery/status_display/power_change()
. = ..()
update()
/obj/machinery/status_display/emp_act(severity)
. = ..()
if(stat & (NOPOWER|BROKEN) || . & EMP_PROTECT_SELF)
return
set_picture("ai_bsod")
/obj/machinery/status_display/examine(mob/user)
. = ..()
if (message1 || message2)
. += "The display says:"
if (message1)
. += "\t<tt>[html_encode(message1)]</tt>"
if (message2)
. += "\t<tt>[html_encode(message2)]</tt>"
// Helper procs for child display types.
/obj/machinery/status_display/proc/display_shuttle_status(obj/docking_port/mobile/shuttle)
if(!shuttle)
// the shuttle is missing - no processing
update_display("shutl?","")
return PROCESS_KILL
else if(shuttle.timer)
var/line1 = "-[shuttle.getModeStr()]-"
var/line2 = shuttle.getTimerStr()
if(length(line2) > CHARS_PER_LINE)
line2 = "error"
update_display(line1, line2)
else
// don't kill processing, the timer might turn back on
remove_display()
/obj/machinery/status_display/proc/examine_shuttle(mob/user, obj/docking_port/mobile/shuttle)
if (shuttle)
var/modestr = shuttle.getModeStr()
if (modestr)
if (shuttle.timer)
modestr = "<br>\t<tt>[modestr]: [shuttle.getTimerStr()]</tt>"
else
modestr = "<br>\t<tt>[modestr]</tt>"
return "The display says:<br>\t<tt>[shuttle.name]</tt>[modestr]"
else
return "The display says:<br>\t<tt>Shuttle missing!</tt>"
/// Evac display which shows shuttle timer or message set by Command.
/obj/machinery/status_display/evac
var/frequency = FREQ_STATUS_DISPLAYS
var/mode = SD_EMERGENCY
var/friendc = FALSE // track if Friend Computer mode
var/last_picture // For when Friend Computer mode is undone
/obj/machinery/status_display/evac/Initialize()
. = ..()
// register for radio system
SSradio.add_object(src, frequency)
/obj/machinery/status_display/evac/Destroy()
SSradio.remove_object(src,frequency)
return ..()
/obj/machinery/status_display/evac/process()
if(stat & NOPOWER)
// No power, no processing.
remove_display()
return PROCESS_KILL
if(friendc) //Makes all status displays except supply shuttle timer display the eye -- Urist
set_picture("ai_friend")
return PROCESS_KILL
switch(mode)
if(SD_BLANK)
remove_display()
return PROCESS_KILL
if(SD_EMERGENCY)
return display_shuttle_status(SSshuttle.emergency)
if(SD_MESSAGE)
return ..()
if(SD_PICTURE)
set_picture(last_picture)
return PROCESS_KILL
/obj/machinery/status_display/evac/examine(mob/user)
. = ..()
if(mode == SD_EMERGENCY)
. += examine_shuttle(user, SSshuttle.emergency)
else if(!message1 && !message2)
. += "The display is blank."
/obj/machinery/status_display/evac/receive_signal(datum/signal/signal)
switch(signal.data["command"])
if("blank")
mode = SD_BLANK
set_message(null, null)
if("shuttle")
mode = SD_EMERGENCY
set_message(null, null)
if("message")
mode = SD_MESSAGE
set_message(signal.data["msg1"], signal.data["msg2"])
if("alert")
mode = SD_PICTURE
last_picture = signal.data["picture_state"]
set_picture(last_picture)
if("friendcomputer")
friendc = !friendc
update()
/// Supply display which shows the status of the supply shuttle.
/obj/machinery/status_display/supply
name = "supply display"
/obj/machinery/status_display/supply/process()
if(stat & NOPOWER)
// No power, no processing.
remove_display()
return PROCESS_KILL
var/line1
var/line2
if(!SSshuttle.supply)
// Might be missing in our first update on initialize before shuttles
// have loaded. Cross our fingers that it will soon return.
line1 = "CARGO"
line2 = "shutl?"
else if(SSshuttle.supply.mode == SHUTTLE_IDLE)
if(is_station_level(SSshuttle.supply.z))
line1 = "CARGO"
line2 = "Docked"
else
line1 = "CARGO"
line2 = SSshuttle.supply.getTimerStr()
if(length(line2) > CHARS_PER_LINE)
line2 = "Error"
update_display(line1, line2)
/obj/machinery/status_display/supply/examine(mob/user)
. = ..()
var/obj/docking_port/mobile/shuttle = SSshuttle.supply
var/shuttleMsg = null
if (shuttle.mode == SHUTTLE_IDLE)
if (is_station_level(shuttle.z))
shuttleMsg = "Docked"
else
shuttleMsg = "[shuttle.getModeStr()]: [shuttle.getTimerStr()]"
if (shuttleMsg)
. += "The display says:<br>\t<tt>[shuttleMsg]</tt>"
else
. += "The display is blank."
/// General-purpose shuttle status display.
/obj/machinery/status_display/shuttle
name = "shuttle display"
var/shuttle_id
/obj/machinery/status_display/shuttle/process()
if(!shuttle_id || (stat & NOPOWER))
// No power, no processing.
remove_display()
return PROCESS_KILL
return display_shuttle_status(SSshuttle.getShuttle(shuttle_id))
/obj/machinery/status_display/shuttle/examine(mob/user)
. = ..()
if(shuttle_id)
. += examine_shuttle(user, SSshuttle.getShuttle(shuttle_id))
else
. += "The display is blank."
/obj/machinery/status_display/shuttle/vv_edit_var(var_name, var_value)
. = ..()
if(!.)
return
switch(var_name)
if("shuttle_id")
update()
/obj/machinery/status_display/shuttle/proc/connect_to_shuttle(obj/docking_port/mobile/port, obj/docking_port/stationary/dock, idnum, override)
if (port && (shuttle_id == initial(shuttle_id) || override))
shuttle_id = port.id
update()
/// Pictograph display which the AI can use to emote.
/obj/machinery/status_display/ai
name = "\improper AI display"
desc = "A small screen which the AI can use to present itself."
var/mode = SD_BLANK
var/emotion = "Neutral"
/obj/machinery/status_display/ai/Initialize()
. = ..()
GLOB.ai_status_displays.Add(src)
/obj/machinery/status_display/ai/Destroy()
GLOB.ai_status_displays.Remove(src)
. = ..()
/obj/machinery/status_display/ai/attack_ai(mob/living/silicon/ai/user)
if(isAI(user))
user.ai_statuschange()
/obj/machinery/status_display/ai/process()
if(mode == SD_BLANK || (stat & NOPOWER))
remove_display()
return PROCESS_KILL
if(mode == SD_AI_EMOTE)
switch(emotion)
if("Very Happy")
set_picture("ai_veryhappy")
if("Happy")
set_picture("ai_happy")
if("Neutral")
set_picture("ai_neutral")
if("Unsure")
set_picture("ai_unsure")
if("Confused")
set_picture("ai_confused")
if("Sad")
set_picture("ai_sad")
if("BSOD")
set_picture("ai_bsod")
if("Blank")
set_picture("ai_off")
if("Problems?")
set_picture("ai_trollface")
if("Awesome")
set_picture("ai_awesome")
if("Dorfy")
set_picture("ai_urist")
if("Thinking")
set_picture("ai_thinking")
if("Facepalm")
set_picture("ai_facepalm")
if("Friend Computer")
set_picture("ai_friend")
if("Blue Glow")
set_picture("ai_sal")
if("Red Glow")
set_picture("ai_hal")
return PROCESS_KILL
if(mode == SD_AI_BSOD)
set_picture("ai_bsod")
return PROCESS_KILL
#undef CHARS_PER_LINE
#undef FONT_SIZE
#undef FONT_COLOR
#undef FONT_STYLE
#undef SCROLL_SPEED
// Status display
// (formerly Countdown timer display)
#define CHARS_PER_LINE 5
#define FONT_SIZE "5pt"
#define FONT_COLOR "#09f"
#define FONT_STYLE "Arial Black"
#define SCROLL_SPEED 2
#define SD_BLANK 0 // 0 = Blank
#define SD_EMERGENCY 1 // 1 = Emergency Shuttle timer
#define SD_MESSAGE 2 // 2 = Arbitrary message(s)
#define SD_PICTURE 3 // 3 = alert picture
#define SD_AI_EMOTE 1 // 1 = AI emoticon
#define SD_AI_BSOD 2 // 2 = Blue screen of death
/// Status display which can show images and scrolling text.
/obj/machinery/status_display
name = "status display"
desc = null
icon = 'icons/obj/status_display.dmi'
icon_state = "frame"
density = FALSE
use_power = IDLE_POWER_USE
idle_power_usage = 10
maptext_height = 26
maptext_width = 32
var/message1 = "" // message line 1
var/message2 = "" // message line 2
var/index1 // display index for scrolling messages or 0 if non-scrolling
var/index2
/// Immediately blank the display.
/obj/machinery/status_display/proc/remove_display()
cut_overlays()
if(maptext)
maptext = ""
/// Immediately change the display to the given picture.
/obj/machinery/status_display/proc/set_picture(state)
remove_display()
add_overlay(state)
/// Immediately change the display to the given two lines.
/obj/machinery/status_display/proc/update_display(line1, line2)
var/new_text = {"<div style="font-size:[FONT_SIZE];color:[FONT_COLOR];font:'[FONT_STYLE]';text-align:center;" valign="top">[line1]<br>[line2]</div>"}
if(maptext != new_text)
maptext = new_text
/// Prepare the display to marquee the given two lines.
///
/// Call with no arguments to disable.
/obj/machinery/status_display/proc/set_message(m1, m2)
if(m1)
index1 = (length(m1) > CHARS_PER_LINE)
message1 = m1
else
message1 = ""
index1 = 0
if(m2)
index2 = (length(m2) > CHARS_PER_LINE)
message2 = m2
else
message2 = ""
index2 = 0
// Timed process - performs default marquee action if so needed.
/obj/machinery/status_display/process()
if(stat & NOPOWER)
// No power, no processing.
remove_display()
return PROCESS_KILL
var/line1 = message1
if(index1)
line1 = copytext("[message1]|[message1]", index1, index1+CHARS_PER_LINE)
var/message1_len = length(message1)
index1 += SCROLL_SPEED
if(index1 > message1_len)
index1 -= message1_len
var/line2 = message2
if(index2)
line2 = copytext("[message2]|[message2]", index2, index2+CHARS_PER_LINE)
var/message2_len = length(message2)
index2 += SCROLL_SPEED
if(index2 > message2_len)
index2 -= message2_len
update_display(line1, line2)
if (!index1 && !index2)
// No marquee, no processing.
return PROCESS_KILL
/// Update the display and, if necessary, re-enable processing.
/obj/machinery/status_display/proc/update()
if (process() != PROCESS_KILL)
START_PROCESSING(SSmachines, src)
/obj/machinery/status_display/power_change()
. = ..()
update()
/obj/machinery/status_display/emp_act(severity)
. = ..()
if(stat & (NOPOWER|BROKEN) || . & EMP_PROTECT_SELF)
return
set_picture("ai_bsod")
/obj/machinery/status_display/examine(mob/user)
. = ..()
if (message1 || message2)
. += "The display says:"
if (message1)
. += "\t<tt>[html_encode(message1)]</tt>"
if (message2)
. += "\t<tt>[html_encode(message2)]</tt>"
// Helper procs for child display types.
/obj/machinery/status_display/proc/display_shuttle_status(obj/docking_port/mobile/shuttle)
if(!shuttle)
// the shuttle is missing - no processing
update_display("shutl?","")
return PROCESS_KILL
else if(shuttle.timer)
var/line1 = "-[shuttle.getModeStr()]-"
var/line2 = shuttle.getTimerStr()
if(length(line2) > CHARS_PER_LINE)
line2 = "error"
update_display(line1, line2)
else
// don't kill processing, the timer might turn back on
remove_display()
/obj/machinery/status_display/proc/examine_shuttle(mob/user, obj/docking_port/mobile/shuttle)
if (shuttle)
var/modestr = shuttle.getModeStr()
if (modestr)
if (shuttle.timer)
modestr = "<br>\t<tt>[modestr]: [shuttle.getTimerStr()]</tt>"
else
modestr = "<br>\t<tt>[modestr]</tt>"
return "The display says:<br>\t<tt>[shuttle.name]</tt>[modestr]"
else
return "The display says:<br>\t<tt>Shuttle missing!</tt>"
/// Evac display which shows shuttle timer or message set by Command.
/obj/machinery/status_display/evac
var/frequency = FREQ_STATUS_DISPLAYS
var/mode = SD_EMERGENCY
var/friendc = FALSE // track if Friend Computer mode
var/last_picture // For when Friend Computer mode is undone
/obj/machinery/status_display/evac/Initialize()
. = ..()
// register for radio system
SSradio.add_object(src, frequency)
/obj/machinery/status_display/evac/Destroy()
SSradio.remove_object(src,frequency)
return ..()
/obj/machinery/status_display/evac/process()
if(stat & NOPOWER)
// No power, no processing.
remove_display()
return PROCESS_KILL
if(friendc) //Makes all status displays except supply shuttle timer display the eye -- Urist
set_picture("ai_friend")
return PROCESS_KILL
switch(mode)
if(SD_BLANK)
remove_display()
return PROCESS_KILL
if(SD_EMERGENCY)
return display_shuttle_status(SSshuttle.emergency)
if(SD_MESSAGE)
return ..()
if(SD_PICTURE)
set_picture(last_picture)
return PROCESS_KILL
/obj/machinery/status_display/evac/examine(mob/user)
. = ..()
if(mode == SD_EMERGENCY)
. += examine_shuttle(user, SSshuttle.emergency)
else if(!message1 && !message2)
. += "The display is blank."
/obj/machinery/status_display/evac/receive_signal(datum/signal/signal)
switch(signal.data["command"])
if("blank")
mode = SD_BLANK
set_message(null, null)
if("shuttle")
mode = SD_EMERGENCY
set_message(null, null)
if("message")
mode = SD_MESSAGE
set_message(signal.data["msg1"], signal.data["msg2"])
if("alert")
mode = SD_PICTURE
last_picture = signal.data["picture_state"]
set_picture(last_picture)
if("friendcomputer")
friendc = !friendc
update()
/// Supply display which shows the status of the supply shuttle.
/obj/machinery/status_display/supply
name = "supply display"
/obj/machinery/status_display/supply/process()
if(stat & NOPOWER)
// No power, no processing.
remove_display()
return PROCESS_KILL
var/line1
var/line2
if(!SSshuttle.supply)
// Might be missing in our first update on initialize before shuttles
// have loaded. Cross our fingers that it will soon return.
line1 = "CARGO"
line2 = "shutl?"
else if(SSshuttle.supply.mode == SHUTTLE_IDLE)
if(is_station_level(SSshuttle.supply.z))
line1 = "CARGO"
line2 = "Docked"
else
line1 = "CARGO"
line2 = SSshuttle.supply.getTimerStr()
if(length(line2) > CHARS_PER_LINE)
line2 = "Error"
update_display(line1, line2)
/obj/machinery/status_display/supply/examine(mob/user)
. = ..()
var/obj/docking_port/mobile/shuttle = SSshuttle.supply
var/shuttleMsg = null
if (shuttle.mode == SHUTTLE_IDLE)
if (is_station_level(shuttle.z))
shuttleMsg = "Docked"
else
shuttleMsg = "[shuttle.getModeStr()]: [shuttle.getTimerStr()]"
if (shuttleMsg)
. += "The display says:<br>\t<tt>[shuttleMsg]</tt>"
else
. += "The display is blank."
/// General-purpose shuttle status display.
/obj/machinery/status_display/shuttle
name = "shuttle display"
var/shuttle_id
/obj/machinery/status_display/shuttle/process()
if(!shuttle_id || (stat & NOPOWER))
// No power, no processing.
remove_display()
return PROCESS_KILL
return display_shuttle_status(SSshuttle.getShuttle(shuttle_id))
/obj/machinery/status_display/shuttle/examine(mob/user)
. = ..()
if(shuttle_id)
. += examine_shuttle(user, SSshuttle.getShuttle(shuttle_id))
else
. += "The display is blank."
/obj/machinery/status_display/shuttle/vv_edit_var(var_name, var_value)
. = ..()
if(!.)
return
switch(var_name)
if("shuttle_id")
update()
/obj/machinery/status_display/shuttle/proc/connect_to_shuttle(obj/docking_port/mobile/port, obj/docking_port/stationary/dock, idnum, override)
if (port && (shuttle_id == initial(shuttle_id) || override))
shuttle_id = port.id
update()
/// Pictograph display which the AI can use to emote.
/obj/machinery/status_display/ai
name = "\improper AI display"
desc = "A small screen which the AI can use to present itself."
var/mode = SD_BLANK
var/emotion = "Neutral"
/obj/machinery/status_display/ai/Initialize()
. = ..()
GLOB.ai_status_displays.Add(src)
/obj/machinery/status_display/ai/Destroy()
GLOB.ai_status_displays.Remove(src)
. = ..()
/obj/machinery/status_display/ai/attack_ai(mob/living/silicon/ai/user)
if(isAI(user))
user.ai_statuschange()
/obj/machinery/status_display/ai/process()
if(mode == SD_BLANK || (stat & NOPOWER))
remove_display()
return PROCESS_KILL
if(mode == SD_AI_EMOTE)
switch(emotion)
if("Very Happy")
set_picture("ai_veryhappy")
if("Happy")
set_picture("ai_happy")
if("Neutral")
set_picture("ai_neutral")
if("Unsure")
set_picture("ai_unsure")
if("Confused")
set_picture("ai_confused")
if("Sad")
set_picture("ai_sad")
if("BSOD")
set_picture("ai_bsod")
if("Blank")
set_picture("ai_off")
if("Problems?")
set_picture("ai_trollface")
if("Awesome")
set_picture("ai_awesome")
if("Dorfy")
set_picture("ai_urist")
if("Thinking")
set_picture("ai_thinking")
if("Facepalm")
set_picture("ai_facepalm")
if("Friend Computer")
set_picture("ai_friend")
if("Blue Glow")
set_picture("ai_sal")
if("Red Glow")
set_picture("ai_hal")
return PROCESS_KILL
if(mode == SD_AI_BSOD)
set_picture("ai_bsod")
return PROCESS_KILL
#undef CHARS_PER_LINE
#undef FONT_SIZE
#undef FONT_COLOR
#undef FONT_STYLE
#undef SCROLL_SPEED
+381 -381
View File
@@ -1,381 +1,381 @@
#define MUSICIAN_HEARCHECK_MINDELAY 4
#define MUSIC_MAXLINES 600
#define MUSIC_MAXLINECHARS 50
/datum/song
var/name = "Untitled"
var/list/lines = new()
var/tempo = 5 // delay between notes
var/playing = 0 // if we're playing
var/help = 0 // if help is open
var/edit = 1 // if we're in editing mode
var/repeat = 0 // number of times remaining to repeat
var/max_repeats = 10 // maximum times we can repeat
var/instrumentDir = "piano" // the folder with the sounds
var/instrumentExt = "ogg" // the file extension
var/obj/instrumentObj = null // the associated obj playing the sound
var/last_hearcheck = 0
var/list/hearing_mobs
/datum/song/New(dir, obj, ext = "ogg")
tempo = sanitize_tempo(tempo)
instrumentDir = dir
instrumentObj = obj
instrumentExt = ext
/datum/song/Destroy()
instrumentObj = null
return ..()
// note is a number from 1-7 for A-G
// acc is either "b", "n", or "#"
// oct is 1-8 (or 9 for C)
/datum/song/proc/playnote(note, acc as text, oct)
// handle accidental -> B<>C of E<>F
if(acc == "b" && (note == 3 || note == 6)) // C or F
if(note == 3)
oct--
note--
acc = "n"
else if(acc == "#" && (note == 2 || note == 5)) // B or E
if(note == 2)
oct++
note++
acc = "n"
else if(acc == "#" && (note == 7)) //G#
note = 1
acc = "b"
else if(acc == "#") // mass convert all sharps to flats, octave jump already handled
acc = "b"
note++
// check octave, C is allowed to go to 9
if(oct < 1 || (note == 3 ? oct > 9 : oct > 8))
return
// now generate name
var/soundfile = "sound/instruments/[instrumentDir]/[ascii2text(note+64)][acc][oct].[instrumentExt]"
soundfile = file(soundfile)
// make sure the note exists
if(!fexists(soundfile))
return
// and play
var/turf/source = get_turf(instrumentObj)
if((world.time - MUSICIAN_HEARCHECK_MINDELAY) > last_hearcheck)
LAZYCLEARLIST(hearing_mobs)
for(var/mob/M in get_hearers_in_view(15, source))
if(!M.client || !(M.client.prefs.toggles & SOUND_INSTRUMENTS))
continue
LAZYADD(hearing_mobs, M)
last_hearcheck = world.time
var/sound/music_played = sound(soundfile)
for(var/i in hearing_mobs)
var/mob/M = i
M.playsound_local(source, null, 100, falloff = 5, S = music_played)
/datum/song/proc/updateDialog(mob/user)
instrumentObj.updateDialog() // assumes it's an object in world, override if otherwise
/datum/song/proc/shouldStopPlaying(mob/user)
if(instrumentObj)
if(!user.canUseTopic(instrumentObj))
return TRUE
return !instrumentObj.anchored // add special cases to stop in subclasses
else
return TRUE
/datum/song/proc/playsong(mob/user)
while(repeat >= 0)
var/cur_oct[7]
var/cur_acc[7]
for(var/i = 1 to 7)
cur_oct[i] = 3
cur_acc[i] = "n"
for(var/line in lines)
for(var/beat in splittext(lowertext(line), ","))
var/list/notes = splittext(beat, "/")
for(var/note in splittext(notes[1], "-"))
if(!playing || shouldStopPlaying(user))//If the instrument is playing, or special case
playing = FALSE
hearing_mobs = null
return
if(!length(note))
continue
var/cur_note = text2ascii(note) - 96
if(cur_note < 1 || cur_note > 7)
continue
for(var/i=2 to length(note))
var/ni = copytext(note,i,i+1)
if(!text2num(ni))
if(ni == "#" || ni == "b" || ni == "n")
cur_acc[cur_note] = ni
else if(ni == "s")
cur_acc[cur_note] = "#" // so shift is never required
else
cur_oct[cur_note] = text2num(ni)
if(user.dizziness > 0 && prob(user.dizziness / 2))
cur_note = CLAMP(cur_note + rand(round(-user.dizziness / 10), round(user.dizziness / 10)), 1, 7)
if(user.dizziness > 0 && prob(user.dizziness / 5))
if(prob(30))
cur_acc[cur_note] = "#"
else if(prob(42))
cur_acc[cur_note] = "b"
else if(prob(75))
cur_acc[cur_note] = "n"
playnote(cur_note, cur_acc[cur_note], cur_oct[cur_note])
if(notes.len >= 2 && text2num(notes[2]))
sleep(sanitize_tempo(tempo / text2num(notes[2])))
else
sleep(tempo)
repeat--
hearing_mobs = null
playing = FALSE
repeat = 0
updateDialog(user)
/datum/song/proc/interact(mob/user)
var/dat = ""
if(lines.len > 0)
dat += "<H3>Playback</H3>"
if(!playing)
dat += "<A href='?src=[REF(src)];play=1'>Play</A> <SPAN CLASS='linkOn'>Stop</SPAN><BR><BR>"
dat += "Repeat Song: "
dat += repeat > 0 ? "<A href='?src=[REF(src)];repeat=-10'>-</A><A href='?src=[REF(src)];repeat=-1'>-</A>" : "<SPAN CLASS='linkOff'>-</SPAN><SPAN CLASS='linkOff'>-</SPAN>"
dat += " [repeat] times "
dat += repeat < max_repeats ? "<A href='?src=[REF(src)];repeat=1'>+</A><A href='?src=[REF(src)];repeat=10'>+</A>" : "<SPAN CLASS='linkOff'>+</SPAN><SPAN CLASS='linkOff'>+</SPAN>"
dat += "<BR>"
else
dat += "<SPAN CLASS='linkOn'>Play</SPAN> <A href='?src=[REF(src)];stop=1'>Stop</A><BR>"
dat += "Repeats left: <B>[repeat]</B><BR>"
if(!edit)
dat += "<BR><B><A href='?src=[REF(src)];edit=2'>Show Editor</A></B><BR>"
else
dat += "<H3>Editing</H3>"
dat += "<B><A href='?src=[REF(src)];edit=1'>Hide Editor</A></B>"
dat += " <A href='?src=[REF(src)];newsong=1'>Start a New Song</A>"
dat += " <A href='?src=[REF(src)];import=1'>Import a Song</A><BR><BR>"
var/bpm = round(600 / tempo)
dat += "Tempo: <A href='?src=[REF(src)];tempo=[world.tick_lag]'>-</A> [bpm] BPM <A href='?src=[REF(src)];tempo=-[world.tick_lag]'>+</A><BR><BR>"
var/linecount = 0
for(var/line in lines)
linecount += 1
dat += "Line [linecount]: <A href='?src=[REF(src)];modifyline=[linecount]'>Edit</A> <A href='?src=[REF(src)];deleteline=[linecount]'>X</A> [line]<BR>"
dat += "<A href='?src=[REF(src)];newline=1'>Add Line</A><BR><BR>"
if(help)
dat += "<B><A href='?src=[REF(src)];help=1'>Hide Help</A></B><BR>"
dat += {"
Lines are a series of chords, separated by commas (,), each with notes separated by hyphens (-).<br>
Every note in a chord will play together, with chord timed by the tempo.<br>
<br>
Notes are played by the names of the note, and optionally, the accidental, and/or the octave number.<br>
By default, every note is natural and in octave 3. Defining otherwise is remembered for each note.<br>
Example: <i>C,D,E,F,G,A,B</i> will play a C major scale.<br>
After a note has an accidental placed, it will be remembered: <i>C,C4,C,C3</i> is <i>C3,C4,C4,C3</i><br>
Chords can be played simply by seperating each note with a hyphon: <i>A-C#,Cn-E,E-G#,Gn-B</i><br>
A pause may be denoted by an empty chord: <i>C,E,,C,G</i><br>
To make a chord be a different time, end it with /x, where the chord length will be length<br>
defined by tempo / x: <i>C,G/2,E/4</i><br>
Combined, an example is: <i>E-E4/4,F#/2,G#/8,B/8,E3-E4/4</i>
<br>
Lines may be up to [MUSIC_MAXLINECHARS] characters.<br>
A song may only contain up to [MUSIC_MAXLINES] lines.<br>
"}
else
dat += "<B><A href='?src=[REF(src)];help=2'>Show Help</A></B><BR>"
var/datum/browser/popup = new(user, "instrument", instrumentObj.name, 700, 500)
popup.set_content(dat)
popup.set_title_image(user.browse_rsc_icon(instrumentObj.icon, instrumentObj.icon_state))
popup.open()
/datum/song/proc/ParseSong(text)
set waitfor = FALSE
//split into lines
lines = splittext(text, "\n")
if(lines.len)
if(copytext(lines[1],1,6) == "BPM: ")
tempo = sanitize_tempo(600 / text2num(copytext(lines[1],6)))
lines.Cut(1,2)
else
tempo = sanitize_tempo(5) // default 120 BPM
if(lines.len > MUSIC_MAXLINES)
to_chat(usr, "Too many lines!")
lines.Cut(MUSIC_MAXLINES + 1)
var/linenum = 1
for(var/l in lines)
if(length(l) > MUSIC_MAXLINECHARS)
to_chat(usr, "Line [linenum] too long!")
lines.Remove(l)
else
linenum++
updateDialog(usr) // make sure updates when complete
/datum/song/Topic(href, href_list)
if(!usr.canUseTopic(instrumentObj))
usr << browse(null, "window=instrument")
usr.unset_machine()
return
instrumentObj.add_fingerprint(usr)
if(href_list["newsong"])
lines = new()
tempo = sanitize_tempo(5) // default 120 BPM
name = ""
else if(href_list["import"])
var/t = ""
do
t = html_encode(input(usr, "Please paste the entire song, formatted:", text("[]", name), t) as message)
if(!in_range(instrumentObj, usr))
return
if(length(t) >= MUSIC_MAXLINES * MUSIC_MAXLINECHARS)
var/cont = input(usr, "Your message is too long! Would you like to continue editing it?", "", "yes") in list("yes", "no")
if(cont == "no")
break
while(length(t) > MUSIC_MAXLINES * MUSIC_MAXLINECHARS)
ParseSong(t)
else if(href_list["help"])
help = text2num(href_list["help"]) - 1
else if(href_list["edit"])
edit = text2num(href_list["edit"]) - 1
if(href_list["repeat"]) //Changing this from a toggle to a number of repeats to avoid infinite loops.
if(playing)
return //So that people cant keep adding to repeat. If the do it intentionally, it could result in the server crashing.
repeat += round(text2num(href_list["repeat"]))
if(repeat < 0)
repeat = 0
if(repeat > max_repeats)
repeat = max_repeats
else if(href_list["tempo"])
tempo = sanitize_tempo(tempo + text2num(href_list["tempo"]))
else if(href_list["play"])
playing = TRUE
spawn()
playsong(usr)
else if(href_list["newline"])
var/newline = html_encode(input("Enter your line: ", instrumentObj.name) as text|null)
if(!newline || !in_range(instrumentObj, usr))
return
if(lines.len > MUSIC_MAXLINES)
return
if(length(newline) > MUSIC_MAXLINECHARS)
newline = copytext(newline, 1, MUSIC_MAXLINECHARS)
lines.Add(newline)
else if(href_list["deleteline"])
var/num = round(text2num(href_list["deleteline"]))
if(num > lines.len || num < 1)
return
lines.Cut(num, num+1)
else if(href_list["modifyline"])
var/num = round(text2num(href_list["modifyline"]),1)
var/content = html_encode(input("Enter your line: ", instrumentObj.name, lines[num]) as text|null)
if(!content || !in_range(instrumentObj, usr))
return
if(length(content) > MUSIC_MAXLINECHARS)
content = copytext(content, 1, MUSIC_MAXLINECHARS)
if(num > lines.len || num < 1)
return
lines[num] = content
else if(href_list["stop"])
playing = FALSE
hearing_mobs = null
updateDialog(usr)
return
/datum/song/proc/sanitize_tempo(new_tempo)
new_tempo = abs(new_tempo)
return max(round(new_tempo, world.tick_lag), world.tick_lag)
// subclass for handheld instruments, like violin
/datum/song/handheld
/datum/song/handheld/updateDialog(mob/user)
instrumentObj.interact(user)
/datum/song/handheld/shouldStopPlaying()
if(instrumentObj)
return !isliving(instrumentObj.loc)
else
return TRUE
//////////////////////////////////////////////////////////////////////////
/obj/structure/piano
name = "space minimoog"
icon = 'icons/obj/musician.dmi'
icon_state = "minimoog"
anchored = TRUE
density = TRUE
var/datum/song/song
/obj/structure/piano/unanchored
anchored = FALSE
/obj/structure/piano/New()
..()
song = new("piano", src)
if(prob(50) && icon_state == initial(icon_state))
name = "space minimoog"
desc = "This is a minimoog, like a space piano, but more spacey!"
icon_state = "minimoog"
else
name = "space piano"
desc = "This is a space piano, like a regular piano, but always in tune! Even if the musician isn't."
icon_state = "piano"
/obj/structure/piano/Destroy()
qdel(song)
song = null
return ..()
/obj/structure/piano/Initialize(mapload)
. = ..()
if(mapload)
song.tempo = song.sanitize_tempo(song.tempo) // tick_lag isn't set when the map is loaded
/obj/structure/piano/attack_hand(mob/user)
. = ..()
if(.)
return
interact(user)
/obj/structure/piano/attack_paw(mob/user)
return attack_hand(user)
/obj/structure/piano/interact(mob/user)
ui_interact(user)
/obj/structure/piano/ui_interact(mob/user)
if(!user || !anchored)
return
if(!user.IsAdvancedToolUser())
to_chat(user, "<span class='warning'>You don't have the dexterity to do this!</span>")
return 1
user.set_machine(src)
song.interact(user)
/obj/structure/piano/wrench_act(mob/living/user, obj/item/I)
default_unfasten_wrench(user, I, 40)
return TRUE
#define MUSICIAN_HEARCHECK_MINDELAY 4
#define MUSIC_MAXLINES 600
#define MUSIC_MAXLINECHARS 50
/datum/song
var/name = "Untitled"
var/list/lines = new()
var/tempo = 5 // delay between notes
var/playing = 0 // if we're playing
var/help = 0 // if help is open
var/edit = 1 // if we're in editing mode
var/repeat = 0 // number of times remaining to repeat
var/max_repeats = 10 // maximum times we can repeat
var/instrumentDir = "piano" // the folder with the sounds
var/instrumentExt = "ogg" // the file extension
var/obj/instrumentObj = null // the associated obj playing the sound
var/last_hearcheck = 0
var/list/hearing_mobs
/datum/song/New(dir, obj, ext = "ogg")
tempo = sanitize_tempo(tempo)
instrumentDir = dir
instrumentObj = obj
instrumentExt = ext
/datum/song/Destroy()
instrumentObj = null
return ..()
// note is a number from 1-7 for A-G
// acc is either "b", "n", or "#"
// oct is 1-8 (or 9 for C)
/datum/song/proc/playnote(note, acc as text, oct)
// handle accidental -> B<>C of E<>F
if(acc == "b" && (note == 3 || note == 6)) // C or F
if(note == 3)
oct--
note--
acc = "n"
else if(acc == "#" && (note == 2 || note == 5)) // B or E
if(note == 2)
oct++
note++
acc = "n"
else if(acc == "#" && (note == 7)) //G#
note = 1
acc = "b"
else if(acc == "#") // mass convert all sharps to flats, octave jump already handled
acc = "b"
note++
// check octave, C is allowed to go to 9
if(oct < 1 || (note == 3 ? oct > 9 : oct > 8))
return
// now generate name
var/soundfile = "sound/instruments/[instrumentDir]/[ascii2text(note+64)][acc][oct].[instrumentExt]"
soundfile = file(soundfile)
// make sure the note exists
if(!fexists(soundfile))
return
// and play
var/turf/source = get_turf(instrumentObj)
if((world.time - MUSICIAN_HEARCHECK_MINDELAY) > last_hearcheck)
LAZYCLEARLIST(hearing_mobs)
for(var/mob/M in get_hearers_in_view(15, source))
if(!M.client || !(M.client.prefs.toggles & SOUND_INSTRUMENTS))
continue
LAZYADD(hearing_mobs, M)
last_hearcheck = world.time
var/sound/music_played = sound(soundfile)
for(var/i in hearing_mobs)
var/mob/M = i
M.playsound_local(source, null, 100, falloff = 5, S = music_played)
/datum/song/proc/updateDialog(mob/user)
instrumentObj.updateDialog() // assumes it's an object in world, override if otherwise
/datum/song/proc/shouldStopPlaying(mob/user)
if(instrumentObj)
if(!user.canUseTopic(instrumentObj))
return TRUE
return !instrumentObj.anchored // add special cases to stop in subclasses
else
return TRUE
/datum/song/proc/playsong(mob/user)
while(repeat >= 0)
var/cur_oct[7]
var/cur_acc[7]
for(var/i = 1 to 7)
cur_oct[i] = 3
cur_acc[i] = "n"
for(var/line in lines)
for(var/beat in splittext(lowertext(line), ","))
var/list/notes = splittext(beat, "/")
for(var/note in splittext(notes[1], "-"))
if(!playing || shouldStopPlaying(user))//If the instrument is playing, or special case
playing = FALSE
hearing_mobs = null
return
if(!length(note))
continue
var/cur_note = text2ascii(note) - 96
if(cur_note < 1 || cur_note > 7)
continue
for(var/i=2 to length(note))
var/ni = copytext(note,i,i+1)
if(!text2num(ni))
if(ni == "#" || ni == "b" || ni == "n")
cur_acc[cur_note] = ni
else if(ni == "s")
cur_acc[cur_note] = "#" // so shift is never required
else
cur_oct[cur_note] = text2num(ni)
if(user.dizziness > 0 && prob(user.dizziness / 2))
cur_note = CLAMP(cur_note + rand(round(-user.dizziness / 10), round(user.dizziness / 10)), 1, 7)
if(user.dizziness > 0 && prob(user.dizziness / 5))
if(prob(30))
cur_acc[cur_note] = "#"
else if(prob(42))
cur_acc[cur_note] = "b"
else if(prob(75))
cur_acc[cur_note] = "n"
playnote(cur_note, cur_acc[cur_note], cur_oct[cur_note])
if(notes.len >= 2 && text2num(notes[2]))
sleep(sanitize_tempo(tempo / text2num(notes[2])))
else
sleep(tempo)
repeat--
hearing_mobs = null
playing = FALSE
repeat = 0
updateDialog(user)
/datum/song/proc/interact(mob/user)
var/dat = ""
if(lines.len > 0)
dat += "<H3>Playback</H3>"
if(!playing)
dat += "<A href='?src=[REF(src)];play=1'>Play</A> <SPAN CLASS='linkOn'>Stop</SPAN><BR><BR>"
dat += "Repeat Song: "
dat += repeat > 0 ? "<A href='?src=[REF(src)];repeat=-10'>-</A><A href='?src=[REF(src)];repeat=-1'>-</A>" : "<SPAN CLASS='linkOff'>-</SPAN><SPAN CLASS='linkOff'>-</SPAN>"
dat += " [repeat] times "
dat += repeat < max_repeats ? "<A href='?src=[REF(src)];repeat=1'>+</A><A href='?src=[REF(src)];repeat=10'>+</A>" : "<SPAN CLASS='linkOff'>+</SPAN><SPAN CLASS='linkOff'>+</SPAN>"
dat += "<BR>"
else
dat += "<SPAN CLASS='linkOn'>Play</SPAN> <A href='?src=[REF(src)];stop=1'>Stop</A><BR>"
dat += "Repeats left: <B>[repeat]</B><BR>"
if(!edit)
dat += "<BR><B><A href='?src=[REF(src)];edit=2'>Show Editor</A></B><BR>"
else
dat += "<H3>Editing</H3>"
dat += "<B><A href='?src=[REF(src)];edit=1'>Hide Editor</A></B>"
dat += " <A href='?src=[REF(src)];newsong=1'>Start a New Song</A>"
dat += " <A href='?src=[REF(src)];import=1'>Import a Song</A><BR><BR>"
var/bpm = round(600 / tempo)
dat += "Tempo: <A href='?src=[REF(src)];tempo=[world.tick_lag]'>-</A> [bpm] BPM <A href='?src=[REF(src)];tempo=-[world.tick_lag]'>+</A><BR><BR>"
var/linecount = 0
for(var/line in lines)
linecount += 1
dat += "Line [linecount]: <A href='?src=[REF(src)];modifyline=[linecount]'>Edit</A> <A href='?src=[REF(src)];deleteline=[linecount]'>X</A> [line]<BR>"
dat += "<A href='?src=[REF(src)];newline=1'>Add Line</A><BR><BR>"
if(help)
dat += "<B><A href='?src=[REF(src)];help=1'>Hide Help</A></B><BR>"
dat += {"
Lines are a series of chords, separated by commas (,), each with notes separated by hyphens (-).<br>
Every note in a chord will play together, with chord timed by the tempo.<br>
<br>
Notes are played by the names of the note, and optionally, the accidental, and/or the octave number.<br>
By default, every note is natural and in octave 3. Defining otherwise is remembered for each note.<br>
Example: <i>C,D,E,F,G,A,B</i> will play a C major scale.<br>
After a note has an accidental placed, it will be remembered: <i>C,C4,C,C3</i> is <i>C3,C4,C4,C3</i><br>
Chords can be played simply by seperating each note with a hyphon: <i>A-C#,Cn-E,E-G#,Gn-B</i><br>
A pause may be denoted by an empty chord: <i>C,E,,C,G</i><br>
To make a chord be a different time, end it with /x, where the chord length will be length<br>
defined by tempo / x: <i>C,G/2,E/4</i><br>
Combined, an example is: <i>E-E4/4,F#/2,G#/8,B/8,E3-E4/4</i>
<br>
Lines may be up to [MUSIC_MAXLINECHARS] characters.<br>
A song may only contain up to [MUSIC_MAXLINES] lines.<br>
"}
else
dat += "<B><A href='?src=[REF(src)];help=2'>Show Help</A></B><BR>"
var/datum/browser/popup = new(user, "instrument", instrumentObj.name, 700, 500)
popup.set_content(dat)
popup.set_title_image(user.browse_rsc_icon(instrumentObj.icon, instrumentObj.icon_state))
popup.open()
/datum/song/proc/ParseSong(text)
set waitfor = FALSE
//split into lines
lines = splittext(text, "\n")
if(lines.len)
if(copytext(lines[1],1,6) == "BPM: ")
tempo = sanitize_tempo(600 / text2num(copytext(lines[1],6)))
lines.Cut(1,2)
else
tempo = sanitize_tempo(5) // default 120 BPM
if(lines.len > MUSIC_MAXLINES)
to_chat(usr, "Too many lines!")
lines.Cut(MUSIC_MAXLINES + 1)
var/linenum = 1
for(var/l in lines)
if(length(l) > MUSIC_MAXLINECHARS)
to_chat(usr, "Line [linenum] too long!")
lines.Remove(l)
else
linenum++
updateDialog(usr) // make sure updates when complete
/datum/song/Topic(href, href_list)
if(!usr.canUseTopic(instrumentObj))
usr << browse(null, "window=instrument")
usr.unset_machine()
return
instrumentObj.add_fingerprint(usr)
if(href_list["newsong"])
lines = new()
tempo = sanitize_tempo(5) // default 120 BPM
name = ""
else if(href_list["import"])
var/t = ""
do
t = html_encode(input(usr, "Please paste the entire song, formatted:", text("[]", name), t) as message)
if(!in_range(instrumentObj, usr))
return
if(length(t) >= MUSIC_MAXLINES * MUSIC_MAXLINECHARS)
var/cont = input(usr, "Your message is too long! Would you like to continue editing it?", "", "yes") in list("yes", "no")
if(cont == "no")
break
while(length(t) > MUSIC_MAXLINES * MUSIC_MAXLINECHARS)
ParseSong(t)
else if(href_list["help"])
help = text2num(href_list["help"]) - 1
else if(href_list["edit"])
edit = text2num(href_list["edit"]) - 1
if(href_list["repeat"]) //Changing this from a toggle to a number of repeats to avoid infinite loops.
if(playing)
return //So that people cant keep adding to repeat. If the do it intentionally, it could result in the server crashing.
repeat += round(text2num(href_list["repeat"]))
if(repeat < 0)
repeat = 0
if(repeat > max_repeats)
repeat = max_repeats
else if(href_list["tempo"])
tempo = sanitize_tempo(tempo + text2num(href_list["tempo"]))
else if(href_list["play"])
playing = TRUE
spawn()
playsong(usr)
else if(href_list["newline"])
var/newline = html_encode(input("Enter your line: ", instrumentObj.name) as text|null)
if(!newline || !in_range(instrumentObj, usr))
return
if(lines.len > MUSIC_MAXLINES)
return
if(length(newline) > MUSIC_MAXLINECHARS)
newline = copytext(newline, 1, MUSIC_MAXLINECHARS)
lines.Add(newline)
else if(href_list["deleteline"])
var/num = round(text2num(href_list["deleteline"]))
if(num > lines.len || num < 1)
return
lines.Cut(num, num+1)
else if(href_list["modifyline"])
var/num = round(text2num(href_list["modifyline"]),1)
var/content = html_encode(input("Enter your line: ", instrumentObj.name, lines[num]) as text|null)
if(!content || !in_range(instrumentObj, usr))
return
if(length(content) > MUSIC_MAXLINECHARS)
content = copytext(content, 1, MUSIC_MAXLINECHARS)
if(num > lines.len || num < 1)
return
lines[num] = content
else if(href_list["stop"])
playing = FALSE
hearing_mobs = null
updateDialog(usr)
return
/datum/song/proc/sanitize_tempo(new_tempo)
new_tempo = abs(new_tempo)
return max(round(new_tempo, world.tick_lag), world.tick_lag)
// subclass for handheld instruments, like violin
/datum/song/handheld
/datum/song/handheld/updateDialog(mob/user)
instrumentObj.interact(user)
/datum/song/handheld/shouldStopPlaying()
if(instrumentObj)
return !isliving(instrumentObj.loc)
else
return TRUE
//////////////////////////////////////////////////////////////////////////
/obj/structure/piano
name = "space minimoog"
icon = 'icons/obj/musician.dmi'
icon_state = "minimoog"
anchored = TRUE
density = TRUE
var/datum/song/song
/obj/structure/piano/unanchored
anchored = FALSE
/obj/structure/piano/New()
..()
song = new("piano", src)
if(prob(50) && icon_state == initial(icon_state))
name = "space minimoog"
desc = "This is a minimoog, like a space piano, but more spacey!"
icon_state = "minimoog"
else
name = "space piano"
desc = "This is a space piano, like a regular piano, but always in tune! Even if the musician isn't."
icon_state = "piano"
/obj/structure/piano/Destroy()
qdel(song)
song = null
return ..()
/obj/structure/piano/Initialize(mapload)
. = ..()
if(mapload)
song.tempo = song.sanitize_tempo(song.tempo) // tick_lag isn't set when the map is loaded
/obj/structure/piano/attack_hand(mob/user)
. = ..()
if(.)
return
interact(user)
/obj/structure/piano/attack_paw(mob/user)
return attack_hand(user)
/obj/structure/piano/interact(mob/user)
ui_interact(user)
/obj/structure/piano/ui_interact(mob/user)
if(!user || !anchored)
return
if(!user.IsAdvancedToolUser())
to_chat(user, "<span class='warning'>You don't have the dexterity to do this!</span>")
return 1
user.set_machine(src)
song.interact(user)
/obj/structure/piano/wrench_act(mob/living/user, obj/item/I)
default_unfasten_wrench(user, I, 40)
return TRUE
+2991 -2991
View File
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff