Skip to content

Commit

Permalink
Achievement for disorientation (#1173)
Browse files Browse the repository at this point in the history
  • Loading branch information
kostmo committed Mar 24, 2023
1 parent 51b4bcd commit 7d7f291
Show file tree
Hide file tree
Showing 3 changed files with 33 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 @@ -82,6 +82,7 @@ data GameplayAchievement
| AttemptSelfDestructBase
| DestroyedBase
| LoseScenario
| GetDisoriented
deriving (Eq, Ord, Show, Bounded, Enum, Generic)

instance FromJSON GameplayAchievement
Expand Down
12 changes: 12 additions & 0 deletions src/Swarm/Game/Achievement/Description.hs
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,15 @@ describe (GameplayAchievement LoseScenario) =
"Lose at a scenario."
Easy
True
describe (GameplayAchievement GetDisoriented) =
AchievementInfo
"Playing Ostrich"
( Just $
FTQuotation $
Quotation
"Lil Jon"
"Fire up that loud / Another round of shots / Turn down for what?"
)
"'turn down' without a compass. Congratulations, you are 'disoriented'. How are you supposed to move now?"
Easy
True
33 changes: 20 additions & 13 deletions src/Swarm/Game/Step.hs
Original file line number Diff line number Diff line change
Expand Up @@ -293,12 +293,7 @@ hypotheticalWinCheck em g ws oc = do

case newWinState of
Unwinnable _ -> do
currentTime <- sendIO getZonedTime
gameAchievements
%= M.insertWith
(<>)
LoseScenario
(Attainment (GameplayAchievement LoseScenario) Nothing currentTime)
grantAchievement LoseScenario
_ -> return ()

announcementQueue %= (>< Seq.fromList (map ObjectiveCompleted $ completionAnnouncementQueue finalAccumulator))
Expand Down Expand Up @@ -842,13 +837,7 @@ stepCESK cesk = case cesk of
-- handled.
case exn of
CmdFailed _ _ (Just a) -> do
currentTime <- sendIO getZonedTime
scenarioPath <- use currentScenarioPath
gameAchievements
%= M.insertWith
(<>)
a
(Attainment (GameplayAchievement a) scenarioPath currentTime)
grantAchievement a
_ -> return ()

-- If an exception rises all the way to the top level without being
Expand Down Expand Up @@ -1045,6 +1034,11 @@ execConst c vs s k = do
when (isCardinal d) $ hasCapabilityFor COrient (TDir d)
robotOrientation . _Just %= applyTurn d
flagRedraw

inst <- use equippedDevices
when (d == DRelative DDown && countByName "compass" inst == 0) $ do
grantAchievement GetDisoriented

return $ Out VUnit s k
_ -> badConst
Place -> case vs of
Expand Down Expand Up @@ -2148,6 +2142,19 @@ execConst c vs s k = do
-- Some utility functions
------------------------------------------------------------

grantAchievement ::
(Has (State GameState) sig m, Has (Lift IO) sig m) =>
GameplayAchievement ->
m ()
grantAchievement a = do
currentTime <- sendIO getZonedTime
scenarioPath <- use currentScenarioPath
gameAchievements
%= M.insertWith
(<>)
a
(Attainment (GameplayAchievement a) scenarioPath currentTime)

-- | How to handle failure, for example when moving to blocked location
data RobotFailure = ThrowExn | Destroy | IgnoreFail

Expand Down

0 comments on commit 7d7f291

Please sign in to comment.