diff --git a/commands.go b/commands.go index b6e72c4..7ff7b95 100644 --- a/commands.go +++ b/commands.go @@ -167,16 +167,7 @@ var mineCommand = &Command{ name: "mine", help: "mines the current system for resources", handler: func(conn *Connection, args ...string) { - conn.StartMining() - var fn func() - fn = func() { - if !conn.IsMining() { - return - } - conn.Payout() - After(500*time.Millisecond, fn) - } - After(500*time.Millisecond, fn) + conn.Mine() }, } diff --git a/connection.go b/connection.go index 4b19b58..21e7390 100644 --- a/connection.go +++ b/connection.go @@ -3,7 +3,6 @@ package main import ( "bufio" "fmt" - "math/rand" "net" "strings" "time" @@ -21,7 +20,6 @@ type Connection struct { kills int dead bool money int - mining bool colonies []*System bombs int state PlayerState // this is wrong... @@ -105,7 +103,8 @@ func (c *Connection) Tick(frame int64) { c.land() } case mining: - c.money += options.miningRate + c.Deposit(options.miningRate) + log_info("%v", c.money) default: log_error("connection %v has invalid state wtf", c) } @@ -193,28 +192,24 @@ func (c *Connection) MadeKill(victim *Connection) { } } -func (c *Connection) StartMining() { - fmt.Fprintf(c, "now mining %s with a payout rate of %v\n", c.System().name, c.System().miningRate) - fmt.Fprintln(c, "(press enter to stop mining)") - c.mining = true +func (c *Connection) Mine() { + switch c.state { + case idle: + fmt.Fprintf(c, "now mining %s with a payout rate of %v\n", c.System().name, c.System().miningRate) + fmt.Fprintln(c, "(press enter to stop mining)") + c.state = mining + default: + fmt.Fprintf(c, "no\n") + } } func (c *Connection) StopMining() { fmt.Fprintf(c, "done mining\n") - c.mining = false + c.state = idle } func (c *Connection) IsMining() bool { - return c.mining -} - -func (c *Connection) Payout() { - if c.dead { - return - } - reward := int(rand.NormFloat64()*5.0 + 100.0*c.System().miningRate) - c.Deposit(reward) - fmt.Fprintf(c, "mined: %d space duckets. total: %d\n", reward, c.money) + return c.state == mining } func (c *Connection) Withdraw(n int) { @@ -223,7 +218,7 @@ func (c *Connection) Withdraw(n int) { func (c *Connection) Deposit(n int) { c.money += n - if c.money >= 25000 { + if c.money >= options.economic { c.Win("economic") } } diff --git a/main.go b/main.go index 40177b7..2731de9 100644 --- a/main.go +++ b/main.go @@ -17,6 +17,7 @@ var options struct { frameRate int miningRate int playerSpeed float64 + economic int } var ( @@ -116,4 +117,5 @@ func init() { flag.IntVar(&options.frameRate, "frame-rate", 100, "frame rate, in frames per second") flag.IntVar(&options.miningRate, "mining-rate", 1, "mining rate, in duckets per frame") flag.Float64Var(&options.playerSpeed, "player-speed", 0.8, "player travel speed, relative to C, the speed of light") + flag.IntVar(&options.economic, "economic", 25000, "amount of money needed to win economic victory") }