]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - clvm_cmds.c
new menu QC builtin "stringwidth(string text, float handleColors)", does not do anyth...
[xonotic/darkplaces.git] / clvm_cmds.c
index e3e8918852c4de63b9fb862b669e85bb48e1213f..68b8ecc20ed0f8aabc138a0e527478e44f92ca3e 100644 (file)
@@ -130,7 +130,7 @@ static void VM_CL_sound (void)
        const char                      *sample;
        int                                     channel;
        prvm_edict_t            *entity;
-       int                             volume;
+       float                           volume;
        float                           attenuation;
 
        VM_SAFEPARMCOUNT(5, VM_CL_sound);
@@ -138,10 +138,10 @@ static void VM_CL_sound (void)
        entity = PRVM_G_EDICT(OFS_PARM0);
        channel = (int)PRVM_G_FLOAT(OFS_PARM1);
        sample = PRVM_G_STRING(OFS_PARM2);
-       volume = (int)(PRVM_G_FLOAT(OFS_PARM3)*255.0f);
+       volume = PRVM_G_FLOAT(OFS_PARM3);
        attenuation = PRVM_G_FLOAT(OFS_PARM4);
 
-       if (volume < 0 || volume > 255)
+       if (volume < 0 || volume > 1)
        {
                VM_Warning("VM_CL_sound: volume must be in range 0-1\n");
                return;
@@ -162,6 +162,37 @@ static void VM_CL_sound (void)
        S_StartSound(32768 + PRVM_NUM_FOR_EDICT(entity), channel, S_FindName(sample), entity->fields.client->origin, volume, attenuation);
 }
 
+// #483 void(vector origin, string sample, float volume, float attenuation) pointsound
+static void VM_CL_pointsound(void)
+{
+       const char                      *sample;
+       float                           volume;
+       float                           attenuation;
+       vec3_t                          org;
+
+       VM_SAFEPARMCOUNT(4, VM_CL_pointsound);
+
+       VectorCopy( PRVM_G_VECTOR(OFS_PARM0), org);
+       sample = PRVM_G_STRING(OFS_PARM1);
+       volume = PRVM_G_FLOAT(OFS_PARM2);
+       attenuation = PRVM_G_FLOAT(OFS_PARM3);
+
+       if (volume < 0 || volume > 1)
+       {
+               VM_Warning("VM_CL_pointsound: volume must be in range 0-1\n");
+               return;
+       }
+
+       if (attenuation < 0 || attenuation > 4)
+       {
+               VM_Warning("VM_CL_pointsound: attenuation must be in range 0-4\n");
+               return;
+       }
+
+       // Send World Entity as Entity to Play Sound (for CSQC, that is 32768)
+       S_StartSound(32768, 0, S_FindName(sample), org, volume, attenuation);
+}
+
 // #14 entity() spawn
 static void VM_CL_spawn (void)
 {
@@ -850,8 +881,24 @@ static void VM_CL_getstatf (void)
 static void VM_CL_getstati (void)
 {
        int i, index;
-       VM_SAFEPARMCOUNT(1, VM_CL_getstati);
+       int firstbit, bitcount;
+
+       VM_SAFEPARMCOUNTRANGE(1, 3, VM_CL_getstati);
+
        index = (int)PRVM_G_FLOAT(OFS_PARM0);
+       if (prog->argc > 1)
+       {
+               firstbit = (int)PRVM_G_FLOAT(OFS_PARM1);
+               if (prog->argc > 2)
+                       bitcount = (int)PRVM_G_FLOAT(OFS_PARM2);
+               else
+                       bitcount = 1;
+       }
+       else
+       {
+               firstbit = 0;
+               bitcount = 32;
+       }
 
        if(index < 0 || index >= MAX_CL_STATS)
        {
@@ -859,6 +906,8 @@ static void VM_CL_getstati (void)
                return;
        }
        i = cl.stats[index];
+       if (bitcount != 32)     //32 causes the mask to overflow, so there's nothing to subtract from.
+               i = (((unsigned int)i)&(((1<<bitcount)-1)<<firstbit))>>firstbit;
        PRVM_G_FLOAT(OFS_RETURN) = i;
 }
 
@@ -1041,6 +1090,9 @@ static void VM_CL_getplayerkey (void)
        else
                if(!strcasecmp(c, "ping"))
                        sprintf(t, "%i", cl.scores[i].qw_ping);
+       else
+               if(!strcasecmp(c, "pl"))
+                       sprintf(t, "%i", cl.scores[i].qw_packetloss);
        else
                if(!strcasecmp(c, "entertime"))
                        sprintf(t, "%f", cl.scores[i].qw_entertime);
@@ -1179,7 +1231,7 @@ static void VM_CL_makestatic (void)
 
                // copy it to the current state
                staticent->render.model = CL_GetModelByIndex((int)ent->fields.client->modelindex);
-               staticent->render.frame = staticent->render.frame1 = staticent->render.frame2 = (int)ent->fields.client->frame;
+               staticent->render.frame1 = staticent->render.frame2 = (int)ent->fields.client->frame;
                staticent->render.framelerp = 0;
                // make torchs play out of sync
                staticent->render.frame1time = staticent->render.frame2time = lhrandom(-10, -1);
@@ -2917,16 +2969,16 @@ NULL,                                                   // #217
 VM_bitshift,                                   // #218 float(float number, float quantity) bitshift (EXT_BITSHIFT)
 NULL,                                                  // #219
 NULL,                                                  // #220
-NULL,                                                  // #221
+VM_strstrofs,                                  // #221 float(string str, string sub[, float startpos]) strstrofs (FTE_STRINGS)
 VM_str2chr,                                            // #222 float(string str, float ofs) str2chr (FTE_STRINGS)
 VM_chr2str,                                            // #223 string(float c, ...) chr2str (FTE_STRINGS)
-NULL,                                                  // #224
-NULL,                                                  // #225
-NULL,                                                  // #226
-NULL,                                                  // #227
+VM_strconv,                                            // #224 string(float ccase, float calpha, float cnum, string s, ...) strconv (FTE_STRINGS)
+VM_strpad,                                             // #225 string(float chars, string s, ...) strpad (FTE_STRINGS)
+VM_infoadd,                                            // #226 string(string info, string key, string value, ...) infoadd (FTE_STRINGS)
+VM_infoget,                                            // #227 string(string info, string key) infoget (FTE_STRINGS)
 VM_strncmp,                                            // #228 float(string s1, string s2, float len) strncmp (FTE_STRINGS)
-NULL,                                                  // #229
-NULL,                                                  // #230
+VM_strncasecmp,                                        // #229 float(string s1, string s2) strcasecmp (FTE_STRINGS)
+VM_strncasecmp,                                        // #230 float(string s1, string s2, float len) strncasecmp (FTE_STRINGS)
 NULL,                                                  // #231
 NULL,                                                  // #232 void(float index, float type, .void field) SV_AddStat (EXT_CSQC)
 NULL,                                                  // #233
@@ -3023,8 +3075,8 @@ VM_drawpic,                                               // #322 float(vector position, string pic, vector size, vector
 VM_drawfill,                                   // #323 float(vector position, vector size, vector rgb, float alpha, float flag) drawfill (EXT_CSQC)
 VM_drawsetcliparea,                            // #324 void(float x, float y, float width, float height) drawsetcliparea
 VM_drawresetcliparea,                  // #325 void(void) drawresetcliparea
-NULL,                                                  // #326
-NULL,                                                  // #327
+VM_drawcolorcodedstring,               // #326 float drawcolorcodedstring(vector position, string text, vector scale, vector rgb, float alpha, float flag) (EXT_CSQC)
+NULL,                                                  // #327 // FIXME add stringwidth() here?
 NULL,                                                  // #328
 NULL,                                                  // #329
 VM_CL_getstatf,                                        // #330 float(float stnum) getstatf (EXT_CSQC)
@@ -3142,10 +3194,10 @@ NULL,                                                   // #440 void(entity e, string s) clientcommand (KRIMZON_SV_PARSECLIE
 VM_tokenize,                                   // #441 float(string s) tokenize (KRIMZON_SV_PARSECLIENTCOMMAND)
 VM_argv,                                               // #442 string(float n) argv (KRIMZON_SV_PARSECLIENTCOMMAND)
 VM_CL_setattachment,                   // #443 void(entity e, entity tagentity, string tagname) setattachment (DP_GFX_QUAKE3MODELTAGS)
-VM_search_begin,                               // #444 float(string pattern, float caseinsensitive, float quiet) search_begin (DP_FS_SEARCH)
-VM_search_end,                                 // #445 void(float handle) search_end (DP_FS_SEARCH)
-VM_search_getsize,                             // #446 float(float handle) search_getsize (DP_FS_SEARCH)
-VM_search_getfilename,                 // #447 string(float handle, float num) search_getfilename (DP_FS_SEARCH)
+VM_search_begin,                               // #444 float(string pattern, float caseinsensitive, float quiet) search_begin (DP_QC_FS_SEARCH)
+VM_search_end,                                 // #445 void(float handle) search_end (DP_QC_FS_SEARCH)
+VM_search_getsize,                             // #446 float(float handle) search_getsize (DP_QC_FS_SEARCH)
+VM_search_getfilename,                 // #447 string(float handle, float num) search_getfilename (DP_QC_FS_SEARCH)
 VM_cvar_string,                                        // #448 string(string s) cvar_string (DP_QC_CVAR_STRING)
 VM_findflags,                                  // #449 entity(entity start, .float fld, float match) findflags (DP_QC_FINDFLAGS)
 VM_findchainflags,                             // #450 entity(.float fld, float match) findchainflags (DP_QC_FINDCHAINFLAGS)
@@ -3181,9 +3233,9 @@ VM_tokenizebyseparator,                   // #479 float(string s) tokenizebyseparator (DP_QC_TOK
 VM_strtolower,                                 // #480 string(string s) VM_strtolower (DP_QC_STRING_CASE_FUNCTIONS)
 VM_strtoupper,                                 // #481 string(string s) VM_strtoupper (DP_QC_STRING_CASE_FUNCTIONS)
 VM_cvar_defstring,                             // #482 string(string s) cvar_defstring (DP_QC_CVAR_DEFSTRING)
-NULL,                                                  // #483
-NULL,                                                  // #484
-NULL,                                                  // #485
+VM_CL_pointsound,                              // #483 void(vector origin, string sample, float volume, float attenuation) (DP_SV_POINTSOUND)
+VM_strreplace,                                 // #484 string(string search, string replace, string subject) strreplace (DP_QC_STRREPLACE)
+VM_strireplace,                                        // #485 string(string search, string replace, string subject) strireplace (DP_QC_STRREPLACE)
 NULL,                                                  // #486
 NULL,                                                  // #487
 NULL,                                                  // #488