Skip to content

Commit

Permalink
replace legacy proc/between with clamp builtin
Browse files Browse the repository at this point in the history
  • Loading branch information
Spookerton committed Jan 31, 2024
1 parent e3393dc commit ea82655
Show file tree
Hide file tree
Showing 67 changed files with 125 additions and 135 deletions.
6 changes: 3 additions & 3 deletions code/ATMOSPHERICS/components/binary_devices/dp_vent_pump.dm
Original file line number Diff line number Diff line change
Expand Up @@ -232,21 +232,21 @@
pump_direction = 1

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

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

if(signal.data["set_external_pressure"])
external_pressure_bound = between(
external_pressure_bound = clamp(
0,
text2num(signal.data["set_external_pressure"]),
ONE_ATMOSPHERE*50
Expand Down
6 changes: 3 additions & 3 deletions code/ATMOSPHERICS/components/binary_devices/passive_gate.dm
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@
unlocked = !unlocked

if("set_target_pressure" in signal.data)
target_pressure = between(
target_pressure = clamp(
0,
text2num(signal.data["set_target_pressure"]),
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(0, new_pressure, 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(0, new_flow_rate, air1.volume)

update_icon()
add_fingerprint(usr)
Expand Down
4 changes: 2 additions & 2 deletions code/ATMOSPHERICS/components/binary_devices/pump.dm
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ 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(
target_pressure = clamp(
0,
text2num(signal.data["set_output_pressure"]),
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(0, new_pressure, 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(0, new_flow_rate, 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(0, new_con, 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(0, text2num(params["value"]), 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(0, number, air_contents.volume)

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

if(signal.data["adjust_internal_pressure"] != null)
internal_pressure_bound = between(
internal_pressure_bound = clamp(
0,
internal_pressure_bound + text2num(signal.data["adjust_internal_pressure"]),
ONE_ATMOSPHERE*50
Expand All @@ -349,7 +349,7 @@
if(signal.data["adjust_external_pressure"] != null)


external_pressure_bound = between(
external_pressure_bound = clamp(
0,
external_pressure_bound + text2num(signal.data["adjust_external_pressure"]),
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(1, X, world.maxx), clamp(1, Y, 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(0, danger + amount, 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(-20, staleness + amount, 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(0, dist_travelled/total_distance, 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(0, (temp_apc.cell.maxcharge/2) + 500, 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(0, round(instability + amount, TECHNOMANCER_INSTABILITY_PRECISION), 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(0, round(instability, TECHNOMANCER_INSTABILITY_PRECISION), 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(0, calculate_spell_power(100) - 100, 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(0, calculate_spell_power(100) - 100, 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(0, removed.temperature, 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(0, new_pressure, 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(0, new_flow, 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(0, new_pressure, 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(0, new_flow, 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(0.2, clone_sickness_length, 1.0) // 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, health + repairing*DOOR_REPAIR_AMOUNT, maxhealth)
update_icon()
repairing = 0
return
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(H.getBrainLoss(), damage_calc, 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(0, round( power_source.percent() , 25), 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

6 changes: 3 additions & 3 deletions code/game/objects/items/weapons/material/material_armor.dm
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ Protectiveness | Armor %

// Makes sure the numbers stay capped.
for(var/number in list(melee_armor, bullet_armor, laser_armor, energy_armor, bomb_armor))
number = between(0, number, 100)
number = clamp(0, number, 100)

armor["melee"] = melee_armor
armor["bullet"] = bullet_armor
Expand All @@ -191,9 +191,9 @@ Protectiveness | Armor %
armor["bomb"] = bomb_armor

if(!isnull(material.conductivity))
siemens_coefficient = between(0, material.conductivity / 10, 10)
siemens_coefficient = clamp(0, material.conductivity / 10, 10)

var/slowdownModified = between(0, round(material.weight / 10, 0.1), 6)
var/slowdownModified = clamp(0, round(material.weight / 10, 0.1), 6)

var/slowdownUncapped = (material_slowdown_multiplier * slowdownModified) - material_slowdown_modifier

Expand Down
2 changes: 1 addition & 1 deletion code/game/objects/items/weapons/tools/weldingtool.dm
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@
if(!istype(user))
return 1
var/safety = user.eyecheck()
safety = between(-1, safety + eye_safety_modifier, 2)
safety = clamp(-1, safety + eye_safety_modifier, 2)
if(istype(user, /mob/living/carbon/human))
var/mob/living/carbon/human/H = user
var/obj/item/organ/internal/eyes/E = H.internal_organs_by_name[O_EYES]
Expand Down
Loading

0 comments on commit ea82655

Please sign in to comment.