+
+#ifdef WORKINGLQUAKE
+#define lhrandom(MIN,MAX) ((rand() & 32767) * (((MAX)-(MIN)) * (1.0f / 32767.0f)) + (MIN))
+#define NUMVERTEXNORMALS 162
+siextern float r_avertexnormals[NUMVERTEXNORMALS][3];
+#define m_bytenormals r_avertexnormals
+#define VectorNormalizeFast VectorNormalize
+#define CL_PointQ1Contents(v) (Mod_PointInLeaf(v,cl.worldmodel)->contents)
+typedef unsigned char qbyte;
+#define cl_stainmaps.integer 0
+void R_Stain (vec3_t origin, float radius, int cr1, int cg1, int cb1, int ca1, int cr2, int cg2, int cb2, int ca2)
+{
+}
+#define CL_EntityParticles R_EntityParticles
+#define CL_ReadPointFile_f R_ReadPointFile_f
+#define CL_ParseParticleEffect R_ParseParticleEffect
+#define CL_ParticleExplosion R_ParticleExplosion
+#define CL_ParticleExplosion2 R_ParticleExplosion2
+#define CL_BlobExplosion R_BlobExplosion
+#define CL_RunParticleEffect R_RunParticleEffect
+#define CL_LavaSplash R_LavaSplash
+void R_CalcBeam_Vertex3f (float *vert, vec3_t org1, vec3_t org2, float width)
+{
+ vec3_t right1, right2, diff, normal;
+
+ VectorSubtract (org2, org1, normal);
+ VectorNormalizeFast (normal);
+
+ // calculate 'right' vector for start
+ VectorSubtract (r_vieworigin, org1, diff);
+ VectorNormalizeFast (diff);
+ CrossProduct (normal, diff, right1);
+
+ // calculate 'right' vector for end
+ VectorSubtract (r_vieworigin, org2, diff);
+ VectorNormalizeFast (diff);
+ CrossProduct (normal, diff, right2);
+
+ vert[ 0] = org1[0] + width * right1[0];
+ vert[ 1] = org1[1] + width * right1[1];
+ vert[ 2] = org1[2] + width * right1[2];
+ vert[ 3] = org1[0] - width * right1[0];
+ vert[ 4] = org1[1] - width * right1[1];
+ vert[ 5] = org1[2] - width * right1[2];
+ vert[ 6] = org2[0] - width * right2[0];
+ vert[ 7] = org2[1] - width * right2[1];
+ vert[ 8] = org2[2] - width * right2[2];
+ vert[ 9] = org2[0] + width * right2[0];
+ vert[10] = org2[1] + width * right2[1];
+ vert[11] = org2[2] + width * right2[2];
+}
+void fractalnoise(qbyte *noise, int size, int startgrid)
+{
+ int x, y, g, g2, amplitude, min, max, size1 = size - 1, sizepower, gridpower;
+ int *noisebuf;
+#define n(x,y) noisebuf[((y)&size1)*size+((x)&size1)]
+
+ for (sizepower = 0;(1 << sizepower) < size;sizepower++);
+ if (size != (1 << sizepower))
+ Sys_Error("fractalnoise: size must be power of 2\n");
+
+ for (gridpower = 0;(1 << gridpower) < startgrid;gridpower++);
+ if (startgrid != (1 << gridpower))
+ Sys_Error("fractalnoise: grid must be power of 2\n");
+
+ startgrid = bound(0, startgrid, size);
+
+ amplitude = 0xFFFF; // this gets halved before use
+ noisebuf = malloc(size*size*sizeof(int));
+ memset(noisebuf, 0, size*size*sizeof(int));
+
+ for (g2 = startgrid;g2;g2 >>= 1)
+ {
+ // brownian motion (at every smaller level there is random behavior)
+ amplitude >>= 1;
+ for (y = 0;y < size;y += g2)
+ for (x = 0;x < size;x += g2)
+ n(x,y) += (rand()&litude);
+
+ g = g2 >> 1;
+ if (g)
+ {
+ // subdivide, diamond-square algorithm (really this has little to do with squares)
+ // diamond
+ for (y = 0;y < size;y += g2)
+ for (x = 0;x < size;x += g2)
+ n(x+g,y+g) = (n(x,y) + n(x+g2,y) + n(x,y+g2) + n(x+g2,y+g2)) >> 2;
+ // square
+ for (y = 0;y < size;y += g2)
+ for (x = 0;x < size;x += g2)
+ {
+ n(x+g,y) = (n(x,y) + n(x+g2,y) + n(x+g,y-g) + n(x+g,y+g)) >> 2;
+ n(x,y+g) = (n(x,y) + n(x,y+g2) + n(x-g,y+g) + n(x+g,y+g)) >> 2;
+ }
+ }
+ }
+ // find range of noise values
+ min = max = 0;
+ for (y = 0;y < size;y++)
+ for (x = 0;x < size;x++)
+ {
+ if (n(x,y) < min) min = n(x,y);
+ if (n(x,y) > max) max = n(x,y);
+ }
+ max -= min;
+ max++;
+ // normalize noise and copy to output
+ for (y = 0;y < size;y++)
+ for (x = 0;x < size;x++)
+ *noise++ = (qbyte) (((n(x,y) - min) * 256) / max);
+ free(noisebuf);
+#undef n
+}
+void VectorVectors(const vec3_t forward, vec3_t right, vec3_t up)
+{
+ float d;
+
+ right[0] = forward[2];
+ right[1] = -forward[0];
+ right[2] = forward[1];
+
+ d = DotProduct(forward, right);
+ right[0] -= d * forward[0];
+ right[1] -= d * forward[1];
+ right[2] -= d * forward[2];
+ VectorNormalizeFast(right);
+ CrossProduct(right, forward, up);
+}
+#if QW
+#include "pmove.h"
+extern qboolean PM_RecursiveHullCheck (hull_t *hull, int num, float p1f, float p2f, vec3_t p1, vec3_t p2, pmtrace_t *trace);
+#endif
+float CL_TraceLine (vec3_t start, vec3_t end, vec3_t impact, vec3_t normal, int hitbmodels, void **hitent, int hitsupercontentsmask)
+{
+#if QW
+ pmtrace_t trace;
+#else
+ trace_t trace;
+#endif
+ memset (&trace, 0, sizeof(trace));
+ trace.fraction = 1;
+ VectorCopy (end, trace.endpos);
+#if QW
+ PM_RecursiveHullCheck (cl.model_precache[1]->hulls, 0, 0, 1, start, end, &trace);
+#else
+ RecursiveHullCheck (cl.worldmodel->hulls, 0, 0, 1, start, end, &trace);
+#endif
+ VectorCopy(trace.endpos, impact);
+ VectorCopy(trace.plane.normal, normal);
+ return trace.fraction;
+}
+#else