예제 #1
0
        /// <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);
                }
            }
        }
예제 #2
0
 /// ----------------------------------------------------------------------------
 /// <summary>
 /// Set the availability for a particular trait.
 /// </summary>
 /// <param name="trait">The trait to set the availability-affect of.</param>
 /// <param name="availability">The affect on availability of this trait.</param>
 /// ----------------------------------------------------------------------------
 public void SetRestriction(string trait, RaceAvailability availability)
 {
     this.restrictions[trait] = availability;
 }