diff --git a/code/datums/helper_datums/global_iterator.dm b/code/datums/helper_datums/global_iterator.dm
index b0f0bc73eab..08546a81ed4 100644
--- a/code/datums/helper_datums/global_iterator.dm
+++ b/code/datums/helper_datums/global_iterator.dm
@@ -55,6 +55,7 @@ Data storage vars:
var/check_for_null = 1
var/forbid_garbage = 0
var/result
+ var/state = 0
New(list/arguments=null,autostart=1)
if(forbid_garbage) //prevents garbage collection with tag != null
@@ -65,13 +66,21 @@ Data storage vars:
return
proc/main()
+ src.state = 1
while(src && control_switch)
last_exec = world.timeofday
if(check_for_null && has_null_args())
- return src.stop()
+ src.stop()
+ return 0
result = src.process(arglist(arg_list))
- sleep(delay)
- return
+ if(src.delay>0)
+ for(var/sleep_time=src.delay;sleep_time>0;sleep_time--) //uhh, this is ugly. But I see no other way to terminate sleeping proc. Such disgrace.
+ if(!src.control_switch)
+ return 0
+ sleep(1)
+ else
+ sleep(src.delay) //delay can also be 0 and -1
+ return 0
proc/start(list/arguments=null)
if(src.active())
@@ -79,15 +88,28 @@ Data storage vars:
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()
- src.main()
+ src.state = src.main()
return 1
proc/stop()
if(!src.active())
return
control_switch = 0
+ if(!state_check())
+ return
+ return 1
+
+ proc/state_check()
+ var/lag = 0
+ while(src.state)
+ sleep(1)
+ if(++lag>10)
+ log_game("The global_iterator loop \ref[src] failed to terminate in designated timeframe. The supplied arguments were {[list2params(arg_list)]}")
+ return 0
return 1
proc/process()
@@ -97,13 +119,8 @@ Data storage vars:
return control_switch
proc/has_null_args()
- if(null in arg_list) //Hope no "" or 0 errors here.
+ if(null in arg_list)
return 1
-/*
- for(var/V in arg_list)
- if(isnull(V))
- return 1
-*/
return 0
diff --git a/code/game/machinery/atmoalter/canister.dm b/code/game/machinery/atmoalter/canister.dm
index 4a1be3644ed..2209e229996 100644
--- a/code/game/machinery/atmoalter/canister.dm
+++ b/code/game/machinery/atmoalter/canister.dm
@@ -134,6 +134,18 @@
/obj/machinery/portable_atmospherics/canister/return_air()
return air_contents
+/obj/machinery/portable_atmospherics/canister/proc/return_temperature()
+ var/datum/gas_mixture/GM = src.return_air()
+ if(GM && GM.volume>0)
+ return GM.temperature
+ return 0
+
+/obj/machinery/portable_atmospherics/canister/proc/return_pressure()
+ var/datum/gas_mixture/GM = src.return_air()
+ if(GM && GM.volume>0)
+ return GM.return_pressure()
+ return 0
+
/obj/machinery/portable_atmospherics/canister/blob_act()
src.health -= 1
healthcheck()
diff --git a/code/game/machinery/turrets.dm b/code/game/machinery/turrets.dm
index e21e8ca9e74..5ce1c9d8c95 100644
--- a/code/game/machinery/turrets.dm
+++ b/code/game/machinery/turrets.dm
@@ -12,10 +12,10 @@
/area/turret_protected/Entered(O)
..()
- if (istype(O, /mob))
- if (!istype(O, /mob/living/silicon))
- if (!(O in turretTargets))
- turretTargets += O
+// world << "[O] entered[src.x],[src.y],[src.z]"
+ if (istype(O, /mob/living/carbon))
+ if (!(O in turretTargets))
+ turretTargets += O
else if (istype(O, /obj/mecha))
var/obj/mecha/M = O
if (M.occupant)
@@ -24,6 +24,7 @@
return 1
/area/turret_protected/Exited(O)
+// world << "[O] exited [src.x],[src.y],[src.z]"
if (istype(O, /mob))
if (!istype(O, /mob/living/silicon))
if (O in turretTargets)
@@ -35,16 +36,9 @@
else if (istype(O, /obj/mecha))
if (O in turretTargets)
turretTargets -= O
-
- if (turretTargets.len == 0)
- popDownTurrets()
-
+ ..()
return 1
-/area/turret_protected/proc/popDownTurrets()
- for (var/obj/machinery/turret/aTurret in src)
- if (!aTurret.isDown())
- aTurret.popDown()
/obj/machinery/turret
name = "turret"
@@ -67,12 +61,19 @@
use_power = 1
idle_power_usage = 50
active_power_usage = 300
+// var/list/targets
+ var/atom/movable/cur_target
+ var/targeting_active = 0
+ var/area/turret_protected/protected_area
+
/obj/machinery/turret/New()
spark_system = new /datum/effects/system/spark_spread
spark_system.set_up(5, 0, src)
spark_system.attach(src)
+// targets = new
..()
+ return
/obj/machinery/turretcover
name = "pop-up turret cover"
@@ -108,122 +109,98 @@
src.lasers = lethal
src.power_change()
+
+/obj/machinery/turret/proc/get_protected_area()
+ var/area/turret_protected/TP = get_area(src)
+ if(istype(TP))
+ return TP
+ return
+
+/obj/machinery/turret/proc/check_target(var/atom/movable/T as mob|obj)
+ if(T && T in protected_area.turretTargets)
+ if(istype(T, /mob/living/carbon))
+ var/mob/living/carbon/MC = T
+ if(!MC.stat)
+ if(!MC.lying || lasers)
+ return 1
+ else if(istype(T, /obj/mecha))
+ var/obj/mecha/ME = T
+ if(ME.occupant)
+ return 1
+ return 0
+
+/obj/machinery/turret/proc/get_new_target()
+ var/list/new_targets = new
+ var/new_target
+ for(var/mob/living/carbon/M in protected_area.turretTargets)
+ if(!M.stat)
+ if(!M.lying || lasers)
+ new_targets += M
+ for(var/obj/mecha/M in protected_area.turretTargets)
+ if(M.occupant)
+ new_targets += M
+ if(new_targets.len)
+ new_target = pick(new_targets)
+ return new_target
+
+
/obj/machinery/turret/process()
- listcheck()
if(stat & (NOPOWER|BROKEN))
return
- if(lastfired && world.time - lastfired < shot_delay)
- return
- lastfired = world.time
- if (src.cover==null)
+ if(src.cover==null)
src.cover = new /obj/machinery/turretcover(src.loc)
- var/loc = src.loc
- if (istype(loc, /turf))
- loc = loc:loc
- if (!istype(loc, /area))
- world << text("Badly positioned turret - loc.loc is [].", loc)
+ protected_area = get_protected_area()
+ if(!protected_area || protected_area.turretTargets.len<=0 || !enabled)
+ if(!isDown() && !isPopping())
+ popDown()
return
- var/area/area = loc
- if (istype(area, /area))
- if (istype(loc, /area/turret_protected))
- src.wasvalid = 1
- var/area/turret_protected/tarea = loc
+ if(!check_target(cur_target)) //if current target fails target check
+ cur_target = get_new_target() //get new target
-
- if (tarea.turretTargets.len>0 && enabled)
- if (!isPopping())
- if (isDown())
- popUp()
- use_power = 2
- else
- targetting()
+ if(cur_target) //if it's found, proceed
+// world << "[cur_target]"
+ if(!isPopping())
+ if(isDown())
+ popUp()
+ use_power = 2
else
- if (!isPopping())
- if (!isDown())
- popDown()
- use_power = 1
- else
- if (src.wasvalid)
- src.die()
- else
- world << text("ERROR: Turret at [x], [y], [z] is NOT in a turret-protected area!")
-
-/obj/machinery/turret/proc/listcheck()
- for (var/mob/living/carbon/guy in loc.loc)
- if (guy in loc.loc:turretTargets)
- continue
- if (guy.lying && !lasers)
- continue
- if (!guy.stat)
- loc.loc:turretTargets += guy
+ spawn()
+ if(!targeting_active)
+ targeting_active = 1
+ target()
+ targeting_active = 0
+ else if(!isPopping())//else, pop down
+ if(!isDown())
+ popDown()
+ use_power = 1
+ return
-/obj/machinery/turret/proc/targetting()
- var/mob/target
- var/notarget = 0
- do
+/obj/machinery/turret/proc/target()
+ while(src && check_target(cur_target))
+ src.dir = get_dir(src, cur_target)
+ shootAt(cur_target)
+ sleep(shot_delay)
+ return
- if (notarget >= 20)
- return
- if (target)
- if (!istype(target.loc.loc, loc.loc))
- loc.loc:Exited(target)
- target = null
- if (target)
- if ((target.lying && !lasers) || target.stat)
- loc.loc:Exited(target)
- target = null
- if (!target)
- listcheck()
- if (!lasers)
- for (var/mob/possible in loc.loc:turretTargets)
- if (!istype(possible.loc.loc, loc.loc))
- loc.loc:Exited(possible)
- continue
- if (possible.stat)
- loc.loc:Exited(possible)
- notarget++
- continue
- if (possible.lying)
- loc.loc:Exited(possible)
- notarget++
- continue
- if (!target)
- target = possible
- notarget = 0
- break
- else
- for (var/mob/possible in loc.loc:turretTargets)
- if (!istype(possible.loc.loc, loc.loc))
- loc.loc:Exited(possible)
- continue
- if (possible.stat)
- loc.loc:Exited(possible)
- notarget++
- continue
- if (!target)
- target = possible
- notarget = 0
- break
- if (target)
- src.dir = get_dir(src, target)
- if (src.enabled)
- if (istype(target, /mob/living))
- if (!target.stat)
- src.shootAt(target)
- else
- loc.loc:Exited(target)
- target = null
- else if (istype(target, /obj/mecha))
- var/obj/mecha/mecha = target
- if(!mecha.occupant)
- if (mecha in loc.loc:turretTargets)
- loc.loc:turretTargets -= mecha
- target = null
- else
- src.shootAt(target)
- else sleep(1)
- while(!target && loc.loc:turretTargets.len>0)
+/obj/machinery/turret/proc/shootAt(var/atom/movable/target)
+ var/turf/T = get_turf(src)
+ var/turf/U = get_turf(target)
+ if (!istype(T) || !istype(U))
+ return
+ var/obj/beam/a_laser/A
+ if (src.lasers)
+ A = new /obj/beam/a_laser( loc )
+ use_power(500)
+ else
+ A = new /obj/bullet/electrode( loc )
+ use_power(200)
+ A.current = T
+ A.yo = U.y - T.y
+ A.xo = U.x - T.x
+ spawn( 0 )
+ A.process()
+ return
/obj/machinery/turret/proc/isDown()
@@ -250,36 +227,6 @@
invisibility = 2
popping = 0
-/obj/machinery/turret/proc/shootAt(var/mob/target)
- var/turf/T = loc
- var/atom/U = (istype(target, /atom/movable) ? target.loc : target)
- if ((!( U ) || !( T )))
- return
- while(!( istype(U, /turf) ))
- U = U.loc
- if (!( istype(T, /turf) ))
- return
-
- var/obj/beam/a_laser/A
- if (src.lasers)
- A = new /obj/beam/a_laser( loc )
- use_power(500)
- else
- A = new /obj/bullet/electrode( loc )
- use_power(200)
-
- if (!( istype(U, /turf) ))
- //A = null
- del(A)
- return
- A.current = U
- A.yo = U.y - T.y
- A.xo = U.x - T.x
- spawn( 0 )
- A.process()
- return
- return
-
/obj/machinery/turret/bullet_act(flag)
if (flag == PROJECTILE_BULLET)
src.health -= 17
@@ -613,4 +560,4 @@
A.xo = targloc.x - curloc.x
A.process()
sleep(2)
- return
\ No newline at end of file
+ return
diff --git a/code/game/mecha/combat/honker.dm b/code/game/mecha/combat/honker.dm
index 2811cc685eb..4708d590f2e 100644
--- a/code/game/mecha/combat/honker.dm
+++ b/code/game/mecha/combat/honker.dm
@@ -38,7 +38,7 @@
IntegriHONK: [health/initial(health)*100] %)
PowerHONK charge: [isnull(cell_charge)?"Someone HONKed powerHonk!!!":"[cell.percent()]%"])
AirHONK pressure: [src.return_pressure()]HoNKs
- Internal HONKature: [src.air_contents.temperature]°honK|[src.air_contents.temperature - T0C]°honCk
+ Internal HONKature: [src.return_temperature()]°honK|[src.return_temperature() - T0C]°honCk
Lights: [lights?"on":"off"]
"}
output += "HONKon systems: