sorted out initial connection changes

This commit is contained in:
Stephen McQuay 2013-11-10 21:24:41 -08:00
parent 384d6c5ca2
commit 42ba19dd1c

65
main.go
View File

@ -14,8 +14,8 @@ import (
) )
var hp = flag.Int("hp", 50, "") var hp = flag.Int("hp", 50, "")
var speed = flag.Float64("speed", 50, "") var speed = flag.Int("speed", 50, "")
var acceleration = flag.Float64("acceleration", 50, "") var acceleration = flag.Int("acceleration", 50, "")
var weaponRadius = flag.Int("wrad", 50, "weapon radius") var weaponRadius = flag.Int("wrad", 50, "weapon radius")
var scannerRadius = flag.Int("srad", 50, "scanner radius") var scannerRadius = flag.Int("srad", 50, "scanner radius")
var fireRate = flag.Int("fire-rate", 50, "scanner radius") var fireRate = flag.Int("fire-rate", 50, "scanner radius")
@ -30,24 +30,32 @@ type infos struct {
width, height float32 width, height float32
} }
type Stats struct { type ClientConfig struct {
Hp int `json:"hp"` ID string `json:"id"`
Speed float32 `json:"speed"` Stats map[string]StatsRequest `json:"stats"`
Acceleration float32 `json:"acceleration"` }
WeaponRadius int `json:"weapon_radius"`
ScannerRadius int `json:"scanner_radius"` type StatsRequest struct {
FireRate int `json:"fire_rate"` Hp int `json:"hp"`
Speed int `json:"speed"`
Acceleration int `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 int `json:"weapon_speed"`
} }
type Scanner struct { type Scanner struct {
Position govector.Point2d `json:"position"` Position govector.Point2d `json:"position"`
Stats Stats `json:"stats"` Stats StatsRequest `json:"stats"`
} }
type Robot struct { type Robot struct {
Id string `json:"id"` Id string `json:"id"`
Name string `json:"name"` Name string `json:"name"`
Stats Stats `json:"stats"` Stats StatsRequest `json:"stats"`
TargetSpeed float32 `json:"speed"` TargetSpeed float32 `json:"speed"`
Speed float32 `json:"speed"` Speed float32 `json:"speed"`
Health int `json:"health"` Health int `json:"health"`
@ -79,7 +87,7 @@ type Splosion struct {
type Instruction struct { type Instruction struct {
MoveTo *govector.Point2d `json:"move_to,omitempty"` MoveTo *govector.Point2d `json:"move_to,omitempty"`
FireAt *govector.Point2d `json:"fire_at,omitempty"` FireAt *govector.Point2d `json:"fire_at,omitempty"`
Stats Stats `json:"stats"` Stats StatsRequest `json:"stats"`
} }
func connect() (*websocket.Conn, error) { func connect() (*websocket.Conn, error) {
@ -155,23 +163,24 @@ func negociate(ws *websocket.Conn, gameid string) (i *infos, err error) {
} }
log.Printf("%+v", gameparam) log.Printf("%+v", gameparam)
err = websocket.JSON.Send(ws, &struct { conf := ClientConfig{
ID string `json:"id"` ID: gameid,
Name string `json:"name"` Stats: map[string]StatsRequest{
// TODO: candidate for embedding? *botname: StatsRequest{
Stats Stats `json:"stats"` Hp: *hp,
}{ Speed: *speed,
ID: gameid, Acceleration: *acceleration,
Name: *botname, WeaponRadius: *weaponRadius,
Stats: Stats{ ScannerRadius: *scannerRadius,
Hp: *hp, TurnSpeed: 50,
Speed: float32(*speed), FireRate: *fireRate,
Acceleration: float32(*acceleration), WeaponDamage: 50,
WeaponRadius: *weaponRadius, WeaponSpeed: 50,
ScannerRadius: *scannerRadius, },
FireRate: *fireRate,
}, },
}) }
err = websocket.JSON.Send(ws, conf)
var handshake struct { var handshake struct {
ID string `json:"id"` ID string `json:"id"`