aboutsummaryrefslogtreecommitdiff
path: root/internal/game/render_map.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/game/render_map.go')
-rw-r--r--internal/game/render_map.go45
1 files changed, 37 insertions, 8 deletions
diff --git a/internal/game/render_map.go b/internal/game/render_map.go
index 1bc9adc..5e57bc7 100644
--- a/internal/game/render_map.go
+++ b/internal/game/render_map.go
@@ -6,6 +6,7 @@ import (
"thehouseoficarus/internal/color"
"thehouseoficarus/internal/net"
+ "thehouseoficarus/internal/player"
"thehouseoficarus/internal/world"
)
@@ -55,10 +56,26 @@ type mapGraph struct {
// player's z-plane is constant.
const playerZ = 0
-func buildGraph(g *Game, startRoomID int) *mapGraph {
+func buildGraph(g *Game, sess *net.Session, startRoomID int) *mapGraph {
rg := world.BuildGrid(startRoomID, func(id int) (*world.Room, bool) {
return loadRoom(g, id)
- }, nil, nil)
+ }, nil, func(fromID int, dir world.ExitDir, targetID int) bool {
+ if sess == nil || sess.Player == nil {
+ return true
+ }
+ room, ok := loadRoom(g, fromID)
+ if !ok {
+ return true
+ }
+ exit, ok := room.Exits[dir]
+ if !ok || exit.Room != targetID {
+ return true
+ }
+ if exit.Hidden && !g.exitDiscovered(sess.Player, fromID, dir) {
+ return false
+ }
+ return true
+ }, nil)
return &mapGraph{posToRoom: rg.RoomAt, dist: rg.Dist}
}
@@ -88,7 +105,7 @@ func renderMapCells(grid [][]mapCell, colorMode string, startRow, endRow int, bo
func buildTinyMap(g *Game, sess *net.Session, roomID int, mg mapGlyphs) []string {
visited := roomsVisited(sess)
- bg := buildGraph(g, roomID)
+ bg := buildGraph(g, sess, roomID)
colorMode := colorModeFor(sess)
atSpec := resolveMapAt(g, sess)
@@ -261,7 +278,7 @@ func buildTinyMap(g *Game, sess *net.Session, roomID int, mg mapGlyphs) []string
func buildFullMap(g *Game, sess *net.Session, roomID, mapWidth, mapHeight int, mg mapGlyphs) []string {
visited := roomsVisited(sess)
- bg := buildGraph(g, roomID)
+ bg := buildGraph(g, sess, roomID)
colorMode := colorModeFor(sess)
atSpec := resolveMapAt(g, sess)
@@ -602,10 +619,15 @@ func exitStateTo(g *Game, sess *net.Session, from int, dir world.ExitDir, neighb
if !ok || exit.Room != neighbor {
return exitAbsent
}
- // Hidden exits are non-traversable to players but are followed by the map
- // layout BFS, so they always render as traversable (open) connectors.
- if exit.Hidden {
- return exitOpen
+ p := sessPlayer(sess)
+ if exit.Hidden && !g.exitDiscovered(p, from, dir) {
+ return exitAbsent
+ }
+ if exit.AlwaysBlocked {
+ if p != nil && p.GodMode {
+ return exitOpen
+ }
+ return exitBlocked
}
if exit.Condition == nil || sess == nil || sess.Player == nil {
return exitOpen
@@ -616,6 +638,13 @@ func exitStateTo(g *Game, sess *net.Session, from int, dir world.ExitDir, neighb
return exitBlocked
}
+func sessPlayer(sess *net.Session) *player.Player {
+ if sess != nil {
+ return sess.Player
+ }
+ return nil
+}
+
func isDiagonalGlyph(ch rune) bool {
return ch == '\\' || ch == '/' || ch == '↗' || ch == '↖' || ch == '↘' || ch == '↙'
}