Replace 4-character constants with enums

This covers only the places where they were used to indicate
a preset selection in constructors.

The usage in qdpict where they're actually passed to the Resource Manager,
as well as the 4-character constants representing file types and creator
codes, are still present.
This commit is contained in:
2020-02-21 00:15:56 -05:00
parent 3d7f8f1d2a
commit 7b93726383
14 changed files with 69 additions and 50 deletions

View File

@@ -2609,7 +2609,7 @@ void start_new_game(bool force) {
// Destroy the universe
univ.~cUniverse();
long party_type = 'dflt';
ePartyPreset party_type = PARTY_DEFAULT;
// display_intro();
// If system key held down, create debug party
@@ -2618,7 +2618,7 @@ void start_new_game(bool force) {
#else
if(kb::isKeyPressed(kb::LControl) || kb::isKeyPressed(kb::RControl))
#endif
party_type = 'dbug';
party_type = PARTY_DEBUG;
// And now, reconstruct the universe.
new(&univ) cUniverse(party_type);

View File

@@ -127,9 +127,9 @@ cItem::cItem(){
cursed = concealed = enchanted = unsellable = false;
}
cItem::cItem(long preset) : cItem() {
cItem::cItem(eItemPreset preset) : cItem() {
switch(preset){
case 'nife':
case ITEM_KNIFE:
variety = eItemType::ONE_HANDED;
item_level = 4;
bonus = 1;
@@ -141,7 +141,7 @@ cItem::cItem(long preset) : cItem() {
name = "Knife";
ident = true;
break;
case 'buck':
case ITEM_BUCKLER:
variety = eItemType::SHIELD;
item_level = 1;
awkward = 1;
@@ -152,7 +152,7 @@ cItem::cItem(long preset) : cItem() {
name = "Buckler";
ident = true;
break;
case 'bow ':
case ITEM_BOW:
variety = eItemType::BOW;
weap_type = eSkill::ARCHERY;
graphic_num = 10;
@@ -162,7 +162,7 @@ cItem::cItem(long preset) : cItem() {
name = "Bow";
ident = true;
break;
case 'arrw':
case ITEM_ARROW:
variety = eItemType::ARROW;
item_level = 12;
charges = 12;
@@ -174,7 +174,7 @@ cItem::cItem(long preset) : cItem() {
name = "Arrows";
ident = true;
break;
case 'pole':
case ITEM_POLEARM:
variety = eItemType::TWO_HANDED;
item_level = 9;
weap_type = eSkill::POLE_WEAPONS;
@@ -185,7 +185,7 @@ cItem::cItem(long preset) : cItem() {
name = "Spear";
ident = true;
break;
case 'helm':
case ITEM_HELM:
variety = eItemType::HELM;
item_level = 1;
weap_type = eSkill::INVALID;
@@ -196,7 +196,7 @@ cItem::cItem(long preset) : cItem() {
name = "Helm";
ident = true;
break;
case 'rdsk':
case ITEM_RAZORDISK:
variety = eItemType::THROWN_MISSILE;
item_level = 9;
bonus = 1;
@@ -210,17 +210,17 @@ cItem::cItem(long preset) : cItem() {
name = "Razordisks";
ident = true;
break;
case 'food':
case ITEM_FOOD:
variety = eItemType::FOOD;
graphic_num = 72;
full_name = "Food";
name = "Food";
break;
case 'spel':
case ITEM_SPELL:
variety = eItemType::NON_USE_OBJECT;
graphic_num = 63;
break;
case 'alch':
case ITEM_POTION:
variety = eItemType::POTION;
charges = 1;
graphic_num = 60;
@@ -229,16 +229,16 @@ cItem::cItem(long preset) : cItem() {
name = "Potion";
magic = true;
break;
case 'spec':
case ITEM_SPECIAL:
item_level = -1;
full_name = "Call Special Node";
case 'shop':
case ITEM_SHOP:
graphic_num = 105; // The blank graphic
break;
}
}
cItem::cItem(eAlchemy recipe) : cItem('alch') {
cItem::cItem(eAlchemy recipe) : cItem(ITEM_POTION) {
full_name = get_str("magic-names", int(recipe) + 200);
switch(recipe) {
case eAlchemy::NONE: break;

View File

@@ -20,6 +20,21 @@
namespace legacy { struct item_record_type; };
enum eItemPreset {
ITEM_KNIFE,
ITEM_BUCKLER,
ITEM_BOW,
ITEM_ARROW,
ITEM_POLEARM,
ITEM_HELM,
ITEM_RAZORDISK,
ITEM_FOOD,
ITEM_SPELL,
ITEM_POTION,
ITEM_SPECIAL,
ITEM_SHOP,
};
class cItem {
public:
eItemType variety;
@@ -59,7 +74,7 @@ public:
bool use_magic() const;
cItem();
explicit cItem(long preset);
explicit cItem(eItemPreset preset);
explicit cItem(eAlchemy recipe);
void import_legacy(legacy::item_record_type& old);
void writeTo(std::ostream& file, std::string prefix = "") const;

View File

@@ -290,10 +290,10 @@ void cScenario::import_legacy(legacy::scen_item_data_type& old){
for(short i = 0; i < 256; i++)
ter_types[i].name = old.ter_names[i];
// Some default shops - the five magic shops and the healing shop.
cShop magic_shop('junk');
cShop magic_shop(SHOP_JUNK);
for(short i = 0; i < 5; i++)
shops.push_back(magic_shop);
shops.push_back(cShop('heal'));
shops.push_back(cShop(SHOP_HEALING));
}
static std::string format_version(const unsigned char(& ver)[3]) {
@@ -469,7 +469,7 @@ cItem cScenario::return_treasure(int loot, bool allow_junk) {
case FOOD:
// food doesn't always appear
if(get_ran(1,0,2) == 1) {
treas = cItem('food');
treas = cItem(ITEM_FOOD);
treas.graphic_num += get_ran(1,0,2);
treas.item_level = get_ran(1,5,10);
if(get_ran(1,0,9) == 5)

View File

@@ -58,17 +58,17 @@ cShop::cShop(eShopType type, eShopPrompt prompt, pic_num_t pic, int adj, std::st
cShop::cShop(std::string name) : cShop(eShopType::NORMAL, eShopPrompt::SHOPPING, 0, 0, name) {}
cShop::cShop(long preset) {
cShop::cShop(eShopPreset preset) {
const short loot_index[10] = {1,1,1,1,2,2,2,3,3,4};
if(preset == 'junk') {
if(preset == SHOP_JUNK) {
type = eShopType::RANDOM;
prompt = eShopPrompt::SHOPPING;
face = 0;
name = "Magic Shop";
for(int i = 0; i < 10; i++)
addSpecial(eShopItemType::TREASURE, loot_index[i]);
} else if(preset == 'heal') {
} else if(preset == SHOP_HEALING) {
type = eShopType::ALLOW_DEAD;
prompt = eShopPrompt::HEALING;
face = 41;
@@ -128,7 +128,7 @@ void cShop::refreshItems(std::vector<cItem>& fromList) {
}
static cItem store_mage_spells(short which_s) {
cItem spell('spel');
cItem spell(ITEM_SPELL);
static const short cost[62] = {
// TODO: Costs for the level 1-3 spells
5,5,5,5,5,5,5,5,5,5,
@@ -149,7 +149,7 @@ static cItem store_mage_spells(short which_s) {
}
static cItem store_priest_spells(short which_s) {
cItem spell('spel');
cItem spell(ITEM_SPELL);
static const short cost[62] = {
// TODO: Costs for the level 1-3 spells
5,5,5,5,5,5,5,5,5,5,
@@ -170,7 +170,7 @@ static cItem store_priest_spells(short which_s) {
}
static cItem store_alchemy(short which_s) {
cItem spell('spel');
cItem spell(ITEM_SPELL);
static const short val[20] = {
50,75,30,130,100,
150, 200,200,300,250,

View File

@@ -52,10 +52,12 @@ enum class eShopItemType {
struct cShopItem {
eShopItemType type = eShopItemType::EMPTY;
size_t quantity, index;
cItem item = cItem('shop');
cItem item{ITEM_SHOP};
int getCost(int adj);
};
enum eShopPreset {SHOP_HEALING, SHOP_JUNK};
class cShop {
std::vector<cShopItem> items;
int cost_adj;
@@ -69,7 +71,7 @@ public:
cShop();
cShop(eShopType type, eShopPrompt prompt, pic_num_t pic, int adj, std::string name);
explicit cShop(std::string name);
explicit cShop(long preset);
explicit cShop(eShopPreset preset);
void addItem(size_t i, cItem item, size_t quantity, int chance = 100);
void addSpecial(std::string name, std::string descr, pic_num_t pic, int node, int cost, int quantity);
void addSpecial(eShopItemType type, int n = 0);

View File

@@ -2419,7 +2419,7 @@ static bool add_shop_entry(cDialog& me, std::string type, cShop& shop, size_t wh
shop.addItem(which_item, scenario.scen_items[which_item], amount);
else shop.addItem(which_item, scenario.scen_items[which_item], amount % 1000, amount / 1000);
} else if(type == "spec") {
cItem item('spec');
cItem item(ITEM_SPECIAL);
size_t amount = 0;
edit_shop_special(me, item, amount);
shop.addSpecial(item.full_name, item.desc, item.graphic_num, item.item_level, item.value, amount);
@@ -2486,7 +2486,7 @@ bool edit_shop(size_t which_shop, cDialog* parent) {
shop_dlg.attachClickHandlers(std::bind(edit_shop_entry, _1, _2, std::ref(shop)), {"ed1", "ed2", "ed3", "ed4", "ed5"});
shop_dlg.attachClickHandlers(std::bind(add_shop_entry, _1, _2, std::ref(shop), std::ref(which_shop)), {"item", "opt", "spec", "mage", "priest", "alch", "skill", "treas", "heal", "class"});
shop_dlg["rand"].attachClickHandler([&shop,which_shop](cDialog& me, std::string, eKeyMod) -> bool {
shop = cShop('junk');
shop = cShop(SHOP_JUNK);
put_shop_in_dlog(me, shop, which_shop);
return true;
});
@@ -2988,7 +2988,7 @@ bool build_scenario() {
warriors_grove->reattach(scenario);
}
scenario.shops.push_back(cShop('heal'));
scenario.shops.push_back(cShop(SHOP_HEALING));
overall_mode = MODE_MAIN_SCREEN;

View File

@@ -21,7 +21,7 @@
#include "fileio.hpp"
#include "mathutil.hpp"
cParty::cParty(long party_preset) {
cParty::cParty(ePartyPreset party_preset) {
gold = 200;
food = 100;
// Note: These starting position values were in the original code and so are included here.

View File

@@ -218,7 +218,7 @@ public:
typedef std::vector<cEncNote>::iterator encIter;
typedef std::vector<cJournal>::iterator journalIter;
typedef std::vector<cConvers>::iterator talkIter;
cParty(long party_preset = 'dflt');
cParty(ePartyPreset party_preset = PARTY_DEFAULT);
~cParty();
// Copy-and-swap
void swap(cParty& other);

View File

@@ -896,21 +896,21 @@ void cPlayer::finish_create() {
// Start items
switch(race) {
case eRace::HUMAN:
items[0] = cItem('nife');
items[1] = cItem('buck');
items[0] = cItem(ITEM_KNIFE);
items[1] = cItem(ITEM_BUCKLER);
break;
case eRace::NEPHIL:
items[0] = cItem('bow ');
items[1] = cItem('arrw');
items[0] = cItem(ITEM_BOW);
items[1] = cItem(ITEM_ARROW);
break;
case eRace::SLITH:
items[0] = cItem('pole');
items[1] = cItem('helm');
items[0] = cItem(ITEM_POLEARM);
items[1] = cItem(ITEM_HELM);
break;
case eRace::VAHNATAI:
// TODO: Should they have a robe instead of a knife?
items[0] = cItem('nife');
items[1] = cItem('rdsk');
items[0] = cItem(ITEM_KNIFE);
items[1] = cItem(ITEM_RAZORDISK);
break;
default: break; // Silence compiler warning
// It's impossible to reach this point, anyway.
@@ -971,11 +971,11 @@ cPlayer::cPlayer(cParty& party) : party(&party), weap_poisoned(*this) {
unique_id = party.next_pc_id++;
}
cPlayer::cPlayer(cParty& party,long key,short slot) : cPlayer(party) {
cPlayer::cPlayer(cParty& party,ePartyPreset key,short slot) : cPlayer(party) {
main_status = eMainStatus::ALIVE;
unique_id = slot + 1000;
party.next_pc_id = max(unique_id + 1, party.next_pc_id);
if(key == 'dbug'){
if(key == PARTY_DEBUG){
switch(slot) {
case 0:
name = "Gunther";
@@ -1025,7 +1025,7 @@ cPlayer::cPlayer(cParty& party,long key,short slot) : cPlayer(party) {
race = eRace::HUMAN;
direction = DIR_N;
}else if(key == 'dflt'){
}else if(key == PARTY_DEFAULT){
static std::map<eSkill, short> pc_stats[6] = {
{
{eSkill::STRENGTH,8}, {eSkill::DEXTERITY,6}, {eSkill::INTELLIGENCE,2},

View File

@@ -27,6 +27,8 @@ namespace legacy { struct pc_record_type; };
enum class eBuyStatus {OK, NO_SPACE, NEED_GOLD, TOO_HEAVY, HAVE_LOTS};
enum ePartyPreset {PARTY_BLANK, PARTY_DEFAULT, PARTY_DEBUG};
enum {
GIVE_DO_PRINT = 1,
GIVE_ALLOW_OVERLOAD = 2,
@@ -168,7 +170,7 @@ public:
void import_legacy(legacy::pc_record_type old);
cPlayer(cParty& party);
cPlayer(cParty& party,long key,short slot);
cPlayer(cParty& party,ePartyPreset key,short slot);
short get_tnl();
void writeTo(std::ostream& file) const;
void readFrom(std::istream& file);

View File

@@ -904,7 +904,7 @@ bool cCurOut::is_road(int x, int y) {
return univ.scenario.outdoors[sector_x][sector_y]->roads[x][y];
}
cUniverse::cUniverse(long party_type) : party(party_type), out(*this), town(*this) {}
cUniverse::cUniverse(ePartyPreset party_type) : party(party_type), out(*this), town(*this) {}
cUniverse::cUniverse(const cUniverse& other)
: strbuf(other.strbuf)

View File

@@ -213,7 +213,7 @@ public:
void refresh_store_items();
void generate_job_bank(int which, job_bank_t& bank);
short difficulty_adjust() const;
explicit cUniverse(long party_type = 'dflt');
explicit cUniverse(ePartyPreset party_type = PARTY_DEFAULT);
~cUniverse();
// Copy-and-swap
void swap(cUniverse& other);

View File

@@ -169,10 +169,10 @@ TEST_CASE("Saving a scenario record") {
// Loading/building shops requires strings to be available
// Here we fetch them from the rsrc dir, rather than the data dir
ResMgr::strings.pushPath("../rsrc/strings");
cItem dummy_item('alch');
cItem dummy_item(ITEM_POTION);
scen.shops.resize(3);
scen.shops[0] = cShop('junk');
scen.shops[1] = cShop('heal');
scen.shops[0] = cShop(SHOP_JUNK);
scen.shops[1] = cShop(SHOP_HEALING);
scen.shops[2].setName("The Test Shop");
scen.shops[2].setType(eShopType::NORMAL);
scen.shops[2].setPrompt(eShopPrompt::SHOPPING);