public void CreateComps() { apparentGrowth = false; diagnosed = false; actualComps.Clear(); apparentComps.Clear(); var list = def.symptomsPossible.Select(x => x); int count = def.symptomsCount.Lerped(Rand.Value * Rand.Value); for (int i = 0; i < count; i++) { if (!list.Any()) { break; } CancerCompDef def = list.RandomElementByWeight(x => x.weight); CancerComp comp = CreateComp(def); if (comp == null) { continue; } if (!comp.IsValid()) { continue; } actualComps.Add(comp); list = list.Where(x => x.tag != def.tag); } }
public override void Tended(float quality, int batchPosition) { diagnosed = true; HashSet <string> apparentTags = new HashSet <string>(); foreach (CancerComp comp in actualComps) { bool mistake = Rand.Range(0f, def.diagnoseDifficulty) > quality; if (!mistake) { apparentComps.Add(comp); apparentTags.Add(comp.def.tag); continue; } // 50% do diagnose wrongly, 50% to not notice if (Rand.Value < 0.5f) { CancerCompDef mistakenDef = def.symptomsPossible.OfType <CancerCompDef>().Where(x => !apparentTags.Contains(x.tag)).RandomElementWithFallback(); if (mistakenDef == null) { continue; } CancerComp mistakenComp = CreateComp(mistakenDef); if (mistakenComp == null) { continue; } apparentComps.Add(mistakenComp); } } }
public CancerComp CreateComp(CancerCompDef def) { CancerComp comp = Activator.CreateInstance(def.compClass) as CancerComp; if (comp == null) { return(null); } comp.def = def; comp.cancer = this; return(comp); }
public override void Tended(float quality, int batchPosition) { // XXX Obsolete? diagnosed = true; HashSet <string> apparentTags = new HashSet <string>(); apparentComps.Clear(); foreach (CancerComp comp in actualComps) { float score = def.diagnoseDifficulty.RandomInRange; bool mistake = score > quality; bool unsure = Math.Abs(score - quality) < def.diagnoseUnsureWindow; if (!mistake) { CancerComp copy = comp.CreateCopy(); copy.doctorIsUnsure = unsure; apparentComps.Add(comp); apparentTags.Add(comp.def.tag); continue; } // 50% do diagnose wrongly, 50% to not notice if (Rand.Value < 0.5f) { CancerCompDef mistakenDef = def.symptomsPossible.OfType <CancerCompDef>().Where(x => !apparentTags.Contains(x.tag)).RandomElementWithFallback(); if (mistakenDef == null) { continue; } CancerComp mistakenComp = CreateComp(mistakenDef); if (mistakenComp == null) { continue; } mistakenComp.doctorIsUnsure = unsure; apparentComps.Add(mistakenComp); apparentTags.Add(mistakenComp.def.tag); } } apparentGrowth = apparentTags.Contains("growthSpeed"); }