From 7d6bdcc2a01949f60a35ecb924ccbce187b69466 Mon Sep 17 00:00:00 2001 From: Shadark Date: Sat, 30 May 2020 09:55:40 +0200 Subject: [PATCH] Glowshrooms v1.0: Decay, spread "rework" and able to be analyzed (#51023) * Added decay for glowshrooms Glowshrooms now decay after a certain time. Also, reworked spreading algorithm. * Planted glowshrooms can be analyzed now * fucking newlines * YOOOOOOO IT'S REVIEW TIME * review time v2 * some suggested changes * new shit --- code/game/objects/effects/glowshroom.dm | 85 +++++++++++++++++++------ 1 file changed, 65 insertions(+), 20 deletions(-) diff --git a/code/game/objects/effects/glowshroom.dm b/code/game/objects/effects/glowshroom.dm index 2f212629e02..2d28d3a041b 100644 --- a/code/game/objects/effects/glowshroom.dm +++ b/code/game/objects/effects/glowshroom.dm @@ -9,12 +9,19 @@ icon = 'icons/obj/lighting.dmi' icon_state = "glowshroom" //replaced in New layer = ABOVE_NORMAL_TURF_LAYER - max_integrity = 30 - var/delay = 1200 + /// Time interval between glowshroom "spreads" + var/delay_spread = 2 MINUTES + /// Time interval between glowshroom decay checks + var/delay_decay = 30 SECONDS + /// Boolean to indicate if the shroom is on the floor/wall var/floor = 0 + /// Mushroom generation number var/generation = 1 - var/spreadIntoAdjacentChance = 60 + /// Chance to spread into adjacent tiles (0-100) + var/spreadIntoAdjacentChance = 75 + /// Internal seed of the glowshroom, stats are stored here var/obj/item/seeds/myseed = /obj/item/seeds/glowshroom + /// Turfs where the glowshroom cannot spread to var/static/list/blacklisted_glowshroom_turfs = typecacheof(list( /turf/open/lava, /turf/open/floor/plating/beach/water)) @@ -43,21 +50,30 @@ QDEL_NULL(myseed) return ..() -/obj/structure/glowshroom/New(loc, obj/item/seeds/newseed, mutate_stats) - ..() +/** + * Creates a new glowshroom structure. + * + * Arguments: + * * newseed - Seed of the shroom + * * mutate_stats - If the plant needs to mutate their stats + * * spread - If the plant is a result of spreading, reduce its stats + */ + +/obj/structure/glowshroom/Initialize(mapload, obj/item/seeds/newseed, mutate_stats, spread) + . = ..() if(newseed) myseed = newseed.Copy() myseed.forceMove(src) else myseed = new myseed(src) + if(spread) + myseed.potency -= round(myseed.potency * 0.25) // Reduce potency of the little mushie if it's spreading if(mutate_stats) //baby mushrooms have different stats :3 - myseed.adjust_potency(rand(-3,6)) - myseed.adjust_yield(rand(-1,2)) - myseed.adjust_production(rand(-3,6)) - myseed.adjust_endurance(rand(-3,6)) - delay = delay - myseed.production * 100 //So the delay goes DOWN with better stats instead of up. :I - obj_integrity = myseed.endurance - max_integrity = myseed.endurance + myseed.adjust_potency(rand(-4,3)) + myseed.adjust_yield(rand(-3,2)) + myseed.adjust_production(rand(-3,3)) + myseed.endurance = clamp(myseed.endurance + rand(-3,2), 0, 100) // adjust_endurance has a min value of 10, need to edit directly + delay_spread = delay_spread - myseed.production * 100 //So the delay goes DOWN with better stats instead of up. :I var/datum/plant_gene/trait/glow/G = myseed.get_gene(/datum/plant_gene/trait/glow) if(ispath(G)) // Seeds were ported to initialize so their genes are still typepaths here, luckily their initializer is smart enough to handle us doing this myseed.genes -= G @@ -80,13 +96,20 @@ else //if on the floor, glowshroom on-floor sprite icon_state = base_icon_state - addtimer(CALLBACK(src, .proc/Spread), delay) + addtimer(CALLBACK(src, .proc/Spread), delay_spread) + addtimer(CALLBACK(src, .proc/Decay), delay_decay, FALSE) // Start decaying the plant + +/** + * Causes glowshroom spreading across the floor/walls. + */ /obj/structure/glowshroom/proc/Spread() var/turf/ownturf = get_turf(src) var/shrooms_planted = 0 for(var/i in 1 to myseed.yield) - if(prob(1/(generation * generation) * 100))//This formula gives you diminishing returns based on generation. 100% with 1st gen, decreasing to 25%, 11%, 6, 4, 2... + var/chance_stats = ((myseed.potency + myseed.endurance * 2) * 0.2) // Chance of generating a new mushroom based on stats + var/chance_generation = (100 / (generation * generation)) // This formula gives you diminishing returns based on generation. 100% with 1st gen, decreasing to 25%, 11%, 6, 4, 2... + if(prob(max(chance_stats, chance_generation))) // Whatever is the higher chance we use it var/list/possibleLocs = list() var/spreadsIntoAdjacent = FALSE @@ -118,16 +141,15 @@ if(shroomCount >= placeCount) continue - var/obj/structure/glowshroom/child = new type(newLoc, myseed, TRUE) + Decay(TRUE, 2) // Decay before spawning new mushrooms to reduce their endurance + var/obj/structure/glowshroom/child = new type(newLoc, myseed, TRUE, TRUE) child.generation = generation + 1 shrooms_planted++ CHECK_TICK - else - shrooms_planted++ //if we failed due to generation, don't try to plant one later - if(shrooms_planted < myseed.yield) //if we didn't get all possible shrooms planted, try again later - myseed.yield -= shrooms_planted - addtimer(CALLBACK(src, .proc/Spread), delay) + if(shrooms_planted <= myseed.yield) //if we didn't get all possible shrooms planted, try again later + myseed.adjust_yield(-shrooms_planted) + addtimer(CALLBACK(src, .proc/Spread), delay_spread) /obj/structure/glowshroom/proc/CalcDir(turf/location = loc) var/direction = 16 @@ -161,6 +183,24 @@ floor = 1 return 1 +/** + * Causes the glowshroom to decay by decreasing its endurance. + * + * Arguments: + * * spread - Boolean to indicate if the decay is due to spreading or natural decay. + * * amount - Amount of endurance to be reduced due to spread decay. + */ +/obj/structure/glowshroom/proc/Decay(spread, amount) + if (spread) // Decay due to spread + myseed.endurance -= amount + else // Timed decay + myseed.endurance -= 1 + if (myseed.endurance > 0) + addtimer(CALLBACK(src, .proc/Decay), delay_decay, FALSE) // Recall decay timer + return + if (myseed.endurance < 1) // Plant is gone + qdel(src) + /obj/structure/glowshroom/play_attack_sound(damage_amount, damage_type = BRUTE, damage_flag = 0) if(damage_type == BURN && damage_amount) playsound(src.loc, 'sound/items/welder.ogg', 100, TRUE) @@ -175,3 +215,8 @@ var/obj/effect/decal/cleanable/molten_object/I = new (get_turf(src)) I.desc = "Looks like this was \an [src] some time ago." qdel(src) + +/obj/structure/glowshroom/attackby(obj/item/I, mob/living/user, params) + if (istype(I, /obj/item/plant_analyzer)) + return myseed.attackby(I, user, params) // Hacky I guess + return ..() // Attack normally