Skip to content

Commit

Permalink
BSH update (ParadiseSS13#26032)
Browse files Browse the repository at this point in the history
* MOAAAAAR POWEEEEEEER

* base points are per level again. reduced to 2

* Style changes, spaghetti is now in a box and the alert logic has been tidied up

* Stabilizer and Autoshutoff buttons are now stuck in the off position when emagged

* Rebuild TGUI

* Rebuild TGUI

* rebuild tgui

* Emag now forces highest level possible

* Rebuild TGUI

* Portal amount no longer dependent on stabilizers. Stabilizers no longer stabilize when off. Portal spawning message now only plays if there are no portals currently spawned to prevent spam when auto shutdown is disabled. Warning message now correctly indicates auto shutdown is disabled. Improved Readability

* corrects a comment

---------

Co-authored-by: Burzah <[email protected]>
  • Loading branch information
Migratingcocofruit and Burzah authored Aug 4, 2024
1 parent 319a3d0 commit b119246
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 26 deletions.
62 changes: 47 additions & 15 deletions code/modules/station_goals/bluespace_tap.dm
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@
#define kW *1000
#define MW kW *1000
#define GW MW *1000
#define BASE_ENERGY_CONVERSION 4e-6
#define BASE_POINTS 2

/**
* # Bluespace Harvester
Expand Down Expand Up @@ -231,12 +233,22 @@

// Tweak these and active_power_consumption to balance power generation

/// Max power input level, I don't expect this to be ever reached
/// Max power input level, I don't expect this to be ever reached. It has been reached.
var/max_level = 25
/// Amount of points to give per mining level
var/base_points = 4
/// amount of points generated per level for the first 10 levels
var/base_points = BASE_POINTS
/// amount of points generated per process cycle per unit of energy consumed
var/conversion_ratio = BASE_ENERGY_CONVERSION
/// How high the machine can be run before it starts having a chance for dimension breaches.
var/safe_levels = 15
/// Whether or not auto shutdown will engage when portals open
var/auto_shutdown = TRUE
/// Whether or not stabilizers will engage to prevent or reduce the chance of portals opening
var/stabilizers = TRUE
/// Amount of power the stabilizers consume
var/stabilizer_power = 0
/// Amount of overhead in levels. Each level of overhead allows stabilizing 15+overhead.
var/overhead = 0
/// When event triggers this will hold references to all portals so we can fix the sprite after they're broken
var/list/active_nether_portals = list()

Expand Down Expand Up @@ -393,31 +405,40 @@
return // and no mining gets done
if(actual_power_usage)
consume_direct_power(actual_power_usage)
var/points_to_add = (input_level + emagged) * base_points
points += points_to_add //point generation, emagging gets you 'free' points at the cost of higher anomaly chance
//2 points per level up to level 10 and 4 points per MW (or 5 when emmaged).
var/points_to_add = min(base_points * 10, base_points * input_level) + actual_power_usage * (conversion_ratio + emagged * 1e-6)
points += points_to_add // point generation, emagging gets you 'free' points at the cost of higher anomaly chance
total_points += points_to_add
// Between levels 15 and 18 get one level of overhead per 5MW of surplus power. Above level 18 get 1 level per 10MW of surplus power.
overhead = input_level >= 18 ? get_surplus() * 1e-7 : get_surplus() * 2e-7
stabilizer_power = stabilizers && input_level > 15 ? input_level >= 18 ? min(get_surplus() , (input_level - 15) * 1e7) : min(get_surplus() , (input_level - 15) * 0.5e7) : 0
consume_direct_power(stabilizer_power)
// actual input level changes slowly
//holy shit every proccess this
if(input_level < desired_level && (get_surplus() >= get_power_use(input_level + 1)))
// holy shit every proccess this
if(input_level < desired_level && (get_surplus() + get_power_use(input_level) + stabilizer_power >= get_power_use(input_level + 1)))
input_level++
update_icon()
else if(input_level > desired_level)
input_level--
update_icon()
if(prob(input_level - safe_levels + (emagged * 5))) //at dangerous levels, start doing freaky shit. prob with values less than 0 treat it as 0
// Stabilizers reduce the chance of portals. prob with values less than 0 treat it as 0.
if(prob(input_level - (safe_levels + stabilizers * overhead) + (emagged * 5)))
var/area/our_area = get_area(src)
GLOB.major_announcement.Announce("Unexpected power spike during Bluespace Harvester Operation. Extra-dimensional intruder alert. Expected location: [our_area.name]. [emagged ? "DANGER: Emergency shutdown failed! Please proceed with manual shutdown." : "Emergency shutdown initiated."]", "Bluespace Harvester Malfunction", 'sound/AI/harvester.ogg')
if(!emagged)
input_level = 0 //emergency shutdown unless we're sabotaged
if(!length(active_nether_portals))
GLOB.major_announcement.Announce("Unexpected power spike during Bluespace Harvester Operation. Extra-dimensional intruder alert. Expected location: [our_area.name]. [emagged ? "DANGER: Emergency shutdown failed! Please proceed with manual shutdown." : auto_shutdown ? "Emergency shutdown initiated." : "Automatic shutdown disabled."]", "Bluespace Harvester Malfunction", 'sound/AI/harvester.ogg')
if(!emagged && auto_shutdown)
input_level = 0 //emergency shutdown unless it is disabled
desired_level = 0
start_nether_portaling(rand(1, 3))
start_nether_portaling(rand(1 , 3) + max((level - 15 - overhead) / 3 , 0))

/obj/machinery/power/bluespace_tap/proc/start_nether_portaling(amount)
var/turf/location = locate(x + rand(-5, 5), y + rand(-5, 5), z)
var/obj/structure/spawner/nether/bluespace_tap/P = new /obj/structure/spawner/nether/bluespace_tap(location)
amount--
active_nether_portals += P
P.linked_source_object = src
// 1 Extra mob for each 2 levels above 15.
P.max_mobs = 5 + max((input_level - 15) / 2, 0)
update_icon()
if(amount)
addtimer(CALLBACK(src, PROC_REF(start_nether_portaling), amount), rand(3, 5) SECONDS)
Expand All @@ -429,12 +450,16 @@
data["inputLevel"] = input_level
data["points"] = points
data["totalPoints"] = total_points
data["powerUse"] = actual_power_usage
data["powerUse"] = actual_power_usage + stabilizer_power
data["availablePower"] = get_surplus()
data["maxLevel"] = max_level
data["emagged"] = emagged
data["safeLevels"] = safe_levels
data["nextLevelPower"] = get_power_use(input_level + 1)
data["autoShutown"] = auto_shutdown
data["overhead"] = overhead
data["stabilizers"] = stabilizers
data["stabilizerPower"] = stabilizer_power

/// A list of lists, each inner list equals a datum
var/list/listed_items = list()
Expand Down Expand Up @@ -498,6 +523,10 @@
if("vend")//it's not really vending as producing, but eh
var/key = text2num(params["target"])
produce(key)
if("auto_shutdown")
auto_shutdown = !auto_shutdown
if("stabilizers")
stabilizers = !stabilizers

/obj/machinery/power/bluespace_tap/ui_state(mob/user)
return GLOB.default_state
Expand All @@ -513,14 +542,15 @@
if(emagged)
return
emagged = TRUE
desired_level = max_level
do_sparks(5, FALSE, src)
if(user)
user.visible_message("<span class='warning'>[user] overrides the safety protocols of [src].</span>", "<span class='warning'>You override the safety protocols.</span>")
user.visible_message("<span class='warning'>[user] disables the [src]'s safeties'.</span>", "<span class='warning'>You disable the [src]'s safeties'.</span>")
return TRUE

/obj/structure/spawner/nether/bluespace_tap
spawn_time = 30 SECONDS
max_mobs = 5 //Dont' want them overrunning the station
max_mobs = 5 // Don't want them overrunning the station
max_integrity = 250
/// the BSH that spawned this portal
var/obj/machinery/power/bluespace_tap/linked_source_object
Expand Down Expand Up @@ -556,3 +586,5 @@
#undef kW
#undef MW
#undef GW
#undef BASE_ENERGY_CONVERSION
#undef BASE_POINTS
62 changes: 52 additions & 10 deletions tgui/packages/tgui/interfaces/BluespaceTap.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,44 +15,62 @@ export const BluespaceTap = (props, context) => {
availablePower,
maxLevel,
emagged,
safeLevels,
nextLevelPower,
autoShutown,
stabilizers,
stabilizerPower,
} = data;
const barColor = (desiredLevel > inputLevel && 'bad') || 'good';
return (
<Window width={650} height={450}>
<Window.Content scrollable>
<Stack fill vertical>
{!!emagged && <NoticeBox danger={1}>Safety Protocols disabled</NoticeBox>}
{!!(inputLevel > safeLevels) && <NoticeBox danger={1}>High Power, Instability likely</NoticeBox>}
<Alerts />
<Collapsible title="Input Management">
<Section fill title="Input">
<Button
icon={!!autoShutown && !emagged ? 'toggle-on' : 'toggle-off'}
content="Auto shutdown"
color={!!autoShutown && !emagged ? 'green' : 'red'}
disabled={!!emagged}
tooltip="Turn auto shutdown on or off"
onClick={() => act('auto_shutdown')}
/>
<Button
icon={!!stabilizers && !emagged ? 'toggle-on' : 'toggle-off'}
content="Stabilizers"
color={!!stabilizers && !emagged ? 'green' : 'red'}
disabled={!!emagged}
tooltip="Turn stabilizers on or off"
onClick={() => act('stabilizers')}
/>
<LabeledList>
<LabeledList.Item label="Input Level">{inputLevel}</LabeledList.Item>
<LabeledList.Item label="Desired Level">
<Stack inline width="100%">
<Stack.Item>
<Button
icon="fast-backward"
disabled={desiredLevel === 0}
disabled={desiredLevel === 0 || emagged}
tooltip="Set to 0"
onClick={() => act('set', { set_level: 0 })}
/>
<Button
icon="step-backward"
tooltip="Decrease to actual input level"
disabled={desiredLevel === 0}
disabled={desiredLevel === 0 || emagged}
onClick={() => act('set', { set_level: inputLevel })}
/>
<Button
icon="backward"
disabled={desiredLevel === 0}
disabled={desiredLevel === 0 || emagged}
tooltip="Decrease one step"
onClick={() => act('decrease')}
/>
</Stack.Item>
<Stack.Item grow={1} mx={1}>
<Slider
disabled={emagged}
value={desiredLevel}
fillValue={inputLevel}
minValue={0}
Expand All @@ -70,23 +88,25 @@ export const BluespaceTap = (props, context) => {
<Stack.Item>
<Button
icon="forward"
disabled={desiredLevel === maxLevel}
disabled={desiredLevel === maxLevel || emagged}
tooltip="Increase one step"
tooltipPosition="left"
onClick={() => act('increase')}
/>
<Button
icon="fast-forward"
disabled={desiredLevel === maxLevel}
disabled={desiredLevel === maxLevel || emagged}
tooltip="Set to max"
tooltipPosition="left"
onClick={() => act('set', { set_level: maxLevel })}
/>
</Stack.Item>
</Stack>
</LabeledList.Item>
<LabeledList.Item label="Current Power Use">{formatPower(powerUse)}</LabeledList.Item>
<LabeledList.Item label="Power for next level">{formatPower(nextLevelPower)}</LabeledList.Item>
<LabeledList.Item label="Total Power Use">{formatPower(powerUse)}</LabeledList.Item>
<LabeledList.Item label="Mining Power Use">{formatPower(powerUse - stabilizerPower)}</LabeledList.Item>
<LabeledList.Item label="Stabilizer Power Use">{formatPower(stabilizerPower)}</LabeledList.Item>
<LabeledList.Item label="Mining Power for next level">{formatPower(nextLevelPower)}</LabeledList.Item>
<LabeledList.Item label="Surplus Power">{formatPower(availablePower)}</LabeledList.Item>
</LabeledList>
</Section>
Expand Down Expand Up @@ -123,3 +143,25 @@ export const BluespaceTap = (props, context) => {
</Window>
);
};

export const Alerts = (props, context) => {
const { act, data } = useBackend(context);
const product = data.product || [];
const { inputLevel, emagged, safeLevels, autoShutown, stabilizers, overhead } = data;
return (
<>
{!autoShutown && !emagged && <NoticeBox danger={1}>Auto shutdown disabled</NoticeBox>}
{emagged ? (
<NoticeBox danger={1}>All safeties disabled</NoticeBox>
) : inputLevel <= safeLevels ? (
''
) : !stabilizers ? (
<NoticeBox danger={1}>Stabilizers disabled, Instability likely</NoticeBox>
) : inputLevel - overhead > safeLevels ? (
<NoticeBox danger={1}>Stabilizers overwhelmed, Instability likely</NoticeBox>
) : (
<NoticeBox>High Power, engaging stabilizers</NoticeBox>
)}
</>
);
};
2 changes: 1 addition & 1 deletion tgui/public/tgui.bundle.js

Large diffs are not rendered by default.

0 comments on commit b119246

Please sign in to comment.