Model Hierarchy

Quick link to the external model hierarchy documentation: Model Hierarchy

The model hierarchy provides script with a mechanism to query and browse game objects. Model hierarchy objects that represent game entities such as factions, regions or military forces may be accessed by script, usually through event contexts. Each model hierarchy object provides an interface on which calls may be made to query that object. For example, a faction may be queried to determine its name, a settlement may be queried to determine its position, or a military force may be queried to determine its current stance.

In many cases objects may also be queried to access related objects. For example, each faction object provides a faction_leader method which can be called to return a character object representing the faction leader character of that faction. This character object can then be queried like any other character object, including being asked for other related objects such as the military force commanded by the character or the region the character is stood in.

A list of model hierarchy interfaces is given further down this page. To see the list of functions they each provide, visit the external documentation. Each interface section on this page provides a link to the relevant section of the external model hierarchy documentation.

In most circumstances the model hierarchy is read-only. Changes to the game cannot be made through model hierarchy functions - see the episodic_scripting interface for a list of code-provided functions that can effect changes the game model. Certain exceptions exist, such as the modify-ritual interfaces.

The following image illustrates many of the main objects provided by the model hierarchy and how they link together. It is by no means authoritative! See the further down this page, or external documentation, for a full list.

loaded in campaign

Loaded in Campaign Loaded in Campaign
Loaded in Battle Loaded in Battle
Loaded in Frontend Loaded in Frontend
Back to top

Accessing the Model Hierarchy

The model hierarchy is accessed mainly through event contexts. When an event is triggered by the campaign model it provides a context object to any listener scripts that gets called. This context object can provides one or more objects within the model hierarchy, each of which represent objects in the game such as a faction, a settlement, or a character. For example, the context of the FactionTurnStart event provides a faction object representing the faction that is starting its turn, whereas the CharacterLootedSettlement object provides both a character and settlement object.

A list of events and what methods the related context object provides can be found in the external model hierarchy documentation. A list of the various objects that the model hierarchy provides is also given further down this page.

As well as accessing through event contexts, the model script interface which underpins the rest of the model hierarchy may also be accessed at any time by calling cm:model on the episodic_scripting interface.

Example - Accessing the model hierarchy through the FactionTurnStart event:

core:add_listener(
"example_faction_turn_start_listener",
"FactionTurnStart",
true,
function(context)
    -- access the faction starting its turn
    local faction = context:faction();
    
    -- retrieve a character script interface representing the faction's leader
    local faction_leader = faction:faction_leader();
    
    -- output some information about the faction starting its turn and the location of the faction leader
    out("* faction " .. faction:name() .. " is starting its turn, faction leader is at [" .. faction_leader:logical_position_x() .. ", " .. faction_leader:logical_position_y() .. "]");
end,
true
);
faction wh3_main_ksl_the_ice_court is starting its turn, faction leader is at [418, 118]

Example - Accessing the model directly:

local model = cm:model();
out("There are currently " .. model:world():faction_list():num_items() .. " factions in the game");
There are currently 108 factions in the game
Back to top

Object Imperminence

Objects retrieved from the model hierarchy in script are imperminent should not be stored for reference later in time. The game reserves the right to delete objects from memory from time to time, so a model hierarchy object stored over time may find itself invalidated. It is safe to use an object reference taken as a local variable on the tick on which it was taken, unless something happens on that tick to invalidate it (e.g. taking a character reference and then killing it - the character reference is no longer safe to use).

If it is required to access a model hierarchy object over time, then a permanent reference by which the object may be looked up should be stored in place of the object itself. This is often the command-queue index (a unique id for each object of a certain type) but can be a string key.

Example - Bad script that tries to use a reference to an object over time:

This script may work some of the time, but is not safe and will cause intermittent failures on some machines.
-- get a faction
local faction = cm:get_faction("wh_main_emp_empire")
out("The Empire have " .. faction:num_allies() .. " allies")

randomise_alliances()

-- wait one second, and try and re-access faction (BAD)
cm:callback(
    function()
        out("After randomising alliances, The Empire have " .. faction:num_allies() .. " allies")
    end,
    1
)

Example - Good script that looks up the faction by key each time it's used over time:

-- get a faction
local faction_key = "wh_main_emp_empire"
local faction = cm:get_faction(faction_key)
out("The Empire have " .. faction:num_allies() .. " allies")

randomise_alliances()

-- wait one second, look up the faction again from its key and use the new reference (GOOD)
cm:callback(
    function()
        local faction = cm:get_faction(faction_key)
        out("After randomising alliances, The Empire have " .. faction:num_allies() .. " allies")
    end,
    1
)

Active Ritual List

A list of active_ritual script interfaces. This list is mainly accessed from the faction_rituals script interface.


Active Ritual

The active ritual interface represents a ritual, previously cast by a faction, that is currently still active.


Ancillary List

A list of ancillary interfaces.


Ancillary

The ancillary interface provides functionality related to an ancillary character. The interface is provided by the CharacterAncillaryGained script event.


Battle Results

Provides an interface to battle results.


Bonus Values

The bonus values script interface provides access to bonus values for a campaign object such as a character or faction.


Building List

A list of building script interfaces. This is accessible from the garrison_residence script inteface.


Building

A building script interface represents a building constructed in a slot within a settlement.


Campaign AI

The campaign AI script interface provides functionality related to AI systems. It is accessible from the model script interface.


Campaign Mission

A campaign mission script interface represents an active mission in campaign. Not currently used.


Character Details List

A list of character_details script interfaces. Each character_details script interface is a persistent reference to a character.


Character Details

A character details interface is a persistent interface related to character. While the character interface related to an immortal character in game can be destroyed and recreated with a new command-queue-index value, the related character_details interface does not change cqi.


Character List

A list of character script interfaces.


Character

The character script interface represents a character in campaign. This is a key interface which is provided by many events and other interfaces in the model hierarchy.

CHARACTER_SCRIPT_INTERFACE

Custom Resource Cost

The custom resource cost script interface represents a cost in resources. Once created using the episodic_scripting function cm:create_new_custom_resource_cost, the object can be customised and can be used for various purposes.


Custom Unit

The custom unit script interface can be used to set up a custom unit type. A object with this interface is returned by the episodic_scripting function cm:create_custom_unit_from_key.


Custom Effect Bundle

The custom effect bundle interface allows customisation of an existing effect bundle record. The record must be defined in the effect_bundles database table.


Debug Drawing

An interface providing some functionality to draw debug lines. This object will not be available in the retail version on the game.


Effect Bundle List

A list of effect_bundle interfaces.


Effect Bundle

An effect bundle is a collection of effect modifiers, and can be applied to many types of game objects.


Effect List

A list of effect interfaces.


Effect

An effect that provides bonus values via a scope. These can be applied to game objects to produce in-game modifications, usually via an effect_bundle.


Faction List

A list of faction interfaces.


Faction Rituals

The faction rituals interface provides access to lists of rituals associated with a faction.


Faction

The faction script interface represents an in-game faction. This is a key interface and is provided by many events and other interfaces.

FACTION_SCRIPT_INTERFACE

Family Member List

A list of family_member interfaces.


Family Member

The family member script interface represents a character within a family tree. This interface is persistent, even if the related character is destroyed and recreated.


Foreign Slot List

A list of foreign_slot interfaces.


Foreign Slot Manager List

A list of foreign_slot_manager interfaces.


Foreign Slot Manager

A foreign slot manager has ownership of all foreign_slot objects for a faction within a settlement/region. A manager is returned by the various foreign-slot-related events, and from the region script interface.


Foreign Slot

A foreign slot is a building slot owned by a faction in a foreign settlement. This underpins mechanics such as Chaos Cults and Skaven Under-Empires. A foreign slot is owned by a foreign_slot_manager.


Garrison Residence

The garrison residence script interface represents the garrison residence within a settlement. It can be queried to determine information about any military_force present within the garrison, or the siege status of the settlement. There is only one settlement/garrison residence in each region.


God Manager

The god manager script interface grants access to god-related functionality, such as gods and any conflicts between them.


God

A god script interface provides functionality related to a particular god within the god system.


God List

A list of god interfaces.


Military Force Building

A building associated with a horde-type military_force.


Military Force Building List

A list of military_force_building interfaces.


Military Force List

A list of military_force interfaces.


Military Force

A military force interface represents any army or navy on the campaign map, including garrison armies. This is a key interface.


Military Force Slot

A military force slot interface represents a building slot within a horde-type military_force.


Military Force Slot List

A list of military_force_slot interfaces.


Model

The model script interface is the root object of the model hierarchy. It is accessible from many other objects, and can be accessed at any time by calling cm:model.


Null Script Interface

An empty interface, returned in situations where a requested interface doesn't exist.


Pending Battle

The pending battle script interface represents a currently-active battle sequence. The battle may or may not have taken place yet. A pending battle object may be retrieved from various battle-related script events and from the model interface.


Pooled Resource Factor List

A list of pooled_resource_factor interfaces.


Pooled Resource Factor

A pooled resource factor is a means by which a pooled resource may be modified. These are listed in the pooled_resource_factors database table.


Pooled Resource List

A list of pooled_resource interfaces.


Pooled Resource

A pooled resource script interface represents a pooled resource, a design-driven currency of some kind like Oathgold, Grimoires, Skulls etc. Valid pooled resources are listed in the pooled_resources database table.


Province List

A list of province interfaces.


Province Manager

A province manager provides a script interface to access provinces in a list or by key.


Province

A province script interface represents a province on the campaign map, containing one or more regions represented by region script interfaces.


Region Data List

A list of region_data interfaces.


Region Data

A region data represents the base data for a region on the campaign map. This may or may not be represented by a region or sea_region.


Region List

A list of region interfaces.


Region Manager

The region manager is a top-level object which provides information about regions and settlements on the campaign map.


Region

A region interface represents a region on the campaign map. A region is the land area associated with a settlement, and there are one or more regions within each province. The region script interface is a key interface, and is provided by many different script events and other interfaces.

Each region is associated with a region_data script interface, which are also linked to sea_region interfaces.


Resource Transaction

The resource cost of a transaction. Currently associated with an active_ritual interface, indicating the cost of that ritual when performed.


Sea Region List

A list of sea_region interfaces.


Sea Region Manager

A central interface which can be queried for information about sea_region entities in the game. This interface can be accessed from the world script interface.


Sea Region

An interface representing a region of sea. This is linked to a region_data interface.


Settlement

A settlement interface represents a settlement on the campaign map. It is most-commonly accessed through the region interface, and is also related to the garrison_residence interface.


Shared States Manager

A central interface, accessed through the model interface, which can be used to query shared state values. Shared state values are accessible by the campaign model, UI and script, and can be used to empower functionality shared between all three. See also the Shared States section of the episodic_scripting documentation.


Siege

An interface representing an active siege. This can


Slot List

A list of slot interfaces.


Slot

A slot interface represents a building slot in a settlement, within which a building may be constructed (or may already exist). It is related to the military_force_slot interface which represent a building slot within a horde-type military_force.


Unique Agent Details List

A list of unique_agent_details interfaces.


Unique Agent Details

An interface representing the details of a unique agent, such as the Green Knight. A faction interface may be queried for a unique_agent_details_list of unique agents the faction contains. Furthermore, objects with this interface are returned by various unique-agent-related script events.


Unit List

A list of unit interfaces.


Unit

An interface that represents a unit belonging to a military_force.


World

World is a central interface that provides access to a variety of other game objects. It is primarly accessible from the model interface.

Last updated 8/23/2024 4:55:15 PM