Clean up Sudden Death messages and animations in Battalion
- Remove SD warning (redundant with engine)
- Play poison moan sounds
- Hide damage tag if no damage
{-# LANGUAGE OverloadedStrings #-}module Main whereimport Control.Monadimport Data.Maybeimport qualified Data.Yaml as YAMLimport Data.Yaml ((.=))import Data.Listimport qualified Data.ByteString.Char8 as Bimport qualified Data.Text as Textimport PascalUnitSyntaxTreefixName :: String -> StringfixName "MaxHedgeHogs" = "max_hedgehogs"fixName"canFlip" = "can_flip"fixName"canInvert" = "can_invert"fixName"canMirror" = "can_mirror"fixName"TemplateWidth" = "width"fixName"TemplateHeight" = "height"fixName"RandPassesCount" = "rand_passes"fixName"BezierizeCount" = "bezie_passes"fixName"hasGirders" = "put_girders"fixName"isNegative" = "is_negative"fixName a = ainstance YAML.ToJSON InitExpression where toJSON (InitArray ar) = YAML.toJSON ar toJSON (InitRecord ar) = YAML.object $ map (\(Identifier i _, iref) -> Text.pack (fixName i) .= iref) $ filter isRelevant ar where isRelevant (Identifier i _, _) | i `elem` ["BasePoints", "FillPoints", "BasePointsCount", "FillPointsCount"] = False isRelevant _ = True toJSON (InitTypeCast {}) = YAML.object [] toJSON (BuiltInFunction {}) = YAML.object [] toJSON (InitNumber n) = YAML.toJSON (read n :: Int) toJSON (InitReference (Identifier "true" _)) = YAML.toJSON True toJSON (InitReference (Identifier "false" _)) = YAML.toJSON False toJSON a = error $ show ainstance YAML.ToJSON Identifier where toJSON (Identifier i _) = YAML.toJSON idata Template = Template InitExpression ([InitExpression], InitExpression) deriving Showinstance YAML.ToJSON Template where toJSON (Template (InitRecord ri) (points, fpoints)) = YAML.toJSON $ InitRecord $ ri ++ [(Identifier "outline_points" BTUnknown, InitArray points), (Identifier "fill_points" BTUnknown, fpoints)]takeLast i = reverse . take i . reverseextractDeclarations :: PascalUnit -> [TypeVarDeclaration]extractDeclarations (Unit (Identifier "uLandTemplates" _) (Interface _ (TypesAndVars decls)) _ _ _) = declsextractDeclarations _ = error "Unexpected file structure"extractTemplatePoints :: Int -> [TypeVarDeclaration] -> ([InitExpression], InitExpression)extractTemplatePoints templateNumber decls = (breakNTPX . head . catMaybes $ map (toTemplatePointInit "Points") decls, head . catMaybes $ map (toTemplatePointInit "FPoints") decls) where toTemplatePointInit suffix (VarDeclaration False False ([Identifier i _], _) ie) | (i == "Template" ++ show templateNumber ++ suffix) = ie | otherwise = Nothing toTemplatePointInit _ _ = Nothing breakNTPX :: InitExpression -> [InitExpression] breakNTPX (InitArray ia) = map InitArray . filter ((<) 0 . length) . map (filter (not . isNtpx)) $ groupBy (\a b -> isNtpx a == isNtpx b) ia breakNTPX a = error $ show a isNtpx :: InitExpression -> Bool isNtpx (InitRecord ((Identifier "x" _, InitReference (Identifier "NTPX" _)):_)) = True isNtpx _ = FalseextractTemplates :: [TypeVarDeclaration] -> [Template]extractTemplates decls = map toFull $ zip (head . catMaybes $ map toTemplateInit decls) [0..] where toTemplateInit (VarDeclaration False False ([Identifier "EdgeTemplates" _], _) (Just (InitArray ia))) = Just ia toTemplateInit _ = Nothing toFull (ie, num) = let ps = extractTemplatePoints num decls in if "NTPX" `isInfixOf` show ps then error $ show num ++ " " ++ show ps else Template ie psconvert :: PascalUnit -> B.ByteStringconvert pu = YAML.encode . extractTemplates . extractDeclarations $ pumain = do f <- liftM read $ readFile "uLandTemplates.dump" B.putStrLn $ convert f