rewrite of the stats system

This commit is contained in:
Fraser Graham
2014-01-16 00:02:59 -08:00
parent 90b7731865
commit 3fa53daadb
7 changed files with 46 additions and 14 deletions
+6 -4
View File
@@ -29,6 +29,7 @@ type Robot struct {
Hit bool `json:"hit"`
Probe *v.Point2d `json:"probe"`
ProbeResult *v.Point2d `json:"probe_result"`
gameStats *BotStats `json:-`
}
// This is the subset of data we send to players about robots
@@ -323,7 +324,7 @@ func (r *Robot) Tick(g *game) {
}
if r.FireAt != nil {
proj := r.fire(g.projectiles, g.turn)
proj := r.fire(g)
if proj != nil {
g.projectiles[proj] = true
}
@@ -384,14 +385,15 @@ func (r *Robot) scan(g *game) {
}
func (r *Robot) fire(projectiles map[*Projectile]bool, turn int) *Projectile {
func (r *Robot) fire(g *game) *Projectile {
// Throttle the fire rate
time_since_fired := (float32(turn) * (delta * 1000)) - (float32(r.LastFired) * (delta * 1000))
time_since_fired := (float32(g.turn) * (delta * 1000)) - (float32(r.LastFired) * (delta * 1000))
if time_since_fired < float32(r.Stats.FireRate) {
return nil
}
r.LastFired = turn
r.LastFired = g.turn
r.gameStats.Shots++
return &Projectile{
Id: idg.Hash(),