From 8b83e58ea03a391f1167bedb0ccf019fe574c8df Mon Sep 17 00:00:00 2001 From: warior4356 Date: Sun, 14 Oct 2018 03:09:48 -0700 Subject: [PATCH] Invalid combinations fixed --- code/game/objects/structures/safe.dm | 42 ++++++++++------------------ 1 file changed, 14 insertions(+), 28 deletions(-) diff --git a/code/game/objects/structures/safe.dm b/code/game/objects/structures/safe.dm index 949eb3b0242..aad0486bbd0 100644 --- a/code/game/objects/structures/safe.dm +++ b/code/game/objects/structures/safe.dm @@ -26,14 +26,16 @@ FLOOR SAFES /obj/structure/safe/New() - tumbler_1_pos = rand(0, 99) - tumbler_1_open = rand(0, 99) - - tumbler_2_pos = rand(0, 99) + tumbler_2_pos = rand(0, 99) // first value in the combination set first tumbler_2_open = rand(0, 99) - open_pos = rand(0,99) - + tumbler_1_pos = rand(0, 99) + do + tumbler_1_open = rand(0, 99) + while(tumbler_1_open > Wrap(tumbler_2_open +48, 0, 99) && tumbler_1_open < Wrap(tumbler_2_open + 53, 0, 99)) // prevents a combination that wont open + do + open_pos = rand(0,99) + while(open_pos > Wrap(tumbler_1_open - 2, 0, 99) && open_pos < Wrap(tumbler_1_open + 2, 0, 99)) // prevents a combination that wont open var/num1 = tumbler_2_open + 54 if(num1 > 99) num1 = num1 - 100 @@ -78,22 +80,6 @@ FLOOR SAFES if(unlocked) if(user) visible_message("[pick("Spring", "Sprang", "Sproing", "Clunk", "Krunk")]!") - - -/obj/structure/safe/proc/decrement(num) - num -= 1 - if(num < 0) - num = 99 - return num - - -/obj/structure/safe/proc/increment(num) - num += 1 - if(num > 99) - num = 0 - return num - - /obj/structure/safe/update_icon() if(open) icon_state = "[initial(icon_state)]-open" @@ -159,12 +145,12 @@ FLOOR SAFES return for(var/i=1 to ticks) if(!check_unlocked()) - dial = decrement(dial) + dial = Wrap(dial - 1, 0 ,99) if(dial == tumbler_1_pos + 1 || dial == tumbler_1_pos - 99) - tumbler_1_pos = decrement(tumbler_1_pos) + tumbler_1_pos = Wrap(tumbler_1_pos - 1, 0, 99) tum1_turns++ if(tumbler_1_pos == tumbler_2_pos + 51 || tumbler_1_pos == tumbler_2_pos - 49) - tumbler_2_pos = decrement(tumbler_2_pos) + tumbler_2_pos = Wrap(tumbler_1_pos - 1, 0, 99) tum2_turns++ check_unlocked() make_noise(tum1_turns, tum2_turns, user, canhear) @@ -178,12 +164,12 @@ FLOOR SAFES return for(var/i=1 to ticks) check_unlocked() - dial = increment(dial) + dial = Wrap(dial + 1, 0, 99) if(dial == tumbler_1_pos - 1 || dial == tumbler_1_pos + 99) - tumbler_1_pos = increment(tumbler_1_pos) + tumbler_1_pos = Wrap(tumbler_1_pos + 1, 0, 99) tum1_turns++ if(tumbler_1_pos == tumbler_2_pos - 51 || tumbler_1_pos == tumbler_2_pos + 49) - tumbler_2_pos = increment(tumbler_2_pos) + tumbler_2_pos = Wrap(tumbler_2_pos + 1, 0, 99) tum2_turns++ make_noise(tum1_turns, tum2_turns, user, canhear) .=1