Quellcode durchsuchen

Merge remote-tracking branch 'origin/unit' into dev

Ivan Arkhipov vor 6 Jahren
Ursprung
Commit
1fe765f57b

+ 5 - 3
client.pro

@@ -53,7 +53,7 @@ guiRes.target = BuildResources
 exists($$DESTDIR/res) {
         message("Directory $$DESTDIR/res already exists")
     } else {
-            gioRes.commands += $(MKDIR) \"$$DESTDIR/res\" $$escape_expand(\n\t);
+            guiRes.commands += $(MKDIR) \"$$DESTDIR/res\" $$escape_expand(\n\t)
     }
 
 win32 {
@@ -95,7 +95,8 @@ SOURCES += \
     source/hotseatgame/gui/RaceIcon.cpp \
     source/hotseatgame/gui/RecruitmentScene.cpp \
     source/hotseatgame/gui/UnitIcon.cpp \
-    source/hotseatgame/gui/HotSeatGame.cpp
+    source/hotseatgame/gui/HotSeatGame.cpp \
+    source/effects/Effect.cpp
 
 HEADERS += \
     include/Cell.h \
@@ -119,7 +120,8 @@ HEADERS += \
     include/hotseatgame/gui/RaceIcon.h \
     include/hotseatgame/gui/RecruitmentScene.h \
     include/hotseatgame/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);
 
     //---------------------------------------------//

+ 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_;

+ 0 - 174
include/units/unit.h

@@ -1,174 +0,0 @@
-#pragma once
-
-#include "AbstractFactory.h"
-#include <QObject>
-#include <QString>
-#include <QImage>
-#include <iostream>
-#include <vector>
-
-class Spell {
-public:
-    int a;
-};
-
-class Cell;
-
-class Unit : public QObject {
-    Q_OBJECT
-
-public:
-    explicit Unit(QString parameters);
-
-    virtual ~Unit() {}
-
-    //---------------------------------------------//
-    //---------Basic traits getters section--------//
-    //---------------------------------------------//
-
-	double getExperience();
-    int getLevel();
-    int getMovementSpeed();
-    int getInitiative();
-
-    int getIntelligence();
-    int getStrength();
-    int getAgility();
-
-    int getActivityPoints();
-    int getAttackPoints();
-    int getAttackCost();
-    int getAttackRange();
-    int getStartingActivityPoints();
-
-    int getHealthPoints();
-
-    int getMagicDefence();
-    int getPhysicDefence();
-
-    int getCost();
-    void setCost(int value);
-    virtual bool isCharacter();
-
-    std::vector<QString> getParentSpecs();
-    std::vector<QString> getUpgradeSpecs();
-
-    //---------------------------------------------//
-    //------------Unit location section------------//
-    //---------------------------------------------//
-
-    Cell* getLocation();
-    void setLocation(Cell* to);
-
-	double getRealX();
-	void setRealX(double x);
-
-	double getRealY();
-	void setRealY(double y);
-
-
-    //---------------------------------------------//
-    //--------Damage checkers & calculators--------//
-    //---------------------------------------------//
-
-    virtual int reduceIncomingDamage(std::string damageType, int value);
-
-    virtual	bool canAttackForDistance(std::string, int) {return false;}
-
-    virtual bool canAttackToCell(Cell* ) {return false;}
-
-    virtual bool canAttackUnit(Unit* ) {return false;}
-
-
-
-    //---------------------------------------------//
-    //-------Movement checkers & calculators-------//
-    //---------------------------------------------//
-
-
-    int lenOfActualPath(Cell* destination);
-
-    virtual bool canMoveForDistance(int distance);
-
-    virtual bool canMoveToCell(Cell* destination);
-
-    virtual void moveToCell(Cell* destination);
-
-    virtual int theSameNear();
-
-    //---------------------------------------------//
-    //----------------GUI section------------------//
-    //---------------------------------------------//
-
-    QString getUnitId() const;
-    QString getUnitName() const;
-    QString getUnitDescr() const;
-    QString getUnitBaseClassId() const;
-    std::vector<QString> getUnitTraits() const;
-    QImage getUnitIcon() const;
-
-    //---------------------------------------------//
-    //-----------Parameters load section-----------//
-    //---------------------------------------------//
-
-private:
-    void loadUnitName(QString unit_folder);
-    void loadUnitDescr(QString unit_folder);
-    void loadUnitBaseClass(QString unit_folder);
-    void loadUnitTraits(QString unit_folder);
-    void loadUnitIcon(QString unit_folder);
-    void loadUnitPrevSpecs(QString unit_folder);
-    void loadUnitUpgradeSpecs(QString unit_folder);
-
-public:
-    bool operator <(const Unit &b) {
-        if (base_class_id_ != b.base_class_id_)
-            return base_class_id_ < b.base_class_id_;
-        return unit_id_ < b.unit_id_;
-    }
-
-protected:
-    std::vector <Spell> skills_;
-
-    //personal information
-    int cost_;
-
-    std::vector<QString> parent_specs_;
-    std::vector<QString> upgrade_specs_;
-
-    double experience_;
-    int level_;
-    std::string race_; //lower case
-
-    //actions and events
-    double initiative_;
-    int activity_points_;
-
-    //movement
-    Cell* location_;
-    int movement_speed_;	//how many cells can move for one activity point
-    double real_x_;
-    double real_y_;
-
-    //attack action
-    int agility_;
-    int attack_range_;
-    int intelligence_;
-    int strength_;
-    int attack_cost_;     //how many activity points does attack cost
-    int starting_activity_points_;
-
-    //durability
-    int health_points_;
-    int magic_defence_;  //less or equal 40
-    int physic_defence_; //less or equal 40
-
-    // GUI values
-    QString race_id_;
-    QString unit_id_;
-
-    QString unit_name_;
-    QString unit_descr_;
-    QString base_class_id_;
-    QImage unit_icon_;
-};

+ 7 - 5
source/effects/Effect.cpp

@@ -1,8 +1,8 @@
 //
 // Created by IgorBat on 21.04.2018.
 //
-#include "abstractfactory.h"
-#include "effects/effect.h"
+#include "AbstractFactory.h"
+#include "effects/Effect.h"
 
 #include <iostream>
 #include <algorithm>
@@ -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;
-}
+}

+ 0 - 67
source/effects/effect.cpp

@@ -1,67 +0,0 @@
-//
-// Created by IgorBat on 21.04.2018.
-//
-#include "abstractfactory.h"
-#include "effects/effect.h"
-
-#include <iostream>
-#include <algorithm>
-#include <cassert>
-#include <string>
-
-#include <QFile>
-#include <QString>
-#include <QTextStream>
-
-Effect::Effect(QString parameters) {
-    QStringList params = parameters.split("|");
-
-    assert(params.size() >= 3);
-
-    effect_name_ = params[0];
-    setCount(params[1].toInt());
-    setDurability(params[2].toInt());
-    QString effect_folder = ":/assets/effects/" + effect_name_ + "/";
-
-    loadEffectDescr(effect_folder);
-    loadEffectIcon(effect_folder);
-}
-
-void Effect::loadEffectDescr(QString effect_folder) {
-    QFile file(effect_folder + "descr.txt");
-    file.open(QIODevice::ReadOnly);
-    QTextStream in(&file);
-    in.setCodec("UTF-8");
-    effect_descr_ = in.readAll();
-}
-
-void Effect::loadEffectIcon(QString effect_folder) {
-    effect_icon_.load(effect_folder + "icon.png");
-}
-
-
-QString Effect::getEffectName() const {
-    return effect_name_;
-}
-
-QString Effect::getEffectDescr() const {
-    return effect_descr_;
-}
-
-QImage Effect::getEffectIcon() const {
-    return effect_icon_;
-}
-
-int Effect::getCount(){
-    return count_;
-}
-void Effect::setCount(int value){
-    count_ = value;
-}
-
-int Effect::getDurability(){
-        return durability_;
-};
-void Effect::setDurability(int value){
-    durability_ = value;
-}

+ 1 - 1
source/gui/GUI.cpp

@@ -1,5 +1,5 @@
 #include <gui/GUI.h>
-#include <ui_gui.h>
+#include <ui_GUI.h>
 #include <QDebug>
 
 GUI::GUI(QWidget *parent) :

+ 1 - 1
source/gui/MainMenu.cpp

@@ -1,6 +1,6 @@
 #include "gui/MainMenu.h"
 #include "gui/GuiSceneManager.h"
-#include "ui_mainmenu.h"
+#include "ui_MainMenu.h"
 
 #include <QString>
 #include <QApplication>

+ 0 - 62
source/gui/gui.cpp

@@ -1,62 +0,0 @@
-#include <gui/GUI.h>
-#include <ui_gui.h>
-#include <QDebug>
-
-GUI::GUI(QWidget *parent) :
-    QMainWindow(parent, Qt::Window | Qt::FramelessWindowHint),
-    ui_(new Ui::GUI), dx_(-100000), dy_(-100000)
-{
-    ui_->setupUi(this);
-    setWindowTitle("Супер-мега-клёвая-игрушка-название-которой-мы-ещё-не-придумали");
-}
-
-GUI::~GUI()
-{
-    delete ui_;
-}
-
-QWidget* GUI::mainContentScene() {
-    return ui_->main_content_;
-}
-
-
-void GUI::mouseMoveEvent( QMouseEvent* e ) {
-    if( e->buttons() | Qt::LeftButton ) {
-        QPoint pt=mapFromGlobal(QCursor::pos());
-
-        if (dx_ != -100000 && dy_ != -100000)
-            setGeometry(pos().x() + ( pt.x() - dx_ ), pos().y() + ( pt.y() - dy_ ), width(), height());
-    }
-}
-
-void GUI::mousePressEvent( QMouseEvent* e ) {
-    if(e->button() == Qt::LeftButton) {
-        QPoint pt = mapFromGlobal(QCursor::pos());
-        QWidget* child=childAt(pt);
-
-        if (child == 0) {
-            dx_ = -100000;
-            dy_ = -100000;
-            return;
-        }
-
-        QString cname = child->objectName();
-        if (cname == "window_top_border_" || cname == "window_bottom_border_"
-                || cname == "window_topleft_border_" || cname == "window_topright_border_"
-                || cname == "window_right_border_" || cname == "window_left_border_"
-                || cname == "window_botright_border_" || cname == "window_botleft_border_") {
-            dx_ = pt.x();
-            dy_ = pt.y();
-        } else {
-            dx_ = -100000;
-            dy_ = -100000;
-        }
-    }
-}
-
-void GUI::mouseReleaseEvent( QMouseEvent* e ) {
-    if( e->button() == Qt::LeftButton ) {
-        dx_ = -100000;
-        dy_ = -100000;
-    }
-}

+ 0 - 28
source/gui/mainmenu.cpp

@@ -1,28 +0,0 @@
-#include "gui/MainMenu.h"
-#include "gui/GuiSceneManager.h"
-#include "ui_mainmenu.h"
-
-#include <QString>
-#include <QApplication>
-
-MainMenu::MainMenu(QWidget *parent) :
-    Scene(parent),
-    ui(new Ui::MainMenu)
-{
-    ui->setupUi(this);
-}
-
-MainMenu::~MainMenu()
-{
-    delete ui;
-}
-
-void MainMenu::on_exit_button_clicked()
-{
-    QApplication::quit();
-}
-
-void MainMenu::on_pvp_local_battle_button_clicked()
-{
-    GuiSceneManager::getInstance().changeScene("pvp_intro");
-}

+ 2 - 2
source/hotseatgame/gui/HotSeatGame.cpp

@@ -1,5 +1,5 @@
-#include "hotseatgame\gui\hotseatgame.h"
-#include "ui_hotseatgame.h"
+#include "hotseatgame/gui/HotSeatGame.h"
+#include "ui_HotSeatGame.h"
 #include "gui/guiscenemanager.h"
 
 #include <QDebug>

+ 1 - 1
source/hotseatgame/gui/PlayerVsPlayerIntro.cpp

@@ -3,7 +3,7 @@
 #include "PlayerManager.h"
 #include "gui/Scene.h"
 
-#include "ui_playervsplayerintro.h"
+#include "ui_PlayerVsPlayerIntro.h"
 
 PlayerVsPlayerIntro::PlayerVsPlayerIntro(QWidget *parent) :
     Scene(parent),

+ 1 - 1
source/hotseatgame/gui/PreBattleScene.cpp

@@ -9,7 +9,7 @@
 #include "hotseatgame/gui/RaceIcon.h"
 #include "hotseatgame/gui/UnitIcon.h"
 #include "gui/GuiSceneManager.h"
-#include "ui_prebattlescene.h"
+#include "ui_PreBattleScene.h"
 
 #include <QMessageBox>
 

+ 1 - 1
source/hotseatgame/gui/RecruitmentScene.cpp

@@ -8,7 +8,7 @@
 #include <RaceManager.h>
 #include <Race.h>
 
-#include <ui_recruitmentscene.h>
+#include <ui_RecruitmentScene.h>
 #include <QHBoxLayout>
 #include <QString>
 #include <QStringList>

+ 0 - 32
source/hotseatgame/gui/hotseatgame.cpp

@@ -1,32 +0,0 @@
-#include "hotseatgame\gui\hotseatgame.h"
-#include "ui_hotseatgame.h"
-#include "gui/guiscenemanager.h"
-
-#include <QDebug>
-
-HotSeatGame::HotSeatGame(QWidget *parent) :
-    Scene(parent),
-    ui(new Ui::HotSeatGame)
-{
-    qDebug() << "Initialising game";
-    ui->setupUi(this);
-    setWindowState(Qt::WindowFullScreen);
-}
-
-void HotSeatGame::init() {
-    GuiSceneManager::getInstance().hideMainWindow();
-}
-
-
-HotSeatGame::~HotSeatGame()
-{
-    delete ui;
-}
-
-void HotSeatGame::on_surrender_button__clicked()
-{
-    GuiSceneManager::getInstance().showMainWindow();
-    GuiSceneManager::getInstance().hideDetachedScene("hotseatgame");
-    //GuiSceneManager::getInstance().changeScene("hotseatgame_results");
-    GuiSceneManager::getInstance().changeScene("main_menu");
-}

+ 0 - 22
source/playermanager.cpp

@@ -1,22 +0,0 @@
-#include "PlayerManager.h"
-#include <cassert>
-
-PlayerManager::PlayerManager(QObject *parent) : QObject(parent)
-{
-
-}
-
-Player* PlayerManager::getPlayer(int id) {
-    assert(unsigned(id) < players_.size());
-    return &players_[id];
-}
-
-int PlayerManager::getPlayersNum() {
-    return players_.size();
-}
-
-void PlayerManager::setPlayersNum(int num) {
-    players_.resize(num);
-    for (int i = 0; i < num; i++)
-        players_[i].init(i);
-}

+ 0 - 90
source/race.cpp

@@ -1,90 +0,0 @@
-#include "Race.h"
-#include "units/Unit.h"
-#include "units/Warrior.h"
-#include "units/Mage.h"
-
-#include <QFile>
-#include <QTextStream>
-#include <QString>
-#include <QDebug>
-
-#include <cassert>
-#include <vector>
-#include <algorithm>
-
-Race::Race(QString race_name, QObject *parent) : QObject(parent)
-{
-    race_id_ = race_name;
-
-    units_factory_.addClass<Warrior, QString>("Warrior");
-    units_factory_.addClass<Warrior, QString>("Mage");
-    units_factory_.addClass<Warrior, QString>("Rider");
-    units_factory_.addClass<Warrior, QString>("Rogue");
-    units_factory_.addClass<Warrior, QString>("Archer");
-
-    QFile file(":/assets/units/" + race_name + "/units.txt");
-    file.open(QIODevice::ReadOnly);
-    QTextStream in(&file);
-    in.setCodec("UTF-8");
-    QString unit_name = in.readLine();
-
-    while (!in.atEnd()) {
-        available_units_list_.push_back(unit_name);
-        all_units_list_.push_back(createUnit(unit_name));
-        unit_name = in.readLine();
-    }
-
-    if (unit_name.length() > 2) {
-        available_units_list_.push_back(unit_name);
-        all_units_list_.push_back(createUnit(unit_name));
-    }
-
-    QFile file0(":/assets/units/" + race_name + "/racename.txt");
-    file0.open(QIODevice::ReadOnly);
-    QTextStream in0(&file0);
-    in0.setCodec("UTF-8");
-    race_name_ = in0.readLine();
-
-    QFile file1(":/assets/units/" + race_name + "/descr.txt");
-    file1.open(QIODevice::ReadOnly);
-    QTextStream in1(&file1);
-    in1.setCodec("UTF-8");
-    race_descr_ = in1.readAll();
-
-    race_icon_.load(":/assets/units/" + race_name + "/icon.png");
-}
-
-QString Race::getRaceId() {
-    return race_id_;
-}
-
-QString Race::getRaceName() {
-    return race_name_;
-}
-
-QImage Race::getRaceIcon() {
-    return race_icon_;
-}
-
-QString Race::getRaceDescr() {
-    return race_descr_;
-}
-
-Unit* Race::createUnit(QString unit_name) {
-    qDebug() << unit_name;
-    QFile file(":/assets/units/" + race_id_ + "/" + unit_name + "/baseclass.txt");
-    file.open(QIODevice::ReadOnly);
-    QTextStream in(&file);
-    in.setCodec("UTF-8");
-    QString class_id = in.readLine();
-    qDebug() << "Creating unit of base class " << class_id << " and major class" <<  race_id_ + "|" + unit_name;
-    return units_factory_.createObject<QString>(class_id, race_id_ + "|" + unit_name);
-}
-
-const std::vector<QString>& Race::getAvailableUnitsList() {
-    return available_units_list_;
-}
-
-const std::vector<Unit*> &Race::getAllUnitsList() {
-    return all_units_list_;
-}

+ 0 - 50
source/racemanager.cpp

@@ -1,50 +0,0 @@
-#include "RaceManager.h"
-#include "Race.h"
-
-#include <QFile>
-#include <QDebug>
-#include <QTextStream>
-#include <QDebug>
-
-RaceManager::RaceManager(QObject *parent) : QObject(parent)
-{
-    QFile file(":/assets/units/races.txt");
-    file.open(QIODevice::ReadOnly);
-    QTextStream in(&file);
-    in.setCodec("UTF-8");
-    QString race_name = in.readLine();
-
-    while(!in.atEnd()) {
-        if (races_.count(race_name) != 0) {
-            qWarning() << "Warning! found double occurences of races in raceslist.txt";
-            continue;
-        }
-        if (race_name.length() < 2)
-            continue;
-        //qDebug() << available_races_;
-        available_races_.push_back(race_name);
-        races_[race_name] = new Race(race_name);
-        race_name = in.readLine();
-    }
-
-    if (race_name.length() >= 2) {
-        //qDebug() << available_races_;
-        available_races_.push_back(race_name);
-        races_[race_name] = new Race(race_name);
-        race_name = in.readLine();
-    }
-
-}
-
-Race* RaceManager::getRace(QString race_name) {
-    if (races_.count(race_name) == 0) {
-        qWarning() << "Error! Not found race with name " << race_name;
-        return nullptr;
-    }
-
-    return races_[race_name];
-}
-
-const std::vector<QString>& RaceManager::getAvailableRacesList() {
-    return available_races_;
-}

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

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