Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Achievement for pointless swapping #1588

Merged
merged 2 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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