hey bombs

slack
Jordan Orelli 10 years ago
parent 0ccc2f91b5
commit 4ecc4c2952

@ -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)
}

@ -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",

@ -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

@ -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))
}

@ -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 {

Loading…
Cancel
Save