woah travel was way broken

slack
Jordan Orelli 10 years ago
parent 9daf5b2786
commit 957a6bfc7a

@ -11,6 +11,7 @@ type Bomb struct {
origin *System origin *System
target *System target *System
start time.Time start time.Time
done bool
fti int64 // frames to impact fti int64 // frames to impact
} }
@ -30,13 +31,15 @@ func NewBomb(from *Connection, to *System) *Bomb {
} }
func (b *Bomb) Dead() bool { func (b *Bomb) Dead() bool {
return b.fti <= 0 return b.done
} }
func (b *Bomb) Tick(frame int64) { func (b *Bomb) Tick(frame int64) {
b.fti -= 1 b.fti -= 1
if b.fti <= 0 { if b.fti <= 0 {
b.target.Bombed(b.player) b.target.Bombed(b.player)
b.done = true
log_info("bomb went off on %s", b.target.Label())
} }
} }

@ -77,7 +77,7 @@ func (c *Connection) Login() {
log_error("unable to create player record: %v", err) log_error("unable to create player record: %v", err)
} }
fmt.Fprintf(c, "you look new around these parts, %s.\n", player.name) fmt.Fprintf(c, "you look new around these parts, %s.\n", player.name)
fmt.Fprintf(c, `if you'd like a description of how to play, type the "help" command`) fmt.Fprintf(c, `if you'd like a description of how to play, type the "help" command\n`)
c.player = player c.player = player
} else { } else {
c.player = player c.player = player
@ -94,13 +94,11 @@ func (c *Connection) Dead() bool {
func (c *Connection) Tick(frame int64) { func (c *Connection) Tick(frame int64) {
// fuck // fuck
switch c.state { switch c.state {
case idle: case idle:
case dead: case dead:
case inTransit: case inTransit:
c.travelRemaining -= 1 c.travelRemaining -= 1
log_info("player %s has remaining travel: %v", c.PlayerName(), c.travelRemaining)
if c.travelRemaining == 0 { if c.travelRemaining == 0 {
c.land() c.land()
} }
@ -116,7 +114,6 @@ func (c *Connection) Tick(frame int64) {
} else { } else {
c.Deposit(1) c.Deposit(1)
sys.money -= 1 sys.money -= 1
log_info("%v", c.money)
} }
default: default:
log_error("connection %v has invalid state wtf", c) log_error("connection %v has invalid state wtf", c)
@ -124,9 +121,11 @@ func (c *Connection) Tick(frame int64) {
} }
func (c *Connection) TravelTo(dest *System) { func (c *Connection) TravelTo(dest *System) {
fmt.Fprintf(c, "traveling to: %s\n", dest.Label())
dist := c.System().DistanceTo(dest) dist := c.System().DistanceTo(dest)
c.travelRemaining = int64(dist / (options.lightSpeed * options.playerSpeed)) c.travelRemaining = int64(dist / (options.lightSpeed * options.playerSpeed))
t := time.Duration(c.travelRemaining) * (time.Second / time.Duration(options.frameRate))
fmt.Fprintf(c, "traveling to: %s. ETA: %v\n", dest.Label(), t)
c.location.Leave(c)
c.location = nil c.location = nil
c.dest = dest c.dest = dest
c.state = inTransit // fuck everything about this c.state = inTransit // fuck everything about this
@ -135,6 +134,7 @@ func (c *Connection) TravelTo(dest *System) {
func (c *Connection) land() { func (c *Connection) land() {
fmt.Fprintf(c, "you have arrived at %v\n", c.dest.Label()) fmt.Fprintf(c, "you have arrived at %v\n", c.dest.Label())
c.location = c.dest c.location = c.dest
c.location.Arrive(c)
c.dest = nil c.dest = nil
c.state = idle c.state = idle
} }
@ -199,6 +199,10 @@ func (c *Connection) NextBomb() time.Duration {
} }
func (c *Connection) MadeKill(victim *Connection) { func (c *Connection) MadeKill(victim *Connection) {
if c == victim {
log_info("player %s commited suicide.", c.PlayerName())
return
}
c.kills += 1 c.kills += 1
if c.kills == 3 { if c.kills == 3 {
c.Win("military") c.Win("military")

@ -41,15 +41,15 @@ func (s *System) Reset() {
func (s *System) Arrive(conn *Connection) { func (s *System) Arrive(conn *Connection) {
conn.SetSystem(s) conn.SetSystem(s)
log_info("player %s has arrived at system %s", conn.PlayerName(), s.name) log_info("player %s has arrived at system %s", conn.PlayerName(), s.Label())
if s.players == nil { if s.players == nil {
s.players = make(map[*Connection]bool, 8) s.players = make(map[*Connection]bool, 8)
} }
s.players[conn] = true s.players[conn] = true
if s.planets == 1 { if s.planets == 1 {
fmt.Fprintf(conn, "you are in the system %s. There is %d planet here.\n", s.name, s.planets) fmt.Fprintf(conn, "you are in the system %s. There is %d planet here.\n", s.Label(), s.planets)
} else { } else {
fmt.Fprintf(conn, "you are in the system %s. There are %d planets here.\n", s.name, s.planets) fmt.Fprintf(conn, "you are in the system %s. There are %d planets here.\n", s.Label(), s.planets)
} }
} }

Loading…
Cancel
Save