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.
23 #include "GarbageQueue.h"
25 #include "GarbageGenerator.h"
26 #include "GarbageManager.h"
30 GarbageQueue::GarbageQueue () {
31 //garbage_queue// = new vector<GarbageQueueElement();
35 GarbageQueue::~GarbageQueue () {
39 void GarbageQueue::reset () {
40 garbage_queue
.clear();
44 // FIXME: This makes xtreme an error condition
45 int GarbageQueue::removeWithSpecials ()
47 if ((*(garbage_queue
.begin())).flavor
== GF_GRAY
) {
48 return removeToFirst(GF_NORMAL
);
50 return removeToFirst(GF_GRAY
);
55 int GarbageQueue::removeToFirst ( int flavor
)
58 assert((*(garbage_queue
.begin())).flavor
!= flavor
);
59 if (garbage_queue
.empty()) return 0;
60 std::vector
<GarbageQueueElement
>::iterator iter
;
61 for (iter
= garbage_queue
.begin(); iter
!= garbage_queue
.end(); ++iter
) {
62 if ((*iter
).flavor
== flavor
) break;
65 if (num_removed
== 0) return 0;
67 int prev_height
= height();
69 MESSAGE("Removing " << num_removed
);
70 MESSAGE("Height before erase " << height());
72 garbage_queue
.erase(garbage_queue
.begin(), iter
);
75 int current_height
= height();
76 MESSAGE("Height after erase " << current_height
);
77 //assert((prev_height - num_removed)==current_height);
78 if (prev_height
- num_removed
!= current_height
) {
79 MESSAGE("***********Assertion would've failed here in GarbageQueue.cxx:75***********");
80 MESSAGE("prev_height - num_removed != current_height (" <<
81 prev_height
<< " - " << num_removed
<< " != " <<
82 current_height
<< ")");
88 void GarbageQueue::add ( int height
, int width
, int flavor
)
90 GarbageQueueElement e
;
98 static void show_element (GarbageQueueElement
&e
) {
100 printf("Element: h %d w %d f %d\n",+
107 void GarbageQueue::add ( GarbageQueueElement
&element
)
109 element
.active
= true;
110 MESSAGE("Adding garbage with height " << element
.height
);
111 show_element(element
);
112 assert(element
.height
<= GC_PLAY_HEIGHT
);
113 assert(element
.width
<= GC_PLAY_WIDTH
);
114 garbage_queue
.push_back(element
);
115 //int old_height = cached_height;
117 //assert(height()-element.height == old_height);
120 int GarbageQueue::height ( )
122 int garbage_height
= 0;
123 std::vector
<GarbageQueueElement
>::iterator iter
;
124 if (cached_height
!= -1) return cached_height
;
125 for (iter
= garbage_queue
.begin(); iter
!= garbage_queue
.end(); ++iter
) {
126 garbage_height
+= (*iter
).height
;
128 cached_height
= garbage_height
;
129 return garbage_height
;
132 int GarbageQueue::specialHeight ( )
134 int garbage_height
= 0;
135 std::vector
<GarbageQueueElement
>::iterator iter
;
136 if (cached_height
!= -1) return cached_height
;
137 for (iter
= garbage_queue
.begin(); iter
!= garbage_queue
.end(); ++iter
) {
138 if (GarbageManager::isSpecialFlavor((*iter
).flavor
))
139 garbage_height
+= (*iter
).height
;
141 return garbage_height
;
144 void GarbageQueue::sendToGenerator ( )
146 std::vector
<GarbageQueueElement
>::iterator iter
;
147 for (iter
= garbage_queue
.begin(); iter
!= garbage_queue
.end(); ++iter
) {
148 GarbageGenerator::addToQueue(*iter
);