From 1b42a193930536f5438a27130f163cf145b186cb Mon Sep 17 00:00:00 2001 From: Fraser Graham Date: Thu, 7 Nov 2013 21:34:54 -0800 Subject: [PATCH] active scanning --- game.go | 2 +- player.go | 29 +++++++++++++++++++++++++---- robot.go | 5 +++++ 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/game.go b/game.go index f6da52d..05d2cbe 100644 --- a/game.go +++ b/game.go @@ -214,7 +214,7 @@ func (g *game) send_update(payload *Boardstate) { // Filter objects for _, ob := range g.obstacles { - if ob.distance_from_point(p.Robot.Position) < float32(p.Robot.Stats.ScannerRadius) { + if ob.distance_from_point(p.Robot.Position) < float32(p.Robot.Stats.ScannerRadius)+p.Robot.ScanCounter { player_payload.Obstacles = append( player_payload.Obstacles, ob) diff --git a/player.go b/player.go index 1a270d9..beacb02 100644 --- a/player.go +++ b/player.go @@ -40,15 +40,21 @@ func (p *player) recv() { break } - if msg.Repair != nil { + if msg.Repair != nil && *msg.Repair == true { p.Robot.TargetSpeed = 0 p.Robot.FireAt = nil p.Robot.MoveTo = nil if p.Robot.RepairCounter <= 0 { p.Robot.RepairCounter = 3.0 } + } else if msg.Scan != nil && *msg.Scan == true { + p.Robot.TargetSpeed = 0 + p.Robot.FireAt = nil + p.Robot.MoveTo = nil + p.Robot.ActiveScan = true } else { p.Robot.RepairCounter = 0 + p.Robot.ActiveScan = false // Reapiring halts all other activity if msg.MoveTo != nil { @@ -72,6 +78,10 @@ func (p *player) recv() { } } + if msg.Message != nil { + p.Robot.Message = *msg.Message + } + } log.Printf("player %s: recv close", p.Robot.Id) p.ws.Close() @@ -133,7 +143,7 @@ func (p *player) Tick(g *game) { // Adjust Heading current_heading := p.Robot.Heading - if current_heading.Mag() == 0 { + if current_heading.Mag() == 0 && p.Robot.MoveTo != nil { // We may have been stopped before this and had no heading current_heading = p.Robot.MoveTo.Sub(p.Robot.Position).Normalize() } @@ -199,6 +209,16 @@ func (p *player) Tick(g *game) { } } + // We only self repair when we're stopped + if math.Abs(float64(p.Robot.Speed)) < v.Epsilon && p.Robot.ActiveScan { + p.Robot.ScanCounter += delta * float32(p.Robot.Stats.ScannerRadius) * 0.1 + } else if p.Robot.ScanCounter > 0 { + p.Robot.ScanCounter -= delta * float32(p.Robot.Stats.ScannerRadius) * 0.05 + if p.Robot.ScanCounter <= 0 { + p.Robot.ScanCounter = 0 + } + } + if p.Robot.FireAt != nil { proj := p.fire(g.projectiles, g.turn) if proj != nil { @@ -213,6 +233,7 @@ func (p *player) Tick(g *game) { p.Robot.ProbeResult = &pos } } + } func (p *player) scan(g *game) { @@ -222,7 +243,7 @@ func (p *player) scan(g *game) { continue } dist := v.Distance(player.Robot.Position, p.Robot.Position) - if dist < float32(p.Robot.Stats.ScannerRadius) { + if dist < float32(p.Robot.Stats.ScannerRadius+int(p.Robot.ScanCounter)) { s := Scanner{ Id: player.Robot.Id, Type: "robot", @@ -237,7 +258,7 @@ func (p *player) scan(g *game) { } dist := v.Distance(proj.Position, p.Robot.Position) - if dist < float32(p.Robot.Stats.ScannerRadius) { + if dist < float32(p.Robot.Stats.ScannerRadius+int(p.Robot.ScanCounter)) { s := Scanner{ Id: proj.Id, Type: "projectile", diff --git a/robot.go b/robot.go index 9b6e2b5..39e1fb8 100644 --- a/robot.go +++ b/robot.go @@ -7,11 +7,14 @@ import ( type Robot struct { Id string `json:"id"` Name string `json:"name"` + Message string `json:"-"` Stats Stats `json:"-"` TargetSpeed float32 `json:"-"` Speed float32 `json:"speed"` Health int `json:"health"` RepairCounter float32 `json:"repair"` + ScanCounter float32 `json:"scan_bonus"` + ActiveScan bool `json:"-"` Position v.Point2d `json:"position"` Heading v.Vector2d `json:"heading"` MoveTo *v.Point2d `json:"-"` @@ -158,10 +161,12 @@ func (s StatsRequest) Valid() bool { } type Instruction struct { + Message *string `json:"message,omitempty"` MoveTo *v.Point2d `json:"move_to,omitempty"` FireAt *v.Point2d `json:"fire_at,omitempty"` Probe *v.Point2d `json:"probe,omitempty"` TargetSpeed *float32 `json:"target_speed,omitempty"` Repair *bool `json:"repair,omitempty"` + Scan *bool `json:"scan,omitempty"` Stats Stats `json:"stats"` }