Skip to content

Commit

Permalink
return southwest instead of northwest corner as structure location
Browse files Browse the repository at this point in the history
  • Loading branch information
kostmo committed Nov 13, 2023
1 parent 9415554 commit 58b6731
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 7 additions & 2 deletions src/Swarm/Game/Step.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1410,9 +1410,14 @@ execConst c vs s k = do
[VText name, VInt idx] -> do
registry <- use $ discovery . structureRecognition . foundStructures
let maybeFoundStructures = M.lookup (StructureName name) $ foundByName registry
mkOutput mapNE = (NE.length xs, indexWrapNonEmpty xs idx ^. planar)
mkOutput mapNE = (NE.length xs, bottomLeftCorner)
where
xs = NEM.keys mapNE
xs = NEM.toList mapNE
(pos, struc) = indexWrapNonEmpty xs idx
topLeftCorner = pos ^. planar
offsetHeight = V2 0 $ -fromIntegral (length (entityGrid struc) - 1)
bottomLeftCorner :: Location
bottomLeftCorner = topLeftCorner .+^ offsetHeight
return $ mkReturn $ mkOutput <$> maybeFoundStructures
_ -> badConst
Floorplan -> case vs of
Expand Down
4 changes: 2 additions & 2 deletions src/Swarm/Language/Syntax.hs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ data Const
Whereami
| -- | Get the x, y coordinates of a named waypoint, by index
Waypoint
| -- | Get the x, y coordinates of a constructed structure, by index
| -- | Get the x, y coordinates of southwest corner of a constructed structure, by index
Structure
| -- | Get the width and height of a structure template
Floorplan
Expand Down Expand Up @@ -648,7 +648,7 @@ constInfo c = case c of
, "A robot can use the count to know whether they have iterated over the full waypoint circuit."
]
Structure ->
command 2 Intangible . doc "Get the x, y coordinates of a constructed structure, by name and index" $
command 2 Intangible . doc "Get the x, y coordinates of the southwest corner of a constructed structure, by name and index" $
[ "The outermost type of the return value indicates whether any structure of such name exists."
, "Since structures can have multiple occurrences, returns a tuple of (count, (x, y))."
, "The supplied index will be wrapped automatically, modulo the structure count."
Expand Down

0 comments on commit 58b6731

Please sign in to comment.