diff --git a/internal/math/vec.go b/internal/math/vec.go index 8f23fdd..140928b 100644 --- a/internal/math/vec.go +++ b/internal/math/vec.go @@ -2,6 +2,7 @@ package math import ( "encoding/json" + "fmt" ) type Vec struct { @@ -9,6 +10,8 @@ type Vec struct { Y int } +func (v Vec) String() string { return fmt.Sprintf("(%d, %d)", v.X, v.Y) } + func (v Vec) MarshalJSON() ([]byte, error) { return json.Marshal([2]int{v.X, v.Y}) } diff --git a/internal/sim/player.go b/internal/sim/player.go index 1b155a0..ed5ec80 100644 --- a/internal/sim/player.go +++ b/internal/sim/player.go @@ -180,7 +180,7 @@ func (Move) NetTag() string { return "move" } func (m *Move) exec(w *world, r *room, p *player, seq int) result { pos := p.avatar.Position target := pos.Add(math.Vec(*m)) - p.Info("running move for player %s from %v to %v", p.name, *m, target) + p.Info("running move for player %s from %v to %v", p.name, p.avatar.Position, target) if !r.Contains(target) { return result{reply: wire.Errorf("target cell (%d, %d) is out of bounds", target.X, target.Y)} } diff --git a/internal/sim/room.go b/internal/sim/room.go index 5a1d68b..cbf7373 100644 --- a/internal/sim/room.go +++ b/internal/sim/room.go @@ -60,6 +60,6 @@ func (r *room) getTile(pos math.Vec) *tile { if !r.Contains(pos) { return nil } - n := pos.X*r.Width + pos.Y + n := r.Width*pos.Y + pos.X return &r.tiles[n] } diff --git a/internal/sim/world.go b/internal/sim/world.go index 487352f..014ed18 100644 --- a/internal/sim/world.go +++ b/internal/sim/world.go @@ -173,8 +173,15 @@ func (w *world) handleRequest(req Request) { func (w *world) register(c connect) { w.Info("register: %#v", c.login) - foyer := w.rooms["foyer"] - if len(foyer.players) >= 100 { + + r := w.rooms["foyer"] + if hall, ok := w.rooms["hall"]; ok { + if len(hall.players) < len(r.players) { + r = hall + } + } + + if len(r.players) >= 100 { c.failed <- fmt.Errorf("room is full") close(c.failed) return @@ -190,11 +197,11 @@ func (w *world) register(c connect) { Wants: &spawnPlayer{}, }, } - foyer.players[c.login.Name] = &p + r.players[c.login.Name] = &p w.players[c.login.Name] = &p w.Info("starting player...") - p.start(w.inbox, c.conn, foyer) + p.start(w.inbox, c.conn, r) } func (w *world) stop() error {