ValidAIs.lua - Page 7

ValidAIs.lua

Requests for features in the spring code.

Moderator: Moderators

raaar
Metal Factions Developer
Posts: 1094
Joined: 20 Feb 2010, 12:17

Re: ValidAIs.lua

Post by raaar »

meanwhile, a new player tried MF and went into a battle against AI. Did he pick MFAI? of course he didn't. He picked some other AI which idled throughout...

The lack of standardized AI filter for games after all this time is incompetence or negligence, or both. Gross.

Then we complain about poor player retention.
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Re: ValidAIs.lua

Post by Forboding Angel »

raaar wrote: We NEED a standard way for games to define this for the lobbies, and maybe even for the engine itself.
Most of us have resorted to stripping it out of the engine that we distribute. If you aren't distributing your own build then I dunno what to tell you. I highly recommend putting metal factions on itch.io
gajop
Moderator
Posts: 3051
Joined: 05 Aug 2009, 20:42

Re: ValidAIs.lua

Post by gajop »

It's an open source project and you are completely responsible for everything your game uses: lobby client, server, engine, infra.
If you delegate any of this responsibility to other people you cannot complain if things aren't perfect
raaar
Metal Factions Developer
Posts: 1094
Joined: 20 Feb 2010, 12:17

Re: ValidAIs.lua

Post by raaar »

That line of thought leads to incompatible packages for each game (lobby, engine, etc.) that break other games. It won't end well.

Shared environment won't work without standards.

There's no point in making a modified lobby if 90% of the potential players access the game through either the official springlobby or some of those other packages.

It's not like i'm asking for some exotic feature here...
raaar
Metal Factions Developer
Posts: 1094
Joined: 20 Feb 2010, 12:17

Re: ValidAIs.lua

Post by raaar »

buuump
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Re: ValidAIs.lua

Post by Forboding Angel »

I genuinely don't understand why this doesn't already exist.
User avatar
ThinkSome
Posts: 387
Joined: 14 Jun 2015, 13:36

Re: ValidAIs.lua

Post by ThinkSome »

Everyone asks about ValidAIs.lua, but what about InvalidAIs.lua? :lol:

Code: Select all

diff --git a/src/gui/hosting/addbotdialog.cpp b/src/gui/hosting/addbotdialog.cpp
index 3580e24e7..010d0c75d 100644
--- a/src/gui/hosting/addbotdialog.cpp
+++ b/src/gui/hosting/addbotdialog.cpp
@@ -9,6 +9,7 @@
 #include <wx/dir.h>
 #include <wx/filename.h>
 #include <wx/listctrl.h>
+#include <wx/log.h>
 #include <wx/sizer.h>
 #include <wx/statline.h>
 #include <wx/stattext.h>
@@ -23,6 +24,11 @@
 #include "utils/conversion.h"
 #include "utils/lslconversion.h"
 
+static const char *banned_AIs[] = {
+	"AAI", "CircuitAI", "CppTestAI",
+	"E323AI", "KAIK", "NullAI", "RAI", "Shard"
+};
+
 BEGIN_EVENT_TABLE(AddBotDialog, wxDialog)
 EVT_BUTTON(ADDBOT_CANCEL, AddBotDialog::OnClose)
 EVT_BUTTON(ADDBOT_ADD, AddBotDialog::OnAddBot)
@@ -138,7 +144,7 @@ wxString AddBotDialog::GetNick()
 
 wxString AddBotDialog::Get(const std::string& section)
 {
-	const auto sel = m_ai->GetSelection();
+	const auto sel = GetAIType();
 	const auto infos = LSL::usync().GetAIInfos(sel);
 	const auto namepos = LSL::Util::IndexInSequence(infos, section);
 	if (namepos == LSL::lslNotFound)
@@ -158,7 +164,7 @@ wxString AddBotDialog::GetAIVersion()
 
 int AddBotDialog::GetAIType()
 {
-	return m_ai->GetSelection();
+	return m_valid_ai_index_map.at (m_ai->GetSelection());
 }
 
 wxString AddBotDialog::RefineAIName(const wxString& name)
@@ -179,19 +185,39 @@ wxString AddBotDialog::GetAiRawName()
 {
 	//    if ( m_ais.GetCount() < m_ai->GetSelection() )
 	//        return wxEmptyString;
-	return m_ais[m_ai->GetSelection()];
+	return m_ais [GetAIType()];
 }
 
 void AddBotDialog::ReloadAIList()
 {
+	LSL::StringVector ais;
 	try {
-		m_ais = lslTowxArrayString(LSL::usync().GetAIList(m_battle.GetHostGameName()));
-	} catch (...) {
+		ais = LSL::usync().GetAIList(m_battle.GetHostGameName());
+	} catch (std::exception& ex) {
+		wxLogWarning("Exception while loading AIs: " + wxString(ex.what()));
 	}
 
 	m_ai->Clear();
-	for (unsigned int i = 0; i < m_ais.GetCount(); i++)
-		m_ai->Append(RefineAIName(m_ais[i]));
+	m_ais.clear();
+	m_valid_ai_index_map.clear();
+	for (unsigned int i = 0; i < ais.size(); ++i) {
+		std::string &AINameVersion = ais.at(i);
+		bool matched = false; // either this or goto...
+
+		for (unsigned int j = 0; j < sizeof (banned_AIs) / sizeof(char *); ++j) {
+			const char *ai_str = banned_AIs[j];
+			if (std::string::npos != AINameVersion.find(ai_str)) {
+				matched = true;
+				break;
+			}
+		}
+		if (!matched) {
+			wxString wxAINV (AINameVersion);
+			m_ais.Add(wxAINV);
+			m_ai->Append(RefineAIName(wxAINV));
+			m_valid_ai_index_map.push_back(i);
+		}
+	}
 	if (m_ais.GetCount() > 0) {
 		m_ai->SetStringSelection(sett().GetLastAI());
 		if (m_ai->GetStringSelection() == wxEmptyString)
diff --git a/src/gui/hosting/addbotdialog.h b/src/gui/hosting/addbotdialog.h
index 334c99747..da7c34ccf 100644
--- a/src/gui/hosting/addbotdialog.h
+++ b/src/gui/hosting/addbotdialog.h
@@ -5,7 +5,10 @@
 
 #include <wx/dialog.h>
 #include <map>
+#include <vector>
+
 #include "gui/windowattributespickle.h"
+
 class wxTextCtrl;
 class wxStaticText;
 class wxChoice;
@@ -72,6 +75,7 @@ private:
 
 	bool m_sp;
 
+	std::vector<int> m_valid_ai_index_map;
 	wxString RefineAIName(const wxString& name);
 
 	enum {
This is a gift to raaar for playing s44 with me. Enjoy.
raaar
Metal Factions Developer
Posts: 1094
Joined: 20 Feb 2010, 12:17

Re: ValidAIs.lua

Post by raaar »

Having defaults is fine as a short-term fix but in either case it should be a config property.

That way whoever wants to test AIs could remove them from the banned list.
raaar
Metal Factions Developer
Posts: 1094
Joined: 20 Feb 2010, 12:17

Re: ValidAIs.lua

Post by raaar »

atm theres luaAI.lua which allows game devs to specify luaAI options and follows this format

Code: Select all

return {
  {
    name = 'AI NAME 1',
    desc = 'AI DESCRIPTION 1'
  },
  {
    name = 'AI NAME 2',
    desc = 'AI DESCRIPTION 2'
  },
  ...

A validAIs.lua could use a similar format, but list external AIs and use regex on the AI names to support ranges of versions:

Code: Select all

return {
  {
    name = 'AAI*',
    desc = 'AI DESCRIPTION 1'
  },
  {
    name = 'KAIK*',
    desc = 'AI DESCRIPTION 2'
  },
  ...
as suggested before, when selecting AIs in battles, lobby clients could then differentiate AI between "recommended" (listed in luaAI OR validAIs) and "other/may not work" instead of just omitting the ones not whitelisted. This would still allow external AI development without input from the game devs.
Post Reply

Return to “Feature Requests”