diff --git a/editors/emacs/swarm-mode.el b/editors/emacs/swarm-mode.el index af9e91aef..f08142579 100644 --- a/editors/emacs/swarm-mode.el +++ b/editors/emacs/swarm-mode.el @@ -91,6 +91,7 @@ "time" "scout" "whereami" + "locateme" "waypoint" "structure" "floorplan" diff --git a/editors/vim/swarm.vim b/editors/vim/swarm.vim index c0e87e123..9a81fdded 100644 --- a/editors/vim/swarm.vim +++ b/editors/vim/swarm.vim @@ -1,6 +1,6 @@ syn keyword Keyword def tydef rec end let in require syn keyword Builtins self parent base if inl inr case fst snd force undefined fail not format chars split charat tochar key -syn keyword Command noop wait selfdestruct move backup volume path push stride turn grab harvest sow ignite place ping give equip unequip make has equipped count drill use build salvage reprogram say listen log view appear create halt time scout whereami waypoint structure floorplan hastag tagmembers detect resonate density sniff chirp watch surveil heading blocked scan upload ishere isempty meet meetall whoami setname random run return try swap atomic instant installkeyhandler teleport as robotnamed robotnumbered knows +syn keyword Command noop wait selfdestruct move backup volume path push stride turn grab harvest sow ignite place ping give equip unequip make has equipped count drill use build salvage reprogram say listen log view appear create halt time scout whereami locateme waypoint structure floorplan hastag tagmembers detect resonate density sniff chirp watch surveil heading blocked scan upload ishere isempty meet meetall whoami setname random run return try swap atomic instant installkeyhandler teleport as robotnamed robotnumbered knows syn keyword Direction east north west south down forward left back right syn match Type "\<[A-Z][a-zA-Z_]*\>" syn match Operators "[-=!<>|&+*/^$:]" diff --git a/src/swarm-engine/Swarm/Game/Step/Const.hs b/src/swarm-engine/Swarm/Game/Step/Const.hs index 74b336f13..142d8219a 100644 --- a/src/swarm-engine/Swarm/Game/Step/Const.hs +++ b/src/swarm-engine/Swarm/Game/Step/Const.hs @@ -557,6 +557,9 @@ execConst runChildProg c vs s k = do Whereami -> do loc <- use robotLocation return $ mkReturn $ loc ^. planar + LocateMe -> do + loc <- use robotLocation + return $ mkReturn $ (loc ^. subworld, loc ^. planar) Waypoint -> case vs of [VText name, VInt idx] -> do lm <- use $ landscape . worldNavigation diff --git a/src/swarm-lang/Swarm/Language/Syntax/Constants.hs b/src/swarm-lang/Swarm/Language/Syntax/Constants.hs index d327f29a5..e9d308efa 100644 --- a/src/swarm-lang/Swarm/Language/Syntax/Constants.hs +++ b/src/swarm-lang/Swarm/Language/Syntax/Constants.hs @@ -146,6 +146,8 @@ data Const Scout | -- | Get the current x, y coordinates Whereami + | -- | Get the current subworld and x, y coordinates + LocateMe | -- | Get the x, y coordinates of a named waypoint, by index Waypoint | -- | Get the x, y coordinates of southwest corner of a constructed structure, by index @@ -678,6 +680,11 @@ constInfo c = case c of shortDoc (Set.singleton $ Query $ Sensing RobotSensing) "Get the current x and y coordinates." + LocateMe -> + command 0 Intangible $ + shortDoc + (Set.singleton $ Query $ Sensing RobotSensing) + "Get the current subworld and x, y coordinates." Waypoint -> command 2 Intangible . doc (Set.singleton $ Query APriori) "Get the x, y coordinates of a named waypoint, by index" $ [ "Return only the waypoints in the same subworld as the calling robot." diff --git a/src/swarm-lang/Swarm/Language/Typecheck.hs b/src/swarm-lang/Swarm/Language/Typecheck.hs index fe46f2f51..4ee5b5060 100644 --- a/src/swarm-lang/Swarm/Language/Typecheck.hs +++ b/src/swarm-lang/Swarm/Language/Typecheck.hs @@ -1036,6 +1036,7 @@ inferConst c = run . runReader @TVCtx Ctx.empty . quantify $ case c of Time -> [tyQ| Cmd Int |] Scout -> [tyQ| Dir -> Cmd Bool |] Whereami -> [tyQ| Cmd (Int * Int) |] + LocateMe -> [tyQ| Cmd (Text, (Int * Int)) |] Waypoint -> [tyQ| Text -> Int -> Cmd (Int * (Int * Int)) |] Structure -> [tyQ| Text -> Int -> Cmd (Unit + (Int * (Int * Int))) |] Floorplan -> [tyQ| Text -> Cmd (Int * Int) |]