refining nearby command

slack
Jordan Orelli 10 years ago
parent f2a33fbac8
commit d84419532c

@ -125,23 +125,29 @@ func BroadcastCommand(sys *System) Command {
} }
} }
// var colonizeCommand = &Command{ func NearbyCommand(sys *System) Command {
// name: "colonize", handler := func(c *Connection, args ...string) {
// help: "establishes a mining colony on the current system", neighbors, err := sys.Nearby(25)
// handler: func(conn *Connection, arg ...string) { if err != nil {
// system := conn.System() log_error("unable to get neighbors: %v", err)
// if conn.money > 2000 { return
// conn.Withdraw(2000) }
// if system.colonizedBy != nil { c.Printf("--------------------------------------------------------------------------------\n")
// system.colonizedBy.Printf("your colony on %s has been stolen by %s\n", system.Label(), conn.Name()) c.Printf("%-4s %-20s %s\n", "id", "name", "distance")
// } c.Printf("--------------------------------------------------------------------------------\n")
// system.colonizedBy = conn for _, neighbor := range neighbors {
// conn.Printf("set up a mining colony on %s\n", conn.System().name) other := index[neighbor.id]
// } else { c.Printf("%-4d %-20s %v\n", other.id, other.name, neighbor.distance)
// conn.Printf("not enough money! it costs 2000 duckets to start a mining colony\n") }
// } c.Printf("--------------------------------------------------------------------------------\n")
// }, }
// } return Command{
name: "nearby",
help: "list nearby star systems",
arity: 0,
handler: handler,
}
}
var winCommand = Command{ var winCommand = Command{
name: "win", name: "win",

@ -18,18 +18,13 @@ func Idle(sys *System) ConnectionState {
helpCommand, helpCommand,
playersCommand, playersCommand,
BroadcastCommand(sys), BroadcastCommand(sys),
NearbyCommand(sys),
Command{ Command{
name: "goto", name: "goto",
help: "travel between star systems", help: "travel between star systems",
arity: 1, arity: 1,
handler: i.travelTo, handler: i.travelTo,
}, },
Command{
name: "nearby",
help: "list nearby star systems",
arity: 0,
handler: i.nearby,
},
Command{ Command{
name: "bomb", name: "bomb",
help: "bomb another star system", help: "bomb another star system",
@ -84,22 +79,6 @@ func (i *IdleState) travelTo(c *Connection, args ...string) {
c.SetState(NewTravel(c, i.System, dest)) c.SetState(NewTravel(c, i.System, dest))
} }
func (i *IdleState) nearby(c *Connection, args ...string) {
neighbors, err := i.Nearby(25)
if err != nil {
log_error("unable to get neighbors: %v", err)
return
}
c.Printf("--------------------------------------------------------------------------------\n")
c.Printf("%-4s %-20s %s\n", "id", "name", "distance")
c.Printf("--------------------------------------------------------------------------------\n")
for _, neighbor := range neighbors {
other := index[neighbor.id]
c.Printf("%-4d %-20s %v\n", other.id, other.name, neighbor.distance)
}
c.Printf("--------------------------------------------------------------------------------\n")
}
func (i *IdleState) bomb(c *Connection, args ...string) { func (i *IdleState) bomb(c *Connection, args ...string) {
if c.bombs <= 0 { if c.bombs <= 0 {
c.Printf("Cannot send bomb: no bombs left! Build more bombs!\n") c.Printf("Cannot send bomb: no bombs left! Build more bombs!\n")

@ -17,6 +17,7 @@ func Mine(sys *System) ConnectionState {
helpCommand, helpCommand,
playersCommand, playersCommand,
BroadcastCommand(sys), BroadcastCommand(sys),
NearbyCommand(sys),
Command{ Command{
name: "stop", name: "stop",
help: "stops mining", help: "stops mining",

Loading…
Cancel
Save