From 7837051e80db777422349eeb086a7d370f4ad440 Mon Sep 17 00:00:00 2001 From: "anton.gurov" Date: Tue, 12 Nov 2019 14:52:17 +0300 Subject: [PATCH] more checking rooms --- assets/prefabs/test.json | 50 ++++++++++++++++++- .../precomputed_shade/precomputed_shade.go | 8 +-- engine/gamemap/level.go | 2 +- engine/gamemap/mapgens/default.go | 13 +++-- engine/gamemap/prefab.go | 4 +- engine/gamemap/room.go | 8 +-- engine/screens/devmenu.go | 4 +- engine/screens/menu.go | 6 +-- engine/types/rect.go | 10 ++-- ui/mainwindow/layer.go | 4 +- ui/mainwindow/mainwindow.go | 2 +- ui/mainwindow/uiwindow.go | 4 +- ui/mainwindow/viewport.go | 4 +- 13 files changed, 82 insertions(+), 37 deletions(-) diff --git a/assets/prefabs/test.json b/assets/prefabs/test.json index 6559867..1cd3238 100644 --- a/assets/prefabs/test.json +++ b/assets/prefabs/test.json @@ -9,6 +9,29 @@ "default_item_legend": {}, "prefabs": [ + {"name": "test_room_2", + "tile_legend": { + "D": "decorated_wall" + }, + "mobs_legend": {}, + "item_legend": {}, + "size": {"x":15, "y":13}, + "body": [ + "??????#+#??????", + "??DDDD#.#DDDD??", + "?DD.........DD?", + "?D...........D?", + "?D...........D?", + "DD....D.D....##", + "+.............+", + "DD....D.D....##", + "?D...........#?", + "?D...........D?", + "?DD.........DD?", + "??DDDD#.#DDDD??", + "??????#+#??????" + ] + }, {"name": "test_room_1", "tile_legend": { "D": "decorated_wall", @@ -24,8 +47,8 @@ "###D.........DD?", "+....wwwwwww..D?", "###..wWWWWWw..D?", - "??#..wW...Ww..##", - "??D..wW.D.Ww...+", + "??#..wW.D.Ww..##", + "??D..wW...Ww...+", "??D..wW...Ww..##", "??D..wWWWWWw..#?", "??D..wwwwwww..D?", @@ -34,6 +57,29 @@ "???????#+#??????" ] + }, + {"name": "test_room_3", + "size":{"x":20, "y":17}, + "body": [ + "##########+#########", + "#..................#", + "#..................#", + "#..................#", + "#..................#", + "#..................#", + "#........#.........#", + "#.....#............#", + "#...#.....#........#", + "+.....#..#.........+", + "#......#...........#", + "#..................#", + "#..................#", + "#..................#", + "#..................#", + "#..................#", + "#..................#", + "##########+#########" + ] } ] } diff --git a/engine/fov/precomputed_shade/precomputed_shade.go b/engine/fov/precomputed_shade/precomputed_shade.go index 4dec910..3fa9af2 100644 --- a/engine/fov/precomputed_shade/precomputed_shade.go +++ b/engine/fov/precomputed_shade/precomputed_shade.go @@ -78,7 +78,7 @@ Pre-Computed Visiblity Trees on RogueBasin Adam Milazzo's FOV Method Roundup where a similar method described as 'permissive' is detailed */ -const MIN_LIT_TO_BE_VISIBLE = 1 +const MIN_LIT_TO_BE_VISIBLE = 0 const MIN_WALL_LIT_TO_BE_VISIBLE = 4 var errNotFoundCell = errors.New("Cell not found") @@ -240,7 +240,8 @@ func (ps *precomputedShade) recalc(level *gamemap.Level, initCoords types.Coords for _, angle := range cell.occludedAngles { if level.GetTile(lc).BlocksSight && ps.LightWalls { - if (nextShade[angle] == 0 && currentShade[angle] == 0) { + //if (nextShade[angle] == 0 && currentShade[angle] == 0) { + if (nextShade[angle] == 0) { level.GetTile(lc).Visible = true level.GetTile(lc).Explored = true } @@ -263,7 +264,8 @@ func (ps *precomputedShade) ComputeFov(level *gamemap.Level, initCoords types.Co for _, cell := range ps.CellList { //fmt.Printf("\n coords: %v, distance: %f, lit: %d", cell.Coords, cell.distance, cell.lit) cs, err := ps.toLevelCoords(level, initCoords, cell.Coords) - if cell.lit > MIN_LIT_TO_BE_VISIBLE { + //if cell.lit > 0 && cell.lit > MIN_LIT_TO_BE_VISIBLE { + if cell.lit > 0 && cell.lit / (ps.MaxTorchRadius - int(cell.distance -1)) > MIN_LIT_TO_BE_VISIBLE { if err != nil { continue } diff --git a/engine/gamemap/level.go b/engine/gamemap/level.go index 258c0d6..c099c73 100644 --- a/engine/gamemap/level.go +++ b/engine/gamemap/level.go @@ -12,7 +12,7 @@ var mapHeight = 90 type Level struct { - *types.Rect + types.Rect ctx util.ClientCtx Name string Branch string diff --git a/engine/gamemap/mapgens/default.go b/engine/gamemap/mapgens/default.go index b684fa0..4a05769 100644 --- a/engine/gamemap/mapgens/default.go +++ b/engine/gamemap/mapgens/default.go @@ -38,7 +38,7 @@ var fges = map[int]types.RectFill{ }, } -func DefaultGen(ctx util.ClientCtx,l *gamemap.Level) (*gamemap.Level, []*gamemap.Room) { +func DefaultGen(ctx util.ClientCtx,l *gamemap.Level) (*gamemap.Level, []gamemap.Room) { rng := util.NewRNG() @@ -54,19 +54,18 @@ func DefaultGen(ctx util.ClientCtx,l *gamemap.Level) (*gamemap.Level, []*gamemap } } - rooms := make([]*gamemap.Room, 0) + rooms := make([]gamemap.Room, 0) prefabUsed := false for i := 0; i < maxrooms; i++ { failed := false var fillage types.RectFill fillage = fges[rng.GetWeightedEntity(map[int]int{1: 10, 2: 1})] - var newRoom *gamemap.Room + var newRoom gamemap.Room if !prefabUsed || rng.Range(0,5) > 3 { //prefab prefabUsed = true - r := pfRooms[rng.Range(0, len(pfRooms) - 1)] //copy to local scope - newRoom = &r - + r := pfRooms[rng.Range(0, len(pfRooms))] //copy to local scope + newRoom = r } else { newRoom = gamemap.NewRandomRectRoom( rng, @@ -118,7 +117,7 @@ func DefaultGen(ctx util.ClientCtx,l *gamemap.Level) (*gamemap.Level, []*gamemap return l, rooms } -func connectRooms(l *gamemap.Level, room, otherRoom *gamemap.Room, toss int) { +func connectRooms(l *gamemap.Level, room, otherRoom gamemap.Room, toss int) { if toss == 0 { digHTunnel(l, room.Center.X, otherRoom.Center.X, room.Center.Y) digVTunnel(l, room.Center.Y, otherRoom.Center.Y, otherRoom.Center.X) diff --git a/engine/gamemap/prefab.go b/engine/gamemap/prefab.go index a5fcc9b..8d9141e 100644 --- a/engine/gamemap/prefab.go +++ b/engine/gamemap/prefab.go @@ -2,7 +2,6 @@ package gamemap import ( "encoding/json" - "fmt" "io/ioutil" "lab.zaar.be/thefish/alchemyst-go/engine/items" "lab.zaar.be/thefish/alchemyst-go/engine/mob" @@ -64,7 +63,6 @@ func (pfbl PrefabLoader) PrefabRoomsList() []Room { currentMobsLegend := file.DefaultMobsLegend currentItemLegend := file.DefaultItemLegend - fmt.Printf("%v",rawPrefab) for k,v := range rawPrefab.TileLegend { currentTileLegend[k] = v } @@ -76,7 +74,7 @@ func (pfbl PrefabLoader) PrefabRoomsList() []Room { } room := Room{ - Rect:&types.Rect{0, 0, rawPrefab.Size.X, rawPrefab.Size.Y}, + Rect:types.Rect{0, 0, rawPrefab.Size.X, rawPrefab.Size.Y}, Center: types.Coords{rawPrefab.Size.X / 2, rawPrefab.Size.Y / 2}, //fixme Geometry: make([]func()*Tile, rawPrefab.Size.X*rawPrefab.Size.Y), Mobs: make([]mob.Mob, rawPrefab.Size.X*rawPrefab.Size.Y), diff --git a/engine/gamemap/room.go b/engine/gamemap/room.go index d086db5..fd92045 100644 --- a/engine/gamemap/room.go +++ b/engine/gamemap/room.go @@ -12,7 +12,7 @@ import ( var invalidBlit = errors.New("trying to blit on existing good tile") type Room struct { - *types.Rect + types.Rect Center types.Coords Geometry []func() *Tile Mobs []mob.Mob @@ -73,8 +73,8 @@ func (room *Room) MoveToCoords(where types.Coords) *Room { return room } -func NewRandomRectRoom(rng *util.RNG, w, h int, fillage types.RectFill) *Room { - newRoom := &Room{ +func NewRandomRectRoom(rng *util.RNG, w, h int, fillage types.RectFill) Room { + newRoom := Room{ Rect: types.NewRect( 0, 0, @@ -84,7 +84,7 @@ func NewRandomRectRoom(rng *util.RNG, w, h int, fillage types.RectFill) *Room { Center: types.Coords{w / 2, h /2 }, Geometry: make([]func()*Tile, w*h), } - newRoom.Blit(fillage, newRoom) + newRoom.Blit(fillage, &newRoom) //add connectors newRoom.Connectors = append( newRoom.Connectors, diff --git a/engine/screens/devmenu.go b/engine/screens/devmenu.go index d558749..98cdd8b 100644 --- a/engine/screens/devmenu.go +++ b/engine/screens/devmenu.go @@ -13,7 +13,7 @@ type DevmenuScreen struct { scm *types.ScreenManager state *gamestate.GameState - *types.Rect + types.Rect renderParent bool @@ -21,7 +21,7 @@ type DevmenuScreen struct { fgColor string } -func NewDevmenuScreen(mw *mainwindow.MainWindow, scm *types.ScreenManager, state *gamestate.GameState, rect *types.Rect, renderParent bool) *DevmenuScreen { +func NewDevmenuScreen(mw *mainwindow.MainWindow, scm *types.ScreenManager, state *gamestate.GameState, rect types.Rect, renderParent bool) *DevmenuScreen { return &DevmenuScreen{ mw: mw, scm: scm, diff --git a/engine/screens/menu.go b/engine/screens/menu.go index 4ac7909..1e677fd 100644 --- a/engine/screens/menu.go +++ b/engine/screens/menu.go @@ -11,7 +11,7 @@ import ( const runeIndex = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" type MenuScreen struct { - *types.Rect + types.Rect mw *mainwindow.MainWindow scm *types.ScreenManager @@ -31,7 +31,7 @@ type MenuScreen struct { fgColor string } -func NewMenuScreen(mw *mainwindow.MainWindow, scm *types.ScreenManager, title, header, footer string, rect *types.Rect, renderParent bool) *MenuScreen { +func NewMenuScreen(mw *mainwindow.MainWindow, scm *types.ScreenManager, title, header, footer string, rect types.Rect, renderParent bool) *MenuScreen { return &MenuScreen{ title: title, header: header, @@ -141,7 +141,7 @@ func (ms *MenuScreen) ListRender() { menuItems = append(menuItems, ms.items[i].(string)) } } - ilw, ilh = menuLayer.PrintInside(&itemField, strings.Join(menuItems, "\n"), blt.TK_ALIGN_LEFT) + ilw, ilh = menuLayer.PrintInside(itemField, strings.Join(menuItems, "\n"), blt.TK_ALIGN_LEFT) } if ilh < len(ms.items) { ms.drawScrollBar(menuLayer, itemField) diff --git a/engine/types/rect.go b/engine/types/rect.go index 50fdd02..97f5437 100644 --- a/engine/types/rect.go +++ b/engine/types/rect.go @@ -8,14 +8,14 @@ type RectFill struct { Top, Bottom, Left, Right, TopLeft, TopRight, BottomLeft, BottomRight, Body interface{} } -func NewRect(x, y, w, h int) *Rect { - return &Rect{x, y, w, h} +func NewRect(x, y, w, h int) Rect { + return Rect{x, y, w, h} } -func NewCenteredRect(source *Rect, w, h int) *Rect { +func NewCenteredRect(source Rect, w, h int) Rect { targetX := source.X + source.W / 2 - w / 2 targetY := source.Y + source.H / 2 - h / 2 - return &Rect{targetX, targetY, w, h} + return Rect{targetX, targetY, w, h} } func (r *Rect) Blit(fillage RectFill, layer Putable) { @@ -52,7 +52,7 @@ func (r *Rect) Blit(fillage RectFill, layer Putable) { layer.Put(r.X+r.W - 1, r.Y+r.H - 1, fillage.BottomRight) } -func (self *Rect) Intersects(other *Rect) bool { +func (self *Rect) Intersects(other Rect) bool { if self.X <= (other.X+other.W) && (self.X+self.W) >= other.X && self.Y <= (other.Y+other.Y) && diff --git a/ui/mainwindow/layer.go b/ui/mainwindow/layer.go index e7f0543..483c0db 100644 --- a/ui/mainwindow/layer.go +++ b/ui/mainwindow/layer.go @@ -93,7 +93,7 @@ func (layer Layer) Print(x, y int, txt string) (w, h int) { return w, h } -func (layer Layer) PrintInside(rect *types.Rect, text string, alignment int) (width int, height int) { +func (layer Layer) PrintInside(rect types.Rect, text string, alignment int) (width int, height int) { return blt.PrintExt(rect.X + 2, rect.Y + 2, rect.W - 4, rect.H - 4, alignment, text) } @@ -105,7 +105,7 @@ func (layer *Layer) Decorate(f func(args ...interface{})) func(args ...interface } } -func (layer *Layer) ClearRect(r *types.Rect) { +func (layer *Layer) ClearRect(r types.Rect) { prevLayer := int(blt.State(blt.TK_LAYER)) blt.Layer(layer.Idx) blt.ClearArea(r.X, r.Y, r.W, r.H) diff --git a/ui/mainwindow/mainwindow.go b/ui/mainwindow/mainwindow.go index 25daf6e..b36a593 100644 --- a/ui/mainwindow/mainwindow.go +++ b/ui/mainwindow/mainwindow.go @@ -8,7 +8,7 @@ import ( ) type MainWindow struct { - *types.Rect + types.Rect ctx util.ClientCtx layers map[string]types.Renderable } diff --git a/ui/mainwindow/uiwindow.go b/ui/mainwindow/uiwindow.go index 7809f66..56dffc4 100644 --- a/ui/mainwindow/uiwindow.go +++ b/ui/mainwindow/uiwindow.go @@ -38,12 +38,12 @@ var doubleBorder = types.RectFill{ } type UiWindow struct { - *types.Rect + types.Rect layer *Layer fillage types.RectFill } -func (layer *Layer) NewWindow(rect *types.Rect) *UiWindow { +func (layer *Layer) NewWindow(rect types.Rect) *UiWindow { return &UiWindow{ Rect: rect, layer: layer, diff --git a/ui/mainwindow/viewport.go b/ui/mainwindow/viewport.go index 658519e..4f81e24 100644 --- a/ui/mainwindow/viewport.go +++ b/ui/mainwindow/viewport.go @@ -14,7 +14,7 @@ import ( var NotInViewError = errors.New("not in ViewPort") type ViewPort struct { - *types.Rect + types.Rect cameraCoords types.Coords layer *Layer Fov fov.Fov @@ -27,7 +27,7 @@ func NewViewPort(x, y, w, h int, layer *Layer) *ViewPort { computedFov := precomputed_shade.NewPrecomputedShade(15) computedFov.Init() vp := ViewPort{ - Rect: &types.Rect{x, y, w, h}, + Rect: types.Rect{x, y, w, h}, layer: layer, Fov: computedFov, }