/* PF_strcat string(string st1, string st2) strcat */ static void PF_strcat (progs_t *pr) { const char *st1 = P_GSTRING (pr, 0); const char *st2 = P_GSTRING (pr, 1); R_STRING (pr) = PR_CatStrings (pr, st1, st2); }
/* 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_getclient entity(string st) getclient */ static void PF_getclient (progs_t *pr) { edict_t *ent; const char *st; int i, uid; client_t *cl; st = P_GSTRING (pr, 0); ent = (edict_t *) KK_Match_Str2 (st); // no substring match? if (!ent) { uid = atoi (st); // lets assume its an user id if (uid != 0) // was it even a number? { // then, lets see if a client with that userid is here for (i = 0, cl = svs.clients; i < MAX_CLIENTS && !ent; i++, cl++) { if (cl->userid == uid) // yeah, found it ent = cl->edict; } } } // Failed retrieving an user by name and by userid, so return world if (!ent) ent = sv.edicts; RETURN_EDICT (pr, ent); }
static void bi_Menu_SelectMenu (progs_t *pr) { const char *name = P_GSTRING (pr, 0); menu = 0; if (name && *name) menu = Hash_Find (menu_hash, name); if (menu) { Key_SetKeyDest (key_menu); if (menu->enter_hook) { run_menu_pre (); PR_ExecuteProgram (&menu_pr_state, menu->enter_hook); run_menu_post (); } } else { if (name && *name) Sys_Printf ("no menu \"%s\"\n", name); if (con_data.force_commandline) { Key_SetKeyDest (key_console); } else { Key_SetKeyDest (key_game); } } }
/* PF_padstr string(string st, float len) padstr */ static void PF_padstr (progs_t *pr) { const char *st; size_t i, padlen, givenlen; char *padding; st = P_GSTRING (pr, 0); padlen = (unsigned int) P_FLOAT (pr, 1); givenlen = strlen (st); // Check if nothing should be done due to error or no need to.. if ( (padlen <= givenlen)) { // nothing should be done R_INT (pr) = P_STRING (pr, 0); // return given string return; } // ok, lets pad it! padlen -= givenlen; padding = alloca (padlen + 1); for (i = 0; i < padlen; i++) padding[i] = ' '; padding[i] = '\0'; R_STRING (pr) = PR_CatStrings (pr, st, padding); }
static void PF_strlen (progs_t *pr) { const char *st; st = P_GSTRING (pr, 0); R_FLOAT (pr) = (float) strlen (st); }
static void bi_Menu_Pic (progs_t *pr) { int x = P_INT (pr, 0); int y = P_INT (pr, 1); const char *name = P_GSTRING (pr, 2); menu_pic (x, y, name, 0, 0, -1, -1); }
static void bi_Menu_TopMenu (progs_t *pr) { const char *name = P_GSTRING (pr, 0); if (top_menu) free ((char *) top_menu); top_menu = strdup (name); }
static void PF_makestr (progs_t *pr) { string_t res = PR_NewMutableString (pr); dstring_t *dst = PR_GetMutableString (pr, res); const char *src = P_GSTRING (pr, 0); dstring_copystr (dst, src); R_STRING (pr) = res; }
static void bi_Menu_CenterPic (progs_t *pr) { int x = P_INT (pr, 0); int y = P_INT (pr, 1); const char *name = P_GSTRING (pr, 2); qpic_t *qpic = r_funcs->Draw_CachePic (name, 1); if (!qpic) return; menu_pic (x - qpic->width / 2, y, name, 0, 0, -1, -1); }
static void bi_Menu_SubPic (progs_t *pr) { int x = P_INT (pr, 0); int y = P_INT (pr, 1); const char *name = P_GSTRING (pr, 2); int srcx = P_INT (pr, 3); int srcy = P_INT (pr, 4); int width = P_INT (pr, 5); int height = P_INT (pr, 6); menu_pic (x, y, name, srcx, srcy, width, height); }
static void bi_Menu_CenterSubPic (progs_t *pr) { int x = P_INT (pr, 0); int y = P_INT (pr, 1); const char *name = P_GSTRING (pr, 2); qpic_t *qpic = r_funcs->Draw_CachePic (name, 1); int srcx = P_INT (pr, 3); int srcy = P_INT (pr, 4); int width = P_INT (pr, 5); int height = P_INT (pr, 6); if (!qpic) return; menu_pic (x - qpic->width / 2, y, name, srcx, srcy, width, height); }
static void bi_Menu_Begin (progs_t *pr) { int x = P_INT (pr, 0); int y = P_INT (pr, 1); const char *text = P_GSTRING (pr, 2); menu_item_t *m = calloc (sizeof (menu_item_t), 1); m->x = x; m->y = y; m->text = text && text[0] ? strdup (text) : 0; if (menu) menu_add_item (menu, m); menu = m; if (m->text) Hash_Add (menu_hash, m); }
static void bi_Menu_Item (progs_t *pr) { int x = P_INT (pr, 0); int y = P_INT (pr, 1); const char *text = P_GSTRING (pr, 2); func_t func = P_FUNCTION (pr, 3); int allkeys = P_INT (pr, 4); menu_item_t *mi = calloc (sizeof (menu_item_t), 1); mi->x = x; mi->y = y; mi->text = text && text[0] ? strdup (text) : 0; mi->func = func; mi->parent = menu; mi->allkeys = allkeys; menu_add_item (menu, mi); }
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_colstr (progs_t *pr) { const char *srcstr; unsigned char *result; unsigned action; size_t len, i; srcstr = P_GSTRING (pr, 0); action = (unsigned) P_FLOAT (pr, 1); len = strlen (srcstr); // Check for errors, if any, return given string if (len == 0 || action > COLSTR_NUMBERV) { R_INT (pr) = P_STRING (pr, 0); // return given string return; } // Process string.. result = alloca (len + 1); strcpy ((char *) result, srcstr); switch (action) { case COLSTR_WHITE: for (i = 0; i < len; i++) { if (result[i] > 160) // is red char result[i] -= 128; } break; case COLSTR_MIX1: for (i = 0; i < len; i++) { if (i & 0x01) { if (result[i] < 128 && result[i] > 32) // is white char result[i] += 128; } else { if (result[i] > 160) // is red char result[i] -= 128; } } break; case COLSTR_RED: for (i = 0; i < len; i++) { if (result[i] < 128 && result[i] > 32) // is white char result[i] += 128; } break; case COLSTR_MIX2: for (i = 0; i < len; i++) { if (i & 0x01) { if (result[i] > 160) // is red char result[i] -= 128; } else { if (result[i] < 128 && result[i] > 32) // is white char result[i] += 128; } } break; case COLSTR_NUMBER: for (i = 0; i < len; i++) { if (result[i] > 47 && result[i] < 58) // is a white number result[i] -= 30; } break; case COLSTR_NUMBERV: for (i = 0; i < len; i++) { if (result[i] > 47 && result[i] < 58) // is a white number result[i] += 98; } } RETURN_STRING (pr, (char *) result); }
static void PF_clientsound (progs_t *pr) { const char *sample; int channel; edict_t *entity; int volume; float attenuation; int sound_num; int i; pr_int_t ent; vec3_t origin; entity = P_EDICT (pr, 0); channel = P_FLOAT (pr, 1); sample = P_GSTRING (pr, 2); volume = P_FLOAT (pr, 3) * 255; attenuation = P_FLOAT (pr, 4); ent = NUM_FOR_EDICT (pr, entity); // If not a client go away if (ent > MAX_CLIENTS || ent < 1) return; if (volume < 0 || volume > 255) Sys_Error ("SV_StartSound: volume = %i", volume); if (attenuation < 0 || attenuation > 4) Sys_Error ("SV_StartSound: attenuation = %f", attenuation); if (channel < 0 || channel > 15) Sys_Error ("SV_StartSound: channel = %i", channel); // find precache number for sound for (sound_num = 1; sound_num < MAX_SOUNDS && sv.sound_precache[sound_num]; sound_num++) if (!strcmp (sample, sv.sound_precache[sound_num])) break; if (sound_num == MAX_SOUNDS || !sv.sound_precache[sound_num]) { Sys_Printf ("SV_StartSound: %s not precacheed\n", sample); return; } channel &= 7; channel = (ent << 3) | channel; if (volume != DEFAULT_SOUND_PACKET_VOLUME) channel |= SND_VOLUME; if (attenuation != DEFAULT_SOUND_PACKET_ATTENUATION) channel |= SND_ATTENUATION; // use the entity origin VectorCopy (SVvector (entity, origin), origin); MSG_WriteByte (&svs.clients[ent - 1].netchan.message, svc_sound); MSG_WriteShort (&svs.clients[ent - 1].netchan.message, channel); if (channel & SND_VOLUME) MSG_WriteByte (&svs.clients[ent - 1].netchan.message, volume); if (channel & SND_ATTENUATION) MSG_WriteByte (&svs.clients[ent - 1].netchan.message, attenuation * 64); MSG_WriteByte (&svs.clients[ent - 1].netchan.message, sound_num); for (i = 0; i < 3; i++) MSG_WriteCoord (&svs.clients[ent - 1].netchan.message, origin[i]); }