Skip to content

Commit

Permalink
Adds latejoin scaling to vendors
Browse files Browse the repository at this point in the history
  • Loading branch information
fira committed Nov 16, 2023
1 parent d7c679f commit b642244
Show file tree
Hide file tree
Showing 11 changed files with 147 additions and 84 deletions.
3 changes: 3 additions & 0 deletions code/__DEFINES/vendors.dm
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,6 @@
//Whether or not to load ammo boxes depending on ammo loaded into the vendor
//Only relevant in big vendors, like Requisitions or Squad Prep
#define VEND_LOAD_AMMO_BOXES (1<<9)
/// Vendors with this flag will fill retroactively based on latejoining players,
/// and expect a scale multiplier instead of amount of items
#define VEND_STOCK_DYNAMIC (1<<10)
35 changes: 28 additions & 7 deletions code/game/gamemodes/cm_initialize.dm
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ Additional game mode variables.
var/list/monkey_types = list() //What type of monkeys do we spawn
var/latejoin_tally = 0 //How many people latejoined Marines
var/latejoin_larva_drop = LATEJOIN_MARINES_PER_LATEJOIN_LARVA //A larva will spawn in once the tally reaches this level. If set to 0, no latejoin larva drop
/// Amount of latejoin_tally already awarded as larvas
var/latejoin_larva_used = 0
/// Multiplier to the amount of gear awarded so far - increases only
var/gear_scale = 1
/// Roundstart gear scale to base off current gear_scale, for latejoin calculations
var/gear_scale_init = 1

//Role Authority set up.
/// List of role titles to override to different roles when starting game
Expand Down Expand Up @@ -903,23 +909,38 @@ Additional game mode variables.
//We do NOT want to initilialize the gear before everyone is properly spawned in
/datum/game_mode/proc/initialize_post_marine_gear_list()
var/scale = get_scaling_value()
init_gear_scale()

//Set up attachment vendor contents related to Marine count
for(var/i in GLOB.cm_vending_vendors)
var/obj/structure/machinery/cm_vending/sorted/CVS = i
CVS.populate_product_list_and_boxes(scale)
CVS.populate_product_list_and_boxes(gear_scale)

//Scale the amount of cargo points through a direct multiplier
supply_controller.points = round(supply_controller.points * scale)
supply_controller.points += round(supply_controller.points_scale * gear_scale)

/datum/game_mode/proc/get_scaling_value()
///Returns a multiplier to the amount of gear that is to be distributed roundstart, stored in [/datum/game_mode/var/gear_scale]
/datum/game_mode/proc/init_gear_scale()
//We take the number of marine players, deduced from other lists, and then get a scale multiplier from it, to be used in arbitrary manners to distribute equipment
//This might count players who ready up but get kicked back to the lobby
var/marine_pop_size = length(GLOB.alive_human_list)
var/marine_pop_size = 0
for(var/mob/living/carbon/human/human as anything in GLOB.alive_human_list)
if(human.faction == FACTION_USCM)
var/datum/job/job = GET_MAPPED_ROLE(human.job)

Check failure on line 928 in code/game/gamemodes/cm_initialize.dm

View workflow job for this annotation

GitHub Actions / Run Linters

got '{', expected one of: operator, field access, as, 'in', ',', ';'
marine_pop_size += RoleAuthority.calculate_role_weight(job)

//This gives a decimal value representing a scaling multiplier. Cannot go below 1
return max(marine_pop_size / MARINE_GEAR_SCALING_NORMAL, 1)
gear_scale = max(marine_pop_size / MARINE_GEAR_SCALING_NORMAL, 1)
gear_scale_init = gear_scale
return gear_scale

///Updates the [/datum/game_mode/var/gear_scale] multiplier based on joining marines in [/datum/game_mode/var/latejoin_tally]
/datum/game_mode/proc/update_gear_scale()
var/new_gear_scale = round(gear_scale_init + latejoin_tally / MARINE_GEAR_SCALING_NORMAL)
if(new_gear_scale > gear_scale)
for(var/obj/structure/machinery/cm_vending/sorted/vendor as anything in GLOB.cm_vending_vendors)
vendor.update_dynamic_stock(new_gear_scale)
supply_controller.points += round((new_gear_scale - gear_scale) * supply_controller.points_scale)
gear_scale = new_gear_scale

// for the toolbox
/datum/game_mode/proc/end_round_message()
Expand Down
2 changes: 2 additions & 0 deletions code/game/jobs/role_authority.dm
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,8 @@ I hope it's easier to tell what the heck this proc is even doing, unlike previou
* survivors and the number of roundstart Squad Rifleman slots.
*/
/datum/authority/branch/role/proc/calculate_role_weight(datum/job/J)
if(!J)
return 0
if(ROLES_MARINES.Find(J.title))
return 1
if(ROLES_XENO.Find(J.title))
Expand Down
7 changes: 4 additions & 3 deletions code/game/machinery/cryopod.dm
Original file line number Diff line number Diff line change
Expand Up @@ -321,13 +321,13 @@ GLOBAL_LIST_INIT(frozen_items, list(SQUAD_MARINE_1 = list(), SQUAD_MARINE_2 = li
dept_console += A
A.moveToNullspace()

var/datum/job/job = GET_MAPPED_ROLE(occupant.job)
if(ishuman(occupant))
var/mob/living/carbon/human/H = occupant
if(H.assigned_squad)
var/datum/squad/S = H.assigned_squad
S.forget_marine_in_squad(H)
var/datum/job/J = GET_MAPPED_ROLE(H.job)
if(istype(J, /datum/job/marine/specialist))
if(istype(job, /datum/job/marine/specialist))
//we make the set this specialist took if any available again
if(H.skills)
var/set_name
Expand All @@ -346,7 +346,8 @@ GLOBAL_LIST_INIT(frozen_items, list(SQUAD_MARINE_1 = list(), SQUAD_MARINE_2 = li
if(set_name && !available_specialist_sets.Find(set_name))
available_specialist_sets += set_name

SSticker.mode.latejoin_tally-- //Cryoing someone out removes someone from the Marines, blocking further larva spawns until accounted for
//Cryoing someone out removes someone from the Marines, blocking further larva spawns until accounted for
SSticker.mode.latejoin_tally -= RoleAuthority.calculate_role_weight(job)

//Handle job slot/tater cleanup.
RoleAuthority.free_role(GET_MAPPED_ROLE(occupant.job), TRUE)
Expand Down
38 changes: 34 additions & 4 deletions code/game/machinery/vending/cm_vending.dm
Original file line number Diff line number Diff line change
Expand Up @@ -810,8 +810,11 @@ GLOBAL_LIST_EMPTY(vending_products)
vend_flags = VEND_CLUTTER_PROTECTION | VEND_LIMITED_INVENTORY | VEND_TO_HAND
show_points = FALSE

//this here is made to provide ability to restock vendors with different subtypes of same object, like handmade and manually filled ammo boxes.
///this here is made to provide ability to restock vendors with different subtypes of same object, like handmade and manually filled ammo boxes.
var/list/corresponding_types_list
///If using [VEND_STOCK_DYNAMIC], assoc list of product entry to list of (product multiplier, awarded objects) - as seen in [/obj/structure/machinery/cm_vending/sorted/proc/populate_product_list]
///This allows us to backtrack and refill the stocks when new players latejoin
var/list/list/dynamic_stock_multipliers

/obj/structure/machinery/cm_vending/sorted/Initialize()
. = ..()
Expand All @@ -824,14 +827,41 @@ GLOBAL_LIST_EMPTY(vending_products)
GLOB.cm_vending_vendors -= src
return ..()

//this proc, well, populates product list based on roundstart amount of players
///this proc, well, populates product list based on roundstart amount of players
/obj/structure/machinery/cm_vending/sorted/proc/populate_product_list_and_boxes(scale)
populate_product_list(scale)
if(vend_flags & VEND_STOCK_DYNAMIC)
populate_product_list(1.0)
dynamic_stock_multipliers = list()
for(var/list/vendspec in listed_products)
var/multiplier = vendspec[2]
if(multiplier > 0)
var/awarded = round(vendspec[2] * scale) // Starting amount
//Record the multiplier and how many have actually been given out
dynamic_stock_multipliers[vendspec] = list(vendspec[2], awarded)
vendspec[2] = awarded // Override starting amount
else
populate_product_list(scale)

if(vend_flags & VEND_LOAD_AMMO_BOXES)
populate_ammo_boxes()
return

//this proc, well, populates product list based on roundstart amount of players
///Updates the vendor stock when the [/datum/game_mode/var/marine_tally] has changed and we're using [VEND_STOCK_DYNAMIC]
///Assumes the scale can only increase!!! Don't take their items away!
/obj/structure/machinery/cm_vending/sorted/proc/update_dynamic_stock(new_scale)
if(!(vend_flags & VEND_STOCK_DYNAMIC))
return
for(var/list/vendspec in dynamic_stock_multipliers)
var/list/metadata = dynamic_stock_multipliers[vendspec]
var/multiplier = metadata[1] // How much do we multiply scales by
var/previous_max_amount = metadata[2] // How many we would have total at old scale
var/projected_max_amount = round(new_scale * multiplier) // How much we would have had total now in total
if(projected_max_amount > previous_max_amount)
vendspec[2] += (projected_max_amount - previous_max_amount) // Add missing ones!
update_derived_ammo_and_boxes_on_add(vendspec)

///this proc, well, populates product list based on roundstart amount of players
///do not rely on scale here if you use VEND_STOCK_DYNAMIC because it's already taken into account
/obj/structure/machinery/cm_vending/sorted/proc/populate_product_list(scale)
return

Expand Down
Loading

0 comments on commit b642244

Please sign in to comment.