From 36e0a3eb9d885e032e793bc5a200ab880994b256 Mon Sep 17 00:00:00 2001 From: noath Date: Wed, 7 Mar 2018 12:57:22 +0300 Subject: [PATCH 01/17] Switched location to Cell*, codestyle corrections --- unit.cpp | 6 +++--- unit.h | 13 ++++++++----- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/unit.cpp b/unit.cpp index 32b93db..84dced9 100644 --- a/unit.cpp +++ b/unit.cpp @@ -56,11 +56,11 @@ void Unit::setAttackRange(double value) { attack_range_ = value; } -std::pair Unit::getLocation() { +Cell* Unit::getLocation() { return location_; } -void Unit::setLocation(double x, double y) { - location_ = std::make_pair(x, y); +void Unit::setLocation(Cell* to) { + location_ = to; } double Unit::getMovementSpeed() { diff --git a/unit.h b/unit.h index eb1e78f..5691296 100644 --- a/unit.h +++ b/unit.h @@ -5,6 +5,9 @@ class Spell { //empty for allow to compile }; +class Cell { + //waiting a realisation +}; class Unit { @@ -21,7 +24,7 @@ class Unit { double initiative_; //movement - std::pair location_; //x - first, y - second + Cell* location_; //x - first, y - second double movement_speed_; //attack action @@ -63,14 +66,14 @@ class Unit { double getAttackRange(); void setAttackRange(double value); - std::pair getLocation(); - void setLocation(double x, double y); + Cell* getLocation(); + void setLocation(Cell* to); double getMovementSpeed(); void setMovementSpeed(double value); - double getInitiative_(); - void setInitiative_(double value); + double getInitiative(); + void setInitiative(double value); double getDamagePerHit(); void setDamagePerHit(double value); From 498341b4e9f0d10a198fed361c14a623d5daa085 Mon Sep 17 00:00:00 2001 From: noath Date: Wed, 7 Mar 2018 15:13:10 +0300 Subject: [PATCH 02/17] added primal movement func --- unit.cpp | 22 ++++++++++++++++++++-- unit.h | 22 ++++++++++++++++++---- 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/unit.cpp b/unit.cpp index 84dced9..6c26c53 100644 --- a/unit.cpp +++ b/unit.cpp @@ -70,10 +70,10 @@ void Unit::setMovementSpeed(double value) { movement_speed_ = value; } -double Unit::getInitiative_() { +double Unit::getInitiative() { return initiative_; } -void Unit::setInitiative_(double value) { +void Unit::setInitiative(double value) { initiative_ = value; } @@ -135,3 +135,21 @@ double Unit::reduceIncomingDamage(std::string damageType, int damage) { //return return (1 - 2.5 * magic_defence_ / 100) * damage; } } + +bool Unit::canMoveForDistance(int distance) { + if (active_points_ >= double(distance) / movement_speed_) { + return true; + } + else return false; +} + +bool Unit::canMoveToCell(Cell* to) { + if (to->isEmpty() && canMoveForDistance(to->actualPath.size())) { + return true; + } + else return false; +} + +/*bool canAttack(int distance) { + +}*/ diff --git a/unit.h b/unit.h index 5691296..b6faa82 100644 --- a/unit.h +++ b/unit.h @@ -3,10 +3,18 @@ #include class Spell { - //empty for allow to compile + //waiting for a realisation }; class Cell { - //waiting a realisation + //waiting for a realisation +public: + bool isEmpty() { + return true; + } + std::vector actualPath() { + std::vector path; + return path; + } }; class Unit { @@ -24,8 +32,8 @@ class Unit { double initiative_; //movement - Cell* location_; //x - first, y - second - double movement_speed_; + Cell* location_; + double movement_speed_; //how many cells can move for one activity point //attack action double agility_; @@ -96,4 +104,10 @@ class Unit { virtual void calculateDamagePerHit(); double reduceIncomingDamage(std::string damageType, int value); + + bool canMoveForDistance(int distance); + + bool Unit::canMoveToCell(Cell* to); + +// bool canAttackForDistance(int distance); }; \ No newline at end of file From 320ec218713834aea4840b78fc9e31c31cf26f38 Mon Sep 17 00:00:00 2001 From: noath Date: Wed, 7 Mar 2018 15:15:22 +0300 Subject: [PATCH 03/17] corrected signature of actualPath --- unit.cpp | 2 +- unit.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/unit.cpp b/unit.cpp index 6c26c53..4f6349f 100644 --- a/unit.cpp +++ b/unit.cpp @@ -144,7 +144,7 @@ bool Unit::canMoveForDistance(int distance) { } bool Unit::canMoveToCell(Cell* to) { - if (to->isEmpty() && canMoveForDistance(to->actualPath.size())) { + if (to->isEmpty() && canMoveForDistance(getLocation()->actualPath(to).size())) { return true; } else return false; diff --git a/unit.h b/unit.h index b6faa82..2b1cb93 100644 --- a/unit.h +++ b/unit.h @@ -11,7 +11,7 @@ class Cell { bool isEmpty() { return true; } - std::vector actualPath() { + std::vector actualPath(Cell* to) { std::vector path; return path; } From 1fba1ca518e5c6deb244d4afb2a8cfde661f9f6e Mon Sep 17 00:00:00 2001 From: noath Date: Wed, 7 Mar 2018 21:34:35 +0300 Subject: [PATCH 04/17] primal int movement --- unit.cpp | 43 +++++++++++++++++++++++-------------------- unit.h | 20 ++++++++++---------- 2 files changed, 33 insertions(+), 30 deletions(-) diff --git a/unit.cpp b/unit.cpp index 4f6349f..78ca329 100644 --- a/unit.cpp +++ b/unit.cpp @@ -5,7 +5,7 @@ #include #include "unit.h" -Unit::Unit(){} +Unit::Unit() {} double Unit::getExperience() { return experience_; @@ -42,13 +42,6 @@ void Unit::setEnergyPoints(double value) { energy_points_ = value; } -double Unit::getActivePoints() { - return active_points_; -} -void Unit::setActivePoints(double value) { - active_points_ = value; -} - double Unit::getAttackRange() { return attack_range_; } @@ -63,11 +56,11 @@ void Unit::setLocation(Cell* to) { location_ = to; } -double Unit::getMovementSpeed() { - return movement_speed_; +int Unit::getMovementPoints() { + return movement_points_; } -void Unit::setMovementSpeed(double value) { - movement_speed_ = value; +void Unit::setMovementPoints(int value) { + movement_points_ = value; } double Unit::getInitiative() { @@ -136,20 +129,30 @@ double Unit::reduceIncomingDamage(std::string damageType, int damage) { //return } } +int Unit::lenOfActualPath(Cell* destination) { + return getLocation()->actualPath(destination).size(); +} + bool Unit::canMoveForDistance(int distance) { - if (active_points_ >= double(distance) / movement_speed_) { - return true; - } - else return false; + return (movement_points_ >= distance); +} + +bool Unit::canMoveToCell(Cell* destination) { + return (destination->isEmpty() && canMoveForDistance(lenOfActualPath(destination))); } -bool Unit::canMoveToCell(Cell* to) { - if (to->isEmpty() && canMoveForDistance(getLocation()->actualPath(to).size())) { - return true; +void Unit::moveToCell(Cell* destination) { + if (!canMoveToCell) + return; //here could be a gui-message about failed move (x-mark, for example) + else { + int decreasedValue = getMovementPoints() - lenOfActualPath(destination); + setMovementPoints(decreasedValue); + setLocation(destination); } - else return false; } /*bool canAttack(int distance) { }*/ + +//TODO: real_x_, real_y_, ptr to player diff --git a/unit.h b/unit.h index 2b1cb93..280ef4a 100644 --- a/unit.h +++ b/unit.h @@ -11,7 +11,7 @@ class Cell { bool isEmpty() { return true; } - std::vector actualPath(Cell* to) { + std::vector actualPath(Cell* destination) { //the shortest existing path from (*this) to (*destination) std::vector path; return path; } @@ -27,13 +27,12 @@ class Unit { double experience_; double level_; - //connect with events - double active_points_; + //actions and events double initiative_; //movement Cell* location_; - double movement_speed_; //how many cells can move for one activity point + double movement_points_; //how many cells can move for one activity point //attack action double agility_; @@ -68,17 +67,14 @@ class Unit { double getEnergyPoints(); void setEnergyPoints(double value); - double getActivePoints(); - void setActivePoints(double value); - double getAttackRange(); void setAttackRange(double value); Cell* getLocation(); void setLocation(Cell* to); - double getMovementSpeed(); - void setMovementSpeed(double value); + int getMovementPoints(); + void setMovementPoints(int value); double getInitiative(); void setInitiative(double value); @@ -105,9 +101,13 @@ class Unit { double reduceIncomingDamage(std::string damageType, int value); + int lenOfActualPath(Cell* destination); + bool canMoveForDistance(int distance); - bool Unit::canMoveToCell(Cell* to); + bool canMoveToCell(Cell* destination); + void moveToCell(Cell* destination); + // bool canAttackForDistance(int distance); }; \ No newline at end of file From 712b5dbd106fa53bdb68a0ed3655f214736cbd23 Mon Sep 17 00:00:00 2001 From: noath Date: Thu, 8 Mar 2018 13:06:47 +0300 Subject: [PATCH 05/17] added real coordinates and race --- unit.cpp | 25 ++++++++++++++++++++++++- unit.h | 22 +++++++++++++++++----- 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/unit.cpp b/unit.cpp index 78ca329..eb91341 100644 --- a/unit.cpp +++ b/unit.cpp @@ -112,6 +112,27 @@ void Unit::setPhysicDefence(double value) { physic_defence_ = value; } +std::string Unit::getRace() { + return race_; +} +void Unit::setRace(std::string new_race) { + race_ = new_race; +} + +double Unit::getRealX() { + return real_x_; +} +void Unit::setRealX(double x) { + real_x_ = x; +} + +double Unit::getRealY() { + return real_y_; +} +void Unit::setRealY(double y) { + real_y_ = y; +} + void Unit::calculateDamagePerHit() { damage_per_hit_ = 0.5 * std::max(getAgility(), std::max(getStrength(), getIntelligence())); } @@ -151,8 +172,10 @@ void Unit::moveToCell(Cell* destination) { } } + + /*bool canAttack(int distance) { }*/ -//TODO: real_x_, real_y_, ptr to player +//TODO: real_x_, real_y_ diff --git a/unit.h b/unit.h index 280ef4a..4b54182 100644 --- a/unit.h +++ b/unit.h @@ -23,9 +23,10 @@ class Unit { std::vector skills_; private: - //personal growth + //personal information double experience_; double level_; + std::string race_; //lower case //actions and events double initiative_; @@ -33,6 +34,8 @@ class Unit { //movement Cell* location_; double movement_points_; //how many cells can move for one activity point + double real_x_; + double real_y_; //attack action double agility_; @@ -97,17 +100,26 @@ class Unit { double getPhysicDefence(); void setPhysicDefence(double value); + std::string getRace(); + void setRace(std::string new_race); + + double getRealX(); + void setRealX(double x); + + double getRealY(); + void setRealY(double y); + virtual void calculateDamagePerHit(); - double reduceIncomingDamage(std::string damageType, int value); + virtual double reduceIncomingDamage(std::string damageType, int value); int lenOfActualPath(Cell* destination); - bool canMoveForDistance(int distance); + virtual bool canMoveForDistance(int distance); - bool canMoveToCell(Cell* destination); + virtual bool canMoveToCell(Cell* destination); - void moveToCell(Cell* destination); + virtual void moveToCell(Cell* destination); // bool canAttackForDistance(int distance); }; \ No newline at end of file From fd1bc6d9831e13683fba6beb345a00ae9a761079 Mon Sep 17 00:00:00 2001 From: GeorgeKolog Date: Fri, 9 Mar 2018 19:45:54 +0300 Subject: [PATCH 06/17] Added class Cell. Add class Unit to #includes --- Cell.cpp | 195 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ Cell.h | 59 +++++++++++++++++ 2 files changed, 254 insertions(+) create mode 100644 Cell.cpp create mode 100644 Cell.h diff --git a/Cell.cpp b/Cell.cpp new file mode 100644 index 0000000..175b407 --- /dev/null +++ b/Cell.cpp @@ -0,0 +1,195 @@ +#include "Cell.h" +#include +#include +//*************** +// +// +// +//*************** +struct Unit { + bool canAttack(int distance) { + return true; + } +}; + +Cell::Cell(Unit & character) { + upLeft_ = up_ = upRight_ = nullptr; + downLeft_ = down_ = downRight_ = nullptr; + character_ = &character; + clearCell_(); + AddedToQuery_ = true; +} + +Cell * Cell::getUpLeft() { + return upLeft_; +} +void Cell::setUpLeft(Cell * t) { + upLeft_ = t; +} +Cell * Cell::getUp() { + return up_; +} +void Cell::setUp(Cell * t) { + up_ = t; +} +Cell * Cell::getUpRight() { + return upRight_; +} +void Cell::setUpRight(Cell * t) { + upRight_ = t; +} +Cell * Cell::getDownLeft() { + return downLeft_; +} +void Cell::setDownLeft(Cell * t) { + downLeft_ = t; +} +Cell * Cell::getDown() { + return down_; +} +void Cell::setDown(Cell * t) { + down_ = t; +} +Cell * Cell::getDownRight() { + return downRight_; +} +void Cell::setDownRight(Cell * t) { + downRight_ = t; +} +Unit * Cell::getCharacter() { + return character_; +} +void Cell::setCharacter(Unit * t) { + character_ = t; +} +bool Cell::getisMoveable() { + return isMoveable_; +} +void Cell::setisMoveable(bool t) { + isMoveable_ = t; +} +bool Cell::getisAttackable() { + return isAttackable_; +} +void Cell::setisAttackable(bool t) { + isAttackable_ = t; +} +int Cell::getDistance() { + return distance_; +} +void Cell::setDistance(int t) { + distance_ = t; +} +bool Cell::isEmpty() { + return character_ == NULL; +} + +void Cell::clearCell_() { + setisMoveable(false); + setisAttackable(false); + setDistance(-1); +} +void Cell::clearTable_() { + std::queue q; + q.push(this); + clearCell_(); + this->AddedToQuery_ = false; + auto f = [&q](Cell * t) { + if (t && t->AddedToQuery_ == true) { + q.push(t); + t->AddedToQuery_ = false; + } + }; + while (!q.empty()) { + Cell * Now = q.front(); + q.pop(); + Now->clearCell_(); + f(Now->getUpLeft()); + f(Now->getUp()); + f(Now->getUpRight()); + f(Now->getDownLeft()); + f(Now->getDown()); + f(Now->getDownRight()); + } +} +void Cell::handleAllMoveableCellsAndUnmoveableCells_(std::queue & Q) { + std::queue q; + q.push(this); + setDistance(0); + while (!q.empty()) { + Cell * Now = q.front(); + Now->setisMoveable(true); + if (getCharacter() != NULL && getCharacter()->canAttack(Now->getDistance())) { + Now->setisAttackable(true); + } + else { + Now->setisAttackable(false); + } + q.pop(); + auto f = [&q, &Q](Cell * t, Cell * parent) { + if (t && !t->AddedToQuery_) { + t->AddedToQuery_ = true; + if (t->getCharacter() != NULL) { + t->setisMoveable(false); + Q.push(t); + return; + } + q.push(t); + t->setDistance(parent->getDistance() + 1); + } + }; + f(Now->getUpLeft(), Now); + f(Now->getUp(), Now); + f(Now->getUpRight(), Now); + f(Now->getDownLeft(), Now); + f(Now->getDown(), Now); + f(Now->getDownRight(), Now); + } +} +void Cell::handleAllUnmoveableCells_(std::queue & Q) { + while (!Q.empty()) { + Cell * Now = Q.front(); + Now->setisMoveable(false); + Now->setisAttackable(false); + Q.pop(); + auto f = [&Q](Cell * t, Cell * parent) { + if (t && !t->AddedToQuery_) { + t->AddedToQuery_ = true; + Q.push(t); + } + }; + f(Now->getUpLeft(), Now); + f(Now->getUp(), Now); + f(Now->getUpRight(), Now); + f(Now->getDownLeft(), Now); + f(Now->getDown(), Now); + f(Now->getDownRight(), Now); + } +} +void Cell::RecalculateTableWithCenterThisPoint() { + clearTable_(); + std::queue qWithoutMoveable; + handleAllMoveableCellsAndUnmoveableCells_(qWithoutMoveable); + handleAllUnmoveableCells_(qWithoutMoveable); +} +std::vector Cell::actualPath(Cell* to) {//std::vector this, end + if (!to || !to->getisMoveable())return std::vector(); + auto ret = std::vector(1, to); + while (to != this) { + Cell * parent = NULL; + auto f = [&parent](Cell * TestParent, Cell * Now) { + if (TestParent && TestParent->getDistance() + 1 == Now->getDistance() && TestParent->getisMoveable()) { + parent = TestParent; + } + }; + f(to->getUpLeft(), to); + f(to->getUp(), to); + f(to->getUpRight(), to); + f(to->getDownLeft(), to); + f(to->getDown(), to); + f(to->getDownRight(), to); + to = parent; + ret.push_back(to); + } + return ret; +} diff --git a/Cell.h b/Cell.h new file mode 100644 index 0000000..133546e --- /dev/null +++ b/Cell.h @@ -0,0 +1,59 @@ +#pragma once +#include +#include + +class Unit; + +class Cell { + +private: + Cell *upLeft_; + Cell *up_; + Cell *upRight_; + Cell * downLeft_; + Cell *down_; + Cell *downRight_; + + Unit *character_; + + bool isMoveable_; + bool isAttackable_; + + int distance_; + bool AddedToQuery_; + + void clearTable_(); + void clearCell_(); + + void handleAllMoveableCellsAndUnmoveableCells_(std::queue & Q); + void handleAllUnmoveableCells_(std::queue & Q); + +public: + + explicit Cell(Unit & character); + + Cell * getUpLeft(); + void setUpLeft(Cell *); + Cell * getUp(); + void setUp(Cell *); + Cell * getUpRight(); + void setUpRight(Cell *); + Cell * getDownLeft(); + void setDownLeft(Cell *); + Cell * getDown(); + void setDown(Cell *); + Cell * getDownRight(); + void setDownRight(Cell *); + Unit * getCharacter(); + void setCharacter(Unit *); + bool getisMoveable(); + void setisMoveable(bool); + bool getisAttackable(); + void setisAttackable(bool); + int getDistance(); + void setDistance(int); + bool isEmpty(); + + void RecalculateTableWithCenterThisPoint(); + std::vector actualPath(Cell*); +}; \ No newline at end of file From 147b13576e8b7052919c848e693b907ab1adcad6 Mon Sep 17 00:00:00 2001 From: GeorgeKologermanskiy <34199416+GeorgeKologermanskiy@users.noreply.github.com> Date: Fri, 9 Mar 2018 19:48:56 +0300 Subject: [PATCH 07/17] Create tmp --- tmp | 1 + 1 file changed, 1 insertion(+) create mode 100644 tmp diff --git a/tmp b/tmp new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/tmp @@ -0,0 +1 @@ + From f984ef11983d2e18213c91b099388b585264d866 Mon Sep 17 00:00:00 2001 From: GeorgeKolog Date: Fri, 9 Mar 2018 19:53:33 +0300 Subject: [PATCH 08/17] Fixed unit.h. Don't tested --- Cell.cpp | 11 +---------- Cell.h | 3 ++- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/Cell.cpp b/Cell.cpp index 175b407..76faa18 100644 --- a/Cell.cpp +++ b/Cell.cpp @@ -1,16 +1,7 @@ #include "Cell.h" +#include "unit.h" #include #include -//*************** -// -// -// -//*************** -struct Unit { - bool canAttack(int distance) { - return true; - } -}; Cell::Cell(Unit & character) { upLeft_ = up_ = upRight_ = nullptr; diff --git a/Cell.h b/Cell.h index 133546e..3eef4ca 100644 --- a/Cell.h +++ b/Cell.h @@ -10,6 +10,7 @@ class Cell { Cell *upLeft_; Cell *up_; Cell *upRight_; + Cell * downLeft_; Cell *down_; Cell *downRight_; @@ -56,4 +57,4 @@ class Cell { void RecalculateTableWithCenterThisPoint(); std::vector actualPath(Cell*); -}; \ No newline at end of file +}; From e1d04e1460c29dbda8648962e9bd622a1c26b8aa Mon Sep 17 00:00:00 2001 From: GeorgeKologermanskiy <34199416+GeorgeKologermanskiy@users.noreply.github.com> Date: Fri, 9 Mar 2018 20:00:01 +0300 Subject: [PATCH 09/17] Update Cell.cpp --- Cell.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/Cell.cpp b/Cell.cpp index 175b407..db35e8e 100644 --- a/Cell.cpp +++ b/Cell.cpp @@ -1,11 +1,7 @@ #include "Cell.h" #include #include -//*************** -// -// -// -//*************** + struct Unit { bool canAttack(int distance) { return true; @@ -172,7 +168,7 @@ void Cell::RecalculateTableWithCenterThisPoint() { handleAllMoveableCellsAndUnmoveableCells_(qWithoutMoveable); handleAllUnmoveableCells_(qWithoutMoveable); } -std::vector Cell::actualPath(Cell* to) {//std::vector this, end +std::vector Cell::actualPath(Cell* to) {//std::vector âêëþ÷àåòñÿ â ñåáÿ è this, è end if (!to || !to->getisMoveable())return std::vector(); auto ret = std::vector(1, to); while (to != this) { From 5d3d09c298d99d0375e5f889206ac95d2b151f47 Mon Sep 17 00:00:00 2001 From: noath Date: Sat, 10 Mar 2018 02:48:38 +0300 Subject: [PATCH 10/17] last personal traits --- unit.cpp | 67 +++++++++++++++++++++++++++++++------------------------- unit.h | 65 +++++++++++++++++++++++++++++++++++++++++++----------- 2 files changed, 89 insertions(+), 43 deletions(-) diff --git a/unit.cpp b/unit.cpp index eb91341..43c0d2d 100644 --- a/unit.cpp +++ b/unit.cpp @@ -28,20 +28,6 @@ void Unit::setHealthPoints(double value) { health_points_ = value; } -double Unit::getManaPoints() { - return mana_points_; -} -void Unit::setManaPoints(double value) { - mana_points_ = value; -} - -double Unit::getEnergyPoints() { - return energy_points_; -} -void Unit::setEnergyPoints(double value) { - energy_points_ = value; -} - double Unit::getAttackRange() { return attack_range_; } @@ -49,6 +35,13 @@ void Unit::setAttackRange(double value) { attack_range_ = value; } +int Unit::getActivityPoints(){ + return activity_points_; +} +void Unit::setActivityPoints(int value){ + activity_points_ = value; +} + Cell* Unit::getLocation() { return location_; } @@ -56,11 +49,18 @@ void Unit::setLocation(Cell* to) { location_ = to; } -int Unit::getMovementPoints() { - return movement_points_; +int Unit::getMovementSpeed() { + return movement_speed_; } -void Unit::setMovementPoints(int value) { - movement_points_ = value; +void Unit::setMovementSpeed(int value) { + movement_speed_ = value; +} + +int Unit::getAttackSpeed(){ + return attack_speed_; +} +void Unit::setAttackSpeed(int value){ + attack_speed_ = value; } double Unit::getInitiative() { @@ -98,6 +98,13 @@ void Unit::setAgility(double value) { agility_ = value; } +int Unit::getAttackPoints(){ + return attack_speed_; +} +void Unit::setAttackPoints(int value){ + attack_speed_ = value; +} + double Unit::getMagicDefence() { return magic_defence_; } @@ -155,27 +162,27 @@ int Unit::lenOfActualPath(Cell* destination) { } bool Unit::canMoveForDistance(int distance) { - return (movement_points_ >= distance); + return (movement_speed_ >= distance); } bool Unit::canMoveToCell(Cell* destination) { - return (destination->isEmpty() && canMoveForDistance(lenOfActualPath(destination))); -} + return (destination->isEmpty() && lenOfActualPath(destination) > 0 && canMoveForDistance(lenOfActualPath(destination))); +} void Unit::moveToCell(Cell* destination) { - if (!canMoveToCell) + if (!canMoveToCell(destination)) return; //here could be a gui-message about failed move (x-mark, for example) else { - int decreasedValue = getMovementPoints() - lenOfActualPath(destination); - setMovementPoints(decreasedValue); + int decreasedValue = getMovementSpeed() - lenOfActualPath(destination); + setMovementSpeed(decreasedValue); setLocation(destination); } } +int main() { + std::cout << "Hello, world!\n"; +} - -/*bool canAttack(int distance) { - -}*/ - -//TODO: real_x_, real_y_ +bool MeleeUnit::canAttackForDistance(int distance) { +// if +} diff --git a/unit.h b/unit.h index 4b54182..b079f0a 100644 --- a/unit.h +++ b/unit.h @@ -30,10 +30,11 @@ class Unit { //actions and events double initiative_; + int activity_points_; //movement Cell* location_; - double movement_points_; //how many cells can move for one activity point + int movement_speed_; //how many cells can move for one activity point double real_x_; double real_y_; @@ -41,10 +42,9 @@ class Unit { double agility_; double attack_range_; double damage_per_hit_; - double energy_points_; //for physical attacks double intelligence_; - double mana_points_; //for magic attacks double strength_; + int attack_cost_; //how many activity points does attack cost //durability double health_points_; @@ -64,20 +64,20 @@ class Unit { double getHealthPoints(); void setHealthPoints(double value); - double getManaPoints(); - void setManaPoints(double value); - - double getEnergyPoints(); - void setEnergyPoints(double value); - double getAttackRange(); void setAttackRange(double value); + int getActivityPoints(); + void setActivityPoints(int value); + Cell* getLocation(); void setLocation(Cell* to); - int getMovementPoints(); - void setMovementPoints(int value); + int getMovementSpeed(); + void setMovementSpeed(int value); + + int getAttackCost(); + void setAttackCost(int value); double getInitiative(); void setInitiative(double value); @@ -94,6 +94,9 @@ class Unit { double getAgility(); void setAgility(double value); + int getAttackPoints(); + void setAttackPoints(int value); + double getMagicDefence(); void setMagicDefence(double value); @@ -121,5 +124,41 @@ class Unit { virtual void moveToCell(Cell* destination); -// bool canAttackForDistance(int distance); -}; \ No newline at end of file + virtual bool canAttackForDistance(int distance) = 0; + + virtual bool canAttackToCell(Cell* destination) = 0; + + virtual bool canAttackUnit(Unit* target) = 0; +}; + +class MeleeUnit : public Unit { +protected: +private: + +public: + virtual ~MeleeUnit() = delete; + + virtual bool canAttackForDistance(int distance); + + virtual bool canAttackToCell(Cell* destination); + + virtual bool canAttackUnit(Unit* target); + +}; + +class RangeUnit : public Unit { +protected: +private: + +public: + virtual ~RangeUnit() = delete; +}; + +template +class AbstractUnitCreator { +public: + AbstractUnitCreator() {} + virtual ~AbstractUnitCreator() {} + virtual Base* create() const = 0; +}; + From 8fd16fb186788c1fd5d22413804c1632dae2d6b4 Mon Sep 17 00:00:00 2001 From: GeorgeKologermanskiy <34199416+GeorgeKologermanskiy@users.noreply.github.com> Date: Sun, 11 Mar 2018 15:32:36 +0300 Subject: [PATCH 11/17] delete tmp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Нахуй он здесь не нужен --- tmp | 1 - 1 file changed, 1 deletion(-) delete mode 100644 tmp diff --git a/tmp b/tmp deleted file mode 100644 index 8b13789..0000000 --- a/tmp +++ /dev/null @@ -1 +0,0 @@ - From 214a2b8f8aceaa11d10ef473e90672ad17af37b1 Mon Sep 17 00:00:00 2001 From: noath Date: Sun, 11 Mar 2018 15:48:07 +0300 Subject: [PATCH 12/17] added cost --- unit.cpp | 20 ++++++++++++++------ unit.h | 43 +++++++++---------------------------------- 2 files changed, 23 insertions(+), 40 deletions(-) diff --git a/unit.cpp b/unit.cpp index 43c0d2d..19547ad 100644 --- a/unit.cpp +++ b/unit.cpp @@ -7,6 +7,14 @@ Unit::Unit() {} +int Unit::getCost(){ + return cost_; +} + +void Unit::setCost(int value){ + cost_ = value; +} + double Unit::getExperience() { return experience_; } @@ -56,11 +64,11 @@ void Unit::setMovementSpeed(int value) { movement_speed_ = value; } -int Unit::getAttackSpeed(){ - return attack_speed_; +int Unit::getAttackCost(){ + return attack_cost_; } -void Unit::setAttackSpeed(int value){ - attack_speed_ = value; +void Unit::setAttackCost(int value){ + attack_cost_ = value; } double Unit::getInitiative() { @@ -99,10 +107,10 @@ void Unit::setAgility(double value) { } int Unit::getAttackPoints(){ - return attack_speed_; + return attack_cost_; } void Unit::setAttackPoints(int value){ - attack_speed_ = value; + attack_cost_ = value; } double Unit::getMagicDefence() { diff --git a/unit.h b/unit.h index b079f0a..0e53c54 100644 --- a/unit.h +++ b/unit.h @@ -24,6 +24,7 @@ class Unit { private: //personal information + int cost_; double experience_; double level_; std::string race_; //lower case @@ -52,9 +53,15 @@ class Unit { double physic_defence_; //less or equal 40 public: - Unit(); + Unit() = delete; + Unit(std::string path) { + + } virtual ~Unit() = delete; + int getCost(); + void setCost(int value); + double getExperience(); void setExperience(double value); @@ -129,36 +136,4 @@ class Unit { virtual bool canAttackToCell(Cell* destination) = 0; virtual bool canAttackUnit(Unit* target) = 0; -}; - -class MeleeUnit : public Unit { -protected: -private: - -public: - virtual ~MeleeUnit() = delete; - - virtual bool canAttackForDistance(int distance); - - virtual bool canAttackToCell(Cell* destination); - - virtual bool canAttackUnit(Unit* target); - -}; - -class RangeUnit : public Unit { -protected: -private: - -public: - virtual ~RangeUnit() = delete; -}; - -template -class AbstractUnitCreator { -public: - AbstractUnitCreator() {} - virtual ~AbstractUnitCreator() {} - virtual Base* create() const = 0; -}; - +}; \ No newline at end of file From 9ebde2aa293414c9d7c9f52d25b9a50242b4a1f8 Mon Sep 17 00:00:00 2001 From: GeorgeKolog Date: Sun, 11 Mar 2018 17:10:57 +0300 Subject: [PATCH 13/17] Fixed orientation, wait for method canAttack from Unit --- Cell.cpp | 163 +++++++++++++++++++++++++++++++------------------------ Cell.h | 56 +++++++++++-------- 2 files changed, 126 insertions(+), 93 deletions(-) diff --git a/Cell.cpp b/Cell.cpp index 06c2f59..c8150ce 100644 --- a/Cell.cpp +++ b/Cell.cpp @@ -1,76 +1,94 @@ #include "Cell.h" -#include "unit.h" +//#include "unit.h" #include #include +/* + * Добавьте в Unit эту функцию + */ +class Unit { +public: + bool СanAttack(int) { return true; } +}; + Cell::Cell(Unit & character) { - upLeft_ = up_ = upRight_ = nullptr; - downLeft_ = down_ = downRight_ = nullptr; + leftUp_ = left_ = leftDown_ = nullptr; + rightUp_ = right_ = rightDown_ = nullptr; character_ = &character; clearCell_(); AddedToQuery_ = true; } -Cell * Cell::getUpLeft() { - return upLeft_; +Cell * Cell::getleftUp() { + return leftUp_; } -void Cell::setUpLeft(Cell * t) { - upLeft_ = t; +void Cell::setleftUp(Cell * t) { + leftUp_ = t; } -Cell * Cell::getUp() { - return up_; + +Cell * Cell::getleft() { + return left_; } -void Cell::setUp(Cell * t) { - up_ = t; +void Cell::setleft(Cell * t) { + left_ = t; } -Cell * Cell::getUpRight() { - return upRight_; + +Cell * Cell::getleftDown() { + return leftDown_; } -void Cell::setUpRight(Cell * t) { - upRight_ = t; +void Cell::setleftDown(Cell * t) { + leftDown_ = t; } -Cell * Cell::getDownLeft() { - return downLeft_; + +Cell * Cell::getrightUp() { + return rightUp_; } -void Cell::setDownLeft(Cell * t) { - downLeft_ = t; +void Cell::setrightUp(Cell * t) { + rightUp_ = t; } -Cell * Cell::getDown() { - return down_; + +Cell * Cell::getright() { + return right_; } -void Cell::setDown(Cell * t) { - down_ = t; +void Cell::setright(Cell * t) { + right_ = t; } -Cell * Cell::getDownRight() { - return downRight_; + +Cell * Cell::getrightDown() { + return rightDown_; } -void Cell::setDownRight(Cell * t) { - downRight_ = t; +void Cell::setrightDown(Cell * t) { + rightDown_ = t; } + Unit * Cell::getCharacter() { return character_; } void Cell::setCharacter(Unit * t) { character_ = t; } + bool Cell::getisMoveable() { return isMoveable_; } void Cell::setisMoveable(bool t) { isMoveable_ = t; } + bool Cell::getisAttackable() { return isAttackable_; } void Cell::setisAttackable(bool t) { isAttackable_ = t; } + int Cell::getDistance() { return distance_; } void Cell::setDistance(int t) { distance_ = t; } + bool Cell::isEmpty() { return character_ == NULL; } @@ -80,6 +98,7 @@ void Cell::clearCell_() { setisAttackable(false); setDistance(-1); } + void Cell::clearTable_() { std::queue q; q.push(this); @@ -95,74 +114,78 @@ void Cell::clearTable_() { Cell * Now = q.front(); q.pop(); Now->clearCell_(); - f(Now->getUpLeft()); - f(Now->getUp()); - f(Now->getUpRight()); - f(Now->getDownLeft()); - f(Now->getDown()); - f(Now->getDownRight()); + f(Now->getleftUp()); + f(Now->getleft()); + f(Now->getleftDown()); + f(Now->getrightUp()); + f(Now->getright()); + f(Now->getrightDown()); } } + void Cell::handleAllMoveableCellsAndUnmoveableCells_(std::queue & Q) { std::queue q; q.push(this); setDistance(0); + auto f = [&q, &Q](Cell * t, Cell * parent) { + if (t && !t->AddedToQuery_) { + t->AddedToQuery_ = true; + if (t->getCharacter() != NULL) { + t->setisMoveable(false); + Q.push(t); + return; + } + q.push(t); + t->setDistance(parent->getDistance() + 1); + } + }; while (!q.empty()) { Cell * Now = q.front(); Now->setisMoveable(true); - if (getCharacter() != NULL && getCharacter()->canAttack(Now->getDistance())) { + if (getCharacter() != NULL && getCharacter()->СanAttack(Now->getDistance())) { Now->setisAttackable(true); } else { Now->setisAttackable(false); } q.pop(); - auto f = [&q, &Q](Cell * t, Cell * parent) { - if (t && !t->AddedToQuery_) { - t->AddedToQuery_ = true; - if (t->getCharacter() != NULL) { - t->setisMoveable(false); - Q.push(t); - return; - } - q.push(t); - t->setDistance(parent->getDistance() + 1); - } - }; - f(Now->getUpLeft(), Now); - f(Now->getUp(), Now); - f(Now->getUpRight(), Now); - f(Now->getDownLeft(), Now); - f(Now->getDown(), Now); - f(Now->getDownRight(), Now); + f(Now->getleftUp(), Now); + f(Now->getleft(), Now); + f(Now->getleftDown(), Now); + f(Now->getrightUp(), Now); + f(Now->getright(), Now); + f(Now->getrightDown(), Now); } } + void Cell::handleAllUnmoveableCells_(std::queue & Q) { + auto f = [&Q](Cell * t, Cell * parent) { + if (t && !t->AddedToQuery_) { + t->AddedToQuery_ = true; + Q.push(t); + } + }; while (!Q.empty()) { Cell * Now = Q.front(); Now->setisMoveable(false); Now->setisAttackable(false); Q.pop(); - auto f = [&Q](Cell * t, Cell * parent) { - if (t && !t->AddedToQuery_) { - t->AddedToQuery_ = true; - Q.push(t); - } - }; - f(Now->getUpLeft(), Now); - f(Now->getUp(), Now); - f(Now->getUpRight(), Now); - f(Now->getDownLeft(), Now); - f(Now->getDown(), Now); - f(Now->getDownRight(), Now); + f(Now->getleftUp(), Now); + f(Now->getleft(), Now); + f(Now->getleftDown(), Now); + f(Now->getrightUp(), Now); + f(Now->getright(), Now); + f(Now->getrightDown(), Now); } } + void Cell::RecalculateTableWithCenterThisPoint() { clearTable_(); std::queue qWithoutMoveable; handleAllMoveableCellsAndUnmoveableCells_(qWithoutMoveable); handleAllUnmoveableCells_(qWithoutMoveable); } + std::vector Cell::actualPath(Cell* to) {//std::vector âêëþ÷àåòñÿ â ñåáÿ è this, è end if (!to || !to->getisMoveable())return std::vector(); auto ret = std::vector(1, to); @@ -173,12 +196,12 @@ std::vector Cell::actualPath(Cell* to) {//std::vector âêëþ÷ parent = TestParent; } }; - f(to->getUpLeft(), to); - f(to->getUp(), to); - f(to->getUpRight(), to); - f(to->getDownLeft(), to); - f(to->getDown(), to); - f(to->getDownRight(), to); + f(to->getleftUp(), to); + f(to->getleft(), to); + f(to->getleftDown(), to); + f(to->getrightUp(), to); + f(to->getright(), to); + f(to->getrightDown(), to); to = parent; ret.push_back(to); } diff --git a/Cell.h b/Cell.h index 3eef4ca..bb527fb 100644 --- a/Cell.h +++ b/Cell.h @@ -7,52 +7,62 @@ class Unit; class Cell { private: - Cell *upLeft_; - Cell *up_; - Cell *upRight_; - - Cell * downLeft_; - Cell *down_; - Cell *downRight_; + Cell * leftUp_; + Cell *left_; + Cell * leftDown_; + + Cell *rightUp_; + Cell *right_; + Cell *rightDown_; Unit *character_; - + bool isMoveable_; bool isAttackable_; - + int distance_; bool AddedToQuery_; void clearTable_(); void clearCell_(); - + void handleAllMoveableCellsAndUnmoveableCells_(std::queue & Q); void handleAllUnmoveableCells_(std::queue & Q); public: - + explicit Cell(Unit & character); + + Cell * getleftUp(); + void setleftUp(Cell *); + + Cell * getleft(); + void setleft(Cell *); + + Cell * getleftDown(); + void setleftDown(Cell *); + + Cell * getrightUp(); + void setrightUp(Cell *); + + Cell * getright(); + void setright(Cell *); + + Cell * getrightDown(); + void setrightDown(Cell *); - Cell * getUpLeft(); - void setUpLeft(Cell *); - Cell * getUp(); - void setUp(Cell *); - Cell * getUpRight(); - void setUpRight(Cell *); - Cell * getDownLeft(); - void setDownLeft(Cell *); - Cell * getDown(); - void setDown(Cell *); - Cell * getDownRight(); - void setDownRight(Cell *); Unit * getCharacter(); void setCharacter(Unit *); + bool getisMoveable(); void setisMoveable(bool); + bool getisAttackable(); void setisAttackable(bool); + int getDistance(); void setDistance(int); + bool isEmpty(); void RecalculateTableWithCenterThisPoint(); From 602a2e71b9a8f25d97e63f7c7d952b9fb608754e Mon Sep 17 00:00:00 2001 From: noath Date: Sun, 11 Mar 2018 18:40:53 +0300 Subject: [PATCH 14/17] added parent/child specs --- unit.cpp | 19 ++++++++++++++++--- unit.h | 12 ++++++++++-- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/unit.cpp b/unit.cpp index 19547ad..4d8c297 100644 --- a/unit.cpp +++ b/unit.cpp @@ -15,6 +15,22 @@ void Unit::setCost(int value){ cost_ = value; } +std::string Unit::getParentSpec(){ + return parent_spec_; +} + +void Unit::setParentSpec(std::string specId){ + parent_spec_ = specId; +} + +std::vector Unit::getUpgradeSpecs(){ + return upgrade_specs_; +} + +void Unit::setUpgradeSpecs(std::vector specs){ + upgrade_specs_ = specs; +} + double Unit::getExperience() { return experience_; } @@ -191,6 +207,3 @@ int main() { std::cout << "Hello, world!\n"; } -bool MeleeUnit::canAttackForDistance(int distance) { -// if -} diff --git a/unit.h b/unit.h index 0e53c54..7b8d9b5 100644 --- a/unit.h +++ b/unit.h @@ -3,7 +3,7 @@ #include class Spell { - //waiting for a realisation + //waiting }; class Cell { //waiting for a realisation @@ -25,6 +25,8 @@ class Unit { private: //personal information int cost_; + std::string parent_spec_; + std::vector upgrade_specs_; double experience_; double level_; std::string race_; //lower case @@ -62,6 +64,12 @@ class Unit { int getCost(); void setCost(int value); + std::string getParentSpec(); + void setParentSpec(std::string specId); + + std::vector getUpgradeSpecs(); + void setUpgradeSpecs(std::vector specs); + double getExperience(); void setExperience(double value); @@ -130,7 +138,7 @@ class Unit { virtual bool canMoveToCell(Cell* destination); virtual void moveToCell(Cell* destination); - + virtual bool canAttackForDistance(int distance) = 0; virtual bool canAttackToCell(Cell* destination) = 0; From f87cdbef63db26d06d42905103b53ccae1ac68b9 Mon Sep 17 00:00:00 2001 From: noath Date: Mon, 12 Mar 2018 16:38:36 +0300 Subject: [PATCH 15/17] fixed classes definition for Cell and Spells --- unit.cpp | 10 ++-------- unit.h | 8 ++++---- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/unit.cpp b/unit.cpp index 4d8c297..df7fc0c 100644 --- a/unit.cpp +++ b/unit.cpp @@ -4,8 +4,7 @@ #include #include #include "unit.h" - -Unit::Unit() {} +#include "AbstractFactory.h" int Unit::getCost(){ return cost_; @@ -201,9 +200,4 @@ void Unit::moveToCell(Cell* destination) { setMovementSpeed(decreasedValue); setLocation(destination); } -} - -int main() { - std::cout << "Hello, world!\n"; -} - +} \ No newline at end of file diff --git a/unit.h b/unit.h index 7b8d9b5..18a06a5 100644 --- a/unit.h +++ b/unit.h @@ -1,14 +1,14 @@ #pragma once #include #include +#include "AbstractFactory.h" -class Spell { - //waiting -}; +class Spell; class Cell { //waiting for a realisation public: - bool isEmpty() { + //must be in cell.h + bool isEmpty() { return true; } std::vector actualPath(Cell* destination) { //the shortest existing path from (*this) to (*destination) From f3dcb10b71c6ff6d3ce04c5f57d8afb44205a5bd Mon Sep 17 00:00:00 2001 From: GeorgeKolog Date: Sun, 18 Mar 2018 00:24:53 +0300 Subject: [PATCH 16/17] =?UTF-8?q?Fixed=20And=20Tested=20Cells.=20=D0=92?= =?UTF-8?q?=D0=B0=D0=BD=D1=8F=20=D0=BD=D0=B5=20=D1=82=D1=80=D0=BE=D0=B3?= =?UTF-8?q?=D0=B0=D0=B9=20=D0=B7=D0=B0=20=D0=BA=D0=BE=D0=B4=D0=A1=D0=A2?= =?UTF-8?q?=D0=90=D0=99=D0=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cell.cpp | 177 +++++++++++++++++++++++++++++++++---------------------- Cell.h | 73 ++++++++++++----------- 2 files changed, 145 insertions(+), 105 deletions(-) diff --git a/Cell.cpp b/Cell.cpp index c8150ce..c7ad0ed 100644 --- a/Cell.cpp +++ b/Cell.cpp @@ -8,57 +8,60 @@ */ class Unit { public: - bool СanAttack(int) { return true; } + bool canAttackForDistance(int) { return true; } + bool canAttackUnit(Unit*) { return true; } }; -Cell::Cell(Unit & character) { - leftUp_ = left_ = leftDown_ = nullptr; - rightUp_ = right_ = rightDown_ = nullptr; - character_ = &character; +Cell::Cell(Unit * character) { + left_up_ = left_ = left_down_ = nullptr; + right_up_ = right_ = right_down_ = nullptr; + character_ = character; clearCell_(); AddedToQuery_ = true; } -Cell * Cell::getleftUp() { - return leftUp_; +Cell::Cell(int i, int j) :i(i), j(j), AddedToQuery_(true) {} + +Cell * Cell::getLeftUp() { + return left_up_; } -void Cell::setleftUp(Cell * t) { - leftUp_ = t; +void Cell::setLeftUp(Cell * t) { + left_up_ = t; } -Cell * Cell::getleft() { +Cell * Cell::getLeft() { return left_; } -void Cell::setleft(Cell * t) { +void Cell::setLeft(Cell * t) { left_ = t; } -Cell * Cell::getleftDown() { - return leftDown_; +Cell * Cell::getLeftDown() { + return left_down_; } -void Cell::setleftDown(Cell * t) { - leftDown_ = t; +void Cell::setLeftDown(Cell * t) { + left_down_ = t; } -Cell * Cell::getrightUp() { - return rightUp_; +Cell * Cell::getRightUp() { + return right_up_; } -void Cell::setrightUp(Cell * t) { - rightUp_ = t; +void Cell::setRightUp(Cell * t) { + right_up_ = t; } -Cell * Cell::getright() { +Cell * Cell::getRight() { return right_; } -void Cell::setright(Cell * t) { +void Cell::setRight(Cell * t) { right_ = t; } -Cell * Cell::getrightDown() { - return rightDown_; +Cell * Cell::getRightDown() { + return right_down_; } -void Cell::setrightDown(Cell * t) { - rightDown_ = t; +void Cell::setRightDown(Cell * t) { + right_down_ = t; } Unit * Cell::getCharacter() { @@ -68,17 +71,17 @@ void Cell::setCharacter(Unit * t) { character_ = t; } -bool Cell::getisMoveable() { +bool Cell::getIsMoveable() { return isMoveable_; } -void Cell::setisMoveable(bool t) { +void Cell::setIsMoveable(bool t) { isMoveable_ = t; } -bool Cell::getisAttackable() { +bool Cell::getIsAttackable() { return isAttackable_; } -void Cell::setisAttackable(bool t) { +void Cell::setIsAttackable(bool t) { isAttackable_ = t; } @@ -94,15 +97,17 @@ bool Cell::isEmpty() { } void Cell::clearCell_() { - setisMoveable(false); - setisAttackable(false); + setIsMoveable(false); setDistance(-1); } -void Cell::clearTable_() { +void Cell::clearTable_(bool NeedClearCell = true) { std::queue q; q.push(this); - clearCell_(); + setIsAttackable(false); + if (NeedClearCell) { + clearCell_(); + } this->AddedToQuery_ = false; auto f = [&q](Cell * t) { if (t && t->AddedToQuery_ == true) { @@ -113,13 +118,16 @@ void Cell::clearTable_() { while (!q.empty()) { Cell * Now = q.front(); q.pop(); - Now->clearCell_(); - f(Now->getleftUp()); - f(Now->getleft()); - f(Now->getleftDown()); - f(Now->getrightUp()); - f(Now->getright()); - f(Now->getrightDown()); + Now->setIsAttackable(false); + if (NeedClearCell) { + Now->clearCell_(); + } + f(Now->getLeftUp()); + f(Now->getLeft()); + f(Now->getLeftDown()); + f(Now->getRightUp()); + f(Now->getRight()); + f(Now->getRightDown()); } } @@ -127,34 +135,38 @@ void Cell::handleAllMoveableCellsAndUnmoveableCells_(std::queue & Q) { std::queue q; q.push(this); setDistance(0); + AddedToQuery_ = true; + setIsMoveable(true); + setIsAttackable(true); auto f = [&q, &Q](Cell * t, Cell * parent) { if (t && !t->AddedToQuery_) { t->AddedToQuery_ = true; + t->setDistance(parent->getDistance() + 1); if (t->getCharacter() != NULL) { - t->setisMoveable(false); + t->setIsMoveable(false); Q.push(t); return; } q.push(t); - t->setDistance(parent->getDistance() + 1); } }; while (!q.empty()) { Cell * Now = q.front(); - Now->setisMoveable(true); - if (getCharacter() != NULL && getCharacter()->СanAttack(Now->getDistance())) { - Now->setisAttackable(true); + Now->setIsMoveable(true); + if (getCharacter() != NULL && getCharacter()->canAttackForDistance(Now->getDistance()) && + (Now->getCharacter() == NULL || getCharacter()->canAttackUnit(Now->getCharacter()))) { + Now->setIsAttackable(true); } else { - Now->setisAttackable(false); + Now->setIsAttackable(false); } q.pop(); - f(Now->getleftUp(), Now); - f(Now->getleft(), Now); - f(Now->getleftDown(), Now); - f(Now->getrightUp(), Now); - f(Now->getright(), Now); - f(Now->getrightDown(), Now); + f(Now->getLeftUp(), Now); + f(Now->getLeft(), Now); + f(Now->getLeftDown(), Now); + f(Now->getRightUp(), Now); + f(Now->getRight(), Now); + f(Now->getRightDown(), Now); } } @@ -162,46 +174,71 @@ void Cell::handleAllUnmoveableCells_(std::queue & Q) { auto f = [&Q](Cell * t, Cell * parent) { if (t && !t->AddedToQuery_) { t->AddedToQuery_ = true; + t->setDistance(parent->getDistance() + 1); Q.push(t); } }; while (!Q.empty()) { Cell * Now = Q.front(); - Now->setisMoveable(false); - Now->setisAttackable(false); + Now->setIsMoveable(false); + Now->setIsAttackable(false); Q.pop(); - f(Now->getleftUp(), Now); - f(Now->getleft(), Now); - f(Now->getleftDown(), Now); - f(Now->getrightUp(), Now); - f(Now->getright(), Now); - f(Now->getrightDown(), Now); + f(Now->getLeftUp(), Now); + f(Now->getLeft(), Now); + f(Now->getLeftDown(), Now); + f(Now->getRightUp(), Now); + f(Now->getRight(), Now); + f(Now->getRightDown(), Now); } } -void Cell::RecalculateTableWithCenterThisPoint() { +void Cell::recalculateTableWithCenterThisPoint() { clearTable_(); std::queue qWithoutMoveable; handleAllMoveableCellsAndUnmoveableCells_(qWithoutMoveable); handleAllUnmoveableCells_(qWithoutMoveable); } -std::vector Cell::actualPath(Cell* to) {//std::vector âêëþ÷àåòñÿ â ñåáÿ è this, è end - if (!to || !to->getisMoveable())return std::vector(); +void Cell::buffTableinDistance(int distance) { + clearTable_(false); + std::queue q; + q.push(this); + setIsAttackable(true); + auto f = [&q, &distance](Cell * Now) { + if (Now != NULL && Now->getDistance() <= distance && !Now->AddedToQuery_) { + q.push(Now); + Now->AddedToQuery_ = true; + Now->setIsAttackable(true); + } + }; + while (!q.empty()) { + Cell * Now = q.front(); + q.pop(); + f(Now->getLeftUp()); + f(Now->getLeft()); + f(Now->getLeftDown()); + f(Now->getRightUp()); + f(Now->getRight()); + f(Now->getRightDown()); + } +} + +std::vector Cell::actualPath(Cell* to) { + if (!to || !to->getIsMoveable())return std::vector(); auto ret = std::vector(1, to); while (to != this) { Cell * parent = NULL; auto f = [&parent](Cell * TestParent, Cell * Now) { - if (TestParent && TestParent->getDistance() + 1 == Now->getDistance() && TestParent->getisMoveable()) { + if (TestParent && TestParent->getDistance() + 1 == Now->getDistance() && TestParent->getIsMoveable()) { parent = TestParent; } }; - f(to->getleftUp(), to); - f(to->getleft(), to); - f(to->getleftDown(), to); - f(to->getrightUp(), to); - f(to->getright(), to); - f(to->getrightDown(), to); + f(to->getLeftUp(), to); + f(to->getLeft(), to); + f(to->getLeftDown(), to); + f(to->getRightUp(), to); + f(to->getRight(), to); + f(to->getRightDown(), to); to = parent; ret.push_back(to); } diff --git a/Cell.h b/Cell.h index bb527fb..99b990a 100644 --- a/Cell.h +++ b/Cell.h @@ -5,15 +5,15 @@ class Unit; class Cell { - + int i, j; private: - Cell * leftUp_; + Cell * left_up_; Cell *left_; - Cell * leftDown_; + Cell * left_down_; - Cell *rightUp_; + Cell *right_up_; Cell *right_; - Cell *rightDown_; + Cell *right_down_; Unit *character_; @@ -23,7 +23,7 @@ class Cell { int distance_; bool AddedToQuery_; - void clearTable_(); + void clearTable_(bool); void clearCell_(); void handleAllMoveableCellsAndUnmoveableCells_(std::queue & Q); @@ -31,40 +31,43 @@ class Cell { public: - explicit Cell(Unit & character); - - Cell * getleftUp(); - void setleftUp(Cell *); - - Cell * getleft(); - void setleft(Cell *); - - Cell * getleftDown(); - void setleftDown(Cell *); - - Cell * getrightUp(); - void setrightUp(Cell *); - - Cell * getright(); - void setright(Cell *); - - Cell * getrightDown(); - void setrightDown(Cell *); - + explicit Cell(Unit * character); + + explicit Cell(int, int); + + Cell * getLeftUp(); + void setLeftUp(Cell *); + + Cell * getLeft(); + void setLeft(Cell *); + + Cell * getLeftDown(); + void setLeftDown(Cell *); + + Cell * getRightUp(); + void setRightUp(Cell *); + + Cell * getRight(); + void setRight(Cell *); + + Cell * getRightDown(); + void setRightDown(Cell *); + Unit * getCharacter(); void setCharacter(Unit *); - - bool getisMoveable(); - void setisMoveable(bool); - - bool getisAttackable(); - void setisAttackable(bool); - + + bool getIsMoveable(); + void setIsMoveable(bool); + + bool getIsAttackable(); + void setIsAttackable(bool); + int getDistance(); void setDistance(int); - + bool isEmpty(); - void RecalculateTableWithCenterThisPoint(); + void recalculateTableWithCenterThisPoint(); + void buffTableinDistance(int); std::vector actualPath(Cell*); }; From 4c2a957b5df6bbe90dfb9b1581f4330c31dc5eba Mon Sep 17 00:00:00 2001 From: GeorgeKolog Date: Sun, 18 Mar 2018 00:27:48 +0300 Subject: [PATCH 17/17] Deleted Debug Constants. Dont see last commit --- Cell.cpp | 183 +++++++++++++++++++++---------------------------------- Cell.h | 69 ++++++++++----------- 2 files changed, 102 insertions(+), 150 deletions(-) diff --git a/Cell.cpp b/Cell.cpp index c7ad0ed..30eb540 100644 --- a/Cell.cpp +++ b/Cell.cpp @@ -1,67 +1,56 @@ #include "Cell.h" -//#include "unit.h" +#include "unit.h" #include #include -/* - * Добавьте в Unit эту функцию - */ -class Unit { -public: - bool canAttackForDistance(int) { return true; } - bool canAttackUnit(Unit*) { return true; } -}; - Cell::Cell(Unit * character) { - left_up_ = left_ = left_down_ = nullptr; - right_up_ = right_ = right_down_ = nullptr; - character_ = character; + leftUp_ = left_ = leftDown_ = nullptr; + rightUp_ = right_ = rightDown_ = nullptr; + character_ = &character; clearCell_(); AddedToQuery_ = true; } -Cell::Cell(int i, int j) :i(i), j(j), AddedToQuery_(true) {} - -Cell * Cell::getLeftUp() { - return left_up_; +Cell * Cell::getleftUp() { + return leftUp_; } -void Cell::setLeftUp(Cell * t) { - left_up_ = t; +void Cell::setleftUp(Cell * t) { + leftUp_ = t; } -Cell * Cell::getLeft() { +Cell * Cell::getleft() { return left_; } -void Cell::setLeft(Cell * t) { +void Cell::setleft(Cell * t) { left_ = t; } -Cell * Cell::getLeftDown() { - return left_down_; +Cell * Cell::getleftDown() { + return leftDown_; } -void Cell::setLeftDown(Cell * t) { - left_down_ = t; +void Cell::setleftDown(Cell * t) { + leftDown_ = t; } -Cell * Cell::getRightUp() { - return right_up_; +Cell * Cell::getrightUp() { + return rightUp_; } -void Cell::setRightUp(Cell * t) { - right_up_ = t; +void Cell::setrightUp(Cell * t) { + rightUp_ = t; } -Cell * Cell::getRight() { +Cell * Cell::getright() { return right_; } -void Cell::setRight(Cell * t) { +void Cell::setright(Cell * t) { right_ = t; } -Cell * Cell::getRightDown() { - return right_down_; +Cell * Cell::getrightDown() { + return rightDown_; } -void Cell::setRightDown(Cell * t) { - right_down_ = t; +void Cell::setrightDown(Cell * t) { + rightDown_ = t; } Unit * Cell::getCharacter() { @@ -71,17 +60,17 @@ void Cell::setCharacter(Unit * t) { character_ = t; } -bool Cell::getIsMoveable() { +bool Cell::getisMoveable() { return isMoveable_; } -void Cell::setIsMoveable(bool t) { +void Cell::setisMoveable(bool t) { isMoveable_ = t; } -bool Cell::getIsAttackable() { +bool Cell::getisAttackable() { return isAttackable_; } -void Cell::setIsAttackable(bool t) { +void Cell::setisAttackable(bool t) { isAttackable_ = t; } @@ -97,17 +86,15 @@ bool Cell::isEmpty() { } void Cell::clearCell_() { - setIsMoveable(false); + setisMoveable(false); + setisAttackable(false); setDistance(-1); } -void Cell::clearTable_(bool NeedClearCell = true) { +void Cell::clearTable_() { std::queue q; q.push(this); - setIsAttackable(false); - if (NeedClearCell) { - clearCell_(); - } + clearCell_(); this->AddedToQuery_ = false; auto f = [&q](Cell * t) { if (t && t->AddedToQuery_ == true) { @@ -118,16 +105,13 @@ void Cell::clearTable_(bool NeedClearCell = true) { while (!q.empty()) { Cell * Now = q.front(); q.pop(); - Now->setIsAttackable(false); - if (NeedClearCell) { - Now->clearCell_(); - } - f(Now->getLeftUp()); - f(Now->getLeft()); - f(Now->getLeftDown()); - f(Now->getRightUp()); - f(Now->getRight()); - f(Now->getRightDown()); + Now->clearCell_(); + f(Now->getleftUp()); + f(Now->getleft()); + f(Now->getleftDown()); + f(Now->getrightUp()); + f(Now->getright()); + f(Now->getrightDown()); } } @@ -135,38 +119,34 @@ void Cell::handleAllMoveableCellsAndUnmoveableCells_(std::queue & Q) { std::queue q; q.push(this); setDistance(0); - AddedToQuery_ = true; - setIsMoveable(true); - setIsAttackable(true); auto f = [&q, &Q](Cell * t, Cell * parent) { if (t && !t->AddedToQuery_) { t->AddedToQuery_ = true; - t->setDistance(parent->getDistance() + 1); if (t->getCharacter() != NULL) { - t->setIsMoveable(false); + t->setisMoveable(false); Q.push(t); return; } q.push(t); + t->setDistance(parent->getDistance() + 1); } }; while (!q.empty()) { Cell * Now = q.front(); - Now->setIsMoveable(true); - if (getCharacter() != NULL && getCharacter()->canAttackForDistance(Now->getDistance()) && - (Now->getCharacter() == NULL || getCharacter()->canAttackUnit(Now->getCharacter()))) { - Now->setIsAttackable(true); + Now->setisMoveable(true); + if (getCharacter() != NULL && getCharacter()->СanAttack(Now->getDistance())) { + Now->setisAttackable(true); } else { - Now->setIsAttackable(false); + Now->setisAttackable(false); } q.pop(); - f(Now->getLeftUp(), Now); - f(Now->getLeft(), Now); - f(Now->getLeftDown(), Now); - f(Now->getRightUp(), Now); - f(Now->getRight(), Now); - f(Now->getRightDown(), Now); + f(Now->getleftUp(), Now); + f(Now->getleft(), Now); + f(Now->getleftDown(), Now); + f(Now->getrightUp(), Now); + f(Now->getright(), Now); + f(Now->getrightDown(), Now); } } @@ -174,71 +154,46 @@ void Cell::handleAllUnmoveableCells_(std::queue & Q) { auto f = [&Q](Cell * t, Cell * parent) { if (t && !t->AddedToQuery_) { t->AddedToQuery_ = true; - t->setDistance(parent->getDistance() + 1); Q.push(t); } }; while (!Q.empty()) { Cell * Now = Q.front(); - Now->setIsMoveable(false); - Now->setIsAttackable(false); + Now->setisMoveable(false); + Now->setisAttackable(false); Q.pop(); - f(Now->getLeftUp(), Now); - f(Now->getLeft(), Now); - f(Now->getLeftDown(), Now); - f(Now->getRightUp(), Now); - f(Now->getRight(), Now); - f(Now->getRightDown(), Now); + f(Now->getleftUp(), Now); + f(Now->getleft(), Now); + f(Now->getleftDown(), Now); + f(Now->getrightUp(), Now); + f(Now->getright(), Now); + f(Now->getrightDown(), Now); } } -void Cell::recalculateTableWithCenterThisPoint() { +void Cell::RecalculateTableWithCenterThisPoint() { clearTable_(); std::queue qWithoutMoveable; handleAllMoveableCellsAndUnmoveableCells_(qWithoutMoveable); handleAllUnmoveableCells_(qWithoutMoveable); } -void Cell::buffTableinDistance(int distance) { - clearTable_(false); - std::queue q; - q.push(this); - setIsAttackable(true); - auto f = [&q, &distance](Cell * Now) { - if (Now != NULL && Now->getDistance() <= distance && !Now->AddedToQuery_) { - q.push(Now); - Now->AddedToQuery_ = true; - Now->setIsAttackable(true); - } - }; - while (!q.empty()) { - Cell * Now = q.front(); - q.pop(); - f(Now->getLeftUp()); - f(Now->getLeft()); - f(Now->getLeftDown()); - f(Now->getRightUp()); - f(Now->getRight()); - f(Now->getRightDown()); - } -} - -std::vector Cell::actualPath(Cell* to) { - if (!to || !to->getIsMoveable())return std::vector(); +std::vector Cell::actualPath(Cell* to) {//std::vector âêëþ÷àåòñÿ â ñåáÿ è this, è end + if (!to || !to->getisMoveable())return std::vector(); auto ret = std::vector(1, to); while (to != this) { Cell * parent = NULL; auto f = [&parent](Cell * TestParent, Cell * Now) { - if (TestParent && TestParent->getDistance() + 1 == Now->getDistance() && TestParent->getIsMoveable()) { + if (TestParent && TestParent->getDistance() + 1 == Now->getDistance() && TestParent->getisMoveable()) { parent = TestParent; } }; - f(to->getLeftUp(), to); - f(to->getLeft(), to); - f(to->getLeftDown(), to); - f(to->getRightUp(), to); - f(to->getRight(), to); - f(to->getRightDown(), to); + f(to->getleftUp(), to); + f(to->getleft(), to); + f(to->getleftDown(), to); + f(to->getrightUp(), to); + f(to->getright(), to); + f(to->getrightDown(), to); to = parent; ret.push_back(to); } diff --git a/Cell.h b/Cell.h index 99b990a..e425ceb 100644 --- a/Cell.h +++ b/Cell.h @@ -5,15 +5,15 @@ class Unit; class Cell { - int i, j; + private: - Cell * left_up_; + Cell * leftUp_; Cell *left_; - Cell * left_down_; + Cell * leftDown_; - Cell *right_up_; + Cell *rightUp_; Cell *right_; - Cell *right_down_; + Cell *rightDown_; Unit *character_; @@ -23,7 +23,7 @@ class Cell { int distance_; bool AddedToQuery_; - void clearTable_(bool); + void clearTable_(); void clearCell_(); void handleAllMoveableCellsAndUnmoveableCells_(std::queue & Q); @@ -33,41 +33,38 @@ class Cell { explicit Cell(Unit * character); - explicit Cell(int, int); - - Cell * getLeftUp(); - void setLeftUp(Cell *); - - Cell * getLeft(); - void setLeft(Cell *); - - Cell * getLeftDown(); - void setLeftDown(Cell *); - - Cell * getRightUp(); - void setRightUp(Cell *); - - Cell * getRight(); - void setRight(Cell *); - - Cell * getRightDown(); - void setRightDown(Cell *); - + Cell * getleftUp(); + void setleftUp(Cell *); + + Cell * getleft(); + void setleft(Cell *); + + Cell * getleftDown(); + void setleftDown(Cell *); + + Cell * getrightUp(); + void setrightUp(Cell *); + + Cell * getright(); + void setright(Cell *); + + Cell * getrightDown(); + void setrightDown(Cell *); + Unit * getCharacter(); void setCharacter(Unit *); - - bool getIsMoveable(); - void setIsMoveable(bool); - - bool getIsAttackable(); - void setIsAttackable(bool); - + + bool getisMoveable(); + void setisMoveable(bool); + + bool getisAttackable(); + void setisAttackable(bool); + int getDistance(); void setDistance(int); - + bool isEmpty(); - void recalculateTableWithCenterThisPoint(); - void buffTableinDistance(int); + void RecalculateTableWithCenterThisPoint(); std::vector actualPath(Cell*); };