From 18399fe926c57f4250359ffaac1ab2ef97138cf7 Mon Sep 17 00:00:00 2001 From: Jordan Orelli Date: Sat, 8 Nov 2014 14:09:38 -0500 Subject: [PATCH] can bomb mining colonies properly now --- commands.go | 9 ++++++--- system.go | 23 ++++++++++++++++++----- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/commands.go b/commands.go index d80d0d2..efa613b 100644 --- a/commands.go +++ b/commands.go @@ -200,8 +200,10 @@ var colonizeCommand = &Command{ var fn func() fn = func() { reward := int64(rand.NormFloat64()*5.0 + 100.0*system.miningRate) - system.colonizedBy.money += reward - fmt.Fprintf(system.colonizedBy, "mining colony on %s pays you %d space duckets. total: %d space duckets.\n", system.name, reward, system.colonizedBy.money) + if system.colonizedBy != nil { + system.colonizedBy.money += reward + fmt.Fprintf(system.colonizedBy, "mining colony on %s pays you %d space duckets. total: %d space duckets.\n", system.name, reward, system.colonizedBy.money) + } After(5*time.Second, fn) } @@ -329,9 +331,10 @@ func init() { registerCommand(colonizeCommand) registerCommand(commandsCommand) registerCommand(gotoCommand) - registerCommand(mineCommand) registerCommand(helpCommand) registerCommand(infoCommand) + registerCommand(mineCommand) registerCommand(nearbyCommand) registerCommand(scanCommand) + registerCommand(mkBombCommand) } diff --git a/system.go b/system.go index 88ee3a4..ae808e8 100644 --- a/system.go +++ b/system.go @@ -3,6 +3,7 @@ package main import ( "database/sql" "fmt" + "io" "math" "math/rand" "time" @@ -187,12 +188,13 @@ func randomSystem() (*System, error) { } type scanResults struct { - life bool - miningRate float64 + life bool + miningRate float64 + colonizedBy *Connection } func (r *scanResults) negative() bool { - return !r.life + return !r.life && r.colonizedBy == nil } func (r *scanResults) String() string { @@ -202,6 +204,15 @@ func (r *scanResults) String() string { return "(none)" } +func (r *scanResults) write(w io.Writer) { + if r.life { + fmt.Fprintf(w, "\tlife detected\n") + } + if r.colonizedBy != nil { + fmt.Fprintf(w, "\tmining colony owned by %s\n", r.colonizedBy.PlayerName()) + } +} + func scanSystem(id int, reply int) { system := index[id] source := index[reply] @@ -212,7 +223,8 @@ func scanSystem(id int, reply int) { fmt.Fprintf(conn, "scan detected from %s\n", source.name) }) results := &scanResults{ - life: len(system.players) > 0, + life: len(system.players) > 0, + colonizedBy: system.colonizedBy, } After(delay, func() { deliverReply(source.id, system.id, results) @@ -228,7 +240,8 @@ func deliverReply(id int, echo int, results *scanResults) { if results.negative() { return } - fmt.Fprintf(conn, "scan results from %s (%v away): %v\n", source.name, delay, results) + fmt.Fprintf(conn, "scan results from %s (%v away):\n", source.name, delay) + results.write(conn) }) }