active scanning

This commit is contained in:
Fraser Graham 2013-11-07 21:34:54 -08:00
parent 3d0eb16f91
commit 1b42a19393
3 changed files with 31 additions and 5 deletions

View File

@ -214,7 +214,7 @@ func (g *game) send_update(payload *Boardstate) {
// Filter objects // Filter objects
for _, ob := range g.obstacles { 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 = append(
player_payload.Obstacles, player_payload.Obstacles,
ob) ob)

View File

@ -40,15 +40,21 @@ func (p *player) recv() {
break break
} }
if msg.Repair != nil { if msg.Repair != nil && *msg.Repair == true {
p.Robot.TargetSpeed = 0 p.Robot.TargetSpeed = 0
p.Robot.FireAt = nil p.Robot.FireAt = nil
p.Robot.MoveTo = nil p.Robot.MoveTo = nil
if p.Robot.RepairCounter <= 0 { if p.Robot.RepairCounter <= 0 {
p.Robot.RepairCounter = 3.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 { } else {
p.Robot.RepairCounter = 0 p.Robot.RepairCounter = 0
p.Robot.ActiveScan = false
// Reapiring halts all other activity // Reapiring halts all other activity
if msg.MoveTo != nil { 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) log.Printf("player %s: recv close", p.Robot.Id)
p.ws.Close() p.ws.Close()
@ -133,7 +143,7 @@ func (p *player) Tick(g *game) {
// Adjust Heading // Adjust Heading
current_heading := p.Robot.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 // We may have been stopped before this and had no heading
current_heading = p.Robot.MoveTo.Sub(p.Robot.Position).Normalize() 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 { if p.Robot.FireAt != nil {
proj := p.fire(g.projectiles, g.turn) proj := p.fire(g.projectiles, g.turn)
if proj != nil { if proj != nil {
@ -213,6 +233,7 @@ func (p *player) Tick(g *game) {
p.Robot.ProbeResult = &pos p.Robot.ProbeResult = &pos
} }
} }
} }
func (p *player) scan(g *game) { func (p *player) scan(g *game) {
@ -222,7 +243,7 @@ func (p *player) scan(g *game) {
continue continue
} }
dist := v.Distance(player.Robot.Position, p.Robot.Position) 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{ s := Scanner{
Id: player.Robot.Id, Id: player.Robot.Id,
Type: "robot", Type: "robot",
@ -237,7 +258,7 @@ func (p *player) scan(g *game) {
} }
dist := v.Distance(proj.Position, p.Robot.Position) 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{ s := Scanner{
Id: proj.Id, Id: proj.Id,
Type: "projectile", Type: "projectile",

View File

@ -7,11 +7,14 @@ import (
type Robot struct { type Robot struct {
Id string `json:"id"` Id string `json:"id"`
Name string `json:"name"` Name string `json:"name"`
Message string `json:"-"`
Stats Stats `json:"-"` Stats Stats `json:"-"`
TargetSpeed float32 `json:"-"` TargetSpeed float32 `json:"-"`
Speed float32 `json:"speed"` Speed float32 `json:"speed"`
Health int `json:"health"` Health int `json:"health"`
RepairCounter float32 `json:"repair"` RepairCounter float32 `json:"repair"`
ScanCounter float32 `json:"scan_bonus"`
ActiveScan bool `json:"-"`
Position v.Point2d `json:"position"` Position v.Point2d `json:"position"`
Heading v.Vector2d `json:"heading"` Heading v.Vector2d `json:"heading"`
MoveTo *v.Point2d `json:"-"` MoveTo *v.Point2d `json:"-"`
@ -158,10 +161,12 @@ func (s StatsRequest) Valid() bool {
} }
type Instruction struct { type Instruction struct {
Message *string `json:"message,omitempty"`
MoveTo *v.Point2d `json:"move_to,omitempty"` MoveTo *v.Point2d `json:"move_to,omitempty"`
FireAt *v.Point2d `json:"fire_at,omitempty"` FireAt *v.Point2d `json:"fire_at,omitempty"`
Probe *v.Point2d `json:"probe,omitempty"` Probe *v.Point2d `json:"probe,omitempty"`
TargetSpeed *float32 `json:"target_speed,omitempty"` TargetSpeed *float32 `json:"target_speed,omitempty"`
Repair *bool `json:"repair,omitempty"` Repair *bool `json:"repair,omitempty"`
Scan *bool `json:"scan,omitempty"`
Stats Stats `json:"stats"` Stats Stats `json:"stats"`
} }