Store rect descriptions together with their rectangle and remove now-unused string-length members

This commit is contained in:
2015-01-22 15:19:26 -05:00
parent 3e0e3d3b8a
commit 952d81ae5a
18 changed files with 58 additions and 112 deletions

View File

@@ -667,7 +667,7 @@ void draw_text_bar() {
if(is_out()) {
for(i = 0; i < 8; i++)
if(loc.in(univ.out->info_rect[i])) {
put_text_bar(univ.out->rect_names[i]);
put_text_bar(univ.out->info_rect[i].descr);
in_area = true;
}
if(!in_area) {
@@ -676,8 +676,8 @@ void draw_text_bar() {
}
if(is_town()) {
for(i = 0; i < 16; i++)
if(loc.in(univ.town->room_rect(i))) {
put_text_bar(univ.town->rect_names[i]);
if(loc.in(univ.town->room_rect[i])) {
put_text_bar(univ.town->room_rect[i].descr);
in_area = true;
}
if(!in_area) {

View File

@@ -3777,10 +3777,10 @@ void townmode_spec(eSpecCtx which_mode,cSpecial cur_node,short cur_spec_type,
break;
case eSpecType::TOWN_NUKE_MONSTS:
for(i = 0; i < univ.town->max_monst(); i++)
if((univ.town.monst[i].active > 0) &&
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) ||
(spec.ex1a == -2 && univ.town.monst[i].attitude % 2 == 1)){
(spec.ex1a == -2 && univ.town.monst[i].attitude % 2 == 1))) {
univ.town.monst[i].active = 0;
}
*redraw = 1;

View File

@@ -10,6 +10,7 @@
#define BOE_LOCATION_H
#include <SFML/Graphics.hpp>
#include <string>
struct rectangle;
@@ -75,6 +76,10 @@ struct rectangle {
}
};
struct info_rect_t : public rectangle {
std::string descr;
};
bool operator == (location p1,location p2);
bool operator != (location p1,location p2);
bool operator == (rectangle r1, rectangle r2);

View File

@@ -134,8 +134,6 @@ void cOutdoors::append(legacy::outdoor_record_type& old){
wandering_locs[i].x = old.wandering_locs[i].x;
wandering_locs[i].y = old.wandering_locs[i].y;
}
for(i = 0; i < 180; i++)
strlens[i] = old.strlens[i];
for(i = 0; i < 60; i++)
specials[i].append(old.specials[i]);
}
@@ -172,12 +170,11 @@ cOutdoors::cOutdoors(cScenario& scenario, bool init_strings) : scenario(scenario
temp_str = get_str("outdoor-default",i + 1);
if(i == 0) out_name = temp_str;
else if(i == 9) comment = temp_str;
else if(i < 9) rect_names[i-1] = temp_str;
else if(i < 9) info_rect[i-1].descr = temp_str;
else if(i >= 10 && i < 100)
spec_strs[i-10] = temp_str;
else if(i >= 100 && i < 108)
sign_strs[i-100] = temp_str;
strlens[i] = temp_str.length();
}
}

View File

@@ -67,13 +67,11 @@ public:
location sign_locs[8];
cWandering wandering[4],special_enc[4];
location wandering_locs[4];
rectangle info_rect[8];
unsigned char strlens[180];
std::array<cSpecial,60> specials;
std::string out_name;
// Using std::array here so we can have .size()
// This'll make the transition smoother once it becomes a vector.
std::array<std::string,8> rect_names;
std::array<info_rect_t,8> info_rect;
std::string comment;
std::array<std::string,90> spec_strs;
std::array<std::string,8> sign_strs;

View File

@@ -70,10 +70,10 @@ void cTinyTown::append(legacy::tiny_tr_type& old, int town_num){
}
}
for(i = 0; i < 16; i++) {
_room_rect[i].top = old.room_rect[i].top;
_room_rect[i].left = old.room_rect[i].left;
_room_rect[i].bottom = old.room_rect[i].bottom;
_room_rect[i].right = old.room_rect[i].right;
room_rect[i].top = old.room_rect[i].top;
room_rect[i].left = old.room_rect[i].left;
room_rect[i].bottom = old.room_rect[i].bottom;
room_rect[i].right = old.room_rect[i].right;
}
for(i = 0; i < 30; i++) {
_creatures[i].append(old.creatures[i]);
@@ -134,10 +134,10 @@ void cMedTown::append(legacy::ave_tr_type& old, int town_num){
}
}
for(i = 0; i < 16; i++) {
_room_rect[i].top = old.room_rect[i].top;
_room_rect[i].left = old.room_rect[i].left;
_room_rect[i].bottom = old.room_rect[i].bottom;
_room_rect[i].right = old.room_rect[i].right;
room_rect[i].top = old.room_rect[i].top;
room_rect[i].left = old.room_rect[i].left;
room_rect[i].bottom = old.room_rect[i].bottom;
room_rect[i].right = old.room_rect[i].right;
}
for(i = 0; i < 40; i++) {
_creatures[i].append(old.creatures[i]);
@@ -198,10 +198,10 @@ void cBigTown::append(legacy::big_tr_type& old, int town_numo){
}
}
for(i = 0; i < 16; i++) {
_room_rect[i].top = old.room_rect[i].top;
_room_rect[i].left = old.room_rect[i].left;
_room_rect[i].bottom = old.room_rect[i].bottom;
_room_rect[i].right = old.room_rect[i].right;
room_rect[i].top = old.room_rect[i].top;
room_rect[i].left = old.room_rect[i].left;
room_rect[i].bottom = old.room_rect[i].bottom;
room_rect[i].right = old.room_rect[i].right;
}
for(i = 0; i < 60; i++) {
_creatures[i].append(old.creatures[i]);
@@ -220,10 +220,6 @@ void cTinyTown::readTerrainFrom(std::istream& file) {
readArray(file, _terrain, 32, 32);
}
rectangle& cTinyTown::room_rect(size_t i){
return _room_rect[i];
}
cCreature& cTinyTown::creatures(size_t i){
return _creatures[i];
}
@@ -244,10 +240,6 @@ void cMedTown::readTerrainFrom(std::istream& file) {
readArray(file, _terrain, 48, 48);
}
rectangle& cMedTown::room_rect(size_t i){
return _room_rect[i];
}
cCreature& cMedTown::creatures(size_t i){
return _creatures[i];
}
@@ -268,10 +260,6 @@ void cBigTown::readTerrainFrom(std::istream& file) {
readArray(file, _terrain, 64, 64);
}
rectangle& cBigTown::room_rect(size_t i){
return _room_rect[i];
}
cCreature& cBigTown::creatures(size_t i){
return _creatures[i];
}
@@ -282,13 +270,6 @@ unsigned char& cBigTown::lighting(size_t i, size_t r){
cBigTown::cBigTown(cScenario& scenario, bool init_strings) : cTown(scenario, init_strings) {
int i;
rectangle d_rect = {0,0,0,0};
for(i = 0; i < 16; i++) {
_room_rect[i].top = d_rect.top;
_room_rect[i].left = d_rect.left;
_room_rect[i].bottom = d_rect.bottom;
_room_rect[i].right = d_rect.right;
}
for(i = 0; i < max_dim(); i++)
for(int j = 0; j < max_dim(); j++) {
terrain(i,j) = scenario.default_ground * 2;
@@ -299,13 +280,6 @@ cBigTown::cBigTown(cScenario& scenario, bool init_strings) : cTown(scenario, ini
cMedTown::cMedTown(cScenario& scenario, bool init_strings) : cTown(scenario, init_strings) {
int i;
rectangle d_rect = {0,0,0,0};
for(i = 0; i < 16; i++) {
_room_rect[i].top = d_rect.top;
_room_rect[i].left = d_rect.left;
_room_rect[i].bottom = d_rect.bottom;
_room_rect[i].right = d_rect.right;
}
for(i = 0; i < max_dim(); i++)
for(int j = 0; j < max_dim(); j++) {
terrain(i,j) = scenario.default_ground * 2;
@@ -316,13 +290,6 @@ cMedTown::cMedTown(cScenario& scenario, bool init_strings) : cTown(scenario, ini
cTinyTown::cTinyTown(cScenario& scenario, bool init_strings) : cTown(scenario, init_strings) {
int i;
rectangle d_rect = {0,0,0,0};
for(i = 0; i < 16; i++) {
_room_rect[i].top = d_rect.top;
_room_rect[i].left = d_rect.left;
_room_rect[i].bottom = d_rect.bottom;
_room_rect[i].right = d_rect.right;
}
for(i = 0; i < max_dim(); i++)
for(int j = 0; j < max_dim(); j++) {
terrain(i,j) = scenario.default_ground * 2;

View File

@@ -25,13 +25,11 @@ namespace legacy {
class cBigTown : public cTown { // formerly big_tr_type
protected:
ter_num_t _terrain[64][64];
rectangle _room_rect[16];
cCreature _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);
rectangle& room_rect(size_t i);
cCreature& creatures(size_t i);
unsigned char& lighting(size_t i, size_t r);
short max_dim() const;
@@ -46,13 +44,11 @@ public:
class cMedTown : public cTown { // formerly ave_tr_type
protected:
ter_num_t _terrain[48][48];
rectangle _room_rect[16];
cCreature _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);
rectangle& room_rect(size_t i);
cCreature& creatures(size_t i);
unsigned char& lighting(size_t i, size_t r);
short max_dim() const;
@@ -67,13 +63,11 @@ public:
class cTinyTown : public cTown { // formerly tiny_tr_type
protected:
ter_num_t _terrain[32][32];
rectangle _room_rect[16];
cCreature _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);
rectangle& room_rect(size_t i);
cCreature& creatures(size_t i);
unsigned char& lighting(size_t i, size_t r);
short max_dim() const;

View File

@@ -25,10 +25,6 @@ void cBigTemplTown::readTerrainFrom(std::istream& /*file*/) {
// TODO: Read in the terrain somehow
}
rectangle& cBigTemplTown::room_rect(size_t i){
return _room_rect[i];
}
cCreature& cBigTemplTown::creatures(size_t i){
return _creatures[i];
}

View File

@@ -40,11 +40,9 @@ class cBigTemplTown : public cBigTown, cTemplTown {
private:
//cCreature _creatures[60];
//ter_num_t _terrain[64][64];
//rectangle _room_rect[16];
//unsigned char _lighting[4][32];
public:
ter_num_t& terrain(size_t x, size_t y);
rectangle& room_rect(size_t i);
cCreature& creatures(size_t i);
unsigned char& lighting(size_t i, size_t r);
short max_dim() const;
@@ -59,11 +57,9 @@ class cMedTemplTown : public cMedTown, cTemplTown {
private:
//cCreature _creatures[40];
//ter_num_t _terrain[48][48];
//rectangle _room_rect[16];
//unsigned char _lighting[4][32];
public:
ter_num_t& terrain(size_t x, size_t y);
rectangle& room_rect(size_t i);
cCreature& creatures(size_t i);
unsigned char& lighting(size_t i, size_t r);
short max_dim() const;
@@ -78,11 +74,9 @@ class cTinyTemplTown : public cTinyTown, cTemplTown {
private:
//cCreature _creatures[30];
//ter_num_t _terrain[32][32];
//rectangle _room_rect[16];
//unsigned char _lighting[4][32];
public:
ter_num_t& terrain(size_t x, size_t y);
rectangle& room_rect(size_t i);
cCreature& creatures(size_t i);
unsigned char& lighting(size_t i, size_t r);
short max_dim() const;

View File

@@ -71,8 +71,6 @@ void cTown::append(legacy::town_record_type& old){
timer_spec_times[i] = old.timer_spec_times[i];
timer_specs[i] = old.timer_specs[i];
}
for(i = 0; i < 180; i++)
strlens[i] = old.strlens[i];
for(i = 0; i < 100; i++)
specials[i].append(old.specials[i]);
difficulty = old.difficulty;
@@ -140,14 +138,13 @@ cTown::cTown(cScenario& scenario, bool init_strings) : scenario(scenario) {
temp_str = get_str("town-default",i + 1);
if(i == 0) town_name = temp_str;
else if(i >= 1 && i < 17)
rect_names[i-1] = temp_str;
room_rect[i-1].descr = temp_str;
else if(i >= 17 && i < 20)
comment[i-17] = temp_str;
else if(i >= 20 && i < 120)
spec_strs[i-20] = temp_str;
else if(i >= 120 && i < 140)
sign_strs[i-120] = temp_str;
strlens[i] = temp_str.length();
}
for(i = 0; i < 200; i++)

View File

@@ -84,7 +84,6 @@ public:
short spec_on_hostile;
short timer_spec_times[8];
short timer_specs[8];
unsigned char strlens[180];
std::array<cSpecial,100> specials;
bool strong_barriers : 1;
bool defy_mapping : 1;
@@ -95,7 +94,7 @@ public:
std::string town_name;
// Using std::array here so we can have .size()
// This'll make the transition smoother once it becomes a vector.
std::array<std::string,16> rect_names;
std::array<info_rect_t,16> room_rect;
std::array<std::string,3> comment;
std::array<std::string,100> spec_strs;
std::array<std::string,20> sign_strs;
@@ -106,7 +105,6 @@ 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 rectangle& room_rect(size_t i) = 0;
virtual cCreature& creatures(size_t i) = 0;
virtual unsigned char& lighting(size_t i, size_t r) = 0;
virtual short max_dim() const = 0;

View File

@@ -44,10 +44,10 @@ void cCurTown::append(legacy::big_tr_type& old){
for(j = 0; j < record()->max_dim(); j++)
record()->terrain(i,j) = old.terrain[i][j];
for(i = 0; i < 16; i++){
record()->room_rect(i).top = old.room_rect[i].top;
record()->room_rect(i).left = old.room_rect[i].left;
record()->room_rect(i).bottom = old.room_rect[i].bottom;
record()->room_rect(i).right = old.room_rect[i].right;
record()->room_rect[i].top = old.room_rect[i].top;
record()->room_rect[i].left = old.room_rect[i].left;
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]);

View File

@@ -472,19 +472,19 @@ bool handle_action(location the_point,sf::Event /*event*/) {
else { // MODE_ROOM_RECT
if(editing_town) {
for(x = 0; x < 16; x++)
if(town->room_rect(x).right == 0) {
town->room_rect(x) = working_rect;
town->rect_names[x] = "";
if(town->room_rect[x].right == 0) {
static_cast<rectangle&>(town->room_rect[x]) = working_rect;
town->room_rect[x].descr = "";
if(!edit_area_rect_str(x,1))
town->room_rect(x).right = 0;
town->room_rect[x].right = 0;
x = 500;
}
}
else {
for(x = 0; x < 8; x++)
if(current_terrain->info_rect[x].right == 0) {
current_terrain->info_rect[x] = working_rect;
current_terrain->rect_names[x] = "";
static_cast<rectangle&>(current_terrain->info_rect[x]) = working_rect;
current_terrain->info_rect[x].descr = "";
if(!edit_area_rect_str(x,0))
current_terrain->info_rect[x].right = 0;
x = 500;

View File

@@ -1056,8 +1056,8 @@ void scen_text_dump(){
fout << " Name: " << scenario.outdoors[out_sec.x][out_sec.y]->out_name;
fout << " Comment: " << scenario.outdoors[out_sec.x][out_sec.y]->comment;
for(i = 0; i < 8; i++)
if(scenario.outdoors[out_sec.x][out_sec.y]->rect_names[i][0] != '*')
fout << " Area Rectangle " << i << ": " << scenario.outdoors[out_sec.x][out_sec.y]->rect_names[i] << endl;
if(scenario.outdoors[out_sec.x][out_sec.y]->info_rect[i].descr[0] != '*')
fout << " Area Rectangle " << i << ": " << scenario.outdoors[out_sec.x][out_sec.y]->info_rect[i].descr << endl;
for(i = 0; i < 90; i++)
if(scenario.outdoors[out_sec.x][out_sec.y]->spec_strs[i][0] != '*')
fout << " Message " << i << ": " << scenario.outdoors[out_sec.x][out_sec.y]->spec_strs[i] << endl;
@@ -1073,8 +1073,8 @@ void scen_text_dump(){
fout << " Town Messages:" << endl;
fout << " Name: " << scenario.towns[i]->town_name << endl;
for(i = 0; i < 16; i++)
if(scenario.towns[i]->rect_names[i][0] != '*')
fout << " Area Rectangle " << i << ": " << scenario.towns[i]->rect_names[i] << endl;
if(scenario.towns[i]->room_rect[i].descr[0] != '*')
fout << " Area Rectangle " << i << ": " << scenario.towns[i]->room_rect[i].descr << endl;
fout << " Name: " << scenario.towns[i]->town_name << endl;
for(i = 0; i < 3; i++)
if(scenario.towns[i]->comment[i][0] != '*')

View File

@@ -777,11 +777,11 @@ void draw_terrain(){
if(editing_town) {
// draw info rects
for(i = 0; i < 16; i++)
if(town->room_rect(i).left > 0) {
draw_rect.left = 22 + 28 * (town->room_rect(i).left - cen_x + 4);
draw_rect.right = 22 + 28 * (town->room_rect(i).right - cen_x + 4);
draw_rect.top = 24 + 36 * (town->room_rect(i).top - cen_y + 4);
draw_rect.bottom = 24 + 36 * (town->room_rect(i).bottom - cen_y + 4);
if(town->room_rect[i].left > 0) {
draw_rect.left = 22 + 28 * (town->room_rect[i].left - cen_x + 4);
draw_rect.right = 22 + 28 * (town->room_rect[i].right - cen_x + 4);
draw_rect.top = 24 + 36 * (town->room_rect[i].top - cen_y + 4);
draw_rect.bottom = 24 + 36 * (town->room_rect[i].bottom - cen_y + 4);
frame_rect(ter_draw_gworld, draw_rect, sf::Color::Red);
}
// draw border rect

View File

@@ -344,8 +344,8 @@ static bool edit_area_rect_event_filter(cDialog& me, std::string item_hit, short
me.toast(true);
std::string str = me["area"].getText().substr(0,29);
if(str_mode == 0)
current_terrain->rect_names[which_str];
else town->rect_names[which_str];
current_terrain->info_rect[which_str].descr;
else town->room_rect[which_str].descr;
} else if(item_hit == "cancel") {
me.setResult(false);
me.toast(false);
@@ -361,8 +361,8 @@ bool edit_area_rect_str(short which_str,short mode) {
dlog.attachClickHandlers(std::bind(edit_area_rect_event_filter, _1, _2, which_str, mode), {"okay", "cancel"});
if(mode == 0)
dlog["area"].setText(current_terrain->rect_names[which_str]);
else dlog["area"].setText(town->rect_names[which_str]);
dlog["area"].setText(current_terrain->info_rect[which_str].descr);
else dlog["area"].setText(town->room_rect[which_str].descr);
dlog.run();

View File

@@ -292,11 +292,11 @@ static bool save_roomdescs(cDialog& me, bool isTown, bool str_do_delete[]) {
for(int i = 0; i < numDescs; i++) {
std::string id = "desc" + std::to_string(i + 1);
if(isTown) {
town->rect_names[i] = me[id].getText().substr(0,30);
town->room_rect[i].descr = me[id].getText().substr(0,30);
if(str_do_delete[i])
town->room_rect(i).right = 0;
town->room_rect[i].right = 0;
} else {
current_terrain->rect_names[i] = me[id].getText().substr(0,30);
current_terrain->info_rect[i].descr = me[id].getText().substr(0,30);
if(str_do_delete[i])
current_terrain->info_rect[i].right = 0;
}
@@ -310,17 +310,17 @@ static void put_roomdescs_in_dlog(cDialog& me, bool isTown, bool str_do_delete[]
std::string id = std::to_string(i + 1);
std::ostringstream str;
bool active = true;
if(isTown && town->room_rect(i).right == 0) active = false;
if(isTown && town->room_rect[i].right == 0) active = false;
if(!isTown && current_terrain->info_rect[i].right == 0) active = false;
if(str_do_delete[i]) active = false;
if(!active) {
str << "Not yet placed.";
me["del" + id].hide();
} else if(isTown) {
me["desc" + id].setText(town->rect_names[i]);
str << "X = " << town->room_rect(i).left << ", Y = " << town->room_rect(i).top;
me["desc" + id].setText(town->room_rect[i].descr);
str << "X = " << town->room_rect[i].left << ", Y = " << town->room_rect[i].top;
} else {
me["desc" + id].setText(current_terrain->rect_names[i]);
me["desc" + id].setText(current_terrain->info_rect[i].descr);
str << "X = " << current_terrain->info_rect[i].left << ", Y = " << current_terrain->info_rect[i].top;
}
me["rect" + id].setText(str.str());

View File

@@ -314,7 +314,7 @@ bool load_town_v1(fs::path scen_file, short which_town, cTown& the_town, legacy:
temp_str[len] = 0;
if(i == 0) the_town.town_name = temp_str;
else if(i >= 1 && i < 17)
the_town.rect_names[i-1] = temp_str;
the_town.room_rect[i-1].descr = temp_str;
else if(i >= 17 && i < 20)
the_town.comment[i-17] = temp_str;
else if(i >= 20 && i < 120)
@@ -445,7 +445,7 @@ bool load_outdoors_v1(fs::path scen_file, location which_out,cOutdoors& the_out,
temp_str[len] = 0;
if(i == 0) the_out.out_name = temp_str;
else if(i == 9) the_out.comment = temp_str;
else if(i < 9) the_out.rect_names[i-1] = temp_str;
else if(i < 9) the_out.info_rect[i-1].descr = temp_str;
else if(i >= 10 && i < 100)
the_out.spec_strs[i-10] = temp_str;
else if(i >= 100 && i < 108)