correct copying of prefabs

This commit is contained in:
anton.gurov
2019-11-12 13:59:19 +03:00
parent d198001ec0
commit 4bdb51d9e3
5 changed files with 17 additions and 63 deletions

View File

@ -54,12 +54,12 @@ func (l *Level) SetTileByXY (x,y int, tile *Tile) {
}
func (l *Level) Put (x, y int, tileFunc interface{}) {
tf := tileFunc.(func() *Tile)()
if tf == nil {
l.ctx.Logger().Fatal().Msgf("Got non-tile type to put into level: %v", tf)
tile := tileFunc.(func() *Tile)()
if tile == nil {
l.ctx.Logger().Fatal().Msgf("Got non-tile type to put into level: %v", tile)
}
if l.InBounds(types.Coords{x, y}) {
l.Tiles[y*l.W+x] = tf
l.Tiles[y*l.W+x] = tile
}
}

View File

@ -10,7 +10,7 @@ import (
//fixme move to config
var minRoomSize = 3
var maxRoomSize = 22
var maxrooms = 50
var maxrooms = 20
var fges = map[int]types.RectFill{
1: types.RectFill{
@ -55,15 +55,18 @@ func DefaultGen(ctx util.ClientCtx,l *gamemap.Level) (*gamemap.Level, []*gamemap
}
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
if rng.Range(0, 5) == 1 {
if !prefabUsed || rng.Range(0,5) > 3 {
//prefab
newRoom = &pfRooms[0]
prefabUsed = true
r := pfRooms[rng.Range(0, len(pfRooms) - 1)] //copy to local scope
newRoom = &r
} else {
newRoom = gamemap.NewRandomRectRoom(
rng,

View File

@ -23,9 +23,9 @@ type PrefabRecord struct {
X int `json:"x"`
Y int `json:"y"`
} `json:"Size"`
TileLegend map[string]string `json:"default_tile_legend"`
MobsLegend map[string]string `json:"default_mobs_legend"`
ItemLegend map[string]string `json:"default_item_legend"`
TileLegend map[string]string `json:"tile_legend"`
MobsLegend map[string]string `json:"mobs_legend"`
ItemLegend map[string]string `json:"item_legend"`
Body []string `json:"body"`
}