Browse Source

primal int movement

noath 6 years ago
parent
commit
1fba1ca518
2 changed files with 33 additions and 30 deletions
  1. 23 20
      unit.cpp
  2. 10 10
      unit.h

+ 23 - 20
unit.cpp

@@ -5,7 +5,7 @@
 #include <string>
 #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

+ 10 - 10
unit.h

@@ -11,7 +11,7 @@ public:
 	bool isEmpty() {
 		return true;
 	}
-	std::vector <Cell*> actualPath(Cell* to) {
+	std::vector <Cell*> actualPath(Cell* destination) { //the shortest existing path from (*this) to (*destination)
 		std::vector <Cell*> path;
 		return path;
 	}
@@ -27,13 +27,12 @@ private:
 	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 @@ public:
 	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 @@ public:
 
 	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);
 };