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.
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"
28 GarbageQueue::GarbageQueue () {
29 //garbage_queue// = new vector<GarbageQueueElement();
33 GarbageQueue::~GarbageQueue () {
37 void GarbageQueue::reset () {
38 garbage_queue
.clear();
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
);
48 return removeToFirst(GF_GRAY
);
53 int GarbageQueue::removeToFirst ( int flavor
)
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;
63 if (num_removed
== 0) return 0;
65 int prev_height
= height();
67 MESSAGE("Removing " << num_removed
);
68 MESSAGE("Height before erase " << height());
70 garbage_queue
.erase(garbage_queue
.begin(), iter
);
73 int current_height
= height();
74 MESSAGE("Height after erase " << current_height
);
75 //assert((prev_height - num_removed)==current_height);
76 if (prev_height
- num_removed
!= current_height
) {
77 MESSAGE("***********Assertion would've failed here in GarbageQueue.cxx:75***********");
78 MESSAGE("prev_height - num_removed != current_height (" <<
79 prev_height
<< " - " << num_removed
<< " != " <<
80 current_height
<< ")");
86 void GarbageQueue::add ( int height
, int width
, int flavor
)
88 GarbageQueueElement e
;
96 static void show_element (GarbageQueueElement
&e
) {
98 printf("Element: h %d w %d f %d\n",+
105 void GarbageQueue::add ( GarbageQueueElement
&element
)
107 element
.active
= true;
108 MESSAGE("Adding garbage with height " << element
.height
);
109 show_element(element
);
110 assert(element
.height
<= GC_PLAY_HEIGHT
);
111 assert(element
.width
<= GC_PLAY_WIDTH
);
112 garbage_queue
.push_back(element
);
113 //int old_height = cached_height;
115 //assert(height()-element.height == old_height);
118 int GarbageQueue::height ( )
120 int garbage_height
= 0;
121 vector
<GarbageQueueElement
>::iterator iter
;
122 if (cached_height
!= -1) return cached_height
;
123 for (iter
= garbage_queue
.begin(); iter
!= garbage_queue
.end(); ++iter
) {
124 garbage_height
+= (*iter
).height
;
126 cached_height
= garbage_height
;
127 return garbage_height
;
130 int GarbageQueue::specialHeight ( )
132 int garbage_height
= 0;
133 vector
<GarbageQueueElement
>::iterator iter
;
134 if (cached_height
!= -1) return cached_height
;
135 for (iter
= garbage_queue
.begin(); iter
!= garbage_queue
.end(); ++iter
) {
136 if (GarbageManager::isSpecialFlavor((*iter
).flavor
))
137 garbage_height
+= (*iter
).height
;
139 return garbage_height
;
142 void GarbageQueue::sendToGenerator ( )
144 vector
<GarbageQueueElement
>::iterator iter
;
145 for (iter
= garbage_queue
.begin(); iter
!= garbage_queue
.end(); ++iter
) {
146 GarbageGenerator::addToQueue(*iter
);