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
+25 -4
View File
@@ -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",