Fix for my last commit (which was all nonsense)
authorunc0rr
Tue, 15 Feb 2011 21:12:22 +0300
changeset 4941 90572c338e60
parent 4940 e247addb947c
child 4942 1c85a8e6e11c
Fix for my last commit (which was all nonsense)
QTfrontend/gamecfgwidget.cpp
QTfrontend/mapContainer.cpp
QTfrontend/mapContainer.h
gameServer/CoreTypes.hs
gameServer/HWProtoInRoomState.hs
gameServer/HWProtoLobbyState.hs
--- a/QTfrontend/gamecfgwidget.cpp	Mon Feb 14 08:31:45 2011 -0500
+++ b/QTfrontend/gamecfgwidget.cpp	Tue Feb 15 21:12:22 2011 +0300
@@ -139,7 +139,7 @@
     connect(pMapContainer, SIGNAL(seedChanged(const QString &)), this, SLOT(seedChanged(const QString &)));
     connect(pMapContainer, SIGNAL(mapChanged(const QString &)), this, SLOT(mapChanged(const QString &)));
     connect(pMapContainer, SIGNAL(mapgenChanged(MapGenerator)), this, SLOT(mapgenChanged(MapGenerator)));
-    connect(pMapContainer, SIGNAL(maze_sizeChanged(int)), this, SLOT(maze_sizeChanged(int)));
+    connect(pMapContainer, SIGNAL(mazeSizeChanged(int)), this, SLOT(maze_sizeChanged(int)));
     connect(pMapContainer, SIGNAL(themeChanged(const QString &)), this, SLOT(themeChanged(const QString &)));
     connect(pMapContainer, SIGNAL(newTemplateFilter(int)), this, SLOT(templateFilterChanged(int)));
     connect(pMapContainer, SIGNAL(drawMapRequested()), this, SIGNAL(goToDrawMap()));
@@ -246,7 +246,7 @@
     switch (mapgen)
     {
         case MAPGEN_MAZE:
-            bcfg << QString("e$maze_size %1").arg(pMapContainer->get_maze_size()).toUtf8();
+            bcfg << QString("e$maze_size %1").arg(pMapContainer->getMazeSize()).toUtf8();
             break;
 
         case MAPGEN_DRAWN:
@@ -315,7 +315,7 @@
     scriptChanged(Scripts->currentIndex());
 
     mapgenChanged(pMapContainer->get_mapgen());
-    maze_sizeChanged(pMapContainer->get_maze_size());
+    maze_sizeChanged(pMapContainer->getMazeSize());
 
     // map must be the last
     QString map = pMapContainer->getCurrentMap();
@@ -352,7 +352,7 @@
             return;
         }
         if (param == "MAZE_SIZE") {
-            pMapContainer->setMaze_size(value.toUInt());
+            pMapContainer->setMazeSize(value.toUInt());
             return;
         }
         if (param == "SCRIPT") {
@@ -373,15 +373,21 @@
         }
     }
 
-    if (slValue.size() == 3)
+    if (slValue.size() == 5)
     {
-        if (param == "FULLGENCFG")
+        if (param == "FULLMAPCONFIG")
         {
-            QString seed = slValue[2];
+            QString seed = slValue[3];
             if (!seedRegexp.exactMatch(seed))
                 pMapContainer->seedEdit->setVisible(true);
 
-            pMapContainer->setMapMapgenSeed(slValue[0], (MapGenerator)slValue[1].toUInt(), seed);
+            pMapContainer->setAllMapParameters(
+                    slValue[0],
+                    (MapGenerator)slValue[1].toUInt(),
+                    slValue[2].toUInt(),
+                    seed,
+                    slValue[4].toUInt()
+                    );
             return;
         }
     }
--- a/QTfrontend/mapContainer.cpp	Mon Feb 14 08:31:45 2011 -0500
+++ b/QTfrontend/mapContainer.cpp	Tue Feb 15 21:12:22 2011 +0300
@@ -140,7 +140,7 @@
     }
     chooseMap->insertSeparator(missionindex); // separator between missions and maps
 
-    connect(chooseMap, SIGNAL(currentIndexChanged(int)), this, SLOT(mapChanged(int)));
+    connect(chooseMap, SIGNAL(activated(int)), this, SLOT(mapChanged(int)));
     mapLayout->addWidget(chooseMap, 1, 1);
 
     QLabel * lblMap = new QLabel(tr("Map"), mapWidget);
@@ -149,32 +149,32 @@
     lblFilter = new QLabel(tr("Filter"), mapWidget);
     mapLayout->addWidget(lblFilter, 2, 0);
 
-    CB_TemplateFilter = new QComboBox(mapWidget);
-    CB_TemplateFilter->addItem(tr("All"), 0);
-    CB_TemplateFilter->addItem(tr("Small"), 1);
-    CB_TemplateFilter->addItem(tr("Medium"), 2);
-    CB_TemplateFilter->addItem(tr("Large"), 3);
-    CB_TemplateFilter->addItem(tr("Cavern"), 4);
-    CB_TemplateFilter->addItem(tr("Wacky"), 5);
-    mapLayout->addWidget(CB_TemplateFilter, 2, 1);
+    cbTemplateFilter = new QComboBox(mapWidget);
+    cbTemplateFilter->addItem(tr("All"), 0);
+    cbTemplateFilter->addItem(tr("Small"), 1);
+    cbTemplateFilter->addItem(tr("Medium"), 2);
+    cbTemplateFilter->addItem(tr("Large"), 3);
+    cbTemplateFilter->addItem(tr("Cavern"), 4);
+    cbTemplateFilter->addItem(tr("Wacky"), 5);
+    mapLayout->addWidget(cbTemplateFilter, 2, 1);
 
-    connect(CB_TemplateFilter, SIGNAL(currentIndexChanged(int)), this, SLOT(templateFilterChanged(int)));
+    connect(cbTemplateFilter, SIGNAL(activated(int)), this, SLOT(setTemplateFilter(int)));
 
     maze_size_label = new QLabel(tr("Type"), mapWidget);
     mainLayout.addWidget(maze_size_label, 2, 0);
     maze_size_label->hide();
-    maze_size_selection = new QComboBox(mapWidget);
-    maze_size_selection->addItem(tr("Small tunnels"), 0);
-    maze_size_selection->addItem(tr("Medium tunnels"), 1);
-    maze_size_selection->addItem(tr("Large tunnels"), 2);
-    maze_size_selection->addItem(tr("Small floating islands"), 3);
-    maze_size_selection->addItem(tr("Medium floating islands"), 4);
-    maze_size_selection->addItem(tr("Large floating islands"), 5);
-    maze_size_selection->setCurrentIndex(1);
+    cbMazeSize = new QComboBox(mapWidget);
+    cbMazeSize->addItem(tr("Small tunnels"), 0);
+    cbMazeSize->addItem(tr("Medium tunnels"), 1);
+    cbMazeSize->addItem(tr("Large tunnels"), 2);
+    cbMazeSize->addItem(tr("Small floating islands"), 3);
+    cbMazeSize->addItem(tr("Medium floating islands"), 4);
+    cbMazeSize->addItem(tr("Large floating islands"), 5);
+    cbMazeSize->setCurrentIndex(1);
 
-    mapLayout->addWidget(maze_size_selection, 2, 1);
-    maze_size_selection->hide();
-    connect(maze_size_selection, SIGNAL(currentIndexChanged(int)), this, SLOT(setMaze_size(int)));
+    mapLayout->addWidget(cbMazeSize, 2, 1);
+    cbMazeSize->hide();
+    connect(cbMazeSize, SIGNAL(activated(int)), this, SLOT(setMazeSize(int)));
 
     gbThemes = new IconedGroupBox(mapWidget);
     gbThemes->setTitleTextPadding(80);
@@ -278,9 +278,9 @@
         updatePreview();
         gbThemes->show();
         lblFilter->show();
-        CB_TemplateFilter->show();
+        cbTemplateFilter->show();
         maze_size_label->hide();
-        maze_size_selection->hide();
+        cbMazeSize->hide();
         emit mapChanged("+rnd+");
         emit mapgenChanged(mapgen);
         emit themeChanged(chooseMap->itemData(index).toList()[1].toString());
@@ -290,9 +290,9 @@
         updatePreview();
         gbThemes->show();
         lblFilter->hide();
-        CB_TemplateFilter->hide();
+        cbTemplateFilter->hide();
         maze_size_label->show();
-        maze_size_selection->show();
+        cbMazeSize->show();
         emit mapChanged("+maze+");
         emit mapgenChanged(mapgen);
         emit themeChanged(chooseMap->itemData(index).toList()[1].toString());
@@ -302,9 +302,9 @@
         updatePreview();
         gbThemes->show();
         lblFilter->hide();
-        CB_TemplateFilter->hide();
+        cbTemplateFilter->hide();
         maze_size_label->hide();
-        maze_size_selection->hide();
+        cbMazeSize->hide();
         emit mapChanged("+drawn+");
         emit mapgenChanged(mapgen);
         emit themeChanged(chooseMap->itemData(index).toList()[1].toString());
@@ -313,9 +313,9 @@
         updatePreview();
         gbThemes->hide();
         lblFilter->hide();
-        CB_TemplateFilter->hide();
+        cbTemplateFilter->hide();
         maze_size_label->hide();
-        maze_size_selection->hide();
+        cbMazeSize->hide();
         emit mapChanged(chooseMap->itemData(index).toList()[0].toString());
     }
 }
@@ -355,7 +355,7 @@
     pMap->getImage(m_seed,
                    getTemplateFilter(),
                    get_mapgen(),
-                   get_maze_size(),
+                   getMazeSize(),
                    getDrawnMapData()
             );
 }
@@ -416,7 +416,7 @@
 
 quint32 HWMapContainer::getTemplateFilter() const
 {
-    return CB_TemplateFilter->itemData(CB_TemplateFilter->currentIndex()).toInt();
+    return cbTemplateFilter->itemData(cbTemplateFilter->currentIndex()).toInt();
 }
 
 void HWMapContainer::resizeEvent ( QResizeEvent * event )
@@ -525,14 +525,15 @@
     lwThemes->setCurrentRow(themeNum);
 }
 
+void HWMapContainer::intSetTemplateFilter(int filter)
+{
+    cbTemplateFilter->setCurrentIndex(filter);
+    emit newTemplateFilter(filter);
+}
+
 void HWMapContainer::setTemplateFilter(int filter)
 {
-    CB_TemplateFilter->setCurrentIndex(filter);
-}
-
-void HWMapContainer::templateFilterChanged(int filter)
-{
-    emit newTemplateFilter(filter);
+    intSetTemplateFilter(filter);
     updatePreview();
 }
 
@@ -541,15 +542,20 @@
     return mapgen;
 }
 
-int HWMapContainer::get_maze_size(void) const
+int HWMapContainer::getMazeSize(void) const
 {
-    return maze_size_selection->currentIndex();
+    return cbMazeSize->currentIndex();
 }
 
-void HWMapContainer::setMaze_size(int size)
+void HWMapContainer::intSetMazeSize(int size)
 {
-    maze_size_selection->setCurrentIndex(size);
-    emit maze_sizeChanged(size);
+    cbMazeSize->setCurrentIndex(size);
+    emit mazeSizeChanged(size);
+}
+
+void HWMapContainer::setMazeSize(int size)
+{
+    intSetMazeSize(size);
     updatePreview();
 }
 
@@ -610,6 +616,7 @@
 
 void HWMapContainer::updatePreview()
 {
+    qDebug("updating a preview");
     int curIndex = chooseMap->currentIndex();
 
     switch(curIndex)
@@ -636,11 +643,13 @@
     }
 }
 
-void HWMapContainer::setMapMapgenSeed(const QString & map, MapGenerator m, const QString & seed)
+void HWMapContainer::setAllMapParameters(const QString &map, MapGenerator m, int mazesize, const QString &seed, int tmpl)
 {
-    setMap(map);
-    setMapgen(m);
-    setSeed(seed);
+    intSetMap(map);
+    intSetMapgen(m);
+    intSetMazeSize(mazesize);
+    intSetSeed(seed);
+    intSetTemplateFilter(tmpl);
 
     updatePreview();
 }
--- a/QTfrontend/mapContainer.h	Mon Feb 14 08:31:45 2011 -0500
+++ b/QTfrontend/mapContainer.h	Tue Feb 15 21:12:22 2011 +0300
@@ -51,7 +51,7 @@
   QString getCurrentWeapons() const;
   quint32 getTemplateFilter() const;
   MapGenerator get_mapgen(void) const;
-  int get_maze_size(void) const;
+  int getMazeSize(void) const;
   bool getCurrentIsMission() const;
   QByteArray getDrawnMapData();
   DrawMapScene * getDrawMapScene();
@@ -65,9 +65,9 @@
   void setTheme(const QString & theme);
   void setTemplateFilter(int);
   void setMapgen(MapGenerator m);
-  void setMaze_size(int size);
+  void setMazeSize(int size);
   void setDrawnMapData(const QByteArray & ar);
-  void setMapMapgenSeed(const QString & map, MapGenerator m, const QString & seed);
+  void setAllMapParameters(const QString & map, MapGenerator m, int mazesize, const QString & seed, int tmpl);
 
  signals:
   void seedChanged(const QString & seed);
@@ -75,7 +75,7 @@
   void themeChanged(const QString & theme);
   void newTemplateFilter(int filter);
   void mapgenChanged(MapGenerator m);
-  void maze_sizeChanged(int s);
+  void mazeSizeChanged(int s);
   void drawMapRequested();
   void drawnMapChanged(const QByteArray & data);
 
@@ -90,7 +90,6 @@
   void setRandomMission();
   void themeSelected(int currentRow);
   void addInfoToPreview(QPixmap image);
-  void templateFilterChanged(int filter);
   void seedEdited();
 
  protected:
@@ -110,9 +109,9 @@
   int templateFilter;
   QPixmap hhSmall;
   QLabel* lblFilter;
-  QComboBox* CB_TemplateFilter;
+  QComboBox* cbTemplateFilter;
   QLabel *maze_size_label;
-  QComboBox *maze_size_selection;
+  QComboBox *cbMazeSize;
   MapGenerator mapgen;
   int numMissions;
   DrawMapScene drawMapScene;
@@ -120,6 +119,8 @@
   void intSetSeed(const QString & seed);
   void intSetMap(const QString & map);
   void intSetMapgen(MapGenerator m);
+  void intSetTemplateFilter(int);
+  void intSetMazeSize(int size);
   void updatePreview();
 };
 
--- a/gameServer/CoreTypes.hs	Mon Feb 14 08:31:45 2011 -0500
+++ b/gameServer/CoreTypes.hs	Tue Feb 15 21:12:22 2011 +0300
@@ -83,6 +83,7 @@
         roundMsgs :: Seq B.ByteString,
         leftTeams :: [B.ByteString],
         teamsAtStart :: [TeamInfo],
+        mapParams :: Map.Map B.ByteString B.ByteString,
         params :: Map.Map B.ByteString [B.ByteString]
     }
 
@@ -107,7 +108,12 @@
         Data.Sequence.empty
         []
         []
-        (Map.singleton "MAP" ["+rnd+"])
+        (
+            Map.fromList $ Prelude.zipWith (,)
+                ["MAP", "MAPGEN", "MAZE_SIZE", "SEED", "TEMPLATE"]
+                ["+rnd+", "0", "0", "seed", "0"]
+        )
+        (Map.singleton "SCHEME" ["Default"])
 
 data StatisticsInfo =
     StatisticsInfo
--- a/gameServer/HWProtoInRoomState.hs	Mon Feb 14 08:31:45 2011 -0500
+++ b/gameServer/HWProtoInRoomState.hs	Tue Feb 15 21:12:22 2011 +0300
@@ -33,10 +33,15 @@
         cl <- thisClient
         if isMaster cl then
            return [
-                ModifyRoom (\r -> r{params = Map.insert paramName paramStrs (params r)}),
+                ModifyRoom f,
                 AnswerClients chans ("CFG" : paramName : paramStrs)]
             else
             return [ProtocolError "Not room master"]
+    where
+        f r = if paramName `Map.member` (mapParams r) then
+                r{mapParams = Map.insert paramName (head paramStrs) (mapParams r)}
+                else
+                r{params = Map.insert paramName paramStrs (params r)}
 
 handleCmd_inRoom ("ADD_TEAM" : tName : color : grave : fort : voicepack : flag : difStr : hhsInfo)
     | length hhsInfo /= 16 = return [ProtocolError "Corrupted hedgehogs info"]
--- a/gameServer/HWProtoLobbyState.hs	Mon Feb 14 08:31:45 2011 -0500
+++ b/gameServer/HWProtoLobbyState.hs	Tue Feb 15 21:12:22 2011 +0300
@@ -40,12 +40,9 @@
                 showB $ playersIn r,
                 showB $ length $ teams r,
                 nick $ irnc `client` masterID r,
-                head (Map.findWithDefault ["+gen+"] "MAP" (params r)),
+                head (Map.findWithDefault ["+rnd+"] "MAP" (mapParams r)),
                 head (Map.findWithDefault ["Default"] "SCHEME" (params r)),
-                head (Map.findWithDefault ["Default"] "AMMO" (params r)),
-                head (Map.findWithDefault ["Default"] "SCHEME" (params r)),
-                head (Map.findWithDefault ["0"] "MAPGEN" (params r)),
-                head (Map.findWithDefault ["seed"] "SEED" (params r))
+                head (Map.findWithDefault ["Default"] "AMMO" (params r))
                 ]
 
 
@@ -96,7 +93,7 @@
                 AnswerClients chans ["CLIENT_FLAGS", "-r", nick cl]
             ]
             ++ map (readynessMessage cl) jRoomClients
-            ++ answerFullConfig cl (params jRoom)
+            ++ answerFullConfig cl (mapParams jRoom) (params jRoom)
             ++ answerTeams cl jRoom
             ++ watchRound cl jRoom
 
@@ -105,10 +102,10 @@
 
         toAnswer cl (paramName, paramStrs) = AnswerClients [sendChan cl] $ "CFG" : paramName : paramStrs
 
-        answerFullConfig cl pr = map (toAnswer cl) $
-                 ("FULLMAPCONFIG", concatMap ((Map.!) pr) ["MAP", "MAPGEN", "SEED"])
+        answerFullConfig cl mpr pr = map (toAnswer cl) $
+                 ("FULLMAPCONFIG", Map.elems mpr)
                  : ("SCHEME", pr Map.! "SCHEME")
-                 : (filter (\(p, _) -> p /= "SCHEME" && p /= "MAP" && p /= "MAPGEN" && p /= "SEED") $ Map.toList pr)
+                 : (filter (\(p, _) -> p /= "SCHEME") $ Map.toList pr)
 
         answerTeams cl jRoom = let f = if gameinprogress jRoom then teamsAtStart else teams in answerAllTeams cl $ f jRoom