World of Might and Magic  0.2.0
Open reimplementation of Might and Magic 6 7 8 game engine
Random.cpp
См. документацию.
1 #include "Engine/Random.h"
2 
3 #include "OurMath.h"
4 
5 struct Random *pRnd = new Random();
6 
7 //----- (004BE59E) --------------------------------------------------------
8 void Random::SetRange(int min, int max) {
9  this->min = min;
10  this->range = max - min;
11 }
12 
13 //----- (004BE5B1) --------------------------------------------------------
15  this->field_0[3] = this->field_0[2];
16  this->field_0[2] = this->field_0[1];
17  this->field_0[1] = this->field_0[0];
18  double v3 = this->field_0[3] * 1492.0 +
19  this->field_0[2] * 1776.0 +
20  this->field_0[3] * 2111111111.0 +
21  this->field_0[0] * 5115.0 +
22  this->field_0[4];
23  this->field_0[0] = v3 - floor(v3);
24  this->field_0[4] = floor(v3) * 2.328306436538696e-10;
25  return this->field_0[0];
26 }
27 
29  float v2 = GetRandom() * (double)this->range;
30  int floored_random = bankersRounding(v2);
31  if (floored_random >= this->range) floored_random = this->range;
32  return floored_random + this->min;
33 }
34 
35 //----- (004BE65D) --------------------------------------------------------
36 void Random::Initialize(int seed) {
37  int v6; // edi@5
38 
39  unsigned int v2 = seed;
40  if (!seed) v2 = -1;
41  for (int i = 0; i < 5; i++) {
42  unsigned int v5 = (((v2 << 13) ^ v2) >> 17) ^ (v2 << 13) ^ v2;
43  v2 = 32 * v5 ^ v5;
44  this->field_0[i] = (double)v2 * 2.328306436538696e-10;
45  }
46 
47  v6 = 19;
48  do {
49  GetRandom();
50  --v6;
51  } while (v6);
52 }
Random::field_0
double field_0[5]
Definition: Random.h:18
pRnd
struct Random * pRnd
Definition: Random.cpp:5
Random::min
int min
Definition: Random.h:19
Random::range
int range
Definition: Random.h:20
Random::Random
Random()
Definition: Random.h:7
Random::GetRandom
double GetRandom()
Definition: Random.cpp:14
bankersRounding
int bankersRounding(const FloatType &value)
Definition: OurMath.h:98
Random::GetInRange
int GetInRange()
Definition: Random.cpp:28
Random
Definition: Random.h:5
Random::Initialize
void Initialize(int seed)
Definition: Random.cpp:36
v2
GLfloat GLfloat GLfloat v2
Definition: SDL_opengl_glext.h:695
v3
GLfloat GLfloat GLfloat GLfloat v3
Definition: SDL_opengl_glext.h:696
Random::SetRange
void SetRange(int min, int max)
Definition: Random.cpp:8
range
GLenum GLint * range
Definition: SDL_opengl_glext.h:1872
OurMath.h
Random.h