remote

package
v0.0.0-...-b239de3 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package remote contains a server to remote control the game world.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Backward

func Backward(w *core.World, owner, tankID string) string

Backward send the tank back.

func BuyTank

func BuyTank(w *core.World, owner, armor, damage, weapon string) string

BuyTank buy a new tank and place it near the home base.

func CloseTargets

func CloseTargets(w *core.World, tankID string, filter ...string) string

CloseTargets returns all objects in the world that are theoretical in weapon range. The weapon type is irrelevant (WeaponCannon or WeaponArtillery) and the angle of the tank is ignored. The list is sorted by distance (from the closest to the farthest).

func Fire

func Fire(w *core.World, owner, tankID, angle, distance string) string

Fire creates a new projectile. The attributes fireAngle and distance determine the direction and distance of the shot. Cannons can fire in vehicle angle only. The distance is limited by the weapon range.

func FireAt

func FireAt(w *core.World, owner, tankID, x, y string) string

FireAt is a wrapper for Fire() and convert the position to fireAngle and distance.

func Forward

func Forward(w *core.World, owner, tankID string) string

Forward send the tank forward.

func GameStatus

func GameStatus(w *core.World) string

GameStatus returns a json with all world data.

func Left

func Left(w *core.World, owner, tankID string) string

Left turn the tank direction 45° left.

func MyName

func MyName(owner string) string

MyName returns the active player of this connection (RedTank or BlueTank)

func PossibleTargets

func PossibleTargets(w *core.World, tankID string, filter ...string) string

PossibleTargets extends CloseTargets. It only returns objects that can actually be attacked,depending on the weapon type. However, it may be necessary for the battle tank to change its angle. The list is sorted by the rotation required to reach the target.

func Right(w *core.World, owner, tankID string) string

Right turn the tank direction 45° right.

func RunServer

func RunServer(host, port string, world *core.World)

RunServer runs a server (BLOCKING!). The server receives commands from the clients and implements them in "World". The first connecting client controls player red. The second connecting client controls player blue.

func SetMacro

func SetMacro(w *core.World, owner, tankID, mco string) string

SetMacro sets a macro that is called with every update. (see MacroAttackMove, MacroFireWall, MacroFireAndManeuver, MacroGuardMode and MacroReset)

func SetMacroMoveTo

func SetMacroMoveTo(w *core.World, owner, tankID, x, y string) string

SetMacroMoveTo sets a special macro with a position that is called with every update.

func Stop

func Stop(w *core.World, owner, tankID string) string

Stop the movement. Weapons can only build up when the tank is stationary

func TankStatus

func TankStatus(w *core.World, tankID string) string

TankStatus returns a json with all data of a requested tank.

Types

type JsonPosition

type JsonPosition struct {
	X  int     `json:"x"`
	Xf float64 `json:"xf"`
	Y  int     `json:"y"`
	Yf float64 `json:"yf"`
}

JsonPosition is the protocol struct of core.Position

func NewJsonPosition

func NewJsonPosition(p core.Position) JsonPosition

NewJsonPosition convert a core object to a json object

func (*JsonPosition) Get

func (p *JsonPosition) Get() string

Get returns a json representation of this object

func (*JsonPosition) Set

func (p *JsonPosition) Set(j string)

Set parse a json string and update the inner variables of this object

type JsonProjectile

type JsonProjectile struct {
	Parent    string       `json:"parent"`
	Pos       JsonPosition `json:"pos"`
	StartPos  JsonPosition `json:"startPos"`
	EndPos    JsonPosition `json:"endPos"`
	Angle     int          `json:"angle"`
	Distance  int          `json:"distance"`
	Speed     int          `json:"speed"`
	Damage    int          `json:"damage"`
	AoeRadius int          `json:"aoeRadius"`
	Collision bool         `json:"collision"`
	Exploded  bool         `json:"exploded"`
}

JsonProjectile is the protocol struct of core.Projectile

func NewJsonProjectile

func NewJsonProjectile(p *core.Projectile) JsonProjectile

NewJsonProjectile convert a core object to a json object

func (*JsonProjectile) Get

func (p *JsonProjectile) Get() string

Get returns a json representation of this object

func (*JsonProjectile) Set

func (p *JsonProjectile) Set(j string)

Set parse a json string and update the inner variables of this object

type JsonTank

type JsonTank struct {
	ID          string       `json:"id"`
	Owner       string       `json:"owner"`
	Health      int          `json:"health"`
	Armor       int          `json:"armor"`
	Speed       int          `json:"speed"`
	Pos         JsonPosition `json:"pos"`
	Command     int          `json:"command"`
	Angle       int          `json:"angle"`
	IsBlocked   bool         `json:"isBlocked"`
	ActiveMacro bool         `json:"activeMacro"`
	Alive       bool         `json:"alive"`
	Moving      bool         `json:"moving"`
	LastRotate  uint64       `json:"lastRotate"`
	Rdy         bool         `json:"rdy"`
	Status      string       `json:"status"`
	Weapon      JsonWeapon   `json:"weapon"`
}

JsonTank is the protocol struct of core.Tank

func NewJsonTank

func NewJsonTank(t *core.Tank) JsonTank

NewJsonTank convert a core object to a json object

func (*JsonTank) Get

func (t *JsonTank) Get() string

Get returns a json representation of this object

func (*JsonTank) Set

func (t *JsonTank) Set(j string)

Set parse a json string and update the inner variables of this object

type JsonTarget

type JsonTarget struct {
	TankID        string `json:"tankID"`
	Distance      int    `json:"distance"`
	RelativeAngle int    `json:"relativeAngle"`
}

JsonTarget is the protocol struct of core.Target

func NewJsonTarget

func NewJsonTarget(t core.Target) JsonTarget

NewJsonTarget convert a core object to a json object

type JsonTargets

type JsonTargets []JsonTarget

JsonTargets is the protocol list of core.Target

func NewJsonTargets

func NewJsonTargets(ts []core.Target) JsonTargets

NewJsonTargets convert a core object list to a json object

func (*JsonTargets) Get

func (ts *JsonTargets) Get() string

Get returns a json representation of this object

func (*JsonTargets) Set

func (ts *JsonTargets) Set(j string)

Set parse a json string and update the inner variables of this object

type JsonWeapon

type JsonWeapon struct {
	Typ           string `json:"typ"`
	Rng           int    `json:"rng"`
	PrepTime      uint64 `json:"prepTime"`
	ReloadTime    uint64 `json:"reloadTime"`
	ProjSpeed     int    `json:"projSpeed"`
	Damage        int    `json:"damage"`
	AoeRadius     int    `json:"aoeRadius"`
	ProjCollision bool   `json:"projCollision"`
	AnyFireAngle  bool   `json:"anyFireAngle"`
	Rdy           bool   `json:"rdy"`
	Status        string `json:"status"`
	LastMove      uint64 `json:"lastMove"`
	LastFire      uint64 `json:"lastFire"`
}

JsonWeapon is the protocol struct of core.Weapon

func NewJsonWeapon

func NewJsonWeapon(w *core.Weapon) JsonWeapon

NewJsonWeapon convert a core object to a json object

func (*JsonWeapon) Get

func (w *JsonWeapon) Get() string

Get returns a json representation of this object

func (*JsonWeapon) Set

func (w *JsonWeapon) Set(j string)

Set parse a json string and update the inner variables of this object

type JsonWorld

type JsonWorld struct {
	GameSpeed     int              `json:"gameSpeed"`
	MovePerTick   float64          `json:"movePerTick"`
	TankRadius    int              `json:"tankRadius"`
	BallRadius    int              `json:"ballRadius"`
	RotationDelay int              `json:"rotationDelay"`
	TankBudget    int              `json:"tankBudget"`
	MinSpeed      int              `json:"minSpeed"`
	MinArmor      int              `json:"minArmor"`
	MaxArmor      int              `json:"maxArmor"`
	MinDamage     int              `json:"minDamage"`
	MaxDamage     int              `json:"maxDamage"`
	XWidth        int              `json:"xWidth"`
	YHeight       int              `json:"yHeight"`
	ScreenWidth   int              `json:"screenWidth"`
	ScreenHeight  int              `json:"screenHeight"`
	Iteration     uint64           `json:"iteration"`
	Freeze        bool             `json:"freeze"`
	CashRed       int              `json:"cashRed"`
	CashBlue      int              `json:"cashBlue"`
	Tanks         []JsonTank       `json:"tanks"`
	Projectiles   []JsonProjectile `json:"projectiles"`
	UnitCountRed  int              `json:"unitCountRed"`
	UnitCountBlue int              `json:"unitCountBlue"`
}

JsonWorld is the protocol struct of core.World

func NewJsonWorld

func NewJsonWorld(w *core.World) JsonWorld

NewJsonWorld convert a core object to a json object

func (*JsonWorld) CoreWorld

func (w *JsonWorld) CoreWorld() *core.World

CoreWorld build and returns a new core.World.

func (*JsonWorld) Get

func (w *JsonWorld) Get() string

Get returns a json representation of this object

func (*JsonWorld) Set

func (w *JsonWorld) Set(j string)

Set parse a json string and update the inner variables of this object

type TcpClient

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

TcpClient is an API to access a server and to remote control player tanks.

func NewTcpClient

func NewTcpClient(host, port string) *TcpClient

NewTcpClient init a TcpClient

func (*TcpClient) Backward

func (tc *TcpClient) Backward(tankID string) string

Backward send the tank back.

func (*TcpClient) BuyTank

func (tc *TcpClient) BuyTank(armor, damage int, weapon string) string

BuyTank buy a new tank and place it near the home base.

func (*TcpClient) CloseTargets

func (tc *TcpClient) CloseTargets(tankID, f1, f2, f3, f4, f5 string) string

CloseTargets returns all objects in the world that are theoretical in weapon range. The weapon type is irrelevant (WeaponCannon or WeaponArtillery) and the angle of the tank is ignored. The list is sorted by distance (from the closest to the farthest).

func (*TcpClient) Exit

func (tc *TcpClient) Exit() string

Exit kills the server (for tests only).

func (*TcpClient) Fire

func (tc *TcpClient) Fire(tankID string, angle, distance int) string

Fire creates a new projectile. The attributes fireAngle and distance determine the direction and distance of the shot. Cannons can fire in vehicle angle only. The distance is limited by the weapon range.

func (*TcpClient) FireAt

func (tc *TcpClient) FireAt(tankID string, x, y int) string

FireAt is a wrapper for Fire() and convert the position to fireAngle and distance.

func (*TcpClient) Forward

func (tc *TcpClient) Forward(tankID string) string

Forward send the tank forward.

func (*TcpClient) GameStatus

func (tc *TcpClient) GameStatus() string

GameStatus returns a json with all world data.

func (*TcpClient) Left

func (tc *TcpClient) Left(tankID string) string

Left turn the tank direction 45° left.

func (*TcpClient) MyName

func (tc *TcpClient) MyName() string

MyName returns the active player of this connection (RedTank or BlueTank)

func (*TcpClient) PossibleTargets

func (tc *TcpClient) PossibleTargets(tankID, f1, f2, f3, f4, f5 string) string

PossibleTargets extends CloseTargets. It only returns objects that can actually be attacked,depending on the weapon type. However, it may be necessary for the battle tank to change its angle. The list is sorted by the rotation required to reach the target.

func (*TcpClient) Right

func (tc *TcpClient) Right(tankID string) string

Right turn the tank direction 45° right.

func (*TcpClient) SetMacro

func (tc *TcpClient) SetMacro(tankID, macro string) string

SetMacro sets a macro that is called with every update.

func (*TcpClient) SetMacroMoveTo

func (tc *TcpClient) SetMacroMoveTo(tankID string, x, y int) string

SetMacroMoveTo sets a special macro with a position that is called with every update.

func (*TcpClient) Stop

func (tc *TcpClient) Stop(tankID string) string

Stop the movement. Weapons can only build up when the tank is stationary

func (*TcpClient) TankStatus

func (tc *TcpClient) TankStatus(tankID string) string

TankStatus returns a json with all data of a requested tank.

Jump to

Keyboard shortcuts

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