From 460a2d8a926d18f679f07361d03006bef1bae22d Mon Sep 17 00:00:00 2001 From: rroqc Date: Mon, 29 Jul 2024 18:19:43 -0300 Subject: [PATCH] Botany reagent cross pollination code improvement and fix (#85329) ## About The Pull Request fixes #83852 Rewrites the code responsible for the pollination reagent selection logic making it more readable and self contained, fixes a bug where plants would repeatedly select reagents they already have for pollination ## Why It's Good For The Game Better code, fixes a bug that would cause reagent cross pollination to take forever in plants with many reagents. ## Changelog :cl: fix: plants no longer select reagent genes they already have while cross pollinating code: improves reagent cross pollination code :cl: --------- Co-authored-by: RafRoq Co-authored-by: Rafael <34388545+RafRoq@users.noreply.github.com> Co-authored-by: Ghom <42542238+Ghommie@users.noreply.github.com> --- code/modules/hydroponics/hydroponics.dm | 10 +--------- code/modules/hydroponics/seeds.dm | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/code/modules/hydroponics/hydroponics.dm b/code/modules/hydroponics/hydroponics.dm index 46865f5bd9b..ed17254fa9b 100644 --- a/code/modules/hydroponics/hydroponics.dm +++ b/code/modules/hydroponics/hydroponics.dm @@ -798,15 +798,7 @@ if(isnull(particles)) particles = new /particles/pollen() if(myseed.instability >= 20 && prob(70) && length(T.myseed.reagents_add)) - var/list/datum/plant_gene/reagent/possible_reagents = list() - for(var/datum/plant_gene/reagent/reag in T.myseed.genes) - possible_reagents += reag - var/datum/plant_gene/reagent/reagent_gene = pick(possible_reagents) //Let this serve as a lession to delete your WIP comments before merge. - if(reagent_gene.can_add(myseed)) - if(!reagent_gene.try_upgrade_gene(myseed)) - myseed.genes += reagent_gene.Copy() - myseed.reagents_from_genes() - continue + myseed.perform_reagent_pollination(T.myseed) if(!any_adjacent) particles = null diff --git a/code/modules/hydroponics/seeds.dm b/code/modules/hydroponics/seeds.dm index 13a49b35189..101239d8d31 100644 --- a/code/modules/hydroponics/seeds.dm +++ b/code/modules/hydroponics/seeds.dm @@ -616,3 +616,27 @@ /obj/item/grown/get_plant_seed() return seed + +/obj/item/seeds/proc/perform_reagent_pollination(obj/item/seeds/donor) + var/list/datum/plant_gene/reagent/valid_reagents = list() + for(var/datum/plant_gene/reagent/donor_reagent in donor.genes) + var/repeated = FALSE + for(var/datum/plant_gene/reagent/receptor_reagent in genes) + if(donor_reagent.reagent_id == receptor_reagent.reagent_id) + if(receptor_reagent.rate < donor_reagent.rate) + receptor_reagent.rate = donor_reagent.rate + // sucessful pollination/upgrade, we stop here. + reagents_from_genes() + return + else + repeated = TRUE + break + + if(!repeated) + valid_reagents += donor_reagent + + if(length(valid_reagents)) + // pick a valid reagent that our receptor seed don't have and add the gene to it + var/datum/plant_gene/reagent/selected_reagent = pick(valid_reagents) + genes += selected_reagent + reagents_from_genes()