static int cpqw_user_cmd (void) { int argc, i; progs_t *pr = &sv_pr_state; if (cpqw_funcs.ClientCommand) { argc = Cmd_Argc (); if (argc > 7) argc = 7; *sv_globals.time = sv.time; *sv_globals.self = EDICT_TO_PROG (&sv_pr_state, sv_player); PR_PushFrame (pr); P_FLOAT (pr, 0) = argc; for (i = 0; i < argc; i++) P_STRING (pr, i + 1) = PR_SetTempString (pr, Cmd_Argv (i)); for (; i < 7; i++) P_STRING (pr, i + 1) = 0; PR_ExecuteProgram (pr, cpqw_funcs.ClientCommand); PR_PopFrame (pr); return (int) R_FLOAT (pr); } return 0; }
static void PF_strlen (progs_t *pr) { const char *st; st = P_GSTRING (pr, 0); R_FLOAT (pr) = (float) strlen (st); }
/* PF_strcasecmp float(string st1, string st2) strcasecmp */ static void PF_strcasecmp (progs_t *pr) { const char *st1; const char *st2; st1 = P_GSTRING (pr, 0); st2 = P_GSTRING (pr, 1); R_FLOAT (pr) = (float) strncasecmp (st1, st2, 99999); }
/* PF_getuid float(entity client) getuid */ static void PF_getuid (progs_t *pr) { edict_t *client_ent; int e_num; float retval = 0; client_ent = P_EDICT (pr, 0); e_num = NUM_FOR_EDICT (pr, client_ent); if (e_num <= MAX_CLIENTS && e_num >= 1) retval = (float) svs.clients[e_num - 1].userid; R_FLOAT (pr) = retval; }
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); }
static void PF_validatefile (progs_t *pr) { float retval; QFile *f; const char *st; st = P_GSTRING (pr, 0); QFS_FOpenFile (st, &f); if (!f) { retval = 0.0; } else { retval = 1.0; Qclose (f); } R_FLOAT (pr) = retval; }
static void PF_mutedtime (progs_t *pr) { edict_t *client_ent; int e_num; float retval = 0; client_ent = P_EDICT (pr, 0); e_num = NUM_FOR_EDICT (pr, client_ent); if (e_num <= MAX_CLIENTS && e_num > 0) { if (realtime >= svs.clients[e_num - 1].lockedtill) retval = (float) 0; else retval = (float) svs.clients[e_num - 1].lockedtill - realtime; } R_FLOAT (pr) = retval; }
static void PF_getwave (progs_t *pr) { float retval, inputnum, minnum, maxnum, balance, offset, shape; float temp; unsigned int modes; inputnum = P_FLOAT (pr, 0); modes = (unsigned int) P_FLOAT (pr, 1); balance = P_FLOAT (pr, 4); (void) balance; //FIXME if (modes & GWAVE_USEOFFSET) offset = P_FLOAT (pr, 5); else offset = 0; // Use special shape? if (modes & GWAVE_USESHAPE) { shape = P_FLOAT (pr, 6); if (shape >= -1 && shape <= 1 && shape != 0) { if (shape < 0) // sine/linear mix { if (shape == -1) // full linear retval = GetLinearWave (inputnum + offset); else { // Get standard sinus retval = sin (2 * M_PI * (inputnum + offset)); temp = GetLinearWave (inputnum + offset); retval = (retval * (1 - fabs (shape))) + (temp * fabs (shape)); } } else // sine/circular mix { if (shape == 1) // full circular retval = GetCircleWave (inputnum + offset); else { // Get standard sinus retval = sin (2 * M_PI * (inputnum + offset)); temp = GetCircleWave (inputnum + offset); retval = retval * (1 - shape) + temp * shape; } } } else // 0 or invalid shape { // Get standard sinus retval = sin (2 * M_PI * (inputnum + offset)); } } else // dont use shape then.. { // Get standard sinus retval = sin (2 * M_PI * (inputnum + offset)); } // Use maximum/minimum values? if (modes & GWAVE_USEMINMAX) { minnum = P_FLOAT (pr, 2); maxnum = P_FLOAT (pr, 3); retval = minnum + ((retval + 1) / 2) * (maxnum - minnum); } // Return it! R_FLOAT (pr) = retval; }