rtsengine

package
v0.0.0-...-c07d657 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2019 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AIPlayer

type AIPlayer struct {
	// Structures common to all players.
	BasePlayer
}

AIPlayer will implement and Machine Intelligent Player

func NewAIPlayer

func NewAIPlayer(description string, worldLocation image.Point, width int, height int, pool *Pool, pathing *AStarPathing, world *World) *AIPlayer

NewAIPlayer constructs a AIPlayer

type AStarPathing

type AStarPathing struct {
}

AStarPathing will implement the A* pathing algorithm A simple description here: http://www.policyalmanac.org/games/aStarTutorial.htm Psuedocode here at the bottom of this: http://web.mit.edu/eranki/www/tutorials/search/ https://github.com/beefsack/go-astar/blob/master/astar.go Smoothing to avoid diagonals: http://www.gamasutra.com/view/feature/131505/toward_more_realistic_pathfinding.php?page=1 Basic line scan/ploting algorithm: https://en.wikipedia.org/wiki/Line_drawing_algorithm

func (*AStarPathing) FindPath

func (path *AStarPathing) FindPath(pool *Pool, grid *Grid, source *image.Point, destination *image.Point) (*list.List, error)

FindPath will find a path between source and destination Points and returns a list of Waypoints of the proper path. All coordinates in world coordinates (absolute coordinates) please.

func (*AStarPathing) FreeList

func (path *AStarPathing) FreeList(pool *Pool, l *list.List)

FreeList will free every Waypoint in the list l

type Acre

type Acre struct {
	AutoNumber
	// contains filtered or unexported fields
}

Acre maintains the state for an acre of the World.

func (*Acre) Collision

func (acre *Acre) Collision() bool

Collision returns true if the locus is already occupied by any other unit OR the terrain is inaccessible such as Mountains, Water and Trees.

func (*Acre) IsOccupiedOrNotGrass

func (acre *Acre) IsOccupiedOrNotGrass() bool

IsOccupiedOrNotGrass returns true if the terrains is occupied or at least not grass.

func (*Acre) Occupied

func (acre *Acre) Occupied() bool

Occupied returns true if this acre is occupied by a unit and false otherwise.

func (*Acre) Set

func (acre *Acre) Set(newUnit IUnit) error

Set will set the newUnit into the acrea. Returns an error if there is already a unit occupying this acre.

type Archer

type Archer struct {
	BaseUnit
}

Archer is an IUnit that maintains a range unit of some sort

type Armory

type Armory struct {
	BaseUnit
}

Armory is an IUnit that maintains an Armory that produces combat units

type AutoNumber

type AutoNumber struct {
	ID int
	// contains filtered or unexported fields
}

AutoNumber produces and maintains an autonumber

func (*AutoNumber) Initialize

func (an *AutoNumber) Initialize()

Initialize the autonumber.

type BasePlayer

type BasePlayer struct {
	// The world map that maintains the terrain and units.
	OurWorld *World

	// Our view (projection) onto that world
	View

	// Map of units for this player
	UnitMap

	// Our master pool for frequently used items
	ItemPool *Pool

	// The automated mechanics of this particular user
	Mechanics []IMechanic

	// Pathing systems
	Pathing *AStarPathing

	// Each player has a unique auto number.
	AutoNumber
	// contains filtered or unexported fields
}

BasePlayer maintains all structures common to all kinds of players. Presently there are two players {HumanPlayer, AIPlayer}

func (*BasePlayer) DumpUnits

func (player *BasePlayer) DumpUnits()

DumpUnits demonstrates how to do that precisely.

func (*BasePlayer) PlayerUnits

func (player *BasePlayer) PlayerUnits() *UnitMap

PlayerUnits returns the player unit map for this player.

func (*BasePlayer) PlayerView

func (player *BasePlayer) PlayerView() *View

PlayerView returns the view associated with this player

type BaseUnit

type BaseUnit struct {
	Poolable
	AutoNumber
	HealthAndAttack
	Owner IPlayer
	Movement
}

BaseUnit composes all the structures necessary for any unit.

func (*BaseUnit) Initialize

func (unit *BaseUnit) Initialize()

Initialize will set the unit to the base state. Call only once per instantiation

type Castle

type Castle struct {
	BaseUnit
}

Castle is an IUnit that maintains a military fortification

type Catapult

type Catapult struct {
	BaseUnit
	Movement
}

Catapult is an IUnit that maintains artillery of some sort.

type Cavalry

type Cavalry struct {
	BaseUnit
}

Cavalry is an IUnit that maintains a horse unit

type Farm

type Farm struct {
	BaseUnit
}

Farm is an IUnit that maintains a farm and adds food resources to an IPlayer

type Fence

type Fence struct {
	BaseUnit
}

Fence is an IUnit that maintains a wood fence

type Game

type Game struct {
	// Description of game
	Description string

	// Our players for this game.
	// Once the game begins this array does not change.
	Players []IPlayer

	// The world map that maintains the terrain and units.
	OurWorld *World

	Mechanics []IMechanic

	// Our master pool for frequently used items
	ItemPool *Pool

	// Pathing systems
	Pathing *AStarPathing

	// Command channel
	CommandChannel chan *WirePacket

	// Our TMX map that describes the world.
	// We never load the images of course.
	TMXMap *tmx.Map

	// First and Last Global Tile Identifier for mountains
	MountainsFirstGID int
	MountainsLastGID  int

	// First and Last Global Tile Identifier for grass
	GrassFirstGID int
	GrassLastGID  int

	// First and Last Global Tile Identifier for trees
	TreesFirstGID int
	TreesLastGID  int

	// First and Last Global Tile Identifier for water
	WaterFirstGID int
	WaterLastGID  int

	// First and Last Global Tile Identifier for dirt
	DirtFirstGID int
	DirtLastGID  int

	// First and Last Global Tile Identifier for sand
	SandFirstGID int
	SandLastGID  int

	// First and Last Global Tile Identifier for snow
	SnowFirstGID int
	SnowLastGID  int

	// Spawn locations. Suggested locations for Home bases.
	// They are called spawns or spawn-points in game lingo.
	SpawnLocations []tmx.Object
}

Game is an actual game with UDP ports and IPlayers In theory the rtsengine can maintain N number of simultaneous running Games as long as UDP ports do not overlap.

func NewGame

func NewGame(
	description string,

	filenameTMX string,

	poolItems int,

	noOfHumanPlayers int,
	noOfAIPlayers int,

	playerViewWidth int, playerViewHeight int,

	worldWidth int, worldHeight int) (*Game, error)

NewGame constructs a new game according to the parameters.

func (*Game) AcceptNetConnections

func (game *Game) AcceptNetConnections(host string, port int) error

AcceptNetConnections will accept connections from UI's (humans presumably) and assign them a player. Once all humanplayers are accepted this method returns WITHOUT starting the game. We are waiting at this point ready to go.

func (*Game) AddUnit

func (game *Game) AddUnit(player IPlayer, unit IUnit)

AddUnit will add a unit to this player without a collision within the view.

func (*Game) AddUnitCloseToPoint

func (game *Game) AddUnitCloseToPoint(player IPlayer, unit IUnit, central *image.Point, radius int) error

AddUnitCloseToPoint will add unit to player no further than radius away from the central point. Will ensure no collisions. Central point is in VIEW coordinates.

func (*Game) CommandChannelHandler

func (game *Game) CommandChannelHandler()

CommandChannelHandler will handle the command channel and dispatch the wire packets.

func (*Game) FindPath

func (game *Game) FindPath(source *image.Point, destination *image.Point) (*list.List, error)

FindPath finds a path from source to destination within this game's world and return it as a list of Waypoints

func (*Game) FreeList

func (game *Game) FreeList(l *list.List)

FreeList will free the list return by FindPath

func (*Game) GenerateUnits

func (game *Game) GenerateUnits(player IPlayer, spawnRect *image.Rectangle)

GenerateUnits will construct the starting units per player.

func (*Game) LoadTMX

func (game *Game) LoadTMX(filename string) (*tmx.Map, error)

LoadTMX will load the TMX (XML) file from disk (filename) and returns a pointer ot the tmx MAP. http://doc.mapeditor.org/reference/tmx-map-format/

func (*Game) ReadyToGo

func (game *Game) ReadyToGo() bool

ReadyToGo returns true if we are ready to start a game.

func (*Game) RenderTMX

func (game *Game) RenderTMX()

RenderTMX will read the TMX file (presumably already loaded) and render the terrain items within to our world.

func (*Game) SituateHomeBases

func (game *Game) SituateHomeBases(noOfPlayers int) ([]*image.Rectangle, error)

SituateHomeBases will construct home bases in the proper locations on the world. That is within the world but not overlapping one another. It's possible for large numbers of players on a too small grid this heuristic will not converge and an error will be returned.

func (*Game) Start

func (game *Game) Start()

Start will start the game.

func (*Game) Stop

func (game *Game) Stop()

Stop will stop the game.

type GameMaster

type GameMaster struct {
	GamesList *list.List
}

GameMaster maintains an array of games. The rtsengine can run N number of simultaneous Games each with N number of players.

func NewGameMaster

func NewGameMaster() *GameMaster

NewGameMaster constructs a new game master

func (*GameMaster) Add

func (gameMaster *GameMaster) Add(game *Game)

Add will add the game to the Games Master.

type Goldmine

type Goldmine struct {
	BaseUnit
}

Goldmine is an IUnit that maintains a gold mine

type Grid

type Grid struct {
	// Actual data copy of a portion of the world grid
	Matrix [][]Acre

	// Width and Height of this Grid
	Span image.Rectangle

	// Where the upper left hand corner of this grid
	// is located in world coordinates. If it is 0,0 then
	// WorldOrigin == Grid
	WorldOrigin image.Point

	// Generator Random number generator for this view
	Generator *rand.Rand
}

Grid maintains an acre grid and its span.

func (*Grid) Add

func (grid *Grid) Add(unit IUnit, location *image.Point) error

Add will place the unit in the grid at location. Error is returned if the location is invalid. That is outside the known grid.

func (*Grid) Center

func (grid *Grid) Center() image.Point

Center returns the x,y center of this Grid.

func (*Grid) Collision

func (grid *Grid) Collision(locus *image.Point) bool

Collision returns true if the locus is already occupied by any other unit OR the terrain is inaccessible such as Mountains and Trees.

func (*Grid) DirectLineBresenham

func (grid *Grid) DirectLineBresenham(source *image.Point, destination *image.Point) []image.Point

DirectLineBresenham returns a direct line between two points. This is an integer implemenation and works on all quadrants https://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm Actual implementation https://rosettacode.org/wiki/Bitmap/Bresenham%27s_line_algorithm#Go

func (*Grid) Distance

func (grid *Grid) Distance(source *image.Point, destination *image.Point) float64

Distance between two points using a floating point operation.

func (*Grid) DistanceDiagonelShortcut

func (grid *Grid) DistanceDiagonelShortcut(source *image.Point, destination *image.Point) float64

DistanceDiagonelShortcut is described here: http://www.policyalmanac.org/games/heuristics.htm

func (*Grid) DistanceInteger

func (grid *Grid) DistanceInteger(source *image.Point, destination *image.Point) int

DistanceInteger is the distance algorithm using integer arithmetic. Don't use intermediate variables.

func (*Grid) DistanceManhattan

func (grid *Grid) DistanceManhattan(source *image.Point, destination *image.Point) float64

DistanceManhattan is described here: http://www.policyalmanac.org/games/heuristics.htm

func (*Grid) GenerateGrid

func (grid *Grid) GenerateGrid(worldLocation image.Point, width int, height int)

GenerateGrid will initialize all internal structures. It will set the grid widith and height and situate the grid onto the world at worldLocation

func (*Grid) In

func (grid *Grid) In(worldPoint *image.Point) bool

In returns true if worldPoint is In the grid. False otherwise.

func (*Grid) Overlaps

func (grid *Grid) Overlaps(other *Grid) bool

Overlaps returns true if the other grid overlaps with this grid

func (*Grid) Print

func (grid *Grid) Print()

Print the world as ascii text.

func (*Grid) RandomPointInGrid

func (grid *Grid) RandomPointInGrid() *image.Point

RandomPointInGrid returns a pointer to a point randomly selected within the grid.

func (*Grid) Remove

func (grid *Grid) Remove(unit IUnit)

Remove will eliminate a unit from the grid where-ever it is found. The algorithm presently is brute force.

func (*Grid) RemoveAt

func (grid *Grid) RemoveAt(unit IUnit, location *image.Point)

RemoveAt will remove the unit at location

func (*Grid) Set

func (grid *Grid) Set(locus *image.Point, unit IUnit) error

Set the unit at locus within this grid.

func (*Grid) SqrtHDU32

func (grid *Grid) SqrtHDU32(x uint32) uint32

SqrtHDU32 is the integer square root for unsigned 32 bit values.

func (*Grid) ToGridPoint

func (grid *Grid) ToGridPoint(worldPoint *image.Point) image.Point

ToGridPoint Converts world coordinates to grid coordinates

func (*Grid) ToWorldPoint

func (grid *Grid) ToWorldPoint(gridPoint *image.Point) image.Point

ToWorldPoint converts grid coordinates to world coordinates

type HealthAndAttack

type HealthAndAttack struct {

	// Init at Life == Hitpoints. Life reduces as hits are absorbed
	Life int

	// Default hit points for a particular unit. The more hit points
	// the more abuse a unit can maintain.
	HitPoints int

	// The number of points a single clash deducts from some other
	// units health
	AttackPoints int

	// The number of acres away a unit can attack.
	// 1 means only adjacent acres. 2 means anything two acres away
	// etc
	AttackRange int
}

HealthAndAttack maintains the health statistics of a unit.

func (*HealthAndAttack) IncreaseHealth

func (health *HealthAndAttack) IncreaseHealth(otherUnit *HealthAndAttack)

IncreaseHealth will increase health using the AttackPoints Presumably this would be used by a medic or repair unit. Maxes out at HitPoints obviously.

func (*HealthAndAttack) IsDead

func (health *HealthAndAttack) IsDead() bool

IsDead returns TRUE if this unit has expired.

func (*HealthAndAttack) IsHealthy

func (health *HealthAndAttack) IsHealthy() bool

IsHealthy returns TRUE if this unit has >=40% of its Hitpoints

func (*HealthAndAttack) IsPerfectlyHealthy

func (health *HealthAndAttack) IsPerfectlyHealthy() bool

IsPerfectlyHealthy returns TRUE if this unit has no damage at all.

func (*HealthAndAttack) ReduceHealth

func (health *HealthAndAttack) ReduceHealth(otherUnit *HealthAndAttack)

ReduceHealth reduces the health of this unit by the AttackPoints held within otherUnit. The argument otherUnit presumably is the Health of some other attacking unit.

type HomeStead

type HomeStead struct {
	BaseUnit
}

HomeStead is an IUnit that maintains a homestead that generates peasants

type HumanPlayer

type HumanPlayer struct {
	// Structures common to all players.
	BasePlayer

	// Live TCPWire to communicate with UI
	Wire *TCPWire
}

HumanPlayer implements the IPlayer interface for a human player

func NewHumanPlayer

func NewHumanPlayer(description string, worldLocation image.Point, width int, height int, pool *Pool, pathing *AStarPathing, world *World) *HumanPlayer

NewHumanPlayer constructs a HumanPlayer

type IMechanic

type IMechanic interface {
	// contains filtered or unexported methods
}

IMechanic encapsulates are particular mechanic managed by the game.

type IPlayer

type IPlayer interface {

	// Returns this player's view
	PlayerView() *View

	// Returns this player's view
	PlayerUnits() *UnitMap
	// contains filtered or unexported methods
}

IPlayer encapsulates are particular mechanic managed by the game.

type IPoolable

type IPoolable interface {
	IsAllocated() bool
	Allocate()
	Deallocate()
}

IPoolable objects can be pooled obviously

type IUnit

type IUnit interface {
	IPoolable
	// contains filtered or unexported methods
}

IUnit is an interface to all unit within the World and can reside within an Acre.

type Infantry

type Infantry struct {
	BaseUnit
}

Infantry is an IUnit that maintains a foot soldier unit. Like a century or company

type Movement

type Movement struct {
	// Last actual movement of this unit
	LastMovement time.Time

	// Movement delta in milliseconds.
	// Thus if this was 500 that would be 2 movements potentially per second.
	// 1000 would be one movement per second etcetera.
	DeltaInMillis int64

	// Destination in world coordinates if a move is in progress.
	MovementDestination *image.Point

	// Current location in world coordinates
	CurrentLocation *image.Point
}

Movement maintains state of the movement capabilities of a unit Stationary only units like a Home or Fence lack this structure.

func (*Movement) CanMove

func (move *Movement) CanMove() bool

CanMove returns true if this unit may move now given the current time. If the elapsed time Sinc Lastmovement is greater than the DeltaInMillis return true.

func (*Movement) UpdateLastMovement

func (move *Movement) UpdateLastMovement()

UpdateLastMovement will update the LastMovement of this unit to the current instant in time.

type MovementMechanic

type MovementMechanic struct {
	// The world map that maintains the terrain and units.
	OurWorld *World

	// Command channel
	CommandChannel chan *WirePacket

	// All players in the game
	Players []IPlayer

	// Pathing systems
	Pathing *AStarPathing

	OurGame *Game
	// contains filtered or unexported fields
}

MovementMechanic handles the global movement of units

func NewMovementMechanic

func NewMovementMechanic(world *World, cc chan *WirePacket, players []IPlayer, pathing *AStarPathing, ourgame *Game) *MovementMechanic

NewMovementMechanic factory

type Peasant

type Peasant struct {
	BaseUnit
}

Peasant is an IUnit. Basic non-combatant that produces resources.

type Pool

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

Pool will pool several types of structures.

func (*Pool) Archers

func (pool *Pool) Archers(n int) []*Archer

Archers allocated n at a time.

func (*Pool) Castles

func (pool *Pool) Castles(n int) []*Castle

Castles allocated n at a time.

func (*Pool) Catapults

func (pool *Pool) Catapults(n int) []*Catapult

Catapults allocated n at a time.

func (*Pool) Cavalry

func (pool *Pool) Cavalry(n int) []*Cavalry

Cavalry allocated n at a time.

func (*Pool) Farms

func (pool *Pool) Farms(n int) []*Farm

Farms allocated n at a time.

func (*Pool) Fences

func (pool *Pool) Fences(n int) []*Fence

Fences allocated n at a time.

func (*Pool) Free

func (pool *Pool) Free(object IPoolable)

Free will deallocate the object and return it to the pool

func (*Pool) Generate

func (pool *Pool) Generate(items int)

Generate a pool of all internal structures of maximum length items.

func (*Pool) Goldmines

func (pool *Pool) Goldmines(n int) []*Goldmine

Goldmines allocated n at a time.

func (*Pool) Infantry

func (pool *Pool) Infantry(n int) []*Infantry

Infantry allocated n at a time.

func (*Pool) Peasants

func (pool *Pool) Peasants(n int) []*Peasant

Peasants allocated n at a time.

func (*Pool) PrintAllocatedWaypoints

func (pool *Pool) PrintAllocatedWaypoints()

PrintAllocatedWaypoints prints the number of still allocated waypoints in the pool

func (*Pool) Ships

func (pool *Pool) Ships(n int) []*Ship

Ships allocated n at a time.

func (*Pool) StoneQuarry

func (pool *Pool) StoneQuarry(n int) []*StoneQuarry

StoneQuarry allocated n at a time.

func (*Pool) Towers

func (pool *Pool) Towers(n int) []*Tower

Towers allocated n at a time.

func (*Pool) Walls

func (pool *Pool) Walls(n int) []*Wall

Walls allocated n at a time.

func (*Pool) Waypoints

func (pool *Pool) Waypoints(n int) []*Waypoint

Waypoints allocated n at a time.

func (*Pool) Woodpiles

func (pool *Pool) Woodpiles(n int) []*WoodPile

Woodpiles allocated n at a time.

type Poolable

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

Poolable objects can be pooled obviously

func (*Poolable) Allocate

func (poolable *Poolable) Allocate()

Allocate this object from the pool

func (*Poolable) Deallocate

func (poolable *Poolable) Deallocate()

Deallocate this object from the pool

func (*Poolable) IsAllocated

func (poolable *Poolable) IsAllocated() bool

IsAllocated is true if this object was previously allocated and thus not available.

type Ship

type Ship struct {
	BaseUnit
}

Ship is an IUnit that maintains a military vessel of some sort.

type StoneQuarry

type StoneQuarry struct {
	BaseUnit
}

StoneQuarry is an IUnit that maintains a stone quarry

type TCPWire

type TCPWire struct {
	Connection  net.Conn
	JSONDecoder *json.Decoder
	JSONEncoder *json.Encoder
}

TCPWire encapsulates our TCP wire connection.

func (*TCPWire) Receive

func (wire *TCPWire) Receive(packet *WirePacket) error

Receive wire packet over the wire and returns any error

func (*TCPWire) ReceiveCheckEOF

func (wire *TCPWire) ReceiveCheckEOF(packet *WirePacket) bool

ReceiveCheckEOF accepts packet over the wire and returns TRUE if EOF encountered

func (*TCPWire) Send

func (wire *TCPWire) Send(packetArray []WirePacket) error

Send a packetarray over the wire. Returns any error

func (*TCPWire) SendAll

func (wire *TCPWire) SendAll(packets ...*WirePacket) error

SendAll will send N number of packets in a single send over the wire.

func (*TCPWire) SendCheckEOF

func (wire *TCPWire) SendCheckEOF(packetArray []WirePacket) bool

SendCheckEOF will send packetArray over the wire. If send failed and EOF detected TRUE is returned.

type Terrain

type Terrain byte

Terrain enumeration

const (
	// Grass is the default.
	Grass Terrain = iota

	// Mountains are assumed to be any stoney structure
	Mountains

	// Trees are 0..N number of trees.
	Trees

	// Water is just that. An ocean is just a large number of these.
	Water

	// Sand is more or less a desert terrain.
	Sand

	// Snow is the white stuff.
	Snow

	// Dirt is dirt.
	Dirt
)

type Tower

type Tower struct {
	BaseUnit
}

Tower is an IUnit that maintains a military watch tower with some defensive capability

type UDPWire

type UDPWire struct {
	Host       string
	Port       string
	Connection net.PacketConn
}

UDPWire encapsulates our UDP wire connection.

type UnitMap

type UnitMap struct {
	Map map[int]IUnit
}

UnitMap maintains a map of IUnits

func (*UnitMap) Add

func (unitmap *UnitMap) Add(unit IUnit)

Add the unit to the UnitMap

func (*UnitMap) AddAll

func (unitmap *UnitMap) AddAll(objects ...IUnit)

AddAll units to the UniMap.

func (*UnitMap) AllUnits

func (unitmap *UnitMap) AllUnits() map[int]IUnit

AllUnits returns the map

func (*UnitMap) Remove

func (unitmap *UnitMap) Remove(unit IUnit)

Remove will remove the unit from the map

type UnitType

type UnitType byte

UnitType is the type of unit

const (
	// UnitArcher or other ranged unit
	UnitArcher UnitType = iota + 1

	// UnitArmory produces soldiers
	UnitArmory
	// UnitCastle fortification
	UnitCastle
	// UnitCatapult or other artillery
	UnitCatapult
	// UnitCavalry or mobile units
	UnitCavalry
	// UnitFarm or food production
	UnitFarm
	// UnitFence wood pallasade or abitus
	UnitFence
	// UnitGoldMine for gold
	UnitGoldMine
	// UnitHomeStead for creating a population
	UnitHomeStead
	// UnitInfantry or foot soldiers
	UnitInfantry
	// UnitPeasant is any villager
	UnitPeasant
	// UnitShip or some military vessel
	UnitShip
	// UnitStoneQuarry produces building material.
	UnitStoneQuarry
	// UnitTower or scout position
	UnitTower
	// UnitWall or defensive parameter
	UnitWall
	// UnitWoodPile or wood production
	UnitWoodPile
)

type View

type View struct {
	// Width and Height of this Grid
	Span image.Rectangle

	// Where the upper left hand corner of this grid
	// is located in world coordinates. If it is 0,0 then
	// WorldOrigin == Grid
	WorldOrigin image.Point

	// Generator Random number generator for this view
	Generator *rand.Rand
}

View is a projection onto the World Grid

func (*View) Center

func (view *View) Center() image.Point

Center returns the x,y center of this View.

func (*View) CenterOfRect

func (view *View) CenterOfRect(rect *image.Rectangle) image.Point

CenterOfRect returns the center of the Rectangle passed as a parameter.

func (*View) GenerateView

func (view *View) GenerateView(worldLocation image.Point, width int, height int)

GenerateView will initialize all internal structures. It will set the grid widith and height and situate the view onto the world at worldLocation

func (*View) In

func (view *View) In(worldPoint *image.Point) bool

In returns true if worldPoint is In the view. False otherwise.

func (*View) Overlaps

func (view *View) Overlaps(other *View) bool

Overlaps returns true if the other view overlaps with this view

func (*View) RandomPointCloseToPoint

func (view *View) RandomPointCloseToPoint(locus *image.Point, maxDistance int) *image.Point

RandomPointCloseToPoint will generate a point close to locus no farther than maxDistance away

func (*View) RandomPointInView

func (view *View) RandomPointInView() *image.Point

RandomPointInView returns a pointer to a point randomly selected within the view.

func (*View) ToViewPoint

func (view *View) ToViewPoint(worldPoint *image.Point) image.Point

ToViewPoint Converts world coordinates to view coordinates

func (*View) ToWorldPoint

func (view *View) ToWorldPoint(viewPoint *image.Point) image.Point

ToWorldPoint converts view coordinates to world coordinates

type Wall

type Wall struct {
	BaseUnit
}

Wall is an IUnit that maintains a stone (masonry) wall or defensive fortification like an abatis.

type Waypoint

type Waypoint struct {
	Poolable

	// The parent Waypoint in a path
	Parent *Waypoint

	// Location in the World Grid in world coordinates
	Locus image.Point

	// Scoring.
	// g is the cost it takes to get to this Waypoint
	// h is our guess (heuristic) as to how much it'll cost to reach the goal from that node
	// f = g + h so f is the final cost. The lower the better.
	F, G, H float64

	// Position (also known as a neihborhood
	Position int
}

Waypoint maintains scoring for a waypoint in the World Grid.

func (*Waypoint) Print

func (s *Waypoint) Print()

Print will dump the contents of this Waypoint

type WireCommand

type WireCommand byte

WireCommand enumeration

const (
	// NOOP is the no operation
	NOOP WireCommand = iota + 1

	// MoveUnit moves unit to and fro. The rts-engine produces this command
	MoveUnit

	// PathUnitToLocation will set the destination of a unit to the CurrentX, CurrentY
	// does starting a pathing operation for the unit. Used by both client and rts-engine.
	PathUnitToLocation

	// NewUnitAdded means a new unit has been generated and added to the world.
	NewUnitAdded

	// UnitDestroyed means just that. That means dead and should be removed.
	UnitDestroyed

	// FullRefreshPlayerToUI means a screen refresh inwhich every acre of a player's view
	// is sent over the wire.
	FullRefreshPlayerToUI

	// PartialRefreshPlayerToUI means a screen refresh inwhich every unit and non-grass acre
	// is sent over the wire. Tha means the UI should assume missing acres are grass
	// Simple alogorithm for reducing chatter.
	PartialRefreshPlayerToUI

	// CancelMove will cancel a move in progress
	CancelMove

	// UnitStateRefresh means the complete state of a unit is sent over the wire to the ui.
	UnitStateRefresh

	// ResourceUpdate means the current tally of resources of a player should be sent over the wire to the ui.
	ResourceUpdate

	// ScrollView scrolls the view to the new x and y which is ToX and ToY
	ScrollView

	// SetView will set the view directly to world coordinates WorldX, WorldY, Width and Height.
	SetView

	// FullView will set the view to the entire World. Used mostly for testing.
	FullView

	// WhoAmI queries the rtsengine to return information on the current user connection.
	WhoAmI
)

type WirePacket

type WirePacket struct {
	Command WireCommand

	// The tarrain at CurrentX and CurrentY
	LocalTerrain Terrain

	// Unit ID. <= 0 if no ID
	UnitID int

	// Is the unique ID of the player that owns the unit.
	// OwnerPlayerID  <= 0 if no ID and thus the unit is owned by nobody.
	OwnerPlayerID int

	// The Type of Unit if any. <=0 means no unit
	Unit UnitType

	// Used in MoveUnit, NewUnitAdded, NewUnitAdded, CancelMove, UnitStateRefresh, UnitDestroyed, ScrollView
	CurrentRow, CurrentColumn int // View Coordinates

	// Used in ResourceUpdate
	Gold, Wood, Food, Stone int

	// UnitStateRefresh
	Life int

	// For the World
	WorldWidth, WorldHeight, WorldRow, WorldColumn int // World Coordinates

	// For the View. The ViewRow and ViewColumn are in world coordinates
	// FullView uses these. SetView sets the new ViewWidth and ViewHeight
	ViewWidth, ViewHeight, ViewRow, ViewColumn int

	// WhoAmI fills this in and nothing more.
	PlayerName string // name of this player
	PlayerID   int    // unique ID of this player

}

WirePacket is a packet of data that can be JSON marshalled/unmarshalled and sent over the wire. Naming of the fields is IMPORTANT so careful.

func (*WirePacket) Clear

func (p *WirePacket) Clear()

Clear will reinitialize the structure for reuse.

func (*WirePacket) Print

func (p *WirePacket) Print()

Print will dump the contents of the packet

type WoodPile

type WoodPile struct {
	BaseUnit
}

WoodPile is an IUnit that maintains a wood pile that provides wood.

type World

type World struct {
	Grid
}

World maintains the world state. This is the big one!

func NewWorld

func NewWorld(width int, height int) *World

NewWorld will construct a random world of width and height specified. works on 'this'. Another way of thinking is width are the columns and height are the rows.

func (*World) Center

func (world *World) Center() image.Point

Center returns the x,y center of this View.

func (*World) GenerateGrassWorld

func (world *World) GenerateGrassWorld()

GenerateGrassWorld will generate a world of grass....

func (*World) GenerateSimple

func (world *World) GenerateSimple()

GenerateSimple will generate a simple world for basic testing. Good for testing pathing etcetera.

Jump to

Keyboard shortcuts

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