From d9b9130d002c037021cb33858278d1f1deb933bf Mon Sep 17 00:00:00 2001 From: Celtic Minstrel Date: Fri, 23 Jan 2015 01:23:43 -0500 Subject: [PATCH] Make monster/item lists in scenario town record dynamic; move monsters to town superclass --- src/boe.actions.cpp | 6 +- src/boe.combat.cpp | 64 ++++++++--------- src/boe.dlgutil.cpp | 4 +- src/boe.fileio.cpp | 4 +- src/boe.global.h | 2 +- src/boe.graphics.cpp | 2 +- src/boe.graphutil.cpp | 2 +- src/boe.items.cpp | 14 ++-- src/boe.locutils.cpp | 6 +- src/boe.monster.cpp | 35 ++++----- src/boe.newgraph.cpp | 2 +- src/boe.party.cpp | 2 +- src/boe.specials.cpp | 16 ++--- src/boe.text.cpp | 2 +- src/boe.town.cpp | 44 ++++++------ src/classes/creatlist.h | 1 + src/classes/monster.cpp | 21 ++++++ src/classes/monster.h | 2 + src/classes/regtown.cpp | 45 ++---------- src/classes/regtown.h | 15 ---- src/classes/tmpltown.cpp | 14 +--- src/classes/tmpltown.h | 24 +------ src/classes/town.cpp | 20 +++++- src/classes/town.h | 8 +-- src/classes/universe.cpp | 7 +- src/scenedit/scen.actions.cpp | 128 +++++++++++++++------------------ src/scenedit/scen.fileio.cpp | 4 +- src/scenedit/scen.graphics.cpp | 31 ++++---- src/scenedit/scen.main.cpp | 5 +- src/scenedit/scen.townout.cpp | 4 +- 30 files changed, 243 insertions(+), 291 deletions(-) diff --git a/src/boe.actions.cpp b/src/boe.actions.cpp index 5b2fe52f..ad242f56 100644 --- a/src/boe.actions.cpp +++ b/src/boe.actions.cpp @@ -519,7 +519,7 @@ static void handle_talk(location destination, bool& did_something, bool& need_re add_string_to_buf(" Can't see space "); need_reprint = true; } else { - for(int i = 0; i < univ.town->max_monst(); i++) { + for(int i = 0; i < univ.town.monst.size(); i++) { if(monst_on_space(destination,i)) { did_something = true; need_redraw = true; @@ -1842,7 +1842,7 @@ bool handle_keystroke(sf::Event& event){ case 'K': if(!in_scen_debug) break; - for(i = 0; i < univ.town->max_monst(); i++) { + for(i = 0; i < univ.town.monst.size(); i++) { if((is_combat()) && (univ.town.monst[i].active > 0) && (univ.town.monst[i].attitude % 2 == 1)) univ.town.monst[i].active = 0; @@ -2984,7 +2984,7 @@ bool town_move_party(location destination,short forced) { } */ - if(monst_there(destination) > univ.town->max_monst()) + if(monst_there(destination) >= univ.town.monst.size()) keep_going = check_special_terrain(destination,eSpecCtx::TOWN_MOVE,0,&spec_num,&check_f); if(check_f) forced = true; diff --git a/src/boe.combat.cpp b/src/boe.combat.cpp index 9589496b..ea946122 100644 --- a/src/boe.combat.cpp +++ b/src/boe.combat.cpp @@ -281,7 +281,7 @@ void start_outdoor_combat(cOutdoors::cCreature encounter,ter_num_t in_which_terr create_out_combat_terrain((short) in_which_terrain,num_walls,0);//// - for(i = 0; i < univ.town->max_monst(); i++) { + for(i = 0; i < univ.town.monst.size(); i++) { univ.town.monst[i].number = 0; univ.town.monst[i].active = 0; } @@ -319,7 +319,7 @@ void start_outdoor_combat(cOutdoors::cCreature encounter,ter_num_t in_which_terr } // place monsters, w. friendly monsts landing near PCs - for(i = 0; i < univ.town->max_monst(); i++) + for(i = 0; i < univ.town.monst.size(); i++) if(univ.town.monst[i].active > 0) { univ.town.monst[i].target = 6; @@ -348,12 +348,12 @@ void start_outdoor_combat(cOutdoors::cCreature encounter,ter_num_t in_which_terr combat_active_pc = 6; spell_caster = 6; missile_firer = 6; - for(i = 0; i < univ.town->max_monst(); i++) + for(i = 0; i < univ.town.monst.size(); i++) univ.town.monst[i].target = 6; for(i = 0; i < 6; i++) { univ.party[i].parry = 0; - univ.party[i].last_attacked = univ.town->max_monst() + 10; + univ.party[i].last_attacked = univ.town.monst.size() + 10; } for(i = 0; i < NUM_TOWN_ITEMS; i++) @@ -383,12 +383,12 @@ bool pc_combat_move(location destination) { monst_hit = monst_there(destination); - if(monst_hit > univ.town->max_monst() && univ.party[current_pc].status[eStatus::FORCECAGE] > 0) { + if(monst_hit >= univ.town.monst.size() && univ.party[current_pc].status[eStatus::FORCECAGE] > 0) { add_string_to_buf("Move: Can't escape."); return false; } - if(monst_hit > univ.town->max_monst()) + if(monst_hit >= univ.town.monst.size()) keep_going = check_special_terrain(destination,eSpecCtx::COMBAT_MOVE,current_pc,&spec_num,&check_f); if(check_f) forced = true; @@ -419,7 +419,7 @@ bool pc_combat_move(location destination) { add_string_to_buf(create_line); return true; } - else if(monst_hit <= univ.town->max_monst()) { + else if(monst_hit < univ.town.monst.size()) { // s2 = 2 here appears to mean "go ahead and attack", while s2 = 1 means "cancel attack". // Then s1 % 2 == 1 means the monster is hostile to the party. s1 = univ.town.monst[monst_hit].attitude; @@ -457,7 +457,7 @@ bool pc_combat_move(location destination) { else if(forced || (!impassable(univ.town->terrain(destination.x,destination.y)) && pc_there(destination) == 6)) { // monsters get back-shots - for(i = 0; i < univ.town->max_monst(); i++) { + for(i = 0; i < univ.town.monst.size(); i++) { monst_loc = univ.town.monst[i].cur_loc; monst_exist = univ.town.monst[i].active; @@ -1228,7 +1228,7 @@ void do_combat_cast(location target) { default: targ_num = monst_there(target); - if(targ_num > univ.town->max_monst()) + if(targ_num >= univ.town.monst.size()) add_string_to_buf(" Nobody there "); else { cur_monst = &univ.town.monst[targ_num]; @@ -1447,7 +1447,7 @@ void handle_marked_damage() { damage_pc(i,univ.party[i].marked_damage,eDamageType::MARKED,eRace::UNKNOWN,0); univ.party[i].marked_damage = 0; } - for(i = 0; i < univ.town->max_monst(); i++) + for(i = 0; i < univ.town.monst.size(); i++) if(univ.town.monst[i].marked_damage > 0) { damage_monst(i, current_pc, univ.town.monst[i].marked_damage, 0, eDamageType::MARKED,0); @@ -1564,12 +1564,12 @@ void fire_missile(location target) { if(univ.party[missile_firer].items[ammo_inv_slot].ability == eItemAbil::SEEKING_MISSILE) { targ_monst = monst_there(target); std::set targets; - if(targ_monst >= univ.town->max_monst() || univ.town.monst[targ_monst].attitude % 2 == 0) { + if(targ_monst >= univ.town.monst.size() || univ.town.monst[targ_monst].attitude % 2 == 0) { for(int i = -1; i <= 1; i++) { for(int j = -1; j <= 1; j++) { if(i == 0 && j == 0) continue; targ_monst = monst_there(loc(target.x + i, target.y + j)); - if(targ_monst < univ.town->max_monst()) { + if(targ_monst < univ.town.monst.size()) { bool invisible = univ.town.monst[targ_monst].invisible; bool friendly = univ.town.monst[targ_monst].attitude % 2 == 0; int seek_chance = 10; @@ -1641,7 +1641,7 @@ void fire_missile(location target) { if(r1 > hit_chance[skill]) add_string_to_buf(" Missed."); - else if((targ_monst = monst_there(target)) < univ.town->max_monst()) { + else if((targ_monst = monst_there(target)) < univ.town.monst.size()) { cur_monst = &univ.town.monst[targ_monst]; eDamageType dmg_tp = eDamageType::UNBLOCKABLE; short bonus_dam = 0; @@ -2000,7 +2000,7 @@ void do_monster_turn() { monsters_going = true; // This affects how graphics are drawn. - num_monst = univ.town->max_monst(); + num_monst = univ.town.monst.size(); if(overall_mode < MODE_COMBAT) which_combat_type = 1; @@ -2017,7 +2017,7 @@ void do_monster_turn() { if(r1 < 50) cur_monst->active = 2; - for(j = 0; j < univ.town->max_monst(); j++) + for(j = 0; j < univ.town.monst.size(); j++) if(monst_near(j,cur_monst->cur_loc,5,1)) { cur_monst->active = 2; } @@ -2025,7 +2025,7 @@ void do_monster_turn() { if((cur_monst->active == 1) && (cur_monst->attitude % 2 == 1)) { // Now it looks for PC-friendly monsters // dist check is for efficiency - for(j = 0; j < univ.town->max_monst(); j++) + for(j = 0; j < univ.town.monst.size(); j++) if((univ.town.monst[j].active > 0) && (univ.town.monst[j].attitude % 2 != 1) && (dist(cur_monst->cur_loc,univ.town.monst[j].cur_loc) <= 6) && @@ -2036,7 +2036,7 @@ void do_monster_turn() { // See if friendly, fighting monster see hostile monster. If so, make mobile // dist check is for efficiency if((cur_monst->active == 1) && (cur_monst->attitude == 2)) { - for(j = 0; j < univ.town->max_monst(); j++) + for(j = 0; j < univ.town.monst.size(); j++) if((univ.town.monst[j].active > 0) && (univ.town.monst[j].attitude % 2 == 1) && (dist(cur_monst->cur_loc,univ.town.monst[j].cur_loc) <= 6) && (can_see_light(cur_monst->cur_loc,univ.town.monst[j].cur_loc,sight_obscurity) < 5)) { @@ -3441,7 +3441,7 @@ bool monst_cast_mage(cCreature *caster,short targ) { for(i = 0; i < 6; i++) if(pc_near(i,caster->cur_loc,8)) slow_pc(i,2 + caster->level / 4); - for(i = 0; i < univ.town->max_monst(); i++) { + for(i = 0; i < univ.town.monst.size(); i++) { if((univ.town.monst[i].active != 0) && (((univ.town.monst[i].attitude % 2 == 1) && (caster->attitude % 2 != 1)) || ((univ.town.monst[i].attitude % 2 != 1) && (caster->attitude % 2 == 1)) || @@ -3452,7 +3452,7 @@ bool monst_cast_mage(cCreature *caster,short targ) { break; case eSpell::HASTE_MAJOR: play_sound(25); - for(i = 0; i < univ.town->max_monst(); i++) + for(i = 0; i < univ.town.monst.size(); i++) if((monst_near(i,caster->cur_loc,8,0)) && (caster->attitude == univ.town.monst[i].attitude)) { affected = &univ.town.monst[i]; @@ -3495,7 +3495,7 @@ bool monst_cast_mage(cCreature *caster,short targ) { break; case eSpell::BLESS_MAJOR: play_sound(25); - for(i = 0; i < univ.town->max_monst(); i++) + for(i = 0; i < univ.town.monst.size(); i++) if((monst_near(i,caster->cur_loc,8,0)) && (caster->attitude == univ.town.monst[i].attitude)) { affected = &univ.town.monst[i]; @@ -3747,7 +3747,7 @@ bool monst_cast_priest(cCreature *caster,short targ) { if(spell == eSpell::PESTILENCE) disease_pc(i,2 + r2); } - for(i = 0; i < univ.town->max_monst(); i++) { + for(i = 0; i < univ.town.monst.size(); i++) { if((univ.town.monst[i].active != 0) && (((univ.town.monst[i].attitude % 2 == 1) && (caster->attitude % 2 != 1)) || ((univ.town.monst[i].attitude % 2 != 1) && (caster->attitude % 2 == 1)) || @@ -3775,7 +3775,7 @@ bool monst_cast_priest(cCreature *caster,short targ) { play_sound(24); // TODO: What's r2 for here? Should it be used for Revive All? r1 = get_ran(2,1,4); r2 = get_ran(3,1,6); - for(i = 0; i < univ.town->max_monst(); i++) + for(i = 0; i < univ.town.monst.size(); i++) if((monst_near(i,caster->cur_loc,8,0)) && (caster->attitude == univ.town.monst[i].attitude)) { affected = &univ.town.monst[i]; @@ -3887,7 +3887,7 @@ location closest_pc_loc(location where) { short count_levels(location where,short radius) { short i,store = 0; - for(i = 0; i < univ.town->max_monst(); i++) + for(i = 0; i < univ.town.monst.size(); i++) if(monst_near(i,where,radius,0)) { if(univ.town.monst[i].attitude % 2 == 1) store = store - univ.town.monst[i].level; @@ -4123,7 +4123,7 @@ static void place_spell_pattern(effect_pat_type pat,location center,unsigned sho fast_bang = 0; // Damage to monsters - for(k = 0; k < univ.town->max_monst(); k++) + for(k = 0; k < univ.town.monst.size(); k++) if((univ.town.monst[k].active > 0) && (dist(center,univ.town.monst[k].cur_loc) <= 5)) { monster_hit = false; // First actually make barriers, then draw them, then inflict damaging effects. @@ -4257,7 +4257,7 @@ void do_shockwave(location target) { if((dist(target,univ.party[i].combat_pos) > 0) && (dist(target,univ.party[i].combat_pos) < 11) && univ.party[i].main_status == eMainStatus::ALIVE) damage_pc(i, get_ran(2 + dist(target,univ.party[i].combat_pos) / 2, 1, 6), eDamageType::UNBLOCKABLE,eRace::UNKNOWN,0); - for(i = 0; i < univ.town->max_monst(); i++) + for(i = 0; i < univ.town.monst.size(); i++) if((univ.town.monst[i].active != 0) && (dist(target,univ.town.monst[i].cur_loc) > 0) && (dist(target,univ.town.monst[i].cur_loc) < 11) && (can_see_light(target,univ.town.monst[i].cur_loc,sight_obscurity) < 5)) @@ -4275,7 +4275,7 @@ void radius_damage(location target,short radius, short dam, eDamageType type) { if((dist(target,univ.town.p_loc) > 0) && (dist(target,univ.town.p_loc) <= radius) && univ.party[i].main_status == eMainStatus::ALIVE) damage_pc(i, dam, type,eRace::UNKNOWN,0); - for(i = 0; i < univ.town->max_monst(); i++) + for(i = 0; i < univ.town.monst.size(); i++) if((univ.town.monst[i].active != 0) && (dist(target,univ.town.monst[i].cur_loc) > 0) && (dist(target,univ.town.monst[i].cur_loc) <= radius) && (can_see_light(target,univ.town.monst[i].cur_loc,sight_obscurity) < 5)) @@ -4288,7 +4288,7 @@ void radius_damage(location target,short radius, short dam, eDamageType type) { if((dist(target,univ.party[i].combat_pos) > 0) && (dist(target,univ.party[i].combat_pos) <= radius) && univ.party[i].main_status == eMainStatus::ALIVE) damage_pc(i, dam, type,eRace::UNKNOWN,0); - for(i = 0; i < univ.town->max_monst(); i++) + for(i = 0; i < univ.town.monst.size(); i++) if((univ.town.monst[i].active != 0) && (dist(target,univ.town.monst[i].cur_loc) > 0) && (dist(target,univ.town.monst[i].cur_loc) <= radius) && (can_see_light(target,univ.town.monst[i].cur_loc,sight_obscurity) < 5)) @@ -4336,7 +4336,7 @@ void hit_space(location target,short dam,eDamageType type,short report,short hit return; } - for(i = 0; i < univ.town->max_monst(); i++) + for(i = 0; i < univ.town.monst.size(); i++) if((hit_monsters) && (univ.town.monst[i].active != 0) && !stop_hitting) if(monst_on_space(target,i)) { if(processing_fields) @@ -4497,7 +4497,7 @@ bool hit_end_c_button() { bool out_monst_all_dead() { short i; - for(i = 0; i < univ.town->max_monst(); i++) + for(i = 0; i < univ.town.monst.size(); i++) if((univ.town.monst[i].active > 0) && (univ.town.monst[i].attitude % 2 == 1)) { //print_nums(5555,i,univ.town.monst[i].number); //print_nums(5555,univ.town.monst[i].m_loc.x,univ.town.monst[i].m_loc.y); @@ -4691,7 +4691,7 @@ void combat_immed_mage_cast(short current_pc, eSpell spell_num, bool freebie) { case eSpell::FEAR_GROUP: add_string_to_buf(" Enemy scared:"); break; case eSpell::PARALYSIS_MASS: add_string_to_buf(" Enemy paralyzed:"); break; } - for(i = 0; i < univ.town->max_monst(); i++) { + for(i = 0; i < univ.town.monst.size(); i++) { if((univ.town.monst[i].active != 0) && (univ.town.monst[i].attitude % 2 == 1) && (dist(univ.party[current_pc].combat_pos,univ.town.monst[i].cur_loc) <= (*spell_num).range) && (can_see_light(univ.party[current_pc].combat_pos,univ.town.monst[i].cur_loc,sight_obscurity) < 5)) { @@ -4846,7 +4846,7 @@ void combat_immed_priest_cast(short current_pc, eSpell spell_num, bool freebie) if(!freebie) univ.party[current_pc].cur_sp -= (*spell_num).cost; store_sound = 24; - for(i = 0; i < univ.town->max_monst(); i++) { + for(i = 0; i < univ.town.monst.size(); i++) { if((univ.town.monst[i].active != 0) &&(univ.town.monst[i].attitude % 2 == 1) && (dist(univ.party[current_pc].combat_pos,univ.town.monst[i].cur_loc) <= (*spell_num).range)) { // TODO: Should this ^ also check that you can see each target? ie can_see_light(...) < 5 @@ -5085,7 +5085,7 @@ void process_fields() { } } - for(i = 0; i < univ.town->max_monst(); i++) + for(i = 0; i < univ.town.monst.size(); i++) if(univ.town.monst[i].active > 0) monst_inflict_fields(i); diff --git a/src/boe.dlgutil.cpp b/src/boe.dlgutil.cpp index 07408784..12e4ab48 100644 --- a/src/boe.dlgutil.cpp +++ b/src/boe.dlgutil.cpp @@ -836,7 +836,7 @@ void handle_talk_event(location p) { talk_end_forced = true; break; case eTalkNode::END_FIGHT: - if(store_m_num >= 0 && store_m_num <= univ.town->max_monst()) { + if(store_m_num >= 0 && store_m_num < univ.town.monst.size()) { univ.town.monst[store_m_num].attitude = 1; univ.town.monst[store_m_num].mobility = 1; } @@ -847,7 +847,7 @@ void handle_talk_event(location p) { talk_end_forced = true; break; case eTalkNode::END_DIE: - if(store_m_num >= 0 && store_m_num <= univ.town->max_monst()) { + if(store_m_num >= 0 && store_m_num < univ.town.monst.size()) { // TODO: Any reason not to call something like kill_monst? univ.town.monst[store_m_num].active = 0; // Special killing effects diff --git a/src/boe.fileio.cpp b/src/boe.fileio.cpp index 27132885..24d91ff8 100644 --- a/src/boe.fileio.cpp +++ b/src/boe.fileio.cpp @@ -120,7 +120,7 @@ void finish_load_party(){ center = univ.party.p_loc; } else { - for(int i = 0; i < univ.town->max_monst(); i++){ + for(int i = 0; i < univ.town.monst.size(); i++){ univ.town.monst[i].targ_loc.x = 0; univ.town.monst[i].targ_loc.y = 0; } @@ -450,7 +450,7 @@ void start_data_dump() { fout << " Combat type " << which_combat_type << " \n"; } - for(long i = 0; i < univ.town->max_monst(); i++) { + for(long i = 0; i < univ.town.monst.size(); i++) { fout << " Monster " << i << " Status " << univ.town.monst[i].active; fout << " Loc " << univ.town.monst[i].cur_loc.x << " " << univ.town.monst[i].cur_loc.y; fout << " Number " << univ.town.monst[i].number << " Att " << univ.town.monst[i].attitude; diff --git a/src/boe.global.h b/src/boe.global.h index f68f669e..9f68e578 100644 --- a/src/boe.global.h +++ b/src/boe.global.h @@ -10,7 +10,7 @@ #define DRAG_EDGE 15 -#define NUM_TOWN_ITEMS 115 +#define NUM_TOWN_ITEMS univ.town.items.size() #define DISPLAY_LEFT 23 diff --git a/src/boe.graphics.cpp b/src/boe.graphics.cpp index aed6e456..8fe7c847 100644 --- a/src/boe.graphics.cpp +++ b/src/boe.graphics.cpp @@ -692,7 +692,7 @@ void draw_text_bar() { } if((is_combat()) && (monsters_going)) // Print bar for 1st monster with >0 ap - that is monster that is going - for(i = 0; i < univ.town->max_monst(); i++) + for(i = 0; i < univ.town.monst.size(); i++) if((univ.town.monst[i].active > 0) && (univ.town.monst[i].ap > 0)) { put_text_bar(print_monster_going(univ.town.monst[i].number,univ.town.monst[i].ap)); i = 400; diff --git a/src/boe.graphutil.cpp b/src/boe.graphutil.cpp index b75637d2..54bbe015 100644 --- a/src/boe.graphutil.cpp +++ b/src/boe.graphutil.cpp @@ -188,7 +188,7 @@ void draw_monsters() { } } if(is_town() || is_combat()) { - for(i = 0; i < univ.town->max_monst(); i++) + for(i = 0; i < univ.town.monst.size(); i++) if(univ.town.monst[i].active != 0 && !univ.town.monst[i].invisible) if(point_onscreen(center,univ.town.monst[i].cur_loc) && party_can_see_monst(i)) { check_if_monst_seen(univ.town.monst[i].number, univ.town.monst[i].cur_loc); diff --git a/src/boe.items.cpp b/src/boe.items.cpp index 2fbee29a..b52722b7 100644 --- a/src/boe.items.cpp +++ b/src/boe.items.cpp @@ -407,7 +407,7 @@ short get_item(location place,short pc_num,bool check_container) { bool item_near = false; short mass_get = 1; - for(i = 0; i < univ.town->max_monst(); i++) + for(i = 0; i < univ.town.monst.size(); i++) if((univ.town.monst[i].active > 0) && (univ.town.monst[i].attitude == 1) && (can_see_light(place,univ.town.monst[i].cur_loc,sight_obscurity) < 5)) mass_get = 0; @@ -427,12 +427,12 @@ short get_item(location place,short pc_num,bool check_container) { } if(item_near) if(display_item(place,pc_num,mass_get,check_container)) { // if true, there was a theft - for(i = 0; i < univ.town->max_monst(); i++) + for(i = 0; i < univ.town.monst.size(); i++) if((univ.town.monst[i].active > 0) && (univ.town.monst[i].attitude % 2 != 1) && (can_see_light(place,univ.town.monst[i].cur_loc,sight_obscurity) < 5)) { make_town_hostile(); - i = univ.town->max_monst(); add_string_to_buf("Your crime was seen!"); + break; } } @@ -465,14 +465,14 @@ void set_town_attitude(short lo,short hi,short att) { univ.town.monst.friendly = 1; // Nice smart indexing, like Python :D - if(lo <= -univ.town->max_monst()) + if(lo <= -univ.town.monst.size()) lo = 0; if(lo < 0) - lo = univ.town->max_monst() + lo; - if(hi <= -univ.town->max_monst()) + lo = univ.town.monst.size() + lo; + if(hi <= -univ.town.monst.size()) hi = 0; if(hi < 0) - hi = univ.town->max_monst() + hi; + hi = univ.town.monst.size() + hi; if(hi < lo) std::swap(lo, hi); diff --git a/src/boe.locutils.cpp b/src/boe.locutils.cpp index 5c45e0d4..7406fc84 100644 --- a/src/boe.locutils.cpp +++ b/src/boe.locutils.cpp @@ -326,10 +326,10 @@ bool monst_on_space(location loc,short m_num) { short monst_there(location where) { // returns 90 if no short i; - for(i = 0; i < univ.town->max_monst(); i++) + for(i = 0; i < univ.town.monst.size(); i++) if((univ.town.monst[i].active != 0) && (monst_on_space(where,i))) return i; - return 90; + return univ.town.monst.size(); } bool monst_can_be_there(location loc,short m_num) { short i,j; @@ -521,7 +521,7 @@ bool combat_pt_in_light(location to_where) { bool party_sees_a_monst() { // Returns true is a hostile monster is in sight. short i; - for(i = 0; i < univ.town->max_monst(); i++) { + for(i = 0; i < univ.town.monst.size(); i++) { if(univ.town.monst[i].active > 0) if((univ.town.monst[i].attitude == 1) && (party_can_see_monst(i))) diff --git a/src/boe.monster.cpp b/src/boe.monster.cpp index 64625a93..94d160d5 100644 --- a/src/boe.monster.cpp +++ b/src/boe.monster.cpp @@ -169,7 +169,7 @@ void get_monst_dims(mon_num_t monst,short *width, short *height) { void set_up_monst(short mode,mon_num_t m_num) { short which; - for(which = 0; which < univ.town->max_monst(); which++) + for(which = 0; which < univ.town.monst.size(); which++) if(univ.town.monst[which].active == 0) { cMonster& monst = m_num >= 10000 ? univ.party.summons[m_num - 10000] : univ.scenario.scen_monsters[m_num]; univ.town.monst.assign(which, cCreature(m_num), monst, PSD[SDF_EASY_MODE], univ.difficulty_adjust()); @@ -187,7 +187,7 @@ void do_monsters() { bool acted_yet = false; if(overall_mode == MODE_TOWN) - for(i = 0; i < univ.town->max_monst(); i++) + for(i = 0; i < univ.town.monst.size(); i++) if(univ.town.monst[i].active != 0 && univ.town.monst[i].status[eStatus::ASLEEP] <= 0 && univ.town.monst[i].status[eStatus::PARALYZED] <= 0) { // have to pick targets @@ -255,7 +255,7 @@ void do_monsters() { play_sound(18); else play_sound(46); } - for(j = 0; j < univ.town->max_monst(); j++) + for(j = 0; j < univ.town.monst.size(); j++) if((univ.town.monst[j].active == 2) && ((dist(univ.town.monst[i].cur_loc,univ.town.monst[j].cur_loc) <= 5))) univ.town.monst[i].active = 2; @@ -418,7 +418,7 @@ short monst_pick_target(short which_m) { short monst_pick_target_monst(cCreature *which_m) { short min_dist = 1000,i,cur_targ = 6; - for(i = 0; i < univ.town->max_monst(); i++) { + for(i = 0; i < univ.town.monst.size(); i++) { if((univ.town.monst[i].active > 0) && // alive (((which_m->attitude % 2 == 1) && (univ.town.monst[i].attitude % 2 == 0)) || ((which_m->attitude % 2 == 0) && (univ.town.monst[i].attitude % 2 == 1)) || @@ -492,7 +492,7 @@ short closest_pc(location where) { short closest_monst(location where,short mode) { short how_close = 200,i,store = 6; - for(i = 0; i < univ.town->max_monst(); i++) + for(i = 0; i < univ.town.monst.size(); i++) if((((univ.town.monst[i].attitude % 2 == 1) && (mode == 1)) || ((univ.town.monst[i].attitude % 2 == 0) && (mode == 2))) && (dist(where,univ.town.monst[i].cur_loc) < how_close)) { @@ -514,7 +514,7 @@ short switch_target_to_adjacent(short which_m,short orig_target) { if((univ.town.monst[orig_target - 100].active > 0) && (monst_adjacent(univ.town.monst[orig_target - 100].cur_loc,which_m))) return orig_target; - for(i = 0; i < univ.town->max_monst(); i++) + for(i = 0; i < univ.town.monst.size(); i++) if((univ.town.monst[i].active > 0) && (univ.town.monst[i].attitude % 2 == 1) && (monst_adjacent(univ.town.monst[i].cur_loc,which_m))) @@ -545,7 +545,7 @@ short switch_target_to_adjacent(short which_m,short orig_target) { return i; // Check for a nice, adjacent, friendly monster and maybe attack - for(i = 0; i < univ.town->max_monst(); i++) + for(i = 0; i < univ.town.monst.size(); i++) if((univ.town.monst[i].active > 0) && (univ.town.monst[i].attitude % 2 == 0) && (monst_adjacent(univ.town.monst[i].cur_loc,which_m)) && @@ -1086,7 +1086,7 @@ void forced_place_monster(mon_num_t which,location where) { bool free_spot = false; short i = 0,r1; - while(!free_spot && (i < univ.town->max_monst())) { + while(!free_spot && (i < univ.town.monst.size())) { if(univ.town.monst[i].active == 0) free_spot = true; i++; @@ -1274,19 +1274,20 @@ void record_monst(cCreature *which_m) { } } -// returns 90 is no placement, OW returns # of spot +// returns size() is no placement, OW returns # of spot short place_monster(mon_num_t which,location where) { short i = 0; - while((i < univ.town->max_monst()) && ((univ.town.monst[i].active != 0) || - (univ.town.monst[i].spec_enc_code > 0))) { + while(i < univ.town.monst.size() && (univ.town.monst[i].active != 0 || univ.town.monst[i].spec_enc_code > 0)) { i++; } - if(i < univ.town->max_monst()) { + if(i < univ.town.monst.size()) { // 10000 or more means an exported summon saved with the party cMonster& monst = which >= 10000 ? univ.party.summons[which - 10000] : univ.scenario.scen_monsters[which]; univ.town.monst.assign(i, cCreature(which), monst, PSD[SDF_EASY_MODE], univ.difficulty_adjust()); + // TODO: Should this static_cast assignment be happening? + // One effect is resetting max health to ignore difficulty_adjust() static_cast(univ.town.monst[i]) = monst; univ.town.monst[i].attitude = monst.default_attitude; if(univ.town.monst[i].attitude % 2 == 0) @@ -1303,7 +1304,7 @@ short place_monster(mon_num_t which,location where) { return i; } - return 90; + return univ.town.monst.size(); } // returns true if placement was successful @@ -1332,7 +1333,7 @@ bool summon_monster(mon_num_t which,location where,short duration,short given_at } spot = place_monster(which,loc); - if(spot >= univ.town->max_monst()) { + if(spot >= univ.town.monst.size()) { if(duration < 100) add_string_to_buf(" Too many monsters."); //ASB(" Monster fails to summon monster."); @@ -1358,9 +1359,9 @@ void activate_monsters(short code,short /*attitude*/) { if(code == 0) return; - for(i = 0; i < univ.town->max_monst(); i++) - if(univ.town.monst[i].spec_enc_code == code) { - cTownperson& monst = univ.town->creatures(i); + for(i = 0; i < univ.town->creatures.size(); i++) + if(i < univ.town.monst.size() && univ.town.monst[i].spec_enc_code == code) { + cTownperson& monst = univ.town->creatures[i]; univ.town.monst.assign(i, monst, univ.scenario.scen_monsters[monst.number], PSD[SDF_EASY_MODE], univ.difficulty_adjust()); univ.town.monst[i].spec_enc_code = 0; univ.town.monst[i].active = 2; diff --git a/src/boe.newgraph.cpp b/src/boe.newgraph.cpp index 01909ad0..312f0ffd 100644 --- a/src/boe.newgraph.cpp +++ b/src/boe.newgraph.cpp @@ -248,7 +248,7 @@ void start_missile_anim() { } for(i = 0; i < 6; i++) univ.party[i].marked_damage = 0; - for(i = 0; i < univ.town->max_monst(); i++) + for(i = 0; i < univ.town.monst.size(); i++) univ.town.monst[i].marked_damage = 0; have_missile = false; have_boom = false; diff --git a/src/boe.party.cpp b/src/boe.party.cpp index e47fd625..81791dd3 100644 --- a/src/boe.party.cpp +++ b/src/boe.party.cpp @@ -1483,7 +1483,7 @@ void cast_town_spell(location where) { break; case eSpell::SCRY_MONSTER: case eSpell::CAPTURE_SOUL: targ = monst_there(where); - if(targ < univ.town->max_monst()) { + if(targ < univ.town.monst.size()) { if(town_spell == eSpell::SCRY_MONSTER) { univ.party.m_noted[univ.town.monst[targ].number] = true; adjust_monst_menu(); diff --git a/src/boe.specials.cpp b/src/boe.specials.cpp index b225a99d..76a32fd7 100644 --- a/src/boe.specials.cpp +++ b/src/boe.specials.cpp @@ -1670,7 +1670,7 @@ void push_things() { if(!belt_present) return; - for(i = 0; i < univ.town->max_monst(); i++) + for(i = 0; i < univ.town.monst.size(); i++) if(univ.town.monst[i].active > 0) { l = univ.town.monst[i].cur_loc; ter = univ.town->terrain(l.x,l.y); @@ -1928,7 +1928,7 @@ void run_special(eSpecCtx which_mode,short which_type,short start_spec,location case eSpecCtx::ATTACKED_RANGE: case eSpecCtx::ATTACKING_RANGE: // The monster/PC on the trigger space is the target current_pc_picked_in_spec_enc = 100 + monst_there(spec_loc); - if(current_pc_picked_in_spec_enc > univ.town->max_monst()) + if(current_pc_picked_in_spec_enc - 100 >= univ.town.monst.size()) current_pc_picked_in_spec_enc = pc_there(spec_loc); if(current_pc_picked_in_spec_enc == 6) current_pc_picked_in_spec_enc = -1; @@ -1936,7 +1936,7 @@ void run_special(eSpecCtx which_mode,short which_type,short start_spec,location case eSpecCtx::TARGET: case eSpecCtx::USE_SPACE: // If there's a monster on the space, select that as the target mon_num_t who = monst_there(spec_loc); - if(who < univ.town->max_monst()) + if(who < univ.town.monst.size()) current_pc_picked_in_spec_enc = 100 + who; break; } @@ -2296,7 +2296,7 @@ void general_spec(eSpecCtx which_mode,cSpecial cur_node,short cur_spec_type, print_nums(spec.ex1a, spec.ex1b, spec.ex1c); break; case 2: // Print monster health and spell points - if(spec.ex1a >= univ.town->max_monst()) break; + if(spec.ex1a >= univ.town.monst.size()) break; print_nums(spec.ex1a, univ.town.monst[spec.ex1a].health, univ.town.monst[spec.ex1a].mp); break; } @@ -3759,12 +3759,12 @@ void townmode_spec(eSpecCtx which_mode,cSpecial cur_node,short cur_spec_type, *redraw = 1; break; case eSpecType::TOWN_DESTROY_MONST: - if(spec.ex1a >= 0 && spec.ex1b >= 0 && (i = monst_there(l))) + if(spec.ex1a >= 0 && spec.ex1b >= 0 && ((i = monst_there(l)) < univ.town.monst.size())) univ.town.monst[i].active = 0; *redraw = 1; break; case eSpecType::TOWN_NUKE_MONSTS: - for(i = 0; i < univ.town->max_monst(); i++) + for(i = 0; i < univ.town.monst.size(); i++) if(univ.town.monst[i].active > 0 && (univ.town.monst[i].number == spec.ex1a || spec.ex1a == 0 || (spec.ex1a == -1 && univ.town.monst[i].attitude % 2 == 0) || @@ -4062,13 +4062,13 @@ void townmode_spec(eSpecCtx which_mode,cSpecial cur_node,short cur_spec_type, i = combat_posing_monster; if(l.y >= 0) { int monst = monst_there(l); - if(monst < 90) + if(monst < univ.town.monst.size()) combat_posing_monster = 100 + monst; else combat_posing_monster = pc_there(l); if(combat_posing_monster == 6) combat_posing_monster = -1; } else combat_posing_monster = spec.ex1a; - if(combat_posing_monster < 0 || combat_posing_monster >= univ.town->max_monst()) { + if(combat_posing_monster < 0 || combat_posing_monster - 100 >= univ.town.monst.size()) { combat_posing_monster = i; break; } diff --git a/src/boe.text.cpp b/src/boe.text.cpp index 833133e0..87e8b933 100644 --- a/src/boe.text.cpp +++ b/src/boe.text.cpp @@ -637,7 +637,7 @@ short do_look(location space) { } if((overall_mode == MODE_LOOK_TOWN) || (overall_mode == MODE_LOOK_COMBAT)) { - for(i = 0; i < univ.town->max_monst(); i++) + for(i = 0; i < univ.town.monst.size(); i++) if((univ.town.monst[i].active != 0) && (is_lit) && (monst_on_space(space,i)) && ((overall_mode == MODE_LOOK_TOWN) || (can_see_light(univ.party[current_pc].combat_pos,space,sight_obscurity) < 5)) diff --git a/src/boe.town.cpp b/src/boe.town.cpp index b68b8051..6b6b3438 100644 --- a/src/boe.town.cpp +++ b/src/boe.town.cpp @@ -186,12 +186,12 @@ void start_town_mode(short which_town, short entry_dir) { univ.town.monst = univ.party.creature_save[i]; monsters_loaded = true; - for(j = 0; j < univ.town->max_monst(); j++) { + for(j = 0; j < univ.town.monst.size(); j++) { if(loc_off_act_area(univ.town.monst[j].cur_loc)) univ.town.monst[j].active = 0; if(univ.town.monst[j].active == 2) univ.town.monst[j].active = 1; - univ.town.monst[j].cur_loc = univ.town->creatures(j).start_loc; + univ.town.monst[j].cur_loc = univ.town.monst[j].start_loc; univ.town.monst[j].health = univ.town.monst[j].m_health; univ.town.monst[j].mp = univ.town.monst[j].max_mp; univ.town.monst[j].morale = univ.town.monst[j].m_morale; @@ -203,7 +203,7 @@ void start_town_mode(short which_town, short entry_dir) { // Now, travelling NPCs might have arrived. Go through and put them in. // These should have protected status (i.e. spec1 >= 200, spec1 <= 204) - for(j = 0; j < univ.town->max_monst(); j++) { + for(j = 0; j < univ.town.monst.size(); j++) { switch(univ.town.monst[j].time_flag){ case eMonstTime::SOMETIMES_A: case eMonstTime::SOMETIMES_B: case eMonstTime::SOMETIMES_C: if((calc_day() % 3) + 3 != int(univ.town.monst[i].time_flag)) @@ -211,7 +211,7 @@ void start_town_mode(short which_town, short entry_dir) { else { univ.town.monst[j].active = 1; univ.town.monst[j].spec_enc_code = 0; - univ.town.monst[j].cur_loc = univ.town->creatures(j).start_loc; + univ.town.monst[j].cur_loc = univ.town.monst[j].start_loc; univ.town.monst[j].health = univ.town.monst[j].m_health; } break ; @@ -255,8 +255,9 @@ void start_town_mode(short which_town, short entry_dir) { } if(!monsters_loaded) { - for(i = 0; i < univ.town->max_monst(); i++){ - if(univ.town->creatures(i).number == 0) { + for(i = 0; i < univ.town->creatures.size(); i++){ + if(i >= univ.town.monst.size()) break; + if(univ.town->creatures[i].number == 0) { univ.town.monst[i].active = 0; univ.town.monst[i].number = 0; univ.town.monst[i].time_flag = eMonstTime::ALWAYS; @@ -264,7 +265,7 @@ void start_town_mode(short which_town, short entry_dir) { } else { // First set up the values. - cTownperson& preset = univ.town->creatures(i); + cTownperson& preset = univ.town->creatures[i]; univ.town.monst.assign(i, preset, univ.scenario.scen_monsters[preset.number], PSD[SDF_EASY_MODE], univ.difficulty_adjust()); if(univ.town.monst[i].spec_enc_code > 0) @@ -315,7 +316,7 @@ void start_town_mode(short which_town, short entry_dir) { // Now munch all large monsters that are misplaced // only large monsters, as some smaller monsters are intentionally placed // where they cannot be - for(i = 0; i < univ.town->max_monst(); i++) { + for(i = 0; i < univ.town.monst.size(); i++) { if(univ.town.monst[i].active > 0) if(((univ.town.monst[i].x_width > 1) || (univ.town.monst[i].y_width > 1)) && !monst_can_be_there(univ.town.monst[i].cur_loc,i)) @@ -331,7 +332,7 @@ void start_town_mode(short which_town, short entry_dir) { if(univ.town->town_chop_time > 0) { if(day_reached(univ.town->town_chop_time,univ.town->town_chop_key)) { add_string_to_buf("Area has been abandoned."); - for(i = 0; i < univ.town->max_monst(); i++) + for(i = 0; i < univ.town.monst.size(); i++) if((univ.town.monst[i].active > 0) && (univ.town.monst[i].active < 10) && (univ.town.monst[i].attitude % 2 == 1)) univ.town.monst[i].active += 10; @@ -339,7 +340,7 @@ void start_town_mode(short which_town, short entry_dir) { } } if(town_toast) { - for(i = 0; i < univ.town->max_monst(); i++) + for(i = 0; i < univ.town.monst.size(); i++) if(univ.town.monst[i].active >= 10) univ.town.monst[i].active -= 10; else univ.town.monst[i].active = 0; @@ -348,9 +349,9 @@ void start_town_mode(short which_town, short entry_dir) { // TODO: Flush the special node queue on scenario start so that the special actually gets called. // Flush excess doomguards and viscous goos - for(i = 0; i < univ.town->max_monst(); i++) + for(i = 0; i < univ.town.monst.size(); i++) if((univ.town.monst[i].abil[eMonstAbil::SPLITS].active) && - (univ.town.monst[i].number != univ.town->creatures(i).number)) + (i >= univ.town->creatures.size() || univ.town.monst[i].number != univ.town->creatures[i].number)) univ.town.monst[i].active = 0; // Set up field booleans, correct for doors @@ -379,7 +380,7 @@ void start_town_mode(short which_town, short entry_dir) { univ.town.items[i] = univ.party.stored_items[j][i]; } - for(i = 0; i < 64; i++) + for(i = 0; i < univ.town->preset_items.size(); i++) if((univ.town->preset_items[i].code >= 0) && (((univ.party.item_taken[univ.town.num][i / 8] & s_pow(2,i % 8)) == 0) || (univ.town->preset_items[i].always_there))) { @@ -421,7 +422,7 @@ void start_town_mode(short which_town, short entry_dir) { } - for(i = 0; i < univ.town->max_monst(); i++) + for(i = 0; i < univ.town.monst.size(); i++) if(loc_off_act_area(univ.town.monst[i].cur_loc)) univ.town.monst[i].active = 0; for(i = 0; i < NUM_TOWN_ITEMS; i++) @@ -429,7 +430,7 @@ void start_town_mode(short which_town, short entry_dir) { univ.town.items[i].variety = eItemType::NO_ITEM; // Clean out unwanted monsters - for(i = 0; i < univ.town->max_monst(); i++) + for(i = 0; i < univ.town.monst.size(); i++) if(sd_legit(univ.town.monst[i].spec1,univ.town.monst[i].spec2)) { if(PSD[univ.town.monst[i].spec1][univ.town.monst[i].spec2] > 0) univ.town.monst[i].active = 0; @@ -484,7 +485,7 @@ void start_town_mode(short which_town, short entry_dir) { } } - for(i = 0; i < univ.town->max_monst(); i++) { + for(i = 0; i < univ.town.monst.size(); i++) { univ.town.monst[i].targ_loc.x = 0; univ.town.monst[i].targ_loc.y = 0; } @@ -555,7 +556,8 @@ location end_town_mode(short switching_level,location destination) { // returns // Clean up special data, just in case - for(i = 0; i < univ.town->max_monst(); i++) { + // TODO: But... this is the life SDF! Why is it set to (0,0)? + for(i = 0; i < univ.town.monst.size(); i++) { univ.town.monst[i].spec1 = 0; univ.town.monst[i].spec2 = 0; } @@ -690,11 +692,11 @@ void start_town_combat(short direction) { overall_mode = MODE_COMBAT; combat_active_pc = 6; - for(i = 0; i < univ.town->max_monst(); i++) + for(i = 0; i < univ.town.monst.size(); i++) univ.town.monst[i].target = 6; for(i = 0; i < 6; i++) { - univ.party[i].last_attacked = univ.town->max_monst() + 10; + univ.party[i].last_attacked = univ.town.monst.size() + 10; univ.party[i].parry = 0; univ.party[i].dir = direction; univ.party[current_pc].direction = direction; @@ -1014,7 +1016,7 @@ void elim_monst(unsigned short which,short spec_a,short spec_b) { if(!sd_legit(spec_a,spec_b)) return; if(PSD[spec_a][spec_b] > 0) { - for(i = 0; i < univ.town->max_monst(); i++) + for(i = 0; i < univ.town.monst.size(); i++) if(univ.town.monst[i].number == which) { univ.town.monst[i].active = 0; } @@ -1431,7 +1433,7 @@ void draw_map(bool need_refresh) { // Now place PCs and monsters if(draw_pcs) { if((is_town()) && (univ.party.status[ePartyStatus::DETECT_LIFE] > 0)) - for(i = 0; i < univ.town->max_monst(); i++) + for(i = 0; i < univ.town.monst.size(); i++) if(univ.town.monst[i].active > 0) { where = univ.town.monst[i].cur_loc; if((is_explored(where.x,where.y)) && diff --git a/src/classes/creatlist.h b/src/classes/creatlist.h index 4d9b6dd6..d597edf1 100644 --- a/src/classes/creatlist.h +++ b/src/classes/creatlist.h @@ -36,6 +36,7 @@ public: void append(legacy::creature_list_type old); void assign(size_t n, const cTownperson& other, const cMonster& base, bool easy, int difficulty_adjust); + size_t size() {return 60;} cCreature& operator[](size_t n); const cCreature& operator[](size_t n) const; cPopulation() : which_town(200) {} diff --git a/src/classes/monster.cpp b/src/classes/monster.cpp index ee3b8aa6..088e20ff 100644 --- a/src/classes/monster.cpp +++ b/src/classes/monster.cpp @@ -398,6 +398,27 @@ cCreature::cCreature(int num) : cCreature() { number = num; } +cTownperson::cTownperson() { + start_loc = {80,80}; + number = 0; + mobility = 1; + time_flag = eMonstTime::ALWAYS; + spec1 = -1; + spec2 = -1; + spec_enc_code = 0; + time_code = 0; + monster_time = 0; + personality = -1; + special_on_kill = -1; +} + +cTownperson::cTownperson(location loc, mon_num_t num, const cMonster& monst) : cTownperson() { + start_loc = loc; + number = num; + start_attitude = monst.default_attitude; + facial_pic = monst.default_facial_pic; +} + void cTownperson::append(legacy::creature_start_type old){ number = old.number; start_attitude = old.start_attitude; diff --git a/src/classes/monster.h b/src/classes/monster.h index 80e0144d..28d04a2d 100644 --- a/src/classes/monster.h +++ b/src/classes/monster.h @@ -177,6 +177,8 @@ public: pic_num_t facial_pic; void append(legacy::creature_start_type old); + cTownperson(); + cTownperson(location loc, mon_num_t num, const cMonster& monst); }; class cCreature : public cMonster, public cTownperson { diff --git a/src/classes/regtown.cpp b/src/classes/regtown.cpp index c98a9f11..d94fb36f 100644 --- a/src/classes/regtown.cpp +++ b/src/classes/regtown.cpp @@ -75,8 +75,9 @@ void cTinyTown::append(legacy::tiny_tr_type& old, int town_num){ room_rect[i].bottom = old.room_rect[i].bottom; room_rect[i].right = old.room_rect[i].right; } + creatures.resize(30); for(i = 0; i < 30; i++) { - _creatures[i].append(old.creatures[i]); + creatures[i].append(old.creatures[i]); } } @@ -139,8 +140,9 @@ void cMedTown::append(legacy::ave_tr_type& old, int town_num){ room_rect[i].bottom = old.room_rect[i].bottom; room_rect[i].right = old.room_rect[i].right; } + creatures.resize(40); for(i = 0; i < 40; i++) { - _creatures[i].append(old.creatures[i]); + creatures[i].append(old.creatures[i]); } } @@ -203,8 +205,9 @@ void cBigTown::append(legacy::big_tr_type& old, int town_numo){ room_rect[i].bottom = old.room_rect[i].bottom; room_rect[i].right = old.room_rect[i].right; } + creatures.resize(60); for(i = 0; i < 60; i++) { - _creatures[i].append(old.creatures[i]); + creatures[i].append(old.creatures[i]); } } @@ -220,10 +223,6 @@ void cTinyTown::readTerrainFrom(std::istream& file) { readArray(file, _terrain, 32, 32); } -cTownperson& cTinyTown::creatures(size_t i){ - return _creatures[i]; -} - unsigned char& cTinyTown::lighting(size_t i, size_t r){ return _lighting[i][r]; } @@ -240,10 +239,6 @@ void cMedTown::readTerrainFrom(std::istream& file) { readArray(file, _terrain, 48, 48); } -cTownperson& cMedTown::creatures(size_t i){ - return _creatures[i]; -} - unsigned char& cMedTown::lighting(size_t i, size_t r){ return _lighting[i][r]; } @@ -260,10 +255,6 @@ void cBigTown::readTerrainFrom(std::istream& file) { readArray(file, _terrain, 64, 64); } -cTownperson& cBigTown::creatures(size_t i){ - return _creatures[i]; -} - unsigned char& cBigTown::lighting(size_t i, size_t r){ return _lighting[i][r]; } @@ -309,27 +300,3 @@ size_t cMedTown::max_dim() const { size_t cTinyTown::max_dim() const { return 32; } - -size_t cBigTown::max_monst() const { - return 60; -} - -size_t cMedTown::max_monst() const { - return 40; -} - -size_t cTinyTown::max_monst() const { - return 30; -} - -size_t cBigTown::max_items() const { - return 64; -} - -size_t cMedTown::max_items() const { - return 64; -} - -size_t cTinyTown::max_items() const { - return 64; -} diff --git a/src/classes/regtown.h b/src/classes/regtown.h index 4c92bfaa..70e178b5 100644 --- a/src/classes/regtown.h +++ b/src/classes/regtown.h @@ -23,18 +23,13 @@ namespace legacy { }; class cBigTown : public cTown { // formerly big_tr_type -protected: ter_num_t _terrain[64][64]; - cTownperson _creatures[60]; unsigned char _lighting[8][64]; public: void append(legacy::big_tr_type& old, int town_num); ter_num_t& terrain(size_t x, size_t y); - cTownperson& creatures(size_t i); unsigned char& lighting(size_t i, size_t r); size_t max_dim() const; - size_t max_monst() const; - size_t max_items() const; explicit cBigTown(cScenario& scenario, bool init_strings = false); void writeTerrainTo(std::ostream& file); @@ -42,18 +37,13 @@ public: }; class cMedTown : public cTown { // formerly ave_tr_type -protected: ter_num_t _terrain[48][48]; - cTownperson _creatures[40]; unsigned char _lighting[6][48]; public: void append(legacy::ave_tr_type& old, int town_num); ter_num_t& terrain(size_t x, size_t y); - cTownperson& creatures(size_t i); unsigned char& lighting(size_t i, size_t r); size_t max_dim() const; - size_t max_monst() const; - size_t max_items() const; explicit cMedTown(cScenario& scenario, bool init_strings = false); void writeTerrainTo(std::ostream& file); @@ -61,18 +51,13 @@ public: }; class cTinyTown : public cTown { // formerly tiny_tr_type -protected: ter_num_t _terrain[32][32]; - cTownperson _creatures[30]; unsigned char _lighting[4][32]; public: void append(legacy::tiny_tr_type& old, int town_num); ter_num_t& terrain(size_t x, size_t y); - cTownperson& creatures(size_t i); unsigned char& lighting(size_t i, size_t r); size_t max_dim() const; - size_t max_monst() const; - size_t max_items() const; explicit cTinyTown(cScenario& scenario, bool init_strings = false); void writeTerrainTo(std::ostream& file); diff --git a/src/classes/tmpltown.cpp b/src/classes/tmpltown.cpp index a0aedf4c..18da76b2 100644 --- a/src/classes/tmpltown.cpp +++ b/src/classes/tmpltown.cpp @@ -14,7 +14,8 @@ #include "classes.h" ter_num_t& cBigTemplTown::terrain(size_t /*x*/, size_t /*y*/){ - return _terrain[0][0]; // TODO: will need to calculate the terrain somehow + static ter_num_t dummy; + return dummy; // TODO: will need to calculate the terrain somehow } void cBigTemplTown::writeTerrainTo(std::ostream& /*file*/) { @@ -25,10 +26,6 @@ void cBigTemplTown::readTerrainFrom(std::istream& /*file*/) { // TODO: Read in the terrain somehow } -cTownperson& cBigTemplTown::creatures(size_t i){ - return _creatures[i]; -} - unsigned char& cBigTemplTown::lighting(size_t i, size_t r){ return _lighting[i][r]; } @@ -37,10 +34,3 @@ size_t cBigTemplTown::max_dim() const { return 0; // not sure what they are yet. } -size_t cBigTemplTown::max_monst() const { - return 30; -} - -size_t cBigTemplTown::max_items() const { - return 64; -} diff --git a/src/classes/tmpltown.h b/src/classes/tmpltown.h index 27646271..11dafdcc 100644 --- a/src/classes/tmpltown.h +++ b/src/classes/tmpltown.h @@ -37,51 +37,33 @@ public: }; class cBigTemplTown : public cBigTown, cTemplTown { -private: - //cTownperson _creatures[60]; - //ter_num_t _terrain[64][64]; - //unsigned char _lighting[4][32]; + unsigned char _lighting[8][64]; public: ter_num_t& terrain(size_t x, size_t y); - cTownperson& creatures(size_t i); unsigned char& lighting(size_t i, size_t r); size_t max_dim() const; - size_t max_monst() const; - size_t max_items() const; void writeTerrainTo(std::ostream& file); void readTerrainFrom(std::istream& file); explicit cBigTemplTown(cScenario& scenario, bool init_strings = false); }; class cMedTemplTown : public cMedTown, cTemplTown { -private: - //cTownperson _creatures[40]; - //ter_num_t _terrain[48][48]; - //unsigned char _lighting[4][32]; + unsigned char _lighting[6][48]; public: ter_num_t& terrain(size_t x, size_t y); - cTownperson& creatures(size_t i); unsigned char& lighting(size_t i, size_t r); size_t max_dim() const; - size_t max_monst() const; - size_t max_items() const; void writeTerrainTo(std::ostream& file); void readTerrainFrom(std::istream& file); explicit cMedTemplTown(cScenario& scenario, bool init_strings = false); }; class cTinyTemplTown : public cTinyTown, cTemplTown { -private: - //cTownperson _creatures[30]; - //ter_num_t _terrain[32][32]; - //unsigned char _lighting[4][32]; + unsigned char _lighting[4][32]; public: ter_num_t& terrain(size_t x, size_t y); - cTownperson& creatures(size_t i); unsigned char& lighting(size_t i, size_t r); size_t max_dim() const; - size_t max_monst() const; - size_t max_items() const; void writeTerrainTo(std::ostream& file); void readTerrainFrom(std::istream& file); explicit cTinyTemplTown(cScenario& scenario, bool init_strings = false); diff --git a/src/classes/town.cpp b/src/classes/town.cpp index 505a4e62..624c95dd 100644 --- a/src/classes/town.cpp +++ b/src/classes/town.cpp @@ -53,6 +53,7 @@ void cTown::append(legacy::town_record_type& old){ in_town_rect.left = old.in_town_rect.left; in_town_rect.bottom = old.in_town_rect.bottom; in_town_rect.right = old.in_town_rect.right; + preset_items.resize(64); for(i = 0; i < 64; i++){ // preset_items[i].loc.x = old.preset_items[i].item_loc.x; // preset_items[i].loc.y = old.preset_items[i].item_loc.y; @@ -82,7 +83,6 @@ cTown::cTown(cScenario& scenario, bool init_strings) : scenario(scenario) { short i; location d_loc(100,0); cTown::cWandering d_wan = {0,0,0,0}; - cTown::cItem null_item = {loc(),-1,0,0,0,0,0}; town_chop_time = -1; town_chop_key = -1; @@ -101,8 +101,6 @@ cTown::cTown(cScenario& scenario, bool init_strings) : scenario(scenario) { exit_locs[i].x = -1; exit_locs[i].y = -1; } - for(i = 0; i < 64; i++) - preset_items[i] = null_item; max_num_monst = 30000; spec_on_entry = -1; spec_on_entry_if_dead = -1; @@ -266,6 +264,22 @@ short cTown::light_obscurity(short x,short y) { return 0; } +cTown::cItem::cItem() { + loc = {80,80}; + code = -1; + ability = -1; + always_there = false; + property = false; + contained = false; +} + +cTown::cItem::cItem(location loc, short num, ::cItem& item) : cItem() { + loc = loc; + code = num; + if(item.variety == eItemType::GOLD || item.variety == eItemType::FOOD) + ability = get_ran(1,4,6); +} + std::ostream& operator<< (std::ostream& out, eLighting light) { switch(light) { case LIGHT_NORMAL: out << "lit"; break; diff --git a/src/classes/town.h b/src/classes/town.h index 1da7d54d..b1647caf 100644 --- a/src/classes/town.h +++ b/src/classes/town.h @@ -57,6 +57,8 @@ public: bool always_there, property, contained; void append(legacy::preset_item_type old); + cItem(); + cItem(location loc, short num, ::cItem& item); }; class cField { // formerly preset_field_type public: @@ -77,7 +79,8 @@ public: location exit_locs[4]; short exit_specs[4]; rectangle in_town_rect; - std::array preset_items; + std::vector preset_items; + std::vector creatures; short max_num_monst; std::vector preset_fields; short spec_on_entry,spec_on_entry_if_dead; @@ -105,11 +108,8 @@ public: virtual void append(legacy::ave_tr_type& old, int town_num); virtual void append(legacy::tiny_tr_type& old, int town_num); virtual ter_num_t& terrain(size_t x, size_t y) = 0; - virtual cTownperson& creatures(size_t i) = 0; virtual unsigned char& lighting(size_t i, size_t r) = 0; virtual size_t max_dim() const = 0; - virtual size_t max_monst() const = 0; - virtual size_t max_items() const = 0; void init_start(); void set_up_lights(); short light_obscurity(short x,short y); // Obscurity function used for calculating lighting diff --git a/src/classes/universe.cpp b/src/classes/universe.cpp index 9f762d48..1af383c5 100644 --- a/src/classes/universe.cpp +++ b/src/classes/universe.cpp @@ -49,8 +49,9 @@ void cCurTown::append(legacy::big_tr_type& old){ record()->room_rect[i].bottom = old.room_rect[i].bottom; record()->room_rect[i].right = old.room_rect[i].right; } - for(i = 0; i < record()->max_monst(); i++) - record()->creatures(i).append(old.creatures[i]); + record()->creatures.resize(60); + for(i = 0; i < 60; i++) + record()->creatures[i].append(old.creatures[i]); for(i = 0; i < record()->max_dim() / 8; i++) for(j = 0; j < record()->max_dim(); j++) record()->lighting(i,j) = old.lighting[i][j]; @@ -1121,7 +1122,7 @@ short cUniverse::difficulty_adjust() const { short cCurTown::countMonsters(){ short to_ret = 0; - for(short i = 0; i < record()->max_monst(); i++) + for(short i = 0; i < monst.size(); i++) if(monst[i].active > 0) to_ret++; return to_ret; diff --git a/src/scenedit/scen.actions.cpp b/src/scenedit/scen.actions.cpp index 4fe93c41..fccb44b4 100644 --- a/src/scenedit/scen.actions.cpp +++ b/src/scenedit/scen.actions.cpp @@ -51,7 +51,7 @@ bool good_palette_buttons[2][6][10] = { {1,1,1,1,1,1,1,1,0,1} } }; -cTown::cItem store_place_item = {loc(),-1,0,0,0,0,0}; +cTown::cItem store_place_item; short flood_count = 0; @@ -549,30 +549,25 @@ bool handle_action(location the_point,sf::Event /*event*/) { mouse_button_held = true; break; case MODE_PLACE_ITEM: - for(x = 0; x < 64; x++) + for(x = 0; x < town->preset_items.size(); x++) if(town->preset_items[x].code < 0) { - town->preset_items[x].loc.x = spot_hit.x; - town->preset_items[x].loc.y = spot_hit.y; - town->preset_items[x].code = mode_count; - town->preset_items[x].ability = -1; - if((scenario.scen_items[mode_count].variety == eItemType::GOLD) || - (scenario.scen_items[mode_count].variety == eItemType::FOOD)) - town->preset_items[x].ability = get_ran(1,4,6); - town->preset_items[x].always_there = 0; - town->preset_items[x].property = 0; - town->preset_items[x].contained = container_there(town->preset_items[x].loc); + town->preset_items[x] = {spot_hit, mode_count, scenario.scen_items[mode_count]}; + if(container_there(spot_hit)) town->preset_items[x].contained = true; store_place_item = town->preset_items[x]; - x = 70; + break; } - if(x == 64) - giveError("You can only have 64 preset items in each town."); + if(x == town->preset_items.size()) { + town->preset_items.push_back({spot_hit, mode_count, scenario.scen_items[mode_count]}); + if(container_there(spot_hit)) town->preset_items.back().contained = true; + store_place_item = town->preset_items.back(); + } overall_mode = MODE_DRAWING; set_cursor(wand_curs); set_string("Drawing mode",(char*)scenario.ter_types[current_terrain_type].name.c_str()); break; case MODE_EDIT_ITEM: - for(x = 0; x < 64; x++) + for(x = 0; x < town->preset_items.size(); x++) if((spot_hit.x == town->preset_items[x].loc.x) && (spot_hit.y == town->preset_items[x].loc.y) && (town->preset_items[x].code >= 0)) { edit_placed_item(x); @@ -586,40 +581,29 @@ bool handle_action(location the_point,sf::Event /*event*/) { giveError("Either no monster has been placed, or the last time you tried to place a monster the operation failed."); break; } - for(i = 0; i < town->max_monst(); i++) - if(town->creatures(i).number == 0) { - town->creatures(i) = last_placed_monst; - town->creatures(i).start_loc = spot_hit; + for(i = 0; i < town->creatures.size(); i++) + if(town->creatures[i].number == 0) { + town->creatures[i] = last_placed_monst; + town->creatures[i].start_loc = spot_hit; break; } - if(i == town->max_monst()) { // Placement failed - giveError("The town only has room for " + std::to_string(town->max_monst()) + " preset monsters."); + if(i == town->creatures.size()) { // Placement failed + town->creatures.push_back(last_placed_monst); + town->creatures.back().start_loc = spot_hit; } overall_mode = MODE_DRAWING; set_cursor(wand_curs); break; case MODE_PLACE_CREATURE: - for(i = 0; i < 60; i++) - if(town->creatures(i).number == 0) { - town->creatures(i).start_loc = spot_hit; - town->creatures(i).number = mode_count; - town->creatures(i).start_attitude = - scenario.scen_monsters[mode_count].default_attitude; - town->creatures(i).mobility = 1; - town->creatures(i).time_flag = eMonstTime::ALWAYS; - town->creatures(i).spec1 = -1; - town->creatures(i).spec2 = -1; - town->creatures(i).spec_enc_code = 0; - town->creatures(i).time_code = 0; - town->creatures(i).monster_time = 0; - town->creatures(i).personality = -1; - town->creatures(i).special_on_kill = -1; - town->creatures(i).facial_pic = scenario.scen_monsters[mode_count].default_facial_pic; - last_placed_monst = town->creatures(i); + for(i = 0; i < town->creatures.size(); i++) + if(town->creatures[i].number == 0) { + town->creatures[i] = {spot_hit, mode_count, scenario.scen_monsters[mode_count]}; + last_placed_monst = town->creatures[i]; break; } - if(i == town->max_monst()) { // Placement failed - giveError("The town only has room for " + std::to_string(town->max_monst()) + " preset monsters."); + if(i == town->creatures.size()) { // Placement failed + town->creatures.push_back({spot_hit, mode_count, scenario.scen_monsters[mode_count]}); + last_placed_monst = town->creatures.back(); } overall_mode = MODE_DRAWING; set_cursor(wand_curs); @@ -695,15 +679,18 @@ bool handle_action(location the_point,sf::Event /*event*/) { giveError("Either no item has been placed, or the last time you tried to place an item the operation failed."); break; } - for(x = 0; x < 64; x++) + for(x = 0; x < town->preset_items.size(); x++) if(town->preset_items[x].code < 0) { town->preset_items[x] = store_place_item; - town->preset_items[x].loc.x = spot_hit.x; - town->preset_items[x].loc.y = spot_hit.y; - - town->preset_items[x].contained = container_there(town->preset_items[x].loc); - x = 64; + town->preset_items[x].loc = spot_hit; + town->preset_items[x].contained = container_there(spot_hit); + break; } + if(x == town->preset_items.size()) { + town->preset_items.push_back(store_place_item); + town->preset_items.back().loc = spot_hit; + town->preset_items.back().contained = container_there(spot_hit); + } set_cursor(wand_curs); overall_mode = MODE_DRAWING; break; @@ -732,10 +719,10 @@ bool handle_action(location the_point,sf::Event /*event*/) { overall_mode = MODE_DRAWING; break; case MODE_EDIT_CREATURE: //edit monst - for(x = 0; x < 60; x++) + for(x = 0; x < town->creatures.size(); x++) if(monst_on_space(spot_hit,x)) { edit_placed_monst(x); - last_placed_monst = town->creatures(x); + last_placed_monst = town->creatures[x]; } set_cursor(wand_curs); overall_mode = MODE_DRAWING; @@ -843,17 +830,23 @@ bool handle_action(location the_point,sf::Event /*event*/) { case MODE_ERASE_CREATURE: //delete monst for(x = 0; x < 60; x++) if(monst_on_space(spot_hit,x)) { - town->creatures(x).number = 0; + town->creatures[x].number = 0; + break; } + while(town->creatures.back().number == 0) + town->creatures.pop_back(); set_cursor(wand_curs); overall_mode = MODE_DRAWING; break; case MODE_ERASE_ITEM: // delete item - for(x = 0; x < 64; x++) + for(x = 0; x < town->preset_items.size(); x++) if((spot_hit.x == town->preset_items[x].loc.x) && (spot_hit.y == town->preset_items[x].loc.y) && (town->preset_items[x].code >= 0)) { town->preset_items[x].code = -1; + break; } + while(town->preset_items.back().code == -1) + town->preset_items.pop_back(); set_cursor(wand_curs); overall_mode = MODE_DRAWING; break; @@ -1361,7 +1354,7 @@ void handle_keystroke(sf::Event event) { handle_action(pass_point,event); break; case 'I': - for(i = 0; i < 64; i++) { + for(i = 0; i < town->preset_items.size(); i++) { if((town->preset_items[i].loc.x < 0) || (town->preset_items[i].loc.y < 0)) town->preset_items[i].code = -1; @@ -2708,22 +2701,15 @@ bool place_item(location spot_hit,short which_item,bool property,bool always,sho return true; if(get_ran(1,1,100) > odds) return false; - for(x = 0; x < 64; x++) + for(x = 0; x < town->preset_items.size(); x++) if(town->preset_items[x].code < 0) { - town->preset_items[x].loc.x = spot_hit.x; - town->preset_items[x].loc.y = spot_hit.y; - town->preset_items[x].code = which_item; - town->preset_items[x].ability = -1; - if((scenario.scen_items[which_item].variety == eItemType::GOLD) || - (scenario.scen_items[which_item].variety == eItemType::FOOD)) - town->preset_items[x].ability = get_ran(1,4,6); - - town->preset_items[x].always_there = always; - town->preset_items[x].property = property; - town->preset_items[x].contained = container_there(town->preset_items[x].loc); + town->preset_items[x] = {spot_hit, which_item, scenario.scen_items[which_item]}; + town->preset_items[x].contained = container_there(spot_hit); return true; } - return false; + town->preset_items.push_back({spot_hit, which_item, scenario.scen_items[which_item]}); + town->preset_items.back().contained = container_there(spot_hit); + return true; } void place_items_in_town() { @@ -3298,12 +3284,14 @@ ter_num_t coord_to_ter(short x,short y) { bool monst_on_space(location loc,short m_num) { if(!editing_town) return false; - if(town->creatures(m_num).number == 0) + if(m_num >= town->creatures.size()) return false; - if((loc.x - town->creatures(m_num).start_loc.x >= 0) && - (loc.x - town->creatures(m_num).start_loc.x <= scenario.scen_monsters[town->creatures(m_num).number].x_width - 1) && - (loc.y - town->creatures(m_num).start_loc.y >= 0) && - (loc.y - town->creatures(m_num).start_loc.y <= scenario.scen_monsters[town->creatures(m_num).number].y_width - 1)) + if(town->creatures[m_num].number == 0) + return false; + if((loc.x - town->creatures[m_num].start_loc.x >= 0) && + (loc.x - town->creatures[m_num].start_loc.x <= scenario.scen_monsters[town->creatures[m_num].number].x_width - 1) && + (loc.y - town->creatures[m_num].start_loc.y >= 0) && + (loc.y - town->creatures[m_num].start_loc.y <= scenario.scen_monsters[town->creatures[m_num].number].y_width - 1)) return true; return false; diff --git a/src/scenedit/scen.fileio.cpp b/src/scenedit/scen.fileio.cpp index 3eb75def..0e063b5f 100644 --- a/src/scenedit/scen.fileio.cpp +++ b/src/scenedit/scen.fileio.cpp @@ -608,10 +608,10 @@ void writeTownToXml(ticpp::Printer&& data, cTown& town) { data.PushElement("contained", true); data.CloseElement("item"); } - for(size_t i = 0; i < town.max_monst(); i++) { + for(size_t i = 0; i < town.creatures.size(); i++) { data.OpenElement("creature"); data.PushAttribute("id", i); - cTownperson& preset = town.creatures(i); + cTownperson& preset = town.creatures[i]; data.PushElement("type", preset.number); data.PushElement("attitude", preset.start_attitude); data.PushElement("mobility", preset.mobility); diff --git a/src/scenedit/scen.graphics.cpp b/src/scenedit/scen.graphics.cpp index 361d96a0..bd6e53b8 100644 --- a/src/scenedit/scen.graphics.cpp +++ b/src/scenedit/scen.graphics.cpp @@ -756,13 +756,13 @@ void draw_terrain(){ Draw_Some_Item(fields_gworld,from_rect,ter_draw_gworld,where_draw,sf::BlendAlpha); } } - for(x = 0; x < town->max_items(); x++) + for(x = 0; x < town->preset_items.size(); x++) if((cen_x + q - 4 == town->preset_items[x].loc.x) && (cen_y + r - 4 == town->preset_items[x].loc.y) && (town->preset_items[x].code >= 0)) { } - for(x = 0; x < town->max_monst(); x++) - if((cen_x + q - 4 == town->creatures(x).start_loc.x) && - (cen_y + r - 4 == town->creatures(x).start_loc.y) && (town->creatures(x).number != 0)) { + for(x = 0; x < town->creatures.size(); x++) + if((cen_x + q - 4 == town->creatures[x].start_loc.x) && + (cen_y + r - 4 == town->creatures[x].start_loc.y) && (town->creatures[x].number != 0)) { } } @@ -844,25 +844,25 @@ void draw_monsts() { rectangle source_rect; location where_draw,store_loc; - for(i = 0; i < town->max_monst(); i++) - if(town->creatures(i).number != 0) { - where_draw.x = town->creatures(i).start_loc.x - cen_x + 4; - where_draw.y = town->creatures(i).start_loc.y - cen_y + 4; - width = scenario.scen_monsters[town->creatures(i).number].x_width; - height = scenario.scen_monsters[town->creatures(i).number].y_width; + for(i = 0; i < town->creatures.size(); i++) + if(town->creatures[i].number != 0) { + where_draw.x = town->creatures[i].start_loc.x - cen_x + 4; + where_draw.y = town->creatures[i].start_loc.y - cen_y + 4; + width = scenario.scen_monsters[town->creatures[i].number].x_width; + height = scenario.scen_monsters[town->creatures[i].number].y_width; for(k = 0; k < width * height; k++) { store_loc = where_draw; if((where_draw.x == minmax(0,8,where_draw.x)) && (where_draw.y == minmax(0,8,where_draw.y)) && - (scenario.scen_monsters[town->creatures(i).number].picture_num >= 1000)) { - graf_pos_ref(from_gworld, source_rect) = spec_scen_g.find_graphic((scenario.scen_monsters[town->creatures(i).number].picture_num + k) % 1000); + (scenario.scen_monsters[town->creatures[i].number].picture_num >= 1000)) { + graf_pos_ref(from_gworld, source_rect) = spec_scen_g.find_graphic((scenario.scen_monsters[town->creatures[i].number].picture_num + k) % 1000); store_loc.x += k % width; store_loc.y += k / width; Draw_Some_Item(*from_gworld, source_rect, ter_draw_gworld, store_loc, sf::BlendAlpha); } - else if(scenario.scen_monsters[town->creatures(i).number].picture_num < 1000) { - m_start_pic = m_pic_index[scenario.scen_monsters[town->creatures(i).number].picture_num].i + k; + else if(scenario.scen_monsters[town->creatures[i].number].picture_num < 1000) { + m_start_pic = m_pic_index[scenario.scen_monsters[town->creatures[i].number].picture_num].i + k; from_gworld = &monst_gworld[m_start_pic / 20]; m_start_pic = m_start_pic % 20; source_rect = calc_rect(2 * (m_start_pic / 10), m_start_pic % 10); @@ -902,7 +902,7 @@ void draw_items() { location where_draw; short pic_num; - for(i = 0; i < town->max_items(); i++) { + for(i = 0; i < town->preset_items.size(); i++) { if(town->preset_items[i].code >= 0) { where_draw.x = town->preset_items[i].loc.x - cen_x + 4; where_draw.y = town->preset_items[i].loc.y - cen_y + 4; @@ -1287,7 +1287,6 @@ void make_field_type(short i,short j,eFieldType field_type) { town->preset_fields[k].type = field_type; return; } - //give_error("Each town can have at most 50 fields and special effects (webs, barrels, blood stains, etc.). To place more, use the eraser first.","",0); cTown::cField the_field; the_field.loc.x = i; the_field.loc.y = j; diff --git a/src/scenedit/scen.main.cpp b/src/scenedit/scen.main.cpp index ef04b17c..df455a69 100644 --- a/src/scenedit/scen.main.cpp +++ b/src/scenedit/scen.main.cpp @@ -376,7 +376,7 @@ void handle_menu_choice(eMenu item_hit) { change_made = true; break; case eMenu::TOWN_ITEMS_NOT_PROPERTY: - for(int i = 0; i < 64; i++) + for(int i = 0; i < town->preset_items.size(); i++) town->preset_items[i].property = 0; cChoiceDlog("set-not-owned").show(); draw_terrain(); @@ -385,8 +385,7 @@ void handle_menu_choice(eMenu item_hit) { case eMenu::TOWN_ITEMS_CLEAR: if(cChoiceDlog("clear-items-confirm", {"okay", "cancel"}).show() == "cancel") break; - for(int i = 0; i < 64; i++) - town->preset_items[i].code = -1; + town->preset_items.clear(); draw_terrain(); change_made = true; break; diff --git a/src/scenedit/scen.townout.cpp b/src/scenedit/scen.townout.cpp index 85eec79b..1b34a417 100644 --- a/src/scenedit/scen.townout.cpp +++ b/src/scenedit/scen.townout.cpp @@ -61,7 +61,7 @@ static bool get_placed_monst_in_dlog(cDialog& me) { store_placed_monst.personality = me["talk"].getTextAsNum(); store_placed_monst.facial_pic = me["picnum"].getTextAsNum(); // later - town->creatures(store_which_placed_monst) = store_placed_monst; + town->creatures[store_which_placed_monst] = store_placed_monst; return true; } @@ -99,7 +99,7 @@ static bool edit_placed_monst_event_filter(cDialog& me, std::string item_hit, eK } void edit_placed_monst(short which_m) { - store_placed_monst = town->creatures(which_m); + store_placed_monst = town->creatures[which_m]; store_which_placed_monst = which_m; cDialog edit("edit-townperson");