Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework xeno guaranteed slots logic and Fix thunderdome evolution slot bug #4206

Merged
merged 4 commits into from
Sep 16, 2023
Merged
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: 22 additions & 17 deletions code/modules/mob/living/carbon/xenomorph/Evolution.dm
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,13 @@
qdel(new_xeno)
return

switch(new_xeno.tier) //They have evolved, add them to the slot count
if(2)
hive.tier_2_xenos |= new_xeno
if(3)
hive.tier_3_xenos |= new_xeno
var/area/xeno_area = get_area(new_xeno)
if(!is_admin_level(new_xeno.z) || (xeno_area.flags_atom & AREA_ALLOW_XENO_JOIN))
switch(new_xeno.tier) //They have evolved, add them to the slot count IF they are in regular game space
if(2)
hive.tier_2_xenos |= new_xeno
if(3)
hive.tier_3_xenos |= new_xeno

log_game("EVOLVE: [key_name(src)] evolved into [new_xeno].")
if(mind)
Expand Down Expand Up @@ -355,24 +357,27 @@

/mob/living/carbon/xenomorph/proc/can_evolve(castepick, potential_queens)
var/selected_caste = GLOB.xeno_datum_list[castepick]?.type
var/free_slots = LAZYACCESS(hive.free_slots, selected_caste)
if(free_slots)
var/free_slot = LAZYACCESS(hive.free_slots, selected_caste)
var/used_slot = LAZYACCESS(hive.used_slots, selected_caste)
if(free_slot > used_slot)
return TRUE

var/burrowed_factor = min(hive.stored_larva, sqrt(4*hive.stored_larva))
burrowed_factor = round(burrowed_factor)

var/used_tier_2_slots = length(hive.tier_2_xenos)
var/used_tier_3_slots = length(hive.tier_3_xenos)
for(var/caste_path in hive.used_free_slots)
if(!hive.used_free_slots[caste_path])
for(var/caste_path in hive.free_slots)
var/slots_free = hive.free_slots[caste_path]
var/slots_used = hive.used_slots[caste_path]
if(!slots_used)
continue
var/datum/caste_datum/C = caste_path
switch(initial(C.tier))
if(2) used_tier_2_slots--
if(3) used_tier_3_slots--
var/datum/caste_datum/current_caste = caste_path
switch(initial(current_caste.tier))
if(2)
used_tier_2_slots -= min(slots_used, slots_free)
if(3)
used_tier_3_slots -= min(slots_used, slots_free)

var/totalXenos = burrowed_factor
var/burrowed_factor = min(hive.stored_larva, sqrt(4*hive.stored_larva))
var/totalXenos = round(burrowed_factor)
for(var/mob/living/carbon/xenomorph/xeno as anything in hive.totalXenos)
if(xeno.counts_for_slots)
totalXenos++
Expand Down
17 changes: 2 additions & 15 deletions code/modules/mob/living/carbon/xenomorph/Xenomorph.dm
Original file line number Diff line number Diff line change
Expand Up @@ -498,11 +498,7 @@
// Only handle free slots if the xeno is not in tdome
if(!is_admin_level(z))
var/selected_caste = GLOB.xeno_datum_list[caste_type]?.type
var/free_slots = LAZYACCESS(hive.free_slots, selected_caste)
if(free_slots)
hive.free_slots[selected_caste]--
var/new_val = LAZYACCESS(hive.used_free_slots, selected_caste) + 1
LAZYSET(hive.used_free_slots, selected_caste, new_val)
hive.used_slots[selected_caste]++

if(round_statistics && !statistic_exempt)
round_statistics.track_new_participant(faction, 1)
Expand Down Expand Up @@ -705,16 +701,7 @@
hive.remove_hive_leader(src, light_mode = TRUE)
SStracking.stop_tracking("hive_[hivenumber]", src)

// Only handle free slots if the xeno is not in tdome
if(!is_admin_level(z))
var/selected_caste = GLOB.xeno_datum_list[caste_type]?.type
var/used_slots = LAZYACCESS(hive.used_free_slots, selected_caste)
if(used_slots)
hive.used_free_slots[selected_caste]--
var/new_val = LAZYACCESS(hive.free_slots, selected_caste) + 1
LAZYSET(hive.free_slots, selected_caste, new_val)

hive.remove_xeno(src)
hive?.remove_xeno(src)
remove_from_all_mob_huds()

observed_xeno = null
Expand Down
47 changes: 27 additions & 20 deletions code/modules/mob/living/carbon/xenomorph/xeno_defines.dm
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,8 @@
/datum/caste_datum/hivelord = 1,
/datum/caste_datum/carrier = 1
)
/// Assoc list of free slots currently used by specific castes
var/list/used_free_slots
/// Assoc list of slots currently used by specific castes (for calculating free_slot usage)
var/list/used_slots = list()
/// list of living tier2 xenos
var/list/tier_2_xenos = list()
/// list of living tier3 xenos
Expand Down Expand Up @@ -473,6 +473,12 @@
else if(xeno.tier == 3)
tier_3_xenos -= xeno

// Only handle free slots if the xeno is not in tdome
if(!is_admin_level(xeno.z))
var/selected_caste = GLOB.xeno_datum_list[xeno.caste_type]?.type
if(used_slots[selected_caste])
used_slots[selected_caste]--

if(!light_mode)
hive_ui.update_xeno_counts()
hive_ui.xeno_removed(xeno)
Expand Down Expand Up @@ -783,30 +789,31 @@
),
)

var/burrowed_factor = min(stored_larva, sqrt(4*stored_larva))
burrowed_factor = round(burrowed_factor)

var/used_tier_2_slots = length(tier_2_xenos)
var/used_tier_3_slots = length(tier_3_xenos)
for(var/caste_path in used_free_slots)
var/used_count = used_free_slots[caste_path]
if(!used_count)
continue
var/datum/caste_datum/C = caste_path
switch(initial(C.tier))
if(2) used_tier_2_slots -= used_count
if(3) used_tier_3_slots -= used_count

for(var/caste_path in free_slots)
var/slot_count = free_slots[caste_path]
if(!slot_count)
var/slots_free = free_slots[caste_path]
var/slots_used = used_slots[caste_path]
var/datum/caste_datum/current_caste = caste_path
if(slots_used)
// Don't count any free slots in use
switch(initial(current_caste.tier))
if(2)
used_tier_2_slots -= min(slots_used, slots_free)
if(3)
used_tier_3_slots -= min(slots_used, slots_free)
if(slots_free <= slots_used)
continue
var/datum/caste_datum/C = caste_path
switch(initial(C.tier))
if(2) slots[TIER_2][GUARANTEED_SLOTS][initial(C.caste_type)] = slot_count
if(3) slots[TIER_3][GUARANTEED_SLOTS][initial(C.caste_type)] = slot_count
// Display any free slots available
switch(initial(current_caste.tier))
if(2)
slots[TIER_2][GUARANTEED_SLOTS][initial(current_caste.caste_type)] = slots_free - slots_used
if(3)
slots[TIER_3][GUARANTEED_SLOTS][initial(current_caste.caste_type)] = slots_free - slots_used

var/effective_total = burrowed_factor
var/burrowed_factor = min(stored_larva, sqrt(4*stored_larva))
var/effective_total = round(burrowed_factor)
for(var/mob/living/carbon/xenomorph/xeno as anything in totalXenos)
if(xeno.counts_for_slots)
effective_total++
Expand Down