mirror of https://github.com/OpenTTD/OpenTTD
(svn r1077) Implements scripts/autoexec.scr to get executed on game starting (sign_de)
- %! allows to merge alias parameters - \% allows to use % in alias strings - "alias" command now overwrites the old alias list entryrelease/0.4.5
parent
77e882c3bd
commit
a9972399c5
29
console.c
29
console.c
|
@ -602,6 +602,7 @@ void IConsoleAliasExec(const char* cmdline, char* tokens[20], byte tokentypes[20
|
||||||
if (cmdline[i] == '%') {
|
if (cmdline[i] == '%') {
|
||||||
i++;
|
i++;
|
||||||
if (cmdline[i] == '+') {
|
if (cmdline[i] == '+') {
|
||||||
|
// all params seperated: "[param 1]" "[param 2]"
|
||||||
t=1;
|
t=1;
|
||||||
while ((tokens[t]!=NULL) && (t<20) &&
|
while ((tokens[t]!=NULL) && (t<20) &&
|
||||||
((tokentypes[t] == ICONSOLE_VAR_STRING) || (tokentypes[t] == ICONSOLE_VAR_UNKNOWN))) {
|
((tokentypes[t] == ICONSOLE_VAR_STRING) || (tokentypes[t] == ICONSOLE_VAR_UNKNOWN))) {
|
||||||
|
@ -617,10 +618,30 @@ void IConsoleAliasExec(const char* cmdline, char* tokens[20], byte tokentypes[20
|
||||||
x += l2+3;
|
x += l2+3;
|
||||||
t++;
|
t++;
|
||||||
}
|
}
|
||||||
|
} else if (cmdline[i] == '!') {
|
||||||
|
// merge the params to one: "[param 1] [param 2] [param 3...]"
|
||||||
|
t=1;
|
||||||
|
*linestream = '"';
|
||||||
|
linestream++;
|
||||||
|
while ((tokens[t]!=NULL) && (t<20) &&
|
||||||
|
((tokentypes[t] == ICONSOLE_VAR_STRING) || (tokentypes[t] == ICONSOLE_VAR_UNKNOWN))) {
|
||||||
|
int l2 = strlen(tokens[t]);
|
||||||
|
memcpy(linestream,tokens[t],l2);
|
||||||
|
linestream += l2;
|
||||||
|
*linestream = ' ';
|
||||||
|
linestream++;
|
||||||
|
x += l2+1;
|
||||||
|
t++;
|
||||||
|
}
|
||||||
|
*linestream = '"';
|
||||||
|
linestream++;
|
||||||
|
x += 2;
|
||||||
} else {
|
} else {
|
||||||
|
// one specific parameter: %A = [param 1] %B = [param 2] ...
|
||||||
int l2;
|
int l2;
|
||||||
t = ((byte)cmdline[i]) - 64;
|
t = ((byte)cmdline[i]) - 64;
|
||||||
if ((t<20) && (tokens[t]!=NULL)) {
|
if ((t<20) && (tokens[t]!=NULL) &&
|
||||||
|
((tokentypes[t] == ICONSOLE_VAR_STRING) || (tokentypes[t] == ICONSOLE_VAR_UNKNOWN))) {
|
||||||
l2 = strlen(tokens[t]);
|
l2 = strlen(tokens[t]);
|
||||||
*linestream = '"';
|
*linestream = '"';
|
||||||
linestream++;
|
linestream++;
|
||||||
|
@ -632,6 +653,7 @@ void IConsoleAliasExec(const char* cmdline, char* tokens[20], byte tokentypes[20
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (cmdline[i] == '\\') {
|
} else if (cmdline[i] == '\\') {
|
||||||
|
// \\ = \ \' = ' \% = %
|
||||||
i++;
|
i++;
|
||||||
if (cmdline[i] == '\\') {
|
if (cmdline[i] == '\\') {
|
||||||
*linestream = '\\';
|
*linestream = '\\';
|
||||||
|
@ -639,11 +661,16 @@ void IConsoleAliasExec(const char* cmdline, char* tokens[20], byte tokentypes[20
|
||||||
} else if (cmdline[i] == '\'') {
|
} else if (cmdline[i] == '\'') {
|
||||||
*linestream = '\'';
|
*linestream = '\'';
|
||||||
linestream++;
|
linestream++;
|
||||||
|
} else if (cmdline[i] == '%') {
|
||||||
|
*linestream = '%';
|
||||||
|
linestream++;
|
||||||
}
|
}
|
||||||
} else if (cmdline[i] == '\'') {
|
} else if (cmdline[i] == '\'') {
|
||||||
|
// ' = "
|
||||||
*linestream = '"';
|
*linestream = '"';
|
||||||
linestream++;
|
linestream++;
|
||||||
} else if (cmdline[i] == ';') {
|
} else if (cmdline[i] == ';') {
|
||||||
|
// ; = start a new line
|
||||||
c++;
|
c++;
|
||||||
*linestream = '\0';
|
*linestream = '\0';
|
||||||
linestream += 1024 - (x % 1024);
|
linestream += 1024 - (x % 1024);
|
||||||
|
|
|
@ -85,6 +85,8 @@ typedef struct _iconsole_alias {
|
||||||
void* _next;
|
void* _next;
|
||||||
} _iconsole_alias;
|
} _iconsole_alias;
|
||||||
|
|
||||||
|
_iconsole_alias* IConsoleAliasGet(const char* name);
|
||||||
|
|
||||||
// ** console parser ** //
|
// ** console parser ** //
|
||||||
|
|
||||||
_iconsole_cmd* _iconsole_cmds; // list of registred commands
|
_iconsole_cmd* _iconsole_cmds; // list of registred commands
|
||||||
|
|
|
@ -367,8 +367,17 @@ DEF_CONSOLE_CMD(ConPrintFC)
|
||||||
|
|
||||||
DEF_CONSOLE_CMD(ConAlias)
|
DEF_CONSOLE_CMD(ConAlias)
|
||||||
{
|
{
|
||||||
|
_iconsole_alias* alias;
|
||||||
|
|
||||||
if (argc < 3) return NULL;
|
if (argc < 3) return NULL;
|
||||||
IConsoleAliasRegister(argv[1],argv[2]);
|
|
||||||
|
alias = IConsoleAliasGet(argv[1]);
|
||||||
|
if (alias == NULL) {
|
||||||
|
IConsoleAliasRegister(argv[1],argv[2]);
|
||||||
|
} else {
|
||||||
|
free(alias->cmdline);
|
||||||
|
alias->cmdline = strdup(argv[2]);
|
||||||
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ OpenTTD supports scripts.
|
||||||
- 'on_dedicated.scr' is additionally executed when you start a dedicated server
|
- 'on_dedicated.scr' is additionally executed when you start a dedicated server
|
||||||
- 'pre_server.scr' is executed before the server is started
|
- 'pre_server.scr' is executed before the server is started
|
||||||
- 'pre_dedicated.scr' is additionally executed when you start a dedicated server
|
- 'pre_dedicated.scr' is additionally executed when you start a dedicated server
|
||||||
|
- 'autoexec.scr' is executed on gamestart [use this for custom aliases per ex.]
|
||||||
|
|
||||||
For examples how a script can look, check the .example examples.
|
For examples how a script can look, check the .example examples.
|
||||||
|
|
||||||
|
|
2
ttd.c
2
ttd.c
|
@ -644,6 +644,8 @@ int ttd_main(int argc, char* argv[])
|
||||||
|
|
||||||
// initialize the ingame console
|
// initialize the ingame console
|
||||||
IConsoleInit();
|
IConsoleInit();
|
||||||
|
IConsoleCmdExec("exec scripts/autoexec.scr 0");
|
||||||
|
|
||||||
InitPlayerRandoms();
|
InitPlayerRandoms();
|
||||||
|
|
||||||
#ifdef ENABLE_NETWORK
|
#ifdef ENABLE_NETWORK
|
||||||
|
|
Loading…
Reference in New Issue