make context great again
This commit is contained in:
55
engine/gamemap/mapgens/delaunay_mst_ext.go
Normal file
55
engine/gamemap/mapgens/delaunay_mst_ext.go
Normal file
@ -0,0 +1,55 @@
|
||||
package mapgens
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"lab.zaar.be/thefish/alchemyst-go/engine/gamemap"
|
||||
"lab.zaar.be/thefish/alchemyst-go/engine/types"
|
||||
"lab.zaar.be/thefish/alchemyst-go/util"
|
||||
"lab.zaar.be/thefish/alchemyst-go/util/appctx"
|
||||
"lab.zaar.be/thefish/alchemyst-go/util/delaunay"
|
||||
)
|
||||
|
||||
func DelaunayMstExtGen(ctx appctx.ClientCtx, l *gamemap.Level) (*gamemap.Level, []gamemap.Room) {
|
||||
|
||||
rng := util.NewRNG()
|
||||
|
||||
//fill with walls
|
||||
for i := 0; i < l.W; i ++ {
|
||||
for j := 0; j < l.H; j++ {
|
||||
l.SetTileByXY(i, j, gamemap.NewWall())
|
||||
}
|
||||
}
|
||||
rooms := GetRandomRoomList(ctx, rng, l, maxrooms, minRoomSize, maxRoomSize)
|
||||
|
||||
|
||||
for _, room := range rooms {
|
||||
err := room.BlitToLevel(l)
|
||||
if err != nil {
|
||||
fmt.Printf("err: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
centers := make([]types.Coords, 0)
|
||||
for _, room := range rooms {
|
||||
centers = append(centers, room.Center)
|
||||
}
|
||||
edges := delaunay.GetMst(centers, l.W, l.H, l.W) //get negative Weights
|
||||
outlyingCorridors := make([]types.Edge, 0)
|
||||
outlyingCorrCount := 0
|
||||
for _, edge := range edges {
|
||||
MedianStraight(rng, l, rooms, centers, edge)
|
||||
outlyingCorridors = append(outlyingCorridors, edge)
|
||||
outlyingCorrCount++
|
||||
if outlyingCorrCount > 5 {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
edges = delaunay.GetMst(centers, l.W, l.H, 0) //get negative Weights
|
||||
for _, edge := range edges {
|
||||
MedianStraight(rng, l, rooms, centers, edge)
|
||||
}
|
||||
|
||||
return l, rooms
|
||||
}
|
||||
|
Reference in New Issue
Block a user