mining no longer uses the schedule

slack
Jordan Orelli 10 years ago
parent afedab97e1
commit 3d6fed160e

@ -167,16 +167,7 @@ var mineCommand = &Command{
name: "mine", name: "mine",
help: "mines the current system for resources", help: "mines the current system for resources",
handler: func(conn *Connection, args ...string) { handler: func(conn *Connection, args ...string) {
conn.StartMining() conn.Mine()
var fn func()
fn = func() {
if !conn.IsMining() {
return
}
conn.Payout()
After(500*time.Millisecond, fn)
}
After(500*time.Millisecond, fn)
}, },
} }

@ -3,7 +3,6 @@ package main
import ( import (
"bufio" "bufio"
"fmt" "fmt"
"math/rand"
"net" "net"
"strings" "strings"
"time" "time"
@ -21,7 +20,6 @@ type Connection struct {
kills int kills int
dead bool dead bool
money int money int
mining bool
colonies []*System colonies []*System
bombs int bombs int
state PlayerState // this is wrong... state PlayerState // this is wrong...
@ -105,7 +103,8 @@ func (c *Connection) Tick(frame int64) {
c.land() c.land()
} }
case mining: case mining:
c.money += options.miningRate c.Deposit(options.miningRate)
log_info("%v", c.money)
default: default:
log_error("connection %v has invalid state wtf", c) log_error("connection %v has invalid state wtf", c)
} }
@ -193,28 +192,24 @@ func (c *Connection) MadeKill(victim *Connection) {
} }
} }
func (c *Connection) StartMining() { func (c *Connection) Mine() {
fmt.Fprintf(c, "now mining %s with a payout rate of %v\n", c.System().name, c.System().miningRate) switch c.state {
fmt.Fprintln(c, "(press enter to stop mining)") case idle:
c.mining = true 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() { func (c *Connection) StopMining() {
fmt.Fprintf(c, "done mining\n") fmt.Fprintf(c, "done mining\n")
c.mining = false c.state = idle
} }
func (c *Connection) IsMining() bool { func (c *Connection) IsMining() bool {
return c.mining return c.state == 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)
} }
func (c *Connection) Withdraw(n int) { func (c *Connection) Withdraw(n int) {
@ -223,7 +218,7 @@ func (c *Connection) Withdraw(n int) {
func (c *Connection) Deposit(n int) { func (c *Connection) Deposit(n int) {
c.money += n c.money += n
if c.money >= 25000 { if c.money >= options.economic {
c.Win("economic") c.Win("economic")
} }
} }

@ -17,6 +17,7 @@ var options struct {
frameRate int frameRate int
miningRate int miningRate int
playerSpeed float64 playerSpeed float64
economic int
} }
var ( var (
@ -116,4 +117,5 @@ func init() {
flag.IntVar(&options.frameRate, "frame-rate", 100, "frame rate, in frames per second") 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.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.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")
} }

Loading…
Cancel
Save