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
This commit is contained in:
Nathan Winters
2023-11-24 15:37:20 +00:00
committed by GitHub
parent f806aed945
commit 60ee7e11b7
3 changed files with 43 additions and 23 deletions
+42 -21
View File
@@ -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.