Really fix the talking crash this time, I'm pretty sure
This commit is contained in:
@@ -524,13 +524,13 @@ void start_talk_mode(short m_num,short personality,m_num_t monst_type,short stor
|
||||
talk_gworld.create(area_rect.width(), area_rect.height());
|
||||
|
||||
// first make sure relevant talk strs are loaded in
|
||||
load_town(personality / 10,univ.town.cur_talk);
|
||||
load_town_talk(personality / 10);
|
||||
|
||||
// load all possible responses
|
||||
store_responses();
|
||||
|
||||
// Dredge up critter's name
|
||||
title_string = std::string(univ.town.cur_talk->talk_strs[personality % 10]) + ":";
|
||||
title_string = std::string(univ.town.cur_talk().talk_strs[personality % 10]) + ":";
|
||||
|
||||
store_pre_talk_mode = overall_mode;
|
||||
overall_mode = MODE_TALKING;
|
||||
@@ -538,7 +538,7 @@ void start_talk_mode(short m_num,short personality,m_num_t monst_type,short stor
|
||||
stat_screen_mode = 1;
|
||||
|
||||
// Bring up and place first strings.
|
||||
place_string1 = univ.town.cur_talk->talk_strs[personality % 10 + 10];
|
||||
place_string1 = univ.town.cur_talk().talk_strs[personality % 10 + 10];
|
||||
strnum1 = personality % 10 + 10;
|
||||
strnum2 = 0;
|
||||
|
||||
@@ -672,7 +672,7 @@ void handle_talk_event(location p)
|
||||
if (force_special > 0) {
|
||||
switch (force_special) {
|
||||
case 1: case 2: case 3:
|
||||
place_string1 = univ.town.cur_talk->talk_strs[store_personality % 10 + 10 * force_special];
|
||||
place_string1 = univ.town.cur_talk().talk_strs[store_personality % 10 + 10 * force_special];
|
||||
|
||||
oldstrnum1 = strnum1; oldstrnum2 = strnum2;
|
||||
strnum1 = store_personality % 10 + 10 * force_special;
|
||||
@@ -725,7 +725,7 @@ void handle_talk_event(location p)
|
||||
one_back1 = old_str1;
|
||||
one_back2 = old_str2;
|
||||
old_str2 = "";
|
||||
old_str1 = univ.town.cur_talk->talk_strs[store_personality % 10 + 160];
|
||||
old_str1 = univ.town.cur_talk().talk_strs[store_personality % 10 + 160];
|
||||
if(old_str1.length() < 2)
|
||||
old_str1 = "You get no response.";
|
||||
place_talk_str(old_str1,old_str2,0,dummy_rect);
|
||||
@@ -733,14 +733,14 @@ void handle_talk_event(location p)
|
||||
return;
|
||||
}
|
||||
|
||||
ttype = univ.town.cur_talk->talk_nodes[which_talk_entry].type;
|
||||
a = univ.town.cur_talk->talk_nodes[which_talk_entry].extras[0];
|
||||
b = univ.town.cur_talk->talk_nodes[which_talk_entry].extras[1];
|
||||
c = univ.town.cur_talk->talk_nodes[which_talk_entry].extras[2];
|
||||
d = univ.town.cur_talk->talk_nodes[which_talk_entry].extras[3];
|
||||
ttype = univ.town.cur_talk().talk_nodes[which_talk_entry].type;
|
||||
a = univ.town.cur_talk().talk_nodes[which_talk_entry].extras[0];
|
||||
b = univ.town.cur_talk().talk_nodes[which_talk_entry].extras[1];
|
||||
c = univ.town.cur_talk().talk_nodes[which_talk_entry].extras[2];
|
||||
d = univ.town.cur_talk().talk_nodes[which_talk_entry].extras[3];
|
||||
|
||||
place_string1 = univ.town.cur_talk->talk_strs[40 + which_talk_entry * 2];
|
||||
place_string2 = univ.town.cur_talk->talk_strs[40 + which_talk_entry * 2 + 1];
|
||||
place_string1 = univ.town.cur_talk().talk_strs[40 + which_talk_entry * 2];
|
||||
place_string2 = univ.town.cur_talk().talk_strs[40 + which_talk_entry * 2 + 1];
|
||||
|
||||
oldstrnum1 = strnum1; oldstrnum2 = strnum2;
|
||||
strnum1 = 40 + which_talk_entry * 2; strnum2 = 40 + which_talk_entry * 2 + 1;
|
||||
|
||||
@@ -176,7 +176,6 @@ void finish_load_party(){
|
||||
else {
|
||||
load_town_str(univ.town.num,univ.town.record);
|
||||
load_town(univ.town.num,univ.town.record);
|
||||
univ.town.cur_talk_loaded = -1;
|
||||
|
||||
for (int i = 0; i < univ.town->max_monst(); i++){
|
||||
univ.town.monst[i].targ_loc.x = 0;
|
||||
@@ -540,7 +539,6 @@ void init_town(){ // formerly part of load_town
|
||||
}
|
||||
|
||||
}
|
||||
univ.town.cur_talk_loaded = -1;
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
@@ -867,15 +867,13 @@ static void put_talk(cDialog& me)
|
||||
char place_str[256];
|
||||
|
||||
if ((personality = univ.party.talk_save[store_page_on].personality) >= 0) {
|
||||
if (personality / 10 != univ.town.cur_talk_loaded){
|
||||
load_town(personality / 10,univ.town.cur_talk);
|
||||
}
|
||||
load_town_talk(personality / 10);
|
||||
|
||||
// TODO: Use cached strings instead of loading them
|
||||
load_town_str(univ.party.talk_save[store_page_on].town_num,0,(char *) place_str);
|
||||
me["loc"].setText(place_str);
|
||||
|
||||
me["who"].setText(univ.town.cur_talk->talk_strs[personality % 10]);
|
||||
me["who"].setText(univ.town.cur_talk().talk_strs[personality % 10]);
|
||||
|
||||
if (univ.party.talk_save[store_page_on].str_num1 >= 1000) {
|
||||
if (univ.party.talk_save[store_page_on].str_num1 >= 3000)
|
||||
@@ -887,7 +885,7 @@ static void put_talk(cDialog& me)
|
||||
}
|
||||
}
|
||||
else if (univ.party.talk_save[store_page_on].str_num1 > 0)
|
||||
me["str1"].setText(univ.town.cur_talk->talk_strs[univ.party.talk_save[store_page_on].str_num1]);
|
||||
me["str1"].setText(univ.town.cur_talk().talk_strs[univ.party.talk_save[store_page_on].str_num1]);
|
||||
|
||||
if (univ.party.talk_save[store_page_on].str_num2 >= 1000) {
|
||||
if (univ.party.talk_save[store_page_on].str_num2 >= 3000)
|
||||
@@ -899,7 +897,7 @@ static void put_talk(cDialog& me)
|
||||
}
|
||||
}
|
||||
else if (univ.party.talk_save[store_page_on].str_num2 > 0)
|
||||
me["str2"].setText(univ.town.cur_talk->talk_strs[univ.party.talk_save[store_page_on].str_num2]);
|
||||
me["str2"].setText(univ.town.cur_talk().talk_strs[univ.party.talk_save[store_page_on].str_num2]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -491,8 +491,6 @@ void close_program()
|
||||
// TODO: Ultimately we would like to have cleanup happen automatically, negating the need for this function
|
||||
//end_music();
|
||||
if(univ.town.loaded()) univ.town.unload();
|
||||
if(univ.town.cur_talk_loaded != univ.town.num)
|
||||
delete univ.town.cur_talk;
|
||||
clean_up_graphtool();
|
||||
}
|
||||
|
||||
|
||||
@@ -1347,13 +1347,13 @@ short scan_for_response(char *str)
|
||||
short i;
|
||||
|
||||
for (i = 0; i < 60; i++) { // 60 response in each bunch
|
||||
if ((univ.town.cur_talk->talk_nodes[i].personality != -1) &&
|
||||
((univ.town.cur_talk->talk_nodes[i].personality == store_personality)
|
||||
|| (univ.town.cur_talk->talk_nodes[i].personality == -2)) &&
|
||||
(((str[0] == univ.town.cur_talk->talk_nodes[i].link1[0]) && (str[1] == univ.town.cur_talk->talk_nodes[i].link1[1])
|
||||
&& (str[2] == univ.town.cur_talk->talk_nodes[i].link1[2]) && (str[3] == univ.town.cur_talk->talk_nodes[i].link1[3]))
|
||||
|| ((str[0] == univ.town.cur_talk->talk_nodes[i].link2[0]) && (str[1] == univ.town.cur_talk->talk_nodes[i].link2[1])
|
||||
&& (str[2] == univ.town.cur_talk->talk_nodes[i].link2[2]) && (str[3] == univ.town.cur_talk->talk_nodes[i].link2[3]))))
|
||||
if((univ.town.cur_talk().talk_nodes[i].personality != -1) &&
|
||||
((univ.town.cur_talk().talk_nodes[i].personality == store_personality)
|
||||
|| (univ.town.cur_talk().talk_nodes[i].personality == -2)) &&
|
||||
(((str[0] == univ.town.cur_talk().talk_nodes[i].link1[0]) && (str[1] == univ.town.cur_talk().talk_nodes[i].link1[1])
|
||||
&& (str[2] == univ.town.cur_talk().talk_nodes[i].link1[2]) && (str[3] == univ.town.cur_talk().talk_nodes[i].link1[3]))
|
||||
|| ((str[0] == univ.town.cur_talk().talk_nodes[i].link2[0]) && (str[1] == univ.town.cur_talk().talk_nodes[i].link2[1])
|
||||
&& (str[2] == univ.town.cur_talk().talk_nodes[i].link2[2]) && (str[3] == univ.town.cur_talk().talk_nodes[i].link2[3]))))
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
|
||||
@@ -179,7 +179,7 @@ void start_town_mode(short which_town, short entry_dir)
|
||||
load_town(town_number,univ.town.record);
|
||||
|
||||
univ.town.num = town_number;
|
||||
load_town(town_number,univ.town.cur_talk);
|
||||
load_town_talk(town_number);
|
||||
init_town();
|
||||
|
||||
// if (play_town_sound == true) {
|
||||
|
||||
@@ -46,7 +46,8 @@ void cCurTown::append(legacy::current_town_type& old,short which_size){
|
||||
in_boat = old.in_boat;
|
||||
p_loc.x = old.p_loc.x;
|
||||
p_loc.y = old.p_loc.y;
|
||||
cur_talk = &record->talking;
|
||||
curTalk = &record->talking;
|
||||
talkNeedsDeleting = false;
|
||||
cur_talk_loaded = num;
|
||||
}
|
||||
|
||||
@@ -113,6 +114,32 @@ void cCurTown::unload(){
|
||||
record = NULL;
|
||||
}
|
||||
|
||||
|
||||
cSpeech& cCurTown::cur_talk() {
|
||||
// Make sure we actually have a valid speech stored
|
||||
if(curTalk == NULL) prep_talk(num);
|
||||
return *curTalk;
|
||||
}
|
||||
|
||||
bool cCurTown::prep_talk(short which) {
|
||||
if(which == cur_talk_loaded) return true;
|
||||
if(talkNeedsDeleting && curTalk != NULL) delete curTalk;
|
||||
cur_talk_loaded = which;
|
||||
if(which == num) {
|
||||
curTalk = &record->talking;
|
||||
talkNeedsDeleting = false;
|
||||
return true;
|
||||
} else {
|
||||
curTalk = new cSpeech;
|
||||
talkNeedsDeleting = true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
cCurTown::~cCurTown() {
|
||||
if(talkNeedsDeleting && curTalk != NULL) delete curTalk;
|
||||
}
|
||||
|
||||
bool cCurTown::is_explored(char x, char y) const{
|
||||
if(x > record->max_dim() || y > record->max_dim()) return false;
|
||||
return fields[x][y] & 1L;
|
||||
|
||||
@@ -30,6 +30,9 @@ namespace legacy {
|
||||
};
|
||||
|
||||
class cCurTown {
|
||||
cSpeech* curTalk = NULL;
|
||||
bool talkNeedsDeleting = false;
|
||||
short cur_talk_loaded = -1;
|
||||
public:
|
||||
cTown* record;
|
||||
// formerly current_town_type
|
||||
@@ -40,8 +43,6 @@ public:
|
||||
cPopulation monst;
|
||||
bool in_boat; // is this really needed?
|
||||
location p_loc;
|
||||
cSpeech* cur_talk; // my addition
|
||||
short cur_talk_loaded; // my addition
|
||||
|
||||
cItemRec items[115]; // formerly town_item_list type
|
||||
|
||||
@@ -64,6 +65,8 @@ public:
|
||||
bool loaded() const;
|
||||
void unload();
|
||||
short countMonsters();
|
||||
cSpeech& cur_talk(); // Get the currently loaded speech
|
||||
bool prep_talk(short which); // Prepare for loading specified speech, returning true if already loaded
|
||||
|
||||
bool is_explored(char x, char y) const;
|
||||
bool is_force_wall(char x, char y) const;
|
||||
@@ -121,6 +124,8 @@ public:
|
||||
// bool set_trim(char x, char y, char t, bool b);
|
||||
void writeTo(std::ostream& file);
|
||||
void readFrom(std::istream& file);
|
||||
|
||||
~cCurTown();
|
||||
};
|
||||
|
||||
class cCurOut {
|
||||
|
||||
@@ -337,15 +337,8 @@ bool load_town(short which_town, cTown*& the_town){
|
||||
return true;
|
||||
}
|
||||
|
||||
bool load_town(short which_town, cSpeech*& the_talk){
|
||||
if(which_town == univ.town.cur_talk_loaded) return true;
|
||||
if(univ.town.num != univ.town.cur_talk_loaded) delete the_talk;
|
||||
univ.town.cur_talk_loaded = which_town;
|
||||
if(which_town == univ.town.num) {
|
||||
the_talk = &univ.town->talking;
|
||||
return true;
|
||||
}
|
||||
the_talk = new cSpeech;
|
||||
bool load_town_talk(short which_town){
|
||||
if(univ.town.prep_talk(which_town)) return true;
|
||||
|
||||
short i,n;
|
||||
long len,len_to_jump = 0;
|
||||
@@ -411,12 +404,13 @@ bool load_town(short which_town, cSpeech*& the_talk){
|
||||
return false;
|
||||
}
|
||||
port_talk_nodes(&store_talk);
|
||||
*the_talk = store_talk;
|
||||
cSpeech& the_talk = univ.town.cur_talk();
|
||||
the_talk = store_talk;
|
||||
|
||||
for (i = 0; i < 170; i++) {
|
||||
len = (long) (the_talk->strlens[i]);
|
||||
n = fread(&(the_talk->talk_strs[i]), len, 1, file_id);
|
||||
the_talk->talk_strs[i][len] = 0;
|
||||
len = (long) (the_talk.strlens[i]);
|
||||
n = fread(&(the_talk.talk_strs[i]), len, 1, file_id);
|
||||
the_talk.talk_strs[i][len] = 0;
|
||||
}
|
||||
|
||||
// town_type = scenario.town_size[which_town];
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace fs = boost::filesystem; // TODO: Centralize this alias!
|
||||
|
||||
bool load_scenario(fs::path file_to_load, bool skip_strings = false);
|
||||
bool load_town(short which_town, cTown*& the_town);
|
||||
bool load_town(short which_town, cSpeech*& the_talk);
|
||||
bool load_town_talk(short which_town);
|
||||
bool load_town_str(short which_town, short which_str, char* str);
|
||||
bool load_town_str(short which_town, cTown*& the_town);
|
||||
bool load_outdoors(location which_out,cOutdoors& the_out);
|
||||
|
||||
Reference in New Issue
Block a user