rts

package
v0.0.0-...-6b508d1 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NilObjectId   = uint8(0)
	NilPlayerId   = NilObjectId
	NilBuildingId = NilObjectId
	NilUnitId     = NilObjectId
)
View Source
const (
	InternalEventId_Shot uint8 = iota
	InternalEventId_Spawned
	InternalEventId_Killed
	InternalEventId_Built
	InternalEventId_Destroyed
)

Variables

View Source
var (
	ErrNotInitialized                = errors.New("not initialized")
	ErrNotStarted                    = errors.New("not started")
	ErrAlreadyInitialized            = errors.New("already initialized")
	ErrAlreadyStarted                = errors.New("already started")
	ErrPlayerLimitReached            = errors.New("player limit reached")
	ErrUnitLimitReached              = errors.New("unit limit reached")
	ErrBuildingLimitReached          = errors.New("building limit reached")
	ErrUnitPrototypeLimitReached     = errors.New("unit prototype limit reached")
	ErrBuildingPrototypeLimitReached = errors.New("building prototype limit reached")
	ErrInvalidPlayerId               = errors.New("invalid player id")
	ErrInvalidUnitId                 = errors.New("invalid unit id")
	ErrInvalidBuildingId             = errors.New("invalid building id")
	ErrInvalidUnitType               = errors.New("invalid unit type")
	ErrInvalidBuildingType           = errors.New("invalid building type")
	ErrNonexistentPlayer             = errors.New("nonexistent player")
	ErrMissingMainBuilding           = errors.New("player has no main building")
	ErrMainBuildingDestroyed         = errors.New("player's main building destroyed")
	ErrAreaNotBuildable              = errors.New("area not buildable")
	ErrUnitDead                      = errors.New("unit dead")
)
View Source
var (
	TableId_Meta, _               = archmod.TableSchemas.TableIdFromName("Meta")
	TableId_Players, _            = archmod.TableSchemas.TableIdFromName("Players")
	TableId_Board, _              = archmod.TableSchemas.TableIdFromName("Board")
	TableId_Units, _              = archmod.TableSchemas.TableIdFromName("Units")
	TableId_Buildings, _          = archmod.TableSchemas.TableIdFromName("Buildings")
	TableId_UnitPrototypes, _     = archmod.TableSchemas.TableIdFromName("UnitPrototypes")
	TableId_BuildingPrototypes, _ = archmod.TableSchemas.TableIdFromName("BuildingPrototypes")
)

Functions

func ChebyshevDistance

func ChebyshevDistance(a, b image.Point) int

func ChebyshevDistanceToArea

func ChebyshevDistanceToArea(position image.Point, area image.Rectangle) int

func DeltasToArea

func DeltasToArea(position image.Point, area image.Rectangle) (int, int)

func DeltasToAreaAsPoint

func DeltasToAreaAsPoint(position image.Point, area image.Rectangle) image.Point

func Distance

func Distance(a image.Point, b image.Point) int

func DistanceToArea

func DistanceToArea(position image.Point, area image.Rectangle) int

func EmptyUnitTile

func EmptyUnitTile(tile *datamod.BoardRow, layer LayerId)

func GetAttackStrength

func GetAttackStrength(proto *datamod.UnitPrototypesRow, layerId LayerId) uint8

func GetDimensionsAsPoint

func GetDimensionsAsPoint(object interface {
	GetWidth() uint8
	GetHeight() uint8
}) image.Point

func GetPositionAsPoint

func GetPositionAsPoint(object interface {
	GetX() uint16
	GetY() uint16
}) image.Point

func IsTileEmpty

func IsTileEmpty(tile *datamod.BoardRow, layer LayerId) bool

func IsTileEmptyAllLayers

func IsTileEmptyAllLayers(tile *datamod.BoardRow) bool

func ManhattanDistance

func ManhattanDistance(a, b image.Point) int

func ManhattanDistanceToArea

func ManhattanDistanceToArea(position image.Point, area image.Rectangle) int

func SetTileAirUnit

func SetTileAirUnit(tile *datamod.BoardRow, playerId uint8, unitId uint8)

func SetTileHoverUnit

func SetTileHoverUnit(tile *datamod.BoardRow, playerId uint8, unitId uint8)

func SetTileLandObject

func SetTileLandObject(tile *datamod.BoardRow, objectType ObjectType, playerId uint8, objectId uint8)

func SetTileUnit

func SetTileUnit(tile *datamod.BoardRow, layer LayerId, playerId uint8, unitId uint8)

func StepTowards

func StepTowards(curPos image.Point, targetArea image.Rectangle) image.Point

func StepTowards1D

func StepTowards1D(curPos, targetL, targetSize int) int

func StepTowards2D

func StepTowards2D(curPos image.Point, targetArea image.Rectangle) image.Point

Types

type BuildingFilter

type BuildingFilter func(playerId, buildingId uint8, building *datamod.BuildingsRow) bool

type BuildingObjectWithRow

type BuildingObjectWithRow struct {
	ObjectWithRow
}

func (BuildingObjectWithRow) Building

type BuildingPlacement

type BuildingPlacement = archmod.ActionData_PlaceBuilding

type BuildingState

type BuildingState uint8
const (
	BuildingState_Nil BuildingState = iota
	BuildingState_Unpaid
	BuildingState_Building
	BuildingState_Built
	BuildingState_Destroyed
	BuildingState_Count
)

func (BuildingState) HasBeenBuilt

func (s BuildingState) HasBeenBuilt() bool

func (BuildingState) IsActive

func (s BuildingState) IsActive() bool

func (BuildingState) IsNil

func (s BuildingState) IsNil() bool

func (BuildingState) Uint8

func (s BuildingState) Uint8() uint8

type CommandPath

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

func NewCommandPath

func NewCommandPath(pathRaw uint64, metaRaw uint8) *CommandPath

func (*CommandPath) CurrentPoint

func (c *CommandPath) CurrentPoint() image.Point

func (*CommandPath) GetPathPoint

func (c *CommandPath) GetPathPoint(i int) image.Point

func (*CommandPath) HasPath

func (c *CommandPath) HasPath() bool

func (*CommandPath) IncPointer

func (c *CommandPath) IncPointer()

func (*CommandPath) Meta

func (c *CommandPath) Meta() commandPathMeta

func (*CommandPath) Path

func (c *CommandPath) Path() []image.Point

func (*CommandPath) PathLen

func (c *CommandPath) PathLen() uint8

func (*CommandPath) Pointer

func (c *CommandPath) Pointer() uint8

func (*CommandPath) RawPath

func (c *CommandPath) RawPath() uint64

func (*CommandPath) SetPath

func (c *CommandPath) SetPath(path []image.Point)

type Core

type Core struct {
	arch.BaseCore
	// contains filtered or unexported fields
}

func (*Core) AbsSubTickIndex

func (c *Core) AbsSubTickIndex() uint32

func (*Core) AddBuildingPrototype

func (c *Core) AddBuildingPrototype(action *BuildingPrototypeAddition) error

func (*Core) AddPlayer

func (c *Core) AddPlayer(action *PlayerAddition) error

func (*Core) AddUnitPrototype

func (c *Core) AddUnitPrototype(action *UnitPrototypeAddition) error

func (*Core) AssignUnit

func (c *Core) AssignUnit(action *UnitAssignation) error

func (*Core) BoardRect

func (c *Core) BoardRect() image.Rectangle

func (*Core) BoardSize

func (c *Core) BoardSize() image.Point

func (*Core) CreateUnit

func (c *Core) CreateUnit(action *UnitCreation) error

func (*Core) EventHandler

func (c *Core) EventHandler() InternalEventHandler

func (*Core) ForEachBuilding

func (c *Core) ForEachBuilding(playerId uint8, forEach func(buildingId uint8, building *datamod.BuildingsRow))

func (*Core) ForEachBuildingPrototype

func (c *Core) ForEachBuildingPrototype(forEach func(prototypeId uint8, prototype *datamod.BuildingPrototypesRow))

func (*Core) ForEachPlayer

func (c *Core) ForEachPlayer(forEach func(playerId uint8, player *datamod.PlayersRow))

func (*Core) ForEachUnit

func (c *Core) ForEachUnit(playerId uint8, forEach func(unitId uint8, unit *datamod.UnitsRow))

func (*Core) ForEachUnitPrototype

func (c *Core) ForEachUnitPrototype(forEach func(prototypeId uint8, prototype *datamod.UnitPrototypesRow))

func (*Core) GetBoardTile

func (c *Core) GetBoardTile(x, y uint16) *datamod.BoardRow

func (*Core) GetBuilding

func (c *Core) GetBuilding(playerId uint8, buildingId uint8) *datamod.BuildingsRow

func (*Core) GetBuildingArea

func (c *Core) GetBuildingArea(playerId uint8, buildingId uint8) image.Rectangle

func (*Core) GetBuildingObject

func (c *Core) GetBuildingObject(playerId uint8, buildingId uint8) BuildingObjectWithRow

func (*Core) GetBuildingPrototype

func (c *Core) GetBuildingPrototype(prototypeId uint8) *datamod.BuildingPrototypesRow

func (*Core) GetMainBuilding

func (c *Core) GetMainBuilding(playerId uint8) *datamod.BuildingsRow

func (*Core) GetMainBuildingArea

func (c *Core) GetMainBuildingArea(playerId uint8) image.Rectangle

func (*Core) GetMainBuildingPosition

func (c *Core) GetMainBuildingPosition(playerId uint8) image.Point

func (*Core) GetMeta

func (c *Core) GetMeta() *datamod.MetaRow

func (*Core) GetNearest

func (c *Core) GetNearest(iter IIterator_Uint8, area image.Rectangle) ObjectMatchByDistance

func (*Core) GetNearestEnemyUnits

func (c *Core) GetNearestEnemyUnits(playerId uint8, position image.Point, filters ...UnitFilter) []PlayerObjectMatchByDistance

func (*Core) GetPlayer

func (c *Core) GetPlayer(playerId uint8) *datamod.PlayersRow

func (*Core) GetSpawnArea

func (c *Core) GetSpawnArea(playerId uint8) image.Rectangle

func (*Core) GetSpawnPoint

func (c *Core) GetSpawnPoint(layer LayerId, playerId uint8) (image.Point, bool)

func (*Core) GetUnit

func (c *Core) GetUnit(playerId uint8, unitId uint8) *datamod.UnitsRow

func (*Core) GetUnitObject

func (c *Core) GetUnitObject(playerId uint8, uintId uint8) UnitObjectWithRow

func (*Core) GetUnitPrototype

func (c *Core) GetUnitPrototype(unitTypeId uint8) *datamod.UnitPrototypesRow

func (*Core) GetUnitToFireAt

func (c *Core) GetUnitToFireAt(obj UnitObjectWithRow) PlayerObjectMatchByDistance

func (*Core) GetWorkerPortArea

func (c *Core) GetWorkerPortArea(playerId uint8) image.Rectangle

func (*Core) GetWorkerPortPosition

func (c *Core) GetWorkerPortPosition(playerId uint8) image.Point

func (*Core) HasStarted

func (c *Core) HasStarted() bool

func (*Core) Initialize

func (c *Core) Initialize(action *Initialization) error

func (*Core) IsBuildableArea

func (c *Core) IsBuildableArea(area image.Rectangle) bool

func (*Core) IsInitialized

func (c *Core) IsInitialized() bool

func (*Core) IterBuildings

func (c *Core) IterBuildings(playerId uint8, filters ...BuildingFilter) *Iterator_uint8

func (*Core) IterPlayers

func (c *Core) IterPlayers(filters ...PlayerFilter) *Iterator_uint8

func (*Core) IterUnits

func (c *Core) IterUnits(playerId uint8, filters ...UnitFilter) *Iterator_uint8

func (*Core) PlaceBuilding

func (c *Core) PlaceBuilding(action *BuildingPlacement) error

func (*Core) Purge

func (c *Core) Purge()

func (*Core) SearchIter

func (c *Core) SearchIter(iter IIterator_Uint8) (uint8, interface{})

func (*Core) SetEventHandler

func (c *Core) SetEventHandler(handler InternalEventHandler)

func (*Core) SetFieldCallback

func (c *Core) SetFieldCallback(tableId lib.TableId, rowKey lib.RowKey, columnIndex int, value []byte)

func (*Core) SetFieldHandler

func (c *Core) SetFieldHandler() SetFieldHandler

func (*Core) SetSetFieldHandler

func (c *Core) SetSetFieldHandler(handler SetFieldHandler)

func (*Core) Start

func (c *Core) Start(action *Start) error

func (*Core) Tick

func (c *Core) Tick()

func (*Core) TicksPerBlock

func (c *Core) TicksPerBlock() uint64

func (*Core) TileIsInBoard

func (c *Core) TileIsInBoard(position image.Point) bool

func (*Core) ValidateBuildingId

func (c *Core) ValidateBuildingId(playerId uint8, buildingId uint8) error

func (*Core) ValidateBuildingType

func (c *Core) ValidateBuildingType(prototypeId uint8) error

func (*Core) ValidatePlayerId

func (c *Core) ValidatePlayerId(playerId uint8) error

func (*Core) ValidatePlayerOrEnvironmentId

func (c *Core) ValidatePlayerOrEnvironmentId(playerId uint8) error

func (*Core) ValidateUnitId

func (c *Core) ValidateUnitId(playerId uint8, unitId uint8) error

func (*Core) ValidateUnitType

func (c *Core) ValidateUnitType(prototypeId uint8) error

type FighterCommandData

type FighterCommandData uint64

<unused> uint24, CommandType uint8, Alpha uint16, Beta uint16

func NewFighterCommandData

func NewFighterCommandData(command FighterCommandType) FighterCommandData

func (FighterCommandData) Alpha

func (c FighterCommandData) Alpha() uint16

func (FighterCommandData) Beta

func (c FighterCommandData) Beta() uint16

func (*FighterCommandData) SetAlpha

func (c *FighterCommandData) SetAlpha(alpha uint16)

func (*FighterCommandData) SetBeta

func (c *FighterCommandData) SetBeta(beta uint16)

func (*FighterCommandData) SetTargetBuilding

func (c *FighterCommandData) SetTargetBuilding(playerId uint8, buildingId uint8)

func (*FighterCommandData) SetTargetBuildingId

func (c *FighterCommandData) SetTargetBuildingId(buildingId uint8)

func (*FighterCommandData) SetTargetPlayerId

func (c *FighterCommandData) SetTargetPlayerId(playerId uint8)

func (*FighterCommandData) SetTargetPosition

func (c *FighterCommandData) SetTargetPosition(p image.Point)

func (*FighterCommandData) SetTargetUnitId

func (c *FighterCommandData) SetTargetUnitId(unitId uint8)

func (FighterCommandData) String

func (c FighterCommandData) String() string

func (*FighterCommandData) TargetBuilding

func (c *FighterCommandData) TargetBuilding() (uint8, uint8)

func (FighterCommandData) TargetBuildingId

func (c FighterCommandData) TargetBuildingId() uint8

func (FighterCommandData) TargetPlayerId

func (c FighterCommandData) TargetPlayerId() uint8

func (FighterCommandData) TargetPosition

func (c FighterCommandData) TargetPosition() image.Point

func (FighterCommandData) TargetUnit

func (c FighterCommandData) TargetUnit() (uint8, uint8)

func (*FighterCommandData) TargetUnitId

func (c *FighterCommandData) TargetUnitId() uint8

func (FighterCommandData) Type

func (FighterCommandData) Uint64

func (c FighterCommandData) Uint64() uint64

type FighterCommandType

type FighterCommandType uint8
const (
	FighterCommandType_HoldPosition FighterCommandType = iota
	FighterCommandType_AttackBuilding
	FighterCommandType_AttackUnit
	FighterCommandType_Count
)

func (FighterCommandType) IsBusy

func (c FighterCommandType) IsBusy() bool

func (FighterCommandType) IsIdle

func (c FighterCommandType) IsIdle() bool

func (FighterCommandType) IsTargetingBuilding

func (c FighterCommandType) IsTargetingBuilding() bool

func (FighterCommandType) IsTargetingPosition

func (c FighterCommandType) IsTargetingPosition() bool

func (FighterCommandType) IsTargetingUnit

func (c FighterCommandType) IsTargetingUnit() bool

func (FighterCommandType) Uint8

func (c FighterCommandType) Uint8() uint8

type IIterator_Uint8

type IIterator_Uint8 interface {
	Next() bool
	Value() (id uint8, val interface{})
}

type Initialization

type Initialization = archmod.ActionData_Initialize

type InternalEventHandler

type InternalEventHandler func(eventId uint8, data interface{})

type InternalEvent_Built

type InternalEvent_Built struct {
	Building Object
}

type InternalEvent_Destroyed

type InternalEvent_Destroyed struct {
	Building Object
}

type InternalEvent_Killed

type InternalEvent_Killed struct {
	Unit Object
}

type InternalEvent_Shot

type InternalEvent_Shot struct {
	Attacker Object
	Target   Object
}

type InternalEvent_Spawned

type InternalEvent_Spawned struct {
	Unit Object
}

type Iterator_uint8

type Iterator_uint8 struct {
	Current uint8
	Max     uint8
	Get     func(idx uint8) (id uint8, val interface{})
	// contains filtered or unexported fields
}

func (*Iterator_uint8) Next

func (i *Iterator_uint8) Next() bool

func (*Iterator_uint8) Value

func (i *Iterator_uint8) Value() (id uint8, val interface{})

type LayerId

type LayerId uint8
const (
	LayerId_Land LayerId = iota
	LayerId_Hover
	LayerId_Air
	LayerId_Count
)

func (LayerId) String

func (l LayerId) String() string

func (LayerId) Uint8

func (l LayerId) Uint8() uint8

type Object

type Object struct {
	Type     ObjectType
	PlayerId uint8
	ObjectId uint8
}

func (Object) IsNil

func (o Object) IsNil() bool

type ObjectMatchByDistance

type ObjectMatchByDistance struct {
	ObjectId uint8
	Distance int
}

func (ObjectMatchByDistance) IsNil

func (m ObjectMatchByDistance) IsNil() bool

type ObjectType

type ObjectType uint8
const (
	ObjectType_Nil ObjectType = iota
	ObjectType_Building
	ObjectType_Unit
	ObjectType_Count
)

func (ObjectType) IsNil

func (t ObjectType) IsNil() bool

func (ObjectType) Uint8

func (t ObjectType) Uint8() uint8

type ObjectWithRow

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

func (ObjectWithRow) IsNil

func (o ObjectWithRow) IsNil() bool

func (ObjectWithRow) Object

func (o ObjectWithRow) Object() Object

func (ObjectWithRow) ObjectId

func (o ObjectWithRow) ObjectId() uint8

func (ObjectWithRow) ObjectType

func (o ObjectWithRow) ObjectType() ObjectType

func (ObjectWithRow) PlayerId

func (o ObjectWithRow) PlayerId() uint8

type PlayerAddition

type PlayerAddition = archmod.ActionData_AddPlayer

type PlayerFilter

type PlayerFilter func(playerId uint8, player *datamod.PlayersRow) bool

type PlayerObjectMatchByDistance

type PlayerObjectMatchByDistance struct {
	PlayerId uint8
	ObjectMatchByDistance
}

type SetFieldHandler

type SetFieldHandler func(table arch.TableSchema, rowKey lib.RowKey, columnName string, value []byte)

type Start

type Start = archmod.ActionData_Start

type Tick

type UnitAssignation

type UnitAssignation = archmod.ActionData_AssignUnit

type UnitCommandData

type UnitCommandData interface {
	Uint64() uint64
	String() string
}

type UnitCommandType

type UnitCommandType interface {
	Uint8() uint8
	IsBusy() bool
}

type UnitCreation

type UnitCreation = archmod.ActionData_CreateUnit

type UnitFilter

type UnitFilter func(playerId, unitId uint8, unit *datamod.UnitsRow) bool

type UnitObjectWithRow

type UnitObjectWithRow struct {
	ObjectWithRow
}

func (UnitObjectWithRow) Unit

type UnitPrototypeAddition

type UnitPrototypeAddition = archmod.ActionData_AddUnitPrototype

type UnitState

type UnitState uint8
const (
	UnitState_Nil UnitState = iota
	UnitState_Unpaid
	UnitState_Spawning
	UnitState_Active
	UnitState_Inactive
	UnitState_Dead
	UnitState_Count
)

func (UnitState) HasSpawned

func (c UnitState) HasSpawned() bool

func (UnitState) IsActive

func (c UnitState) IsActive() bool

func (UnitState) IsAlive

func (c UnitState) IsAlive() bool

func (UnitState) IsDeadOrInactive

func (c UnitState) IsDeadOrInactive() bool

func (UnitState) IsNil

func (c UnitState) IsNil() bool

func (UnitState) IsPaid

func (c UnitState) IsPaid() bool

func (UnitState) IsSpawning

func (c UnitState) IsSpawning() bool

func (UnitState) Uint8

func (c UnitState) Uint8() uint8

type WorkerCommandData

type WorkerCommandData uint64

<unused> uint40, CommandType uint8, PlayerId uint8, BuildingId uint8

func NewWorkerCommandData

func NewWorkerCommandData(commandType WorkerCommandType) WorkerCommandData

func (*WorkerCommandData) SetTargetBuilding

func (c *WorkerCommandData) SetTargetBuilding(playerId uint8, buildingId uint8)

func (*WorkerCommandData) SetTargetBuildingId

func (c *WorkerCommandData) SetTargetBuildingId(buildingId uint8)

func (*WorkerCommandData) SetTargetPlayerId

func (c *WorkerCommandData) SetTargetPlayerId(playerId uint8)

func (WorkerCommandData) String

func (c WorkerCommandData) String() string

func (*WorkerCommandData) TargetBuilding

func (c *WorkerCommandData) TargetBuilding() (uint8, uint8)

func (WorkerCommandData) TargetBuildingId

func (c WorkerCommandData) TargetBuildingId() uint8

func (WorkerCommandData) TargetPlayerId

func (c WorkerCommandData) TargetPlayerId() uint8

func (WorkerCommandData) Type

func (WorkerCommandData) Uint64

func (c WorkerCommandData) Uint64() uint64

type WorkerCommandType

type WorkerCommandType uint8
const (
	WorkerCommandType_Idle WorkerCommandType = iota
	WorkerCommandType_Gather
	WorkerCommandType_Build
	WorkerCommandType_Count
)

func (WorkerCommandType) IsBusy

func (c WorkerCommandType) IsBusy() bool

func (WorkerCommandType) IsIdle

func (c WorkerCommandType) IsIdle() bool

func (WorkerCommandType) Uint8

func (c WorkerCommandType) Uint8() uint8

Jump to

Keyboard shortcuts

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