From 212b673ae004da92f5e239646b964e906587aa6a Mon Sep 17 00:00:00 2001 From: YPO <30683121+YPOQ@users.noreply.github.com> Date: Wed, 20 Sep 2017 15:24:33 -0600 Subject: [PATCH 1/2] Fixes persistence --- code/controllers/subsystem/persistence.dm | 12 ++--- .../modules/awaymissions/super_secret_room.dm | 7 ++- .../mob/living/carbon/human/interactive.dm | 3 +- .../mob/living/carbon/monkey/punpun.dm | 28 +++++------ .../mob/living/simple_animal/friendly/cat.dm | 13 ++--- .../mob/living/simple_animal/friendly/dog.dm | 20 +++++--- .../hostile/megafauna/colossus.dm | 5 +- .../mob/living/simple_animal/parrot.dm | 50 ++++++++++--------- 8 files changed, 70 insertions(+), 68 deletions(-) diff --git a/code/controllers/subsystem/persistence.dm b/code/controllers/subsystem/persistence.dm index e714dc1171b..ac7db6e51f9 100644 --- a/code/controllers/subsystem/persistence.dm +++ b/code/controllers/subsystem/persistence.dm @@ -42,8 +42,7 @@ SUBSYSTEM_DEF(persistence) var/json_file = file("data/npc_saves/SecretSatchels[SSmapping.config.map_name].json") if(!fexists(json_file)) return - var/list/json = list() - json = json_decode(file2text(json_file)) + var/list/json = json_decode(file2text(json_file)) old_secret_satchels = json["data"] if(old_secret_satchels.len) if(old_secret_satchels.len >= 20) //guards against low drop pools assuring that one player cannot reliably find his own gear. @@ -85,8 +84,7 @@ SUBSYSTEM_DEF(persistence) var/json_file = file("data/npc_saves/ChiselMessages[SSmapping.config.map_name].json") if(!fexists(json_file)) return - var/list/json - json = json_decode(file2text(json_file)) + var/list/json = json_decode(file2text(json_file)) if(!json) return @@ -130,8 +128,7 @@ SUBSYSTEM_DEF(persistence) var/json_file = file("data/npc_saves/TrophyItems.json") if(!fexists(json_file)) return - var/list/json = list() - json = json_decode(file2text(json_file)) + var/list/json = json_decode(file2text(json_file)) if(!json) return saved_trophies = json["data"] @@ -141,8 +138,7 @@ SUBSYSTEM_DEF(persistence) var/json_file = file("data/RecentModes.json") if(!fexists(json_file)) return - var/list/json = list() - json = json_decode(file2text(json_file)) + var/list/json = json_decode(file2text(json_file)) if(!json) return saved_modes = json["data"] diff --git a/code/modules/awaymissions/super_secret_room.dm b/code/modules/awaymissions/super_secret_room.dm index 5d26e340544..2375f10e0fd 100644 --- a/code/modules/awaymissions/super_secret_room.dm +++ b/code/modules/awaymissions/super_secret_room.dm @@ -10,8 +10,11 @@ var/list/shenanigans = list() /obj/structure/speaking_tile/New() - var/savefile/S = new /savefile("data/npc_saves/Poly.sav") - S["phrases"] >> shenanigans + var/json_file = file("data/npc_saves/Poly.json") + if(!fexists(json_file)) + return + var/list/json = json_decode(file2text(json_file)) + shenanigans = json["phrases"] ..() /obj/structure/speaking_tile/interact(mob/user) diff --git a/code/modules/mob/living/carbon/human/interactive.dm b/code/modules/mob/living/carbon/human/interactive.dm index e081e832e53..269af8ed6f6 100644 --- a/code/modules/mob/living/carbon/human/interactive.dm +++ b/code/modules/mob/living/carbon/human/interactive.dm @@ -95,8 +95,7 @@ var/json_file = file("data/npc_saves/snpc.json") if(!fexists(json_file)) return - var/list/json = list() - json = json_decode(file2text(json_file)) + var/list/json = json_decode(file2text(json_file)) knownStrings = json["knownStrings"] if(isnull(knownStrings)) knownStrings = list() diff --git a/code/modules/mob/living/carbon/monkey/punpun.dm b/code/modules/mob/living/carbon/monkey/punpun.dm index e67adf0b1b9..fc0d97e3cb9 100644 --- a/code/modules/mob/living/carbon/monkey/punpun.dm +++ b/code/modules/mob/living/carbon/monkey/punpun.dm @@ -5,7 +5,7 @@ var/ancestor_chain = 1 var/relic_hat //Note: these two are paths var/relic_mask - var/memory_saved = 0 + var/memory_saved = FALSE var/list/pet_monkey_names = list("Pun Pun", "Bubbles", "Mojo", "George", "Darwin", "Aldo", "Caeser", "Kanzi", "Kong", "Terk", "Grodd", "Mala", "Bojangles", "Coco", "Able", "Baker", "Scatter", "Norbit", "Travis") var/list/rare_pet_monkey_names = list("Professor Bobo", "Deempisi's Revenge", "Furious George", "King Louie", "Dr. Zaius", "Jimmy Rustles", "Dinner", "Lanky") @@ -32,13 +32,14 @@ equip_to_slot_or_del(new relic_mask, slot_wear_mask) /mob/living/carbon/monkey/punpun/Life() - if(SSticker.current_state == GAME_STATE_FINISHED && !memory_saved) - Write_Memory(0) + if(!stat && SSticker.current_state == GAME_STATE_FINISHED && !memory_saved) + Write_Memory(FALSE, FALSE) + memory_saved = TRUE ..() /mob/living/carbon/monkey/punpun/death(gibbed) - if(!memory_saved || gibbed) - Write_Memory(1,gibbed) + if(!memory_saved) + Write_Memory(TRUE, gibbed) ..() /mob/living/carbon/monkey/punpun/proc/Read_Memory() @@ -53,8 +54,7 @@ var/json_file = file("data/npc_saves/Punpun.json") if(!fexists(json_file)) return - var/list/json = list() - json = json_decode(file2text(json_file)) + var/list/json = json_decode(file2text(json_file)) ancestor_name = json["ancestor_name"] ancestor_chain = json["ancestor_chain"] relic_hat = json["relic_hat"] @@ -68,14 +68,10 @@ file_data["ancestor_chain"] = null file_data["relic_hat"] = null file_data["relic_mask"] = null - if(dead) - file_data["ancestor_name"] = ancestor_name - file_data["ancestor_chain"] = ancestor_chain + 1 - file_data["relic_hat"] = head ? head.type : null - file_data["relic_mask"] = wear_mask ? wear_mask.type : null - if(!ancestor_name) - file_data["ancestor_name"] = name + else + file_data["ancestor_name"] = ancestor_name ? ancestor_name : name + file_data["ancestor_chain"] = dead ? ancestor_chain + 1 : ancestor_chain + file_data["relic_hat"] = head ? head.type : null + file_data["relic_mask"] = wear_mask ? wear_mask.type : null fdel(json_file) WRITE_FILE(json_file, json_encode(file_data)) - if(!dead) - memory_saved = 1 diff --git a/code/modules/mob/living/simple_animal/friendly/cat.dm b/code/modules/mob/living/simple_animal/friendly/cat.dm index 8e460b0582e..8139c226748 100644 --- a/code/modules/mob/living/simple_animal/friendly/cat.dm +++ b/code/modules/mob/living/simple_animal/friendly/cat.dm @@ -83,7 +83,7 @@ var/list/family = list()//var restored from savefile, has count of each child type var/list/children = list()//Actual mob instances of children var/cats_deployed = 0 - var/memory_saved = 0 + var/memory_saved = FALSE /mob/living/simple_animal/pet/cat/Runtime/Initialize() if(prob(5)) @@ -98,6 +98,7 @@ Deploy_The_Cats() if(!stat && SSticker.current_state == GAME_STATE_FINISHED && !memory_saved) Write_Memory() + memory_saved = TRUE ..() /mob/living/simple_animal/pet/cat/Runtime/make_babies() @@ -108,7 +109,7 @@ /mob/living/simple_animal/pet/cat/Runtime/death() if(!memory_saved) - Write_Memory(1) + Write_Memory(TRUE) ..() /mob/living/simple_animal/pet/cat/Runtime/proc/Read_Memory() @@ -120,14 +121,14 @@ var/json_file = file("data/npc_saves/Runtime.json") if(!fexists(json_file)) return - var/list/json = list() - json = json_decode(file2text(json_file)) + var/list/json = json_decode(file2text(json_file)) family = json["family"] if(isnull(family)) family = list() /mob/living/simple_animal/pet/cat/Runtime/proc/Write_Memory(dead) var/json_file = file("data/npc_saves/Runtime.json") + var/list/file_data = list() family = list() if(!dead) for(var/mob/living/simple_animal/pet/cat/kitten/C in children) @@ -137,9 +138,9 @@ family[C.type] += 1 else family[C.type] = 1 + file_data["family"] = family fdel(json_file) - WRITE_FILE(json_file, json_encode(family)) - memory_saved = 1 + WRITE_FILE(json_file, json_encode(file_data)) /mob/living/simple_animal/pet/cat/Runtime/proc/Deploy_The_Cats() cats_deployed = 1 diff --git a/code/modules/mob/living/simple_animal/friendly/dog.dm b/code/modules/mob/living/simple_animal/friendly/dog.dm index dac592f49f1..67d92853167 100644 --- a/code/modules/mob/living/simple_animal/friendly/dog.dm +++ b/code/modules/mob/living/simple_animal/friendly/dog.dm @@ -290,7 +290,7 @@ gold_core_spawnable = 0 var/age = 0 var/record_age = 1 - var/memory_saved = 0 + var/memory_saved = FALSE var/saved_head //path /mob/living/simple_animal/pet/dog/corgi/Ian/Initialize() @@ -306,7 +306,7 @@ P.real_name = "Ian" P.gender = MALE P.desc = "It's the HoP's beloved corgi puppy." - Write_Memory(0) + Write_Memory(FALSE) qdel(src) else if(age == record_age) icon_state = "old_corgi" @@ -316,13 +316,14 @@ turns_per_move = 20 /mob/living/simple_animal/pet/dog/corgi/Ian/Life() - if(SSticker.current_state == GAME_STATE_FINISHED && !memory_saved) - Write_Memory(0) + if(!stat && SSticker.current_state == GAME_STATE_FINISHED && !memory_saved) + Write_Memory(FALSE) + memory_saved = TRUE ..() /mob/living/simple_animal/pet/dog/corgi/Ian/death() if(!memory_saved) - Write_Memory(1) + Write_Memory(TRUE) ..() /mob/living/simple_animal/pet/dog/corgi/Ian/proc/Read_Memory() @@ -336,8 +337,7 @@ var/json_file = file("data/npc_saves/Ian.json") if(!fexists(json_file)) return - var/list/json = list() - json = json_decode(file2text(json_file)) + var/list/json = json_decode(file2text(json_file)) age = json["age"] record_age = json["record_age"] saved_head = json["saved_head"] @@ -355,14 +355,18 @@ file_data["age"] = age + 1 if((age + 1) > record_age) file_data["record_age"] = record_age + 1 + else + file_data["record_age"] = record_age if(inventory_head) file_data["saved_head"] = inventory_head.type + else + file_data["saved_head"] = null else file_data["age"] = 0 + file_data["record_age"] = record_age file_data["saved_head"] = null fdel(json_file) WRITE_FILE(json_file, json_encode(file_data)) - memory_saved = 1 /mob/living/simple_animal/pet/dog/corgi/Ian/Life() ..() diff --git a/code/modules/mob/living/simple_animal/hostile/megafauna/colossus.dm b/code/modules/mob/living/simple_animal/hostile/megafauna/colossus.dm index 9c9cf18b019..346f07b9247 100644 --- a/code/modules/mob/living/simple_animal/hostile/megafauna/colossus.dm +++ b/code/modules/mob/living/simple_animal/hostile/megafauna/colossus.dm @@ -276,6 +276,7 @@ Difficulty: Very Hard ..() if(!memory_saved && SSticker.current_state == GAME_STATE_FINISHED) WriteMemory() + memory_saved = TRUE /obj/machinery/smartfridge/black_box/proc/WriteMemory() var/json_file = file("data/npc_saves/Blackbox.json") @@ -287,7 +288,6 @@ Difficulty: Very Hard file_data["data"] = stored_items fdel(json_file) WRITE_FILE(json_file, json_encode(file_data)) - memory_saved = TRUE /obj/machinery/smartfridge/black_box/proc/ReadMemory() if(fexists("data/npc_saves/Blackbox.sav")) //legacy compatability to convert old format to new @@ -298,8 +298,7 @@ Difficulty: Very Hard var/json_file = file("data/npc_saves/Blackbox.json") if(!fexists(json_file)) return - var/list/json = list() - json = json_decode(file2text(json_file)) + var/list/json = json_decode(file2text(json_file)) stored_items = json["data"] if(isnull(stored_items)) stored_items = list() diff --git a/code/modules/mob/living/simple_animal/parrot.dm b/code/modules/mob/living/simple_animal/parrot.dm index 7372583c686..cf9f0a27f44 100644 --- a/code/modules/mob/living/simple_animal/parrot.dm +++ b/code/modules/mob/living/simple_animal/parrot.dm @@ -871,7 +871,7 @@ speak = list("Poly wanna cracker!", ":e Check the crystal, you chucklefucks!",":e Wire the solars, you lazy bums!",":e WHO TOOK THE DAMN HARDSUITS?",":e OH GOD ITS ABOUT TO DELAMINATE CALL THE SHUTTLE") gold_core_spawnable = 0 speak_chance = 3 - var/memory_saved = 0 + var/memory_saved = FALSE var/rounds_survived = 0 var/longest_survival = 0 var/longest_deathstreak = 0 @@ -902,24 +902,19 @@ rounds_survived = max(++rounds_survived,1) if(rounds_survived > longest_survival) longest_survival = rounds_survived - Write_Memory() + Write_Memory(FALSE) + memory_saved = TRUE ..() /mob/living/simple_animal/parrot/Poly/death(gibbed) if(!memory_saved) - var/go_ghost = 0 - if(rounds_survived == longest_survival || rounds_survived == longest_deathstreak || prob(0.666)) - go_ghost = 1 - rounds_survived = min(--rounds_survived,0) - if(rounds_survived < longest_deathstreak) - longest_deathstreak = rounds_survived - Write_Memory() - if(go_ghost) - var/mob/living/simple_animal/parrot/Poly/ghost/G = new(loc) - if(mind) - mind.transfer_to(G) - else - G.key = key + Write_Memory(TRUE) + if(rounds_survived == longest_survival || rounds_survived == longest_deathstreak || prob(0.666)) + var/mob/living/simple_animal/parrot/Poly/ghost/G = new(loc) + if(mind) + mind.transfer_to(G) + else + G.key = key ..(gibbed) /mob/living/simple_animal/parrot/Poly/proc/Read_Memory() @@ -934,8 +929,7 @@ var/json_file = file("data/npc_saves/Poly.json") if(!fexists(json_file)) return - var/list/json = list() - json = json_decode(file2text(json_file)) + var/list/json = json_decode(file2text(json_file)) speech_buffer = json["phrases"] rounds_survived = json["roundssurvived"] longest_survival = json["longestsurvival"] @@ -943,17 +937,27 @@ if(!islist(speech_buffer)) speech_buffer = list() -/mob/living/simple_animal/parrot/Poly/proc/Write_Memory() +/mob/living/simple_animal/parrot/Poly/proc/Write_Memory(dead) var/json_file = file("data/npc_saves/Poly.json") var/list/file_data = list() if(islist(speech_buffer)) file_data["phrases"] = speech_buffer - file_data["roundssurvived"] = rounds_survived - file_data["longestsurvival"] = longest_survival - file_data["longestdeathstreak"] = longest_deathstreak + if(dead) + file_data["roundssurvived"] = min(rounds_survived - 1, 0) + file_data["longestsurvival"] = longest_survival + if(rounds_survived - 1 < longest_deathstreak) + file_data["longestdeathstreak"] = rounds_survived - 1 + else + file_data["longestdeathstreak"] = longest_deathstreak + else + file_data["roundssurvived"] = rounds_survived + 1 + if(rounds_survived + 1 > longest_survival) + file_data["longestsurvival"] = rounds_survived + 1 + else + file_data["longestsurvival"] = longest_survival + file_data["longestdeathstreak"] = longest_deathstreak fdel(json_file) WRITE_FILE(json_file, json_encode(file_data)) - memory_saved = 1 /mob/living/simple_animal/parrot/Poly/ghost name = "The Ghost of Poly" @@ -965,7 +969,7 @@ butcher_results = list(/obj/item/ectoplasm = 1) /mob/living/simple_animal/parrot/Poly/ghost/Initialize() - memory_saved = 1 //At this point nothing is saved + memory_saved = TRUE //At this point nothing is saved ..() /mob/living/simple_animal/parrot/Poly/ghost/handle_automated_speech() From 3930d1886f30db59314b24141c21583e2fad3afe Mon Sep 17 00:00:00 2001 From: YPO <30683121+YPOQ@users.noreply.github.com> Date: Wed, 20 Sep 2017 16:59:59 -0600 Subject: [PATCH 2/2] initialize --- code/modules/awaymissions/super_secret_room.dm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/code/modules/awaymissions/super_secret_room.dm b/code/modules/awaymissions/super_secret_room.dm index 2375f10e0fd..c861a9ffb4a 100644 --- a/code/modules/awaymissions/super_secret_room.dm +++ b/code/modules/awaymissions/super_secret_room.dm @@ -9,13 +9,13 @@ var/times_spoken_to = 0 var/list/shenanigans = list() -/obj/structure/speaking_tile/New() +/obj/structure/speaking_tile/Initialize() + . = ..() var/json_file = file("data/npc_saves/Poly.json") if(!fexists(json_file)) return var/list/json = json_decode(file2text(json_file)) shenanigans = json["phrases"] - ..() /obj/structure/speaking_tile/interact(mob/user) if(!isliving(user) || speaking)