From aad28d63ce46c6fc6af96ed9fd36026767d15dbe Mon Sep 17 00:00:00 2001 From: PsiOmega Date: Sat, 16 May 2015 13:31:37 +0200 Subject: [PATCH] Cleans up welder code. Icon and inhand states should now update properly. --- code/game/objects/items/weapons/tools.dm | 127 +++++++++-------------- 1 file changed, 47 insertions(+), 80 deletions(-) diff --git a/code/game/objects/items/weapons/tools.dm b/code/game/objects/items/weapons/tools.dm index 1066c4e8db0..2754068d465 100644 --- a/code/game/objects/items/weapons/tools.dm +++ b/code/game/objects/items/weapons/tools.dm @@ -162,6 +162,10 @@ R.add_reagent("fuel", max_fuel) return +/obj/item/weapon/weldingtool/Destroy() + if(welding) + processing_objects -= src + ..() /obj/item/weapon/weldingtool/examine(mob/user) if(..(user, 0)) @@ -171,13 +175,13 @@ /obj/item/weapon/weldingtool/attackby(obj/item/W as obj, mob/user as mob) if(istype(W,/obj/item/weapon/screwdriver)) if(welding) - user << "\red Stop welding first!" + user << "Stop welding first!" return status = !status if(status) - user << "\blue You resecure the welder." + user << "You secure the welder." else - user << "\blue The welder can now be attached and modified." + user << "The welder can now be attached and modified." src.add_fingerprint(user) return @@ -207,31 +211,8 @@ /obj/item/weapon/weldingtool/process() - switch(welding) - //If off - if(0) - if(src.icon_state != "welder") //Check that the sprite is correct, if it isnt, it means toggle() was not called - src.force = 3 - src.damtype = "brute" - src.icon_state = "welder" - src.welding = 0 - processing_objects.Remove(src) - return - //Welders left on now use up fuel, but lets not have them run out quite that fast - if(1) - if(src.icon_state != "welder1") //Check that the sprite is correct, if it isnt, it means toggle() was not called - src.force = 15 - src.damtype = "fire" - src.icon_state = "welder1" - if(prob(5)) - remove_fuel(1) - - //If you're actually actively welding, use fuel faster. - //Is this actually used or set anywhere? - Nodrak - if(2) - if(prob(75)) - remove_fuel(1) - + if(welding && prob(5) && !remove_fuel(1)) + setWelding(0) //I'm not sure what this does. I assume it has to do with starting fires... //...but it doesnt check to see if the welder is on or not. @@ -248,7 +229,7 @@ if(!proximity) return if (istype(O, /obj/structure/reagent_dispensers/fueltank) && get_dist(src,O) <= 1 && !src.welding) O.reagents.trans_to_obj(src, max_fuel) - user << "\blue Welder refueled" + user << "Welder refueled" playsound(src.loc, 'sound/effects/refill.ogg', 50, 1, -6) return else if (istype(O, /obj/structure/reagent_dispensers/fueltank) && get_dist(src,O) <= 1 && src.welding) @@ -270,7 +251,7 @@ /obj/item/weapon/weldingtool/attack_self(mob/user as mob) - toggle() + setWelding(!welding, usr) return //Returns the amount of fuel in the welder @@ -280,81 +261,67 @@ //Removes fuel from the welding tool. If a mob is passed, it will perform an eyecheck on the mob. This should probably be renamed to use() /obj/item/weapon/weldingtool/proc/remove_fuel(var/amount = 1, var/mob/M = null) - if(!welding || !check_fuel()) - return 0 if(get_fuel() >= amount) reagents.remove_reagent("fuel", amount) - check_fuel() if(M) eyecheck(M) return 1 else if(M) - M << "\blue You need more welding fuel to complete this task." + M << "You need more welding fuel to complete this task." + else + visible_message("\The [src] sputters and switches off.") return 0 //Returns whether or not the welding tool is currently on. /obj/item/weapon/weldingtool/proc/isOn() return src.welding +/obj/item/weapon/weldingtool/update_icon() + ..() + icon_state = welding ? "welder1" : "welder" + var/mob/M = loc + if(M) + M.update_inv_l_hand() + M.update_inv_r_hand() + //Sets the welding state of the welding tool. If you see W.welding = 1 anywhere, please change it to W.setWelding(1) //so that the welding tool updates accordingly -/obj/item/weapon/weldingtool/proc/setWelding(var/temp_welding) +/obj/item/weapon/weldingtool/proc/setWelding(var/set_welding, var/mob/M) + if(!status) return + + var/turf/T = get_turf(src) //If we're turning it on - if(temp_welding > 0) + if(set_welding && !welding) if (remove_fuel(1)) - usr << "\blue The [src] switches on." + if(M) + M.visible_message("[M] has ignited \the [src] on.", "You ignite \the [src].", "You hear the sound of \a [src] being ignited.") + else if(T) + T.visible_message("\The [src] has been ignited.","You hear the sound of \a [src] being ignited.") src.force = 15 src.damtype = "fire" - src.icon_state = "welder1" - processing_objects.Add(src) + src.w_class = 4 + welding = 1 + update_icon() + processing_objects |= src else - usr << "\blue Need more fuel!" - src.welding = 0 + if(M) + M.visible_message("\The [src] sputters as [M] fail to ignite it.", "You fail to ignite \the [src] on.", "You hear the sputtering sound of \a [src] failing to ignite.") + else if(T) + T.visible_message("\The [src] sputters as it fails to ignite.", "You hear the sputtering sound of \a [src] failing to ignite.") return //Otherwise - else - usr << "\blue The [src] switches off." + else if(!set_welding && welding) + processing_objects -= src + if(M) + M.visible_message("[M] has turned off \the [src].", "You turn off \the [src].", "You hear the sound of a gas fire suddenly stopping.") + else if(T) + T.visible_message("\The [src] turns off.", "You hear the sound of a gas fire suddenly stopping.") src.force = 3 src.damtype = "brute" - src.icon_state = "welder" - src.welding = 0 - -//Turns off the welder if there is no more fuel (does this really need to be its own proc?) -/obj/item/weapon/weldingtool/proc/check_fuel() - if((get_fuel() <= 0) && welding) - toggle(1) - return 0 - return 1 - - -//Toggles the welder off and on -/obj/item/weapon/weldingtool/proc/toggle(var/message = 0) - if(!status) return - src.welding = !( src.welding ) - if (src.welding) - if (remove_fuel(1)) - usr << "You switch the [src] on." - src.force = 15 - src.damtype = "fire" - src.icon_state = "welder1" - src.w_class = 4 - processing_objects.Add(src) - else - usr << "You need more fuel!" - src.welding = 0 - else - if(!message) - usr << "You switch \the [src] off." - else - usr << "\The [src] shuts off!" - src.force = 3 - src.damtype = "brute" - src.icon_state = "welder" - src.welding = 0 src.w_class = initial(src.w_class) - usr.update_inv_l_hand() - usr.update_inv_r_hand() + src.welding = 0 + update_icon() //Decides whether or not to damage a player's eyes based on what they're wearing as protection //Note: This should probably be moved to mob