Build realistic medieval family relationships with age-appropriate logic and inheritance patterns
using Omnivael.MedievalBio;
// Generate a character with family
var context = new NpcContext
{
Id = "merchant_001",
HomeTier = SettlementTier.Town,
TownLevelScore = 65,
Faction = FactionType.Civilian,
GenerateExtendedFamily = true
};
var character = CharacterBioGenerator.Generate(context);
// Access family members
var parents = character.Family.Parents;
var spouse = character.Family.Spouse;
var children = character.Family.Children;
Debug.Log($"Character: {character.Profile.DisplayName}");
Debug.Log($"Parents: {parents.Count}");
Debug.Log($"Spouse: {(spouse != null ? spouse.DisplayName : "None")}");
Debug.Log($"Children: {children.Count}");
// Marriage likelihood based on character age
Age 16-25: 20% chance of being unmarried
Age 26-35: 70% chance of being married
Age 36-45: 85% chance of being married
Age 46+: 60% chance of being married (higher widow rate)
// Generate a noble family with specific parameters
var nobleContext = new NpcContext
{
Id = "lord_thornbury",
HomeTier = SettlementTier.City,
TownLevelScore = 85,
Faction = FactionType.Noble,
AgeOverride = 45,
GenderOverride = Gender.Male
};
var noble = CharacterBioGenerator.Generate(nobleContext);
// Access detailed family information
Debug.Log($"Lord: {noble.Profile.DisplayName}");
Debug.Log($"Age: {noble.Profile.Age}");
foreach (var parent in noble.Family.Parents)
{
Debug.Log($"Parent: {parent.DisplayName} (Age: {parent.Age})");
Debug.Log($"Parent Occupation: {parent.Occupation}");
}
if (noble.Family.Spouse != null)
{
Debug.Log($"Spouse: {noble.Family.Spouse.DisplayName} (Age: {noble.Family.Spouse.Age})");
}
foreach (var child in noble.Family.Children)
{
Debug.Log($"Child: {child.DisplayName} (Age: {child.Age})");
Debug.Log($"Child Occupation: {child.Occupation}");
}
// Manual family tree generation
var familyGenerator = new EnhancedFamilyTreeGenerator();
var mainCharacter = new PersonProfile { /* your character data */ };
// Generate specific family members
var parents = familyGenerator.GenerateParents(mainCharacter);
var spouse = familyGenerator.GenerateSpouse(mainCharacter);
var children = familyGenerator.GenerateChildren(mainCharacter, spouse);
// Create custom family tree
var familyTree = new FamilyTree
{
MainCharacter = mainCharacter,
Parents = parents,
Spouse = spouse,
Children = children
};
public class DynamicNpcSpawner : MonoBehaviour
{
public void SpawnFamilyGroup(SettlementTier tier, Vector3 location)
{
// Generate family patriarch/matriarch
var elderContext = new NpcContext
{
Id = $"elder_{location.GetHashCode()}",
HomeTier = tier,
TownLevelScore = GetSettlementScore(location),
Faction = FactionType.Civilian,
AgeOverride = Random.Range(40, 65)
};
var elder = CharacterBioGenerator.Generate(elderContext);
SpawnNpc(elder, location);
// Spawn family members
foreach (var child in elder.Family.Children)
{
if (child.Age >= 16) // Only spawn adult children
{
SpawnNpc(child, location + Random.insideUnitSphere * 5f);
}
}
if (elder.Family.Spouse != null)
{
SpawnNpc(elder.Family.Spouse, location + Vector3.right * 2f);
}
}
}