Really low graphics patch thanks to Stephan Beyer
[crack-attack.git] / src / SignManager.cxx
blob1be7c0a6d70a0d88a4b2e0a081d42fa1674c4d93
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 using namespace std;
30 #include "Game.h"
31 #include "SignManager.h"
32 #include "Random.h"
34 int SignManager::sign_count;
35 Sign SignManager::signs[DC_MAX_SIGN_NUMBER];
37 // maximum levels for each sign type
38 const int maximum_levels[3]
39 = { 8, 10, 8 };
41 // which sign texture contains which signs
42 const int texture_mapping[3][11]
43 = { { 0, 0, 0, 0, 0, 0, 1, 1, 1 },
44 { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
45 { 1, 1, 1, 1, 1, 1, 1, 1, 1 } };
47 // where a sign's subtexture is located
48 const GLfloat subtexture_s_mapping[3][11]
49 = { { 0.0f, 0.0f, DC_SIGN_SMALL_SUBTEX_COORD_S, DC_SIGN_SMALL_SUBTEX_COORD_S,
50 2.0f * DC_SIGN_SMALL_SUBTEX_COORD_S, 2.0f * DC_SIGN_SMALL_SUBTEX_COORD_S,
51 0.0f, 0.0f, 0.0f },
52 { 0.0f, 1.0f * DC_SIGN_LARGE_SUBTEX_COORD_S,
53 DC_SIGN_LARGE_SUBTEX_COORD_S, DC_SIGN_LARGE_SUBTEX_COORD_S,
54 DC_SIGN_LARGE_SUBTEX_COORD_S, 2.0f * DC_SIGN_LARGE_SUBTEX_COORD_S,
55 2.0f * DC_SIGN_LARGE_SUBTEX_COORD_S, 2.0f * DC_SIGN_LARGE_SUBTEX_COORD_S,
56 2.0f * DC_SIGN_LARGE_SUBTEX_COORD_S, 3.0f * DC_SIGN_LARGE_SUBTEX_COORD_S,
57 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, 3.0f * DC_SIGN_LARGE_SUBTEX_COORD_S,
62 3.0f * DC_SIGN_LARGE_SUBTEX_COORD_S } };
63 const GLfloat subtexture_t_mapping[3][11]
64 = { { 0.0f, DC_SIGN_SMALL_SUBTEX_COORD_T, 0.0f, DC_SIGN_SMALL_SUBTEX_COORD_T,
65 0.0f, DC_SIGN_SMALL_SUBTEX_COORD_T, 0.0f, DC_SIGN_LARGE_SUBTEX_COORD_T,
66 2.0f * DC_SIGN_LARGE_SUBTEX_COORD_T },
67 { 3.0f * DC_SIGN_LARGE_SUBTEX_COORD_T, 0.0f, DC_SIGN_LARGE_SUBTEX_COORD_T,
68 2.0f * DC_SIGN_LARGE_SUBTEX_COORD_T, 3.0f * DC_SIGN_LARGE_SUBTEX_COORD_T,
69 0.0f, DC_SIGN_LARGE_SUBTEX_COORD_T, 2.0f * DC_SIGN_LARGE_SUBTEX_COORD_T,
70 3.0f * DC_SIGN_LARGE_SUBTEX_COORD_T, 0.0f,
71 DC_SIGN_LARGE_SUBTEX_COORD_T },
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, 2.0f * DC_SIGN_LARGE_SUBTEX_COORD_S,
76 2.0f * DC_SIGN_LARGE_SUBTEX_COORD_S } };
78 void SignManager::initialize ( )
80 sign_count = 0;
81 for (int n = DC_MAX_SIGN_NUMBER; n--; )
82 signs[n].active = false;
85 void SignManager::createSign ( int x, int y, int type, int level )
87 if (sign_count == DC_MAX_SIGN_NUMBER) return;
89 int n;
90 for (n = 0; signs[n].active; n++);
91 Sign &sign = signs[n];
93 if (type == ST_MULTIPLIER) {
94 sign.g_x = x + 1;
95 sign.g_y = y - 1;
96 if (!confirmSignLocation(signs[n]))
97 if (sign.g_x > 1)
98 sign.g_x--;
99 else
100 sign.g_y++;
102 } else {
103 sign.g_x = x;
104 sign.g_y = y;
105 if (!confirmSignLocation(sign))
106 if (sign.g_x < GC_PLAY_WIDTH - 1)
107 sign.g_x++;
108 else
109 sign.g_y++;
112 while (!confirmSignLocation(sign))
113 sign.g_y++;
115 sign.x = sign.g_x * DC_GRID_ELEMENT_LENGTH
116 + (DC_PLAY_OFFSET_X + DC_SIGN_OFFSET_X - DC_SIGN_OFFSET_SPREAD)
117 + (2 * DC_SIGN_OFFSET_SPREAD) * Random::number();
118 sign.y = sign.g_y * DC_GRID_ELEMENT_LENGTH
119 + Displayer::play_offset_y + (DC_SIGN_OFFSET_Y - DC_SIGN_OFFSET_SPREAD)
120 + (2 * DC_SIGN_OFFSET_SPREAD) * Random::number();
122 if (level > maximum_levels[type])
123 level = maximum_levels[type];
125 sign.texture = texture_mapping[type][level];
126 sign.subtexture_s = subtexture_s_mapping[type][level];
127 sign.subtexture_t = subtexture_t_mapping[type][level];
129 if (type != ST_SPECIAL)
130 sign.color = 0;
131 else
132 sign.color = level;
134 sign.life_time = 0;
136 sign_count++;
137 sign.active = true;
140 void SignManager::timeStep_inline_split_ ( )
142 int c = sign_count;
143 for (int n = 0; c; n++)
144 if (signs[n].active) {
145 Sign &sign = signs[n];
146 c--;
148 if (++sign.life_time == DC_SIGN_LIFE_TIME) {
149 sign_count--;
150 sign.active = false;
153 if (sign.life_time < DC_SIGN_ACCELERATION_TIME)
154 sign.y += DC_SIGN_ACCELERATION * sign.life_time;
156 else
157 sign.y += DC_SIGN_TERMINAL_VELOCITY;