Make autopackage work
[crack-attack.git] / src / GarbageQueue.cxx
blob9f882dbdacd614e6223575fb37834c75c4e0435c
1 /*
2 * GarbageQueue.cxx
3 *
4 * Crack Attack! is the legal property of its developers, whose names
5 * are too numerous to list here. Please refer to the COPYRIGHT file
6 * distributed with this source distribution for a full listing.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 #include "GarbageQueue.h"
23 #include "GarbageGenerator.h"
24 #include "GarbageManager.h"
26 #include <cassert>
28 GarbageQueue::GarbageQueue () {
29 //garbage_queue// = new vector<GarbageQueueElement();
30 cached_height = -1;
33 GarbageQueue::~GarbageQueue () {
34 reset();
37 void GarbageQueue::reset () {
38 garbage_queue.clear();
39 cached_height = -1;
42 // FIXME: This makes xtreme an error condition
43 int GarbageQueue::removeWithSpecials ()
45 if ((*(garbage_queue.begin())).flavor == GF_GRAY) {
46 return removeToFirst(GF_NORMAL);
47 } else {
48 return removeToFirst(GF_GRAY);
50 return 0;
53 int GarbageQueue::removeToFirst ( int flavor )
55 int num_removed = 0;
56 assert((*(garbage_queue.begin())).flavor != flavor);
57 if (garbage_queue.empty()) return 0;
58 vector<GarbageQueueElement>::iterator iter;
59 for (iter = garbage_queue.begin(); iter != garbage_queue.end(); ++iter) {
60 if ((*iter).flavor == flavor) break;
61 ++num_removed;
63 if (num_removed == 0) return 0;
64 garbage_queue.erase(garbage_queue.begin(), iter);
65 cached_height = -1;
66 return num_removed;
69 void GarbageQueue::add ( int height, int width, int flavor)
71 GarbageQueueElement e;
72 e.active = true;
73 e.height = height;
74 e.width = width;
75 e.flavor = flavor;
76 add(e);
79 static void show_element (GarbageQueueElement &e) {
80 #ifndef NDEBUG
81 printf("Element: %p h %d w %d f %d\n",
83 e.height,
84 e.width,
85 e.flavor);
86 #endif
89 void GarbageQueue::add ( GarbageQueueElement &element )
91 element.active = true;
92 MESSAGE("Adding garbage " << element.active);
93 show_element(element);
94 assert(element.height <= GC_PLAY_HEIGHT);
95 assert(element.width <= GC_PLAY_WIDTH);
96 garbage_queue.push_back(element);
97 cached_height = -1;
100 int GarbageQueue::height ( )
102 int garbage_height = 0;
103 vector<GarbageQueueElement>::iterator iter;
104 if (cached_height != -1) return cached_height;
105 for (iter = garbage_queue.begin(); iter != garbage_queue.end(); ++iter) {
106 garbage_height += (*iter).height;
108 cached_height = garbage_height;
109 return garbage_height;
112 int GarbageQueue::specialHeight ( )
114 int garbage_height = 0;
115 vector<GarbageQueueElement>::iterator iter;
116 if (cached_height != -1) return cached_height;
117 for (iter = garbage_queue.begin(); iter != garbage_queue.end(); ++iter) {
118 if (GarbageManager::isSpecialFlavor((*iter).flavor))
119 garbage_height += (*iter).height;
121 return garbage_height;
124 void GarbageQueue::sendToGenerator ( )
126 vector<GarbageQueueElement>::iterator iter;
127 for (iter = garbage_queue.begin(); iter != garbage_queue.end(); ++iter) {
128 GarbageGenerator::addToQueue(*iter);