Skip to content

Commit

Permalink
Allow multiplayer autogames to be started from the command line.
Browse files Browse the repository at this point in the history
Usage: Start two clients, one with --autogame --host and one with
--autogame --join=127.0.0.1

Command line autogames will now use semperfi.js AI automatically.
  • Loading branch information
perim committed Jan 3, 2016
1 parent 4947489 commit c6e96a7
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 23 deletions.
8 changes: 0 additions & 8 deletions data/mp/multiplay/skirmish/semperfi.js
Expand Up @@ -26,19 +26,11 @@ var fundamentalsTriggered = false; // avoid triggering it multiple times

function log(message)
{
if (me == selectedPlayer)
{
console(message);
}
dump(gameTime + " : " + message);
}

function logObj(obj, message)
{
if (obj.selected)
{
console(message);
}
dump(gameTime + " [" + obj.name + " id=" + obj.id + "] > " + message);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/script/chat_lexer.cpp
Expand Up @@ -2499,7 +2499,7 @@ void chat_free (void * ptr )


/* Set the current input buffer for the lexer */
void chatSetInputBuffer(char *pBuffer, UDWORD size)
void chatSetInputBuffer(const char *pBuffer, UDWORD size)
{
pInputBuffer = pBuffer;
pEndBuffer = pBuffer + size;
Expand Down
2 changes: 1 addition & 1 deletion lib/script/chat_parser.cpp
Expand Up @@ -2554,7 +2554,7 @@ yyparse ()


/* Initialize Bison and start chat processing */
bool chatLoad(char *pData, UDWORD size)
bool chatLoad(const char *pData, UDWORD size)
{
SDWORD cmdIndex,parseResult;

Expand Down
4 changes: 2 additions & 2 deletions lib/script/chat_processing.h
Expand Up @@ -64,9 +64,9 @@ extern CHAT_MSG chat_msg;
extern void chatGetErrorData(int *pLine, char **ppText);

/* Set the current input buffer for the lexer */
extern void chatSetInputBuffer(char *pBuffer, UDWORD size);
extern void chatSetInputBuffer(const char *pBuffer, UDWORD size);

// Load message
extern bool chatLoad(char *pData, UDWORD size);
extern bool chatLoad(const char *pData, UDWORD size);

#endif
1 change: 1 addition & 0 deletions src/levels.cpp
Expand Up @@ -1045,6 +1045,7 @@ bool levLoadData(char const *name, Sha256 const *hash, char *pSaveName, GAME_TYP
if (autogame_enabled())
{
gameTimeSetMod(Rational(500));
jsAutogameSpecific("multiplay/skirmish/semperfi.js", selectedPlayer);
}

return true;
Expand Down
11 changes: 10 additions & 1 deletion src/multiint.cpp
Expand Up @@ -60,7 +60,7 @@
#include "display3d.h"
#include "objmem.h"
#include "gateway.h"

#include "clparse.h"
#include "configuration.h"
#include "intdisplay.h"
#include "design.h"
Expand Down Expand Up @@ -3870,6 +3870,15 @@ bool startMultiOptions(bool bReenter)

loadMapPreview(false);

if (autogame_enabled())
{
if (!ingame.localJoiningInProgress)
{
processMultiopWidgets(MULTIOP_HOST);
}
SendReadyRequest(selectedPlayer, true);
}

return true;
}

Expand Down
23 changes: 14 additions & 9 deletions src/qtscript.cpp
Expand Up @@ -867,6 +867,19 @@ bool jsEvaluate(QScriptEngine *engine, const QString &text)
return true;
}

void jsAutogameSpecific(const QString &name, int player)
{
QScriptEngine *engine = loadPlayerScript(name, player, DIFFICULTY_MEDIUM);
if (!engine)
{
console("Failed to load selected AI! Check your logs to see why.");
return;
}
console("Loaded the %s AI script for current player!", name.toUtf8().constData());
callFunction(engine, "eventGameInit", QScriptValueList());
callFunction(engine, "eventStartLevel", QScriptValueList());
}

void jsAutogame()
{
QString srcPath(PHYSFS_getWriteDir());
Expand All @@ -879,15 +892,7 @@ void jsAutogame()
console("No file specified");
return;
}
QScriptEngine *engine = loadPlayerScript("scripts/" + basename.fileName(), selectedPlayer, DIFFICULTY_MEDIUM);
if (!engine)
{
console("Failed to load selected AI! Check your logs to see why.");
return;
}
console("Loaded the %s AI script for current player!", path.toUtf8().constData());
callFunction(engine, "eventGameInit", QScriptValueList());
callFunction(engine, "eventStartLevel", QScriptValueList());
jsAutogameSpecific("scripts/" + basename.fileName(), selectedPlayer);
}

void jsShowDebug()
Expand Down
5 changes: 4 additions & 1 deletion src/qtscript.h
Expand Up @@ -82,9 +82,12 @@ void scriptRemoveObject(BASE_OBJECT *psObj);
/// Open debug GUI
void jsShowDebug();

/// Choose autogame AI
/// Choose autogame AI with GUI
void jsAutogame();

/// Choose a specific autogame AI
void jsAutogameSpecific(const QString &name, int player);

/// Run-time code from user
bool jsEvaluate(QScriptEngine *engine, const QString &text);

Expand Down

0 comments on commit c6e96a7

Please sign in to comment.