now building facilities
This commit is contained in:
parent
5ab26a1507
commit
b8028ecd54
1 changed files with 47 additions and 6 deletions
|
@ -55,7 +55,8 @@ buildHallFloor fc gen =
|
||||||
(g2, withIW) = buildInnerWalls g1 withElv
|
(g2, withIW) = buildInnerWalls g1 withElv
|
||||||
withOW = buildOuterWalls withIW
|
withOW = buildOuterWalls withIW
|
||||||
closed = closeOffices withOW
|
closed = closeOffices withOW
|
||||||
in closed
|
(g3, facilities) = buildFacilities g2 fc closed
|
||||||
|
in facilities
|
||||||
|
|
||||||
emptyFloor :: FloorConfig -> Matrix TileState
|
emptyFloor :: FloorConfig -> Matrix TileState
|
||||||
emptyFloor fc =
|
emptyFloor fc =
|
||||||
|
@ -270,3 +271,43 @@ buildOuterWalls input =
|
||||||
, ncols horz
|
, ncols horz
|
||||||
]
|
]
|
||||||
in vert
|
in vert
|
||||||
|
|
||||||
|
buildFacilities
|
||||||
|
:: StdGen
|
||||||
|
-> FloorConfig
|
||||||
|
-> Matrix TileState
|
||||||
|
-> (StdGen, Matrix TileState)
|
||||||
|
buildFacilities gen fc input =
|
||||||
|
let flood ts mat coords@(cr, cc) =
|
||||||
|
let cur = mat M.! coords
|
||||||
|
altered = M.setElem ts coords mat
|
||||||
|
in
|
||||||
|
if cur == ts || cur /= Offi
|
||||||
|
then mat
|
||||||
|
else foldl (\acc cs -> flood ts acc cs)
|
||||||
|
altered
|
||||||
|
[ (cr + 1, cc)
|
||||||
|
, (cr - 1, cc)
|
||||||
|
, (cr, cc + 1)
|
||||||
|
, (cr, cc - 1)
|
||||||
|
]
|
||||||
|
nearests = map (findNearestOffice input) (facilities fc)
|
||||||
|
in (foldl (\(agen, acc) x ->
|
||||||
|
let (numfac, ngen) = randomR (0 :: Int, 1 :: Int) agen
|
||||||
|
facil = if numfac == 1 then Kitc else Toil
|
||||||
|
in (ngen, flood facil acc x)
|
||||||
|
) (gen, input) nearests)
|
||||||
|
|
||||||
|
findNearestOffice
|
||||||
|
:: Matrix TileState
|
||||||
|
-> (Int, Int)
|
||||||
|
-> (Int, Int)
|
||||||
|
findNearestOffice mat (rrr, ccc) =
|
||||||
|
let matcoord = (,) <$> [1 .. nrows mat] <*> [1 .. ncols mat]
|
||||||
|
distance (ar, ac) = (ar - rrr) ^ 2 + (ac - ccc) ^ 2
|
||||||
|
inlist = zip matcoord (M.toList mat)
|
||||||
|
in foldl (\acc@(arow, acol) x@(xc@(crow, ccol), ts) ->
|
||||||
|
if ts == Offi && distance acc > distance xc
|
||||||
|
then xc
|
||||||
|
else acc
|
||||||
|
) (fst $ head inlist) inlist
|
||||||
|
|
Loading…
Reference in a new issue