Skip to content

Clans, roles and succession from code

A clan decides who sits in its court, how it starts and ends, and who it stands beside or under. This page lists the calls that change a clan, and the hooks that change who inherits a seat. The ideas behind them are on Clans, roles and succession.

You want to give someone a seat, found or end a clan, set a relation, or take part in succession from your own code. The clan calls below write to the world, so the host runs them. A multiplayer client gets one warning and no change. The Scripting overview explains why.

Both calls are on Clan (Clans/Clan.cs). Get a clan from IM.GetClan(nameOrId) or from actor.Clan, and a role from IM.GetRole(nameOrId).

Signature What it does
bool Appoint(Actor actor, Role role, bool replace = false) Gives a court role of this clan to an actor, who joins the clan first when needed. When every seat is taken, replace makes the holder listed last by GetHolders leave, which is the youngest. Without it nothing changes. A personal role is simply given. false for a null actor or role, a court role without seats, or every seat taken without replace.
bool Appoint(Actor actor, Role role, Actor replacing) Exactly replacing leaves the seat when every seat is taken. When they do not hold it, nothing changes and the answer is false.
bool Appoint(Actor actor, Role role, in ActorRanking leaves, DiceRoll roll = default) leaves says which holder leaves first.
bool Appoint(Actor actor, string roleNameOrId, bool replace = false) By the role’s name or ID. false when no role has it.
int Dismiss(Role role) Takes the role from every living member of this clan who holds it. Returns how many lost it.

The overloads that take a replacing actor or a ranking also have an out Actor left form that tells who left.

A seat that empties raises IM.onRoleVacant. Actor.SetRole gives a seat only when one is free. Appoint is the call that can make room.

Other reads on the clan: Head (the living holder of the highest-ranking court role), GetHolder(string roleNameOrId), GetHolders(Role role, List<Actor> results), SeatsOf(Role), FreeSeats(Role), GetMembers(string roleFilter, List<Actor> results, bool includeDead = false), Members, MemberCount, LivingMemberCount.

Signature What it does
static Clan Found(string name, ClanOptions options = null) Founds a new clan and adds it to the game. Returns null (one Log line) when a clan that is not disbanded already has the name. Raises IM.onClanFounded.
Clan FoundBranch(string name, Actor founder, ClanOptions options = null) Founds a clan that stands under this one.
bool Disband(DisbandTerms terms = null) Its living members leave, the clans under it go where the terms or the world’s rules say, and it is marked IsDisbanded. It stays in the game and re-forms when someone joins. false when it is disbanded already.
bool MergeInto(Clan other, MergeTerms terms = null) Merges this clan into other and ends it. false for null, the clan itself, or a clan already disbanded.
bool SetOverlord(Clan newOverlord) Puts this clan under another, or with null makes it stand alone. A loop is refused.

ClanOptions holds what a new clan starts with: Overlord, Founder, Story, Motto, Colour, SecondColour, Emblem, Culture, Policies. Every value may stay unset.

MergeTerms has three fields with defaults: Members = MergeMembers.Join, Subjects = MergeSubjects.Follow, Numbers = MergeNumbers.Add. The other values are MergeMembers.Leave, MergeSubjects.BecomeFree and MergeNumbers.Keep. DisbandTerms.Subjects is an EndedSubjects?: BecomeFree, GoToItsOverlord, or null for what the world’s rules say.

A call made inside a listener of another clan operation is carried out after that operation, and true then means accepted. IM.AddClan also raises IM.onClanFounded once the clan is in the game. Clan.Create(...) also exists, and returns the clan that already has the name instead of a new one.

Example, not compiled.

var branch = parent.FoundBranch("Northern Branch", founder);
if (branch == null) return; // the name is taken by a clan that is not disbanded
old.MergeInto(branch, new MergeTerms { Numbers = MergeNumbers.Keep });

A relation is a kind of tie between clans, such as an alliance, a feud or a vassal bond. The kind comes from the database.

Signature What it does
bool Relate(Clan other, string kindNameOrId, RelationTerms terms = default) Starts a relation. A one-way kind is held by this clan over the other. false for an unknown kind, a null or same clan, a kind between characters, or off the host.
int EndRelation(Clan other, string kindNameOrId = null, RelationEndCause cause = RelationEndCause.Ended) Ends relations of a kind (null: every kind) with other (null: any clan), either way round. Returns how many ended.
bool HasRelation(Clan other = null, string kindNameOrId = null) True when such a relation exists, either way round.
bool RelationWith(Clan other, string kindNameOrId, out ClanRelation relation) The relation, when there is one.
int GetRelations(List<ClanRelation> results, string kindNameOrId = null) Fills results (cleared first).

RelationTerms has Forever, ForDays(int), Until(GameDate) and UntilDay(int), and default means as the kind says. RelationEndCause is RanOut, Ended, Replaced, ClanEnded or TermsBroken. The events are IM.onClanRelationStarted and IM.onClanRelationEnded.

Succession is a static class in Clans/Succession/Succession.cs. A seat passes on by itself when its holder dies or steps down. These are the hooks, from light to heavy.

Hook What it does
Actor.SetHeir(Actor) Chooses the heir of one actor’s court seat.
static event Func<Actor, Role, Actor, bool> CanInherit Asked for every person who could inherit: holder, role, candidate. Return false to refuse the candidate. A refused person keeps their place for their children.
static void Register(string method, SuccessionMethod pick) Registers the method a rule of kind Custom names in SuccessionRule.Method. SuccessionMethod is void (Actor holder, Role role, Clan clan, List<Actor> line).
static void Unregister(string method) Removes it.
IM.onRoleVacant Appoint someone when a seat empties, with Clan.Appoint.
static bool Fill(Clan clan, Role role, Actor previousHolder) Fills an empty seat from the previous holder’s line. false when the seat has no free place, the role is not inherited or nobody is in line.
static void Refresh() Works every heir out again on its next read. Call it after you change what a hook reads.

The reads: GetLine(Actor holder, List<HeirCandidate> results, int max = 10) and its Role overload, Explain(...) (also lists the people passed over, with the reason), RuleFor(Clan, Role) and Version.

Keep CanInherit listeners cheap and free of side effects. They are asked whenever a line is worked out, which includes menus and tooltips, and not only when a role passes on. Hooks are cleared when a Play session starts, so add them from a component or an AfterAssembliesLoaded method.

Two events report what happened. Both carry a SuccessionInfo with Clan, Role, Previous, Heir and Cause.

Event Raised when
IM.onRoleInherited A role passed on. Also for a personal role.
IM.onRoleVacant A seat became empty. Heir is null. Never for a personal role.

SuccessionCause is Death, DeathWithoutInheritance, Abdication, Left, Promoted or Code. Guard against loops when a vacancy listener appoints someone: the appointee’s old seat can become vacant in turn.

What you see Why What to do
Appoint returns false The role has no seats, or every seat is taken. Pass replace: true, or name who leaves.
Found returns null A clan that is not disbanded has that name. Pick another name. A name held only by disbanded clans is free.
Menus feel slow after you add a CanInherit listener It is asked whenever a line is worked out, menus and tooltips included. Keep it cheap, and call Succession.Refresh() when the data it reads changes.
A vacancy loop A vacancy listener appoints someone whose old seat becomes vacant. Guard the listener.