can now set up mining colonies

pull/5/head
Jordan Orelli 10 years ago
parent b5f447aab6
commit 12ecbae59d

@ -2,6 +2,7 @@ package main
import ( import (
"fmt" "fmt"
"math/rand"
"sort" "sort"
"strconv" "strconv"
"strings" "strings"
@ -189,6 +190,36 @@ var mineCommand = &Command{
}, },
} }
var colonizeCommand = &Command{
name: "colonize",
help: "establishes a mining colony on the current system",
handler: func(conn *Connection, arg ...string) {
system := conn.System()
var fn func()
fn = func() {
reward := int64(rand.NormFloat64()*5.0 + 100.0*system.miningRate)
system.colonizedBy.money += 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.money -= 2000
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")
}
},
}
func move(conn *Connection, to *System) { func move(conn *Connection, to *System) {
start := conn.System() start := conn.System()
start.Leave(conn) start.Leave(conn)
@ -271,6 +302,7 @@ func init() {
commandRegistry = make(map[string]*Command, 16) commandRegistry = make(map[string]*Command, 16)
registerCommand(bombCommand) registerCommand(bombCommand)
registerCommand(broadcastCommand) registerCommand(broadcastCommand)
registerCommand(colonizeCommand)
registerCommand(commandsCommand) registerCommand(commandsCommand)
registerCommand(gotoCommand) registerCommand(gotoCommand)
registerCommand(mineCommand) registerCommand(mineCommand)

@ -22,6 +22,7 @@ type Connection struct {
dead bool dead bool
money int64 money int64
mining bool mining bool
colonies []*System
} }
func NewConnection(conn net.Conn) *Connection { func NewConnection(conn net.Conn) *Connection {

@ -14,12 +14,13 @@ var (
) )
type System struct { type System struct {
id int id int
x, y, z float64 x, y, z float64
planets int planets int
name string name string
players map[*Connection]bool players map[*Connection]bool
miningRate float64 miningRate float64
colonizedBy *Connection
} }
func (s *System) Arrive(p *Connection) { func (s *System) Arrive(p *Connection) {
@ -182,7 +183,8 @@ func randomSystem() (*System, error) {
} }
type scanResults struct { type scanResults struct {
life bool life bool
miningRate float64
} }
func (r *scanResults) negative() bool { func (r *scanResults) negative() bool {

Loading…
Cancel
Save