2018-04-14 09:18:37 +00:00
|
|
|
module NPC where
|
|
|
|
|
|
|
|
import Affection as A
|
|
|
|
|
|
|
|
import qualified Data.Matrix as M
|
|
|
|
import Data.Ecstasy as E
|
|
|
|
|
|
|
|
import Linear
|
|
|
|
|
|
|
|
import System.Random
|
|
|
|
|
|
|
|
import NanoVG hiding (V2(..))
|
|
|
|
|
|
|
|
-- internal imports
|
|
|
|
|
2018-04-14 11:34:28 +00:00
|
|
|
import Navigation
|
|
|
|
import Util
|
|
|
|
|
2018-04-14 09:18:37 +00:00
|
|
|
import Types.UserData
|
2018-04-14 11:34:28 +00:00
|
|
|
import Types.Interior
|
|
|
|
import Types.Map
|
2018-04-14 09:18:37 +00:00
|
|
|
|
|
|
|
drawNPCs
|
|
|
|
:: Context
|
|
|
|
-> [V2 Double]
|
|
|
|
-> Double
|
|
|
|
-> Double
|
|
|
|
-> Int
|
|
|
|
-> Int
|
|
|
|
-> Affection UserData ()
|
|
|
|
drawNPCs ctx npcposs prow pcol row col = do
|
|
|
|
ud <- getAffection
|
|
|
|
let fnpcposs = filter
|
|
|
|
(\(V2 nr nc) -> floor nr == row && floor nc == col)
|
|
|
|
npcposs
|
|
|
|
liftIO $ mapM_
|
|
|
|
(\(V2 nr nc) -> do
|
|
|
|
let x = realToFrac $ 640 + ((nc - pcol) + (nr - prow)) * 32
|
|
|
|
y = realToFrac $ 360 + ((nr - prow) - (nc - pcol)) * 16
|
|
|
|
beginPath ctx
|
|
|
|
circle ctx x y 5
|
|
|
|
closePath ctx
|
|
|
|
fillColor ctx (rgba 255 0 0 255)
|
|
|
|
fill ctx
|
|
|
|
)
|
|
|
|
fnpcposs
|
|
|
|
|
2018-04-14 11:34:28 +00:00
|
|
|
placeNPCs
|
|
|
|
:: M.Matrix (Maybe ImgId)
|
|
|
|
-> [ReachPoint]
|
|
|
|
-> [Graph]
|
|
|
|
-> Int
|
|
|
|
-> Affection UserData [V2 Double]
|
|
|
|
placeNPCs imgmat rp gr count =
|
2018-04-14 09:18:37 +00:00
|
|
|
doPlace 1 []
|
|
|
|
where
|
|
|
|
doPlace :: Int -> [V2 Double] -> Affection UserData [V2 Double]
|
|
|
|
doPlace nr acc = do
|
|
|
|
if nr <= count
|
|
|
|
then do
|
|
|
|
r <- liftIO $ randomRIO (1, M.nrows imgmat)
|
|
|
|
c <- liftIO $ randomRIO (1, M.ncols imgmat)
|
2018-04-14 11:34:28 +00:00
|
|
|
if null (imgObstacle $ imgmat M.! (r, c)) &&
|
|
|
|
isReachable imgmat [V2 r c] (exits r c)
|
2018-04-14 09:18:37 +00:00
|
|
|
then doPlace (nr + 1) ((V2 (fromIntegral r) (fromIntegral c)) : acc)
|
|
|
|
else doPlace nr acc
|
|
|
|
else
|
|
|
|
return acc
|
2018-04-14 11:34:28 +00:00
|
|
|
applRooms row col =
|
|
|
|
filter (\r -> graphIsRoom r && inBounds (V2 row col) (bounds r)) gr
|
|
|
|
exits row col= concatMap (\b ->
|
|
|
|
filter (\p -> pointType p == RoomExit && inBounds (pointCoord p) b) rp
|
|
|
|
) (map bounds (applRooms row col))
|