client/botserv.go

159 lines
4.4 KiB
Go
Raw Normal View History

2013-11-10 22:32:54 -08:00
package main
import (
"bitbucket.org/hackerbots/vector"
2014-01-10 01:22:33 -08:00
"fmt"
2013-11-10 22:32:54 -08:00
)
type ClientConfig struct {
ID string `json:"id"`
Stats map[string]StatsRequest `json:"stats"`
}
2013-11-10 23:30:23 -08:00
type BoardSize struct {
Width float32 `json:"width"`
Height float32 `json:"height"`
}
type GameParam struct {
BoardSize BoardSize `json:"boardsize"`
name string
Type string `json:"type"`
}
2013-11-10 22:32:54 -08:00
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"`
2013-11-11 00:24:11 -08:00
WeaponRadius int `json:"weapon_radius"`
2013-11-10 22:32:54 -08:00
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 bool `json:"collision"`
Hit bool `json:"hit"`
Probe *govector.Point2d `json:"probe"`
ProbeResult *govector.Point2d `json:"probe_result"`
}
type Stats struct {
Hp int `json:"-"`
Speed float32 `json:"-"`
Acceleration float32 `json:"-"`
WeaponRadius int `json:"-"`
ScannerRadius int `json:"-"`
TurnSpeed int `json:"-"`
FireRate int `json:"-"`
WeaponDamage int `json:"-"`
WeaponSpeed float32 `json:"-"`
}
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 {
2014-01-10 01:22:33 -08:00
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"`
2013-11-10 22:32:54 -08:00
}
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"`
}
2014-01-10 01:22:33 -08:00
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])},
},
}
}
2013-11-10 22:32:54 -08:00
type Obstacle struct {
2013-12-05 12:36:05 -08:00
Bounds govector.AABB2d `json:"bounds"`
2014-01-10 01:22:33 -08:00
Hp int `json:"-"`
2013-11-10 22:32:54 -08:00
}
type BotHealth struct {
RobotId string `json:"robot_id"`
Health int `json:"health"`
}