can bomb mining colonies properly now

pull/5/head
Jordan Orelli 10 years ago
parent 962c3bd108
commit 18399fe926

@ -200,8 +200,10 @@ var colonizeCommand = &Command{
var fn func() var fn func()
fn = func() { fn = func() {
reward := int64(rand.NormFloat64()*5.0 + 100.0*system.miningRate) reward := int64(rand.NormFloat64()*5.0 + 100.0*system.miningRate)
system.colonizedBy.money += reward if system.colonizedBy != nil {
fmt.Fprintf(system.colonizedBy, "mining colony on %s pays you %d space duckets. total: %d space duckets.\n", system.name, reward, system.colonizedBy.money) 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) After(5*time.Second, fn)
} }
@ -329,9 +331,10 @@ func init() {
registerCommand(colonizeCommand) registerCommand(colonizeCommand)
registerCommand(commandsCommand) registerCommand(commandsCommand)
registerCommand(gotoCommand) registerCommand(gotoCommand)
registerCommand(mineCommand)
registerCommand(helpCommand) registerCommand(helpCommand)
registerCommand(infoCommand) registerCommand(infoCommand)
registerCommand(mineCommand)
registerCommand(nearbyCommand) registerCommand(nearbyCommand)
registerCommand(scanCommand) registerCommand(scanCommand)
registerCommand(mkBombCommand)
} }

@ -3,6 +3,7 @@ package main
import ( import (
"database/sql" "database/sql"
"fmt" "fmt"
"io"
"math" "math"
"math/rand" "math/rand"
"time" "time"
@ -187,12 +188,13 @@ func randomSystem() (*System, error) {
} }
type scanResults struct { type scanResults struct {
life bool life bool
miningRate float64 miningRate float64
colonizedBy *Connection
} }
func (r *scanResults) negative() bool { func (r *scanResults) negative() bool {
return !r.life return !r.life && r.colonizedBy == nil
} }
func (r *scanResults) String() string { func (r *scanResults) String() string {
@ -202,6 +204,15 @@ func (r *scanResults) String() string {
return "(none)" 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) { func scanSystem(id int, reply int) {
system := index[id] system := index[id]
source := index[reply] source := index[reply]
@ -212,7 +223,8 @@ func scanSystem(id int, reply int) {
fmt.Fprintf(conn, "scan detected from %s\n", source.name) fmt.Fprintf(conn, "scan detected from %s\n", source.name)
}) })
results := &scanResults{ results := &scanResults{
life: len(system.players) > 0, life: len(system.players) > 0,
colonizedBy: system.colonizedBy,
} }
After(delay, func() { After(delay, func() {
deliverReply(source.id, system.id, results) deliverReply(source.id, system.id, results)
@ -228,7 +240,8 @@ func deliverReply(id int, echo int, results *scanResults) {
if results.negative() { if results.negative() {
return 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)
}) })
} }

Loading…
Cancel
Save