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

[MIRROR] fixes signal circuit not working | refactors name of timer cooldown macros to be inherent, also docs them #368

Merged
merged 1 commit into from
Nov 1, 2023
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
10 changes: 7 additions & 3 deletions code/__DEFINES/cooldowns.dm
Original file line number Diff line number Diff line change
Expand Up @@ -74,22 +74,26 @@

#define TIMER_COOLDOWN_START(cd_source, cd_index, cd_time) LAZYSET(cd_source.cooldowns, cd_index, addtimer(CALLBACK(GLOBAL_PROC, GLOBAL_PROC_REF(end_cooldown), cd_source, cd_index), cd_time))

#define TIMER_COOLDOWN_CHECK(cd_source, cd_index) LAZYACCESS(cd_source.cooldowns, cd_index)
/// Checks if a timer based cooldown is NOT finished.
#define TIMER_COOLDOWN_RUNNING(cd_source, cd_index) LAZYACCESS(cd_source.cooldowns, cd_index)

/// Checks if a timer based cooldown is finished.
#define TIMER_COOLDOWN_FINISHED(cd_source, cd_index) (!TIMER_COOLDOWN_RUNNING(cd_source, cd_index))

#define TIMER_COOLDOWN_END(cd_source, cd_index) LAZYREMOVE(cd_source.cooldowns, cd_index)

/*
* Stoppable timer cooldowns.
* Use indexes the same as the regular tiemr cooldowns.
* They make use of the TIMER_COOLDOWN_CHECK() and TIMER_COOLDOWN_END() macros the same, just not the TIMER_COOLDOWN_START() one.
* They make use of the TIMER_COOLDOWN_RUNNING() and TIMER_COOLDOWN_END() macros the same, just not the TIMER_COOLDOWN_START() one.
* A bit more expensive than the regular timers, but can be reset before they end and the time left can be checked.
*/

#define S_TIMER_COOLDOWN_START(cd_source, cd_index, cd_time) LAZYSET(cd_source.cooldowns, cd_index, addtimer(CALLBACK(GLOBAL_PROC, GLOBAL_PROC_REF(end_cooldown), cd_source, cd_index), cd_time, TIMER_STOPPABLE))

#define S_TIMER_COOLDOWN_RESET(cd_source, cd_index) reset_cooldown(cd_source, cd_index)

#define S_TIMER_COOLDOWN_TIMELEFT(cd_source, cd_index) (timeleft(TIMER_COOLDOWN_CHECK(cd_source, cd_index)))
#define S_TIMER_COOLDOWN_TIMELEFT(cd_source, cd_index) (timeleft(TIMER_COOLDOWN_RUNNING(cd_source, cd_index)))


/*
Expand Down
2 changes: 1 addition & 1 deletion code/datums/components/bumpattack.dm
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
var/obj/item/our_weapon = proxy_weapon || parent
if(!istype(our_weapon))
CRASH("[our_weapon] somehow failed istype")
if(!TIMER_COOLDOWN_CHECK(src, COOLDOWN_BUMP_ATTACK))
if(TIMER_COOLDOWN_FINISHED(src, COOLDOWN_BUMP_ATTACK))
TIMER_COOLDOWN_START(src, COOLDOWN_BUMP_ATTACK, attack_cooldown)
INVOKE_ASYNC(target, TYPE_PROC_REF(/atom, attackby), our_weapon, bumper)
bumper.visible_message(span_danger("[bumper] charges into [target], attacking with [our_weapon]!"), span_danger("You charge into [target], attacking with [our_weapon]!"), vision_distance = COMBAT_MESSAGE_RANGE)
Expand Down
2 changes: 1 addition & 1 deletion code/datums/emotes.dm
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
// SKYRAT EDIT END

var/tmp_sound = get_sound(user)
if(tmp_sound && should_play_sound(user, intentional) && !TIMER_COOLDOWN_CHECK(user, type))
if(tmp_sound && should_play_sound(user, intentional) && TIMER_COOLDOWN_FINISHED(user, type))
TIMER_COOLDOWN_START(user, type, audio_cooldown)
//SKYRAT EDIT CHANGE BEGIN
//playsound(user, tmp_sound, 50, vary) - SKYRAT EDIT - ORIGINAL
Expand Down
2 changes: 1 addition & 1 deletion code/game/objects/items/robot/robot_upgrades.dm
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@
cyborg.cell.use(5)
next_repair = world.time + repair_cooldown * 10 // Multiply by 10 since world.time is in deciseconds

if(!TIMER_COOLDOWN_CHECK(src, COOLDOWN_BORG_SELF_REPAIR))
if(TIMER_COOLDOWN_FINISHED(src, COOLDOWN_BORG_SELF_REPAIR))
TIMER_COOLDOWN_START(src, COOLDOWN_BORG_SELF_REPAIR, 200 SECONDS)
var/msgmode = "standby"
if(cyborg.health < 0)
Expand Down
4 changes: 2 additions & 2 deletions code/game/turfs/closed/minerals.dm
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
if (!isturf(T))
return

if(TIMER_COOLDOWN_CHECK(src, REF(user))) //prevents mining turfs in progress
if(TIMER_COOLDOWN_RUNNING(src, REF(user))) //prevents mining turfs in progress
return

TIMER_COOLDOWN_START(src, REF(user), tool_mine_speed)
Expand All @@ -121,7 +121,7 @@
var/turf/user_turf = user.loc
if (!isturf(user_turf))
return
if(TIMER_COOLDOWN_CHECK(src, REF(user))) //prevents mining turfs in progress
if(TIMER_COOLDOWN_RUNNING(src, REF(user))) //prevents mining turfs in progress
return
var/mining_speed = mining_arms ? tool_mine_speed : hand_mine_speed
TIMER_COOLDOWN_START(src, REF(user), mining_speed)
Expand Down
4 changes: 2 additions & 2 deletions code/modules/assembly/signaler.dm
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
switch(action)
if("signal")
if(cooldown_length > 0)
if(TIMER_COOLDOWN_CHECK(src, COOLDOWN_SIGNALLER_SEND))
if(TIMER_COOLDOWN_RUNNING(src, COOLDOWN_SIGNALLER_SEND))
balloon_alert(ui.user, "recharging!")
return
TIMER_COOLDOWN_START(src, COOLDOWN_SIGNALLER_SEND, cooldown_length)
Expand Down Expand Up @@ -135,7 +135,7 @@
return
if(!ishuman(user))
return
if(TIMER_COOLDOWN_CHECK(src, COOLDOWN_SIGNALLER_SEND))
if(TIMER_COOLDOWN_RUNNING(src, COOLDOWN_SIGNALLER_SEND))
balloon_alert(user, "still recharging...")
return
TIMER_COOLDOWN_START(src, COOLDOWN_SIGNALLER_SEND, 1 SECONDS)
Expand Down
2 changes: 1 addition & 1 deletion code/modules/cargo/expressconsole.dm
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@


if("add")//Generate Supply Order first
if(TIMER_COOLDOWN_CHECK(src, COOLDOWN_EXPRESSPOD_CONSOLE))
if(TIMER_COOLDOWN_RUNNING(src, COOLDOWN_EXPRESSPOD_CONSOLE))
say("Railgun recalibrating. Stand by.")
return
var/id = params["id"]
Expand Down
6 changes: 3 additions & 3 deletions code/modules/mob/living/emote.dm
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@
if(!isliving(user))
return

if(!TIMER_COOLDOWN_CHECK(user, COOLDOWN_YAWN_PROPAGATION))
if(TIMER_COOLDOWN_FINISHED(user, COOLDOWN_YAWN_PROPAGATION))
TIMER_COOLDOWN_START(user, COOLDOWN_YAWN_PROPAGATION, cooldown * 3)

var/mob/living/carbon/carbon_user = user
Expand All @@ -585,7 +585,7 @@
var/propagation_distance = user.client ? 5 : 2 // mindless mobs are less able to spread yawns

for(var/mob/living/iter_living in view(user, propagation_distance))
if(IS_DEAD_OR_INCAP(iter_living) || TIMER_COOLDOWN_CHECK(iter_living, COOLDOWN_YAWN_PROPAGATION))
if(IS_DEAD_OR_INCAP(iter_living) || TIMER_COOLDOWN_RUNNING(iter_living, COOLDOWN_YAWN_PROPAGATION))
continue

var/dist_between = get_dist(user, iter_living)
Expand All @@ -604,7 +604,7 @@

/// This yawn has been triggered by someone else yawning specifically, likely after a delay. Check again if they don't have the yawned recently trait
/datum/emote/living/yawn/proc/propagate_yawn(mob/user)
if(!istype(user) || TIMER_COOLDOWN_CHECK(user, COOLDOWN_YAWN_PROPAGATION))
if(!istype(user) || TIMER_COOLDOWN_RUNNING(user, COOLDOWN_YAWN_PROPAGATION))
return
user.emote("yawn")

Expand Down
2 changes: 1 addition & 1 deletion code/modules/vehicles/cars/clowncar.dm
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@
* * Fart and make everyone nearby laugh
*/
/obj/vehicle/sealed/car/clowncar/proc/roll_the_dice(mob/user)
if(TIMER_COOLDOWN_CHECK(src, COOLDOWN_CLOWNCAR_RANDOMNESS))
if(TIMER_COOLDOWN_RUNNING(src, COOLDOWN_CLOWNCAR_RANDOMNESS))
to_chat(user, span_notice("The button panel is currently recharging."))
return
TIMER_COOLDOWN_START(src, COOLDOWN_CLOWNCAR_RANDOMNESS, dice_cooldown_time)
Expand Down
4 changes: 2 additions & 2 deletions code/modules/vehicles/mecha/_mecha.dm
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@
if(!(livinguser in return_controllers_with_flag(VEHICLE_CONTROL_MELEE)))
to_chat(livinguser, span_warning("You're in the wrong seat to interact with your hands."))
return
var/on_cooldown = TIMER_COOLDOWN_CHECK(src, COOLDOWN_MECHA_MELEE_ATTACK)
var/on_cooldown = TIMER_COOLDOWN_RUNNING(src, COOLDOWN_MECHA_MELEE_ATTACK)
var/adjacent = Adjacent(target)
if(SEND_SIGNAL(src, COMSIG_MECHA_MELEE_CLICK, livinguser, target, on_cooldown, adjacent) & COMPONENT_CANCEL_MELEE_CLICK)
return
Expand Down Expand Up @@ -749,7 +749,7 @@
balloon_alert(user, "cabin can't be sealed!")
log_message("Tried to seal cabin. This mech can't be airtight.", LOG_MECHA)
return
if(TIMER_COOLDOWN_CHECK(src, COOLDOWN_MECHA_CABIN_SEAL))
if(TIMER_COOLDOWN_RUNNING(src, COOLDOWN_MECHA_CABIN_SEAL))
balloon_alert(user, "on cooldown!")
return
TIMER_COOLDOWN_START(src, COOLDOWN_MECHA_CABIN_SEAL, 1 SECONDS)
Expand Down
2 changes: 1 addition & 1 deletion code/modules/vehicles/mecha/combat/marauder.dm
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
/datum/action/vehicle/sealed/mecha/mech_smoke/Trigger(trigger_flags)
if(!owner || !chassis || !(owner in chassis.occupants))
return
if(!TIMER_COOLDOWN_CHECK(src, COOLDOWN_MECHA_SMOKE) && chassis.smoke_charges>0)
if(TIMER_COOLDOWN_FINISHED(src, COOLDOWN_MECHA_SMOKE) && chassis.smoke_charges>0)
chassis.smoke_system.start()
chassis.smoke_charges--
TIMER_COOLDOWN_START(src, COOLDOWN_MECHA_SMOKE, chassis.smoke_cooldown)
Expand Down
4 changes: 2 additions & 2 deletions code/modules/vehicles/mecha/combat/savannah_ivanov.dm
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
if(chassis.phasing)
to_chat(owner, span_warning("You're already airborne!"))
return
if(TIMER_COOLDOWN_CHECK(chassis, COOLDOWN_MECHA_SKYFALL))
if(TIMER_COOLDOWN_RUNNING(chassis, COOLDOWN_MECHA_SKYFALL))
var/timeleft = S_TIMER_COOLDOWN_TIMELEFT(chassis, COOLDOWN_MECHA_SKYFALL)
to_chat(owner, span_warning("You need to wait [DisplayTimeText(timeleft, 1)] before attempting to Skyfall."))
return
Expand Down Expand Up @@ -254,7 +254,7 @@
/datum/action/vehicle/sealed/mecha/ivanov_strike/Trigger(trigger_flags)
if(!owner || !chassis || !(owner in chassis.occupants))
return
if(TIMER_COOLDOWN_CHECK(chassis, COOLDOWN_MECHA_MISSILE_STRIKE))
if(TIMER_COOLDOWN_RUNNING(chassis, COOLDOWN_MECHA_MISSILE_STRIKE))
var/timeleft = S_TIMER_COOLDOWN_TIMELEFT(chassis, COOLDOWN_MECHA_MISSILE_STRIKE)
to_chat(owner, span_warning("You need to wait [DisplayTimeText(timeleft, 1)] before firing another Ivanov Strike."))
return
Expand Down
2 changes: 1 addition & 1 deletion code/modules/vehicles/mecha/equipment/mecha_equipment.dm
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
if(get_integrity() <= 1)
to_chat(chassis.occupants, span_warning("Error -- Equipment critically damaged."))
return FALSE
if(TIMER_COOLDOWN_CHECK(chassis, COOLDOWN_MECHA_EQUIPMENT(type)))
if(TIMER_COOLDOWN_RUNNING(chassis, COOLDOWN_MECHA_EQUIPMENT(type)))
return FALSE
return TRUE

Expand Down
10 changes: 5 additions & 5 deletions code/modules/vehicles/mecha/mecha_movement.dm
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@
return loc_atom.relaymove(src, direction)
var/obj/machinery/portable_atmospherics/canister/internal_tank = get_internal_tank()
if(internal_tank?.connected_port)
if(!TIMER_COOLDOWN_CHECK(src, COOLDOWN_MECHA_MESSAGE))
if(TIMER_COOLDOWN_FINISHED(src, COOLDOWN_MECHA_MESSAGE))
to_chat(occupants, "[icon2html(src, occupants)][span_warning("Unable to move while connected to the air system port!")]")
TIMER_COOLDOWN_START(src, COOLDOWN_MECHA_MESSAGE, 2 SECONDS)
return FALSE
if(!Process_Spacemove(direction))
return FALSE
if(zoom_mode)
if(!TIMER_COOLDOWN_CHECK(src, COOLDOWN_MECHA_MESSAGE))
if(TIMER_COOLDOWN_FINISHED(src, COOLDOWN_MECHA_MESSAGE))
to_chat(occupants, "[icon2html(src, occupants)][span_warning("Unable to move while in zoom mode!")]")
TIMER_COOLDOWN_START(src, COOLDOWN_MECHA_MESSAGE, 2 SECONDS)
return FALSE
Expand All @@ -89,17 +89,17 @@
if(isnull(servo))
missing_parts += "micro-servo"
if(length(missing_parts))
if(!TIMER_COOLDOWN_CHECK(src, COOLDOWN_MECHA_MESSAGE))
if(TIMER_COOLDOWN_FINISHED(src, COOLDOWN_MECHA_MESSAGE))
to_chat(occupants, "[icon2html(src, occupants)][span_warning("Missing [english_list(missing_parts)].")]")
TIMER_COOLDOWN_START(src, COOLDOWN_MECHA_MESSAGE, 2 SECONDS)
return FALSE
if(!use_power(step_energy_drain))
if(!TIMER_COOLDOWN_CHECK(src, COOLDOWN_MECHA_MESSAGE))
if(TIMER_COOLDOWN_FINISHED(src, COOLDOWN_MECHA_MESSAGE))
to_chat(occupants, "[icon2html(src, occupants)][span_warning("Insufficient power to move!")]")
TIMER_COOLDOWN_START(src, COOLDOWN_MECHA_MESSAGE, 2 SECONDS)
return FALSE
if(lavaland_only && is_mining_level(z))
if(!TIMER_COOLDOWN_CHECK(src, COOLDOWN_MECHA_MESSAGE))
if(TIMER_COOLDOWN_FINISHED(src, COOLDOWN_MECHA_MESSAGE))
to_chat(occupants, "[icon2html(src, occupants)][span_warning("Invalid Environment.")]")
TIMER_COOLDOWN_START(src, COOLDOWN_MECHA_MESSAGE, 2 SECONDS)
return FALSE
Expand Down
4 changes: 2 additions & 2 deletions code/modules/vehicles/vehicle_actions.dm
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@
var/hornsound = 'sound/items/carhorn.ogg'

/datum/action/vehicle/sealed/horn/Trigger(trigger_flags)
if(TIMER_COOLDOWN_CHECK(src, COOLDOWN_CAR_HONK))
if(TIMER_COOLDOWN_RUNNING(src, COOLDOWN_CAR_HONK))
return
TIMER_COOLDOWN_START(src, COOLDOWN_CAR_HONK, 2 SECONDS)
vehicle_entered_target.visible_message(span_danger("[vehicle_entered_target] loudly honks!"))
Expand Down Expand Up @@ -316,7 +316,7 @@
var/bell_cooldown

/datum/action/vehicle/ridden/wheelchair/bell/Trigger(trigger_flags)
if(TIMER_COOLDOWN_CHECK(src, bell_cooldown))
if(TIMER_COOLDOWN_RUNNING(src, bell_cooldown))
return
TIMER_COOLDOWN_START(src, bell_cooldown, 0.5 SECONDS)
playsound(vehicle_ridden_target, 'sound/machines/microwave/microwave-end.ogg', 70)
Expand Down
4 changes: 2 additions & 2 deletions code/modules/wiremod/components/action/pathfind.dm
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
return

// If we're going to the same place and the cooldown hasn't subsided, we're probably on the same path as before
if (destination == old_dest && TIMER_COOLDOWN_CHECK(parent, COOLDOWN_CIRCUIT_PATHFIND_SAME))
if (destination == old_dest && TIMER_COOLDOWN_RUNNING(parent, COOLDOWN_CIRCUIT_PATHFIND_SAME))

// Check if the current turf is the same as the current turf we're supposed to be in. If so, then we set the next step as the next turf on the list
if(current_turf == next_turf)
Expand All @@ -92,7 +92,7 @@

else // Either we're not going to the same place or the cooldown is over. Either way, we need a new path

if(destination != old_dest && TIMER_COOLDOWN_CHECK(parent, COOLDOWN_CIRCUIT_PATHFIND_DIF))
if(destination != old_dest && TIMER_COOLDOWN_RUNNING(parent, COOLDOWN_CIRCUIT_PATHFIND_DIF))
failed.set_output(COMPONENT_SIGNAL)
reason_failed.set_output("Cooldown still active!")
return
Expand Down
2 changes: 1 addition & 1 deletion code/modules/wiremod/components/action/radio.dm
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
INVOKE_ASYNC(src, PROC_REF(handle_radio_input), port)

/obj/item/circuit_component/radio/proc/handle_radio_input(datum/port/input/port)
if(!TIMER_COOLDOWN_CHECK(parent, COOLDOWN_SIGNALLER_SEND))
if(TIMER_COOLDOWN_RUNNING(parent, COOLDOWN_SIGNALLER_SEND))
return

var/frequency = freq.value
Expand Down
2 changes: 1 addition & 1 deletion code/modules/wiremod/components/action/soundemitter.dm
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
if(!parent.shell)
return

if(TIMER_COOLDOWN_CHECK(parent.shell, COOLDOWN_CIRCUIT_SOUNDEMITTER))
if(TIMER_COOLDOWN_RUNNING(parent.shell, COOLDOWN_CIRCUIT_SOUNDEMITTER))
return

var/sound_to_play = options_map[sound_file.value]
Expand Down
2 changes: 1 addition & 1 deletion code/modules/wiremod/components/action/speech.dm
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
if(!parent.shell)
return

if(TIMER_COOLDOWN_CHECK(parent.shell, COOLDOWN_CIRCUIT_SPEECH))
if(TIMER_COOLDOWN_RUNNING(parent.shell, COOLDOWN_CIRCUIT_SPEECH))
return

if(message.value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
if(!owner || !istype(owner) || !owner.client)
return

if(TIMER_COOLDOWN_CHECK(parent.shell, COOLDOWN_CIRCUIT_TARGET_INTERCEPT))
if(TIMER_COOLDOWN_RUNNING(parent.shell, COOLDOWN_CIRCUIT_TARGET_INTERCEPT))
return

to_chat(owner, "<B>Left-click to trigger target interceptor!</B>")
Expand Down
2 changes: 1 addition & 1 deletion code/modules/wiremod/components/sensors/view_sensor.dm
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
if(!parent.shell)
return

if(TIMER_COOLDOWN_CHECK(parent.shell, COOLDOWN_CIRCUIT_VIEW_SENSOR))
if(TIMER_COOLDOWN_RUNNING(parent.shell, COOLDOWN_CIRCUIT_VIEW_SENSOR))
result.set_output(null)
cooldown.set_output(COMPONENT_SIGNAL)
return
Expand Down
Loading