mirror of
https://github.com/PolarisSS13/Polaris.git
synced 2026-08-31 09:08:56 +01:00
between() -> clamp() & swaps args 1 and 2 in uses
This commit is contained in:
@@ -65,7 +65,7 @@
|
||||
icon_update = 0
|
||||
|
||||
var/cellcount = 0
|
||||
var/charge_level = between(0, round(Percentage() / 12), 7)
|
||||
var/charge_level = clamp(round(Percentage() / 12), 0, 7)
|
||||
|
||||
|
||||
add_overlay("charge[charge_level]")
|
||||
@@ -87,7 +87,7 @@
|
||||
newmaxcharge /= CELLRATE // Convert to Joules
|
||||
newmaxcharge *= SMESRATE // And to SMES charge units (which are for some reason different than CELLRATE)
|
||||
capacity = newmaxcharge
|
||||
charge = between(0, charge, newmaxcharge)
|
||||
charge = clamp(charge, 0, newmaxcharge)
|
||||
|
||||
|
||||
// Sets input/output depending on our "mode" var.
|
||||
@@ -204,7 +204,7 @@
|
||||
celldiff = (least.maxcharge / 100) * percentdiff
|
||||
else
|
||||
celldiff = (most.maxcharge / 100) * percentdiff
|
||||
celldiff = between(0, celldiff, max_transfer_rate * CELLRATE)
|
||||
celldiff = clamp(celldiff, 0, max_transfer_rate * CELLRATE)
|
||||
// Ensure we don't transfer more energy than the most charged cell has, and that the least charged cell can input.
|
||||
celldiff = min(min(celldiff, most.charge), least.maxcharge - least.charge)
|
||||
least.give(most.use(celldiff))
|
||||
@@ -286,7 +286,7 @@
|
||||
update_io(0)
|
||||
return 1
|
||||
else if( href_list["enable"] )
|
||||
update_io(between(1, text2num(href_list["enable"]), 3))
|
||||
update_io(clamp(text2num(href_list["enable"]), 1, 3))
|
||||
return 1
|
||||
else if( href_list["equaliseon"] )
|
||||
equalise = 1
|
||||
@@ -309,4 +309,4 @@
|
||||
update_icon()
|
||||
RefreshParts()
|
||||
update_maxcharge()
|
||||
return 1
|
||||
return 1
|
||||
|
||||
@@ -211,7 +211,7 @@
|
||||
//or if it is already above upper_limit, limit the increase to 0.
|
||||
var/inc_limit = max(upper_limit - temperature, 0)
|
||||
var/dec_limit = min(temperature - lower_limit, 0)
|
||||
temperature += between(dec_limit, rand(-7 + bias, 7 + bias), inc_limit)
|
||||
temperature += clamp(rand(-7 + bias, 7 + bias), dec_limit, inc_limit)
|
||||
|
||||
if (temperature > max_temperature)
|
||||
overheat()
|
||||
@@ -228,7 +228,7 @@
|
||||
|
||||
if(temperature > cooling_temperature)
|
||||
var/temp_loss = (temperature - cooling_temperature)/TEMPERATURE_DIVISOR
|
||||
temp_loss = between(2, round(temp_loss, 1), TEMPERATURE_CHANGE_MAX)
|
||||
temp_loss = clamp(round(temp_loss, 1), 2, TEMPERATURE_CHANGE_MAX)
|
||||
temperature = max(temperature - temp_loss, cooling_temperature)
|
||||
updateDialog()
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
return max(avail - load, 0)
|
||||
|
||||
/datum/powernet/proc/draw_power(var/amount)
|
||||
var/draw = between(0, amount, avail - load)
|
||||
var/draw = clamp(amount, 0, avail - load)
|
||||
load += draw
|
||||
return draw
|
||||
|
||||
@@ -122,7 +122,7 @@
|
||||
|
||||
// At this point, all other machines have finished using power. Anything left over may be used up to charge SMESs.
|
||||
if(inputting.len && smes_demand)
|
||||
var/smes_input_percentage = between(0, (netexcess / smes_demand) * 100, 100)
|
||||
var/smes_input_percentage = clamp((netexcess / smes_demand) * 100, 0, 100)
|
||||
for(var/obj/machinery/power/terminal/T in inputting)
|
||||
var/obj/machinery/power/smes/S = T.master
|
||||
if(istype(S))
|
||||
@@ -152,11 +152,11 @@
|
||||
var/smes_used = load - (avail - smes_avail) // SMESs are always last to provide power
|
||||
if(!smes_used || smes_used < 0 || !smes_avail) // SMES power isn't available or being used at all, SMES load is therefore 0%
|
||||
return 0
|
||||
return between(0, (smes_used / smes_avail) * 100, 100) // Otherwise return percentage load of SMESs.
|
||||
return clamp((smes_used / smes_avail) * 100, 0, 100) // Otherwise return percentage load of SMESs.
|
||||
else
|
||||
if(!load)
|
||||
return 0
|
||||
return between(0, (load / avail) * 100, 100)
|
||||
return clamp((load / avail) * 100, 0, 100)
|
||||
|
||||
/datum/powernet/proc/get_electrocute_damage()
|
||||
switch(avail)
|
||||
|
||||
@@ -256,7 +256,7 @@
|
||||
adjust_integrity(-1000) // This kills the emitter.
|
||||
|
||||
/obj/machinery/power/emitter/proc/adjust_integrity(amount)
|
||||
integrity = between(0, integrity + amount, initial(integrity))
|
||||
integrity = clamp(integrity + amount, 0, initial(integrity))
|
||||
if(integrity == 0)
|
||||
if(powernet && avail(active_power_usage)) // If it's powered, it goes boom if killed.
|
||||
visible_message(src, "<span class='danger'>\The [src] explodes violently!</span>", "<span class='danger'>You hear an explosion!</span>")
|
||||
|
||||
@@ -48,7 +48,7 @@ field_generator power level display
|
||||
// Scale % power to % num_power_levels and truncate value
|
||||
var/level = round(num_power_levels * power / field_generator_max_power)
|
||||
// Clamp between 0 and num_power_levels for out of range power values
|
||||
level = between(0, level, num_power_levels)
|
||||
level = clamp(level, 0, num_power_levels)
|
||||
if(level)
|
||||
add_overlay("+p[level]")
|
||||
|
||||
|
||||
@@ -126,7 +126,7 @@ GLOBAL_LIST_EMPTY(smeses)
|
||||
|
||||
/obj/machinery/power/smes/proc/input_power(var/percentage, var/obj/machinery/power/terminal/term)
|
||||
var/to_input = target_load * (percentage/100)
|
||||
to_input = between(0, to_input, target_load)
|
||||
to_input = clamp(to_input, 0, target_load)
|
||||
if(percentage == 100)
|
||||
inputting = 2
|
||||
else if(percentage)
|
||||
@@ -193,7 +193,7 @@ GLOBAL_LIST_EMPTY(smeses)
|
||||
return
|
||||
|
||||
var/total_restore = output_used * (percent_load / 100) // First calculate amount of power used from our output
|
||||
total_restore = between(0, total_restore, output_used) // Now clamp the value between 0 and actual output, just for clarity.
|
||||
total_restore = clamp(total_restore, 0, output_used) // Now clamp the value between 0 and actual output, just for clarity.
|
||||
total_restore = output_used - total_restore // And, at last, subtract used power from outputted power, to get amount of power we will give back to the SMES.
|
||||
|
||||
// now recharge this amount
|
||||
|
||||
@@ -154,7 +154,7 @@
|
||||
capacity += C.ChargeCapacity
|
||||
input_level_max += C.IOCapacity
|
||||
output_level_max += C.IOCapacity
|
||||
charge = between(0, charge, capacity)
|
||||
charge = clamp(charge, 0, capacity)
|
||||
return 1
|
||||
return 0
|
||||
|
||||
@@ -383,12 +383,12 @@
|
||||
// Parameters: 1 (new_input - New input value in Watts)
|
||||
// Description: Sets input setting on this SMES. Trims it if limits are exceeded.
|
||||
/obj/machinery/power/smes/buildable/proc/set_input(var/new_input = 0)
|
||||
input_level = between(0, new_input, input_level_max)
|
||||
input_level = clamp(new_input, 0, input_level_max)
|
||||
update_icon()
|
||||
|
||||
// Proc: set_output()
|
||||
// Parameters: 1 (new_output - New output value in Watts)
|
||||
// Description: Sets output setting on this SMES. Trims it if limits are exceeded.
|
||||
/obj/machinery/power/smes/buildable/proc/set_output(var/new_output = 0)
|
||||
output_level = between(0, new_output, output_level_max)
|
||||
update_icon()
|
||||
output_level = clamp(new_output, 0, output_level_max)
|
||||
update_icon()
|
||||
|
||||
@@ -218,8 +218,8 @@
|
||||
var/explosion_power = min_explosion_power
|
||||
if(power > 0)
|
||||
// 0-100% where 0% is at DETONATION_EXPLODE_MIN_POWER or lower and 100% is at DETONATION_EXPLODE_MAX_POWER or higher
|
||||
var/strength_percentage = between(0, (power - DETONATION_EXPLODE_MIN_POWER) / ((DETONATION_EXPLODE_MAX_POWER - DETONATION_EXPLODE_MIN_POWER) / 100), 100)
|
||||
explosion_power = between(min_explosion_power, (((max_explosion_power - min_explosion_power) * (strength_percentage / 100)) + min_explosion_power), max_explosion_power)
|
||||
var/strength_percentage = clamp((power - DETONATION_EXPLODE_MIN_POWER) / ((DETONATION_EXPLODE_MAX_POWER - DETONATION_EXPLODE_MIN_POWER) / 100), 0, 100)
|
||||
explosion_power = clamp((((max_explosion_power - min_explosion_power) * (strength_percentage / 100)) + min_explosion_power), min_explosion_power, max_explosion_power)
|
||||
|
||||
explosion(TS, explosion_power/2, explosion_power, max_explosion_power, explosion_power * 4, 1)
|
||||
qdel(src)
|
||||
@@ -377,7 +377,7 @@
|
||||
visible_message("[src]: Releasing additional [round((heat_capacity_new - heat_capacity)*removed.temperature)] W with exhaust gasses.")
|
||||
|
||||
removed.add_thermal_energy(thermal_power)
|
||||
removed.temperature = between(0, removed.temperature, 10000)
|
||||
removed.temperature = clamp(removed.temperature, 0, 10000)
|
||||
|
||||
env.merge(removed)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user