crt

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 14, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package crt decodes Total Annihilation: Kingdoms .crt scenario files.

A .crt file accompanies a TA:K map (.tnt) and stores the scripted layer of a scenario: the pre-placed units/objects, the per-player rule engine (each rule a set of conditions guarding a set of actions) and the named rectangular trigger regions referenced by those rules. Multiplayer maps ship an empty stub (no units, nine empty players, no triggers); the campaign and special maps populate every section.

The layout is a direct image of the in-memory C structures, so each unit record carries a fixed 256-byte type and name field followed by a block of 32-bit fields, several of which are uninitialised padding in shipped files.

Index

Constants

View Source
const Signature uint32 = 0x3F800000

Signature is the little-endian uint32 that opens every .crt file. It is the IEEE-754 encoding of the float 1.0, used by the engine as a format marker.

Variables

This section is empty.

Functions

This section is empty.

Types

type Clause

type Clause struct {
	// Opcode selects the condition or action to evaluate.
	Opcode uint32
	// Args holds the five raw 64-byte argument slots verbatim.
	Args [argsPerClause][argSize]byte
}

Clause is a single condition or action: a numeric opcode followed by five fixed-size argument slots.

type File

type File struct {
	// Unknown1 is the header word following the signature; 0 for every shipped
	// map except one hand-edited outlier.
	Unknown1 uint32
	Units    []Unit
	Players  []Player
	Triggers []Trigger
}

File is a decoded .crt scenario.

func Load

func Load(data []byte) (*File, error)

Load decodes a .crt file from raw bytes.

func (*File) RuleCount

func (f *File) RuleCount() int

RuleCount returns the total number of rules across all players.

func (*File) UnitCounts

func (f *File) UnitCounts() map[string]int

UnitCounts returns the number of placements per unit type.

type Player

type Player struct {
	Rules []Rule
}

Player is one scenario player slot and its rule list. Empty slots (the common case) carry no rules.

type Rule

type Rule struct {
	Conditions []Clause
	Actions    []Clause
}

Rule pairs a set of conditions with the actions they fire.

type Trigger

type Trigger struct {
	Name                     string
	Left, Top, Right, Bottom uint32
}

Trigger is a named rectangular region referenced by rule conditions/actions.

type Unit

type Unit struct {
	// Type is the unit/object definition name (e.g. "VERLIEGE", "NPCFARM").
	Type string
	// Name is the per-instance scripting handle; usually empty.
	Name string
	// X, Y, Z are the world position. Y is the vertical (height) axis.
	X, Y, Z uint32
	// Player is the owning player slot (0-based).
	Player uint32
	// HealthPercent, ArmorPercent, WeaponPercent are starting condition,
	// normally 100.
	HealthPercent, ArmorPercent, WeaponPercent uint32
	// Angle is the facing, in the engine's angle units.
	Angle uint32
	// Veteran is the starting veterancy level.
	Veteran uint32
	// FootprintX, FootprintZ are the unit's footprint in map cells.
	FootprintX, FootprintZ uint32
	// Unknown1..3 are undecoded fields, retained for round-trip fidelity.
	Unknown1, Unknown2, Unknown3 uint32
}

Unit is a single pre-placed unit or object.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL