lib

package
v0.0.0-...-3135f88 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2024 License: GPL-2.0 Imports: 15 Imported by: 1

Documentation

Overview

Package lib implements routines for reading data from Command Series game files, and simulating logic of the original games.

Index

Constants

This section is empty.

Variables

Sequence of pairs of arrows pointing at the center of the tile. To be displayed over the objective of a selected unit.

Sequence of concentric circles ending with a light bolt. To be displayed over the location of a skirmish.

View Source
var Computer = Commander{1}
View Source
var Full = Intelligence{0}
View Source
var Limited = Intelligence{1}
View Source
var Player = Commander{0}
View Source
var RGBPalette = [257]color.RGBA{}/* 257 elements not displayed */

An approximation of Atari palette colors + a transparent color as 256.

Functions

func Abs

func Abs[T SignedNumber](i T) T

func Clamp

func Clamp[T constraints.Ordered](v, min, max T) T

func DivRoundUp

func DivRoundUp(n, d int) int

Works only for positive arguments.

func GetPalette

func GetPalette(n int, palette *[8]byte) []color.Color

func InRange

func InRange[T constraints.Ordered](v, min, max T) bool

func LongRangeHexNeighbourOffset

func LongRangeHexNeighbourOffset(i int) (int, int)

func Max

func Max[T constraints.Ordered](i0, i1 T) T

func Min

func Min[T constraints.Ordered](i0, i1 T) T

func ParseSpriteData

func ParseSpriteData(data io.Reader, width, height, scaleX, scaleY, bits int) ([]*image.Paletted, error)

func Rand

func Rand(n int, rnd *rand.Rand) int

func Sign

func Sign[T SignedNumber](v T) int

func SmallMapOffsets

func SmallMapOffsets(i int) (int, int)

func TinyMapOffsets

func TinyMapOffsets(i int) (int, int)

func UnpackFile

func UnpackFile(data io.Reader) ([]byte, error)

Types

type AI

type AI struct {
	// contains filtered or unexported fields
}

func (*AI) ContainsVisibleUnit

func (s *AI) ContainsVisibleUnit(xy UnitCoords) bool

func (*AI) NeighbourScore

func (s *AI) NeighbourScore(arr *[6][8]int, xy UnitCoords, side int) int

score of the location based on occupancy and terrain of neighbouring tiles. arr is one of arrays in Hexes

func (*AI) ResupplyUnit

func (s *AI) ResupplyUnit(unit Unit, supplyLevels *[2]int, sync *MessageSync) Unit

func (*AI) UpdateUnit

func (s *AI) UpdateUnit(weather int, isNight bool, sync *MessageSync) (message MessageFromUnit, quit bool)

type Cities

type Cities []City

Cities contains list of all the cities included in the scenario.

func (*Cities) ReadOwnerAndVictoryPoints

func (c *Cities) ReadOwnerAndVictoryPoints(data io.Reader) error

func (Cities) WriteOwnerAndVictoryPoints

func (c Cities) WriteOwnerAndVictoryPoints(writer io.Writer) error

type City

type City struct {
	// Owner signifies which player is owner of the given city. It may be either 0 or 1.
	Owner int
	// VictoryPoints tells how much points players gain by taking control of the city.
	VictoryPoints int
	// XY are coordinates of the city on the map.
	XY UnitCoords
	// Iff nth bit of the VariantBitmap is 0, the city should be used in nth variant
	// of the scenario.
	VariantBitmap byte
	// Name of the city
	Name string
}

City contains information about a city on the map, as parsed from a {scenario}.TER file.

func ParseCity

func ParseCity(data io.Reader) (City, error)

type ColorSchemes

type ColorSchemes struct {
	// contains filtered or unexported fields
}

func NewColorSchemes

func NewColorSchemes(daytimePalette *[8]byte, nightPalette *[8]byte) *ColorSchemes

func (*ColorSchemes) GetBackgroundForegroundColors

func (c *ColorSchemes) GetBackgroundForegroundColors(colorScheme byte, isNight bool) []color.Color

func (*ColorSchemes) GetMapBackgroundColor

func (c *ColorSchemes) GetMapBackgroundColor(isNight bool) color.Color

type Commander

type Commander struct {
	// contains filtered or unexported fields
}

func (Commander) Int

func (c Commander) Int() int

func (Commander) Other

func (c Commander) Other() Commander

func (Commander) String

func (c Commander) String() string

type CommanderFlags

type CommanderFlags struct {
	PlayerControlled      [2]bool
	PlayerCanSeeUnits     [2]bool
	PlayerHasIntelligence [2]bool
}

func (*CommanderFlags) Deserialize

func (c *CommanderFlags) Deserialize(value uint8)

func (*CommanderFlags) Serialize

func (c *CommanderFlags) Serialize() (result uint8)

func (*CommanderFlags) SwitchSides

func (c *CommanderFlags) SwitchSides()

type DailyUpdate

type DailyUpdate struct {
	DaysRemaining int
	SupplyLevels  [2]int
}

type Data

type Data struct {
	Data0Low    [16]int  // Data[0:16] per unit type (lower 4 bits)
	Data0High   [16]int  // Data[0:16] per unit type (higher 4 bits)
	Data16Low   [16]int  // Data[16:32] per unit type (lower 4 bits)
	Data16High  [16]int  // Data[16:32] per unit type (higher 4 bits)
	Data32      [16]int  // Data[32:48] per unit type
	Data32_8    [16]bool // Data32 & 8
	Data32_32   [16]bool // Data32 & 32
	Data32_64   [16]bool // Data32 & 64
	Data32_128  [16]bool // Data32 & 128
	AttackRange [16]int  // Data32 & 31 (attack range)
	// Score gained by destroying enemy unit of this type
	// Units with score >= 4 are high importance units which are priority targets.
	UnitScores   [16]int // Data[48:64]
	RecoveryRate [16]int // Data[64:80]
	// Various bits concerning unit types... not all clear yet
	UnitMask             [16]byte // Data[80:96] (per unit type)
	UnitMask0            [16]bool // bit 0
	UnitMask1            [16]bool // bit 1
	UnitMask2            [16]bool // bit 2
	UnitUsesSupplies     [16]bool // !bit 3(&8) of bytes Data[80:96]
	UnitMask4            [16]bool // bit4 (weather has no impact?)
	UnitMask5            [16]bool // bit5
	UnitCanMove          [16]bool // !bit 6(&64) of bytes Data[80:96]
	UnitMask7            [16]bool // bit7
	TerrainMenAttack     [8]int   // Data[96:104]
	TerrainTankAttack    [8]int   // Data[104:112]
	TerrainMenDefence    [8]int   // Data[112:120]
	TerrainTankDefence   [8]int   // Data[120:128]
	FormationMenAttack   [8]int   // Data[128:136]
	FormationTankAttack  [8]int   // Data[136:144]
	FormationMenDefence  [8]int   // Data[144:152]
	FormationTankDefence [8]int   // Data[152:160]
	// Units with type >=MinSupplyType can provide supply to other units.
	// Such units can receive supplies only from units with larger type numbers.
	MinSupplyType          int // Data[160]
	HexSizeInMiles         int // Data[161]
	Data162                int // Data[162] some generic supply use (while attacking?)
	Data163                int // Data[163] some generic supply use (while being attacked?)
	MaxResupplyAmount      int // Data[164]
	MaxSupplyTransportCost int // Data[165] in half-miles
	// On average that many supplies will be used by each unit every day.
	AvgDailySupplyUse              int        // Data[166]
	Data167                        int        // Data[167]
	MinutesPerTick                 int        // Data[168]
	UnitUpdatesPerTimeIncrement    int        // Data[169]
	MenMultiplier                  int        // Data[170] (one man stored in unit data correspond to that many actual men)
	TanksMultiplier                int        // Data[171] (same as above but for tanks)
	Data173                        int        // Data[173] (a fatigue increase)
	Data174                        int        // Data[174]
	Data175                        int        // Data[175]
	Data176                        [4][4]int  // Data[176:190] four bytes per order (numbers 0-5)
	Data192                        [8]int     // Data[192:200] move cost per formation
	Data200Low                     [16]int    // Data[200:216] lower three bits per type
	UnitResupplyPerType            [16]int    // Data[200:216] top four bits div 2
	FormationChangeSpeed           [2][8]int  // Data[216:232]
	ResupplyRate                   [2]int     // Data[232,233]
	MenReplacementRate             [2]int     // Data[234,235]
	TankReplacementRate            [2]int     // Data[236,237]
	SideColor                      [2]int     // Data[248,249] the value*16 is the hue corresponding to the given side
	Data252                        [2]int     // Data[252:254] per side
	MoveSpeedPerTerrainTypeAndUnit [8][16]int // Data[255:383]
	// Every chunk of four bytes list possible weather for a year's quarter.
	PossibleWeather [16]byte       // Data[384:400]
	DaytimePalette  [8]byte        // Data[400:408]
	NightPalette    [8]byte        // Data[408:416]
	MenCountLimit   [16]int        // Data[416:432]
	TankCountLimit  [16]int        // Data[432:448]
	DataUpdates     [21]DataUpdate // Data[448:511]
	UnitTypes       []string
	Strings1        []string
	Formations      []string
	Experience      []string
	Strings4        []string
	Equipments      []string
	UnitNames       [2][]string
	Strings7        []string
	Strings9        []string
	Months          []string
	Sides           []string
	Weather         []string
	Colors          []string
}

Representation of data parsed from {scenario}.DTA files.

func ParseData

func ParseData(data []byte) (*Data, error)

ParseData parses data from a {scenario.DTA file.

func ReadData

func ReadData(fsys fs.FS, filename string) (*Data, error)

ReadData reads and parses given {scenario}.DTA.

func (*Data) ReadFirst255Bytes

func (d *Data) ReadFirst255Bytes(reader io.Reader) error

func (*Data) UpdateData

func (s *Data) UpdateData(offset int, value byte)

func (*Data) WriteFirst255Bytes

func (d *Data) WriteFirst255Bytes(writer io.Writer) error

type DataUpdate

type DataUpdate struct {
	Day    int
	Offset int
	Value  byte
}

At Day change byte at Offset of the scenario data to Value.

type FlashbackHistory

type FlashbackHistory []FlashbackUnits

func (*FlashbackHistory) Read

func (h *FlashbackHistory) Read(reader io.Reader) error

func (FlashbackHistory) Write

func (h FlashbackHistory) Write(writer io.Writer) error

type FlashbackUnit

type FlashbackUnit struct {
	XY           UnitCoords
	ColorPalette int
	Type         int
}

type FlashbackUnits

type FlashbackUnits []FlashbackUnit

func (*FlashbackUnits) Read

func (u *FlashbackUnits) Read(reader io.Reader) error

func (FlashbackUnits) Write

func (u FlashbackUnits) Write(writer io.Writer) error

type Font

type Font struct {
	// contains filtered or unexported fields
}

func (*Font) Glyph

func (f *Font) Glyph(r rune) *image.Paletted

func (*Font) Size

func (f *Font) Size() image.Point

type Game

type Game int
const (
	Crusade  Game = 0
	Decision Game = 1
	Conflict Game = 2
)

func DetectGame

func DetectGame(fsys fs.FS) (Game, error)

func FilePrefixToGame

func FilePrefixToGame(filePrefix string) (Game, error)

func FilenameToGame

func FilenameToGame(filename string) (Game, error)

type GameData

type GameData struct {
	Game           Game
	Scenarios      []Scenario
	Sprites        *Sprites
	Icons          *Icons
	Map            *Map
	Generic        *Generic
	TerrainTypeMap *TerrainTypeMap
	Hexes          *Hexes
}

func LoadGameData

func LoadGameData(fsys fs.FS) (*GameData, error)

type GameOver

type GameOver struct{ Results string }

type GameState

type GameState struct {
	// contains filtered or unexported fields
}

func NewGameState

func NewGameState(rand *rand.Rand, gameData *GameData, scenarioData *ScenarioData, scenarioNum, variantNum int, options *Options, sync *MessageSync) *GameState

func (*GameState) CitiesHeld

func (s *GameState) CitiesHeld(side int) int

func (*GameState) Day

func (s *GameState) Day() int

func (*GameState) FinalResults

func (s *GameState) FinalResults(playerSide int) (int, int, int)

func (*GameState) Flashback

func (s *GameState) Flashback() FlashbackHistory

func (*GameState) HideAllUnits

func (s *GameState) HideAllUnits()

func (*GameState) Hour

func (s *GameState) Hour() int

func (*GameState) Init

func (s *GameState) Init() bool

func (*GameState) IsNight

func (s *GameState) IsNight() bool

func (*GameState) IsUnitVisible

func (s *GameState) IsUnitVisible(unit Unit) bool

func (*GameState) Load

func (s *GameState) Load(reader io.Reader) error

func (*GameState) MenLost

func (s *GameState) MenLost(side int) int

func (*GameState) Minute

func (s *GameState) Minute() int

func (*GameState) Month

func (s *GameState) Month() string

func (*GameState) Save

func (s *GameState) Save(writer io.Writer) error

func (*GameState) ShowAllVisibleUnits

func (s *GameState) ShowAllVisibleUnits()

func (*GameState) SwitchSides

func (s *GameState) SwitchSides()

func (*GameState) TanksLost

func (s *GameState) TanksLost(side int) int

func (*GameState) TerrainTypeMap

func (s *GameState) TerrainTypeMap() *TerrainTypeMap

func (*GameState) Update

func (s *GameState) Update() bool

func (*GameState) Weather

func (s *GameState) Weather() string

func (*GameState) WinningSideAndAdvantage

func (s *GameState) WinningSideAndAdvantage() (winningSide int, advantage int)

func (*GameState) Year

func (s *GameState) Year() int

type General

type General struct {
	// A bitmap of various flags of the general
	Data0    byte
	Data0_26 int // from bits 2 and 6
	Data0_15 int // from bits 1 and 5
	Data0_37 int // from bits 3 and 7
	Data0_04 int // from bits 0 and 4
	// Attack bonus for the units commanded by the general from 0 to 15
	Attack    int
	Data1High int
	// Defence bonus for the units commanded by the general from 0 to 15
	Defence   int
	Data2High int
	// Movement bonus for the units commanded by the general from 0 to 15
	Movement int
	Name     string
}

Represenation of data parsed from {scenario}.GEN files.

type Generals

type Generals [2][]General

func ParseGenerals

func ParseGenerals(data io.Reader) (*Generals, error)

func ReadGenerals

func ReadGenerals(fsys fs.FS, filename string) (*Generals, error)

type Generic

type Generic struct {
	// Terrain colors on the overview map.
	Data60 [4]int
	// Types of terrain 0-7 (0 is road, 7 is an impassable terrain, other vary from game to game).
	TerrainTypes []int
}

Representation of data parsed from GENERIC.DTA file.

func ParseGeneric

func ParseGeneric(reader io.Reader, game Game) (*Generic, error)

func ReadGeneric

func ReadGeneric(fsys fs.FS, game Game) (*Generic, error)

type Hexes

type Hexes struct {
	Arr0   [6][8]int // Data[0:48]
	Arr48  [6][8]int // Data[48:96]
	Arr96  [6][8]int // Data[96:144]
	Arr144 [6][8]int // Data[144:192]
}

Representation of data parsed from HEXES.DTA file.

func ParseHexes

func ParseHexes(reader io.Reader) (*Hexes, error)

func ReadHexes

func ReadHexes(fsys fs.FS) (*Hexes, error)

type IconType

type IconType int
const (
	Cursor           IconType = 0
	LightningBolt    IconType = 1
	Circles0         IconType = 2
	Circles1         IconType = 3
	Circles2         IconType = 4
	Circles3         IconType = 5
	Circles4         IconType = 6
	Circles5         IconType = 7
	SupplyTruck      IconType = 8
	FightingUnit     IconType = 9
	UnitOnKnees      IconType = 10
	SurrenderingUnit IconType = 11
	ExclamationMark  IconType = 12
	SmilingFace      IconType = 13
	MovingUnit       IconType = 14
	QuestionMark     IconType = 15
	Arrows0          IconType = 16
	Arrows1          IconType = 17
	Arrows2          IconType = 18
	Arrows3          IconType = 19
	Arrows4          IconType = 20
	Arrows5          IconType = 21
	Arrows6          IconType = 22
	Arrows7          IconType = 23
)

type Icons

type Icons struct {
	Sprites [24]*image.Paletted
}

func ParseIcons

func ParseIcons(iconsData io.Reader) (*Icons, error)

func ReadIcons

func ReadIcons(fsys fs.FS) (*Icons, error)

type Initialized

type Initialized struct{}

type Intelligence

type Intelligence struct {
	// contains filtered or unexported fields
}

func (Intelligence) Int

func (i Intelligence) Int() int

func (Intelligence) Other

func (i Intelligence) Other() Intelligence

func (Intelligence) String

func (i Intelligence) String() string

type Map

type Map struct {
	Width, Height int
	// contains filtered or unexported fields
}

A representation of a hex map parsed from CRUSADE.MAP file.

func ParseMap

func ParseMap(data io.Reader, width, height int) (*Map, error)

ParseMap parses CRUSADE.MAP files.

func ReadMap

func ReadMap(fsys fs.FS, game Game) (*Map, error)

func (*Map) AreCoordsValid

func (m *Map) AreCoordsValid(xy MapCoords) bool

func (*Map) CoordsToIndex

func (m *Map) CoordsToIndex(xy MapCoords) int

func (*Map) GetTile

func (m *Map) GetTile(xy MapCoords) byte

x, y in map coords, not unit coords

func (*Map) SetTile

func (m *Map) SetTile(xy MapCoords, tile byte)

type MapCoords

type MapCoords struct {
	X, Y int
}

func (MapCoords) ToUnitCoords

func (c MapCoords) ToUnitCoords() UnitCoords

type MessageFromUnit

type MessageFromUnit interface {
	Unit() Unit     // Unit that's sending the message
	Icon() IconType // Icon to be displyed on the map when the message is shown
	String() string // Text of message to show
}

type MessageSync

type MessageSync struct {
	// contains filtered or unexported fields
}

func NewMessageSync

func NewMessageSync() *MessageSync

func (*MessageSync) GetUpdate

func (s *MessageSync) GetUpdate() interface{}

func (*MessageSync) SendUpdate

func (s *MessageSync) SendUpdate(msg interface{}) bool

func (*MessageSync) Stop

func (s *MessageSync) Stop()

func (*MessageSync) Wait

func (s *MessageSync) Wait() bool

type Options

type Options struct {
	AlliedCommander Commander // [0..1]
	GermanCommander Commander // [0..1]
	Intelligence    Intelligence
	UnitDisplay     UnitDisplay // [0..1]
	GameBalance     int         // [0..4]
	Speed           Speed       // [1..3]
}

func DefaultOptions

func DefaultOptions() Options

func (*Options) Read

func (o *Options) Read(reader io.Reader) error

func (Options) Write

func (o Options) Write(writer io.Writer) error

type OrderType

type OrderType int

Order given to the unit: Reserve, Defend, Attack or Move

const (
	Reserve OrderType = 0
	Defend  OrderType = 1
	Attack  OrderType = 2
	Move    OrderType = 3
)

func (OrderType) String

func (o OrderType) String() string

type Reinforcements

type Reinforcements struct{ Sides [2]bool }

type Scenario

type Scenario struct {
	Name                   string
	FilePrefix             string
	StartMinute            int
	StartHour              int
	StartDay               int
	StartMonth             int
	StartYear              int
	StartWeather           int
	StartSupplyLevels      [2]int
	MinX, MaxX, MinY, MaxY int
}

Representation of the data parsed from a {scenario}.SCN file.

func ParseScn

func ParseScn(data []byte) (Scenario, error)

func ReadScenario

func ReadScenario(fsys fs.FS, filename string) (Scenario, error)

func ReadScenarios

func ReadScenarios(fsys fs.FS) ([]Scenario, error)

type ScenarioData

type ScenarioData struct {
	Variants []Variant
	Generals *Generals
	Terrain  *Terrain
	Data     *Data
	Units    *Units
}

func LoadScenarioData

func LoadScenarioData(fsys fs.FS, filePrefix string) (*ScenarioData, error)

type Score

type Score struct {
	MenLost                   [2]int // 29927 + side*2
	TanksLost                 [2]int // 29927 + 4 + side*2
	CitiesHeld                [2]int // 29927 + 13 + side*2
	CriticalLocationsCaptured [2]int // 29927 + 21 + side*2
	// contains filtered or unexported fields
}

func (Score) FinalResults

func (s Score) FinalResults(playerSide int) (int, int, int)

func (Score) WinningSideAndAdvantage

func (s Score) WinningSideAndAdvantage() (winningSide int, advantage int)

type SignedNumber

type SignedNumber interface {
	constraints.Signed | constraints.Float
}

type Speed

type Speed int
const (
	Fast   Speed = 1
	Medium Speed = 2
	Slow   Speed = 3
)

func (Speed) DelayTicks

func (s Speed) DelayTicks() int

func (Speed) Faster

func (s Speed) Faster() Speed

func (Speed) Slower

func (s Speed) Slower() Speed

func (Speed) String

func (s Speed) String() string

type Sprites

type Sprites struct {
	GameFont          *Font
	IntroFont         *Font
	IntroSprites      []*image.Paletted
	TerrainTiles      [48]*image.Paletted
	UnitSymbolSprites [16]*image.Paletted
	UnitIconSprites   [16]*image.Paletted
}

func ParseSprites

func ParseSprites(iconData, symbolData, introData io.Reader) (*Sprites, error)

func ReadSprites

func ReadSprites(fsys fs.FS) (*Sprites, error)

type SupplyDistributionEnd

type SupplyDistributionEnd struct{}

type SupplyDistributionStart

type SupplyDistributionStart struct{}

type SupplyTruckMove

type SupplyTruckMove struct {
	XY0, XY1 MapCoords
}

type Terrain

type Terrain struct {
	// Cities contains list of all the cities included in the scenario.
	Cities Cities
	// Coefficients for 4x4-tile squares on the map (a 16x16 map of coefficients).
	// n-th (0-based) coefficient, if a coefficient for square with top left corner:
	// (4*(n%16), 4*n/16).
	Coeffs [16][16]int // Bytes [768-1024]
}

Terrain is a representation of data parsed from a {scenario}.TER file.

func ParseTerrain

func ParseTerrain(data io.Reader) (*Terrain, error)

func ReadTerrain

func ReadTerrain(fsys fs.FS, filename string, game Game) (*Terrain, error)

ReadTerrain reads terrain information for a particular game from given file on the given file system. If there is an error while loading returns pair (nil, error), otherwise returns pair (terrain, nil).

func (Terrain) FindCityAt

func (t Terrain) FindCityAt(xy UnitCoords) (*City, bool)

FindCityAt returns pair (pointer to a city, true) if there is a city in the loaded scenario, in the selected variant. Otherwise returns pair (nil, false).

func (Terrain) IsCityAt

func (t Terrain) IsCityAt(xy UnitCoords) bool

IsCityAt returns true iff in the loaded scenario, in the selected variant there is a city at coordinates xy.

type TerrainTypeMap

type TerrainTypeMap struct {
	// contains filtered or unexported fields
}

func (*TerrainTypeMap) AreCoordsValid

func (m *TerrainTypeMap) AreCoordsValid(xy MapCoords) bool

func (*TerrainTypeMap) ContainsUnit

func (m *TerrainTypeMap) ContainsUnit(xy UnitCoords) bool

func (*TerrainTypeMap) HideUnitAt

func (m *TerrainTypeMap) HideUnitAt(xy UnitCoords)

func (*TerrainTypeMap) ShowUnitAt

func (m *TerrainTypeMap) ShowUnitAt(xy UnitCoords)

type TimeChanged

type TimeChanged struct{}

type Unit

type Unit struct {
	Side                int  // 0 or 1
	InContactWithEnemy  bool // &1 != 0
	IsUnderAttack       bool // &2 != 0
	State2              bool // &4 != 0
	HasSupplyLine       bool // &8 == 0
	State4              bool // &16 != 0, is neighbouring enemy
	HasLocalCommand     bool // &32 != 0
	SeenByEnemy         bool // &64 != 0
	IsInGame            bool // &128 != 0
	XY                  UnitCoords
	MenCount, TankCount int
	// Formation of the unit, a number from 0 to 7.
	// Names of formations are read from {scenario}.DTA file into Data.Formations.
	Formation       int
	SupplyUnit      int // Index of this unit's supply unit
	LongRangeAttack bool
	Type            int
	TypeName        string
	ColorPalette    int
	NameIndex       int
	Name            string
	// Formation the unit wants to have. It will gradually change the formation
	// from Formation to TargetFormation with speed defined by Data.FormationChangeSpeed.
	TargetFormation int
	OrderBit4       bool
	Order           OrderType

	// Commanding general of the unit.
	General     General
	SupplyLevel int
	Morale      int

	// Iff nth bit of the VariantBitmap is 0, the unit should be used in nth variant
	// of the scenario.
	VariantBitmap        byte
	HalfDaysUntilAppear  int
	InvAppearProbability int

	Fatigue   int // Value from 0 to 255
	Objective UnitCoords

	Index int
	// contains filtered or unexported fields
}

Unit type desribes state of game unit.

func ParseUnit

func ParseUnit(data [16]byte, unitTypeNames []string, unitNames []string, generals []General) (Unit, error)

func (*Unit) ClearState

func (u *Unit) ClearState()

func (Unit) FullName

func (u Unit) FullName() string

func (Unit) FullString

func (u Unit) FullString() string

func (Unit) Function15_distanceToObjective

func (u Unit) Function15_distanceToObjective() int

func (Unit) IsVisible

func (u Unit) IsVisible() bool

func (*Unit) StateByte

func (u *Unit) StateByte() byte

func (*Unit) Write

func (u *Unit) Write(writer io.Writer) error

type UnitAttack

type UnitAttack struct {
	XY      UnitCoords
	Outcome int
}

type UnitCoords

type UnitCoords struct {
	X, Y int
}

func FirstNeighbourFromTowards

func FirstNeighbourFromTowards(xy0, xy1 UnitCoords, variant int) UnitCoords

First neighbouring tile met when going from x0,y0 towards x1,y1. If variant is 0 or 1, pick one of the most direct directions. If variant is 2 or 3, pick one of the less direct directions.

func IthNeighbour

func IthNeighbour(xy UnitCoords, i int) UnitCoords

func (UnitCoords) ToMapCoords

func (c UnitCoords) ToMapCoords() MapCoords

type UnitDisplay

type UnitDisplay int
const (
	ShowAsSymbols UnitDisplay = 0
	ShowAsIcons   UnitDisplay = 1
)

func (UnitDisplay) String

func (u UnitDisplay) String() string

type UnitMove

type UnitMove struct {
	Unit     Unit
	XY0, XY1 MapCoords
}

type Units

type Units [2][]Unit

func ParseUnits

func ParseUnits(data io.Reader, unitTypeNames []string, unitNames [2][]string, generals *Generals) (*Units, error)

func ReadUnits

func ReadUnits(fsys fs.FS, filename string, game Game, unitTypeNames []string, unitNames [2][]string, generals *Generals) (*Units, error)

func (Units) FindUnitAt

func (u Units) FindUnitAt(xy UnitCoords) (Unit, bool)

func (Units) FindUnitOfSideAt

func (u Units) FindUnitOfSideAt(xy UnitCoords, side int) (Unit, bool)

func (Units) IsUnitAt

func (u Units) IsUnitAt(xy UnitCoords) bool

func (Units) IsUnitOfSideAt

func (u Units) IsUnitOfSideAt(xy UnitCoords, side int) bool

func (Units) NeighbourUnitCount

func (u Units) NeighbourUnitCount(xy UnitCoords, side int) int

func (*Units) Write

func (u *Units) Write(writer io.Writer) error

type Variant

type Variant struct {
	Name              string
	LengthInDays      int
	CriticalLocations [2]int // per side. Number of critical locations that need to be captured by a side to win.
	Data3             int
	CitiesHeld        [2]int
}

Representation of data parsed from {scenario}.VAR file.

func ParseVariants

func ParseVariants(reader io.Reader) ([]Variant, error)

func ReadVariants

func ReadVariants(fsys fs.FS, filename string) ([]Variant, error)

func (*Variant) Read

func (v *Variant) Read(reader io.Reader) error

func (Variant) Write

func (v Variant) Write(writer io.Writer) error

type WeAreAttacking

type WeAreAttacking struct {
	// contains filtered or unexported fields
}

func (WeAreAttacking) Enemy

func (a WeAreAttacking) Enemy() Unit

func (WeAreAttacking) EnemyMessage

func (a WeAreAttacking) EnemyMessage() WeAreUnderFire

func (WeAreAttacking) Icon

func (a WeAreAttacking) Icon() IconType

func (WeAreAttacking) String

func (a WeAreAttacking) String() string

func (WeAreAttacking) Unit

func (a WeAreAttacking) Unit() Unit

type WeAreInContactWithEnemy

type WeAreInContactWithEnemy struct {
	// contains filtered or unexported fields
}

func (WeAreInContactWithEnemy) Icon

func (WeAreInContactWithEnemy) String

func (c WeAreInContactWithEnemy) String() string

func (WeAreInContactWithEnemy) Unit

func (c WeAreInContactWithEnemy) Unit() Unit

type WeAreRetreating

type WeAreRetreating struct {
	// contains filtered or unexported fields
}

func (WeAreRetreating) Icon

func (r WeAreRetreating) Icon() IconType

func (WeAreRetreating) String

func (r WeAreRetreating) String() string

func (WeAreRetreating) Unit

func (r WeAreRetreating) Unit() Unit

type WeAreUnderFire

type WeAreUnderFire struct {
	// contains filtered or unexported fields
}

func (WeAreUnderFire) Icon

func (u WeAreUnderFire) Icon() IconType

func (WeAreUnderFire) String

func (u WeAreUnderFire) String() string

func (WeAreUnderFire) Unit

func (u WeAreUnderFire) Unit() Unit

type WeHaveBeenOverrun

type WeHaveBeenOverrun struct {
	// contains filtered or unexported fields
}

func (WeHaveBeenOverrun) Icon

func (o WeHaveBeenOverrun) Icon() IconType

func (WeHaveBeenOverrun) String

func (o WeHaveBeenOverrun) String() string

func (WeHaveBeenOverrun) Unit

func (o WeHaveBeenOverrun) Unit() Unit

type WeHaveCaptured

type WeHaveCaptured struct {
	// contains filtered or unexported fields
}

func (WeHaveCaptured) Icon

func (c WeHaveCaptured) Icon() IconType

func (WeHaveCaptured) String

func (c WeHaveCaptured) String() string

func (WeHaveCaptured) Unit

func (c WeHaveCaptured) Unit() Unit

type WeHaveExhaustedSupplies

type WeHaveExhaustedSupplies struct {
	// contains filtered or unexported fields
}

func (WeHaveExhaustedSupplies) Icon

func (WeHaveExhaustedSupplies) String

func (e WeHaveExhaustedSupplies) String() string

func (WeHaveExhaustedSupplies) Unit

func (e WeHaveExhaustedSupplies) Unit() Unit

type WeHaveMetStrongResistance

type WeHaveMetStrongResistance struct {
	// contains filtered or unexported fields
}

func (WeHaveMetStrongResistance) Icon

func (WeHaveMetStrongResistance) String

func (m WeHaveMetStrongResistance) String() string

func (WeHaveMetStrongResistance) Unit

type WeHaveReachedOurObjective

type WeHaveReachedOurObjective struct {
	// contains filtered or unexported fields
}

func (WeHaveReachedOurObjective) Icon

func (WeHaveReachedOurObjective) String

func (r WeHaveReachedOurObjective) String() string

func (WeHaveReachedOurObjective) Unit

type WeMustSurrender

type WeMustSurrender struct {
	// contains filtered or unexported fields
}

func (WeMustSurrender) Icon

func (a WeMustSurrender) Icon() IconType

func (WeMustSurrender) String

func (m WeMustSurrender) String() string

func (WeMustSurrender) Unit

func (m WeMustSurrender) Unit() Unit

type WeatherForecast

type WeatherForecast struct{ Weather int }

Jump to

Keyboard shortcuts

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