--- a/QTfrontend/gamecfgwidget.cpp Sun Dec 12 20:17:00 2010 -0500
+++ b/QTfrontend/gamecfgwidget.cpp Mon Dec 13 04:53:48 2010 +0100
@@ -47,46 +47,90 @@
QGridLayout *GBoxOptionsLayout = new QGridLayout(GBoxOptions);
- GameSchemes = new QComboBox(GBoxOptions);
- GBoxOptionsLayout->addWidget(GameSchemes, 0, 2);
+ GBoxOptionsLayout->addWidget(new QLabel(QLabel::tr("Gameplay"), GBoxOptions), 0, 0);
+
+ Scripts = new QComboBox(GBoxOptions);
+ GBoxOptionsLayout->addWidget(Scripts, 0, 1);
+
+ Scripts->addItem(QComboBox::tr("Normal"));
+ Scripts->insertSeparator(1);
+
+ for (int i = 0; i < scriptList->size(); ++i) {
+ QString script = (*scriptList)[i].remove(".lua", Qt::CaseInsensitive);
+ QList<QVariant> scriptInfo;
+ QFile scriptCfgFile(QString("%1/Scripts/Multiplayer/%2.cfg").arg(datadir->absolutePath()).arg(script));
+ if (scriptCfgFile.exists() && scriptCfgFile.open(QFile::ReadOnly)) {
+ QString scheme;
+ QString weapons;
+ QTextStream input(&scriptCfgFile);
+ input >> scheme;
+ input >> weapons;
+ if (scheme.isEmpty())
+ scheme = "locked";
+ scheme.replace("_", " ");
+ if (weapons.isEmpty())
+ weapons = "locked";
+ weapons.replace("_", " ");
+ scriptInfo.push_back(scheme);
+ scriptInfo.push_back(weapons);
+ scriptCfgFile.close();
+ }
+ else
+ {
+ scriptInfo.push_back("locked");
+ scriptInfo.push_back("locked");
+ }
+ Scripts->addItem(script, scriptInfo);
+ }
+
+ connect(Scripts, SIGNAL(currentIndexChanged(int)), this, SLOT(scriptChanged(int)));
+
+ QWidget *SchemeWidget = new QWidget(GBoxOptions);
+ GBoxOptionsLayout->addWidget(SchemeWidget, 1, 0, 1, 2);
+
+ QGridLayout *SchemeWidgetLayout = new QGridLayout(SchemeWidget);
+ SchemeWidgetLayout->setMargin(0);
+
+ GameSchemes = new QComboBox(SchemeWidget);
+ SchemeWidgetLayout->addWidget(GameSchemes, 0, 2);
connect(GameSchemes, SIGNAL(currentIndexChanged(int)), this, SLOT(schemeChanged(int)));
- GBoxOptionsLayout->addWidget(new QLabel(QLabel::tr("Game scheme"), GBoxOptions), 0, 0);
+ SchemeWidgetLayout->addWidget(new QLabel(QLabel::tr("Game scheme"), SchemeWidget), 0, 0);
QPixmap pmEdit(":/res/edit.png");
- QPushButton * goToSchemePage = new QPushButton(GBoxOptions);
+ QPushButton * goToSchemePage = new QPushButton(SchemeWidget);
goToSchemePage->setToolTip(tr("Edit schemes"));
goToSchemePage->setIconSize(pmEdit.size());
goToSchemePage->setIcon(pmEdit);
goToSchemePage->setMaximumWidth(pmEdit.width() + 6);
- GBoxOptionsLayout->addWidget(goToSchemePage, 0, 3);
+ SchemeWidgetLayout->addWidget(goToSchemePage, 0, 3);
connect(goToSchemePage, SIGNAL(clicked()), this, SLOT(jumpToSchemes()));
- GBoxOptionsLayout->addWidget(new QLabel(QLabel::tr("Weapons"), GBoxOptions), 1, 0);
+ SchemeWidgetLayout->addWidget(new QLabel(QLabel::tr("Weapons"), SchemeWidget), 1, 0);
- WeaponsName = new QComboBox(GBoxOptions);
- GBoxOptionsLayout->addWidget(WeaponsName, 1, 2);
+ WeaponsName = new QComboBox(SchemeWidget);
+ SchemeWidgetLayout->addWidget(WeaponsName, 1, 2);
connect(WeaponsName, SIGNAL(currentIndexChanged(int)), this, SLOT(ammoChanged(int)));
- QPushButton * goToWeaponPage = new QPushButton(GBoxOptions);
+ QPushButton * goToWeaponPage = new QPushButton(SchemeWidget);
goToWeaponPage->setToolTip(tr("Edit weapons"));
goToWeaponPage->setIconSize(pmEdit.size());
goToWeaponPage->setIcon(pmEdit);
goToWeaponPage->setMaximumWidth(pmEdit.width() + 6);
- GBoxOptionsLayout->addWidget(goToWeaponPage, 1, 3);
+ SchemeWidgetLayout->addWidget(goToWeaponPage, 1, 3);
connect(goToWeaponPage, SIGNAL(clicked()), this, SLOT(jumpToWeapons()));
//GBoxOptionsLayout->addWidget(new QLabel(QLabel::tr("Bind schemes with weapons"), GBoxOptions), 2, 0);
- bindEntries = new QCheckBox(GBoxOptions);
+ bindEntries = new QCheckBox(SchemeWidget);
bindEntries->setToolTip(tr("When this option is enabled selecting a game scheme will auto-select a weapon"));
bindEntries->setChecked(true);
bindEntries->setMaximumWidth(42);
bindEntries->setStyleSheet( "QCheckBox::indicator:checked { image: url(\":/res/lock.png\"); }"
"QCheckBox::indicator:unchecked { image: url(\":/res/unlock.png\"); }" );
- GBoxOptionsLayout->addWidget(bindEntries, 0, 1, 0, 1, Qt::AlignVCenter);
+ SchemeWidgetLayout->addWidget(bindEntries, 0, 1, 0, 1, Qt::AlignVCenter);
//GBoxOptionsLayout->addWidget(bindEntries, 2, 2);
connect(pMapContainer, SIGNAL(seedChanged(const QString &)), this, SLOT(seedChanged(const QString &)));
@@ -224,6 +268,11 @@
}
bcfg << QString("etheme " + pMapContainer->getCurrentTheme()).toUtf8();
+ if (Scripts->currentIndex() > 0)
+ {
+ bcfg << QString("escript Scripts/Multiplayer/%1.lua").arg(Scripts->currentText()).toUtf8();
+ }
+
QByteArray result;
foreach(QByteArray ba, bcfg)
@@ -257,6 +306,7 @@
themeChanged(pMapContainer->getCurrentTheme());
schemeChanged(GameSchemes->currentIndex());
+ scriptChanged(Scripts->currentIndex());
mapgenChanged(pMapContainer->get_mapgen());
maze_sizeChanged(pMapContainer->get_maze_size());
@@ -296,6 +346,10 @@
pMapContainer->setMaze_size(value.toUInt());
return;
}
+ if (param == "SCRIPT") {
+ Scripts->setCurrentIndex(Scripts->findText(value));
+ return;
+ }
}
if (slValue.size() == 2)
@@ -323,14 +377,47 @@
{
if(pMapContainer->getCurrentIsMission())
{
- GameSchemes->setEnabled(false);
- WeaponsName->setEnabled(false);
- bindEntries->setEnabled(false);
- GameSchemes->setCurrentIndex(GameSchemes->findText("Default"));
- WeaponsName->setCurrentIndex(WeaponsName->findText("Default"));
+ Scripts->setEnabled(false);
+ Scripts->setCurrentIndex(0);
+
+ if (pMapContainer->getCurrentScheme() == "locked")
+ {
+ GameSchemes->setEnabled(false);
+ GameSchemes->setCurrentIndex(GameSchemes->findText("Default"));
+ }
+ else
+ {
+ GameSchemes->setEnabled(true);
+ int num = GameSchemes->findText(pMapContainer->getCurrentScheme());
+ if (num != -1)
+ GameSchemes->setCurrentIndex(num);
+ else
+ GameSchemes->setCurrentIndex(GameSchemes->findText("Default"));
+ }
+
+ if (pMapContainer->getCurrentWeapons() == "locked")
+ {
+ WeaponsName->setEnabled(false);
+ WeaponsName->setCurrentIndex(WeaponsName->findText("Default"));
+ }
+ else
+ {
+ WeaponsName->setEnabled(true);
+ int num = WeaponsName->findText(pMapContainer->getCurrentWeapons());
+ if (num != -1)
+ WeaponsName->setCurrentIndex(num);
+ else
+ WeaponsName->setCurrentIndex(WeaponsName->findText("Default"));
+ }
+
+ if (pMapContainer->getCurrentScheme() != "locked" && pMapContainer->getCurrentWeapons() != "locked")
+ bindEntries->setEnabled(true);
+ else
+ bindEntries->setEnabled(false);
}
else
{
+ Scripts->setEnabled(true);
GameSchemes->setEnabled(true);
WeaponsName->setEnabled(true);
bindEntries->setEnabled(true);
@@ -363,7 +450,7 @@
emit paramChanged("SCHEME", sl);
- if (bindEntries->isChecked() == true) {
+ if (bindEntries->isEnabled() && bindEntries->isChecked()) {
QString schemeName = GameSchemes->itemText(index);
for (int i = 0; i < WeaponsName->count(); i++) {
QString weapName = WeaponsName->itemText(i);
@@ -377,6 +464,57 @@
}
}
+void GameCFGWidget::scriptChanged(int index)
+{
+ if(index > 0)
+ {
+ QString scheme = Scripts->itemData(Scripts->currentIndex()).toList()[0].toString();
+ QString weapons = Scripts->itemData(Scripts->currentIndex()).toList()[1].toString();
+
+ if (scheme == "locked")
+ {
+ GameSchemes->setEnabled(false);
+ GameSchemes->setCurrentIndex(GameSchemes->findText("Default"));
+ }
+ else
+ {
+ GameSchemes->setEnabled(true);
+ int num = GameSchemes->findText(scheme);
+ if (num != -1)
+ GameSchemes->setCurrentIndex(num);
+ else
+ GameSchemes->setCurrentIndex(GameSchemes->findText("Default"));
+ }
+
+ if (weapons == "locked")
+ {
+ WeaponsName->setEnabled(false);
+ WeaponsName->setCurrentIndex(WeaponsName->findText("Default"));
+ }
+ else
+ {
+ WeaponsName->setEnabled(true);
+ int num = WeaponsName->findText(weapons);
+ if (num != -1)
+ WeaponsName->setCurrentIndex(num);
+ else
+ WeaponsName->setCurrentIndex(WeaponsName->findText("Default"));
+ }
+
+ if (scheme != "locked" && weapons != "locked")
+ bindEntries->setEnabled(true);
+ else
+ bindEntries->setEnabled(false);
+ }
+ else
+ {
+ GameSchemes->setEnabled(true);
+ WeaponsName->setEnabled(true);
+ bindEntries->setEnabled(true);
+ }
+ emit paramChanged("SCRIPT", QStringList(Scripts->itemText(index)));
+}
+
void GameCFGWidget::mapgenChanged(MapGenerator m)
{
emit paramChanged("MAPGEN", QStringList(QString::number(m)));
--- a/QTfrontend/gamecfgwidget.h Sun Dec 12 20:17:00 2010 -0500
+++ b/QTfrontend/gamecfgwidget.h Mon Dec 13 04:53:48 2010 +0100
@@ -40,6 +40,7 @@
quint32 getGameFlags() const;
quint32 getInitHealth() const;
QByteArray getFullConfig() const;
+ QComboBox * Scripts;
QComboBox * GameSchemes;
QComboBox * WeaponsName;
HWMapContainer* pMapContainer;
@@ -64,6 +65,7 @@
void seedChanged(const QString &);
void themeChanged(const QString &);
void schemeChanged(int);
+ void scriptChanged(int);
void jumpToSchemes();
void jumpToWeapons();
void mapgenChanged(MapGenerator m);
--- a/QTfrontend/hwconsts.cpp.in Sun Dec 12 20:17:00 2010 -0500
+++ b/QTfrontend/hwconsts.cpp.in Mon Dec 13 04:53:48 2010 +0100
@@ -29,6 +29,7 @@
QStringList * Themes;
QStringList * mapList;
+QStringList * scriptList;
bool custom_config = false;
bool custom_data = false;
--- a/QTfrontend/hwconsts.h Sun Dec 12 20:17:00 2010 -0500
+++ b/QTfrontend/hwconsts.h Mon Dec 13 04:53:48 2010 +0100
@@ -38,6 +38,7 @@
extern QStringList * Themes;
extern QStringList * mapList;
+extern QStringList * scriptList;
extern QString * cDefaultAmmoStore;
extern int cAmmoNumber;
--- a/QTfrontend/main.cpp Sun Dec 12 20:17:00 2010 -0500
+++ b/QTfrontend/main.cpp Mon Dec 13 04:53:48 2010 +0100
@@ -399,6 +399,11 @@
tmpdir.setFilter(QDir::Dirs | QDir::NoDotAndDotDot);
mapList = new QStringList(tmpdir.entryList(QStringList("*")));
+ tmpdir.cd(datadir->absolutePath());
+ tmpdir.cd("Scripts/Multiplayer");
+ tmpdir.setFilter(QDir::Files | QDir::NoDotAndDotDot);
+ scriptList = new QStringList(tmpdir.entryList(QStringList("*.lua")));
+
QTranslator Translator;
{
--- a/QTfrontend/mapContainer.cpp Sun Dec 12 20:17:00 2010 -0500
+++ b/QTfrontend/mapContainer.cpp Mon Dec 13 04:53:48 2010 +0100
@@ -94,10 +94,14 @@
if (mapCfgFile.open(QFile::ReadOnly)) {
QString theme;
quint32 limit = 0;
+ QString scheme;
+ QString weapons;
QList<QVariant> mapInfo;
QTextStream input(&mapCfgFile);
input >> theme;
input >> limit;
+ input >> scheme;
+ input >> weapons;
mapInfo.push_back(map);
mapInfo.push_back(theme);
if (limit)
@@ -105,6 +109,14 @@
else
mapInfo.push_back(18);
mapInfo.push_back(mapLuaFile.exists());
+ if (scheme.isEmpty())
+ scheme = "locked";
+ scheme.replace("_", " ");
+ if (weapons.isEmpty())
+ weapons = "locked";
+ weapons.replace("_", " ");
+ mapInfo.push_back(scheme);
+ mapInfo.push_back(weapons);
if(mapLuaFile.exists())
{
chooseMap->insertItem(missionindex++,
@@ -373,6 +385,16 @@
return hhLimit;
}
+QString HWMapContainer::getCurrentScheme() const
+{
+ return chooseMap->itemData(chooseMap->currentIndex()).toList()[4].toString();
+}
+
+QString HWMapContainer::getCurrentWeapons() const
+{
+ return chooseMap->itemData(chooseMap->currentIndex()).toList()[5].toString();
+}
+
quint32 HWMapContainer::getTemplateFilter() const
{
return CB_TemplateFilter->itemData(CB_TemplateFilter->currentIndex()).toInt();
@@ -512,4 +534,4 @@
QByteArray HWMapContainer::getDrawnMapData()
{
return drawnMapData;
-}
\ No newline at end of file
+}
--- a/QTfrontend/mapContainer.h Sun Dec 12 20:17:00 2010 -0500
+++ b/QTfrontend/mapContainer.h Mon Dec 13 04:53:48 2010 +0100
@@ -45,6 +45,8 @@
QString getCurrentMap() const;
QString getCurrentTheme() const;
int getCurrentHHLimit() const;
+ QString getCurrentScheme() const;
+ QString getCurrentWeapons() const;
quint32 getTemplateFilter() const;
MapGenerator get_mapgen(void) const;
int get_maze_size(void) const;
--- a/share/hedgewars/Data/Scripts/CMakeLists.txt Sun Dec 12 20:17:00 2010 -0500
+++ b/share/hedgewars/Data/Scripts/CMakeLists.txt Mon Dec 13 04:53:48 2010 +0100
@@ -4,3 +4,4 @@
${luafiles}
DESTINATION ${SHAREPATH}Data/Scripts)
+add_subdirectory(Multiplayer)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/share/hedgewars/Data/Scripts/Multiplayer/CMakeLists.txt Mon Dec 13 04:53:48 2010 +0100
@@ -0,0 +1,7 @@
+file(GLOB luafiles *.lua)
+file(GLOB cfgfiles *.cfg)
+
+install(FILES
+ ${luafiles}
+ ${cfgfiles}
+ DESTINATION ${SHAREPATH}Data/Scripts/Multiplayer)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/share/hedgewars/Data/Scripts/Multiplayer/RandomWeapon.cfg Mon Dec 13 04:53:48 2010 +0100
@@ -0,0 +1,2 @@
+Default
+locked
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/share/hedgewars/Data/Scripts/Multiplayer/RandomWeapon.lua Mon Dec 13 04:53:48 2010 +0100
@@ -0,0 +1,42 @@
+local weapons = { amGrenade, amClusterBomb, amBazooka, amBee, amShotgun,
+ amMine, amDEagle, amDynamite, amFirePunch, amWhip, amPickHammer,
+ amBaseballBat, amAirAttack, amMineStrike, amTeleport, amMortar, amCake,
+ amSeduction, amWatermelon, amHellishBomb, amNapalm, amDrill, amBallgun,
+ amRCPlane, amSniperRifle, amMolotov, amBirdy, amBlowTorch,
+ amGasBomb, amFlamethrower, amSMine, amHammer, amDrillStrike }
+
+local lastRound = -1
+local weapon = 0
+
+function onGameInit()
+ GameFlags = band(bor(GameFlags, gfResetWeps), bnot(gfInfAttack + gfPerHogAmmo))
+end
+
+function onAmmoStoreInit()
+ SetAmmo(amSkip, 9, 0, 0, 0)
+
+ SetAmmo(amParachute, 0, 1, 0, 1)
+ SetAmmo(amGirder, 0, 1, 0, 2)
+ SetAmmo(amSwitch, 0, 1, 0, 1)
+ SetAmmo(amLowGravity, 0, 1, 0, 1)
+ SetAmmo(amExtraDamage, 0, 1, 0, 1)
+ SetAmmo(amInvulnerable, 0, 1, 0, 1)
+ SetAmmo(amExtraTime, 0, 1, 0, 1)
+ SetAmmo(amLaserSight, 0, 1, 0, 1)
+ SetAmmo(amVampiric, 0, 1, 0, 1)
+ SetAmmo(amJetpack, 0, 1, 0, 1)
+ SetAmmo(amPortalGun, 0, 1, 0, 1)
+ SetAmmo(amResurrector, 0, 1, 0, 1)
+
+ for i, w in pairs(weapons) do
+ SetAmmo(w, 0, 0, 0, 1)
+ end
+end
+
+function onNewTurn()
+ if lastRound ~= TotalRounds then
+ weapon = GetRandom(table.maxn(weapons)) + 1
+ lastRound = TotalRounds
+ end
+ AddAmmo(CurrentHedgehog, weapons[weapon])
+end