aboutsummaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authormafaldo <mafaldo@heavyhammer.home>2018-02-12 23:43:14 +0100
committermafaldo <mafaldo@heavyhammer.home>2018-02-12 23:43:14 +0100
commit3472e0de54bbfa63517de8db7d665b732389ae85 (patch)
treea3754a70c36dad94ea80877323c2b9798b5b5036 /src/main
parentAdd Actor attributes (diff)
downloadSubconscious-old-3472e0de54bbfa63517de8db7d665b732389ae85.tar.gz
Subconscious-old-3472e0de54bbfa63517de8db7d665b732389ae85.zip
Add RangedWeapon, MeleeWeapon
Diffstat (limited to 'src/main')
-rw-r--r--src/main/cpp/MeleeWeapon.cpp15
-rw-r--r--src/main/cpp/RangedWeapon.cpp25
-rw-r--r--src/main/headers/Bullet.hpp12
-rw-r--r--src/main/headers/Item.hpp11
-rw-r--r--src/main/headers/MeleeWeapon.hpp7
-rw-r--r--src/main/headers/RangedWeapon.hpp8
-rw-r--r--src/main/headers/Weapon.hpp4
7 files changed, 76 insertions, 6 deletions
diff --git a/src/main/cpp/MeleeWeapon.cpp b/src/main/cpp/MeleeWeapon.cpp
new file mode 100644
index 0000000..92c7632
--- /dev/null
+++ b/src/main/cpp/MeleeWeapon.cpp
@@ -0,0 +1,15 @@
+#include "MeleeWeapon.hpp"
+#include "Actor.hpp"
+
+#include <string>
+
+MeleeWeapon::MeleeWeapon(Type t, const std::string &name)
+: Weapon(name), type(t)
+{
+}
+
+bool MeleeWeapon::use(Actor &user, Actor &actor)
+{
+ //TODO implement attack probability
+ //actor.damage(_damage);
+}
diff --git a/src/main/cpp/RangedWeapon.cpp b/src/main/cpp/RangedWeapon.cpp
new file mode 100644
index 0000000..eb33780
--- /dev/null
+++ b/src/main/cpp/RangedWeapon.cpp
@@ -0,0 +1,25 @@
+#include "RangedWeapon.hpp"
+#include "Actor.hpp"
+
+#include <string>
+#include <algorithm>
+#include <vector>
+
+RangedWeapon::RangedWeapon(const std::string &name)
+: Weapon(name)
+{
+}
+
+bool RangedWeapon::use(Actor &user, Actor &actor)
+{
+ //TODO implement attack probability
+ if (_charged) {
+ actor.damage(user.attack() + _damage - actor.defence());
+ _charged = false;
+ }
+}
+
+void RangedWeapon::reload(Actor &actor)
+{
+ //std::vector<Item> bullet = actor.bullet();
+}
diff --git a/src/main/headers/Bullet.hpp b/src/main/headers/Bullet.hpp
new file mode 100644
index 0000000..e38c3f2
--- /dev/null
+++ b/src/main/headers/Bullet.hpp
@@ -0,0 +1,12 @@
+#ifndef BULLET_HPP
+#define BULLET_HPP
+
+#include "Item.hpp"
+
+class Bullet : public Item
+{
+public:
+ bool use(RangedWeapon &weapon);
+}
+
+#endif
diff --git a/src/main/headers/Item.hpp b/src/main/headers/Item.hpp
index 3664a0e..caa1e6f 100644
--- a/src/main/headers/Item.hpp
+++ b/src/main/headers/Item.hpp
@@ -14,16 +14,17 @@ public:
Item() = delete;
virtual ~Item() {}
- virtual bool use(Actor &actor) = 0;
- virtual bool use(Item &item) = 0;
+ virtual bool use(Actor &user, Actor &actor) = 0;
bool stackable() { return _maxAmount == 1; }
protected:
- const unsigned _maxAmount;
- const unsigned _amount; // stackable
+ unsigned _maxAmount;
+ unsigned _amount; // stackable
- std::string _name;
+ const std::string _name;
+
+ Item(const std::string &name) : _name(name) {}
};
#endif
diff --git a/src/main/headers/MeleeWeapon.hpp b/src/main/headers/MeleeWeapon.hpp
index e031333..b98d027 100644
--- a/src/main/headers/MeleeWeapon.hpp
+++ b/src/main/headers/MeleeWeapon.hpp
@@ -4,6 +4,8 @@
#include "Weapon.hpp"
#include "Actor.hpp"
+#include <string>
+
class MeleeWeapon : public Weapon
{
@@ -12,7 +14,10 @@ public:
SWORD, AXE, LANCE
};
- virtual bool use(Actor &actor);
+ const Type type;
+
+ MeleeWeapon(Type t, const std::string &name);
+ bool use(Actor &user, Actor &actor);
protected:
bool _throwable;
diff --git a/src/main/headers/RangedWeapon.hpp b/src/main/headers/RangedWeapon.hpp
index 57b6ea4..0cc3be1 100644
--- a/src/main/headers/RangedWeapon.hpp
+++ b/src/main/headers/RangedWeapon.hpp
@@ -1,10 +1,18 @@
#ifndef RANGEDWEAPON_HPP
#define RANGEDWEAPON_HPP
+#include "Actor.hpp"
+#include "Weapon.hpp"
+
#include <string>
class RangedWeapon : public Weapon
{
+public:
+ RangedWeapon(const std::string &name);
+ bool use(Actor &user, Actor &actor);
+ void reload(Actor &actor);
+
protected:
bool _charged;
unsigned _range;
diff --git a/src/main/headers/Weapon.hpp b/src/main/headers/Weapon.hpp
index ef9d3d5..4c134ea 100644
--- a/src/main/headers/Weapon.hpp
+++ b/src/main/headers/Weapon.hpp
@@ -4,11 +4,15 @@
#include "Item.hpp"
#include "Actor.hpp"
+#include <string>
+
class Weapon : public Item
{
protected:
unsigned _damage;
unsigned _requiredLevel;
+
+ Weapon(const std::string &name) : Item(name) {}
};
#endif