Skip to content

Commit

Permalink
Achievement for pointless swapping (#1588)
Browse files Browse the repository at this point in the history
# Demo

    scripts/play.sh -i creative --seed 0

Then:

    turn right; move; turn right; move; t <- grab; move; swap t;

![image](https://github.com/swarm-game/swarm/assets/261693/eb2fb7bf-26e7-43c3-8b0b-2c92f35f9244)
  • Loading branch information
kostmo authored Oct 23, 2023
1 parent 4f21fd8 commit d3889ef
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
1 change: 1 addition & 0 deletions src/Swarm/Game/Achievement/Definitions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ data GameplayAchievement
| DestroyedBase
| LoseScenario
| GetDisoriented
| SwapSame
deriving (Eq, Ord, Show, Bounded, Enum, Generic)

instance FromJSON GameplayAchievement
Expand Down
7 changes: 7 additions & 0 deletions src/Swarm/Game/Achievement/Description.hs
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,10 @@ describe = \case
"`turn down` without a compass. Congratulations, you are \"disoriented\". How are you supposed to move now?"
Easy
True
GameplayAchievement SwapSame ->
AchievementInfo
"Fair Trade"
(Just $ Freeform "The *Law of Equivalent Exchange*... taken literally.")
"`swap` an item for itself."
Easy
True
31 changes: 18 additions & 13 deletions src/Swarm/Game/Step.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1159,8 +1159,8 @@ execConst c vs s k = do

return $ Out VUnit s k
_ -> badConst
Grab -> doGrab Grab'
Harvest -> doGrab Harvest'
Grab -> mkReturn <$> doGrab Grab'
Harvest -> mkReturn <$> doGrab Harvest'
Ignite -> case vs of
[VDir d] -> do
Combustion.igniteCommand c d
Expand All @@ -1172,14 +1172,16 @@ execConst c vs s k = do
-- Make sure the robot has the thing in its inventory
e <- hasInInventoryOrFail name
-- Grab
r <- doGrab Swap'
case r of
Out {} -> do
-- Place the entity and remove it from the inventory
updateEntityAt loc (const (Just e))
robotInventory %= delete e
_ -> pure ()
return r
newE <- doGrab Swap'

-- Place the entity and remove it from the inventory
updateEntityAt loc (const (Just e))
robotInventory %= delete e

when (e == newE) $
grantAchievement SwapSame

return $ mkReturn newE
_ -> badConst
Turn -> case vs of
[VDir d] -> do
Expand Down Expand Up @@ -2510,9 +2512,12 @@ execConst c vs s k = do
`holdsOrFail` ["You don't have", indefinite eName, "to", cmd <> "."]
return e

mkReturn :: Valuable a => a -> CESK
mkReturn x = Out (asValue x) s k

-- The code for grab and harvest is almost identical, hence factored
-- out here.
doGrab :: (HasRobotStepState sig m, Has (Lift IO) sig m) => GrabbingCmd -> m CESK
doGrab :: (HasRobotStepState sig m, Has (Lift IO) sig m) => GrabbingCmd -> m Entity
doGrab cmd = do
let verb = verbGrabbingCmd cmd
verbed = verbedGrabbingCmd cmd
Expand Down Expand Up @@ -2556,8 +2561,8 @@ execConst c vs s k = do
robotInventory %= insert e'
updateDiscoveredEntities e'

-- Return the name of the item obtained.
return $ Out (VText (e' ^. entityName)) s k
-- Return the item obtained.
return e'

------------------------------------------------------------
-- The "watch" command
Expand Down

0 comments on commit d3889ef

Please sign in to comment.