ignore new binary
Create new bserv binary Herein lie the following ideas: - change package visibility of many things - try to stash the globals into structs - the code is far from correct; it merely compiles
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
package main
|
||||
package botserv
|
||||
|
||||
import (
|
||||
v "bitbucket.org/hackerbots/vector"
|
||||
"log"
|
||||
"math"
|
||||
"math/rand"
|
||||
|
||||
v "bitbucket.org/hackerbots/vector"
|
||||
)
|
||||
|
||||
type Robot struct {
|
||||
@@ -30,6 +31,8 @@ type Robot struct {
|
||||
Probe *v.Point2d `json:"probe"`
|
||||
ProbeResult *Collision `json:"probe_result"`
|
||||
gameStats *BotStats `json:-`
|
||||
Delta float32 `json:-`
|
||||
Idg *IdGenerator
|
||||
}
|
||||
|
||||
type Collision struct {
|
||||
@@ -172,7 +175,7 @@ type Instruction struct {
|
||||
|
||||
// returns collision, the intersection point, and the robot with whom r has
|
||||
// collided, if this happened.
|
||||
func (r *Robot) checkCollisions(g *game, probe v.Vector2d) (bool, *v.Point2d, *Robot) {
|
||||
func (r *Robot) checkCollisions(g *Game, probe v.Vector2d) (bool, *v.Point2d, *Robot) {
|
||||
finalCollision := false
|
||||
collision := false
|
||||
closest := float32(math.Inf(1))
|
||||
@@ -243,19 +246,19 @@ func (r *Robot) checkCollisions(g *game, probe v.Vector2d) (bool, *v.Point2d, *R
|
||||
return finalCollision, intersection, finalRobot
|
||||
}
|
||||
|
||||
func (r *Robot) Tick(g *game) {
|
||||
func (r *Robot) Tick(g *Game) {
|
||||
r.Collision = nil
|
||||
r.Hit = false
|
||||
r.scan(g)
|
||||
|
||||
// Adjust Speed
|
||||
if r.Speed < r.TargetSpeed {
|
||||
r.Speed += (r.Stats.Acceleration * delta)
|
||||
r.Speed += (r.Stats.Acceleration * r.Delta)
|
||||
if r.Speed > r.TargetSpeed {
|
||||
r.Speed = r.TargetSpeed
|
||||
}
|
||||
} else if float32(math.Abs(float64(r.Speed-r.TargetSpeed))) > v.Epsilon {
|
||||
r.Speed -= (r.Stats.Acceleration * delta)
|
||||
r.Speed -= (r.Stats.Acceleration * r.Delta)
|
||||
// Cap reverse to 1/2 speed
|
||||
if r.Speed < (-0.5 * r.TargetSpeed) {
|
||||
r.Speed = (-0.5 * r.TargetSpeed)
|
||||
@@ -292,15 +295,15 @@ func (r *Robot) Tick(g *game) {
|
||||
}
|
||||
|
||||
// Max turn radius in this case is in degrees per second
|
||||
if float32(math.Abs(float64(angle))) > (float32(r.Stats.TurnSpeed) * delta) {
|
||||
if float32(math.Abs(float64(angle))) > (float32(r.Stats.TurnSpeed) * r.Delta) {
|
||||
// New heading should be a little less, take current heading and
|
||||
// rotate by the max turn radius per frame.
|
||||
rot := (float32(r.Stats.TurnSpeed) * delta) * v.Deg2rad
|
||||
rot := (float32(r.Stats.TurnSpeed) * r.Delta) * v.Deg2rad
|
||||
|
||||
new_heading = current_heading.Rotate(rot * float32(dir))
|
||||
}
|
||||
|
||||
move_vector := new_heading.Scale(r.Speed * delta)
|
||||
move_vector := new_heading.Scale(r.Speed * r.Delta)
|
||||
collision, intersection_point, hit_robot := r.checkCollisions(g, move_vector)
|
||||
if collision {
|
||||
dmg := int(math.Abs(float64(r.Speed)) / 10.0)
|
||||
@@ -352,7 +355,7 @@ func (r *Robot) Tick(g *game) {
|
||||
|
||||
// We only self repair when we're stopped
|
||||
if math.Abs(float64(r.Speed)) < v.Epsilon && r.RepairCounter > 0 {
|
||||
r.RepairCounter -= delta
|
||||
r.RepairCounter -= r.Delta
|
||||
if r.RepairCounter < 0 {
|
||||
r.Health += g.repair_hp
|
||||
if r.Health > r.Stats.Hp {
|
||||
@@ -364,9 +367,9 @@ func (r *Robot) Tick(g *game) {
|
||||
|
||||
// We are only allowed to scan when we're stopped
|
||||
if math.Abs(float64(r.Speed)) < v.Epsilon && r.ActiveScan {
|
||||
r.ScanCounter += delta * float32(r.Stats.ScannerRadius) * 0.1
|
||||
r.ScanCounter += r.Delta * float32(r.Stats.ScannerRadius) * 0.1
|
||||
} else if r.ScanCounter > 0 {
|
||||
r.ScanCounter -= delta * float32(r.Stats.ScannerRadius) * 0.05
|
||||
r.ScanCounter -= r.Delta * float32(r.Stats.ScannerRadius) * 0.05
|
||||
if r.ScanCounter <= 0 {
|
||||
r.ScanCounter = 0
|
||||
}
|
||||
@@ -394,7 +397,7 @@ func (r *Robot) Tick(g *game) {
|
||||
}
|
||||
}
|
||||
|
||||
func (r *Robot) scan(g *game) {
|
||||
func (r *Robot) scan(g *Game) {
|
||||
r.Scanners = r.Scanners[:0]
|
||||
for player := range g.players {
|
||||
for _, bot := range player.Robots {
|
||||
@@ -440,9 +443,9 @@ func (r *Robot) scan(g *game) {
|
||||
|
||||
}
|
||||
|
||||
func (r *Robot) fire(g *game) *Projectile {
|
||||
func (r *Robot) fire(g *Game) *Projectile {
|
||||
// Throttle the fire rate
|
||||
time_since_fired := (float32(g.turn) * (delta * 1000)) - (float32(r.LastFired) * (delta * 1000))
|
||||
time_since_fired := (float32(g.turn) * (r.Delta * 1000)) - (float32(r.LastFired) * (r.Delta * 1000))
|
||||
if time_since_fired < float32(r.Stats.FireRate) {
|
||||
return nil
|
||||
}
|
||||
@@ -451,7 +454,7 @@ func (r *Robot) fire(g *game) *Projectile {
|
||||
r.gameStats.Shots++
|
||||
|
||||
return &Projectile{
|
||||
Id: idg.Hash(),
|
||||
Id: r.Idg.Hash(),
|
||||
Position: r.Position,
|
||||
MoveTo: *r.FireAt,
|
||||
Damage: r.Stats.WeaponDamage,
|
||||
@@ -461,7 +464,7 @@ func (r *Robot) fire(g *game) *Projectile {
|
||||
}
|
||||
}
|
||||
|
||||
func (r *Robot) reset(g *game) {
|
||||
func (r *Robot) reset(g *Game) {
|
||||
for {
|
||||
start_pos := v.Point2d{
|
||||
X: rand.Float32() * float32(g.width),
|
||||
|
||||
Reference in New Issue
Block a user