Browse Source

added based classes, corrected abstract unit files, added human icons

noath 7 years ago
parent
commit
6c53c9652e

+ 16 - 0
assets/units/Archer/include/Archer.h

@@ -0,0 +1,16 @@
+#pragma once
+#include <iostream>
+#include <cassert>
+#include "unit.h"
+
+class Archer : public Unit {
+	Archer() = delete;
+	Archer(std::string id);
+	~Archer();
+
+	bool canAttackForDistance(int distance);
+
+	bool canAttackToCell(Cell* destination);
+
+	bool canAttackUnit(Unit* target);
+};

+ 25 - 0
assets/units/Archer/source/Archer.cpp

@@ -0,0 +1,25 @@
+#pragma once
+#include <iostream>
+#include <random>
+#include <ctime>
+#include "unit.h"
+#include "Archer.h"
+
+Archer::Archer(std::string id) {
+}
+
+Archer::~Archer() {}
+
+bool Archer::canAttackForDistance(int distance) { 
+	//this is a dummy
+	srand(time(0));
+	return rand() % 2;
+}
+
+bool Archer::canAttackToCell(Cell * destination) {
+	return canAttackForDistance(lenOfActualPath(destination) + getAttackCost() * getMovementSpeed());
+}
+
+bool Archer::canAttackUnit(Unit * target) {
+	return canAttackToCell(target->getLocation());
+}

+ 17 - 0
assets/units/Mage/include/Mage.h

@@ -0,0 +1,17 @@
+#pragma once
+#pragma once
+#include <iostream>
+#include <cassert>
+#include "unit.h"
+
+class Mage : public Unit {
+	Mage() = delete;
+	Mage(std::string id);
+	~Mage();
+
+	bool canAttackForDistance(int distance);
+
+	bool canAttackToCell(Cell* destination);
+
+	bool canAttackUnit(Unit* target);
+};

+ 24 - 0
assets/units/Mage/source/Mage.cpp

@@ -0,0 +1,24 @@
+#pragma once
+#include <iostream>
+#include <random>
+#include <ctime>
+#include "unit.h"
+#include "Mage.h"
+
+Mage::Mage(std::string id){
+}
+
+Mage::~Mage(){}
+
+bool Mage::canAttackForDistance(int distance){ //this is a dummy
+	srand(time(0));
+	return rand() % 2;
+}
+
+bool Mage::canAttackToCell(Cell * destination){
+	return canAttackForDistance(lenOfActualPath(destination) + getAttackCost() * getMovementSpeed());
+}
+
+bool Mage::canAttackUnit(Unit * target){
+	return canAttackToCell(target->getLocation());
+}

+ 18 - 0
assets/units/Rider/include/Rider.h

@@ -0,0 +1,18 @@
+#pragma once
+#include <iostream>
+#include <cassert>
+#include "unit.h"
+
+class Rider : public Unit {
+	Rider() = delete;
+	Rider(std::string id);
+	~Rider();
+
+	//increase dmg with len of movement path
+
+	bool canAttackForDistance(int distance);
+
+	bool canAttackToCell(Cell* destination);
+
+	bool canAttackUnit(Unit* target);
+};

+ 24 - 0
assets/units/Rider/source/Rider.cpp

@@ -0,0 +1,24 @@
+#pragma once
+#include <iostream>
+#include <random>
+#include <ctime>
+#include "unit.h"
+#include "Rider.h"
+
+Rider::Rider(std::string id) {
+}
+
+Rider::~Rider(){}
+
+bool Rider::canAttackForDistance(int distance) {
+	return (canMoveForDistance(attack_cost_ * getMovementSpeed() + distance - attack_range_));
+}
+
+bool Rider::canAttackToCell(Cell * destination) {
+	return lenOfActualPath(destination) != 0 &&
+		canAttackForDistance(lenOfActualPath(destination));
+}
+
+bool Rider::canAttackUnit(Unit * target) {
+	return canAttackToCell(target->getLocation());
+}

+ 18 - 0
assets/units/Rogue/include/Rogue.h

@@ -0,0 +1,18 @@
+#pragma once
+#include <iostream>
+#include <cassert>
+#include "unit.h"
+
+class Rogue : public Unit {
+	Rogue() = delete;
+	Rogue(std::string id);
+	~Rogue();
+
+	//backstab
+
+	bool canAttackForDistance(int distance);
+
+	bool canAttackToCell(Cell* destination);
+
+	bool canAttackUnit(Unit* target);
+};

+ 24 - 0
assets/units/Rogue/source/Rogue.cpp

@@ -0,0 +1,24 @@
+#pragma once
+#include <iostream>
+#include <random>
+#include <ctime>
+#include "unit.h"
+#include "Rogue.h"
+
+Rogue::Rogue(std::string id) {
+}
+
+Rogue::~Rogue() {}
+
+bool Rogue::canAttackForDistance(int distance) {
+	return (canMoveForDistance(attack_cost_ * getMovementSpeed() + distance - attack_range_));
+}
+
+bool Rogue::canAttackToCell(Cell * destination) {
+	return lenOfActualPath(destination) != 0 &&
+		canAttackForDistance(lenOfActualPath(destination));
+}
+
+bool Rogue::canAttackUnit(Unit * target) {
+	return canAttackToCell(target->getLocation());
+}

+ 18 - 0
assets/units/Warrior/include/Warrior.h

@@ -0,0 +1,18 @@
+#pragma once
+#include <iostream>
+#include <cassert>
+#include "unit.h"
+
+class Warrior : public Unit {
+	Warrior() = delete;
+	Warrior(std::string id);
+	~Warrior();
+
+	double reduceIncomingDamage(std::string damageType, int damage);
+
+	bool canAttackForDistance(int distance);
+
+	bool canAttackToCell(Cell* destination);
+
+	bool canAttackUnit(Unit* target);
+};

+ 42 - 0
assets/units/Warrior/source/Warrior.cpp

@@ -0,0 +1,42 @@
+#pragma once
+#include <iostream>
+#include <random>
+#include <ctime>
+#include "unit.h"
+#include "Warrior.h"
+
+Warrior::Warrior(std::string id){
+}
+
+Warrior::~Warrior(){}
+
+double Warrior::reduceIncomingDamage(std::string damageType, int damage) {//returns damage after reducing by defence
+	assert("Incorrect damage type in call reduceIncomingDamage(), expected" &&
+		damageType[0] == 'p' || damageType[0] == 'P' || damageType[0] == 'm' || damageType[0] == 'M');
+	assert("Magic defence of unit is incorrectly high (>40), but must be" && magic_defence_ <= 40);
+	assert("Physic defence of unit is incorrectly high (>40), but must be" && physic_defence_ <= 40);
+	if (damageType[0] == 'p' || damageType[0] == 'P') {
+		srand(time(0));
+		double reduced = (1 - 2.5 * physic_defence_ / 100) * damage;
+		if (rand() % 10 == 0) {
+			reduced = reduced / 2.0;
+		}
+		return reduced;
+	}
+	else if (damageType[0] == 'm' || damageType[0] == 'M') {
+		return (1 - 2.5 * magic_defence_ / 100) * damage;
+	}
+}
+
+bool Warrior::canAttackForDistance(int distance){
+	return (canMoveForDistance(attack_cost_ * getMovementSpeed() + distance - attack_range_));
+}
+
+bool Warrior::canAttackToCell(Cell * destination){
+	return lenOfActualPath(destination) != 0 && 
+				canAttackForDistance(lenOfActualPath(destination));
+}
+
+bool Warrior::canAttackUnit(Unit * target){
+	return canAttackToCell(target->getLocation());
+}

BIN
assets/units/human/icon.png


BIN
assets/units/human/second-icon.png


+ 13 - 8
include/unit.h

@@ -12,7 +12,7 @@ public:
 		return true;
 	}
 	std::vector <Cell*> actualPath(Cell* destination) { //the shortest existing path from (*this) to (*destination)
-		std::vector <Cell*> path;
+		std::vector <Cell*> path;  //empty if there is no way
 		return path;
 	}
 };
@@ -22,7 +22,6 @@ class Unit {
 protected:
 	std::vector <Spell> skills_;
 
-private:
 	//personal information
 	int cost_;
 	std::string parent_spec_;
@@ -30,10 +29,12 @@ private:
 	double experience_;
 	double level_;
 	std::string race_; //lower case
+	int max_copies_in_army_; 
 
 	//actions and events
 	double initiative_;
 	int activity_points_;
+	int starting_activity_points_; //at start turn
 
 	//movement
 	Cell* location_;
@@ -55,11 +56,9 @@ private:
 	double physic_defence_; //less or equal 40
 
 public:
-	Unit() = delete;
-	Unit(std::string path) {
-
-	}
-	virtual ~Unit() = delete;
+	Unit() {};
+	Unit(std::string id);
+	virtual ~Unit() {};
 
 	int getCost();
 	void setCost(int value);
@@ -85,6 +84,9 @@ public:
 	int getActivityPoints();
 	void setActivityPoints(int value);
 
+	int getStartingActivityPoints();
+	void setStartingActivityPoints(int value);
+
 	Cell* getLocation();
 	void setLocation(Cell* to);
 
@@ -118,6 +120,9 @@ public:
 	double getPhysicDefence();
 	void setPhysicDefence(double value);
 
+	int getMaxCopiesInArmy();
+	void setMaxCopiesInArmy(int count);
+
 	std::string getRace();
 	void setRace(std::string new_race);
 
@@ -129,7 +134,7 @@ public:
 
 	virtual void calculateDamagePerHit();
 
-	virtual double reduceIncomingDamage(std::string damageType, int value);
+	virtual double reduceIncomingDamage(std::string damageType, int damage);
 
 	int lenOfActualPath(Cell* destination);
 

+ 21 - 3
source/unit.cpp

@@ -6,6 +6,9 @@
 #include "unit.h"
 #include "AbstractFactory.h"
 
+Unit::Unit(std::string id){
+}
+
 int Unit::getCost(){
 	return cost_;
 }
@@ -65,6 +68,13 @@ void Unit::setActivityPoints(int value){
 	activity_points_ = value;
 }
 
+int Unit::getStartingActivityPoints() {
+	return starting_activity_points_;
+}
+void Unit::setStartingActivityPoints(int value) {
+	starting_activity_points_ = value;
+}
+
 Cell* Unit::getLocation() {
 	return location_;
 }
@@ -142,6 +152,14 @@ void Unit::setPhysicDefence(double value) {
 	physic_defence_ = value;
 }
 
+int Unit::getMaxCopiesInArmy(){
+	return max_copies_in_army_;
+}
+
+void Unit::setMaxCopiesInArmy(int count){
+	max_copies_in_army_ = count;
+}
+
 std::string Unit::getRace() {
 	return race_;
 }
@@ -185,7 +203,7 @@ int Unit::lenOfActualPath(Cell* destination) {
 }
 
 bool Unit::canMoveForDistance(int distance) {
-	return (movement_speed_ >= distance);
+	return (activity_points_ * movement_speed_ >= distance);
 }
 
 bool Unit::canMoveToCell(Cell* destination) {
@@ -196,8 +214,8 @@ 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);
+		int decreasedPoints = getActivityPoints() * getMovementSpeed() - lenOfActualPath(destination);
+		setActivityPoints(decreasedPoints);
 		setLocation(destination);
 	}
 }