it runs again, but correctness is questionable
This commit is contained in:
parent
8b5a9e6006
commit
23483de264
4 changed files with 74 additions and 32 deletions
|
@ -1,9 +1,12 @@
|
||||||
module Floorplan where
|
module Floorplan where
|
||||||
|
|
||||||
|
import Affection as A
|
||||||
|
|
||||||
import Data.Matrix (Matrix(..))
|
import Data.Matrix (Matrix(..))
|
||||||
import qualified Data.Matrix as M
|
import qualified Data.Matrix as M
|
||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
import Data.Maybe
|
import Data.Maybe
|
||||||
|
import Data.List (intersect)
|
||||||
|
|
||||||
import Linear (V2(..))
|
import Linear (V2(..))
|
||||||
|
|
||||||
|
@ -69,12 +72,14 @@ buildHallFloorIO fc progress increment = do
|
||||||
( p + increment
|
( p + increment
|
||||||
, "Built facilities"
|
, "Built facilities"
|
||||||
)))
|
)))
|
||||||
-- accessGraph <- assignClearance doorgraph facils
|
accessGraph <- assignClearance doorgraph facils
|
||||||
modifyMVar_ progress (return . (\(p, _) ->
|
modifyMVar_ progress (return . (\(p, _) ->
|
||||||
( p + increment
|
( p + increment
|
||||||
, "Assigned room clearances"
|
, "Assigned room clearances"
|
||||||
)))
|
)))
|
||||||
return (facils, doorgraph)
|
A.logIO A.Debug ("length accessGraph: " ++ show (length accessGraph))
|
||||||
|
A.logIO A.Debug ("length doorgraph: " ++ show (length doorgraph))
|
||||||
|
return (facils, accessGraph)
|
||||||
|
|
||||||
emptyFloor :: FloorConfig -> Matrix TileState
|
emptyFloor :: FloorConfig -> Matrix TileState
|
||||||
emptyFloor fc =
|
emptyFloor fc =
|
||||||
|
@ -415,21 +420,42 @@ buildDoorsGraph mat =
|
||||||
|
|
||||||
assignClearance :: [Graph] -> M.Matrix TileState -> IO [Graph]
|
assignClearance :: [Graph] -> M.Matrix TileState -> IO [Graph]
|
||||||
assignClearance graph imat =
|
assignClearance graph imat =
|
||||||
mapM doAssignClearance graph
|
foldM doAssignClearance [] graph
|
||||||
where
|
where
|
||||||
doAssignClearance (GHall conns) =
|
doAssignClearance acc (GHall conns) = do
|
||||||
GHall <$> mapM (reassign True) conns
|
ret <- GHall <$> foldM (\acc a -> do
|
||||||
doAssignClearance room =
|
res <- reassign True acc a
|
||||||
reassign False room
|
return (acc ++ [res])
|
||||||
reassign p room@(GRoom ns b c t) =
|
) [] conns
|
||||||
|
return (ret : acc)
|
||||||
|
doAssignClearance acc room = do
|
||||||
|
ret <- reassign False acc room
|
||||||
|
return (acc ++ [ret])
|
||||||
|
reassign :: Bool -> [Graph] -> Graph -> IO Graph
|
||||||
|
reassign p acc room@(GRoom ns b c t) =
|
||||||
if p
|
if p
|
||||||
then do
|
then do
|
||||||
if actualRoomType b imat == Offi
|
if actualRoomType b imat == Offi
|
||||||
then doRandomAssign room
|
then do
|
||||||
|
ret <- doRandomAssign room
|
||||||
|
return ret
|
||||||
else return room
|
else return room
|
||||||
else do
|
else do
|
||||||
let neigh = findNeighbor (head ns) b imat graph
|
if actualRoomType b imat == Offi
|
||||||
|
then do
|
||||||
|
let neigh =
|
||||||
|
catMaybes
|
||||||
|
(map
|
||||||
|
(\n -> findNeighbor n b imat onlyrooms)
|
||||||
|
nonhalls
|
||||||
|
)
|
||||||
|
onlyrooms = connects (head acc) ++ tail acc
|
||||||
|
nonhalls = ns -- filter ((/= Hall) . snd) ns
|
||||||
|
ret <- if null neigh
|
||||||
|
then doRandomAssign room
|
||||||
|
else doBoundedAssign room (clearance $ head neigh)
|
||||||
|
return ret
|
||||||
|
else return room
|
||||||
|
|
||||||
actualRoomType :: Boundaries Int -> M.Matrix TileState -> TileState
|
actualRoomType :: Boundaries Int -> M.Matrix TileState -> TileState
|
||||||
actualRoomType (Boundaries (minrow, mincol) (maxrow, maxcol)) imat =
|
actualRoomType (Boundaries (minrow, mincol) (maxrow, maxcol)) imat =
|
||||||
|
@ -441,7 +467,7 @@ doRandomAssign :: Graph -> IO Graph
|
||||||
doRandomAssign g = do
|
doRandomAssign g = do
|
||||||
c <- randomRIO (0, 4)
|
c <- randomRIO (0, 4)
|
||||||
return g
|
return g
|
||||||
{ clearance = if actualRoomType c
|
{ clearance = c
|
||||||
}
|
}
|
||||||
|
|
||||||
doBoundedAssign :: Graph -> Word -> IO Graph
|
doBoundedAssign :: Graph -> Word -> IO Graph
|
||||||
|
@ -454,30 +480,35 @@ doBoundedAssign g b = do
|
||||||
findNeighbor :: (GraphDirection, TileState) -> Boundaries Int -> M.Matrix TileState -> [Graph] -> Maybe Graph
|
findNeighbor :: (GraphDirection, TileState) -> Boundaries Int -> M.Matrix TileState -> [Graph] -> Maybe Graph
|
||||||
findNeighbor (dir, _) bnds imat ingraph
|
findNeighbor (dir, _) bnds imat ingraph
|
||||||
| dir == North =
|
| dir == North =
|
||||||
let row = fst (matmin bnds) - 2
|
let row = fst (matmin bnds) - 1
|
||||||
col = snd (matmin bnds) + (snd (matmax bnds) - snd (matmin bnds) `div` 2)
|
col = snd (matmin bnds) + ((snd (matmax bnds) - snd (matmin bnds)) `div` 2)
|
||||||
in postprocess row col
|
in postprocess row col
|
||||||
| dir == East =
|
| dir == East =
|
||||||
let row = fst (matmin bnds) + (fst (matmax bnds) - fst (matmin bnds) `div` 2)
|
let row = fst (matmin bnds) + ((fst (matmax bnds) - fst (matmin bnds)) `div` 2)
|
||||||
col = snd (matmin bnds) - 2
|
col = snd (matmax bnds) + 1
|
||||||
in postprocess row col
|
in postprocess row col
|
||||||
| dir == South =
|
| dir == South =
|
||||||
let row = fst (matmax bnds) + 2
|
let row = fst (matmax bnds) + 1
|
||||||
col = snd (matmin bnds) + (snd (matmax bnds) - snd (matmin bnds) `div` 2)
|
col = snd (matmin bnds) + ((snd (matmax bnds) - snd (matmin bnds)) `div` 2)
|
||||||
in postprocess row col
|
in postprocess row col
|
||||||
| dir == West =
|
| dir == West =
|
||||||
let row = fst (matmin bnds) + (fst (matmax bnds) - fst (matmin bnds) `div` 2)
|
let row = fst (matmin bnds) + ((fst (matmax bnds) - fst (matmin bnds)) `div` 2)
|
||||||
col = snd (matmax bnds) + 2
|
col = snd (matmin bnds) - 1
|
||||||
in postprocess row col
|
in postprocess row col
|
||||||
where
|
where
|
||||||
neighTile row col = imat M.! (row, col)
|
neighTile row col = imat M.! (row, col)
|
||||||
postprocess row col =
|
postprocess row col =
|
||||||
case filter (inBounds (V2 row col) . bounds) (filter graphIsRoom ingraph) of
|
let filtered = filter
|
||||||
[a@(GRoom _ _ _ ts)] -> if ts == neighTile row col
|
(inBounds (V2 row col) . bounds)
|
||||||
then Just a
|
ingraph
|
||||||
else error "findNeighbor: Query Result dies not match"
|
in
|
||||||
[] -> Nothing
|
case A.log A.Debug ("filtered: " ++ show filtered) filtered of
|
||||||
_ -> error "findNeighbor: Non-singleton filter result"
|
[a@(GRoom _ _ _ ts)] -> Just a
|
||||||
|
-- if ts == neighTile row col
|
||||||
|
-- then Just a
|
||||||
|
-- else error "findNeighbor: Query Result does not match"
|
||||||
|
[] -> Nothing
|
||||||
|
_ -> error "findNeighbor: Non-singleton filter result"
|
||||||
|
|
||||||
buildDoors :: Matrix TileState -> [Graph] -> IO (Matrix TileState)
|
buildDoors :: Matrix TileState -> [Graph] -> IO (Matrix TileState)
|
||||||
buildDoors = foldM placeDoors
|
buildDoors = foldM placeDoors
|
||||||
|
|
|
@ -221,7 +221,7 @@ loadMapFork ud ad future progress = do
|
||||||
( p + increment
|
( p + increment
|
||||||
, "Registering NPCs into WorldState"
|
, "Registering NPCs into WorldState"
|
||||||
)))
|
)))
|
||||||
mapM_ (\crp -> do
|
mapM_ (\cpr -> do
|
||||||
fact <- liftIO $ randomRIO (0.5, 1.5)
|
fact <- liftIO $ randomRIO (0.5, 1.5)
|
||||||
-- fut <- liftIO newEmptyMVar
|
-- fut <- liftIO newEmptyMVar
|
||||||
stats <- liftIO $ NPCStats
|
stats <- liftIO $ NPCStats
|
||||||
|
@ -231,15 +231,21 @@ loadMapFork ud ad future progress = do
|
||||||
<*> (randomRIO (0, 1))
|
<*> (randomRIO (0, 1))
|
||||||
<*> (randomRIO (0, 1))
|
<*> (randomRIO (0, 1))
|
||||||
<*> (randomRIO (0, 1))
|
<*> (randomRIO (0, 1))
|
||||||
|
let room = head
|
||||||
|
(Prelude.filter
|
||||||
|
((inBounds $ pointCoord cpr) . bounds)
|
||||||
|
(Types.connects (head gr) ++ tail gr)
|
||||||
|
)
|
||||||
void $ createEntity $ newEntity
|
void $ createEntity $ newEntity
|
||||||
{ pos = Just (fmap ((+ 0.5) . fromIntegral) (pointCoord crp))
|
{ pos = Just (fmap ((+ 0.5) . fromIntegral) (pointCoord cpr))
|
||||||
, vel = Just (V2 0 0)
|
, vel = Just (V2 0 0)
|
||||||
, velFact = Just fact
|
, velFact = Just fact
|
||||||
, rot = Just SE
|
, rot = Just SE
|
||||||
, npcMoveState = Just (NPCWalking [pointCoord crp])
|
, npcMoveState = Just (NPCWalking [pointCoord cpr])
|
||||||
, npcWorkplace = Just crp
|
, npcWorkplace = Just cpr
|
||||||
, npcActionState = Just ASWork
|
, npcActionState = Just ASWork
|
||||||
, npcStats = Just stats
|
, npcStats = Just stats
|
||||||
|
, npcClearanceLvl = Just (clearance room)
|
||||||
, anim = Just $ AnimState (AnimId "jdoem" "standing" SE) 0 0
|
, anim = Just $ AnimState (AnimId "jdoem" "standing" SE) 0 0
|
||||||
}
|
}
|
||||||
) computers
|
) computers
|
||||||
|
|
|
@ -26,7 +26,7 @@ data Entity f = Entity
|
||||||
, npcWorkplace :: Component f 'Field ReachPoint
|
, npcWorkplace :: Component f 'Field ReachPoint
|
||||||
, npcActionState :: Component f 'Field NPCActionState
|
, npcActionState :: Component f 'Field NPCActionState
|
||||||
, npcStats :: Component f 'Field NPCStats
|
, npcStats :: Component f 'Field NPCStats
|
||||||
, npcClearanceLvl :: Component f 'Field Int
|
, npcClearanceLvl :: Component f 'Field Word
|
||||||
, anim :: Component f 'Field AnimState
|
, anim :: Component f 'Field AnimState
|
||||||
, objAccess :: Component f 'Field ((V2 Int), Direction)
|
, objAccess :: Component f 'Field ((V2 Int), Direction)
|
||||||
, objType :: Component f 'Field ObjType
|
, objType :: Component f 'Field ObjType
|
||||||
|
|
|
@ -58,7 +58,12 @@ data Graph
|
||||||
, clearance :: Word
|
, clearance :: Word
|
||||||
, roomType :: TileState
|
, roomType :: TileState
|
||||||
}
|
}
|
||||||
deriving (Show, Eq)
|
deriving (Show)
|
||||||
|
|
||||||
|
instance Eq Graph where
|
||||||
|
(GHall la) == (GHall lb) = la == lb
|
||||||
|
(GRoom na ba _ _) == (GRoom nb bb _ _) = na == nb && ba == bb
|
||||||
|
_ == _ = False
|
||||||
|
|
||||||
graphIsRoom :: Graph -> Bool
|
graphIsRoom :: Graph -> Bool
|
||||||
graphIsRoom (GRoom _ _ _ _) = True
|
graphIsRoom (GRoom _ _ _ _) = True
|
||||||
|
|
Loading…
Reference in a new issue