gameServer/EngineInteraction.hs
branchqmlfrontend
changeset 10817 48a53259fad8
parent 10779 d85fe0cb5df2
child 10983 6aba07ea908b
equal deleted inserted replaced
10757:f71275973737 10817:48a53259fad8
   102         , [eml ["eseed ", mParams Map.! "SEED"]]
   102         , [eml ["eseed ", mParams Map.! "SEED"]]
   103         , [eml ["e$gmflags ", showB gameFlags]]
   103         , [eml ["e$gmflags ", showB gameFlags]]
   104         , schemeFlags
   104         , schemeFlags
   105         , schemeAdditional
   105         , schemeAdditional
   106         , [eml ["e$template_filter ", mParams Map.! "TEMPLATE"]]
   106         , [eml ["e$template_filter ", mParams Map.! "TEMPLATE"]]
       
   107         , [eml ["e$feature_size ", mParams Map.! "FEATURE_SIZE"]]
   107         , [eml ["e$mapgen ", mapgen]]
   108         , [eml ["e$mapgen ", mapgen]]
   108         , mapgenSpecific
   109         , mapgenSpecific
   109         , concatMap teamSetup ti
   110         , concatMap teamSetup ti
   110         , msgs
   111         , msgs
   111         , [em "!"]
   112         , [em "!"]
   112         ]
   113         ]
   113     where
   114     where
   114         keys1, keys2 :: Set.Set B.ByteString
   115         keys1, keys2 :: Set.Set B.ByteString
   115         keys1 = Set.fromList ["MAP", "MAPGEN", "MAZE_SIZE", "SEED", "TEMPLATE"]
   116         keys1 = Set.fromList ["FEATURE_SIZE", "MAP", "MAPGEN", "MAZE_SIZE", "SEED", "TEMPLATE"]
   116         keys2 = Set.fromList ["AMMO", "SCHEME", "SCRIPT", "THEME"]
   117         keys2 = Set.fromList ["AMMO", "SCHEME", "SCRIPT", "THEME"]
   117         sane = Set.null (keys1 Set.\\ Map.keysSet mParams)
   118         sane = Set.null (keys1 Set.\\ Map.keysSet mParams)
   118             && Set.null (keys2 Set.\\ Map.keysSet prms)
   119             && Set.null (keys2 Set.\\ Map.keysSet prms)
   119             && (not . null . drop 40 $ scheme)
   120             && (not . null . drop 41 $ scheme)
   120             && (not . null . tail $ prms Map.! "AMMO")
   121             && (not . null . tail $ prms Map.! "AMMO")
   121         mapGenTypes = ["+rnd+", "+maze+", "+drawn+"]
   122         mapGenTypes = ["+rnd+", "+maze+", "+drawn+", "+perlin+"]
   122         maybeScript = let s = head . fromMaybe ["Normal"] $ Map.lookup "SCRIPT" prms in if s == "Normal" then [] else [eml ["escript Scripts/Multiplayer/", s, ".lua"]]
   123         maybeScript = let s = head . fromMaybe ["Normal"] $ Map.lookup "SCRIPT" prms in if s == "Normal" then [] else [eml ["escript Scripts/Multiplayer/", s, ".lua"]]
   123         maybeMap = let m = mParams Map.! "MAP" in if m `elem` mapGenTypes then [] else [eml ["emap ", m]]
   124         maybeMap = let m = mParams Map.! "MAP" in if m `elem` mapGenTypes then [] else [eml ["emap ", m]]
   124         scheme = tail $ prms Map.! "SCHEME"
   125         scheme = tail $ prms Map.! "SCHEME"
   125         mapgen = mParams Map.! "MAPGEN"
   126         mapgen = mParams Map.! "MAPGEN"
       
   127         templateFilterMsg = eml ["e$maze_size ", mParams Map.! "MAZE_SIZE"]
   126         mapgenSpecific = case mapgen of
   128         mapgenSpecific = case mapgen of
   127             "1" -> [eml ["e$maze_size ", mParams Map.! "MAZE_SIZE"]]
   129             "3" -> let d = head . fromMaybe [""] $ Map.lookup "DRAWNMAP" prms in if BW.length d <= 4 then [] else drawnMapData d
   128             "2" -> let d = head . fromMaybe [""] $ Map.lookup "DRAWNMAP" prms in if BW.length d <= 4 then [] else drawnMapData d
   130             _ -> [templateFilterMsg]
   129             _ -> []
       
   130         gameFlags :: Word32
   131         gameFlags :: Word32
   131         gameFlags = foldl (\r (b, f) -> if b == "false" then r else r .|. f) 0 $ zip scheme gameFlagConsts
   132         gameFlags = foldl (\r (b, f) -> if b == "false" then r else r .|. f) 0 $ zip scheme gameFlagConsts
   132         schemeFlags = map (\(v, (n, m)) -> eml [n, " ", showB $ (readInt_ v) * m])
   133         schemeFlags = map (\(v, (n, m)) -> eml [n, " ", showB $ (readInt_ v) * m])
   133             $ filter (\(_, (n, _)) -> not $ B.null n)
   134             $ filter (\(_, (n, _)) -> not $ B.null n)
   134             $ zip (drop (length gameFlagConsts) scheme) schemeParams
   135             $ zip (drop (length gameFlagConsts) scheme) schemeParams