Documentation ¶
Overview ¶
Package remote contains a server to remote control the game world.
Index ¶
- func Backward(w *core.World, owner, tankID string) string
- func BuyTank(w *core.World, owner, armor, damage, weapon string) string
- func CloseTargets(w *core.World, tankID string, filter ...string) string
- func Fire(w *core.World, owner, tankID, angle, distance string) string
- func FireAt(w *core.World, owner, tankID, x, y string) string
- func Forward(w *core.World, owner, tankID string) string
- func GameStatus(w *core.World) string
- func Left(w *core.World, owner, tankID string) string
- func MyName(owner string) string
- func PossibleTargets(w *core.World, tankID string, filter ...string) string
- func Right(w *core.World, owner, tankID string) string
- func RunServer(host, port string, world *core.World)
- func SetMacro(w *core.World, owner, tankID, mco string) string
- func SetMacroMoveTo(w *core.World, owner, tankID, x, y string) string
- func Stop(w *core.World, owner, tankID string) string
- func TankStatus(w *core.World, tankID string) string
- type JsonPosition
- type JsonProjectile
- type JsonTank
- type JsonTarget
- type JsonTargets
- type JsonWeapon
- type JsonWorld
- type TcpClient
- func (tc *TcpClient) Backward(tankID string) string
- func (tc *TcpClient) BuyTank(armor, damage int, weapon string) string
- func (tc *TcpClient) CloseTargets(tankID, f1, f2, f3, f4, f5 string) string
- func (tc *TcpClient) Exit() string
- func (tc *TcpClient) Fire(tankID string, angle, distance int) string
- func (tc *TcpClient) FireAt(tankID string, x, y int) string
- func (tc *TcpClient) Forward(tankID string) string
- func (tc *TcpClient) GameStatus() string
- func (tc *TcpClient) Left(tankID string) string
- func (tc *TcpClient) MyName() string
- func (tc *TcpClient) PossibleTargets(tankID, f1, f2, f3, f4, f5 string) string
- func (tc *TcpClient) Right(tankID string) string
- func (tc *TcpClient) SetMacro(tankID, macro string) string
- func (tc *TcpClient) SetMacroMoveTo(tankID string, x, y int) string
- func (tc *TcpClient) Stop(tankID string) string
- func (tc *TcpClient) TankStatus(tankID string) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CloseTargets ¶
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 ¶
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 GameStatus ¶
GameStatus returns a json with all world data.
func PossibleTargets ¶
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 RunServer ¶
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 ¶
SetMacro sets a macro that is called with every update. (see MacroAttackMove, MacroFireWall, MacroFireAndManeuver, MacroGuardMode and MacroReset)
func SetMacroMoveTo ¶
SetMacroMoveTo sets a special macro with a position that is called with every update.
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 ¶
NewJsonTank convert a core object to a json 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 ¶
NewJsonWorld convert a core object to a json 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 (*TcpClient) CloseTargets ¶
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) Fire ¶
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 ¶
FireAt is a wrapper for Fire() and convert the position to fireAngle and distance.
func (*TcpClient) GameStatus ¶
GameStatus returns a json with all world data.
func (*TcpClient) MyName ¶
MyName returns the active player of this connection (RedTank or BlueTank)
func (*TcpClient) PossibleTargets ¶
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) SetMacroMoveTo ¶
SetMacroMoveTo sets a special macro with a position that is called with every update.
func (*TcpClient) TankStatus ¶
TankStatus returns a json with all data of a requested tank.