sorted out initial connection changes

This commit is contained in:
Stephen McQuay 2013-11-10 21:24:41 -08:00
parent 384d6c5ca2
commit 42ba19dd1c
1 changed files with 37 additions and 28 deletions

65
main.go
View File

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