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{
// name: "colonize",
// help: "establishes a mining colony on the current system",
// handler: func(conn *Connection, arg ...string) {
// system := conn.System()
// if conn.money > 2000 {
// conn.Withdraw(2000)
// if system.colonizedBy != nil {
// system.colonizedBy.Printf("your colony on %s has been stolen by %s\n", system.Label(), conn.Name())
// }
// system.colonizedBy = conn
// conn.Printf("set up a mining colony on %s\n", conn.System().name)
// } else {
// conn.Printf("not enough money! it costs 2000 duckets to start a mining colony\n")
// }
// },
// }
func NearbyCommand(sys *System) Command {
handler := func(c *Connection, args ...string) {
neighbors, err := sys.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")
}
return Command{
name: "nearby",
help: "list nearby star systems",
arity: 0,
handler: handler,
}
}
var winCommand = Command{
name: "win",

@ -18,18 +18,13 @@ func Idle(sys *System) ConnectionState {
helpCommand,
playersCommand,
BroadcastCommand(sys),
NearbyCommand(sys),
Command{
name: "goto",
help: "travel between star systems",
arity: 1,
handler: i.travelTo,
},
Command{
name: "nearby",
help: "list nearby star systems",
arity: 0,
handler: i.nearby,
},
Command{
name: "bomb",
help: "bomb another star system",
@ -84,22 +79,6 @@ func (i *IdleState) travelTo(c *Connection, args ...string) {
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) {
if c.bombs <= 0 {
c.Printf("Cannot send bomb: no bombs left! Build more bombs!\n")

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

Loading…
Cancel
Save