Xonotic
random.qc File Reference
#include "random.qh"
+ Include dependency graph for random.qc:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

ERASEABLE float DistributeEvenly_Get (float weight)
 
ERASEABLE float DistributeEvenly_GetRandomized (float weight)
 
ERASEABLE void DistributeEvenly_Init (float amount, float totalweight)
 
ERASEABLE float gsl_ran_gaussian (float sigma)
 
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 DistributeEvenly_amount
 
float DistributeEvenly_totalweight
 
float gsl_ran_gaussian_lastvalue
 
float gsl_ran_gaussian_lastvalue_set
 
float prandom_seed
 

Function Documentation

◆ DistributeEvenly_Get()

ERASEABLE float DistributeEvenly_Get ( float  weight)

Definition at line 54 of file random.qc.

References DistributeEvenly_amount, DistributeEvenly_totalweight, ERASEABLE, and floor().

Referenced by Invasion_RoundStart(), kh_LoserTeam(), and kh_WinnerTeam().

55 {
56  float f;
57  if (weight <= 0) return 0;
61  return f;
62 }
float DistributeEvenly_totalweight
Definition: random.qc:39
float DistributeEvenly_amount
Definition: random.qc:38
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DistributeEvenly_GetRandomized()

ERASEABLE float DistributeEvenly_GetRandomized ( float  weight)

Definition at line 65 of file random.qc.

References DistributeEvenly_amount, DistributeEvenly_totalweight, floor(), and random().

66 {
67  float f;
68  if (weight <= 0) return 0;
72  return f;
73 }
float DistributeEvenly_totalweight
Definition: random.qc:39
float DistributeEvenly_amount
Definition: random.qc:38
+ Here is the call graph for this function:

◆ DistributeEvenly_Init()

ERASEABLE void DistributeEvenly_Init ( float  amount,
float  totalweight 
)

Definition at line 42 of file random.qc.

References DistributeEvenly_amount, DistributeEvenly_totalweight, ERASEABLE, ftos(), and LOG_TRACE.

Referenced by Invasion_RoundStart(), kh_LoserTeam(), and kh_WinnerTeam().

43 {
45  {
46  LOG_TRACE("DistributeEvenly_Init: UNFINISHED DISTRIBUTION (", ftos(DistributeEvenly_amount), " for ", ftos(DistributeEvenly_totalweight), " left!)");
47  }
48  if (totalweight == 0) DistributeEvenly_amount = 0;
49  else DistributeEvenly_amount = amount;
50  DistributeEvenly_totalweight = totalweight;
51 }
float DistributeEvenly_totalweight
Definition: random.qc:39
#define LOG_TRACE(...)
Definition: log.qh:81
float DistributeEvenly_amount
Definition: random.qc:38
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ gsl_ran_gaussian()

ERASEABLE float gsl_ran_gaussian ( float  sigma)

Definition at line 79 of file random.qc.

References cos(), gsl_ran_gaussian_lastvalue, gsl_ran_gaussian_lastvalue_set, log(), M_PI, random(), sin(), and sqrt().

Referenced by W_CalculateSpread().

80 {
82  {
84  return sigma * gsl_ran_gaussian_lastvalue;
85  }
86  else
87  {
88  float a = random() * 2 * M_PI;
89  float b = sqrt(-2 * log(random()));
92  return sigma * sin(a) * b;
93  }
94 }
float gsl_ran_gaussian_lastvalue
Definition: random.qc:76
float gsl_ran_gaussian_lastvalue_set
Definition: random.qc:77
const float M_PI
Definition: csprogsdefs.qc:269
float log(float f)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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

◆ DistributeEvenly_amount

float DistributeEvenly_amount

◆ DistributeEvenly_totalweight

float DistributeEvenly_totalweight

◆ gsl_ran_gaussian_lastvalue

float gsl_ran_gaussian_lastvalue

Definition at line 76 of file random.qc.

Referenced by gsl_ran_gaussian().

◆ gsl_ran_gaussian_lastvalue_set

float gsl_ran_gaussian_lastvalue_set

Definition at line 77 of file random.qc.

Referenced by gsl_ran_gaussian().

◆ prandom_seed

float prandom_seed

Definition at line 99 of file random.qc.

Referenced by prandom(), and psrandom().