//Tinkerer's Daemon: A machine that rapidly produces components at a power cost. /obj/structure/destructible/clockwork/powered/tinkerers_daemon name = "tinkerer's daemon" desc = "A strange machine with three small brass obelisks attached to it." clockwork_desc = "An efficient machine that can rapidly produce components at a small power cost. It will only function if active daemons are outnumbered by servants at a rate to 5:1." icon_state = "tinkerers_daemon" active_icon = "tinkerers_daemon" inactive_icon = "tinkerers_daemon" unanchored_icon = "tinkerers_daemon_unwrenched" max_integrity = 100 construction_value = 20 break_message = "The daemon shatters into millions of pieces, leaving only a disc of metal!" debris = list(/obj/item/clockwork/alloy_shards/medium = 1, \ /obj/item/clockwork/alloy_shards/small = 6, \ /obj/item/clockwork/component/replicant_alloy/replication_plate = 1) var/static/mutable_appearance/daemon_glow = mutable_appearance('icons/obj/clockwork_objects.dmi', "tinkerglow") var/static/mutable_appearance/component_glow = mutable_appearance('icons/obj/clockwork_objects.dmi', "t_random_component") var/component_id_to_produce var/production_time = 0 //last time we produced a component var/production_cooldown = 70 /obj/structure/destructible/clockwork/powered/tinkerers_daemon/Destroy() GLOB.active_daemons -= src return ..() /obj/structure/destructible/clockwork/powered/tinkerers_daemon/examine(mob/user) ..() if(is_servant_of_ratvar(user) || isobserver(user)) if(active) if(component_id_to_produce) to_chat(user, "It is currently producing [get_component_name(component_id_to_produce)][component_id_to_produce != REPLICANT_ALLOY ? "s":""].") else to_chat(user, "It is currently producing random components.") to_chat(user, "It will produce a component every [round((production_cooldown*0.1) * get_efficiency_mod(TRUE), 0.1)] seconds and requires at least the following power for each component type:") for(var/i in GLOB.clockwork_component_cache) to_chat(user, "[get_component_icon(i)] [get_component_name(i)]: [get_component_cost(i)]W ([GLOB.clockwork_component_cache[i]] exist[GLOB.clockwork_component_cache[i] == 1 ? "s" : ""])") /obj/structure/destructible/clockwork/powered/tinkerers_daemon/forced_disable(bad_effects) if(active) if(bad_effects) try_use_power(MIN_CLOCKCULT_POWER*4) visible_message("[src] shuts down with a horrible grinding noise!") playsound(src, 'sound/magic/clockwork/anima_fragment_attack.ogg', 50, 1) else visible_message("[src] shuts down!") toggle() return TRUE /obj/structure/destructible/clockwork/powered/tinkerers_daemon/attack_hand(mob/living/user) if(!is_servant_of_ratvar(user)) to_chat(user, "You place your hand on the daemon, but nothing happens.") return if(active) toggle(0, user) else if(!anchored) to_chat(user, "[src] needs to be secured to the floor before it can be activated!") return FALSE if(!GLOB.clockwork_caches) to_chat(user, "\"You require a cache for this daemon to operate. Get to it.\"") return var/min_power_usable = 0 for(var/i in GLOB.clockwork_component_cache) if(!min_power_usable) min_power_usable = get_component_cost(i) else min_power_usable = min(min_power_usable, get_component_cost(i)) if(total_accessable_power() < min_power_usable) to_chat(user, "\"You need more power to activate this daemon, friend.\"") return var/servants = 0 for(var/mob/living/L in GLOB.living_mob_list) if(is_servant_of_ratvar(L)) servants++ if(servants * 0.2 < 1) to_chat(user, "\"There are too few servants for daemons to work.\"") return var/choice = alert(user,"Activate Daemon...",,"Specific Component","Random Component","Cancel") switch(choice) if("Specific Component") var/list/components = list() for(var/i in GLOB.clockwork_component_cache) components["[get_component_name(i)] ([get_component_cost(i)]W)"] = i var/input_component = input(user, "Choose a component type.", name) as null|anything in components component_id_to_produce = components[input_component] servants = 0 for(var/mob/living/L in GLOB.living_mob_list) if(is_servant_of_ratvar(L)) servants++ if(!is_servant_of_ratvar(user) || !user.canUseTopic(src, !issilicon(user), NO_DEXTERY) || active || !GLOB.clockwork_caches || servants * 0.2 < 1) return if(!component_id_to_produce) to_chat(user, "You decide not to select a component and activate the daemon.") return if(total_accessable_power() < get_component_cost(component_id_to_produce)) to_chat(user, "There is too little power to produce this type of component!") return toggle(0, user) if("Random Component") component_id_to_produce = null servants = 0 for(var/mob/living/L in GLOB.living_mob_list) if(is_servant_of_ratvar(L)) servants++ if(!is_servant_of_ratvar(user) || !user.canUseTopic(src, !issilicon(user), NO_DEXTERY) || active || !GLOB.clockwork_caches || servants * 0.2 < 1) return toggle(0, user) /obj/structure/destructible/clockwork/powered/tinkerers_daemon/toggle(fast_process, mob/living/user) . = ..() if(active) GLOB.active_daemons += src var/component_color = get_component_color(component_id_to_produce) daemon_glow.color = component_color add_overlay(daemon_glow) component_glow.icon_state = "t_[component_id_to_produce ? component_id_to_produce :"random_component"]" component_glow.color = component_color add_overlay(component_glow) production_time = world.time + production_cooldown //don't immediately produce when turned on after being off set_light(2, 0.9, get_component_color_bright(component_id_to_produce)) else GLOB.active_daemons -= src cut_overlays() set_light(0) /obj/structure/destructible/clockwork/powered/tinkerers_daemon/proc/get_component_cost(id) return max(MIN_CLOCKCULT_POWER*2, (MIN_CLOCKCULT_POWER*2) * (1 + round(GLOB.clockwork_component_cache[id] * 0.2))) /obj/structure/destructible/clockwork/powered/tinkerers_daemon/process() var/servants = 0 for(var/mob/living/L in GLOB.living_mob_list) if(is_servant_of_ratvar(L)) servants++ while(servants * 0.2 < LAZYLEN(GLOB.active_daemons)) var/obj/structure/destructible/clockwork/powered/tinkerers_daemon/D = GLOB.active_daemons[1] if(!istype(D)) break if(D.active) D.forced_disable(FALSE) if(D == src) return . = ..() var/min_power_usable = 0 if(!component_id_to_produce) for(var/i in GLOB.clockwork_component_cache) if(!min_power_usable) min_power_usable = get_component_cost(i) else min_power_usable = min(min_power_usable, get_component_cost(i)) else min_power_usable = get_component_cost(component_id_to_produce) if(!GLOB.clockwork_caches || . < min_power_usable) //if we don't have enough to produce the lowest or what we chose to produce, cancel out forced_disable(FALSE) return if(production_time <= world.time) var/component_to_generate = component_id_to_produce if(!component_to_generate) component_to_generate = get_weighted_component_id() //more likely to generate components that we have less of if(!try_use_power(get_component_cost(component_to_generate))) component_to_generate = null if(!component_id_to_produce) for(var/i in GLOB.clockwork_component_cache) if(try_use_power(get_component_cost(i))) //if we fail but are producing random, try and get a different component to produce component_to_generate = i break if(component_to_generate) generate_cache_component(component_to_generate, src) production_time = world.time + (production_cooldown * get_efficiency_mod(TRUE)) //go on cooldown visible_message("[src] hums as it produces a component.") else forced_disable(FALSE) //we shouldn't actually ever get here, as we should cancel out way before this