From d2d88311db653a61d63d6d0c5a7899a012169ea1 Mon Sep 17 00:00:00 2001 From: Celtic Minstrel Date: Sat, 30 May 2009 03:36:41 +0000 Subject: [PATCH] - Made add_string_to_buf accept a string rather than a char*, and began to take advantage of this. - Added an operator[] to cParty; I intend to get rid of the ADVEN macro eventually in favour of accessing PCs with the operator - Added using cMonster::operator= to cCreature, because this will be needed once I rearrange these two structures. - Added an operator= to the cPopulation type, so that the "monst.dudes[...]" redundancy can be avoide. - Added outdoors and towns members to the scenario class for future use (they will old all the outdoor sections and towns, respectively, from the current scenario) git-svn-id: http://openexile.googlecode.com/svn/trunk@81 4ebdad44-0ea0-11de-aab3-ff745001d230 --- osx/boe.consts.h | 2 +- osx/boe.global.h | 14 -------------- osx/boe.text.cpp | 18 +++++++++--------- osx/boe.text.h | 2 +- osx/boe.town.cpp | 2 +- osx/classes/creatlist.cpp | 4 ++++ osx/classes/creatlist.h | 3 ++- osx/classes/monster.h | 1 + osx/classes/party.cpp | 7 ++++++- osx/classes/party.h | 5 +++-- osx/classes/scenario.h | 4 +++- 11 files changed, 31 insertions(+), 31 deletions(-) diff --git a/osx/boe.consts.h b/osx/boe.consts.h index 5edee1f9..3145c016 100644 --- a/osx/boe.consts.h +++ b/osx/boe.consts.h @@ -215,7 +215,7 @@ enum eTrapType { TRAP_DART = 2, TRAP_GAS = 3, // poisons all TRAP_EXPLOSION = 4, // damages all => uses c_town.difficulty rather than trap_level to calculates damages (and even c_town.difficulty /13). - TRAP_SLEEP_RAY = 5, + TRAP_SLEEP_RAY = 5, // TODO: Rename "Paralysis ray" TRAP_FALSE_ALARM = 6, TRAP_DRAIN_XP = 7, TRAP_ALERT = 8, // makes town hostile diff --git a/osx/boe.global.h b/osx/boe.global.h index f68b706e..10f9899f 100644 --- a/osx/boe.global.h +++ b/osx/boe.global.h @@ -40,20 +40,6 @@ #define NUM_FACE_G 80 #define NUM_DLOG_G 28 - -#define DOOR_LIGHT can_enter = run_trap(7,&PSD[c_town.town_num][which],4220,0); break; -#define DOOR_HEAVY can_enter = run_trap(7,&PSD[c_town.town_num][which],4220,20); break; -#define DOOR_ALARM can_enter = run_trap(7,&PSD[c_town.town_num][which],4220,11); break; -#define DRESSER_LIGHT can_enter = run_trap(7,&PSD[c_town.town_num][which],4221,0); break; -#define DRESSER_HEAVY can_enter = run_trap(7,&PSD[c_town.town_num][which],4221,20); break; -#define DRESSER_ALARM can_enter = run_trap(7,&PSD[c_town.town_num][which],4221,11); break; -#define FLOOR_LIGHT can_enter = run_trap(7,&PSD[c_town.town_num][which],4222,0); break; -#define FLOOR_HEAVY can_enter = run_trap(7,&PSD[c_town.town_num][which],4222,20); break; -#define FLOOR_ALARM can_enter = run_trap(7,&PSD[c_town.town_num][which],4222,11); break; -#define CHEST_LIGHT can_enter = run_trap(7,&PSD[c_town.town_num][which],3450,0); break; -#define CHEST_HEAVY can_enter = run_trap(7,&PSD[c_town.town_num][which],3450,20); break; -#define CHEST_ALARM can_enter = run_trap(7,&PSD[c_town.town_num][which],3450,11); break; - #define CDGT cd_retrieve_text_edit_str #define CDGN cd_retrieve_text_edit_num #define CDST cd_set_text_edit_str diff --git a/osx/boe.text.cpp b/osx/boe.text.cpp index eb9815fa..dcd8e824 100644 --- a/osx/boe.text.cpp +++ b/osx/boe.text.cpp @@ -811,17 +811,17 @@ void print_party_stats() { char store_string[255]; add_string_to_buf("PARTY STATS:"); sprintf((char *) store_string, " Number of kills: %lld ", univ.party.total_m_killed); - add_string_to_buf((char *) store_string); + add_string_to_buf(store_string); if ((is_town()) || ((is_combat()) && (which_combat_type == 1))) { sprintf((char *) store_string, " Kills in this town: %d ", univ.party.m_killed[univ.town.num]); - add_string_to_buf((char *) store_string); + add_string_to_buf(store_string); } sprintf((char *) store_string, " Total experience: %lld ", univ.party.total_xp_gained); - add_string_to_buf((char *) store_string); + add_string_to_buf(store_string); sprintf((char *) store_string, " Total damage done: %lld ", univ.party.total_dam_done); - add_string_to_buf((char *) store_string); + add_string_to_buf(store_string); sprintf((char *) store_string, " Total damage taken: %lld ", univ.party.total_dam_taken); - add_string_to_buf((char *) store_string); + add_string_to_buf(store_string); print_buf(); } @@ -844,7 +844,7 @@ short do_look(location space) if ((space == pc_pos[i]) && (ADVEN[i].main_status == 1) && (is_lit == true) && (can_see(pc_pos[current_pc],space,0) < 5)) { msg = " " + ADVEN[i].name; - add_string_to_buf((char *) msg.c_str()); + add_string_to_buf(msg); } if ((overall_mode == MODE_LOOK_TOWN) || (overall_mode == MODE_LOOK_COMBAT)) { @@ -1284,13 +1284,13 @@ short print_terrain(location space) } std::string msg = get_ter_name(which_terrain); msg = " " + msg; - add_string_to_buf((char *) msg.c_str()); + add_string_to_buf(msg); return (short) which_terrain; } -void add_string_to_buf(char *string) +void add_string_to_buf(std::string str) { if (in_startup_mode == true) return; @@ -1301,7 +1301,7 @@ void add_string_to_buf(char *string) print_buf(); through_sending(); } - sprintf((char *)text_buffer[buf_pointer].line, "%-49.49s", string); + sprintf((char *)text_buffer[buf_pointer].line, "%-49.49s", str.c_str()); // c2pstr((char *)text_buffer[buf_pointer].line); if (buf_pointer == (TEXT_BUF_LEN - 1)) buf_pointer = 0; diff --git a/osx/boe.text.h b/osx/boe.text.h index 792a83d2..8c554ba6 100644 --- a/osx/boe.text.h +++ b/osx/boe.text.h @@ -33,7 +33,7 @@ void monst_damaged_mes(short which_m,short how_much,short how_much_spec); void monst_killed_mes(short which_m); void print_nums(short a,short b,short c); short print_terrain(location space); -void add_string_to_buf(char *string); +void add_string_to_buf(std::string str); void init_buf(); void print_buf () ; void restart_printing(); diff --git a/osx/boe.town.cpp b/osx/boe.town.cpp index 439c12b1..74c12888 100644 --- a/osx/boe.town.cpp +++ b/osx/boe.town.cpp @@ -550,7 +550,7 @@ void start_town_mode(short which_town, short entry_dir) add_string_to_buf("Now entering:"); sprintf ((char *) message, " %-30.30s ",univ.town->town_strs(0)); - add_string_to_buf((char *) message); + add_string_to_buf(message); // clear entry space, and check exploration diff --git a/osx/classes/creatlist.cpp b/osx/classes/creatlist.cpp index 6e72dbe7..5a88e9f7 100644 --- a/osx/classes/creatlist.cpp +++ b/osx/classes/creatlist.cpp @@ -23,3 +23,7 @@ cPopulation& cPopulation::operator = (legacy::creature_list_type old){ friendly = old.friendly; return *this; } + +cCreature& cPopulation::operator[](size_t n){ + return dudes[n]; +} diff --git a/osx/classes/creatlist.h b/osx/classes/creatlist.h index 9b255946..ba71cd42 100644 --- a/osx/classes/creatlist.h +++ b/osx/classes/creatlist.h @@ -32,7 +32,8 @@ public: short which_town; short friendly; - cPopulation& operator = (legacy::creature_list_type old); + cPopulation& operator= (legacy::creature_list_type old); + cCreature& operator[](size_t n); }; #endif \ No newline at end of file diff --git a/osx/classes/monster.h b/osx/classes/monster.h index 59a48734..819886f8 100644 --- a/osx/classes/monster.h +++ b/osx/classes/monster.h @@ -184,6 +184,7 @@ public: class cCreature : public cMonster { public: + using cMonster::operator=; cMonster m_d; // TODO: Delete this member in favour of the inherited fields unsigned long id; m_num_t number; // TODO: This appears to be a duplicate of cMonster::m_num (ie it's used for the same thing) diff --git a/osx/classes/party.cpp b/osx/classes/party.cpp index 1200992d..89ab7cd9 100644 --- a/osx/classes/party.cpp +++ b/osx/classes/party.cpp @@ -10,7 +10,7 @@ #include #include #include - +#include #include "classes.h" #include "oldstructs.h" @@ -457,3 +457,8 @@ void cParty::readFrom(std::istream& file){ for(int k = 0; k < 64; k++) bin >> setup[i][j][k]; } + +cPlayer& cParty::operator[](unsigned short n){ + if(n >= 6) throw std::out_of_range("Attempt to access a player that doesn't exist."); + return adven[n]; +} diff --git a/osx/classes/party.h b/osx/classes/party.h index 1c6663ea..d1b70122 100644 --- a/osx/classes/party.h +++ b/osx/classes/party.h @@ -112,14 +112,15 @@ public: bool add_to_journal(short event, short day); bool record(short what, short where); bool start_timer(short time, short node, short type); + cPlayer& operator[](unsigned short n); + void writeTo(std::ostream& file); + void readFrom(std::istream& file); typedef std::vector::iterator encIter; typedef std::vector::iterator journalIter; typedef std::vector::iterator talkIter; typedef std::vector::iterator timerIter; typedef std::map >::iterator campIter; - void writeTo(std::ostream& file); - void readFrom(std::istream& file); }; #endif \ No newline at end of file diff --git a/osx/classes/scenario.h b/osx/classes/scenario.h index 38c7cccb..e752fe30 100644 --- a/osx/classes/scenario.h +++ b/osx/classes/scenario.h @@ -39,7 +39,7 @@ public: unsigned char out_width,out_height,difficulty,intro_pic,default_ground; unsigned char town_size[200]; unsigned char town_hidden[200]; - short flag_a; + short flag_a; // TODO: Remove these flags short intro_mess_pic,intro_mess_len; location where_start,out_sec_start,out_start; short which_town_start; @@ -88,6 +88,8 @@ public: char spec_item_strs[50][256]; char spec_strs[100][256]; FSSpec scen_file; // transient + cOutdoors* outdoors; + cTown* towns; char(& scen_strs(short i))[256]; cScenario& operator = (legacy::scenario_data_type& old);