Generalize the editor's terrain frills mechanism

This commit is contained in:
2015-09-26 15:05:49 -04:00
parent 06930e30d4
commit ab232bb31a
10 changed files with 74 additions and 17 deletions

View File

@@ -384,4 +384,12 @@ void cTerrain::append(legacy::terrain_type_type& old){
};
if(picture < 1000) map_pic = picture;
else map_pic = NO_PIC;
if(i == 1)
frill_for = 0, frill_chance = 10;
else if(i == 3)
frill_for = 2, frill_chance = 15;
else if(i == 4)
frill_for = 2, frill_chance = 10;
else if(i == 37)
frill_for = 36, frill_chance = 25;
}

View File

@@ -38,6 +38,8 @@ public:
unsigned int ground_type = 0; // ditto
eTrimType trim_type = eTrimType::NONE; // ditto, mostly
long trim_ter = 0; // ditto
long frill_for = -1;
unsigned short frill_chance = 0;
unsigned short combat_arena = 0;
location obj_pos; // editor use only
location obj_size; // editor use only

View File

@@ -1882,14 +1882,13 @@ void frill_up_terrain() {
for(j = 0; j < ((editing_town) ? town->max_dim() : 48); j++) {
terrain_type = editing_town ? town->terrain(i,j) : current_terrain->terrain[i][j];
if((terrain_type == 2) && (get_ran(1,1,20) < 3))
terrain_type = 3;
if((terrain_type == 2) && (get_ran(1,1,20) < 2))
terrain_type = 4;
if((terrain_type == 0) && (get_ran(1,1,20) < 2))
terrain_type = 1;
if((terrain_type == 36) && (get_ran(1,1,20) < 5))
terrain_type = 37;
for(size_t k = 0; k < scenario.ter_types.size(); k++) {
if(terrain_type == k) continue;
cTerrain& ter = scenario.ter_types[k];
if(terrain_type == ter.frill_for && get_ran(1,1,100) < ter.frill_chance)
terrain_type = k;
}
if(editing_town)
town->terrain(i,j) = terrain_type;
else current_terrain->terrain[i][j] = terrain_type;
@@ -1904,14 +1903,11 @@ void unfrill_terrain() {
for(i = 0; i < ((editing_town) ? town->max_dim() : 48); i++)
for(j = 0; j < ((editing_town) ? town->max_dim() : 48); j++) {
terrain_type = editing_town ? town->terrain(i,j) : current_terrain->terrain[i][j];
if(terrain_type == 3)
terrain_type = 2;
if(terrain_type == 4)
terrain_type = 2;
if(terrain_type == 1)
terrain_type = 0;
if(terrain_type == 37)
terrain_type = 36;
cTerrain& ter = scenario.ter_types[terrain_type];
if(ter.frill_for >= 0)
terrain_type = ter.frill_for;
if(editing_town)
town->terrain(i,j) = terrain_type;
else current_terrain->terrain[i][j] = terrain_type;

View File

@@ -393,6 +393,13 @@ void writeTerrainToXml(ticpp::Printer&& data, cScenario& scenario) {
data.OpenElement("editor");
if(ter.shortcut_key > 0 && ter.shortcut_key < '\x7f')
data.PushElement("shortcut", ter.shortcut_key);
if(ter.frill_for >= 0) {
data.OpenElement("frill");
if(ter.frill_chance != 10)
data.PushAttribute("chance", ter.frill_chance);
data.PushText(ter.frill_for);
data.CloseElement("frill");
}
if(ter.obj_num > 0) {
data.OpenElement("object");
data.PushElement("num", ter.obj_num);

View File

@@ -1008,6 +1008,9 @@ void readTerrainFromXml(ticpp::Document&& data, cScenario& scenario) {
val.clear();
edit->GetText(&val, false);
the_ter.shortcut_key = val.empty() ? 0 : val[0];
} else if(type == "frill") {
edit->GetText(&the_ter.frill_for);
edit->GetAttributeOrDefault("chance", &the_ter.frill_chance, 10);
} else if(type == "object") {
std::set<std::string> reqs = {"num", "pos", "size"};
Iterator<Element> obj;