Options for bonus box probability tuning and number of turn until sudden death
authorunc0rr
Sat, 31 Jan 2009 15:39:53 +0000
changeset 1782 e7589e37a6d6
parent 1781 28f674367d68
child 1783 169ebeefd7ab
Options for bonus box probability tuning and number of turn until sudden death
QTfrontend/gamecfgwidget.cpp
QTfrontend/gamecfgwidget.h
QTfrontend/hwform.cpp
QTfrontend/newnetclient.cpp
QTfrontend/newnetclient.h
hedgewars/uConsole.pas
hedgewars/uGears.pas
hedgewars/uMisc.pas
--- a/QTfrontend/gamecfgwidget.cpp	Sat Jan 31 11:58:09 2009 +0000
+++ b/QTfrontend/gamecfgwidget.cpp	Sat Jan 31 15:39:53 2009 +0000
@@ -57,9 +57,13 @@
 
 	L_TurnTime = new QLabel(QLabel::tr("Turn time"), GBoxOptions);
 	L_InitHealth = new QLabel(QLabel::tr("Initial health"), GBoxOptions);
+	L_SuddenDeath = new QLabel(QLabel::tr("Turns before SD"), GBoxOptions);
+	L_CaseProb = new QLabel(QLabel::tr("Bonus factor"), GBoxOptions);
 	GBoxOptionsLayout->addWidget(L_TurnTime, 3, 0);
 	GBoxOptionsLayout->addWidget(L_InitHealth, 4, 0);
-	GBoxOptionsLayout->addWidget(new QLabel(QLabel::tr("Weapons"), GBoxOptions), 5, 0);
+	GBoxOptionsLayout->addWidget(L_SuddenDeath, 5, 0);
+	GBoxOptionsLayout->addWidget(L_CaseProb, 6, 0);
+	GBoxOptionsLayout->addWidget(new QLabel(QLabel::tr("Weapons"), GBoxOptions), 7, 0);
 
 	SB_TurnTime = new QSpinBox(GBoxOptions);
 	SB_TurnTime->setRange(1, 99);
@@ -70,14 +74,28 @@
 	SB_InitHealth->setRange(50, 200);
 	SB_InitHealth->setValue(100);
 	SB_InitHealth->setSingleStep(25);
+	
+	SB_SuddenDeath = new QSpinBox(GBoxOptions);
+	SB_SuddenDeath->setRange(0, 50);
+	SB_SuddenDeath->setValue(15);
+	SB_SuddenDeath->setSingleStep(3);
+	
+	SB_CaseProb = new QSpinBox(GBoxOptions);
+	SB_CaseProb->setRange(0, 9);
+	SB_CaseProb->setValue(5);
+
 	GBoxOptionsLayout->addWidget(SB_TurnTime, 3, 1);
 	GBoxOptionsLayout->addWidget(SB_InitHealth, 4, 1);
+	GBoxOptionsLayout->addWidget(SB_SuddenDeath, 5, 1);
+	GBoxOptionsLayout->addWidget(SB_CaseProb, 6, 1);
 	
 	WeaponsName = new QComboBox(GBoxOptions);
-	GBoxOptionsLayout->addWidget(WeaponsName, 5, 1);
+	GBoxOptionsLayout->addWidget(WeaponsName, 7, 1);
 
 	connect(SB_InitHealth, SIGNAL(valueChanged(int)), this, SIGNAL(initHealthChanged(int)));
 	connect(SB_TurnTime, SIGNAL(valueChanged(int)), this, SIGNAL(turnTimeChanged(int)));
+	connect(SB_SuddenDeath, SIGNAL(valueChanged(int)), this, SIGNAL(suddenDeathTurnsChanged(int)));
+	connect(SB_CaseProb, SIGNAL(valueChanged(int)), this, SIGNAL(caseProbabilityChanged(int)));
 	connect(CB_mode_Forts, SIGNAL(toggled(bool)), this, SIGNAL(fortsModeChanged(bool)));
 	connect(CB_teamsDivide, SIGNAL(toggled(bool)), this, SIGNAL(teamsDivideChanged(bool)));
 	connect(CB_solid, SIGNAL(toggled(bool)), this, SIGNAL(solidChanged(bool)));
@@ -127,12 +145,25 @@
 	return SB_TurnTime->value();
 }
 
+quint32 GameCFGWidget::getSuddenDeathTurns() const
+{
+	return SB_SuddenDeath->value();
+}
+
+quint32 GameCFGWidget::getCaseProbability() const
+{
+	return SB_CaseProb->value();
+}
+
 QStringList GameCFGWidget::getFullConfig() const
 {
 	QStringList sl;
 	sl.append("eseed " + getCurrentSeed());
 	sl.append(QString("e$gmflags %1").arg(getGameFlags()));
 	sl.append(QString("e$turntime %1").arg(getTurnTime() * 1000));
+	sl.append(QString("e$sd_turns %1").arg(getSuddenDeathTurns()));
+	sl.append(QString("e$casefreq %1").arg(getCaseProbability()));
+
 	QString currentMap = getCurrentMap();
 	if (currentMap.size() > 0)
 		sl.append("emap " + currentMap);
@@ -165,6 +196,16 @@
 	SB_TurnTime->setValue(time);
 }
 
+void GameCFGWidget::setSuddenDeathTurns(int turns)
+{
+	SB_SuddenDeath->setValue(turns);
+}
+
+void GameCFGWidget::setCaseProbability(int prob)
+{
+	SB_CaseProb->setValue(prob);
+}
+
 void GameCFGWidget::setFortsMode(bool value)
 {
 	CB_mode_Forts->setChecked(value);
--- a/QTfrontend/gamecfgwidget.h	Sat Jan 31 11:58:09 2009 +0000
+++ b/QTfrontend/gamecfgwidget.h	Sat Jan 31 15:39:53 2009 +0000
@@ -42,6 +42,8 @@
 	QString getCurrentTheme() const;
 	quint32 getInitHealth() const;
 	quint32 getTurnTime() const;
+	quint32 getSuddenDeathTurns() const;
+	quint32 getCaseProbability() const;
 	QStringList getFullConfig() const;
 
 	QComboBox* WeaponsName;
@@ -52,6 +54,8 @@
 	void setTheme(const QString & theme);
 	void setInitHealth(int health);
 	void setTurnTime(int time);
+	void setSuddenDeathTurns(int turns);
+	void setCaseProbability(int prob);
 	void setFortsMode(bool value);
 	void setTeamsDivide(bool value);
 	void setSolid(bool value);
@@ -63,6 +67,8 @@
 	void themeChanged(const QString & theme);
 	void initHealthChanged(int health);
 	void turnTimeChanged(int time);
+	void suddenDeathTurnsChanged(int turns);
+	void caseProbabilityChanged(int prob);
 	void fortsModeChanged(bool value);
 	void teamsDivideChanged(bool value);
 	void solidChanged(bool value);
@@ -79,8 +85,12 @@
 	HWMapContainer* pMapContainer;
 	QSpinBox * SB_TurnTime;
 	QSpinBox * SB_InitHealth;
+	QSpinBox * SB_SuddenDeath;
+	QSpinBox * SB_CaseProb;
 	QLabel * L_TurnTime;
 	QLabel * L_InitHealth;
+	QLabel * L_SuddenDeath;
+	QLabel * L_CaseProb;
 
 	QString curNetAmmoName;
 	QString curNetAmmo;
--- a/QTfrontend/hwform.cpp	Sat Jan 31 11:58:09 2009 +0000
+++ b/QTfrontend/hwform.cpp	Sat Jan 31 15:39:53 2009 +0000
@@ -523,6 +523,8 @@
 	connect(ui.pageNetGame->pGameCFG, SIGNAL(themeChanged(const QString &)), hwnet, SLOT(onThemeChanged(const QString &)));
 	connect(ui.pageNetGame->pGameCFG, SIGNAL(initHealthChanged(int)), hwnet, SLOT(onInitHealthChanged(int)));
 	connect(ui.pageNetGame->pGameCFG, SIGNAL(turnTimeChanged(int)), hwnet, SLOT(onTurnTimeChanged(int)));
+	connect(ui.pageNetGame->pGameCFG, SIGNAL(suddenDeathTurnsChanged(int)), hwnet, SLOT(onSuddenDeathTurnsChanged(int)));
+	connect(ui.pageNetGame->pGameCFG, SIGNAL(caseProbabilityChanged(int)), hwnet, SLOT(onCaseProbabilityChanged(int)));
 	connect(ui.pageNetGame->pGameCFG, SIGNAL(fortsModeChanged(bool)), hwnet, SLOT(onFortsModeChanged(bool)));
 	connect(ui.pageNetGame->pGameCFG, SIGNAL(teamsDivideChanged(bool)), hwnet, SLOT(onTeamsDivideChanged(bool)));
 	connect(ui.pageNetGame->pGameCFG, SIGNAL(solidChanged(bool)), hwnet, SLOT(onSolidChanged(bool)));
@@ -535,6 +537,8 @@
 	connect(hwnet, SIGNAL(themeChanged(const QString &)), ui.pageNetGame->pGameCFG, SLOT(setTheme(const QString &)));
 	connect(hwnet, SIGNAL(initHealthChanged(int)), ui.pageNetGame->pGameCFG, SLOT(setInitHealth(int)));
 	connect(hwnet, SIGNAL(turnTimeChanged(int)), ui.pageNetGame->pGameCFG, SLOT(setTurnTime(int)));
+	connect(hwnet, SIGNAL(suddenDeathTurnsChanged(int)), ui.pageNetGame->pGameCFG, SLOT(setSuddenDeathTurns(int)));
+	connect(hwnet, SIGNAL(caseProbabilityChanged(int)), ui.pageNetGame->pGameCFG, SLOT(setCaseProbability(int)));
 	connect(hwnet, SIGNAL(fortsModeChanged(bool)), ui.pageNetGame->pGameCFG, SLOT(setFortsMode(bool)));
 	connect(hwnet, SIGNAL(teamsDivideChanged(bool)), ui.pageNetGame->pGameCFG, SLOT(setTeamsDivide(bool)));
 	connect(hwnet, SIGNAL(solidChanged(bool)), ui.pageNetGame->pGameCFG, SLOT(setSolid(bool)));
--- a/QTfrontend/newnetclient.cpp	Sat Jan 31 11:58:09 2009 +0000
+++ b/QTfrontend/newnetclient.cpp	Sat Jan 31 15:39:53 2009 +0000
@@ -468,6 +468,14 @@
 			emit turnTimeChanged(lst[2].toUInt());
 			return;
 		}
+		if (lst[1] == "SD_TURNS") {
+			emit suddenDeathTurnsChanged(lst[2].toUInt());
+			return;
+		}
+		if (lst[1] == "CASEFACTOR") {
+			emit caseProbabilityChanged(lst[2].toUInt());
+			return;
+		}
 		if (lst[1] == "FORTSMODE") {
 			emit fortsModeChanged(lst[2].toInt() != 0);
 			return;
@@ -610,6 +618,16 @@
 	if (isChief) RawSendNet(QString("CONFIG_PARAM%1TURNTIME%1%2").arg(delimeter).arg(time));
 }
 
+void HWNewNet::onSuddenDeathTurnsChanged(int turns)
+{
+	if (isChief) RawSendNet(QString("CONFIG_PARAM%1SD_TURNS%1%2").arg(delimeter).arg(turns));
+}
+
+void HWNewNet::onCaseProbabilityChanged(int prob)
+{
+	if (isChief) RawSendNet(QString("CONFIG_PARAM%1CASEFACTOR%1%2").arg(delimeter).arg(prob));
+}
+
 void HWNewNet::onFortsModeChanged(bool value)
 {
 	if (isChief) RawSendNet(QString("CONFIG_PARAM%1FORTSMODE%1%2").arg(delimeter).arg(value));
--- a/QTfrontend/newnetclient.h	Sat Jan 31 11:58:09 2009 +0000
+++ b/QTfrontend/newnetclient.h	Sat Jan 31 15:39:53 2009 +0000
@@ -106,6 +106,8 @@
   void themeChanged(const QString & theme);
   void initHealthChanged(int health);
   void turnTimeChanged(int time);
+  void suddenDeathTurnsChanged(int turns);
+  void caseProbabilityChanged(int prob);
   void fortsModeChanged(bool value);
   void teamsDivideChanged(bool value);
   void solidChanged(bool value);
@@ -136,6 +138,8 @@
   void onThemeChanged(const QString & theme);
   void onInitHealthChanged(int health);
   void onTurnTimeChanged(int time);
+  void onSuddenDeathTurnsChanged(int turns);
+  void onCaseProbabilityChanged(int prob);
   void onFortsModeChanged(bool value);
   void onTeamsDivideChanged(bool value);
   void onSolidChanged(bool value);
--- a/hedgewars/uConsole.pas	Sat Jan 31 11:58:09 2009 +0000
+++ b/hedgewars/uConsole.pas	Sat Jan 31 15:39:53 2009 +0000
@@ -239,6 +239,7 @@
 RegisterVariable('seed'    , vtCommand, @chSetSeed      , false);
 RegisterVariable('delay'   , vtLongInt, @cInactDelay    , false);
 RegisterVariable('casefreq', vtLongInt, @cCaseFactor    , false);
+RegisterVariable('sd_turns', vtLongInt, @cSuddenDTurns  , false);
 RegisterVariable('landadds', vtLongInt, @cLandAdditions , false);
 RegisterVariable('gmflags' , vtLongInt, @GameFlags      , false);
 RegisterVariable('turntime', vtLongInt, @cHedgehogTurnTime, false);
--- a/hedgewars/uGears.pas	Sat Jan 31 11:58:09 2009 +0000
+++ b/hedgewars/uGears.pas	Sat Jan 31 15:39:53 2009 +0000
@@ -518,7 +518,7 @@
 			end;
 	stWater: if (not bBetweenTurns) and (not isInMultiShoot) then
 				begin
-				if TotalRounds = 17 then bWaterRising:= true;
+				if TotalRounds = cSuddenDTurns + 2 then bWaterRising:= true;
 
 				if bWaterRising then
 				AddGear(0, 0, gtWaterUp, 0, _0, _0, 0);
@@ -530,7 +530,7 @@
 			inc(step)
 			end;
 	stHealth: begin
-			if (TotalRounds = 15) and (cHealthDecrease = 0) then
+			if (TotalRounds = cSuddenDTurns) and (cHealthDecrease = 0) then
 				begin
 				cHealthDecrease:= 5;
 				AddCaption(trmsg[sidSuddenDeath], $FFFFFF, capgrpGameState)
--- a/hedgewars/uMisc.pas	Sat Jan 31 11:58:09 2009 +0000
+++ b/hedgewars/uMisc.pas	Sat Jan 31 15:39:53 2009 +0000
@@ -37,6 +37,7 @@
 	GameType      : TGameType = gmtLocal;
 	GameFlags     : Longword = 0;
 	TurnTimeLeft  : Longword = 0;
+	cSuddenDTurns : Longword = 15;
 	cHedgehogTurnTime: Longword = 45000;
 	cMaxAIThinkTime  : Longword = 9000;