From 0437176bee36a4f07c9f3c4ce22f57c3ae45cc61 Mon Sep 17 00:00:00 2001 From: Yolopanther Date: Mon, 16 Nov 2015 19:35:03 -0800 Subject: [PATCH 1/6] Allows light replacer to be refilled with box of lights --- code/game/objects/items/devices/lightreplacer.dm | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/code/game/objects/items/devices/lightreplacer.dm b/code/game/objects/items/devices/lightreplacer.dm index e722223bc6a..0fed7a28a76 100644 --- a/code/game/objects/items/devices/lightreplacer.dm +++ b/code/game/objects/items/devices/lightreplacer.dm @@ -98,6 +98,20 @@ user << "You need a working light!" return + if(istype(W, /obj/item/weapon/storage/box/lights)) + var/obj/item/weapon/storage/box/lights/B = W + if(!B.contents.len) + user << "The [B.name] is empty!" + else if(uses == max_uses) + user << "The [src.name] is full!" + else + B.close_all() + while(src.uses < max_uses && B.contents.len > 0) + B.contents.Cut(1,2) + AddUses(1) + user << "You fill the [src.name] with lights from the [B.name]. You have [uses] lights remaining." + return + /obj/item/device/lightreplacer/emag_act() if(!emagged) Emag() From 082538240e51c6399cecd71fb0862237e531fad0 Mon Sep 17 00:00:00 2001 From: Yolopanther Date: Mon, 16 Nov 2015 19:40:26 -0800 Subject: [PATCH 2/6] Haha indentation fixes. --- .../objects/items/devices/lightreplacer.dm | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/code/game/objects/items/devices/lightreplacer.dm b/code/game/objects/items/devices/lightreplacer.dm index 0fed7a28a76..949182190b5 100644 --- a/code/game/objects/items/devices/lightreplacer.dm +++ b/code/game/objects/items/devices/lightreplacer.dm @@ -98,19 +98,19 @@ user << "You need a working light!" return - if(istype(W, /obj/item/weapon/storage/box/lights)) - var/obj/item/weapon/storage/box/lights/B = W - if(!B.contents.len) - user << "The [B.name] is empty!" - else if(uses == max_uses) - user << "The [src.name] is full!" - else - B.close_all() - while(src.uses < max_uses && B.contents.len > 0) - B.contents.Cut(1,2) - AddUses(1) - user << "You fill the [src.name] with lights from the [B.name]. You have [uses] lights remaining." - return + if(istype(W, /obj/item/weapon/storage/box/lights)) + var/obj/item/weapon/storage/box/lights/B = W + if(!B.contents.len) + user << "The [B.name] is empty!" + else if(uses == max_uses) + user << "The [src.name] is full!" + else + B.close_all() + while(src.uses < max_uses && B.contents.len > 0) + B.contents.Cut(1,2) + AddUses(1) + user << "You fill the [src.name] with lights from the [B.name]. You have [uses] lights remaining." + return /obj/item/device/lightreplacer/emag_act() if(!emagged) From 93b5ef000cc472e90616b50912e296156acf6789 Mon Sep 17 00:00:00 2001 From: Yolopanther Date: Mon, 16 Nov 2015 23:21:08 -0800 Subject: [PATCH 3/6] replacing broken lights with broken lights since 1999 --- .../objects/items/devices/lightreplacer.dm | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/code/game/objects/items/devices/lightreplacer.dm b/code/game/objects/items/devices/lightreplacer.dm index 949182190b5..204f0da8237 100644 --- a/code/game/objects/items/devices/lightreplacer.dm +++ b/code/game/objects/items/devices/lightreplacer.dm @@ -100,15 +100,24 @@ if(istype(W, /obj/item/weapon/storage/box/lights)) var/obj/item/weapon/storage/box/lights/B = W - if(!B.contents.len) - user << "The [B.name] is empty!" + var/tmp/useable_lights = 0 + for(var/obj/item/weapon/light/L in B.contents) + if(L.status == 0) // If the light is not broken or burned out + useable_lights = 1 + break + if(!useable_lights) // This check necessitates the loop above, as I figure it to be useful to know the box has no useable lights first. + user << "The [B.name] contains no useable lights!" else if(uses == max_uses) user << "The [src.name] is full!" else B.close_all() - while(src.uses < max_uses && B.contents.len > 0) - B.contents.Cut(1,2) - AddUses(1) + for(var/obj/item/weapon/light/L in B.contents) + if(L.status == 0) // Don't want to allow broken or burnt out lights to be useable + if(src.uses < max_uses) + qdel(L) + AddUses(1) + else + break user << "You fill the [src.name] with lights from the [B.name]. You have [uses] lights remaining." return From 12c7d7a90dee9e5667810a6ee2b58ee8a4994499 Mon Sep 17 00:00:00 2001 From: Yolopanther Date: Tue, 17 Nov 2015 04:46:25 -0800 Subject: [PATCH 4/6] Now only loops through the content of the box once instead of twice. --- .../objects/items/devices/lightreplacer.dm | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/code/game/objects/items/devices/lightreplacer.dm b/code/game/objects/items/devices/lightreplacer.dm index 204f0da8237..af2d4742de3 100644 --- a/code/game/objects/items/devices/lightreplacer.dm +++ b/code/game/objects/items/devices/lightreplacer.dm @@ -100,26 +100,30 @@ if(istype(W, /obj/item/weapon/storage/box/lights)) var/obj/item/weapon/storage/box/lights/B = W - var/tmp/useable_lights = 0 - for(var/obj/item/weapon/light/L in B.contents) - if(L.status == 0) // If the light is not broken or burned out - useable_lights = 1 - break - if(!useable_lights) // This check necessitates the loop above, as I figure it to be useful to know the box has no useable lights first. - user << "The [B.name] contains no useable lights!" - else if(uses == max_uses) - user << "The [src.name] is full!" + var/tmp/replacement_status = 1 // 0-useable lights found, 1-no useable lights, 2-light replacer was full + + if(src.uses == max_uses) + if(!B.contents.len) // empty box + replacement_status = 1 + else // I REAALLYYY want 'no useable lights' to be the primary warning + replacement_status = 2 else - B.close_all() for(var/obj/item/weapon/light/L in B.contents) if(L.status == 0) // Don't want to allow broken or burnt out lights to be useable + replacement_status = 0 if(src.uses < max_uses) qdel(L) AddUses(1) else break - user << "You fill the [src.name] with lights from the [B.name]. You have [uses] lights remaining." - return + + if(replacement_status == 1) + user << "The [B.name] contains no useable lights!" + return + else if(replacement_status == 2) + user << "The [src.name] is full!" + return + user << "You fill the [src.name] with lights from the [B.name]. You have [uses] lights remaining." /obj/item/device/lightreplacer/emag_act() if(!emagged) From 922df5f02c513920879d422ebacb612695a5aae9 Mon Sep 17 00:00:00 2001 From: Yolopanther Date: Tue, 17 Nov 2015 19:06:31 -0800 Subject: [PATCH 5/6] Single loop and looks nice. --- .../objects/items/devices/lightreplacer.dm | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/code/game/objects/items/devices/lightreplacer.dm b/code/game/objects/items/devices/lightreplacer.dm index af2d4742de3..e66828df703 100644 --- a/code/game/objects/items/devices/lightreplacer.dm +++ b/code/game/objects/items/devices/lightreplacer.dm @@ -98,32 +98,32 @@ user << "You need a working light!" return - if(istype(W, /obj/item/weapon/storage/box/lights)) - var/obj/item/weapon/storage/box/lights/B = W - var/tmp/replacement_status = 1 // 0-useable lights found, 1-no useable lights, 2-light replacer was full + if(istype(W, /obj/item/weapon/storage)) + var/obj/item/weapon/storage/S = W + var/found_good_light = 0 + var/replaced_something = 0 - if(src.uses == max_uses) - if(!B.contents.len) // empty box - replacement_status = 1 - else // I REAALLYYY want 'no useable lights' to be the primary warning - replacement_status = 2 - else - for(var/obj/item/weapon/light/L in B.contents) - if(L.status == 0) // Don't want to allow broken or burnt out lights to be useable - replacement_status = 0 + for(var/obj/item/I in S.contents) + if(istype(I,/obj/item/weapon/light)) + var/obj/item/weapon/light/L = I + if(L.status == LIGHT_OK) + found_good_light = 1 if(src.uses < max_uses) qdel(L) AddUses(1) + replaced_something = 1 else break - if(replacement_status == 1) - user << "The [B.name] contains no useable lights!" + if(!found_good_light) + user << "The [S.name] contains no useable lights!" return - else if(replacement_status == 2) + + if(!replaced_something && src.uses == max_uses) user << "The [src.name] is full!" return - user << "You fill the [src.name] with lights from the [B.name]. You have [uses] lights remaining." + + user << "You fill the [src.name] with lights from the [S.name]. You have [uses] lights remaining." /obj/item/device/lightreplacer/emag_act() if(!emagged) From f767524d3e9dbcdaf734e48d762e75ee8fa2ed7e Mon Sep 17 00:00:00 2001 From: Yolopanther Date: Wed, 18 Nov 2015 00:52:16 -0800 Subject: [PATCH 6/6] Proper formatting of the notifications. --- code/game/objects/items/devices/lightreplacer.dm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/code/game/objects/items/devices/lightreplacer.dm b/code/game/objects/items/devices/lightreplacer.dm index e66828df703..47020fbc330 100644 --- a/code/game/objects/items/devices/lightreplacer.dm +++ b/code/game/objects/items/devices/lightreplacer.dm @@ -116,14 +116,14 @@ break if(!found_good_light) - user << "The [S.name] contains no useable lights!" + user << "\The [S] contains no useable lights!" return if(!replaced_something && src.uses == max_uses) - user << "The [src.name] is full!" + user << "\The [src] is full!" return - user << "You fill the [src.name] with lights from the [S.name]. You have [uses] lights remaining." + user << "You fill \the [src] with lights from \the [S]. You have [uses] lights remaining." /obj/item/device/lightreplacer/emag_act() if(!emagged)