ED 209 update (#5182)

Depends on #5075

ED 209 uses verbal command like "stay, stop, patrol, arrest, detain".

ED 209 can arrest/detain people if given the command.
This commit is contained in:
Mykhailo Bykhovtsev
2018-09-02 09:40:18 -07:00
committed by Erki
parent 06bbe3f943
commit 78b52be7f0
4 changed files with 266 additions and 3 deletions

View File

@@ -1,9 +1,19 @@
#define SECBOT_IDLE 0 // idle
#define SECBOT_HUNT 1 // found target, hunting
#define SECBOT_ARREST 2 // arresting target
#define SECBOT_START_PATROL 3 // start patrol
#define SECBOT_WAIT_PATROL 4 // waiting for signals
#define SECBOT_PATROL 5 // patrolling
#define SECBOT_SUMMON 6 // summoned by PDA
#define SECBOT_STOP 7 // basically 'do nothing'
#define SECBOT_FOLLOW 8 // follows a target
/mob/living/bot/secbot/ed209
name = "ED-209 Security Robot"
desc = "A security robot. He looks less than thrilled."
icon = 'icons/obj/aibots.dmi'
icon_state = "ed2090"
density = 1
density = 0
health = 100
maxHealth = 100
@@ -19,6 +29,213 @@
var/shot_delay = 4
var/last_shot = 0
// vars for verbal commands
var/short_name = null
var/list/command_buffer = list()
var/list/known_commands = list("stay", "stop", "arrest", "detain", "follow", "patrol")
var/emote_hear = "states"
move_to_delay = 3
/mob/living/bot/secbot/ed209/Initialize()
..()
if(!short_name)
short_name = name
/mob/living/bot/secbot/ed209/hear_say(var/message, var/verb = "says", var/datum/language/language = null, var/alt_name = "", var/italics = 0, var/mob/speaker = null, var/sound/speech_sound, var/sound_vol)
if(thinking_enabled && !stat && has_ui_access(speaker))
command_buffer.Add(speaker)
command_buffer.Add(lowertext(html_decode(message)))
return 0
/mob/living/bot/secbot/ed209/hear_radio(var/message, var/verb="says", var/datum/language/language=null, var/part_a, var/part_b, var/part_c, var/mob/speaker = null, var/hard_to_hear = 0)
if(thinking_enabled && !stat && has_ui_access(speaker))
command_buffer.Add(speaker)
command_buffer.Add(lowertext(html_decode(message)))
return 0
/mob/living/bot/secbot/ed209/think()
while(command_buffer.len > 0)
var/mob/speaker = command_buffer[1]
var/text = command_buffer[2]
var/filtered_name = lowertext(html_decode(name))
var/filtered_short = lowertext(html_decode(short_name))
if(dd_hasprefix(text,filtered_name))
var/substring = copytext(text,length(filtered_name)+1) //get rid of the name.
listen(speaker,substring)
else if(dd_hasprefix(text,filtered_short))
var/substring = copytext(text,length(filtered_short)+1) //get rid of the name.
listen(speaker,substring)
command_buffer.Remove(command_buffer[1],command_buffer[2])
..()
switch(mode)
if(SECBOT_FOLLOW)
follow_target()
if(SECBOT_STOP)
commanded_stop()
/mob/living/bot/secbot/ed209/on_think_disabled()
..()
command_buffer.Cut()
/mob/living/bot/secbot/ed209/proc/follow_target()
if(!target)
return
if(target in view(7, src))
walk_to(src,target,1,move_to_delay)
/mob/living/bot/secbot/ed209/proc/commanded_stop() //basically a proc that runs whenever we are asked to stay put. Probably going to remain unused.
return
/mob/living/bot/secbot/ed209/proc/listen(var/mob/speaker, var/text)
for(var/command in known_commands)
if(findtext(text,command))
switch(command)
if("stay")
if(stay_command(speaker,text)) //find a valid command? Stop. Dont try and find more.
break
if("stop")
if(stop_command(speaker,text))
break
if("arrest")
if(arrest_command(speaker,text))
break
if("detain")
if(arrest_command(speaker,text))
break
if("follow")
if(follow_command(speaker,text))
break
if("patrol")
if(patrol_command(speaker, text))
break
return 1
//returns a list of everybody we wanna do stuff with.
/mob/living/bot/secbot/ed209/proc/get_target_by_name(var/text)
var/list/possible_targets = hearers(src,10)
for(var/mob/M in possible_targets)
if(findtext(text, "[M]"))
return M
else
var/list/parsed_name = splittext(replace_characters(lowertext(html_decode("[M]")),list("-"=" ", "."=" ", "," = " ", "'" = " ")), " ") //this big MESS is basically 'turn this into words, no punctuation, lowercase so we can check first name/last name/etc'
for(var/a in parsed_name)
if(a == "the" || length(a) < 2) //get rid of shit words.
continue
if(findtext(text,"[a]"))
return M
return null
/mob/living/bot/secbot/ed209/proc/arrest_command(var/mob/speaker,var/text)
target = null //want me to attack something? Well I better forget my old target.
walk_to(src,0)
target = get_target_by_name(text)
if(!(target in view(7, src)))
return 0
if(findtext(text,"detain"))
arrest_type = 1
else
arrest_type = 0
if(isnull(target))
custom_emote(2, "[emote_hear], \"Error, unit is unable to find target in view range!\"")
return 0
else
if(ishuman(target))
idcheck = TRUE
var/mob/living/carbon/human/H = target
var/perpname = H.name
var/obj/item/weapon/card/id/id = H.GetIdCard()
if(id)
perpname = id.registered_name
var/datum/data/record/R = find_security_record("name", perpname)
if(R)
R.fields["criminal"] = "*Arrest*"
else
custom_emote(2, "[emote_hear], \"Warning, [target] does not have Security records! Enabling security records check mode!\"")
check_records = TRUE
mode = SECBOT_HUNT
custom_emote(2, "[emote_hear], \"[arrest_type ? ("Detaining") : ("Arresting")] [target]\"")
/mob/living/bot/secbot/ed209/proc/stay_command(var/mob/speaker,var/text)
walk_to(src, src, 0, move_to_delay)
mode = SECBOT_IDLE
auto_patrol = 0
target = null
check_records = FALSE
custom_emote(2, "[emote_hear], \"Roger that, going into idle mode. Auto patrol disabled.\"")
return 1
/mob/living/bot/secbot/ed209/proc/stop_command(var/mob/speaker,var/text)
if(!on)
return
walk_to(src, src, 0, move_to_delay)
check_records = FALSE
custom_emote(2, "[emote_hear], \"Roger that, unit going offline.\"")
turn_off()
return 1
/mob/living/bot/secbot/ed209/proc/patrol_command(var/mob/speaker,var/text)
walk_to(src, src, 0, move_to_delay)
mode = SECBOT_IDLE
auto_patrol = 1
target = null
custom_emote(2, "[emote_hear], \"Roger that, starting patrol now.\"")
return 1
/mob/living/bot/secbot/ed209/proc/follow_command(var/mob/speaker,var/text)
//we can assume 'stop following' is handled by stop_command
if(findtext(text,"me"))
mode = SECBOT_FOLLOW
target = speaker
custom_emote(2, "[emote_hear], \"Roger that, following you\"")
return 1
target = get_target_by_name(text)
if(!(target in view(7, src)))
return 0
if(!target)
return 0
mode = SECBOT_FOLLOW
custom_emote(2, "[emote_hear], \"Roger that, following [target]\"")
return 1
/mob/living/bot/secbot/ed209/verb/change_name()
set name = "Change nickname"
set category = "IC"
set src in view(1)
if(!usr.mind) return 0
// Check if they are set to arrest
if(ishuman(usr))
var/mob/living/carbon/human/H = usr
var/perpname = H.name
var/obj/item/weapon/card/id/id = H.GetIdCard()
if(id)
perpname = id.registered_name
var/datum/data/record/R = find_security_record("name", perpname)
if(R && R.fields["criminal"] == "*Arrest*")
to_chat(usr, "<span class='warning'>Warning, you do not have access!</span>")
// Check if they have access to the bot
if(!has_ui_access(usr))
to_chat(usr, "<span class='warning'>Warning, you do not have access!</span>")
return 0
var/short_input = sanitizeSafe(input("What do you want [src] respond to?", , ""), MAX_NAME_LEN)
if(src && short_input && !usr.stat && in_range(usr,src))
short_name = short_input
return 1
/mob/living/bot/secbot/ed209/update_icons()
if(on && is_attacking)
icon_state = "ed209-c"
@@ -26,7 +243,7 @@
icon_state = "ed209[on]"
/mob/living/bot/secbot/ed209/explode()
visible_message("<span class='warning'>[src] blows apart!</span>")
visible_message("<span class='danger'>[src] blows apart!</span>")
var/turf/Tsec = get_turf(src)
new /obj/item/weapon/secbot_assembly/ed209_assembly(Tsec)
@@ -188,3 +405,13 @@
qdel(W)
qdel(src)
return 1
#undef SECBOT_IDLE
#undef SECBOT_HUNT
#undef SECBOT_ARREST
#undef SECBOT_START_PATROL
#undef SECBOT_WAIT_PATROL
#undef SECBOT_PATROL
#undef SECBOT_SUMMON
#undef SECBOT_STOP
#undef SECBOT_FOLLOW

View File

@@ -561,6 +561,21 @@
..()
if (ismob(P.firer))
var/found = 0
// Check if we can see them.
for(var/mob/living/M in view(7, src))
if(M.invisibility >= INVISIBILITY_LEVEL_ONE)
continue
if(M.stat)
continue
if(M == P.firer)
found = 1
break
if(!found)
broadcast_security_hud_message("[src] was shot with <b>[P]</b>, Unable to locate source! Requesting backup", src)
return
target = P.firer
mode = SECBOT_HUNT
if(ishuman(P.firer))
@@ -698,3 +713,11 @@
if(!in_range(src, usr) && loc != usr)
return
created_name = t
#undef SECBOT_IDLE
#undef SECBOT_HUNT
#undef SECBOT_ARREST
#undef SECBOT_START_PATROL
#undef SECBOT_WAIT_PATROL
#undef SECBOT_PATROL
#undef SECBOT_SUMMON