|
@@ -1,9 +1,12 @@
|
|
|
#include <hotseatgame/unitsqueue.h>
|
|
|
#include <vector>
|
|
|
#include <string>
|
|
|
+#include <algorithm>
|
|
|
+#include <units/unit.h>
|
|
|
|
|
|
void UnitsQueue::add(Unit* unit){
|
|
|
queue_.push_back(unit);
|
|
|
+ recalcQueue();
|
|
|
}
|
|
|
|
|
|
void UnitsQueue::remove(viterator iter){
|
|
@@ -31,3 +34,19 @@ UnitsQueue::viterator UnitsQueue::beginIterator() {
|
|
|
UnitsQueue::viterator UnitsQueue::endIterator(){
|
|
|
return queue_.end();
|
|
|
}
|
|
|
+
|
|
|
+Unit* UnitsQueue::front(){
|
|
|
+ return *beginIterator();
|
|
|
+}
|
|
|
+
|
|
|
+void UnitsQueue::pop(){
|
|
|
+ return remove(beginIterator());
|
|
|
+}
|
|
|
+
|
|
|
+void UnitsQueue::recalcQueue(){
|
|
|
+ std::stable_sort(beginIterator(), endIterator(),[](Unit* a, Unit* b)->bool{
|
|
|
+ auto a_init = a->getInitiative();
|
|
|
+ auto b_init = b->getInitiative();
|
|
|
+ return a_init > b_init;
|
|
|
+ });
|
|
|
+}
|