active scanning
This commit is contained in:
parent
3d0eb16f91
commit
1b42a19393
2
game.go
2
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)
|
||||
|
29
player.go
29
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",
|
||||
|
5
robot.go
5
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"`
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user