Added a few useful builtins and began adding GIB hooks into quakeworld.

The player global branch variable is now updated with useful information
and the location.get builtin is available to return the current location
of the player based on loc files.  Fixed a bug with zooming out in zoom.gib.
This commit is contained in:
Brian Koropoff 2002-08-24 05:14:46 +00:00
parent 147f940510
commit 876eaa467c
10 changed files with 122 additions and 21 deletions

View file

@ -84,7 +84,7 @@ function "zoom.increase" {
function "zoom.decrease" {
ifnot ${zoom.zoomed} return
zoom.mult = (${zoom.mult}/(1 + ${zoom.mult.step}))
zoom.mult = (${zoom.mult}/${zoom.mult.step})
if (${zoom.mult} < ${zoom.mult.lower}) {
zoom.mult = ${zoom.mult.lower}
}

View file

@ -39,6 +39,11 @@ typedef struct gib_builtin_s {
} type;
} gib_builtin_t;
unsigned int GIB_Argc (void);
const char *GIB_Argv (unsigned int arg);
const char *GIB_Args (unsigned int arg);
void GIB_Arg_Strip_Delim (unsigned int arg);
void GIB_Return (const char *str);
void GIB_Builtin_Add (const char *name, void (*func) (void), enum gib_builtin_type_e type);
gib_builtin_t *GIB_Builtin_Find (const char *name);
void GIB_Builtin_Init (void);

View file

@ -39,9 +39,10 @@ typedef struct gib_var_s {
struct hashtab_s *subvars;
} gib_var_t;
void GIB_Var_Set (cbuf_t *cbuf, const char *key, const char *value);
const char *GIB_Var_Get (cbuf_t *cbuf, const char *key);
void GIB_Var_Set_Local (cbuf_t *cbuf, const char *key, const char *value);
void GIB_Var_Set_Global (const char *key, const char *value);
const char *GIB_Var_Get_Local (cbuf_t *cbuf, const char *key);
const char *GIB_Var_Get_Global (const char *key);
const char *GIB_Var_Get_Key (void *ele, void *ptr);
void GIB_Var_Free (void *ele, void *ptr);
void GIB_Var_Set_R (hashtab_t *vars, char *name, const char *value);
gib_var_t *GIB_Var_Get_R (hashtab_t *vars, char *name);

View file

@ -212,7 +212,7 @@ GIB_Local_f (void)
"lset: invalid syntax\n"
"usage: local variable");
else
GIB_Var_Set (cbuf_active, GIB_Argv(1), "");
GIB_Var_Set_Local (cbuf_active, GIB_Argv(1), "");
}
void
@ -224,9 +224,7 @@ GIB_Global_f (void)
"usage: global variable");
else {
char *a = strdup (GIB_Argv(1));
if (!gib_globals)
gib_globals = Hash_NewTable (256, GIB_Var_Get_Key, GIB_Var_Free, 0);
GIB_Var_Set_R (gib_globals, a, "");
GIB_Var_Set_Global (a, "");
free(a);
}
}
@ -357,9 +355,33 @@ GIB_Export_f (void)
}
}
void
GIB_String_Length_f (void)
{
if (GIB_Argc() != 2)
Cbuf_Error ("syntax",
"string.length: invalid syntax\n"
"usage: string.length string");
else
GIB_Return (va("%i", strlen(GIB_Argv(1))));
}
void
GIB_String_Equal_f (void)
{
if (GIB_Argc() != 3)
Cbuf_Error ("syntax",
"string.length: invalid syntax\n"
"usage: string.equal string1 string2");
else
GIB_Return (va("%i", !strcmp(GIB_Argv(1), GIB_Argv(2))));
}
void
GIB_Builtin_Init (void)
{
gib_globals = Hash_NewTable (512, GIB_Var_Get_Key, GIB_Var_Free, 0);
GIB_Builtin_Add ("function", GIB_Function_f, GIB_BUILTIN_NORMAL);
GIB_Builtin_Add ("function.get", GIB_FunctionDotGet_f, GIB_BUILTIN_NORMAL);
GIB_Builtin_Add ("export", GIB_Export_f, GIB_BUILTIN_NORMAL);
@ -370,4 +392,6 @@ GIB_Builtin_Init (void)
GIB_Builtin_Add ("ifnot", GIB_If_f, GIB_BUILTIN_FIRSTONLY);
GIB_Builtin_Add ("while", GIB_While_f, GIB_BUILTIN_NOPROCESS);
GIB_Builtin_Add ("break", GIB_Break_f, GIB_BUILTIN_NORMAL);
GIB_Builtin_Add ("string.length", GIB_String_Length_f, GIB_BUILTIN_NORMAL);
GIB_Builtin_Add ("string.equal", GIB_String_Equal_f, GIB_BUILTIN_NORMAL);
}

View file

@ -143,6 +143,6 @@ GIB_Function_Execute (gib_function_t *func)
cbuf_active->state = CBUF_STATE_STACK;
for (i = 0; i < cbuf_active->args->argc; i++)
GIB_Var_Set (sub, va("%i", i), cbuf_active->args->argv[i]->str);
GIB_Var_Set (sub, "argc", va("%i", cbuf_active->args->argc));
GIB_Var_Set_Local (sub, va("%i", i), cbuf_active->args->argv[i]->str);
GIB_Var_Set_Local (sub, "argc", va("%i", cbuf_active->args->argc));
}

View file

@ -474,13 +474,13 @@ void GIB_Parse_Execute_Line (cbuf_t *cbuf)
char *c = 0;
if ((c = strchr (args->argv[0]->str, '.'))) // Only check stem
*c = 0;
glob = (!GIB_Var_Get (cbuf, args->argv[0]->str) && GIB_Var_Get_R (gib_globals, args->argv[0]->str));
glob = (!GIB_Var_Get_Local (cbuf, args->argv[0]->str) && GIB_Var_Get_Global (args->argv[0]->str));
if (c)
*c = '.';
if (glob)
GIB_Var_Set_R (gib_globals, args->argv[0]->str, args->argv[2]->str); // Set the global
GIB_Var_Set_Global (args->argv[0]->str, args->argv[2]->str); // Set the global
else
GIB_Var_Set (cbuf, args->argv[0]->str, args->argv[2]->str); // Set the local
GIB_Var_Set_Local (cbuf, args->argv[0]->str, args->argv[2]->str); // Set the local
} else
Cmd_Command (cbuf->args);
dstring_clearstr (cbuf->line);

View file

@ -83,17 +83,16 @@ unsigned int
GIB_Process_Variable (struct dstring_s *dstr, unsigned int pos, qboolean tolerant)
{
cvar_t *cvar;
gib_var_t *gvar;
const char *str;
char *p, c;
for (p = dstr->str+pos+1; tolerant ? *p : isalnum ((byte)*p) || *p == '_'; p++);
c = *p;
*p = 0;
if ((str = GIB_Var_Get (cbuf_active, dstr->str+pos+1)))
if ((str = GIB_Var_Get_Local (cbuf_active, dstr->str+pos+1)))
; // yay for us
else if ((gvar = GIB_Var_Get_R (gib_globals, dstr->str+pos+1)))
str = gvar->value->str;
else if ((str = GIB_Var_Get_Global (dstr->str+pos+1)))
; // yay again
else if ((cvar = Cvar_FindVar (dstr->str+pos+1)))
str = cvar->string;
else

View file

@ -116,7 +116,7 @@ GIB_Var_Set_R (hashtab_t *vars, char *name, const char *value)
}
void
GIB_Var_Set (cbuf_t *cbuf, const char *key, const char *value)
GIB_Var_Set_Local (cbuf_t *cbuf, const char *key, const char *value)
{
char *k = strdup (key);
if (!GIB_DATA(cbuf)->locals)
@ -125,8 +125,16 @@ GIB_Var_Set (cbuf_t *cbuf, const char *key, const char *value)
free(k);
}
void
GIB_Var_Set_Global (const char *key, const char *value)
{
char *k = strdup (key);
GIB_Var_Set_R (gib_globals, k, value);
free (k);
}
const char *
GIB_Var_Get (cbuf_t *cbuf, const char *key)
GIB_Var_Get_Local (cbuf_t *cbuf, const char *key)
{
gib_var_t *l;
char *k;
@ -140,3 +148,16 @@ GIB_Var_Get (cbuf_t *cbuf, const char *key)
else
return 0;
}
const char *
GIB_Var_Get_Global (const char *key)
{
gib_var_t *l;
char *k = strdup (key);
l = GIB_Var_Get_R (gib_globals, k);
free (k);
if (l)
return l->value->str;
else
return 0;
}

View file

@ -56,6 +56,7 @@ static const char rcsid[] =
#include "QF/va.h"
#include "QF/vfile.h"
#include "QF/dstring.h"
#include "QF/gib_vars.h"
#include "bothdefs.h"
#include "cl_ents.h"
@ -1054,6 +1055,7 @@ void
CL_SetStat (int stat, int value)
{
int j;
const char *arm;
if (stat < 0 || stat >= MAX_CL_STATS)
Host_Error ("CL_SetStat: %i is invalid", stat);
@ -1061,16 +1063,47 @@ CL_SetStat (int stat, int value)
Sbar_Changed ();
switch (stat) {
case STAT_ITEMS: // set flash times
case STAT_ITEMS:
Sbar_Changed ();
GIB_Var_Set_Global ("player.key.1", value & IT_KEY1 ? "1" : "0");
GIB_Var_Set_Global ("player.key.2", value & IT_KEY2 ? "1" : "0");
if (value & IT_ARMOR1)
arm = "green";
else if (value & IT_ARMOR2)
arm = "yellow";
else if (value & IT_ARMOR3)
arm = "red";
else
arm = "blue";
GIB_Var_Set_Global ("player.armor.type", arm);
GIB_Var_Set_Global ("player.weapon.1", value & IT_AXE ? "1" : "0");
for (j = 0; j < 7; j++)
GIB_Var_Set_Global (va("player.weapon.%i", j+2),
value & (1 << j) ? "1" : "0");
for (j = 0; j < 32; j++)
if ((value & (1 << j)) && !(cl.stats[stat] & (1 << j)))
cl.item_gettime[j] = cl.time;
break;
case STAT_HEALTH:
GIB_Var_Set_Global ("player.health", va("%i", value));
if (value <= 0)
Team_Dead ();
break;
case STAT_ARMOR:
GIB_Var_Set_Global ("player.armor", va("%i", value));
break;
case STAT_SHELLS:
GIB_Var_Set_Global ("player.ammo.shells", va("%i", value));
break;
case STAT_NAILS:
GIB_Var_Set_Global ("player.ammo.nails", va("%i", value));
break;
case STAT_ROCKETS:
GIB_Var_Set_Global ("player.ammo.rockets", va("%i", value));
break;
case STAT_CELLS:
GIB_Var_Set_Global ("player.ammo.cells", va("%i", value));
break;
}
cl.stats[stat] = value;

View file

@ -51,6 +51,7 @@ static const char rcsid[] =
#include "QF/teamplay.h"
#include "QF/va.h"
#include "QF/skin.h"
#include "QF/gib_builtin.h"
#include "bothdefs.h"
#include "cl_input.h"
@ -399,11 +400,28 @@ locs_loc (void)
}
}
void
Locs_Location_Get (void)
{
location_t *location;
if (GIB_Argc() != 1)
Cbuf_Error (
"syntax",
"location.get: invalid syntax\n"
"usage: location.get"
);
else {
location = locs_find (cl.simorg);
GIB_Return (location ? location->name : "unknown");
}
}
void
Locs_Init (void)
{
Cmd_AddCommand ("loc", locs_loc, "Location marker editing commands: 'loc "
"help' for more");
GIB_Builtin_Add ("location.get", Locs_Location_Get, GIB_BUILTIN_NORMAL);
}
char *