Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace legacy proc/between with clamp builtin #9303

Merged
merged 1 commit into from
Nov 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions code/ATMOSPHERICS/components/binary_devices/dp_vent_pump.dm
Original file line number Diff line number Diff line change
Expand Up @@ -232,23 +232,23 @@
pump_direction = 1

if(signal.data["set_input_pressure"])
input_pressure_min = between(
0,
input_pressure_min = clamp(
text2num(signal.data["set_input_pressure"]),
0,
ONE_ATMOSPHERE*50
)

if(signal.data["set_output_pressure"])
output_pressure_max = between(
0,
output_pressure_max = clamp(
text2num(signal.data["set_output_pressure"]),
0,
ONE_ATMOSPHERE*50
)

if(signal.data["set_external_pressure"])
external_pressure_bound = between(
0,
external_pressure_bound = clamp(
text2num(signal.data["set_external_pressure"]),
0,
ONE_ATMOSPHERE*50
)

Expand Down
8 changes: 4 additions & 4 deletions code/ATMOSPHERICS/components/binary_devices/passive_gate.dm
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,9 @@
unlocked = !unlocked

if("set_target_pressure" in signal.data)
target_pressure = between(
0,
target_pressure = clamp(
text2num(signal.data["set_target_pressure"]),
0,
max_pressure_setting
)

Expand Down Expand Up @@ -262,7 +262,7 @@
target_pressure = max_pressure_setting
if("set")
var/new_pressure = input(usr,"Enter new output pressure (0-[max_pressure_setting]kPa)","Pressure Control",src.target_pressure) as num
src.target_pressure = between(0, new_pressure, max_pressure_setting)
src.target_pressure = clamp(new_pressure, 0, max_pressure_setting)

if("set_flow_rate")
. = TRUE
Expand All @@ -273,7 +273,7 @@
set_flow_rate = air1.volume
if("set")
var/new_flow_rate = input(usr,"Enter new flow rate limit (0-[air1.volume]L/s)","Flow Rate Control",src.set_flow_rate) as num
src.set_flow_rate = between(0, new_flow_rate, air1.volume)
src.set_flow_rate = clamp(new_flow_rate, 0, air1.volume)

update_icon()
add_fingerprint(usr)
Expand Down
6 changes: 3 additions & 3 deletions code/ATMOSPHERICS/components/binary_devices/pump.dm
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,9 @@ Thus, the two variables affect pump operation are set in New():
update_use_power(!use_power)

if(signal.data["set_output_pressure"])
target_pressure = between(
0,
target_pressure = clamp(
text2num(signal.data["set_output_pressure"]),
0,
ONE_ATMOSPHERE*50
)

Expand Down Expand Up @@ -227,7 +227,7 @@ Thus, the two variables affect pump operation are set in New():
target_pressure = max_pressure_setting
if("set")
var/new_pressure = input(usr,"Enter new output pressure (0-[max_pressure_setting]kPa)","Pressure control",src.target_pressure) as num
src.target_pressure = between(0, new_pressure, max_pressure_setting)
src.target_pressure = clamp(new_pressure, 0, max_pressure_setting)
. = TRUE

add_fingerprint(usr)
Expand Down
6 changes: 3 additions & 3 deletions code/ATMOSPHERICS/components/omni_devices/mixer.dm
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@
if(!configuring || use_power)
return
var/new_flow_rate = input(usr,"Enter new flow rate limit (0-[max_flow_rate]L/s)","Flow Rate Control",set_flow_rate) as num
set_flow_rate = between(0, new_flow_rate, max_flow_rate)
set_flow_rate = clamp(new_flow_rate, 0, max_flow_rate)
if("switch_mode")
. = TRUE
if(!configuring || use_power)
Expand Down Expand Up @@ -268,7 +268,7 @@
var/new_con = (input(usr,"Enter a new concentration (0-[round(remain_con * 100, 0.5)])%","Concentration control", min(remain_con, old_con)*100) as num) / 100

//cap it between 0 and the max remaining concentration
new_con = between(0, new_con, remain_con)
new_con = clamp(new_con, 0, remain_con)

//new_con = min(remain_con, new_con)

Expand All @@ -294,4 +294,4 @@
/obj/machinery/atmospherics/omni/mixer/proc/con_lock(var/port = NORTH)
for(var/datum/omni_port/P in inputs)
if(P.dir == port)
P.con_lock = !P.con_lock
P.con_lock = !P.con_lock
2 changes: 1 addition & 1 deletion code/ATMOSPHERICS/components/unary/heat_source.dm
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
else
set_temperature = max(amount, 0)
if("setPower") //setting power to 0 is redundant anyways
var/new_setting = between(0, text2num(params["value"]), 100)
var/new_setting = clamp(text2num(params["value"]), 0, 100)
set_power_level(new_setting)

add_fingerprint(usr)
Expand Down
2 changes: 1 addition & 1 deletion code/ATMOSPHERICS/components/unary/outlet_injector.dm
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@

if(signal.data["set_volume_rate"])
var/number = text2num(signal.data["set_volume_rate"])
volume_rate = between(0, number, air_contents.volume)
volume_rate = clamp(number, 0, air_contents.volume)

if(signal.data["status"])
spawn(2)
Expand Down
16 changes: 8 additions & 8 deletions code/ATMOSPHERICS/components/unary/vent_pump.dm
Original file line number Diff line number Diff line change
Expand Up @@ -323,35 +323,35 @@
if (signal.data["set_internal_pressure"] == "default")
internal_pressure_bound = internal_pressure_bound_default
else
internal_pressure_bound = between(
0,
internal_pressure_bound = clamp(
text2num(signal.data["set_internal_pressure"]),
0,
ONE_ATMOSPHERE*50
)

if(signal.data["set_external_pressure"] != null)
if (signal.data["set_external_pressure"] == "default")
external_pressure_bound = external_pressure_bound_default
else
external_pressure_bound = between(
0,
external_pressure_bound = clamp(
text2num(signal.data["set_external_pressure"]),
0,
ONE_ATMOSPHERE*50
)

if(signal.data["adjust_internal_pressure"] != null)
internal_pressure_bound = between(
0,
internal_pressure_bound = clamp(
internal_pressure_bound + text2num(signal.data["adjust_internal_pressure"]),
0,
ONE_ATMOSPHERE*50
)

if(signal.data["adjust_external_pressure"] != null)


external_pressure_bound = between(
0,
external_pressure_bound = clamp(
external_pressure_bound + text2num(signal.data["adjust_external_pressure"]),
0,
ONE_ATMOSPHERE*50
)

Expand Down
6 changes: 1 addition & 5 deletions code/_helpers/unsorted.dm
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ Turf and target are separate in case you want to teleport some distance from a t
line+=locate(px,py,M.z)
return line

#define LOCATE_COORDS(X, Y, Z) locate(between(1, X, world.maxx), between(1, Y, world.maxy), Z)
#define LOCATE_COORDS(X, Y, Z) locate(clamp(X, 1, world.maxx), clamp(Y, 1, world.maxy), Z)
/proc/getcircle(turf/center, var/radius) //Uses a fast Bresenham rasterization algorithm to return the turfs in a thin circle.
if(!radius) return list(center)

Expand Down Expand Up @@ -566,10 +566,6 @@ Turf and target are separate in case you want to teleport some distance from a t
var/y = min(world.maxy, max(1, A.y + dy))
return locate(x,y,A.z)

//Makes sure MIDDLE is between LOW and HIGH. If not, it adjusts it. Returns the adjusted value.
/proc/between(var/low, var/middle, var/high)
return max(min(middle, high), low)

//returns random gauss number
/proc/GaussRand(var/sigma)
var/x,y,rsq
Expand Down
6 changes: 3 additions & 3 deletions code/controllers/subsystems/game_master.dm
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ SUBSYSTEM_DEF(game_master)
// Tell the game master that something dangerous happened, e.g. someone dying, station explosions.
/datum/controller/subsystem/game_master/proc/adjust_danger(amount)
amount *= GM.danger_modifier
danger = round(between(0, danger + amount, 1000), 0.1)
danger = round(clamp(danger + amount, 0, 1000), 0.1)

// Tell the game master that things are getting boring if positive, or something interesting if negative..
/datum/controller/subsystem/game_master/proc/adjust_staleness(amount)
amount *= GM.staleness_modifier
staleness = round( between(-20, staleness + amount, 100), 0.1)
staleness = round( clamp(staleness + amount, -20, 100), 0.1)

// These are ran before committing to an event.
// Returns TRUE if the system is allowed to proceed, otherwise returns FALSE.
Expand Down Expand Up @@ -364,4 +364,4 @@ SUBSYSTEM_DEF(game_master)
danger = amount
message_admins("GM danger was set to [amount] by [usr.key].")

interact(usr) // To refresh the UI.
interact(usr) // To refresh the UI.
2 changes: 1 addition & 1 deletion code/game/atoms_movable.dm
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@
a = get_area(src.loc)
// and yet it moves

var/arc_progress = between(0, dist_travelled/total_distance, 1)
var/arc_progress = clamp(dist_travelled / total_distance, 0, 1)
var/sine_position = arc_progress * 180
var/pixel_z_position = arc * sin(sine_position)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@
if(temp_apc)
temp_apc.emp_act(3) // Such power surges are not good for APC electronics
if(temp_apc.cell)
temp_apc.cell.maxcharge -= between(0, (temp_apc.cell.maxcharge/2) + 500, temp_apc.cell.maxcharge)
temp_apc.cell.maxcharge -= clamp(temp_apc.cell.maxcharge / 2 + 500, 0, temp_apc.cell.maxcharge)
if(temp_apc.cell.maxcharge < 100) // That's it, you busted the APC cell completely. Break the APC and completely destroy the cell.
qdel(temp_apc.cell)
temp_apc.set_broken()
Expand Down
5 changes: 2 additions & 3 deletions code/game/gamemodes/technomancer/instability.dm
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
// Parameters: 0
// Description: Does nothing, because inheritance.
/mob/living/proc/adjust_instability(var/amount)
instability = between(0, round(instability + amount, TECHNOMANCER_INSTABILITY_PRECISION), 200)
instability = clamp(round(instability + amount, TECHNOMANCER_INSTABILITY_PRECISION), 0, 200)

// Proc: adjust_instability()
// Parameters: 1 (amount - how much instability to give)
Expand Down Expand Up @@ -56,7 +56,7 @@
// Description: Makes instability decay. instability_effects() handles the bad effects for having instability. It will also hold back
// from causing bad effects more than one every ten seconds, to prevent sudden death from angry RNG.
/mob/living/proc/handle_instability()
instability = between(0, round(instability, TECHNOMANCER_INSTABILITY_PRECISION), 200)
instability = clamp(round(instability, TECHNOMANCER_INSTABILITY_PRECISION), 0, 200)
last_instability = instability

//This should cushion against really bad luck.
Expand Down Expand Up @@ -287,4 +287,3 @@
else
to_chat(src, "<span class='cult'><font size='4'>The purple glow makes you feel strange...</font></span>")
adjust_instability(amount)

6 changes: 3 additions & 3 deletions code/game/gamemodes/technomancer/spells/gambit.dm
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
// Gives a random spell.
/obj/item/spell/gambit/proc/random_spell()
var/list/potential_spells = all_technomancer_gambit_spells.Copy()
var/rare_spell_chance = between(0, calculate_spell_power(100) - 100, 100) // Having 120% spellpower means a 20% chance to get to roll for rare spells.
var/rare_spell_chance = clamp(calculate_spell_power(100) - 100, 0, 100) // Having 120% spellpower means a 20% chance to get to roll for rare spells.
if(prob(rare_spell_chance))
potential_spells += rare_spells.Copy()
to_chat(owner, "<span class='notice'>You feel a bit luckier...</span>")
Expand All @@ -55,7 +55,7 @@
// Gives a "random" spell.
/obj/item/spell/gambit/proc/biased_random_spell()
var/list/potential_spells = list()
var/rare_spell_chance = between(0, calculate_spell_power(100) - 100, 100)
var/rare_spell_chance = clamp(calculate_spell_power(100) - 100, 0, 100)
var/give_rare_spells = FALSE
if(prob(rare_spell_chance))
give_rare_spells = TRUE
Expand Down Expand Up @@ -131,4 +131,4 @@
if(!potential_spells.len)
potential_spells = all_technomancer_gambit_spells.Copy()

return pick(potential_spells)
return pick(potential_spells)
2 changes: 1 addition & 1 deletion code/game/gamemodes/technomancer/spells/radiance.dm
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
var/thermal_power = 300 * adjusted_power

removed.add_thermal_energy(thermal_power)
removed.temperature = between(0, removed.temperature, 10000)
removed.temperature = clamp(removed.temperature, 0, 10000)

env.merge(removed)

Expand Down
12 changes: 6 additions & 6 deletions code/game/machinery/atmo_control.dm
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,12 @@
switch(action)
if("adj_pressure")
var/new_pressure = text2num(params["adj_pressure"])
pressure_setting = between(0, new_pressure, 50*ONE_ATMOSPHERE)
pressure_setting = clamp(new_pressure, 0, 50 * ONE_ATMOSPHERE)
return TRUE

if("adj_input_flow_rate")
var/new_flow = text2num(params["adj_input_flow_rate"])
input_flow_setting = between(0, new_flow, ATMOS_DEFAULT_VOLUME_PUMP + 500) //default flow rate limit for air injectors
input_flow_setting = clamp(new_flow, 0, ATMOS_DEFAULT_VOLUME_PUMP + 500) //default flow rate limit for air injectors
return TRUE

if(!radio_connection)
Expand Down Expand Up @@ -288,12 +288,12 @@
switch(action)
if("adj_pressure")
var/new_pressure = text2num(params["adj_pressure"])
pressure_setting = between(0, new_pressure, 10*ONE_ATMOSPHERE)
pressure_setting = clamp(new_pressure, 0, 10 * ONE_ATMOSPHERE)
return TRUE

if("adj_input_flow_rate")
var/new_flow = text2num(params["adj_input_flow_rate"])
input_flow_setting = between(0, new_flow, ATMOS_DEFAULT_VOLUME_PUMP + 500) //default flow rate limit for air injectors
input_flow_setting = clamp(new_flow, 0, ATMOS_DEFAULT_VOLUME_PUMP + 500) //default flow rate limit for air injectors
return TRUE

if(!radio_connection)
Expand Down Expand Up @@ -399,7 +399,7 @@
/obj/machinery/computer/general_air_control/fuel_injection/tgui_act(action, params)
if(..())
return TRUE

switch(action)
if("refresh_status")
device_info = null
Expand Down Expand Up @@ -452,4 +452,4 @@
)

radio_connection.post_signal(src, signal, radio_filter = RADIO_ATMOSIA)
. = TRUE
. = TRUE
2 changes: 1 addition & 1 deletion code/game/machinery/cloning.dm
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@

// Upgraded cloners can reduce the time of the modifier, up to 80%
var/clone_sickness_length = abs(((heal_level - 20) / 100 ) - 1)
clone_sickness_length = between(0.2, clone_sickness_length, 1.0) // Caps it off just incase.
clone_sickness_length = clamp(clone_sickness_length, 0.2, 1) // Caps it off just incase.
modifier_lower_bound = round(modifier_lower_bound * clone_sickness_length, 1)
modifier_upper_bound = round(modifier_upper_bound * clone_sickness_length, 1)

Expand Down
2 changes: 1 addition & 1 deletion code/game/machinery/doors/door.dm
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@
playsound(src, welder.usesound, 50, 1)
if(do_after(user, (5 * repairing) * welder.toolspeed) && welder && welder.isOn())
to_chat(user, "<span class='notice'>You finish repairing the damage to \the [src].</span>")
health = between(health, health + repairing*DOOR_REPAIR_AMOUNT, maxhealth)
health = clamp(health + repairing * DOOR_REPAIR_AMOUNT, health, maxhealth)
update_icon()
repairing = 0
return
Expand Down
4 changes: 2 additions & 2 deletions code/game/machinery/telecomms/telecomms.dm
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
var/obj/item/stack/nanopaste/T = P
if (integrity < 100)
if (T.use(1))
integrity = between(0, integrity + rand(10, 20), 100)
integrity = clamp(integrity + rand(10, 20), 0, 100)
to_chat(usr, "You apply the Nanopaste to [src], repairing some of the damage.")
else
to_chat(usr, "This machine is already in perfect condition.")
Expand Down Expand Up @@ -272,7 +272,7 @@
if ((T0C + 200) to INFINITY)
damage_chance = 100
if (damage_chance && prob(damage_chance))
integrity = between(0, integrity - 1, 100)
integrity = clamp(integrity - 1, 0, 100)
if (delay > 0)
delay--
else if (on)
Expand Down
2 changes: 1 addition & 1 deletion code/game/objects/items/devices/defib.dm
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@
var/damage_calc = LERP(brain.max_damage, H.getBrainLoss(), brain_death_scale)

// A bit of sanity.
var/brain_damage = between(H.getBrainLoss(), damage_calc, brain.max_damage)
var/brain_damage = clamp(damage_calc, H.getBrainLoss(), brain.max_damage)

H.setBrainLoss(brain_damage)

Expand Down
3 changes: 1 addition & 2 deletions code/game/objects/items/devices/radio/jammer.dm
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ var/global/list/active_radio_jammers = list()

var/overlay_percent = 0
if(power_source)
overlay_percent = between(0, round( power_source.percent() , 25), 100)
overlay_percent = clamp(round(power_source.percent(), 25), 0, 100)
else
overlay_percent = 0

Expand All @@ -115,4 +115,3 @@ var/global/list/active_radio_jammers = list()
cut_overlays()
add_overlay("jammer_overlay_[overlay_percent]")
last_overlay_percent = overlay_percent

Loading
Loading