Skip to content

Commit

Permalink
Hopefully made saiph respond to wish prompts so it won't waste wishes.
Browse files Browse the repository at this point in the history
  • Loading branch information
brightcloudy authored and canidae committed Apr 9, 2011
1 parent 4a47b20 commit a1b9106
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 26 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ set(HEADER_FILES
include/Analyzers/Vault.h
# include/Analyzers/Wand.h
include/Analyzers/Weapon.h
# include/Analyzers/Wish.h
include/Analyzers/Wish.h
# Data
include/Data/Amulet.h
include/Data/Armor.h
Expand Down Expand Up @@ -215,7 +215,7 @@ set(SOURCE_FILES
src/Analyzers/Vault.cpp
# src/Analyzers/Wand.cpp
src/Analyzers/Weapon.cpp
# src/Analyzers/Wish.cpp
src/Analyzers/Wish.cpp
# Data
src/Data/Amulet.cpp
src/Data/Armor.cpp
Expand Down
49 changes: 25 additions & 24 deletions src/Analyzers/Wish.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "Analyzers/Wish.h"

#include <string>
#include "Actions/Answer.h"
#include "Inventory.h"
#include "Globals.h"
#include "Saiph.h"
#include "World.h"
Expand All @@ -15,37 +17,36 @@ Wish::Wish(Saiph* saiph) : Analyzer("Wish"), saiph(saiph), wand_of_wishing_key(0

/* methods */
void Wish::parseMessages(const string& messages) {
if (saiph->inventory_changed) {
wand_of_wishing_key = 0;
for (map<unsigned char, Item>::iterator i = saiph->inventory.begin(); i != saiph->inventory.end(); ++i) {
if (i->second.name == "wand of wishing") {
wand_of_wishing_key = i->first;
}
}
}
//if (saiph->inventory_changed) {
//wand_of_wishing_key = 0;
//for (map<unsigned char, Item>::iterator i = saiph->inventory.begin(); i != saiph->inventory.end(); ++i) {
//if (i->second.name == "wand of wishing") {
//wand_of_wishing_key = i->first;
//}
//}
//}
if (messages.find(MESSAGE_FOR_WHAT_DO_YOU_WISH, 0) != string::npos) {
haveMR = saiph->world->player.extrinsics & PROPERTY_MAGICRES;
haveMR = saiph->extrinsics() & PROPERTY_MAGICRES;
if (haveMR) {
MRarmor = wearing("gray dragon scale mail") || wearing("gray dragon scales");
MRcloak = wearing("cloak of magic resistance");
} else
MRarmor = MRcloak = false;
haveReflection = saiph->world->player.extrinsics & PROPERTY_REFLECTION;
haveReflection = saiph->extrinsics() & PROPERTY_REFLECTION;
if (haveReflection) {
reflectionArmor = wearing("silver dragon scale mail") || wearing("silver dragon scales");
reflectionAmulet = wearing("amulet of reflection");
reflectionShield = wearing("shield of reflection");
} else
reflectionArmor = reflectionAmulet = reflectionShield = false;
command = "3 blessed greased fixed +3 " + selectWish();
Debug::notice(saiph->last_turn) << WISH_DEBUG_NAME << "Wishing for " << command << endl;
string command = "blessed greased fixed +3 " + selectWish();
Debug::notice() << WISH_DEBUG_NAME << "Wishing for " << command << endl;
command.append("\n");
priority = PRIORITY_CONTINUE_ACTION;
World::queueAction(static_cast<action::Action*> (new action::Answer(this, command)));
return;
} else if (zapping_wand && messages.find(MESSAGE_WHAT_TO_ZAP, 0) != string::npos) {
zapping_wand = false;
command = wand_of_wishing_key;
priority = PRIORITY_CONTINUE_ACTION;
//string command = wand_of_wishing_key;
return;
}
}
Expand All @@ -54,13 +55,13 @@ void Wish::analyze() {
//if we have a wand of wishing, we need to decide if we should zap
//TODO: get charging and recharge it; currently it'll wrest it before charging
//since it has no idea of "this wand is empty"
if (wand_of_wishing_key != 0) {
if (!haveReflection || !haveMR || !wearing("speed boots") || !wearing("gauntlets of power")) {
zapping_wand = true;
command = ZAP_WAND;
priority = PRIORITY_WISH_ZAP_WAND;
}
}
//if (wand_of_wishing_key != 0) {
//if (!haveReflection || !haveMR || !wearing("speed boots") || !wearing("gauntlets of power")) {
//zapping_wand = true;
//command = ZAP_WAND;
//priority = PRIORITY_WISH_ZAP_WAND;
//}
//}
}

string Wish::selectWish() {
Expand All @@ -86,8 +87,8 @@ string Wish::selectWish() {
}

bool Wish::wearing(const string& name) {
for (map<unsigned char, Item>::iterator i = saiph->inventory.begin(); i != saiph->inventory.end(); ++i)
if (i->second.name.find(name) != string::npos)
for (map<unsigned char, Item>::iterator i = Inventory::items().begin(); i != Inventory::items().end(); ++i)
if (i->second.name().find(name) != string::npos)
return true;
return false;
}

0 comments on commit a1b9106

Please sign in to comment.