浏览代码

Compilation of most of AI's is now optional

Ivan Savenko 1 周之前
父节点
当前提交
e4497284a1

+ 15 - 3
AI/CMakeLists.txt

@@ -35,11 +35,23 @@ endif()
 #        Add subdirectories           #
 #######################################
 
-add_subdirectory(BattleAI)
-add_subdirectory(VCAI)
-add_subdirectory(StupidAI)
+# Combat AI's
+if(ENABLE_STUPID_AI)
+	add_subdirectory(StupidAI)
+endif()
+
+if(ENABLE_BATTLE_AI)
+	add_subdirectory(BattleAI)
+endif()
+
+# Adventure AI's
 add_subdirectory(EmptyAI)
+add_subdirectory(VCAI)
+
 if(ENABLE_NULLKILLER_AI)
 	add_subdirectory(Nullkiller)
+endif()
+
+if(ENABLE_NULLKILLER2_AI)
 	add_subdirectory(Nullkiller2)
 endif()

+ 20 - 1
CMakeLists.txt

@@ -46,10 +46,16 @@ option(ENABLE_ERM "Enable compilation of ERM scripting module" OFF)
 option(ENABLE_LUA "Enable compilation of LUA scripting module" OFF)
 option(ENABLE_VIDEO "Enable video support using ffmpeg" ON)
 option(ENABLE_TRANSLATIONS "Enable generation of translations for launcher and editor" ON)
-option(ENABLE_NULLKILLER_AI "Enable compilation of Nullkiller AI library" ON)
 option(ENABLE_MINIMAL_LIB "Build only core parts of vcmi library that are required for game lobby" OFF)
 option(ENABLE_GOLDMASTER "Build in public release mode in which some debug routines are disabled" OFF)
 
+# AI libraries. Empty AI is always on
+
+option(ENABLE_NULLKILLER_AI "Enable compilation of NullkillerAI library" ON)
+option(ENABLE_NULLKILLER2_AI "Enable compilation of Nullkiller2AI library" ON)
+option(ENABLE_STUPID_AI "Enable compilation of StupidAI library" ON)
+option(ENABLE_BATTLE_AI "Enable compilation of BattleAI library" ON)
+
 # Compilation options
 
 option(ENABLE_PCH "Enable compilation using precompiled headers" ON)
@@ -284,6 +290,19 @@ if(ENABLE_GOLDMASTER)
 	add_definitions(-DENABLE_GOLDMASTER)
 endif()
 
+if(ENABLE_NULLKILLER_AI)
+	add_definitions(-DENABLE_NULLKILLER_AI)
+endif()
+if(ENABLE_NULLKILLER2_AI)
+	add_definitions(-DENABLE_NULLKILLER2_AI)
+endif()
+if(ENABLE_STUPID_AI)
+	add_definitions(-DENABLE_STUPID_AI)
+endif()
+if(ENABLE_BATTLE_AI)
+	add_definitions(-DENABLE_BATTLE_AI)
+endif()
+
 if(IOS)
 	set(CMAKE_MACOSX_RPATH 1)
 	set(CMAKE_OSX_DEPLOYMENT_TARGET 12.0)

+ 14 - 6
client/CMakeLists.txt

@@ -452,16 +452,24 @@ assign_source_group(${vcmiclientcommon_SRCS} ${vcmiclientcommon_HEADERS})
 add_library(vcmiclientcommon STATIC ${vcmiclientcommon_SRCS} ${vcmiclientcommon_HEADERS})
 
 if(NOT ENABLE_STATIC_LIBS)
-	add_dependencies(vcmiclientcommon
-		BattleAI
-		EmptyAI
-		StupidAI
-		VCAI
-	)
+	add_dependencies(vcmiclientcommon EmptyAI VCAI)
+
 	if(ENABLE_NULLKILLER_AI)
 		add_dependencies(vcmiclientcommon Nullkiller)
+	endif()
+
+	if(ENABLE_NULLKILLER2_AI)
 		add_dependencies(vcmiclientcommon Nullkiller2)
 	endif()
+
+	if(ENABLE_STUPID_AI)
+		add_dependencies(vcmiclientcommon StupidAI)
+	endif()
+
+	if(ENABLE_BATTLE_AI)
+		add_dependencies(vcmiclientcommon BattleAI)
+	endif()
+
 endif()
 if(IOS)
 	if(ENABLE_ERM)

+ 2 - 2
config/schemas/settings.json

@@ -589,11 +589,11 @@
 				},
 				"playerAI" : {
 					"type" : "string",
-					"default" : "Nullkiller"
+					"default" : "Nullkiller2"
 				},
 				"alliedAI" : {
 					"type" : "string",
-					"default" : "Nullkiller"
+					"default" : "Nullkiller2"
 				},
 				"friendlyAI" : {
 					"type" : "string",

+ 65 - 12
launcher/settingsView/csettingsview_moc.cpp

@@ -91,6 +91,60 @@ void CSettingsView::updateCheckbuttonText(QToolButton * button)
 		button->setText(tr("Off"));
 }
 
+void CSettingsView::fillValidCombatAILibraries(QComboBox * comboBox, QString activeAI)
+{
+	comboBox->clear();
+
+#ifdef ENABLE_STUPID_AI
+	comboBox->addItem(tr("StupidAI (deprecated)"), "StupidAI");
+#endif
+
+#ifdef ENABLE_BATTLE_AI
+	comboBox->addItem(tr("BattleAI (default, recommended)"), "BattleAI");
+#endif
+
+	fillValidAnyAILibraries(comboBox, activeAI);
+}
+
+void CSettingsView::fillValidAdventureAILibraries(QComboBox * comboBox, QString activeAI)
+{
+	comboBox->clear();
+
+	comboBox->addItem(tr("VCAI (deprecated)"), "VCAI");
+
+#ifdef ENABLE_NULLKILLER_AI
+	comboBox->addItem(tr("Nullkiller (superseded by Nullkiller2)"), "Nullkiller");
+#endif
+
+#ifdef ENABLE_NULLKILLER2_AI
+	comboBox->addItem(tr("Nullkiller2 (default, recommended)"), "Nullkiller2");
+#endif
+
+	if (comboBox->count() == 0)
+		comboBox->addItem(tr("EmptyAI - No valid AI libraries found!"), "EmptyAI");
+
+	fillValidAnyAILibraries(comboBox, activeAI);
+}
+
+void CSettingsView::fillValidAnyAILibraries(QComboBox * comboBox, QString activeAI)
+{
+	int indexToSelect = comboBox->findData(activeAI);
+
+	if (indexToSelect == -1)
+		comboBox->setCurrentIndex(0);
+	else
+		comboBox->setCurrentIndex(indexToSelect);
+}
+
+void CSettingsView::fillValidAILibraries()
+{
+	fillValidAdventureAILibraries(ui->comboBoxAlliedPlayerAI,QString::fromStdString(settings["server"]["alliedAI"].String()));
+	fillValidAdventureAILibraries(ui->comboBoxEnemyPlayerAI, QString::fromStdString(settings["server"]["playerAI"].String()));
+	fillValidCombatAILibraries(ui->comboBoxEnemyAI, QString::fromStdString(settings["server"]["enemyAI"].String()));
+	fillValidCombatAILibraries(ui->comboBoxFriendlyAI, QString::fromStdString(settings["server"]["friendlyAI"].String()));
+	fillValidCombatAILibraries(ui->comboBoxNeutralAI, QString::fromStdString(settings["server"]["neutralAI"].String()));
+}
+
 void CSettingsView::loadSettings()
 {
 #ifdef VCMI_MOBILE
@@ -129,6 +183,7 @@ void CSettingsView::loadSettings()
 	ui->buttonIgnoreMuteSwitch->hide();
 #endif
 	fillValidScalingRange();
+	fillValidAILibraries();
 
 	ui->buttonScalingAuto->setChecked(settings["video"]["resolution"]["scaling"].Integer() == 0);
 	if (settings["video"]["resolution"]["scaling"].Integer() == 0)
@@ -140,13 +195,6 @@ void CSettingsView::loadSettings()
 	ui->spinBoxFramerateLimit->setDisabled(settings["video"]["vsync"].Bool());
 	ui->sliderReservedArea->setValue(std::round(settings["video"]["reservedWidth"].Float() * 100));
 
-	ui->comboBoxFriendlyAI->setCurrentText(QString::fromStdString(settings["server"]["friendlyAI"].String()));
-	ui->comboBoxNeutralAI->setCurrentText(QString::fromStdString(settings["server"]["neutralAI"].String()));
-	ui->comboBoxEnemyAI->setCurrentText(QString::fromStdString(settings["server"]["enemyAI"].String()));
-
-	ui->comboBoxEnemyPlayerAI->setCurrentText(QString::fromStdString(settings["server"]["playerAI"].String()));
-	ui->comboBoxAlliedPlayerAI->setCurrentText(QString::fromStdString(settings["server"]["alliedAI"].String()));
-
 	ui->spinBoxNetworkPort->setValue(settings["server"]["localPort"].Integer());
 
 	ui->lineEditRepositoryDefault->setText(QString::fromStdString(settings["launcher"]["defaultRepositoryURL"].String()));
@@ -448,20 +496,23 @@ void CSettingsView::on_comboBoxDisplayIndex_currentIndexChanged(int index)
 	fillValidResolutionsForScreen(index);
 }
 
-void CSettingsView::on_comboBoxFriendlyAI_currentTextChanged(const QString & arg1)
+void CSettingsView::on_comboBoxFriendlyAI_currentIndexChanged(int index)
 {
+	QString arg1 = ui->comboBoxFriendlyAI->itemData(index).toString();
 	Settings node = settings.write["server"]["friendlyAI"];
 	node->String() = arg1.toUtf8().data();
 }
 
-void CSettingsView::on_comboBoxNeutralAI_currentTextChanged(const QString & arg1)
+void CSettingsView::on_comboBoxNeutralAI_currentIndexChanged(int index)
 {
+	QString arg1 = ui->comboBoxNeutralAI->itemData(index).toString();
 	Settings node = settings.write["server"]["neutralAI"];
 	node->String() = arg1.toUtf8().data();
 }
 
-void CSettingsView::on_comboBoxEnemyAI_currentTextChanged(const QString & arg1)
+void CSettingsView::on_comboBoxEnemyAI_currentIndexChanged(int index)
 {
+	QString arg1 = ui->comboBoxEnemyAI->itemData(index).toString();
 	Settings node = settings.write["server"]["enemyAI"];
 	node->String() = arg1.toUtf8().data();
 }
@@ -657,14 +708,16 @@ void CSettingsView::on_buttonVSync_toggled(bool value)
 	ui->spinBoxFramerateLimit->setDisabled(settings["video"]["vsync"].Bool());
 }
 
-void CSettingsView::on_comboBoxEnemyPlayerAI_currentTextChanged(const QString &arg1)
+void CSettingsView::on_comboBoxEnemyPlayerAI_currentIndexChanged(int index)
 {
+	QString arg1 = ui->comboBoxEnemyPlayerAI->itemData(index).toString();
 	Settings node = settings.write["server"]["playerAI"];
 	node->String() = arg1.toUtf8().data();
 }
 
-void CSettingsView::on_comboBoxAlliedPlayerAI_currentTextChanged(const QString &arg1)
+void CSettingsView::on_comboBoxAlliedPlayerAI_currentIndexChanged(int index)
 {
+	QString arg1 = ui->comboBoxAlliedPlayerAI->itemData(index).toString();
 	Settings node = settings.write["server"]["alliedAI"];
 	node->String() = arg1.toUtf8().data();
 }

+ 10 - 5
launcher/settingsView/csettingsview_moc.h

@@ -42,9 +42,9 @@ public slots:
 private slots:
 	void on_comboBoxResolution_currentTextChanged(const QString & arg1);
 	void on_comboBoxFullScreen_currentIndexChanged(int index);
-	void on_comboBoxFriendlyAI_currentTextChanged(const QString & arg1);
-	void on_comboBoxNeutralAI_currentTextChanged(const QString & arg1);
-	void on_comboBoxEnemyAI_currentTextChanged(const QString & arg1);
+	void on_comboBoxFriendlyAI_currentIndexChanged(int index);
+	void on_comboBoxNeutralAI_currentIndexChanged(int index);
+	void on_comboBoxEnemyAI_currentIndexChanged(int index);
 	void on_spinBoxNetworkPort_valueChanged(int arg1);
 	void on_buttonShowIntro_toggled(bool value);
 	void on_buttonAllowPortrait_toggled(bool value);
@@ -63,8 +63,8 @@ private slots:
 	void on_buttonConfigEditor_clicked();
 	void on_spinBoxFramerateLimit_valueChanged(int arg1);
 	void on_buttonVSync_toggled(bool value);
-	void on_comboBoxEnemyPlayerAI_currentTextChanged(const QString &arg1);
-	void on_comboBoxAlliedPlayerAI_currentTextChanged(const QString &arg1);
+	void on_comboBoxEnemyPlayerAI_currentIndexChanged(int index);
+	void on_comboBoxAlliedPlayerAI_currentIndexChanged(int index);
 	void on_buttonAutoSavePrefix_toggled(bool value);
 	void on_spinBoxAutoSaveLimit_valueChanged(int arg1);
 	void on_lineEditAutoSavePrefix_textEdited(const QString &arg1);
@@ -107,4 +107,9 @@ private:
 	void fillValidResolutionsForScreen(int screenIndex);
 	void fillValidScalingRange();
 	QSize getPreferredRenderingResolution();
+
+	void fillValidAILibraries();
+	void fillValidCombatAILibraries(QComboBox *, QString activeAI);
+	void fillValidAdventureAILibraries(QComboBox *, QString activeAI);
+	void fillValidAnyAILibraries(QComboBox *, QString activeAI);
 };

+ 9 - 69
launcher/settingsView/csettingsview_moc.ui

@@ -47,9 +47,9 @@
       <property name="geometry">
        <rect>
         <x>0</x>
-        <y>0</y>
+        <y>-860</y>
         <width>729</width>
-        <height>1503</height>
+        <height>1758</height>
        </rect>
       </property>
       <layout class="QGridLayout" name="gridLayout" columnstretch="20,5,5,5,5,10">
@@ -83,7 +83,7 @@
          </property>
         </widget>
        </item>
-      <item row="64" column="1" colspan="5">
+       <item row="64" column="1" colspan="5">
         <widget class="QPushButton" name="buttonConfigEditor">
          <property name="text">
           <string>Open editor</string>
@@ -396,23 +396,8 @@
        <item row="50" column="1" colspan="5">
         <widget class="QComboBox" name="comboBoxEnemyPlayerAI">
          <property name="currentText">
-          <string notr="true">VCAI</string>
+          <string notr="true"/>
          </property>
-         <item>
-          <property name="text">
-           <string notr="true">VCAI</string>
-          </property>
-         </item>
-         <item>
-          <property name="text">
-           <string notr="true">Nullkiller</string>
-          </property>
-         </item>
-         <item>
-          <property name="text">
-           <string notr="true">Nullkiller2</string>
-          </property>
-         </item>
         </widget>
        </item>
        <item row="58" column="2" colspan="4">
@@ -428,23 +413,8 @@
        <item row="51" column="1" colspan="5">
         <widget class="QComboBox" name="comboBoxAlliedPlayerAI">
          <property name="currentText">
-          <string notr="true">VCAI</string>
+          <string notr="true"/>
          </property>
-         <item>
-          <property name="text">
-           <string notr="true">VCAI</string>
-          </property>
-         </item>
-         <item>
-          <property name="text">
-           <string notr="true">Nullkiller</string>
-          </property>
-         </item>
-         <item>
-          <property name="text">
-           <string notr="true">Nullkiller2</string>
-          </property>
-         </item>
         </widget>
        </item>
        <item row="4" column="0">
@@ -924,18 +894,8 @@
        <item row="52" column="1" colspan="5">
         <widget class="QComboBox" name="comboBoxNeutralAI">
          <property name="currentText">
-          <string notr="true">BattleAI</string>
+          <string notr="true"/>
          </property>
-         <item>
-          <property name="text">
-           <string notr="true">BattleAI</string>
-          </property>
-         </item>
-         <item>
-          <property name="text">
-           <string notr="true">StupidAI</string>
-          </property>
-         </item>
         </widget>
        </item>
        <item row="26" column="1" colspan="5">
@@ -1002,18 +962,8 @@
           <bool>false</bool>
          </property>
          <property name="currentText">
-          <string notr="true">BattleAI</string>
+          <string notr="true"/>
          </property>
-         <item>
-          <property name="text">
-           <string notr="true">BattleAI</string>
-          </property>
-         </item>
-         <item>
-          <property name="text">
-           <string notr="true">StupidAI</string>
-          </property>
-         </item>
         </widget>
        </item>
        <item row="4" column="5">
@@ -1122,18 +1072,8 @@
           <bool>false</bool>
          </property>
          <property name="currentText">
-          <string notr="true">BattleAI</string>
+          <string notr="true"/>
          </property>
-         <item>
-          <property name="text">
-           <string notr="true">BattleAI</string>
-          </property>
-         </item>
-         <item>
-          <property name="text">
-           <string notr="true">StupidAI</string>
-          </property>
-         </item>
         </widget>
        </item>
        <item row="59" column="2" colspan="4">
@@ -1548,7 +1488,7 @@ Fullscreen Exclusive Mode - the game will cover the entirety of your screen and
  <resources/>
  <connections/>
  <buttongroups>
-  <buttongroup name="buttonGroupFonts"/>
   <buttongroup name="buttonGroupValidation"/>
+  <buttongroup name="buttonGroupFonts"/>
  </buttongroups>
 </ui>

+ 14 - 7
lib/CMakeLists.txt

@@ -835,16 +835,23 @@ target_link_libraries(vcmi PUBLIC
 
 if(ENABLE_STATIC_LIBS AND ENABLE_CLIENT)
 	target_compile_definitions(vcmi PRIVATE STATIC_AI)
-	target_link_libraries(vcmi PRIVATE
-		BattleAI
-		EmptyAI
-		StupidAI
-		VCAI
-	)
+	target_link_libraries(vcmi PRIVATE EmptyAI VCAI)
 	if(ENABLE_NULLKILLER_AI)
 		target_link_libraries(vcmi PRIVATE Nullkiller)
-		target_link_libraries(vcmi PRIVATE Nullkiller2)
 	endif()
+
+	if(ENABLE_NULLKILLER2_AI)
+		target_link_libraries(vcmi PRIVATE Nullkiller)
+	endif()
+
+	if(ENABLE_STUPID_AI)
+		target_link_libraries(vcmi PRIVATE StupidAI)
+	endif()
+
+	if(ENABLE_BATTLE_AI)
+		target_link_libraries(vcmi PRIVATE BattleAI)
+	endif()
+
 endif()
 
 # no longer necessary, but might be useful to keep in future

+ 2 - 2
test/CMakeLists.txt

@@ -140,7 +140,7 @@ if(ENABLE_ERM)
 	)
 endif()
 
-if(ENABLE_NULLKILLER_AI)
+if(ENABLE_NULLKILLER2_AI)
 	# When not static, linking the library below is not enough, we need the .cpp files as well
 	file(GLOB_RECURSE NULLKILLER2_TEST_SRCS "../AI/Nullkiller2/*.cpp")
 	list(FILTER NULLKILLER2_TEST_SRCS EXCLUDE REGEX ".*main\\.cpp$")
@@ -198,7 +198,7 @@ target_link_libraries(vcmitest PRIVATE gtest gmock vcmi ${SYSTEM_LIBS})
 if(ENABLE_LUA)
 	target_link_libraries(vcmitest PRIVATE vcmiLua)
 endif()
-if(ENABLE_NULLKILLER_AI)
+if(ENABLE_NULLKILLER2_AI)
 	target_link_libraries(vcmitest PUBLIC Nullkiller2)
 endif()