Make monster/item lists in scenario town record dynamic; move monsters to town superclass
This commit is contained in:
@@ -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;
|
||||
|
||||
|
@@ -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);
|
||||
|
@@ -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;
|
||||
|
@@ -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;
|
||||
|
@@ -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");
|
||||
|
Reference in New Issue
Block a user