Development back on the trunk!
[crack-attack.git] / src / Random.cxx
blob435bc1e1d11a7d648876492e0bb9e485f8ead6b5
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 <ctime>
30 using namespace std;
32 #include "Game.h"
33 #include "Random.h"
35 #include <cmath>
37 Angle Random::angle_table[GC_SIZE_RANDOM_ANGLE_TABLE];
38 Angle Random::angle_death_spark_table[GC_SIZE_RANDOM_ANGLE_TABLE];
39 Angle Random::angle_celebration_spark_1_table[GC_SIZE_RANDOM_ANGLE_TABLE];
40 Angle Random::angle_celebration_spark_2_table[GC_SIZE_RANDOM_ANGLE_TABLE];
42 void Random::seed ( unsigned int seed )
44 * Called by Communicator to seed the random numbers.
47 srand(seed);
50 unsigned int Random::generateSeed ( )
52 * Called by Communicator if we're the server. The result is used to seed our
53 * random numbers as well as sent to the client for theirs.
56 return (unsigned int) time(null);
59 void Random::initialize ( )
61 * Attack calls seed() before this.
64 for (int n = GC_SIZE_RANDOM_ANGLE_TABLE; n--; ) {
65 float angle = (2.0f * PI) * Random::number();
66 angle_table[n].x = cos(angle);
67 angle_table[n].y = sin(angle);
70 for (int n = GC_SIZE_RANDOM_ANGLE_TABLE; n--; ) {
71 float angle = (PI / 4.0f) + (PI / 2.0f) * Random::number();
72 angle_death_spark_table[n].x = cos(angle);
73 angle_death_spark_table[n].y = sin(angle);
76 for (int n = GC_SIZE_RANDOM_ANGLE_TABLE; n--; ) {
77 float angle = (3.0f * PI / 16.0f) + (PI / 8.0f) * Random::number();
78 angle_celebration_spark_1_table[n].x = cos(angle);
79 angle_celebration_spark_1_table[n].y = sin(angle);
82 for (int n = GC_SIZE_RANDOM_ANGLE_TABLE; n--; ) {
83 float angle = (7.0f * PI / 16.0f) + (PI / 8.0f) * Random::number();
84 angle_celebration_spark_2_table[n].x = cos(angle);
85 angle_celebration_spark_2_table[n].y = sin(angle);