Skip to content

Commit

Permalink
Show vocations on runes look message
Browse files Browse the repository at this point in the history
  • Loading branch information
ranisalt committed Jan 5, 2016
1 parent 545dd73 commit 4cd4c2f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 10 deletions.
44 changes: 39 additions & 5 deletions src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,12 @@

#include "actions.h"
#include "combat.h"
#include "spells.h"
#include "vocation.h"

extern Game g_game;
extern Spells* g_spells;
extern Vocations g_vocations;

Items Item::items;

Expand Down Expand Up @@ -814,18 +818,48 @@ std::string Item::getDescription(const ItemType& it, int32_t lookDistance,
}

if (it.isRune()) {
if (!it.runeSpellName.empty()) {
s << " (\"" << it.runeSpellName << "\")";
}

if (it.runeLevel > 0 || it.runeMagLevel > 0) {
int32_t tmpSubType = subType;

if (item) {
tmpSubType = item->getSubType();
}

s << ". " << (it.stackable && tmpSubType > 1 ? "They" : "It") << " can only be used with";
s << ". " << (it.stackable && tmpSubType > 1 ? "They" : "It") << " can only be used by ";

VocSpellMap vocMap = g_spells->getRuneSpell(it.id)->getVocMap();
if (vocMap.empty()) {
s << "players";
} else {
std::vector<Vocation*> showVocMap;

// vocations listed are mostly unpromoted ones and the promoted version, with the latter hidden from
// description, so probably always `total / 2` is the amount of vocations to be shown.
showVocMap.reserve(vocMap.size() / 2);

for (const auto& voc: vocMap) {
if (voc.second) {
showVocMap.push_back(g_vocations.getVocation(voc.first));
}
}

auto vocIt = showVocMap.begin(), vocLast = (showVocMap.end() - 1);

while (vocIt != vocLast) {
auto vocName = asLowerCaseString((*vocIt)->getVocName());
++vocIt;

s << vocName << "s";
if (vocIt == vocLast) {
s << " and ";
} else {
s << ", ";
}
}
s << asLowerCaseString((*vocLast)->getVocName()) << "s";
}

s << " with";

if (it.runeLevel > 0) {
s << " level " << it.runeLevel;
Expand Down
7 changes: 2 additions & 5 deletions src/spells.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -572,11 +572,8 @@ bool Spell::configureSpell(const pugi::xml_node& node)

int32_t vocationId = g_vocations.getVocationId(attr.as_string());
if (vocationId != -1) {
vocSpellMap[vocationId] = true;
int32_t promotedVocation = g_vocations.getPromotedVocation(vocationId);
if (promotedVocation != VOCATION_NONE) {
vocSpellMap[promotedVocation] = true;
}
attr = vocationNode.attribute("showInDescription");
vocSpellMap[vocationId] = not attr or attr.as_bool();
} else {
std::cout << "[Warning - Spell::configureSpell] Wrong vocation name: " << attr.as_string() << std::endl;
}
Expand Down

0 comments on commit 4cd4c2f

Please sign in to comment.