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": {},
"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": [
"##########+#########",
"#..................#",
"#..................#",
"#..................#",
"#..................#",
"#..................#",
"#........#.........#",
"#.....#............#",
"#...#.....#........#",
"+.....#..#.........+",
"#......#...........#",
"#..................#",
"#..................#",
"#..................#",
"#..................#",
"#..................#",
"#..................#",
"##########+#########"
]
}
]
}

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
*/
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
}

View File

@ -12,7 +12,7 @@ var mapHeight = 90
type Level struct {
*types.Rect
types.Rect
ctx util.ClientCtx
Name 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()
@ -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)

View File

@ -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),

View File

@ -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,

View File

@ -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,

View File

@ -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)

View File

@ -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) &&

View File

@ -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)

View File

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

View File

@ -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,

View File

@ -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,
}