Richard Boegli's CnC_Generals_Zero_Hour Fork
WIP
This is documentation of Richard Boegil's Zero Hour Fork
Loading...
Searching...
No Matches
crandom.h
Go to the documentation of this file.
1
/*
2
** Command & Conquer Generals Zero Hour(tm)
3
** Copyright 2025 Electronic Arts Inc.
4
**
5
** This program is free software: you can redistribute it and/or modify
6
** it under the terms of the GNU General Public License as published by
7
** the Free Software Foundation, either version 3 of the License, or
8
** (at your option) any later version.
9
**
10
** This program is distributed in the hope that it will be useful,
11
** but WITHOUT ANY WARRANTY; without even the implied warranty of
12
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
** GNU General Public License for more details.
14
**
15
** You should have received a copy of the GNU General Public License
16
** along with this program. If not, see <http://www.gnu.org/licenses/>.
17
*/
18
19
/***********************************************************************************************
20
*** Confidential - Westwood Studios ***
21
***********************************************************************************************
22
* *
23
* Project Name : Commando *
24
* *
25
* $Archive:: /Commando/Code/Combat/crandom.h $*
26
* *
27
* $Author:: Byon_g $*
28
* *
29
* $Modtime:: 5/09/01 3:48p $*
30
* *
31
* $Revision:: 2 $*
32
* *
33
*---------------------------------------------------------------------------------------------*
34
* Functions: *
35
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
36
37
#ifndef CRANDOM_H
38
#define CRANDOM_H
39
40
#ifndef ALWAYS_H
41
#include "
always.h
"
42
#endif
43
44
#ifndef RANDOM_H
45
#include "
random.h
"
46
#endif
47
48
#ifndef WWDEBUG_H
49
#include "
wwdebug.h
"
50
#endif
51
52
#define CRANDOM_FLOAT_RANGE 0x1000
53
54
/*
55
** Commando Random Numbers Manager
56
*/
57
class
CRandom
{
58
59
public
:
60
CRandom
(
void
) {}
61
~CRandom
(
void
) {}
62
63
// Get a random 32 bit long integer
64
inline
int
Get_Int
(
void
) {
return
Generator(); }
65
66
// Get a random 32 bit long integer less than max
67
inline
int
Get_Int
(
int
max
) {
WWASSERT
(
max
> 0 );
return
(Generator() & 0x7FFFFFFF) %
max
; }
68
69
// Get a random 32 bit long between min and max (both inclusive)
70
inline
int
Get_Int
(
int
min
,
int
max
);
71
72
// Get a random float between 0 and 1 (both inclusive)
73
inline
float
Get_Float
(
void
) {
return
(
float
)(
Get_Int
(
CRANDOM_FLOAT_RANGE
+1 )) / (
float
)
CRANDOM_FLOAT_RANGE
; }
74
75
// Get a random float between 0 and max (both inclusive)
76
inline
float
Get_Float
(
float
max
) {
return
Get_Float
() *
max
; }
77
78
// Get a random float between min and max (both inclusive)
79
inline
float
Get_Float
(
float
min
,
float
max
);
80
81
private
:
82
Random2Class
Generator;
83
};
84
85
86
// Get a random 32 bit long between min and max (both inclusive)
87
inline
int
CRandom::Get_Int
(
int
min
,
int
max
)
88
{
89
// make sure we have a valid range
90
if
(
min
>
max
) {
91
int
temp =
min
;
92
min
=
max
;
93
max
= temp;
94
}
95
96
// Get one
97
return
Get_Int
(
max
-
min
) +
min
;
98
}
99
100
101
// Get a random float between min and max (both inclusive)
102
inline
float
CRandom::Get_Float
(
float
min
,
float
max
)
103
{
104
// make sure we have a valid range
105
if
(
min
>
max
) {
106
float
temp =
min
;
107
min
=
max
;
108
max
= temp;
109
}
110
111
// Get one
112
return
Get_Float
() * (
max
-
min
) +
min
;
113
}
114
115
116
117
/*
118
** A free random number generator. This can be used for any numbers not required to
119
** be synced between other computers. Good for simple visual and sound effects.
120
*/
121
extern
CRandom
FreeRandom
;
122
123
#endif
min
#define min(x, y)
Definition
BaseType.h:101
max
#define max(x, y)
Definition
BaseType.h:105
WWASSERT
#define WWASSERT
Definition
aabtreebuilder.cpp:68
always.h
RANDOM.H
CRandom
Definition
crandom.h:57
CRandom::Get_Int
int Get_Int(void)
Definition
crandom.h:64
CRandom::Get_Int
int Get_Int(int max)
Definition
crandom.h:67
CRandom::Get_Float
float Get_Float(void)
Definition
crandom.h:73
CRandom::CRandom
CRandom(void)
Definition
crandom.h:60
CRandom::~CRandom
~CRandom(void)
Definition
crandom.h:61
CRandom::Get_Float
float Get_Float(float max)
Definition
crandom.h:76
Random2Class
Definition
RANDOM.H:99
FreeRandom
CRandom FreeRandom
CRANDOM_FLOAT_RANGE
#define CRANDOM_FLOAT_RANGE
Definition
crandom.h:52
wwdebug.h
Code
Libraries
Source
WWVegas
WWLib
crandom.h
Generated by
1.13.2