From 7cb38a76aa1fb702454f5b86db7aeb1b1b8d0449 Mon Sep 17 00:00:00 2001 From: Stephen McQuay Date: Thu, 23 Jan 2014 22:33:05 -0800 Subject: [PATCH] recv the calculated stats values --- botserv.go | 23 ++++++++++++++--------- main.go | 2 +- robot.go | 35 ++++++++++++++++++++++++++--------- 3 files changed, 41 insertions(+), 19 deletions(-) diff --git a/botserv.go b/botserv.go index 993a08e..236c28c 100644 --- a/botserv.go +++ b/botserv.go @@ -69,15 +69,15 @@ type ProbeResult struct { } 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:"-"` + 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 { @@ -163,3 +163,8 @@ type BotHealth struct { RobotId string `json:"robot_id"` Health int `json:"health"` } + +type Failure struct { + Reason string `json:"reason"` + Type string `json:"type"` +} diff --git a/main.go b/main.go index 15f506c..cfb5a13 100644 --- a/main.go +++ b/main.go @@ -51,7 +51,7 @@ func main() { Name: gameName, }, // XXX: update with missing fields - stats: StatsRequest{ + statsReq: StatsRequest{ Hp: *hp, Speed: *speed, Acceleration: *acceleration, diff --git a/robot.go b/robot.go index cdff203..3e5a54a 100644 --- a/robot.go +++ b/robot.go @@ -22,13 +22,14 @@ func connect(server string, port int) (*websocket.Conn, error) { } type robot struct { - server string - port int - ws *websocket.Conn - game GameParam - playerId string - name string - stats StatsRequest + server string + port int + ws *websocket.Conn + game GameParam + playerId string + name string + statsReq StatsRequest + statsCalculated Stats speed float32 moveto *govector.Point2d @@ -96,7 +97,7 @@ func (r *robot) negociate() (err error) { conf := ClientConfig{ ID: r.game.Name, Stats: map[string]StatsRequest{ - r.name: r.stats, + r.name: r.statsReq, }, } @@ -106,15 +107,31 @@ func (r *robot) negociate() (err error) { Id string `json:"id"` Success bool `json:"success"` Type string `json:"type"` + Failure } websocket.JSON.Receive(r.ws, &handshake) if !handshake.Success { - return errors.New("failed to validate correct stats request") + return errors.New(handshake.Reason) } r.playerId = handshake.Id if *verbose { log.Printf("%s: handshake: %+v", r.name, handshake) } + + dstats := map[string]Stats{} + err = websocket.JSON.Receive(r.ws, &dstats) + if err != nil { + return err + } + + // this player only ever has one robot, so we're just picking off our own + // stats + _, ok := dstats[r.name] + if !ok { + return errors.New("my name not found in stats map") + } + r.statsCalculated = dstats[r.name] + return nil }