Copyright updates. I hope that I didn't miss anybody.
[crack-attack.git] / src / X.cxx
blob5c73ccbd3459c03c1b4cb2e9c63ab1a292a25e82
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 using namespace std;
30 #include "Game.h"
31 #include "Grid.h"
32 #include "Block.h"
33 #include "Swapper.h"
34 #include "X.h"
36 int X::reverse_controls;
37 int X::invisible_swapper;
38 int X::crazy_lights;
39 int X::swapper_alpha;
40 int X::light_mode;
41 int X::light_alarm;
42 int X::wild_count;
43 Wild X::wilds[GC_MAX_WILD_NUMBER];
44 int X::special_color_count;
46 const GLfloat X::light_level_map[6][3]
47 = { { 0.0f, 1.0f, 1.0f },
48 { 0.5f, 0.5f, 1.0f },
49 { 1.0f, 0.0f, 1.0f },
50 { 1.0f, 0.5f, 0.5f },
51 { 1.0f, 1.0f, 0.0f },
52 { 0.5f, 1.0f, 0.5f } };
54 void X::gameStart ( )
56 reverse_controls = 0;
58 invisible_swapper = 0;
59 swapper_alpha = GC_INVISIBLE_MAX_ALPHA;
61 crazy_lights = 0;
62 light_mode = -1;
64 wild_count = 0;
65 for (int n = GC_MAX_WILD_NUMBER; n--; )
66 wilds[n].active = false;
68 special_color_count = 0;
71 void X::timeStep ( )
73 // evolve the swapper's invisibleness
74 if (invisible_swapper != 0 || swapper_alpha != GC_INVISIBLE_MAX_ALPHA)
75 if (invisible_swapper != 0) {
77 // drop the swapper's alpha
78 if (swapper_alpha > 0)
79 swapper_alpha -= GC_INVISIBLE_QUICK_DECAY_RATE;
80 else if (swapper_alpha > GC_INVISIBLE_MIN_ALPHA)
81 swapper_alpha--;
83 // there is a chance the swapper's alpha will spike upward
84 if (Random::chanceIn(GC_INVISIBLE_PULSE_CHANCE_IN)) {
85 swapper_alpha += GC_INVISIBLE_PULSE_STRENGTH;
86 if (swapper_alpha > GC_INVISIBLE_MAX_ALPHA)
87 swapper_alpha = GC_INVISIBLE_MAX_ALPHA;
90 // raise the swapper's alpha back to normal
91 } else
92 swapper_alpha++;
94 // evolve the wild blocks' state
95 if (wild_count != 0) {
96 int c = wild_count;
97 for (int n = 0; c; n++)
98 if (wilds[n].active) {
99 c--;
100 if (!--wilds[n].alarm) {
102 // switch flavors
103 wilds[n].alarm = GC_WILD_PERIOD;
104 if (wilds[n].flavor == 0)
105 wilds[n].flavor = BF_WILD;
106 else {
107 wilds[n].flavor--;
108 if (wilds[n].block->y != 0)
109 Grid::requestEliminationCheck(*wilds[n].block);
115 // evolve the crazy lights
116 if (crazy_lights != 0 || light_mode != -1) {
118 // switch light colors
119 if (!--light_alarm) {
121 // if craziness continues
122 if (crazy_lights != 0) {
123 if (light_mode != 11)
124 light_mode++;
125 else
126 light_mode = 0;
128 // odd modes - non-white modes - are longer
129 if (light_mode & (1 << 0))
130 light_alarm = GC_CRAZY_LONG_MODE_PERIOD;
131 else
132 light_alarm = GC_CRAZY_SHORT_MODE_PERIOD;
134 // end craziness
135 } else
136 light_mode = -1;
141 void X::notifyImpact ( Garbage &garbage )
143 * Garbage has impacted. We must check to see if it's flavor has a special
144 * effect.
147 // controls are reversed
148 if (garbage.flavor == GF_REVERSE_CONTROLS) {
149 reverse_controls++;
150 if (invisible_swapper == 0)
151 Swapper::color = 1;
152 else
153 Swapper::color = 3;
155 // swapper becomes invisible
156 } else if (garbage.flavor == GF_INVISIBLE_SWAPPER) {
157 invisible_swapper++;
158 if (reverse_controls == 0)
159 Swapper::color = 2;
160 else
161 Swapper::color = 3;
163 // lights go crazy
164 } else if (garbage.flavor == GF_CRAZY_LIGHTS) {
165 crazy_lights++;
166 if (light_mode == -1) {
167 light_mode = (Random::number(6) << 1) + 1;
168 light_alarm = 150;
173 void X::notifyShatter ( Garbage &garbage )
175 * Garbage has shattered. We must check to see if this effects the special
176 * effects which are occuring.
179 if (garbage.flavor == GF_REVERSE_CONTROLS) {
180 reverse_controls--;
181 if (reverse_controls == 0)
182 if (invisible_swapper == 0)
183 Swapper::color = 0;
184 else
185 Swapper::color = 2;
187 } else if (garbage.flavor == GF_INVISIBLE_SWAPPER) {
188 invisible_swapper--;
189 if (invisible_swapper == 0)
190 if (reverse_controls == 0)
191 Swapper::color = 0;
192 else
193 Swapper::color = 1;
195 } else if (garbage.flavor == GF_CRAZY_LIGHTS)
196 crazy_lights--;
199 void X::modifyHeadlightColor ( GLfloat headlight_color[3] )
201 * Called by LightManager to allow us the opportunity to modify the headlight
202 * color.
205 assert(crazyLights());
207 GLfloat fade = light_alarm * (2.0f / (float) GC_CRAZY_LONG_MODE_PERIOD);
208 if (fade > 1.0f)
209 fade = -1.0f + fade;
210 else
211 fade = 1.0f - fade;
212 fade *= fade;
214 headlight_color[0] = light_level_map[light_mode >> 1][0]
215 + fade * (1.0f - light_level_map[light_mode >> 1][0]);
216 headlight_color[1] = light_level_map[light_mode >> 1][1]
217 + fade * (1.0f - light_level_map[light_mode >> 1][1]);
218 headlight_color[2] = light_level_map[light_mode >> 1][2]
219 + fade * (1.0f - light_level_map[light_mode >> 1][2]);