Generalise pathing, usable with flying creatures

This commit is contained in:
2026-04-02 19:30:44 +01:00
parent c2de804fa9
commit ff903bfb3b
19 changed files with 322 additions and 215 deletions
+9 -2
View File
@@ -33,6 +33,7 @@ import qualified IntMapHelp as IM
import LensHelp
import Linear
import NewInt
import qualified Data.Set as S
-- it is desirable to be able to determine when an action is finished,
-- so that DoActionThen and the like are easy to define
@@ -113,11 +114,17 @@ performAimAt cr w tcid p = ([TurnToward tpos aimSp], [AimAt tcid tpos])
| canSee' = w ^?! cWorld . lWorld . creatures . ix tcid . crPos . _xy
| otherwise = p
crPathing :: Creature -> (Point2 -> Point2 -> World -> Bool,S.Set EdgeObstacle -> Bool)
crPathing cr = case cr ^. crStance . carriage of
Flying {} -> (isFlyable, not . S.member (WallObstacle WallNotAutoOpen))
_ -> (isWalkable, not . pathEdgeObstructed)
performPathTo :: Creature -> World -> Point2 -> ActionUpdate
performPathTo cr w p
| dist cpos p <= crRad (cr ^. crType) = mempty
| isWalkable cpos p w = gotowards p
| otherwise = case pointTowardsImpulse cpos p w of
-- | isWalkable cpos p w = gotowards p
| fst (crPathing cr) cpos p w = gotowards p
| otherwise = case uncurry pointTowardsImpulse' (crPathing cr) cpos p w of
Just q -> gotowards q
_ -> ([ChangeStrategy Flee], [])
where