Skip to content

Commit

Permalink
Give the artifact bow a range of 12 and ordinary bows a range of 10.
Browse files Browse the repository at this point in the history
  • Loading branch information
SoftMonster committed Mar 16, 2018
1 parent e47039f commit 883a0f8
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 11 deletions.
6 changes: 6 additions & 0 deletions creature.cpp
Expand Up @@ -1267,6 +1267,12 @@ CreatureAction Creature::payFor(const vector<WItem>& items) const {
.append([=](WCreature) { for (auto it : items) it->setShopkeeper(nullptr); });
}

int Creature::getMaximumRange() const {
auto weapon = getEquipment().getSlotItems(EquipmentSlot::RANGED_WEAPON);
if (weapon.empty()) return 0;
return weapon.getOnlyElement()->getRangedWeapon()->getMaxDistance();
}

CreatureAction Creature::fire(Vec2 direction) const {
CHECK(direction.length8() == 1);
if (getEquipment().getItems(ItemIndex::RANGED_WEAPON).empty())
Expand Down
1 change: 1 addition & 0 deletions creature.h
Expand Up @@ -93,6 +93,7 @@ class Creature : public Renderable, public UniqueEntity<Creature>, public OwnedO
bool canSee(Position) const;
bool canSee(Vec2) const;
bool isEnemy(WConstCreature) const;
int getMaximumRange() const;
void tick();

const CreatureName& getName() const;
Expand Down
4 changes: 2 additions & 2 deletions item_type.cpp
Expand Up @@ -745,7 +745,7 @@ ItemAttributes ItemType::ElvenBow::getAttributes() const {
i.viewId = ViewId::ELVEN_BOW;
i.itemClass = ItemClass::RANGED_WEAPON;
i.equipmentSlot = EquipmentSlot::RANGED_WEAPON;
i.rangedWeapon = RangedWeapon(AttrType::RANGED_DAMAGE, "arrow", ViewId::ARROW);
i.rangedWeapon = RangedWeapon(AttrType::RANGED_DAMAGE, "arrow", ViewId::ARROW, 12);
i.weaponInfo.twoHanded = true;
i.weight = 1;
i.modifiers[AttrType::RANGED_DAMAGE] = 16;
Expand All @@ -760,7 +760,7 @@ ItemAttributes ItemType::Bow::getAttributes() const {
i.name = "short bow";
i.itemClass = ItemClass::RANGED_WEAPON;
i.equipmentSlot = EquipmentSlot::RANGED_WEAPON;
i.rangedWeapon = RangedWeapon(AttrType::RANGED_DAMAGE, "arrow", ViewId::ARROW);
i.rangedWeapon = RangedWeapon(AttrType::RANGED_DAMAGE, "arrow", ViewId::ARROW, 10);
i.weaponInfo.twoHanded = true;
i.weight = 1;
i.modifiers[AttrType::RANGED_DAMAGE] = 10 + maybePlusMinusOne(4);
Expand Down
3 changes: 1 addition & 2 deletions monster_ai.cpp
Expand Up @@ -37,7 +37,6 @@
#include "furniture.h"
#include "furniture_factory.h"
#include "file_path.h"
#include "ranged_weapon.h"

class Behaviour {
public:
Expand Down Expand Up @@ -582,7 +581,7 @@ class Fighter : public Behaviour {
if (auto move = considerBuffs())
return move;
if (distance > 1) {
if (distance <= MAX_RANGED_DISTANCE) {
if (distance <= creature->getMaximumRange()) {
if (MoveInfo move = getFireMove(enemyDir, other))
return move;
if (MoveInfo move = getThrowMove(enemyDir, other))
Expand Down
14 changes: 9 additions & 5 deletions ranged_weapon.cpp
Expand Up @@ -31,11 +31,11 @@
#include "event_listener.h"
#include "vision.h"

SERIALIZE_DEF(RangedWeapon, damageAttr, projectileName, projectileViewId)
SERIALIZE_DEF(RangedWeapon, damageAttr, projectileName, projectileViewId, maxDistance)
SERIALIZATION_CONSTRUCTOR_IMPL(RangedWeapon)

RangedWeapon::RangedWeapon(AttrType attr, const string& name, ViewId id)
: damageAttr(attr), projectileName(name), projectileViewId(id) {}
RangedWeapon::RangedWeapon(AttrType attr, const string& name, ViewId id, int dist)
: damageAttr(attr), projectileName(name), projectileViewId(id), maxDistance(dist) {}

void RangedWeapon::fire(WCreature c, Vec2 dir) const {
CHECK(dir.length8() == 1);
Expand All @@ -59,8 +59,7 @@ void RangedWeapon::fire(WCreature c, Vec2 dir) const {
pos.globalMessage("the " + projectileName + " hits the " + pos.getName());
break;
}
if (distance >= MAX_RANGED_DISTANCE)
{
if (distance >= maxDistance) {
pos.globalMessage("the " + projectileName + " falls short.");
break;
}
Expand All @@ -71,3 +70,8 @@ void RangedWeapon::fire(WCreature c, Vec2 dir) const {
AttrType RangedWeapon::getDamageAttr() const {
return damageAttr;
}

int RangedWeapon::getMaxDistance() const {
return maxDistance;
}

5 changes: 3 additions & 2 deletions ranged_weapon.h
Expand Up @@ -17,19 +17,20 @@

#include "util.h"
#include "item.h"
#define MAX_RANGED_DISTANCE 10

class RangedWeapon {
public:
RangedWeapon(AttrType damageAttr, const string& projectileName, ViewId projectileViewId);
RangedWeapon(AttrType damageAttr, const string& projectileName, ViewId projectileViewId, int maxDistance);

void fire(WCreature c, Vec2 dir) const;
AttrType getDamageAttr() const;
int getMaxDistance() const;

SERIALIZATION_DECL(RangedWeapon);

private:
AttrType SERIAL(damageAttr);
string SERIAL(projectileName);
ViewId SERIAL(projectileViewId);
int SERIAL(maxDistance);
};

0 comments on commit 883a0f8

Please sign in to comment.