more checking rooms

This commit is contained in:
anton.gurov 2019-11-12 14:52:17 +03:00
parent 4bdb51d9e3
commit 7837051e80
13 changed files with 82 additions and 37 deletions

View File

@ -9,6 +9,29 @@
"default_item_legend": {}, "default_item_legend": {},
"prefabs": [ "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", {"name": "test_room_1",
"tile_legend": { "tile_legend": {
"D": "decorated_wall", "D": "decorated_wall",
@ -24,8 +47,8 @@
"###D.........DD?", "###D.........DD?",
"+....wwwwwww..D?", "+....wwwwwww..D?",
"###..wWWWWWw..D?", "###..wWWWWWw..D?",
"??#..wW...Ww..##", "??#..wW.D.Ww..##",
"??D..wW.D.Ww...+", "??D..wW...Ww...+",
"??D..wW...Ww..##", "??D..wW...Ww..##",
"??D..wWWWWWw..#?", "??D..wWWWWWw..#?",
"??D..wwwwwww..D?", "??D..wwwwwww..D?",
@ -34,6 +57,29 @@
"???????#+#??????" "???????#+#??????"
] ]
},
{"name": "test_room_3",
"size":{"x":20, "y":17},
"body": [
"##########+#########",
"#..................#",
"#..................#",
"#..................#",
"#..................#",
"#..................#",
"#........#.........#",
"#.....#............#",
"#...#.....#........#",
"+.....#..#.........+",
"#......#...........#",
"#..................#",
"#..................#",
"#..................#",
"#..................#",
"#..................#",
"#..................#",
"##########+#########"
]
} }
] ]
} }

View File

@ -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 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 const MIN_WALL_LIT_TO_BE_VISIBLE = 4
var errNotFoundCell = errors.New("Cell not found") 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 { for _, angle := range cell.occludedAngles {
if level.GetTile(lc).BlocksSight && ps.LightWalls { 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).Visible = true
level.GetTile(lc).Explored = 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 { for _, cell := range ps.CellList {
//fmt.Printf("\n coords: %v, distance: %f, lit: %d", cell.Coords, cell.distance, cell.lit) //fmt.Printf("\n coords: %v, distance: %f, lit: %d", cell.Coords, cell.distance, cell.lit)
cs, err := ps.toLevelCoords(level, initCoords, cell.Coords) 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 { if err != nil {
continue continue
} }

View File

@ -12,7 +12,7 @@ var mapHeight = 90
type Level struct { type Level struct {
*types.Rect types.Rect
ctx util.ClientCtx ctx util.ClientCtx
Name string Name string
Branch string Branch string

View File

@ -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() 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 prefabUsed := false
for i := 0; i < maxrooms; i++ { for i := 0; i < maxrooms; i++ {
failed := false failed := false
var fillage types.RectFill var fillage types.RectFill
fillage = fges[rng.GetWeightedEntity(map[int]int{1: 10, 2: 1})] 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 { if !prefabUsed || rng.Range(0,5) > 3 {
//prefab //prefab
prefabUsed = true prefabUsed = true
r := pfRooms[rng.Range(0, len(pfRooms) - 1)] //copy to local scope r := pfRooms[rng.Range(0, len(pfRooms))] //copy to local scope
newRoom = &r newRoom = r
} else { } else {
newRoom = gamemap.NewRandomRectRoom( newRoom = gamemap.NewRandomRectRoom(
rng, rng,
@ -118,7 +117,7 @@ func DefaultGen(ctx util.ClientCtx,l *gamemap.Level) (*gamemap.Level, []*gamemap
return l, rooms 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 { if toss == 0 {
digHTunnel(l, room.Center.X, otherRoom.Center.X, room.Center.Y) digHTunnel(l, room.Center.X, otherRoom.Center.X, room.Center.Y)
digVTunnel(l, room.Center.Y, otherRoom.Center.Y, otherRoom.Center.X) digVTunnel(l, room.Center.Y, otherRoom.Center.Y, otherRoom.Center.X)

View File

@ -2,7 +2,6 @@ package gamemap
import ( import (
"encoding/json" "encoding/json"
"fmt"
"io/ioutil" "io/ioutil"
"lab.zaar.be/thefish/alchemyst-go/engine/items" "lab.zaar.be/thefish/alchemyst-go/engine/items"
"lab.zaar.be/thefish/alchemyst-go/engine/mob" "lab.zaar.be/thefish/alchemyst-go/engine/mob"
@ -64,7 +63,6 @@ func (pfbl PrefabLoader) PrefabRoomsList() []Room {
currentMobsLegend := file.DefaultMobsLegend currentMobsLegend := file.DefaultMobsLegend
currentItemLegend := file.DefaultItemLegend currentItemLegend := file.DefaultItemLegend
fmt.Printf("%v",rawPrefab)
for k,v := range rawPrefab.TileLegend { for k,v := range rawPrefab.TileLegend {
currentTileLegend[k] = v currentTileLegend[k] = v
} }
@ -76,7 +74,7 @@ func (pfbl PrefabLoader) PrefabRoomsList() []Room {
} }
room := 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 Center: types.Coords{rawPrefab.Size.X / 2, rawPrefab.Size.Y / 2}, //fixme
Geometry: make([]func()*Tile, rawPrefab.Size.X*rawPrefab.Size.Y), Geometry: make([]func()*Tile, rawPrefab.Size.X*rawPrefab.Size.Y),
Mobs: make([]mob.Mob, rawPrefab.Size.X*rawPrefab.Size.Y), Mobs: make([]mob.Mob, rawPrefab.Size.X*rawPrefab.Size.Y),

View File

@ -12,7 +12,7 @@ import (
var invalidBlit = errors.New("trying to blit on existing good tile") var invalidBlit = errors.New("trying to blit on existing good tile")
type Room struct { type Room struct {
*types.Rect types.Rect
Center types.Coords Center types.Coords
Geometry []func() *Tile Geometry []func() *Tile
Mobs []mob.Mob Mobs []mob.Mob
@ -73,8 +73,8 @@ func (room *Room) MoveToCoords(where types.Coords) *Room {
return room return room
} }
func NewRandomRectRoom(rng *util.RNG, w, h int, fillage types.RectFill) *Room { func NewRandomRectRoom(rng *util.RNG, w, h int, fillage types.RectFill) Room {
newRoom := &Room{ newRoom := Room{
Rect: types.NewRect( Rect: types.NewRect(
0, 0,
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 }, Center: types.Coords{w / 2, h /2 },
Geometry: make([]func()*Tile, w*h), Geometry: make([]func()*Tile, w*h),
} }
newRoom.Blit(fillage, newRoom) newRoom.Blit(fillage, &newRoom)
//add connectors //add connectors
newRoom.Connectors = append( newRoom.Connectors = append(
newRoom.Connectors, newRoom.Connectors,

View File

@ -13,7 +13,7 @@ type DevmenuScreen struct {
scm *types.ScreenManager scm *types.ScreenManager
state *gamestate.GameState state *gamestate.GameState
*types.Rect types.Rect
renderParent bool renderParent bool
@ -21,7 +21,7 @@ type DevmenuScreen struct {
fgColor string 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{ return &DevmenuScreen{
mw: mw, mw: mw,
scm: scm, scm: scm,

View File

@ -11,7 +11,7 @@ import (
const runeIndex = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" const runeIndex = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
type MenuScreen struct { type MenuScreen struct {
*types.Rect types.Rect
mw *mainwindow.MainWindow mw *mainwindow.MainWindow
scm *types.ScreenManager scm *types.ScreenManager
@ -31,7 +31,7 @@ type MenuScreen struct {
fgColor string 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{ return &MenuScreen{
title: title, title: title,
header: header, header: header,
@ -141,7 +141,7 @@ func (ms *MenuScreen) ListRender() {
menuItems = append(menuItems, ms.items[i].(string)) 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) { if ilh < len(ms.items) {
ms.drawScrollBar(menuLayer, itemField) ms.drawScrollBar(menuLayer, itemField)

View File

@ -8,14 +8,14 @@ type RectFill struct {
Top, Bottom, Left, Right, TopLeft, TopRight, BottomLeft, BottomRight, Body interface{} Top, Bottom, Left, Right, TopLeft, TopRight, BottomLeft, BottomRight, Body interface{}
} }
func NewRect(x, y, w, h int) *Rect { func NewRect(x, y, w, h int) Rect {
return &Rect{x, y, w, h} 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 targetX := source.X + source.W / 2 - w / 2
targetY := source.Y + source.H / 2 - h / 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) { 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) 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) && if self.X <= (other.X+other.W) &&
(self.X+self.W) >= other.X && (self.X+self.W) >= other.X &&
self.Y <= (other.Y+other.Y) && self.Y <= (other.Y+other.Y) &&

View File

@ -93,7 +93,7 @@ func (layer Layer) Print(x, y int, txt string) (w, h int) {
return w, h 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) 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)) prevLayer := int(blt.State(blt.TK_LAYER))
blt.Layer(layer.Idx) blt.Layer(layer.Idx)
blt.ClearArea(r.X, r.Y, r.W, r.H) blt.ClearArea(r.X, r.Y, r.W, r.H)

View File

@ -8,7 +8,7 @@ import (
) )
type MainWindow struct { type MainWindow struct {
*types.Rect types.Rect
ctx util.ClientCtx ctx util.ClientCtx
layers map[string]types.Renderable layers map[string]types.Renderable
} }

View File

@ -38,12 +38,12 @@ var doubleBorder = types.RectFill{
} }
type UiWindow struct { type UiWindow struct {
*types.Rect types.Rect
layer *Layer layer *Layer
fillage types.RectFill fillage types.RectFill
} }
func (layer *Layer) NewWindow(rect *types.Rect) *UiWindow { func (layer *Layer) NewWindow(rect types.Rect) *UiWindow {
return &UiWindow{ return &UiWindow{
Rect: rect, Rect: rect,
layer: layer, layer: layer,

View File

@ -14,7 +14,7 @@ import (
var NotInViewError = errors.New("not in ViewPort") var NotInViewError = errors.New("not in ViewPort")
type ViewPort struct { type ViewPort struct {
*types.Rect types.Rect
cameraCoords types.Coords cameraCoords types.Coords
layer *Layer layer *Layer
Fov fov.Fov Fov fov.Fov
@ -27,7 +27,7 @@ func NewViewPort(x, y, w, h int, layer *Layer) *ViewPort {
computedFov := precomputed_shade.NewPrecomputedShade(15) computedFov := precomputed_shade.NewPrecomputedShade(15)
computedFov.Init() computedFov.Init()
vp := ViewPort{ vp := ViewPort{
Rect: &types.Rect{x, y, w, h}, Rect: types.Rect{x, y, w, h},
layer: layer, layer: layer,
Fov: computedFov, Fov: computedFov,
} }