aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHolger Zickner <[email protected]>2004-08-19 20:56:41 +0000
committerHolger Zickner <[email protected]>2004-08-19 20:56:41 +0000
commita1a1c7334c9b03113344078d2d7977193a1d7b5e (patch)
tree194eea388d4f118763383ee9661f9fb6c6ee5965
parent59a051a177d1a3730a332bee518dabb086349e96 (diff)
command line completion
remove references to GameBase.gi from Cmd
-rw-r--r--src/jake2/client/Key.java72
-rw-r--r--src/jake2/game/Cmd.java120
-rw-r--r--src/jake2/qcommon/Cvar.java22
3 files changed, 127 insertions, 87 deletions
diff --git a/src/jake2/client/Key.java b/src/jake2/client/Key.java
index 6d011cb..d1c1fc8 100644
--- a/src/jake2/client/Key.java
+++ b/src/jake2/client/Key.java
@@ -2,7 +2,7 @@
* Key.java
* Copyright (C) 2003
*
- * $Id: Key.java,v 1.5 2004-07-23 10:02:49 hzi Exp $
+ * $Id: Key.java,v 1.6 2004-08-19 20:56:41 hzi Exp $
*/
/*
Copyright (C) 1997-2001 Id Software, Inc.
@@ -25,17 +25,16 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package jake2.client;
-import java.io.IOException;
-import java.io.RandomAccessFile;
-
import jake2.Defines;
import jake2.Globals;
import jake2.game.Cmd;
import jake2.qcommon.*;
-import jake2.qcommon.Cbuf;
-import jake2.qcommon.Com;
import jake2.util.Lib;
+import java.io.IOException;
+import java.io.RandomAccessFile;
+import java.util.Vector;
+
/**
* Key
*/
@@ -673,26 +672,49 @@ public class Key extends Globals {
}
+ private static void printCompletions(String type, Vector compl) {
+ Com.Printf(type);
+ for (int i = 0; i < compl.size(); i++) {
+ Com.Printf((String)compl.get(i) + " ");
+ }
+ Com.Printf("\n");
+ }
+
static void CompleteCommand() {
- // 00166 char *cmd, *s;
- // 00167
- // 00168 s = key_lines[edit_line]+1;
- // 00169 if (*s == '\\' || *s == '/')
- // 00170 s++;
- // 00171
- // 00172 cmd = Cmd_CompleteCommand (s);
- // 00173 if (!cmd)
- // 00174 cmd = Cvar_CompleteVariable (s);
- // 00175 if (cmd)
- // 00176 {
- // 00177 key_lines[edit_line][1] = '/';
- // 00178 strcpy (key_lines[edit_line]+2, cmd);
- // 00179 key_linepos = strlen(cmd)+2;
- // 00180 key_lines[edit_line][key_linepos] = ' ';
- // 00181 key_linepos++;
- // 00182 key_lines[edit_line][key_linepos] = 0;
- // 00183 return;
- // 00184 }
+
+ int start = 1;
+ if (key_lines[edit_line][start] == '\\' || key_lines[edit_line][start] == '/')
+ start++;
+
+ int end = start;
+ while (key_lines[edit_line][end] != 0) end++;
+
+ String s = new String(key_lines[edit_line], start, end-start);
+
+ Vector cmds = Cmd.CompleteCommand(s);
+ Vector vars = Cvar.CompleteVariable(s);
+
+ int c = cmds.size();
+ int v = vars.size();
+
+ if ((c + v) > 1) {
+ if (c > 0) printCompletions("\nCommands:\n", cmds);
+ if (v > 0) printCompletions("\nVariables:\n", vars);
+ return;
+ } else if (c == 1) {
+ s = (String)cmds.get(0);
+ } else if (v == 1) {
+ s = (String)vars.get(0);
+ } else return;
+
+ key_lines[edit_line][1] = '/';
+ byte[] bytes = s.getBytes();
+ System.arraycopy(bytes, 0, key_lines[edit_line], 2, bytes.length);
+ key_linepos = bytes.length + 2;
+ key_lines[edit_line][key_linepos++] = ' ';
+ key_lines[edit_line][key_linepos] = 0;
+
+ return;
}
public static xcommand_t Bind_f = new xcommand_t() {
diff --git a/src/jake2/game/Cmd.java b/src/jake2/game/Cmd.java
index 22d35a5..591e9fc 100644
--- a/src/jake2/game/Cmd.java
+++ b/src/jake2/game/Cmd.java
@@ -2,7 +2,7 @@
* Cmd.java
* Copyright (C) 2003
*
- * $Id: Cmd.java,v 1.4 2004-07-23 10:07:14 hzi Exp $
+ * $Id: Cmd.java,v 1.5 2004-08-19 20:56:41 hzi Exp $
*/
/*
Copyright (C) 1997-2001 Id Software, Inc.
@@ -28,9 +28,11 @@ package jake2.game;
import jake2.Defines;
import jake2.Globals;
import jake2.qcommon.*;
+import jake2.server.SV_GAME;
import jake2.util.Lib;
import java.util.Arrays;
+import java.util.Vector;
/**
* Cmd
@@ -504,21 +506,21 @@ public final class Cmd extends PlayerView
if (GameBase.deathmatch.value == 0 && GameBase.sv_cheats.value == 0)
{
- GameBase.gi.cprintf(ent, Defines.PRINT_HIGH, "You must run the server with '+set cheats 1' to enable this command.\n");
+ SV_GAME.PF_cprintf(ent, Defines.PRINT_HIGH, "You must run the server with '+set cheats 1' to enable this command.\n");
return;
}
- name= GameBase.gi.args();
+ name= Cmd.Args();
if (0 == Lib.Q_stricmp(name, "all"))
give_all= true;
else
give_all= false;
- if (give_all || 0 == Lib.Q_stricmp(GameBase.gi.argv(1), "health"))
+ if (give_all || 0 == Lib.Q_stricmp(Cmd.Argv(1), "health"))
{
- if (GameBase.gi.argc() == 3)
- ent.health= Lib.atoi(GameBase.gi.argv(2));
+ if (Cmd.Argc() == 3)
+ ent.health= Lib.atoi(Cmd.Argv(2));
else
ent.health= ent.max_health;
if (!give_all)
@@ -604,18 +606,18 @@ public final class Cmd extends PlayerView
it= GameUtil.FindItem(name);
if (it == null)
{
- name= GameBase.gi.argv(1);
+ name= Cmd.Argv(1);
it= GameUtil.FindItem(name);
if (it == null)
{
- GameBase.gi.cprintf(ent, Defines.PRINT_HIGH, "unknown item\n");
+ SV_GAME.PF_cprintf(ent, Defines.PRINT_HIGH, "unknown item\n");
return;
}
}
if (it.pickup == null)
{
- GameBase.gi.cprintf(ent, Defines.PRINT_HIGH, "non-pickup item\n");
+ SV_GAME.PF_cprintf(ent, Defines.PRINT_HIGH, "non-pickup item\n");
return;
}
@@ -623,8 +625,8 @@ public final class Cmd extends PlayerView
if ((it.flags & Defines.IT_AMMO) != 0)
{
- if (GameBase.gi.argc() == 3)
- ent.client.pers.inventory[index]= Lib.atoi(GameBase.gi.argv(2));
+ if (Cmd.Argc() == 3)
+ ent.client.pers.inventory[index]= Lib.atoi(Cmd.Argv(2));
else
ent.client.pers.inventory[index] += it.quantity;
}
@@ -654,7 +656,7 @@ public final class Cmd extends PlayerView
if (GameBase.deathmatch.value == 0 && GameBase.sv_cheats.value == 0)
{
- GameBase.gi.cprintf(ent, Defines.PRINT_HIGH, "You must run the server with '+set cheats 1' to enable this command.\n");
+ SV_GAME.PF_cprintf(ent, Defines.PRINT_HIGH, "You must run the server with '+set cheats 1' to enable this command.\n");
return;
}
@@ -664,7 +666,7 @@ public final class Cmd extends PlayerView
else
msg= "godmode ON\n";
- GameBase.gi.cprintf(ent, Defines.PRINT_HIGH, msg);
+ SV_GAME.PF_cprintf(ent, Defines.PRINT_HIGH, msg);
}
/*
@@ -682,7 +684,7 @@ public final class Cmd extends PlayerView
if (GameBase.deathmatch.value != 0 && GameBase.sv_cheats.value == 0)
{
- GameBase.gi.cprintf(ent, Defines.PRINT_HIGH, "You must run the server with '+set cheats 1' to enable this command.\n");
+ SV_GAME.PF_cprintf(ent, Defines.PRINT_HIGH, "You must run the server with '+set cheats 1' to enable this command.\n");
return;
}
@@ -692,7 +694,7 @@ public final class Cmd extends PlayerView
else
msg= "notarget ON\n";
- GameBase.gi.cprintf(ent, Defines.PRINT_HIGH, msg);
+ SV_GAME.PF_cprintf(ent, Defines.PRINT_HIGH, msg);
}
/*
@@ -708,7 +710,7 @@ public final class Cmd extends PlayerView
if (GameBase.deathmatch.value != 0 && GameBase.sv_cheats.value == 0)
{
- GameBase.gi.cprintf(ent, Defines.PRINT_HIGH, "You must run the server with '+set cheats 1' to enable this command.\n");
+ SV_GAME.PF_cprintf(ent, Defines.PRINT_HIGH, "You must run the server with '+set cheats 1' to enable this command.\n");
return;
}
@@ -723,7 +725,7 @@ public final class Cmd extends PlayerView
msg= "noclip ON\n";
}
- GameBase.gi.cprintf(ent, Defines.PRINT_HIGH, msg);
+ SV_GAME.PF_cprintf(ent, Defines.PRINT_HIGH, msg);
}
/*
@@ -739,22 +741,22 @@ public final class Cmd extends PlayerView
gitem_t it;
String s;
- s= GameBase.gi.args();
+ s= Cmd.Args();
it= GameUtil.FindItem(s);
if (it == null)
{
- GameBase.gi.cprintf(ent, Defines.PRINT_HIGH, "unknown item: " + s + "\n");
+ SV_GAME.PF_cprintf(ent, Defines.PRINT_HIGH, "unknown item: " + s + "\n");
return;
}
if (it.use == null)
{
- GameBase.gi.cprintf(ent, Defines.PRINT_HIGH, "Item is not usable.\n");
+ SV_GAME.PF_cprintf(ent, Defines.PRINT_HIGH, "Item is not usable.\n");
return;
}
index= GameUtil.ITEM_INDEX(it);
if (0 == ent.client.pers.inventory[index])
{
- GameBase.gi.cprintf(ent, Defines.PRINT_HIGH, "Out of item: " + s + "\n");
+ SV_GAME.PF_cprintf(ent, Defines.PRINT_HIGH, "Out of item: " + s + "\n");
return;
}
@@ -774,22 +776,22 @@ public final class Cmd extends PlayerView
gitem_t it;
String s;
- s= GameBase.gi.args();
+ s= Cmd.Args();
it= GameUtil.FindItem(s);
if (it == null)
{
- GameBase.gi.cprintf(ent, Defines.PRINT_HIGH, "unknown item: " + s + "\n");
+ SV_GAME.PF_cprintf(ent, Defines.PRINT_HIGH, "unknown item: " + s + "\n");
return;
}
if (it.drop == null)
{
- GameBase.gi.cprintf(ent, Defines.PRINT_HIGH, "Item is not dropable.\n");
+ SV_GAME.PF_cprintf(ent, Defines.PRINT_HIGH, "Item is not dropable.\n");
return;
}
index= GameUtil.ITEM_INDEX(it);
if (0 == ent.client.pers.inventory[index])
{
- GameBase.gi.cprintf(ent, Defines.PRINT_HIGH, "Out of item: " + s + "\n");
+ SV_GAME.PF_cprintf(ent, Defines.PRINT_HIGH, "Out of item: " + s + "\n");
return;
}
@@ -840,14 +842,14 @@ public final class Cmd extends PlayerView
if (ent.client.pers.selected_item == -1)
{
- GameBase.gi.cprintf(ent, Defines.PRINT_HIGH, "No item to use.\n");
+ SV_GAME.PF_cprintf(ent, Defines.PRINT_HIGH, "No item to use.\n");
return;
}
it= GameAI.itemlist[ent.client.pers.selected_item];
if (it.use == null)
{
- GameBase.gi.cprintf(ent, Defines.PRINT_HIGH, "Item is not usable.\n");
+ SV_GAME.PF_cprintf(ent, Defines.PRINT_HIGH, "Item is not usable.\n");
return;
}
it.use.use(ent, it);
@@ -970,14 +972,14 @@ public final class Cmd extends PlayerView
if (ent.client.pers.selected_item == -1)
{
- GameBase.gi.cprintf(ent, Defines.PRINT_HIGH, "No item to drop.\n");
+ SV_GAME.PF_cprintf(ent, Defines.PRINT_HIGH, "No item to drop.\n");
return;
}
it= GameAI.itemlist[ent.client.pers.selected_item];
if (it.drop == null)
{
- GameBase.gi.cprintf(ent, Defines.PRINT_HIGH, "Item is not dropable.\n");
+ SV_GAME.PF_cprintf(ent, Defines.PRINT_HIGH, "Item is not dropable.\n");
return;
}
it.drop.drop(ent, it);
@@ -1117,7 +1119,7 @@ public final class Cmd extends PlayerView
large += small;
}
- GameBase.gi.cprintf(ent, Defines.PRINT_HIGH, "" + large + "\n" + count + " players\n");
+ SV_GAME.PF_cprintf(ent, Defines.PRINT_HIGH, "" + large + "\n" + count + " players\n");
}
/*
@@ -1129,7 +1131,7 @@ public final class Cmd extends PlayerView
{
int i;
- i= Lib.atoi(GameBase.gi.argv(1));
+ i= Lib.atoi(Cmd.Argv(1));
// can't wave when ducked
if ((ent.client.ps.pmove.pm_flags & Defines.PMF_DUCKED) != 0)
@@ -1143,28 +1145,28 @@ public final class Cmd extends PlayerView
switch (i)
{
case 0 :
- GameBase.gi.cprintf(ent, Defines.PRINT_HIGH, "flipoff\n");
+ SV_GAME.PF_cprintf(ent, Defines.PRINT_HIGH, "flipoff\n");
ent.s.frame= M_Player.FRAME_flip01 - 1;
ent.client.anim_end= M_Player.FRAME_flip12;
break;
case 1 :
- GameBase.gi.cprintf(ent, Defines.PRINT_HIGH, "salute\n");
+ SV_GAME.PF_cprintf(ent, Defines.PRINT_HIGH, "salute\n");
ent.s.frame= M_Player.FRAME_salute01 - 1;
ent.client.anim_end= M_Player.FRAME_salute11;
break;
case 2 :
- GameBase.gi.cprintf(ent, Defines.PRINT_HIGH, "taunt\n");
+ SV_GAME.PF_cprintf(ent, Defines.PRINT_HIGH, "taunt\n");
ent.s.frame= M_Player.FRAME_taunt01 - 1;
ent.client.anim_end= M_Player.FRAME_taunt17;
break;
case 3 :
- GameBase.gi.cprintf(ent, Defines.PRINT_HIGH, "wave\n");
+ SV_GAME.PF_cprintf(ent, Defines.PRINT_HIGH, "wave\n");
ent.s.frame= M_Player.FRAME_wave01 - 1;
ent.client.anim_end= M_Player.FRAME_wave11;
break;
case 4 :
default :
- GameBase.gi.cprintf(ent, Defines.PRINT_HIGH, "point\n");
+ SV_GAME.PF_cprintf(ent, Defines.PRINT_HIGH, "point\n");
ent.s.frame= M_Player.FRAME_point01 - 1;
ent.client.anim_end= M_Player.FRAME_point12;
break;
@@ -1184,7 +1186,7 @@ public final class Cmd extends PlayerView
String text;
gclient_t cl;
- if (gi.argc() < 2 && !arg0)
+ if (Cmd.Argc() < 2 && !arg0)
return;
if (0 == ((int) (dmflags.value) & (DF_MODELTEAMS | DF_SKINTEAMS)))
@@ -1197,16 +1199,16 @@ public final class Cmd extends PlayerView
if (arg0)
{
- text += gi.argv(0);
+ text += Cmd.Argv(0);
text += " ";
- text += gi.args();
+ text += Cmd.Args();
}
else
{
- if (gi.args().startsWith("\""))
- text += gi.args().substring(1, gi.args().length() - 1);
+ if (Cmd.Args().startsWith("\""))
+ text += Cmd.Args().substring(1, Cmd.Args().length() - 1);
else
- text += gi.args();
+ text += Cmd.Args();
/*
p = gi.args();
// *p ==
@@ -1232,7 +1234,7 @@ public final class Cmd extends PlayerView
if (level.time < cl.flood_locktill)
{
- gi.cprintf(ent, PRINT_HIGH, "You can't talk for " + (int) (cl.flood_locktill - level.time) + " more seconds\n");
+ SV_GAME.PF_cprintf(ent, PRINT_HIGH, "You can't talk for " + (int) (cl.flood_locktill - level.time) + " more seconds\n");
return;
}
i= (int) (cl.flood_whenhead - flood_msgs.value + 1);
@@ -1242,7 +1244,7 @@ public final class Cmd extends PlayerView
if (cl.flood_when[i] != 0 && level.time - cl.flood_when[i] < flood_persecond.value)
{
cl.flood_locktill= level.time + flood_waitdelay.value;
- gi.cprintf(ent, PRINT_CHAT, "Flood protection: You can't talk for " + (int) flood_waitdelay.value + " seconds.\n");
+ SV_GAME.PF_cprintf(ent, PRINT_CHAT, "Flood protection: You can't talk for " + (int) flood_waitdelay.value + " seconds.\n");
return;
}
//cl.flood_whenhead = (cl.flood_whenhead + 1) % (sizeof(cl.flood_when) / sizeof(cl.flood_when[0]));
@@ -1251,7 +1253,7 @@ public final class Cmd extends PlayerView
}
if (dedicated.value != 0)
- gi.cprintf(null, PRINT_CHAT, "" + text + "");
+ SV_GAME.PF_cprintf(null, PRINT_CHAT, "" + text + "");
for (j= 1; j <= game.maxclients; j++)
{
@@ -1265,7 +1267,7 @@ public final class Cmd extends PlayerView
if (!OnSameTeam(ent, other))
continue;
}
- gi.cprintf(other, PRINT_CHAT, "" + text + "");
+ SV_GAME.PF_cprintf(other, PRINT_CHAT, "" + text + "");
}
}
@@ -1308,12 +1310,12 @@ public final class Cmd extends PlayerView
if (text.length() + st.length() > 1024 - 50)
{
text += "And more...\n";
- GameBase.gi.cprintf(ent, Defines.PRINT_HIGH, "" + text + "");
+ SV_GAME.PF_cprintf(ent, Defines.PRINT_HIGH, "" + text + "");
return;
}
text += st;
}
- GameBase.gi.cprintf(ent, Defines.PRINT_HIGH, text);
+ SV_GAME.PF_cprintf(ent, Defines.PRINT_HIGH, text);
}
// ======================================================================
@@ -1345,6 +1347,26 @@ public final class Cmd extends PlayerView
SZ.Print(Globals.cls.netchan.message, " ");
SZ.Print(Globals.cls.netchan.message, Cmd.Args());
}
- };
+ }
+
+ /*
+ ============
+ Cmd_CompleteCommand
+ ============
+ */
+ public static Vector CompleteCommand(String partial)
+ {
+ Vector cmds = new Vector();
+
+ // check for match
+ for (cmd_function_t cmd = cmd_functions; cmd != null ; cmd = cmd.next)
+ if (cmd.name.startsWith(partial))
+ cmds.add(cmd.name);
+ for (cmdalias_t a = cmd_alias; a != null; a=a.next)
+ if (a.name.startsWith(partial))
+ cmds.add(a.name);
+
+ return cmds;
+ }
}
diff --git a/src/jake2/qcommon/Cvar.java b/src/jake2/qcommon/Cvar.java
index 34bcb70..a43464b 100644
--- a/src/jake2/qcommon/Cvar.java
+++ b/src/jake2/qcommon/Cvar.java
@@ -2,7 +2,7 @@
* Cvar.java
* Copyright (C) 2003
*
- * $Id: Cvar.java,v 1.3 2004-07-30 06:08:41 hzi Exp $
+ * $Id: Cvar.java,v 1.4 2004-08-19 20:56:41 hzi Exp $
*/
/*
Copyright (C) 1997-2001 Id Software, Inc.
@@ -28,6 +28,7 @@ package jake2.qcommon;
import java.io.IOException;
import java.io.RandomAccessFile;
+import java.util.Vector;
import jake2.Defines;
import jake2.Globals;
@@ -430,21 +431,16 @@ public class Cvar extends Globals {
Cvar_CompleteVariable
============
*/
- static String CompleteVariable(String partial) {
- cvar_t cvar;
- int len;
-
- len = partial.length();
-
- if (len == 0)
- return null;
+ public static Vector CompleteVariable(String partial) {
+
+ Vector vars = new Vector();
// check match
- for (cvar = Globals.cvar_vars; cvar != null; cvar = cvar.next)
+ for (cvar_t cvar = Globals.cvar_vars; cvar != null; cvar = cvar.next)
if (cvar.name.startsWith(partial))
- return cvar.name;
-
- return null;
+ vars.add(cvar.name);
+
+ return vars;
}
/*