X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;ds=sidebyside;f=prvm_cmds.c;h=e82fa7f7442fee53c955fbf01d5c8dcc029c6e1c;hb=9c94125fe3b3877ebb6b0ec22db94a32df0cc7a5;hp=9930c3318d551dc3844856476b4366799ec9dee4;hpb=929495474f9cc099a83a4a884d85272791c5e7c3;p=xonotic%2Fdarkplaces.git diff --git a/prvm_cmds.c b/prvm_cmds.c index 9930c331..e82fa7f7 100644 --- a/prvm_cmds.c +++ b/prvm_cmds.c @@ -76,7 +76,7 @@ static qboolean checkextension(const char *name) { int len; char *e, *start; - len = strlen(name); + len = (int)strlen(name); for (e = prog->extensionstring;*e;e++) { @@ -87,11 +87,8 @@ static qboolean checkextension(const char *name) start = e; while (*e && *e != ' ') e++; - if (e - start == len) - if (!strncasecmp(start, name, len)) - { - return true; - } + if ((e - start) == len && !strncasecmp(start, name, len)) + return true; } return false; } @@ -155,7 +152,7 @@ void VM_objerror (void) } else // objerror has to display the object fields -> else call - PRVM_ERROR ("VM_objecterror: self not defined !\n"); + PRVM_ERROR ("VM_objecterror: self not defined !"); } /* @@ -255,24 +252,20 @@ void VM_normalize (void) { float *value1; vec3_t newvalue; - float new; + double f; VM_SAFEPARMCOUNT(1,VM_normalize); value1 = PRVM_G_VECTOR(OFS_PARM0); - new = value1[0] * value1[0] + value1[1] * value1[1] + value1[2]*value1[2]; - new = sqrt(new); - - if (new == 0) - newvalue[0] = newvalue[1] = newvalue[2] = 0; - else + f = VectorLength2(value1); + if (f) { - new = 1/new; - newvalue[0] = value1[0] * new; - newvalue[1] = value1[1] * new; - newvalue[2] = value1[2] * new; + f = 1.0 / sqrt(f); + VectorScale(value1, f, newvalue); } + else + VectorClear(newvalue); VectorCopy (newvalue, PRVM_G_VECTOR(OFS_RETURN)); } @@ -286,17 +279,8 @@ scalar vlen(vector) */ void VM_vlen (void) { - float *value1; - float new; - VM_SAFEPARMCOUNT(1,VM_vlen); - - value1 = PRVM_G_VECTOR(OFS_PARM0); - - new = value1[0] * value1[0] + value1[1] * value1[1] + value1[2]*value1[2]; - new = sqrt(new); - - PRVM_G_FLOAT(OFS_RETURN) = new; + PRVM_G_FLOAT(OFS_RETURN) = VectorLength(PRVM_G_VECTOR(OFS_PARM0)); } /* @@ -524,7 +508,7 @@ void VM_cvar_string(void) name = PRVM_G_STRING(OFS_PARM0); if(!name) - PRVM_ERROR("VM_str_cvar: %s: null string\n", PRVM_NAME); + PRVM_ERROR("VM_cvar_string: %s: null string", PRVM_NAME); VM_CheckEmptyString(name); @@ -537,6 +521,36 @@ void VM_cvar_string(void) PRVM_G_INT(OFS_RETURN) = PRVM_SetEngineString(out); } + +/* +======================== +VM_cvar_defstring + +const string VM_cvar_defstring (string) +======================== +*/ +void VM_cvar_defstring (void) +{ + char *out; + const char *name; + const char *cvar_string; + VM_SAFEPARMCOUNT(1,VM_cvar_string); + + name = PRVM_G_STRING(OFS_PARM0); + + if(!name) + PRVM_ERROR("VM_cvar_defstring: %s: null string", PRVM_NAME); + + VM_CheckEmptyString(name); + + out = VM_GetTempString(); + + cvar_string = Cvar_VariableDefString(name); + + strcpy(out, cvar_string); + + PRVM_G_INT(OFS_RETURN) = PRVM_SetEngineString(out); +} /* ================= VM_cvar_set @@ -564,7 +578,11 @@ void VM_dprint (void) if (developer.integer) { VM_VarString(0, string, sizeof(string)); +#if 1 + Con_Printf("%s", string); +#else Con_Printf("%s: %s", PRVM_NAME, string); +#endif } } @@ -690,7 +708,7 @@ void VM_ftoi(void) ent = PRVM_G_FLOAT(OFS_PARM0); if(PRVM_PROG_TO_EDICT(ent)->priv.required->free) - PRVM_ERROR ("VM_ftoe: %s tried to access a freed entity (entity %i)!\n", PRVM_NAME, ent); + PRVM_ERROR ("VM_ftoe: %s tried to access a freed entity (entity %i)!", PRVM_NAME, ent); PRVM_G_INT(OFS_RETURN) = ent; } @@ -735,9 +753,9 @@ void VM_remove (void) PRVM_ED_Free (ed); } // if (ed == prog->edicts) -// PRVM_ERROR ("remove: tried to remove world\n"); +// PRVM_ERROR ("remove: tried to remove world"); // if (PRVM_NUM_FOR_EDICT(ed) <= sv.maxclients) -// Host_Error("remove: tried to remove a client\n"); +// Host_Error("remove: tried to remove a client"); } /* @@ -832,7 +850,6 @@ VM_findchain entity findchain(.string field, string match) ========= */ -int PRVM_ED_FindFieldOffset(const char *field); // chained search for strings in entity fields // entity(.string field, string match) findchain = #402; void VM_findchain (void) @@ -847,9 +864,9 @@ void VM_findchain (void) // is the same like !(prog->flag & PRVM_FE_CHAIN) - even if the operator precedence is another if(!prog->flag & PRVM_FE_CHAIN) - PRVM_ERROR("VM_findchain: %s doesnt have a chain field !\n", PRVM_NAME); + PRVM_ERROR("VM_findchain: %s doesnt have a chain field !", PRVM_NAME); - chain_of = PRVM_ED_FindFieldOffset ("chain"); + chain_of = PRVM_ED_FindField("chain")->ofs; chain = prog->edicts; @@ -901,9 +918,9 @@ void VM_findchainfloat (void) VM_SAFEPARMCOUNT(2, VM_findchainfloat); if(!prog->flag & PRVM_FE_CHAIN) - PRVM_ERROR("VM_findchainfloat: %s doesnt have a chain field !\n", PRVM_NAME); + PRVM_ERROR("VM_findchainfloat: %s doesnt have a chain field !", PRVM_NAME); - chain_of = PRVM_ED_FindFieldOffset ("chain"); + chain_of = PRVM_ED_FindField("chain")->ofs; chain = (prvm_edict_t *)prog->edicts; @@ -926,6 +943,88 @@ void VM_findchainfloat (void) VM_RETURN_EDICT(chain); } +/* +======================== +VM_findflags + +entity findflags(entity start, .float field, float match) +======================== +*/ +// LordHavoc: search for flags in float fields +void VM_findflags (void) +{ + int e; + int f; + int s; + prvm_edict_t *ed; + + VM_SAFEPARMCOUNT(3, VM_findflags); + + + e = PRVM_G_EDICTNUM(OFS_PARM0); + f = PRVM_G_INT(OFS_PARM1); + s = (int)PRVM_G_FLOAT(OFS_PARM2); + + for (e++ ; e < prog->num_edicts ; e++) + { + prog->xfunction->builtinsprofile++; + ed = PRVM_EDICT_NUM(e); + if (ed->priv.required->free) + continue; + if ((int)PRVM_E_FLOAT(ed,f) & s) + { + VM_RETURN_EDICT(ed); + return; + } + } + + VM_RETURN_EDICT(prog->edicts); +} + +/* +======================== +VM_findchainflags + +entity findchainflags(.float field, float match) +======================== +*/ +// LordHavoc: chained search for flags in float fields +void VM_findchainflags (void) +{ + int i; + int f; + int s; + int chain_of; + prvm_edict_t *ent, *chain; + + VM_SAFEPARMCOUNT(2, VM_findchainflags); + + if(!prog->flag & PRVM_FE_CHAIN) + PRVM_ERROR("VM_findchainflags: %s doesnt have a chain field !", PRVM_NAME); + + chain_of = PRVM_ED_FindField("chain")->ofs; + + chain = (prvm_edict_t *)prog->edicts; + + f = PRVM_G_INT(OFS_PARM0); + s = (int)PRVM_G_FLOAT(OFS_PARM1); + + ent = PRVM_NEXT_EDICT(prog->edicts); + for (i = 1;i < prog->num_edicts;i++, ent = PRVM_NEXT_EDICT(ent)) + { + prog->xfunction->builtinsprofile++; + if (ent->priv.required->free) + continue; + if (!((int)PRVM_E_FLOAT(ent,f) & s)) + continue; + + PRVM_E_INT(ent,chain_of) = PRVM_EDICT_TO_PROG(chain); + chain = ent; + } + + VM_RETURN_EDICT(chain); +} + /* ========= VM_coredump @@ -969,7 +1068,7 @@ void VM_crash(void) { VM_SAFEPARMCOUNT(0, VM_crash); - PRVM_ERROR("Crash called by %s\n",PRVM_NAME); + PRVM_ERROR("Crash called by %s",PRVM_NAME); } /* @@ -1263,7 +1362,7 @@ void VM_min (void) PRVM_G_FLOAT(OFS_RETURN) = f; } else - PRVM_ERROR("VM_min: %s must supply at least 2 floats\n", PRVM_NAME); + PRVM_ERROR("VM_min: %s must supply at least 2 floats", PRVM_NAME); } /* @@ -1290,7 +1389,7 @@ void VM_max (void) PRVM_G_FLOAT(OFS_RETURN) = f; } else - PRVM_ERROR("VM_max: %s must supply at least 2 floats\n", PRVM_NAME); + PRVM_ERROR("VM_max: %s must supply at least 2 floats", PRVM_NAME); } /* @@ -1448,7 +1547,7 @@ void VM_fopen(void) modestring = "wb"; break; default: - Con_Printf("VM_fopen: %s no such mode %i (valid: 0 = read, 1 = append, 2 = write)\n", PRVM_NAME, mode); + Con_Printf("VM_fopen: %s: no such mode %i (valid: 0 = read, 1 = append, 2 = write)\n", PRVM_NAME, mode); PRVM_G_FLOAT(OFS_RETURN) = -3; return; } @@ -1461,13 +1560,13 @@ void VM_fopen(void) if (VM_FILES[filenum] == NULL) { if (developer.integer) - Con_Printf("fopen: %s mode %s failed\n", filename, modestring); + Con_Printf("VM_fopen: %s: %s mode %s failed\n", PRVM_NAME, filename, modestring); PRVM_G_FLOAT(OFS_RETURN) = -1; } else { if (developer.integer) - Con_Printf("fopen: %s mode %s opened as #%i\n", filename, modestring, filenum); + Con_Printf("VM_fopen: %s: %s mode %s opened as #%i\n", PRVM_NAME, filename, modestring, filenum); PRVM_G_FLOAT(OFS_RETURN) = filenum; } } @@ -1498,7 +1597,7 @@ void VM_fclose(void) return; } if (developer.integer) - Con_Printf("fclose #%i\n", filenum); + Con_Printf("VM_fclose: %s: #%i closed\n", PRVM_NAME, filenum); FS_Close(VM_FILES[filenum]); VM_FILES[filenum] = NULL; } @@ -1583,7 +1682,7 @@ void VM_fputs(void) return; } VM_VarString(1, string, sizeof(string)); - if ((stringlength = strlen(string))) + if ((stringlength = (int)strlen(string))) FS_Write(VM_FILES[filenum], string, stringlength); if (developer.integer) Con_Printf("fputs: %s: %s\n", PRVM_NAME, string); @@ -1625,7 +1724,7 @@ void VM_strcat(void) char *s; if(prog->argc < 1) - PRVM_ERROR("VM_strcat wrong parameter count (min. 1 expected ) !\n"); + PRVM_ERROR("VM_strcat wrong parameter count (min. 1 expected ) !"); s = VM_GetTempString(); VM_VarString(0, s, VM_STRINGTEMP_LENGTH); @@ -1755,10 +1854,10 @@ float tokenize(string s) //this function originally written by KrimZon, made shorter by LordHavoc //20040203: rewritten by LordHavoc (no longer uses allocations) int num_tokens = 0; -char *tokens[256], tokenbuf[4096]; +char *tokens[256], tokenbuf[MAX_INPUTLINE]; void VM_tokenize (void) { - int pos; + size_t pos; const char *p; VM_SAFEPARMCOUNT(1,VM_tokenize); @@ -1971,13 +2070,13 @@ void VM_parseentitydata(void) // get edict and test it ent = PRVM_G_EDICT(OFS_PARM0); if (ent->priv.required->free) - PRVM_ERROR ("VM_parseentitydata: %s: Can only set already spawned entities (entity %i is free)!\n", PRVM_NAME, PRVM_NUM_FOR_EDICT(ent)); + PRVM_ERROR ("VM_parseentitydata: %s: Can only set already spawned entities (entity %i is free)!", PRVM_NAME, PRVM_NUM_FOR_EDICT(ent)); data = PRVM_G_STRING(OFS_PARM1); // parse the opening brace if (!COM_ParseToken(&data, false) || com_token[0] != '{' ) - PRVM_ERROR ("VM_parseentitydata: %s: Couldn't parse entity data:\n%s\n", PRVM_NAME, data ); + PRVM_ERROR ("VM_parseentitydata: %s: Couldn't parse entity data:\n%s", PRVM_NAME, data ); PRVM_ED_ParseEdict (data, ent); } @@ -1992,7 +2091,7 @@ loadfromfile(string file) void VM_loadfromfile(void) { const char *filename; - qbyte *data; + char *data; VM_SAFEPARMCOUNT(1,VM_loadfromfile); @@ -2009,7 +2108,7 @@ void VM_loadfromfile(void) } // not conform with VM_fopen - data = FS_LoadFile(filename, tempmempool, false); + data = (char *)FS_LoadFile(filename, tempmempool, false, NULL); if (data == NULL) PRVM_G_FLOAT(OFS_RETURN) = -1; @@ -2241,7 +2340,7 @@ void VM_precache_pic(void) PRVM_G_INT(OFS_RETURN) = PRVM_G_INT(OFS_PARM0); if(!s) - PRVM_ERROR ("VM_precache_pic: %s: NULL\n", PRVM_NAME); + PRVM_ERROR ("VM_precache_pic: %s: NULL", PRVM_NAME); VM_CheckEmptyString (s); @@ -2266,7 +2365,7 @@ void VM_freepic(void) s = PRVM_G_STRING(OFS_PARM0); if(!s) - PRVM_ERROR ("VM_freepic: %s: NULL\n"); + PRVM_ERROR ("VM_freepic: %s: NULL"); VM_CheckEmptyString (s); @@ -2508,7 +2607,7 @@ void VM_getimagesize(void) p = PRVM_G_STRING(OFS_PARM0); if(!p) - PRVM_ERROR("VM_getimagepos: %s passed null picture name !\n", PRVM_NAME); + PRVM_ERROR("VM_getimagepos: %s passed null picture name !", PRVM_NAME); VM_CheckEmptyString (p); @@ -2583,7 +2682,7 @@ void VM_cin_setstate( void ) name = PRVM_G_STRING( OFS_PARM0 ); VM_CheckEmptyString( name ); - state = PRVM_G_FLOAT( OFS_PARM1 ); + state = (clvideostate_t)((int)PRVM_G_FLOAT( OFS_PARM1 )); video = CL_GetVideo( name ); if( video && state > CLVIDEO_UNUSED && state < CLVIDEO_STATECOUNT )