3 * Daniel Nelson - 8/24/0
5 * Copyright (C) 2000 Daniel Nelson
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
25 * Allocates and frees blocks.
31 #include "BlockManager.h"
32 #include "ComboTabulator.h"
36 int BlockManager::block_count
;
37 Block
BlockManager::blockStore
[GC_BLOCK_STORE_SIZE
];
38 bool BlockManager::storeMap
[GC_BLOCK_STORE_SIZE
];
40 int BlockManager::last_flavor_a
, BlockManager::second_to_last_flavor_a
;
41 int BlockManager::last_flavor_c
, BlockManager::second_to_last_flavor_c
;
42 int BlockManager::last_row_a
[GC_PLAY_WIDTH
];
43 int BlockManager::second_to_last_row_a
[GC_PLAY_WIDTH
];
44 int BlockManager::last_row_c
[GC_PLAY_WIDTH
];
45 int BlockManager::second_to_last_row_c
[GC_PLAY_WIDTH
];
46 int BlockManager::special_block_location
;
48 int BlockManager::next_pop_direction
;
50 void BlockManager::gameStart ( )
53 for (int n
= GC_BLOCK_STORE_SIZE
; n
--; ) {
58 last_flavor_a
= second_to_last_flavor_a
= 0;
59 last_flavor_c
= second_to_last_flavor_c
= 0;
60 for (int x
= GC_PLAY_WIDTH
; x
--; ) {
62 second_to_last_row_a
[x
] = 0;
64 second_to_last_row_c
[x
] = 0;
67 next_pop_direction
= (1 << 0);
69 special_block_location
= -1;
72 void BlockManager::newAwakingBlock ( int x
, int y
, int pop_delay
,
73 int awake_delay
, ComboTabulator
*combo
, int pop_color
)
78 flavor
= Random::number(BF_NUMBER_NORMAL
);
79 } while ((flavor
== last_flavor_a
80 && last_flavor_a
== second_to_last_flavor_a
)
81 || (flavor
== last_row_a
[x
] && last_row_a
[x
] == second_to_last_row_a
[x
]));
83 second_to_last_row_a
[x
] = last_row_a
[x
];
84 last_row_a
[x
] = flavor
;
86 second_to_last_flavor_a
= last_flavor_a
;
87 last_flavor_a
= flavor
;
89 newBlock(x
, y
, flavor
, pop_delay
, awake_delay
, combo
, pop_color
);
92 void BlockManager::newCreepBlock ( int x
)
96 if (x
!= special_block_location
) {
98 flavor
= Random::number(BF_NUMBER_NORMAL
);
99 while ((flavor
== last_flavor_c
&& last_flavor_c
100 == second_to_last_flavor_c
) || (flavor
== last_row_c
[x
] && last_row_c
[x
]
101 == second_to_last_row_c
[x
]));
103 second_to_last_row_c
[x
] = last_row_c
[x
];
104 last_row_c
[x
] = flavor
;
106 second_to_last_flavor_c
= last_flavor_c
;
107 last_flavor_c
= flavor
;
112 if (!(MetaState::mode
& CM_X
)) {
113 if ((BF_GRAY
== last_flavor_c
&& last_flavor_c
114 == second_to_last_flavor_c
) || (BF_GRAY
== last_row_c
[x
]
115 && last_row_c
[x
] == second_to_last_row_c
[x
]))
117 flavor
= Random::number(BF_NUMBER_NORMAL
);
118 while ((flavor
== last_flavor_c
&& last_flavor_c
119 == second_to_last_flavor_c
) || (flavor
== last_row_c
[x
]
120 && last_row_c
[x
] == second_to_last_row_c
[x
]));
123 base_flavor
= flavor
;
127 switch (Random::number(10)) {
128 case 0: case 1: case 2:
129 base_flavor
= flavor
= BF_GRAY
;
131 case 3: case 4: case 5: case 6:
132 base_flavor
= mapSpecialColorFlavorToColor(flavor
133 = Random::number(BF_NUMBER_NORMAL
) + BF_SPECIAL_COLOR_1
);
134 if (!X::specialColorAllowed())
135 flavor
= base_flavor
;
138 if (X::wildAllowed())
139 base_flavor
= flavor
= BF_WILD
;
141 base_flavor
= flavor
= BF_GRAY
;
144 if (Random::chanceIn2(2))
148 base_flavor
= mapFlavorToBaseFlavor(flavor
);
151 } while ((base_flavor
== last_flavor_c
&& last_flavor_c
152 == second_to_last_flavor_c
) || (base_flavor
== last_row_c
[x
]
153 && last_row_c
[x
] == second_to_last_row_c
[x
]));
156 second_to_last_row_c
[x
] = last_row_c
[x
];
157 last_row_c
[x
] = base_flavor
;
159 second_to_last_flavor_c
= last_flavor_c
;
160 last_flavor_c
= base_flavor
;
163 newBlock(x
, 0, flavor
);