bombs no longer rely on the scheduler

(but their echoes do)
slack
Jordan Orelli 10 years ago
parent 442478013d
commit 720c37d0b6

@ -0,0 +1,44 @@
package main
import (
"fmt"
"time"
)
type Bomb struct {
player *Connection
origin *System
target *System
start time.Time
fti int64 // frames to impact
}
func NewBomb(from *Connection, to *System) *Bomb {
origin := from.System()
dist := origin.DistanceTo(to)
fti := int64(dist / (options.lightSpeed * options.bombSpeed))
eta := time.Duration(fti) * time.Second / time.Duration(options.frameRate)
log_info("bomb from: %s to: %s ETA: %v", from.PlayerName(), to.Label(), eta)
return &Bomb{
player: from,
origin: origin,
target: to,
fti: fti,
start: time.Now(),
}
}
func (b *Bomb) Dead() bool {
return b.fti <= 0
}
func (b *Bomb) Tick(frame int64) {
b.fti -= 1
if b.fti <= 0 {
b.target.Bombed(b.player)
}
}
func (b *Bomb) String() string {
return fmt.Sprintf("[bomb from: %s to: %s lived: %s]", b.origin.Label(), b.target.Label(), time.Since(b.start))
}

@ -207,7 +207,7 @@ var bombCommand = &Command{
dest_name := strings.Join(args, " ") dest_name := strings.Join(args, " ")
to, ok := nameIndex[dest_name] to, ok := nameIndex[dest_name]
if ok { if ok {
bomb(conn, to) currentGame.Register(NewBomb(conn, to))
return return
} }
@ -226,7 +226,7 @@ var bombCommand = &Command{
fmt.Fprintf(conn, "weapons are still reloading. Can bomb again in %v\n", conn.NextBomb()) fmt.Fprintf(conn, "weapons are still reloading. Can bomb again in %v\n", conn.NextBomb())
return return
} }
bomb(conn, to) currentGame.Register(NewBomb(conn, to))
}, },
} }
@ -246,15 +246,6 @@ var mkBombCommand = &Command{
}, },
} }
func bomb(conn *Connection, to *System) {
conn.bombs -= 1
delay := conn.System().BombTimeTo(to)
fmt.Fprintf(conn, "sending bomb to %s. ETA: %v\n", to.name, delay)
After(delay, func() {
to.Bombed(conn)
})
}
func isCommand(name string) bool { func isCommand(name string) bool {
_, ok := commandRegistry[name] _, ok := commandRegistry[name]
return ok return ok

@ -17,6 +17,7 @@ var options struct {
frameRate int frameRate int
miningRate int miningRate int
playerSpeed float64 playerSpeed float64
bombSpeed float64
economic int economic int
} }
@ -117,5 +118,6 @@ func init() {
flag.IntVar(&options.frameRate, "frame-rate", 100, "frame rate, in frames per second") flag.IntVar(&options.frameRate, "frame-rate", 100, "frame rate, in frames per second")
flag.IntVar(&options.miningRate, "mining-rate", 1, "mining rate, in duckets per frame") flag.IntVar(&options.miningRate, "mining-rate", 1, "mining rate, in duckets per frame")
flag.Float64Var(&options.playerSpeed, "player-speed", 0.8, "player travel speed, relative to C, the speed of light") flag.Float64Var(&options.playerSpeed, "player-speed", 0.8, "player travel speed, relative to C, the speed of light")
flag.Float64Var(&options.bombSpeed, "bomb-speed", 0.9, "bomb travel speed, relattive to C, the speed of light")
flag.IntVar(&options.economic, "economic", 25000, "amount of money needed to win economic victory") flag.IntVar(&options.economic, "economic", 25000, "amount of money needed to win economic victory")
} }

Loading…
Cancel
Save