]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - svvm_cmds.c
DP_QC_URI_ESCAPE
[xonotic/darkplaces.git] / svvm_cmds.c
index dffc4fda6681cdad0621b4de8cff199a19d0bbd1..e2d1de3b6f16d46af2f0319214118709f17024b8 100644 (file)
@@ -55,7 +55,9 @@ char *vm_sv_extensions =
 "DP_QC_CHANGEPITCH "
 "DP_QC_COPYENTITY "
 "DP_QC_CVAR_DEFSTRING "
+"DP_QC_CVAR_TYPE "
 "DP_QC_CVAR_STRING "
+"DP_QC_EDICT_NUM "
 "DP_QC_ETOS "
 "DP_QC_FINDCHAIN "
 "DP_QC_FINDCHAINFLAGS "
@@ -80,6 +82,7 @@ char *vm_sv_extensions =
 "DP_QC_TRACE_MOVETYPE_HITMODEL "
 "DP_QC_TRACE_MOVETYPE_WORLDONLY "
 "DP_QC_UNLIMITEDTEMPSTRINGS "
+"DP_QC_VECTOANGLES_WITH_ROLL "
 "DP_QC_VECTORVECTORS "
 "DP_QUAKE2_MODEL "
 "DP_QUAKE2_SPRITE "
@@ -146,6 +149,11 @@ char *vm_sv_extensions =
 "FTE_STRINGS "
 "DP_CON_BESTWEAPON "
 "DP_QC_STRREPLACE "
+"DP_QC_CRC16 "
+"DP_SV_SHUTDOWN "
+"DP_GECKO_SUPPORT "
+"DP_QC_GETSURFACEPOINTATTRIBUTE "
+"DP_QC_URI_ESCAPE "
 ;
 
 /*
@@ -180,8 +188,8 @@ static void VM_SV_setorigin (void)
        SV_LinkEdict (e, false);
 }
 
-
-void SetMinMaxSize (prvm_edict_t *e, float *min, float *max, qboolean rotate)
+// TODO: rotate param isnt used.. could be a bug. please check this and remove it if possible [1/10/2008 Black]
+static void SetMinMaxSize (prvm_edict_t *e, float *min, float *max, qboolean rotate)
 {
        int             i;
 
@@ -865,8 +873,7 @@ static void VM_SV_findradius (void)
 static void VM_SV_precache_sound (void)
 {
        VM_SAFEPARMCOUNT(1, VM_SV_precache_sound);
-       SV_SoundIndex(PRVM_G_STRING(OFS_PARM0), 2);
-       PRVM_G_INT(OFS_RETURN) = PRVM_G_INT(OFS_PARM0);
+       PRVM_G_FLOAT(OFS_RETURN) = SV_SoundIndex(PRVM_G_STRING(OFS_PARM0), 2);
 }
 
 static void VM_SV_precache_model (void)
@@ -966,18 +973,52 @@ static void VM_SV_droptofloor (void)
        VectorCopy (ent->fields.server->origin, end);
        end[2] -= 256;
 
-       trace = SV_Move (ent->fields.server->origin, ent->fields.server->mins, ent->fields.server->maxs, end, MOVE_NORMAL, ent, SV_GenericHitSuperContentsMask(ent));
+       if (sv_gameplayfix_droptofloorstartsolid_nudgetocorrect.integer)
+               SV_UnstickEntity(ent);
 
-       if (trace.fraction != 1 || (trace.startsolid && sv_gameplayfix_droptofloorstartsolid.integer))
-       {
-               if (trace.fraction < 1)
+       trace = SV_Move (ent->fields.server->origin, ent->fields.server->mins, ent->fields.server->maxs, end, MOVE_NORMAL, ent, SV_GenericHitSuperContentsMask(ent));
+       if (trace.startsolid && sv_gameplayfix_droptofloorstartsolid.integer)
+       {
+               vec3_t offset, org;
+               VectorSet(offset, 0.5f * (ent->fields.server->mins[0] + ent->fields.server->maxs[0]), 0.5f * (ent->fields.server->mins[1] + ent->fields.server->maxs[1]), ent->fields.server->mins[2]);
+               VectorAdd(ent->fields.server->origin, offset, org);
+               trace = SV_Move (org, vec3_origin, vec3_origin, end, MOVE_NORMAL, ent, SV_GenericHitSuperContentsMask(ent));
+               VectorSubtract(trace.endpos, offset, trace.endpos);
+               if (trace.startsolid)
+               {
+                       Con_DPrintf("droptofloor at %f %f %f - COULD NOT FIX BADLY PLACED ENTITY\n", ent->fields.server->origin[0], ent->fields.server->origin[1], ent->fields.server->origin[2]);
+                       SV_UnstickEntity(ent);
+                       SV_LinkEdict (ent, false);
+                       ent->fields.server->flags = (int)ent->fields.server->flags | FL_ONGROUND;
+                       ent->fields.server->groundentity = 0;
+                       PRVM_G_FLOAT(OFS_RETURN) = 1;
+               }
+               else if (trace.fraction < 1)
+               {
+                       Con_DPrintf("droptofloor at %f %f %f - FIXED BADLY PLACED ENTITY\n", ent->fields.server->origin[0], ent->fields.server->origin[1], ent->fields.server->origin[2]);
                        VectorCopy (trace.endpos, ent->fields.server->origin);
-               SV_LinkEdict (ent, false);
-               ent->fields.server->flags = (int)ent->fields.server->flags | FL_ONGROUND;
-               ent->fields.server->groundentity = PRVM_EDICT_TO_PROG(trace.ent);
-               PRVM_G_FLOAT(OFS_RETURN) = 1;
-               // if support is destroyed, keep suspended (gross hack for floating items in various maps)
-               ent->priv.server->suspendedinairflag = true;
+                       SV_UnstickEntity(ent);
+                       SV_LinkEdict (ent, false);
+                       ent->fields.server->flags = (int)ent->fields.server->flags | FL_ONGROUND;
+                       ent->fields.server->groundentity = PRVM_EDICT_TO_PROG(trace.ent);
+                       PRVM_G_FLOAT(OFS_RETURN) = 1;
+                       // if support is destroyed, keep suspended (gross hack for floating items in various maps)
+                       ent->priv.server->suspendedinairflag = true;
+               }
+       }
+       else
+       {
+               if (trace.fraction != 1)
+               {
+                       if (trace.fraction < 1)
+                               VectorCopy (trace.endpos, ent->fields.server->origin);
+                       SV_LinkEdict (ent, false);
+                       ent->fields.server->flags = (int)ent->fields.server->flags | FL_ONGROUND;
+                       ent->fields.server->groundentity = PRVM_EDICT_TO_PROG(trace.ent);
+                       PRVM_G_FLOAT(OFS_RETURN) = 1;
+                       // if support is destroyed, keep suspended (gross hack for floating items in various maps)
+                       ent->priv.server->suspendedinairflag = true;
+               }
        }
 }
 
@@ -1409,11 +1450,11 @@ void VM_SV_UpdateCustomStats (client_t *client, prvm_edict_t *ent, sizebuf_t *ms
                        stats[i+35] = s[12] + s[13] * 256 + s[14] * 65536 + s[15] * 16777216;
                        break;
                //float field sent as-is
-               case 2:
+               case 8:
                        stats[i+32] = PRVM_E_INT(ent, vm_customstats[i].fieldoffset);
                        break;
                //integer value of float field
-               case 8:
+               case 2:
                        stats[i+32] = (int)PRVM_E_FLOAT(ent, vm_customstats[i].fieldoffset);
                        break;
                default:
@@ -2151,6 +2192,79 @@ static void VM_SV_getsurfacepoint(void)
        // FIXME: implement rotation/scaling
        VectorAdd(&(model->surfmesh.data_vertex3f + 3 * surface->num_firstvertex)[pointnum * 3], ed->fields.server->origin, PRVM_G_VECTOR(OFS_RETURN));
 }
+//PF_getsurfacepointattribute,     // #486 vector(entity e, float s, float n, float a) getsurfacepointattribute = #486;
+// float SPA_POSITION = 0;
+// float SPA_S_AXIS = 1;
+// float SPA_T_AXIS = 2;
+// float SPA_R_AXIS = 3; // same as SPA_NORMAL
+// float SPA_TEXCOORDS0 = 4;
+// float SPA_LIGHTMAP0_TEXCOORDS = 5;
+// float SPA_LIGHTMAP0_COLOR = 6;
+static void VM_SV_getsurfacepointattribute(void)
+{
+       prvm_edict_t *ed;
+       model_t *model;
+       msurface_t *surface;
+       int pointnum;
+       int attributetype;
+
+       VM_SAFEPARMCOUNT(4, VM_SV_getsurfacepoint);
+       VectorClear(PRVM_G_VECTOR(OFS_RETURN));
+       ed = PRVM_G_EDICT(OFS_PARM0);
+       if (!(model = getmodel(ed)) || !(surface = getsurface(model, (int)PRVM_G_FLOAT(OFS_PARM1))))
+               return;
+       // note: this (incorrectly) assumes it is a simple polygon
+       pointnum = (int)PRVM_G_FLOAT(OFS_PARM2);
+       if (pointnum < 0 || pointnum >= surface->num_vertices)
+               return;
+       // FIXME: implement rotation/scaling
+       attributetype = (int) PRVM_G_FLOAT(OFS_PARM3);
+
+       switch( attributetype ) {
+               // float SPA_POSITION = 0;
+               case 0:
+                       VectorAdd(&(model->surfmesh.data_vertex3f + 3 * surface->num_firstvertex)[pointnum * 3], ed->fields.server->origin, PRVM_G_VECTOR(OFS_RETURN));
+                       break;
+               // float SPA_S_AXIS = 1;
+               case 1:
+                       VectorCopy(&(model->surfmesh.data_svector3f + 3 * surface->num_firstvertex)[pointnum * 3], PRVM_G_VECTOR(OFS_RETURN));
+                       break;
+               // float SPA_T_AXIS = 2;
+               case 2:
+                       VectorCopy(&(model->surfmesh.data_tvector3f + 3 * surface->num_firstvertex)[pointnum * 3], PRVM_G_VECTOR(OFS_RETURN));
+                       break;
+               // float SPA_R_AXIS = 3; // same as SPA_NORMAL
+               case 3:
+                       VectorCopy(&(model->surfmesh.data_normal3f + 3 * surface->num_firstvertex)[pointnum * 3], PRVM_G_VECTOR(OFS_RETURN));
+                       break;
+               // float SPA_TEXCOORDS0 = 4;
+               case 4: {
+                       float *ret = PRVM_G_VECTOR(OFS_RETURN);
+                       float *texcoord = &(model->surfmesh.data_texcoordtexture2f + 2 * surface->num_firstvertex)[pointnum * 2];
+                       ret[0] = texcoord[0];
+                       ret[1] = texcoord[1];
+                       ret[2] = 0.0f;
+                       break;
+               }
+               // float SPA_LIGHTMAP0_TEXCOORDS = 5;
+               case 5: {
+                       float *ret = PRVM_G_VECTOR(OFS_RETURN);
+                       float *texcoord = &(model->surfmesh.data_texcoordlightmap2f + 2 * surface->num_firstvertex)[pointnum * 2];
+                       ret[0] = texcoord[0];
+                       ret[1] = texcoord[1];
+                       ret[2] = 0.0f;
+                       break;
+               }
+               // float SPA_LIGHTMAP0_COLOR = 6;
+               case 6:
+                       // ignore alpha for now..
+                       VectorCopy( &(model->surfmesh.data_lightmapcolor4f + 4 * surface->num_firstvertex)[pointnum * 4], PRVM_G_VECTOR(OFS_RETURN));
+                       break;
+               default:
+                       VectorSet( PRVM_G_VECTOR(OFS_RETURN), 0.0f, 0.0f, 0.0f );
+                       break;
+       }
+}
 //PF_getsurfacenormal,    // #436 vector(entity e, float s) getsurfacenormal = #436;
 static void VM_SV_getsurfacenormal(void)
 {
@@ -2487,7 +2601,8 @@ static void VM_SV_gettagindex (void)
        {
                tag_index = SV_GetTagIndex(ent, tag_name);
                if (tag_index == 0)
-                       Con_DPrintf("gettagindex(entity #%i): tag \"%s\" not found\n", PRVM_NUM_FOR_EDICT(ent), tag_name);
+                       if(developer.integer >= 100)
+                               Con_Printf("gettagindex(entity #%i): tag \"%s\" not found\n", PRVM_NUM_FOR_EDICT(ent), tag_name);
        }
        PRVM_G_FLOAT(OFS_RETURN) = tag_index;
 };
@@ -3221,7 +3336,7 @@ VM_cvar_defstring,                                // #482 string(string s) cvar_defstring (DP_QC_CVAR_DEFSTR
 VM_SV_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
+VM_SV_getsurfacepointattribute,// #486 vector(entity e, float s, float n, float a) getsurfacepointattribute = #486;
 NULL,                                                  // #487
 NULL,                                                  // #488
 NULL,                                                  // #489
@@ -3229,12 +3344,32 @@ NULL,                                                   // #490
 NULL,                                                  // #491
 NULL,                                                  // #492
 NULL,                                                  // #493
-NULL,                                                  // #494
-NULL,                                                  // #495
+VM_crc16,                                              // #494 float(float caseinsensitive, string s, ...) crc16 = #494 (DP_QC_CRC16)
+VM_cvar_type,                                  // #495 float(string name) cvar_type = #495; (DP_QC_CVAR_TYPE)
 NULL,                                                  // #496
 NULL,                                                  // #497
 NULL,                                                  // #498
 NULL,                                                  // #499
+NULL,                                                  // #500
+NULL,                                                  // #501
+NULL,                                                  // #502
+NULL,                                                  // #503
+NULL,                                                  // #504
+NULL,                                                  // #505
+NULL,                                                  // #506
+NULL,                                                  // #507
+NULL,                                                  // #508
+NULL,                                                  // #509
+VM_uri_escape,                                 // #510 string(string in) uri_escape = #510;
+VM_uri_unescape,                               // #511 string(string in) uri_unescape = #511;
+NULL,                                                  // #512
+NULL,                                                  // #513
+NULL,                                                  // #514
+NULL,                                                  // #515
+NULL,                                                  // #516
+NULL,                                                  // #517
+NULL,                                                  // #518
+NULL,                                                  // #519
 };
 
 const int vm_sv_numbuiltins = sizeof(vm_sv_builtins) / sizeof(prvm_builtin_t);
@@ -3246,6 +3381,13 @@ void VM_SV_Cmd_Init(void)
 
 void VM_SV_Cmd_Reset(void)
 {
+       if(prog->funcoffsets.SV_Shutdown)
+       {
+               func_t s = prog->funcoffsets.SV_Shutdown;
+               prog->funcoffsets.SV_Shutdown = 0; // prevent it from getting called again
+               PRVM_ExecuteProgram(s,"SV_Shutdown() required");
+       }
+
        VM_Cmd_Reset();
 }