diff --git a/creature.cpp b/creature.cpp index b95e3ec86..a8d356e2b 100644 --- a/creature.cpp +++ b/creature.cpp @@ -56,7 +56,7 @@ template void Creature::serialize(Archive& ar, const unsigned int version) { ar & SUBCLASS(OwnedObject) & SUBCLASS(Renderable) & SUBCLASS(UniqueEntity); - ar(attributes, position, equipment, shortestPath, knownHiding, tribe, morale); + ar(attributes, position, ammoCooldownPoints, equipment, shortestPath, knownHiding, tribe, morale); ar(deathTime, hidden, lastMoveCounter, captureHealth); ar(deathReason, nextPosIntent, globalTime); ar(unknownAttackers, privateEnemies, holding); @@ -247,6 +247,8 @@ optional Creature::spendTime(TimeInterval t) { MovementInfo ret(Vec2(0, 0), *getLocalTime(), *getLocalTime() + t, 0, MovementInfo::MOVE); lastMoveCounter = ret.moveCounter = position.getModel()->getMoveCounter(); if (!isDead()) { + if (ammoCooldownPoints < 141) + ammoCooldownPoints++; if (isAffected(LastingEffect::SPEED) && t == 1_visible) { if (m->getTimeQueue().hasExtraMove(this)) ret.tBegin += 0.5; @@ -1308,7 +1310,7 @@ CreatureAction Creature::payFor(const vector& items) const { .append([=](WCreature) { for (auto it : items) it->setShopkeeper(nullptr); }); } -CreatureAction Creature::fire(Vec2 direction) const { +CreatureAction Creature::fire(Vec2 direction) { CHECK(direction.length8() == 1); if (getEquipment().getItems(ItemIndex::RANGED_WEAPON).empty()) return CreatureAction("You need a ranged weapon."); @@ -1319,7 +1321,18 @@ CreatureAction Creature::fire(Vec2 direction) const { return CreatureAction(this, [=](WCreature self) { auto& weapon = *self->getEquipment().getSlotItems(EquipmentSlot::RANGED_WEAPON).getOnlyElement() ->getRangedWeapon(); - weapon.fire(self, direction); + if (ammoCooldownPoints < 10) { + getPosition().globalMessage("Getting ammunition."); + } + else { + weapon.fire(self, direction); + if (ammoCooldownPoints < 10) { + ammoCooldownPoints = -1; + } + else { + ammoCooldownPoints = ammoCooldownPoints - 10; + } + } self->spendTime(); }); } @@ -1818,3 +1831,6 @@ optional Creature::getLastCombatIntent() const { return lastCombatIntent; } +int Creature::getAmmoCooldownPoints() const { + return ammoCooldownPoints; +} \ No newline at end of file diff --git a/creature.h b/creature.h index d9be7534b..6529561e5 100644 --- a/creature.h +++ b/creature.h @@ -94,6 +94,7 @@ class Creature : public Renderable, public UniqueEntity, public OwnedO bool canSee(Vec2) const; bool isEnemy(WConstCreature) const; void tick(); + int getAmmoCooldownPoints() const; const CreatureName& getName() const; CreatureName& getName(); @@ -168,7 +169,7 @@ class Creature : public Renderable, public UniqueEntity, public OwnedO CreatureAction stealFrom(Vec2 direction, const vector&) const; CreatureAction give(WCreature whom, vector items) const; CreatureAction payFor(const vector&) const; - CreatureAction fire(Vec2 direction) const; + CreatureAction fire(Vec2 direction); CreatureAction construct(Vec2 direction, FurnitureType) const; CreatureAction whip(const Position&) const; bool canConstruct(FurnitureType) const; @@ -298,6 +299,7 @@ class Creature : public Renderable, public UniqueEntity, public OwnedO HeapAllocated SERIAL(attributes); Position SERIAL(position); + int SERIAL(ammoCooldownPoints); HeapAllocated SERIAL(equipment); HeapAllocated> SERIAL(shortestPath); EntitySet SERIAL(knownHiding); diff --git a/monster_ai.cpp b/monster_ai.cpp index df82494a5..422bad68c 100644 --- a/monster_ai.cpp +++ b/monster_ai.cpp @@ -596,6 +596,7 @@ class Fighter : public Behaviour { auto weapon = c->getEquipment().getSlotItems(EquipmentSlot::RANGED_WEAPON); if (weapon.empty()) return 0; + if (c->getAmmoCooldownPoints() < 1) return 0; return weapon.getOnlyElement()->getRangedWeapon()->getMaxDistance(); }