Mercurial > mm7
annotate Random.cpp @ 2483:b3f96acf6bab
Fixing arrows not being drawn for 2nd player char
author | Grumpy7 |
---|---|
date | Sat, 06 Sep 2014 20:52:46 +0200 |
parents | f4af3b203f65 |
children |
rev | line source |
---|---|
2415 | 1 #define _CRTDBG_MAP_ALLOC |
2 #include <stdlib.h> | |
3 #include <crtdbg.h> | |
4 | |
2253
aff7a7b072b7
adding _CRT_SECURE_NO_WARNINGS to get rid of a few hundrer annoying warnings + adding count parameter to swprintf
Grumpy7
parents:
2196
diff
changeset
|
5 #define _CRT_SECURE_NO_WARNINGS |
0 | 6 #include <math.h> |
7 | |
8 #include "Random.h" | |
2037
7a9477135943
Renamed Math.h -> OurMath.h (file resolution was sometimes ambiguous)
Nomad
parents:
1262
diff
changeset
|
9 #include "OurMath.h" |
0 | 10 |
11 | |
12 | |
13 | |
780 | 14 struct Random *pRnd=new Random(); // idb |
0 | 15 |
16 | |
17 | |
18 | |
19 | |
20 //----- (004BE59E) -------------------------------------------------------- | |
21 void Random::SetRange(int min, int max) | |
22 { | |
23 this->min = min; | |
24 this->range = max - min; | |
25 } | |
26 | |
27 //----- (004BE5B1) -------------------------------------------------------- | |
28 double Random::GetRandom() | |
29 { | |
30 Random *v1; // esi@1 | |
31 double v2; // st7@1 | |
32 double v3; // st7@1 | |
33 | |
34 v1 = this; | |
35 this->field_0[3] = this->field_0[2]; | |
36 this->field_0[2] = this->field_0[1]; | |
37 v2 = this->field_0[0]; | |
38 this->field_0[1] = v2; | |
39 v3 = this->field_0[3] * 1492.0 | |
40 + this->field_0[2] * 1776.0 | |
41 + this->field_0[3] * 2111111111.0 | |
42 + v2 * 5115.0 | |
43 + this->field_0[4]; | |
44 v1->field_0[0] = v3 - floor(v3); | |
2196 | 45 v1->field_0[4] = floor(v3) * 2.328306436538696e-10; |
46 return v1->field_0[0]; | |
0 | 47 } |
48 | |
49 //----- (004BE623) -------------------------------------------------------- | |
50 int Random::GetInRange() | |
51 { | |
2334 | 52 // Random *v1; // esi@1 |
0 | 53 float v2; // ST10_4@1 |
2334 | 54 // double v3; // ST04_8@1 |
0 | 55 int floored_random; // ecx@1 |
56 | |
57 v2 = GetRandom() * (double)this->range; | |
1262 | 58 floored_random = bankersRounding(v2); |
59 if ( floored_random >= this->range ) | |
60 floored_random = this->range; | |
61 return floored_random + this->min; | |
0 | 62 } |
63 | |
64 //----- (004BE65D) -------------------------------------------------------- | |
65 void Random::Initialize(int seed) | |
66 { | |
67 int v2; // eax@1 | |
68 Random *this_; // esi@1 | |
69 signed int v4; // ecx@3 | |
70 unsigned int v5; // eax@4 | |
71 signed int v6; // edi@5 | |
72 | |
73 v2 = seed; | |
74 this_ = this; | |
75 if ( !seed ) | |
76 v2 = -1; | |
77 v4 = 0; | |
78 do | |
79 { | |
80 v5 = (((v2 << 13) ^ (unsigned int)v2) >> 17) ^ (v2 << 13) ^ v2; | |
81 v2 = 32 * v5 ^ v5; | |
82 this_->field_0[v4++] = (double)(unsigned int)v2 * 2.328306436538696e-10; | |
83 } | |
84 while ( v4 < 5 ); | |
85 v6 = 19; | |
86 do | |
87 { | |
88 GetRandom(); | |
89 --v6; | |
90 } | |
91 while ( v6 ); | |
92 } | |
93 |