Readd wall corner collisions
This commit is contained in:
@@ -36,7 +36,7 @@ import Control.Lens
|
||||
--import Control.Monad
|
||||
--import Control.Applicative
|
||||
import Data.Maybe
|
||||
--import Data.List
|
||||
import Data.List (findIndex)
|
||||
import System.Random
|
||||
import Control.Monad.Reader
|
||||
--import qualified Data.Map as M
|
||||
@@ -203,11 +203,21 @@ setMinInvSize n cr = creatures . ix (_crID cr) . crInv %~ f
|
||||
f inv = IM.unionWith const inv $ IM.fromList $ [0..n-1] <&> (, NoItem)
|
||||
|
||||
stripNoItems :: Creature -> World -> World
|
||||
stripNoItems cr = creatures . ix (_crID cr) . crInv %~ IM.mapMaybe f
|
||||
stripNoItems cr = organiseInvKeys (_crID cr) .
|
||||
( creatures . ix (_crID cr) . crInv %~ IM.mapMaybe f )
|
||||
where
|
||||
f NoItem = Nothing
|
||||
f x = Just x
|
||||
|
||||
organiseInvKeys :: Int -> World -> World
|
||||
organiseInvKeys cid w = w & creatures . ix cid %~
|
||||
( ( crInvSel .~ newSelKey ) . (crInv .~ newInv ) )
|
||||
where
|
||||
cr = _creatures w IM.! cid
|
||||
pairs = IM.toList (_crInv cr)
|
||||
newSelKey = fromJust $ findIndex ( (== _crInvSel cr) . fst) pairs
|
||||
newInv = IM.fromAscList $ zip [0..] $ map snd pairs
|
||||
|
||||
dropUnselected :: Creature -> World -> World
|
||||
dropUnselected cr w = foldr (dropItem cr) w . IM.keys
|
||||
$ _crInvSel cr `IM.delete` _crInv cr
|
||||
|
||||
Reference in New Issue
Block a user