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 {
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"`
}

View File

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

View File

@ -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
}