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

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