Skip to content
Open
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
39 changes: 39 additions & 0 deletions code/__HELPERS/_lists.dm
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,45 @@
};\
} while(FALSE)

#define SORT_FIRST_INDEX(list) (list[1])
#define SORT_PRIORITY_INDEX(list) (list["priority"])
#define SORT_COMPARE_DIRECTLY(thing) (thing)
#define SORT_VAR_NO_TYPE(varname) var/varname
/****
* Even more custom binary search sorted insert, using defines instead of vars
* INPUT: Item to be inserted
* LIST: List to insert INPUT into
* TYPECONT: A define setting the var to the typepath of the contents of the list
* COMPARE: The item to compare against, usualy the same as INPUT
* COMPARISON: A define that takes an item to compare as input, and returns their comparable value
* COMPTYPE: How should the list be compared? Either COMPARE_KEY or COMPARE_VALUE.
*/
#define BINARY_INSERT_DEFINE(INPUT, LIST, TYPECONT, COMPARE, COMPARISON, COMPTYPE) \
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: this is non-modular bc it's just a straight port from tg, so it's prolly fine in the long run

do {\
var/list/__BIN_LIST = LIST;\
var/__BIN_CTTL = length(__BIN_LIST);\
if(!__BIN_CTTL) {\
__BIN_LIST += INPUT;\
} else {\
var/__BIN_LEFT = 1;\
var/__BIN_RIGHT = __BIN_CTTL;\
var/__BIN_MID = (__BIN_LEFT + __BIN_RIGHT) >> 1;\
##TYPECONT(__BIN_ITEM);\
while(__BIN_LEFT < __BIN_RIGHT) {\
__BIN_ITEM = COMPTYPE;\
if(##COMPARISON(__BIN_ITEM) <= ##COMPARISON(COMPARE)) {\
__BIN_LEFT = __BIN_MID + 1;\
} else {\
__BIN_RIGHT = __BIN_MID;\
};\
__BIN_MID = (__BIN_LEFT + __BIN_RIGHT) >> 1;\
};\
__BIN_ITEM = COMPTYPE;\
__BIN_MID = ##COMPARISON(__BIN_ITEM) > ##COMPARISON(COMPARE) ? __BIN_MID : __BIN_MID + 1;\
__BIN_LIST.Insert(__BIN_MID, INPUT);\
};\
} while(FALSE)

//Returns a list in plain english as a string
/proc/english_list(list/input, nothing_text = "nothing", and_text = " and ", comma_text = ", ", final_comma_text = "" )
var/total = length(input)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/datum/component/storage/_process_numerical_display()
. = list()
for(var/obj/item/item in accessible_items())
if(QDELING(item))
continue
var/id = item.numerical_display_id()
if(!.[id])
.[id] = new /datum/numbered_display(item, 1, src)
else
var/datum/numbered_display/display = .[id]
display.number++
22 changes: 22 additions & 0 deletions modular_pentest/master_files/code/game/objects/items.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/// Returns the "ID" used for grouping items together in numerical displays.
/obj/item/proc/numerical_display_id()
. = "[type]"
// adding a label separates them
var/datum/component/label/label = GetComponent(/datum/component/label)
if(label)
. += "-[label.label_name]"
// spray painting colors also separates them, if there is no label
else if(length(atom_colours) >= WASHABLE_COLOUR_PRIORITY)
var/painted_color = atom_colours[WASHABLE_COLOUR_PRIORITY]
if(painted_color)
. += "-[painted_color]"

// for beakers/bottles/etc, also group by what reagents they have
/obj/item/reagent_containers/numerical_display_id()
. = ..()
var/list/reagent_names = list()
// sort them first so that it's consistent no matter what order we inserted the reagents in
for(var/datum/reagent/reagent as anything in reagents.reagent_list)
BINARY_INSERT_DEFINE(reagent.name, reagent_names, SORT_VAR_NO_TYPE, reagent.name, SORT_COMPARE_DIRECTLY, COMPARE_KEY)
if(length(reagent_names))
. += "+" + jointext(reagent_names, "+")
2 changes: 2 additions & 0 deletions modular_pentest/~pentest.dme
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "master_files\code\datums\dog_fashion.dm"
#include "master_files\code\datums\holocall.dm"
#include "master_files\code\datums\brain_damage\phobia.dm"
#include "master_files\code\datums\components\storage\ui.dm"
#include "master_files\code\datums\components\slippery.dm"
#include "master_files\code\datums\components\soulstoned.dm"
#include "master_files\code\datums\components\crafting\recipes\misc.dm"
Expand All @@ -36,6 +37,7 @@
#include "master_files\code\game\mecha\mech_fabricator.dm"
#include "master_files\code\game\mecha\equipment\tools\mech_fabricator.dm"
#include "master_files\code\game\objects\AI_modules.dm"
#include "master_files\code\game\objects\items.dm"
#include "master_files\code\game\objects\effects\decals\turfdecal\flooring_decals.dm"
#include "master_files\code\game\objects\effects\spawners\random\food_or_drink.dm"
#include "master_files\code\game\objects\items\dna_injector.dm"
Expand Down
Loading