Updates for a new interface to the networking
[crack-attack.git] / src / GarbageManager.h
blob5acf9dc89f5b1b06e99e9752267713573db97cac
1 /*
2 * GarbageManager.h
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
26 #ifndef GARBAGEMANAGER_H
27 #define GARBAGEMANAGER_H
29 #include <cassert>
31 using namespace std;
33 #include "Garbage.h"
34 #include "GarbageFlavorImage.h"
36 class ComboTabulator;
38 /* static */ class GarbageManager {
39 public:
40 static void gameStart ( );
41 static bool newFallingGarbage ( int height, int width, int flavor );
43 static inline void newAwakingGarbage ( int x, int y, int height,
44 int pop_delay, int awake_delay, ComboTabulator *combo, int pop_color )
46 if (garbage_count == GC_GARBAGE_STORE_SIZE) return;
48 int id = findFreeId();
49 allocateId(id);
50 Garbage *garbage = garbageStore + id;
52 garbage->initializeAwaking(x, y, height, pop_delay, awake_delay, combo,
53 pop_color);
56 static inline void newFallingGarbage ( int x, int y, int height, int width,
57 int flavor )
59 if (garbage_count == GC_GARBAGE_STORE_SIZE) return;
61 int id = findFreeId();
62 allocateId(id);
63 Garbage *garbage = garbageStore + id;
65 garbage->initializeFalling(x, y, height, width, flavor);
67 GarbageFlavorImage::requestGarbageFlavorImage(*garbage);
70 static inline void deleteGarbage ( Garbage *garbage )
72 GarbageFlavorImage::notifyGarbageDestruction(*garbage);
73 freeId(garbage->id);
76 static inline void shiftUp ( )
78 int c = garbage_count;
79 for (int n = 0; c; n++)
80 if (storeMap[n]) {
81 c--;
82 garbageStore[n].y++;
86 static inline bool isSpecialFlavor ( int flavor )
88 return flavor;
91 static inline int mapBlockCodeToGarbageFlavor ( int code )
93 return code + (GF_GRAY + 1);
96 static int garbage_count;
97 static Garbage garbageStore[GC_GARBAGE_STORE_SIZE];
98 static bool storeMap[GC_GARBAGE_STORE_SIZE];
100 private:
101 static inline int findFreeId ( )
103 int n;
104 for (n = 0; storeMap[n]; n++);
105 return n;
108 static inline void allocateId ( int id )
110 assert(!storeMap[id]);
111 storeMap[id] = true;
112 garbage_count++;
115 static inline void freeId ( int id )
117 assert(storeMap[id]);
118 storeMap[id] = false;
119 garbage_count--;
123 #endif