Turn sparse arrays into sets.
This commit is contained in:
@@ -1729,12 +1729,10 @@ bool handle_keystroke(sf::Event& event){
|
||||
|
||||
case '?':
|
||||
if(overall_mode == MODE_SHOPPING) {
|
||||
univ.party.help_received[26] = 0;
|
||||
give_help(226,27);
|
||||
break;
|
||||
}
|
||||
if(overall_mode == MODE_TALKING) {
|
||||
univ.party.help_received[5] = 0;
|
||||
give_help(205,6);
|
||||
break;
|
||||
}
|
||||
|
@@ -1348,7 +1348,7 @@ void do_combat_cast(location target) {
|
||||
}
|
||||
store_m_type = -1;
|
||||
play_sound(52);
|
||||
univ.party.m_noted[cur_monst->number] = true;
|
||||
univ.party.m_noted.insert(cur_monst->number);
|
||||
adjust_monst_menu();
|
||||
display_monst(0,cur_monst,0);
|
||||
store_sound = 25;
|
||||
|
@@ -217,8 +217,7 @@ void handle_shop_event(location p) {
|
||||
location loc = {p.x + ul.x, p.y + ul.y};
|
||||
if(!help_btn->handleClick(loc))
|
||||
return;
|
||||
univ.party.help_received[26] = 0;
|
||||
give_help(26,27);
|
||||
give_help(226,27);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -673,8 +672,7 @@ void handle_talk_event(location p) {
|
||||
location loc = {p.x + ul.x, p.y + ul.y};
|
||||
if(!help_btn->handleClick(loc))
|
||||
return;
|
||||
univ.party.help_received[5] = 0;
|
||||
give_help(5,6);
|
||||
give_help(205,6);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1134,9 +1132,7 @@ void load_prefs(){
|
||||
PSD[SDF_GAME_SPEED] = get_int_pref("GameSpeed");
|
||||
|
||||
std::vector<int> help = get_iarray_pref("ReceivedHelp");
|
||||
for(int i : help)
|
||||
if(i < 120)
|
||||
univ.party.help_received[i] = 1;
|
||||
std::copy(help.begin(), help.end(), std::inserter(univ.party.help_received, univ.party.help_received.begin()));
|
||||
}
|
||||
|
||||
void save_prefs(bool resetHelp){
|
||||
@@ -1215,8 +1211,7 @@ static bool prefs_event_filter (cDialog& me, std::string id, eKeyMod) {
|
||||
else if(speed == "snail")
|
||||
PSD[SDF_GAME_SPEED] = 3;
|
||||
if(dynamic_cast<cLed&>(me["resethelp"]).getState() == led_red) {
|
||||
for(i = 0; i < 120; i++)
|
||||
univ.party.help_received[i] = 0;
|
||||
univ.party.help_received.clear();
|
||||
reset_help = true;
|
||||
}
|
||||
}
|
||||
@@ -1280,14 +1275,10 @@ void pick_preferences() {
|
||||
break;
|
||||
}
|
||||
|
||||
if(univ.party.help_received[55] == 0) {
|
||||
// TODO: Not sure if this bit is needed?
|
||||
// cd_initial_draw(1099);
|
||||
give_help(55,0,prefsDlog);
|
||||
}
|
||||
void (*give_help)(short,short,cDialog&) = ::give_help;
|
||||
|
||||
int store_display_mode = display_mode;
|
||||
prefsDlog.run();
|
||||
prefsDlog.run(std::bind(give_help, 55, 0, std::ref(prefsDlog)));
|
||||
|
||||
if(display_mode != store_display_mode)
|
||||
changed_display_mode = true;
|
||||
@@ -1325,7 +1316,6 @@ static bool edit_party_event_filter(cDialog& me, std::string item_hit, eKeyMod)
|
||||
if(item_hit == "done") {
|
||||
me.toast(true);
|
||||
} else if(item_hit == "help") {
|
||||
univ.party.help_received[22] = 0;
|
||||
give_help(222,23,me);
|
||||
} else {
|
||||
short which_pc = item_hit[item_hit.length()-1] - '1';
|
||||
@@ -1390,11 +1380,10 @@ void edit_party() {
|
||||
pcDialog.attachClickHandlers(edit_party_event_filter, buttons);
|
||||
|
||||
put_party_stats(pcDialog);
|
||||
if(univ.party.help_received[22] == 0) {
|
||||
give_help(22,23,pcDialog);
|
||||
}
|
||||
void (*give_help)(short,short,cDialog&) = ::give_help;
|
||||
give_help(22,23,pcDialog);
|
||||
|
||||
pcDialog.run();
|
||||
pcDialog.run(std::bind(give_help, 22, 23, std::ref(pcDialog)));
|
||||
|
||||
if(univ.party[current_pc].main_status != eMainStatus::ALIVE)
|
||||
current_pc = first_active_pc();
|
||||
|
@@ -681,8 +681,8 @@ char get_fluid_trim(location where,ter_num_t ter_type) {
|
||||
// Sees if party has seen a monster of this sort, gives special messages as necessary
|
||||
void check_if_monst_seen(unsigned short m_num, location at) {\
|
||||
// Give special messages if necessary
|
||||
if(m_num < 10000 && !univ.party.m_seen[m_num]) {
|
||||
univ.party.m_seen[m_num] = true;
|
||||
if(m_num < 10000 && !univ.party.m_seen.count(m_num)) {
|
||||
univ.party.m_seen.insert(m_num);
|
||||
play_see_monster_str(m_num, at);
|
||||
}
|
||||
// Make the monster vocalize if applicable
|
||||
|
@@ -829,9 +829,9 @@ static void give_help(short help1,short help2,cDialog* parent) {
|
||||
}
|
||||
if((PSD[SDF_NO_INSTANT_HELP] > 0) && !help_forced)
|
||||
return;
|
||||
if(univ.party.help_received[help1] > 0 && !help_forced)
|
||||
if(univ.party.help_received.count(help1) > 0 && !help_forced)
|
||||
return;
|
||||
univ.party.help_received[help1] = 1;
|
||||
univ.party.help_received.insert(help1);
|
||||
append_iarray_pref("ReceivedHelp", help1);
|
||||
str1 = get_str("help",help1);
|
||||
if(help2 > 0)
|
||||
|
@@ -628,11 +628,9 @@ bool show_get_items(std::string titleText, std::vector<cItem*>& itemRefs, short
|
||||
}
|
||||
put_item_graphics(itemDialog, first_item, pc_getting, itemRefs);
|
||||
|
||||
if(univ.party.help_received[36] == 0) {
|
||||
give_help(36,37,itemDialog);
|
||||
}
|
||||
void (*give_help)(short,short,cDialog&) = ::give_help;
|
||||
|
||||
itemDialog.run();
|
||||
itemDialog.run(std::bind(give_help, 36, 37, _1));
|
||||
|
||||
return itemDialog.getResult<bool>();
|
||||
|
||||
|
@@ -70,7 +70,7 @@ void adjust_monst_menu() {
|
||||
on_monst_menu[i] = -1;
|
||||
}
|
||||
for(i = 1; i < 256; i++) {
|
||||
if((i == 1) || (univ.party.m_noted[i] > 0)) {
|
||||
if(i == 1 || univ.party.m_noted.count(i) > 0) {
|
||||
on_monst_menu[monst_pos] = i;
|
||||
monst_pos++;
|
||||
}
|
||||
|
@@ -147,8 +147,6 @@ static void init_party_scen_data() {
|
||||
for(i = 0; i < 5; i++)
|
||||
for(j = 0; j < 10; j++)
|
||||
univ.party.magic_store_items[i][j].variety = eItemType::NO_ITEM;
|
||||
for(i = 0; i < 256; i++)
|
||||
univ.party.m_seen[i] = univ.party.m_noted[i] = 0;
|
||||
// for(i = 0; i < 50; i++)
|
||||
// univ.party.journal_str[i] = -1;
|
||||
// for(i = 0; i < 140; i++)
|
||||
@@ -1322,7 +1320,7 @@ void cast_town_spell(location where) {
|
||||
if(iLiving* targ = univ.target_there(where, TARG_MONST)) {
|
||||
cCreature* monst = dynamic_cast<cCreature*>(targ);
|
||||
if(town_spell == eSpell::SCRY_MONSTER) {
|
||||
univ.party.m_noted[monst->number] = true;
|
||||
univ.party.m_noted.insert(monst->number);
|
||||
adjust_monst_menu();
|
||||
display_monst(0,monst,0);
|
||||
}
|
||||
@@ -1886,7 +1884,6 @@ static bool pick_spell_event_filter(cDialog& me, std::string item_hit, const eSk
|
||||
put_spell_list(me, store_situation);
|
||||
put_spell_led_buttons(me, store_situation, store_spell);
|
||||
} else if(item_hit == "help") {
|
||||
univ.party.help_received[7] = 0;
|
||||
give_help(207,8,me);
|
||||
}
|
||||
return true;
|
||||
@@ -2099,11 +2096,9 @@ eSpell pick_spell(short pc_num,eSkill type) { // 70 - no spell OW spell num
|
||||
draw_caster_buttons(castSpell, type);
|
||||
put_spell_led_buttons(castSpell, type, former_spell);
|
||||
|
||||
if(univ.party.help_received[7] == 0) {
|
||||
give_help(7,8,castSpell);
|
||||
}
|
||||
void (*give_help)(short,short,cDialog&) = ::give_help;
|
||||
|
||||
castSpell.run();
|
||||
castSpell.run(std::bind(give_help, 7, 8, _1));
|
||||
|
||||
return cSpell::fromNum(type, castSpell.getResult<short>());
|
||||
}
|
||||
@@ -2205,8 +2200,7 @@ void do_alchemy() {
|
||||
|
||||
static bool alch_choice_event_filter(cDialog& me, std::string item_hit, eKeyMod) {
|
||||
if(item_hit == "help") {
|
||||
univ.party.help_received[20] = 0;
|
||||
give_help(20,21,me);
|
||||
give_help(220,21,me);
|
||||
return true;
|
||||
}
|
||||
if(item_hit == "cancel")
|
||||
@@ -2240,11 +2234,10 @@ eAlchemy alch_choice(short pc_num) {
|
||||
sout << univ.party[pc_num].name;
|
||||
sout << " (skill " << univ.party[pc_num].skill(eSkill::ALCHEMY) << ")";
|
||||
chooseAlchemy["mixer"].setText(sout.str());
|
||||
if(univ.party.help_received[20] == 0) {
|
||||
give_help(20,21,chooseAlchemy);
|
||||
}
|
||||
|
||||
chooseAlchemy.run();
|
||||
void (*give_help)(short,short,cDialog&) = ::give_help;
|
||||
|
||||
chooseAlchemy.run(std::bind(give_help, 20, 21, std::ref(chooseAlchemy)));
|
||||
return chooseAlchemy.getResult<eAlchemy>();
|
||||
}
|
||||
|
||||
|
@@ -108,7 +108,8 @@ void cParty::append(legacy::party_record_type& old){
|
||||
magic_store_items[j][i].append(old.magic_store_items[j][i]);
|
||||
}
|
||||
for(i = 0; i < 256; i++)
|
||||
m_noted[i] = old.m_seen[i];
|
||||
if(old.m_seen[i])
|
||||
m_noted.insert(i);
|
||||
journal.reserve(50);
|
||||
// The journal wasn't used before, so let's not bother converting it
|
||||
// for(i = 0; i < 50; i++){
|
||||
@@ -129,7 +130,8 @@ void cParty::append(legacy::party_record_type& old){
|
||||
cConvers t;
|
||||
t.append(old.talk_save[i], univ.scenario);
|
||||
talk_save.push_back(t);
|
||||
help_received[i] = old.help_received[i];
|
||||
if(old.help_received[i])
|
||||
help_received.insert(i);
|
||||
}
|
||||
direction = eDirection(old.direction);
|
||||
at_which_save_slot = old.at_which_save_slot;
|
||||
@@ -516,12 +518,10 @@ void cParty::writeTo(std::ostream& file) const {
|
||||
file << "SPLIT_LEFT_IN " << left_in << '\n';
|
||||
file << "SPLIT_LEFT_AT " << left_at.x << ' ' << left_at.y << '\n';
|
||||
}
|
||||
for(int i = 0; i < 256; i++)
|
||||
if(m_noted[i])
|
||||
file << "ROSTER " << i << '\n';
|
||||
for(int i = 0; i < 256; i++)
|
||||
if(m_seen[i])
|
||||
file << "SEEN " << i << '\n';
|
||||
for(int i : m_noted)
|
||||
file << "ROSTER " << i << '\n';
|
||||
for(int i : m_seen)
|
||||
file << "SEEN " << i << '\n';
|
||||
for(int i = 0; i < 4; i++)
|
||||
if(imprisoned_monst[i] > 0)
|
||||
file << "SOULCRYSTAL " << i << ' ' << imprisoned_monst[i] << '\n';
|
||||
@@ -539,9 +539,8 @@ void cParty::writeTo(std::ostream& file) const {
|
||||
for(int i = 0; i < 50; i++)
|
||||
if(spec_items[i])
|
||||
file << "ITEM " << i << '\n';
|
||||
for(int i = 0; i < 120; i++)
|
||||
if(help_received[i])
|
||||
file << "HELP " << i << '\n';
|
||||
for(int i : help_received)
|
||||
file << "HELP " << i << '\n';
|
||||
for(int i = 0; i < 200; i++)
|
||||
if(m_killed[i] > 0)
|
||||
file << "TOWNSLAUGHTER " << i << ' ' << m_killed[i] << '\n';
|
||||
@@ -736,11 +735,11 @@ void cParty::readFrom(std::istream& file){
|
||||
else if(cur == "ROSTER"){
|
||||
int i;
|
||||
sin >> i;
|
||||
m_noted[i] = true;
|
||||
m_noted.insert(i);
|
||||
}else if(cur == "SEEN"){
|
||||
int i;
|
||||
sin >> i;
|
||||
m_seen[i] = true;
|
||||
m_seen.insert(i);
|
||||
}else if(cur == "SOULCRYSTAL"){
|
||||
int i;
|
||||
sin >> i;
|
||||
@@ -768,7 +767,7 @@ void cParty::readFrom(std::istream& file){
|
||||
}else if(cur == "HELP"){
|
||||
int i;
|
||||
sin >> i;
|
||||
help_received[i] = true;
|
||||
help_received.insert(i);
|
||||
}else if(cur == "TOWNSLAUGHTER"){
|
||||
int i;
|
||||
sin >> i;
|
||||
|
@@ -97,8 +97,8 @@ public:
|
||||
std::map<int,std::map<int,int>> store_limited_stock;
|
||||
std::vector<job_bank_t> job_banks;
|
||||
mon_num_t imprisoned_monst[4]; // Soul Crystal
|
||||
char m_noted[256]; // has the monster been scried?
|
||||
char m_seen[256]; // has the monster ever been seen? (this used to have the above meaning)
|
||||
std::set<mon_num_t> m_noted; // has the monster been scried?
|
||||
std::set<mon_num_t> m_seen; // has the monster ever been seen? (this used to have the above meaning)
|
||||
std::vector<cJournal> journal;
|
||||
std::vector<cEncNote> special_notes;
|
||||
std::vector<cConvers> talk_save;
|
||||
@@ -116,7 +116,7 @@ public:
|
||||
short key_times[100];
|
||||
std::vector<cTimer> party_event_timers;
|
||||
std::array<bool,50> spec_items;
|
||||
char help_received[120];
|
||||
std::set<int> help_received;
|
||||
short m_killed[200]; // monsters killed per town, I think
|
||||
long long total_m_killed, total_dam_done, total_xp_gained, total_dam_taken;
|
||||
std::string scen_name;
|
||||
|
@@ -1028,7 +1028,7 @@ bool cDialog::sendInput(cKey key) {
|
||||
return true;
|
||||
}
|
||||
|
||||
void cDialog::run(){
|
||||
void cDialog::run(std::function<void(cDialog&)> onopen){
|
||||
cDialog* formerTop = topWindow;
|
||||
// TODO: The introduction of the static topWindow means I may be able to use this instead of parent->win; do I still need parent?
|
||||
sf::RenderWindow* parentWin = &(parent ? parent->win : mainPtr);
|
||||
@@ -1059,6 +1059,7 @@ void cDialog::run(){
|
||||
makeFrontWindow(parent ? parent-> win : mainPtr);
|
||||
makeFrontWindow(win);
|
||||
ModalSession dlog(win, *parentWin);
|
||||
if(onopen) onopen(*this);
|
||||
animTimer.restart();
|
||||
while(dialogNotToast){
|
||||
draw();
|
||||
|
@@ -85,7 +85,8 @@ public:
|
||||
/// @note Even if it returns false, the label has been attached (ie, the existing label was updated).
|
||||
bool addLabelFor(std::string key, std::string label, eLabelPos where, short offset, bool bold);
|
||||
/// Show the dialog and start its event loop. All dialogs are modal.
|
||||
void run(); // cd_run_dialog
|
||||
/// @param onopen A function to be called after the dialog is displayed but before the event loop starts.
|
||||
void run(std::function<void(cDialog&)> onopen = nullptr); // cd_run_dialog
|
||||
/// Get the result of the dialog.
|
||||
/// @tparam type The result type.
|
||||
/// @throw boost::bad_any_cast if the provided result type is different from the type set by getResult().
|
||||
|
@@ -348,9 +348,9 @@ static void give_help(short help1,short help2,cDialog* parent) {
|
||||
// This SDF is the "never show instant help" flag
|
||||
if(univ.party.stuff_done[306][4] > 0 && !help_forced)
|
||||
return;
|
||||
if(univ.party.help_received[help1] > 0 && !help_forced)
|
||||
if(univ.party.help_received.count(help1) > 0 && !help_forced)
|
||||
return;
|
||||
univ.party.help_received[help1] = 1;
|
||||
univ.party.help_received.insert(help1);
|
||||
str1 = get_str("help",help1);
|
||||
if(help2 > 0)
|
||||
str2 = get_str("help",help2);
|
||||
|
Reference in New Issue
Block a user