From 5b827b036e99efca4407ce43c6213b0693a8e48b Mon Sep 17 00:00:00 2001 From: Jordan Orelli Date: Sun, 16 Nov 2014 18:50:47 -0500 Subject: [PATCH] scan shows shield energy --- connection.go | 10 +++++----- main.go | 2 ++ scan.go | 19 +++++++++++++++---- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/connection.go b/connection.go index d020288..67f428d 100644 --- a/connection.go +++ b/connection.go @@ -177,10 +177,10 @@ func (c *Connection) Name() string { } func (c *Connection) RecordScan() { - fmt.Fprintln(c, "scanning known systems for signs of life") + c.Printf("scanning known systems for signs of life\n") c.lastScan = time.Now() - time.AfterFunc(1*time.Minute, func() { - fmt.Fprintln(c, "scanner ready") + time.AfterFunc(options.scanTime, func() { + c.Printf("scanner ready\n") }) } @@ -192,11 +192,11 @@ func (c *Connection) RecordBomb() { } func (c *Connection) CanScan() bool { - return time.Since(c.lastScan) > 1*time.Minute + return time.Since(c.lastScan) > options.scanTime } func (c *Connection) NextScan() time.Duration { - return -time.Since(c.lastScan.Add(time.Minute)) + return -time.Since(c.lastScan.Add(options.scanTime)) } func (c *Connection) NextBomb() time.Duration { diff --git a/main.go b/main.go index ba999a4..59a7aad 100644 --- a/main.go +++ b/main.go @@ -27,6 +27,7 @@ var options struct { playerSpeed float64 respawnFrames int64 respawnTime time.Duration + scanTime time.Duration speckPath string startBombs int startMoney int @@ -128,4 +129,5 @@ func init() { flag.IntVar(&options.startBombs, "start-bombs", 0, "number of bombs a player has at game start") flag.IntVar(&options.startMoney, "start-money", 1000, "amount of money a player has to start") flag.DurationVar(&options.makeShieldTime, "shield-time", 15*time.Second, "time it takes to make a shield") + flag.DurationVar(&options.scanTime, "scan-recharge", 1*time.Minute, "time it takes for scanners to recharge") } diff --git a/scan.go b/scan.go index 46413bd..110a172 100644 --- a/scan.go +++ b/scan.go @@ -15,10 +15,12 @@ type scan struct { } type scanResult struct { - system *System - dist float64 - players map[*Connection]bool - colonizedBy *Connection + system *System + dist float64 + players map[*Connection]bool + colonizedBy *Connection + shielded bool + shieldEnergy float64 } func (r *scanResult) Empty() bool { @@ -75,6 +77,10 @@ func (s *scan) hitSystem(sys *System, dist float64) scanResult { system: sys, colonizedBy: sys.colonizedBy, dist: dist * 2.0, + shielded: sys.Shield != nil, + } + if sys.Shield != nil { + r.shieldEnergy = sys.Shield.energy } if sys.players != nil { r.players = make(map[*Connection]bool, len(sys.players)) @@ -97,6 +103,10 @@ func (s *scan) echos() { } s.origin.NotifyInhabitants("results from scan of %v:\n", res.system) s.origin.NotifyInhabitants("\tdistance: %v\n", s.origin.DistanceTo(res.system)) + s.origin.NotifyInhabitants("\tshielded: %v\n", res.shielded) + if res.shielded { + s.origin.NotifyInhabitants("\tshield energy: %v\n", res.shieldEnergy) + } inhabitants := res.playerNames() if inhabitants != nil { s.origin.NotifyInhabitants("\tinhabitants: %v\n", inhabitants) @@ -104,5 +114,6 @@ func (s *scan) echos() { if res.colonizedBy != nil { s.origin.NotifyInhabitants("\tcolonized by: %v\n", res.colonizedBy.Name()) } + } }