3 * Daniel Nelson - 8/25/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.
28 #include "GarbageManager.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 ( )
41 for (int n
= GC_GARBAGE_STORE_SIZE
; n
--; ) {
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.
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;
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)
66 Grid::top_occupied_row
= drop_row
+ height
- 1;
68 if (width
== GC_PLAY_WIDTH
)
69 newFallingGarbage(0, drop_row
, height
, width
, flavor
);
71 newFallingGarbage(Random::number((GC_PLAY_WIDTH
+ 1) - width
), drop_row
,
72 height
, width
, flavor
);