mirror of
https://github.com/CHOMPStation2/CHOMPStation2.git
synced 2025-12-10 02:09:41 +00:00
Allows multiple AIs to share holopad.
This commit is contained in:
@@ -24,10 +24,12 @@ Possible to do for anyone motivated enough:
|
||||
* Holopad
|
||||
*/
|
||||
|
||||
// HOLOPAD MODE
|
||||
// 0 = RANGE BASED
|
||||
// 1 = AREA BASED
|
||||
var/const/HOLOPAD_MODE = 0
|
||||
#define HOLOPAD_PASSIVE_POWER_USAGE 1
|
||||
#define HOLOGRAM_POWER_USAGE 2
|
||||
#define RANGE_BASED 4
|
||||
#define AREA_BASED 6
|
||||
|
||||
var/const/HOLOPAD_MODE = RANGE_BASED
|
||||
|
||||
/obj/machinery/hologram/holopad
|
||||
name = "\improper AI holopad"
|
||||
@@ -36,7 +38,7 @@ var/const/HOLOPAD_MODE = 0
|
||||
|
||||
layer = TURF_LAYER+0.1 //Preventing mice and drones from sneaking under them.
|
||||
|
||||
var/mob/living/silicon/ai/master//Which AI, if any, is controlling the object? Only one AI may control a hologram at any time.
|
||||
var/list/mob/living/silicon/ai/masters = new() //List of AIs that use the holopad
|
||||
var/last_request = 0 //to prevent request spam. ~Carn
|
||||
var/holo_range = 5 // Change to change how far the AI can move away from the holopad before deactivating.
|
||||
|
||||
@@ -62,52 +64,53 @@ var/const/HOLOPAD_MODE = 0
|
||||
This may change in the future but for now will suffice.*/
|
||||
if(user.eyeobj.loc != src.loc)//Set client eye on the object if it's not already.
|
||||
user.eyeobj.setLoc(get_turf(src))
|
||||
else if(!hologram)//If there is no hologram, possibly make one.
|
||||
else if(!masters[user])//If there is no hologram, possibly make one.
|
||||
activate_holo(user)
|
||||
else if(master==user)//If there is a hologram, remove it. But only if the user is the master. Otherwise do nothing.
|
||||
clear_holo()
|
||||
else//If there is a hologram, remove it.
|
||||
clear_holo(user)
|
||||
return
|
||||
|
||||
/obj/machinery/hologram/holopad/proc/activate_holo(mob/living/silicon/ai/user)
|
||||
if(!(stat & NOPOWER) && user.eyeobj.loc == src.loc)//If the projector has power and client eye is on it.
|
||||
if(!hologram)//If there is not already a hologram.
|
||||
create_holo(user)//Create one.
|
||||
src.visible_message("A holographic image of [user] flicks to life right before your eyes!")
|
||||
else
|
||||
user << "\red ERROR: \black Image feed in progress."
|
||||
if(!(stat & NOPOWER) && user.eyeobj.loc == src.loc)//If the projector has power and client eye is on it
|
||||
if (user.holo)
|
||||
user << "<span class='danger'>ERROR:</span> Image feed in progress."
|
||||
return
|
||||
create_holo(user)//Create one.
|
||||
src.visible_message("A holographic image of [user] flicks to life right before your eyes!")
|
||||
else
|
||||
user << "\red ERROR: \black Unable to project hologram."
|
||||
user << "<span class='danger'>ERROR:</span> Unable to project hologram."
|
||||
return
|
||||
|
||||
/*This is the proc for special two-way communication between AI and holopad/people talking near holopad.
|
||||
For the other part of the code, check silicon say.dm. Particularly robot talk.*/
|
||||
/obj/machinery/hologram/holopad/hear_talk(mob/living/M, text, verb, datum/language/speaking)
|
||||
if(M&&hologram&&master)//Master is mostly a safety in case lag hits or something.
|
||||
if(!master.say_understands(M, speaking))//The AI will be able to understand most mobs talking through the holopad.
|
||||
if(M)
|
||||
for(var/mob/living/silicon/ai/master in masters)
|
||||
if(!master.say_understands(M, speaking))//The AI will be able to understand most mobs talking through the holopad.
|
||||
if(speaking)
|
||||
text = speaking.scramble(text)
|
||||
else
|
||||
text = stars(text)
|
||||
var/name_used = M.GetVoice()
|
||||
//This communication is imperfect because the holopad "filters" voices and is only designed to connect to the master only.
|
||||
var/rendered
|
||||
if(speaking)
|
||||
text = speaking.scramble(text)
|
||||
rendered = "<i><span class='game say'>Holopad received, <span class='name'>[name_used]</span> [speaking.format_message(text, verb)]</span></i>"
|
||||
else
|
||||
text = stars(text)
|
||||
var/name_used = M.GetVoice()
|
||||
//This communication is imperfect because the holopad "filters" voices and is only designed to connect to the master only.
|
||||
var/rendered
|
||||
if(speaking)
|
||||
rendered = "<i><span class='game say'>Holopad received, <span class='name'>[name_used]</span> [speaking.format_message(text, verb)]</span></i>"
|
||||
else
|
||||
rendered = "<i><span class='game say'>Holopad received, <span class='name'>[name_used]</span> [verb], <span class='message'>\"[text]\"</span></span></i>"
|
||||
master.show_message(rendered, 2)
|
||||
return
|
||||
rendered = "<i><span class='game say'>Holopad received, <span class='name'>[name_used]</span> [verb], <span class='message'>\"[text]\"</span></span></i>"
|
||||
master.show_message(rendered, 2)
|
||||
|
||||
/obj/machinery/hologram/holopad/see_emote(mob/living/M, text)
|
||||
if(M && hologram && master)
|
||||
//var/name_used = M.GetVoice()
|
||||
var/rendered = "<i><span class='game say'>Holopad received, <span class='message'>[text]</span></span></i>"
|
||||
//The lack of name_used is needed, because message already contains a name. This is needed for simple mobs to emote properly.
|
||||
master.show_message(rendered, 2)
|
||||
if(M)
|
||||
for(var/mob/living/silicon/ai/master in masters)
|
||||
//var/name_used = M.GetVoice()
|
||||
var/rendered = "<i><span class='game say'>Holopad received, <span class='message'>[text]</span></span></i>"
|
||||
//The lack of name_used is needed, because message already contains a name. This is needed for simple mobs to emote properly.
|
||||
master.show_message(rendered, 2)
|
||||
return
|
||||
|
||||
/obj/machinery/hologram/holopad/proc/create_holo(mob/living/silicon/ai/A, turf/T = loc)
|
||||
hologram = new(T)//Spawn a blank effect at the location.
|
||||
var/obj/effect/overlay/hologram = new(T)//Spawn a blank effect at the location.
|
||||
hologram.icon = A.holo_icon
|
||||
hologram.mouse_opacity = 0//So you can't click on it.
|
||||
hologram.layer = FLY_LAYER//Above all the other objects/mobs. Or the vast majority of them.
|
||||
@@ -115,32 +118,33 @@ For the other part of the code, check silicon say.dm. Particularly robot talk.*/
|
||||
hologram.name = "[A.name] (Hologram)"//If someone decides to right click.
|
||||
hologram.SetLuminosity(2) //hologram lighting
|
||||
hologram.color = color //painted holopad gives coloured holograms
|
||||
masters[A] = hologram
|
||||
SetLuminosity(2) //pad lighting
|
||||
icon_state = "holopad1"
|
||||
A.holo = src
|
||||
master = A//AI is the master.
|
||||
use_power = 2//Active power usage.
|
||||
use_power += HOLOGRAM_POWER_USAGE
|
||||
return 1
|
||||
|
||||
/obj/machinery/hologram/holopad/proc/clear_holo()
|
||||
// hologram.SetLuminosity(0)//Clear lighting. //handled by the lighting controller when its ower is deleted
|
||||
del(hologram)//Get rid of hologram.
|
||||
if(master.holo == src)
|
||||
master.holo = null
|
||||
master = null//Null the master, since no-one is using it now.
|
||||
SetLuminosity(0) //pad lighting (hologram lighting will be handled automatically since its owner was deleted)
|
||||
icon_state = "holopad0"
|
||||
use_power = 1//Passive power usage.
|
||||
/obj/machinery/hologram/holopad/proc/clear_holo(mob/living/silicon/ai/user)
|
||||
if(user.holo == src)
|
||||
user.holo = null
|
||||
del(masters[user])//Get rid of user's hologram //qdel
|
||||
masters -= user //Discard AI from the list of those who use holopad
|
||||
use_power = max(HOLOPAD_PASSIVE_POWER_USAGE, use_power - HOLOGRAM_POWER_USAGE)//Reduce power usage
|
||||
if (!masters.len)//If no users left
|
||||
SetLuminosity(0) //pad lighting (hologram lighting will be handled automatically since its owner was deleted)
|
||||
icon_state = "holopad0"
|
||||
use_power = HOLOPAD_PASSIVE_POWER_USAGE
|
||||
return 1
|
||||
|
||||
/obj/machinery/hologram/holopad/process()
|
||||
if(hologram)//If there is a hologram.
|
||||
for (var/mob/living/silicon/ai/master in masters)
|
||||
if(master && !master.stat && master.client && master.eyeobj)//If there is an AI attached, it's not incapacitated, it has a client, and the client eye is centered on the projector.
|
||||
if(!(stat & NOPOWER))//If the machine has power.
|
||||
if((HOLOPAD_MODE == 0 && (get_dist(master.eyeobj, src) <= holo_range)))
|
||||
if((HOLOPAD_MODE == RANGE_BASED && (get_dist(master.eyeobj, src) <= holo_range)))
|
||||
return 1
|
||||
|
||||
else if (HOLOPAD_MODE == 1)
|
||||
else if (HOLOPAD_MODE == AREA_BASED)
|
||||
|
||||
var/area/holo_area = get_area(src)
|
||||
var/area/eye_area = get_area(master.eyeobj)
|
||||
@@ -148,14 +152,15 @@ For the other part of the code, check silicon say.dm. Particularly robot talk.*/
|
||||
if(eye_area in holo_area.master.related)
|
||||
return 1
|
||||
|
||||
clear_holo()//If not, we want to get rid of the hologram.
|
||||
clear_holo(master)//If not, we want to get rid of the hologram.
|
||||
return 1
|
||||
|
||||
/obj/machinery/hologram/holopad/proc/move_hologram()
|
||||
if(hologram)
|
||||
step_to(hologram, master.eyeobj) // So it turns.
|
||||
hologram.loc = get_turf(master.eyeobj)
|
||||
|
||||
/obj/machinery/hologram/holopad/proc/move_hologram(mob/living/silicon/ai/user)
|
||||
if(masters[user])
|
||||
step_to(masters[user], user.eyeobj) // So it turns.
|
||||
var/obj/effect/overlay/H = masters[user]
|
||||
H.loc = get_turf(user.eyeobj)
|
||||
masters[user] = H
|
||||
return 1
|
||||
|
||||
/*
|
||||
@@ -167,7 +172,6 @@ For the other part of the code, check silicon say.dm. Particularly robot talk.*/
|
||||
use_power = 1
|
||||
idle_power_usage = 5
|
||||
active_power_usage = 100
|
||||
var/obj/effect/overlay/hologram//The projection itself. If there is one, the instrument is on, off otherwise.
|
||||
|
||||
//Destruction procs.
|
||||
/obj/machinery/hologram/ex_act(severity)
|
||||
@@ -190,9 +194,9 @@ For the other part of the code, check silicon say.dm. Particularly robot talk.*/
|
||||
del(src)
|
||||
return
|
||||
|
||||
/obj/machinery/hologram/Del()
|
||||
if(hologram)
|
||||
src:clear_holo()
|
||||
/obj/machinery/hologram/holopad/Del()
|
||||
for (var/mob/living/silicon/ai/master in masters)
|
||||
clear_holo(master)
|
||||
..()
|
||||
|
||||
/*
|
||||
@@ -224,3 +228,9 @@ Holographic project of everything else.
|
||||
desc = "It makes a hologram appear...with magnets or something..."
|
||||
icon = 'icons/obj/stationobjs.dmi'
|
||||
icon_state = "hologram0"
|
||||
|
||||
|
||||
#undef RANGE_BASED
|
||||
#undef AREA_BASED
|
||||
#undef HOLOPAD_PASSIVE_POWER_USAGE
|
||||
#undef HOLOGRAM_POWER_USAGE
|
||||
|
||||
Reference in New Issue
Block a user