Skip to content

Commit 16354de

Browse files
committed
Rewrite shuttle computers for better code quality
1 parent 266e28a commit 16354de

File tree

1 file changed

+46
-52
lines changed

1 file changed

+46
-52
lines changed

code/game/machinery/computer/shuttle.dm

Lines changed: 46 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -5,66 +5,60 @@
55
icon_screen = "shuttle"
66
light_color = "#00ffff"
77
construct_state = null
8-
var/auth_need = 3.0
9-
var/list/authorized = list( )
8+
var/auths_needed = 3
9+
var/list/authorized
1010

11+
/obj/machinery/computer/shuttle/Initialize()
12+
if(!istype(SSevac.evacuation_controller, /datum/evacuation_controller/shuttle))
13+
PRINT_STACK_TRACE("Shuttle console found without a shuttle evacuation controller!")
14+
return INITIALIZE_HINT_QDEL
15+
return ..()
1116

1217
/obj/machinery/computer/shuttle/attackby(var/obj/item/used_item, var/mob/user)
13-
if(stat & (BROKEN|NOPOWER)) return TRUE
14-
15-
var/datum/evacuation_controller/shuttle/evac_control = SSevac.evacuation_controller
16-
if(!istype(evac_control))
17-
to_chat(user, "<span class='danger'>This console should not be in use on this map. Please report this to a developer.</span>")
18+
if(stat & (BROKEN|NOPOWER))
1819
return TRUE
1920

20-
if(!istype(used_item, /obj/item/card)) // don't try to get an ID card if we're an emag
21-
used_item = used_item.GetIdCard() // handles stored IDs in modcomps and similar
22-
23-
if ((!istype(used_item, /obj/item/card) || evac_control.has_evacuated() || !user))
21+
var/obj/item/card/id/id_card = used_item.GetIdCard() // if used_item is already an ID, it'll just return itself
22+
if(!istype(id_card, /obj/item/card/id) || SSevac.evacuation_controller.has_evacuated() || SSevac.evacuation_controller.is_prepared() || !user)
2423
return FALSE
2524

26-
if (istype(used_item, /obj/item/card/id))
27-
var/obj/item/card/id/id_card = used_item
28-
if(!LAZYISIN(id_card.access, access_bridge)) //doesn't have this access
29-
to_chat(user, "The access level of [id_card.registered_name]\'s card is not high enough.")
30-
return TRUE
31-
32-
var/choice = alert(user, "Would you like to (un)authorize a shortened launch time? [auth_need - authorized.len] authorization\s are still needed. Use abort to cancel all authorizations.", "Shuttle Launch", "Authorize", "Repeal", "Abort")
33-
if(evac_control.is_prepared() && user.get_active_held_item() != used_item)
34-
return TRUE
35-
switch(choice)
36-
if("Authorize")
37-
src.authorized -= id_card.registered_name
38-
src.authorized += id_card.registered_name
39-
if (src.auth_need - src.authorized.len > 0)
40-
message_admins("[key_name_admin(user)] has authorized early shuttle launch")
41-
log_game("[user.ckey] has authorized early shuttle launch")
42-
to_world("<span class='notice'><b>Alert: [auth_need - authorized.len] authorizations needed until shuttle is launched early</b></span>")
43-
else
44-
message_admins("[key_name_admin(user)] has launched the shuttle")
45-
log_game("[user.ckey] has launched the shuttle early")
46-
to_world("<span class='notice'><b>Alert: Shuttle launch time shortened to 10 seconds!</b></span>")
47-
evac_control.set_launch_time(world.time+100)
48-
//src.authorized = null
49-
qdel(src.authorized)
50-
src.authorized = list( )
25+
if(!LAZYISIN(id_card.access, access_bridge)) //doesn't have the required access
26+
to_chat(user, "The access level of [id_card.registered_name]\'s card is not high enough.")
27+
return TRUE
5128

52-
if("Repeal")
53-
src.authorized -= id_card.registered_name
54-
to_world("<span class='notice'><b>Alert: [auth_need - authorized.len] authorizations needed until shuttle is launched early</b></span>")
29+
var/choice = alert(user, "Would you like to (un)authorize a shortened launch time? [auths_needed - LAZYLEN(authorized)] authorization\s are still needed. Use abort to cancel all authorizations.", "Shuttle Launch", "Authorize", "Repeal", "Abort")
30+
// since alert() sleeps, we need to recheck the previous SSevacuation conditions
31+
// and make sure used_item is still being held
32+
if(SSevac.evacuation_controller.has_evacuated() || SSevac.evacuation_controller.is_prepared() || user.get_active_held_item() != used_item)
33+
return TRUE // we've already had a user-visible interaction, so return TRUE to avoid further interactions this click
34+
switch(choice)
35+
if("Authorize")
36+
LAZYDISTINCTADD(authorized, id_card.registered_name)
37+
if (LAZYLEN(authorized) >= auths_needed)
38+
message_admins("[key_name_admin(user)] has launched the shuttle")
39+
log_game("[user.ckey] has launched the shuttle early")
40+
to_world(SPAN_NOTICE("<b>Alert: Shuttle launch time shortened to 10 seconds!</b>"))
41+
SSevac.evacuation_controller.evac_launch_time = world.time + 10 SECONDS
42+
LAZYCLEARLIST(authorized)
43+
else
44+
message_admins("[key_name_admin(user)] has authorized early shuttle launch")
45+
log_game("[user.ckey] has authorized early shuttle launch")
46+
to_world(SPAN_NOTICE("<b>Alert: [auths_needed - LAZYLEN(authorized)] authorizations needed until shuttle is launched early</b>"))
5547

56-
if("Abort")
57-
to_world("<span class='notice'><b>All authorizations to shortening time for shuttle launch have been revoked!</b></span>")
58-
src.authorized.len = 0
59-
src.authorized = list( )
60-
return TRUE
48+
if("Repeal")
49+
LAZYREMOVE(authorized, id_card.registered_name)
50+
to_world(SPAN_NOTICE("<b>Alert: [auths_needed - LAZYLEN(authorized)] authorizations needed until shuttle is launched early</b>"))
6151

62-
else if (istype(used_item, /obj/item/card/emag) && !emagged)
63-
var/choice = alert(user, "Would you like to launch the shuttle?","Shuttle control", "Launch", "Cancel")
52+
if("Abort")
53+
to_world(SPAN_NOTICE("<b>All authorizations to shortening time for shuttle launch have been revoked!</b>"))
54+
LAZYCLEARLIST(authorized)
55+
return TRUE
6456

65-
if(!emagged && !evac_control.is_prepared() && user.get_active_held_item() == used_item && choice == "Launch")
66-
to_world("<span class='notice'><b>Alert: Shuttle launch time shortened to 10 seconds!</b></span>")
67-
evac_control.set_launch_time(world.time+100)
68-
emagged = 1
69-
return TRUE
70-
return FALSE
57+
/obj/machinery/computer/shuttle/emag_act(remaining_charges, mob/user, emag_source)
58+
// Must not be launched or launching, and not already emagged
59+
if(SSevac.evacuation_controller.has_evacuated() || SSevac.evacuation_controller.is_prepared() || emagged)
60+
return NO_EMAG_ACT
61+
to_world(SPAN_NOTICE("<b>Alert: Shuttle launch time shortened to 10 seconds!</b>"))
62+
SSevac.evacuation_controller.evac_launch_time = world.time + 10 SECONDS
63+
emagged = TRUE
64+
return 1 // not a bool, number of charges to consume

0 commit comments

Comments
 (0)