Clean up tons of commented fileio code
This commit is contained in:
@@ -24,17 +24,14 @@
|
||||
#include "tarball.hpp"
|
||||
|
||||
bool cur_scen_is_mac = true, mac_is_intel;
|
||||
extern short town_type; // TODO: Put this somewhere better
|
||||
extern cScenario scenario;
|
||||
extern sf::Texture items_gworld,tiny_obj_gworld,fields_gworld,roads_gworld,boom_gworld,missiles_gworld;
|
||||
extern sf::Texture dlogpics_gworld,monst_gworld[],terrain_gworld[],anim_gworld,talkfaces_gworld,pc_gworld;
|
||||
extern sf::Texture status_gworld, vehicle_gworld, small_ter_gworld;
|
||||
extern cCustomGraphics spec_scen_g;
|
||||
extern cUniverse univ;
|
||||
//extern unsigned char borders[4][50];
|
||||
//extern cOutdoors current_terrain;
|
||||
//extern cTown* town;
|
||||
fs::path progDir, tempDir;
|
||||
//extern short overall_mode;
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
@@ -146,47 +143,10 @@ bool load_scenario(fs::path file_to_load, bool skip_strings){
|
||||
|
||||
fclose(file_id);
|
||||
|
||||
// code for master
|
||||
/*
|
||||
for (i = 0; i < 30000; i++) {
|
||||
if (check_p(i) == true) {
|
||||
user_given_password = i;
|
||||
i = 30000;
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
/* Now check password
|
||||
|
||||
if (check_p(0) == false) {
|
||||
user_given_password = enter_password();
|
||||
if (check_p(user_given_password) == false) {
|
||||
fancy_choice_dialog(868,0);
|
||||
if (overall_mode != 61) {
|
||||
user_given_password = enter_password();
|
||||
if (check_p(user_given_password) == false)
|
||||
ExitToShell();
|
||||
}
|
||||
else return;
|
||||
}
|
||||
}
|
||||
else user_given_password = 0; /**/
|
||||
|
||||
|
||||
//given_password = user_given_password;
|
||||
|
||||
scenario.ter_types[23].fly_over = false;
|
||||
delete temp_scenario;
|
||||
delete item_data;
|
||||
|
||||
//store_file_reply = file_to_load;
|
||||
// overall_mode = 60;
|
||||
// change_made = false;
|
||||
// if(!load_town(scenario.last_town_edited)) return false;
|
||||
// //load_town(0);
|
||||
// if(!load_outdoors(scenario.last_out_edited,0)) return false;
|
||||
// augment_terrain(scenario.last_out_edited);
|
||||
scenario.scen_file = file_to_load;
|
||||
load_spec_graphics();
|
||||
return true;
|
||||
@@ -222,9 +182,6 @@ static bool load_town_v1(short which_town, cTown*& the_town) {
|
||||
legacy::ave_tr_type ave_t;
|
||||
legacy::tiny_tr_type tiny_t;
|
||||
|
||||
// if (overall_mode == 61)
|
||||
// return;
|
||||
|
||||
if (which_town != minmax(0,scenario.num_towns - 1,which_town)) {
|
||||
// This should never be reached from the scenario editor,
|
||||
// because it does its own range checking before calling load_town.
|
||||
@@ -307,7 +264,7 @@ static bool load_town_v1(short which_town, cTown*& the_town) {
|
||||
the_town->talking.talk_strs[i][len] = 0;
|
||||
}
|
||||
|
||||
// town_type = scenario.town_size[which_town];
|
||||
town_type = scenario.town_size[which_town];
|
||||
n = fclose(file_id);
|
||||
if(n != 0) {
|
||||
oopsError(18, 0, 0);
|
||||
@@ -343,9 +300,6 @@ static bool load_town_talk_v1(short which_town) {
|
||||
legacy::town_record_type store_town;
|
||||
legacy::talking_record_type store_talk;
|
||||
|
||||
// if (overall_mode == 61)
|
||||
// return;
|
||||
|
||||
if (which_town != minmax(0,scenario.num_towns - 1,which_town)) {
|
||||
// This should never be reached from the scenario editor,
|
||||
// because it does its own range checking before calling load_town.
|
||||
@@ -411,7 +365,7 @@ static bool load_town_talk_v1(short which_town) {
|
||||
the_talk.talk_strs[i][len] = 0;
|
||||
}
|
||||
|
||||
// town_type = scenario.town_size[which_town];
|
||||
town_type = scenario.town_size[which_town];
|
||||
n = fclose(file_id);
|
||||
if(n != 0) {
|
||||
oopsError(23, 0, 0);
|
||||
@@ -432,9 +386,6 @@ bool load_town_str(short which_town, short which_str, char* str){
|
||||
short i,n;
|
||||
long len,len_to_jump = 0;
|
||||
legacy::town_record_type store_town;
|
||||
|
||||
// if (overall_mode == 61)
|
||||
// return;
|
||||
|
||||
FILE* file_id = fopen(scenario.scen_file.c_str(), "rb");
|
||||
if(file_id == NULL) {
|
||||
@@ -482,7 +433,7 @@ bool load_town_str(short which_town, short which_str, char* str){
|
||||
else fseek(file_id, len, SEEK_CUR);
|
||||
}
|
||||
|
||||
// town_type = scenario.town_size[which_town];
|
||||
town_type = scenario.town_size[which_town];
|
||||
n = fclose(file_id);
|
||||
if(n != 0) {
|
||||
oopsError(27, 0, 0);
|
||||
@@ -496,9 +447,6 @@ bool load_town_str(short which_town, cTown*& t){
|
||||
long len,len_to_jump = 0;
|
||||
legacy::town_record_type store_town;
|
||||
|
||||
// if (overall_mode == 61)
|
||||
// return;
|
||||
|
||||
FILE* file_id = fopen(scenario.scen_file.c_str(), "rb");
|
||||
if(file_id == NULL) {
|
||||
oopsError(28, 0, 0);
|
||||
@@ -541,7 +489,7 @@ bool load_town_str(short which_town, cTown*& t){
|
||||
t->town_strs(i)[len] = 0;
|
||||
}
|
||||
|
||||
// town_type = scenario.town_size[which_town];
|
||||
town_type = scenario.town_size[which_town];
|
||||
n = fclose(file_id);
|
||||
if(n != 0) {
|
||||
oopsError(31, 0, 0);
|
||||
@@ -575,9 +523,6 @@ static bool load_outdoors_v1(location which_out,cOutdoors& the_out){
|
||||
long len,len_to_jump;
|
||||
legacy::outdoor_record_type store_out;
|
||||
|
||||
// if (overall_mode == 61)
|
||||
// return;
|
||||
|
||||
if ((which_out.x != minmax(0,scenario.out_width - 1,which_out.x)) ||
|
||||
(which_out.y != minmax(0,scenario.out_height - 1,which_out.y))) {
|
||||
the_out = cOutdoors();
|
||||
@@ -816,10 +761,7 @@ bool load_party(fs::path file_to_load){
|
||||
bool in_scen = false;
|
||||
enum {old_mac, old_win, new_oboe, unknown} format;
|
||||
|
||||
//char flag_data[8];
|
||||
long len;
|
||||
// flag_type flag;
|
||||
// flag_type *flag_ptr;
|
||||
short vers,n;
|
||||
struct {ushort a; ushort b; ushort c; ushort d; ushort e;} flags;
|
||||
|
||||
@@ -840,16 +782,10 @@ bool load_party(fs::path file_to_load){
|
||||
if(file_id == NULL) {
|
||||
cChoiceDlog("load-game-fail.xml").show();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//file_size = sizeof(legacy::party_record_type); // 45368
|
||||
}
|
||||
|
||||
len = sizeof(flags); // 10
|
||||
|
||||
// sprintf((char *) debug, " Len %d ", (short) len);
|
||||
// add_string_to_buf((char *) debug);
|
||||
|
||||
n = fread(&flags, len, 1, file_id);
|
||||
if(n < 1) {
|
||||
fclose(file_id);
|
||||
@@ -936,49 +872,12 @@ bool load_party(fs::path file_to_load){
|
||||
return false;
|
||||
}
|
||||
|
||||
// for (i = 0; i < 3; i++) {
|
||||
// error = FSRead(file_id, &len, (char *) &flag);
|
||||
// if (error != 0) {
|
||||
// FSClose(file_id);
|
||||
// FCD(1064,0);
|
||||
// return false;
|
||||
// }
|
||||
//// flag_ptr = (flag_type *) flag_data;
|
||||
//// flag = *flag_ptr;
|
||||
// if (flag == 0x0B0E) { // new format save
|
||||
// new_format = true;
|
||||
// i--;
|
||||
// continue;
|
||||
// }
|
||||
// if(mac_is_intel && !new_format) flip_short(&flag); // because the old format save was made for non-intel macs
|
||||
// if ((flag != flags[i][0]) && (flag != flags[i][1])) { // OK Exile II save file?
|
||||
// FSClose(file_id);
|
||||
// FCD(1063,0);
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// if ((i == 0) && (flag == flags[i][1]))
|
||||
// town_restore = true;
|
||||
// if ((i == 1) && (flag == flags[i][0])) {
|
||||
// in_scen = true;
|
||||
// }
|
||||
// if ((i == 2) && (flag == flags[i][1]))
|
||||
// maps_there = true;
|
||||
// }
|
||||
return true;
|
||||
}
|
||||
|
||||
bool load_party_v1(fs::path file_to_load, bool town_restore, bool in_scen, bool maps_there, bool must_port){
|
||||
std::ifstream fin(file_to_load.c_str(), std::ios_base::binary);
|
||||
fin.seekg(3*sizeof(short),std::ios_base::beg); // skip the header, which is 6 bytes in the old format
|
||||
//short flags[3];
|
||||
//fin.read((char*)flags,3*sizeof(short));
|
||||
// OSErr error = FSpOpenDF(&file_to_load,1,&file_id);
|
||||
// if (error != 0) {
|
||||
// FCD(1064,0);
|
||||
// SysBeep(2);
|
||||
// return false;
|
||||
// }
|
||||
|
||||
legacy::party_record_type store_party;
|
||||
legacy::setup_save_type store_setup;
|
||||
@@ -999,13 +898,6 @@ bool load_party_v1(fs::path file_to_load, bool town_restore, bool in_scen, bool
|
||||
len = (long) sizeof(legacy::party_record_type); // should be 46398
|
||||
store_len = len;
|
||||
fin.read((char*)&store_party, len);
|
||||
// error = FSRead(file_id, &len, (char *) &store_party)
|
||||
// if (error != 0){
|
||||
// FSClose(file_id);
|
||||
// SysBeep(2);
|
||||
// FCD(1064,0);
|
||||
// return false;
|
||||
// }
|
||||
if(must_port) port_party(&store_party);
|
||||
party_ptr = (char*) &store_party;
|
||||
for (count = 0; count < store_len; count++)
|
||||
@@ -1014,26 +906,12 @@ bool load_party_v1(fs::path file_to_load, bool town_restore, bool in_scen, bool
|
||||
// LOAD SETUP
|
||||
len = (long) sizeof(legacy::setup_save_type);
|
||||
fin.read((char*)&store_setup, len);
|
||||
// error = FSRead(file_id, &len, (char *) &store_setup)
|
||||
// if (error != 0){
|
||||
// FSClose(file_id);
|
||||
// SysBeep(2);
|
||||
// FCD(1064,0);
|
||||
// return false;
|
||||
// }
|
||||
|
||||
// LOAD PCS
|
||||
store_len = (long) sizeof(legacy::pc_record_type);
|
||||
for (int i = 0; i < 6; i++) {
|
||||
len = store_len;
|
||||
fin.read((char*)&store_pc[i], len);
|
||||
// error = FSRead(file_id, &len, (char *) &store_pc[i]);
|
||||
// if (error != 0){
|
||||
// FSClose(file_id);
|
||||
// SysBeep(2);
|
||||
// FCD(1064,0);
|
||||
// return false;
|
||||
// }
|
||||
if(must_port) port_pc(&store_pc[i]);
|
||||
pc_ptr = (char*) &store_pc[i];
|
||||
for (count = 0; count < store_len; count++)
|
||||
@@ -1045,13 +923,6 @@ bool load_party_v1(fs::path file_to_load, bool town_restore, bool in_scen, bool
|
||||
// LOAD OUTDOOR MAP
|
||||
len = (long) sizeof(legacy::out_info_type);
|
||||
fin.read((char*)&store_out_info, len);
|
||||
// error = FSRead(file_id, &len, (char *) &store_out_info)
|
||||
// if (error != 0){
|
||||
// FSClose(file_id);
|
||||
// SysBeep(2);
|
||||
// FCD(1064,0);
|
||||
// return false;
|
||||
// }
|
||||
|
||||
if(univ.town.loaded()) univ.town.unload();
|
||||
|
||||
@@ -1059,102 +930,40 @@ bool load_party_v1(fs::path file_to_load, bool town_restore, bool in_scen, bool
|
||||
if (town_restore) {
|
||||
len = (long) sizeof(legacy::current_town_type);
|
||||
fin.read((char*)&store_c_town, len);
|
||||
// error = FSRead(file_id, &len, (char *) &store_c_town)
|
||||
// if (error != 0){
|
||||
// FSClose(file_id);
|
||||
// SysBeep(2);
|
||||
// FCD(1064,0);
|
||||
// return false;
|
||||
// }
|
||||
if(must_port) port_c_town(&store_c_town);
|
||||
|
||||
len = (long) sizeof(legacy::big_tr_type);
|
||||
fin.read((char*)&t_d, len);
|
||||
// error = FSRead(file_id, &len, (char *) &t_d)
|
||||
// if (error != 0){
|
||||
// FSClose(file_id);
|
||||
// SysBeep(2);
|
||||
// FCD(1064,0);
|
||||
// return false;
|
||||
// }
|
||||
if(must_port) port_t_d(&t_d);
|
||||
|
||||
len = (long) sizeof(legacy::town_item_list);
|
||||
fin.read((char*)&t_i, len);
|
||||
// error = FSRead(file_id, &len, (char *) &t_i)
|
||||
// if (error != 0){
|
||||
// FSClose(file_id);
|
||||
// SysBeep(2);
|
||||
// FCD(1064,0);
|
||||
// return false;
|
||||
// }
|
||||
|
||||
fin.read((char*)&t_i, len);
|
||||
}else univ.town.num = 200;
|
||||
|
||||
// LOAD STORED ITEMS
|
||||
for (int i = 0; i < 3; i++) {
|
||||
len = (long) sizeof(legacy::stored_items_list_type);
|
||||
fin.read((char*)&stored_items[i], len);
|
||||
// error = FSRead(file_id, &len, (char *) &stored_items[i])
|
||||
// if (error != 0){
|
||||
// FSClose(file_id);
|
||||
// SysBeep(2);
|
||||
// FCD(1064,0);
|
||||
// return false;
|
||||
// }
|
||||
}
|
||||
|
||||
// LOAD SAVED MAPS
|
||||
if (maps_there) {
|
||||
len = (long) sizeof(legacy::stored_town_maps_type);
|
||||
fin.read((char*)&town_maps, len);
|
||||
// error = FSRead(file_id, &len, (char *) &(town_maps))
|
||||
// if (error != 0){
|
||||
// FSClose(file_id);
|
||||
// SysBeep(2);
|
||||
// FCD(1064,0);
|
||||
// return false;
|
||||
// }
|
||||
|
||||
len = (long) sizeof(legacy::stored_outdoor_maps_type);
|
||||
fin.read((char*)&o_maps, len);
|
||||
// error = FSRead(file_id, &len, (char *) &o_maps)
|
||||
// if (error != 0) {
|
||||
// FSClose(file_id);
|
||||
// SysBeep(2);
|
||||
// FCD(1064,0);
|
||||
// return false;
|
||||
// }
|
||||
}
|
||||
|
||||
// LOAD SFX & MISC_I
|
||||
len = (long) (64 * 64);
|
||||
fin.read((char*)sfx, len);
|
||||
// error = FSRead(file_id, &len, (char *) sfx)
|
||||
// if (error != 0){
|
||||
// FSClose(file_id);
|
||||
// SysBeep(2);
|
||||
// FCD(1064,0);
|
||||
// return false;
|
||||
// }
|
||||
fin.read((char*)misc_i, len);
|
||||
// error = FSRead(file_id, &len, (char *) misc_i)
|
||||
// if (error != 0){
|
||||
// FSClose(file_id);
|
||||
// SysBeep(2);
|
||||
// FCD(1064,0);
|
||||
// return false;
|
||||
// }
|
||||
|
||||
fin.read((char*)misc_i, len);
|
||||
|
||||
} // end if_scen
|
||||
|
||||
fin.close();
|
||||
// error = FSClose(file_id)
|
||||
// if (error != 0){
|
||||
// give_error("Load: Can't close file.","",0);
|
||||
// SysBeep(2);
|
||||
// return false;
|
||||
// }
|
||||
|
||||
univ.party = store_party;
|
||||
univ.party.append(store_setup);
|
||||
@@ -1177,7 +986,7 @@ bool load_party_v1(fs::path file_to_load, bool town_restore, bool in_scen, bool
|
||||
if(in_scen){
|
||||
fs::path path;
|
||||
path = progDir/"Blades of Exile Scenarios"/univ.party.scen_name;
|
||||
//std::cout<<path<<'\n';
|
||||
|
||||
if(!load_scenario(path))
|
||||
return false;
|
||||
univ.file = path;
|
||||
|
Reference in New Issue
Block a user