diff --git a/code/modules/mob/living/carbon/xenomorph/Evolution.dm b/code/modules/mob/living/carbon/xenomorph/Evolution.dm index d8767ffce87a..332f8d1778dd 100644 --- a/code/modules/mob/living/carbon/xenomorph/Evolution.dm +++ b/code/modules/mob/living/carbon/xenomorph/Evolution.dm @@ -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) @@ -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++ diff --git a/code/modules/mob/living/carbon/xenomorph/Xenomorph.dm b/code/modules/mob/living/carbon/xenomorph/Xenomorph.dm index 368dded9c17e..90c22e19c483 100644 --- a/code/modules/mob/living/carbon/xenomorph/Xenomorph.dm +++ b/code/modules/mob/living/carbon/xenomorph/Xenomorph.dm @@ -499,11 +499,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) @@ -706,16 +702,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 diff --git a/code/modules/mob/living/carbon/xenomorph/xeno_defines.dm b/code/modules/mob/living/carbon/xenomorph/xeno_defines.dm index 1de164fccc85..a74fa7413804 100644 --- a/code/modules/mob/living/carbon/xenomorph/xeno_defines.dm +++ b/code/modules/mob/living/carbon/xenomorph/xeno_defines.dm @@ -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 @@ -479,6 +479,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) @@ -789,30 +795,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++