Didn't set the version as a string
[crack-attack.git] / src / Random.h
blobd01ff64026ddb823e05e5517944af97f51ec0f6a
1 /*
2 * Random.h
3 * Daniel Nelson - 8/24/0
5 * Copyright (C) 2000 Daniel Nelson
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 * Daniel Nelson - aluminumangel.org
22 * 174 W. 18th Ave.
23 * Columbus, OH 43210
26 #ifndef RANDOM_H
27 #define RANDOM_H
29 using namespace std;
31 #include "Game.h"
33 class Angle {
34 public:
35 float x;
36 float y;
39 /* static */ class Random {
40 public:
41 static void seed ( unsigned int seed );
42 static unsigned int generateSeed ( );
43 static void initialize ( );
45 static inline bool chanceIn ( int chance )
46 { return rand() % chance == 0; }
48 // use then chance is a power of 2
49 static inline bool chanceIn2 ( int chance )
50 { return (rand() & (chance - 1)) == 0; }
52 static inline int number ( int maximum )
53 { return rand() % maximum; }
55 // use then maximum is a power of 2
56 static inline int number2 ( int maximum )
57 { return rand() & (maximum - 1); }
59 static inline float number ( )
60 { return rand() * (1.0 / (float) RAND_MAX); }
62 static inline void angle ( float &x, float &y )
64 int n = number2(GC_SIZE_RANDOM_ANGLE_TABLE);
65 x = angle_table[n].x;
66 y = angle_table[n].y;
69 static inline void deathSparkAngle ( float &x, float &y )
71 int n = number2(GC_SIZE_RANDOM_ANGLE_TABLE);
72 x = angle_death_spark_table[n].x;
73 y = angle_death_spark_table[n].y;
76 static inline void celebrationSpark1Angle ( float &x, float &y )
78 int n = number2(GC_SIZE_RANDOM_ANGLE_TABLE);
79 x = angle_celebration_spark_1_table[n].x;
80 y = angle_celebration_spark_1_table[n].y;
83 static inline void celebrationSpark2Angle ( float &x, float &y )
85 int n = number2(GC_SIZE_RANDOM_ANGLE_TABLE);
86 x = angle_celebration_spark_2_table[n].x;
87 y = angle_celebration_spark_2_table[n].y;
90 private:
91 static Angle angle_table[GC_SIZE_RANDOM_ANGLE_TABLE];
92 static Angle angle_death_spark_table[GC_SIZE_RANDOM_ANGLE_TABLE];
93 static Angle angle_celebration_spark_1_table[GC_SIZE_RANDOM_ANGLE_TABLE];
94 static Angle angle_celebration_spark_2_table[GC_SIZE_RANDOM_ANGLE_TABLE];
97 #endif