Unhardcode species age ranges (#11979)
This commit is contained in:
@@ -34,5 +34,5 @@ public sealed class HumanoidComponent : SharedHumanoidComponent
|
|||||||
|
|
||||||
// Couldn't these be somewhere else?
|
// Couldn't these be somewhere else?
|
||||||
[ViewVariables] public Gender Gender = default!;
|
[ViewVariables] public Gender Gender = default!;
|
||||||
[ViewVariables] public int Age = HumanoidCharacterProfile.MinimumAge;
|
[ViewVariables] public int Age = 18;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ public sealed partial class HumanoidSystem : SharedHumanoidSystem
|
|||||||
{
|
{
|
||||||
var identity = Identity.Entity(component.Owner, EntityManager);
|
var identity = Identity.Entity(component.Owner, EntityManager);
|
||||||
var species = GetSpeciesRepresentation(component.Species).ToLower();
|
var species = GetSpeciesRepresentation(component.Species).ToLower();
|
||||||
var age = GetAgeRepresentation(component.Age);
|
var age = GetAgeRepresentation(component.Species, component.Age);
|
||||||
|
|
||||||
args.PushText(Loc.GetString("humanoid-appearance-component-examine", ("user", identity), ("age", age), ("species", species)));
|
args.PushText(Loc.GetString("humanoid-appearance-component-examine", ("user", identity), ("age", age), ("species", species)));
|
||||||
}
|
}
|
||||||
@@ -498,14 +498,23 @@ public sealed partial class HumanoidSystem : SharedHumanoidSystem
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetAgeRepresentation(int age)
|
public string GetAgeRepresentation(string species, int age)
|
||||||
{
|
{
|
||||||
return age switch
|
_prototypeManager.TryIndex<SpeciesPrototype>(species, out var speciesPrototype);
|
||||||
|
|
||||||
|
if (speciesPrototype == null)
|
||||||
{
|
{
|
||||||
<= 30 => Loc.GetString("identity-age-young"),
|
Logger.Error("Tried to get age representation of species that couldn't be indexed: " + species);
|
||||||
> 30 and <= 60 => Loc.GetString("identity-age-middle-aged"),
|
return Loc.GetString("identity-age-young");
|
||||||
> 60 => Loc.GetString("identity-age-old")
|
}
|
||||||
};
|
|
||||||
|
if (age < speciesPrototype.YoungAge)
|
||||||
|
return Loc.GetString("identity-age-young");
|
||||||
|
|
||||||
|
if (age < speciesPrototype.OldAge)
|
||||||
|
Loc.GetString("identity-age-middle-aged");
|
||||||
|
|
||||||
|
return Loc.GetString("identity-age-old");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void EnsureDefaultMarkings(EntityUid uid, HumanoidComponent? humanoid)
|
private void EnsureDefaultMarkings(EntityUid uid, HumanoidComponent? humanoid)
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ public class IdentitySystem : SharedIdentitySystem
|
|||||||
InventoryComponent? inventory=null,
|
InventoryComponent? inventory=null,
|
||||||
HumanoidComponent? appearance=null)
|
HumanoidComponent? appearance=null)
|
||||||
{
|
{
|
||||||
int age = HumanoidCharacterProfile.MinimumAge;
|
int age = 18;
|
||||||
Gender gender = Gender.Epicene;
|
Gender gender = Gender.Epicene;
|
||||||
|
|
||||||
// Always use their actual age and gender, since that can't really be changed by an ID.
|
// Always use their actual age and gender, since that can't really be changed by an ID.
|
||||||
|
|||||||
@@ -95,6 +95,31 @@ public sealed class SpeciesPrototype : IPrototype
|
|||||||
|
|
||||||
[DataField("sexes")]
|
[DataField("sexes")]
|
||||||
public List<Sex> Sexes { get; } = new List<Sex>(){ Sex.Male, Sex.Female };
|
public List<Sex> Sexes { get; } = new List<Sex>(){ Sex.Male, Sex.Female };
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Characters younger than this are too young to be hired by Nanotrasen.
|
||||||
|
/// <summary>
|
||||||
|
[DataField("minAge")]
|
||||||
|
public int MinAge = 18;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Characters younger than this appear young.
|
||||||
|
/// <summary>
|
||||||
|
[DataField("youngAge")]
|
||||||
|
public int YoungAge = 30;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Characters older than this appear old. Characters in between young and old age appear middle aged.
|
||||||
|
/// </summary>
|
||||||
|
[DataField("oldAge")]
|
||||||
|
public int OldAge = 60;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Characters cannot be older than this. Only used for restrictions...
|
||||||
|
/// although imagine if ghosts could age people WYCI...
|
||||||
|
/// <summary>
|
||||||
|
[DataField("maxAge")]
|
||||||
|
public int MaxAge = 120;
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum SpeciesNaming : byte
|
public enum SpeciesNaming : byte
|
||||||
|
|||||||
@@ -24,8 +24,6 @@ namespace Content.Shared.Preferences
|
|||||||
[Serializable, NetSerializable]
|
[Serializable, NetSerializable]
|
||||||
public sealed class HumanoidCharacterProfile : ICharacterProfile
|
public sealed class HumanoidCharacterProfile : ICharacterProfile
|
||||||
{
|
{
|
||||||
public const int MinimumAge = 18;
|
|
||||||
public const int MaximumAge = 120;
|
|
||||||
public const int MaxNameLength = 32;
|
public const int MaxNameLength = 32;
|
||||||
public const int MaxDescLength = 512;
|
public const int MaxDescLength = 512;
|
||||||
|
|
||||||
@@ -110,7 +108,7 @@ namespace Content.Shared.Preferences
|
|||||||
"John Doe",
|
"John Doe",
|
||||||
"",
|
"",
|
||||||
SharedHumanoidSystem.DefaultSpecies,
|
SharedHumanoidSystem.DefaultSpecies,
|
||||||
MinimumAge,
|
18,
|
||||||
Sex.Male,
|
Sex.Male,
|
||||||
Gender.Male,
|
Gender.Male,
|
||||||
HumanoidCharacterAppearance.Default(),
|
HumanoidCharacterAppearance.Default(),
|
||||||
@@ -136,7 +134,7 @@ namespace Content.Shared.Preferences
|
|||||||
"John Doe",
|
"John Doe",
|
||||||
"",
|
"",
|
||||||
species,
|
species,
|
||||||
MinimumAge,
|
18,
|
||||||
Sex.Male,
|
Sex.Male,
|
||||||
Gender.Male,
|
Gender.Male,
|
||||||
HumanoidCharacterAppearance.DefaultWithSpecies(species),
|
HumanoidCharacterAppearance.DefaultWithSpecies(species),
|
||||||
@@ -172,15 +170,16 @@ namespace Content.Shared.Preferences
|
|||||||
var random = IoCManager.Resolve<IRobustRandom>();
|
var random = IoCManager.Resolve<IRobustRandom>();
|
||||||
|
|
||||||
var sex = Sex.Unsexed;
|
var sex = Sex.Unsexed;
|
||||||
|
var age = 18;
|
||||||
if (prototypeManager.TryIndex<SpeciesPrototype>(species, out var speciesPrototype))
|
if (prototypeManager.TryIndex<SpeciesPrototype>(species, out var speciesPrototype))
|
||||||
{
|
{
|
||||||
sex = random.Pick(speciesPrototype.Sexes);
|
sex = random.Pick(speciesPrototype.Sexes);
|
||||||
|
age = random.Next(speciesPrototype.MinAge, speciesPrototype.OldAge); // people don't look and keep making 119 year old characters with zero rp, cap it at middle aged
|
||||||
}
|
}
|
||||||
|
|
||||||
var gender = sex == Sex.Male ? Gender.Male : Gender.Female;
|
var gender = sex == Sex.Male ? Gender.Male : Gender.Female;
|
||||||
|
|
||||||
var name = GetName(species, gender);
|
var name = GetName(species, gender);
|
||||||
var age = random.Next(MinimumAge, MaximumAge);
|
|
||||||
|
|
||||||
return new HumanoidCharacterProfile(name, "", species, age, sex, gender, HumanoidCharacterAppearance.Random(species, sex), ClothingPreference.Jumpsuit, BackpackPreference.Backpack,
|
return new HumanoidCharacterProfile(name, "", species, age, sex, gender, HumanoidCharacterAppearance.Random(species, sex), ClothingPreference.Jumpsuit, BackpackPreference.Backpack,
|
||||||
new Dictionary<string, JobPriority>
|
new Dictionary<string, JobPriority>
|
||||||
@@ -354,8 +353,6 @@ namespace Content.Shared.Preferences
|
|||||||
|
|
||||||
public void EnsureValid()
|
public void EnsureValid()
|
||||||
{
|
{
|
||||||
var age = Math.Clamp(Age, MinimumAge, MaximumAge);
|
|
||||||
|
|
||||||
var prototypeManager = IoCManager.Resolve<IPrototypeManager>();
|
var prototypeManager = IoCManager.Resolve<IPrototypeManager>();
|
||||||
|
|
||||||
prototypeManager.TryIndex<SpeciesPrototype>(Species, out var speciesPrototype);
|
prototypeManager.TryIndex<SpeciesPrototype>(Species, out var speciesPrototype);
|
||||||
@@ -368,13 +365,15 @@ namespace Content.Shared.Preferences
|
|||||||
_ => Sex.Male // Invalid enum values.
|
_ => Sex.Male // Invalid enum values.
|
||||||
};
|
};
|
||||||
|
|
||||||
// ensure the species can be that sex
|
// ensure the species can be that sex and their age fits the founds
|
||||||
|
var age = Age;
|
||||||
if (speciesPrototype != null)
|
if (speciesPrototype != null)
|
||||||
{
|
{
|
||||||
if (!speciesPrototype.Sexes.Contains(sex))
|
if (!speciesPrototype.Sexes.Contains(sex))
|
||||||
{
|
{
|
||||||
sex = speciesPrototype.Sexes[0];
|
sex = speciesPrototype.Sexes[0];
|
||||||
}
|
}
|
||||||
|
age = Math.Clamp(Age, speciesPrototype.MinAge, speciesPrototype.MaxAge);
|
||||||
}
|
}
|
||||||
|
|
||||||
var gender = Gender switch
|
var gender = Gender switch
|
||||||
|
|||||||
Reference in New Issue
Block a user