All characters of a faction have an index based on when they were created. The first character defined for the faction in descr_strat.txt has index 0, the second character has index 1, and so on. Children and adoptees, who are added to the faction later in time, must necessarily have higher indices than their older siblings, who in turn have higher indices than their parents, who have higher indices than their grandparents, and so on. Therefore, we can think of the list of characters by index as a sort of "order of precedence" that we can use for inheritable stuff like titles - the character with the lowest index will have the highest order of precedence or "claim to the title". This is actually the same system the game uses to assign the next heir, all other things (like authority) being equal.
You will also notice that the CharacterTurnStart event (like all other events) fires in the order of lowest index to highest, e.g. CharacterTurnStart for character 0 fires before that of character 1 and so on. If you use EOP to print a list of characters by index and another list of characters by CharacterTurnStart, the lists should be identical. What this means is that we can use the CharacterTurnStart event to iterate through all characters by index and thus by order of precedence.
We first create a trait that will be given to all
viable heirs. This trait can be visible, as in your "Of the House of Essex" idea, or it can be Hidden, depending on what you want to do with this. Then, we create an ancillary for the title/lordship/whatever. To grant the ancillary, we use CharacterTurnStart to iterate over all characters who have the viable heir trait, we use the I_WorldWideAncillary condition to make the ancillary unique on the map, and we grant the ancillary to the first viable heir who meets the conditions - this character will be the next in line of succession for the ancillary.
export_descr_character_traits.txt |
Code:
Trait house_essex ;this trait identifies everyone who is a viable heir
Characters family
Level house_essex_level_1
Description house_essex_desc
EffectsDescription house_essex_effects_desc
Threshold 1
;[...]
Trigger inheret_house_essex
WhenToTest CharacterTurnStart ;CharacterTurnStart here is a catch-all, as opposed to using CharacterComesOfAge, etc. etc.
Condition FatherTrait house_essex > 0
and not Trait house_essex > 0
Affects house_essex 1 Chance 100
Trigger assume_house_essex ;this trigger accounts for the situations where the player transfers the ancillary to a character who isn't a viable heir or if the entire household of viable heirs dies out
WhenToTest CharacterTurnStart
Condition HasAncType earl_of_essex_type
and not Trait house_essex > 0
Affects house_essex 1 Chance 100
|
export_descr_ancillaries.txt |
Code:
Ancillary earl_of_essex
Type earl_of_essex_type
Transferable 1 ;this is optional, if the ancillary is transferable to characters who don't originally have the house_essex trait, then you can effectively expand the house by ancillary transfer, but the title might still revert to the original lineage due to the order of precedence
Image whatever.tga
ExcludedAncillaries ;perhaps list here other titles that characters aren't allowed to hold at the same time as "Earl of Essex"
Description earl_of_essex_desc
EffectsDescription earl_of_essex_effects_desc
Effect ;whatever
;[...]
Trigger inherit_earl_of_essex
WhenToTest CharacterTurnStart
Condition Trait house_essex > 0
and not I_WorldWideAncillaryExists earl_of_essex ;this is the key bit, this condition doesn't exist for traits but it allows us to make ancillaries unique
;and... whatever other conditions
AcquireAncillary earl_of_essex chance 100
Trigger regenerate_earl_of_essex ;this optional trigger is an example of how you might regenerate the title ancillary if the entire household of viable heirs dies out
WhenToTest CharacterTurnEndInSettlement
Condition SettlementName Essex
and not I_WorldWideAncillaryExists earl_of_essex
;and... whatever other conditions
AcquireAncillary earl_of_essex chance 100
|
That is the general idea. Any refinements you make on this concept will probably be easier in EOP. For example, if you wanted to make the ancillary only inheritable by the eldest surviving son (instead of possibly going to uncles and others higher on the order of precedence), you could create another unique ancillary to designate eldest son (which would be needed because the FatherAnc condition is broken and always returns true). Or... you could just test the character's relationships using EOP. The main virtue of EOP for scripting is the ability to identify arbitrary characters.