2019-09-18 07:16:58 -07:00
|
|
|
// common.qc: common functions
|
|
|
|
|
2019-09-19 13:57:27 -07:00
|
|
|
const float PO2_LUT[25] = {
|
|
|
|
1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768,
|
|
|
|
65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216
|
|
|
|
};
|
|
|
|
|
|
|
|
float(float x, float y) bit_shift_right = {
|
|
|
|
return rint(x / PO2_LUT[y]);
|
|
|
|
};
|
|
|
|
|
|
|
|
float(float x, float y) bit_shift_left = {
|
|
|
|
return rint(x * PO2_LUT[y]);
|
|
|
|
};
|
|
|
|
|
2019-09-18 07:16:58 -07:00
|
|
|
float() crandom = {
|
|
|
|
return 2 * (random() - 0.5);
|
|
|
|
};
|
|
|
|
|
2019-09-18 12:42:12 -07:00
|
|
|
float(float x, float y) max = {
|
|
|
|
return x < y ? y : x;
|
|
|
|
};
|
|
|
|
|
|
|
|
float(float x, float y) min = {
|
|
|
|
return x < y ? x : y;
|
|
|
|
};
|
2019-09-18 07:16:58 -07:00
|
|
|
|
2019-09-18 12:42:12 -07:00
|
|
|
float(float x, float mi, float ma) minmax = {
|
|
|
|
return min(max(x, mi), ma);
|
|
|
|
};
|
|
|
|
|
|
|
|
/* returns the range catagorization of an entity reletive to self
|
|
|
|
* 0 melee range, will become hostile even if back is turned
|
|
|
|
* 1 visibility and infront, or visibility and show hostile
|
|
|
|
* 2 infront and show hostile
|
|
|
|
* 3 only triggered by damage
|
|
|
|
*/
|
2019-09-18 07:16:58 -07:00
|
|
|
float(entity targ) range = {
|
|
|
|
vector spot1, spot2;
|
|
|
|
float r;
|
|
|
|
spot1 = self.origin + self.view_ofs;
|
|
|
|
spot2 = targ.origin + targ.view_ofs;
|
|
|
|
|
|
|
|
r = vlen(spot1 - spot2);
|
|
|
|
if(r < 120) {
|
|
|
|
return RANGE_MELEE;
|
|
|
|
}
|
|
|
|
if(r < 500) {
|
|
|
|
return RANGE_NEAR;
|
|
|
|
}
|
|
|
|
if(r < 1000) {
|
|
|
|
return RANGE_MID;
|
|
|
|
}
|
|
|
|
return RANGE_FAR;
|
|
|
|
};
|
|
|
|
|
2019-09-18 12:42:12 -07:00
|
|
|
// returns 1 if the entity is visible to self, even if not infront()
|
2019-09-18 07:16:58 -07:00
|
|
|
float(entity targ) visible = {
|
|
|
|
vector spot1, spot2;
|
|
|
|
|
|
|
|
spot1 = self.origin + self.view_ofs;
|
|
|
|
spot2 = targ.origin + targ.view_ofs;
|
|
|
|
traceline(spot1, spot2, TRUE, self); // see through other monsters
|
|
|
|
|
|
|
|
if(trace_inopen && trace_inwater) {
|
|
|
|
return FALSE; // sight line crossed contents
|
|
|
|
}
|
|
|
|
|
2019-09-19 07:16:20 -07:00
|
|
|
return trace_fraction == 1;
|
2019-09-18 07:16:58 -07:00
|
|
|
};
|
|
|
|
|
2019-09-18 12:42:12 -07:00
|
|
|
// returns 1 if the entity is in front(in sight) of self
|
2019-09-18 07:16:58 -07:00
|
|
|
float(entity targ) infront = {
|
|
|
|
vector vec;
|
|
|
|
float dot;
|
|
|
|
|
|
|
|
makevectors(self.angles);
|
|
|
|
vec = normalize(targ.origin - self.origin);
|
|
|
|
dot = vec * v_forward;
|
|
|
|
|
2019-09-19 07:16:20 -07:00
|
|
|
return dot > 0.3;
|
2019-09-18 07:16:58 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
// EOF
|