From 5bfdb5eafa740616a3e1232538141637ff6333ca Mon Sep 17 00:00:00 2001 From: Celtic Minstrel Date: Wed, 10 Dec 2014 23:53:50 -0500 Subject: [PATCH] Misc little bits of housekeeping and stuff --- osx/boe.combat.cpp | 2 +- osx/boe.graphutil.cpp | 2 +- osx/boe.items.cpp | 2 ++ osx/boe.locutils.cpp | 2 ++ osx/boe.party.cpp | 11 +++-------- osx/boe.specials.cpp | 16 +++++----------- osx/boe.town.cpp | 2 +- osx/classes/party.cpp | 3 ++- osx/classes/town.cpp | 1 + osx/classes/universe.cpp | 2 +- osx/dialogxml/dialog.h | 8 ++++++++ osx/dialogxml/dlogutil.cpp | 2 +- osx/tools/fileio.cpp | 2 ++ osx/tools/soundtool.cpp | 2 +- 14 files changed, 31 insertions(+), 26 deletions(-) diff --git a/osx/boe.combat.cpp b/osx/boe.combat.cpp index b757d05e..a5121d05 100644 --- a/osx/boe.combat.cpp +++ b/osx/boe.combat.cpp @@ -440,7 +440,7 @@ void start_outdoor_combat(cOutdoors::cCreature encounter,ter_num_t in_which_terr bool pc_combat_move(location destination) //// { short dir,monst_hit,s1,s2,i,monst_exist,switch_pc; - bool keep_going = true,forced = false,check_f; + bool keep_going = true,forced = false,check_f = false; location monst_loc,store_loc; short spec_num; diff --git a/osx/boe.graphutil.cpp b/osx/boe.graphutil.cpp index e8ddca38..1eaad8b7 100644 --- a/osx/boe.graphutil.cpp +++ b/osx/boe.graphutil.cpp @@ -597,7 +597,7 @@ RECT get_monster_template_rect (pic_num_t picture_wanted,short mode,short which_ //mode; // 0 - left 1 - right +10 - combat mode { RECT store_rect = {0,0,36,28}; - short adj; + short adj = 0; if (mode >= 10) { adj += 4; diff --git a/osx/boe.items.cpp b/osx/boe.items.cpp index 0a7c4c35..32901ff3 100644 --- a/osx/boe.items.cpp +++ b/osx/boe.items.cpp @@ -886,6 +886,8 @@ void set_town_attitude(short lo,short hi,short att) { run_special(eSpecCtx::TOWN_HOSTILE, 2, univ.town->spec_on_hostile, univ.party.p_loc, &a[0], &a[1], &a[2]); } +// TODO: Set town status to "dead"? Could reuse above with magic att (eg -1), or write new function. + static void put_item_graphics(cDialog& me, size_t& first_item_shown, short& current_getting_pc, const std::vector& item_array) { diff --git a/osx/boe.locutils.cpp b/osx/boe.locutils.cpp index 6e8f7ebc..1a735330 100644 --- a/osx/boe.locutils.cpp +++ b/osx/boe.locutils.cpp @@ -202,6 +202,7 @@ short sight_obscurity(short x,short y) { what_terrain = coord_to_ter(x,y); // TODO: This should not be hard-coded! + // It appears to refer to mountain cave entrances, surface tower, and surface pit. (WHY?) if ((what_terrain >= 237) && (what_terrain <= 242)) return 1; @@ -326,6 +327,7 @@ bool is_blocked(location to_check) return true; if ((is_combat()) && (scenario.ter_types[coord_to_ter(to_check.x,to_check.y)].trim_type == eTrimType::CITY)) return true; // TODO: Maybe replace eTrimType::CITY with a blockage == clear/special && is_special() check + // Note: The purpose of the above check is to avoid portals. // Party there? if (is_town()) diff --git a/osx/boe.party.cpp b/osx/boe.party.cpp index 7df942c9..b11f959f 100644 --- a/osx/boe.party.cpp +++ b/osx/boe.party.cpp @@ -242,8 +242,6 @@ void init_party(short mode) univ.party.can_find_town[i] = 0; for (i = 0; i < 20; i++) univ.party.key_times[i] = 30000; -// for (i = 0; i < 30; i++) -// univ.party.party_event_timers[i] = 0; univ.party.party_event_timers.clear(); for (i = 0; i < 50; i++) univ.party.spec_items[i] = 0; @@ -369,8 +367,7 @@ void init_party_scen_data() // univ.party.special_notes_str[i][j] = 0; // for (i = 0; i < 120; i++) // univ.party.talk_save[i].personality = -1; - // TODO: The journal at least should persist across scenarios; the other two, maybe, maybe not - univ.party.journal.clear(); + // TODO: The journal at least should persist across scenarios; the special and talk notes, maybe, maybe not univ.party.special_notes.clear(); univ.party.talk_save.clear(); @@ -380,8 +377,6 @@ void init_party_scen_data() univ.party.can_find_town[i] = 1 - scenario.town_hidden[i]; for (i = 0; i < 20; i++) univ.party.key_times[i] = 30000; -// for (i = 0; i < 30; i++) -// univ.party.party_event_timers[i] = 0; univ.party.party_event_timers.clear(); for (i = 0; i < 50; i++) univ.party.spec_items[i] = (scenario.special_items[i].flags >= 10) ? 1 : 0; @@ -471,8 +466,6 @@ void put_party_in_scen(std::string scen_name) univ.party.age = 0; for (i = 0; i < 200; i++) univ.party.m_killed[i] = 0; -// for (i = 0; i < 30; i++) -// univ.party.party_event_timers[i] = 0; univ.party.party_event_timers.clear(); fs::path path; @@ -1992,6 +1985,8 @@ bool pc_can_cast_spell(short pc_num,short type,short spell_num) level = spell_level[spell_num]; + if(overall_mode >= MODE_TALKING) + return false; // From Windows version. It does kinda make sense, though this function shouldn't even be called in these modes. if ((spell_num < 0) || (spell_num > 61)) return false; if (univ.party[pc_num].skills[9 + type] < level) diff --git a/osx/boe.specials.cpp b/osx/boe.specials.cpp index 44d01be6..9e4114e5 100644 --- a/osx/boe.specials.cpp +++ b/osx/boe.specials.cpp @@ -365,7 +365,7 @@ bool check_special_terrain(location where_check,eSpecCtx mode,short which_pc,sho fast_bang = 1; if(mode == eSpecCtx::COMBAT_MOVE) damage_pc(which_pc,r1,dam_type,eRace::UNKNOWN,0); - if (overall_mode < MODE_COMBAT) + else boom_space(univ.party.p_loc,overall_mode,pic_type,r1,12); fast_bang = 0; break; @@ -1533,7 +1533,7 @@ bool damage_monst(short which_m, short who_hit, short how_much, short how_much_s if ((dam_type == 3) && (get_ran(1,0,24) <= victim->level)) how_much /= 2; - // Rentar-Ihrno? + // Invulnerable? if (victim->spec_skill == 36) how_much = how_much / 10; @@ -1632,17 +1632,11 @@ bool damage_monst(short which_m, short who_hit, short how_much, short how_much_s } if ((victim->attitude % 2 != 1) && (who_hit < 7) && - (processing_fields == false) && (monsters_going == false)) { + ((processing_fields && !monsters_going) || (processing_fields && !PSD[SDF_HOSTILES_PRESENT]))) { add_string_to_buf("Damaged an innocent. "); victim->attitude = 1; make_town_hostile(); } - if ((victim->attitude % 2 != 1) && (who_hit < 7) && - ((processing_fields == true) && (PSD[SDF_HOSTILES_PRESENT] == 0))) { - add_string_to_buf("Damaged an innocent."); - victim->attitude = 1; - make_town_hostile(); - } return true; } @@ -1663,7 +1657,7 @@ void kill_monst(cCreature *which_m,short who_killed) } else switch(which_m->m_type) { case eRace::GIANT: play_sound(29); break; // TODO: Should sliths be considered reptiles too? Check original bladbase. - // TODO: Should birds be considered beasts? If there are iny birds in the bladbase, probably; otherwise, better to have new sound + // TODO: Should birds be considered beasts? If there are any birds in the bladbase, probably; otherwise, better to have new sound case eRace::REPTILE: case eRace::BEAST: case eRace::DEMON: case eRace::UNDEAD: case eRace::STONE: i = get_ran(1,0,1); play_sound(31 + i); break; default: play_sound(33); break; @@ -1942,7 +1936,7 @@ void run_special(pending_special_type spec, short* a, short* b, short* redraw) { // 13 - encountering outdoor enc (a - 1 if no fight) // 14 - winning outdoor enc // 15 - fleeing outdoor enc -// 16 - ritual of sanct TODO: This will become "target space", hopefully +// 16 - target spell on space TODO: Maybe this will become just "target space"? // 17 - using space // 18 - seeing monster // which_type - 0 - scen 1 - out 2 - town diff --git a/osx/boe.town.cpp b/osx/boe.town.cpp index aeb5a530..d244e070 100644 --- a/osx/boe.town.cpp +++ b/osx/boe.town.cpp @@ -1244,7 +1244,7 @@ void erase_specials()//// void erase_out_specials() { - short i,j,k,l,m,out_num; + short out_num; cSpecial sn; short sd1,sd2; location where; diff --git a/osx/classes/party.cpp b/osx/classes/party.cpp index ef6c94d7..1ea7479d 100644 --- a/osx/classes/party.cpp +++ b/osx/classes/party.cpp @@ -619,7 +619,8 @@ void cParty::readFrom(std::istream& file){ cPlayer& cParty::operator[](unsigned short n){ if(n > 6) throw std::out_of_range("Attempt to access a player that doesn't exist."); - else if(n == 6) return adven[0]; // TODO: PC #6 should never be accessed, but bounds checking is rarely done, so this is a quick fix. + else if(n == 6) + return adven[0]; // TODO: PC #6 should never be accessed, but bounds checking is rarely done, so this is a quick fix. return adven[n]; } diff --git a/osx/classes/town.cpp b/osx/classes/town.cpp index c3a37b94..a1c18047 100644 --- a/osx/classes/town.cpp +++ b/osx/classes/town.cpp @@ -66,6 +66,7 @@ cTown& cTown::operator = (legacy::town_record_type& old){ max_num_monst = old.max_num_monst; spec_on_entry = old.spec_on_entry; spec_on_entry_if_dead = old.spec_on_entry_if_dead; + spec_on_hostile = -1; for(i = 0; i < 8; i++){ timer_spec_times[i] = old.timer_spec_times[i]; timer_specs[i] = old.timer_specs[i]; diff --git a/osx/classes/universe.cpp b/osx/classes/universe.cpp index ad7509e9..3fa70771 100644 --- a/osx/classes/universe.cpp +++ b/osx/classes/universe.cpp @@ -787,7 +787,7 @@ void cCurTown::writeTo(std::ostream& file){ file << "INBOAT " << in_boat << '\n'; file << "AT " << p_loc.x << ' ' << p_loc.y << '\n'; file << '\f'; - for(int i; i < 115; i++) + for(int i = 0; i < 115; i++) if(items[i].variety != eItemType::NO_ITEM){ file << "ITEM " << i << '\n'; items[i].writeTo(file); diff --git a/osx/dialogxml/dialog.h b/osx/dialogxml/dialog.h index 89624ade..3bed58b7 100644 --- a/osx/dialogxml/dialog.h +++ b/osx/dialogxml/dialog.h @@ -97,6 +97,14 @@ public: template void setResult(const type& val){ result = val; } + /// Iterate through all the controls in the dialog. + /// @param callback A function taking a string as its first argument + /// and a control reference as its second argument. + template void forEach(Fcn callback) { + for(auto ctrl : controls) { + callback(ctrl.first, *ctrl.second); + } + } /// Set the background pattern of the dialog. /// @param n The numeric index of the background pattern, which should be in the range [0,20]. /// You can use the constants BG_LIGHT or BG_DARK to reference the most commonly used backgrounds. diff --git a/osx/dialogxml/dlogutil.cpp b/osx/dialogxml/dlogutil.cpp index a1e9e64f..eeb4b4c7 100644 --- a/osx/dialogxml/dlogutil.cpp +++ b/osx/dialogxml/dlogutil.cpp @@ -330,7 +330,7 @@ cThreeChoice::cThreeChoice void cThreeChoice::init_strings(std::vector& strings, unsigned short left){ TextStyle style; RECT cur_text_rect = {2, left, 0, 0}; - size_t total_len, str_width, str_height; + size_t total_len = 0, str_width, str_height; for (unsigned int i = 0; i < strings.size(); i++) total_len += string_length(strings[i], style); total_len = total_len * 12; diff --git a/osx/tools/fileio.cpp b/osx/tools/fileio.cpp index 32680e54..947abf2c 100644 --- a/osx/tools/fileio.cpp +++ b/osx/tools/fileio.cpp @@ -715,6 +715,8 @@ bool load_outdoor_str(location which_out, short which_str, char* str){ return false; } + // TODO: len was never assigned at all, is this the correct value? + len = sizeof(store_out); n = fread(&store_out, len, 1, file_id); for (i = 0; i < 120; i++) { len = (long) (store_out.strlens[i]); diff --git a/osx/tools/soundtool.cpp b/osx/tools/soundtool.cpp index 853814d3..027ea456 100644 --- a/osx/tools/soundtool.cpp +++ b/osx/tools/soundtool.cpp @@ -111,7 +111,7 @@ void play_sound(short which, short how_many_times) { // if < 0, play asynch } snd_played[channel] = abs(which); } - if (which < 0) // TODO: Guessing the delay should be in milliseconds; maybe this isn't the case. + if (which < 0) sf::sleep(time_in_ticks(sound_delay[-1 * which])); if(how_many_times > 1) play_sound(which, how_many_times - 1);