Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
util.qc File Reference
Include dependency graph for util.qc:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define PRECACHE_PIC   draw_PreloadPicture
#define PRECACHE_PIC   precache_pic
#define SKIN_PATH   (strreplace("gfx/menu", "gfx/hud", draw_currentSkin))
#define SKIN_PATH   hud_skin_path
#define X(name, translated_name, cl_hook, mut)

Functions

vector animfixfps (entity e, vector a, vector b)
Notification Announcer_PickNumber (int type, int num)
void attach_sameorigin (entity e, entity to, string tag)
ERASEABLE float blink (float base, float range, float freq)
ERASEABLE float blink_synced (float base, float range, float freq, float start_time, int start_pos)
string build_mutator_list (string s)
float CheckWireframeBox (entity forent, vector v0, vector dvx, vector dvy, vector dvz)
float compressShortVector (vector vec)
float compressShotOrigin (vector v)
ERASEABLE float cvar_or (string cv, float v)
float cvar_settemp (string tmp_cvar, string tmp_value)
int cvar_settemp_restore ()
vector decompressShortVector (int data)
vector decompressShotOrigin (int f)
void depthfirst (entity start,.entity up,.entity downleft,.entity right, void(entity, entity) funcPre, void(entity, entity) funcPost, entity pass)
void detach_sameorigin (entity e)
void execute_next_frame ()
string find_last_color_code (string s)
vector findbetterlocation (vector org, float mindist)
void FindConnectedComponent (entity e,.entity fld, findNextEntityNearFunction_t nxt, isConnectedFunction_t iscon, entity pass)
string fixPriorityList (string order, float from, float to, float subtract, float complete)
void follow_sameorigin (entity e, entity to)
void get_mi_min_max (float mode)
void get_mi_min_max_texcoords (float mode)
string get_model_datafilename (string m, float sk, string fil)
float get_model_parameters (string m, float sk)
vector get_shotvelocity (vector myvel, vector mydir, float spd, float newton_style, float mi, float ma)
string getcurrentmod ()
string getWrappedLine (float maxWidth, vector theFontSize, textLengthUpToWidth_widthFunction_t tw)
string getWrappedLineLen (int maxLength, textLengthUpToLength_lenFunction_t tw)
vector healtharmor_applydamage (float h, float a, float armorblock, int deathtype, float damage)
vector healtharmor_maxdamage (float h, float a, float armorblock, int deathtype)
string icon_path_from_menuskin (string theIcon)
 Returns icon path from the current menu skin (MENU only).
float invertLengthLog (float dist)
float isGametypeInFilter (Gametype gt, float tp, float ts, string pattern)
int LostMovetypeFollow (entity ent)
string mapPriorityList (string order, string(string) mapfunc)
float matchacl (string acl, string str)
int Mod_Q1BSP_NativeContentsFromSuperContents (int supercontents)
int Mod_Q1BSP_SuperContentsFromNativeContents (int nativecontents)
bool mut_is_active (int mut)
void mut_set_active (int mut)
string playername (string thename, int teamid, bool team_colorize)
void queue_to_execute_next_frame (string s)
vector real_origin (entity ent)
string ScoreString (int pFlags, float pValue, int rounds_played)
void SetMovetypeFollow (entity ent, entity e)
bool should_break_after (int c)
bool should_break_before (int c)
void Skeleton_SetBones (entity e)
vector solve_shotdirection (vector myorg, vector myvel, vector eorg, vector evel, float spd, float newton_style)
 STATIC_INIT (compressShortVector)
void SV_Shutdown () void CSQC_Shutdown() void m_shutdown()
string swapInPriorityList (string order, float i, float j)
string take_wrapped_line_until (int take_until, float colorlen)
float textLengthUpToLength (string theText, int maxLength, textLengthUpToLength_lenFunction_t w)
float textLengthUpToWidth (string theText, float maxWidth, vector theSize, textLengthUpToWidth_widthFunction_t w)
string textShortenToLength (string theText, float maxWidth, textLengthUpToLength_lenFunction_t tw)
string textShortenToWidth (string theText, float maxWidth, vector theFontSize, textLengthUpToWidth_widthFunction_t tw)
float trace_hits_box (vector start, vector end, vector thmi, vector thma)
float trace_hits_box_1d (float end, float thmi, float thma)
float tracebox_hits_box (vector start, vector mi, vector ma, vector end, vector thmi, vector thma)
float tracebox_inverted (vector v1, vector mi, vector ma, vector v2, float nomonsters, entity forent, float stopatentity, entity ignorestopatentity)
void traceline_inverted (vector v1, vector v2, float nomonsters, entity forent, float stopatentity, entity ignorestopatentity)
string translate_key (string key)
void UnsetMovetypeFollow (entity ent)
string wordwrap (string s, float l)
void wordwrap_buffer_put (string s)
void wordwrap_buffer_sprint (string s)
void wordwrap_cb (string s, float l, void(string) callback)
void wordwrap_sprint (entity to, string s, float l)
ERASEABLE void write_String_To_File (int fh, string str, bool alsoprint)
float xdecode (string s)
string xencode (int f)

Variables

entity _wordwrap_buffer_sprint_ent
string aiment_classname
float aiment_deadflag
float FindConnectedComponent_processing
float lengthLogTable [128]
float shutdown_running
float skeleton_bones_index
string to_execute_next_frame
float trace_hits_box_a0
float trace_hits_box_a1
string wordwrap_buffer
const string XENCODE_2 = "xX"
const string XENCODE_22 = "0123456789abcdefABCDEF"

Macro Definition Documentation

◆ PRECACHE_PIC [1/2]

#define PRECACHE_PIC   draw_PreloadPicture

Definition at line 215 of file util.qc.

◆ PRECACHE_PIC [2/2]

#define PRECACHE_PIC   precache_pic

Definition at line 215 of file util.qc.

◆ SKIN_PATH [1/2]

#define SKIN_PATH   (strreplace("gfx/menu", "gfx/hud", draw_currentSkin))

Definition at line 216 of file util.qc.

◆ SKIN_PATH [2/2]

#define SKIN_PATH   hud_skin_path

Definition at line 216 of file util.qc.

◆ X

#define X ( name,
translated_name,
cl_hook,
mut )
Value:
case name: \
s2 = cons_mid(s2, ", ", translated_name); \
mut_set_active(mut); \
if (!already_called && !isdemo() && cl_hook != "") \
localcmd("\n", cl_hook, "\n"); \
break;
string name
Definition menu.qh:30
float isdemo()
spree_inf s1 s2 s3loc s2 spree_inf s1 s2 s3loc s2 spree_inf s1 s2 s3loc s2 s1 s2loc s1 s2loc s1 s2loc s1 s2loc s1 s2loc s1 s2loc s1 s2 f1points s1 s2
Definition all.inc:477
ERASEABLE string cons_mid(string a, string mid, string b)
Definition string.qh:285

Referenced by build_mutator_list().

Function Documentation

◆ animfixfps()

vector animfixfps ( entity e,
vector a,
vector b )

Definition at line 1907 of file util.qc.

1908{
1909 // multi-frame anim: keep as-is
1910 if(a.y == 1)
1911 {
1912 float dur = frameduration(e.modelindex, a.x);
1913 if (dur <= 0 && b.y)
1914 {
1915 a = b;
1916 dur = frameduration(e.modelindex, a.x);
1917 }
1918 if (dur > 0)
1919 a.z = 1.0 / dur;
1920 }
1921 return a;
1922}

References entity(), and vector.

Referenced by animdecide_load_if_needed(), CL_WeaponEntity_SetModel(), and monsters_animoverride().

◆ Announcer_PickNumber()

Notification Announcer_PickNumber ( int type,
int num )

Definition at line 1926 of file util.qc.

1927{
1928 return = NULL;
1929 switch (type)
1930 {
1931 case CNT_GAMESTART:
1932 {
1933 switch(num)
1934 {
1935 case 10: return ANNCE_NUM_GAMESTART_10;
1936 case 9: return ANNCE_NUM_GAMESTART_9;
1937 case 8: return ANNCE_NUM_GAMESTART_8;
1938 case 7: return ANNCE_NUM_GAMESTART_7;
1939 case 6: return ANNCE_NUM_GAMESTART_6;
1940 case 5: return ANNCE_NUM_GAMESTART_5;
1941 case 4: return ANNCE_NUM_GAMESTART_4;
1942 case 3: return ANNCE_NUM_GAMESTART_3;
1943 case 2: return ANNCE_NUM_GAMESTART_2;
1944 case 1: return ANNCE_NUM_GAMESTART_1;
1945 }
1946 break;
1947 }
1948 case CNT_KILL:
1949 {
1950 switch(num)
1951 {
1952 case 10: return ANNCE_NUM_KILL_10;
1953 case 9: return ANNCE_NUM_KILL_9;
1954 case 8: return ANNCE_NUM_KILL_8;
1955 case 7: return ANNCE_NUM_KILL_7;
1956 case 6: return ANNCE_NUM_KILL_6;
1957 case 5: return ANNCE_NUM_KILL_5;
1958 case 4: return ANNCE_NUM_KILL_4;
1959 case 3: return ANNCE_NUM_KILL_3;
1960 case 2: return ANNCE_NUM_KILL_2;
1961 case 1: return ANNCE_NUM_KILL_1;
1962 }
1963 break;
1964 }
1965 case CNT_RESPAWN:
1966 {
1967 switch(num)
1968 {
1969 case 10: return ANNCE_NUM_RESPAWN_10;
1970 case 9: return ANNCE_NUM_RESPAWN_9;
1971 case 8: return ANNCE_NUM_RESPAWN_8;
1972 case 7: return ANNCE_NUM_RESPAWN_7;
1973 case 6: return ANNCE_NUM_RESPAWN_6;
1974 case 5: return ANNCE_NUM_RESPAWN_5;
1975 case 4: return ANNCE_NUM_RESPAWN_4;
1976 case 3: return ANNCE_NUM_RESPAWN_3;
1977 case 2: return ANNCE_NUM_RESPAWN_2;
1978 case 1: return ANNCE_NUM_RESPAWN_1;
1979 }
1980 break;
1981 }
1982 case CNT_ROUNDSTART:
1983 {
1984 switch(num)
1985 {
1986 case 10: return ANNCE_NUM_ROUNDSTART_10;
1987 case 9: return ANNCE_NUM_ROUNDSTART_9;
1988 case 8: return ANNCE_NUM_ROUNDSTART_8;
1989 case 7: return ANNCE_NUM_ROUNDSTART_7;
1990 case 6: return ANNCE_NUM_ROUNDSTART_6;
1991 case 5: return ANNCE_NUM_ROUNDSTART_5;
1992 case 4: return ANNCE_NUM_ROUNDSTART_4;
1993 case 3: return ANNCE_NUM_ROUNDSTART_3;
1994 case 2: return ANNCE_NUM_ROUNDSTART_2;
1995 case 1: return ANNCE_NUM_ROUNDSTART_1;
1996 }
1997 break;
1998 }
1999 case CNT_NORMAL:
2000 default:
2001 {
2002 switch(num)
2003 {
2004 case 10: return ANNCE_NUM_10;
2005 case 9: return ANNCE_NUM_9;
2006 case 8: return ANNCE_NUM_8;
2007 case 7: return ANNCE_NUM_7;
2008 case 6: return ANNCE_NUM_6;
2009 case 5: return ANNCE_NUM_5;
2010 case 4: return ANNCE_NUM_4;
2011 case 3: return ANNCE_NUM_3;
2012 case 2: return ANNCE_NUM_2;
2013 case 1: return ANNCE_NUM_1;
2014 }
2015 break;
2016 }
2017 }
2018}
const int CNT_NORMAL
Definition util.qh:258
const int CNT_RESPAWN
Definition util.qh:262
const int CNT_KILL
Definition util.qh:261
const int CNT_ROUNDSTART
Definition util.qh:263
const int CNT_GAMESTART
Definition util.qh:259
#define NULL
Definition post.qh:14

References CNT_GAMESTART, CNT_KILL, CNT_NORMAL, CNT_RESPAWN, CNT_ROUNDSTART, and NULL.

Referenced by Announcer_Countdown(), instagib_countdown(), KillIndicator_Think(), and ShowRespawnCountdown().

◆ attach_sameorigin()

void attach_sameorigin ( entity e,
entity to,
string tag )

Definition at line 2059 of file util.qc.

2060{
2061 vector org, t_forward, t_left, t_up, e_forward, e_up;
2062 float tagscale;
2063
2064 org = e.origin - gettaginfo(to, gettagindex(to, tag));
2065 tagscale = (vlen(v_forward) ** -2); // undo a scale on the tag
2066 t_forward = v_forward * tagscale;
2067 t_left = v_right * -tagscale;
2068 t_up = v_up * tagscale;
2069
2070 e.origin_x = org * t_forward;
2071 e.origin_y = org * t_left;
2072 e.origin_z = org * t_up;
2073
2074 // current forward and up directions
2075 if (substring(e.model, 0, 1) == "*") // bmodels have their own rules
2076 e.angles = AnglesTransform_FromVAngles(e.angles);
2077 else
2078 e.angles = AnglesTransform_FromAngles(e.angles);
2079 fixedmakevectors(e.angles);
2080
2081 // untransform forward, up!
2082 e_forward.x = v_forward * t_forward;
2083 e_forward.y = v_forward * t_left;
2084 e_forward.z = v_forward * t_up;
2085 e_up.x = v_up * t_forward;
2086 e_up.y = v_up * t_left;
2087 e_up.z = v_up * t_up;
2088
2089 e.angles = fixedvectoangles2(e_forward, e_up);
2090 if (substring(e.model, 0, 1) == "*") // bmodels have their own rules
2091 e.angles = AnglesTransform_ToVAngles(e.angles);
2092 else
2093 e.angles = AnglesTransform_ToAngles(e.angles);
2094
2095 setattachment(e, to, tag);
2096 setorigin(e, e.origin);
2097}
vector AnglesTransform_ToAngles(vector v)
vector AnglesTransform_ToVAngles(vector v)
vector AnglesTransform_FromAngles(vector v)
vector AnglesTransform_FromVAngles(vector v)
#define fixedvectoangles2
void fixedmakevectors(vector a)
vector v_up
vector v_right
vector v_forward
#define gettagindex
string substring(string s, float start, float length)
float vlen(vector v)
#define gettaginfo
Definition post.qh:32
vector
Definition self.qh:96
vector org
Definition self.qh:96

References AnglesTransform_FromAngles(), AnglesTransform_FromVAngles(), AnglesTransform_ToAngles(), AnglesTransform_ToVAngles(), entity(), fixedmakevectors(), fixedvectoangles2, gettagindex, gettaginfo, org, substring(), v_forward, v_right, v_up, vector, and vlen().

Referenced by follow_init().

◆ blink()

ERASEABLE float blink ( float base,
float range,
float freq )

Definition at line 2276 of file util.qc.

2277{
2278 return blink_synced(base, range, freq, 0, 0);
2279}
ERASEABLE float blink_synced(float base, float range, float freq, float start_time, int start_pos)
Definition util.qc:2264
#define base
float freq
Definition pendulum.qc:3

References base, blink_synced(), and freq.

Referenced by DrawItemsTimeItem(), HUD_Get_Num_Color(), HUD_HealthArmor(), HUD_Mod_Keepaway(), HUD_Mod_KH(), HUD_Mod_TeamKeepaway(), and HUD_Radar_InputEvent().

◆ blink_synced()

ERASEABLE float blink_synced ( float base,
float range,
float freq,
float start_time,
int start_pos )

Definition at line 2264 of file util.qc.

2265{
2266 // note:
2267 // RMS = sqrt(base^2 + 0.5 * range^2)
2268 // thus
2269 // base = sqrt(RMS^2 - 0.5 * range^2)
2270 // ensure RMS == 1
2271
2272 return base + range * sin((time - start_time - (M_PI / 2) * start_pos) * freq);
2273}
float time
#define M_PI
pi
Definition mathlib.qh:114
float sin(float f)

References base, freq, M_PI, sin(), and time.

Referenced by blink(), and HUD_HealthArmor().

◆ build_mutator_list()

string build_mutator_list ( string s)

Definition at line 272 of file util.qc.

273{
274 if (s == "")
275 return "";
276
277 static bool already_called = false;
278 if (!already_called && !isdemo())
279 localcmd("\ncl_hook_mutator_all\n");
280
281 int n = tokenizebyseparator(s, ", ");
282 string s2 = "";
283 for (int i = 0; i < n; ++i)
284 {
285 #define X(name, translated_name, cl_hook, mut) \
286 case name: \
287 s2 = cons_mid(s2, ", ", translated_name); \
288 mut_set_active(mut); \
289 if (!already_called && !isdemo() && cl_hook != "") \
290 localcmd("\n", cl_hook, "\n"); \
291 break;
292 switch (argv(i))
293 {
294 X("Dodging" , _("Dodging") , "" , MUT_DODGING)
295 X("InstaGib" , _("InstaGib") , "cl_hook_mutator_instagib" , MUT_INSTAGIB)
296 X("New Toys" , _("New Toys") , "" , MUT_NEW_TOYS)
297 X("NIX" , _("NIX") , "" , MUT_NIX)
298 X("Rocket Flying" , _("Rocket Flying") , "" , MUT_ROCKET_FLYING)
299 X("Invincible Projectiles" , _("Invincible Projectiles") , "" , MUT_INVINCIBLE_PROJECTILES)
300 X("Low gravity" , _("Low Gravity") , "" , MUT_GRAVITY)
301 X("Cloaked" , _("Cloaked") , "" , MUT_CLOAKED)
302 X("Hook" , _("Offhand Hook") , "cl_hook_mutator_hook" , MUT_GRAPPLING_HOOK)
303 X("Midair" , _("Midair") , "" , MUT_MIDAIR)
304 X("Melee only Arena" , _("Melee Only Arena") , "" , MUT_MELEE_ONLY)
305 X("Vampire" , _("Vampire") , "" , MUT_VAMPIRE)
306 X("Piñata" , _("Piñata") , "" , MUT_PINATA)
307 X("Weapons stay" , _("Weapons Stay") , "" , MUT_WEAPON_STAY)
308 X("Blood loss" , _("Blood Loss") , "" , MUT_BLOODLOSS)
309 X("Jetpack" , _("Jetpack") , "cl_hook_mutator_jetpack" , MUT_JETPACK)
310 X("Overkill" , _("Overkill") , "cl_hook_mutator_overkill" , MUT_OVERKILL)
311 X("Buffs" , _("Buffs") , "" , MUT_BUFFS)
312 X("No powerups" , _("No Powerups") , "" , MUT_NO_POWERUPS)
313 X("Powerups" , _("Powerups") , "" , MUT_POWERUPS)
314 X("Buffs replace Powerups" , _("Buffs Replace Powerups") , "" , MUT_BUFFS_REPLACE_POWERUPS)
315 X("Touch explode" , _("Touch Explode") , "" , MUT_TOUCHEXPLODE)
316 X("Wall jumping" , _("Wall Jumping") , "" , MUT_WALLJUMP)
317 X("No start weapons" , _("No Start Weapons") , "" , MUT_NO_START_WEAPONS)
318 X("Nades" , _("Nades") , "" , MUT_NADES)
319 X("Offhand blaster" , _("Offhand Blaster") , "" , MUT_OFFHAND_BLASTER)
320 }
321 #undef X
322 }
323 already_called = true;
324 return s2;
325}
#define X(name, translated_name, cl_hook, mut)
const int MUT_WEAPON_STAY
Definition util.qh:74
const int MUT_VAMPIRE
Definition util.qh:72
const int MUT_GRAPPLING_HOOK
Definition util.qh:69
const int MUT_TOUCHEXPLODE
Definition util.qh:82
const int MUT_JETPACK
Definition util.qh:76
const int MUT_INVINCIBLE_PROJECTILES
Definition util.qh:66
const int MUT_NO_START_WEAPONS
Definition util.qh:84
const int MUT_NEW_TOYS
Definition util.qh:63
const int MUT_ROCKET_FLYING
Definition util.qh:65
const int MUT_DODGING
Definition util.qh:61
const int MUT_INSTAGIB
Definition util.qh:62
const int MUT_GRAVITY
Definition util.qh:67
const int MUT_BLOODLOSS
Definition util.qh:75
const int MUT_MELEE_ONLY
Definition util.qh:71
const int MUT_CLOAKED
Definition util.qh:68
const int MUT_MIDAIR
Definition util.qh:70
const int MUT_OVERKILL
Definition util.qh:77
const int MUT_NIX
Definition util.qh:64
const int MUT_NO_POWERUPS
Definition util.qh:79
const int MUT_PINATA
Definition util.qh:73
const int MUT_POWERUPS
Definition util.qh:80
const int MUT_OFFHAND_BLASTER
Definition util.qh:86
const int MUT_BUFFS_REPLACE_POWERUPS
Definition util.qh:81
const int MUT_WALLJUMP
Definition util.qh:83
const int MUT_NADES
Definition util.qh:85
const int MUT_BUFFS
Definition util.qh:78
#define tokenizebyseparator
void localcmd(string command,...)
string argv(float n)

References argv(), isdemo(), localcmd(), MUT_BLOODLOSS, MUT_BUFFS, MUT_BUFFS_REPLACE_POWERUPS, MUT_CLOAKED, MUT_DODGING, MUT_GRAPPLING_HOOK, MUT_GRAVITY, MUT_INSTAGIB, MUT_INVINCIBLE_PROJECTILES, MUT_JETPACK, MUT_MELEE_ONLY, MUT_MIDAIR, MUT_NADES, MUT_NEW_TOYS, MUT_NIX, MUT_NO_POWERUPS, MUT_NO_START_WEAPONS, MUT_OFFHAND_BLASTER, MUT_OVERKILL, MUT_PINATA, MUT_POWERUPS, MUT_ROCKET_FLYING, MUT_TOUCHEXPLODE, MUT_VAMPIRE, MUT_WALLJUMP, MUT_WEAPON_STAY, s2, tokenizebyseparator, and X.

Referenced by net_handle_ServerWelcome().

◆ CheckWireframeBox()

float CheckWireframeBox ( entity forent,
vector v0,
vector dvx,
vector dvy,
vector dvz )

Definition at line 582 of file util.qc.

583{
584 traceline(v0, v0 + dvx, true, forent); if(trace_fraction < 1) return 0;
585 traceline(v0, v0 + dvy, true, forent); if(trace_fraction < 1) return 0;
586 traceline(v0, v0 + dvz, true, forent); if(trace_fraction < 1) return 0;
587 traceline(v0 + dvx, v0 + dvx + dvy, true, forent); if(trace_fraction < 1) return 0;
588 traceline(v0 + dvx, v0 + dvx + dvz, true, forent); if(trace_fraction < 1) return 0;
589 traceline(v0 + dvy, v0 + dvy + dvx, true, forent); if(trace_fraction < 1) return 0;
590 traceline(v0 + dvy, v0 + dvy + dvz, true, forent); if(trace_fraction < 1) return 0;
591 traceline(v0 + dvz, v0 + dvz + dvx, true, forent); if(trace_fraction < 1) return 0;
592 traceline(v0 + dvz, v0 + dvz + dvy, true, forent); if(trace_fraction < 1) return 0;
593 traceline(v0 + dvx + dvy, v0 + dvx + dvy + dvz, true, forent); if(trace_fraction < 1) return 0;
594 traceline(v0 + dvx + dvz, v0 + dvx + dvy + dvz, true, forent); if(trace_fraction < 1) return 0;
595 traceline(v0 + dvy + dvz, v0 + dvx + dvy + dvz, true, forent); if(trace_fraction < 1) return 0;
596 return 1;
597}
float trace_fraction

References entity(), trace_fraction, and vector.

Referenced by Portal_Spawn(), and Porto_Draw().

◆ compressShortVector()

float compressShortVector ( vector vec)

Definition at line 521 of file util.qc.

522{
523 vector ang;
524 float p, y, len;
525 if(vec == '0 0 0')
526 return 0;
527 //print("compress: ", vtos(vec), "\n");
528 ang = vectoangles(vec);
529 ang.x = -ang.x;
530 if(ang.x < -90)
531 ang.x += 360;
532 if(ang.x < -90 && ang.x > +90)
533 error("BOGUS vectoangles");
534 //print("angles: ", vtos(ang), "\n");
535
536 p = floor(0.5 + (ang.x + 90) * (16 / 180)) & 15; // -90..90 to 0..14
537 if(p == 0)
538 {
539 if(vec.z < 0)
540 y = 31;
541 else
542 y = 30;
543 }
544 else
545 y = floor(0.5 + ang.y * (32 / 360)) & 31; // 0..360 to 0..32
546 len = invertLengthLog(vlen(vec));
547
548 //print("compressed: p:", ftos(p)); print(" y:", ftos(y)); print(" len:", ftos(len), "\n");
549
550 return (p * 0x1000) + (y * 0x80) + len;
551}
float invertLengthLog(float dist)
Definition util.qc:457
v y
Definition ent_cs.qc:146
vector vectoangles(vector v)
float floor(float f)
#define error
Definition pre.qh:6
vector vector ang
Definition self.qh:96

References ang, error, floor(), invertLengthLog(), vectoangles(), vector, vlen(), and y.

Referenced by pointparticles_SendEntity(), rainsnow_SendEntity(), SpawnCasing(), STATIC_INIT(), and Violence_GibSplash_At().

◆ compressShotOrigin()

float compressShotOrigin ( vector v)

Definition at line 1350 of file util.qc.

1351{
1352 int rx_neg = (v.x < 0) ? 1 : 0;
1353 int ry_neg = (v.y < 0) ? 1 : 0;
1354 int rz_neg = (v.z < 0) ? 1 : 0;
1355 int rx = rint(fabs(v.x) * 2);
1356 int ry = rint(fabs(v.y) * 2);
1357 int rz = rint(fabs(v.z) * 2);
1358 if(rx > 255) // 128 * 2 - 1
1359 {
1360 LOG_DEBUG("shot origin ", vtos(v), " x out of bounds\n");
1361 rx = bound(0, rx, 255);
1362 }
1363 if(ry > 63) // 32 * 2 - 1
1364 {
1365 LOG_DEBUG("shot origin ", vtos(v), " y out of bounds\n");
1366 ry = bound(0, ry, 63);
1367 }
1368 if(rz > 63) // 32 * 2 - 1
1369 {
1370 LOG_DEBUG("shot origin ", vtos(v), " z out of bounds\n");
1371 rz = bound(0, rz, 63);
1372 }
1373 ry |= ry_neg * BIT(6) + rx_neg * BIT(7);
1374 rz |= rz_neg * BIT(6); // BIT(7) unused
1375 return rx * 0x10000 + ry * 0x100 + rz;
1376}
#define BIT(n)
Only ever assign into the first 24 bits in QC (so max is BIT(23)).
Definition bits.qh:8
#define LOG_DEBUG(...)
Definition log.qh:78
float bound(float min, float value, float max)
string vtos(vector v)
float rint(float f)
float fabs(float f)

References BIT, bound(), fabs(), LOG_DEBUG, rint(), vector, and vtos().

Referenced by CL_WeaponEntity_SetModel(), and ClientInit_misc().

◆ cvar_or()

ERASEABLE float cvar_or ( string cv,
float v )

Definition at line 2248 of file util.qc.

2249{
2250 string s = cvar_string(cv);
2251 if(s == "")
2252 return v;
2253 else
2254 return stof(s);
2255}
float stof(string val,...)
const string cvar_string(string name)

References cvar_string(), and stof().

◆ cvar_settemp()

float cvar_settemp ( string tmp_cvar,
string tmp_value )

Definition at line 809 of file util.qc.

810{
811 float created_saved_value = 0;
812
813 if (!(tmp_cvar || tmp_value))
814 {
815 LOG_TRACE("Error: Invalid usage of cvar_settemp(string, string); !");
816 return 0;
817 }
818
819 if(!cvar_type(tmp_cvar))
820 {
821 LOG_INFOF("Error: cvar %s doesn't exist!", tmp_cvar);
822 return 0;
823 }
824
825 IL_EACH(g_saved_cvars, it.netname == tmp_cvar,
826 {
827 created_saved_value = -1; // skip creation
828 break; // no need to continue
829 });
830
831 if(created_saved_value != -1)
832 {
833 // creating a new entity to keep track of this cvar
834 entity e = new_pure(saved_cvar_value);
836 e.netname = strzone(tmp_cvar);
837 e.message = strzone(cvar_string(tmp_cvar));
838 created_saved_value = 1;
839 }
840
841 // update the cvar to the value given
842 cvar_set(tmp_cvar, tmp_value);
843
844 return created_saved_value;
845}
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
IntrusiveList g_saved_cvars
Definition util.qh:35
ERASEABLE entity IL_PUSH(IntrusiveList this, entity it)
Push to tail.
#define IL_EACH(this, cond, body)
#define LOG_TRACE(...)
Definition log.qh:74
#define LOG_INFOF(...)
Definition log.qh:63
void cvar_set(string name, string value)
string strzone(string s)
#define new_pure(class)
purely logical entities (not linked to the area grid)
Definition oo.qh:66

References cvar_set(), cvar_string(), entity(), g_saved_cvars, IL_EACH, IL_PUSH(), LOG_INFOF, LOG_TRACE, new_pure, and strzone().

Referenced by _MapInfo_Parse_Settemp(), CampaignPreInit(), CSQC_Init(), CSQCPlayer_PostUpdate(), CSQCPlayer_Remove(), GameCommand_bot_cmd(), GameCommand_nospectators(), GameCommand_setbots(), GenericCommand_settemp(), NET_HANDLE(), NET_HANDLE(), REGISTER_MUTATOR(), View_EventChase(), and View_Ortho().

◆ cvar_settemp_restore()

int cvar_settemp_restore ( )

Definition at line 847 of file util.qc.

848{
849 int j = 0;
850 // FIXME this new-style loop fails!
851#if 0
852 FOREACH_ENTITY_CLASS("saved_cvar_value", true,
853 {
854 if(cvar_type(it.netname))
855 {
856 cvar_set(it.netname, it.message);
857 strunzone(it.netname);
858 strunzone(it.message);
859 delete(it);
860 ++j;
861 }
862 else
863 LOG_INFOF("Error: cvar %s doesn't exist anymore! It can still be restored once it's manually recreated.", it.netname);
864 });
865
866#else
867 entity e = NULL;
868 while((e = find(e, classname, "saved_cvar_value")))
869 {
870 if(cvar_type(e.netname))
871 {
872 cvar_set(e.netname, e.message);
873 delete(e);
874 ++j;
875 }
876 else
877 print(sprintf("Error: cvar %s doesn't exist anymore! It can still be restored once it's manually recreated.", e.netname));
878 }
879#endif
880
881 return j;
882}
string classname
#define FOREACH_ENTITY_CLASS(class, cond, body)
Definition iter.qh:189
entity find(entity start,.string field, string match)
void strunzone(string s)
void print(string text,...)

References classname, cvar_set(), entity(), find(), FOREACH_ENTITY_CLASS, LOG_INFOF, NULL, print(), and strunzone().

Referenced by DoNextMapOverride(), GenericCommand_settemp_restore(), MapInfo_LoadMap(), and SV_Shutdown().

◆ decompressShortVector()

vector decompressShortVector ( int data)

Definition at line 486 of file util.qc.

487{
488 vector out;
489 if(data == 0)
490 return '0 0 0';
491 float p = (data & 0xF000) / 0x1000;
492 float q = (data & 0x0F80) / 0x80;
493 int len = (data & 0x007F);
494
495 //print("\ndecompress: p:", ftos(p)); print(" q:", ftos(q)); print(" len:", ftos(len), "\n");
496
497 if(p == 0)
498 {
499 out.x = 0;
500 out.y = 0;
501 if(q == 31)
502 out.z = -1;
503 else
504 out.z = +1;
505 }
506 else
507 {
508 q = M_PI / 16 * q;
509 p = M_PI / 16 * p - M_PI_2;
510 float cos_p = cos(p);
511 out.x = cos(q) * cos_p;
512 out.y = sin(q) * cos_p;
513 out.z = -sin(p);
514 }
515
516 //print("decompressed: ", vtos(out), "\n");
517
518 return out * lengthLogTable[len];
519}
float lengthLogTable[128]
Definition util.qc:455
const float M_PI_2
pi/2
Definition mathlib.qh:115
float cos(float f)

References cos(), lengthLogTable, M_PI, M_PI_2, sin(), and vector.

Referenced by NET_HANDLE(), NET_HANDLE(), and STATIC_INIT().

◆ decompressShotOrigin()

vector decompressShotOrigin ( int f)

Definition at line 1377 of file util.qc.

1378{
1379 vector v;
1380 v.x = f >> 16;
1381 v.y = (f & 0xFF00) >> 8;
1382 v.z = f & 0xFF;
1383 // remove sign bits and apply sign
1384 if (v.y & BIT(7)) { v.y &= ~BIT(7); v.x *= -1; }
1385 if (v.y & BIT(6)) { v.y &= ~BIT(6); v.y *= -1; }
1386 if (v.z & BIT(6)) { v.z &= ~BIT(6); v.z *= -1; }
1387 return v * 0.5;
1388}

References BIT, and vector.

Referenced by CL_WeaponEntity_SetModel(), NET_HANDLE(), and TrueAimCheck().

◆ depthfirst()

void depthfirst ( entity start,
.entity up,
.entity downleft,
.entity right,
void(entity, entity) funcPre,
void(entity, entity) funcPost,
entity pass )

Definition at line 394 of file util.qc.

395{
396 entity e = start;
397 funcPre(pass, e);
398 while (e.(downleft))
399 {
400 e = e.(downleft);
401 funcPre(pass, e);
402 }
403 funcPost(pass, e);
404 while(e != start)
405 {
406 if (e.(right))
407 {
408 e = e.(right);
409 funcPre(pass, e);
410 while (e.(downleft))
411 {
412 e = e.(downleft);
413 funcPre(pass, e);
414 }
415 }
416 else
417 e = e.(up);
418 funcPost(pass, e);
419 }
420}
#define pass(name, colormin, colormax)

References entity(), and pass.

Referenced by forAllDescendants().

◆ detach_sameorigin()

void detach_sameorigin ( entity e)

Definition at line 2099 of file util.qc.

2100{
2101 vector org = gettaginfo(e, 0);
2102 e.angles = fixedvectoangles2(v_forward, v_up);
2103 if (substring(e.model, 0, 1) == "*") // bmodels have their own rules
2104 e.angles = AnglesTransform_ToVAngles(e.angles);
2105 else
2106 e.angles = AnglesTransform_ToAngles(e.angles);
2107 setorigin(e, org);
2108 setattachment(e, NULL, "");
2109 setorigin(e, e.origin);
2110}

References AnglesTransform_ToAngles(), AnglesTransform_ToVAngles(), entity(), fixedvectoangles2, gettaginfo, NULL, org, substring(), v_forward, v_up, and vector.

Referenced by Drag().

◆ execute_next_frame()

void execute_next_frame ( )

Definition at line 1847 of file util.qc.

1848{
1850 {
1851 localcmd("\n", to_execute_next_frame, "\n");
1853 }
1854}
string to_execute_next_frame
Definition util.qc:1846
#define strfree(this)
Definition string.qh:57

References localcmd(), strfree, and to_execute_next_frame.

Referenced by CSQC_UpdateView(), m_draw(), and StartFrame().

◆ find_last_color_code()

string find_last_color_code ( string s)

Definition at line 956 of file util.qc.

957{
958 int start = strstrofs(s, "^", 0);
959 if (start == -1) // no caret found
960 return "";
961 int len = strlen(s)-1;
962 for(int i = len; i >= start; --i)
963 {
964 if(substring(s, i, 1) != "^")
965 continue;
966
967 int carets = 1;
968 while (i-carets >= start && substring(s, i-carets, 1) == "^")
969 ++carets;
970
971 // check if carets aren't all escaped
972 if (carets & 1)
973 {
974 if(i+1 <= len)
975 if(IS_DIGIT(substring(s, i+1, 1)))
976 {
977 if(start == 0 && len == 1)
978 return "";
979 return substring(s, i, 2);
980 }
981
982 if(i+4 <= len)
983 if(substring(s, i+1, 1) == "x")
984 if(IS_HEXDIGIT(substring(s, i + 2, 1)))
985 if(IS_HEXDIGIT(substring(s, i + 3, 1)))
986 if(IS_HEXDIGIT(substring(s, i + 4, 1)))
987 {
988 if(start == 0 && len == 4)
989 return "";
990 return substring(s, i, 5);
991 }
992 }
993 i -= carets; // this also skips one char before the carets
994 }
995
996 return "";
997}
#define strstrofs
#define strlen
#define IS_DIGIT(d)
Definition string.qh:583
#define IS_HEXDIGIT(d)
Definition string.qh:580

References IS_DIGIT, IS_HEXDIGIT, strlen, strstrofs, and substring().

Referenced by hash_replace(), minigame_getWrappedLine(), and take_wrapped_line_until().

◆ findbetterlocation()

vector findbetterlocation ( vector org,
float mindist )

Definition at line 116 of file util.qc.

117{
118 vector vec = mindist * '1 0 0';
119 int c = 0;
120 while (c < 6)
121 {
122 traceline (org, org + vec, true, NULL);
123 vec = -vec;
124 if (trace_fraction < 1)
125 {
126 vector loc = trace_endpos;
127 traceline (loc, loc + vec, true, NULL);
128 if (trace_fraction >= 1)
129 org = loc + vec;
130 }
131 if (c & 1)
132 {
133 float h = vec.y;
134 vec.y = vec.x;
135 vec.x = vec.z;
136 vec.z = h;
137 }
138 ++c;
139 }
140
141 return org;
142}
vector trace_endpos

References NULL, org, trace_endpos, trace_fraction, and vector.

Referenced by nade_boom().

◆ FindConnectedComponent()

void FindConnectedComponent ( entity e,
.entity fld,
findNextEntityNearFunction_t nxt,
isConnectedFunction_t iscon,
entity pass )

Definition at line 1865 of file util.qc.

1866{
1867 entity queue_start, queue_end;
1868
1869 // we build a queue of to-be-processed entities.
1870 // queue_start is the next entity to be checked for neighbors
1871 // queue_end is the last entity added
1872
1873 if(e.FindConnectedComponent_processing)
1874 error("recursion or broken cleanup");
1875
1876 // start with a 1-element queue
1877 queue_start = queue_end = e;
1878 queue_end.(fld) = NULL;
1879 queue_end.FindConnectedComponent_processing = 1;
1880
1881 // for each queued item:
1882 for (; queue_start; queue_start = queue_start.(fld))
1883 {
1884 // find all neighbors of queue_start
1885 entity t;
1886 for(t = NULL; (t = nxt(t, queue_start, pass)); )
1887 {
1888 if(t.FindConnectedComponent_processing)
1889 continue;
1890 if(iscon(t, queue_start, pass))
1891 {
1892 // it is connected? ADD IT. It will look for neighbors soon too.
1893 queue_end.(fld) = t;
1894 queue_end = t;
1895 queue_end.(fld) = NULL;
1896 queue_end.FindConnectedComponent_processing = 1;
1897 }
1898 }
1899 }
1900
1901 // unmark
1902 for (queue_start = e; queue_start; queue_start = queue_start.(fld))
1903 queue_start.FindConnectedComponent_processing = 0;
1904}

References entity(), error, NULL, and pass.

Referenced by LinkDoors().

◆ fixPriorityList()

string fixPriorityList ( string order,
float from,
float to,
float subtract,
float complete )

Definition at line 600 of file util.qc.

601{
602 string neworder;
603 float i, n, w;
604
605 n = tokenize_console(order);
606 neworder = "";
607 for(i = 0; i < n; ++i)
608 {
609 w = stof(argv(i));
610 if(w == floor(w))
611 {
612 if(w >= from && w <= to)
613 neworder = strcat(neworder, ftos(w), " ");
614 else
615 {
616 w -= subtract;
617 if(w >= from && w <= to)
618 neworder = strcat(neworder, ftos(w), " ");
619 }
620 }
621 }
622
623 if(complete)
624 {
625 n = tokenize_console(neworder);
626 for(w = to; w >= from; --w)
627 {
628 int wflags = REGISTRY_GET(Weapons, w).spawnflags;
629 if(wflags & WEP_FLAG_SPECIALATTACK)
630 continue;
631 for(i = 0; i < n; ++i)
632 if(stof(argv(i)) == w)
633 break;
634 if(i == n) // not found
635 neworder = strcat(neworder, ftos(w), " ");
636 }
637 }
638
639 return substring(neworder, 0, strlen(neworder) - 1);
640}
#define tokenize_console
Weapons
Definition guide.qh:113
string ftos(float f)
strcat(_("^F4Countdown stopped!"), "\n^BG", _("Teams are too unbalanced."))
#define REGISTRY_GET(id, i)
Definition registry.qh:62
const int WEP_FLAG_SPECIALATTACK
special attack (not a true weapon); NOTE: if this flag is set then WEP_FLAG_HIDDEN must be set as wel...
Definition weapon.qh:264

References argv(), floor(), ftos(), REGISTRY_GET, stof(), strcat(), strlen, substring(), tokenize_console, Weapons, and WEP_FLAG_SPECIALATTACK.

Referenced by W_FixWeaponOrder().

◆ follow_sameorigin()

void follow_sameorigin ( entity e,
entity to )

Definition at line 2112 of file util.qc.

2113{
2114 set_movetype(e, MOVETYPE_FOLLOW); // make the hole follow
2115 e.aiment = to; // make the hole follow bmodel
2116 e.punchangle = to.angles; // the original angles of bmodel
2117 e.view_ofs = e.origin - to.origin; // relative origin
2118 e.v_angle = e.angles - to.angles; // relative angles
2119}
void set_movetype(entity this, int mt)
Definition movetypes.qc:4
const int MOVETYPE_FOLLOW
Definition movetypes.qh:145

References entity(), MOVETYPE_FOLLOW, and set_movetype().

Referenced by follow_init().

◆ get_mi_min_max()

void get_mi_min_max ( float mode)

Definition at line 676 of file util.qc.

677{
678 vector mi, ma;
679
680 string s = mapname;
681 if(!strcasecmp(substring(s, 0, 5), "maps/"))
682 s = substring(s, 5, strlen(s) - 5);
683 if(!strcasecmp(substring(s, strlen(s) - 4, 4), ".bsp"))
684 s = substring(s, 0, strlen(s) - 4);
686
687#ifdef CSQC
688 mi = world.mins;
689 ma = world.maxs;
690#else
691 mi = world.absmin;
692 ma = world.absmax;
693#endif
694
695 mi_min = mi;
696 mi_max = ma;
699 {
702 }
703 else
704 {
705 // not specified
706 if(mode)
707 {
708 // be clever
709 tracebox('1 0 0' * mi.x,
710 '0 1 0' * mi.y + '0 0 1' * mi.z,
711 '0 1 0' * ma.y + '0 0 1' * ma.z,
712 '1 0 0' * ma.x,
714 NULL);
716 mi_min.x = trace_endpos.x;
717
718 tracebox('0 1 0' * mi.y,
719 '1 0 0' * mi.x + '0 0 1' * mi.z,
720 '1 0 0' * ma.x + '0 0 1' * ma.z,
721 '0 1 0' * ma.y,
723 NULL);
725 mi_min.y = trace_endpos.y;
726
727 tracebox('0 0 1' * mi.z,
728 '1 0 0' * mi.x + '0 1 0' * mi.y,
729 '1 0 0' * ma.x + '0 1 0' * ma.y,
730 '0 0 1' * ma.z,
732 NULL);
734 mi_min.z = trace_endpos.z;
735
736 tracebox('1 0 0' * ma.x,
737 '0 1 0' * mi.y + '0 0 1' * mi.z,
738 '0 1 0' * ma.y + '0 0 1' * ma.z,
739 '1 0 0' * mi.x,
741 NULL);
743 mi_max.x = trace_endpos.x;
744
745 tracebox('0 1 0' * ma.y,
746 '1 0 0' * mi.x + '0 0 1' * mi.z,
747 '1 0 0' * ma.x + '0 0 1' * ma.z,
748 '0 1 0' * mi.y,
750 NULL);
752 mi_max.y = trace_endpos.y;
753
754 tracebox('0 0 1' * ma.z,
755 '1 0 0' * mi.x + '0 1 0' * mi.y,
756 '1 0 0' * ma.x + '0 1 0' * ma.y,
757 '0 0 1' * mi.z,
759 NULL);
761 mi_max.z = trace_endpos.z;
762 }
763 }
764}
string mi_shortname
Definition util.qh:133
vector mi_min
Definition util.qh:134
vector mi_max
Definition util.qh:135
string mapname
float trace_startsolid
float MOVE_WORLDONLY
#define strcasecmp
int MapInfo_Get_ByName(string pFilename, float pAllowGenerate, Gametype pGametypeToSet)
Definition mapinfo.qc:1387
vector MapInfo_Map_maxs
Definition mapinfo.qh:17
vector MapInfo_Map_mins
Definition mapinfo.qh:16
#define world
Definition post.qh:15
#define strcpy(this, s)
Definition string.qh:51

References MapInfo_Get_ByName(), MapInfo_Map_maxs, MapInfo_Map_mins, mapname, mi_max, mi_min, mi_shortname, MOVE_WORLDONLY, NULL, strcasecmp, strcpy, strlen, substring(), trace_endpos, trace_startsolid, vector, and world.

Referenced by get_mi_min_max_texcoords(), and InitGameplayMode().

◆ get_mi_min_max_texcoords()

void get_mi_min_max_texcoords ( float mode)

Definition at line 766 of file util.qc.

767{
768 vector extend;
769
770 get_mi_min_max(mode);
771
774
775 // extend mi_picmax to get a square aspect ratio
776 // center the map in that area
777 extend = mi_picmax - mi_picmin;
778 if(extend.y > extend.x)
779 {
780 mi_picmin.x -= (extend.y - extend.x) * 0.5;
781 mi_picmax.x += (extend.y - extend.x) * 0.5;
782 }
783 else
784 {
785 mi_picmin.y -= (extend.x - extend.y) * 0.5;
786 mi_picmax.y += (extend.x - extend.y) * 0.5;
787 }
788
789 // add another some percent
790 extend = (mi_picmax - mi_picmin) * (1 / 64.0);
791 mi_picmin -= extend;
792 mi_picmax += extend;
793
794 // calculate the texcoords
796 // first the two corners of the origin
797 mi_pictexcoord0_x = (mi_min.x - mi_picmin.x) / (mi_picmax.x - mi_picmin.x);
798 mi_pictexcoord0_y = (mi_min.y - mi_picmin.y) / (mi_picmax.y - mi_picmin.y);
799 mi_pictexcoord2_x = (mi_max.x - mi_picmin.x) / (mi_picmax.x - mi_picmin.x);
800 mi_pictexcoord2_y = (mi_max.y - mi_picmin.y) / (mi_picmax.y - mi_picmin.y);
801 // then the other corners
802 mi_pictexcoord1_x = mi_pictexcoord0_x;
803 mi_pictexcoord1_y = mi_pictexcoord2_y;
804 mi_pictexcoord3_x = mi_pictexcoord2_x;
805 mi_pictexcoord3_y = mi_pictexcoord0_y;
806}
void get_mi_min_max(float mode)
Definition util.qc:676
vector mi_picmin
Definition util.qh:138
vector mi_pictexcoord2
Definition util.qh:142
vector mi_pictexcoord3
Definition util.qh:143
vector mi_pictexcoord0
Definition util.qh:140
vector mi_picmax
Definition util.qh:139
vector mi_pictexcoord1
Definition util.qh:141

References get_mi_min_max(), mi_max, mi_min, mi_picmax, mi_picmin, mi_pictexcoord0, mi_pictexcoord1, mi_pictexcoord2, mi_pictexcoord3, and vector.

Referenced by CSQC_Init().

◆ get_model_datafilename()

string get_model_datafilename ( string m,
float sk,
string fil )

Definition at line 1481 of file util.qc.

1482{
1483 if(m)
1484 m = strcat(m, "_");
1485 else
1486 m = "models/player/*_";
1487 if(sk >= 0)
1488 m = strcat(m, ftos(sk));
1489 else
1490 m = strcat(m, "*");
1491 return strcat(m, ".", fil);
1492}

References ftos(), and strcat().

Referenced by get_model_parameters(), UpdatePlayerSounds(), and XonoticPlayerModelSelector_loadModels().

◆ get_model_parameters()

float get_model_parameters ( string m,
float sk )

Definition at line 1494 of file util.qc.

1495{
1506 for(int i = 0; i < MAX_AIM_BONES; ++i)
1507 {
1510 }
1513
1514#ifdef GAMEQC
1515 MUTATOR_CALLHOOK(ClearModelParams);
1516#endif
1517
1518 if (!m)
1519 return 1;
1520
1521 if(substring(m, -9, 5) == "_lod1" || substring(m, -9, 5) == "_lod2")
1522 m = strcat(substring(m, 0, -10), substring(m, -4, -1));
1523
1524 if(sk < 0)
1525 {
1526 if(substring(m, -4, -1) != ".txt")
1527 return 0;
1528 if(substring(m, -6, 1) != "_")
1529 return 0;
1530 sk = stof(substring(m, -5, 1));
1531 m = substring(m, 0, -7);
1532 }
1533
1534 string fn = get_model_datafilename(m, sk, "txt");
1535 int fh = fopen(fn, FILE_READ);
1536 if(fh < 0)
1537 {
1538 sk = 0;
1539 fn = get_model_datafilename(m, sk, "txt");
1540 fh = fopen(fn, FILE_READ);
1541 if(fh < 0)
1542 return 0;
1543 }
1544
1547 string s, c;
1548 while((s = fgets(fh)))
1549 {
1550 if(s == "")
1551 break; // next lines will be description
1552 c = car(s);
1553 s = cdr(s);
1554 if(c == "name")
1556 if(c == "species")
1557 switch(s)
1558 {
1559 case "human": get_model_parameters_species = SPECIES_HUMAN; break;
1560 case "alien": get_model_parameters_species = SPECIES_ALIEN; break;
1561 case "robot_shiny": get_model_parameters_species = SPECIES_ROBOT_SHINY; break;
1562 case "robot_rusty": get_model_parameters_species = SPECIES_ROBOT_RUSTY; break;
1563 case "robot_solid": get_model_parameters_species = SPECIES_ROBOT_SOLID; break;
1564 case "animal": get_model_parameters_species = SPECIES_ANIMAL; break;
1565 case "reserved": get_model_parameters_species = SPECIES_RESERVED; break;
1566 }
1567 if(c == "sex")
1568 {
1569 if (s == "Male") s = _("Male");
1570 else if (s == "Female") s = _("Female");
1571 else if (s == "Undisclosed") s = _("Undisclosed");
1573 }
1574 if(c == "weight")
1576 if(c == "age")
1578 if(c == "description")
1580 if(c == "bone_upperbody")
1582 if(c == "bone_weapon")
1584 #ifdef GAMEQC
1585 MUTATOR_CALLHOOK(GetModelParams, c, s);
1586 #endif
1587 for(int i = 0; i < MAX_AIM_BONES; ++i)
1588 if(c == strcat("bone_aim", ftos(i)))
1589 {
1592 }
1593 if(c == "fixbone")
1595 if(c == "hidden")
1597 }
1598
1599 while((s = fgets(fh)))
1600 {
1603 if(s != "")
1605 }
1606
1607 fclose(fh);
1608
1609 return 1;
1610}
#define MUTATOR_CALLHOOK(id,...)
Definition base.qh:143
string get_model_datafilename(string m, float sk, string fil)
Definition util.qc:1481
const int MAX_AIM_BONES
Definition util.qh:195
float get_model_parameters_weight
Definition util.qh:189
float get_model_parameters_fixbone
Definition util.qh:198
string get_model_parameters_sex
Definition util.qh:188
float get_model_parameters_species
Definition util.qh:187
float get_model_parameters_bone_aimweight[MAX_AIM_BONES]
Definition util.qh:197
float get_model_parameters_modelskin
Definition util.qh:185
string get_model_parameters_name
Definition util.qh:186
string get_model_parameters_bone_weapon
Definition util.qh:194
string get_model_parameters_description
Definition util.qh:192
bool get_model_parameters_hidden
Definition util.qh:191
string get_model_parameters_modelname
Definition util.qh:184
string get_model_parameters_bone_upperbody
Definition util.qh:193
string get_model_parameters_bone_aim[MAX_AIM_BONES]
Definition util.qh:196
float get_model_parameters_age
Definition util.qh:190
string get_model_parameters_desc
Definition util.qh:199
const int SPECIES_ANIMAL
Definition constants.qh:26
const int SPECIES_ROBOT_SOLID
Definition constants.qh:24
const int SPECIES_ROBOT_RUSTY
Definition constants.qh:27
const int SPECIES_RESERVED
Definition constants.qh:29
const int SPECIES_ROBOT_SHINY
Definition constants.qh:28
const int SPECIES_ALIEN
Definition constants.qh:25
const int SPECIES_HUMAN
Definition constants.qh:23
const float FILE_READ
#define stob(s)
Definition int.qh:5
string fgets(float fhandle)
void fclose(float fhandle)
float fopen(string filename, float mode)
string string_null
Definition nil.qh:9
ERASEABLE string car(string s)
Returns first word.
Definition string.qh:258
ERASEABLE string cdr(string s)
Returns all but first word.
Definition string.qh:268

References car(), cdr(), fclose(), fgets(), FILE_READ, fopen(), ftos(), get_model_datafilename(), get_model_parameters_age, get_model_parameters_bone_aim, get_model_parameters_bone_aimweight, get_model_parameters_bone_upperbody, get_model_parameters_bone_weapon, get_model_parameters_desc, get_model_parameters_description, get_model_parameters_fixbone, get_model_parameters_hidden, get_model_parameters_modelname, get_model_parameters_modelskin, get_model_parameters_name, get_model_parameters_sex, get_model_parameters_species, get_model_parameters_weight, MAX_AIM_BONES, MUTATOR_CALLHOOK, SPECIES_ALIEN, SPECIES_ANIMAL, SPECIES_HUMAN, SPECIES_RESERVED, SPECIES_ROBOT_RUSTY, SPECIES_ROBOT_SHINY, SPECIES_ROBOT_SOLID, stob, stof(), strcat(), string_null, and substring().

Referenced by player_getspecies(), skeleton_loadinfo(), and XonoticPlayerModelSelector_loadModels().

◆ get_shotvelocity()

vector get_shotvelocity ( vector myvel,
vector mydir,
float spd,
float newton_style,
float mi,
float ma )

Definition at line 1298 of file util.qc.

1299{
1300 if(!newton_style)
1301 return spd * mydir;
1302
1303 if(newton_style == 2)
1304 {
1305 // true Newtonian projectiles with automatic aim adjustment
1306 //
1307 // solve: |outspeed * mydir - myvel| = spd
1308 // outspeed^2 - 2 * outspeed * (mydir * myvel) + myvel^2 - spd^2 = 0
1309 // outspeed = (mydir * myvel) +- sqrt((mydir * myvel)^2 - myvel^2 + spd^2)
1310 // PLUS SIGN!
1311 // not defined?
1312 // then...
1313 // myvel^2 - (mydir * myvel)^2 > spd^2
1314 // velocity without mydir component > spd
1315 // fire at smallest possible spd that works?
1316 // |(mydir * myvel) * myvel - myvel| = spd
1317
1318 vector solution = solve_quadratic(1, -2 * (mydir * myvel), myvel * myvel - spd * spd);
1319
1320 float outspeed;
1321 if(solution.z)
1322 outspeed = solution.y; // the larger one
1323 else
1324 {
1325 //outspeed = 0; // slowest possible shot
1326 outspeed = solution.x; // the real part (that is, the average!)
1327 //dprint("impossible shot, adjusting\n");
1328 }
1329
1330 outspeed = bound(spd * mi, outspeed, spd * ma);
1331 return mydir * outspeed;
1332 }
1333
1334 // real Newtonian
1335 return myvel + spd * mydir;
1336}
ERASEABLE vector solve_quadratic(float a, float b, float c)
ax^2 + bx + c = 0
Definition math.qh:312

References bound(), solve_quadratic(), and vector.

Referenced by W_CalculateProjectileVelocity().

◆ getcurrentmod()

string getcurrentmod ( )

Definition at line 1429 of file util.qc.

1430{
1431 string m = cvar_string("fs_gamedir");
1432 float n = tokenize_console(m);
1433 if(n == 0)
1434 return "data";
1435 else
1436 return argv(n - 1);
1437}

References argv(), cvar_string(), and tokenize_console.

Referenced by resolvemod().

◆ getWrappedLine()

string getWrappedLine ( float maxWidth,
vector theFontSize,
textLengthUpToWidth_widthFunction_t tw )

Definition at line 1133 of file util.qc.

1134{
1135 string s = getWrappedLine_remaining;
1136 if (maxWidth <= 0)
1137 {
1139 return s; // the line has no size ANYWAY, nothing would be displayed.
1140 }
1141
1142 int take_until = textLengthUpToWidth(s, maxWidth, theFontSize, tw);
1143
1144 if (take_until <= 0 || take_until >= strlen(s)) {
1146 return s; // remaining text fits the line
1147 }
1148
1149 float colorlen = tw("^7", theFontSize);
1150 return take_wrapped_line_until(take_until, colorlen);
1151}
string take_wrapped_line_until(int take_until, float colorlen)
Definition util.qc:1064
float textLengthUpToWidth(string theText, float maxWidth, vector theSize, textLengthUpToWidth_widthFunction_t w)
Definition util.qc:884
string getWrappedLine_remaining
Definition util.qh:154

References getWrappedLine_remaining, string_null, strlen, take_wrapped_line_until(), textLengthUpToWidth(), and vector.

Referenced by Checkpoints_drawstring(), GameTypeVote_DrawGameTypeItem(), HUD_CenterPrint(), InfoMessages_drawstring(), Label_draw(), Label_recalcPositionWithText(), m_tooltip(), rewrapCampaign(), wrapGuideText(), XonoticEntryList_drawListBoxItem(), and XonoticTextBox_setText().

◆ getWrappedLineLen()

string getWrappedLineLen ( int maxLength,
textLengthUpToLength_lenFunction_t tw )

Definition at line 1153 of file util.qc.

1154{
1155 string s = getWrappedLine_remaining;
1156 if (maxLength <= 0)
1157 {
1159 return s; // the line has no size ANYWAY, nothing would be displayed.
1160 }
1161
1162 int take_until = textLengthUpToLength(s, maxLength, tw);
1163
1164 if (take_until <= 0 || take_until >= strlen(s)) {
1166 return s; // remaining text fits the line
1167 }
1168
1169 float colorlen = tw("^7");
1170 return take_wrapped_line_until(take_until, colorlen);
1171}
float textLengthUpToLength(string theText, int maxLength, textLengthUpToLength_lenFunction_t w)
Definition util.qc:920

References getWrappedLine_remaining, string_null, strlen, take_wrapped_line_until(), and textLengthUpToLength().

Referenced by Say().

◆ healtharmor_applydamage()

vector healtharmor_applydamage ( float h,
float a,
float armorblock,
int deathtype,
float damage )

Definition at line 1415 of file util.qc.

1416{
1417 vector v;
1418 if (DEATH_IS(deathtype, DEATH_DROWN)) // Why should armor help here...
1419 armorblock = 0;
1420 if (deathtype & HITTYPE_ARMORPIERCE)
1421 armorblock = 0;
1422 v.y = bound(0, damage * armorblock, a); // save
1423 v.x = bound(0, damage - v.y, h); // take
1424 v.z = 0;
1425 return v;
1426}
const int HITTYPE_ARMORPIERCE
ignore armor calculations
Definition all.qh:34
#define DEATH_IS(t, dt)
Definition all.qh:42

References bound(), DEATH_IS, HITTYPE_ARMORPIERCE, and vector.

Referenced by Damage(), Monster_Damage(), PlayerCorpseDamage(), and PlayerDamage().

◆ healtharmor_maxdamage()

vector healtharmor_maxdamage ( float h,
float a,
float armorblock,
int deathtype )

Definition at line 1391 of file util.qc.

1392{
1393 // NOTE: we'll always choose the SMALLER value...
1394 float healthdamage, armordamage, armorideal;
1395 if (DEATH_IS(deathtype, DEATH_DROWN)) // Why should armor help here...
1396 armorblock = 0;
1397 vector v;
1398 healthdamage = (h - 1) / (1 - armorblock); // damage we can take if we could use more health
1399 armordamage = a + (h - 1); // damage we can take if we could use more armor
1400 armorideal = healthdamage * armorblock;
1401 v.y = armorideal;
1402 if(armordamage < healthdamage)
1403 {
1404 v.x = armordamage;
1405 v.z = 1;
1406 }
1407 else
1408 {
1409 v.x = healthdamage;
1410 v.z = 0;
1411 }
1412 return v;
1413}

References DEATH_IS, and vector.

Referenced by crosshair_getcolor(), ctf_FlagcarrierWaypoints(), HUD_HealthArmor(), if(), PlayerFrame(), and WaypointSprite_AttachCarrier().

◆ icon_path_from_menuskin()

string icon_path_from_menuskin ( string theIcon)

Returns icon path from the current menu skin (MENU only).

Definition at line 239 of file util.qc.

240{
241 if (theIcon == "")
242 return "";
243
244 string img = strcat("/", draw_currentSkin, "/", theIcon);
245 if (draw_PreloadPicture(img) == "")
246 img = sprintf("/gfx/menu/wickedx/%s", theIcon); // default menu skin
247 return img;
248}
string draw_PreloadPicture(string pic)
Definition draw.qc:60

References draw_PreloadPicture(), and strcat().

Referenced by Gametype::display(), Monster::display(), and Mutator::display().

◆ invertLengthLog()

float invertLengthLog ( float dist)

Definition at line 457 of file util.qc.

458{
459 int l, r, m;
460
461 if(dist >= lengthLogTable[127])
462 return 127;
463 if(dist <= lengthLogTable[0])
464 return 0;
465
466 l = 0;
467 r = 127;
468
469 while(r - l > 1)
470 {
471 m = floor((l + r) / 2);
472 if(lengthLogTable[m] < dist)
473 l = m;
474 else
475 r = m;
476 }
477
478 // now: r is >=, l is <
479 float lerr = (dist - lengthLogTable[l]);
480 float rerr = (lengthLogTable[r] - dist);
481 if(lerr < rerr)
482 return l;
483 return r;
484}

References floor(), and lengthLogTable.

Referenced by compressShortVector().

◆ isGametypeInFilter()

float isGametypeInFilter ( Gametype gt,
float tp,
float ts,
string pattern )

Definition at line 1189 of file util.qc.

1190{
1191 string subpattern, subpattern2, subpattern3, subpattern4;
1192 subpattern = strcat(",", MapInfo_Type_ToString(gt), ",");
1193 if(tp)
1194 subpattern2 = ",teams,";
1195 else
1196 subpattern2 = ",noteams,";
1197 if(ts)
1198 subpattern3 = ",teamspawns,";
1199 else
1200 subpattern3 = ",noteamspawns,";
1201 if(gt == MAPINFO_TYPE_RACE || gt == MAPINFO_TYPE_CTS)
1202 subpattern4 = ",race,";
1203 else
1204 subpattern4 = string_null;
1205
1206 if(substring(pattern, 0, 1) == "-")
1207 {
1208 pattern = substring(pattern, 1, strlen(pattern) - 1);
1209 if(strstrofs(strcat(",", pattern, ","), subpattern, 0) >= 0)
1210 return 0;
1211 if(strstrofs(strcat(",", pattern, ","), subpattern2, 0) >= 0)
1212 return 0;
1213 if(strstrofs(strcat(",", pattern, ","), subpattern3, 0) >= 0)
1214 return 0;
1215 if(subpattern4 && strstrofs(strcat(",", pattern, ","), subpattern4, 0) >= 0)
1216 return 0;
1217 }
1218 else
1219 {
1220 if(substring(pattern, 0, 1) == "+")
1221 pattern = substring(pattern, 1, strlen(pattern) - 1);
1222 if(strstrofs(strcat(",", pattern, ","), subpattern, 0) < 0)
1223 if(strstrofs(strcat(",", pattern, ","), subpattern2, 0) < 0)
1224 if(strstrofs(strcat(",", pattern, ","), subpattern3, 0) < 0)
1225 {
1226 if (!subpattern4)
1227 return 0;
1228 if(strstrofs(strcat(",", pattern, ","), subpattern4, 0) < 0)
1229 return 0;
1230 }
1231 }
1232 return 1;
1233}
string MapInfo_Type_ToString(Gametype t)
Definition mapinfo.qc:655

References MapInfo_Type_ToString(), strcat(), string_null, strlen, strstrofs, and substring().

Referenced by Cmd_Scoreboard_SetFields(), and SV_OnEntityPreSpawnFunction().

◆ LostMovetypeFollow()

int LostMovetypeFollow ( entity ent)

Definition at line 2161 of file util.qc.

2162{
2163/*
2164 if(ent.move_movetype != MOVETYPE_FOLLOW)
2165 if(ent.aiment)
2166 error("???");
2167*/
2168 // FIXME: engine bug?
2169 // when aiment disconnects the engine will set orb's origin close to world's origin
2170 if(!ent.aiment)
2171 return 2;
2172 if(ent.aiment.classname != ent.aiment_classname || ent.aiment.deadflag != ent.aiment_deadflag)
2173 return 1;
2174 return 0;
2175}

References entity().

Referenced by GrapplingHookThink(), W_Electro_Orb_Follow_Think(), and W_MineLayer_Think().

◆ mapPriorityList()

string mapPriorityList ( string order,
string(string) mapfunc )

Definition at line 642 of file util.qc.

643{
644 string neworder;
645 float n = tokenize_console(order);
646 neworder = "";
647 for(float i = 0; i < n; ++i)
648 neworder = strcat(neworder, mapfunc(argv(i)), " ");
649
650 return substring(neworder, 0, strlen(neworder) - 1);
651}

References argv(), strcat(), strlen, substring(), and tokenize_console.

Referenced by W_NameWeaponOrder(), and W_NumberWeaponOrder().

◆ matchacl()

float matchacl ( string acl,
string str )

Definition at line 1439 of file util.qc.

1440{
1441 string t, s;
1442 float r, d;
1443 r = 0;
1444 while(acl)
1445 {
1446 t = car(acl); acl = cdr(acl);
1447
1448 d = 1;
1449 if(substring(t, 0, 1) == "-")
1450 {
1451 d = -1;
1452 t = substring(t, 1, strlen(t) - 1);
1453 }
1454 else if(substring(t, 0, 1) == "+")
1455 t = substring(t, 1, strlen(t) - 1);
1456
1457 if(substring(t, -1, 1) == "*")
1458 {
1459 t = substring(t, 0, strlen(t) - 1);
1460 s = substring(str, 0, strlen(t));
1461 }
1462 else
1463 s = str;
1464
1465 if(s == t)
1466 {
1467 r = d;
1468 break; // if we found a killing case, apply it! other settings may be allowed in the future, but this one is caught
1469 }
1470 }
1471 return r;
1472}

References car(), cdr(), strlen, and substring().

Referenced by _MapInfo_Parse_Settemp().

◆ Mod_Q1BSP_NativeContentsFromSuperContents()

int Mod_Q1BSP_NativeContentsFromSuperContents ( int supercontents)

Definition at line 2042 of file util.qc.

2043{
2044 if(supercontents & (DPCONTENTS_SOLID | DPCONTENTS_BODY))
2045 return CONTENT_SOLID;
2046 if(supercontents & DPCONTENTS_SKY)
2047 return CONTENT_SKY;
2048 if(supercontents & DPCONTENTS_LAVA)
2049 return CONTENT_LAVA;
2050 if(supercontents & DPCONTENTS_SLIME)
2051 return CONTENT_SLIME;
2052 if(supercontents & DPCONTENTS_WATER)
2053 return CONTENT_WATER;
2054 return CONTENT_EMPTY;
2055}
float DPCONTENTS_SKY
const float CONTENT_SKY
float DPCONTENTS_SOLID
const float CONTENT_SOLID
float DPCONTENTS_BODY
const float CONTENT_WATER
float DPCONTENTS_SLIME
float DPCONTENTS_LAVA
const float CONTENT_LAVA
float DPCONTENTS_WATER
const float CONTENT_EMPTY
const float CONTENT_SLIME

References CONTENT_EMPTY, CONTENT_LAVA, CONTENT_SKY, CONTENT_SLIME, CONTENT_SOLID, CONTENT_WATER, DPCONTENTS_BODY, DPCONTENTS_LAVA, DPCONTENTS_SKY, DPCONTENTS_SLIME, DPCONTENTS_SOLID, and DPCONTENTS_WATER.

◆ Mod_Q1BSP_SuperContentsFromNativeContents()

int Mod_Q1BSP_SuperContentsFromNativeContents ( int nativecontents)

Definition at line 2022 of file util.qc.

2023{
2024 switch(nativecontents)
2025 {
2026 case CONTENT_EMPTY:
2027 return 0;
2028 case CONTENT_SOLID:
2030 case CONTENT_WATER:
2031 return DPCONTENTS_WATER;
2032 case CONTENT_SLIME:
2033 return DPCONTENTS_SLIME;
2034 case CONTENT_LAVA:
2036 case CONTENT_SKY:
2037 return DPCONTENTS_SKY | DPCONTENTS_NODROP | DPCONTENTS_OPAQUE; // to match behaviour of Q3 maps, let sky count as opaque
2038 }
2039 return 0;
2040}
float DPCONTENTS_NODROP
float DPCONTENTS_OPAQUE

References CONTENT_EMPTY, CONTENT_LAVA, CONTENT_SKY, CONTENT_SLIME, CONTENT_SOLID, CONTENT_WATER, DPCONTENTS_LAVA, DPCONTENTS_NODROP, DPCONTENTS_OPAQUE, DPCONTENTS_SKY, DPCONTENTS_SLIME, DPCONTENTS_SOLID, and DPCONTENTS_WATER.

Referenced by _Movetype_CheckWater(), and racer_frame().

◆ mut_is_active()

bool mut_is_active ( int mut)

Definition at line 263 of file util.qc.

264{
265 if (mut >= 24)
266 return (active_mutators[1] & (BIT(mut - 24)));
267 else
268 return (active_mutators[0] & BIT(mut));
269}
int active_mutators[2]
Definition util.qh:90

References active_mutators, and BIT.

Referenced by MUTATOR_HOOKFUNCTION(), MUTATOR_HOOKFUNCTION(), MUTATOR_HOOKFUNCTION(), and MUTATOR_HOOKFUNCTION().

◆ mut_set_active()

void mut_set_active ( int mut)

Definition at line 255 of file util.qc.

256{
257 if (mut >= 24)
258 active_mutators[1] |= BIT(mut - 24);
259 else
260 active_mutators[0] |= BIT(mut);
261}

References active_mutators, and BIT.

◆ playername()

string playername ( string thename,
int teamid,
bool team_colorize )

Definition at line 2180 of file util.qc.

2181{
2182 TC(int, teamid);
2183 bool do_colorize = (teamplay && team_colorize);
2184#ifdef SVQC
2185 if(do_colorize && !intermission_running)
2186#else
2187 if(do_colorize)
2188#endif
2189 {
2190 string t = Team_ColorCode(teamid);
2191 return strcat(t, strdecolorize(thename));
2192 }
2193 else
2194 return thename;
2195}
bool intermission_running
#define TC(T, sym)
Definition _all.inc:82
bool teamplay
Definition teams.qh:59
string Team_ColorCode(int teamid)
Definition teams.qh:63

References intermission_running, strcat(), TC, Team_ColorCode(), and teamplay.

Referenced by CheatsAllowed(), ClientCommand_ready(), ClientConnect(), Draw_ShowNames(), DumpStats(), GameCommand_adminmsg(), GameCommand_defer_clear(), GameCommand_moveplayer(), GetCallerName(), MatchEnd_RestoreSpectatorAndTeamStatus(), NextLevel(), OriginalCallerName(), PlayerFrame(), PlayerStats_GameReport_FinalizePlayer(), Remove_Countdown(), Say(), Score_NicePrint_Player(), Score_NicePrint_Spectator(), TeamBalance_RemoveExcessPlayers(), and W_HitPlotOpen().

◆ queue_to_execute_next_frame()

void queue_to_execute_next_frame ( string s)

Definition at line 1855 of file util.qc.

1856{
1858 {
1859 s = strcat(s, "\n", to_execute_next_frame);
1860 }
1862}

References strcat(), strcpy, and to_execute_next_frame.

Referenced by GenericCommand_nextframe().

◆ real_origin()

vector real_origin ( entity ent)

Definition at line 147 of file util.qc.

148{
149 vector v = ((ent.absmin + ent.absmax) * 0.5);
150 entity e = ent.tag_entity;
151
152 while(e)
153 {
154 v += (e.absmin + e.absmax) * 0.5;
155 e = e.tag_entity;
156 }
157
158 return v;
159}

References entity(), and vector.

Referenced by bumblebee_gunner_exit(), bumblebee_gunner_frame(), bumblebee_pilot_frame(), racer_frame(), raptor_frame(), turret_aim_generic(), turret_do_updates(), turret_targetscore_generic(), turret_validate_target(), and vehicles_damage().

◆ ScoreString()

string ScoreString ( int pFlags,
float pValue,
int rounds_played )

Definition at line 423 of file util.qc.

424{
425 string valstr;
426 float l;
427
428 pValue = floor(pValue + 0.5); // round
429
430 if((pValue == 0) && (pFlags & (SFL_HIDE_ZERO | SFL_RANK | SFL_TIME)))
431 valstr = "";
432 else if(pFlags & SFL_RANK)
433 valstr = (pValue < 256 ? count_ordinal(pValue) : _("N/A"));
434 else if(pFlags & SFL_TIME)
435 valstr = TIME_ENCODED_TOSTRING(pValue, true);
436 else if (rounds_played)
437 valstr = sprintf("%.1f", pValue / rounds_played);
438 else
439 valstr = ftos(pValue);
440
441 return valstr;
442}
const int SFL_TIME
Display as mm:ss.s, value is stored as 10ths of a second (AND 0 is the worst possible value!...
Definition scores.qh:122
const int SFL_RANK
Display as a rank (with st, nd, rd, th suffix).
Definition scores.qh:117
const int SFL_HIDE_ZERO
Don't show zero values as scores.
Definition scores.qh:107
int rounds_played
Definition stats.qh:379
#define TIME_ENCODED_TOSTRING(n, compact)
Definition util.qh:103
ERASEABLE string count_ordinal(int interval)
Definition counting.qh:66

References count_ordinal(), floor(), ftos(), rounds_played, SFL_HIDE_ZERO, SFL_RANK, SFL_TIME, and TIME_ENCODED_TOSTRING.

Referenced by Score_NicePrint_Player(), Score_NicePrint_Team(), Scoreboard_Fraglimit_Draw(), and Scoreboard_GetField().

◆ SetMovetypeFollow()

void SetMovetypeFollow ( entity ent,
entity e )

Definition at line 2131 of file util.qc.

2132{
2133 set_movetype(ent, MOVETYPE_FOLLOW); // make the hole follow
2134 ent.solid = SOLID_NOT; // MOVETYPE_FOLLOW is always non-solid - this means this cannot be teleported by warpzones any more! Instead, we must notice when our owner gets teleported.
2135 ent.aiment = e; // make the hole follow bmodel
2136 ent.punchangle = e.angles; // the original angles of bmodel
2137 ent.view_ofs = ent.origin - e.origin; // relative origin
2138 ent.v_angle = ent.angles - e.angles; // relative angles
2139 ent.aiment_classname = e.classname;
2140 ent.aiment_deadflag = e.deadflag;
2141
2142 if(IS_PLAYER(ent.aiment))
2143 {
2144 entity pl = ent.aiment;
2145 ent.view_ofs.x = bound(pl.mins.x + 4, ent.view_ofs.x, pl.maxs.x - 4);
2146 ent.view_ofs.y = bound(pl.mins.y + 4, ent.view_ofs.y, pl.maxs.y - 4);
2147 ent.view_ofs.z = bound(pl.mins.z + 4, ent.view_ofs.z, pl.maxs.z - 4);
2148 }
2149}
#define IS_PLAYER(s)
Definition player.qh:242
const float SOLID_NOT

References bound(), entity(), IS_PLAYER, MOVETYPE_FOLLOW, set_movetype(), and SOLID_NOT.

Referenced by GrapplingHookTouch(), W_Electro_Orb_Stick(), and W_MineLayer_Stick().

◆ should_break_after()

bool should_break_after ( int c)

Definition at line 1023 of file util.qc.

1023 {
1024 switch (c)
1025 {
1026 case 0x3001: /* 、 */
1027 case 0x3002: /* 。 */
1028 case 0x3009: /* 〉 */
1029 case 0x300b: /* 》 */
1030 case 0x300d: /* 」 */
1031 case 0x300f: /* 』 */
1032 case 0x3011: /* 】 */
1033 case 0xff01: /* ! */
1034 case 0xff09: /* ) */
1035 case 0xff0c: /* , */
1036 case 0xff1a: /* : */
1037 case 0xff1b: /* ; */
1038 case 0xff1f: /* ? */
1039 /* rarely used */
1040 // case 0x3015: /* 〕 */
1041 // case 0x3017: /* 〗 */
1042 // case 0x3019: /* 〙 */
1043 // case 0x301b: /* 〛 */
1044 // case 0x301e: /* 〞 */
1045 // case 0x301f: /* 〟 */
1046 // case 0x3099: /* ゙ */
1047 // case 0x309a: /* ゚ */
1048 // case 0x309b: /* ゛ */
1049 // case 0x309c: /* ゜ */
1050 // case 0xff0e: /* . */
1051 // case 0xff3d: /* ] */
1052 // case 0xff5d: /* } */
1053 // case 0xff60: /* ⦆ */
1054 // case 0xff63: /* 」 */
1055 // case 0xff61: /* 。 */
1056 // case 0xff64: /* 、 */
1057 // case 0xff9e: /* ゙ */
1058 // case 0xff9f: /* ゚ */
1059 return true;
1060 }
1061 return false;
1062}

Referenced by take_wrapped_line_until().

◆ should_break_before()

bool should_break_before ( int c)

Definition at line 999 of file util.qc.

999 {
1000 switch (c)
1001 {
1002 case 0x3008: /* 〈 */
1003 case 0x300a: /* 《 */
1004 case 0x300c: /* 「 */
1005 case 0x300e: /* 『 */
1006 case 0x3010: /* 【 */
1007 case 0xff08: /* ( */
1008 /* rarely used */
1009 // case 0x3014: /* 〔 */
1010 // case 0x3016: /* 〖 */
1011 // case 0x3018: /* 〘 */
1012 // case 0x301a: /* 〚 */
1013 // case 0x301d: /* 〝 */
1014 // case 0xff3b: /* [ */
1015 // case 0xff5b: /* { */
1016 // case 0xff5f: /* ⦅ */
1017 // case 0xff62: /* 「 */
1018 return true;
1019 }
1020 return false;
1021}

Referenced by take_wrapped_line_until().

◆ Skeleton_SetBones()

void Skeleton_SetBones ( entity e)

Definition at line 1833 of file util.qc.

1834{
1835 // set skeleton_bones to the total number of bones on the model
1836 if(e.skeleton_bones_index == e.modelindex)
1837 return; // same model, nothing to update
1838
1839 float skelindex = skel_create(e.modelindex);
1840 e.skeleton_bones = skel_get_numbones(skelindex);
1841 skel_delete(skelindex);
1842 e.skeleton_bones_index = e.modelindex;
1843}

References entity().

◆ solve_shotdirection()

vector solve_shotdirection ( vector myorg,
vector myvel,
vector eorg,
vector evel,
float spd,
float newton_style )

Definition at line 1235 of file util.qc.

1236{
1237 vector ret;
1238
1239 // make origin and speed relative
1240 eorg -= myorg;
1241 if(newton_style)
1242 evel -= myvel;
1243
1244 // now solve for ret, ret normalized:
1245 // eorg + t * evel == t * ret * spd
1246 // or, rather, solve for t:
1247 // |eorg + t * evel| == t * spd
1248 // eorg^2 + t^2 * evel^2 + 2 * t * (eorg * evel) == t^2 * spd^2
1249 // t^2 * (evel^2 - spd^2) + t * (2 * (eorg * evel)) + eorg^2 == 0
1250 vector solution = solve_quadratic(evel * evel - spd * spd, 2 * (eorg * evel), eorg * eorg);
1251 // p = 2 * (eorg * evel) / (evel * evel - spd * spd)
1252 // q = (eorg * eorg) / (evel * evel - spd * spd)
1253 if(!solution.z) // no real solution
1254 {
1255 // happens if D < 0
1256 // (eorg * evel)^2 < (evel^2 - spd^2) * eorg^2
1257 // (eorg * evel)^2 / eorg^2 < evel^2 - spd^2
1258 // spd^2 < ((evel^2 * eorg^2) - (eorg * evel)^2) / eorg^2
1259 // spd^2 < evel^2 * (1 - cos^2 angle(evel, eorg))
1260 // spd^2 < evel^2 * sin^2 angle(evel, eorg)
1261 // spd < |evel| * sin angle(evel, eorg)
1262 return '0 0 0';
1263 }
1264 else if(solution.x > 0)
1265 {
1266 // both solutions > 0: take the smaller one
1267 // happens if p < 0 and q > 0
1268 ret = normalize(eorg + solution.x * evel);
1269 }
1270 else if(solution.y > 0)
1271 {
1272 // one solution > 0: take the larger one
1273 // happens if q < 0 or q == 0 and p < 0
1274 ret = normalize(eorg + solution.y * evel);
1275 }
1276 else
1277 {
1278 // no solution > 0: reject
1279 // happens if p > 0 and q >= 0
1280 // 2 * (eorg * evel) / (evel * evel - spd * spd) > 0
1281 // (eorg * eorg) / (evel * evel - spd * spd) >= 0
1282 //
1283 // |evel| >= spd
1284 // eorg * evel > 0
1285 //
1286 // "Enemy is moving away from me at more than spd"
1287 return '0 0 0';
1288 }
1289
1290 // NOTE: we always got a solution if spd > |evel|
1291
1292 if(newton_style == 2)
1293 ret = normalize(ret * spd + myvel);
1294
1295 return ret;
1296}
vector normalize(vector v)

References normalize(), solve_quadratic(), and vector.

◆ STATIC_INIT()

STATIC_INIT ( compressShortVector )

Definition at line 553 of file util.qc.

554{
555 float l = 1;
556 float f = (2 ** (1/8));
557 int i;
558 for(i = 0; i < 128; ++i)
559 {
560 lengthLogTable[i] = l;
561 l *= f;
562 }
563
564 if(cvar("developer") > 0)
565 {
566 LOG_TRACE("Verifying vector compression table...");
567 for(i = 0x0F00; i < 0xFFFF; ++i)
569 {
571 "BROKEN vector compression: %s -> %s -> %s",
572 ftos(i),
575 );
576 }
577 LOG_TRACE("Done.");
578 }
579}
float compressShortVector(vector vec)
Definition util.qc:521
vector decompressShortVector(int data)
Definition util.qc:486
#define LOG_FATALF(...)
Definition log.qh:51
float cvar(string name)

References compressShortVector(), cvar(), decompressShortVector(), ftos(), lengthLogTable, LOG_FATALF, LOG_TRACE, and vtos().

◆ SV_Shutdown()

void SV_Shutdown ( )

Definition at line 1809 of file util.qc.

1817{
1819 {
1820 LOG_INFO("Recursive shutdown detected! Only restoring cvars...");
1821 }
1822 else
1823 {
1824 shutdown_running = 1;
1825 Shutdown();
1826 shutdownhooks();
1827 }
1828 cvar_settemp_restore(); // this must be done LAST, but in any case
1829}
void Shutdown()
Definition main.qc:163
float shutdown_running
Definition util.qc:1807
int cvar_settemp_restore()
Definition util.qc:847
#define LOG_INFO(...)
Definition log.qh:62
#define shutdownhooks()
Definition static.qh:51

References cvar_settemp_restore(), LOG_INFO, Shutdown(), shutdown_running, and shutdownhooks.

◆ swapInPriorityList()

string swapInPriorityList ( string order,
float i,
float j )

Definition at line 653 of file util.qc.

654{
655 float n = tokenize_console(order);
656
657 if(i >= 0 && i < n && j >= 0 && j < n && i != j)
658 {
659 string s = "";
660 for(float w = 0; w < n; ++w)
661 {
662 if(w == i)
663 s = strcat(s, argv(j), " ");
664 else if(w == j)
665 s = strcat(s, argv(i), " ");
666 else
667 s = strcat(s, argv(w), " ");
668 }
669 return substring(s, 0, strlen(s) - 1);
670 }
671
672 return order;
673}

References argv(), strcat(), strlen, substring(), and tokenize_console.

Referenced by WeaponsList_MoveDown_Click(), WeaponsList_MoveUp_Click(), XonoticPlayList_mouseDrag(), and XonoticWeaponsList_mouseDrag().

◆ take_wrapped_line_until()

string take_wrapped_line_until ( int take_until,
float colorlen )

Definition at line 1064 of file util.qc.

1065{
1066 string s = getWrappedLine_remaining;
1067 int c = 0;
1068 int i = take_until;
1069 int skip = 0;
1070 bool take_next_char = false;
1071 while (i > 0)
1072 {
1073 --i;
1074 c = str2chr(s, i);
1075
1076 // break at ascii space, and skip it
1077 if (c == 0x20)
1078 {
1079 skip = 1;
1080 break;
1081 }
1082
1083 // optimize for many non-CJK languages
1084 if (c < 0x3000)
1085 continue;
1086
1087 if (should_break_before(c))
1088 break;
1089
1090 if (should_break_after(c)
1091 /* Unicode range that can break anywhere */
1092 || (c >= 0x3000 && c <= 0x9fff) // CJK Symbols and Ideographs
1093 || (c >= 0xac00 && c <= 0xd7af) // Hangul Syllables
1094 /* CJK Unified Ideographs Extension, B to G, rarely used */
1095 /*
1096 || (c >= 0x20000 && c <= 0x2a6df)
1097 || (c >= 0x2a700 && c <= 0x2b73f)
1098 || (c >= 0x2b740 && c <= 0x2b81f)
1099 || (c >= 0x2b820 && c <= 0x2ceaf)
1100 || (c >= 0x2ebf0 && c <= 0x2eeff)
1101 || (c >= 0x30000 && c <= 0x303ff)
1102 */
1103 )
1104 {
1105 ++i;
1106 take_next_char = true;
1107 break;
1108 }
1109 }
1110
1111 if (i != 0)
1112 {
1113 // If the next line starts with a punctuation,
1114 // wrap before the last character instead.
1115 if (take_next_char)
1116 {
1117 // str2chr is bound checked in darkplaces.
1118 c = str2chr(s, i);
1119 if (should_break_after(c))
1120 --i;
1121 }
1122 take_until = i;
1123 }
1124
1125 getWrappedLine_remaining = substring(s, take_until + skip, strlen(s) - take_until);
1126 if (getWrappedLine_remaining == "")
1128 else if (colorlen == 0)
1130 return substring(s, 0, take_until);
1131}
bool should_break_before(int c)
Definition util.qc:999
string find_last_color_code(string s)
Definition util.qc:956
bool should_break_after(int c)
Definition util.qc:1023
#define str2chr

References find_last_color_code(), getWrappedLine_remaining, should_break_after(), should_break_before(), str2chr, strcat(), string_null, strlen, and substring().

Referenced by getWrappedLine(), and getWrappedLineLen().

◆ textLengthUpToLength()

float textLengthUpToLength ( string theText,
int maxLength,
textLengthUpToLength_lenFunction_t w )

Definition at line 920 of file util.qc.

921{
922 // STOP.
923 // The following function is SLOW.
924 // For your safety and for the protection of those around you...
925 // DO NOT CALL THIS AT HOME.
926 // No really, don't.
927 if(w(theText) <= maxLength)
928 return strlen(theText); // yeah!
929
930 bool colors = (w("^7") == 0);
931
932 // binary search for right place to cut string
933 int len, left, right, middle;
934 left = 0;
935 right = len = strlen(theText);
936 int ofs = 0;
937 do
938 {
939 middle = floor((left + right) / 2);
940 if(colors)
941 {
942 vector res = checkColorCode(theText, len, middle, true);
943 ofs = (!res.x) ? 0 : res.x - res.y;
944 }
945
946 if(w(substring(theText, 0, middle + ofs)) <= maxLength)
947 left = middle + ofs;
948 else
949 right = middle;
950 }
951 while(left < right - 1);
952
953 return left;
954}
v x
Definition ent_cs.qc:146
ERASEABLE vector checkColorCode(string theText, int text_len, int pos, bool check_at_the_end)
Returns 0 if pos is NOT in the middle or at the end of a color code otherwise it returns a vector wit...
Definition string.qh:616

References checkColorCode(), floor(), strlen, substring(), and vector.

Referenced by getWrappedLineLen(), PlayerFrame(), and textShortenToLength().

◆ textLengthUpToWidth()

float textLengthUpToWidth ( string theText,
float maxWidth,
vector theSize,
textLengthUpToWidth_widthFunction_t w )

Definition at line 884 of file util.qc.

885{
886 // STOP.
887 // The following function is SLOW.
888 // For your safety and for the protection of those around you...
889 // DO NOT CALL THIS AT HOME.
890 // No really, don't.
891 if(w(theText, theSize) <= maxWidth)
892 return strlen(theText); // yeah!
893
894 bool colors = (w("^7", theSize) == 0);
895
896 // binary search for right place to cut string
897 int len, left, right, middle;
898 left = 0;
899 right = len = strlen(theText);
900 int ofs = 0;
901 do
902 {
903 middle = floor((left + right) / 2);
904 if(colors)
905 {
906 vector res = checkColorCode(theText, len, middle, false);
907 ofs = (res.x) ? res.x - res.y : 0;
908 }
909
910 if(w(substring(theText, 0, middle + ofs), theSize) <= maxWidth)
911 left = middle + ofs;
912 else
913 right = middle;
914 }
915 while(left < right - 1);
916
917 return left;
918}

References checkColorCode(), floor(), strlen, substring(), and vector.

Referenced by draw_TextLengthUpToWidth(), getWrappedLine(), minigame_getWrappedLine(), and textShortenToWidth().

◆ textShortenToLength()

string textShortenToLength ( string theText,
float maxWidth,
textLengthUpToLength_lenFunction_t tw )

Definition at line 1181 of file util.qc.

1182{
1183 if(tw(theText) <= maxWidth)
1184 return theText;
1185 else
1186 return strcat(substring(theText, 0, textLengthUpToLength(theText, maxWidth - tw("..."), tw)), "...");
1187}

References strcat(), substring(), and textLengthUpToLength().

◆ textShortenToWidth()

string textShortenToWidth ( string theText,
float maxWidth,
vector theFontSize,
textLengthUpToWidth_widthFunction_t tw )

◆ trace_hits_box()

float trace_hits_box ( vector start,
vector end,
vector thmi,
vector thma )

Definition at line 2221 of file util.qc.

2222{
2223 end -= start;
2224 thmi -= start;
2225 thma -= start;
2226 // now it is a trace from 0 to end
2227
2230
2231 if (!trace_hits_box_1d(end.x, thmi.x, thma.x))
2232 return false;
2233 if (!trace_hits_box_1d(end.y, thmi.y, thma.y))
2234 return false;
2235 if (!trace_hits_box_1d(end.z, thmi.z, thma.z))
2236 return false;
2237
2238 return true;
2239}
float trace_hits_box_a1
Definition util.qc:2197
float trace_hits_box_a0
Definition util.qc:2197
float trace_hits_box_1d(float end, float thmi, float thma)
Definition util.qc:2199

References trace_hits_box_1d(), trace_hits_box_a0, trace_hits_box_a1, and vector.

Referenced by Headshot(), and tracebox_hits_box().

◆ trace_hits_box_1d()

float trace_hits_box_1d ( float end,
float thmi,
float thma )

Definition at line 2199 of file util.qc.

2200{
2201 if (end == 0)
2202 {
2203 // just check if x is in range
2204 if (0 < thmi)
2205 return false;
2206 if (0 > thma)
2207 return false;
2208 }
2209 else
2210 {
2211 // do the trace with respect to x
2212 // 0 -> end has to stay in thmi -> thma
2213 trace_hits_box_a0 = max(trace_hits_box_a0, min(thmi / end, thma / end));
2214 trace_hits_box_a1 = min(trace_hits_box_a1, max(thmi / end, thma / end));
2216 return false;
2217 }
2218 return true;
2219}
float min(float f,...)
float max(float f,...)

References max(), min(), trace_hits_box_a0, and trace_hits_box_a1.

Referenced by trace_hits_box().

◆ tracebox_hits_box()

float tracebox_hits_box ( vector start,
vector mi,
vector ma,
vector end,
vector thmi,
vector thma )

Definition at line 2241 of file util.qc.

2242{
2243 return trace_hits_box(start, end, thmi - ma, thma - mi);
2244}
float trace_hits_box(vector start, vector end, vector thmi, vector thma)
Definition util.qc:2221

References trace_hits_box(), and vector.

Referenced by tracebox_hits_trigger_hurt().

◆ tracebox_inverted()

float tracebox_inverted ( vector v1,
vector mi,
vector ma,
vector v2,
float nomonsters,
entity forent,
float stopatentity,
entity ignorestopatentity )

Definition at line 23 of file util.qc.

24{
25 vector pos, dir, t;
26 float nudge;
27 entity stopentity;
28
29 //nudge = 2 * cvar("collision_impactnudge"); // why not?
30 nudge = 0.5;
31
32 dir = normalize(v2 - v1);
33
34 pos = v1 + dir * nudge;
35
36 float c = 0;
37
38 for (;;)
39 {
40 if(pos * dir >= v2 * dir)
41 {
42 // went too far
44 trace_endpos = v2;
45 return c;
46 }
47
48 tracebox(pos, mi, ma, v2, nomonsters, forent);
49 ++c;
50
51 if(c == 50)
52 {
53 LOG_TRACE("When tracing from ", vtos(v1), " to ", vtos(v2));
54 LOG_TRACE(" Nudging gets us nowhere at ", vtos(pos));
55 LOG_TRACE(" trace_endpos is ", vtos(trace_endpos));
56 LOG_TRACE(" trace distance is ", ftos(vlen(pos - trace_endpos)));
57 }
58
59 stopentity = trace_ent;
60
62 {
63 // we started inside solid.
64 // then trace from endpos to pos
65 t = trace_endpos;
66 tracebox(t, mi, ma, pos, nomonsters, forent);
67 ++c;
69 {
70 // t is still inside solid? bad
71 // force advance, then, and retry
72 pos = t + dir * nudge;
73
74 // but if we hit an entity, stop RIGHT before it
75 if(stopatentity && stopentity && stopentity != ignorestopatentity)
76 {
77 trace_ent = stopentity;
78 trace_endpos = t;
79 trace_fraction = ((trace_endpos - v1) * dir) / ((v2 - v1) * dir);
80 return c;
81 }
82 }
83 else
84 {
85 // we actually LEFT solid!
86 trace_fraction = ((trace_endpos - v1) * dir) / ((v2 - v1) * dir);
87 return c;
88 }
89 }
90 else
91 {
92 // pos is outside solid?!? but why?!? never mind, just return it.
93 trace_endpos = pos;
94 trace_fraction = ((trace_endpos - v1) * dir) / ((v2 - v1) * dir);
95 return c;
96 }
97 }
98}
entity trace_ent
int dir
Definition impulse.qc:89

References dir, entity(), ftos(), LOG_TRACE, normalize(), trace_endpos, trace_ent, trace_fraction, trace_startsolid, vector, vlen(), and vtos().

Referenced by traceline_inverted().

◆ traceline_inverted()

void traceline_inverted ( vector v1,
vector v2,
float nomonsters,
entity forent,
float stopatentity,
entity ignorestopatentity )

Definition at line 100 of file util.qc.

101{
102 tracebox_inverted(v1, '0 0 0', '0 0 0', v2, nomonsters, forent, stopatentity, ignorestopatentity);
103}
float tracebox_inverted(vector v1, vector mi, vector ma, vector v2, float nomonsters, entity forent, float stopatentity, entity ignorestopatentity)
Definition util.qc:23

References entity(), tracebox_inverted(), and vector.

Referenced by fireBullet_falloff().

◆ translate_key()

string translate_key ( string key)

Definition at line 1612 of file util.qc.

1613{
1614 if (prvm_language == "en") return key;
1615
1616 if (substring(key, 0, 1) == "<")
1617 {
1618 if (key == "<KEY NOT FOUND>") return _("<KEY NOT FOUND>");
1619 if (key == "<UNKNOWN KEYNUM>") return _("<UNKNOWN KEYNUM>");
1620 }
1621
1622 switch(key)
1623 {
1624 case "TAB": return _("TAB");
1625 case "ENTER": return _("ENTER");
1626 case "ESCAPE": return _("ESCAPE");
1627 case "SPACE": return _("SPACE");
1628
1629 case "BACKSPACE": return _("BACKSPACE");
1630 case "UPARROW": return _("UPARROW");
1631 case "DOWNARROW": return _("DOWNARROW");
1632 case "LEFTARROW": return _("LEFTARROW");
1633 case "RIGHTARROW": return _("RIGHTARROW");
1634
1635 case "ALT": return _("ALT");
1636 case "CTRL": return _("CTRL");
1637 case "SHIFT": return _("SHIFT");
1638
1639 case "INS": return _("INS");
1640 case "DEL": return _("DEL");
1641 case "PGDN": return _("PGDN");
1642 case "PGUP": return _("PGUP");
1643 case "HOME": return _("HOME");
1644 case "END": return _("END");
1645
1646 case "PAUSE": return _("PAUSE");
1647
1648 case "NUMLOCK": return _("NUMLOCK");
1649 case "CAPSLOCK": return _("CAPSLOCK");
1650 case "SCROLLOCK": return _("SCROLLOCK");
1651
1652 case "SEMICOLON": return _("SEMICOLON");
1653 case "TILDE": return _("TILDE");
1654 case "BACKQUOTE": return _("BACKQUOTE");
1655 case "QUOTE": return _("QUOTE");
1656 case "APOSTROPHE": return _("APOSTROPHE");
1657 case "BACKSLASH": return _("BACKSLASH");
1658 }
1659
1660 if (substring(key, 0, 1) == "F")
1661 {
1662 string subkey = substring(key, 1, -1);
1663 if (IS_DIGIT(substring(key, 3, 1))) // check only first digit
1664 {
1665 return sprintf(_("F%d"), stof(subkey));
1666 }
1667 // continue in case there is another key name starting with F
1668 }
1669
1670 if (substring(key, 0, 3) == "KP_")
1671 {
1672 string subkey = substring(key, 3, -1);
1673 if (IS_DIGIT(substring(key, 3, 1))) // check only first digit
1674 {
1675 return sprintf(_("KP_%d"), stof(subkey));
1676 }
1677
1678 switch(subkey)
1679 {
1680 case "INS": return sprintf(_("KP_%s"), _("INS"));
1681 case "END": return sprintf(_("KP_%s"), _("END"));
1682 case "DOWNARROW": return sprintf(_("KP_%s"), _("DOWNARROW"));
1683 case "PGDN": return sprintf(_("KP_%s"), _("PGDN"));
1684 case "LEFTARROW": return sprintf(_("KP_%s"), _("LEFTARROW"));
1685 case "RIGHTARROW": return sprintf(_("KP_%s"), _("RIGHTARROW"));
1686 case "HOME": return sprintf(_("KP_%s"), _("HOME"));
1687 case "UPARROW": return sprintf(_("KP_%s"), _("UPARROW"));
1688 case "PGUP": return sprintf(_("KP_%s"), _("PGUP"));
1689 case "PERIOD": return sprintf(_("KP_%s"), _("PERIOD"));
1690 case "DEL": return sprintf(_("KP_%s"), _("DEL"));
1691 case "DIVIDE": return sprintf(_("KP_%s"), _("DIVIDE"));
1692 case "SLASH": return sprintf(_("KP_%s"), _("SLASH"));
1693 case "MULTIPLY": return sprintf(_("KP_%s"), _("MULTIPLY"));
1694 case "MINUS": return sprintf(_("KP_%s"), _("MINUS"));
1695 case "PLUS": return sprintf(_("KP_%s"), _("PLUS"));
1696 case "ENTER": return sprintf(_("KP_%s"), _("ENTER"));
1697 case "EQUALS": return sprintf(_("KP_%s"), _("EQUALS"));
1698 default: return key;
1699 }
1700 }
1701
1702 if (key == "PRINTSCREEN") return _("PRINTSCREEN");
1703
1704 if (substring(key, 0, 5) == "MOUSE")
1705 return sprintf(_("MOUSE%d"), stof(substring(key, 5, -1)));
1706
1707 if (key == "MWHEELUP") return _("MWHEELUP");
1708 if (key == "MWHEELDOWN") return _("MWHEELDOWN");
1709
1710 if (substring(key, 0,3) == "JOY")
1711 return sprintf(_("JOY%d"), stof(substring(key, 3, -1)));
1712
1713 if (substring(key, 0,3) == "AUX")
1714 return sprintf(_("AUX%d"), stof(substring(key, 3, -1)));
1715
1716 if (substring(key, 0, 4) == "X360_")
1717 {
1718 string subkey = substring(key, 4, -1);
1719 switch(subkey)
1720 {
1721 case "DPAD_UP": return sprintf(_("X360_%s"), _("DPAD_UP"));
1722 case "DPAD_DOWN": return sprintf(_("X360_%s"), _("DPAD_DOWN"));
1723 case "DPAD_LEFT": return sprintf(_("X360_%s"), _("DPAD_LEFT"));
1724 case "DPAD_RIGHT": return sprintf(_("X360_%s"), _("DPAD_RIGHT"));
1725 case "START": return sprintf(_("X360_%s"), _("START"));
1726 case "BACK": return sprintf(_("X360_%s"), _("BACK"));
1727 case "LEFT_THUMB": return sprintf(_("X360_%s"), _("LEFT_THUMB"));
1728 case "RIGHT_THUMB": return sprintf(_("X360_%s"), _("RIGHT_THUMB"));
1729 case "LEFT_SHOULDER": return sprintf(_("X360_%s"), _("LEFT_SHOULDER"));
1730 case "RIGHT_SHOULDER": return sprintf(_("X360_%s"), _("RIGHT_SHOULDER"));
1731 case "LEFT_TRIGGER": return sprintf(_("X360_%s"), _("LEFT_TRIGGER"));
1732 case "RIGHT_TRIGGER": return sprintf(_("X360_%s"), _("RIGHT_TRIGGER"));
1733 case "LEFT_THUMB_UP": return sprintf(_("X360_%s"), _("LEFT_THUMB_UP"));
1734 case "LEFT_THUMB_DOWN": return sprintf(_("X360_%s"), _("LEFT_THUMB_DOWN"));
1735 case "LEFT_THUMB_LEFT": return sprintf(_("X360_%s"), _("LEFT_THUMB_LEFT"));
1736 case "LEFT_THUMB_RIGHT": return sprintf(_("X360_%s"), _("LEFT_THUMB_RIGHT"));
1737 case "RIGHT_THUMB_UP": return sprintf(_("X360_%s"), _("RIGHT_THUMB_UP"));
1738 case "RIGHT_THUMB_DOWN": return sprintf(_("X360_%s"), _("RIGHT_THUMB_DOWN"));
1739 case "RIGHT_THUMB_LEFT": return sprintf(_("X360_%s"), _("RIGHT_THUMB_LEFT"));
1740 case "RIGHT_THUMB_RIGHT": return sprintf(_("X360_%s"), _("RIGHT_THUMB_RIGHT"));
1741 default: return key;
1742 }
1743 }
1744
1745 if (substring(key, 0, 4) == "JOY_")
1746 {
1747 string subkey = substring(key, 4, -1);
1748 switch(subkey)
1749 {
1750 case "UP": return sprintf(_("JOY_%s"), _("UP"));
1751 case "DOWN": return sprintf(_("JOY_%s"), _("DOWN"));
1752 case "LEFT": return sprintf(_("JOY_%s"), _("LEFT"));
1753 case "RIGHT": return sprintf(_("JOY_%s"), _("RIGHT"));
1754 default: return key;
1755 }
1756 }
1757
1758 if (substring(key, 0, 8) == "MIDINOTE")
1759 return sprintf(_("MIDINOTE%d"), stof(substring(key, 8, -1)));
1760
1761 return key;
1762}
string prvm_language
Definition i18n.qh:8

References IS_DIGIT, prvm_language, stof(), and substring().

Referenced by _getcommandkey(), KeyBinds_BuildList(), Scoreboard_Draw(), W_Guide_Keybinds(), and XonoticKeyBinder_drawListBoxItem().

◆ UnsetMovetypeFollow()

void UnsetMovetypeFollow ( entity ent)

Definition at line 2151 of file util.qc.

2152{
2155 ent.aiment_classname = string_null;
2156 // FIXME: engine bug?
2157 // resetting aiment the engine will set orb's origin close to world's origin
2158 //ent.aiment = NULL;
2159}
const int MOVETYPE_FLY
Definition movetypes.qh:138
#define PROJECTILE_MAKETRIGGER(e)
Definition common.qh:46

References entity(), MOVETYPE_FLY, PROJECTILE_MAKETRIGGER, set_movetype(), and string_null.

Referenced by W_MineLayer_Think().

◆ wordwrap()

string wordwrap ( string s,
float l )

Definition at line 169 of file util.qc.

170{
171 string r;
172 wordwrap_buffer = "";
174 r = wordwrap_buffer;
175 wordwrap_buffer = "";
176 return r;
177}
void wordwrap_cb(string s, float l, void(string) callback)
Definition util.qc:328
void wordwrap_buffer_put(string s)
Definition util.qc:164
string wordwrap_buffer
Definition util.qc:162

References wordwrap_buffer, wordwrap_buffer_put(), and wordwrap_cb().

◆ wordwrap_buffer_put()

void wordwrap_buffer_put ( string s)

Definition at line 164 of file util.qc.

165{
167}

References strcat(), and wordwrap_buffer.

Referenced by wordwrap().

◆ wordwrap_buffer_sprint()

void wordwrap_buffer_sprint ( string s)

Definition at line 181 of file util.qc.

182{
184 if(s == "\n")
185 {
187 wordwrap_buffer = "";
188 }
189}
entity _wordwrap_buffer_sprint_ent
Definition util.qc:180
void sprint(float clientnum, string text,...)

References _wordwrap_buffer_sprint_ent, sprint(), strcat(), and wordwrap_buffer.

Referenced by wordwrap_sprint().

◆ wordwrap_cb()

void wordwrap_cb ( string s,
float l,
void(string) callback )

Definition at line 328 of file util.qc.

329{
330 string c;
331 float lleft, i, j, wlen;
332
333 s = strzone(s);
334 lleft = l;
335 int len = strlen(s);
336 for (i = 0; i < len; ++i)
337 {
338 if (substring(s, i, 2) == "\\n")
339 {
340 callback("\n");
341 lleft = l;
342 ++i;
343 }
344 else if (substring(s, i, 1) == "\n")
345 {
346 callback("\n");
347 lleft = l;
348 }
349 else if (substring(s, i, 1) == " ")
350 {
351 if (lleft > 0)
352 {
353 callback(" ");
354 --lleft;
355 }
356 }
357 else
358 {
359 for (j = i+1; j < len; ++j)
360 // ^^ this skips over the first character of a word, which
361 // is ALWAYS part of the word
362 // this is safe since if i+1 == strlen(s), i will become
363 // strlen(s)-1 at the end of this block and the function
364 // will terminate. A space can't be the first character we
365 // read here, and neither can a \n be the start, since these
366 // two cases have been handled above.
367 {
368 c = substring(s, j, 1);
369 if (c == " ")
370 break;
371 if (c == "\\")
372 break;
373 if (c == "\n")
374 break;
375 // we need to keep this tempstring alive even if substring is
376 // called repeatedly, so call strcat even though we're not
377 // doing anything
378 callback("");
379 }
380 wlen = j - i;
381 if (lleft < wlen)
382 {
383 callback("\n");
384 lleft = l;
385 }
386 callback(substring(s, i, wlen));
387 lleft -= wlen;
388 i = j - 1;
389 }
390 }
391 strunzone(s);
392}

References strlen, strunzone(), strzone(), and substring().

Referenced by wordwrap(), and wordwrap_sprint().

◆ wordwrap_sprint()

void wordwrap_sprint ( entity to,
string s,
float l )

Definition at line 191 of file util.qc.

192{
193 wordwrap_buffer = "";
197 if(wordwrap_buffer != "")
198 sprint(to, strcat(wordwrap_buffer, "\n"));
199 wordwrap_buffer = "";
200 return;
201}
void wordwrap_buffer_sprint(string s)
Definition util.qc:181

References _wordwrap_buffer_sprint_ent, entity(), NULL, sprint(), strcat(), wordwrap_buffer, wordwrap_buffer_sprint(), and wordwrap_cb().

Referenced by CommonCommand_info(), and VoteCommand_macro_help().

◆ write_String_To_File()

ERASEABLE void write_String_To_File ( int fh,
string str,
bool alsoprint )

Definition at line 1475 of file util.qc.

1476{
1477 fputs(fh, str);
1478 if (alsoprint) LOG_HELP(str);
1479}
#define LOG_HELP(...)
Definition log.qh:83
void fputs(float fhandle, string s)

References fputs(), and LOG_HELP.

◆ xdecode()

float xdecode ( string s)

Definition at line 1782 of file util.qc.

1783{
1784 float a, b, c, d;
1785 if(substring(s, 0, 1) != "^")
1786 return -1;
1787 if(strlen(s) < 5)
1788 return -1;
1789 a = strstrofs(XENCODE_2, substring(s, 1, 1), 0);
1790 b = strstrofs(XENCODE_22, substring(s, 2, 1), 0);
1791 c = strstrofs(XENCODE_22, substring(s, 3, 1), 0);
1792 d = strstrofs(XENCODE_22, substring(s, 4, 1), 0);
1793 if(a < 0 || b < 0 || c < 0 || d < 0)
1794 return -1;
1795 return ((a * 22 + b) * 22 + c) * 22 + d;
1796}
const string XENCODE_22
Definition util.qc:1766
const string XENCODE_2
Definition util.qc:1765

References strlen, strstrofs, substring(), XENCODE_2, and XENCODE_22.

◆ xencode()

string xencode ( int f)

Definition at line 1767 of file util.qc.

1768{
1769 float a, b, c, d;
1770 d = f % 22; f = floor(f / 22);
1771 c = f % 22; f = floor(f / 22);
1772 b = f % 22; f = floor(f / 22);
1773 a = f % 2; // f = floor(f / 2);
1774 return strcat(
1775 "^",
1776 substring(XENCODE_2, a, 1),
1777 substring(XENCODE_22, b, 1),
1778 substring(XENCODE_22, c, 1),
1779 substring(XENCODE_22, d, 1)
1780 );
1781}

References floor(), strcat(), substring(), XENCODE_2, and XENCODE_22.

Variable Documentation

◆ _wordwrap_buffer_sprint_ent

entity _wordwrap_buffer_sprint_ent

Definition at line 180 of file util.qc.

Referenced by wordwrap_buffer_sprint(), and wordwrap_sprint().

◆ aiment_classname

string aiment_classname

Definition at line 2129 of file util.qc.

◆ aiment_deadflag

float aiment_deadflag

Definition at line 2130 of file util.qc.

◆ FindConnectedComponent_processing

float FindConnectedComponent_processing

Definition at line 1864 of file util.qc.

◆ lengthLogTable

float lengthLogTable[128]

Definition at line 455 of file util.qc.

Referenced by decompressShortVector(), invertLengthLog(), and STATIC_INIT().

◆ shutdown_running

float shutdown_running

Definition at line 1807 of file util.qc.

Referenced by SV_Shutdown().

◆ skeleton_bones_index

float skeleton_bones_index

Definition at line 1832 of file util.qc.

◆ to_execute_next_frame

string to_execute_next_frame

Definition at line 1846 of file util.qc.

Referenced by execute_next_frame(), and queue_to_execute_next_frame().

◆ trace_hits_box_a0

float trace_hits_box_a0

Definition at line 2197 of file util.qc.

Referenced by trace_hits_box(), and trace_hits_box_1d().

◆ trace_hits_box_a1

float trace_hits_box_a1

Definition at line 2197 of file util.qc.

Referenced by trace_hits_box(), and trace_hits_box_1d().

◆ wordwrap_buffer

string wordwrap_buffer

Definition at line 162 of file util.qc.

Referenced by wordwrap(), wordwrap_buffer_put(), wordwrap_buffer_sprint(), and wordwrap_sprint().

◆ XENCODE_2

const string XENCODE_2 = "xX"

Definition at line 1765 of file util.qc.

Referenced by xdecode(), and xencode().

◆ XENCODE_22

const string XENCODE_22 = "0123456789abcdefABCDEF"

Definition at line 1766 of file util.qc.

Referenced by xdecode(), and xencode().