djcev.com

//

Git Repos / fte_dogmode / qc / utility.qc

Last update to this file was on 2024-03-24 at 02:40.

Show utility.qc

//==============================================================================
// utility.qc
//==============================================================================

//======================================================================
// forward declarations
//======================================================================

void(string s1, string s2) dprint2;
void(string s1, string s2, string s3) dprint3;
void(string s1, string s2, string s3, string s4) dprint4;
void(string s1, string s2, string s3, string s4, string s5) dprint5;
void(string s1, string s2, string s3, string s4, string s5, string s6) dprint6;
void(string s1, string s2, string s3, string s4, string s5, string s6,
string s7) dprint7;
void(string s1, string s2, string s3, string s4, string s5, string s6,
string s7, string s8) dprint8;
void(string s1, string s2, string s3, string s4, string s5, string s6,
string s7, string s8, string s9) dprint9;

float(float in) bprint_int;
float(float in) zeroconvert;
float(float in, float def) zeroconvertdefault;

float(vector v, vector s) bounds_angle_size;

void(entity client, float f) stuffcmd_digit;
void(entity client, float f, float numdigits) stuffcmd_int;
void(entity client, float f) stuffcmd_float;

//------------------------------------------------------------------------------

//----------------------------------------------------------------------
// dprint shims
//----------------------------------------------------------------------
void(string s1, string s2) dprint2 =
{
dprint (s1);
dprint (s2);
};

//----------------------------------------------------------------------
void(string s1, string s2, string s3) dprint3 =
{
dprint (s1);
dprint (s2);
dprint (s3);
};

//----------------------------------------------------------------------
void(string s1, string s2, string s3, string s4) dprint4 =
{
dprint (s1);
dprint (s2);
dprint (s3);
dprint (s4);
};

//----------------------------------------------------------------------
void(string s1, string s2, string s3, string s4, string s5) dprint5 =
{
dprint (s1);
dprint (s2);
dprint (s3);
dprint (s4);
dprint (s5);
};

//----------------------------------------------------------------------
void(string s1, string s2, string s3, string s4, string s5, string s6) dprint6 =
{
dprint (s1);
dprint (s2);
dprint (s3);
dprint (s4);
dprint (s5);
dprint (s6);
};

//----------------------------------------------------------------------
void(string s1, string s2, string s3, string s4, string s5, string s6,
string s7) dprint7 =
{
dprint (s1);
dprint (s2);
dprint (s3);
dprint (s4);
dprint (s5);
dprint (s6);
dprint (s7);
};

//----------------------------------------------------------------------
void(string s1, string s2, string s3, string s4, string s5, string s6,
string s7, string s8) dprint8 =
{
dprint (s1);
dprint (s2);
dprint (s3);
dprint (s4);
dprint (s5);
dprint (s6);
dprint (s7);
dprint (s8);
};

//----------------------------------------------------------------------
void(string s1, string s2, string s3, string s4, string s5, string s6,
string s7, string s8, string s9) dprint9 =
{
dprint (s1);
dprint (s2);
dprint (s3);
dprint (s4);
dprint (s5);
dprint (s6);
dprint (s7);
dprint (s8);
dprint (s9);
};

//======================================================================
// Sourced from utility.qc from smej2
//======================================================================

//----------------------------------------------------------------------
float(float in) bprint_int =
{
in = floor (in);
if (in <= 0)
return 0;

local float digit;
digit = in - bprint_int (in / 10);

switch (digit)
{
case 9: bprint("9"); break;
case 8: bprint("8"); break;
case 7: bprint("7"); break;
case 6: bprint("6"); break;
case 5: bprint("5"); break;
case 4: bprint("4"); break;
case 3: bprint("3"); break;
case 2: bprint("2"); break;
case 1: bprint("1"); break;
case 0: bprint("0"); break;
}

return in * 10;
};

//----------------------------------------------------------------------
// shorthand for turning -1 to 0 for keyvalues for which 0 is a
// valid non-default selection
//----------------------------------------------------------------------
float(float in) zeroconvert =
{
if (in == -1)
return 0;
return in;
};

//----------------------------------------------------------------------
float(float in, float def) zeroconvertdefault =
{
if (in == -1)
return 0;
if (in == 0)
return def;
return in;
}

//----------------------------------------------------------------------
// for measuring how large an entity is along an arbitrary vector
// FIXME: this is trash and it returns trash
//----------------------------------------------------------------------
float(vector v, vector s) bounds_angle_size =
{
v_x = fabs (v_x);
v_y = fabs (v_y);
v_z = fabs (v_z);

// size is always + + + but this is in case I switch the
// parameters somewhere
s_x = fabs (s_x);
s_y = fabs (s_y);
s_z = fabs (s_z);

return v * s;
};

//----------------------------------------------------------------------
// count -4 = numclients in coop
//----------------------------------------------------------------------
/*
void(.float fld) playercount_convert =
{
if (self.fld != -4)
return;
if (!coop)
self.fld = 1;
else
self.fld = clients;
};
*/

//======================================================================
// wonderful stuffcmd code from Honey by czg
//======================================================================

//----------------------------------------------------------------------
// stuffcmd_float
// This is a horrible hack that I am ashamed of!
//----------------------------------------------------------------------
void(entity client, float f) stuffcmd_digit =
{
local float d;
d = floor (f);
d = mod (d, 10);

// CLOSE YOUR EYES, HONEY! DON'T LOOK!
switch (d)
{
case 0: stuffcmd (client, "0"); break;
case 1: stuffcmd (client, "1"); break;
case 2: stuffcmd (client, "2"); break;
case 3: stuffcmd (client, "3"); break;
case 4: stuffcmd (client, "4"); break;
case 5: stuffcmd (client, "5"); break;
case 6: stuffcmd (client, "6"); break;
case 7: stuffcmd (client, "7"); break;
case 8: stuffcmd (client, "8"); break;
case 9: stuffcmd (client, "9"); break;
}
};

//----------------------------------------------------------------------
void(entity client, float f, float numdigits) stuffcmd_int =
{
local float tmp;

if (f == 0)
{
stuffcmd (client, "0");
return;
}

if (f < 0)
{
// Yeah sure.
stuffcmd (client, "-");
f = fabs (f);
}

if (numdigits <= 0)
{
tmp = f;
numdigits = 1;
while (tmp >= 1)
{
tmp = tmp / 10;
numdigits = numdigits * 10;
}
}

// I don't know what I'm thinking here...
// I need to do this to get zero-padding to work.

while (numdigits > 1)
{
numdigits = numdigits / 10;
tmp = f / numdigits;
stuffcmd_digit (client, tmp);
}
};

//----------------------------------------------------------------------
void(entity client, float f) stuffcmd_float =
{
local float intpart, decpart, isNegative;

isNegative = FALSE;

if (f == 0)
{
stuffcmd (client, "0");
return;
}

if (f < 0)
{
// easier this way
isNegative = TRUE;
f = fabs (f);
}

// 1: stuff the integer part.
intpart = floor (f);
if (isNegative)
stuffcmd (client, "-");
stuffcmd_int (client, intpart, 0);

// 2: stuff the decimal point.
stuffcmd (client, ".");

// 3: stuff the decimal part.
decpart = mod (f, 1);
decpart = decpart * 10000;
stuffcmd_int (client, decpart, 10000);
};

Return to the top of this page or return to the overview of this repo.

Log utility.qc

Date Commit Message Author + -
2024-03-24 2nd pass refactor, rework QC class structure cev +29 -10
2024-01-31 Class based monster refactor & start projectiles cev +22 -22
2023-12-02 More refactoring & moving, begin adding mdls & snd cev +8 -1
2023-11-27 Code reorg, minor movement changes, misc cev +203 -136
2023-10-13 Rename "qc-server" dir to "qc" cev +218  

Return to the top of this page or return to the overview of this repo.