aboutsummaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
Diffstat (limited to 'internal')
-rw-r--r--internal/game/cmd_undig.go8
-rw-r--r--internal/game/render_map.go97
2 files changed, 83 insertions, 22 deletions
diff --git a/internal/game/cmd_undig.go b/internal/game/cmd_undig.go
index 1fc70c1..2215c51 100644
--- a/internal/game/cmd_undig.go
+++ b/internal/game/cmd_undig.go
@@ -58,10 +58,9 @@ func (g *Game) executeUndig(sess *net.Session, args []string, rawInput string) {
sess.State = net.StateUndigConfirm
sess.WriteLine(fmt.Sprintf("You are about to DELETE Room #%d (%s) and all exits leading to it.", targetID, targetRoom.Name))
- sess.WriteLine("")
g.listUndigOrphans(sess, targetID)
sess.WriteLine("")
- sess.WriteLine(fmt.Sprintf("Type UNDIG %s to confirm, or anything else to cancel.", strings.ToUpper(string(dir))))
+ sess.WriteLine("Undig? [y/N]")
}
func (g *Game) listUndigOrphans(sess *net.Session, targetID int) {
@@ -131,7 +130,7 @@ func (g *Game) handleUndigConfirm(sess *net.Session, input string) {
return
}
- choice := strings.TrimSpace(input)
+ choice := strings.ToLower(strings.TrimSpace(input))
dir := sess.PendingUndigDir
targetID := sess.PendingUndigRoom
sess.PendingUndigDir = ""
@@ -143,8 +142,7 @@ func (g *Game) handleUndigConfirm(sess *net.Session, input string) {
return
}
- expected := "UNDIG " + strings.ToUpper(dir)
- if strings.ToUpper(choice) != expected {
+ if choice != "y" && choice != "yes" {
sess.WriteLine("Undig cancelled.")
g.writePrompt(sess)
return
diff --git a/internal/game/render_map.go b/internal/game/render_map.go
index b210e77..b4b8c93 100644
--- a/internal/game/render_map.go
+++ b/internal/game/render_map.go
@@ -206,30 +206,46 @@ func buildTinyMap(g *Game, sess *net.Session, roomID int, mg mapGlyphs) []string
cur, _ := loadRoom(g, roomID)
if cur != nil {
- if upTarget, hasUp := exitTarget(cur, world.Up); hasUp {
+ _, hasUp := exitTarget(cur, world.Up)
+ _, hasDown := exitTarget(cur, world.Down)
+
+ upCorners := [][2]int{
+ {1, 3}, // NE
+ {1, 1}, // NW
+ {3, 3}, // SE
+ {3, 1}, // SW
+ }
+ downCorners := [][2]int{
+ {3, 1}, // SW
+ {3, 3}, // SE
+ {1, 3}, // NE
+ {1, 1}, // NW
+ }
+
+ placeArrow := func(corners [][2]int, glyph rune, blockedSpec color.ColorSpec) {
+ for _, c := range corners {
+ if grid[c[0]][c[1]].char == ' ' {
+ grid[c[0]][c[1]] = mapCell{char: glyph, spec: blockedSpec}
+ return
+ }
+ }
+ }
+
+ if hasUp {
spec := color.NoColor()
- if exitStateTo(g, sess, roomID, world.Up, upTarget) == exitBlocked {
+ if upTarget, _ := exitTarget(cur, world.Up); upTarget != 0 &&
+ exitStateTo(g, sess, roomID, world.Up, upTarget) == exitBlocked {
spec = ctx.blockedSpec
}
- switch {
- case grid[1][3].char == ' ':
- grid[1][3] = mapCell{char: mg.upArrow, spec: spec}
- case grid[1][1].char == ' ':
- grid[1][1] = mapCell{char: mg.upArrow, spec: spec}
- case grid[1][2].char == ' ':
- grid[1][2] = mapCell{char: mg.upArrow, spec: spec}
- }
+ placeArrow(upCorners, mg.upArrow, spec)
}
- if downTarget, hasDown := exitTarget(cur, world.Down); hasDown {
+ if hasDown {
spec := color.NoColor()
- if exitStateTo(g, sess, roomID, world.Down, downTarget) == exitBlocked {
+ if downTarget, _ := exitTarget(cur, world.Down); downTarget != 0 &&
+ exitStateTo(g, sess, roomID, world.Down, downTarget) == exitBlocked {
spec = ctx.blockedSpec
}
- if grid[3][1].char == ' ' {
- grid[3][1] = mapCell{char: mg.downArrow, spec: spec}
- } else if grid[3][3].char == ' ' {
- grid[3][3] = mapCell{char: mg.downArrow, spec: spec}
- }
+ placeArrow(downCorners, mg.downArrow, spec)
}
}
@@ -333,6 +349,53 @@ func buildFullMap(g *Game, sess *net.Session, roomID, mapWidth, mapHeight int, m
}
}
+ cur, _ := loadRoom(g, roomID)
+ if cur != nil {
+ _, hasUp := exitTarget(cur, world.Up)
+ _, hasDown := exitTarget(cur, world.Down)
+
+ upCorners := [][2]int{
+ {cy - 1, cx + 1}, // NE
+ {cy - 1, cx - 1}, // NW
+ {cy + 1, cx + 1}, // SE
+ {cy + 1, cx - 1}, // SW
+ }
+ downCorners := [][2]int{
+ {cy + 1, cx - 1}, // SW
+ {cy + 1, cx + 1}, // SE
+ {cy - 1, cx + 1}, // NE
+ {cy - 1, cx - 1}, // NW
+ }
+
+ placeArrow := func(corners [][2]int, glyph rune, blockedSpec color.ColorSpec) {
+ for _, c := range corners {
+ r, col := c[0], c[1]
+ if r >= 0 && r < mapHeight && col >= 0 && col < mapWidth &&
+ grid[r][col].char == ' ' {
+ grid[r][col] = mapCell{char: glyph, spec: blockedSpec}
+ return
+ }
+ }
+ }
+
+ if hasUp {
+ spec := color.NoColor()
+ if upTarget, _ := exitTarget(cur, world.Up); upTarget != 0 &&
+ exitStateTo(g, sess, roomID, world.Up, upTarget) == exitBlocked {
+ spec = ctx.blockedSpec
+ }
+ placeArrow(upCorners, mg.upArrow, spec)
+ }
+ if hasDown {
+ spec := color.NoColor()
+ if downTarget, _ := exitTarget(cur, world.Down); downTarget != 0 &&
+ exitStateTo(g, sess, roomID, world.Down, downTarget) == exitBlocked {
+ spec = ctx.blockedSpec
+ }
+ placeArrow(downCorners, mg.downArrow, spec)
+ }
+ }
+
return renderMapCells(grid, colorMode, 0, mapHeight, 0)
}