Skip to content

Commit

Permalink
Very basic/hacky support for religious modifiers
Browse files Browse the repository at this point in the history
Should fix HairyDude#22
  • Loading branch information
mras0 committed Apr 7, 2021
1 parent 4e7a1ea commit af37a9e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/EU4/Handlers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1198,11 +1198,18 @@ addModifier kind stmt@(Statement _ OpEq (CompoundRhs scr)) =
meffect = modEffects <$> mthemod
mpp_meffect <- scope EU4Bonus $ maybeM ppMany meffect

-- Is this a religious modifer?
mpp_meffect' <- case (mpp_meffect, modReligious <$> mthemod) of
(Just pp_meffect, Just True) -> do
relMsg <- withCurrentIndent $ \i -> return (i + 1, MsgReligiousModifier)
return $ Just $ pp_meffect ++ [relMsg]
_ -> do return mpp_meffect

case mname_or_key of
Just modid ->
-- default presented name to mod id
let name_loc = fromMaybe modid mname_or_key_loc
in case (mwho, amod_power amod, mdur, mpp_meffect) of
in case (mwho, amod_power amod, mdur, mpp_meffect') of
-- Event modifiers - expect effects
(Nothing, Nothing, Nothing, Just pp_effect) -> do
msghead <- alsoIndent' (MsgGainMod modid tkind name_loc)
Expand Down
10 changes: 9 additions & 1 deletion src/EU4/Modifiers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,19 @@ parseEU4Modifier :: (IsGameData (GameData g), IsGameState (GameState g), MonadEr
parseEU4Modifier [pdx| $modid = @effects |]
= withCurrentFile $ \file -> do
mlocid <- getGameL10nIfPresent modid

-- Handle religions modifiers
-- FIXME: This is a pretty terrible way of doing it...
let oldLength = length effects
rest = flip filter effects $ \stmt -> case stmt of
[pdx| religion = yes |] -> False
_ -> True
return . Right . Just $ EU4Modifier {
modName = modid
, modLocName = mlocid
, modPath = file
, modEffects = effects
, modReligious = length rest /= oldLength
, modEffects = rest
}
parseEU4Modifier _ = withCurrentFile $ \file ->
throwError ("unrecognised form for modifier in " <> T.pack file)
Expand Down
1 change: 1 addition & 0 deletions src/EU4/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ data EU4Modifier = EU4Modifier
{ modName :: Text
, modLocName :: Maybe Text
, modPath :: FilePath
, modReligious :: Bool
, modEffects :: GenericScript
} deriving (Show)
data EU4OpinionModifier = EU4OpinionModifier
Expand Down
3 changes: 3 additions & 0 deletions src/Messages.hs
Original file line number Diff line number Diff line change
Expand Up @@ -992,6 +992,7 @@ data ScriptMessage
| MsgRegionProvinceScope
| MsgSetRevolutionProvince { scriptMessageYn :: Bool }
| MsgGovernmentHasAttribute { scriptMessageWhat :: Text }
| MsgReligiousModifier

-- | Whether to default to English localization.
useEnglish :: [Text] -> Bool
Expand Down Expand Up @@ -6520,6 +6521,8 @@ instance RenderMessage Script ScriptMessage where
[ "Has government type where: "
, _what
]
MsgReligiousModifier
-> "These effects are lost if the state religion changes"

renderMessage _ _ _ = error "Sorry, non-English localisation not yet supported."

Expand Down

0 comments on commit af37a9e

Please sign in to comment.