mirror of
https://github.com/CHOMPStation2/CHOMPStation2.git
synced 2026-07-12 08:43:26 +01:00
Merge pull request #954 from cadyn/newportals
Some simple portals for kassc
This commit is contained in:
@@ -0,0 +1,113 @@
|
||||
/obj/effect/simple_portal
|
||||
name = "Portal"
|
||||
desc = "It looks like a portal that leads to somewhere, although you can't quite see through it."
|
||||
icon = 'icons/obj/stationobjs.dmi'
|
||||
icon_state = "portal"
|
||||
density = 1
|
||||
unacidable = TRUE
|
||||
anchored = TRUE
|
||||
var/atom/destination
|
||||
var/teleport_sound = 'sound/effects/portal_effect.ogg'
|
||||
|
||||
/obj/effect/simple_portal/Bumped(atom/movable/AM)
|
||||
. = ..()
|
||||
handle_teleport(AM)
|
||||
|
||||
/obj/effect/simple_portal/Crossed(atom/movable/AM)
|
||||
. = ..()
|
||||
handle_teleport(AM)
|
||||
|
||||
/obj/effect/simple_portal/proc/handle_teleport(atom/movable/AM)
|
||||
if(destination)
|
||||
AM.forceMove(destination)
|
||||
if(!AM.is_incorporeal())
|
||||
playsound(get_turf(src),teleport_sound,60,1)
|
||||
playsound(get_turf(destination),teleport_sound,60,1)
|
||||
|
||||
/obj/effect/simple_portal/coords
|
||||
var/tele_x
|
||||
var/tele_y
|
||||
var/tele_z
|
||||
|
||||
/obj/effect/simple_portal/coords/handle_teleport(atom/movable/AM)
|
||||
destination = null
|
||||
if(!isnull(tele_x) && !isnull(tele_y) && !isnull(tele_z))
|
||||
destination = locate(tele_x,tele_y,tele_z)
|
||||
. = ..()
|
||||
|
||||
/obj/effect/simple_portal/linked
|
||||
icon_state = "portal1"
|
||||
var/obj/effect/simple_portal/linked/linked_portal
|
||||
var/portal_id
|
||||
|
||||
/obj/effect/simple_portal/linked/handle_teleport(atom/movable/AM)
|
||||
destination = null
|
||||
update_icon()
|
||||
if(linked_portal && icon_state == "portal")
|
||||
var/rel_x = round(rand(-1,1))
|
||||
var/rel_y = round(rand(-1,1))
|
||||
var/movingdir = get_dir(AM,src)
|
||||
if(!isnull(movingdir))
|
||||
destination = get_step(get_turf(linked_portal),movingdir)
|
||||
else
|
||||
while(rel_x == 0 && rel_y == 0)
|
||||
rel_x = round(rand(-1,1))
|
||||
rel_y = round(rand(-1,1))
|
||||
destination = locate(linked_portal.loc.x + rel_x, linked_portal.loc.y + rel_y, linked_portal.loc.z)
|
||||
if(!valid_destination(destination))
|
||||
var/list/possible_x = shuffle(list(-1,0,1))
|
||||
var/list/possible_y = shuffle(list(-1,0,1))
|
||||
for(rel_x in possible_x)
|
||||
for(rel_y in possible_y)
|
||||
if(rel_x == 0 && rel_y == 0)
|
||||
continue
|
||||
destination = locate(linked_portal.loc.x + rel_x, linked_portal.loc.y + rel_y, linked_portal.loc.z)
|
||||
if(valid_destination(destination))
|
||||
break
|
||||
. = ..()
|
||||
|
||||
/obj/effect/simple_portal/linked/proc/valid_destination(var/turf/dest,var/atom/movable/AM)
|
||||
if(!dest)
|
||||
return FALSE
|
||||
if(dest.density)
|
||||
return FALSE
|
||||
if(dest == get_turf(linked_portal))
|
||||
return FALSE
|
||||
var/windows = 0
|
||||
for(var/obj/struct in dest)
|
||||
var/obj/structure/window/window = struct
|
||||
if(istype(window))
|
||||
windows++
|
||||
if(window.fulltile)
|
||||
return FALSE
|
||||
else
|
||||
if(!struct.density)
|
||||
continue
|
||||
if(struct.throwpass || struct.flags & ON_BORDER)
|
||||
continue
|
||||
else
|
||||
return FALSE
|
||||
if(windows>2)
|
||||
return FALSE
|
||||
return TRUE
|
||||
|
||||
/obj/effect/simple_portal/linked/proc/link_portal()
|
||||
if(!portal_id)
|
||||
return "SET PORTAL ID FIRST"
|
||||
var/list/candidates = get_all_of_type(/obj/effect/simple_portal/linked)
|
||||
for(var/obj/effect/simple_portal/linked/candidate in candidates)
|
||||
if(istype(candidate) && portal_id == candidate.portal_id && candidate != src)
|
||||
linked_portal = candidate
|
||||
break
|
||||
update_icon()
|
||||
|
||||
/obj/effect/simple_portal/linked/update_icon()
|
||||
if(linked_portal && !QDELETED(linked_portal))
|
||||
icon_state = "portal"
|
||||
else
|
||||
icon_state = "portal1"
|
||||
|
||||
/obj/effect/simple_portal/linked/Initialize()
|
||||
. = ..()
|
||||
if(portal_id)
|
||||
link_portal()
|
||||
@@ -0,0 +1,91 @@
|
||||
/obj/effect/ctrigger
|
||||
name = "Step Trigger"
|
||||
icon = null
|
||||
anchored = 1
|
||||
invisibility = INVISIBILITY_OBSERVER
|
||||
density = 0
|
||||
var/list/potential_triggerers = list() //What can set off our trigger?
|
||||
var/list/trig_target_paths = list() //What are the paths of whatever we want to call our proc on?
|
||||
var/trig_target_trigger_uid //What is the trigger_uid of whatever we want to call our proc on?
|
||||
var/trig_proc //What proc do we want to call?
|
||||
var/list/trig_args = list() //What are the arguments for said proc?
|
||||
var/trig_message //Should we send a message to the person who stepped here?
|
||||
var/message_span_class = "notice" //If we're gonna send them a message, what span class to use?
|
||||
var/trig_single_use = FALSE //Is this only a single use trigger, or can it be used multiple times?
|
||||
var/has_been_used = FALSE //Has this trigger been set off yet?
|
||||
var/list/trig_targets = list() //This is set automatically if the other target vars are set.
|
||||
var/list/been_triggered_by = list() //Who has set this off so far?
|
||||
var/trig_single_use_per_triggerer = FALSE //Do we want to make so each atom can only trigger this once?
|
||||
var/trig_target_is_trigerrer = FALSE //Do we want to use the atom that trigerred us as the target?
|
||||
|
||||
/obj/effect/ctrigger/proc/can_use_trigger(atom/movable/mover)
|
||||
if(trig_single_use && has_been_used)
|
||||
return FALSE
|
||||
if(trig_single_use_per_triggerer && (mover in been_triggered_by))
|
||||
return FALSE
|
||||
if(!potential_triggerers.len)
|
||||
return TRUE
|
||||
else
|
||||
for(var/path in potential_triggerers)
|
||||
if(istype(mover,text2path(trim(path))))
|
||||
return TRUE
|
||||
else
|
||||
continue
|
||||
return FALSE
|
||||
|
||||
/obj/effect/ctrigger/Crossed(atom/movable/mover)
|
||||
. = ..()
|
||||
if(can_use_trigger(mover))
|
||||
if(trig_proc)
|
||||
if(trig_target_is_trigerrer)
|
||||
trig_targets = list(mover)
|
||||
if(trig_targets.len)
|
||||
var/testname = trig_proc
|
||||
//Find one of the 3 possible ways they could have written /proc/PROCNAME
|
||||
if(findtext(trig_proc, "/proc/"))
|
||||
testname = replacetext(trig_proc, "/proc/", "")
|
||||
else if(findtext(trig_proc, "/proc"))
|
||||
testname = replacetext(trig_proc, "/proc", "")
|
||||
else if(findtext(trig_proc, "proc/"))
|
||||
testname = replacetext(trig_proc, "proc/", "")
|
||||
//Clear out any parenthesis if they're a dummy
|
||||
testname = replacetext(testname, "()", "")
|
||||
for(var/trig_target in trig_targets)
|
||||
if(trig_target && !hascall(trig_target,testname))
|
||||
message_admins("TRIGGER ERROR: ONE OR MORE TRIGGER TARGETS LACKS THE MENTIONED PROC")
|
||||
return
|
||||
for(var/trig_target in trig_targets)
|
||||
call(trig_target,testname)(arglist(trig_args))
|
||||
else
|
||||
var/procpath = text2path(trig_proc)
|
||||
if(!procpath)
|
||||
message_admins("TRIGGER ERROR: INVALID PROC")
|
||||
return
|
||||
call(procpath)(arglist(trig_args))
|
||||
if(trig_message)
|
||||
to_chat(mover,"<span class='[message_span_class]'>"+trig_message+"</span>")
|
||||
has_been_used = TRUE
|
||||
been_triggered_by |= mover
|
||||
else
|
||||
return
|
||||
|
||||
/obj/effect/ctrigger/proc/update_trig_targets()
|
||||
trig_targets = list()
|
||||
for(var/path in trig_target_paths)
|
||||
var/trig_target_path = text2path(path)
|
||||
if(trig_target_path && trig_target_trigger_uid)
|
||||
var/list/candidates = get_all_of_type(trig_target_path)
|
||||
for(var/candidate in candidates)
|
||||
var/datum/cand_datum = candidate
|
||||
if(istype(cand_datum))
|
||||
if(cand_datum.trigger_uid == trig_target_trigger_uid)
|
||||
trig_targets += candidate
|
||||
continue
|
||||
continue
|
||||
if(!trig_targets.len)
|
||||
message_admins("TRIGGER ERROR: trig_targets STILL EMPTY AFTER CALLED update_trig_targets()")
|
||||
|
||||
/obj/effect/ctrigger/Initialize(mapload)
|
||||
. = ..()
|
||||
if(trig_target_paths.len)
|
||||
update_trig_targets()
|
||||
Reference in New Issue
Block a user