Fixes for datatype size on amd64.
[crack-attack.git] / src / X.cxx
blob5fe9f3d84e2183da3a4f9e9831f5209d8e1b23cc
1 /*
2 * X.cxx
3 * Daniel Nelson - 11/11/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 * Holds the X-treme state.
28 #include "X.h"
30 #include "Game.h"
31 #include "Grid.h"
32 #include "Block.h"
33 #include "Swapper.h"
35 int X::reverse_controls;
36 int X::invisible_swapper;
37 int X::crazy_lights;
38 int X::swapper_alpha;
39 int X::light_mode;
40 int X::light_alarm;
41 int X::wild_count;
42 Wild X::wilds[GC_MAX_WILD_NUMBER];
43 int X::special_color_count;
45 const GLfloat X::light_level_map[6][3]
46 = { { 0.0f, 1.0f, 1.0f },
47 { 0.5f, 0.5f, 1.0f },
48 { 1.0f, 0.0f, 1.0f },
49 { 1.0f, 0.5f, 0.5f },
50 { 1.0f, 1.0f, 0.0f },
51 { 0.5f, 1.0f, 0.5f } };
53 void X::gameStart ( )
55 reverse_controls = 0;
57 invisible_swapper = 0;
58 swapper_alpha = GC_INVISIBLE_MAX_ALPHA;
60 crazy_lights = 0;
61 light_mode = -1;
63 wild_count = 0;
64 for (int n = GC_MAX_WILD_NUMBER; n--; )
65 wilds[n].active = false;
67 special_color_count = 0;
70 void X::timeStep ( )
72 // evolve the swapper's invisibleness
73 if (invisible_swapper != 0 || swapper_alpha != GC_INVISIBLE_MAX_ALPHA)
74 if (invisible_swapper != 0) {
76 // drop the swapper's alpha
77 if (swapper_alpha > 0)
78 swapper_alpha -= GC_INVISIBLE_QUICK_DECAY_RATE;
79 else if (swapper_alpha > GC_INVISIBLE_MIN_ALPHA)
80 swapper_alpha--;
82 // there is a chance the swapper's alpha will spike upward
83 if (Random::chanceIn(GC_INVISIBLE_PULSE_CHANCE_IN)) {
84 swapper_alpha += GC_INVISIBLE_PULSE_STRENGTH;
85 if (swapper_alpha > GC_INVISIBLE_MAX_ALPHA)
86 swapper_alpha = GC_INVISIBLE_MAX_ALPHA;
89 // raise the swapper's alpha back to normal
90 } else
91 swapper_alpha++;
93 // evolve the wild blocks' state
94 if (wild_count != 0) {
95 int c = wild_count;
96 for (int n = 0; c; n++)
97 if (wilds[n].active) {
98 c--;
99 if (!--wilds[n].alarm) {
101 // switch flavors
102 wilds[n].alarm = GC_WILD_PERIOD;
103 if (wilds[n].flavor == 0)
104 wilds[n].flavor = BF_WILD;
105 else {
106 wilds[n].flavor--;
107 if (wilds[n].block->y != 0)
108 Grid::requestEliminationCheck(*wilds[n].block);
114 // evolve the crazy lights
115 if (crazy_lights != 0 || light_mode != -1) {
117 // switch light colors
118 if (!--light_alarm) {
120 // if craziness continues
121 if (crazy_lights != 0) {
122 if (light_mode != 11)
123 light_mode++;
124 else
125 light_mode = 0;
127 // odd modes - non-white modes - are longer
128 if (light_mode & (1 << 0))
129 light_alarm = GC_CRAZY_LONG_MODE_PERIOD;
130 else
131 light_alarm = GC_CRAZY_SHORT_MODE_PERIOD;
133 // end craziness
134 } else
135 light_mode = -1;
140 void X::notifyImpact ( Garbage &garbage )
142 * Garbage has impacted. We must check to see if it's flavor has a special
143 * effect.
146 // controls are reversed
147 if (garbage.flavor == GF_REVERSE_CONTROLS) {
148 reverse_controls++;
149 if (invisible_swapper == 0)
150 Swapper::color = 1;
151 else
152 Swapper::color = 3;
154 // swapper becomes invisible
155 } else if (garbage.flavor == GF_INVISIBLE_SWAPPER) {
156 invisible_swapper++;
157 if (reverse_controls == 0)
158 Swapper::color = 2;
159 else
160 Swapper::color = 3;
162 // lights go crazy
163 } else if (garbage.flavor == GF_CRAZY_LIGHTS) {
164 crazy_lights++;
165 if (light_mode == -1) {
166 light_mode = (Random::number(6) << 1) + 1;
167 light_alarm = 150;
172 void X::notifyShatter ( Garbage &garbage )
174 * Garbage has shattered. We must check to see if this effects the special
175 * effects which are occuring.
178 if (garbage.flavor == GF_REVERSE_CONTROLS) {
179 reverse_controls--;
180 if (reverse_controls == 0)
181 if (invisible_swapper == 0)
182 Swapper::color = 0;
183 else
184 Swapper::color = 2;
186 } else if (garbage.flavor == GF_INVISIBLE_SWAPPER) {
187 invisible_swapper--;
188 if (invisible_swapper == 0)
189 if (reverse_controls == 0)
190 Swapper::color = 0;
191 else
192 Swapper::color = 1;
194 } else if (garbage.flavor == GF_CRAZY_LIGHTS)
195 crazy_lights--;
198 void X::modifyHeadlightColor ( GLfloat headlight_color[3] )
200 * Called by LightManager to allow us the opportunity to modify the headlight
201 * color.
204 assert(crazyLights());
206 GLfloat fade = light_alarm * (2.0f / (float) GC_CRAZY_LONG_MODE_PERIOD);
207 if (fade > 1.0f)
208 fade = -1.0f + fade;
209 else
210 fade = 1.0f - fade;
211 fade *= fade;
213 headlight_color[0] = light_level_map[light_mode >> 1][0]
214 + fade * (1.0f - light_level_map[light_mode >> 1][0]);
215 headlight_color[1] = light_level_map[light_mode >> 1][1]
216 + fade * (1.0f - light_level_map[light_mode >> 1][1]);
217 headlight_color[2] = light_level_map[light_mode >> 1][2]
218 + fade * (1.0f - light_level_map[light_mode >> 1][2]);