- Handle mapgen-specific parameters
authorunc0rr
Fri, 08 Feb 2013 00:27:07 +0400
changeset 8481 692ff6468b63
parent 8480 42d2565b5700
child 8482 5656a73fe3c3
- Handle mapgen-specific parameters - Convert ammo set into engine messages
gameServer/EngineInteraction.hs
--- a/gameServer/EngineInteraction.hs	Thu Feb 07 00:07:32 2013 +0400
+++ b/gameServer/EngineInteraction.hs	Fri Feb 08 00:27:07 2013 +0400
@@ -10,6 +10,7 @@
 import qualified Data.Map as Map
 import Data.Word
 import Data.Bits
+import Control.Arrow
 -------------
 import CoreTypes
 import Utils
@@ -51,7 +52,9 @@
         , [eml ["e$gmflags ", showB gameFlags]]
         , schemeFlags
         , [eml ["e$template_filter ", mapParams Map.! "TEMPLATE"]]
-        , [eml ["e$mapgen ", mapParams Map.! "MAPGEN"]]
+        , [eml ["e$mapgen ", mapgen]]
+        , mapgenSpecific
+        , concatMap teamSetup teams
         , msgs
         ]
     where
@@ -61,12 +64,25 @@
         maybeScript = let s = head $ params Map.! "SCRIPT" in if s == "Normal" then [] else [eml ["escript Scripts/Multiplayer/", s, ".lua"]]
         maybeMap = let m = mapParams Map.! "MAP" in if m `elem` mapGenTypes then [] else [eml ["emap ", m]]
         scheme = tail $ params Map.! "SCHEME"
+        mapgen = mapParams Map.! "MAPGEN"
+        mapgenSpecific = case mapgen of
+            "+maze+" -> [eml ["e$maze_size ", head $ params Map.! "MAZE_SIZE"]]
+            "+drawn" -> drawnMapData . head $ params Map.! "DRAWNMAP"
+            _ -> []
         gameFlags :: Word32
         gameFlags = foldl (\r (b, f) -> if b == "false" then r else r .|. f) 0 $ zip scheme gameFlagConsts
         schemeFlags = map (\(v, (n, m)) -> eml [n, " ", showB $ (readInt_ v) * m])
             $ filter (\(_, (n, _)) -> not $ B.null n)
             $ zip (drop (length gameFlagConsts) scheme) schemeParams
+        ammoStr :: B.ByteString
+        ammoStr = head . tail $ params Map.! "AMMO"
+        ammo = let l = B.length ammoStr `div` 4; ((a, b), (c, d)) = (B.splitAt l . fst &&& B.splitAt l . snd) . B.splitAt (l * 2) $ ammoStr in
+                   map (\(x, y) -> eml [x, " ", y]) $ zip ["eammloadt", "eammprob", "eammdelay", "eammreinf"] [a, b, c, d]
+        teamSetup :: TeamInfo -> [B.ByteString]
+        teamSetup _ = ammo
 
+drawnMapData :: B.ByteString -> [B.ByteString]
+drawnMapData = undefined
 
 schemeParams :: [(B.ByteString, Int)]
 schemeParams = [