Fixes for datatype size on amd64.
[crack-attack.git] / src / BlockManager.cxx
blob01fb4fb8742d7935da966adc5cd62aef0111841b
1 /*
2 * BlockManager.cxx
3 * Daniel Nelson - 8/24/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 * Allocates and frees blocks.
28 #include "BlockManager.h"
30 #include "Game.h"
31 #include "ComboTabulator.h"
32 #include "Random.h"
33 #include "X.h"
35 int BlockManager::block_count;
36 Block BlockManager::blockStore[GC_BLOCK_STORE_SIZE];
37 bool BlockManager::storeMap[GC_BLOCK_STORE_SIZE];
39 int BlockManager::last_flavor_a, BlockManager::second_to_last_flavor_a;
40 int BlockManager::last_flavor_c, BlockManager::second_to_last_flavor_c;
41 int BlockManager::last_row_a[GC_PLAY_WIDTH];
42 int BlockManager::second_to_last_row_a[GC_PLAY_WIDTH];
43 int BlockManager::last_row_c[GC_PLAY_WIDTH];
44 int BlockManager::second_to_last_row_c[GC_PLAY_WIDTH];
45 int BlockManager::special_block_location;
47 int BlockManager::next_pop_direction;
49 void BlockManager::gameStart ( )
51 block_count = 0;
52 for (int n = GC_BLOCK_STORE_SIZE; n--; ) {
53 storeMap[n] = false;
54 blockStore[n].id = n;
57 last_flavor_a = second_to_last_flavor_a = 0;
58 last_flavor_c = second_to_last_flavor_c = 0;
59 for (int x = GC_PLAY_WIDTH; x--; ) {
60 last_row_a[x] = 0;
61 second_to_last_row_a[x] = 0;
62 last_row_c[x] = 0;
63 second_to_last_row_c[x] = 0;
66 next_pop_direction = (1 << 0);
68 special_block_location = -1;
71 void BlockManager::newAwakingBlock ( int x, int y, int pop_delay,
72 int awake_delay, ComboTabulator *combo, int pop_color )
74 int flavor;
76 do {
77 flavor = Random::number(BF_NUMBER_NORMAL);
78 } while ((flavor == last_flavor_a
79 && last_flavor_a == second_to_last_flavor_a)
80 || (flavor == last_row_a[x] && last_row_a[x] == second_to_last_row_a[x]));
82 second_to_last_row_a[x] = last_row_a[x];
83 last_row_a[x] = flavor;
85 second_to_last_flavor_a = last_flavor_a;
86 last_flavor_a = flavor;
88 newBlock(x, y, flavor, pop_delay, awake_delay, combo, pop_color);
91 void BlockManager::newCreepBlock ( int x )
93 int flavor = 0;
95 if (x != special_block_location) {
97 flavor = Random::number(BF_NUMBER_NORMAL);
98 while ((flavor == last_flavor_c && last_flavor_c
99 == second_to_last_flavor_c) || (flavor == last_row_c[x] && last_row_c[x]
100 == second_to_last_row_c[x]));
102 second_to_last_row_c[x] = last_row_c[x];
103 last_row_c[x] = flavor;
105 second_to_last_flavor_c = last_flavor_c;
106 last_flavor_c = flavor;
108 } else {
109 int base_flavor = 0;
111 if (!(MetaState::mode & CM_X)) {
112 if ((BF_GRAY == last_flavor_c && last_flavor_c
113 == second_to_last_flavor_c) || (BF_GRAY == last_row_c[x]
114 && last_row_c[x] == second_to_last_row_c[x]))
116 flavor = Random::number(BF_NUMBER_NORMAL);
117 while ((flavor == last_flavor_c && last_flavor_c
118 == second_to_last_flavor_c) || (flavor == last_row_c[x]
119 && last_row_c[x] == second_to_last_row_c[x]));
120 else
121 flavor = BF_GRAY;
122 base_flavor = flavor;
124 } else {
125 do {
126 switch (Random::number(10)) {
127 case 0: case 1: case 2:
128 base_flavor = flavor = BF_GRAY;
129 break;
130 case 3: case 4: case 5: case 6:
131 base_flavor = mapSpecialColorFlavorToColor(flavor
132 = Random::number(BF_NUMBER_NORMAL) + BF_SPECIAL_COLOR_1);
133 if (!X::specialColorAllowed())
134 flavor = base_flavor;
135 break;
136 case 7: case 8:
137 if (X::wildAllowed())
138 base_flavor = flavor = BF_WILD;
139 else
140 base_flavor = flavor = BF_GRAY;
141 break;
142 case 9:
143 if (Random::chanceIn2(2))
144 flavor = BF_BLACK;
145 else
146 flavor = BF_WHITE;
147 base_flavor = mapFlavorToBaseFlavor(flavor);
148 break;
150 } while ((base_flavor == last_flavor_c && last_flavor_c
151 == second_to_last_flavor_c) || (base_flavor == last_row_c[x]
152 && last_row_c[x] == second_to_last_row_c[x]));
155 second_to_last_row_c[x] = last_row_c[x];
156 last_row_c[x] = base_flavor;
158 second_to_last_flavor_c = last_flavor_c;
159 last_flavor_c = base_flavor;
162 newBlock(x, 0, flavor);