|
@@ -5,23 +5,18 @@
|
|
//#include "unit.h"
|
|
//#include "unit.h"
|
|
#include <queue>
|
|
#include <queue>
|
|
#include <vector>
|
|
#include <vector>
|
|
|
|
+#include <map>
|
|
|
|
+#include <iostream>
|
|
|
|
|
|
class Unit{
|
|
class Unit{
|
|
|
|
+private:
|
|
public:
|
|
public:
|
|
bool CanMoveForDistance(int distance){
|
|
bool CanMoveForDistance(int distance){
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
- /*
|
|
|
|
- template<std::string AttackType>
|
|
|
|
- bool CanAttackForDistance(int distance){
|
|
|
|
|
|
+ bool CanAttackForDistance(std::string AttackType, int distance){
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
- bool CanAttackForDistance<"Melee">(int distance){
|
|
|
|
- return true;
|
|
|
|
- }
|
|
|
|
- bool CanAttackForDistance<"Range">(int distance){
|
|
|
|
- return true;
|
|
|
|
- }*/
|
|
|
|
};
|
|
};
|
|
|
|
|
|
class EffectsForCell{
|
|
class EffectsForCell{
|
|
@@ -35,6 +30,7 @@ Cell::Cell(Unit* character) {
|
|
character_ = character;
|
|
character_ = character;
|
|
clearCell_();
|
|
clearCell_();
|
|
AddedToQuery_ = true;
|
|
AddedToQuery_ = true;
|
|
|
|
+ col_ = row_ = 0;
|
|
}
|
|
}
|
|
|
|
|
|
Cell * Cell::getleftUp() {
|
|
Cell * Cell::getleftUp() {
|
|
@@ -113,7 +109,7 @@ void Cell::setisRangeAttackAble(bool isRangeAttackAble){
|
|
}
|
|
}
|
|
|
|
|
|
bool Cell::isEmpty() {
|
|
bool Cell::isEmpty() {
|
|
- return character_ == NULL;
|
|
|
|
|
|
+ return character_ == nullptr;
|
|
}
|
|
}
|
|
|
|
|
|
void Cell::recalculateAllEffectsList(){
|
|
void Cell::recalculateAllEffectsList(){
|
|
@@ -123,6 +119,8 @@ void Cell::recalculateAllEffectsList(){
|
|
}
|
|
}
|
|
}
|
|
}
|
|
void Cell::add(EffectsForCell* effect){
|
|
void Cell::add(EffectsForCell* effect){
|
|
|
|
+ if(effect == nullptr)
|
|
|
|
+ throw new int(228);
|
|
effects_list_.push_back(effect);
|
|
effects_list_.push_back(effect);
|
|
}
|
|
}
|
|
void Cell::remove(std::vector<EffectsForCell*>::iterator it){
|
|
void Cell::remove(std::vector<EffectsForCell*>::iterator it){
|
|
@@ -148,9 +146,9 @@ std::vector<EffectsForCell*>::iterator Cell::endIteratorEffectsList(){
|
|
|
|
|
|
void Cell::RecalculateTableWithCenterThisPoint() {
|
|
void Cell::RecalculateTableWithCenterThisPoint() {
|
|
clearTable_();
|
|
clearTable_();
|
|
- std::queue<Cell*> qWithoutMoveable;
|
|
|
|
- updateMoveableCells_(qWithoutMoveable);
|
|
|
|
- updateUnMovealeCells_(qWithoutMoveable);
|
|
|
|
|
|
+ std::queue<Cell*> qWithUnMoveable;
|
|
|
|
+ updateMoveableCells_(qWithUnMoveable);
|
|
|
|
+ updateUnMovealeCells_(qWithUnMoveable);
|
|
}
|
|
}
|
|
std::vector <Cell*> Cell::actualPath(Cell* to) {
|
|
std::vector <Cell*> Cell::actualPath(Cell* to) {
|
|
if (!to || !to->getisMoveAble())return std::vector<Cell*>();
|
|
if (!to || !to->getisMoveAble())return std::vector<Cell*>();
|
|
@@ -190,9 +188,11 @@ void Cell::clearTable_() {
|
|
clearCell_();
|
|
clearCell_();
|
|
setdistance_through(0);
|
|
setdistance_through(0);
|
|
this->AddedToQuery_ = false;
|
|
this->AddedToQuery_ = false;
|
|
- auto f = [&q](Cell * t, Cell * parent) {
|
|
|
|
|
|
+ auto f = [&q](Cell * t, Cell * parent, int delta_col, int delta_row) {
|
|
if (t && t->AddedToQuery_ == true) {
|
|
if (t && t->AddedToQuery_ == true) {
|
|
q.push(t);
|
|
q.push(t);
|
|
|
|
+ t->col_ = parent->col_ + delta_col;
|
|
|
|
+ t->row_ = parent->row_ + delta_row;
|
|
t->setdistance_through(
|
|
t->setdistance_through(
|
|
parent->getdistance_through() + 1
|
|
parent->getdistance_through() + 1
|
|
);
|
|
);
|
|
@@ -203,32 +203,35 @@ void Cell::clearTable_() {
|
|
Cell * Now = q.front();
|
|
Cell * Now = q.front();
|
|
q.pop();
|
|
q.pop();
|
|
Now->clearCell_();
|
|
Now->clearCell_();
|
|
- 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, -1, 0);
|
|
|
|
+ f(Now->getleft(), Now, 0, -1);
|
|
|
|
+ f(Now->getleftDown(), Now, 1, -1);
|
|
|
|
+ f(Now->getrightUp(), Now, -1, 1);
|
|
|
|
+ f(Now->getright(), Now, 0, 1);
|
|
|
|
+ f(Now->getrightDown(), Now, 1, 0);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-void Cell::recalcAttackable_(Cell * Now){
|
|
|
|
|
|
+void Cell::recalcAttackable_(Cell * Now,bool isReached){
|
|
if(Now == nullptr)return;
|
|
if(Now == nullptr)return;
|
|
if (!isEmpty() && !Now->isEmpty() &&
|
|
if (!isEmpty() && !Now->isEmpty() &&
|
|
- getCharacter()->CanAttackForDistance<"Melee">(Now->getdistance_barrier())
|
|
|
|
|
|
+ getCharacter()->CanAttackForDistance("Melee", Now->getdistance_barrier())
|
|
) {
|
|
) {
|
|
- Now->setisMeleeAttackAble(true);
|
|
|
|
|
|
+ Now->setisMeleeAttackAble(isReached);
|
|
}
|
|
}
|
|
if (!isEmpty() && !Now->isEmpty() &&
|
|
if (!isEmpty() && !Now->isEmpty() &&
|
|
- getCharacter()->CanAttackForDistance<"Range">(Now->getdistance_barrier())
|
|
|
|
|
|
+ getCharacter()->CanAttackForDistance("Range", Now->getdistance_barrier())
|
|
) {
|
|
) {
|
|
Now->setisRangeAttackAble(true);
|
|
Now->setisRangeAttackAble(true);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-void Cell::recalcMoveable_(Cell * Now){
|
|
|
|
|
|
+void Cell::recalcMoveable_(Cell * Now, bool isReached){
|
|
if(Now == nullptr || Now->isEmpty() || isEmpty())return;
|
|
if(Now == nullptr || Now->isEmpty() || isEmpty())return;
|
|
- getCharacter()->CanMoveForDistance()
|
|
|
|
|
|
+ if(!isEmpty() && Now->isEmpty() &&
|
|
|
|
+ getCharacter()->CanMoveForDistance(Now->getdistance_barrier())){
|
|
|
|
+ Now->setisMoveAble(isReached);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
void Cell::updateMoveableCells_(std::queue<Cell*> & Q) {
|
|
void Cell::updateMoveableCells_(std::queue<Cell*> & Q) {
|
|
@@ -250,9 +253,10 @@ void Cell::updateMoveableCells_(std::queue<Cell*> & Q) {
|
|
};
|
|
};
|
|
while (!q.empty()) {
|
|
while (!q.empty()) {
|
|
Cell * Now = q.front();
|
|
Cell * Now = q.front();
|
|
- Now->setisMoveAble();
|
|
|
|
- recalcAttackable_(Now);
|
|
|
|
q.pop();
|
|
q.pop();
|
|
|
|
+ recalcMoveable_(Now, true);
|
|
|
|
+ recalcAttackable_(Now, true);
|
|
|
|
+
|
|
f(Now->getleftUp(), Now);
|
|
f(Now->getleftUp(), Now);
|
|
f(Now->getleft(), Now);
|
|
f(Now->getleft(), Now);
|
|
f(Now->getleftDown(), Now);
|
|
f(Now->getleftDown(), Now);
|
|
@@ -271,8 +275,8 @@ void Cell::updateUnMovealeCells_(std::queue<Cell*> & Q) {
|
|
};
|
|
};
|
|
while (!Q.empty()) {
|
|
while (!Q.empty()) {
|
|
Cell * Now = Q.front();
|
|
Cell * Now = Q.front();
|
|
- Now->setisMoveable(false);
|
|
|
|
- Now->setisAttackable(false);
|
|
|
|
|
|
+ recalcMoveable_(Now, false);
|
|
|
|
+ recalcAttackable_(Now, false);
|
|
Q.pop();
|
|
Q.pop();
|
|
f(Now->getleftUp(), Now);
|
|
f(Now->getleftUp(), Now);
|
|
f(Now->getleft(), Now);
|
|
f(Now->getleft(), Now);
|
|
@@ -282,3 +286,57 @@ void Cell::updateUnMovealeCells_(std::queue<Cell*> & Q) {
|
|
f(Now->getrightDown(), Now);
|
|
f(Now->getrightDown(), Now);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+void Cell::print() {
|
|
|
|
+ std::cout << "(" << col_ << ", " << row_ << ")";
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+Cell* Cell::getRealShootTarget(Cell* next){
|
|
|
|
+ if(next == this){
|
|
|
|
+ return next;
|
|
|
|
+ }
|
|
|
|
+ int next_col = next->col_;
|
|
|
|
+ int next_row = next->row_;
|
|
|
|
+ if(next_col - col_ == next_row - row_){//GoMainDiagonal
|
|
|
|
+ if(next_col > col_){
|
|
|
|
+ return getrightDown()->getright();
|
|
|
|
+ }
|
|
|
|
+ if(next_col < col_){
|
|
|
|
+ return getleftUp()->getleft();
|
|
|
|
+ }
|
|
|
|
+ throw std::string("Don`t recalculated");
|
|
|
|
+ }
|
|
|
|
+ if(-2 * (next_col - col_) == (next_row - row_)){//GoSecondaryDiagonal
|
|
|
|
+ if(next_col < col_){
|
|
|
|
+ return getrightUp()->getright();
|
|
|
|
+ }
|
|
|
|
+ if(next_col > col_){
|
|
|
|
+ return getleftDown()->getleft();
|
|
|
|
+ }
|
|
|
|
+ throw std::string("Don`t recalculated");
|
|
|
|
+ }
|
|
|
|
+ if(next_col - col_ == -2 * (next_row - row_)){//GoUp
|
|
|
|
+ if(next_col < col_){
|
|
|
|
+ return (getleftUp() != nullptr ? getleftUp()->getrightUp() : getrightUp()->getleftUp());
|
|
|
|
+ }
|
|
|
|
+ if(next_col > col_){
|
|
|
|
+ return (getleftDown() != nullptr ? getleftDown()->getrightDown() : getrightDown()->getleftDown());
|
|
|
|
+ }
|
|
|
|
+ throw std::string("Don`t recalculated");
|
|
|
|
+ }
|
|
|
|
+ int row_secondary_diag = row_ - 2 * (next_col - col_);
|
|
|
|
+ int row_main_diag = row_ + next_col - col_;
|
|
|
|
+ int twice_row_up_line = 2 * row_ + col_ - next_col;
|
|
|
|
+ if(next_col > col_){
|
|
|
|
+ if(next_row < row_main_diag)return getleft();
|
|
|
|
+ if(2 * next_row < twice_row_up_line)return getleftUp();
|
|
|
|
+ if(next_row < row_secondary_diag)return getrightUp();
|
|
|
|
+ return getright();
|
|
|
|
+ }
|
|
|
|
+ else{
|
|
|
|
+ if(next_row < row_secondary_diag)return getleft();
|
|
|
|
+ if(2 * next_row < twice_row_up_line)return getleftDown();
|
|
|
|
+ if(next_row < row_main_diag)return getrightDown();
|
|
|
|
+ return getright();
|
|
|
|
+ }
|
|
|
|
+}
|