From 13a2630028c4a618190900e6e616102d1e5136d5 Mon Sep 17 00:00:00 2001 From: GDN <96800819+GDNgit@users.noreply.github.com> Date: Wed, 14 Feb 2024 13:45:37 -0600 Subject: [PATCH] Removes comparisons to true and false (#24083) * Removes comparisons to true and false * Update .github/CONTRIBUTING.md Co-authored-by: Luc <89928798+lewcc@users.noreply.github.com> --------- Co-authored-by: Luc <89928798+lewcc@users.noreply.github.com> --- .github/CONTRIBUTING.md | 24 ++++++++++++++++++- code/__HELPERS/unsorted.dm | 2 +- code/_onclick/hud/parallax.dm | 2 +- code/datums/station_traits/negative_traits.dm | 2 +- .../gamemodes/miniantags/guardian/guardian.dm | 2 +- code/game/gamemodes/nuclear/nuclearbomb.dm | 2 +- code/game/gamemodes/wizard/spellbook.dm | 2 +- .../objects/items/devices/traitordevices.dm | 2 +- code/game/objects/items/weapons/rpd.dm | 4 ++-- code/modules/admin/verbs/randomverbs.dm | 2 +- .../atmospherics/machinery/airalarm.dm | 4 ++-- code/modules/library/library_computer.dm | 2 +- code/modules/lighting/lighting_atom.dm | 2 +- code/modules/mining/equipment/survival_pod.dm | 2 +- code/modules/mob/dead/observer/spells.dm | 2 +- .../living/carbon/human/species/_species.dm | 8 +++---- .../silicon/robot/drone/drone_manufacturer.dm | 2 +- .../power/engines/supermatter/supermatter.dm | 2 +- code/modules/power/gravitygenerator.dm | 4 ++-- .../reagents/chemistry/reagents/medicine.dm | 4 ++-- .../reagent_containers/glass_containers.dm | 2 +- code/modules/recycling/disposal.dm | 4 ++-- .../surgery/organs/augments_internal.dm | 2 +- code/modules/surgery/organs/brain.dm | 4 ++-- 24 files changed, 55 insertions(+), 33 deletions(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 5d8358af58d..9cc3db12eeb 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -146,6 +146,28 @@ The previous code made compliant: code ``` +### Do not compare boolean values to TRUE or FALSE + +Do not compare boolean values to TRUE or FALSE. For TRUE you should just check if there's a value in that address. For FALSE you should use the ! operator. An exception is made to this when working with JS or other external languages. If a function/variable can contain more values beyond null/0 or TRUE, use numbers and defines instead of true/false comparisons. + +```dm +// Bad +var/thing = pick(list(TRUE, FALSE)) +if(thing == TRUE) + return "bleh" +var/other_thing = pick(list(TRUE, FALSE)) +if(other_thing == FALSE) + return "meh" + +// Good +var/thing = pick(list(TRUE, FALSE)) +if(thing) + return "bleh" +var/other_thing = pick(list(TRUE, FALSE)) +if(!other_thing) + return "meh" +``` + ### User Interfaces All new user interfaces in the game must be created using the TGUI framework. Documentation can be found inside the [`tgui/docs`](../tgui/docs) folder, and the [`README.md`](../tgui/README.md) file. This is to ensure all ingame UIs are snappy and respond well. An exception is made for user interfaces which are purely for OOC actions (Such as character creation, or anything admin related) @@ -354,7 +376,7 @@ This is clearer and enhances readability of your code! Get used to doing it! ### Player Output -Due to the use of "Goonchat", Paradise requires a special syntax for outputting text messages to players. Instead of `mob << "message"`, you must use `to_chat(mob, "message")`. Failure to do so will lead to your code not working. +Due to the use of "TGchat", Paradise requires a special syntax for outputting text messages to players. Instead of `mob << "message"`, you must use `to_chat(mob, "message")`. Failure to do so will lead to your code not working. ### Use early returns diff --git a/code/__HELPERS/unsorted.dm b/code/__HELPERS/unsorted.dm index c205f50fd88..fe812773023 100644 --- a/code/__HELPERS/unsorted.dm +++ b/code/__HELPERS/unsorted.dm @@ -1601,7 +1601,7 @@ GLOBAL_DATUM_INIT(dview_mob, /mob/dview, new) return closest_atom /proc/pick_closest_path(value, list/matches = get_fancy_list_of_atom_types()) - if(value == FALSE) //nothing should be calling us with a number, so this is safe + if(!value) //nothing should be calling us with a number, so this is safe value = input("Enter type to find (blank for all, cancel to cancel)", "Search for type") as null|text if(isnull(value)) return diff --git a/code/_onclick/hud/parallax.dm b/code/_onclick/hud/parallax.dm index 35c450a1e47..75b34cfa1d3 100644 --- a/code/_onclick/hud/parallax.dm +++ b/code/_onclick/hud/parallax.dm @@ -98,7 +98,7 @@ if(new_parallax_movedir == C.parallax_movedir) return var/animatedir = new_parallax_movedir - if(new_parallax_movedir == FALSE) + if(!new_parallax_movedir) var/animate_time = 0 for(var/thing in C.parallax_layers) var/obj/screen/parallax_layer/L = thing diff --git a/code/datums/station_traits/negative_traits.dm b/code/datums/station_traits/negative_traits.dm index 24a56cb3c97..f8fb95e185c 100644 --- a/code/datums/station_traits/negative_traits.dm +++ b/code/datums/station_traits/negative_traits.dm @@ -74,7 +74,7 @@ E.weight *= weight_multiplier for(var/role_weight in E.role_weights) E.role_weights[role_weight] *= weight_multiplier - if(disable_is_one_shot == TRUE) + if(disable_is_one_shot) E.one_shot = FALSE modified_event = TRUE if(!modified_event) diff --git a/code/game/gamemodes/miniantags/guardian/guardian.dm b/code/game/gamemodes/miniantags/guardian/guardian.dm index c0cbe14476b..f293b12f107 100644 --- a/code/game/gamemodes/miniantags/guardian/guardian.dm +++ b/code/game/gamemodes/miniantags/guardian/guardian.dm @@ -278,7 +278,7 @@ if(user.mind && (ischangeling(user) || user.mind.has_antag_datum(/datum/antagonist/vampire))) to_chat(user, "[ling_failure]") return - if(used == TRUE) + if(used) to_chat(user, "[used_message]") return used = TRUE // Set this BEFORE the popup to prevent people using the injector more than once, polling ghosts multiple times, and receiving multiple guardians. diff --git a/code/game/gamemodes/nuclear/nuclearbomb.dm b/code/game/gamemodes/nuclear/nuclearbomb.dm index 1d649cf290f..2d9914bcb52 100644 --- a/code/game/gamemodes/nuclear/nuclearbomb.dm +++ b/code/game/gamemodes/nuclear/nuclearbomb.dm @@ -277,7 +277,7 @@ GLOBAL_VAR(bomb_set) else if(!panel_open) to_chat(user, "[src] emits a buzzing noise, the panel staying locked in.") - if(panel_open == TRUE) + if(panel_open) panel_open = FALSE to_chat(user, "You screw the control panel of [src] back on.") core_stage = removal_stage diff --git a/code/game/gamemodes/wizard/spellbook.dm b/code/game/gamemodes/wizard/spellbook.dm index ca8b909eca3..33c43c884bf 100644 --- a/code/game/gamemodes/wizard/spellbook.dm +++ b/code/game/gamemodes/wizard/spellbook.dm @@ -397,7 +397,7 @@ var/item_path = null /datum/spellbook_entry/item/Buy(mob/living/carbon/human/user, obj/item/spellbook/book) - if(spawn_on_floor == FALSE) + if(!spawn_on_floor) user.put_in_hands(new item_path) else new item_path(user.loc) diff --git a/code/game/objects/items/devices/traitordevices.dm b/code/game/objects/items/devices/traitordevices.dm index 73c043bfdd1..3e4a7816cd8 100644 --- a/code/game/objects/items/devices/traitordevices.dm +++ b/code/game/objects/items/devices/traitordevices.dm @@ -145,7 +145,7 @@ new/obj/effect/temp_visual/teleport_abductor/syndi_teleporter(mobloc) playsound(destination, "sparks", 50, TRUE, SHORT_RANGE_SOUND_EXTRARANGE) new/obj/effect/temp_visual/teleport_abductor/syndi_teleporter(destination) - else if(EMP_D == FALSE && !(bagholding.len && !flawless)) // This is where the fun begins + else if(!EMP_D && !(bagholding.len && !flawless)) // This is where the fun begins var/direction = get_dir(user, destination) panic_teleport(user, destination, direction) else // Emp activated? Bag of holding? No saving throw for you diff --git a/code/game/objects/items/weapons/rpd.dm b/code/game/objects/items/weapons/rpd.dm index 223fbdd594c..a0a629f54e0 100644 --- a/code/game/objects/items/weapons/rpd.dm +++ b/code/game/objects/items/weapons/rpd.dm @@ -275,7 +275,7 @@ if(target != T) // We only check the rpd_act of the target if it isn't the turf, because otherwise // (A) blocked turfs can be acted on, and (B) unblocked turfs get acted on twice. - if(target.rpd_act(user, src) == TRUE) + if(target.rpd_act(user, src)) // If the object we are clicking on has a valid RPD interaction for just that specific object, do that and nothing else. // Example: clicking on a pipe with a RPD in rotate mode should rotate that pipe and ignore everything else on the tile. if(ranged) @@ -286,7 +286,7 @@ // This is done by calling rpd_blocksusage on every /obj in the tile. If any block usage, fail at this point. for(var/obj/O in T) - if(O.rpd_blocksusage() == TRUE) + if(O.rpd_blocksusage()) to_chat(user, "[O] blocks [src]!") return diff --git a/code/modules/admin/verbs/randomverbs.dm b/code/modules/admin/verbs/randomverbs.dm index 7943e30dc3d..807b676a996 100644 --- a/code/modules/admin/verbs/randomverbs.dm +++ b/code/modules/admin/verbs/randomverbs.dm @@ -869,7 +869,7 @@ Traitors and the like can also be revived with the previous role mostly intact. if(SSshuttle.emergency.mode >= SHUTTLE_DOCKED) return - if(SSshuttle.emergency.canRecall == FALSE) + if(!SSshuttle.emergency.canRecall) if(alert("Shuttle is currently set to be nonrecallable. Recalling may break things. Respect Recall Status?", "Override Recall Status?", "Yes", "No") == "Yes") return else diff --git a/code/modules/atmospherics/machinery/airalarm.dm b/code/modules/atmospherics/machinery/airalarm.dm index 1fcce455bce..330c78baab6 100644 --- a/code/modules/atmospherics/machinery/airalarm.dm +++ b/code/modules/atmospherics/machinery/airalarm.dm @@ -334,7 +334,7 @@ var/datum/gas_mixture/gas = location.remove_air(0.25 * environment.total_moles()) if(!gas) return - if(!regulating_temperature && thermostat_state == TRUE) + if(!regulating_temperature && thermostat_state) regulating_temperature = TRUE visible_message("\The [src] clicks as it starts [environment.temperature > target_temperature ? "cooling" : "heating"] the room.", "You hear a click and a faint electronic hum.") @@ -344,7 +344,7 @@ if(target_temperature < MIN_TEMPERATURE) target_temperature = MIN_TEMPERATURE - if(thermostat_state == TRUE) + if(thermostat_state) var/heat_capacity = gas.heat_capacity() var/energy_used = max(abs(heat_capacity * (gas.temperature - target_temperature) ), MAX_ENERGY_CHANGE) diff --git a/code/modules/library/library_computer.dm b/code/modules/library/library_computer.dm index fc858b8d43d..f6854b9fb67 100644 --- a/code/modules/library/library_computer.dm +++ b/code/modules/library/library_computer.dm @@ -474,7 +474,7 @@ return FALSE /obj/machinery/computer/library/proc/select_book(obj/item/book/B) - if(B.carved == TRUE) + if(B.carved) return user_data.selected_book.title = B.title ? B.title : "No Title" user_data.selected_book.author = B.author ? B.author : "No Author" diff --git a/code/modules/lighting/lighting_atom.dm b/code/modules/lighting/lighting_atom.dm index 731dfebc6f5..49541458f78 100644 --- a/code/modules/lighting/lighting_atom.dm +++ b/code/modules/lighting/lighting_atom.dm @@ -78,7 +78,7 @@ if(!isturf(T)) return - if(new_opacity == TRUE) + if(new_opacity) T.has_opaque_atom = TRUE T.reconsider_lights() else diff --git a/code/modules/mining/equipment/survival_pod.dm b/code/modules/mining/equipment/survival_pod.dm index a4b6dc25c57..25b563aa096 100644 --- a/code/modules/mining/equipment/survival_pod.dm +++ b/code/modules/mining/equipment/survival_pod.dm @@ -41,7 +41,7 @@ /obj/item/survivalcapsule/attack_self() // Can't grab when capsule is New() because templates aren't loaded then get_template() - if(used == FALSE) + if(!used) loc.visible_message("[src] begins to shake. Stand back!") used = TRUE sleep(50) diff --git a/code/modules/mob/dead/observer/spells.dm b/code/modules/mob/dead/observer/spells.dm index afcd7421196..46f0f4342d6 100644 --- a/code/modules/mob/dead/observer/spells.dm +++ b/code/modules/mob/dead/observer/spells.dm @@ -41,7 +41,7 @@ GLOBAL_LIST_INIT(boo_phrases, list( if(target.get_spooked()) var/area/spook_zone = get_area(target) - if(spook_zone.is_haunted == TRUE) + if(spook_zone.is_haunted) to_chat(usr, "The veil is weak in [spook_zone], it took less effort to influence [target].") cooldown_handler.start_recharge(cooldown_handler.recharge_duration / 2) return diff --git a/code/modules/mob/living/carbon/human/species/_species.dm b/code/modules/mob/living/carbon/human/species/_species.dm index d1448de82c5..0ab16ec9953 100644 --- a/code/modules/mob/living/carbon/human/species/_species.dm +++ b/code/modules/mob/living/carbon/human/species/_species.dm @@ -486,7 +486,7 @@ return /datum/species/proc/help(mob/living/carbon/human/user, mob/living/carbon/human/target, datum/martial_art/attacker_style) - if(attacker_style && attacker_style.help_act(user, target) == TRUE)//adminfu only... + if(attacker_style && attacker_style.help_act(user, target))//adminfu only... return TRUE if(target.on_fire) user.pat_out(target) @@ -500,7 +500,7 @@ if(target.check_block()) target.visible_message("[target] blocks [user]'s grab attempt!") return FALSE - if(attacker_style && attacker_style.grab_act(user, target) == TRUE) + if(attacker_style && attacker_style.grab_act(user, target)) return TRUE else target.grabbedby(user) @@ -532,7 +532,7 @@ return FALSE if(SEND_SIGNAL(target, COMSIG_HUMAN_ATTACKED, user) & COMPONENT_CANCEL_ATTACK_CHAIN) return FALSE - if(attacker_style && attacker_style.harm_act(user, target) == TRUE) + if(attacker_style && attacker_style.harm_act(user, target)) return TRUE else var/datum/unarmed_attack/attack = user.dna.species.unarmed @@ -587,7 +587,7 @@ user.do_attack_animation(target, ATTACK_EFFECT_DISARM) playsound(target.loc, 'sound/weapons/punchmiss.ogg', 25, 1, -1) return FALSE - if(attacker_style && attacker_style.disarm_act(user, target) == TRUE) + if(attacker_style && attacker_style.disarm_act(user, target)) return TRUE user.do_attack_animation(target, ATTACK_EFFECT_DISARM) if(target.move_resist > user.pull_force) diff --git a/code/modules/mob/living/silicon/robot/drone/drone_manufacturer.dm b/code/modules/mob/living/silicon/robot/drone/drone_manufacturer.dm index e4d87181b8b..5445512e2fb 100644 --- a/code/modules/mob/living/silicon/robot/drone/drone_manufacturer.dm +++ b/code/modules/mob/living/silicon/robot/drone/drone_manufacturer.dm @@ -134,7 +134,7 @@ if(!G.check_ahud_rejoin_eligibility()) to_chat(usr, "Upon using the antagHUD you forfeited the ability to join the round.") return - if(G.started_as_observer == TRUE) + if(G.started_as_observer) joinedasobserver = TRUE var/deathtimeminutes = round(deathtime / 600) diff --git a/code/modules/power/engines/supermatter/supermatter.dm b/code/modules/power/engines/supermatter/supermatter.dm index 69551d47d37..5eb1232d935 100644 --- a/code/modules/power/engines/supermatter/supermatter.dm +++ b/code/modules/power/engines/supermatter/supermatter.dm @@ -1212,7 +1212,7 @@ next_event_time = fake_time + world.time /obj/machinery/atmospherics/supermatter_crystal/proc/try_events() - if(has_been_powered == FALSE) + if(!has_been_powered) return if(!next_event_time) // for when the SM starts make_next_event_time() diff --git a/code/modules/power/gravitygenerator.dm b/code/modules/power/gravitygenerator.dm index edddf5bb244..9ca42781ddc 100644 --- a/code/modules/power/gravitygenerator.dm +++ b/code/modules/power/gravitygenerator.dm @@ -288,7 +288,7 @@ GLOBAL_LIST_EMPTY(gravity_generators) change_power_mode(on ? ACTIVE_POWER_USE : IDLE_POWER_USE) if(gravity) // If we turned on - if(generators_in_level() == FALSE) // And there's no gravity + if(generators_in_level() == 0) // And there's no other gravity generators on this z level alert = TRUE investigate_log("was brought online and is now producing gravity for this level.", "gravity") message_admins("The gravity generator was brought online. ([src_area.name])") @@ -297,7 +297,7 @@ GLOBAL_LIST_EMPTY(gravity_generators) continue A.gravitychange(TRUE, A) - else if(generators_in_level() == TRUE) // Turned off, and there is gravity + else if(generators_in_level() == 1) // Turned off, and there is only one gravity generator on the Z level alert = TRUE investigate_log("was brought offline and there is now no gravity for this level.", "gravity") message_admins("The gravity generator was brought offline with no backup generator. ([src_area.name])") diff --git a/code/modules/reagents/chemistry/reagents/medicine.dm b/code/modules/reagents/chemistry/reagents/medicine.dm index d67a524c7c8..3cd551e24f9 100644 --- a/code/modules/reagents/chemistry/reagents/medicine.dm +++ b/code/modules/reagents/chemistry/reagents/medicine.dm @@ -1485,7 +1485,7 @@ M.reagents.remove_reagent(R.id, 0.5) //We will be generous (for nukies really) and purge out the chemicals during this phase, so they don't fucking die during the next phase. Of course, if they try to use adrenals in the next phase, well... if(20 to 43) //If they have stimulants or stimulant drugs then just apply toxin damage instead. - if(has_stimulant == TRUE) + if(has_stimulant) update_flags |= M.adjustToxLoss(10, FALSE) else //apply debilitating effects if(prob(75)) @@ -1496,7 +1496,7 @@ to_chat(M, "Your body goes rigid, you cannot move at all!") M.AdjustWeakened(15 SECONDS) if(45 to INFINITY) // Start fixing bones | If they have stimulants or stimulant drugs in their system then the nanites won't work. - if(has_stimulant == TRUE) + if(has_stimulant) return ..() else for(var/obj/item/organ/external/E in M.bodyparts) diff --git a/code/modules/reagents/reagent_containers/glass_containers.dm b/code/modules/reagents/reagent_containers/glass_containers.dm index 7e4f4662694..44cc8cae37d 100644 --- a/code/modules/reagents/reagent_containers/glass_containers.dm +++ b/code/modules/reagents/reagent_containers/glass_containers.dm @@ -165,7 +165,7 @@ if(!is_open_container()) . += "lid_[initial(icon_state)]" - if(blocks_emissive == FALSE) + if(!blocks_emissive) . += emissive_blocker(icon, "lid_[initial(icon_state)]") if(assembly) . += "assembly" diff --git a/code/modules/recycling/disposal.dm b/code/modules/recycling/disposal.dm index 0fc5b50e67b..b455b844486 100644 --- a/code/modules/recycling/disposal.dm +++ b/code/modules/recycling/disposal.dm @@ -1446,9 +1446,9 @@ /obj/structure/disposaloutlet/screwdriver_act(mob/living/user, obj/item/I) add_fingerprint(user) - if(mode == FALSE) + if(!mode) to_chat(user, "You remove the screws around the power connection.") - else if(mode == TRUE) + else if(mode) to_chat(user, "You attach the screws around the power connection.") I.play_tool_sound(src) mode = !mode diff --git a/code/modules/surgery/organs/augments_internal.dm b/code/modules/surgery/organs/augments_internal.dm index a9b16a009d9..54a1b020316 100644 --- a/code/modules/surgery/organs/augments_internal.dm +++ b/code/modules/surgery/organs/augments_internal.dm @@ -189,7 +189,7 @@ ..() if(crit_fail) return - if(owner.stat == UNCONSCIOUS && cooldown == FALSE) + if(owner.stat == UNCONSCIOUS && !cooldown) owner.AdjustSleeping(-200 SECONDS) owner.AdjustParalysis(-200 SECONDS) to_chat(owner, "You feel a rush of energy course through your body!") diff --git a/code/modules/surgery/organs/brain.dm b/code/modules/surgery/organs/brain.dm index 28b8c04dccd..f756a29f392 100644 --- a/code/modules/surgery/organs/brain.dm +++ b/code/modules/surgery/organs/brain.dm @@ -59,7 +59,7 @@ for(var/mob/dead/observer/G in GLOB.player_list) if(G.mind == brainmob.mind) foundghost = TRUE - if(G.can_reenter_corpse == FALSE) + if(!G.can_reenter_corpse) foundghost = FALSE break if(foundghost) @@ -129,7 +129,7 @@ owner.setBrainLoss(120) /obj/item/organ/internal/brain/on_life() - if(decoy_brain || damage < 10) + if(decoy_brain || damage < 10) return switch(damage) if(10 to 30)