Skip to content

Commit

Permalink
World Initialization Refactor (#13672)
Browse files Browse the repository at this point in the history
* World Initialization Refactor

Co-authored-by: Jordan Brown <[email protected]>

* Log bandaid for now

* Fix hive status

* Fix orbit menu icons

---------

Co-authored-by: Jordan Brown <[email protected]>
  • Loading branch information
ivanmixo and Cyberboss authored Aug 7, 2023
1 parent 7bfadde commit 1cb5507
Show file tree
Hide file tree
Showing 22 changed files with 357 additions and 259 deletions.
8 changes: 4 additions & 4 deletions code/__DEFINES/_globals.dm
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
#define GLOBAL_PROTECT(X)
#endif

//Standard BYOND global, do not use
#define GLOBAL_REAL_VAR(X) var/global/##X
/// Standard BYOND global, seriously do not use without an earthshakingly good reason
#define GLOBAL_REAL_VAR(X) var/global/##X;

//Standard typed BYOND global, do not use
#define GLOBAL_REAL(X, Typepath) var/global##Typepath/##X
/// Standard typed BYOND global, seriously do not use without an earthshakingly good reason
#define GLOBAL_REAL(X, Typepath) var/global##Typepath/##X;

//Defines a global var on the controller, do not use
#define GLOBAL_RAW(X) /datum/controller/global_vars/var/global##X
Expand Down
109 changes: 20 additions & 89 deletions code/__HELPERS/global_lists.dm
Original file line number Diff line number Diff line change
Expand Up @@ -9,46 +9,17 @@
GLOBAL_LIST_INIT(poster_designs, subtypesof(/datum/poster))


// Pill icons
GLOBAL_LIST_EMPTY(randomized_pill_icons)

//////////////////////////
/////Initial Building/////
//////////////////////////

/proc/make_datum_references_lists()
// Hair - Initialise all /datum/sprite_accessory/hair into an list indexed by hair-style name
for(var/path in subtypesof(/datum/sprite_accessory/hair))
var/datum/sprite_accessory/hair/H = new path()
GLOB.hair_styles_list[H.name] = H

// Hair Gradients - Initialise all /datum/sprite_accessory/hair_gradient into an list indexed by gradient-style name
for(var/path in subtypesof(/datum/sprite_accessory/hair_gradient))
var/datum/sprite_accessory/hair_gradient/H = new path()
GLOB.hair_gradients_list[H.name] = H

// Facial Hair - Initialise all /datum/sprite_accessory/facial_hair into an list indexed by facialhair-style name
for(var/path in subtypesof(/datum/sprite_accessory/facial_hair))
var/datum/sprite_accessory/facial_hair/H = new path()
GLOB.facial_hair_styles_list[H.name] = H

// Species specific
for(var/path in subtypesof(/datum/sprite_accessory/moth_wings)) //todo use init accesries
var/datum/sprite_accessory/moth_wings/wings = new path()
GLOB.moth_wings_list[wings.name] = wings

// Ethnicity - Initialise all /datum/ethnicity into a list indexed by ethnicity name
for(var/path in subtypesof(/datum/ethnicity))
var/datum/ethnicity/E = new path()
GLOB.ethnicities_list[E.name] = E

// Surgery Steps - Initialize all /datum/surgery_step into a list
for(var/T in subtypesof(/datum/surgery_step))
var/datum/surgery_step/S = new T
GLOB.surgery_steps += S

sort_surgeries()
/proc/init_sprite_accessories()
init_sprite_accessory_subtypes(/datum/sprite_accessory/hair, GLOB.hair_styles_list)
init_sprite_accessory_subtypes(/datum/sprite_accessory/hair_gradient, GLOB.hair_gradients_list)
init_sprite_accessory_subtypes(/datum/sprite_accessory/facial_hair, GLOB.facial_hair_styles_list)
init_sprite_accessory_subtypes(/datum/sprite_accessory/moth_wings, GLOB.moth_wings_list)

/proc/init_species()
var/rkey = 0

// Species
Expand All @@ -60,48 +31,8 @@ GLOBAL_LIST_EMPTY(randomized_pill_icons)
if(S.joinable_roundstart)
GLOB.roundstart_species[S.name] = S

// Our ammo stuff is initialized here.
var/blacklist = list(/datum/ammo/energy, /datum/ammo/bullet/shotgun, /datum/ammo/xeno)
for(var/t in subtypesof(/datum/ammo) - blacklist)
var/datum/ammo/A = new t
GLOB.ammo_list[A.type] = A

for(var/X in subtypesof(/datum/xeno_caste))
var/datum/xeno_caste/C = new X
if(!(C.caste_type_path in GLOB.xeno_caste_datums))
GLOB.xeno_caste_datums[C.caste_type_path] = list()
GLOB.xeno_caste_datums[C.caste_type_path][C.upgrade] = C

for(var/H in subtypesof(/datum/hive_status))
var/datum/hive_status/HS = new H
GLOB.hive_datums[HS.hivenumber] = HS

// Initializes static ui data used by all hive status UI
var/list/per_tier_counter = list()
for(var/caste_type_path AS in GLOB.xeno_caste_datums)
var/datum/xeno_caste/caste = GLOB.xeno_caste_datums[caste_type_path][XENO_UPGRADE_BASETYPE]
var/type_path = initial(caste.caste_type_path)

GLOB.hive_ui_caste_index[type_path] = length(GLOB.hive_ui_static_data) //Starts from 0.

var/icon/xeno_minimap = icon('icons/UI_icons/map_blips.dmi', initial(caste.minimap_icon))
var/tier = initial(caste.tier)
if(tier == XENO_TIER_MINION)
continue
if(isnull(per_tier_counter[tier]))
per_tier_counter[tier] = 0

GLOB.hive_ui_static_data += list(list(
"name" = initial(caste.caste_name),
"is_queen" = type_path == /mob/living/carbon/xenomorph/queen,
"minimap" = icon2base64(xeno_minimap),
"sort_mod" = per_tier_counter[tier]++,
"tier" = GLOB.tier_as_number[tier],
"is_unique" = caste.maximum_active_caste == 1,
"can_transfer_plasma" = CHECK_BITFIELD(initial(caste.can_flags), CASTE_CAN_BE_GIVEN_PLASMA),
"evolution_max" = initial(caste.evolution_threshold)
))

/proc/init_language_datums()
for(var/L in subtypesof(/datum/language))
var/datum/language/language = L
if(!initial(language.key))
Expand All @@ -113,23 +44,18 @@ GLOBAL_LIST_EMPTY(randomized_pill_icons)

GLOB.language_datum_instances[language] = instance

/proc/init_emote_list()
//Emotes
for(var/path in subtypesof(/datum/emote))
var/datum/emote/E = new path()
E.emote_list[E.key] = E

init_keybindings()

for(var/i in 1 to 21)
GLOB.randomized_pill_icons += "pill[i]"
shuffle(GLOB.randomized_pill_icons)

/proc/init_chemistry()
for(var/path in subtypesof(/datum/reagent))
var/datum/reagent/D = new path()
GLOB.chemical_reagents_list[path] = D

for(var/path in subtypesof(/datum/chemical_reaction))

var/datum/chemical_reaction/D = new path()
var/list/reaction_ids = list()

Expand All @@ -139,15 +65,14 @@ GLOBAL_LIST_EMPTY(randomized_pill_icons)
for(var/reaction in D.required_reagents)
reaction_ids += reaction



// Create filters based on each reagent id in the required reagents list
for(var/id in reaction_ids)
if(!GLOB.chemical_reactions_list[id])
GLOB.chemical_reactions_list[id] = list()
GLOB.chemical_reactions_list[id] += D
break // Don't bother adding ourselves to other reagent ids, it is redundant

/proc/init_namepool()
for(var/path in typesof(/datum/namepool))
var/datum/namepool/NP = new path
GLOB.namepool[path] = NP
Expand All @@ -156,11 +81,17 @@ GLOBAL_LIST_EMPTY(randomized_pill_icons)
var/datum/operation_namepool/NP = new path
GLOB.operation_namepool[path] = NP

/// Minimap icons for UI display
for(var/icon_state in GLOB.playable_icons)
GLOB.minimap_icons[icon_state] = icon2base64(icon('icons/UI_icons/map_blips.dmi', icon_state, frame = 1))

return TRUE
/// These should be replaced with proper _INIT macros
/proc/make_datum_reference_lists()
populate_seed_list()
init_sprite_accessories()
init_species()
init_language_datums()
init_emote_list()
init_chemistry()
init_namepool()
init_keybindings()


//creates every subtype of prototype (excluding prototype) and adds it to list L.
Expand Down
10 changes: 0 additions & 10 deletions code/__HELPERS/unsorted.dm
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,6 @@
/datum/proc/stack_trace(msg)
CRASH(msg)


GLOBAL_REAL_VAR(list/stack_trace_storage)
/proc/gib_stack_trace()
stack_trace_storage = list()
stack_trace()
stack_trace_storage.Cut(1, min(3, length(stack_trace_storage)))
. = stack_trace_storage
stack_trace_storage = null


//returns a GUID like identifier (using a mostly made up record format)
//guids are not on their own suitable for access or security tokens, as most of their bits are predictable.
// (But may make a nice salt to one)
Expand Down
13 changes: 0 additions & 13 deletions code/_debugger.dm

This file was deleted.

2 changes: 1 addition & 1 deletion code/_globalvars/configuration.dm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
GLOBAL_REAL(config, /datum/controller/configuration)

GLOBAL_DATUM(revdata, /datum/getrev)
GLOBAL_DATUM_INIT(revdata, /datum/getrev, new)

GLOBAL_VAR(host)
GLOBAL_VAR_INIT(game_version, "TGMC")
Expand Down
18 changes: 16 additions & 2 deletions code/_globalvars/lists/flavor_misc.dm
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
//Preferences stuff
GLOBAL_LIST_EMPTY(ethnicities_list)
GLOBAL_LIST_INIT(ethnicities_list, init_ethnicities())

/// Ethnicity - Initialise all /datum/ethnicity into a list indexed by ethnicity name
/proc/init_ethnicities()
. = list()
for(var/path in subtypesof(/datum/ethnicity))
var/datum/ethnicity/E = new path()
.[E.name] = E

//Hairstyles
GLOBAL_LIST_EMPTY(hair_styles_list) //stores /datum/sprite_accessory/hair indexed by name
GLOBAL_LIST_EMPTY(hair_gradients_list) //stores /datum/sprite_accessory/hair_gradient indexed by name
Expand Down Expand Up @@ -76,7 +84,6 @@ GLOBAL_LIST_INIT(backpacklist, list("Nothing", "Backpack", "Satchel"))

GLOBAL_LIST_INIT(genders, list(MALE, FEMALE, NEUTER))

GLOBAL_LIST_EMPTY(minimap_icons)
GLOBAL_LIST_INIT(playable_icons, list(
"boiler",
"bull",
Expand Down Expand Up @@ -126,3 +133,10 @@ GLOBAL_LIST_INIT(playable_squad_icons, list(
"medic",
"smartgunner",
))

GLOBAL_LIST_INIT(minimap_icons, init_minimap_icons())

/proc/init_minimap_icons()
. = list()
for(var/icon_state in GLOB.playable_icons)
.[icon_state] = icon2base64(icon('icons/UI_icons/map_blips.dmi', icon_state, frame = 1))
54 changes: 50 additions & 4 deletions code/_globalvars/lists/mobs.dm
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,16 @@ GLOBAL_LIST_EMPTY(all_languages)
GLOBAL_LIST_EMPTY(all_species)
GLOBAL_LIST_EMPTY(roundstart_species)

GLOBAL_LIST_EMPTY_TYPED(xeno_caste_datums, /list/datum/xeno_caste)
GLOBAL_LIST_INIT_TYPED(xeno_caste_datums, /list/datum/xeno_caste, init_xeno_caste_list())

/proc/init_xeno_caste_list()
. = list()
for(var/X in subtypesof(/datum/xeno_caste))
var/datum/xeno_caste/C = new X
if(!(C.caste_type_path in .))
.[C.caste_type_path] = list()
.[C.caste_type_path][C.upgrade] = C

GLOBAL_LIST_INIT(all_xeno_types, list(
/mob/living/carbon/xenomorph/runner,
/mob/living/carbon/xenomorph/runner/mature,
Expand Down Expand Up @@ -165,13 +174,50 @@ GLOBAL_LIST_INIT(xeno_types_tier_one, list(/mob/living/carbon/xenomorph/runner,
GLOBAL_LIST_INIT(xeno_types_tier_two, list(/mob/living/carbon/xenomorph/hunter, /mob/living/carbon/xenomorph/warrior, /mob/living/carbon/xenomorph/spitter, /mob/living/carbon/xenomorph/hivelord, /mob/living/carbon/xenomorph/carrier, /mob/living/carbon/xenomorph/bull, /mob/living/carbon/xenomorph/wraith))
GLOBAL_LIST_INIT(xeno_types_tier_three, list(/mob/living/carbon/xenomorph/gorger, /mob/living/carbon/xenomorph/widow, /mob/living/carbon/xenomorph/ravager, /mob/living/carbon/xenomorph/praetorian, /mob/living/carbon/xenomorph/boiler, /mob/living/carbon/xenomorph/defiler, /mob/living/carbon/xenomorph/crusher, /mob/living/carbon/xenomorph/shrike))

GLOBAL_LIST_EMPTY_TYPED(hive_datums, /datum/hive_status) // init by make_datum_references_lists()
GLOBAL_LIST_INIT_TYPED(hive_datums, /datum/hive_status, init_hive_datum_list()) // init by make_datum_references_lists()

/proc/init_hive_datum_list()
. = list()
for(var/H in subtypesof(/datum/hive_status))
var/datum/hive_status/HS = new H
.[HS.hivenumber] = HS

///Contains static data passed to all hive status UI.
GLOBAL_LIST_EMPTY(hive_ui_static_data) // init by make_datum_references_lists()
///Returns the index of the corresponding static caste data given caste typepath.
GLOBAL_LIST_EMPTY(hive_ui_caste_index)

///Contains static data passed to all hive status UI.
GLOBAL_LIST_INIT(hive_ui_static_data, init_hive_status_lists()) // init by make_datum_references_lists()

/proc/init_hive_status_lists()
. = list()
// Initializes static ui data used by all hive status UI
var/list/per_tier_counter = list()
for(var/caste_type_path AS in GLOB.xeno_caste_datums)
var/datum/xeno_caste/caste = GLOB.xeno_caste_datums[caste_type_path][XENO_UPGRADE_BASETYPE]
var/type_path = initial(caste.caste_type_path)

GLOB.hive_ui_caste_index[type_path] = length(.) //Starts from 0.

var/icon/xeno_minimap = icon('icons/UI_icons/map_blips.dmi', initial(caste.minimap_icon))
var/tier = initial(caste.tier)
if(tier == XENO_TIER_MINION)
continue
if(isnull(per_tier_counter[tier]))
per_tier_counter[tier] = 0

. += list(list(
"name" = initial(caste.caste_name),
"is_queen" = type_path == /mob/living/carbon/xenomorph/queen,
"minimap" = icon2base64(xeno_minimap),
"sort_mod" = per_tier_counter[tier]++,
"tier" = GLOB.tier_as_number[tier],
"is_unique" = caste.maximum_active_caste == 1,
"can_transfer_plasma" = CHECK_BITFIELD(initial(caste.can_flags), CASTE_CAN_BE_GIVEN_PLASMA),
"evolution_max" = initial(caste.evolution_threshold)
))



/proc/update_config_movespeed_type_lookup(update_mobs = TRUE)
var/list/mob_types = list()
var/list/entry_value = CONFIG_GET(keyed_list/multiplicative_movespeed)
Expand Down
18 changes: 17 additions & 1 deletion code/_globalvars/lists/objects.dm
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
GLOBAL_LIST_EMPTY(cable_list) //Index for all cables, so that powernets don't have to look through the entire world all the time
GLOBAL_LIST_EMPTY(ammo_list) //List of all ammo types. Used by guns to tell the projectile how to act.
GLOBAL_LIST_INIT(ammo_list, init_ammo_list()) //List of all ammo types. Used by guns to tell the projectile how to act.

/proc/init_ammo_list()
. = list()
// Our ammo stuff is initialized here.
var/blacklist = list(/datum/ammo/energy, /datum/ammo/bullet/shotgun, /datum/ammo/xeno)
for(var/t in subtypesof(/datum/ammo) - blacklist)
var/datum/ammo/A = new t
.[A.type] = A

GLOBAL_LIST_EMPTY(marine_turrets)

GLOBAL_LIST_EMPTY(droppod_list)
Expand Down Expand Up @@ -33,6 +42,13 @@ GLOBAL_LIST_EMPTY(main_overwatch_consoles) //list of all main overwatch consol

GLOBAL_LIST_EMPTY(chemical_reactions_list) ///list of all /datum/chemical_reaction datums index by reactants, Used during chemical reactions
GLOBAL_LIST_EMPTY(chemical_reagents_list) ///list of all /datum/reagent datums instances indexed by reagent typepath. Used by chemistry stuff
GLOBAL_LIST_INIT(randomized_pill_icons, init_pill_icons())

/proc/init_pill_icons()
. = list()
for(var/i in 1 to 21)
. += "pill[i]"
shuffle(.)

GLOBAL_LIST_EMPTY(apcs_list) //list of all Area Power Controller machines, separate from machines for powernet speeeeeeed.

Expand Down
Loading

0 comments on commit 1cb5507

Please sign in to comment.