Strictify and use talk node type enum

This commit is contained in:
2015-01-17 02:41:25 -05:00
parent 544cc80e56
commit 4e2c0100e8
8 changed files with 94 additions and 90 deletions

View File

@@ -480,7 +480,8 @@ void handle_talk_event(location p) {
short i,get_pc,s1 = -1,s2 = -1,s3 = -1;
char asked[4];
short a,b,c,d,ttype;
short a,b,c,d;
eTalkNode ttype;
p.x -= 5;
p.y -= 5;
@@ -593,9 +594,9 @@ void handle_talk_event(location p) {
strnum1 = 40 + which_talk_entry * 2; strnum2 = 40 + which_talk_entry * 2 + 1;
switch(ttype) {
case 0:
case eTalkNode::REGULAR:
break;
case 1:
case eTalkNode::DEP_ON_SDF:
if(PSD[a][b] > c) {
strnum1 = strnum2;
save_talk_str1 = save_talk_str2;
@@ -603,10 +604,10 @@ void handle_talk_event(location p) {
save_talk_str2 = "";
strnum2 = 0;
break;
case 2:
case eTalkNode::SET_SDF:
PSD[a][b] = 1;
break;
case 3:
case eTalkNode::INN:
if(univ.party.gold < a) {
strnum1 = strnum2;
save_talk_str1 = save_talk_str2;
@@ -623,7 +624,7 @@ void handle_talk_event(location p) {
strnum2 = 0;
save_talk_str2 = "";
break;
case 4:
case eTalkNode::DEP_ON_TIME:
if(day_reached((unsigned char) a,0)) {
strnum1 = strnum2;
save_talk_str1 = save_talk_str2;
@@ -631,7 +632,7 @@ void handle_talk_event(location p) {
save_talk_str2 = "";
strnum2 = 0;
break;
case 5:
case eTalkNode::DEP_ON_TIME_AND_EVENT:
if(day_reached((unsigned char) a,(unsigned char) b)) {
strnum1 = strnum2;
save_talk_str1 = save_talk_str2;
@@ -639,7 +640,7 @@ void handle_talk_event(location p) {
save_talk_str2 = "";
strnum2 = 0;
break;
case 6:
case eTalkNode::DEP_ON_TOWN:
if(univ.town.num != a) {
strnum1 = strnum2;
save_talk_str1 = save_talk_str2;
@@ -647,12 +648,12 @@ void handle_talk_event(location p) {
save_talk_str2 = "";
strnum2 = 0;
break;
case 7:
case eTalkNode::BUY_ITEMS:
c = minmax(1,30,c);
start_shop_mode(eShopType::ITEMS,b,b + c - 1,a,save_talk_str1.c_str());
strnum1 = -1;
return;
case 8:
case eTalkNode::TRAINING:
if((get_pc = char_select_pc(0,"Train who?")) < 6) {
strnum1 = -1;
spend_xp(get_pc,1, NULL);
@@ -660,54 +661,54 @@ void handle_talk_event(location p) {
save_talk_str1 = "You conclude your training.";
return;
case 9:
case eTalkNode::BUY_MAGE:
c = minmax(1,61,c);
start_shop_mode(eShopType::MAGE,b,b + c - 1,a,save_talk_str1.c_str());
strnum1 = -1;
return;
case 10:
case eTalkNode::BUY_PRIEST:
c = minmax(1,61,c);
start_shop_mode(eShopType::PRIEST,b,b + c - 1,a,save_talk_str1.c_str());
strnum1 = -1;
return;
case 11:
case eTalkNode::BUY_ALCHEMY:
c = minmax(1,19,c);
start_shop_mode(eShopType::ALCHEMY,b,b + c - 1,a,save_talk_str1.c_str());
strnum1 = -1;
return;
case 12: //healer
case eTalkNode::BUY_HEALING:
// TODO: extra1 and extra2 are actually never used! So remove them.
start_shop_mode(eShopType::HEALING,univ.town.monst[store_m_num].extra1,
univ.town.monst[store_m_num].extra2,a,save_talk_str1.c_str());
strnum1 = -1;
return;
break;
case 13: // sell weap
case eTalkNode::SELL_WEAPONS:
strnum1 = -1;
stat_screen_mode = 3;
put_item_screen(stat_window,1);
give_help(42,43);
break;
case 14: // sell armor
case eTalkNode::SELL_ARMOR:
strnum1 = -1;
stat_screen_mode = 4;
put_item_screen(stat_window,1);
give_help(42,43);
break;
case 15: // sell misc
case eTalkNode::SELL_ITEMS:
strnum1 = -1;
stat_screen_mode = 5;
put_item_screen(stat_window,1);
give_help(42,43);
break;
case 16: case 17: // ident enchant
case eTalkNode::IDENTIFY: case eTalkNode::ENCHANT:
strnum1 = -1;
stat_screen_mode = (ttype == 16) ? 2 : 6;
stat_screen_mode = (ttype == eTalkNode::IDENTIFY) ? 2 : 6;
shop_identify_cost = a;
put_item_screen(stat_window,1);
give_help(ttype - 16 + 44,0);
give_help(ttype == eTalkNode::IDENTIFY ? 44 : 45,0);
break;
case 18:
case eTalkNode::BUY_INFO:
if(univ.party.gold < a) {
strnum1 = strnum2;
save_talk_str1 = save_talk_str2;
@@ -720,7 +721,7 @@ void handle_talk_event(location p) {
save_talk_str2 = "";
strnum2 = 0;
break;
case 19:
case eTalkNode::BUY_SDF:
if((sd_legit(b,c)) && (PSD[b][c] == d)) {
save_talk_str1 = "You've already learned that.";
strnum1 = -1;
@@ -739,7 +740,7 @@ void handle_talk_event(location p) {
strnum2 = 0;
save_talk_str2 = "";
break;
case 20:
case eTalkNode::BUY_SHIP:
if(univ.party.gold < a) {
strnum1 = strnum2;
strnum2 = 0;
@@ -765,7 +766,7 @@ void handle_talk_event(location p) {
strnum1 = -1;
strnum2 = -1;
break;
case 21:
case eTalkNode::BUY_HORSE:
if(univ.party.gold < a) {
strnum1 = strnum2;
strnum2 = 0;
@@ -791,7 +792,7 @@ void handle_talk_event(location p) {
strnum1 = -1;
strnum2 = -1;
break;
case 22:
case eTalkNode::BUY_SPEC_ITEM:
if(univ.party.spec_items[a] > 0) {
save_talk_str1 = "You already have it.";
strnum1 = -1;
@@ -808,12 +809,12 @@ void handle_talk_event(location p) {
strnum2 = 0;
save_talk_str2 = "";
break;
case 23:
case eTalkNode::BUY_JUNK:
start_shop_mode(eShopType(5 + b),0,
9,a,save_talk_str1.c_str());
strnum1 = -1;
return;
case 24:
case eTalkNode::BUY_TOWN_LOC:
if(univ.party.can_find_town[b]) {
// TODO: Uh, is something supposed to happen here?
}
@@ -829,19 +830,19 @@ void handle_talk_event(location p) {
strnum2 = 0;
save_talk_str2 = "";
break;
case 25:
case eTalkNode::END_FORCE:
talk_end_forced = true;
break;
case 26:
case eTalkNode::END_FIGHT:
univ.town.monst[store_m_num].attitude = 1;
univ.town.monst[store_m_num].mobility = 1;
talk_end_forced = true;
break;
case 27:
case eTalkNode::END_ALARM:
make_town_hostile();
talk_end_forced = true;
break;
case 28:
case eTalkNode::END_DIE:
// TODO: Any reason not to call something like kill_monst?
univ.town.monst[store_m_num].active = 0;
// Special killing effects
@@ -850,7 +851,7 @@ void handle_talk_event(location p) {
talk_end_forced = true;
break;
// TODO: Strings resulting from this don't seem to be recordable; whyever not?
case 29: // town special
case eTalkNode::CALL_TOWN_SPEC:
run_special(eSpecCtx::TALK,2,a,univ.town.p_loc,&s1,&s2,&s3);
// check s1 & s2 to see if we got diff str, and, if so, munch old strs
if((s1 >= 0) || (s2 >= 0)) {
@@ -865,7 +866,7 @@ void handle_talk_event(location p) {
put_pc_screen();
put_item_screen(stat_window,0);
break;
case 30: // scen special
case eTalkNode::CALL_SCEN_SPEC:
run_special(eSpecCtx::TALK,0,a,univ.town.p_loc,&s1,&s2,&s3);
// check s1 & s2 to see if we got diff str, and, if so, munch old strs
if((s1 >= 0) || (s2 >= 0)) {

View File

@@ -685,38 +685,38 @@ inline eSpecCat getNodeCategory(eSpecType node) {
return eSpecCat::INVALID;
}
enum eTalkNodeType {
TALK_REGULAR = 0,
TALK_DEP_ON_SDF = 1,
TALK_SET_SDF = 2,
TALK_INN = 3,
TALK_DEP_ON_TIME = 4,
TALK_DEP_ON_TIME_AND_EVENT = 5,
TALK_DEP_ON_TOWN = 6,
TALK_BUY_ITEMS = 7,
TALK_TRAINING = 8,
TALK_BUY_MAGE = 9,
TALK_BUY_PRIEST = 10,
TALK_BUY_ALCHEMY = 11,
TALK_BUY_HEALING = 12,
TALK_SELL_WEAPONS = 13,
TALK_SELL_ARMOR = 14,
TALK_SELL_ITEMS = 15,
TALK_IDENTIFY = 16,
TALK_ENCHANT = 17,
TALK_BUY_INFO = 18,
TALK_BUY_SDF = 19,
TALK_BUY_SHIP = 20,
TALK_BUY_HORSE = 21,
TALK_BUY_SPEC_ITEM = 22,
TALK_BUY_JUNK = 23,
TALK_BUY_TOWN_LOC = 24,
TALK_END_FORCE = 25,
TALK_END_FIGHT = 26,
TALK_END_ALARM = 27, // Town hostile
TALK_END_DIE = 28,
TALK_CALL_TOWN_SPEC = 29,
TALK_CALL_SCEN_SPEC = 30,
enum class eTalkNode {
REGULAR = 0,
DEP_ON_SDF = 1,
SET_SDF = 2,
INN = 3,
DEP_ON_TIME = 4,
DEP_ON_TIME_AND_EVENT = 5,
DEP_ON_TOWN = 6,
BUY_ITEMS = 7,
TRAINING = 8,
BUY_MAGE = 9,
BUY_PRIEST = 10,
BUY_ALCHEMY = 11,
BUY_HEALING = 12,
SELL_WEAPONS = 13,
SELL_ARMOR = 14,
SELL_ITEMS = 15,
IDENTIFY = 16,
ENCHANT = 17,
BUY_INFO = 18,
BUY_SDF = 19,
BUY_SHIP = 20,
BUY_HORSE = 21,
BUY_SPEC_ITEM = 22,
BUY_JUNK = 23,
BUY_TOWN_LOC = 24,
END_FORCE = 25,
END_FIGHT = 26,
END_ALARM = 27, // Town hostile
END_DIE = 28,
CALL_TOWN_SPEC = 29,
CALL_SCEN_SPEC = 30,
};
enum eEncNoteType {

View File

@@ -20,7 +20,7 @@ void cSpeech::append(legacy::talking_record_type& old){
strlens[i] = old.strlens[i];
for(i = 0; i < 60; i++){
talk_nodes[i].personality = old.talk_nodes[i].personality;
talk_nodes[i].type = old.talk_nodes[i].type;
talk_nodes[i].type = eTalkNode(old.talk_nodes[i].type);
for(j = 0; j < 4; j++){
talk_nodes[i].link1[j] = old.talk_nodes[i].link1[j];
talk_nodes[i].link2[j] = old.talk_nodes[i].link2[j];

View File

@@ -26,7 +26,8 @@ class cSpeech { // formerly talking_record_type
public:
class cNode { // formerly talking_node_type
public:
short personality,type;
short personality;
eTalkNode type;
char link1[4],link2[4];
short extras[4];
std::string str1, str2;

View File

@@ -122,7 +122,7 @@ cTown::cTown(cScenario& scenario, bool init_strings) : scenario(scenario) {
strong_barriers = defy_scrying = defy_mapping = is_hidden = false;
for(i = 0; i < 60; i++) {
talking.talk_nodes[i].personality = -1;
talking.talk_nodes[i].type = 0;
talking.talk_nodes[i].type = eTalkNode::REGULAR;
talking.talk_nodes[i].extras[0] = 0;
talking.talk_nodes[i].extras[1] = 0;
talking.talk_nodes[i].extras[2] = 0;

View File

@@ -43,7 +43,7 @@ size_t num_strs(short str_mode) {
}
//cre = check range error
bool cre(short val,short min,short max,const char *text1,const char *text2,cDialog* parent) {
bool cre(short val,short min,short max,std::string text1,std::string text2,cDialog* parent) {
if((val < min) || (val > max)) {
giveError(text1,text2,parent);
return true;

View File

@@ -13,7 +13,7 @@ enum eStrType {
STRT_STATUS, STRT_SPELL_PAT,
};
bool cre(short val,short min,short max,const char *text1,const char *text2,cDialog* parent) ;
bool cre(short val,short min,short max,std::string text1,std::string text2,cDialog* parent) ;
void display_strings(char *text1, char *text2,
char *title,short sound_num,short graphic_num,short graphic_type,cDialog* parent);
void put_choice_pics(short g_type);

View File

@@ -873,40 +873,41 @@ static bool save_talk_node(cDialog& me, std::string item_hit, std::stack<short>&
talk_node.extras[i] = me["extra" + std::to_string(i + 1)].getTextAsNum();
switch(talk_node.type) {
case 1: case 2:
case eTalkNode::DEP_ON_SDF: case eTalkNode::SET_SDF:
if(cre(talk_node.extras[0],0,299,"First part of Stuff Done flag must be from 0 to 299.","",&me)) return false;
if(cre(talk_node.extras[1],0,9,"Second part of Stuff Done flag must be from 0 to 9.","",&me)) return false;
break;
case 3:
case eTalkNode::INN:
if(cre(talk_node.extras[0],0,1000,"Inn cost must be from 0 to 1000.","",&me)) return false;
if(cre(talk_node.extras[1],0,3,"Inn quality must be from 0 to 3.","",&me)) return false;
break;
case 5:
case eTalkNode::DEP_ON_TIME_AND_EVENT:
if(cre(talk_node.extras[1],0,9,"Event must be from 0 to 9. (0 means no event)","",&me)) return false;
break;
case 6:
if(cre(talk_node.extras[0],0,199,"Town number must be from 0 to 199.","",&me)) return false;
case eTalkNode::DEP_ON_TOWN:
if(cre(talk_node.extras[0],0,scenario.towns.size(),"Town number must be from 0 to " + std::to_string(scenario.towns.size()) + ".","",&me)) return false;
break;
case 7: case 9: case 10: case 11: case 12:
case eTalkNode::BUY_ITEMS: case eTalkNode::BUY_MAGE: case eTalkNode::BUY_PRIEST:
case eTalkNode::BUY_ALCHEMY: case eTalkNode::BUY_HEALING:
if(cre(talk_node.extras[0],0,6,"Cost adjustment must be from 0 (cheapest) to 6 (most expensive).","",&me)) return false;
break;
case 17:
case eTalkNode::ENCHANT:
if(cre(talk_node.extras[0],0,6,"Enchantment type must be from 0 to 6. See the documentation for a list of possible abilities.","",&me)) return false;
break;
case 19: case 23:
case eTalkNode::BUY_SDF:
if(cre(talk_node.extras[1],0,299,"First part of Stuff Done flag must be from 0 to 299.","",&me)) return false;
if(cre(talk_node.extras[2],0,9,"Second part of Stuff Done flag must be from 0 to 9.","",&me)) return false;
break;
case 20: case 21:
case eTalkNode::BUY_SHIP: case eTalkNode::BUY_HORSE:
if(cre(talk_node.extras[1],0,29,"The first boat/horse must be in the legal range (0 - 29).","",&me)) return false;
break;
case 22:
case eTalkNode::BUY_SPEC_ITEM:
if(cre(talk_node.extras[0],0,49,"The special item must be in the legal range (0 - 49).","",&me)) return false;
break;
case 29:
case eTalkNode::CALL_TOWN_SPEC:
if(cre(talk_node.extras[0],-1,99,"The town special node called must be in the legal range (0 - 99), or -1 for No Special.","",&me)) return false;
break;
case 30:
case eTalkNode::CALL_SCEN_SPEC:
if(cre(talk_node.extras[0],-1,255,"The scenario special node called must be in the legal range (0 - 255), or -1 for No Special.","",&me)) return false;
break;
}
@@ -930,7 +931,7 @@ static void put_talk_node_in_dlog(cDialog& me, std::stack<short>& talk_edit_stac
for(int i = 0; i < 4; i++) link += talk_node.link2[i];
me["key2"].setText(link);
int iDescBase = talk_node.type * 7;
int iDescBase = int(talk_node.type) * 7;
static const char*const strIDs[] = {"type", "lblA", "lblB", "lblC", "lblD", "lbl1", "lbl2"};
for(int i = 0; i < 7; i++)
me[strIDs[i]].setText(get_str("talk-node-descs", iDescBase + i + 1));
@@ -941,10 +942,10 @@ static void put_talk_node_in_dlog(cDialog& me, std::stack<short>& talk_edit_stac
me["str1"].setText(talk_node.str1);
me["str2"].setText(talk_node.str2);
if(talk_node.type == 7 || talk_node.type == 9 || talk_node.type == 10 || talk_node.type == 11)
if(talk_node.type == eTalkNode::BUY_ITEMS || talk_node.type == eTalkNode::BUY_MAGE || talk_node.type == eTalkNode::BUY_PRIEST || talk_node.type == eTalkNode::BUY_ALCHEMY)
me["chooseB"].show();
else me["chooseB"].hide();
if(talk_node.type != 29 && talk_node.type != 30)
if(talk_node.type != eTalkNode::CALL_TOWN_SPEC && talk_node.type != eTalkNode::CALL_SCEN_SPEC)
me["chooseA"].hide();
else me["chooseA"].show();
@@ -981,8 +982,9 @@ static bool talk_node_branch(cDialog& me, std::stack<short>& talk_edit_stack) {
}
static bool select_talk_node_type(cDialog& me, std::stack<short>& talk_edit_stack) {
short& i = town->talking.talk_nodes[talk_edit_stack.top()].type;
short i = short(town->talking.talk_nodes[talk_edit_stack.top()].type);
i = choose_text(STRT_TALK_NODE, i, &me, "What Talking Node type?");
town->talking.talk_nodes[talk_edit_stack.top()].type = eTalkNode(i);
put_talk_node_in_dlog(me, talk_edit_stack);
return true;
}
@@ -992,13 +994,13 @@ static bool select_talk_node_value(cDialog& me, std::string item_hit, const std:
if(item_hit == "chooseB") {
int i = me["extra2"].getTextAsNum();
switch(talk_node.type) {
case 9:
case eTalkNode::BUY_MAGE:
i = choose_text(STRT_MAGE,i,&me,"What is the first mage spell in the shop?");
break;
case 10:
case eTalkNode::BUY_PRIEST:
i = choose_text(STRT_PRIEST,i,&me,"What is the first priest spell in the shop?");
break;
case 11:
case eTalkNode::BUY_ALCHEMY:
i = choose_text(STRT_ALCHEMY,i,&me,"What is the first recipe in the shop?");
break;
default:
@@ -1008,7 +1010,7 @@ static bool select_talk_node_value(cDialog& me, std::string item_hit, const std:
me["extra1"].setTextToNum(i);
} else if(item_hit == "chooseA") {
int spec = me["extra1"].getTextAsNum();
int mode = talk_node.type == 29 ? 2 : 0;
int mode = talk_node.type == eTalkNode::CALL_TOWN_SPEC ? 2 : 0;
if(spec < 0 || spec >= 100) {
spec = get_fresh_spec(mode);
if(spec < 0) {