Each module now includes its own header first. Removed sstream.h and the definition...
[crack-attack.git] / src / GarbageManager.cxx
blob607af54373b68973e62921ccdba0e3fa0e2f3fc1
1 /*
2 * GarbageManager.cxx
3 * Daniel Nelson - 8/25/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 "GarbageManager.h"
30 #include "Game.h"
31 #include "Grid.h"
32 #include "Random.h"
34 int GarbageManager::garbage_count;
35 Garbage GarbageManager::garbageStore[GC_GARBAGE_STORE_SIZE];
36 bool GarbageManager::storeMap[GC_GARBAGE_STORE_SIZE];
38 void GarbageManager::gameStart ( )
40 garbage_count = 0;
41 for (int n = GC_GARBAGE_STORE_SIZE; n--; ) {
42 storeMap[n] = false;
43 garbageStore[n].id = n;
47 bool GarbageManager::newFallingGarbage ( int height, int width, int flavor )
49 * The Grid variable top_occupied_row must be accurate at the time of call.
52 int drop_row;
54 if (height > GC_MAX_GARBAGE_HEIGHT) height = GC_MAX_GARBAGE_HEIGHT;
56 if (Grid::top_occupied_row >= GC_SAFE_HEIGHT)
57 drop_row = Grid::top_occupied_row + 1;
58 else
59 drop_row = GC_SAFE_HEIGHT + 1;
61 // no room in the inn; try again later; don't allow it to occupy the top
62 // row, to leave room for the final creep
63 if (drop_row + height > GC_PLAY_HEIGHT - 1)
64 return false;
66 Grid::top_occupied_row = drop_row + height - 1;
68 if (width == GC_PLAY_WIDTH)
69 newFallingGarbage(0, drop_row, height, width, flavor);
70 else
71 newFallingGarbage(Random::number((GC_PLAY_WIDTH + 1) - width), drop_row,
72 height, width, flavor);
74 return true;