diff --git a/bomb.go b/bomb.go index 2448820..3f2e66e 100644 --- a/bomb.go +++ b/bomb.go @@ -35,7 +35,7 @@ func (b *Bomb) Dead() bool { func (b *Bomb) Tick(frame int64) { b.fti -= 1 if b.fti <= 0 { - b.target.Bombed(b.profile) + b.target.Bombed(b.profile, frame) b.done = true log_info("bomb went off on %v", b.target) } diff --git a/commands.go b/commands.go index 0eb4b6b..f4faba5 100644 --- a/commands.go +++ b/commands.go @@ -157,19 +157,6 @@ var commandsCommand = Command{ }, } -// var scanCommand = &Command{ -// name: "scan", -// help: "super duper scan", -// handler: func(conn *Connection, args ...string) { -// if !conn.CanScan() { -// conn.Printf("scanners are still recharging. Can scan again in %v\n", conn.NextScan()) -// return -// } -// currentGame.Register(NewScan(conn.System())) -// conn.RecordScan() -// }, -// } - // var broadcastCommand = &Command{ // name: "broadcast", // help: "broadcast a message for all systems to hear", diff --git a/connection.go b/connection.go index 8b128ae..b5d0d54 100644 --- a/connection.go +++ b/connection.go @@ -128,22 +128,6 @@ func (c *Connection) SetState(s ConnectionState) { c.ConnectionState = s } -// func (c *Connection) SendBomb(target *System) { -// if c.bombs <= 0 { -// fmt.Fprintln(c, "cannot send bomb: no bombs left") -// return -// } -// if time.Since(c.lastBomb) < 5*time.Second { -// fmt.Fprintln(c, "cannod send bomb: bombs are reloading") -// return -// } -// c.bombs -= 1 -// c.lastBomb = time.Now() -// bomb := NewBomb(c, target) -// currentGame.Register(bomb) -// c.Printf("sending bomb to system %v\n", target) -// } - func (c *Connection) ReadLines(out chan []string) { defer close(out) @@ -243,6 +227,10 @@ func (c *Connection) Win(method string) { currentGame.Win(c, method) } +func (c *Connection) Die(frame int64) { + c.SetState(NewDeadState(frame)) +} + type ConnectionState interface { CommandSuite String() string diff --git a/idle.go b/idle.go index 9999dc4..fb4242d 100644 --- a/idle.go +++ b/idle.go @@ -7,7 +7,6 @@ import ( type IdleState struct { CommandSuite - NopEnter NopExit *System } @@ -16,7 +15,6 @@ func Idle(sys *System) ConnectionState { i := &IdleState{System: sys} i.CommandSuite = CommandSet{ balCommand, - commandsCommand, helpCommand, playersCommand, Command{ @@ -49,10 +47,20 @@ func Idle(sys *System) ConnectionState { arity: 0, handler: i.info, }, + Command{ + name: "scan", + help: "scans the galaxy for signs of life", + arity: 0, + handler: i.scan, + }, } return i } +func (i *IdleState) Enter(c *Connection) { + i.System.Arrive(c) +} + func (i *IdleState) String() string { return fmt.Sprintf("idle on %v", i.System) } @@ -115,3 +123,11 @@ func (i *IdleState) mine(c *Connection, args ...string) { func (i *IdleState) info(c *Connection, args ...string) { c.Printf("Currently idle on system %v\n", i.System) } + +func (i *IdleState) scan(c *Connection, args ...string) { + if time.Since(c.lastScan) < 1*time.Minute { + return + } + c.Printf("Scanning the galaxy for signs of life...\n") + currentGame.Register(NewScan(i.System)) +} diff --git a/system.go b/system.go index 53c558e..841ed2f 100644 --- a/system.go +++ b/system.go @@ -58,6 +58,9 @@ func (s *System) Reset() { func (s *System) Arrive(conn *Connection) { // conn.SetSystem(s) + if s.players[conn] { + return + } log_info("player %s has arrived at system %v", conn.Name(), s) if s.players == nil { s.players = make(map[*Connection]bool, 8) @@ -161,9 +164,9 @@ func (s *System) Distances() []Ray { return s.distances } -func (s *System) Bombed(bomber *Connection) { +func (s *System) Bombed(bomber *Connection, frame int64) { s.EachConn(func(conn *Connection) { - // conn.Die() + conn.Die(frame) bomber.MadeKill(conn) }) if s.colonizedBy != nil {