Make autopackage work
[crack-attack.git] / src / GarbageManager.cxx
blobbb9583c8a82c8c475a605691c7fb84ecaba978b2
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 using namespace std;
30 #include "Game.h"
31 #include "GarbageManager.h"
32 #include "Grid.h"
33 #include "Random.h"
35 int GarbageManager::garbage_count;
36 Garbage GarbageManager::garbageStore[GC_GARBAGE_STORE_SIZE];
37 bool GarbageManager::storeMap[GC_GARBAGE_STORE_SIZE];
39 void GarbageManager::gameStart ( )
41 garbage_count = 0;
42 for (int n = GC_GARBAGE_STORE_SIZE; n--; ) {
43 storeMap[n] = false;
44 garbageStore[n].id = n;
48 bool GarbageManager::newFallingGarbage ( int height, int width, int flavor )
50 * The Grid variable top_occupied_row must be accurate at the time of call.
53 int drop_row;
55 if (height > GC_MAX_GARBAGE_HEIGHT) height = GC_MAX_GARBAGE_HEIGHT;
57 if (Grid::top_occupied_row >= GC_SAFE_HEIGHT)
58 drop_row = Grid::top_occupied_row + 1;
59 else
60 drop_row = GC_SAFE_HEIGHT + 1;
62 // no room in the inn; try again later; don't allow it to occupy the top
63 // row, to leave room for the final creep
64 if (drop_row + height > GC_PLAY_HEIGHT - 1)
65 return false;
67 Grid::top_occupied_row = drop_row + height - 1;
69 if (width == GC_PLAY_WIDTH)
70 newFallingGarbage(0, drop_row, height, width, flavor);
71 else
72 newFallingGarbage(Random::number((GC_PLAY_WIDTH + 1) - width), drop_row,
73 height, width, flavor);
75 return true;