colonization no longer relies on scheduler

slack
Jordan Orelli 10 years ago
parent 3d6fed160e
commit 442478013d

@ -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")
}

@ -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
}

@ -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)

Loading…
Cancel
Save