Fixes for datatype size on amd64.
[crack-attack.git] / src / SignManager.cxx
blob8ca26ae858c1635f8f484dcad8d16d47e81365df
1 /*
2 * SignManager.cxx
3 * Daniel Nelson - 9/14/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 little reward signs.
28 #include "SignManager.h"
30 #include "Game.h"
31 #include "Random.h"
33 int SignManager::sign_count;
34 Sign SignManager::signs[DC_MAX_SIGN_NUMBER];
36 // maximum levels for each sign type
37 const int maximum_levels[3]
38 = { 8, 10, 8 };
40 // which sign texture contains which signs
41 const int texture_mapping[3][11]
42 = { { 0, 0, 0, 0, 0, 0, 1, 1, 1 },
43 { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
44 { 1, 1, 1, 1, 1, 1, 1, 1, 1 } };
46 // where a sign's subtexture is located
47 const GLfloat subtexture_s_mapping[3][11]
48 = { { 0.0f, 0.0f, DC_SIGN_SMALL_SUBTEX_COORD_S, DC_SIGN_SMALL_SUBTEX_COORD_S,
49 2.0f * DC_SIGN_SMALL_SUBTEX_COORD_S, 2.0f * DC_SIGN_SMALL_SUBTEX_COORD_S,
50 0.0f, 0.0f, 0.0f },
51 { 0.0f, 1.0f * DC_SIGN_LARGE_SUBTEX_COORD_S,
52 DC_SIGN_LARGE_SUBTEX_COORD_S, DC_SIGN_LARGE_SUBTEX_COORD_S,
53 DC_SIGN_LARGE_SUBTEX_COORD_S, 2.0f * DC_SIGN_LARGE_SUBTEX_COORD_S,
54 2.0f * DC_SIGN_LARGE_SUBTEX_COORD_S, 2.0f * DC_SIGN_LARGE_SUBTEX_COORD_S,
55 2.0f * DC_SIGN_LARGE_SUBTEX_COORD_S, 3.0f * DC_SIGN_LARGE_SUBTEX_COORD_S,
56 3.0f * DC_SIGN_LARGE_SUBTEX_COORD_S },
57 { 3.0f * DC_SIGN_LARGE_SUBTEX_COORD_S, 3.0f * DC_SIGN_LARGE_SUBTEX_COORD_S,
58 3.0f * DC_SIGN_LARGE_SUBTEX_COORD_S, 3.0f * DC_SIGN_LARGE_SUBTEX_COORD_S,
59 3.0f * DC_SIGN_LARGE_SUBTEX_COORD_S, 3.0f * DC_SIGN_LARGE_SUBTEX_COORD_S,
60 3.0f * DC_SIGN_LARGE_SUBTEX_COORD_S, 3.0f * DC_SIGN_LARGE_SUBTEX_COORD_S,
61 3.0f * DC_SIGN_LARGE_SUBTEX_COORD_S } };
62 const GLfloat subtexture_t_mapping[3][11]
63 = { { 0.0f, DC_SIGN_SMALL_SUBTEX_COORD_T, 0.0f, DC_SIGN_SMALL_SUBTEX_COORD_T,
64 0.0f, DC_SIGN_SMALL_SUBTEX_COORD_T, 0.0f, DC_SIGN_LARGE_SUBTEX_COORD_T,
65 2.0f * DC_SIGN_LARGE_SUBTEX_COORD_T },
66 { 3.0f * DC_SIGN_LARGE_SUBTEX_COORD_T, 0.0f, DC_SIGN_LARGE_SUBTEX_COORD_T,
67 2.0f * DC_SIGN_LARGE_SUBTEX_COORD_T, 3.0f * DC_SIGN_LARGE_SUBTEX_COORD_T,
68 0.0f, DC_SIGN_LARGE_SUBTEX_COORD_T, 2.0f * DC_SIGN_LARGE_SUBTEX_COORD_T,
69 3.0f * DC_SIGN_LARGE_SUBTEX_COORD_T, 0.0f,
70 DC_SIGN_LARGE_SUBTEX_COORD_T },
71 { 2.0f * DC_SIGN_LARGE_SUBTEX_COORD_S, 2.0f * DC_SIGN_LARGE_SUBTEX_COORD_S,
72 2.0f * DC_SIGN_LARGE_SUBTEX_COORD_S, 2.0f * DC_SIGN_LARGE_SUBTEX_COORD_S,
73 2.0f * DC_SIGN_LARGE_SUBTEX_COORD_S, 2.0f * DC_SIGN_LARGE_SUBTEX_COORD_S,
74 2.0f * DC_SIGN_LARGE_SUBTEX_COORD_S, 2.0f * DC_SIGN_LARGE_SUBTEX_COORD_S,
75 2.0f * DC_SIGN_LARGE_SUBTEX_COORD_S } };
77 void SignManager::initialize ( )
79 sign_count = 0;
80 for (int n = DC_MAX_SIGN_NUMBER; n--; )
81 signs[n].active = false;
84 void SignManager::createSign ( int x, int y, int type, int level )
86 if (sign_count == DC_MAX_SIGN_NUMBER) return;
88 int n;
89 for (n = 0; signs[n].active; n++);
90 Sign &sign = signs[n];
92 if (type == ST_MULTIPLIER) {
93 sign.g_x = x + 1;
94 sign.g_y = y - 1;
95 if (!confirmSignLocation(signs[n]))
96 if (sign.g_x > 1)
97 sign.g_x--;
98 else
99 sign.g_y++;
101 } else {
102 sign.g_x = x;
103 sign.g_y = y;
104 if (!confirmSignLocation(sign))
105 if (sign.g_x < GC_PLAY_WIDTH - 1)
106 sign.g_x++;
107 else
108 sign.g_y++;
111 while (!confirmSignLocation(sign))
112 sign.g_y++;
114 sign.x = sign.g_x * DC_GRID_ELEMENT_LENGTH
115 + (DC_PLAY_OFFSET_X + DC_SIGN_OFFSET_X - DC_SIGN_OFFSET_SPREAD)
116 + (2 * DC_SIGN_OFFSET_SPREAD) * Random::number();
117 sign.y = sign.g_y * DC_GRID_ELEMENT_LENGTH
118 + Displayer::play_offset_y + (DC_SIGN_OFFSET_Y - DC_SIGN_OFFSET_SPREAD)
119 + (2 * DC_SIGN_OFFSET_SPREAD) * Random::number();
121 if (level > maximum_levels[type])
122 level = maximum_levels[type];
124 sign.texture = texture_mapping[type][level];
125 sign.subtexture_s = subtexture_s_mapping[type][level];
126 sign.subtexture_t = subtexture_t_mapping[type][level];
128 if (type != ST_SPECIAL)
129 sign.color = 0;
130 else
131 sign.color = level;
133 sign.life_time = 0;
135 sign_count++;
136 sign.active = true;
139 void SignManager::timeStep_inline_split_ ( )
141 int c = sign_count;
142 for (int n = 0; c; n++)
143 if (signs[n].active) {
144 Sign &sign = signs[n];
145 c--;
147 if (++sign.life_time == DC_SIGN_LIFE_TIME) {
148 sign_count--;
149 sign.active = false;
152 if (sign.life_time < DC_SIGN_ACCELERATION_TIME)
153 sign.y += DC_SIGN_ACCELERATION * sign.life_time;
155 else
156 sign.y += DC_SIGN_TERMINAL_VELOCITY;