Browse Source

Must to work

GeorgeKolog 6 years ago
parent
commit
e93f8ed9da
2 changed files with 22 additions and 0 deletions
  1. 3 0
      include/hotseatgame/unitsqueue.h
  2. 19 0
      source/hotseatgame/unitsqueue.cpp

+ 3 - 0
include/hotseatgame/unitsqueue.h

@@ -8,8 +8,11 @@ private:
     typedef std::vector<Unit*>::iterator viterator;
     typedef std::vector<Unit*>::iterator viterator;
 public:
 public:
     void add(Unit*);
     void add(Unit*);
+    Unit* front();
+    void pop();
     void remove(viterator);
     void remove(viterator);
     void remove(Unit*);
     void remove(Unit*);
     viterator beginIterator();
     viterator beginIterator();
     viterator endIterator();
     viterator endIterator();
+    void recalcQueue();
 };
 };

+ 19 - 0
source/hotseatgame/unitsqueue.cpp

@@ -1,9 +1,12 @@
 #include <hotseatgame/unitsqueue.h>
 #include <hotseatgame/unitsqueue.h>
 #include <vector>
 #include <vector>
 #include <string>
 #include <string>
+#include <algorithm>
+#include <units/unit.h>
 
 
 void UnitsQueue::add(Unit* unit){
 void UnitsQueue::add(Unit* unit){
     queue_.push_back(unit);
     queue_.push_back(unit);
+    recalcQueue();
 }
 }
 
 
 void UnitsQueue::remove(viterator iter){
 void UnitsQueue::remove(viterator iter){
@@ -31,3 +34,19 @@ UnitsQueue::viterator UnitsQueue::beginIterator() {
 UnitsQueue::viterator UnitsQueue::endIterator(){
 UnitsQueue::viterator UnitsQueue::endIterator(){
     return queue_.end();
     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;
+    });
+}