Permalink
Browse files

Pay our way out of shops we're stuck in. Don't beatify or move to fig…

…ht when hallucinating.

Be very paranoid about farlooking @ in minetown.
  • Loading branch information...
1 parent 9f332c6 commit f458a8cf0bd7525acb7ac909aa79313bc7c68764 Ryan Karl committed Apr 18, 2011
View
2 README
@@ -54,7 +54,7 @@ People who are working on or have contributed to saiph:
-------------------------------------------------------
Vidar Wahlberg <canidae@exent.net>, aka. canidae
Stefan O'Rear <stefanor@cox.net>, aka. sorear
-Ryan Karl, aka. rawrmage
+Ryan Karl <rawrnix@rawrnix.com>, aka. rawrmage
Patric Mueller <bhaak@gmx.net>, aka. bhaak
Adrien Panhaleux <adrien.panhaleux@ens-lyon.fr>, aka. DainDwarf
Kenny Root <kenny@the-b.org>, aka. kroot
View
@@ -0,0 +1,59 @@
+#ifndef ACTION_PAY_H
+#define ACTION_PAY_H
+
+#include "World.h"
+#include "Actions/Action.h"
+
+namespace action {
+
+ class Pay : public Action {
+ public:
+ static const int ID;
+
+ Pay(analyzer::Analyzer* analyzer, int priority) : Action(analyzer), _pay("p", priority), _answer_no(NO, PRIORITY_CONTINUE_ACTION), _answer_yes(YES, PRIORITY_CONTINUE_ACTION) {
+ }
+
+ virtual ~Pay() {
+ }
+
+ virtual int id() {
+ return ID;
+ }
+
+ virtual const Command& command() {
+ switch (_sequence) {
+
+ case 0:
+ return _pay;
+
+ case 1:
+ return _answer_no;
+
+ case 2:
+ return _answer_yes;
+
+ default:
+ return Action::NOOP;
+ }
+ }
+
+ virtual void update(const std::string& messages) {
+ if (messages.find(MESSAGE_ITEMIZED_BILLING) != std::string::npos) {
+ /* asking if we want to use itemized billing */
+ _sequence = 1;
+ } else if (messages.find(MESSAGE_PAY) != std::string::npos) {
+ /* we do want to pay for this item */
+ _sequence = 2;
+ } else {
+ /* we finished paying */
+ _sequence = 3;
+ }
+ }
+
+ private:
+ const Command _pay;
+ const Command _answer_no;
+ const Command _answer_yes;
+ };
+}
+#endif
View
@@ -6,6 +6,10 @@
#define SHOP_MESSAGE_LEAVE_TOOL " \"Will you please leave your "
#define SHOP_MESSAGE_LEAVE_TOOL_ANGRY " \"Leave the "
+#define SHOP_MESSAGE_BIT_IT " bit it, you bought it!\" "
+#define SHOP_MESSAGE_USAGE_FEE " Usage fee "
+#define SHOP_MESSAGE_SPELLBOOK " no free library, cad!\" "
+#define PRIORITY_PAY_FOR_ITEMS 400
namespace analyzer {
class Shop : public Analyzer {
@@ -14,6 +18,8 @@ namespace analyzer {
void analyze();
void parseMessages(const std::string&);
+ private:
+ int payed;
};
}
#endif
View
@@ -376,6 +376,7 @@
#define MESSAGE_IN_WHAT_DIRECTION " In what direction? "
#define MESSAGE_IS_DESTROYED " is destroyed! "
#define MESSAGE_IS_KILLED " is killed! "
+#define MESSAGE_ITEMIZED_BILLING " Itemized billing? [yn] (n) "
#define MESSAGE_ITEM_TO_CALL " What do you want to call? "
#define MESSAGE_ITEM_TO_NAME " What do you want to name? "
#define MESSAGE_LEG_IS_BETTER " Your leg feels somewhat better. "
@@ -397,6 +398,7 @@
#define MESSAGE_PERHAPS_THATS_WHY " Perhaps that's why you cannot move it. "
#define MESSAGE_PICK_A_SKILL " Pick a skill to advance: "
#define MESSAGE_PICK_UP_WHAT " Pick up what? "
+#define MESSAGE_PAY " Pay? [yn] (n) "
#define MESSAGE_PLAY_PASSTUNE " Play the passtune? [yn] (n) "
#define MESSAGE_POISON_RES_GAIN1 " You feel healthy. "
#define MESSAGE_POISON_RES_GAIN2 " You feel especially healthy. "
View
@@ -22,6 +22,7 @@
#include "Actions/Move.h"
#include "Actions/Name.h"
#include "Actions/Open.h"
+#include "Actions/Pay.h"
#include "Actions/Pray.h"
#include "Actions/PutOn.h"
#include "Actions/Remove.h"
@@ -69,6 +70,7 @@ const int TakeOff::ID = 29;
const int Wear::ID = 30;
const int Dip::ID = 31;
const int Donate::ID = 32;
+const int Pay::ID = 33;
/* used for the travel command "_" */
Point Move::_last_target;
@@ -91,4 +93,4 @@ bool Action::increaseTurnCounter() {
void Action::failed() {
_analyzer->actionFailed();
-}
+}
@@ -24,8 +24,8 @@ Beatitude::Beatitude() : Analyzer("Beatitude"), _max_priority(ILLEGAL_PRIORITY)
void Beatitude::analyze() {
if (_beatify.size() <= 0)
return; // no items to beatify
- else if (Saiph::blind() || Saiph::confused() || Saiph::stunned())
- return; // no buc-testing while blind/confused/stunned
+ else if (Saiph::blind() || Saiph::confused() || Saiph::stunned() || Saiph::hallucinating())
+ return; // no buc-testing while blind/confused/stunned/hallucinating
else if (_max_priority < World::currentPriority())
return; // got something more important to do
View
@@ -78,7 +78,7 @@ void Fight::analyze() {
Debug::custom(name()) << "Setting action to melee '" << m->second.symbol() << "' with priority " << priority << endl;
continue;
}
- if (Saiph::blind() || Saiph::confused() || Saiph::stunned())
+ if (Saiph::hallucinating() || Saiph::blind() || Saiph::confused() || Saiph::stunned())
continue; // don't move while blind/confused/stunned
/* we can neither melee nor throw at the monster, move towards it */
Tile& tile = World::shortestPath(m->first);
@@ -23,7 +23,8 @@ void MonsterInfo::analyze() {
continue; // don't farlook monsters we can't see
if (_look_at->second.symbol() == 'I' || _look_at->second.symbol() == 'm')
continue; // don't farlook 'I' or 'm' monsters
- if (_look_at->second.attitude() == HOSTILE)
+ /* we're paranoid about @ in minetown (elf/watch switchup) */
+ if (_look_at->second.attitude() == HOSTILE && World::level().branch() != BRANCH_MINETOWN && _look_at->second.symbol() != '@')
continue; // we don't expect hostile monsters to go friendly (XXX: scroll of taming, etc will need special handling)
map<Point, unsigned int>::iterator c = _checked.find(_look_at->first);
if (c != _checked.end() && c->second == World::internalTurn())
View
@@ -6,17 +6,25 @@
#include "Saiph.h"
#include "World.h"
#include "Events/ReceivedItems.h"
+#include "Actions/Action.h"
+#include "Actions/Pay.h"
using namespace analyzer;
using namespace event;
using namespace std;
/* constructors/destructor */
-Shop::Shop() : Analyzer("Shop") {
+Shop::Shop() : Analyzer("Shop"), payed(0) {
}
/* methods */
-void Shop::parseMessages(const string&) {
+void Shop::parseMessages(const string& messages) {
+ if (messages.find(SHOP_MESSAGE_BIT_IT) != string::npos || messages.find(SHOP_MESSAGE_USAGE_FEE) != string::npos || messages.find(SHOP_MESSAGE_SPELLBOOK) != string::npos) { // oops
+ if (World::turn() - payed > 10) {
+ World::setAction(static_cast<action::Action*> (new action::Pay(this, PRIORITY_PAY_FOR_ITEMS)));
+ payed = World::turn();
+ }
+ }
/* FIXME: need to handle pick-axes & stuff */
// if (messages.find(SHOP_MESSAGE_LEAVE_TOOL, 0) != string::npos || messages.find(SHOP_MESSAGE_LEAVE_TOOL_ANGRY, 0) != string::npos) {
// /* we're most likely standing in a doorway, next to a shopkeeper.
@@ -101,7 +109,16 @@ void Shop::analyze() {
for (map<Point, Monster>::const_iterator m = World::level().monsters().begin(); m != World::level().monsters().end(); ++m) {
if (!m->second.shopkeeper() || !m->second.visible())
continue;
-
+
+ if (World::shortestPath('-').cost() < UNREACHABLE) {
+ /* we probably don't owe money, since we can leave */
+ } else {
+ /* we can't leave! let's pay for what we bought */
+ if (World::turn() - payed > 10) { // do other things too
+ World::setAction(static_cast<action::Action*> (new action::Pay(this, PRIORITY_PAY_FOR_ITEMS)));
+ payed = World::turn();
+ }
+ }
/* figure out if we're in the same room as the shopkeeper */
Point nw = Saiph::position();
Point se = Saiph::position();

0 comments on commit f458a8c

Please sign in to comment.