/// <summary> /// <para>Use this overload if you want to specify a custom skin, and specify the /// family it belongs to so that something reasonable gets displayed if the skin /// can't be loaded.</para> /// </summary> /// <param name='skinFamily'>An AnimalSkinFamily value that specifies the skin to use for this organism if the custom one can't be loaded.</param> /// <param name='skin'>The name of the assembly the contains the skin you want to use.</param> public AnimalSkinAttribute(AnimalSkinFamily skinFamily, string skin) { SkinFamily = skinFamily; Skin = skin; }
/// <summary> /// <para>Use this constructor if you don't have a custom skin you want to use with /// your organism.</para> /// </summary> /// <param name='skinFamily'>An AnimalSkinFamily value that specifies the skin to use for this organism.</param> public AnimalSkinAttribute(AnimalSkinFamily skinFamily) { Skin = string.Empty; SkinFamily = skinFamily; }
/// <summary> /// <para>Use this constructor if you don't have a custom skin you want to use with /// your organism.</para> /// </summary> /// <param name='skinFamily'>An AnimalSkinFamily value that specifies the skin to use for this organism.</param> public AnimalSkinAttribute(AnimalSkinFamily skinFamily) { this.skinFamily = skinFamily; }
/// <summary> /// Creates a new Animal species from a CLR Type object. Initializes /// the new species properties based on various attributes on the Type. /// </summary> /// <param name="clrType">The type for the organism class.</param> public AnimalSpecies(Type clrType) : base(clrType) { int totalPoints = 0; Debug.Assert(clrType != null, "Null type passed to AnimalSpecies"); Debug.Assert(typeof(Animal).IsAssignableFrom(clrType)); AnimalSkinAttribute skinAttribute = (AnimalSkinAttribute) Attribute.GetCustomAttribute(clrType, typeof(AnimalSkinAttribute)); if (skinAttribute != null) { skinFamily = skinAttribute.SkinFamily; animalSkin = skinAttribute.Skin; } CarnivoreAttribute carnivoreAttribute = (CarnivoreAttribute) Attribute.GetCustomAttribute(clrType, typeof(CarnivoreAttribute)); if (carnivoreAttribute == null) { throw new AttributeRequiredException("CarnivoreAttribute"); } isCarnivore = carnivoreAttribute.IsCarnivore; EatingSpeedPointsAttribute eatingSpeedAttribute = (EatingSpeedPointsAttribute) Attribute.GetCustomAttribute(clrType, typeof(EatingSpeedPointsAttribute)); if (eatingSpeedAttribute == null) { throw new AttributeRequiredException("EatingSpeedPointsAttribute"); } eatingSpeedPerUnitRadius = eatingSpeedAttribute.EatingSpeedPerUnitRadius; totalPoints += eatingSpeedAttribute.Points; AttackDamagePointsAttribute attackDamageAttribute = (AttackDamagePointsAttribute) Attribute.GetCustomAttribute(clrType, typeof(AttackDamagePointsAttribute)); if (attackDamageAttribute == null) { throw new AttributeRequiredException("AttackDamagePointsAttribute"); } if (IsCarnivore) { maximumAttackDamagePerUnitRadius = (int) ((double) attackDamageAttribute.MaximumAttackDamagePerUnitRadius * EngineSettings.CarnivoreAttackDefendMultiplier); } else { maximumAttackDamagePerUnitRadius = attackDamageAttribute.MaximumAttackDamagePerUnitRadius; } totalPoints += attackDamageAttribute.Points; DefendDamagePointsAttribute defendDamageAttribute = (DefendDamagePointsAttribute) Attribute.GetCustomAttribute(clrType, typeof(DefendDamagePointsAttribute)); if (defendDamageAttribute == null) { throw new AttributeRequiredException("DefendDamagePointsAttribute"); } if (IsCarnivore) { maximumDefendDamagePerUnitRadius = (int) ((double) defendDamageAttribute.MaximumDefendDamagePerUnitRadius * EngineSettings.CarnivoreAttackDefendMultiplier); } else { maximumDefendDamagePerUnitRadius = defendDamageAttribute.MaximumDefendDamagePerUnitRadius; } totalPoints += defendDamageAttribute.Points; MaximumEnergyPointsAttribute energyAttribute = (MaximumEnergyPointsAttribute) Attribute.GetCustomAttribute(clrType, typeof(MaximumEnergyPointsAttribute)); if (energyAttribute == null) { throw new AttributeRequiredException("MaximumEnergyPointsAttribute"); } totalPoints += energyAttribute.Points; MaximumSpeedPointsAttribute speedAttribute = (MaximumSpeedPointsAttribute) Attribute.GetCustomAttribute(clrType, typeof(MaximumSpeedPointsAttribute)); if (speedAttribute == null) { throw new AttributeRequiredException("MaximumSpeedPointsAttribute"); } totalPoints += speedAttribute.Points; maximumSpeed = speedAttribute.MaximumSpeed; CamouflagePointsAttribute camouflageAttribute = (CamouflagePointsAttribute) Attribute.GetCustomAttribute(clrType, typeof(CamouflagePointsAttribute)); if (camouflageAttribute == null) { throw new AttributeRequiredException("CamouflagePointsAttribute"); } totalPoints += camouflageAttribute.Points; invisibleOdds = camouflageAttribute.InvisibleOdds; EyesightPointsAttribute eyesightAttribute = (EyesightPointsAttribute) Attribute.GetCustomAttribute(clrType, typeof(EyesightPointsAttribute)); if (eyesightAttribute == null) { throw new AttributeRequiredException("EyesightPointsAttribute"); } totalPoints += eyesightAttribute.Points; eyesightRadius = eyesightAttribute.EyesightRadius; if (totalPoints > EngineSettings.MaxAvailableCharacteristicPoints) { throw new TooManyPointsException(); } }