colonization no longer relies on scheduler

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

@ -2,11 +2,9 @@ package main
import ( import (
"fmt" "fmt"
"math/rand"
"sort" "sort"
"strconv" "strconv"
"strings" "strings"
"time"
) )
var commandRegistry map[string]*Command var commandRegistry map[string]*Command
@ -176,27 +174,13 @@ var colonizeCommand = &Command{
help: "establishes a mining colony on the current system", help: "establishes a mining colony on the current system",
handler: func(conn *Connection, arg ...string) { handler: func(conn *Connection, arg ...string) {
system := conn.System() 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 { if conn.money > 2000 {
conn.Withdraw(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 system.colonizedBy = conn
fmt.Fprintf(conn, "set up a mining colony on %s\n", conn.System().name) fmt.Fprintf(conn, "set up a mining colony on %s\n", conn.System().name)
After(5*time.Second, fn)
} else { } else {
fmt.Fprintf(conn, "not enough money! it costs 2000 duckets to start a mining colony\n") 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 { if err := game.Create(); err != nil {
log_error("unable to create game: %v", err) log_error("unable to create game: %v", err)
} }
for _, system := range index {
game.Register(system)
}
return game return game
} }

@ -24,6 +24,16 @@ type System struct {
distances []Ray 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) { func (s *System) Arrive(conn *Connection) {
conn.SetSystem(s) conn.SetSystem(s)
log_info("player %s has arrived at system %s", conn.PlayerName(), s.name) log_info("player %s has arrived at system %s", conn.PlayerName(), s.name)

Loading…
Cancel
Save