File standardisation (#13131)

* Adds the check components

* Adds in trailing newlines

* Converts all CRLF to LF

* Post merge EOF

* Post merge line endings

* Final commit
This commit is contained in:
AffectedArc07
2020-03-17 18:08:51 -04:00
committed by GitHub
parent ec19ea3d2d
commit 04ba5c1cc9
1451 changed files with 183694 additions and 183593 deletions
+244 -244
View File
@@ -1,244 +1,244 @@
#define FORWARD -1
#define BACKWARD 1
#define CONSTRUCTION_TOOL_BEHAVIOURS list(TOOL_CROWBAR, TOOL_SCREWDRIVER, TOOL_WELDER, TOOL_WRENCH)
/datum/construction
var/list/steps
var/atom/holder
var/result
var/list/steps_desc
var/taskpath = null // Path of job objective completed.
/datum/construction/New(atom)
..()
holder = atom
if(!holder) //don't want this without a holder
spawn
qdel(src)
set_desc(steps.len)
return
/datum/construction/proc/next_step(mob/user as mob)
steps.len--
if(!steps.len)
spawn_result(user)
else
set_desc(steps.len)
return
/datum/construction/proc/action(atom/used_atom,mob/user as mob)
return
/datum/construction/proc/check_step(atom/used_atom,mob/user as mob) //check last step only
var/valid_step = is_right_key(used_atom)
if(valid_step)
if(custom_action(valid_step, used_atom, user))
next_step(user)
return 1
return 0
/datum/construction/proc/is_right_key(atom/used_atom) // returns current step num if used_atom is of the right type.
var/list/L = steps[steps.len]
if(do_tool_or_atom_check(used_atom, L["key"]))
return steps.len
return 0
/datum/construction/proc/custom_action(step, used_atom, user)
if(istype(used_atom, /obj/item/stack/cable_coil))
var/obj/item/stack/cable_coil/C = used_atom
if(C.amount<4)
to_chat(user, ("<span class='warning'>There's not enough cable to finish the task.</span>"))
return 0
else
C.use(4)
playsound(holder, C.usesound, 50, 1)
else if(istype(used_atom, /obj/item/stack))
var/obj/item/stack/S = used_atom
if(S.amount < 5)
to_chat(user, ("<span class='warning'>There's not enough material in this stack.</span>"))
return 0
else
S.use(5)
else if(isitem(used_atom))
var/obj/item/I = used_atom
if(I.tool_behaviour in CONSTRUCTION_TOOL_BEHAVIOURS)
if(!I.use_tool(holder, user, 0, volume = I.tool_volume))
return 0
return 1
/datum/construction/proc/check_all_steps(atom/used_atom,mob/user as mob) //check all steps, remove matching one.
for(var/i=1;i<=steps.len;i++)
var/list/L = steps[i];
if(do_tool_or_atom_check(used_atom, L["key"]) && custom_action(i, used_atom, user))
steps[i]=null;//stupid byond list from list removal...
listclearnulls(steps);
if(!steps.len)
spawn_result(user)
return 1
return 0
/datum/construction/proc/spawn_result(mob/user as mob)
if(result)
if(taskpath)
var/datum/job_objective/task = user.mind.findJobTask(taskpath)
if(istype(task))
task.unit_completed()
new result(get_turf(holder))
spawn()
qdel(holder)
return
/datum/construction/proc/set_desc(index as num)
var/list/step = steps[index]
holder.desc = step["desc"]
return
/datum/construction/proc/try_consume(mob/user as mob, atom/used_atom, amount)
if(amount > 0)
// CABLES
if(istype(used_atom,/obj/item/stack/cable_coil))
var/obj/item/stack/cable_coil/coil=used_atom
if(!coil.use(amount))
to_chat(user, "<span class='warning'>You don't have enough cable! You need at least [amount] coils.</span>")
return 0
// TOOLS
if(isitem(used_atom))
var/obj/item/I = used_atom
if(I.tool_behaviour in CONSTRUCTION_TOOL_BEHAVIOURS)
if(!I.use(amount))
return 0
// STACKS
if(istype(used_atom,/obj/item/stack))
var/obj/item/stack/stack=used_atom
if(stack.amount < amount)
to_chat(user, "<span class='warning'>You don't have enough [stack]! You need at least [amount].</span>")
return 0
stack.use(amount)
return 1
/datum/construction/proc/do_tool_or_atom_check(used_atom, thing_to_check) //Checks if an atom is either a required thing; or if it's a required tool
if(istype(used_atom, thing_to_check))
return TRUE
else if(isitem(used_atom))
var/obj/item/I = used_atom
if(I.tool_behaviour == thing_to_check)
return TRUE
/datum/construction/reversible
var/index
/datum/construction/reversible/New(atom)
..()
index = steps.len
return
/datum/construction/reversible/proc/update_index(diff as num, mob/user as mob)
index+=diff
if(index==0)
spawn_result(user)
else
set_desc(index)
return
/datum/construction/reversible/is_right_key(atom/used_atom) // returns index step
var/list/L = steps[index]
if(do_tool_or_atom_check(used_atom, L["key"]))
return FORWARD //to the first step -> forward
else if(L["backkey"] && do_tool_or_atom_check(used_atom, L["backkey"]))
return BACKWARD //to the last step -> backwards
return 0
/datum/construction/reversible/check_step(atom/used_atom,mob/user as mob)
var/diff = is_right_key(used_atom)
if(diff)
if(custom_action(index, diff, used_atom, user))
update_index(diff, user)
return 1
return 0
/datum/construction/reversible/custom_action(index, diff, used_atom, user)
if(!..(index,used_atom,user))
return 0
return 1
#define state_next "next"
#define state_prev "prev"
/datum/construction/reversible2
var/index
var/base_icon = "durand"
/datum/construction/reversible2/New(atom)
..()
index = 1
return
/datum/construction/reversible2/proc/update_index(diff as num, mob/user as mob)
index-=diff
if(index==steps.len+1)
spawn_result(user)
else
set_desc(index)
return
/datum/construction/reversible2/proc/update_icon()
holder.icon_state="[base_icon]_[index]"
/datum/construction/reversible2/is_right_key(mob/user as mob,atom/used_atom) // returns index step
var/list/state = steps[index]
if(state_next in state)
var/list/step = state[state_next]
if(do_tool_or_atom_check(used_atom, step["key"]))
//if(L["consume"] && !try_consume(used_atom,L["consume"]))
// return 0
return FORWARD //to the first step -> forward
else if(state_prev in state)
var/list/step = state[state_prev]
if(do_tool_or_atom_check(used_atom, step["key"]))
//if(L["consume"] && !try_consume(used_atom,L["consume"]))
// return 0
return BACKWARD //to the first step -> forward
return 0
/datum/construction/reversible2/check_step(atom/used_atom,mob/user as mob)
var/diff = is_right_key(user,used_atom)
if(diff)
if(custom_action(index, diff, used_atom, user))
update_index(diff,user)
update_icon()
return 1
return 0
/datum/construction/reversible2/proc/fixText(text,user)
text = replacetext(text,"{USER}","[user]")
text = replacetext(text,"{HOLDER}","[holder]")
return text
/datum/construction/reversible2/custom_action(index, diff, used_atom, var/mob/user)
if(!..(index,used_atom,user))
return 0
var/list/step = steps[index]
var/list/state = step[diff==FORWARD ? state_next : state_prev]
user.visible_message(fixText(state["vis_msg"],user),fixText(state["self_msg"],user))
if("delete" in state)
qdel(used_atom)
else if("spawn" in state)
var/spawntype=state["spawn"]
var/atom/A = new spawntype(holder.loc)
if("amount" in state)
if(istype(A,/obj/item/stack/cable_coil))
var/obj/item/stack/cable_coil/C=A
C.amount=state["amount"]
if(istype(A,/obj/item/stack))
var/obj/item/stack/S=A
S.amount=state["amount"]
return 1
/datum/construction/reversible2/action(used_atom,user)
return check_step(used_atom,user)
#define FORWARD -1
#define BACKWARD 1
#define CONSTRUCTION_TOOL_BEHAVIOURS list(TOOL_CROWBAR, TOOL_SCREWDRIVER, TOOL_WELDER, TOOL_WRENCH)
/datum/construction
var/list/steps
var/atom/holder
var/result
var/list/steps_desc
var/taskpath = null // Path of job objective completed.
/datum/construction/New(atom)
..()
holder = atom
if(!holder) //don't want this without a holder
spawn
qdel(src)
set_desc(steps.len)
return
/datum/construction/proc/next_step(mob/user as mob)
steps.len--
if(!steps.len)
spawn_result(user)
else
set_desc(steps.len)
return
/datum/construction/proc/action(atom/used_atom,mob/user as mob)
return
/datum/construction/proc/check_step(atom/used_atom,mob/user as mob) //check last step only
var/valid_step = is_right_key(used_atom)
if(valid_step)
if(custom_action(valid_step, used_atom, user))
next_step(user)
return 1
return 0
/datum/construction/proc/is_right_key(atom/used_atom) // returns current step num if used_atom is of the right type.
var/list/L = steps[steps.len]
if(do_tool_or_atom_check(used_atom, L["key"]))
return steps.len
return 0
/datum/construction/proc/custom_action(step, used_atom, user)
if(istype(used_atom, /obj/item/stack/cable_coil))
var/obj/item/stack/cable_coil/C = used_atom
if(C.amount<4)
to_chat(user, ("<span class='warning'>There's not enough cable to finish the task.</span>"))
return 0
else
C.use(4)
playsound(holder, C.usesound, 50, 1)
else if(istype(used_atom, /obj/item/stack))
var/obj/item/stack/S = used_atom
if(S.amount < 5)
to_chat(user, ("<span class='warning'>There's not enough material in this stack.</span>"))
return 0
else
S.use(5)
else if(isitem(used_atom))
var/obj/item/I = used_atom
if(I.tool_behaviour in CONSTRUCTION_TOOL_BEHAVIOURS)
if(!I.use_tool(holder, user, 0, volume = I.tool_volume))
return 0
return 1
/datum/construction/proc/check_all_steps(atom/used_atom,mob/user as mob) //check all steps, remove matching one.
for(var/i=1;i<=steps.len;i++)
var/list/L = steps[i];
if(do_tool_or_atom_check(used_atom, L["key"]) && custom_action(i, used_atom, user))
steps[i]=null;//stupid byond list from list removal...
listclearnulls(steps);
if(!steps.len)
spawn_result(user)
return 1
return 0
/datum/construction/proc/spawn_result(mob/user as mob)
if(result)
if(taskpath)
var/datum/job_objective/task = user.mind.findJobTask(taskpath)
if(istype(task))
task.unit_completed()
new result(get_turf(holder))
spawn()
qdel(holder)
return
/datum/construction/proc/set_desc(index as num)
var/list/step = steps[index]
holder.desc = step["desc"]
return
/datum/construction/proc/try_consume(mob/user as mob, atom/used_atom, amount)
if(amount > 0)
// CABLES
if(istype(used_atom,/obj/item/stack/cable_coil))
var/obj/item/stack/cable_coil/coil=used_atom
if(!coil.use(amount))
to_chat(user, "<span class='warning'>You don't have enough cable! You need at least [amount] coils.</span>")
return 0
// TOOLS
if(isitem(used_atom))
var/obj/item/I = used_atom
if(I.tool_behaviour in CONSTRUCTION_TOOL_BEHAVIOURS)
if(!I.use(amount))
return 0
// STACKS
if(istype(used_atom,/obj/item/stack))
var/obj/item/stack/stack=used_atom
if(stack.amount < amount)
to_chat(user, "<span class='warning'>You don't have enough [stack]! You need at least [amount].</span>")
return 0
stack.use(amount)
return 1
/datum/construction/proc/do_tool_or_atom_check(used_atom, thing_to_check) //Checks if an atom is either a required thing; or if it's a required tool
if(istype(used_atom, thing_to_check))
return TRUE
else if(isitem(used_atom))
var/obj/item/I = used_atom
if(I.tool_behaviour == thing_to_check)
return TRUE
/datum/construction/reversible
var/index
/datum/construction/reversible/New(atom)
..()
index = steps.len
return
/datum/construction/reversible/proc/update_index(diff as num, mob/user as mob)
index+=diff
if(index==0)
spawn_result(user)
else
set_desc(index)
return
/datum/construction/reversible/is_right_key(atom/used_atom) // returns index step
var/list/L = steps[index]
if(do_tool_or_atom_check(used_atom, L["key"]))
return FORWARD //to the first step -> forward
else if(L["backkey"] && do_tool_or_atom_check(used_atom, L["backkey"]))
return BACKWARD //to the last step -> backwards
return 0
/datum/construction/reversible/check_step(atom/used_atom,mob/user as mob)
var/diff = is_right_key(used_atom)
if(diff)
if(custom_action(index, diff, used_atom, user))
update_index(diff, user)
return 1
return 0
/datum/construction/reversible/custom_action(index, diff, used_atom, user)
if(!..(index,used_atom,user))
return 0
return 1
#define state_next "next"
#define state_prev "prev"
/datum/construction/reversible2
var/index
var/base_icon = "durand"
/datum/construction/reversible2/New(atom)
..()
index = 1
return
/datum/construction/reversible2/proc/update_index(diff as num, mob/user as mob)
index-=diff
if(index==steps.len+1)
spawn_result(user)
else
set_desc(index)
return
/datum/construction/reversible2/proc/update_icon()
holder.icon_state="[base_icon]_[index]"
/datum/construction/reversible2/is_right_key(mob/user as mob,atom/used_atom) // returns index step
var/list/state = steps[index]
if(state_next in state)
var/list/step = state[state_next]
if(do_tool_or_atom_check(used_atom, step["key"]))
//if(L["consume"] && !try_consume(used_atom,L["consume"]))
// return 0
return FORWARD //to the first step -> forward
else if(state_prev in state)
var/list/step = state[state_prev]
if(do_tool_or_atom_check(used_atom, step["key"]))
//if(L["consume"] && !try_consume(used_atom,L["consume"]))
// return 0
return BACKWARD //to the first step -> forward
return 0
/datum/construction/reversible2/check_step(atom/used_atom,mob/user as mob)
var/diff = is_right_key(user,used_atom)
if(diff)
if(custom_action(index, diff, used_atom, user))
update_index(diff,user)
update_icon()
return 1
return 0
/datum/construction/reversible2/proc/fixText(text,user)
text = replacetext(text,"{USER}","[user]")
text = replacetext(text,"{HOLDER}","[holder]")
return text
/datum/construction/reversible2/custom_action(index, diff, used_atom, var/mob/user)
if(!..(index,used_atom,user))
return 0
var/list/step = steps[index]
var/list/state = step[diff==FORWARD ? state_next : state_prev]
user.visible_message(fixText(state["vis_msg"],user),fixText(state["self_msg"],user))
if("delete" in state)
qdel(used_atom)
else if("spawn" in state)
var/spawntype=state["spawn"]
var/atom/A = new spawntype(holder.loc)
if("amount" in state)
if(istype(A,/obj/item/stack/cable_coil))
var/obj/item/stack/cable_coil/C=A
C.amount=state["amount"]
if(istype(A,/obj/item/stack))
var/obj/item/stack/S=A
S.amount=state["amount"]
return 1
/datum/construction/reversible2/action(used_atom,user)
return check_step(used_atom,user)
+68 -68
View File
@@ -1,68 +1,68 @@
/*
* WARRANTY VOID IF CODE USED
*/
/datum/events
var/list/events
/datum/events/New()
..()
events = new
/datum/events/proc/addEventType(event_type as text)
if(!(event_type in events) || !islist(events[event_type]))
events[event_type] = list()
return 1
return
// Arguments: event_type as text, proc_holder as datum, proc_name as text
// Returns: New event, null on error.
/datum/events/proc/addEvent(event_type as text, proc_holder, proc_name as text)
if(!event_type || !proc_holder || !proc_name)
return
addEventType(event_type)
var/list/event = events[event_type]
var/datum/event/E = new /datum/event(proc_holder,proc_name)
event += E
return E
// Arguments: event_type as text, any number of additional arguments to pass to event handler
// Returns: null
/datum/events/proc/fireEvent()
//world << "Events in [args[1]] called"
var/list/event = listgetindex(events,args[1])
if(istype(event))
spawn(0)
for(var/datum/event/E in event)
if(!E.Fire(arglist(args.Copy(2))))
clearEvent(args[1],E)
return
// Arguments: event_type as text, E as /datum/event
// Returns: 1 if event cleared, null on error
/datum/events/proc/clearEvent(event_type as text, datum/event/E)
if(!event_type || !E)
return
var/list/event = listgetindex(events,event_type)
event -= E
return 1
/datum/event
var/listener
var/proc_name
/datum/event/New(tlistener,tprocname)
listener = tlistener
proc_name = tprocname
return ..()
/datum/event/proc/Fire()
//world << "Event fired"
if(listener)
call(listener,proc_name)(arglist(args))
return 1
return
/*
* WARRANTY VOID IF CODE USED
*/
/datum/events
var/list/events
/datum/events/New()
..()
events = new
/datum/events/proc/addEventType(event_type as text)
if(!(event_type in events) || !islist(events[event_type]))
events[event_type] = list()
return 1
return
// Arguments: event_type as text, proc_holder as datum, proc_name as text
// Returns: New event, null on error.
/datum/events/proc/addEvent(event_type as text, proc_holder, proc_name as text)
if(!event_type || !proc_holder || !proc_name)
return
addEventType(event_type)
var/list/event = events[event_type]
var/datum/event/E = new /datum/event(proc_holder,proc_name)
event += E
return E
// Arguments: event_type as text, any number of additional arguments to pass to event handler
// Returns: null
/datum/events/proc/fireEvent()
//world << "Events in [args[1]] called"
var/list/event = listgetindex(events,args[1])
if(istype(event))
spawn(0)
for(var/datum/event/E in event)
if(!E.Fire(arglist(args.Copy(2))))
clearEvent(args[1],E)
return
// Arguments: event_type as text, E as /datum/event
// Returns: 1 if event cleared, null on error
/datum/events/proc/clearEvent(event_type as text, datum/event/E)
if(!event_type || !E)
return
var/list/event = listgetindex(events,event_type)
event -= E
return 1
/datum/event
var/listener
var/proc_name
/datum/event/New(tlistener,tprocname)
listener = tlistener
proc_name = tprocname
return ..()
/datum/event/proc/Fire()
//world << "Event fired"
if(listener)
call(listener,proc_name)(arglist(args))
return 1
return
+152 -152
View File
@@ -1,152 +1,152 @@
/*
README:
The global_iterator datum is supposed to provide a simple and robust way to
create some constantly "looping" processes with ability to stop and restart them at will.
Generally, the only thing you want to play with (meaning, redefine) is the process() proc.
It must contain all the things you want done.
Control functions:
new - used to create datum. First argument (optional) - var list(to use in process() proc) as list,
second (optional) - autostart control.
If autostart == TRUE, the loop will be started immediately after datum creation.
start(list/arguments) - starts the loop. Takes arguments(optional) as a list, which is then used
by process() proc. Returns null if datum already active, 1 if loop started succesfully and 0 if there's
an error in supplied arguments (not list or empty list).
stop() - stops the loop. Returns null if datum is already inactive and 1 on success.
set_delay(new_delay) - sets the delay between iterations. Pretty selfexplanatory.
Returns 0 on error(new_delay is not numerical), 1 otherwise.
set_process_args(list/arguments) - passes the supplied arguments to the process() proc.
active() - Returns 1 if datum is active, 0 otherwise.
toggle() - toggles datum state. Returns new datum state (see active()).
Misc functions:
get_last_exec_time() - Returns the time of last iteration.
get_last_exec_time_as_text() - Returns the time of last iteration as text
Control vars:
delay - delay between iterations
check_for_null - if equals TRUE, on each iteration the supplied arguments will be checked for nulls.
If some varible equals null (and null only), the loop is stopped.
Usefull, if some var unexpectedly becomes null - due to object deletion, for example.
Of course, you can also check the variables inside process() proc to prevent runtime errors.
Data storage vars:
result - stores the value returned by process() proc
*/
/datum/global_iterator
var/control_switch = 0
var/delay = 10
var/list/arg_list = new
var/last_exec = null
var/check_for_null = 1
var/forbid_garbage = 0
var/result
var/state = 0
/datum/global_iterator/New(list/arguments=null,autostart=1)
delay = delay>0?(delay):1
if(forbid_garbage) //prevents garbage collection with tag != null
tag = "\ref[src]"
set_process_args(arguments)
if(autostart)
start()
return
/datum/global_iterator/proc/main()
state = 1
while(src && control_switch)
last_exec = world.timeofday
if(check_for_null && has_null_args())
stop()
return 0
result = process(arglist(arg_list))
for(var/sleep_time=delay;sleep_time>0;sleep_time--) //uhh, this is ugly. But I see no other way to terminate sleeping proc. Such disgrace.
if(!control_switch)
return 0
sleep(1)
return 0
/datum/global_iterator/proc/start(list/arguments=null)
if(active())
return
if(arguments)
if(!set_process_args(arguments))
return 0
if(!state_check()) //the main loop is sleeping, wait for it to terminate.
return
control_switch = 1
spawn()
state = main()
return 1
/datum/global_iterator/proc/stop()
if(!active())
return
control_switch = 0
spawn(-1) //report termination error but don't wait for state_check().
state_check()
return 1
/datum/global_iterator/proc/state_check()
var/lag = 0
while(state)
sleep(1)
if(++lag>10)
CRASH("The global_iterator loop \ref[src] failed to terminate in designated timeframe. This may be caused by server lagging.")
return 1
/datum/global_iterator/process()
return
/datum/global_iterator/proc/active()
return control_switch
/datum/global_iterator/proc/has_null_args()
if(null in arg_list)
return 1
return 0
/datum/global_iterator/proc/set_delay(new_delay)
if(isnum(new_delay))
delay = max(1, round(new_delay))
return 1
else
return 0
/datum/global_iterator/proc/get_last_exec_time()
return (last_exec||0)
/datum/global_iterator/proc/get_last_exec_time_as_text()
return (time2text(last_exec)||"Wasn't executed yet")
/datum/global_iterator/proc/set_process_args(list/arguments)
if(arguments && istype(arguments, /list) && arguments.len)
arg_list = arguments
return 1
else
// to_chat(world, "<span class='warning'>Invalid arguments supplied for [src.type], ref = \ref[src]</span>")
return 0
/datum/global_iterator/proc/toggle_null_checks()
check_for_null = !check_for_null
return check_for_null
/datum/global_iterator/proc/toggle()
if(!stop())
start()
return active()
/*
README:
The global_iterator datum is supposed to provide a simple and robust way to
create some constantly "looping" processes with ability to stop and restart them at will.
Generally, the only thing you want to play with (meaning, redefine) is the process() proc.
It must contain all the things you want done.
Control functions:
new - used to create datum. First argument (optional) - var list(to use in process() proc) as list,
second (optional) - autostart control.
If autostart == TRUE, the loop will be started immediately after datum creation.
start(list/arguments) - starts the loop. Takes arguments(optional) as a list, which is then used
by process() proc. Returns null if datum already active, 1 if loop started succesfully and 0 if there's
an error in supplied arguments (not list or empty list).
stop() - stops the loop. Returns null if datum is already inactive and 1 on success.
set_delay(new_delay) - sets the delay between iterations. Pretty selfexplanatory.
Returns 0 on error(new_delay is not numerical), 1 otherwise.
set_process_args(list/arguments) - passes the supplied arguments to the process() proc.
active() - Returns 1 if datum is active, 0 otherwise.
toggle() - toggles datum state. Returns new datum state (see active()).
Misc functions:
get_last_exec_time() - Returns the time of last iteration.
get_last_exec_time_as_text() - Returns the time of last iteration as text
Control vars:
delay - delay between iterations
check_for_null - if equals TRUE, on each iteration the supplied arguments will be checked for nulls.
If some varible equals null (and null only), the loop is stopped.
Usefull, if some var unexpectedly becomes null - due to object deletion, for example.
Of course, you can also check the variables inside process() proc to prevent runtime errors.
Data storage vars:
result - stores the value returned by process() proc
*/
/datum/global_iterator
var/control_switch = 0
var/delay = 10
var/list/arg_list = new
var/last_exec = null
var/check_for_null = 1
var/forbid_garbage = 0
var/result
var/state = 0
/datum/global_iterator/New(list/arguments=null,autostart=1)
delay = delay>0?(delay):1
if(forbid_garbage) //prevents garbage collection with tag != null
tag = "\ref[src]"
set_process_args(arguments)
if(autostart)
start()
return
/datum/global_iterator/proc/main()
state = 1
while(src && control_switch)
last_exec = world.timeofday
if(check_for_null && has_null_args())
stop()
return 0
result = process(arglist(arg_list))
for(var/sleep_time=delay;sleep_time>0;sleep_time--) //uhh, this is ugly. But I see no other way to terminate sleeping proc. Such disgrace.
if(!control_switch)
return 0
sleep(1)
return 0
/datum/global_iterator/proc/start(list/arguments=null)
if(active())
return
if(arguments)
if(!set_process_args(arguments))
return 0
if(!state_check()) //the main loop is sleeping, wait for it to terminate.
return
control_switch = 1
spawn()
state = main()
return 1
/datum/global_iterator/proc/stop()
if(!active())
return
control_switch = 0
spawn(-1) //report termination error but don't wait for state_check().
state_check()
return 1
/datum/global_iterator/proc/state_check()
var/lag = 0
while(state)
sleep(1)
if(++lag>10)
CRASH("The global_iterator loop \ref[src] failed to terminate in designated timeframe. This may be caused by server lagging.")
return 1
/datum/global_iterator/process()
return
/datum/global_iterator/proc/active()
return control_switch
/datum/global_iterator/proc/has_null_args()
if(null in arg_list)
return 1
return 0
/datum/global_iterator/proc/set_delay(new_delay)
if(isnum(new_delay))
delay = max(1, round(new_delay))
return 1
else
return 0
/datum/global_iterator/proc/get_last_exec_time()
return (last_exec||0)
/datum/global_iterator/proc/get_last_exec_time_as_text()
return (time2text(last_exec)||"Wasn't executed yet")
/datum/global_iterator/proc/set_process_args(list/arguments)
if(arguments && istype(arguments, /list) && arguments.len)
arg_list = arguments
return 1
else
// to_chat(world, "<span class='warning'>Invalid arguments supplied for [src.type], ref = \ref[src]</span>")
return 0
/datum/global_iterator/proc/toggle_null_checks()
check_for_null = !check_for_null
return check_for_null
/datum/global_iterator/proc/toggle()
if(!stop())
start()
return active()
+1 -1
View File
@@ -161,4 +161,4 @@
var/datum/map_template/shuttle/S = new shuttle_type()
shuttle_templates[S.shuttle_id] = S
map_templates[S.shuttle_id] = S
map_templates[S.shuttle_id] = S
+237 -237
View File
@@ -1,237 +1,237 @@
//wrapper
/proc/do_teleport(ateleatom, adestination, aprecision=0, afteleport=1, aeffectin=null, aeffectout=null, asoundin=null, asoundout=null, bypass_area_flag=FALSE)
var/datum/teleport/instant/science/D = new
if(D.start(arglist(args)))
return 1
return 0
/datum/teleport
var/atom/movable/teleatom //atom to teleport
var/atom/destination //destination to teleport to
var/precision = 0 //teleport precision
var/datum/effect_system/effectin //effect to show right before teleportation
var/datum/effect_system/effectout //effect to show right after teleportation
var/soundin //soundfile to play before teleportation
var/soundout //soundfile to play after teleportation
var/force_teleport = 1 //if false, teleport will use Move() proc (dense objects will prevent teleportation)
var/ignore_area_flag = FALSE
/datum/teleport/proc/start(ateleatom, adestination, aprecision=0, afteleport=1, aeffectin=null, aeffectout=null, asoundin=null, asoundout=null, bypass_area_flag=FALSE)
if(!initTeleport(arglist(args)))
return 0
return 1
/datum/teleport/proc/initTeleport(ateleatom, adestination, aprecision, afteleport, aeffectin, aeffectout, asoundin, asoundout, bypass_area_flag=FALSE)
if(!setTeleatom(ateleatom))
return 0
if(!setDestination(adestination))
return 0
if(!setPrecision(aprecision))
return 0
setEffects(aeffectin,aeffectout)
setForceTeleport(afteleport)
setSounds(asoundin,asoundout)
ignore_area_flag = bypass_area_flag
return 1
//must succeed
/datum/teleport/proc/setPrecision(aprecision)
if(isnum(aprecision))
precision = aprecision
return 1
return 0
//must succeed
/datum/teleport/proc/setDestination(atom/adestination)
if(istype(adestination))
destination = adestination
return 1
return 0
//must succeed in most cases
/datum/teleport/proc/setTeleatom(atom/movable/ateleatom)
if(istype(ateleatom, /obj/effect) && !istype(ateleatom, /obj/effect/dummy/chameleon))
qdel(ateleatom)
return 0
if(istype(ateleatom))
teleatom = ateleatom
return 1
return 0
//custom effects must be properly set up first for instant-type teleports
//optional
/datum/teleport/proc/setEffects(datum/effect_system/aeffectin=null,datum/effect_system/aeffectout=null)
effectin = istype(aeffectin) ? aeffectin : null
effectout = istype(aeffectout) ? aeffectout : null
return 1
//optional
/datum/teleport/proc/setForceTeleport(afteleport)
force_teleport = afteleport
return 1
//optional
/datum/teleport/proc/setSounds(asoundin=null,asoundout=null)
soundin = isfile(asoundin) ? asoundin : null
soundout = isfile(asoundout) ? asoundout : null
return 1
//placeholder
/datum/teleport/proc/teleportChecks()
return 1
/datum/teleport/proc/playSpecials(atom/location,datum/effect_system/effect,sound)
if(location)
if(effect)
spawn(-1)
src = null
effect.attach(location)
effect.start()
if(sound)
spawn(-1)
src = null
playsound(location,sound,60,1)
return
//do the monkey dance
/datum/teleport/proc/doTeleport()
var/turf/destturf
var/turf/curturf = get_turf(teleatom)
var/area/curarea = get_area(curturf)
if(precision)
var/list/posturfs = list()
var/center = get_turf(destination)
if(!center)
center = destination
for(var/turf/T in range(precision,center))
posturfs.Add(T)
destturf = safepick(posturfs)
else
destturf = get_turf(destination)
if(!is_teleport_allowed(destturf.z) && !ignore_area_flag)
return 0
// Only check the destination zlevel for is_teleport_allowed. Checking origin as well breaks ERT teleporters.
var/area/destarea = get_area(destturf)
if(!ignore_area_flag)
if(curarea.tele_proof)
return 0
if(destarea.tele_proof)
return 0
if(!destturf || !curturf)
return 0
playSpecials(curturf,effectin,soundin)
if(force_teleport)
teleatom.forceMove(destturf)
playSpecials(destturf,effectout,soundout)
else
if(teleatom.Move(destturf))
playSpecials(destturf,effectout,soundout)
if(isliving(teleatom))
var/mob/living/L = teleatom
if(L.buckled)
L.buckled.unbuckle_mob(L, force = TRUE)
if(L.has_buckled_mobs())
L.unbuckle_all_mobs(force = TRUE)
destarea.Entered(teleatom)
return 1
/datum/teleport/proc/teleport()
if(teleportChecks())
return doTeleport()
return 0
/datum/teleport/instant //teleports when datum is created
start(ateleatom, adestination, aprecision=0, afteleport=1, aeffectin=null, aeffectout=null, asoundin=null, asoundout=null)
if(..())
if(teleport())
return 1
return 0
/datum/teleport/instant/science
/datum/teleport/instant/science/setEffects(datum/effect_system/aeffectin,datum/effect_system/aeffectout)
if(aeffectin==null || aeffectout==null)
var/datum/effect_system/spark_spread/aeffect = new
aeffect.set_up(5, 1, teleatom)
effectin = effectin || aeffect
effectout = effectout || aeffect
return 1
else
return ..()
/datum/teleport/instant/science/setPrecision(aprecision)
..()
if(!is_admin_level(destination.z))
if(istype(teleatom, /obj/item/storage/backpack/holding))
precision = rand(1, 100)
var/list/bagholding = teleatom.search_contents_for(/obj/item/storage/backpack/holding)
if(bagholding.len)
precision = max(rand(1, 100)*bagholding.len, 100)
if(istype(teleatom, /mob/living))
var/mob/living/MM = teleatom
to_chat(MM, "<span class='warning'>The bluespace interface on your bag of holding interferes with the teleport!</span>")
return 1
// Safe location finder
/proc/find_safe_turf(zlevel, list/zlevels, extended_safety_checks = FALSE)
if(!zlevels)
if(zlevel)
zlevels = list(zlevel)
else
zlevels = levels_by_trait(STATION_LEVEL)
var/cycles = 1000
for(var/cycle in 1 to cycles)
// DRUNK DIALLING WOOOOOOOOO
var/x = rand(1, world.maxx)
var/y = rand(1, world.maxy)
var/z = pick(zlevels)
var/random_location = locate(x,y,z)
if(!isfloorturf(random_location))
continue
var/turf/simulated/floor/F = random_location
if(!F.air)
continue
var/datum/gas_mixture/A = F.air
// Can most things breathe?
if(A.trace_gases.len)
continue
if(A.oxygen < 16)
continue
if(A.toxins)
continue
if(A.carbon_dioxide >= 10)
continue
// Aim for goldilocks temperatures and pressure
if((A.temperature <= 270) || (A.temperature >= 360))
continue
var/pressure = A.return_pressure()
if((pressure <= 20) || (pressure >= 550))
continue
if(extended_safety_checks)
if(islava(F)) //chasms aren't /floor, and so are pre-filtered
var/turf/simulated/floor/plating/lava/L = F
if(!L.is_safe())
continue
// DING! You have passed the gauntlet, and are "probably" safe.
return F
//wrapper
/proc/do_teleport(ateleatom, adestination, aprecision=0, afteleport=1, aeffectin=null, aeffectout=null, asoundin=null, asoundout=null, bypass_area_flag=FALSE)
var/datum/teleport/instant/science/D = new
if(D.start(arglist(args)))
return 1
return 0
/datum/teleport
var/atom/movable/teleatom //atom to teleport
var/atom/destination //destination to teleport to
var/precision = 0 //teleport precision
var/datum/effect_system/effectin //effect to show right before teleportation
var/datum/effect_system/effectout //effect to show right after teleportation
var/soundin //soundfile to play before teleportation
var/soundout //soundfile to play after teleportation
var/force_teleport = 1 //if false, teleport will use Move() proc (dense objects will prevent teleportation)
var/ignore_area_flag = FALSE
/datum/teleport/proc/start(ateleatom, adestination, aprecision=0, afteleport=1, aeffectin=null, aeffectout=null, asoundin=null, asoundout=null, bypass_area_flag=FALSE)
if(!initTeleport(arglist(args)))
return 0
return 1
/datum/teleport/proc/initTeleport(ateleatom, adestination, aprecision, afteleport, aeffectin, aeffectout, asoundin, asoundout, bypass_area_flag=FALSE)
if(!setTeleatom(ateleatom))
return 0
if(!setDestination(adestination))
return 0
if(!setPrecision(aprecision))
return 0
setEffects(aeffectin,aeffectout)
setForceTeleport(afteleport)
setSounds(asoundin,asoundout)
ignore_area_flag = bypass_area_flag
return 1
//must succeed
/datum/teleport/proc/setPrecision(aprecision)
if(isnum(aprecision))
precision = aprecision
return 1
return 0
//must succeed
/datum/teleport/proc/setDestination(atom/adestination)
if(istype(adestination))
destination = adestination
return 1
return 0
//must succeed in most cases
/datum/teleport/proc/setTeleatom(atom/movable/ateleatom)
if(istype(ateleatom, /obj/effect) && !istype(ateleatom, /obj/effect/dummy/chameleon))
qdel(ateleatom)
return 0
if(istype(ateleatom))
teleatom = ateleatom
return 1
return 0
//custom effects must be properly set up first for instant-type teleports
//optional
/datum/teleport/proc/setEffects(datum/effect_system/aeffectin=null,datum/effect_system/aeffectout=null)
effectin = istype(aeffectin) ? aeffectin : null
effectout = istype(aeffectout) ? aeffectout : null
return 1
//optional
/datum/teleport/proc/setForceTeleport(afteleport)
force_teleport = afteleport
return 1
//optional
/datum/teleport/proc/setSounds(asoundin=null,asoundout=null)
soundin = isfile(asoundin) ? asoundin : null
soundout = isfile(asoundout) ? asoundout : null
return 1
//placeholder
/datum/teleport/proc/teleportChecks()
return 1
/datum/teleport/proc/playSpecials(atom/location,datum/effect_system/effect,sound)
if(location)
if(effect)
spawn(-1)
src = null
effect.attach(location)
effect.start()
if(sound)
spawn(-1)
src = null
playsound(location,sound,60,1)
return
//do the monkey dance
/datum/teleport/proc/doTeleport()
var/turf/destturf
var/turf/curturf = get_turf(teleatom)
var/area/curarea = get_area(curturf)
if(precision)
var/list/posturfs = list()
var/center = get_turf(destination)
if(!center)
center = destination
for(var/turf/T in range(precision,center))
posturfs.Add(T)
destturf = safepick(posturfs)
else
destturf = get_turf(destination)
if(!is_teleport_allowed(destturf.z) && !ignore_area_flag)
return 0
// Only check the destination zlevel for is_teleport_allowed. Checking origin as well breaks ERT teleporters.
var/area/destarea = get_area(destturf)
if(!ignore_area_flag)
if(curarea.tele_proof)
return 0
if(destarea.tele_proof)
return 0
if(!destturf || !curturf)
return 0
playSpecials(curturf,effectin,soundin)
if(force_teleport)
teleatom.forceMove(destturf)
playSpecials(destturf,effectout,soundout)
else
if(teleatom.Move(destturf))
playSpecials(destturf,effectout,soundout)
if(isliving(teleatom))
var/mob/living/L = teleatom
if(L.buckled)
L.buckled.unbuckle_mob(L, force = TRUE)
if(L.has_buckled_mobs())
L.unbuckle_all_mobs(force = TRUE)
destarea.Entered(teleatom)
return 1
/datum/teleport/proc/teleport()
if(teleportChecks())
return doTeleport()
return 0
/datum/teleport/instant //teleports when datum is created
start(ateleatom, adestination, aprecision=0, afteleport=1, aeffectin=null, aeffectout=null, asoundin=null, asoundout=null)
if(..())
if(teleport())
return 1
return 0
/datum/teleport/instant/science
/datum/teleport/instant/science/setEffects(datum/effect_system/aeffectin,datum/effect_system/aeffectout)
if(aeffectin==null || aeffectout==null)
var/datum/effect_system/spark_spread/aeffect = new
aeffect.set_up(5, 1, teleatom)
effectin = effectin || aeffect
effectout = effectout || aeffect
return 1
else
return ..()
/datum/teleport/instant/science/setPrecision(aprecision)
..()
if(!is_admin_level(destination.z))
if(istype(teleatom, /obj/item/storage/backpack/holding))
precision = rand(1, 100)
var/list/bagholding = teleatom.search_contents_for(/obj/item/storage/backpack/holding)
if(bagholding.len)
precision = max(rand(1, 100)*bagholding.len, 100)
if(istype(teleatom, /mob/living))
var/mob/living/MM = teleatom
to_chat(MM, "<span class='warning'>The bluespace interface on your bag of holding interferes with the teleport!</span>")
return 1
// Safe location finder
/proc/find_safe_turf(zlevel, list/zlevels, extended_safety_checks = FALSE)
if(!zlevels)
if(zlevel)
zlevels = list(zlevel)
else
zlevels = levels_by_trait(STATION_LEVEL)
var/cycles = 1000
for(var/cycle in 1 to cycles)
// DRUNK DIALLING WOOOOOOOOO
var/x = rand(1, world.maxx)
var/y = rand(1, world.maxy)
var/z = pick(zlevels)
var/random_location = locate(x,y,z)
if(!isfloorturf(random_location))
continue
var/turf/simulated/floor/F = random_location
if(!F.air)
continue
var/datum/gas_mixture/A = F.air
// Can most things breathe?
if(A.trace_gases.len)
continue
if(A.oxygen < 16)
continue
if(A.toxins)
continue
if(A.carbon_dioxide >= 10)
continue
// Aim for goldilocks temperatures and pressure
if((A.temperature <= 270) || (A.temperature >= 360))
continue
var/pressure = A.return_pressure()
if((pressure <= 20) || (pressure >= 550))
continue
if(extended_safety_checks)
if(islava(F)) //chasms aren't /floor, and so are pre-filtered
var/turf/simulated/floor/plating/lava/L = F
if(!L.is_safe())
continue
// DING! You have passed the gauntlet, and are "probably" safe.
return F
+60 -60
View File
@@ -1,60 +1,60 @@
/datum/topic_input
var/href
var/list/href_list
/datum/topic_input/New(thref,list/thref_list)
href = thref
href_list = thref_list.Copy()
return
/datum/topic_input/proc/get(i)
return listgetindex(href_list,i)
/datum/topic_input/proc/getAndLocate(i)
var/t = get(i)
if(t)
t = locate(t)
return t || null
/datum/topic_input/proc/getNum(i)
var/t = get(i)
if(t)
t = text2num(t)
return isnum(t) ? t : null
/datum/topic_input/proc/getObj(i)
var/t = getAndLocate(i)
return isobj(t) ? t : null
/datum/topic_input/proc/getMob(i)
var/t = getAndLocate(i)
return ismob(t) ? t : null
/datum/topic_input/proc/getTurf(i)
var/t = getAndLocate(i)
return isturf(t) ? t : null
/datum/topic_input/proc/getAtom(i)
return getType(i,/atom)
/datum/topic_input/proc/getArea(i)
var/t = getAndLocate(i)
return isarea(t) ? t : null
/datum/topic_input/proc/getStr(i)//params should always be text, but...
var/t = get(i)
return istext(t) ? t : null
/datum/topic_input/proc/getType(i,type)
var/t = getAndLocate(i)
return istype(t,type) ? t : null
/datum/topic_input/proc/getPath(i)
var/t = get(i)
if(t)
t = text2path(t)
return ispath(t) ? t : null
/datum/topic_input/proc/getList(i)
var/t = getAndLocate(i)
return islist(t) ? t : null
/datum/topic_input
var/href
var/list/href_list
/datum/topic_input/New(thref,list/thref_list)
href = thref
href_list = thref_list.Copy()
return
/datum/topic_input/proc/get(i)
return listgetindex(href_list,i)
/datum/topic_input/proc/getAndLocate(i)
var/t = get(i)
if(t)
t = locate(t)
return t || null
/datum/topic_input/proc/getNum(i)
var/t = get(i)
if(t)
t = text2num(t)
return isnum(t) ? t : null
/datum/topic_input/proc/getObj(i)
var/t = getAndLocate(i)
return isobj(t) ? t : null
/datum/topic_input/proc/getMob(i)
var/t = getAndLocate(i)
return ismob(t) ? t : null
/datum/topic_input/proc/getTurf(i)
var/t = getAndLocate(i)
return isturf(t) ? t : null
/datum/topic_input/proc/getAtom(i)
return getType(i,/atom)
/datum/topic_input/proc/getArea(i)
var/t = getAndLocate(i)
return isarea(t) ? t : null
/datum/topic_input/proc/getStr(i)//params should always be text, but...
var/t = get(i)
return istext(t) ? t : null
/datum/topic_input/proc/getType(i,type)
var/t = getAndLocate(i)
return istype(t,type) ? t : null
/datum/topic_input/proc/getPath(i)
var/t = get(i)
if(t)
t = text2path(t)
return ispath(t) ? t : null
/datum/topic_input/proc/getList(i)
var/t = getAndLocate(i)
return islist(t) ? t : null