Each module now includes its own header first. Removed sstream.h and the definition...
[crack-attack.git] / src / Random.cxx
blob796649e0bd94576ef4c0a3a1af752bcaa0caa7d6
1 /*
2 * Random.cxx
3 * Daniel Nelson - 11/10/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
25 * Handles all the random number tables.
28 #include "Random.h"
30 #include <ctime>
31 #include <cmath>
33 #include "Game.h"
36 Angle Random::angle_table[GC_SIZE_RANDOM_ANGLE_TABLE];
37 Angle Random::angle_death_spark_table[GC_SIZE_RANDOM_ANGLE_TABLE];
38 Angle Random::angle_celebration_spark_1_table[GC_SIZE_RANDOM_ANGLE_TABLE];
39 Angle Random::angle_celebration_spark_2_table[GC_SIZE_RANDOM_ANGLE_TABLE];
41 void Random::seed ( unsigned int seed )
43 * Called by Communicator to seed the random numbers.
46 srand(seed);
49 unsigned int Random::generateSeed ( )
51 * Called by Communicator if we're the server. The result is used to seed our
52 * random numbers as well as sent to the client for theirs.
55 return (unsigned int) time(null);
58 void Random::initialize ( )
60 * Attack calls seed() before this.
63 for (int n = GC_SIZE_RANDOM_ANGLE_TABLE; n--; ) {
64 float angle = (2.0f * PI) * Random::number();
65 angle_table[n].x = cos(angle);
66 angle_table[n].y = sin(angle);
69 for (int n = GC_SIZE_RANDOM_ANGLE_TABLE; n--; ) {
70 float angle = (PI / 4.0f) + (PI / 2.0f) * Random::number();
71 angle_death_spark_table[n].x = cos(angle);
72 angle_death_spark_table[n].y = sin(angle);
75 for (int n = GC_SIZE_RANDOM_ANGLE_TABLE; n--; ) {
76 float angle = (3.0f * PI / 16.0f) + (PI / 8.0f) * Random::number();
77 angle_celebration_spark_1_table[n].x = cos(angle);
78 angle_celebration_spark_1_table[n].y = sin(angle);
81 for (int n = GC_SIZE_RANDOM_ANGLE_TABLE; n--; ) {
82 float angle = (7.0f * PI / 16.0f) + (PI / 8.0f) * Random::number();
83 angle_celebration_spark_2_table[n].x = cos(angle);
84 angle_celebration_spark_2_table[n].y = sin(angle);