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

Go to the source code of this file.

Macros

#define prandom_debug()
 
#define RandomSelection_AddEnt(e, weight, priority)   RandomSelection_Add(e, 0, string_null, '0 0 0', weight, priority)
 
#define RandomSelection_AddFloat(f, weight, priority)   RandomSelection_Add(NULL, f, string_null, '0 0 0', weight, priority)
 
#define RandomSelection_AddString(s, weight, priority)   RandomSelection_Add(NULL, 0, s, '0 0 0', weight, priority)
 
#define RandomSelection_AddVec(v, weight, priority)   RandomSelection_Add(NULL, 0, string_null, v, weight, priority)
 
#define USE_PRANDOM
 

Functions

float prandom ()
 
vector prandomvec ()
 
void psrandom (float seed)
 
ERASEABLE void RandomSelection_Add (entity e, float f, string s, vector v, float weight, float priority)
 
ERASEABLE void RandomSelection_Init ()
 

Variables

float RandomSelection_best_priority
 
entity RandomSelection_chosen_ent
 
float RandomSelection_chosen_float
 
string RandomSelection_chosen_string
 
vector RandomSelection_chosen_vec
 
float RandomSelection_totalweight
 

Macro Definition Documentation

◆ prandom_debug

#define prandom_debug ( )

Definition at line 31 of file random.qh.

Referenced by NET_HANDLE(), and psrandom().

◆ RandomSelection_AddEnt

#define RandomSelection_AddEnt (   e,
  weight,
  priority 
)    RandomSelection_Add(e, 0, string_null, '0 0 0', weight, priority)

◆ RandomSelection_AddFloat

#define RandomSelection_AddFloat (   f,
  weight,
  priority 
)    RandomSelection_Add(NULL, f, string_null, '0 0 0', weight, priority)

◆ RandomSelection_AddString

#define RandomSelection_AddString (   s,
  weight,
  priority 
)    RandomSelection_Add(NULL, 0, s, '0 0 0', weight, priority)

◆ RandomSelection_AddVec

#define RandomSelection_AddVec (   v,
  weight,
  priority 
)    RandomSelection_Add(NULL, 0, string_null, v, weight, priority)

Definition at line 17 of file random.qh.

◆ USE_PRANDOM

#define USE_PRANDOM

Definition at line 21 of file random.qh.

Function Documentation

◆ prandom()

float prandom ( )

Definition at line 100 of file random.qc.

References ftos(), LOG_TRACE, M_PI, prandom_seed, and strcat().

Referenced by prandomvec(), SND_GIB_SPLAT_RANDOM(), and turret_gibtoss().

101  {
102  float c;
103  c = crc16(false, strcat(ftos(prandom_seed), ftos(prandom_seed + M_PI)));
104  prandom_seed = c;
105 
106  #ifdef USE_PRANDOM_DEBUG
107  LOG_TRACE("RANDOM -> ", ftos(c));
108  #endif
109 
110  return c / 65536; // in [0..1[
111  }
float prandom_seed
Definition: random.qc:99
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"))
const float M_PI
Definition: csprogsdefs.qc:269
#define LOG_TRACE(...)
Definition: log.qh:81
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ prandomvec()

vector prandomvec ( )

Definition at line 113 of file random.qc.

References prandom(), v, and vector().

Referenced by turret_gibtoss().

114  {
115  vector v;
116 
117  do
118  {
119  v.x = prandom();
120  v.y = prandom();
121  v.z = prandom();
122  }
123  while (v * v > 1);
124 
125  return v;
126  }
float prandom()
Definition: random.qc:100
vector(float skel, float bonenum) _skel_get_boneabs_hidden
vector v
Definition: ent_cs.qc:116
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ psrandom()

void psrandom ( float  seed)

Definition at line 128 of file random.qc.

References ftos(), LOG_TRACE, prandom_debug, and prandom_seed.

Referenced by NET_HANDLE().

129  {
130  prandom_seed = seed;
131  #ifdef USE_PRANDOM_DEBUG
132  LOG_TRACE("SRANDOM ", ftos(seed));
133  #endif
134  }
float prandom_seed
Definition: random.qc:99
#define LOG_TRACE(...)
Definition: log.qh:81
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ RandomSelection_Add()

ERASEABLE void RandomSelection_Add ( entity  e,
float  f,
string  s,
vector  v,
float  weight,
float  priority 
)

Definition at line 14 of file random.qc.

References random(), RandomSelection_best_priority, RandomSelection_chosen_ent, RandomSelection_chosen_float, RandomSelection_chosen_string, RandomSelection_chosen_vec, RandomSelection_totalweight, and v.

Referenced by MUTATOR_HOOKFUNCTION().

15 {
16  if (priority > RandomSelection_best_priority)
17  {
24  }
25  else if (priority == RandomSelection_best_priority)
26  {
28  if (random() * RandomSelection_totalweight <= weight)
29  {
34  }
35  }
36 }
float RandomSelection_totalweight
Definition: random.qh:3
vector RandomSelection_chosen_vec
Definition: random.qh:8
string RandomSelection_chosen_string
Definition: random.qh:7
float RandomSelection_chosen_float
Definition: random.qh:6
entity RandomSelection_chosen_ent
Definition: random.qh:5
vector v
Definition: ent_cs.qc:116
float RandomSelection_best_priority
Definition: random.qh:4
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ RandomSelection_Init()

ERASEABLE void RandomSelection_Init ( )

Definition at line 4 of file random.qc.

References ERASEABLE, NULL, RandomSelection_best_priority, RandomSelection_chosen_ent, RandomSelection_chosen_float, RandomSelection_chosen_string, RandomSelection_totalweight, and string_null.

Referenced by bot_setnameandstuff(), buff_NewType(), CheatCommand(), CheatImpulse(), FixIntermissionClient(), GiveRandomWeapons(), invasion_PickMonster(), invasion_PickSpawn(), invasion_SpawnChosenMonster(), Item_FindTeam(), Item_Touch(), jumppad_push(), MapInfo_LoadMapSettings(), MapVote_CheckRules_2(), MUTATOR_HOOKFUNCTION(), NIX_ChooseNextWeapon(), RandomItems_GetRandomInstagibItemClassName(), RandomItems_GetRandomItemClassNameWithProperty(), RandomItems_GetRandomOverkillItemClassName(), RandomItems_GetRandomVanillaItemClassName(), Simple_TeleportPlayer(), Spawn_WeightedPoint(), spawnmonster(), SUB_UseTargets_Ex(), TeamBalance_FindBestTeam(), TeleportPlayer(), train_next_find(), and W_RandomWeapons().

5 {
11 }
string string_null
Definition: nil.qh:9
float RandomSelection_totalweight
Definition: random.qh:3
string RandomSelection_chosen_string
Definition: random.qh:7
float RandomSelection_chosen_float
Definition: random.qh:6
entity RandomSelection_chosen_ent
Definition: random.qh:5
#define NULL
Definition: post.qh:17
float RandomSelection_best_priority
Definition: random.qh:4
+ Here is the caller graph for this function:

Variable Documentation

◆ RandomSelection_best_priority

float RandomSelection_best_priority

Definition at line 4 of file random.qh.

Referenced by MapVote_CheckRules_2(), RandomSelection_Add(), and RandomSelection_Init().

◆ RandomSelection_chosen_ent

◆ RandomSelection_chosen_float

◆ RandomSelection_chosen_string

◆ RandomSelection_chosen_vec

vector RandomSelection_chosen_vec

Definition at line 8 of file random.qh.

Referenced by MUTATOR_HOOKFUNCTION(), and RandomSelection_Add().

◆ RandomSelection_totalweight

float RandomSelection_totalweight

Definition at line 3 of file random.qh.

Referenced by RandomSelection_Add(), and RandomSelection_Init().