AI
[crack-attack.git] / src / GarbageManager.h
blob9ad9e3bc821e510613c63d53223391d05f472db3
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 MESSAGE("Calling initializeFalling x " << x << " y " << y << " height " << height << " width " << width);
66 garbage->initializeFalling(x, y, height, width, flavor);
68 GarbageFlavorImage::requestGarbageFlavorImage(*garbage);
71 static inline void deleteGarbage ( Garbage *garbage )
73 GarbageFlavorImage::notifyGarbageDestruction(*garbage);
74 freeId(garbage->id);
77 static inline void shiftUp ( )
79 int c = garbage_count;
80 for (int n = 0; c; n++)
81 if (storeMap[n]) {
82 c--;
83 garbageStore[n].y++;
87 static inline bool isSpecialFlavor ( int flavor )
89 return flavor;
92 static inline int mapBlockCodeToGarbageFlavor ( int code )
94 return code + (GF_GRAY + 1);
97 static int garbage_count;
98 static Garbage garbageStore[GC_GARBAGE_STORE_SIZE];
99 static bool storeMap[GC_GARBAGE_STORE_SIZE];
101 private:
102 static inline int findFreeId ( )
104 int n;
105 for (n = 0; storeMap[n]; n++);
106 return n;
109 static inline void allocateId ( int id )
111 assert(!storeMap[id]);
112 storeMap[id] = true;
113 garbage_count++;
116 static inline void freeId ( int id )
118 assert(storeMap[id]);
119 storeMap[id] = false;
120 garbage_count--;
124 #endif