can make colonies again

slack
Jordan Orelli 10 years ago
parent 4c688080b3
commit 3663e4ec62

@ -0,0 +1,44 @@
package main
import ()
func MakeColony(c *Connection, sys *System) {
if c.money < options.colonyCost {
c.Printf("Not enough money! Colonies cost %v but you only have %v space duckets. Mine more space duckets!\n", options.colonyCost, c.money)
return
}
if sys.colonizedBy == c {
c.Printf("You've already colonized this system.\n")
return
}
c.money -= options.colonyCost
m := &MakeColonyState{
System: sys,
}
c.SetState(m)
}
type MakeColonyState struct {
CommandSuite
*System
start int64
}
func (m *MakeColonyState) Enter(c *Connection) {
c.Printf("Making colony on %v...\n", m.System)
}
func (m *MakeColonyState) Tick(c *Connection, frame int64) ConnectionState {
if m.start == 0 {
m.start = frame
}
if framesToDur(frame-m.start) >= options.makeColonyTime {
return Idle(m.System)
}
return m
}
func (m *MakeColonyState) Exit(c *Connection) {
m.System.colonizedBy = c
c.Printf("Established colony on %v.\n", m.System)
}

@ -85,7 +85,8 @@ func (c *Connection) Tick(frame int64) {
func (c *Connection) RunCommand(name string, args ...string) { func (c *Connection) RunCommand(name string, args ...string) {
defer func() { defer func() {
if r := recover(); r != nil { if r := recover(); r != nil {
c.Printf("shit is *really* fucked up.\n") c.Printf("something is broken. Log this as a ticket!\n")
c.Printf("recovered: %v\n", r)
log_error("recovered: %v", r) log_error("recovered: %v", r)
} }
}() }()

@ -138,6 +138,7 @@ func (i *IdleState) scan(c *Connection, args ...string) {
currentGame.Register(NewScan(i.System)) currentGame.Register(NewScan(i.System))
} }
// "make" is already a keyword
func (i *IdleState) maek(c *Connection, args ...string) { func (i *IdleState) maek(c *Connection, args ...string) {
switch args[0] { switch args[0] {
case "bomb": case "bomb":
@ -146,6 +147,9 @@ func (i *IdleState) maek(c *Connection, args ...string) {
return return
} }
c.SetState(MakeBomb(i.System)) c.SetState(MakeBomb(i.System))
case "colony":
MakeColony(c, i.System)
return
default: default:
c.Printf("I don't know how to make a %v.\n", args[0]) c.Printf("I don't know how to make a %v.\n", args[0])
} }

@ -16,9 +16,11 @@ var options struct {
debug bool debug bool
economic int economic int
frameLength time.Duration frameLength time.Duration
colonyCost int
frameRate int frameRate int
lightSpeed float64 lightSpeed float64
makeBombTime time.Duration makeBombTime time.Duration
makeColonyTime time.Duration
moneyMean float64 moneyMean float64
moneySigma float64 moneySigma float64
playerSpeed float64 playerSpeed float64
@ -118,4 +120,6 @@ func init() {
flag.DurationVar(&options.respawnTime, "respawn-time", 60*time.Second, "time for player respawn") flag.DurationVar(&options.respawnTime, "respawn-time", 60*time.Second, "time for player respawn")
flag.DurationVar(&options.makeBombTime, "bomb-time", 5*time.Second, "time it takes to make a bomb") flag.DurationVar(&options.makeBombTime, "bomb-time", 5*time.Second, "time it takes to make a bomb")
flag.IntVar(&options.bombCost, "bomb-cost", 500, "price of a bomb") flag.IntVar(&options.bombCost, "bomb-cost", 500, "price of a bomb")
flag.IntVar(&options.colonyCost, "colony-cost", 2000, "price of a colony")
flag.DurationVar(&options.makeColonyTime, "colony-time", 15*time.Second, "time it takes to make a colony")
} }

Loading…
Cancel
Save