GeorgeKolog il y a 6 ans
Parent
commit
e93f8ed9da
2 fichiers modifiés avec 22 ajouts et 0 suppressions
  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;
 public:
     void add(Unit*);
+    Unit* front();
+    void pop();
     void remove(viterator);
     void remove(Unit*);
     viterator beginIterator();
     viterator endIterator();
+    void recalcQueue();
 };

+ 19 - 0
source/hotseatgame/unitsqueue.cpp

@@ -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;
+    });
+}