Fix training dialog not functioning in the PC editor

This commit is contained in:
2015-02-05 13:06:46 -05:00
parent e71ebdc895
commit aa938178ce
3 changed files with 119 additions and 71 deletions

View File

@@ -64,7 +64,7 @@ bool handle_action(sf::Event event) {
pick_race_abil(&univ.party[current_active_pc],0); pick_race_abil(&univ.party[current_active_pc],0);
break; break;
case 3: case 3:
spend_xp(current_active_pc,1,NULL); spend_xp(current_active_pc,2,NULL);
break; break;
case 4: case 4:
edit_xp(&univ.party[current_active_pc]); edit_xp(&univ.party[current_active_pc]);

View File

@@ -280,13 +280,56 @@ static void do_xp_keep(xp_dlog_state& save) {
} }
static bool can_change_skill(eSkill skill, xp_dlog_state& save, bool increase) {
unsigned int min_level, max_level, cur_level, orig_level, cost, g_cost;
if(skill == eSkill::MAX_HP) {
min_level = 6;
max_level = 250;
cur_level = save.hp;
orig_level = univ.party[save.who].max_health;
cost = 1;
g_cost = 10;
} else if(skill == eSkill::MAX_SP) {
min_level = 0;
max_level = 150;
cur_level = save.sp;
orig_level = univ.party[save.who].max_sp;
cost = 1;
g_cost = 15;
} else {
if(skill == eSkill::STRENGTH || skill == eSkill::DEXTERITY || skill == eSkill::INTELLIGENCE)
min_level = 1;
else min_level = 0;
max_level = skill_max[skill];
cur_level = save.skills[skill];
orig_level = univ.party[save.who].skills[skill];
cost = skill_cost[skill];
g_cost = skill_g_cost[skill];
}
if(increase) {
if(cur_level == max_level)
return false;
if(save.mode < 2 && save.skp < cost)
return false;
if(save.mode == 1 && save.g < g_cost)
return false;
return true;
} else {
if(cur_level == min_level)
return false;
if(save.mode == 1 && cur_level == orig_level)
return false;
return true;
}
}
static void draw_xp_skills(cDialog& me,xp_dlog_state& save) { static void draw_xp_skills(cDialog& me,xp_dlog_state& save) {
short i; short i;
// TODO: Wouldn't it make more sense for it to be red when you can't buy the skill rather than red when you can? // TODO: Wouldn't it make more sense for it to be red when you can't buy the skill rather than red when you can?
for(i = 0; i < 19; i++) { for(i = 0; i < 19; i++) {
cControl& cur = me[skill_ids[i]]; cControl& cur = me[skill_ids[i]];
eSkill skill = eSkill(i); eSkill skill = eSkill(i);
if((save.skp >= skill_cost[skill]) && (save.g >= skill_g_cost[skill])) if(can_change_skill(skill, save, true))
cur.setColour(sf::Color::Red); cur.setColour(sf::Color::Red);
else cur.setColour(me.getDefTextClr()); else cur.setColour(me.getDefTextClr());
cur.setTextToNum(save.skills[skill]); cur.setTextToNum(save.skills[skill]);
@@ -294,11 +337,11 @@ static void draw_xp_skills(cDialog& me,xp_dlog_state& save) {
cControl& sp = me["sp"]; cControl& sp = me["sp"];
cControl& hp = me["hp"]; cControl& hp = me["hp"];
if((save.skp >= 1) && (save.g >= 10)) if(can_change_skill(eSkill::MAX_HP, save, true))
hp.setColour(sf::Color::Red); hp.setColour(sf::Color::Red);
else hp.setColour(me.getDefTextClr()); else hp.setColour(me.getDefTextClr());
hp.setTextToNum(save.hp); hp.setTextToNum(save.hp);
if((save.skp >= 1) && (save.g >= 15)) if(can_change_skill(eSkill::MAX_SP, save, true))
sp.setColour(sf::Color::Red); sp.setColour(sf::Color::Red);
else sp.setColour(me.getDefTextClr()); else sp.setColour(me.getDefTextClr());
sp.setTextToNum(save.sp); sp.setTextToNum(save.sp);
@@ -373,25 +416,29 @@ static bool spend_xp_event_filter(cDialog& me, std::string item_hit, eKeyMod mod
cStrDlog aboutHP(get_str("help",63),"","About Health",24,PIC_DLOG,&me); cStrDlog aboutHP(get_str("help",63),"","About Health",24,PIC_DLOG,&me);
aboutHP.setSound(57); aboutHP.setSound(57);
aboutHP.show(); aboutHP.show();
} else if(((save.hp >= 250) && (item_hit[3] == 'p')) || } else if(item_hit[3] == 'm') {
((save.hp == univ.party[save.who].max_health) && (item_hit[3] == 'm') && (save.mode == 1)) || if(can_change_skill(eSkill::MAX_HP, save, false)) {
((save.hp == 6) && (item_hit[3] == 'm') && (save.mode == 0))) save.hp -= 2;
beep(); // TODO: This is a game event, so it should have a game sound, not a system alert. if(save.mode < 2) {
else if(item_hit == "hp-m") { save.skp += 1;
save.g += 10; if(save.mode == 1)
save.hp -= 2; save.g += 10;
save.skp += 1; }
} } else beep(); // TODO: This is a game event, so it should have a game sound, not a system alert.
else { } else if(item_hit[3] == 'p') {
if((save.g < 10) || (save.skp < 1)) { if(can_change_skill(eSkill::MAX_SP, save, true)) {
if(save.g < 10)
give_help(24,0,me);
else give_help(25,0,me);
}
else {
save.g -= 10;
save.hp += 2; save.hp += 2;
save.skp -= 1; if(save.mode < 2) {
save.skp -= 1;
if(save.mode == 1)
save.g -= 10;
}
} else {
if(save.mode < 2 && save.skp < 1)
give_help(25,0,me);
else if(save.mode == 1 && save.g < 10)
give_help(24,0,me);
else beep();
} }
} }
@@ -404,25 +451,29 @@ static bool spend_xp_event_filter(cDialog& me, std::string item_hit, eKeyMod mod
cStrDlog aboutSP(get_str("help",64),"","About Spell Points",24,PIC_DLOG,&me); cStrDlog aboutSP(get_str("help",64),"","About Spell Points",24,PIC_DLOG,&me);
aboutSP.setSound(57); aboutSP.setSound(57);
aboutSP.show(); aboutSP.show();
} else if(((save.sp >= 150) && (item_hit[3] == 'p')) || } else if(item_hit[3] == 'm') {
((save.sp == univ.party[save.who].max_sp) && (item_hit[3] == 'm') && (save.mode == 1)) || if(can_change_skill(eSkill::MAX_SP, save, false)) {
((save.sp == 0) && (item_hit[3] == 'm') && (save.mode == 0))) save.sp -= 1;
beep(); // TODO: This is a game event, so it should have a game sound, not a system alert. if(save.mode < 2) {
else if(item_hit == "sp-m") { save.skp += 1;
save.g += 15; if(save.mode == 1)
save.sp -= 1; save.g += 15;
save.skp += 1; }
} } else beep(); // TODO: This is a game event, so it should have a game sound, not a system alert.
else { } else if(item_hit[3] == 'p') {
if((save.g < 15) || (save.skp < 1)) { if(can_change_skill(eSkill::MAX_SP, save, true)) {
if(save.g < 15)
give_help(24,0,me);
else give_help(25,0,me);
}
else {
save.sp += 1; save.sp += 1;
save.g -= 15; if(save.mode < 2) {
save.skp -= 1; save.skp -= 1;
if(save.mode == 1)
save.g -= 15;
}
} else {
if(save.mode < 2 && save.skp < 1)
give_help(25,0,me);
else if(save.mode == 1 && save.g < 15)
give_help(24,0,me);
else beep();
} }
} }
@@ -444,47 +495,44 @@ static bool spend_xp_event_filter(cDialog& me, std::string item_hit, eKeyMod mod
else { else {
char dir = item_hit[item_hit.length() - 1]; char dir = item_hit[item_hit.length() - 1];
// TODO: This is a game event, so it should have a game sound, not a system alert. if(dir == 'm') {
if(save.skills[which_skill] >= skill_max[which_skill] && dir == 'p') if(can_change_skill(which_skill, save, false)) {
beep();
else if(save.skills[which_skill] == univ.party[save.who].skills[which_skill] && dir == 'm' && save.mode == 1)
beep();
else if(save.skills[which_skill] == 0 && dir == 'm' && save.mode == 0 &&
which_skill != eSkill::STRENGTH && which_skill != eSkill::DEXTERITY && which_skill != eSkill::INTELLIGENCE)
beep();
else if(save.skills[which_skill] == 1 && dir == 'm' && save.mode == 0 &&
(which_skill == eSkill::STRENGTH || which_skill == eSkill::DEXTERITY || which_skill == eSkill::INTELLIGENCE))
beep();
else {
if(dir == 'm') {
save.g += skill_g_cost[which_skill];
save.skills[which_skill] -= 1; save.skills[which_skill] -= 1;
save.skp += skill_cost[which_skill]; if(save.mode < 2) {
} save.skp += skill_cost[which_skill];
else { if(save.mode == 1)
if((save.g < skill_g_cost[which_skill]) || (save.skp < skill_cost[which_skill])) { save.g += skill_g_cost[which_skill];
if(save.g < skill_g_cost[which_skill])
give_help(24,0,me);
else give_help(25,0,me);
} }
else { } else beep(); // TODO: This is a game event, so it should have a game sound, not a system alert.
save.skills[which_skill] += 1; } else if(dir == 'p') {
save.g -= skill_g_cost[which_skill]; if(can_change_skill(which_skill, save, true)) {
save.skills[which_skill] += 1;
if(save.mode < 2) {
save.skp -= skill_cost[which_skill]; save.skp -= skill_cost[which_skill];
if(save.mode == 1)
save.g -= skill_g_cost[which_skill];
} }
} else {
if(save.mode < 2 && save.skp < skill_cost[which_skill])
give_help(25,0,me);
else if(save.mode == 1 && save.g < skill_g_cost[which_skill])
give_help(24,0,me);
else beep(); // TODO: This is a game event, so it should have a game sound, not a system alert.
} }
update_gold_skills(me, save);
me[skill_ids[int(which_skill)]].setTextToNum(save.skills[which_skill]);
draw_xp_skills(me,save);
} }
update_gold_skills(me, save);
me[skill_ids[int(which_skill)]].setTextToNum(save.skills[which_skill]);
draw_xp_skills(me,save);
} }
} }
return true; return true;
} }
//short mode; // 0 - create 1 - train // Mode is one of the following:
// returns 1 if cancelled // 0 - Creating a new character (need skill points but not gold)
// 1 - Training a character (need both skill points and gold)
// 2 - Editing a character (need neither skill points nor gold)
bool spend_xp(short pc_num, short mode, cDialog* parent) { bool spend_xp(short pc_num, short mode, cDialog* parent) {
using namespace std::placeholders; using namespace std::placeholders;

View File

@@ -302,7 +302,7 @@ void handle_menu_choice(eMenu item_hit) {
pick_race_abil(&univ.party[current_active_pc],0); pick_race_abil(&univ.party[current_active_pc],0);
break; break;
case eMenu::EDIT_SKILLS: case eMenu::EDIT_SKILLS:
spend_xp(current_active_pc,1,0); spend_xp(current_active_pc,2,0);
break; break;
case eMenu::EDIT_XP: case eMenu::EDIT_XP:
edit_xp(&univ.party[current_active_pc]); edit_xp(&univ.party[current_active_pc]);