client/botserv.go

174 lines
4.9 KiB
Go

package main
import (
"fmt"
"bitbucket.org/hackerbots/vector"
)
type ClientConfig struct {
ID string `json:"id"`
Stats map[string]StatsRequest `json:"stats"`
}
type BoardSize struct {
Width float32 `json:"width"`
Height float32 `json:"height"`
}
// This is kind of misused here; we set Name, but expect to get the other
// values back from the server
type GameParam struct {
BoardSize BoardSize `json:"boardsize"`
MaxPoints int `json:"max_points"`
Name string `json:"name"`
Type string `json:"type"`
Encoding string `json:"encoding"`
}
type StatsRequest struct {
Hp int `json:"hp"`
Speed int `json:"speed"`
Acceleration int `json:"acceleration"`
ScannerRadius int `json:"scanner_radius"`
TurnSpeed int `json:"turn_speed"`
FireRate int `json:"fire_rate"`
WeaponRadius int `json:"weapon_radius"`
WeaponDamage int `json:"weapon_damage"`
WeaponSpeed int `json:"weapon_speed"`
}
type Scanner struct {
Position govector.Point2d `json:"position"`
Stats StatsRequest `json:"stats"`
}
type Robot struct {
Id string `json:"id"`
Name string `json:"name"`
Message string `json:"-"`
Stats Stats `json:"-"`
TargetSpeed float32 `json:"-"`
Speed float32 `json:"speed"`
Health int `json:"health"`
RepairCounter float32 `json:"repair"`
ScanCounter float32 `json:"scan_bonus"`
ActiveScan bool `json:"-"`
Position govector.Point2d `json:"position"`
Heading govector.Vector2d `json:"heading"`
MoveTo *govector.Point2d `json:"-"`
FireAt *govector.Point2d `json:"-"`
Scanners []Scanner `json:"scanners"`
LastFired int `json:"-"`
Collision *Collision `json:"collision"`
Hit bool `json:"hit"`
Probe *govector.Point2d `json:"probe"`
ProbeResult *Collision `json:"probe_result"`
}
type Collision struct {
govector.Point2d
Type string `json:"type"`
}
type Stats struct {
Hp int `json:"hp"`
Speed float32 `json:"speed"`
Acceleration float32 `json:"acceleration"`
WeaponRadius int `json:"weapon_radius"`
ScannerRadius int `json:"scanner_radius"`
TurnSpeed int `json:"turn_speed"`
FireRate int `json:"fire_rate"`
WeaponDamage int `json:"weapon_damage"`
WeaponSpeed float32 `json:"weapon_speed"`
}
type Projectile struct {
Id string `json:"id"`
Position govector.Point2d `json:"position"`
MoveTo govector.Point2d `json:"move_to"`
Radius int `json:"radius"`
Speed float32 `json:"speed"`
Damage int `json:"damage"`
}
type Splosion struct {
Id string `json:"id"`
Position govector.Point2d `json:"position"`
Radius int `json:"radius"`
MaxDamage int `json:"damage"`
MinDamage int `json:"damage"`
Lifespan int `json:"lifespan"`
}
type Instruction struct {
Message *string `json:"message,omitempty"`
MoveTo *govector.Point2d `json:"move_to,omitempty"`
FireAt *govector.Point2d `json:"fire_at,omitempty"`
Probe *govector.Point2d `json:"probe,omitempty"`
TargetSpeed *float32 `json:"target_speed,omitempty"`
Repair *bool `json:"repair,omitempty"`
Scan *bool `json:"scan,omitempty"`
}
type Boardstate struct {
MyRobots []Robot `json:"my_robots"`
OtherRobots []OtherRobot `json:"robots"`
Projectiles []Projectile `json:"projectiles"`
Splosions []Splosion `json:"splosions"`
Obstacles []MiniObstacle `json:"objects"`
Reset bool `json:"reset"`
Type string `json:"type"`
Turn int `json:"turn"`
AllBots []BotHealth `json:"all_bots"`
Messages []string `json:"messages"`
}
type OtherRobot struct {
Id string `json:"id"`
Name string `json:"name"`
Position govector.Point2d `json:"position"`
Heading govector.Vector2d `json:"heading"`
Health int `json:"health"`
}
type MiniObstacle [4]int
func (mo *MiniObstacle) id() string {
return fmt.Sprintf(
"%x%x%x%x",
mo[0],
mo[1],
mo[2],
mo[3],
)
}
func (mo MiniObstacle) String() string {
return mo.id()
}
func (mo *MiniObstacle) toObstacle() Obstacle {
return Obstacle{
Bounds: govector.AABB2d{
A: govector.Point2d{float32(mo[0]), float32(mo[1])},
B: govector.Point2d{float32(mo[2]), float32(mo[3])},
},
}
}
type Obstacle struct {
Bounds govector.AABB2d `json:"bounds"`
Hp int `json:"-"`
}
type BotHealth struct {
RobotId string `json:"robot_id"`
Health int `json:"health"`
}
type Failure struct {
Reason string `json:"reason"`
Type string `json:"type"`
}