Fix laser targeting draw when creature offscreen

This commit is contained in:
2022-03-06 22:58:05 +00:00
parent f82bd3f788
commit 1364e7c8c8
14 changed files with 108 additions and 138 deletions
-34
View File
@@ -14,7 +14,6 @@ module Dodge.Room.Link
, randomiseAllLinks
, shuffleLinks
, filterLinks
, changeLinkTo
, randomiseOutLinks
, chooseOneInLink
, restrictRMInLinksPD
@@ -78,43 +77,10 @@ shuffleLinks r = do
newLinks <- shuffle $ _rmLinks r
return $ r {_rmLinks = newLinks }
--randomiseLinksBy
-- :: ( [(Point2,Float)] -> State g [(Point2,Float)] )
-- -> Room
-- -> State g Room
--randomiseLinksBy f r = do
-- newLinks <- f $ _rmOutLinks r ++ _rmInLinks r
-- return $ r {_rmOutLinks = init newLinks
-- , _rmInLinks = [last newLinks]
-- }
filterLinks :: RandomGen g => ((Point2,Float) -> Bool) -> Room -> State g Room
filterLinks cond r = do
newLinks <- shuffle $ filter (cond . lnkPosDir) $ _rmLinks r
return $ r {_rmLinks = newLinks}
{- | Swaps the last link in the list with one that satisfies a given
- property (it might swap with itself). Unsafe.
- Be careful about calling this after changeLinkFrom. -}
-- TODO replace with something more sensible
changeLinkTo :: RandomGen g => ((Point2,Float) -> Bool) -> Room -> State g Room
changeLinkTo cond r = do
let alllinks = _rmLinks r
l <- takeOne $ filter (cond . lnkPosDir) alllinks
let l' = l & rlType .~ S.singleton InLink
let newLinks = delete l alllinks
return $ r & rmLinks .~ (l':newLinks)
{- | Move a room so that the first link in '_rmInLinks' lines up to
an external point and direction.
This is intended to work when the external point is an outgoing link from another room.
-}
--shiftRoomToLink :: (Point2,Float) -> Room -> Room
--shiftRoomToLink l r
-- = shiftRoomBy l
-- . shiftRoomBy (V2 0 0 , pi-a)
-- $ shiftRoomBy (V2 0 0 -.- p , 0)
-- r
-- where
-- (p,a) = lnkPosDir $ head $ _rmInLinks r
doRoomShift :: Room -> Room
doRoomShift rm = shiftRoomBy (_rmShift rm) rm & rmShift .~ _rmShift rm