Simplify doorMechanism (involves hack)
This commit is contained in:
@@ -125,6 +125,10 @@ mvPointToward !ep !p
|
|||||||
| dist p ep < 1 = ep
|
| dist p ep < 1 = ep
|
||||||
| otherwise = p +.+ normalizeV (ep -.- p)
|
| otherwise = p +.+ normalizeV (ep -.- p)
|
||||||
|
|
||||||
|
vecBetweenSpeed :: Float -> Point2 -> Point2 -> Point2
|
||||||
|
vecBetweenSpeed s sp ep
|
||||||
|
| dist sp ep < s = ep -.- sp
|
||||||
|
| otherwise = s *.* normalizeV (ep -.- sp)
|
||||||
|
|
||||||
sigmoid :: Floating a => a -> a
|
sigmoid :: Floating a => a -> a
|
||||||
sigmoid x = x/sqrt(1+x^(2::Int))
|
sigmoid x = x/sqrt(1+x^(2::Int))
|
||||||
|
|||||||
@@ -41,5 +41,5 @@ initialWorld = defaultWorld
|
|||||||
}
|
}
|
||||||
|
|
||||||
testStringInit :: World -> [String]
|
testStringInit :: World -> [String]
|
||||||
testStringInit = map show . M.toList . _mouseButtons
|
testStringInit = map (show . _drStatus) . IM.elems . _doors
|
||||||
--testStringInit = const []
|
--testStringInit = const []
|
||||||
|
|||||||
@@ -75,18 +75,20 @@ doorMechanismStepwise nsteps drid wlids pss dr w
|
|||||||
newps = uncurry (rectanglePairs 9) (pss !! n)
|
newps = uncurry (rectanglePairs 9) (pss !! n)
|
||||||
-- it is not at all clear that the zoning selects the correct walls
|
-- it is not at all clear that the zoning selects the correct walls
|
||||||
|
|
||||||
doorMechanism :: [(Int,(Point2,Point2),(Point2,Point2))] -> Door -> World -> World
|
-- TODO sort out why DoorClosed status does not update correctly 22/06/23
|
||||||
doorMechanism wlidOpCps dr w
|
doorMechanism :: Door -> World -> World
|
||||||
| toOpen && dstatus /= DoorOpen = moveUpdate $ foldl' doOpen w wlidOpCps
|
doorMechanism dr w = case mvDir of
|
||||||
& doors . ix drid . drPos %~ mvPs speed (_drOpenPos dr)
|
Just d -> w
|
||||||
| not toOpen && dstatus /= DoorClosed = moveUpdate $ foldl' doClose w wlidOpCps
|
& flip (IS.foldr (`translateWallID` d)) (_drWallIDs dr)
|
||||||
& doors . ix drid . drPos %~ mvPs speed (_drClosePos dr)
|
& moveUpdate
|
||||||
| otherwise = w
|
& doors . ix drid . drPos . each %~ (+.+ d)
|
||||||
|
Nothing -> w
|
||||||
where
|
where
|
||||||
toOpen = _drTrigger dr w
|
toOpen = _drTrigger dr w
|
||||||
mvDir
|
mvDir
|
||||||
| toOpen && dist dpos dop > 1 = Just $ mvPointTowardAtSpeed speed dop dpos
|
| toOpen && _drStatus dr == DoorOpen = Nothing -- Not sure why necessary
|
||||||
| dist dpos dcp > 1 = Just $ mvPointTowardAtSpeed speed dcp dpos
|
| toOpen && dist dpos dop > 0.5 = Just $ vecBetweenSpeed speed dpos dop
|
||||||
|
| dist dpos dcp > 0.5 = Just $ vecBetweenSpeed speed dpos dcp
|
||||||
| otherwise = Nothing
|
| otherwise = Nothing
|
||||||
speed = _drSpeed dr
|
speed = _drSpeed dr
|
||||||
drid = _drID dr
|
drid = _drID dr
|
||||||
@@ -99,9 +101,6 @@ doorMechanism wlidOpCps dr w
|
|||||||
| dist dpos dop < 1 = doors . ix drid . drStatus .~ DoorOpen
|
| dist dpos dop < 1 = doors . ix drid . drStatus .~ DoorOpen
|
||||||
| dist dpos dcp < 1 = doors . ix drid . drStatus .~ DoorClosed
|
| dist dpos dcp < 1 = doors . ix drid . drStatus .~ DoorClosed
|
||||||
| otherwise = doors . ix drid . drStatus .~ DoorHalfway
|
| otherwise = doors . ix drid . drStatus .~ DoorHalfway
|
||||||
dstatus = _drStatus dr
|
|
||||||
doOpen w' (wlid,opp, _) = moveWallIDToward wlid speed opp w'
|
|
||||||
doClose w' (wlid,_ ,clp) = moveWallIDToward wlid speed clp w'
|
|
||||||
|
|
||||||
-- TODO cut pathing if not pathable, reset when opened
|
-- TODO cut pathing if not pathable, reset when opened
|
||||||
plSlideDoor
|
plSlideDoor
|
||||||
@@ -123,7 +122,7 @@ plSlideDoor isPathable col cond shiftOffset a b speed gw
|
|||||||
, _drWallIDs = IS.fromList wlids
|
, _drWallIDs = IS.fromList wlids
|
||||||
, _drStatus = DoorClosed
|
, _drStatus = DoorClosed
|
||||||
, _drTrigger = cond
|
, _drTrigger = cond
|
||||||
, _drMech = doorMechanism (zip3 wlids shiftedPairs pairs)
|
, _drMech = doorMechanism
|
||||||
, _drPos = (a,b)
|
, _drPos = (a,b)
|
||||||
, _drOpenPos = (shiftLeft a,shiftLeft b)
|
, _drOpenPos = (shiftLeft a,shiftLeft b)
|
||||||
, _drClosePos = (a,b)
|
, _drClosePos = (a,b)
|
||||||
@@ -131,7 +130,6 @@ plSlideDoor isPathable col cond shiftOffset a b speed gw
|
|||||||
}
|
}
|
||||||
addDoorWalls w' = foldl' (addDoorWall drid col isPathable) w' $ zip wlids pairs
|
addDoorWalls w' = foldl' (addDoorWall drid col isPathable) w' $ zip wlids pairs
|
||||||
pairs = rectanglePairs 9 a b
|
pairs = rectanglePairs 9 a b
|
||||||
shiftedPairs = map (bimap shiftLeft shiftLeft) pairs
|
|
||||||
shiftLeft = (+.+ (a -.- b +.+ shiftOffset *.* normalizeV (b -.- a)))
|
shiftLeft = (+.+ (a -.- b +.+ shiftOffset *.* normalizeV (b -.- a)))
|
||||||
wlids = take 4 [IM.newKey $ _walls gw ..]
|
wlids = take 4 [IM.newKey $ _walls gw ..]
|
||||||
-- old code that may help with pathing
|
-- old code that may help with pathing
|
||||||
|
|||||||
Reference in New Issue
Block a user