mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-01-21 22:47:19 +00:00
## About The Pull Request Part 2 of #79686 where we trim down the size of `holder.dm` even further and in the process give some procs more advanced features as they get merged with their counterparts. **1. Removes & merges `get_multiple_reagent_amounts()` proc with `get_reagent_amount()`** The proc `get_multiple_reagent_amounts()` was only used by bio generator and 1 other item with its only use being finding the sum of all reagents present in the list returned by `typesof(datum/reagent/consumable/nutrient)`. Currently the approach is very inefficient because. - `typesof()` is an expensive call which returns a long list of reagents - `get_multiple_reagent_amounts()` would then use 2 nested for loops. One to loop over every reagent in this holder & another inner for loop to loop over every reagent returned by `typesof()` operator so the time complexity of this proc is overall multiplicative which in lamen terms means "Bad" We can replicate the same behaviour of `typesof()` by using the `type2parent()` proc and 1 more direct type check to get the exact same behaviour but with much faster results, therefore reducing overall code **2. Removes & merges `get_reagent()` proc with `has_reagent()`** The proc `has_reagent()` is way more advanced than `get_reagent()` with arguments requesting for a specific amount, metabolization and now even has a new argument i.e. `chemical flag`. `has_reagent()` has always returned the reagent reference directly and not a simple TRUE/FALSE so it is a perfect replacement for `get_reagent()`, therefore reducing overall code **3. Removes & merges `has_chemical_flag()` proc with `has_reagent()`** The proc `has_reagent()` can now look for a specific reagent with a specific chemical flag as well as mentioned above thus it can replace `has_chemical_flag()` therefore reducing overall code ## Changelog 🆑 code: Removes & merges `get_multiple_reagent_amounts()` proc with `get_reagent_amount()` inside reagent holder code: Removes & merges `get_reagent()` proc with `has_reagent()` inside reagent holder code: Removes & merges `has_chemical_flag()` proc with `has_reagent()` inside reagent holder refactor: Reagent holder code has been further compressed. Report bugs on github /🆑
119 lines
4.2 KiB
Plaintext
119 lines
4.2 KiB
Plaintext
/obj/item/mop
|
|
desc = "The world of janitalia wouldn't be complete without a mop."
|
|
name = "mop"
|
|
icon = 'icons/obj/service/janitor.dmi'
|
|
icon_state = "mop"
|
|
inhand_icon_state = "mop"
|
|
lefthand_file = 'icons/mob/inhands/equipment/custodial_lefthand.dmi'
|
|
righthand_file = 'icons/mob/inhands/equipment/custodial_righthand.dmi'
|
|
force = 8
|
|
throwforce = 10
|
|
throw_speed = 3
|
|
throw_range = 7
|
|
w_class = WEIGHT_CLASS_NORMAL
|
|
attack_verb_continuous = list("mops", "bashes", "bludgeons", "whacks")
|
|
attack_verb_simple = list("mop", "bash", "bludgeon", "whack")
|
|
resistance_flags = FLAMMABLE
|
|
var/mopcount = 0
|
|
///Maximum volume of reagents it can hold.
|
|
var/max_reagent_volume = 15
|
|
var/mopspeed = 1.5 SECONDS
|
|
force_string = "robust... against germs"
|
|
var/insertable = TRUE
|
|
var/static/list/clean_blacklist = typecacheof(list(
|
|
/obj/item/reagent_containers/cup/bucket,
|
|
/obj/structure/mop_bucket,
|
|
))
|
|
|
|
/obj/item/mop/apply_fantasy_bonuses(bonus)
|
|
. = ..()
|
|
mopspeed = modify_fantasy_variable("mopspeed", mopspeed, -bonus)
|
|
|
|
/obj/item/mop/remove_fantasy_bonuses(bonus)
|
|
mopspeed = reset_fantasy_variable("mopspeed", mopspeed)
|
|
return ..()
|
|
|
|
/obj/item/mop/Initialize(mapload)
|
|
. = ..()
|
|
AddComponent(/datum/component/cleaner, mopspeed, pre_clean_callback=CALLBACK(src, PROC_REF(should_clean)), on_cleaned_callback=CALLBACK(src, PROC_REF(apply_reagents)))
|
|
create_reagents(max_reagent_volume)
|
|
GLOB.janitor_devices += src
|
|
|
|
/obj/item/mop/Destroy(force)
|
|
GLOB.janitor_devices -= src
|
|
return ..()
|
|
|
|
///Checks whether or not we should clean.
|
|
/obj/item/mop/proc/should_clean(datum/cleaning_source, atom/atom_to_clean, mob/living/cleaner)
|
|
if(clean_blacklist[atom_to_clean.type])
|
|
return DO_NOT_CLEAN
|
|
if(reagents.total_volume < 0.1)
|
|
cleaner.balloon_alert(cleaner, "mop is dry!")
|
|
return DO_NOT_CLEAN
|
|
return reagents.has_reagent(amount = 1, chemical_flags = REAGENT_CLEANS)
|
|
|
|
/**
|
|
* Applies reagents to the cleaned floor and removes them from the mop.
|
|
*
|
|
* Arguments
|
|
* * cleaning_source the source of the cleaning
|
|
* * cleaned_turf the turf that is being cleaned
|
|
* * cleaner the mob that is doing the cleaning
|
|
*/
|
|
/obj/item/mop/proc/apply_reagents(datum/cleaning_source, turf/cleaned_turf, mob/living/cleaner)
|
|
reagents.expose(cleaned_turf, TOUCH, 10) //Needed for proper floor wetting.
|
|
var/val2remove = 1
|
|
if(cleaner?.mind)
|
|
val2remove = round(cleaner.mind.get_skill_modifier(/datum/skill/cleaning, SKILL_SPEED_MODIFIER), 0.1)
|
|
reagents.remove_any(val2remove) //reaction() doesn't use up the reagents
|
|
|
|
/obj/item/mop/cyborg/Initialize(mapload)
|
|
. = ..()
|
|
ADD_TRAIT(src, TRAIT_NODROP, CYBORG_ITEM_TRAIT)
|
|
|
|
/obj/item/mop/advanced
|
|
desc = "The most advanced tool in a custodian's arsenal, complete with a condenser for self-wetting! Just think of all the viscera you will clean up with this!"
|
|
name = "advanced mop"
|
|
max_reagent_volume = 10
|
|
icon_state = "advmop"
|
|
inhand_icon_state = "advmop"
|
|
lefthand_file = 'icons/mob/inhands/equipment/custodial_lefthand.dmi'
|
|
righthand_file = 'icons/mob/inhands/equipment/custodial_righthand.dmi'
|
|
force = 12
|
|
throwforce = 14
|
|
throw_range = 4
|
|
mopspeed = 0.8 SECONDS
|
|
var/refill_enabled = TRUE //Self-refill toggle for when a janitor decides to mop with something other than water.
|
|
/// Amount of reagent to refill per second
|
|
var/refill_rate = 0.5
|
|
var/refill_reagent = /datum/reagent/water //Determins what reagent to use for refilling, just in case someone wanted to make a HOLY MOP OF PURGING
|
|
|
|
/obj/item/mop/advanced/Initialize(mapload)
|
|
. = ..()
|
|
START_PROCESSING(SSobj, src)
|
|
|
|
/obj/item/mop/advanced/attack_self(mob/user)
|
|
refill_enabled = !refill_enabled
|
|
if(refill_enabled)
|
|
START_PROCESSING(SSobj, src)
|
|
else
|
|
STOP_PROCESSING(SSobj,src)
|
|
user.balloon_alert(user, "condenser switch [refill_enabled ? "on" : "off"]")
|
|
playsound(user, 'sound/machines/click.ogg', 30, TRUE)
|
|
|
|
/obj/item/mop/advanced/process(seconds_per_tick)
|
|
var/amadd = min(max_reagent_volume - reagents.total_volume, refill_rate * seconds_per_tick)
|
|
if(amadd > 0)
|
|
reagents.add_reagent(refill_reagent, amadd)
|
|
|
|
/obj/item/mop/advanced/examine(mob/user)
|
|
. = ..()
|
|
. += span_notice("The condenser switch is set to <b>[refill_enabled ? "ON" : "OFF"]</b>.")
|
|
|
|
/obj/item/mop/advanced/Destroy()
|
|
STOP_PROCESSING(SSobj, src)
|
|
return ..()
|
|
|
|
/obj/item/mop/advanced/cyborg
|
|
insertable = FALSE
|