mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-01-16 12:07:48 +00:00
## About The Pull Request When it comes to deconstructing an object we have `proc/deconstruct()` & `NO_DECONSTRUCT` Lets talk about the flag first. **Problems with `NO_DECONSTRUCTION`** I know what the comment says on what it should dob5593bc693/code/__DEFINES/obj_flags.dm (L18)But everywhere people have decided to give their own meaning/definition to this flag. Here are some examples on how this flag is used **1. Make the object just disappear(not drop anything) when deconstructed** This is by far the largest use case everywhere. If an object is deconstructed(either via tools or smashed apart) then if it has this flag it should not drop any of its contents but just disappear. You have seen this code pattern used everywhereb5593bc693/code/game/machinery/constructable_frame.dm (L26-L31)This behaviour is then leveraged by 2 important components. When an object is frozen, if it is deconstructed it should just disappear without leaving any traces behindb5593bc693/code/datums/elements/frozen.dm (L66-L67)By hologram objects. Obviously if you destroy an hologram nothing real should drop outb5593bc693/code/modules/holodeck/computer.dm (L301-L304)And there are other use cases as well but we won't go into them as they aren't as significant as these. **2. To stop an object from being wrenched ??** Yeah this one is weird. Like why? I understand in some instances (chair, table, rack etc) a wrench can be used to deconstruct a object so using the flag there to stop it from happening makes sense but why can't we even anchor an object just because of this flag?b5593bc693/code/game/objects/objs.dm (L368-L369)This is one of those instances where somebody just decided this behaviour for their own convenience just like the above example with no explanation as to why **3. To stop using tools to deconstruct the object** This was the original intent of the flag but it is enforced in few places far & between. One example is when deconstructing the a machine via crowbar.b5593bc693/code/game/machinery/_machinery.dm (L811)But machines are a special dual use case for this flag. Because if you look at its deconstruct proc the flag also prevents the machine from spawning a frame.b5593bc693/code/game/machinery/_machinery.dm (L820-L822)How can 1 flag serve 2 purposes within the same type? **4. Simply forget to check for this flag altogether** Yup if you find this flag not doing its job for some objects don't be surprised. People & sometimes even maintainers just forget that it even existsb5593bc693/code/game/objects/items/piggy_bank.dm (L66-L67)**Solution** These are the main examples i found. As you can see the same flag can perform 2 different functions within the same type and do something else in a different object & in some instances don't even work cause people just forget, etc. In order to bring consistency to this flag we need to move it to the atom level where it means the same thing everywhere. Where in the atom you may ask? .Well, I'll just post what MrMelbert said in https://github.com/tgstation/tgstation/pull/81656#discussion_r1503086862 > ...Ideally the .deconstruct call would handle NO_DECONSTRUCTION handling as it wants, Yup that's the ideal case now. This flag is checked directly in `deconstruct()`. Now like i said we want to give a universal definition to this flag and as you have seen from my examples it is used in 3 cases 1) Make an object disappear(doesn't dropping anything) when deconstructed 2) Stop it from being wrenched 3) Stop it from being deconstructed via tools We can't enforce points 2 & 3 inside `deconstruct()` which leaves us with only case 1) i.e. make the object disappear. And that's what i have done. Therefore after more than a decade or since this flag got introduced `NO_DECONSTRUCT` now has a new definition as of 2024 _"Make an object disappear(don't dropping anything) when deconstructed either via tools or forcefully smashed apart"_ Now i very well understand this will open up bugs in places where cases 2 & 3 are required but its worth it. In fact they could even be qol changes for all we know so who knows it might even benefit us but for now we need to give a universal definition to this flag to bring some consistency & that's what this PR does. **Problem with deconstruct()** This proc actually sends out a signal which is currently used by the material container but could be used by other objects later on.3e84c3e6da/code/game/objects/obj_defense.dm (L160)So objects that override this proc should call its parent. Sadly that isn't the case in many instances like such3e84c3e6da/code/game/machinery/deployable.dm (L20-L23)Instead of `return ..()` which would delete the object & send the signal it deletes the object directly thus the signal never gets sent. **Solution** Make this proc non overridable. For objects to add their own custom deconstruction behaviour a new proc has been introduced `atom_deconstruct()` Subtypes should now override this proc to handle object deconstruction. If objects have certain important stuff inside them (like mobs in machines for example) they want to drop by handling `NO_DECONSTRUCT` flag in a more carefully customized way they can do this by overriding `handle_deconstruct()` which by default delegates to `atom_deconstruct()` if the `NO_DECONSTRUCT` flag is absent. This proc will allow you to handle the flag in a more customized way if you ever need to. ## Why It's Good For The Game 1) I'm goanna post the full comment from MrMelbert https://github.com/tgstation/tgstation/pull/81656#discussion_r1503086862 > ...Ideally the .deconstruct call would handle NO_DECONSTRUCTION handling as it wants, but there's a shocking lack of consistency around NO_DECONSTRUCTION, where some objects treat it as "allow deconstruction, but make it drop no parts" and others simply "disallow deconstruction at all" This PR now makes `NO_DECONSTRUCTION` handled by `deconstruct()` & gives this flag the consistency it deserves. Not to mention as shown in case 4 there are objects that simply forgot to check for this flag. Now it applies for those missing instances as well. 2) No more copying pasting the most overused code pattern in this code base history `if(obj_flags & NO_DECONSTRUCTION)`. Just makes code cleaner everywhere 3) All objects now send the `COMSIG_OBJ_DECONSTRUCT` signal on object deconstruction which is now available for use should you need it ## Changelog 🆑 refactor: refactors how objects are deconstructed in relation to the `NO_DECONSTRUCTION` flag. Certain objects & machinery may display different tool interactions & behaviours when destroyed/deconstructed. Report these changes if you feel like they are bugs /🆑 --------- Co-authored-by: san7890 <the@san7890.com>
225 lines
6.6 KiB
Plaintext
225 lines
6.6 KiB
Plaintext
#define VOTE_TEXT_LIMIT 255
|
|
#define MAX_VOTES 255
|
|
|
|
/obj/structure/votebox
|
|
name = "voting box"
|
|
desc = "An automatic voting box."
|
|
|
|
icon = 'icons/obj/storage/box.dmi'
|
|
icon_state = "votebox_maint"
|
|
|
|
anchored = TRUE
|
|
|
|
var/obj/item/card/id/owner //Slapping the box with this ID starts/ends the vote.
|
|
|
|
var/voting_active = FALSE //Voting or Maintenance Mode
|
|
var/id_auth = FALSE //One vote per ID.
|
|
var/vote_description = ""
|
|
|
|
var/list/voted //List of ID's that already voted.
|
|
COOLDOWN_DECLARE(vote_print_cooldown)
|
|
|
|
/obj/structure/votebox/attackby(obj/item/I, mob/living/user, params)
|
|
if(istype(I,/obj/item/card/id))
|
|
if(!owner)
|
|
register_owner(I,user)
|
|
return
|
|
if(istype(I,/obj/item/paper))
|
|
if(voting_active)
|
|
apply_vote(I,user)
|
|
else
|
|
to_chat(user,span_warning("[src] is in maintenance mode. Voting is not possible at the moment."))
|
|
return
|
|
return ..()
|
|
|
|
/obj/structure/votebox/interact(mob/user)
|
|
..()
|
|
ui_interact(user)
|
|
|
|
/obj/structure/votebox/ui_interact(mob/user)
|
|
. = ..()
|
|
|
|
var/list/dat = list()
|
|
if(!owner)
|
|
dat += "<h1> Unregistered. Swipe ID card to register as voting box operator </h1>"
|
|
dat += "<h1>[vote_description]</h1>"
|
|
if(is_operator(user))
|
|
dat += "Voting: <a href='?src=[REF(src)];act=toggle_vote'>[voting_active ? "Active" : "Maintenance Mode"]</a><br>"
|
|
dat += "Set Description: <a href='?src=[REF(src)];act=set_desc'>Set Description</a><br>"
|
|
dat += "One vote per ID: <a href='?src=[REF(src)];act=toggle_auth'>[id_auth ? "Yes" : "No"]</a><br>"
|
|
dat += "Reset voted ID's: <a href='?src=[REF(src)];act=reset_voted'>Reset</a><br>"
|
|
dat += "Draw random vote: <a href='?src=[REF(src)];act=raffle'>Raffle</a><br>"
|
|
dat += "Shred votes: <a href='?src=[REF(src)];act=shred'>Shred</a><br>"
|
|
dat += "Tally votes: <a href='?src=[REF(src)];act=tally'>Tally</a><br>"
|
|
|
|
var/datum/browser/popup = new(user, "votebox", "Voting Box", 300, 300)
|
|
popup.set_content(dat.Join())
|
|
popup.open()
|
|
|
|
/obj/structure/votebox/Topic(href, href_list)
|
|
if(..())
|
|
return
|
|
|
|
var/mob/user = usr
|
|
if(!can_interact(user))
|
|
return
|
|
if(!is_operator(user))
|
|
to_chat(user,span_warning("Voting box operator authorization required!"))
|
|
return
|
|
|
|
if(href_list["act"])
|
|
switch(href_list["act"])
|
|
if("toggle_vote")
|
|
voting_active = !voting_active
|
|
update_appearance()
|
|
if("toggle_auth")
|
|
id_auth = !id_auth
|
|
if("reset_voted")
|
|
if(voted)
|
|
voted.Cut()
|
|
to_chat(user,span_notice("You reset the voter buffer. Everyone can vote again."))
|
|
if("raffle")
|
|
raffle(user)
|
|
if("shred")
|
|
shred(user)
|
|
if("tally")
|
|
print_tally(user)
|
|
if("set_desc")
|
|
set_description(user)
|
|
interact(user)
|
|
|
|
/obj/structure/votebox/proc/register_owner(obj/item/card/id/I,mob/living/user)
|
|
owner = I
|
|
to_chat(user,span_notice("You register [src] to your ID card."))
|
|
ui_interact(user)
|
|
|
|
/obj/structure/votebox/proc/set_description(mob/user)
|
|
var/new_description = tgui_input_text(user, "Enter a new description", "Vote Description", vote_description, multiline = TRUE)
|
|
if(new_description)
|
|
vote_description = new_description
|
|
|
|
/obj/structure/votebox/proc/is_operator(mob/living/user)
|
|
return (istype(user) && user?.get_idcard() == owner)
|
|
|
|
/obj/structure/votebox/proc/apply_vote(obj/item/paper/I,mob/living/user)
|
|
var/obj/item/card/id/voter_card = user.get_idcard()
|
|
if(id_auth)
|
|
if(!voter_card)
|
|
to_chat(user,span_warning("[src] requires a valid ID card to vote!"))
|
|
return
|
|
if(voted && (voter_card in voted))
|
|
to_chat(user,span_warning("[src] allows only one vote per person."))
|
|
return
|
|
if(user.transferItemToLoc(I,src))
|
|
if(!voted)
|
|
voted = list()
|
|
voted += voter_card
|
|
to_chat(user,span_notice("You cast your vote."))
|
|
|
|
/obj/structure/votebox/proc/valid_vote(obj/item/paper/voting_slip)
|
|
if(voting_slip.get_total_length() > VOTE_TEXT_LIMIT)
|
|
return FALSE
|
|
|
|
for(var/datum/paper_input/text as anything in voting_slip.raw_text_inputs)
|
|
if(findtext(text.raw_text, "<h1>Voting Results:</h1><hr><ol>"))
|
|
return FALSE
|
|
return TRUE
|
|
|
|
/obj/structure/votebox/proc/shred(mob/user)
|
|
for(var/obj/item/paper/P in contents)
|
|
qdel(P)
|
|
to_chat(user,span_notice("You shred the current votes."))
|
|
|
|
/obj/structure/votebox/wrench_act(mob/living/user, obj/item/tool)
|
|
. = ..()
|
|
default_unfasten_wrench(user, tool, time = 4 SECONDS)
|
|
return ITEM_INTERACT_SUCCESS
|
|
|
|
/obj/structure/votebox/crowbar_act(mob/living/user, obj/item/I)
|
|
. = ..()
|
|
if(voting_active)
|
|
to_chat(user,span_warning("You can only retrieve votes if maintenance mode is active!"))
|
|
return FALSE
|
|
dump_contents()
|
|
to_chat(user,span_notice("You open vote retrieval hatch and dump all the votes."))
|
|
return TRUE
|
|
|
|
/obj/structure/votebox/dump_contents()
|
|
var/atom/droppoint = drop_location()
|
|
for(var/atom/movable/AM in contents)
|
|
AM.forceMove(droppoint)
|
|
|
|
/obj/structure/votebox/atom_deconstruct(disassembled)
|
|
dump_contents()
|
|
|
|
/obj/structure/votebox/proc/raffle(mob/user)
|
|
var/list/options = list()
|
|
for(var/obj/item/paper/P in contents)
|
|
options += P
|
|
if(!length(options))
|
|
to_chat(user, span_warning("[src] is empty!"))
|
|
else
|
|
var/obj/item/paper/P = pick(options)
|
|
user.put_in_hands(P)
|
|
to_chat(user, span_notice("[src] pops out random vote."))
|
|
|
|
/obj/structure/votebox/proc/print_tally(mob/user)
|
|
var/list/results = list()
|
|
var/i = 0
|
|
for(var/obj/item/paper/paper_content in contents)
|
|
if(i++ > MAX_VOTES)
|
|
break
|
|
if(!valid_vote(paper_content))
|
|
continue
|
|
|
|
var/full_vote_text = ""
|
|
for(var/datum/paper_input/text as anything in paper_content.raw_text_inputs)
|
|
full_vote_text += "[text.raw_text]"
|
|
|
|
if(!results[full_vote_text])
|
|
results[full_vote_text] = 1
|
|
else
|
|
results[full_vote_text] += 1
|
|
|
|
sortTim(results, cmp=/proc/cmp_numeric_dsc, associative = TRUE)
|
|
if(!COOLDOWN_FINISHED(src, vote_print_cooldown))
|
|
return
|
|
COOLDOWN_START(src, vote_print_cooldown, 60 SECONDS)
|
|
var/obj/item/paper/vote_tally_paper = new(drop_location())
|
|
var/list/tally = list()
|
|
tally += {"
|
|
<style>
|
|
.vote_box_content{
|
|
max-width:250px;
|
|
display:inline-block;
|
|
overflow:hidden;
|
|
text-overflow:ellipsis;
|
|
white-space:nowrap;
|
|
vertical-align:bottom
|
|
}
|
|
.vote_box_content br {
|
|
display: none;
|
|
}
|
|
.vote_box_content hr {
|
|
display: none;
|
|
}
|
|
</style>"}
|
|
|
|
tally += "<h1>Voting Results:</h1><br/><h2>[vote_description]</h2><hr><ol>"
|
|
for(var/option in results)
|
|
tally += "<li>\"<span class='vote_box_content'>[option]</span>\" - [results[option]] Vote[results[option] > 1 ? "s" : ""].</li>"
|
|
tally += "</ol>"
|
|
|
|
vote_tally_paper.add_raw_text(tally.Join())
|
|
vote_tally_paper.name = "Voting Results"
|
|
vote_tally_paper.update_appearance()
|
|
user.put_in_hands(vote_tally_paper)
|
|
to_chat(user,span_notice("[src] prints out the voting tally."))
|
|
|
|
/obj/structure/votebox/update_icon_state()
|
|
icon_state = "votebox_[voting_active ? "active" : "maint"]"
|
|
return ..()
|
|
|
|
#undef VOTE_TEXT_LIMIT
|
|
#undef MAX_VOTES
|