/// <summary> /// Updates the collection for the given race and tech level. /// Note this does not remove any existing components from the collection. /// </summary> /// <param name="newRace"></param> /// <param name="newTech"></param> public void DetermineRaceComponents(Race newRace, TechLevel newTech) { race = newRace; tech = newTech.Clone(); if (race == null) { throw new System.NullReferenceException(); } if (tech == null) { throw new System.NullReferenceException(); } // go through the AllCompoents list foreach (Component component in allComponents.GetAll.Values) { // first check the required tech level if (tech < component.RequiredTech) { continue; } if (Contains(component.Name)) { continue; } // check if the component is restricted by this race's Primary or Secondary traits. bool restricted = false; foreach (string trait in AllTraits.TraitKeys) { bool hasTrait = race.HasTrait(trait); RaceAvailability availability = component.Restrictions.Availability(trait); if (availability == RaceAvailability.not_available && hasTrait) { restricted = true; break; } if (availability == RaceAvailability.required && !hasTrait) { restricted = true; break; } } if (!restricted) { Add(component.Name, component); } } }