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.

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)
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 a, float armorblock, int deathtype, float damage)
vector healtharmor_maxdamage (float h, float a, float armorblock, int deathtype)
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)
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"

Function Documentation

◆ animfixfps()

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

Definition at line 1917 of file util.qc.

1918{
1919 // multi-frame anim: keep as-is
1920 if(a.y == 1)
1921 {
1922 float dur = frameduration(e.modelindex, a.x);
1923 if (dur <= 0 && b.y)
1924 {
1925 a = b;
1926 dur = frameduration(e.modelindex, a.x);
1927 }
1928 if (dur > 0)
1929 a.z = 1.0 / dur;
1930 }
1931 return a;
1932}

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 1936 of file util.qc.

1937{
1938 return = NULL;
1939 switch (type)
1940 {
1941 case CNT_GAMESTART:
1942 {
1943 switch(num)
1944 {
1945 case 10: return ANNCE_NUM_GAMESTART_10;
1946 case 9: return ANNCE_NUM_GAMESTART_9;
1947 case 8: return ANNCE_NUM_GAMESTART_8;
1948 case 7: return ANNCE_NUM_GAMESTART_7;
1949 case 6: return ANNCE_NUM_GAMESTART_6;
1950 case 5: return ANNCE_NUM_GAMESTART_5;
1951 case 4: return ANNCE_NUM_GAMESTART_4;
1952 case 3: return ANNCE_NUM_GAMESTART_3;
1953 case 2: return ANNCE_NUM_GAMESTART_2;
1954 case 1: return ANNCE_NUM_GAMESTART_1;
1955 }
1956 break;
1957 }
1958 case CNT_KILL:
1959 {
1960 switch(num)
1961 {
1962 case 10: return ANNCE_NUM_KILL_10;
1963 case 9: return ANNCE_NUM_KILL_9;
1964 case 8: return ANNCE_NUM_KILL_8;
1965 case 7: return ANNCE_NUM_KILL_7;
1966 case 6: return ANNCE_NUM_KILL_6;
1967 case 5: return ANNCE_NUM_KILL_5;
1968 case 4: return ANNCE_NUM_KILL_4;
1969 case 3: return ANNCE_NUM_KILL_3;
1970 case 2: return ANNCE_NUM_KILL_2;
1971 case 1: return ANNCE_NUM_KILL_1;
1972 }
1973 break;
1974 }
1975 case CNT_RESPAWN:
1976 {
1977 switch(num)
1978 {
1979 case 10: return ANNCE_NUM_RESPAWN_10;
1980 case 9: return ANNCE_NUM_RESPAWN_9;
1981 case 8: return ANNCE_NUM_RESPAWN_8;
1982 case 7: return ANNCE_NUM_RESPAWN_7;
1983 case 6: return ANNCE_NUM_RESPAWN_6;
1984 case 5: return ANNCE_NUM_RESPAWN_5;
1985 case 4: return ANNCE_NUM_RESPAWN_4;
1986 case 3: return ANNCE_NUM_RESPAWN_3;
1987 case 2: return ANNCE_NUM_RESPAWN_2;
1988 case 1: return ANNCE_NUM_RESPAWN_1;
1989 }
1990 break;
1991 }
1992 case CNT_ROUNDSTART:
1993 {
1994 switch(num)
1995 {
1996 case 10: return ANNCE_NUM_ROUNDSTART_10;
1997 case 9: return ANNCE_NUM_ROUNDSTART_9;
1998 case 8: return ANNCE_NUM_ROUNDSTART_8;
1999 case 7: return ANNCE_NUM_ROUNDSTART_7;
2000 case 6: return ANNCE_NUM_ROUNDSTART_6;
2001 case 5: return ANNCE_NUM_ROUNDSTART_5;
2002 case 4: return ANNCE_NUM_ROUNDSTART_4;
2003 case 3: return ANNCE_NUM_ROUNDSTART_3;
2004 case 2: return ANNCE_NUM_ROUNDSTART_2;
2005 case 1: return ANNCE_NUM_ROUNDSTART_1;
2006 }
2007 break;
2008 }
2009 case CNT_NORMAL:
2010 default:
2011 {
2012 switch(num)
2013 {
2014 case 10: return ANNCE_NUM_10;
2015 case 9: return ANNCE_NUM_9;
2016 case 8: return ANNCE_NUM_8;
2017 case 7: return ANNCE_NUM_7;
2018 case 6: return ANNCE_NUM_6;
2019 case 5: return ANNCE_NUM_5;
2020 case 4: return ANNCE_NUM_4;
2021 case 3: return ANNCE_NUM_3;
2022 case 2: return ANNCE_NUM_2;
2023 case 1: return ANNCE_NUM_1;
2024 }
2025 break;
2026 }
2027 }
2028}
const int CNT_NORMAL
Definition util.qh:251
const int CNT_RESPAWN
Definition util.qh:255
const int CNT_KILL
Definition util.qh:254
const int CNT_ROUNDSTART
Definition util.qh:256
const int CNT_GAMESTART
Definition util.qh:252
#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 2069 of file util.qc.

2070{
2071 vector org, t_forward, t_left, t_up, e_forward, e_up;
2072 float tagscale;
2073
2074 org = e.origin - gettaginfo(to, gettagindex(to, tag));
2075 tagscale = (vlen(v_forward) ** -2); // undo a scale on the tag
2076 t_forward = v_forward * tagscale;
2077 t_left = v_right * -tagscale;
2078 t_up = v_up * tagscale;
2079
2080 e.origin_x = org * t_forward;
2081 e.origin_y = org * t_left;
2082 e.origin_z = org * t_up;
2083
2084 // current forward and up directions
2085 if (substring(e.model, 0, 1) == "*") // bmodels have their own rules
2086 e.angles = AnglesTransform_FromVAngles(e.angles);
2087 else
2088 e.angles = AnglesTransform_FromAngles(e.angles);
2089 fixedmakevectors(e.angles);
2090
2091 // untransform forward, up!
2092 e_forward.x = v_forward * t_forward;
2093 e_forward.y = v_forward * t_left;
2094 e_forward.z = v_forward * t_up;
2095 e_up.x = v_up * t_forward;
2096 e_up.y = v_up * t_left;
2097 e_up.z = v_up * t_up;
2098
2099 e.angles = fixedvectoangles2(e_forward, e_up);
2100 if (substring(e.model, 0, 1) == "*") // bmodels have their own rules
2101 e.angles = AnglesTransform_ToVAngles(e.angles);
2102 else
2103 e.angles = AnglesTransform_ToAngles(e.angles);
2104
2105 setattachment(e, to, tag);
2106 setorigin(e, e.origin);
2107}
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 2286 of file util.qc.

2287{
2288 return blink_synced(base, range, freq, 0, 0);
2289}
ERASEABLE float blink_synced(float base, float range, float freq, float start_time, int start_pos)
Definition util.qc:2274
float freq
Definition pendulum.qc:3

References 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 2274 of file util.qc.

2275{
2276 // note:
2277 // RMS = sqrt(base^2 + 0.5 * range^2)
2278 // thus
2279 // base = sqrt(RMS^2 - 0.5 * range^2)
2280 // ensure RMS == 1
2281
2282 return base + range * sin((time - start_time - (M_PI / 2) * start_pos) * freq);
2283}
float time
#define M_PI
pi
Definition mathlib.qh:112
float sin(float f)

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

Referenced by blink(), and HUD_HealthArmor().

◆ CheckWireframeBox()

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

Definition at line 592 of file util.qc.

593{
594 traceline(v0, v0 + dvx, true, forent); if(trace_fraction < 1) return 0;
595 traceline(v0, v0 + dvy, true, forent); if(trace_fraction < 1) return 0;
596 traceline(v0, v0 + dvz, true, forent); if(trace_fraction < 1) return 0;
597 traceline(v0 + dvx, v0 + dvx + dvy, true, forent); if(trace_fraction < 1) return 0;
598 traceline(v0 + dvx, v0 + dvx + dvz, true, forent); if(trace_fraction < 1) return 0;
599 traceline(v0 + dvy, v0 + dvy + dvx, true, forent); if(trace_fraction < 1) return 0;
600 traceline(v0 + dvy, v0 + dvy + dvz, true, forent); if(trace_fraction < 1) return 0;
601 traceline(v0 + dvz, v0 + dvz + dvx, true, forent); if(trace_fraction < 1) return 0;
602 traceline(v0 + dvz, v0 + dvz + dvy, true, forent); if(trace_fraction < 1) return 0;
603 traceline(v0 + dvx + dvy, v0 + dvx + dvy + dvz, true, forent); if(trace_fraction < 1) return 0;
604 traceline(v0 + dvx + dvz, v0 + dvx + dvy + dvz, true, forent); if(trace_fraction < 1) return 0;
605 traceline(v0 + dvy + dvz, v0 + dvx + dvy + dvz, true, forent); if(trace_fraction < 1) return 0;
606 return 1;
607}
float trace_fraction

References entity(), trace_fraction, and vector.

Referenced by Portal_Spawn(), and Porto_Draw().

◆ compressShortVector()

float compressShortVector ( vector vec)

Definition at line 531 of file util.qc.

532{
533 vector ang;
534 float p, y, len;
535 if(vec == '0 0 0')
536 return 0;
537 //print("compress: ", vtos(vec), "\n");
538 ang = vectoangles(vec);
539 ang.x = -ang.x;
540 if(ang.x < -90)
541 ang.x += 360;
542 if(ang.x < -90 && ang.x > +90)
543 error("BOGUS vectoangles");
544 //print("angles: ", vtos(ang), "\n");
545
546 p = floor(0.5 + (ang.x + 90) * (16 / 180)) & 15; // -90..90 to 0..14
547 if(p == 0)
548 {
549 if(vec.z < 0)
550 y = 31;
551 else
552 y = 30;
553 }
554 else
555 y = floor(0.5 + ang.y * (32 / 360)) & 31; // 0..360 to 0..32
556 len = invertLengthLog(vlen(vec));
557
558 //print("compressed: p:", ftos(p)); print(" y:", ftos(y)); print(" len:", ftos(len), "\n");
559
560 return (p * 0x1000) + (y * 0x80) + len;
561}
float invertLengthLog(float dist)
Definition util.qc:467
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 1360 of file util.qc.

1361{
1362 int rx_neg = (v.x < 0) ? 1 : 0;
1363 int ry_neg = (v.y < 0) ? 1 : 0;
1364 int rz_neg = (v.z < 0) ? 1 : 0;
1365 int rx = rint(fabs(v.x) * 2);
1366 int ry = rint(fabs(v.y) * 2);
1367 int rz = rint(fabs(v.z) * 2);
1368 if(rx > 255) // 128 * 2 - 1
1369 {
1370 LOG_DEBUG("shot origin ", vtos(v), " x out of bounds\n");
1371 rx = bound(0, rx, 255);
1372 }
1373 if(ry > 63) // 32 * 2 - 1
1374 {
1375 LOG_DEBUG("shot origin ", vtos(v), " y out of bounds\n");
1376 ry = bound(0, ry, 63);
1377 }
1378 if(rz > 63) // 32 * 2 - 1
1379 {
1380 LOG_DEBUG("shot origin ", vtos(v), " z out of bounds\n");
1381 rz = bound(0, rz, 63);
1382 }
1383 ry |= ry_neg * BIT(6) + rx_neg * BIT(7);
1384 rz |= rz_neg * BIT(6); // BIT(7) unused
1385 return rx * 0x10000 + ry * 0x100 + rz;
1386}
#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 2258 of file util.qc.

2259{
2260 string s = cvar_string(cv);
2261 if(s == "")
2262 return v;
2263 else
2264 return stof(s);
2265}
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 819 of file util.qc.

820{
821 float created_saved_value = 0;
822
823 if (!(tmp_cvar || tmp_value))
824 {
825 LOG_TRACE("Error: Invalid usage of cvar_settemp(string, string); !");
826 return 0;
827 }
828
829 if(!cvar_type(tmp_cvar))
830 {
831 LOG_INFOF("Error: cvar %s doesn't exist!", tmp_cvar);
832 return 0;
833 }
834
835 IL_EACH(g_saved_cvars, it.netname == tmp_cvar,
836 {
837 created_saved_value = -1; // skip creation
838 break; // no need to continue
839 });
840
841 if(created_saved_value != -1)
842 {
843 // creating a new entity to keep track of this cvar
844 entity e = new_pure(saved_cvar_value);
846 e.netname = strzone(tmp_cvar);
847 e.message = strzone(cvar_string(tmp_cvar));
848 created_saved_value = 1;
849 }
850
851 // update the cvar to the value given
852 cvar_set(tmp_cvar, tmp_value);
853
854 return created_saved_value;
855}
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
IntrusiveList g_saved_cvars
Definition util.qh:33
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 857 of file util.qc.

858{
859 int j = 0;
860 // FIXME this new-style loop fails!
861#if 0
862 FOREACH_ENTITY_CLASS("saved_cvar_value", true,
863 {
864 if(cvar_type(it.netname))
865 {
866 cvar_set(it.netname, it.message);
867 strunzone(it.netname);
868 strunzone(it.message);
869 delete(it);
870 ++j;
871 }
872 else
873 LOG_INFOF("Error: cvar %s doesn't exist anymore! It can still be restored once it's manually recreated.", it.netname);
874 });
875
876#else
877 entity e = NULL;
878 while((e = find(e, classname, "saved_cvar_value")))
879 {
880 if(cvar_type(e.netname))
881 {
882 cvar_set(e.netname, e.message);
883 delete(e);
884 ++j;
885 }
886 else
887 print(sprintf("Error: cvar %s doesn't exist anymore! It can still be restored once it's manually recreated.", e.netname));
888 }
889#endif
890
891 return j;
892}
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 496 of file util.qc.

497{
498 vector out;
499 if(data == 0)
500 return '0 0 0';
501 float p = (data & 0xF000) / 0x1000;
502 float q = (data & 0x0F80) / 0x80;
503 int len = (data & 0x007F);
504
505 //print("\ndecompress: p:", ftos(p)); print(" q:", ftos(q)); print(" len:", ftos(len), "\n");
506
507 if(p == 0)
508 {
509 out.x = 0;
510 out.y = 0;
511 if(q == 31)
512 out.z = -1;
513 else
514 out.z = +1;
515 }
516 else
517 {
518 q = M_PI / 16 * q;
519 p = M_PI / 16 * p - M_PI_2;
520 float cos_p = cos(p);
521 out.x = cos(q) * cos_p;
522 out.y = sin(q) * cos_p;
523 out.z = -sin(p);
524 }
525
526 //print("decompressed: ", vtos(out), "\n");
527
528 return out * lengthLogTable[len];
529}
float lengthLogTable[128]
Definition util.qc:465
const float M_PI_2
pi/2
Definition mathlib.qh:113
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 1387 of file util.qc.

1388{
1389 vector v;
1390 v.x = f >> 16;
1391 v.y = (f & 0xFF00) >> 8;
1392 v.z = f & 0xFF;
1393 // remove sign bits and apply sign
1394 if (v.y & BIT(7)) { v.y &= ~BIT(7); v.x *= -1; }
1395 if (v.y & BIT(6)) { v.y &= ~BIT(6); v.y *= -1; }
1396 if (v.z & BIT(6)) { v.z &= ~BIT(6); v.z *= -1; }
1397 return v * 0.5;
1398}

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 404 of file util.qc.

405{
406 entity e = start;
407 funcPre(pass, e);
408 while (e.(downleft))
409 {
410 e = e.(downleft);
411 funcPre(pass, e);
412 }
413 funcPost(pass, e);
414 while(e != start)
415 {
416 if (e.(right))
417 {
418 e = e.(right);
419 funcPre(pass, e);
420 while (e.(downleft))
421 {
422 e = e.(downleft);
423 funcPre(pass, e);
424 }
425 }
426 else
427 e = e.(up);
428 funcPost(pass, e);
429 }
430}
#define pass(name, colormin, colormax)

References entity(), and pass.

Referenced by forAllDescendants().

◆ detach_sameorigin()

void detach_sameorigin ( entity e)

Definition at line 2109 of file util.qc.

2110{
2111 vector org = gettaginfo(e, 0);
2112 e.angles = fixedvectoangles2(v_forward, v_up);
2113 if (substring(e.model, 0, 1) == "*") // bmodels have their own rules
2114 e.angles = AnglesTransform_ToVAngles(e.angles);
2115 else
2116 e.angles = AnglesTransform_ToAngles(e.angles);
2117 setorigin(e, org);
2118 setattachment(e, NULL, "");
2119 setorigin(e, e.origin);
2120}

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 1857 of file util.qc.

1858{
1860 {
1861 localcmd("\n", to_execute_next_frame, "\n");
1863 }
1864}
string to_execute_next_frame
Definition util.qc:1856
void localcmd(string command,...)
#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 966 of file util.qc.

967{
968 int start = strstrofs(s, "^", 0);
969 if (start == -1) // no caret found
970 return "";
971 int len = strlen(s)-1;
972 for(int i = len; i >= start; --i)
973 {
974 if(substring(s, i, 1) != "^")
975 continue;
976
977 int carets = 1;
978 while (i-carets >= start && substring(s, i-carets, 1) == "^")
979 ++carets;
980
981 // check if carets aren't all escaped
982 if (carets & 1)
983 {
984 if(i+1 <= len)
985 if(IS_DIGIT(substring(s, i+1, 1)))
986 {
987 if(start == 0 && len == 1)
988 return "";
989 return substring(s, i, 2);
990 }
991
992 if(i+4 <= len)
993 if(substring(s, i+1, 1) == "x")
994 if(IS_HEXDIGIT(substring(s, i + 2, 1)))
995 if(IS_HEXDIGIT(substring(s, i + 3, 1)))
996 if(IS_HEXDIGIT(substring(s, i + 4, 1)))
997 {
998 if(start == 0 && len == 4)
999 return "";
1000 return substring(s, i, 5);
1001 }
1002 }
1003 i -= carets; // this also skips one char before the carets
1004 }
1005
1006 return "";
1007}
#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(), and W_Seeker_Tag_Touch().

◆ FindConnectedComponent()

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

Definition at line 1875 of file util.qc.

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

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 610 of file util.qc.

611{
612 string neworder;
613 float i, n, w;
614
615 n = tokenize_console(order);
616 neworder = "";
617 for(i = 0; i < n; ++i)
618 {
619 w = stof(argv(i));
620 if(w == floor(w))
621 {
622 if(w >= from && w <= to)
623 neworder = strcat(neworder, ftos(w), " ");
624 else
625 {
626 w -= subtract;
627 if(w >= from && w <= to)
628 neworder = strcat(neworder, ftos(w), " ");
629 }
630 }
631 }
632
633 if(complete)
634 {
635 n = tokenize_console(neworder);
636 for(w = to; w >= from; --w)
637 {
638 int wflags = REGISTRY_GET(Weapons, w).spawnflags;
639 if(wflags & WEP_FLAG_SPECIALATTACK)
640 continue;
641 for(i = 0; i < n; ++i)
642 if(stof(argv(i)) == w)
643 break;
644 if(i == n) // not found
645 neworder = strcat(neworder, ftos(w), " ");
646 }
647 }
648
649 return substring(neworder, 0, strlen(neworder) - 1);
650}
#define tokenize_console
Weapons
Definition guide.qh:113
string ftos(float f)
string argv(float n)
strcat(_("^F4Countdown stopped!"), "\n^BG", _("Teams are too unbalanced."))
#define REGISTRY_GET(id, i)
Definition registry.qh:62
const int WEP_FLAG_SPECIALATTACK
Definition weapon.qh:269

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 2122 of file util.qc.

2123{
2124 set_movetype(e, MOVETYPE_FOLLOW); // make the hole follow
2125 e.aiment = to; // make the hole follow bmodel
2126 e.punchangle = to.angles; // the original angles of bmodel
2127 e.view_ofs = e.origin - to.origin; // relative origin
2128 e.v_angle = e.angles - to.angles; // relative angles
2129}
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 686 of file util.qc.

687{
688 vector mi, ma;
689
690 string s = mapname;
691 if(!strcasecmp(substring(s, 0, 5), "maps/"))
692 s = substring(s, 5, strlen(s) - 5);
693 if(!strcasecmp(substring(s, strlen(s) - 4, 4), ".bsp"))
694 s = substring(s, 0, strlen(s) - 4);
696
697#ifdef CSQC
698 mi = world.mins;
699 ma = world.maxs;
700#else
701 mi = world.absmin;
702 ma = world.absmax;
703#endif
704
705 mi_min = mi;
706 mi_max = ma;
709 {
712 }
713 else
714 {
715 // not specified
716 if(mode)
717 {
718 // be clever
719 tracebox('1 0 0' * mi.x,
720 '0 1 0' * mi.y + '0 0 1' * mi.z,
721 '0 1 0' * ma.y + '0 0 1' * ma.z,
722 '1 0 0' * ma.x,
724 NULL);
726 mi_min.x = trace_endpos.x;
727
728 tracebox('0 1 0' * mi.y,
729 '1 0 0' * mi.x + '0 0 1' * mi.z,
730 '1 0 0' * ma.x + '0 0 1' * ma.z,
731 '0 1 0' * ma.y,
733 NULL);
735 mi_min.y = trace_endpos.y;
736
737 tracebox('0 0 1' * mi.z,
738 '1 0 0' * mi.x + '0 1 0' * mi.y,
739 '1 0 0' * ma.x + '0 1 0' * ma.y,
740 '0 0 1' * ma.z,
742 NULL);
744 mi_min.z = trace_endpos.z;
745
746 tracebox('1 0 0' * ma.x,
747 '0 1 0' * mi.y + '0 0 1' * mi.z,
748 '0 1 0' * ma.y + '0 0 1' * ma.z,
749 '1 0 0' * mi.x,
751 NULL);
753 mi_max.x = trace_endpos.x;
754
755 tracebox('0 1 0' * ma.y,
756 '1 0 0' * mi.x + '0 0 1' * mi.z,
757 '1 0 0' * ma.x + '0 0 1' * ma.z,
758 '0 1 0' * mi.y,
760 NULL);
762 mi_max.y = trace_endpos.y;
763
764 tracebox('0 0 1' * ma.z,
765 '1 0 0' * mi.x + '0 1 0' * mi.y,
766 '1 0 0' * ma.x + '0 1 0' * ma.y,
767 '0 0 1' * mi.z,
769 NULL);
771 mi_max.z = trace_endpos.z;
772 }
773 }
774}
string mi_shortname
Definition util.qh:126
vector mi_min
Definition util.qh:127
vector mi_max
Definition util.qh:128
string mapname
float trace_startsolid
float MOVE_WORLDONLY
#define strcasecmp
int MapInfo_Get_ByName(string pFilename, float pAllowGenerate, Gametype pGametypeToSet)
Definition mapinfo.qc:1382
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 776 of file util.qc.

777{
778 vector extend;
779
780 get_mi_min_max(mode);
781
784
785 // extend mi_picmax to get a square aspect ratio
786 // center the map in that area
787 extend = mi_picmax - mi_picmin;
788 if(extend.y > extend.x)
789 {
790 mi_picmin.x -= (extend.y - extend.x) * 0.5;
791 mi_picmax.x += (extend.y - extend.x) * 0.5;
792 }
793 else
794 {
795 mi_picmin.y -= (extend.x - extend.y) * 0.5;
796 mi_picmax.y += (extend.x - extend.y) * 0.5;
797 }
798
799 // add another some percent
800 extend = (mi_picmax - mi_picmin) * (1 / 64.0);
801 mi_picmin -= extend;
802 mi_picmax += extend;
803
804 // calculate the texcoords
806 // first the two corners of the origin
807 mi_pictexcoord0_x = (mi_min.x - mi_picmin.x) / (mi_picmax.x - mi_picmin.x);
808 mi_pictexcoord0_y = (mi_min.y - mi_picmin.y) / (mi_picmax.y - mi_picmin.y);
809 mi_pictexcoord2_x = (mi_max.x - mi_picmin.x) / (mi_picmax.x - mi_picmin.x);
810 mi_pictexcoord2_y = (mi_max.y - mi_picmin.y) / (mi_picmax.y - mi_picmin.y);
811 // then the other corners
812 mi_pictexcoord1_x = mi_pictexcoord0_x;
813 mi_pictexcoord1_y = mi_pictexcoord2_y;
814 mi_pictexcoord3_x = mi_pictexcoord2_x;
815 mi_pictexcoord3_y = mi_pictexcoord0_y;
816}
void get_mi_min_max(float mode)
Definition util.qc:686
vector mi_picmin
Definition util.qh:131
vector mi_pictexcoord2
Definition util.qh:135
vector mi_pictexcoord3
Definition util.qh:136
vector mi_pictexcoord0
Definition util.qh:133
vector mi_picmax
Definition util.qh:132
vector mi_pictexcoord1
Definition util.qh:134

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 1491 of file util.qc.

1492{
1493 if(m)
1494 m = strcat(m, "_");
1495 else
1496 m = "models/player/*_";
1497 if(sk >= 0)
1498 m = strcat(m, ftos(sk));
1499 else
1500 m = strcat(m, "*");
1501 return strcat(m, ".", fil);
1502}

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 1504 of file util.qc.

1505{
1516 for(int i = 0; i < MAX_AIM_BONES; ++i)
1517 {
1520 }
1523
1524#ifdef GAMEQC
1525 MUTATOR_CALLHOOK(ClearModelParams);
1526#endif
1527
1528 if (!m)
1529 return 1;
1530
1531 if(substring(m, -9, 5) == "_lod1" || substring(m, -9, 5) == "_lod2")
1532 m = strcat(substring(m, 0, -10), substring(m, -4, -1));
1533
1534 if(sk < 0)
1535 {
1536 if(substring(m, -4, -1) != ".txt")
1537 return 0;
1538 if(substring(m, -6, 1) != "_")
1539 return 0;
1540 sk = stof(substring(m, -5, 1));
1541 m = substring(m, 0, -7);
1542 }
1543
1544 string fn = get_model_datafilename(m, sk, "txt");
1545 int fh = fopen(fn, FILE_READ);
1546 if(fh < 0)
1547 {
1548 sk = 0;
1549 fn = get_model_datafilename(m, sk, "txt");
1550 fh = fopen(fn, FILE_READ);
1551 if(fh < 0)
1552 return 0;
1553 }
1554
1557 string s, c;
1558 while((s = fgets(fh)))
1559 {
1560 if(s == "")
1561 break; // next lines will be description
1562 c = car(s);
1563 s = cdr(s);
1564 if(c == "name")
1566 if(c == "species")
1567 switch(s)
1568 {
1569 case "human": get_model_parameters_species = SPECIES_HUMAN; break;
1570 case "alien": get_model_parameters_species = SPECIES_ALIEN; break;
1571 case "robot_shiny": get_model_parameters_species = SPECIES_ROBOT_SHINY; break;
1572 case "robot_rusty": get_model_parameters_species = SPECIES_ROBOT_RUSTY; break;
1573 case "robot_solid": get_model_parameters_species = SPECIES_ROBOT_SOLID; break;
1574 case "animal": get_model_parameters_species = SPECIES_ANIMAL; break;
1575 case "reserved": get_model_parameters_species = SPECIES_RESERVED; break;
1576 }
1577 if(c == "sex")
1578 {
1579 if (s == "Male") s = _("Male");
1580 else if (s == "Female") s = _("Female");
1581 else if (s == "Undisclosed") s = _("Undisclosed");
1583 }
1584 if(c == "weight")
1586 if(c == "age")
1588 if(c == "description")
1590 if(c == "bone_upperbody")
1592 if(c == "bone_weapon")
1594 #ifdef GAMEQC
1595 MUTATOR_CALLHOOK(GetModelParams, c, s);
1596 #endif
1597 for(int i = 0; i < MAX_AIM_BONES; ++i)
1598 if(c == strcat("bone_aim", ftos(i)))
1599 {
1602 }
1603 if(c == "fixbone")
1605 if(c == "hidden")
1607 }
1608
1609 while((s = fgets(fh)))
1610 {
1613 if(s != "")
1615 }
1616
1617 fclose(fh);
1618
1619 return 1;
1620}
#define MUTATOR_CALLHOOK(id,...)
Definition base.qh:143
string get_model_datafilename(string m, float sk, string fil)
Definition util.qc:1491
const int MAX_AIM_BONES
Definition util.qh:188
float get_model_parameters_weight
Definition util.qh:182
float get_model_parameters_fixbone
Definition util.qh:191
string get_model_parameters_sex
Definition util.qh:181
float get_model_parameters_species
Definition util.qh:180
float get_model_parameters_bone_aimweight[MAX_AIM_BONES]
Definition util.qh:190
float get_model_parameters_modelskin
Definition util.qh:178
string get_model_parameters_name
Definition util.qh:179
string get_model_parameters_bone_weapon
Definition util.qh:187
string get_model_parameters_description
Definition util.qh:185
bool get_model_parameters_hidden
Definition util.qh:184
string get_model_parameters_modelname
Definition util.qh:177
string get_model_parameters_bone_upperbody
Definition util.qh:186
string get_model_parameters_bone_aim[MAX_AIM_BONES]
Definition util.qh:189
float get_model_parameters_age
Definition util.qh:183
string get_model_parameters_desc
Definition util.qh:192
const int SPECIES_ANIMAL
Definition constants.qh:25
const int SPECIES_ROBOT_SOLID
Definition constants.qh:23
const int SPECIES_ROBOT_RUSTY
Definition constants.qh:26
const int SPECIES_RESERVED
Definition constants.qh:28
const int SPECIES_ROBOT_SHINY
Definition constants.qh:27
const int SPECIES_ALIEN
Definition constants.qh:24
const int SPECIES_HUMAN
Definition constants.qh:22
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 1308 of file util.qc.

1309{
1310 if(!newton_style)
1311 return spd * mydir;
1312
1313 if(newton_style == 2)
1314 {
1315 // true Newtonian projectiles with automatic aim adjustment
1316 //
1317 // solve: |outspeed * mydir - myvel| = spd
1318 // outspeed^2 - 2 * outspeed * (mydir * myvel) + myvel^2 - spd^2 = 0
1319 // outspeed = (mydir * myvel) +- sqrt((mydir * myvel)^2 - myvel^2 + spd^2)
1320 // PLUS SIGN!
1321 // not defined?
1322 // then...
1323 // myvel^2 - (mydir * myvel)^2 > spd^2
1324 // velocity without mydir component > spd
1325 // fire at smallest possible spd that works?
1326 // |(mydir * myvel) * myvel - myvel| = spd
1327
1328 vector solution = solve_quadratic(1, -2 * (mydir * myvel), myvel * myvel - spd * spd);
1329
1330 float outspeed;
1331 if(solution.z)
1332 outspeed = solution.y; // the larger one
1333 else
1334 {
1335 //outspeed = 0; // slowest possible shot
1336 outspeed = solution.x; // the real part (that is, the average!)
1337 //dprint("impossible shot, adjusting\n");
1338 }
1339
1340 outspeed = bound(spd * mi, outspeed, spd * ma);
1341 return mydir * outspeed;
1342 }
1343
1344 // real Newtonian
1345 return myvel + spd * mydir;
1346}
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 1439 of file util.qc.

1440{
1441 string m = cvar_string("fs_gamedir");
1442 float n = tokenize_console(m);
1443 if(n == 0)
1444 return "data";
1445 else
1446 return argv(n - 1);
1447}

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

Referenced by resolvemod().

◆ getWrappedLine()

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

Definition at line 1143 of file util.qc.

1144{
1145 string s = getWrappedLine_remaining;
1146 if (maxWidth <= 0)
1147 {
1149 return s; // the line has no size ANYWAY, nothing would be displayed.
1150 }
1151
1152 int take_until = textLengthUpToWidth(s, maxWidth, theFontSize, tw);
1153
1154 if (take_until <= 0 || take_until >= strlen(s)) {
1156 return s; // remaining text fits the line
1157 }
1158
1159 float colorlen = tw("^7", theFontSize);
1160 return take_wrapped_line_until(take_until, colorlen);
1161}
string take_wrapped_line_until(int take_until, float colorlen)
Definition util.qc:1074
float textLengthUpToWidth(string theText, float maxWidth, vector theSize, textLengthUpToWidth_widthFunction_t w)
Definition util.qc:894
string getWrappedLine_remaining
Definition util.qh:147

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 1163 of file util.qc.

1164{
1165 string s = getWrappedLine_remaining;
1166 if (maxLength <= 0)
1167 {
1169 return s; // the line has no size ANYWAY, nothing would be displayed.
1170 }
1171
1172 int take_until = textLengthUpToLength(s, maxLength, tw);
1173
1174 if (take_until <= 0 || take_until >= strlen(s)) {
1176 return s; // remaining text fits the line
1177 }
1178
1179 float colorlen = tw("^7");
1180 return take_wrapped_line_until(take_until, colorlen);
1181}
float textLengthUpToLength(string theText, int maxLength, textLengthUpToLength_lenFunction_t w)
Definition util.qc:930

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

Referenced by Say().

◆ healtharmor_applydamage()

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

Definition at line 1425 of file util.qc.

1426{
1427 vector v;
1428 if (DEATH_IS(deathtype, DEATH_DROWN)) // Why should armor help here...
1429 armorblock = 0;
1430 if (deathtype & HITTYPE_ARMORPIERCE)
1431 armorblock = 0;
1432 v.y = bound(0, damage * armorblock, a); // save
1433 v.x = bound(0, damage - v.y, damage); // take
1434 v.z = 0;
1435 return v;
1436}
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 1401 of file util.qc.

1402{
1403 // NOTE: we'll always choose the SMALLER value...
1404 float healthdamage, armordamage, armorideal;
1405 if (DEATH_IS(deathtype, DEATH_DROWN)) // Why should armor help here...
1406 armorblock = 0;
1407 vector v;
1408 healthdamage = (h - 1) / (1 - armorblock); // damage we can take if we could use more health
1409 armordamage = a + (h - 1); // damage we can take if we could use more armor
1410 armorideal = healthdamage * armorblock;
1411 v.y = armorideal;
1412 if(armordamage < healthdamage)
1413 {
1414 v.x = armordamage;
1415 v.z = 1;
1416 }
1417 else
1418 {
1419 v.x = healthdamage;
1420 v.z = 0;
1421 }
1422 return v;
1423}

References DEATH_IS, and vector.

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

◆ invertLengthLog()

float invertLengthLog ( float dist)

Definition at line 467 of file util.qc.

468{
469 int l, r, m;
470
471 if(dist >= lengthLogTable[127])
472 return 127;
473 if(dist <= lengthLogTable[0])
474 return 0;
475
476 l = 0;
477 r = 127;
478
479 while(r - l > 1)
480 {
481 m = floor((l + r) / 2);
482 if(lengthLogTable[m] < dist)
483 l = m;
484 else
485 r = m;
486 }
487
488 // now: r is >=, l is <
489 float lerr = (dist - lengthLogTable[l]);
490 float rerr = (lengthLogTable[r] - dist);
491 if(lerr < rerr)
492 return l;
493 return r;
494}

References floor(), and lengthLogTable.

Referenced by compressShortVector().

◆ isGametypeInFilter()

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

Definition at line 1199 of file util.qc.

1200{
1201 string subpattern, subpattern2, subpattern3, subpattern4;
1202 subpattern = strcat(",", MapInfo_Type_ToString(gt), ",");
1203 if(tp)
1204 subpattern2 = ",teams,";
1205 else
1206 subpattern2 = ",noteams,";
1207 if(ts)
1208 subpattern3 = ",teamspawns,";
1209 else
1210 subpattern3 = ",noteamspawns,";
1211 if(gt == MAPINFO_TYPE_RACE || gt == MAPINFO_TYPE_CTS)
1212 subpattern4 = ",race,";
1213 else
1214 subpattern4 = string_null;
1215
1216 if(substring(pattern, 0, 1) == "-")
1217 {
1218 pattern = substring(pattern, 1, strlen(pattern) - 1);
1219 if(strstrofs(strcat(",", pattern, ","), subpattern, 0) >= 0)
1220 return 0;
1221 if(strstrofs(strcat(",", pattern, ","), subpattern2, 0) >= 0)
1222 return 0;
1223 if(strstrofs(strcat(",", pattern, ","), subpattern3, 0) >= 0)
1224 return 0;
1225 if(subpattern4 && strstrofs(strcat(",", pattern, ","), subpattern4, 0) >= 0)
1226 return 0;
1227 }
1228 else
1229 {
1230 if(substring(pattern, 0, 1) == "+")
1231 pattern = substring(pattern, 1, strlen(pattern) - 1);
1232 if(strstrofs(strcat(",", pattern, ","), subpattern, 0) < 0)
1233 if(strstrofs(strcat(",", pattern, ","), subpattern2, 0) < 0)
1234 if(strstrofs(strcat(",", pattern, ","), subpattern3, 0) < 0)
1235 {
1236 if (!subpattern4)
1237 return 0;
1238 if(strstrofs(strcat(",", pattern, ","), subpattern4, 0) < 0)
1239 return 0;
1240 }
1241 }
1242 return 1;
1243}
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 2171 of file util.qc.

2172{
2173/*
2174 if(ent.move_movetype != MOVETYPE_FOLLOW)
2175 if(ent.aiment)
2176 error("???");
2177*/
2178 // FIXME: engine bug?
2179 // when aiment disconnects the engine will set orb's origin close to world's origin
2180 if(!ent.aiment)
2181 return 2;
2182 if(ent.aiment.classname != ent.aiment_classname || ent.aiment.deadflag != ent.aiment_deadflag)
2183 return 1;
2184 return 0;
2185}

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 652 of file util.qc.

653{
654 string neworder;
655 float n = tokenize_console(order);
656 neworder = "";
657 for(float i = 0; i < n; ++i)
658 neworder = strcat(neworder, mapfunc(argv(i)), " ");
659
660 return substring(neworder, 0, strlen(neworder) - 1);
661}

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 1449 of file util.qc.

1450{
1451 string t, s;
1452 float r, d;
1453 r = 0;
1454 while(acl)
1455 {
1456 t = car(acl); acl = cdr(acl);
1457
1458 d = 1;
1459 if(substring(t, 0, 1) == "-")
1460 {
1461 d = -1;
1462 t = substring(t, 1, strlen(t) - 1);
1463 }
1464 else if(substring(t, 0, 1) == "+")
1465 t = substring(t, 1, strlen(t) - 1);
1466
1467 if(substring(t, -1, 1) == "*")
1468 {
1469 t = substring(t, 0, strlen(t) - 1);
1470 s = substring(str, 0, strlen(t));
1471 }
1472 else
1473 s = str;
1474
1475 if(s == t)
1476 {
1477 r = d;
1478 break; // if we found a killing case, apply it! other settings may be allowed in the future, but this one is caught
1479 }
1480 }
1481 return r;
1482}

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

Referenced by _MapInfo_Parse_Settemp().

◆ Mod_Q1BSP_NativeContentsFromSuperContents()

int Mod_Q1BSP_NativeContentsFromSuperContents ( int supercontents)

Definition at line 2052 of file util.qc.

2053{
2054 if(supercontents & (DPCONTENTS_SOLID | DPCONTENTS_BODY))
2055 return CONTENT_SOLID;
2056 if(supercontents & DPCONTENTS_SKY)
2057 return CONTENT_SKY;
2058 if(supercontents & DPCONTENTS_LAVA)
2059 return CONTENT_LAVA;
2060 if(supercontents & DPCONTENTS_SLIME)
2061 return CONTENT_SLIME;
2062 if(supercontents & DPCONTENTS_WATER)
2063 return CONTENT_WATER;
2064 return CONTENT_EMPTY;
2065}
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 2032 of file util.qc.

2033{
2034 switch(nativecontents)
2035 {
2036 case CONTENT_EMPTY:
2037 return 0;
2038 case CONTENT_SOLID:
2040 case CONTENT_WATER:
2041 return DPCONTENTS_WATER;
2042 case CONTENT_SLIME:
2043 return DPCONTENTS_SLIME;
2044 case CONTENT_LAVA:
2046 case CONTENT_SKY:
2047 return DPCONTENTS_SKY | DPCONTENTS_NODROP | DPCONTENTS_OPAQUE; // to match behaviour of Q3 maps, let sky count as opaque
2048 }
2049 return 0;
2050}
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().

◆ playername()

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

Definition at line 2190 of file util.qc.

2191{
2192 TC(int, teamid);
2193 bool do_colorize = (teamplay && team_colorize);
2194#ifdef SVQC
2195 if(do_colorize && !intermission_running)
2196#else
2197 if(do_colorize)
2198#endif
2199 {
2200 string t = Team_ColorCode(teamid);
2201 return strcat(t, strdecolorize(thename));
2202 }
2203 else
2204 return thename;
2205}
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 1865 of file util.qc.

1866{
1868 {
1869 s = strcat(s, "\n", to_execute_next_frame);
1870 }
1872}

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 433 of file util.qc.

434{
435 string valstr;
436 float l;
437
438 pValue = floor(pValue + 0.5); // round
439
440 if((pValue == 0) && (pFlags & (SFL_HIDE_ZERO | SFL_RANK | SFL_TIME)))
441 valstr = "";
442 else if(pFlags & SFL_RANK)
443 valstr = (pValue < 256 ? count_ordinal(pValue) : _("N/A"));
444 else if(pFlags & SFL_TIME)
445 valstr = TIME_ENCODED_TOSTRING(pValue, true);
446 else if (rounds_played)
447 valstr = sprintf("%.1f", pValue / rounds_played);
448 else
449 valstr = ftos(pValue);
450
451 return valstr;
452}
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:96
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 2141 of file util.qc.

2142{
2143 set_movetype(ent, MOVETYPE_FOLLOW); // make the hole follow
2144 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.
2145 ent.aiment = e; // make the hole follow bmodel
2146 ent.punchangle = e.angles; // the original angles of bmodel
2147 ent.view_ofs = ent.origin - e.origin; // relative origin
2148 ent.v_angle = ent.angles - e.angles; // relative angles
2149 ent.aiment_classname = e.classname;
2150 ent.aiment_deadflag = e.deadflag;
2151
2152 if(IS_PLAYER(ent.aiment))
2153 {
2154 entity pl = ent.aiment;
2155 ent.view_ofs.x = bound(pl.mins.x + 4, ent.view_ofs.x, pl.maxs.x - 4);
2156 ent.view_ofs.y = bound(pl.mins.y + 4, ent.view_ofs.y, pl.maxs.y - 4);
2157 ent.view_ofs.z = bound(pl.mins.z + 4, ent.view_ofs.z, pl.maxs.z - 4);
2158 }
2159}
#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 1033 of file util.qc.

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

Referenced by take_wrapped_line_until().

◆ should_break_before()

bool should_break_before ( int c)

Definition at line 1009 of file util.qc.

1009 {
1010 switch (c)
1011 {
1012 case 0x3008: /* 〈 */
1013 case 0x300a: /* 《 */
1014 case 0x300c: /* 「 */
1015 case 0x300e: /* 『 */
1016 case 0x3010: /* 【 */
1017 case 0xff08: /* ( */
1018 /* rarely used */
1019 // case 0x3014: /* 〔 */
1020 // case 0x3016: /* 〖 */
1021 // case 0x3018: /* 〘 */
1022 // case 0x301a: /* 〚 */
1023 // case 0x301d: /* 〝 */
1024 // case 0xff3b: /* [ */
1025 // case 0xff5b: /* { */
1026 // case 0xff5f: /* ⦅ */
1027 // case 0xff62: /* 「 */
1028 return true;
1029 }
1030 return false;
1031}

Referenced by take_wrapped_line_until().

◆ Skeleton_SetBones()

void Skeleton_SetBones ( entity e)

Definition at line 1843 of file util.qc.

1844{
1845 // set skeleton_bones to the total number of bones on the model
1846 if(e.skeleton_bones_index == e.modelindex)
1847 return; // same model, nothing to update
1848
1849 float skelindex = skel_create(e.modelindex);
1850 e.skeleton_bones = skel_get_numbones(skelindex);
1851 skel_delete(skelindex);
1852 e.skeleton_bones_index = e.modelindex;
1853}

References entity().

◆ solve_shotdirection()

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

Definition at line 1245 of file util.qc.

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

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

◆ STATIC_INIT()

STATIC_INIT ( compressShortVector )

Definition at line 563 of file util.qc.

564{
565 float l = 1;
566 float f = (2 ** (1/8));
567 int i;
568 for(i = 0; i < 128; ++i)
569 {
570 lengthLogTable[i] = l;
571 l *= f;
572 }
573
574 if(cvar("developer") > 0)
575 {
576 LOG_TRACE("Verifying vector compression table...");
577 for(i = 0x0F00; i < 0xFFFF; ++i)
579 {
581 "BROKEN vector compression: %s -> %s -> %s",
582 ftos(i),
585 );
586 }
587 LOG_TRACE("Done.");
588 }
589}
float compressShortVector(vector vec)
Definition util.qc:531
vector decompressShortVector(int data)
Definition util.qc:496
#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 1819 of file util.qc.

1827{
1829 {
1830 LOG_INFO("Recursive shutdown detected! Only restoring cvars...");
1831 }
1832 else
1833 {
1834 shutdown_running = 1;
1835 Shutdown();
1836 shutdownhooks();
1837 }
1838 cvar_settemp_restore(); // this must be done LAST, but in any case
1839}
void Shutdown()
Definition main.qc:162
float shutdown_running
Definition util.qc:1817
int cvar_settemp_restore()
Definition util.qc:857
#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 663 of file util.qc.

664{
665 float n = tokenize_console(order);
666
667 if(i >= 0 && i < n && j >= 0 && j < n && i != j)
668 {
669 string s = "";
670 for(float w = 0; w < n; ++w)
671 {
672 if(w == i)
673 s = strcat(s, argv(j), " ");
674 else if(w == j)
675 s = strcat(s, argv(i), " ");
676 else
677 s = strcat(s, argv(w), " ");
678 }
679 return substring(s, 0, strlen(s) - 1);
680 }
681
682 return order;
683}

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 1074 of file util.qc.

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

931{
932 // STOP.
933 // The following function is SLOW.
934 // For your safety and for the protection of those around you...
935 // DO NOT CALL THIS AT HOME.
936 // No really, don't.
937 if(w(theText) <= maxLength)
938 return strlen(theText); // yeah!
939
940 bool colors = (w("^7") == 0);
941
942 // binary search for right place to cut string
943 int len, left, right, middle;
944 left = 0;
945 right = len = strlen(theText);
946 int ofs = 0;
947 do
948 {
949 middle = floor((left + right) / 2);
950 if(colors)
951 {
952 vector res = checkColorCode(theText, len, middle, true);
953 ofs = (!res.x) ? 0 : res.x - res.y;
954 }
955
956 if(w(substring(theText, 0, middle + ofs)) <= maxLength)
957 left = middle + ofs;
958 else
959 right = middle;
960 }
961 while(left < right - 1);
962
963 return left;
964}
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 894 of file util.qc.

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

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 1191 of file util.qc.

1192{
1193 if(tw(theText) <= maxWidth)
1194 return theText;
1195 else
1196 return strcat(substring(theText, 0, textLengthUpToLength(theText, maxWidth - tw("..."), tw)), "...");
1197}

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 2231 of file util.qc.

2232{
2233 end -= start;
2234 thmi -= start;
2235 thma -= start;
2236 // now it is a trace from 0 to end
2237
2240
2241 if (!trace_hits_box_1d(end.x, thmi.x, thma.x))
2242 return false;
2243 if (!trace_hits_box_1d(end.y, thmi.y, thma.y))
2244 return false;
2245 if (!trace_hits_box_1d(end.z, thmi.z, thma.z))
2246 return false;
2247
2248 return true;
2249}
float trace_hits_box_a1
Definition util.qc:2207
float trace_hits_box_a0
Definition util.qc:2207
float trace_hits_box_1d(float end, float thmi, float thma)
Definition util.qc:2209

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 2209 of file util.qc.

2210{
2211 if (end == 0)
2212 {
2213 // just check if x is in range
2214 if (0 < thmi)
2215 return false;
2216 if (0 > thma)
2217 return false;
2218 }
2219 else
2220 {
2221 // do the trace with respect to x
2222 // 0 -> end has to stay in thmi -> thma
2223 trace_hits_box_a0 = max(trace_hits_box_a0, min(thmi / end, thma / end));
2224 trace_hits_box_a1 = min(trace_hits_box_a1, max(thmi / end, thma / end));
2226 return false;
2227 }
2228 return true;
2229}
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 2251 of file util.qc.

2252{
2253 return trace_hits_box(start, end, thmi - ma, thma - mi);
2254}
float trace_hits_box(vector start, vector end, vector thmi, vector thma)
Definition util.qc:2231

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 1622 of file util.qc.

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

2162{
2165 ent.aiment_classname = string_null;
2166 // FIXME: engine bug?
2167 // resetting aiment the engine will set orb's origin close to world's origin
2168 //ent.aiment = NULL;
2169}
const int MOVETYPE_FLY
Definition movetypes.qh:138
#define PROJECTILE_MAKETRIGGER(e)
Definition common.qh:34

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:338
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 338 of file util.qc.

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

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 1485 of file util.qc.

1486{
1487 fputs(fh, str);
1488 if (alsoprint) LOG_HELP(str);
1489}
#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 1792 of file util.qc.

1793{
1794 float a, b, c, d;
1795 if(substring(s, 0, 1) != "^")
1796 return -1;
1797 if(strlen(s) < 5)
1798 return -1;
1799 a = strstrofs(XENCODE_2, substring(s, 1, 1), 0);
1800 b = strstrofs(XENCODE_22, substring(s, 2, 1), 0);
1801 c = strstrofs(XENCODE_22, substring(s, 3, 1), 0);
1802 d = strstrofs(XENCODE_22, substring(s, 4, 1), 0);
1803 if(a < 0 || b < 0 || c < 0 || d < 0)
1804 return -1;
1805 return ((a * 22 + b) * 22 + c) * 22 + d;
1806}
const string XENCODE_22
Definition util.qc:1776
const string XENCODE_2
Definition util.qc:1775

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

◆ xencode()

string xencode ( int f)

Definition at line 1777 of file util.qc.

1778{
1779 float a, b, c, d;
1780 d = f % 22; f = floor(f / 22);
1781 c = f % 22; f = floor(f / 22);
1782 b = f % 22; f = floor(f / 22);
1783 a = f % 2; // f = floor(f / 2);
1784 return strcat(
1785 "^",
1786 substring(XENCODE_2, a, 1),
1787 substring(XENCODE_22, b, 1),
1788 substring(XENCODE_22, c, 1),
1789 substring(XENCODE_22, d, 1)
1790 );
1791}

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 2139 of file util.qc.

◆ aiment_deadflag

float aiment_deadflag

Definition at line 2140 of file util.qc.

◆ FindConnectedComponent_processing

float FindConnectedComponent_processing

Definition at line 1874 of file util.qc.

◆ lengthLogTable

float lengthLogTable[128]

Definition at line 465 of file util.qc.

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

◆ shutdown_running

float shutdown_running

Definition at line 1817 of file util.qc.

Referenced by SV_Shutdown().

◆ skeleton_bones_index

float skeleton_bones_index

Definition at line 1842 of file util.qc.

◆ to_execute_next_frame

string to_execute_next_frame

Definition at line 1856 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 2207 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 2207 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 1775 of file util.qc.

Referenced by xdecode(), and xencode().

◆ XENCODE_22

const string XENCODE_22 = "0123456789abcdefABCDEF"

Definition at line 1776 of file util.qc.

Referenced by xdecode(), and xencode().