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

Go to the source code of this file.

Functions

vector damage_explosion_calcpush (vector explosion_f, vector target_v, float speedfactor)
 
float explosion_calcpush_getmultiplier (vector explosion_v, vector target_v)
 
vector W_CalculateSpread (vector forward, float spread, float spreadfactor, float spreadstyle)
 
int W_GunAlign (entity this, int preferred_align)
 

Function Documentation

◆ damage_explosion_calcpush()

vector damage_explosion_calcpush ( vector  explosion_f,
vector  target_v,
float  speedfactor 
)

Definition at line 45 of file calculations.qc.

References explosion_calcpush_getmultiplier(), LOG_INFOF, v, and vector().

Referenced by Damage(), and MUTATOR_HOOKFUNCTION().

46 {
47  // if below 1, the formulas make no sense (and would cause superjumps)
48  if(speedfactor < 1)
49  return explosion_f;
50 
51 #if 0
52  float m;
53  // find m so that
54  // speedfactor * (1 + e) * m / (1 + m) == 1
55  m = 1 / ((1 + 0) * speedfactor - 1);
56  vector v;
57  v = explosion_calcpush(explosion_f * speedfactor, m, target_v, 1, 0);
58  // the factor we then get is:
59  // 1
60  LOG_INFOF("MASS: %f\nv: %v -> %v\nENERGY BEFORE == %f + %f = %f\nENERGY AFTER >= %f",
61  m,
62  target_v, target_v + v,
63  target_v * target_v, m * explosion_f * speedfactor * explosion_f * speedfactor, target_v * target_v + m * explosion_f * speedfactor * explosion_f * speedfactor,
64  (target_v + v) * (target_v + v));
65  return v;
66 #endif
67  return explosion_f * explosion_calcpush_getmultiplier(explosion_f * speedfactor, target_v);
68 }
float explosion_calcpush_getmultiplier(vector explosion_v, vector target_v)
Definition: calculations.qc:7
#define LOG_INFOF(...)
Definition: log.qh:71
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:

◆ explosion_calcpush_getmultiplier()

float explosion_calcpush_getmultiplier ( vector  explosion_v,
vector  target_v 
)

Definition at line 7 of file calculations.qc.

References explosion_calcpush_getmultiplier(), and vector().

Referenced by damage_explosion_calcpush(), and explosion_calcpush_getmultiplier().

8 {
9  float a;
10  a = explosion_v * (explosion_v - target_v);
11 
12  if(a <= 0)
13  // target is too fast to be hittable by this
14  return 0;
15 
16  a /= (explosion_v * explosion_v);
17  // we know we can divide by this, or above a would be == 0
18 
19  return a;
20 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ W_CalculateSpread()

vector W_CalculateSpread ( vector  forward,
float  spread,
float  spreadfactor,
float  spreadstyle 
)

Definition at line 187 of file calculations.qc.

References cliptoplane(), cos(), cross, error(), findperpendicular(), gsl_ran_gaussian(), M_PI, normalize(), random(), randomvec(), sin(), solve_cubic_abcd(), sqrt(), and vector().

Referenced by W_SetupProjVelocity_Explicit().

188 {
189  float sigma;
190  vector v1 = '0 0 0', v2;
191  float dx, dy, r;
192  spread *= spreadfactor; //autocvar_g_weaponspreadfactor;
193  if(spread <= 0)
194  return forward;
195 
196  switch(spreadstyle)
197  {
198  case 0:
199  {
200  // this is the baseline for the spread value!
201  // standard deviation: sqrt(2/5)
202  // density function: sqrt(1-r^2)
203  return forward + randomvec() * spread;
204  }
205  case 1:
206  {
207  // same thing, basically
208  return normalize(forward + cliptoplane(randomvec() * spread, forward));
209  }
210  case 2:
211  {
212  // circle spread... has at sigma=1 a standard deviation of sqrt(1/2)
213  sigma = spread * 0.89442719099991587855; // match baseline stddev
214  v1 = findperpendicular(forward);
215  v2 = cross(forward, v1);
216  // random point on unit circle
217  dx = random() * 2 * M_PI;
218  dy = sin(dx);
219  dx = cos(dx);
220  // radius in our dist function
221  r = random();
222  r = sqrt(r);
223  return normalize(forward + (v1 * dx + v2 * dy) * r * sigma);
224  }
225  case 3: // gauss 3d
226  {
227  sigma = spread * 0.44721359549996; // match baseline stddev
228  // note: 2D gaussian has sqrt(2) times the stddev of 1D, so this factor is right
229  v1 = forward;
230  v1_x += gsl_ran_gaussian(sigma);
231  v1_y += gsl_ran_gaussian(sigma);
232  v1_z += gsl_ran_gaussian(sigma);
233  return v1;
234  }
235  case 4: // gauss 2d
236  {
237  sigma = spread * 0.44721359549996; // match baseline stddev
238  // note: 2D gaussian has sqrt(2) times the stddev of 1D, so this factor is right
239  v1_x = gsl_ran_gaussian(sigma);
240  v1_y = gsl_ran_gaussian(sigma);
241  v1_z = gsl_ran_gaussian(sigma);
242  return normalize(forward + cliptoplane(v1, forward));
243  }
244  case 5: // 1-r
245  {
246  sigma = spread * 1.154700538379252; // match baseline stddev
247  v1 = findperpendicular(forward);
248  v2 = cross(forward, v1);
249  // random point on unit circle
250  dx = random() * 2 * M_PI;
251  dy = sin(dx);
252  dx = cos(dx);
253  // radius in our dist function
254  r = random();
255  r = solve_cubic_abcd(-2, 3, 0, -r) * '0 1 0';
256  return normalize(forward + (v1 * dx + v2 * dy) * r * sigma);
257  }
258  case 6: // 1-r^2
259  {
260  sigma = spread * 1.095445115010332; // match baseline stddev
261  v1 = findperpendicular(forward);
262  v2 = cross(forward, v1);
263  // random point on unit circle
264  dx = random() * 2 * M_PI;
265  dy = sin(dx);
266  dx = cos(dx);
267  // radius in our dist function
268  r = random();
269  r = sqrt(1 - r);
270  r = sqrt(1 - r);
271  return normalize(forward + (v1 * dx + v2 * dy) * r * sigma);
272  }
273  case 7: // (1-r) (2-r)
274  {
275  sigma = spread * 1.224744871391589; // match baseline stddev
276  v1 = findperpendicular(forward);
277  v2 = cross(forward, v1);
278  // random point on unit circle
279  dx = random() * 2 * M_PI;
280  dy = sin(dx);
281  dx = cos(dx);
282  // radius in our dist function
283  r = random();
284  r = 1 - sqrt(r);
285  r = 1 - sqrt(r);
286  return normalize(forward + (v1 * dx + v2 * dy) * r * sigma);
287  }
288  default:
289  error("g_projectiles_spread_style must be 0 (sphere), 1 (flattened sphere), 2 (circle), 3 (gauss 3D), 4 (gauss plane), 5 (linear falloff), 6 (quadratic falloff), 7 (stronger falloff)!");
290  }
291 
292  return '0 0 0';
293  /*
294  * how to derive falloff functions:
295  * rho(r) := (2-r) * (1-r);
296  * a : 0;
297  * b : 1;
298  * rhor(r) := r * rho(r);
299  * cr(t) := integrate(rhor(r), r, a, t);
300  * scr(t) := integrate(rhor(r) * r^2, r, a, t);
301  * variance : scr(b) / cr(b);
302  * solve(cr(r) = rand * cr(b), r), programmmode:false;
303  * sqrt(0.4 / variance), numer;
304  */
305 }
ERASEABLE float gsl_ran_gaussian(float sigma)
Definition: random.qc:79
vector cliptoplane(vector v, vector p)
Definition: calculations.qc:75
vector findperpendicular(vector v)
vector solve_cubic_abcd(float a, float b, float c, float d)
vector(float skel, float bonenum) _skel_get_boneabs_hidden
const float M_PI
Definition: csprogsdefs.qc:269
#define cross(a, b)
Definition: vector.qh:25
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ W_GunAlign()

int W_GunAlign ( entity  this,
int  preferred_align 
)

Definition at line 169 of file calculations.qc.

References entity().

Referenced by findperpendicular(), FireGrapplingHook(), GrapplingHookThink(), W_Model(), and W_ResetGunAlign().

170  {
171  return this.m_gunalign > 0 ? this.m_gunalign : preferred_align;
172  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function: