From 3663e4ec62ee909136339a4592a6d45db2220182 Mon Sep 17 00:00:00 2001 From: Jordan Orelli Date: Sun, 16 Nov 2014 12:26:03 -0500 Subject: [PATCH] can make colonies again --- colony.go | 44 ++++++++++++++++++++++++++++++++++++++++++++ connection.go | 3 ++- idle.go | 4 ++++ main.go | 32 ++++++++++++++++++-------------- 4 files changed, 68 insertions(+), 15 deletions(-) create mode 100644 colony.go diff --git a/colony.go b/colony.go new file mode 100644 index 0000000..25e1fa9 --- /dev/null +++ b/colony.go @@ -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) +} diff --git a/connection.go b/connection.go index b5d0d54..0baa12c 100644 --- a/connection.go +++ b/connection.go @@ -85,7 +85,8 @@ func (c *Connection) Tick(frame int64) { func (c *Connection) RunCommand(name string, args ...string) { defer func() { 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) } }() diff --git a/idle.go b/idle.go index 5f1b0cc..7387b9c 100644 --- a/idle.go +++ b/idle.go @@ -138,6 +138,7 @@ func (i *IdleState) scan(c *Connection, args ...string) { currentGame.Register(NewScan(i.System)) } +// "make" is already a keyword func (i *IdleState) maek(c *Connection, args ...string) { switch args[0] { case "bomb": @@ -146,6 +147,9 @@ func (i *IdleState) maek(c *Connection, args ...string) { return } c.SetState(MakeBomb(i.System)) + case "colony": + MakeColony(c, i.System) + return default: c.Printf("I don't know how to make a %v.\n", args[0]) } diff --git a/main.go b/main.go index 54f4031..ef02c9f 100644 --- a/main.go +++ b/main.go @@ -11,20 +11,22 @@ import ( ) var options struct { - bombCost int - bombSpeed float64 - debug bool - economic int - frameLength time.Duration - frameRate int - lightSpeed float64 - makeBombTime time.Duration - moneyMean float64 - moneySigma float64 - playerSpeed float64 - respawnFrames int64 - respawnTime time.Duration - speckPath string + bombCost int + bombSpeed float64 + debug bool + economic int + frameLength time.Duration + colonyCost int + frameRate int + lightSpeed float64 + makeBombTime time.Duration + makeColonyTime time.Duration + moneyMean float64 + moneySigma float64 + playerSpeed float64 + respawnFrames int64 + respawnTime time.Duration + speckPath string } var ( @@ -118,4 +120,6 @@ func init() { 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.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") }