diff --git a/commands.go b/commands.go index 7ff7b95..16603a6 100644 --- a/commands.go +++ b/commands.go @@ -2,11 +2,9 @@ package main import ( "fmt" - "math/rand" "sort" "strconv" "strings" - "time" ) var commandRegistry map[string]*Command @@ -176,27 +174,13 @@ var colonizeCommand = &Command{ help: "establishes a mining colony on the current system", handler: func(conn *Connection, arg ...string) { system := conn.System() - var fn func() - fn = func() { - reward := int(rand.NormFloat64()*5.0 + 100.0*system.miningRate) - if system.colonizedBy != nil { - system.colonizedBy.Deposit(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) - } - - if system.colonizedBy != nil { - system.colonizedBy = conn - After(5*time.Second, fn) - return - } - if conn.money > 2000 { conn.Withdraw(2000) + if system.colonizedBy != nil { + fmt.Fprintf(system.colonizedBy, "your colony on %s has been stolen by %s\n", system.Label(), conn.PlayerName()) + } system.colonizedBy = conn fmt.Fprintf(conn, "set up a mining colony on %s\n", conn.System().name) - After(5*time.Second, fn) } else { fmt.Fprintf(conn, "not enough money! it costs 2000 duckets to start a mining colony\n") } diff --git a/game.go b/game.go index a591580..e9a2d88 100644 --- a/game.go +++ b/game.go @@ -39,6 +39,9 @@ func NewGame() *Game { if err := game.Create(); err != nil { log_error("unable to create game: %v", err) } + for _, system := range index { + game.Register(system) + } return game } diff --git a/system.go b/system.go index f8fb062..659ec03 100644 --- a/system.go +++ b/system.go @@ -24,6 +24,16 @@ type System struct { distances []Ray } +func (s *System) Tick(frame int64) { + if s.colonizedBy != nil { + s.colonizedBy.Deposit(1) + } +} + +func (s *System) Dead() bool { + return false +} + func (s *System) Arrive(conn *Connection) { conn.SetSystem(s) log_info("player %s has arrived at system %s", conn.PlayerName(), s.name)