Ejemplo n.º 1
0
int
call_progs_main (progs_t *pr, int argc, const char **argv)
{
	int         i;
	dfunction_t *dfunc;
	func_t      progs_main = 0;
	string_t   *pr_argv;

	if ((dfunc = PR_FindFunction (pr, "main"))) {
		progs_main = dfunc - pr->pr_functions;
	} else {
		PR_Undefined (pr, "function", "main");
		return -1;
	}

	PR_PushFrame (pr);
	pr_argv = PR_Zone_Malloc (pr, (argc + 1) * 4);
	for (i = 0; i < argc; i++)
		pr_argv[i] = PR_SetTempString (pr, argv[1 + i]);
	pr_argv[i] = 0;
	PR_RESET_PARAMS (pr);
	P_INT (pr, 0) = argc;
	P_POINTER (pr, 1) = PR_SetPointer (pr, pr_argv);
	PR_ExecuteProgram (pr, progs_main);
	PR_PopFrame (pr);
	PR_Zone_Free (pr, pr_argv);
	return R_INT (pr);
}
Ejemplo n.º 2
0
int
main (int argc, char **argv)
{
	dfunction_t *dfunc;
	func_t      main_func = 0;
	const char *name = "progs.dat";
	string_t   *pr_argv;
	int         pr_argc = 1, i;

	i = parse_options (argc, argv);
	argc -= i;
	argv += i;

	init_qf ();

	if (argc > 0)
		name = argv[0];

	if (!load_progs (name))
		Sys_Error ("couldn't load %s", name);

	PR_PushFrame (&pr);
	if (argc > 2)
		pr_argc = argc - 1;
	pr_argv = PR_Zone_Malloc (&pr, (pr_argc + 1) * 4);
	pr_argv[0] = PR_SetTempString (&pr, name);
	for (i = 1; i < pr_argc; i++)
		pr_argv[i] = PR_SetTempString (&pr, argv[1 + i]);
	pr_argv[i] = 0;

	if ((dfunc = PR_FindFunction (&pr, ".main"))
		|| (dfunc = PR_FindFunction (&pr, "main")))
		main_func = dfunc - pr.pr_functions;
	else
		PR_Undefined (&pr, "function", "main");
	PR_RESET_PARAMS (&pr);
	P_INT (&pr, 0) = pr_argc;
	P_POINTER (&pr, 1) = PR_SetPointer (&pr, pr_argv);
	PR_ExecuteProgram (&pr, main_func);
	PR_PopFrame (&pr);
	if (options.flote)
		return R_FLOAT (&pr);
	return R_INT (&pr);
}
Ejemplo n.º 3
0
static int
cpqw_load (progs_t *pr)
{
	size_t      i;

	for (i = 0;
		 i < sizeof (cpqw_func_list) / sizeof (cpqw_func_list[0]); i++) {
		dfunction_t *f = PR_FindFunction (pr, cpqw_func_list[i].name);

		*cpqw_func_list[i].field = 0;
		if (f)
			*cpqw_func_list[i].field = (func_t) (f - pr->pr_functions);
	}
	ucmd_unknown = cpqw_user_cmd;
	return 1;
}
Ejemplo n.º 4
0
static int
menu_resolve_globals (progs_t *pr)
{
	const char *sym;
	ddef_t     *def;
	dfunction_t *f;
	size_t      i;

	for (i = 0;
		 i < sizeof (menu_functions) / sizeof (menu_functions[0]); i++) {
		sym = menu_functions[i].name;
		if (!(f = PR_FindFunction (pr, sym)))
			goto error;
		*menu_functions[i].func = (func_t) (f - menu_pr_state.pr_functions);
	}

	if (!(def = PR_FindGlobal (pr, sym = "time")))
		goto error;
	menu_pr_state.globals.time = &G_FLOAT (pr, def->ofs);
	return 1;
error:
	Sys_Printf ("%s: undefined symbol %s\n", pr->progs_name, sym);
	return 0;
}
Ejemplo n.º 5
0
/*
============
SV_CycleWeaponReverse

(JDH: copy of weapons.qc function) 
============
*/
void SV_CycleWeaponReverse (edict_t *ent)
{
	int			it, weapon;
	qboolean	has_ammo;
	dfunction_t	*func;
	
	it = (int) ent->v.items;
	weapon = (int) ent->v.weapon;
	ent->v.impulse = 0;

	while (1)
	{
		has_ammo = true;

		switch (weapon)
		{
		case IT_LIGHTNING:
			weapon = IT_ROCKET_LAUNCHER;
			if (ent->v.ammo_rockets < 1)
				has_ammo = false;
			break;
		case IT_ROCKET_LAUNCHER:
			weapon = IT_GRENADE_LAUNCHER;
			if (ent->v.ammo_rockets < 1)
				has_ammo = false;
			break;
		case IT_GRENADE_LAUNCHER:
			weapon = IT_SUPER_NAILGUN;
			if (ent->v.ammo_nails < 2)
				has_ammo = false;
			break;
		case IT_SUPER_NAILGUN:
			weapon = IT_NAILGUN;
			if (ent->v.ammo_nails < 1)
				has_ammo = false;
			break;
		case IT_NAILGUN:
			weapon = IT_SUPER_SHOTGUN;
			if (ent->v.ammo_shells < 2)
				has_ammo = false;
			break;
		case IT_SUPER_SHOTGUN:
			weapon = IT_SHOTGUN;
			if (ent->v.ammo_shells < 1)
				has_ammo = false;
			break;
		case IT_SHOTGUN:
			weapon = IT_AXE;
			break;
		case IT_AXE:
			weapon = IT_LIGHTNING;
			if (ent->v.ammo_cells < 1)
				has_ammo = false;
			break;
		}
		
		if ((it & weapon) && has_ammo)
		{
			func = PR_FindFunction ("W_SetCurrentAmmo", PRFF_NOBUILTINS);
			if (func)
			{
			// W_SetCurrentAmmo usually has no params, but for lthsp2-lthsp5
			// it expects "self" as an argument
				if (func->numparms == 1)
					((int *)pr_globals)[OFS_PARM0] = PR_GLOBAL(self);
				ent->v.weapon = weapon;
				PR_ExecuteProgram (func - pr_functions);
			}
			return;
		}
	}
};
Ejemplo n.º 6
0
float SV_ChatFunc(const char *func)	//parse a condition/function
{
	globalvars_t *pr_globals;
	float result;
	int noted = false;
	const char *s, *os;
	char namebuf[64];
	func_t f;
	int parm;
	while (*func <= ' ')
		func++;
	if (*func == '!')
	{
		noted = true;
		func++;
	}
	s = COM_ParseToken(func, NULL);
	if (*com_token == '(')
	{//open bracket
		//find correct close
		parm = 1;
		for (s = func+1; ; s++)
		{
			if (!*s)
				Sys_Error("No close bracket");
			if (*s == ')')
			{
				parm--;
				if (!parm)break;
			}
			if (*s == '(')
				parm++;
		}
		func = strchr(func, '(');
		s=COM_ParseToken(s+1, NULL);
		if (!strncmp(com_token, "&&", 2))
			result = SV_ChatFunc(func+1) && SV_ChatFunc(s);
		else if (!strncmp(com_token, "||", 2))
			result = SV_ChatFunc(func+1) || SV_ChatFunc(s);
		else
			result = SV_ChatFunc(func+1);
	}
	else
	{
	strcpy(namebuf, com_token);	//get first word	

	while (*s <= ' ')
		s++;
	
	if (*s == '(')	//if followed by brackets
	{
		s++;
		pr_globals = PR_globals(svprogfuncs, PR_CURRENT);
		parm = OFS_PARM0;
		while((s=COM_ParseToken(os = s, NULL)))
		{
			if (*com_token == ')')
				break;
			if (*com_token == ',')
				continue;
			if (com_tokentype == TTP_STRING)
				G_INT(parm) = PR_NewString(svprogfuncs, com_token);
			else if (!strcmp(com_token, "ent"))
				G_INT(parm) = EDICT_TO_PROG(svprogfuncs, host_client->chat.edict);
			else
				G_FLOAT(parm) = SV_ChatFunc(os);

			parm+=OFS_PARM1-OFS_PARM0;
		}

		f = PR_FindFunction(svprogfuncs, namebuf, PR_CURRENT);
		if (f)
		{		
			PR_ExecuteProgram(svprogfuncs, f);
		}
		else
			Con_Printf("Failed to find function %s\n", namebuf);

		pr_globals = PR_globals(svprogfuncs, PR_CURRENT);
		result = G_FLOAT(OFS_RETURN);
	}
	else
	{
		//comparision operators
		if (!strncmp(s, "==", 2))
			result = (SV_ChatGetValue(namebuf) == SV_ChatFunc(s+2));
		else if (!strncmp(s, ">=", 2))
			result = (SV_ChatGetValue(namebuf) >= SV_ChatFunc(s+2));
		else if (!strncmp(s, "<=", 2))
			result = (SV_ChatGetValue(namebuf) <= SV_ChatFunc(s+2));
		else if (!strncmp(s, "!=", 2))
			result = (SV_ChatGetValue(namebuf) != SV_ChatFunc(s+2));
		else if (!strncmp(s, ">", 1))
			result = (SV_ChatGetValue(namebuf) >= SV_ChatFunc(s+2));
		else if (!strncmp(s, "<", 1))
			result = (SV_ChatGetValue(namebuf) <= SV_ChatFunc(s+2));

		//asignment operators
		else if (!strncmp(s, "=", 1))
			result = (SV_ChatSetValue(namebuf, SV_ChatFunc(s+1)));
		else if (!strncmp(s, "+=", 2))
			result = (SV_ChatSetValue(namebuf, SV_ChatGetValue(namebuf)+SV_ChatFunc(s+2)));
		else if (!strncmp(s, "-=", 2))
			result = (SV_ChatSetValue(namebuf, SV_ChatGetValue(namebuf)-SV_ChatFunc(s+2)));
		else if (!strncmp(s, "*=", 2))
			result = (SV_ChatSetValue(namebuf, SV_ChatGetValue(namebuf)*SV_ChatFunc(s+2)));
		else if (!strncmp(s, "/=", 2))
			result = (SV_ChatSetValue(namebuf, SV_ChatGetValue(namebuf)/SV_ChatFunc(s+2)));
		else if (!strncmp(s, "|=", 2))
			result = (SV_ChatSetValue(namebuf, (int)SV_ChatGetValue(namebuf)|(int)SV_ChatFunc(s+2)));
		else if (!strncmp(s, "&=", 2))
			result = (SV_ChatSetValue(namebuf, (int)SV_ChatGetValue(namebuf)&(int)SV_ChatFunc(s+2)));

		//mathematical operators
		else if (!strncmp(s, "+", 1))
			result = ( SV_ChatGetValue(namebuf)+SV_ChatFunc(s+1));
		else if (!strncmp(s, "-", 1))
			result = (SV_ChatGetValue(namebuf)-SV_ChatFunc(s+1));
		else if (!strncmp(s, "*", 1))
			result = (SV_ChatGetValue(namebuf)*SV_ChatFunc(s+1));
		else if (!strncmp(s, "/", 1))
			result = (SV_ChatGetValue(namebuf)/SV_ChatFunc(s+1));
		else if (!strncmp(s, "|", 1))
			result = ((int)SV_ChatGetValue(namebuf)|(int)SV_ChatFunc(s+1));
		else if (!strncmp(s, "&", 1))
			result = ((int)SV_ChatGetValue(namebuf)&(int)SV_ChatFunc(s+1));

		//operatorless
		else
			result = SV_ChatGetValue(namebuf);
	}
	}

	if (noted)
		result = !result;

	return result;
}