From 60ee7e11b72397f156c56c4fcd87ac9dade17613 Mon Sep 17 00:00:00 2001 From: Nathan Winters <100448493+CinnamonSnowball@users.noreply.github.com> Date: Fri, 24 Nov 2023 16:37:20 +0100 Subject: [PATCH] Lets lockers/crates protect food from ants (#23286) * Let lockers prevent ants * Refactor ants check; exclude closed lockers and cardboard boxes from turf structure check * Make the structure check more lenient, convert to typecache * gnarg * gnarg 2: Electric Boogaloo * Minor simplification/optimization --- .../structures/crates_lockers/closets.dm | 1 + code/game/objects/structures/tables_racks.dm | 2 - code/modules/food_and_drinks/food_base.dm | 63 ++++++++++++------- 3 files changed, 43 insertions(+), 23 deletions(-) diff --git a/code/game/objects/structures/crates_lockers/closets.dm b/code/game/objects/structures/crates_lockers/closets.dm index ffd73efa883..bb2e6da5fef 100644 --- a/code/game/objects/structures/crates_lockers/closets.dm +++ b/code/game/objects/structures/crates_lockers/closets.dm @@ -388,6 +388,7 @@ return ..() + /obj/structure/closet/bluespace name = "bluespace closet" desc = "A storage unit that moves and stores through the fourth dimension." diff --git a/code/game/objects/structures/tables_racks.dm b/code/game/objects/structures/tables_racks.dm index 5c1c3f7074f..fce002c46a5 100644 --- a/code/game/objects/structures/tables_racks.dm +++ b/code/game/objects/structures/tables_racks.dm @@ -401,7 +401,6 @@ return 1 - /obj/structure/table/water_act(volume, temperature, source, method) . = ..() if(HAS_TRAIT(src, TRAIT_OIL_SLICKED)) @@ -409,7 +408,6 @@ remove_atom_colour(FIXED_COLOUR_PRIORITY) REMOVE_TRAIT(src, TRAIT_OIL_SLICKED, "potion") - /* * Glass Tables */ diff --git a/code/modules/food_and_drinks/food_base.dm b/code/modules/food_and_drinks/food_base.dm index 8da6483aef5..51bca61fe51 100644 --- a/code/modules/food_and_drinks/food_base.dm +++ b/code/modules/food_and_drinks/food_base.dm @@ -4,17 +4,22 @@ /obj/item/reagent_containers/food possible_transfer_amounts = null visible_transfer_rate = FALSE - volume = 50 //Sets the default container amount for all food items. - var/filling_color = "#FFFFFF" //Used by sandwiches. - var/junkiness = 0 //for junk food. used to lower human satiety. + volume = 50 + /// Used by sandwiches + var/filling_color = "#FFFFFF" + /// Used by junk food to lower satiety + var/junkiness = 0 var/bitesize = 2 var/consume_sound = 'sound/items/eatfood.ogg' - var/antable = TRUE // Will ants come near it? - /// location checked every 5 minutes. If its the same place, the food has a chance to spawn ants + /// Will ants infest it? + var/antable = TRUE + /// Location checked every 5 minutes. If its the same place, the food has a chance to spawn ants var/ant_location + /// Things that suppress food from being infested by ants when on the same turf + var/static/list/ant_suppressors /// Time we last checked for ants var/last_ant_time = 0 - ///Name of the food to show up in kitchen machines (microwaves, ovens, etc) + /// Name of the food to show up in kitchen machines (microwaves, ovens, etc) var/ingredient_name var/ingredient_name_plural resistance_flags = FLAMMABLE @@ -22,10 +27,18 @@ /obj/item/reagent_containers/food/Initialize(mapload) . = ..() - if(antable) - START_PROCESSING(SSobj, src) - ant_location = get_turf(src) - last_ant_time = world.time + if(!antable) + return + + if(!ant_suppressors) + ant_suppressors = typecacheof(list( + /obj/structure/table, + /obj/structure/rack, + /obj/structure/closet + )) + START_PROCESSING(SSobj, src) + ant_location = get_turf(src) + last_ant_time = world.time /obj/item/reagent_containers/food/Destroy() ant_location = null @@ -41,18 +54,26 @@ /obj/item/reagent_containers/food/proc/check_for_ants() last_ant_time = world.time - var/turf/T = get_turf(src) - if(!isturf(loc)) + + // Are we unshielded from the fury of space ants? + if(!prob(15)) // Ants are often not the smartest return - if((locate(/obj/structure/table) in T) || (locate(/obj/structure/rack) in T)) + if(!isturf(loc)) // Being inside something protects the food return - if(ant_location == T) //It must have been on the same floor since at least the last check_for_ants() - if(prob(15)) - if(!locate(/obj/effect/decal/cleanable/ants) in T) - new /obj/effect/decal/cleanable/ants(T) - antable = FALSE - desc += " It appears to be infested with ants. Yuck!" - reagents.add_reagent("ants", 1) // Don't eat things with ants in it you weirdo. - else + var/turf/T = get_turf(src) + + if(T != ant_location) // Moving the food before a full ant swarm can arrive to the location also helps ant_location = T + return + + for(var/obj/structure/S in T) // Check if some object on our turf protects the food from ants + if(is_type_in_typecache(S, ant_suppressors)) + return + + // Dinner time! + if(!locate(/obj/effect/decal/cleanable/ants) in T) + new /obj/effect/decal/cleanable/ants(T) + antable = FALSE + desc += " It appears to be infested with ants. Yuck!" + reagents.add_reagent("ants", 1) // Don't eat things with ants in it you weirdo.