Xonotic
util.qh File Reference
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define APPEND_TO_STRING(list, sep, add)   ((list) = (((list) != "") ? strcat(list, sep, add) : (add)))
 
#define bprintf(...)   bprint(sprintf(__VA_ARGS__))
 
#define COMPARE_INCREASING(to, from)   (to < from ? from + to + 2 : to - from)
 
#define CTF_RECORD   "/ctf100record/"
 
#define CTS_RECORD   "/cts100record/"
 
#define fprintf(file, ...)   fputs(file, sprintf(__VA_ARGS__))
 
#define RACE_RECORD   "/race100record/"
 
#define TIME_DECODE(n)   ((n) / TIME_FACTOR)
 
#define TIME_ENCODE(t)   TIME_TO_NTHS(t, TIME_FACTOR)
 
#define TIME_ENCODED_TOSTRING(n)   mmssth(n)
 
#define TIME_TO_NTHS(t, n)   floor((t) * (n) + 0.5)
 
#define XPD(...)   __VA_ARGS__
 

Typedefs

using findNextEntityNearFunction_t = entity(entity cur, entity near, entity pass)
 
using isConnectedFunction_t = float(entity a, entity b, entity pass)
 
using textLengthUpToLength_lenFunction_t = float(string s)
 
using textLengthUpToWidth_widthFunction_t = float(string s, vector size)
 

Functions

float blink (float base, float range, float freq)
 
float blink_synced (float base, float range, float freq, float start_time, int start_blink)
 
float compressShortVector (vector vec)
 
float compressShotOrigin (vector v)
 
float cvar_or (string cv, float v)
 
float cvar_settemp (string pKey, string pValue)
 
float cvar_settemp_restore ()
 
vector decompressShortVector (float data)
 
vector decompressShotOrigin (float f)
 
void depthfirst (entity start,.entity up,.entity downleft,.entity right, void(entity, entity) funcPre, void(entity, entity) funcPost, entity pass)
 
string draw_UseSkinFor (string pic)
 
void execute_next_frame ()
 
void FindConnectedComponent (entity e,.entity fld, findNextEntityNearFunction_t nxt, isConnectedFunction_t iscon, entity pass)
 
string fixPriorityList (string pl, float from, float to, float subtract, float complete)
 
string get_model_datafilename (string mod, float skn, string fil)
 
float get_model_parameters (string mod, float skn)
 
vector get_shotvelocity (vector myvel, vector mydir, float spd, float newton_style, float mi, float ma)
 
string getcurrentmod ()
 
string getWrappedLine (float w, vector size, textLengthUpToWidth_widthFunction_t tw)
 
string getWrappedLineLen (float w, textLengthUpToLength_lenFunction_t tw)
 
float isGametypeInFilter (entity gt, float tp, float ts, string pattern)
 
string mapPriorityList (string order, string(string) mapfunc)
 
float matchacl (string acl, string str)
 
void queue_to_execute_next_frame (string s)
 
void Shutdown ()
 
vector solve_shotdirection (vector myorg, vector myvel, vector eorg, vector evel, float spd, float newton_style)
 
 STATIC_INIT (g_saved_cvars)
 
string swapInPriorityList (string order, float i, float j)
 
float textLengthUpToLength (string theText, float maxWidth, textLengthUpToLength_lenFunction_t tw)
 
float textLengthUpToWidth (string theText, float maxWidth, vector size, textLengthUpToWidth_widthFunction_t tw)
 
string textShortenToLength (string theText, float maxWidth, textLengthUpToLength_lenFunction_t tw)
 
string textShortenToWidth (string theText, float maxWidth, vector size, textLengthUpToWidth_widthFunction_t tw)
 
ERASEABLE string translate_key (string key)
 
string wordwrap (string s, float l)
 
void wordwrap_cb (string s, float l, void(string) callback)
 
void write_String_To_File (int fh, string str, bool alsoprint)
 
float xdecode (string s)
 
string xencode (float f)
 

Variables

string draw_currentSkin
 
IntrusiveList g_saved_cvars
 
float get_model_parameters_age
 
string get_model_parameters_bone_aim [MAX_AIM_BONES]
 
float get_model_parameters_bone_aimweight [MAX_AIM_BONES]
 
string get_model_parameters_bone_upperbody
 
string get_model_parameters_bone_weapon
 
string get_model_parameters_desc
 
string get_model_parameters_description
 
float get_model_parameters_fixbone
 
bool get_model_parameters_hidden
 
string get_model_parameters_modelname
 
float get_model_parameters_modelskin
 
string get_model_parameters_name
 
string get_model_parameters_sex
 
float get_model_parameters_species
 
float get_model_parameters_weight
 
string getWrappedLine_remaining
 
const int MAX_AIM_BONES = 4
 
string message
 
string netname
 
const int TIME_DECIMALS = 2
 
const float TIME_FACTOR = 100
 
const float XENCODE_LEN = 5
 
const float XENCODE_MAX = 21295
 

Macro Definition Documentation

◆ APPEND_TO_STRING

#define APPEND_TO_STRING (   list,
  sep,
  add 
)    ((list) = (((list) != "") ? strcat(list, sep, add) : (add)))

Definition at line 225 of file util.qh.

Referenced by UpdateNotification_URI_Get_Callback().

◆ bprintf

#define bprintf (   ...)    bprint(sprintf(__VA_ARGS__))

Definition at line 192 of file util.qh.

Referenced by CheatsAllowed().

◆ COMPARE_INCREASING

#define COMPARE_INCREASING (   to,
  from 
)    (to < from ? from + to + 2 : to - from)

Definition at line 228 of file util.qh.

Referenced by HitSound(), and UpdateDamage().

◆ CTF_RECORD

#define CTF_RECORD   "/ctf100record/"

Definition at line 60 of file util.qh.

Referenced by ctf_Initialize().

◆ CTS_RECORD

#define CTS_RECORD   "/cts100record/"

Definition at line 59 of file util.qh.

Referenced by cts_Initialize(), getladder(), and HUD_Mod_Race().

◆ fprintf

#define fprintf (   file,
  ... 
)    fputs(file, sprintf(__VA_ARGS__))

Definition at line 191 of file util.qh.

◆ RACE_RECORD

#define RACE_RECORD   "/race100record/"

Definition at line 58 of file util.qh.

Referenced by getladder(), HUD_Mod_Race(), rc_SetLimits(), and spawnfunc().

◆ TIME_DECODE

#define TIME_DECODE (   n)    ((n) / TIME_FACTOR)

Definition at line 62 of file util.qh.

Referenced by race_setTime().

◆ TIME_ENCODE

#define TIME_ENCODE (   t)    TIME_TO_NTHS(t, TIME_FACTOR)

◆ TIME_ENCODED_TOSTRING

#define TIME_ENCODED_TOSTRING (   n)    mmssth(n)

◆ TIME_TO_NTHS

#define TIME_TO_NTHS (   t,
 
)    floor((t) * (n) + 0.5)

Definition at line 53 of file util.qh.

◆ XPD

#define XPD (   ...)    __VA_ARGS__

Definition at line 188 of file util.qh.

Typedef Documentation

◆ findNextEntityNearFunction_t

Definition at line 183 of file util.qh.

◆ isConnectedFunction_t

Definition at line 184 of file util.qh.

◆ textLengthUpToLength_lenFunction_t

Definition at line 102 of file util.qh.

◆ textLengthUpToWidth_widthFunction_t

Definition at line 101 of file util.qh.

Function Documentation

◆ blink()

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

Definition at line 2044 of file util.qc.

References blink_synced().

Referenced by HUD_HealthArmor(), HUD_Mod_Keepaway(), HUD_Mod_KH(), and Item_ItemsTime_Allow().

2045 {
2046  return blink_synced(base, range, freq, 0, 0);
2047 }
ERASEABLE float blink_synced(float base, float range, float freq, float start_time, int start_pos)
Definition: util.qc:2032
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ blink_synced()

float blink_synced ( float  base,
float  range,
float  freq,
float  start_time,
int  start_blink 
)

Definition at line 2032 of file util.qc.

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

Referenced by blink(), and HUD_HealthArmor().

2033 {
2034  // note:
2035  // RMS = sqrt(base^2 + 0.5 * range^2)
2036  // thus
2037  // base = sqrt(RMS^2 - 0.5 * range^2)
2038  // ensure RMS == 1
2039 
2040  return base + range * sin((time - start_time - (M_PI / 2) * start_pos) * freq);
2041 }
const float M_PI
Definition: csprogsdefs.qc:269
float time
Definition: csprogsdefs.qc:16
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ compressShortVector()

float compressShortVector ( vector  vec)

Definition at line 406 of file util.qc.

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

Referenced by STATIC_INIT().

407 {
408  vector ang;
409  float p, y, len;
410  if(vec == '0 0 0')
411  return 0;
412  //print("compress: ", vtos(vec), "\n");
413  ang = vectoangles(vec);
414  ang.x = -ang.x;
415  if(ang.x < -90)
416  ang.x += 360;
417  if(ang.x < -90 && ang.x > +90)
418  error("BOGUS vectoangles");
419  //print("angles: ", vtos(ang), "\n");
420 
421  p = floor(0.5 + (ang.x + 90) * 16 / 180) & 15; // -90..90 to 0..14
422  if(p == 0)
423  {
424  if(vec.z < 0)
425  y = 31;
426  else
427  y = 30;
428  }
429  else
430  y = floor(0.5 + ang.y * 32 / 360) & 31; // 0..360 to 0..32
431  len = invertLengthLog(vlen(vec));
432 
433  //print("compressed: p ", ftos(p)); print("y ", ftos(y)); print("len ", ftos(len), "\n");
434 
435  return (p * 0x1000) + (y * 0x80) + len;
436 }
float invertLengthLog(float dist)
Definition: util.qc:343
vector(float skel, float bonenum) _skel_get_boneabs_hidden
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ compressShotOrigin()

float compressShotOrigin ( vector  v)

Definition at line 1121 of file util.qc.

References bound(), LOG_DEBUG, rint(), and vtos().

Referenced by ClientInit_misc(), and W_Model().

1122 {
1123  float rx = rint(v.x * 2);
1124  float ry = rint(v.y * 4) + 128;
1125  float rz = rint(v.z * 4) + 128;
1126  if(rx > 255 || rx < 0)
1127  {
1128  LOG_DEBUG("shot origin ", vtos(v), " x out of bounds\n");
1129  rx = bound(0, rx, 255);
1130  }
1131  if(ry > 255 || ry < 0)
1132  {
1133  LOG_DEBUG("shot origin ", vtos(v), " y out of bounds\n");
1134  ry = bound(0, ry, 255);
1135  }
1136  if(rz > 255 || rz < 0)
1137  {
1138  LOG_DEBUG("shot origin ", vtos(v), " z out of bounds\n");
1139  rz = bound(0, rz, 255);
1140  }
1141  return rx * 0x10000 + ry * 0x100 + rz;
1142 }
vector v
Definition: ent_cs.qc:116
#define LOG_DEBUG(...)
Definition: log.qh:85
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cvar_or()

float cvar_or ( string  cv,
float  v 
)

Definition at line 2016 of file util.qc.

References cvar_string(), ERASEABLE, stof(), and v.

2017 {
2018  string s = cvar_string(cv);
2019  if(s == "")
2020  return v;
2021  else
2022  return stof(s);
2023 }
vector v
Definition: ent_cs.qc:116
+ Here is the call graph for this function:

◆ cvar_settemp()

float cvar_settemp ( string  pKey,
string  pValue 
)

Definition at line 696 of file util.qc.

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(), CSQCPlayer_PostUpdate(), CSQCPlayer_Remove(), GameCommand_bot_cmd(), GameCommand_setbots(), GenericCommand_settemp(), NET_HANDLE(), REGISTER_MUTATOR(), View_EventChase(), and View_Ortho().

697 {
698  float created_saved_value;
699 
700  created_saved_value = 0;
701 
702  if (!(tmp_cvar || tmp_value))
703  {
704  LOG_TRACE("Error: Invalid usage of cvar_settemp(string, string); !");
705  return 0;
706  }
707 
708  if(!cvar_type(tmp_cvar))
709  {
710  LOG_INFOF("Error: cvar %s doesn't exist!", tmp_cvar);
711  return 0;
712  }
713 
714  IL_EACH(g_saved_cvars, it.netname == tmp_cvar,
715  {
716  created_saved_value = -1; // skip creation
717  break; // no need to continue
718  });
719 
720  if(created_saved_value != -1)
721  {
722  // creating a new entity to keep track of this cvar
723  entity e = new_pure(saved_cvar_value);
725  e.netname = strzone(tmp_cvar);
726  e.message = strzone(cvar_string(tmp_cvar));
727  created_saved_value = 1;
728  }
729 
730  // update the cvar to the value given
731  cvar_set(tmp_cvar, tmp_value);
732 
733  return created_saved_value;
734 }
#define IL_EACH(this, cond, body)
entity() spawn
ERASEABLE entity IL_PUSH(IntrusiveList this, entity it)
Push to tail.
#define LOG_INFOF(...)
Definition: log.qh:71
#define LOG_TRACE(...)
Definition: log.qh:81
#define new_pure(class)
purely logical entities (.origin doesn&#39;t work)
Definition: oo.qh:62
IntrusiveList g_saved_cvars
Definition: util.qh:33
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cvar_settemp_restore()

float cvar_settemp_restore ( )

Definition at line 736 of file util.qc.

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

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

737 {
738  int j = 0;
739  // FIXME this new-style loop fails!
740 #if 0
741  FOREACH_ENTITY_CLASS("saved_cvar_value", true,
742  {
743  if(cvar_type(it.netname))
744  {
745  cvar_set(it.netname, it.message);
746  strunzone(it.netname);
747  strunzone(it.message);
748  delete(it);
749  ++j;
750  }
751  else
752  LOG_INFOF("Error: cvar %s doesn't exist anymore! It can still be restored once it's manually recreated.", it.netname);
753  });
754 
755 #else
756  entity e = NULL;
757  while((e = find(e, classname, "saved_cvar_value")))
758  {
759  if(cvar_type(e.netname))
760  {
761  cvar_set(e.netname, e.message);
762  delete(e);
763  ++j;
764  }
765  else
766  print(sprintf("Error: cvar %s doesn't exist anymore! It can still be restored once it's manually recreated.", e.netname));
767  }
768 #endif
769 
770  return j;
771 }
entity() spawn
string classname
Definition: csprogsdefs.qc:107
#define FOREACH_ENTITY_CLASS(class, cond, body)
Definition: iter.qh:189
#define LOG_INFOF(...)
Definition: log.qh:71
#define NULL
Definition: post.qh:17
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ decompressShortVector()

vector decompressShortVector ( float  data)

◆ decompressShotOrigin()

vector decompressShotOrigin ( float  f)

◆ depthfirst()

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

Definition at line 281 of file util.qc.

References count_ordinal(), entity(), floor(), SFL_HIDE_ZERO, SFL_RANK, and SFL_TIME.

Referenced by forAllDescendants(), and GameCommand().

282 {
283  entity e;
284  e = start;
285  funcPre(pass, e);
286  while (e.(downleft))
287  {
288  e = e.(downleft);
289  funcPre(pass, e);
290  }
291  funcPost(pass, e);
292  while(e != start)
293  {
294  if (e.(right))
295  {
296  e = e.(right);
297  funcPre(pass, e);
298  while (e.(downleft))
299  {
300  e = e.(downleft);
301  funcPre(pass, e);
302  }
303  }
304  else
305  e = e.(up);
306  funcPost(pass, e);
307  }
308 }
entity() spawn
#define pass(name, colormin, colormax)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ draw_UseSkinFor()

string draw_UseSkinFor ( string  pic)

Definition at line 206 of file util.qc.

References draw_currentSkin, strcat(), strlen(), and substring().

Referenced by draw_BorderPicture(), draw_ButtonPicture(), draw_Picture(), draw_PictureSize(), draw_PreloadPicture(), draw_PreloadPictureWithFlags(), draw_setMousePointer(), draw_VertButtonPicture(), and MapVote_DrawMapItem().

207 {
208  if(substring(pic, 0, 1) == "/")
209  return substring(pic, 1, strlen(pic)-1);
210  else
211  return strcat(draw_currentSkin, "/", pic);
212 }
string draw_currentSkin
Definition: util.qh:45
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ execute_next_frame()

void execute_next_frame ( )

Definition at line 1612 of file util.qc.

References localcmd, and strfree.

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

1613 {
1615  {
1616  localcmd("\n", to_execute_next_frame, "\n");
1618  }
1619 }
string to_execute_next_frame
Definition: util.qc:1581
#define strfree(this)
Definition: string.qh:56
+ Here is the caller graph for this function:

◆ FindConnectedComponent()

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

Definition at line 1630 of file util.qc.

References AnglesTransform_FromAngles(), AnglesTransform_FromVAngles(), AnglesTransform_ToAngles(), AnglesTransform_ToVAngles(), bound(), CONTENT_EMPTY, CONTENT_LAVA, CONTENT_SKY, CONTENT_SLIME, CONTENT_SOLID, CONTENT_WATER, DPCONTENTS_BODY, DPCONTENTS_LAVA, DPCONTENTS_NODROP, DPCONTENTS_OPAQUE, DPCONTENTS_SKY, DPCONTENTS_SLIME, DPCONTENTS_SOLID, DPCONTENTS_WATER, entity(), ERASEABLE, error(), fixedmakevectors, fixedvectoangles2, gettagindex, gettaginfo, intermission_running, IS_PLAYER, max(), min(), MOVETYPE_FLY, MOVETYPE_FOLLOW, MOVETYPE_NONE, NULL, PROJECTILE_MAKETRIGGER, set_movetype(), setorigin(), SOLID_NOT, strcat(), strunzone(), strzone(), substring(), TC, Team_ColorCode(), teamplay, to, v_forward, v_right, v_up, vector(), and vlen().

Referenced by LinkDoors().

1631 {
1632  entity queue_start, queue_end;
1633 
1634  // we build a queue of to-be-processed entities.
1635  // queue_start is the next entity to be checked for neighbors
1636  // queue_end is the last entity added
1637 
1638  if(e.FindConnectedComponent_processing)
1639  error("recursion or broken cleanup");
1640 
1641  // start with a 1-element queue
1642  queue_start = queue_end = e;
1643  queue_end.(fld) = NULL;
1644  queue_end.FindConnectedComponent_processing = 1;
1645 
1646  // for each queued item:
1647  for (; queue_start; queue_start = queue_start.(fld))
1648  {
1649  // find all neighbors of queue_start
1650  entity t;
1651  for(t = NULL; (t = nxt(t, queue_start, pass)); )
1652  {
1653  if(t.FindConnectedComponent_processing)
1654  continue;
1655  if(iscon(t, queue_start, pass))
1656  {
1657  // it is connected? ADD IT. It will look for neighbors soon too.
1658  queue_end.(fld) = t;
1659  queue_end = t;
1660  queue_end.(fld) = NULL;
1661  queue_end.FindConnectedComponent_processing = 1;
1662  }
1663  }
1664  }
1665 
1666  // unmark
1667  for (queue_start = e; queue_start; queue_start = queue_start.(fld))
1668  queue_start.FindConnectedComponent_processing = 0;
1669 }
entity() spawn
#define NULL
Definition: post.qh:17
#define pass(name, colormin, colormax)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fixPriorityList()

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

Definition at line 485 of file util.qc.

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

Referenced by W_FixWeaponOrder().

486 {
487  string neworder;
488  float i, n, w;
489 
490  n = tokenize_console(order);
491  neworder = "";
492  for(i = 0; i < n; ++i)
493  {
494  w = stof(argv(i));
495  if(w == floor(w))
496  {
497  if(w >= from && w <= to)
498  neworder = strcat(neworder, ftos(w), " ");
499  else
500  {
501  w -= subtract;
502  if(w >= from && w <= to)
503  neworder = strcat(neworder, ftos(w), " ");
504  }
505  }
506  }
507 
508  if(complete)
509  {
510  n = tokenize_console(neworder);
511  for(w = to; w >= from; --w)
512  {
513  int wflags = REGISTRY_GET(Weapons, w).spawnflags;
514  if(wflags & WEP_FLAG_SPECIALATTACK)
515  continue;
516  for(i = 0; i < n; ++i)
517  if(stof(argv(i)) == w)
518  break;
519  if(i == n) // not found
520  neworder = strcat(neworder, ftos(w), " ");
521  }
522  }
523 
524  return substring(neworder, 0, strlen(neworder) - 1);
525 }
#define REGISTRY_GET(id, i)
Definition: registry.qh:43
entity to
Definition: self.qh:96
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
#define tokenize_console
Definition: dpextensions.qh:24
const int WEP_FLAG_SPECIALATTACK
Definition: weapon.qh:211
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_model_datafilename()

string get_model_datafilename ( string  mod,
float  skn,
string  fil 
)

Definition at line 1245 of file util.qc.

References ftos(), and strcat().

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

1246 {
1247  if(m)
1248  m = strcat(m, "_");
1249  else
1250  m = "models/player/*_";
1251  if(sk >= 0)
1252  m = strcat(m, ftos(sk));
1253  else
1254  m = strcat(m, "*");
1255  return strcat(m, ".", fil);
1256 }
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_model_parameters()

float get_model_parameters ( string  mod,
float  skn 
)

Definition at line 1258 of file util.qc.

References car(), cdr(), fgets(), FILE_READ, fopen(), 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_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, stof(), strcat(), string_null, and substring().

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

1259 {
1270  for(int i = 0; i < MAX_AIM_BONES; ++i)
1271  {
1274  }
1277 
1278 #ifdef GAMEQC
1279  MUTATOR_CALLHOOK(ClearModelParams);
1280 #endif
1281 
1282  if (!m)
1283  return 1;
1284 
1285  if(substring(m, -9, 5) == "_lod1" || substring(m, -9, 5) == "_lod2")
1286  m = strcat(substring(m, 0, -10), substring(m, -4, -1));
1287 
1288  if(sk < 0)
1289  {
1290  if(substring(m, -4, -1) != ".txt")
1291  return 0;
1292  if(substring(m, -6, 1) != "_")
1293  return 0;
1294  sk = stof(substring(m, -5, 1));
1295  m = substring(m, 0, -7);
1296  }
1297 
1298  string fn = get_model_datafilename(m, sk, "txt");
1299  int fh = fopen(fn, FILE_READ);
1300  if(fh < 0)
1301  {
1302  sk = 0;
1303  fn = get_model_datafilename(m, sk, "txt");
1304  fh = fopen(fn, FILE_READ);
1305  if(fh < 0)
1306  return 0;
1307  }
1308 
1311  string s, c;
1312  while((s = fgets(fh)))
1313  {
1314  if(s == "")
1315  break; // next lines will be description
1316  c = car(s);
1317  s = cdr(s);
1318  if(c == "name")
1320  if(c == "species")
1321  switch(s)
1322  {
1323  case "human": get_model_parameters_species = SPECIES_HUMAN; break;
1324  case "alien": get_model_parameters_species = SPECIES_ALIEN; break;
1325  case "robot_shiny": get_model_parameters_species = SPECIES_ROBOT_SHINY; break;
1326  case "robot_rusty": get_model_parameters_species = SPECIES_ROBOT_RUSTY; break;
1327  case "robot_solid": get_model_parameters_species = SPECIES_ROBOT_SOLID; break;
1328  case "animal": get_model_parameters_species = SPECIES_ANIMAL; break;
1329  case "reserved": get_model_parameters_species = SPECIES_RESERVED; break;
1330  }
1331  if(c == "sex")
1332  {
1333  if (s == "Male") s = _("Male");
1334  else if (s == "Female") s = _("Female");
1335  else if (s == "Undisclosed") s = _("Undisclosed");
1337  }
1338  if(c == "weight")
1340  if(c == "age")
1342  if(c == "description")
1344  if(c == "bone_upperbody")
1346  if(c == "bone_weapon")
1348  #ifdef GAMEQC
1349  MUTATOR_CALLHOOK(GetModelParams, c, s);
1350  #endif
1351  for(int i = 0; i < MAX_AIM_BONES; ++i)
1352  if(c == strcat("bone_aim", ftos(i)))
1353  {
1356  }
1357  if(c == "fixbone")
1359  if(c == "hidden")
1361  }
1362 
1363  while((s = fgets(fh)))
1364  {
1367  if(s != "")
1369  }
1370 
1371  fclose(fh);
1372 
1373  return 1;
1374 }
float get_model_parameters_weight
Definition: util.qh:142
string get_model_datafilename(string m, float sk, string fil)
Definition: util.qc:1245
string get_model_parameters_desc
Definition: util.qh:152
const int SPECIES_ALIEN
Definition: constants.qh:22
#define stob(s)
Definition: int.qh:5
string string_null
Definition: nil.qh:9
const int SPECIES_HUMAN
Definition: constants.qh:20
const int SPECIES_ROBOT_RUSTY
Definition: constants.qh:24
const int MAX_AIM_BONES
Definition: util.qh:148
const int SPECIES_ANIMAL
Definition: constants.qh:23
string get_model_parameters_description
Definition: util.qh:145
ERASEABLE string cdr(string s)
returns all but first word
Definition: string.qh:249
const float FILE_READ
Definition: csprogsdefs.qc:231
float get_model_parameters_fixbone
Definition: util.qh:151
ERASEABLE string car(string s)
returns first word
Definition: string.qh:240
string get_model_parameters_sex
Definition: util.qh:141
float get_model_parameters_age
Definition: util.qh:143
float get_model_parameters_modelskin
Definition: util.qh:138
float get_model_parameters_species
Definition: util.qh:140
string get_model_parameters_modelname
Definition: util.qh:137
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
string get_model_parameters_bone_aim[MAX_AIM_BONES]
Definition: util.qh:149
const int SPECIES_ROBOT_SHINY
Definition: constants.qh:25
string get_model_parameters_bone_weapon
Definition: util.qh:147
string get_model_parameters_bone_upperbody
Definition: util.qh:146
const int SPECIES_RESERVED
Definition: constants.qh:26
const int SPECIES_ROBOT_SOLID
Definition: constants.qh:21
#define MUTATOR_CALLHOOK(id,...)
Definition: base.qh:140
bool get_model_parameters_hidden
Definition: util.qh:144
float get_model_parameters_bone_aimweight[MAX_AIM_BONES]
Definition: util.qh:150
string get_model_parameters_name
Definition: util.qh:139
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_shotvelocity()

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

Definition at line 1081 of file util.qc.

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

Referenced by W_CalculateProjectileVelocity().

1082 {
1083  if(!newton_style)
1084  return spd * mydir;
1085 
1086  if(newton_style == 2)
1087  {
1088  // true Newtonian projectiles with automatic aim adjustment
1089  //
1090  // solve: |outspeed * mydir - myvel| = spd
1091  // outspeed^2 - 2 * outspeed * (mydir * myvel) + myvel^2 - spd^2 = 0
1092  // outspeed = (mydir * myvel) +- sqrt((mydir * myvel)^2 - myvel^2 + spd^2)
1093  // PLUS SIGN!
1094  // not defined?
1095  // then...
1096  // myvel^2 - (mydir * myvel)^2 > spd^2
1097  // velocity without mydir component > spd
1098  // fire at smallest possible spd that works?
1099  // |(mydir * myvel) * myvel - myvel| = spd
1100 
1101  vector solution = solve_quadratic(1, -2 * (mydir * myvel), myvel * myvel - spd * spd);
1102 
1103  float outspeed;
1104  if(solution.z)
1105  outspeed = solution.y; // the larger one
1106  else
1107  {
1108  //outspeed = 0; // slowest possible shot
1109  outspeed = solution.x; // the real part (that is, the average!)
1110  //dprint("impossible shot, adjusting\n");
1111  }
1112 
1113  outspeed = bound(spd * mi, outspeed, spd * ma);
1114  return mydir * outspeed;
1115  }
1116 
1117  // real Newtonian
1118  return myvel + spd * mydir;
1119 }
ERASEABLE vector solve_quadratic(float a, float b, float c)
ax^2 + bx + c = 0
Definition: math.qh:307
vector(float skel, float bonenum) _skel_get_boneabs_hidden
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getcurrentmod()

string getcurrentmod ( )

Definition at line 1191 of file util.qc.

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

Referenced by resolvemod().

1192 {
1193  float n;
1194  string m;
1195  m = cvar_string("fs_gamedir");
1196  n = tokenize_console(m);
1197  if(n == 0)
1198  return "data";
1199  else
1200  return argv(n - 1);
1201 }
#define tokenize_console
Definition: dpextensions.qh:24
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getWrappedLine()

string getWrappedLine ( float  w,
vector  size,
textLengthUpToWidth_widthFunction_t  tw 
)

Definition at line 880 of file util.qc.

References find_last_color_code(), getWrappedLine_remaining, strcat(), string_null, strlen(), substring(), and textLengthUpToWidth().

Referenced by GameTypeVote_DrawGameTypeItem(), InfoMessages_drawstring(), Label_draw(), Label_recalcPositionWithText(), m_tooltip(), rewrapCampaign(), and XonoticTextBox_setText().

881 {
882  string s = getWrappedLine_remaining;
883 
884  if(w <= 0)
885  {
887  return s; // the line has no size ANYWAY, nothing would be displayed.
888  }
889 
890  int take_until = textLengthUpToWidth(s, w, theFontSize, tw);
891  if(take_until > 0 && take_until < strlen(s))
892  {
893  int last_word = take_until - 1;
894  while(last_word > 0 && substring(s, last_word, 1) != " ")
895  --last_word;
896 
897  int skip = 0;
898  if(last_word != 0)
899  {
900  take_until = last_word;
901  skip = 1;
902  }
903 
904  getWrappedLine_remaining = substring(s, take_until + skip, strlen(s) - take_until);
905  if(getWrappedLine_remaining == "")
907  else if (tw("^7", theFontSize) == 0)
909  return substring(s, 0, take_until);
910  }
911  else
912  {
914  return s;
915  }
916 }
string string_null
Definition: nil.qh:9
string find_last_color_code(string s)
Definition: util.qc:845
string getWrappedLine_remaining
Definition: util.qh:108
float textLengthUpToWidth(string theText, float maxWidth, vector theSize, textLengthUpToWidth_widthFunction_t w)
Definition: util.qc:773
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getWrappedLineLen()

string getWrappedLineLen ( float  w,
textLengthUpToLength_lenFunction_t  tw 
)

Definition at line 918 of file util.qc.

References find_last_color_code(), getWrappedLine_remaining, strcat(), string_null, strlen(), substring(), and textLengthUpToLength().

Referenced by Say().

919 {
920  string s = getWrappedLine_remaining;
921 
922  if(w <= 0)
923  {
925  return s; // the line has no size ANYWAY, nothing would be displayed.
926  }
927 
928  int take_until = textLengthUpToLength(s, w, tw);
929  if(take_until > 0 && take_until < strlen(s))
930  {
931  int last_word = take_until - 1;
932  while(last_word > 0 && substring(s, last_word, 1) != " ")
933  --last_word;
934 
935  int skip = 0;
936  if(last_word != 0)
937  {
938  take_until = last_word;
939  skip = 1;
940  }
941 
942  getWrappedLine_remaining = substring(s, take_until + skip, strlen(s) - take_until);
943  if(getWrappedLine_remaining == "")
945  else if (tw("^7") == 0)
947  return substring(s, 0, take_until);
948  }
949  else
950  {
952  return s;
953  }
954 }
string string_null
Definition: nil.qh:9
string find_last_color_code(string s)
Definition: util.qc:845
string getWrappedLine_remaining
Definition: util.qh:108
float textLengthUpToLength(string theText, float maxWidth, textLengthUpToLength_lenFunction_t w)
Definition: util.qc:809
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isGametypeInFilter()

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

◆ mapPriorityList()

string mapPriorityList ( string  order,
string(string mapfunc 
)

Definition at line 527 of file util.qc.

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

Referenced by W_NameWeaponOrder(), and W_NumberWeaponOrder().

528 {
529  string neworder;
530  float n;
531 
532  n = tokenize_console(order);
533  neworder = "";
534  for(float i = 0; i < n; ++i)
535  neworder = strcat(neworder, mapfunc(argv(i)), " ");
536 
537  return substring(neworder, 0, strlen(neworder) - 1);
538 }
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
#define tokenize_console
Definition: dpextensions.qh:24
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ matchacl()

float matchacl ( string  acl,
string  str 
)

Definition at line 1203 of file util.qc.

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

Referenced by _MapInfo_Parse_Settemp().

1204 {
1205  string t, s;
1206  float r, d;
1207  r = 0;
1208  while(acl)
1209  {
1210  t = car(acl); acl = cdr(acl);
1211 
1212  d = 1;
1213  if(substring(t, 0, 1) == "-")
1214  {
1215  d = -1;
1216  t = substring(t, 1, strlen(t) - 1);
1217  }
1218  else if(substring(t, 0, 1) == "+")
1219  t = substring(t, 1, strlen(t) - 1);
1220 
1221  if(substring(t, -1, 1) == "*")
1222  {
1223  t = substring(t, 0, strlen(t) - 1);
1224  s = substring(str, 0, strlen(t));
1225  }
1226  else
1227  s = str;
1228 
1229  if(s == t)
1230  {
1231  r = d;
1232  break; // if we found a killing case, apply it! other settings may be allowed in the future, but this one is caught
1233  }
1234  }
1235  return r;
1236 }
ERASEABLE string cdr(string s)
returns all but first word
Definition: string.qh:249
ERASEABLE string car(string s)
returns first word
Definition: string.qh:240
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ queue_to_execute_next_frame()

void queue_to_execute_next_frame ( string  s)

Definition at line 1620 of file util.qc.

References strcat(), and strcpy.

Referenced by GenericCommand_nextframe().

1621 {
1623  {
1624  s = strcat(s, "\n", to_execute_next_frame);
1625  }
1627 }
#define strcpy(this, s)
Definition: string.qh:49
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
string to_execute_next_frame
Definition: util.qc:1581
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Shutdown()

void Shutdown ( )

Definition at line 152 of file main.qc.

References __init_dedicated_server_shutdown(), autocvar_chase_active, autocvar_cl_db_saveasdump, autocvar_developer, autocvar_r_drawviewmodel, autocvar_sessionid, autocvar_sv_db_saveasdump, Ban_SaveBans(), binddb, bot_endgame(), calledhooks, camera_active, chase_active_backup, cheatcount_total, CheatShutdown(), ClientProgsDB, cvar_defstring(), cvar_set(), db_close(), db_dump(), db_save(), deactivate_minigame(), FOREACH_ENTITY_ORDERED, ftos(), HOOK_END, HOOK_START, HUD_MinigameMenu_Close(), isdemo(), localcmd, LOG_INFO, LOG_TRACE, m_hide(), MapInfo_Shutdown(), NULL, orig_slowmo, players, ServerProgsDB, strcat(), strfree, sv_termsofservice_url_escaped, teams, tempdb, TemporaryDB, TIMEOUT_ACTIVE, WarpZone_Shutdown(), WeaponStats_Shutdown(), and world_initialized.

153 {
155 
156  delete(teams);
157  delete(players);
158  db_close(binddb);
159  db_close(tempdb);
161  db_dump(ClientProgsDB, "client.db");
162  else
163  db_save(ClientProgsDB, "client.db");
165 
166  if(camera_active)
167  cvar_set("chase_active",ftos(chase_active_backup));
168 
169  // unset the event chasecam's chase_active
170  if(autocvar_chase_active < 0)
171  cvar_set("chase_active", "0");
172 
173  if (autocvar_r_drawviewmodel < 0)
174  cvar_set("r_drawviewmodel", "0");
175 
176  cvar_set("slowmo", cvar_defstring("slowmo")); // reset it back to 'default'
177 
178  if (!isdemo())
179  {
180  if (!(calledhooks & HOOK_START))
181  localcmd("\n_cl_hook_gamestart nop\n");
182  if (!(calledhooks & HOOK_END))
183  localcmd("\ncl_hook_gameend\n");
184  }
185 
186  localcmd("\ncl_hook_shutdown\n");
187 
188  localcmd("\n-button12\n");
189 
192 
193  ReplicateVars(REPLICATEVARS_DESTROY);
194 }
int binddb
Definition: main.qh:160
ERASEABLE void db_close(int db)
Definition: map.qh:84
void HUD_MinigameMenu_Close(entity this, entity actor, entity trigger)
int ClientProgsDB
Definition: main.qh:176
int tempdb
Definition: main.qh:175
int calledhooks
Definition: main.qh:134
entity teams
Definition: main.qh:44
void deactivate_minigame()
Definition: cl_minigames.qc:83
void WarpZone_Shutdown()
Definition: client.qc:290
ERASEABLE void db_save(int db, string filename)
Definition: map.qh:8
ERASEABLE void db_dump(int db, string filename)
Definition: map.qh:69
#define NULL
Definition: post.qh:17
float chase_active_backup
Definition: main.qh:124
const int HOOK_END
Definition: main.qh:136
const int HOOK_START
Definition: main.qh:135
entity players
Definition: main.qh:43
bool autocvar_r_drawviewmodel
Definition: view.qh:94
float camera_active
Definition: main.qh:123
int autocvar_chase_active
Definition: view.qh:17
bool autocvar_cl_db_saveasdump
Definition: main.qh:6
+ Here is the call graph for this function:

◆ solve_shotdirection()

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

Definition at line 1018 of file util.qc.

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

1019 {
1020  vector ret;
1021 
1022  // make origin and speed relative
1023  eorg -= myorg;
1024  if(newton_style)
1025  evel -= myvel;
1026 
1027  // now solve for ret, ret normalized:
1028  // eorg + t * evel == t * ret * spd
1029  // or, rather, solve for t:
1030  // |eorg + t * evel| == t * spd
1031  // eorg^2 + t^2 * evel^2 + 2 * t * (eorg * evel) == t^2 * spd^2
1032  // t^2 * (evel^2 - spd^2) + t * (2 * (eorg * evel)) + eorg^2 == 0
1033  vector solution = solve_quadratic(evel * evel - spd * spd, 2 * (eorg * evel), eorg * eorg);
1034  // p = 2 * (eorg * evel) / (evel * evel - spd * spd)
1035  // q = (eorg * eorg) / (evel * evel - spd * spd)
1036  if(!solution.z) // no real solution
1037  {
1038  // happens if D < 0
1039  // (eorg * evel)^2 < (evel^2 - spd^2) * eorg^2
1040  // (eorg * evel)^2 / eorg^2 < evel^2 - spd^2
1041  // spd^2 < ((evel^2 * eorg^2) - (eorg * evel)^2) / eorg^2
1042  // spd^2 < evel^2 * (1 - cos^2 angle(evel, eorg))
1043  // spd^2 < evel^2 * sin^2 angle(evel, eorg)
1044  // spd < |evel| * sin angle(evel, eorg)
1045  return '0 0 0';
1046  }
1047  else if(solution.x > 0)
1048  {
1049  // both solutions > 0: take the smaller one
1050  // happens if p < 0 and q > 0
1051  ret = normalize(eorg + solution.x * evel);
1052  }
1053  else if(solution.y > 0)
1054  {
1055  // one solution > 0: take the larger one
1056  // happens if q < 0 or q == 0 and p < 0
1057  ret = normalize(eorg + solution.y * evel);
1058  }
1059  else
1060  {
1061  // no solution > 0: reject
1062  // happens if p > 0 and q >= 0
1063  // 2 * (eorg * evel) / (evel * evel - spd * spd) > 0
1064  // (eorg * eorg) / (evel * evel - spd * spd) >= 0
1065  //
1066  // |evel| >= spd
1067  // eorg * evel > 0
1068  //
1069  // "Enemy is moving away from me at more than spd"
1070  return '0 0 0';
1071  }
1072 
1073  // NOTE: we always got a solution if spd > |evel|
1074 
1075  if(newton_style == 2)
1076  ret = normalize(ret * spd + myvel);
1077 
1078  return ret;
1079 }
ERASEABLE vector solve_quadratic(float a, float b, float c)
ax^2 + bx + c = 0
Definition: math.qh:307
vector(float skel, float bonenum) _skel_get_boneabs_hidden
+ Here is the call graph for this function:

◆ STATIC_INIT()

STATIC_INIT ( g_saved_cvars  )

Definition at line 34 of file util.qh.

References entity(), IL_NEW, to, wordwrap(), and wordwrap_cb().

34 { g_saved_cvars = IL_NEW(); }
#define IL_NEW()
IntrusiveList g_saved_cvars
Definition: util.qh:33
+ Here is the call graph for this function:

◆ swapInPriorityList()

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

Definition at line 540 of file util.qc.

References argv(), MapInfo_Get_ByName(), MapInfo_Map_maxs, MapInfo_Map_mins, mapname, MOVE_WORLDONLY, NULL, strcasecmp, strcat(), strcpy, strlen(), substring(), tokenize_console, trace_endpos, trace_startsolid, vector(), and world.

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

541 {
542  float n = tokenize_console(order);
543 
544  if(i >= 0 && i < n && j >= 0 && j < n && i != j)
545  {
546  string s = "";
547  for(float w = 0; w < n; ++w)
548  {
549  if(w == i)
550  s = strcat(s, argv(j), " ");
551  else if(w == j)
552  s = strcat(s, argv(i), " ");
553  else
554  s = strcat(s, argv(w), " ");
555  }
556  return substring(s, 0, strlen(s) - 1);
557  }
558 
559  return order;
560 }
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
#define tokenize_console
Definition: dpextensions.qh:24
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ textLengthUpToLength()

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

Definition at line 809 of file util.qc.

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

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

810 {
811  // STOP.
812  // The following function is SLOW.
813  // For your safety and for the protection of those around you...
814  // DO NOT CALL THIS AT HOME.
815  // No really, don't.
816  if(w(theText) <= maxWidth)
817  return strlen(theText); // yeah!
818 
819  bool colors = (w("^7") == 0);
820 
821  // binary search for right place to cut string
822  int len, left, right, middle;
823  left = 0;
824  right = len = strlen(theText);
825  int ofs = 0;
826  do
827  {
828  middle = floor((left + right) / 2);
829  if(colors)
830  {
831  vector res = checkColorCode(theText, len, middle, true);
832  ofs = (!res.x) ? 0 : res.x - res.y;
833  }
834 
835  if(w(substring(theText, 0, middle + ofs)) <= maxWidth)
836  left = middle + ofs;
837  else
838  right = middle;
839  }
840  while(left < right - 1);
841 
842  return left;
843 }
vector(float skel, float bonenum) _skel_get_boneabs_hidden
ERASEABLE vector checkColorCode(string theText, int text_len, int pos, bool check_at_the_end)
Definition: string.qh:540
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ textLengthUpToWidth()

float textLengthUpToWidth ( string  theText,
float  maxWidth,
vector  size,
textLengthUpToWidth_widthFunction_t  tw 
)

Definition at line 773 of file util.qc.

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

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

774 {
775  // STOP.
776  // The following function is SLOW.
777  // For your safety and for the protection of those around you...
778  // DO NOT CALL THIS AT HOME.
779  // No really, don't.
780  if(w(theText, theSize) <= maxWidth)
781  return strlen(theText); // yeah!
782 
783  bool colors = (w("^7", theSize) == 0);
784 
785  // binary search for right place to cut string
786  int len, left, right, middle;
787  left = 0;
788  right = len = strlen(theText);
789  int ofs = 0;
790  do
791  {
792  middle = floor((left + right) / 2);
793  if(colors)
794  {
795  vector res = checkColorCode(theText, len, middle, false);
796  ofs = (res.x) ? res.x - res.y : 0;
797  }
798 
799  if(w(substring(theText, 0, middle + ofs), theSize) <= maxWidth)
800  left = middle + ofs;
801  else
802  right = middle;
803  }
804  while(left < right - 1);
805 
806  return left;
807 }
vector(float skel, float bonenum) _skel_get_boneabs_hidden
ERASEABLE vector checkColorCode(string theText, int text_len, int pos, bool check_at_the_end)
Definition: string.qh:540
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ textShortenToLength()

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

Definition at line 964 of file util.qc.

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

965 {
966  if(tw(theText) <= maxWidth)
967  return theText;
968  else
969  return strcat(substring(theText, 0, textLengthUpToLength(theText, maxWidth - tw("..."), tw)), "...");
970 }
float textLengthUpToLength(string theText, float maxWidth, textLengthUpToLength_lenFunction_t w)
Definition: util.qc:809
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
+ Here is the call graph for this function:

◆ textShortenToWidth()

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

Definition at line 956 of file util.qc.

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

Referenced by Draw_ShowNames(), draw_TextShortenToWidth(), HUD_Chat(), HUD_Quickmenu_DrawEntry(), minigame_drawcolorcodedstring_trunc(), minigame_drawstring_trunc(), Scoreboard_DrawOthers(), Scoreboard_FixColumnWidth(), and Scoreboard_Rankings_Draw().

957 {
958  if(tw(theText, theFontSize) <= maxWidth)
959  return theText;
960  else
961  return strcat(substring(theText, 0, textLengthUpToWidth(theText, maxWidth - tw("...", theFontSize), theFontSize, tw)), "...");
962 }
float textLengthUpToWidth(string theText, float maxWidth, vector theSize, textLengthUpToWidth_widthFunction_t w)
Definition: util.qc:773
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ translate_key()

ERASEABLE string translate_key ( string  key)

Definition at line 1376 of file util.qc.

References prvm_language, and substring().

Referenced by _getcommandkey(), and XonoticKeyBinder_drawListBoxItem().

1377 {
1378  if (prvm_language == "en") return key;
1379 
1380  if (substring(key, 0, 1) == "<")
1381  {
1382  if (key == "<KEY NOT FOUND>") return _("<KEY NOT FOUND>");
1383  if (key == "<UNKNOWN KEYNUM>") return _("<UNKNOWN KEYNUM>");
1384  }
1385 
1386  switch(key)
1387  {
1388  case "TAB": return _("TAB");
1389  case "ENTER": return _("ENTER");
1390  case "ESCAPE": return _("ESCAPE");
1391  case "SPACE": return _("SPACE");
1392 
1393  case "BACKSPACE": return _("BACKSPACE");
1394  case "UPARROW": return _("UPARROW");
1395  case "DOWNARROW": return _("DOWNARROW");
1396  case "LEFTARROW": return _("LEFTARROW");
1397  case "RIGHTARROW": return _("RIGHTARROW");
1398 
1399  case "ALT": return _("ALT");
1400  case "CTRL": return _("CTRL");
1401  case "SHIFT": return _("SHIFT");
1402 
1403  case "INS": return _("INS");
1404  case "DEL": return _("DEL");
1405  case "PGDN": return _("PGDN");
1406  case "PGUP": return _("PGUP");
1407  case "HOME": return _("HOME");
1408  case "END": return _("END");
1409 
1410  case "PAUSE": return _("PAUSE");
1411 
1412  case "NUMLOCK": return _("NUMLOCK");
1413  case "CAPSLOCK": return _("CAPSLOCK");
1414  case "SCROLLOCK": return _("SCROLLOCK");
1415 
1416  case "SEMICOLON": return _("SEMICOLON");
1417  case "TILDE": return _("TILDE");
1418  case "BACKQUOTE": return _("BACKQUOTE");
1419  case "QUOTE": return _("QUOTE");
1420  case "APOSTROPHE": return _("APOSTROPHE");
1421  case "BACKSLASH": return _("BACKSLASH");
1422  }
1423 
1424  if (substring(key, 0, 1) == "F")
1425  {
1426  string subkey = substring(key, 1, -1);
1427  if (IS_DIGIT(substring(key, 3, 1))) // check only first digit
1428  {
1429  return sprintf(_("F%d"), stof(subkey));
1430  }
1431  // continue in case there is another key name starting with F
1432  }
1433 
1434  if (substring(key, 0, 3) == "KP_")
1435  {
1436  string subkey = substring(key, 3, -1);
1437  if (IS_DIGIT(substring(key, 3, 1))) // check only first digit
1438  {
1439  return sprintf(_("KP_%d"), stof(subkey));
1440  }
1441 
1442  switch(subkey)
1443  {
1444  case "INS": return sprintf(_("KP_%s"), _("INS"));
1445  case "END": return sprintf(_("KP_%s"), _("END"));
1446  case "DOWNARROW": return sprintf(_("KP_%s"), _("DOWNARROW"));
1447  case "PGDN": return sprintf(_("KP_%s"), _("PGDN"));
1448  case "LEFTARROW": return sprintf(_("KP_%s"), _("LEFTARROW"));
1449  case "RIGHTARROW": return sprintf(_("KP_%s"), _("RIGHTARROW"));
1450  case "HOME": return sprintf(_("KP_%s"), _("HOME"));
1451  case "UPARROW": return sprintf(_("KP_%s"), _("UPARROW"));
1452  case "PGUP": return sprintf(_("KP_%s"), _("PGUP"));
1453  case "PERIOD": return sprintf(_("KP_%s"), _("PERIOD"));
1454  case "DEL": return sprintf(_("KP_%s"), _("DEL"));
1455  case "DIVIDE": return sprintf(_("KP_%s"), _("DIVIDE"));
1456  case "SLASH": return sprintf(_("KP_%s"), _("SLASH"));
1457  case "MULTIPLY": return sprintf(_("KP_%s"), _("MULTIPLY"));
1458  case "MINUS": return sprintf(_("KP_%s"), _("MINUS"));
1459  case "PLUS": return sprintf(_("KP_%s"), _("PLUS"));
1460  case "ENTER": return sprintf(_("KP_%s"), _("ENTER"));
1461  case "EQUALS": return sprintf(_("KP_%s"), _("EQUALS"));
1462  default: return key;
1463  }
1464  }
1465 
1466  if (key == "PRINTSCREEN") return _("PRINTSCREEN");
1467 
1468  if (substring(key, 0, 5) == "MOUSE")
1469  return sprintf(_("MOUSE%d"), stof(substring(key, 5, -1)));
1470 
1471  if (key == "MWHEELUP") return _("MWHEELUP");
1472  if (key == "MWHEELDOWN") return _("MWHEELDOWN");
1473 
1474  if (substring(key, 0,3) == "JOY")
1475  return sprintf(_("JOY%d"), stof(substring(key, 3, -1)));
1476 
1477  if (substring(key, 0,3) == "AUX")
1478  return sprintf(_("AUX%d"), stof(substring(key, 3, -1)));
1479 
1480  if (substring(key, 0, 4) == "X360_")
1481  {
1482  string subkey = substring(key, 4, -1);
1483  switch(subkey)
1484  {
1485  case "DPAD_UP": return sprintf(_("X360_%s"), _("DPAD_UP"));
1486  case "DPAD_DOWN": return sprintf(_("X360_%s"), _("DPAD_DOWN"));
1487  case "DPAD_LEFT": return sprintf(_("X360_%s"), _("DPAD_LEFT"));
1488  case "DPAD_RIGHT": return sprintf(_("X360_%s"), _("DPAD_RIGHT"));
1489  case "START": return sprintf(_("X360_%s"), _("START"));
1490  case "BACK": return sprintf(_("X360_%s"), _("BACK"));
1491  case "LEFT_THUMB": return sprintf(_("X360_%s"), _("LEFT_THUMB"));
1492  case "RIGHT_THUMB": return sprintf(_("X360_%s"), _("RIGHT_THUMB"));
1493  case "LEFT_SHOULDER": return sprintf(_("X360_%s"), _("LEFT_SHOULDER"));
1494  case "RIGHT_SHOULDER": return sprintf(_("X360_%s"), _("RIGHT_SHOULDER"));
1495  case "LEFT_TRIGGER": return sprintf(_("X360_%s"), _("LEFT_TRIGGER"));
1496  case "RIGHT_TRIGGER": return sprintf(_("X360_%s"), _("RIGHT_TRIGGER"));
1497  case "LEFT_THUMB_UP": return sprintf(_("X360_%s"), _("LEFT_THUMB_UP"));
1498  case "LEFT_THUMB_DOWN": return sprintf(_("X360_%s"), _("LEFT_THUMB_DOWN"));
1499  case "LEFT_THUMB_LEFT": return sprintf(_("X360_%s"), _("LEFT_THUMB_LEFT"));
1500  case "LEFT_THUMB_RIGHT": return sprintf(_("X360_%s"), _("LEFT_THUMB_RIGHT"));
1501  case "RIGHT_THUMB_UP": return sprintf(_("X360_%s"), _("RIGHT_THUMB_UP"));
1502  case "RIGHT_THUMB_DOWN": return sprintf(_("X360_%s"), _("RIGHT_THUMB_DOWN"));
1503  case "RIGHT_THUMB_LEFT": return sprintf(_("X360_%s"), _("RIGHT_THUMB_LEFT"));
1504  case "RIGHT_THUMB_RIGHT": return sprintf(_("X360_%s"), _("RIGHT_THUMB_RIGHT"));
1505  default: return key;
1506  }
1507  }
1508 
1509  if (substring(key, 0, 4) == "JOY_")
1510  {
1511  string subkey = substring(key, 4, -1);
1512  switch(subkey)
1513  {
1514  case "UP": return sprintf(_("JOY_%s"), _("UP"));
1515  case "DOWN": return sprintf(_("JOY_%s"), _("DOWN"));
1516  case "LEFT": return sprintf(_("JOY_%s"), _("LEFT"));
1517  case "RIGHT": return sprintf(_("JOY_%s"), _("RIGHT"));
1518  default: return key;
1519  }
1520  }
1521 
1522  if (substring(key, 0, 8) == "MIDINOTE")
1523  return sprintf(_("MIDINOTE%d"), stof(substring(key, 8, -1)));
1524 
1525  return key;
1526 }
#define IS_DIGIT(d)
Definition: string.qh:507
string prvm_language
Definition: i18n.qh:8
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ wordwrap()

string wordwrap ( string  s,
float  l 
)

Definition at line 170 of file util.qc.

References entity(), NULL, sprint(), strcat(), to, wordwrap_buffer, wordwrap_buffer_put(), and wordwrap_cb().

Referenced by STATIC_INIT().

171 {
172  string r;
173  wordwrap_buffer = "";
175  r = wordwrap_buffer;
176  wordwrap_buffer = "";
177  return r;
178 }
void wordwrap_buffer_put(string s)
Definition: util.qc:165
string wordwrap_buffer
Definition: util.qc:163
void wordwrap_cb(string s, float l, void(string) callback)
Definition: util.qc:215
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ wordwrap_cb()

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

Definition at line 215 of file util.qc.

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

Referenced by STATIC_INIT(), and wordwrap().

216 {
217  string c;
218  float lleft, i, j, wlen;
219 
220  s = strzone(s);
221  lleft = l;
222  int len = strlen(s);
223  for (i = 0; i < len; ++i)
224  {
225  if (substring(s, i, 2) == "\\n")
226  {
227  callback("\n");
228  lleft = l;
229  ++i;
230  }
231  else if (substring(s, i, 1) == "\n")
232  {
233  callback("\n");
234  lleft = l;
235  }
236  else if (substring(s, i, 1) == " ")
237  {
238  if (lleft > 0)
239  {
240  callback(" ");
241  --lleft;
242  }
243  }
244  else
245  {
246  for (j = i+1; j < len; ++j)
247  // ^^ this skips over the first character of a word, which
248  // is ALWAYS part of the word
249  // this is safe since if i+1 == strlen(s), i will become
250  // strlen(s)-1 at the end of this block and the function
251  // will terminate. A space can't be the first character we
252  // read here, and neither can a \n be the start, since these
253  // two cases have been handled above.
254  {
255  c = substring(s, j, 1);
256  if (c == " ")
257  break;
258  if (c == "\\")
259  break;
260  if (c == "\n")
261  break;
262  // we need to keep this tempstring alive even if substring is
263  // called repeatedly, so call strcat even though we're not
264  // doing anything
265  callback("");
266  }
267  wlen = j - i;
268  if (lleft < wlen)
269  {
270  callback("\n");
271  lleft = l;
272  }
273  callback(substring(s, i, wlen));
274  lleft -= wlen;
275  i = j - 1;
276  }
277  }
278  strunzone(s);
279 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ write_String_To_File()

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

Definition at line 1239 of file util.qc.

References fputs(), and LOG_HELP.

1240 {
1241  fputs(fh, str);
1242  if (alsoprint) LOG_HELP(str);
1243 }
#define LOG_HELP(...)
Definition: log.qh:95
+ Here is the call graph for this function:

◆ xdecode()

float xdecode ( string  s)

Definition at line 1546 of file util.qc.

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

1547 {
1548  float a, b, c, d;
1549  if(substring(s, 0, 1) != "^")
1550  return -1;
1551  if(strlen(s) < 5)
1552  return -1;
1553  a = strstrofs(XENCODE_2, substring(s, 1, 1), 0);
1554  b = strstrofs(XENCODE_22, substring(s, 2, 1), 0);
1555  c = strstrofs(XENCODE_22, substring(s, 3, 1), 0);
1556  d = strstrofs(XENCODE_22, substring(s, 4, 1), 0);
1557  if(a < 0 || b < 0 || c < 0 || d < 0)
1558  return -1;
1559  return ((a * 22 + b) * 22 + c) * 22 + d;
1560 }
const string XENCODE_22
Definition: util.qc:1530
const string XENCODE_2
Definition: util.qc:1529
#define strstrofs
Definition: dpextensions.qh:42
+ Here is the call graph for this function:

◆ xencode()

string xencode ( float  f)

Variable Documentation

◆ draw_currentSkin

string draw_currentSkin

Definition at line 45 of file util.qh.

Referenced by draw_cursor(), draw_UseSkinFor(), LoadMenuSkinValues(), and m_init_delayed().

◆ g_saved_cvars

IntrusiveList g_saved_cvars

Definition at line 33 of file util.qh.

Referenced by cvar_settemp().

◆ get_model_parameters_age

float get_model_parameters_age

Definition at line 143 of file util.qh.

Referenced by get_model_parameters(), and XonoticPlayerModelSelector_loadModels().

◆ get_model_parameters_bone_aim

string get_model_parameters_bone_aim[MAX_AIM_BONES]

Definition at line 149 of file util.qh.

Referenced by get_model_parameters(), and skeleton_loadinfo().

◆ get_model_parameters_bone_aimweight

float get_model_parameters_bone_aimweight[MAX_AIM_BONES]

Definition at line 150 of file util.qh.

Referenced by get_model_parameters(), and skeleton_loadinfo().

◆ get_model_parameters_bone_upperbody

string get_model_parameters_bone_upperbody

Definition at line 146 of file util.qh.

Referenced by get_model_parameters(), and skeleton_loadinfo().

◆ get_model_parameters_bone_weapon

string get_model_parameters_bone_weapon

Definition at line 147 of file util.qh.

Referenced by get_model_parameters(), and skeleton_loadinfo().

◆ get_model_parameters_desc

string get_model_parameters_desc

Definition at line 152 of file util.qh.

Referenced by get_model_parameters(), and XonoticPlayerModelSelector_loadModels().

◆ get_model_parameters_description

string get_model_parameters_description

Definition at line 145 of file util.qh.

Referenced by XonoticPlayerModelSelector_loadModels().

◆ get_model_parameters_fixbone

float get_model_parameters_fixbone

Definition at line 151 of file util.qh.

Referenced by get_model_parameters(), and skeleton_loadinfo().

◆ get_model_parameters_hidden

bool get_model_parameters_hidden

Definition at line 144 of file util.qh.

Referenced by get_model_parameters(), and XonoticPlayerModelSelector_loadModels().

◆ get_model_parameters_modelname

string get_model_parameters_modelname

Definition at line 137 of file util.qh.

Referenced by get_model_parameters(), and XonoticPlayerModelSelector_loadModels().

◆ get_model_parameters_modelskin

float get_model_parameters_modelskin

Definition at line 138 of file util.qh.

Referenced by get_model_parameters(), and XonoticPlayerModelSelector_loadModels().

◆ get_model_parameters_name

string get_model_parameters_name

Definition at line 139 of file util.qh.

Referenced by get_model_parameters(), and XonoticPlayerModelSelector_loadModels().

◆ get_model_parameters_sex

string get_model_parameters_sex

Definition at line 141 of file util.qh.

Referenced by get_model_parameters(), and XonoticPlayerModelSelector_loadModels().

◆ get_model_parameters_species

float get_model_parameters_species

Definition at line 140 of file util.qh.

Referenced by get_model_parameters(), and player_getspecies().

◆ get_model_parameters_weight

float get_model_parameters_weight

Definition at line 142 of file util.qh.

Referenced by get_model_parameters(), and XonoticPlayerModelSelector_loadModels().

◆ getWrappedLine_remaining

◆ MAX_AIM_BONES

const int MAX_AIM_BONES = 4

Definition at line 148 of file util.qh.

Referenced by get_model_parameters(), skeleton_from_frames(), and skeleton_loadinfo().

◆ message

string message

Definition at line 31 of file util.qh.

◆ netname

string netname

Definition at line 30 of file util.qh.

◆ TIME_DECIMALS

const int TIME_DECIMALS = 2

Definition at line 55 of file util.qh.

Referenced by HUD_Score(), and MakeRaceString().

◆ TIME_FACTOR

const float TIME_FACTOR = 100

Definition at line 56 of file util.qh.

◆ XENCODE_LEN

const float XENCODE_LEN = 5

Definition at line 161 of file util.qh.

◆ XENCODE_MAX

const float XENCODE_MAX = 21295

Definition at line 160 of file util.qh.