recv the calculated stats values

This commit is contained in:
Stephen McQuay 2014-01-23 22:33:05 -08:00
parent b964a14bba
commit 7cb38a76aa
3 changed files with 41 additions and 19 deletions

View File

@ -69,15 +69,15 @@ type ProbeResult struct {
} }
type Stats struct { type Stats struct {
Hp int `json:"-"` Hp int `json:"hp"`
Speed float32 `json:"-"` Speed float32 `json:"speed"`
Acceleration float32 `json:"-"` Acceleration float32 `json:"acceleration"`
WeaponRadius int `json:"-"` WeaponRadius int `json:"weapon_radius"`
ScannerRadius int `json:"-"` ScannerRadius int `json:"scanner_radius"`
TurnSpeed int `json:"-"` TurnSpeed int `json:"turn_speed"`
FireRate int `json:"-"` FireRate int `json:"fire_rate"`
WeaponDamage int `json:"-"` WeaponDamage int `json:"weapon_damage"`
WeaponSpeed float32 `json:"-"` WeaponSpeed float32 `json:"weapon_speed"`
} }
type Projectile struct { type Projectile struct {
@ -163,3 +163,8 @@ type BotHealth struct {
RobotId string `json:"robot_id"` RobotId string `json:"robot_id"`
Health int `json:"health"` Health int `json:"health"`
} }
type Failure struct {
Reason string `json:"reason"`
Type string `json:"type"`
}

View File

@ -51,7 +51,7 @@ func main() {
Name: gameName, Name: gameName,
}, },
// XXX: update with missing fields // XXX: update with missing fields
stats: StatsRequest{ statsReq: StatsRequest{
Hp: *hp, Hp: *hp,
Speed: *speed, Speed: *speed,
Acceleration: *acceleration, Acceleration: *acceleration,

View File

@ -28,7 +28,8 @@ type robot struct {
game GameParam game GameParam
playerId string playerId string
name string name string
stats StatsRequest statsReq StatsRequest
statsCalculated Stats
speed float32 speed float32
moveto *govector.Point2d moveto *govector.Point2d
@ -96,7 +97,7 @@ func (r *robot) negociate() (err error) {
conf := ClientConfig{ conf := ClientConfig{
ID: r.game.Name, ID: r.game.Name,
Stats: map[string]StatsRequest{ 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"` Id string `json:"id"`
Success bool `json:"success"` Success bool `json:"success"`
Type string `json:"type"` Type string `json:"type"`
Failure
} }
websocket.JSON.Receive(r.ws, &handshake) websocket.JSON.Receive(r.ws, &handshake)
if !handshake.Success { if !handshake.Success {
return errors.New("failed to validate correct stats request") return errors.New(handshake.Reason)
} }
r.playerId = handshake.Id r.playerId = handshake.Id
if *verbose { if *verbose {
log.Printf("%s: handshake: %+v", r.name, handshake) 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 return nil
} }