Browse Source

added operate() for Unit, fixed some build errors and codestyle fails (not at all)

noath 6 years ago
parent
commit
632e732829
5 changed files with 68 additions and 12 deletions
  1. 4 2
      client.pro
  2. 6 2
      include/effects/effect.h
  3. 19 5
      include/units/unit.h
  4. 5 3
      source/effects/effect.cpp
  5. 34 0
      source/units/unit.cpp

+ 4 - 2
client.pro

@@ -95,7 +95,8 @@ SOURCES += \
     source/PlayerManager.cpp \
     source/Race.cpp \
     source/RaceManager.cpp \
-    source/hotseatgame/gui/HotSeatGame.cpp
+    source/hotseatgame/gui/HotSeatGame.cpp \
+    source/effects/effect.cpp
 
 HEADERS += \
     include/Cell.h \
@@ -118,7 +119,8 @@ HEADERS += \
     include/gui/RecruitmentScene.h \
     include/gui/Scene.h \
     include/gui/UnitIcon.h \
-    include/hotseatgame/gui/HotSeatGame.h
+    include/hotseatgame/gui/HotSeatGame.h \
+    include/effects/effect.h
 
 FORMS += \
     include/gui/GUI.ui \

+ 6 - 2
include/effects/effect.h

@@ -8,7 +8,11 @@
 #pragma once
 #include <iostream>
 #include <vector>
-//#include "AbstractFactory.h"
+
+#include <QFile>
+#include <QString>
+#include <QTextStream>
+#include <QImage>
 
 class Unit;
 class Cell;
@@ -24,7 +28,7 @@ public:
     int getCount();
     void setCount(int value);
 
-    int getDurability;
+    int getDurability();
     void setDurability(int value);
 
     //---------------------------------------------//

+ 19 - 5
include/units/unit.h

@@ -7,10 +7,7 @@
 #include <iostream>
 #include <vector>
 
-class Spell {
-public:
-    int a;
-};
+class Effect;
 
 class Cell;
 
@@ -80,6 +77,23 @@ public:
     virtual bool canAttackUnit(Unit* ) {return false;}
 
 
+    //---------------------------------------------//
+    //--------Effect processing & calling----------//
+    //---------------------------------------------//
+
+    void operateEffectList();
+
+    void add(Effect*);
+
+    void remove(std::vector<Effect*>::iterator);
+
+    void remove(Effect*);
+
+    std::vector<Effect*>::iterator beginIteratorEffectsList();
+
+    std::vector<Effect*>::iterator endIteratorEffectsList();
+
+
 
     //---------------------------------------------//
     //-------Movement checkers & calculators-------//
@@ -128,7 +142,7 @@ public:
     }
 
 protected:
-    std::vector <Spell> skills_;
+    std::vector <Effect*> effects_;
 
     //personal information
     int cost_;

+ 5 - 3
source/effects/effect.cpp

@@ -12,6 +12,7 @@
 #include <QFile>
 #include <QString>
 #include <QTextStream>
+#include <QImage>
 
 Effect::Effect(QString parameters) {
     QStringList params = parameters.split("|");
@@ -60,8 +61,9 @@ void Effect::setCount(int value){
 }
 
 int Effect::getDurability(){
-        return durability_;
-};
+    return durability_;
+}
+
 void Effect::setDurability(int value){
     durability_ = value;
-}
+}

+ 34 - 0
source/units/unit.cpp

@@ -1,6 +1,7 @@
 #include "AbstractFactory.h"
 #include "units/Unit.h"
 #include "Cell.h"
+#include "effects/effect.h"
 
 #include <iostream>
 #include <algorithm>
@@ -284,3 +285,36 @@ std::vector<QString> Unit::getUnitTraits() const {
 QImage Unit::getUnitIcon() const {
     return unit_icon_;
 }
+
+void Unit::operateEffectList(){
+    for(std::vector<Effect*>::iterator it = beginIteratorEffectsList();
+            it != endIteratorEffectsList(); ++it){
+        (*it)->OperateOnUnit(this);
+    }
+}
+void Unit::add(Effect* effect){
+    if(effect == nullptr)
+        throw new std::string("Try to add undefined effect to unit");
+    effects_.push_back(effect);
+}
+void Unit::remove(std::vector<Effect*>::iterator it){
+    if(beginIteratorEffectsList() <= it && it < endIteratorEffectsList()){
+        effects_.erase(it);
+    }
+}
+void Unit::remove(Effect* effect){
+    for(std::vector<Effect*>::iterator it = beginIteratorEffectsList();
+            it != endIteratorEffectsList(); ++it){
+        if((*it) == effect){
+            remove(it);
+            return;
+        }
+    }
+}
+std::vector<Effect*>::iterator Unit::beginIteratorEffectsList(){
+    return effects_.begin();
+}
+std::vector<Effect*>::iterator Unit::endIteratorEffectsList(){
+    return effects_.end();
+}
+