travel no longer uses the scheduler

slack
Jordan Orelli 10 years ago
parent 24907f1644
commit afedab97e1

@ -144,7 +144,7 @@ var gotoCommand = &Command{
dest_name := strings.Join(args, " ")
to, ok := nameIndex[dest_name]
if ok {
move(conn, to)
conn.TravelTo(to)
return
}
@ -159,7 +159,7 @@ var gotoCommand = &Command{
fmt.Fprintf(conn, `oh dear, there doesn't seem to be a system with id %d`, id_n)
return
}
move(conn, to)
conn.TravelTo(to)
},
}
@ -187,7 +187,7 @@ var colonizeCommand = &Command{
system := conn.System()
var fn func()
fn = func() {
reward := int64(rand.NormFloat64()*5.0 + 100.0*system.miningRate)
reward := int(rand.NormFloat64()*5.0 + 100.0*system.miningRate)
if system.colonizedBy != nil {
system.colonizedBy.Deposit(reward)
fmt.Fprintf(system.colonizedBy, "mining colony on %s pays you %d space duckets. total: %d space duckets.\n", system.name, reward, system.colonizedBy.money)
@ -220,18 +220,6 @@ var winCommand = &Command{
},
}
func move(conn *Connection, to *System) {
start := conn.System()
start.Leave(conn)
delay := start.TravelTimeTo(to)
fmt.Fprintf(conn, "moving to %s. ETA: %v\n", to.name, delay)
After(delay, func() {
to.Arrive(conn)
fmt.Fprintf(conn, "You have arrived at the %s system after a total travel time of %v.\n", to.name, delay)
})
}
var bombCommand = &Command{
name: "bomb",
help: "bombs a system, with a big space bomb",

@ -12,18 +12,30 @@ import (
type Connection struct {
net.Conn
*bufio.Reader
player *Player
location *System
lastScan time.Time
lastBomb time.Time
kills int
dead bool
money int64
mining bool
colonies []*System
bombs int
player *Player
location *System
dest *System
travelRemaining int64
lastScan time.Time
lastBomb time.Time
kills int
dead bool
money int
mining bool
colonies []*System
bombs int
state PlayerState // this is wrong...
}
type PlayerState int
const (
idle PlayerState = iota
dead
inTransit
mining
)
func NewConnection(conn net.Conn) *Connection {
c := &Connection{
Conn: conn,
@ -74,7 +86,45 @@ func (c *Connection) Login() {
}
break
}
currentGame.Register(c)
}
func (c *Connection) Dead() bool {
return false
}
func (c *Connection) Tick(frame int64) {
// fuck
switch c.state {
case idle:
case dead:
case inTransit:
c.travelRemaining -= 1
log_info("player %s has remaining travel: %v", c.PlayerName(), c.travelRemaining)
if c.travelRemaining == 0 {
c.land()
}
case mining:
c.money += options.miningRate
default:
log_error("connection %v has invalid state wtf", c)
}
}
func (c *Connection) TravelTo(dest *System) {
fmt.Fprintf(c, "traveling to: %s\n", dest.Label())
dist := c.System().DistanceTo(dest)
c.travelRemaining = int64(dist / (options.lightSpeed * options.playerSpeed))
c.location = nil
c.dest = dest
c.state = inTransit // fuck everything about this
}
func (c *Connection) land() {
fmt.Fprintf(c, "you have arrived at %v\n", c.dest.Label())
c.location = c.dest
c.dest = nil
c.state = idle
}
func (c *Connection) SetSystem(s *System) {
@ -162,16 +212,16 @@ func (c *Connection) Payout() {
if c.dead {
return
}
reward := int64(rand.NormFloat64()*5.0 + 100.0*c.System().miningRate)
reward := int(rand.NormFloat64()*5.0 + 100.0*c.System().miningRate)
c.Deposit(reward)
fmt.Fprintf(c, "mined: %d space duckets. total: %d\n", reward, c.money)
}
func (c *Connection) Withdraw(n int64) {
func (c *Connection) Withdraw(n int) {
c.money -= n
}
func (c *Connection) Deposit(n int64) {
func (c *Connection) Deposit(n int) {
c.money += n
if c.money >= 25000 {
c.Win("economic")

@ -13,8 +13,10 @@ import (
)
var options struct {
lightSpeed float64
frameRate int
lightSpeed float64
frameRate int
miningRate int
playerSpeed float64
}
var (
@ -112,4 +114,6 @@ func main() {
func init() {
flag.Float64Var(&options.lightSpeed, "light-speed", 0.01, "speed of light in parsecs per frame")
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.Float64Var(&options.playerSpeed, "player-speed", 0.8, "player travel speed, relative to C, the speed of light")
}

@ -29,14 +29,6 @@ func (p *Player) Create() error {
return nil
}
func (p *Player) Dead() bool {
return false
}
func (p *Player) Tick(frame int64) {
}
func playersTable() {
stmnt := `create table if not exists players (
id integer not null primary key autoincrement,

Loading…
Cancel
Save