Tiberian Technologies Scripts Reference Revision: 9000
Loading...
Searching...
No Matches
Random2Class.h
1/* Renegade Scripts.dll
2 Copyright 2013 Tiberian Technologies
3
4 This file is part of the Renegade scripts.dll
5 The Renegade scripts.dll is free software; you can redistribute it and/or modify it under
6 the terms of the GNU General Public License as published by the Free
7 Software Foundation; either version 2, or (at your option) any later
8 version. See the file COPYING for more details.
9 In addition, an exemption is given to allow Run Time Dynamic Linking of this code with any closed source module that does not contain code covered by this licence.
10 Only the source code to the module(s) containing the licenced code has to be released.
11*/
12#ifndef TT_INCLUDE__RANDOM2CLASS_H
13#define TT_INCLUDE__RANDOM2CLASS_H
14#define ARRAY_SIZE(x) int(sizeof(x)/sizeof(x[0]))
15class Random2Class
16{
17public:
18 Random2Class(unsigned seed = 0);
19 operator int(void)
20 {
21 return(operator()());
22 }
23 int operator() (void);
24 int operator() (int minval, int maxval);
25 enum
26 {
27 SIGNIFICANT_BITS=32
28 };
29protected:
30 int Index1;
31 int Index2;
32 int Table[250];
33}; // 03F0
34
35#define CRANDOM_FLOAT_RANGE 0x1000
36class CRandom {
37public:
38 CRandom( void )
39 {
40 }
41 ~CRandom( void )
42 {
43 }
44 inline int Get_Int( void )
45 {
46 return Generator();
47 }
48 inline int Get_Int( int max )
49 {
50 if (max)
51 {
52 return (Generator() & 0x7FFFFFFF) % max;
53 }
54 return 0;
55 }
56 inline int Get_Int( int min, int max )
57 {
58 if ( min > max )
59 {
60 int temp = min;
61 min = max;
62 max = temp;
63 }
64 return Get_Int( max - min ) + min;
65 }
66 inline float Get_Float( void )
67 {
68 return (float)(Get_Int( CRANDOM_FLOAT_RANGE+1 )) / (float)CRANDOM_FLOAT_RANGE;
69 }
70 inline float Get_Float( float max )
71 {
72 return Get_Float() * max;
73 }
74 inline float Get_Float( float min, float max )
75 {
76 if ( min > max )
77 {
78 float temp = min;
79 min = max;
80 max = temp;
81 }
82 return Get_Float() * ( max - min ) + min;
83 }
84private:
85 Random2Class Generator;
86};
87class Random4Class
88{
89 public:
90 Random4Class(unsigned int seed=4357);
91 operator int(void)
92 {
93 return(operator()());
94 }
95 int operator() (void);
96 int operator() (int minval, int maxval);
97 float Get_Float();
98 enum {
99 SIGNIFICANT_BITS=32
100 };
101protected:
102 unsigned int mt[624];
103 int mti;
104};
105#ifndef TTLE_EXPORTS
106#ifndef TDBEDIT
107#ifndef W3DVIEWER
108extern REF_DECL(CRandom, FreeRandom);
109#endif
110#endif
111#endif
112#endif