Start work on pathfinding

This commit is contained in:
2025-10-13 06:30:55 +01:00
parent 9e7b7a3f76
commit 6b5090e697
7 changed files with 265 additions and 287 deletions
-3
View File
@@ -142,7 +142,6 @@ holdForm ycr crs cr = p
cpos = cr ^. crPos . _xy cpos = cr ^. crPos . _xy
ps = map (^. crPos . _xy) $ IM.elems crs ps = map (^. crPos . _xy) $ IM.elems crs
cen = centroid ps cen = centroid ps
--cen = (1 / fromIntegral (length ps)) *.* foldr1 (+.+) ps
p p
| dist cen ypos < 20 = ypos | dist cen ypos < 20 = ypos
| otherwise = ypos +.+ cpos -.- cen | otherwise = ypos +.+ cpos -.- cen
@@ -153,7 +152,6 @@ lineUp ycr crs cr = p
ypos = ycr ^. crPos . _xy ypos = ycr ^. crPos . _xy
cpos = cr ^. crPos . _xy cpos = cr ^. crPos . _xy
ps = map (^. crPos . _xy) $ IM.elems crs ps = map (^. crPos . _xy) $ IM.elems crs
--cen = (1 / fromIntegral (length ps)) *.* foldr1 (+.+) ps
cen = centroid ps cen = centroid ps
p = (0.05 *.* ypos) +.+ (0.95 *.* errorClosestPointOnLine 500 cen ypos cpos) p = (0.05 *.* ypos) +.+ (0.95 *.* errorClosestPointOnLine 500 cen ypos cpos)
@@ -165,7 +163,6 @@ spreadOut ycr crs cr = p
cpos = cr ^. crPos . _xy cpos = cr ^. crPos . _xy
ps = map (^. crPos . _xy) $ IM.elems crs ps = map (^. crPos . _xy) $ IM.elems crs
cen = centroid ps cen = centroid ps
-- cen = (1 / fromIntegral (length ps)) *.* foldr1 (+.+) ps
p p
| dist cen ypos < 30 = ypos | dist cen ypos < 30 = ypos
| otherwise = ypos +.+ (spreadFactor *.* cpos -.- cen) | otherwise = ypos +.+ (spreadFactor *.* cpos -.- cen)
+4 -4
View File
@@ -43,11 +43,11 @@ updateCreature' cr =
chasmTest cr . case _crType cr of chasmTest cr . case _crType cr of
Avatar{} -> Avatar{} ->
(cWorld . lWorld . creatures . ix 0 . crType . avatarPulse %~ updatePulse) (cWorld . lWorld . creatures . ix 0 . crType . avatarPulse %~ updatePulse)
. crUpdate' yourControl cr . crUpdate yourControl cr
LampCrit{} -> updateLampoid cr LampCrit{} -> updateLampoid cr
BarrelCrit bt -> updateBarreloid bt cr BarrelCrit bt -> updateBarreloid bt cr
AvatarDead -> id AvatarDead -> id
_ -> crUpdate' updateHumanoid cr _ -> crUpdate updateHumanoid cr
{- | this seems to work, but I am not sure about the ordering: {- | this seems to work, but I am not sure about the ordering:
previously, the movement was updated before the ai in order to correctly set the oldpos. previously, the movement was updated before the ai in order to correctly set the oldpos.
@@ -56,8 +56,8 @@ updateCreature' cr =
at what point invSideEffects is applied wrt to when the creature moves at what point invSideEffects is applied wrt to when the creature moves
may affect whether the shield moves correctly may affect whether the shield moves correctly
-} -}
crUpdate' :: (Creature -> World -> World) -> Creature -> World -> World crUpdate :: (Creature -> World -> World) -> Creature -> World -> World
crUpdate' f cr = crUpdate f cr =
checkDeath cid checkDeath cid
. doDamage cid . doDamage cid
. invItemEffs cid . invItemEffs cid
+2 -2
View File
@@ -200,8 +200,8 @@ drawCreatureDisplayTexts w = foldMap (creatureDisplayText w) (w ^. cWorld . lWor
drawPathBetween :: World -> Picture drawPathBetween :: World -> Picture
drawPathBetween w = concat $ do drawPathBetween w = concat $ do
sp <- w ^. input . clickPos . at ButtonLeft sp <- w ^. input . heldWorldPos . at ButtonLeft
ep <- w ^. input . clickPos . at ButtonRight ep <- w ^. input . heldWorldPos . at ButtonRight
let nodepos = (`getNodePos` w) let nodepos = (`getNodePos` w)
nodelist = makePathBetween sp ep w nodelist = makePathBetween sp ep w
return . setLayer DebugLayer $ return . setLayer DebugLayer $
+2 -2
View File
@@ -52,7 +52,6 @@ walkableNodeNear w p = fmap fst . find (flip (isWalkable p) w . snd) $ nodesNear
nodesNear = zonesExtract (w ^. pnZoning) $ zonesAroundPoint pnZoneSize p nodesNear = zonesExtract (w ^. pnZoning) $ zonesAroundPoint pnZoneSize p
makePathBetweenPs :: Point2 -> Point2 -> World -> Maybe [Point2] makePathBetweenPs :: Point2 -> Point2 -> World -> Maybe [Point2]
--makePathBetweenPs a b w = mapMaybe (lab $ _pathGraph (_cWorld w)) <$> makePathBetween a b w
makePathBetweenPs a b w = mapMaybe (lab $ w ^. cWorld . pathGraph) <$> makePathBetween a b w makePathBetweenPs a b w = mapMaybe (lab $ w ^. cWorld . pathGraph) <$> makePathBetween a b w
bfsNodePoints :: Int -> World -> [Point2] bfsNodePoints :: Int -> World -> [Point2]
@@ -61,7 +60,8 @@ bfsNodePoints n w = mapMaybe (lab g) $ bfs n g
g = w ^. cWorld . pathGraph g = w ^. cWorld . pathGraph
pointTowardsImpulse :: Point2 -> Point2 -> World -> Maybe Point2 pointTowardsImpulse :: Point2 -> Point2 -> World -> Maybe Point2
pointTowardsImpulse a b w = (find (flip (isWalkable a) w) . reverse) =<< makePathBetweenPs a b w pointTowardsImpulse a b w = (find (flip (isWalkable a) w) . reverse) =<<
(makePathBetweenPs a b w <&> (<>[b]))
------ continues a walk from a list of points, without repetitions ------ continues a walk from a list of points, without repetitions
------ supposes that the list is non-empty ------ supposes that the list is non-empty
+3 -3
View File
@@ -399,9 +399,9 @@ critsRoom :: Int -> State LayoutVars (Tree Room)
critsRoom i = critsRoom i =
join $ join $
takeOne takeOne
[ return <$> roomCCrits i -- [ return <$> roomCCrits i
, return <$> critsPillarRoom i -- , return <$> critsPillarRoom i
, return <$> glassSwitchBackCrits i [ return <$> glassSwitchBackCrits i
] ]
-- cor <- shuffleLinks corridor -- cor <- shuffleLinks corridor
+1 -1
View File
@@ -230,7 +230,7 @@ removeLights = rmPmnts %~ mapMaybe f
tutHub :: State LayoutVars (MetaTree Room String) tutHub :: State LayoutVars (MetaTree Room String)
tutHub = do tutHub = do
(is, wbp) <- setTreeInts =<< critsRoom 2 (is, wbp) <- setTreeInts =<< critsRoom 1
i <- nextLayoutInt i <- nextLayoutInt
j <- nextLayoutInt j <- nextLayoutInt
k <- nextLayoutInt k <- nextLayoutInt
+253 -272
View File
File diff suppressed because it is too large Load Diff