Ver Fonte

Merge branch 'abstract_unit' of https://github.com/Gilnobag/client into cell

GeorgeKolog há 6 anos atrás
pai
commit
f4d8fd6e1d
2 ficheiros alterados com 172 adições e 55 exclusões
  1. 95 29
      unit.cpp
  2. 77 26
      unit.h

+ 95 - 29
unit.cpp

@@ -4,8 +4,31 @@
 #include <cassert>
 #include <string>
 #include "unit.h"
+#include "AbstractFactory.h"
 
-Unit::Unit(){}
+int Unit::getCost(){
+	return cost_;
+}
+
+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<std::string> Unit::getUpgradeSpecs(){
+	return upgrade_specs_;
+}
+
+void Unit::setUpgradeSpecs(std::vector<std::string> specs){
+	upgrade_specs_ = specs;
+}
 
 double Unit::getExperience() {
 	return experience_;
@@ -28,27 +51,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::getActivePoints() {
-	return active_points_;
-}
-void Unit::setActivePoints(double value) {
-	active_points_ = value;
-}
-
 double Unit::getAttackRange() {
 	return attack_range_;
 }
@@ -56,24 +58,38 @@ void Unit::setAttackRange(double value) {
 	attack_range_ = value;
 }
 
-std::pair<int, int> Unit::getLocation() {
+int Unit::getActivityPoints(){
+	return activity_points_;
+}
+void Unit::setActivityPoints(int value){
+	activity_points_ = value;
+}
+
+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() {
+int Unit::getMovementSpeed() {
 	return movement_speed_;
 }
-void Unit::setMovementSpeed(double value) {
+void Unit::setMovementSpeed(int value) {
 	movement_speed_ = value;
 }
 
-double Unit::getInitiative_() {
+int Unit::getAttackCost(){
+	return attack_cost_;
+}
+void Unit::setAttackCost(int value){
+	attack_cost_ = value;
+}
+
+double Unit::getInitiative() {
 	return initiative_;
 }
-void Unit::setInitiative_(double value) {
+void Unit::setInitiative(double value) {
 	initiative_ = value;
 }
 
@@ -105,6 +121,13 @@ void Unit::setAgility(double value) {
 	agility_ = value;
 }
 
+int Unit::getAttackPoints(){
+	return attack_cost_;
+}
+void Unit::setAttackPoints(int value){
+	attack_cost_ = value;
+}
+
 double Unit::getMagicDefence() {
 	return magic_defence_;
 }
@@ -119,6 +142,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()));
 }
@@ -135,3 +179,25 @@ double Unit::reduceIncomingDamage(std::string damageType, int damage) { //return
 		return (1 - 2.5 * magic_defence_ / 100) * damage;
 	}
 }
+
+int Unit::lenOfActualPath(Cell* destination) {
+	return getLocation()->actualPath(destination).size();
+}
+
+bool Unit::canMoveForDistance(int distance) {
+	return (movement_speed_ >= distance);
+}
+
+bool Unit::canMoveToCell(Cell* destination) {
+	return (destination->isEmpty() && lenOfActualPath(destination) > 0 && canMoveForDistance(lenOfActualPath(destination)));
+}	
+
+void Unit::moveToCell(Cell* destination) {
+	if (!canMoveToCell(destination))
+		return;	//here could be a gui-message about failed move (x-mark, for example)
+	else {
+		int decreasedValue = getMovementSpeed() - lenOfActualPath(destination);
+		setMovementSpeed(decreasedValue);
+		setLocation(destination);
+	}
+}

+ 77 - 26
unit.h

@@ -1,9 +1,20 @@
 #pragma once
 #include <iostream>
 #include <vector>
+#include "AbstractFactory.h"
 
-class Spell {
-	//empty for allow to compile
+class Spell;	
+class Cell {
+	//waiting for a realisation
+public:
+	//must be in cell.h
+	bool isEmpty() { 
+		return true;
+	}
+	std::vector <Cell*> actualPath(Cell* destination) { //the shortest existing path from (*this) to (*destination)
+		std::vector <Cell*> path;
+		return path;
+	}
 };
 
 class Unit {
@@ -12,26 +23,31 @@ protected:
 	std::vector <Spell> skills_;
 
 private:
-	//personal growth
+	//personal information
+	int cost_;
+	std::string parent_spec_;
+	std::vector<std::string> upgrade_specs_;
 	double experience_;
 	double level_;
+	std::string race_; //lower case
 
-	//connect with events
-	double active_points_;
+	//actions and events
 	double initiative_;
+	int activity_points_;
 
 	//movement
-	std::pair <int, int> location_; //x - first, y - second
-	double movement_speed_;
+	Cell* location_;
+	int movement_speed_;	//how many cells can move for one activity point
+	double real_x_;
+	double real_y_;
 
 	//attack action
 	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_;
@@ -39,9 +55,21 @@ private:
 	double physic_defence_; //less or equal 40
 
 public:
-	Unit();
+	Unit() = delete;
+	Unit(std::string path) {
+
+	}
 	virtual ~Unit() = delete;
 
+	int getCost();
+	void setCost(int value);
+
+	std::string getParentSpec();
+	void setParentSpec(std::string specId);
+
+	std::vector<std::string> getUpgradeSpecs();
+	void setUpgradeSpecs(std::vector <std::string> specs);
+
 	double getExperience();
 	void setExperience(double value);
 
@@ -51,26 +79,23 @@ public:
 	double getHealthPoints();
 	void setHealthPoints(double value);
 
-	double getManaPoints();
-	void setManaPoints(double value);
-
-	double getEnergyPoints();
-	void setEnergyPoints(double value);
-
-	double getActivePoints();
-	void setActivePoints(double value);
-
 	double getAttackRange();
 	void setAttackRange(double value);
 
-	std::pair<int, int> getLocation();
-	void setLocation(double x, double y);
+	int getActivityPoints();
+	void setActivityPoints(int value);
+
+	Cell* getLocation();
+	void setLocation(Cell* to);
 
-	double getMovementSpeed();
-	void setMovementSpeed(double value);
+	int getMovementSpeed();
+	void setMovementSpeed(int value);
 
-	double getInitiative_();
-	void setInitiative_(double value);
+	int getAttackCost();
+	void setAttackCost(int value);
+
+	double getInitiative();
+	void setInitiative(double value);
 
 	double getDamagePerHit();
 	void setDamagePerHit(double value);
@@ -84,13 +109,39 @@ public:
 	double getAgility();
 	void setAgility(double value);
 
+	int getAttackPoints();
+	void setAttackPoints(int value);
+
 	double getMagicDefence();
 	void setMagicDefence(double value);
 
 	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);
+
+	virtual bool canMoveForDistance(int distance);
+
+	virtual bool canMoveToCell(Cell* destination);
+
+	virtual void moveToCell(Cell* destination);
+
+	virtual	bool canAttackForDistance(int distance) = 0;
+
+	virtual bool canAttackToCell(Cell* destination) = 0;
+
+	virtual bool canAttackUnit(Unit* target) = 0;
 };