Make it possible to change base and overlay separately...

...in [terrain] and [terrain_mask] actions.
This commit is contained in:
Moritz Göbelbecker 2008-05-22 13:21:04 +00:00
parent 0ea0879210
commit c470637f8f
7 changed files with 224 additions and 82 deletions

View file

@ -59,6 +59,7 @@ Version 1.5.0+svn:
* add "default_base" parameter to overlay terrains, which specifies the
base terrain the editor draws by default.
* New [heal_unit] action.
* Make it possible to change base and overlay separately in [terrain] and [terrain_mask] actions.
* wesnothd
* added expiration time to bans
* added restart command to server that does gracefull restart

View file

@ -2,30 +2,30 @@
[test]
name="Test scenario"
map_data="usage=map
border_size=1
map_data="border_size=1
usage=map
Mm ,Mm , Mm , Mm , Mm^Xm , Mm^Xm , Mm^Xm , Gg , Ww , Gg , Dd , Gg , Aa , Gg , Aa , Gg , Hh , Gg , Mm , Gg , Uu , Gg , Wo , Wo , Ch , Wo , Wo , Wo , Gg , Wo , Wo , Wo , Md , Wo , Wo , Wo , Rd , Wo , Wo
Mm ,Mm , Mm , Mm , Mm^Xm , Mm^Xm , Mm^Xm , Gg , Ww^Vm , Gg , Dd^Vda , Gg , Aa^Vea , Gg , Aa^Vha , Gg , Hh^Vhh , Gg , Mm^Vhh , Gg , Uu^Vu , Gg , Wo , Wo , Ch , Wo , Wo , Wo , Gg , Wo , Wo , Wo , Md , Wo , Wo , Wo , Rd , Wo , Wo
Mm ,Mm , Mm , Mm , Mm , Mm^Xm , Gg , Gg , Gg , Uu^Vud , Gg , Dd^Vdt , Gg , Gg^Ve , Gg , Gg^Vh , Gg , Ha^Vhha , Gg , Gs^Vht , Wo , Wo , Cud , Ch , Wo , Wo , Ds , Gg , Wo , Wo , Hd , Md , Wo , Wo , Re , Rd , Wo , Wo , Wo
Mm ,Mm , Gg , Gg , Gg , Gg , Gg , Ch , Ch , Ch , Ch , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Ss^Vhs , Gg , Cud , Wo , Wo , Dd , Ds , Wo , Wo , Ha , Hd , Wo , Wo , Ql , Re , Wo , Wo , Uu , Uu , Uu
Mm ,Mm , Gg , Gg , Gg , Gg , Gg , Ch , 1 Kh , Ch , Ww , Gg , Gg , Mm^Vhh , Gg , Gg , Gg , Gg , Gg , Gs^Fp , Gs^Fp , Gs^Fp , Gs^Fp , Dd , Wo , Wo , Gs , Ha , Wo , Wo , Mm , Ql , Wo , Wo , Uh , Uh , Wo , Wo , Wo
Mm ,Mm , Gg , Gg , Gg , Gg , Gg , Ch , Ch , Ch , Gg , Ww , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gs^Fp , Gs^Fp , Gs^Fp , Gs^Fp , Wo , Gs , Gs , Gg^Vh , Ww , Ww , Mm , Ww , Wo , Rr , Rr , Wo , Wo , Gg , Gg , Gg
Mm ,Mm , Gg , Gg , Gg , Gg , Gg , Ch , Ch , Ch , Gg , Gg , Gg , Gg , Rr , Gg , Rr , Rr , Rr , Gs^Fp , Gs^Fp , Gs^Fp , Gs^Fp , Gs^Fp , Gg^Vh , Rr , Gg , Ww , Ww , Hh , Hh , Hh , Wo , Wo , Wo , Gg , Wo , Gg , Gg
Mm ,Mm , Gg , Gg , Gg , Gg , Gg , Gg^Ve , Gg , Gg^Ve , Gg , Gg , Gg , Gg , Gg , Gg , Rr , Gg , Rr , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Ww , Ww , Ww , Ww , Gg , Wo , Mm^Xm , Wo , Gg , Wo , Ha , Ha
Gg ,Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gs , Gg , Gg , Rr , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Wo , Mm^Xm , Wo , Gg , Wo , Ha , Ha
Gg ,Gg , Gs^Fp , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gs , Gg , Gs , Gg , Gs , Gg , Gg , Re , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Wo , Aa , Wo , Gg , Wo , Hh , Hh
Gg ,Gg , Gg , Gg , Gs^Ft , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gs , Gs , Gs , Gg , Re , Gg , Re , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Wo , Aa , Wo , Md , Wo , Hh , Hh
Gg ,Gg , Dd^Do , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gs , Gg , Gg , Rd , Gg , Gg , Re , Re , Re , Gg , Gg , Ch , Ch , Ch , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Wo , Ai , Wo , Md , Wo , Ss^Bw| , Ss^Bw|
Gg ,Gg , Gg , Gg , Gg^Fet , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Rd , Gg , Rd , Gg , Gg , Gg , Gg , Gg , Gg , Ch , Ch , Ch , Gg , Gg , Gg , Ww , Gg , Wo , Gg , Wo , Ai , Wo , Mm , Wo , Ss , Ss
Xu ,Xu , Xu , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Rd , Gg , Rd , Rd , Rd , Gg , Re , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Wo^Bw\ , Wo^Bw/ , Wo^Bw| , Ww , Gg , Wo , Dd , Wo , Mm , Wo , Ss , Ss
Xu ,Xu , Xu , Ce , Ce , Ke , Ce , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Ce , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Ss^Bw/ , Ww , Ss^Bw| , Ss^Bw\ , Gg , Wo , Dd , Wo , Qxu , Wo , Rr , Rr
Xu ,Xu , Uu^Uf , Xu , Ce , Ce , Xu , Gg , Uh , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Ke , Ce , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Ss^Bw\ , Wo , Ds , Wo , Qxu , Wo , Rr , Rr
Xu ,Xu , Uu^Uf , Xu , Xu , Xu , Xu , Xu , Uu , Gg , Uh , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Ss , Gg , Gg , 2 Kh , Gg , Gg , Wo , Ds , Wo , Rd , Wo , Uh , Uh
Xu ,Xu , Qxu , Qxu , Cud , Xu , Uu , Uu^Ii , Uu^Vu , Gg , Xu , Gg , Gg , Gg , Gg^Ve , Gg , Ch , Gg , Gg , Chr , Chr , Gg , Chw , Ww , Gg , Chs , Chs , Gg , Cud , Gg , Gg , Gg , Wo , Gs , Wo , Rd , Wo , Uh , Uh
Xu ,Xu , Xu , Qxu , Ql , Cud , Uh , Uu^Vu , Uu^Uf , Xu , Ql , Gg^Ve , Xu , Gg , Gg , Gg , Kh , Ch , Gg , Khr , Gg , Gg , Khw , Chw , Gg , Khs , Gg , Gg , Kud , Cud , Ww^Bw/ , Ww^Bw/ , Wo , Gs , Wo , Re , Wo , Uu , Uu
Xu ,Xu , Qxu , Qxu , Ql , Ql , Ql , Xu , Xu , Xu , Xu , Xu , Xu , Xu , Xu , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Wo , Gg , Wo , Re , Wo , Uu , Uu
Xu ,Xu , Qxu , Qxu , Ql , Ql , Ql , Xu , Xu , Xu , Xu , Xu , Xu , Xu , Xu , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Wo , Gg , Wo , Re , Wo , Uu , Uu
Mm , Mm , Mm , Mm , Mm^Xm , Mm^Xm , Mm^Xm , Gg , Ww , Gg , Dd , Gg , Aa , Gg , Aa , Gg , Hh , Gg , Mm , Gg , Uu , Gg , Wo , Wo , Ch , Wo , Wo , Wo , Gg , Wo , Wo , Wo , Md , Wo , Wo , Wo , Rd , Wo , Wo
Mm , Mm , Mm , Mm , Mm^Xm , Mm^Xm , Mm^Xm , Gg , Ww^Vm , Gg , Dd^Vda , Gg , Aa^Vea , Gg , Aa^Vha , Gg , Hh^Vhh , Gg , Mm^Vhh , Gg , Uu^Vu , Gg , Wo , Wo , Ch , Wo , Wo , Wo , Gg , Wo , Wo , Wo , Md , Wo , Wo , Wo , Rd , Wo , Wo
Mm , Mm , Mm , Mm , Mm , Mm^Xm , Gg , Gg , Gg , Uu^Vud , Gg , Dd^Vdt , Gg , Gg^Ve , Gg , Gg^Vh , Gg , Ha^Vhha , Gg , Gs^Vht , Wo , Wo , Cud , Ch , Wo , Wo , Ds , Gg , Wo , Wo , Hd , Md , Wo , Wo , Re , Rd , Wo , Wo , Wo
Mm , Mm , Gg , Gg , Gg , Gg , Gg , Ch , Ch , Ch , Ch , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Ss^Vhs , Gg , Cud , Wo , Wo , Dd , Ds , Wo , Wo , Ha , Hd , Wo , Wo , Ql , Re , Wo , Wo , Uu , Uu , Uu
Mm , Mm , Gg , Gg , Gg , Gg , Gg , Ch , 1 Kh , Ch , Ww , Gg , Gg , Mm^Vhh , Gg , Gg , Gg , Gg , Gg , Gs^Fp , Gs^Fp , Gs^Fp , Gs^Fp , Dd , Wo , Wo , Gs , Ha , Wo , Wo , Mm , Ql , Wo , Wo , Uh , Uh , Wo , Wo , Wo
Mm , Mm , Gg , Gg , Gg , Gg , Gg , Ch , Ch , Ch , Gg , Ww , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gs^Fp , Gs^Fp , Gs^Fp , Gs^Fp , Wo , Gs , Gs , Gg^Vh , Ww , Ww , Mm , Ww , Wo , Rr , Rr , Wo , Wo , Gg , Gg , Gg
Mm , Mm , Gg , Gg , Gg , Gg , Gg , Ch , Ch , Ch , Gg , Gg , Gg , Gg , Rr , Gg , Rr , Rr , Rr , Gs^Fp , Gs^Fp , Gs^Fp , Gs^Fp , Gs^Fp , Gg^Vh , Rr , Gg , Ww , Ww , Hh , Hh , Hh , Wo , Wo , Wo , Gg , Wo , Gg , Gg
Mm , Mm , Gg , Gg , Gg , Gg , Gg , Gg^Ve , Gg , Gg^Ve , Gg , Gg , Gg , Gg , Gg , Gg , Rr , Gg , Rr , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Ww , Ww , Ww , Ww , Gg , Wo , Mm^Xm , Wo , Gg , Wo , Ha , Ha
Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gs , Gg , Gg , Rr , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Wo , Mm^Xm , Wo , Gg , Wo , Ha , Ha
Gg , Gg , Gs^Fp , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gs , Gg , Gs , Gg , Gs , Gg , Gg , Re , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Wo , Aa , Wo , Gg , Wo , Hh , Hh
Gg , Gg , Gg , Gg , Gs^Ft , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gs , Gs , Gs , Gg , Re , Gg , Re , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Wo , Aa , Wo , Md , Wo , Hh , Hh
Gg , Gg , Dd^Do , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gs , Gg , Gg , Rd , Gg , Gg , Re , Re , Re , Gg , Gg , Ch , Ch , Ch , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Wo , Ai , Wo , Md , Wo , Ss^Bw| , Ss^Bw|
Gg , Gg , Gg , Gg , Gg^Fet , Gg , Gg , Gg , Gs^Fpa , Ds^Fp , Gs^Fp , Gg , Gg , Rd , Gg , Rd , Gg , Gg , Gg , Gg , Gg , Gg , Ch , Ch , Ch , Gg , Gg , Gg , Ww , Gg , Wo , Gg , Wo , Ai , Wo , Mm , Wo , Ss , Ss
Xu , Xu , Xu , Gg , Gg , Gg , Gg , Gg , Re^Fp , Gg^Fet , Gg^Fp , Ss^Vm , Gg , Rd , Rd , Rd , Gg , Re , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Wo^Bw\ , Wo^Bw/ , Wo^Bw| , Ww , Gg , Wo , Dd , Wo , Mm , Wo , Ss , Ss
Xu , Xu , Xu , Ce , Ce , Ke , Ce , Gg , Gg , Re^Fp , Gg^Ve , Gg^Vh , Gg , Gg , Gg , Gg , Ce , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Ss^Bw/ , Ww , Ss^Bw| , Ss^Bw\ , Gg , Wo , Dd , Wo , Qxu , Wo , Rr , Rr
Xu , Xu , Uu^Uf , Xu , Ce , Ce , Xu , Gg , Uh , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Ke , Ce , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Ss^Bw\ , Wo , Ds , Wo , Qxu , Wo , Rr , Rr
Xu , Xu , Uu^Uf , Xu , Xu , Xu , Xu , Xu , Uu , Gg , Uh , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Ss , Gg , Gg , 2 Kh , Gg , Gg , Wo , Ds , Wo , Rd , Wo , Uh , Uh
Xu , Xu , Qxu , Qxu , Cud , Xu , Uu , Uu^Ii , Uu^Vu , Gg , Xu , Gg , Gg , Gg , Gg^Ve , Gg , Ch , Gg , Gg , Chr , Chr , Gg , Chw , Ww , Gg , Chs , Chs , Gg , Cud , Gg , Gg , Gg , Wo , Gs , Wo , Rd , Wo , Uh , Uh
Xu , Xu , Xu , Qxu , Ql , Cud , Uh , Uu^Vu , Uu^Uf , Xu , Ql , Gg^Ve , Xu , Gg , Gg , Gg , Kh , Ch , Gg , Khr , Gg , Gg , Khw , Chw , Gg , Khs , Gg , Gg , Kud , Cud , Ww^Bw/ , Ww^Bw/ , Wo , Gs , Wo , Re , Wo , Uu , Uu
Xu , Xu , Qxu , Qxu , Ql , Ql , Ql , Xu , Xu , Xu , Xu , Xu , Xu , Xu , Xu , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Wo , Gg , Wo , Re , Wo , Uu , Uu
Xu , Xu , Qxu , Qxu , Ql , Ql , Ql , Xu , Xu , Xu , Xu , Xu , Xu , Xu , Xu , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Gg , Wo , Gg , Wo , Re , Wo , Uu , Uu
"
# [event]
@ -722,6 +722,104 @@ _s, _s, _s, _s, Aa, Aa, _s, _s, _s, _s
[/rule]
[/terrain_mask]
[/event]
[label]
x,y = 9,13
text = "Plant palms"
[/label]
[event]
# Replace all trees with tropic forest but leave the base terrain intact
name="moveto"
first_time_only=yes
[filter]
x,y=9,13
[/filter]
[terrain_mask]
x,y=8,11
mask="
usage=mask
^Ft, ^Ft, ^Ft, ^Ft
^Ft, ^Ft, ^Ft, ^Ft
^Ft, ^Ft, ^Ft, ^Ft
^Ft, ^Ft, ^Ft, ^Ft
"
[rule]
old=*^F*
layer=overlay
[/rule]
# # default: Will match everything, since 'old' and 'new' aren't specified.
# # Set 'use_old=yes' to signal no change.
[rule]
use_old=yes
[/rule]
[/terrain_mask]
[terrain]
x=12
y=12
terrain=Aa^Ft
layer=overlay
[/terrain]
[/event]
[label]
x,y = 10,13
text = "Flood"
[/label]
[event]
# replace the base terrain while leaving the overlay intact
name="moveto"
first_time_only=yes
[filter]
x,y=10,13
[/filter]
[terrain_mask]
x,y=8,11
mask="
usage=mask
Ww, Ww, Ww, Ww
Ww, Ww, Ww, Ww
Ww, Ww, Ww, Ww
Ww, Ww, Ww, Ww
"
[rule]
old=*^Ve*
layer=base
[/rule]
[rule]
layer=base
replace_if_failed=true # if just replacing the base failed, replace the whole terrain
# this will make the human village disappear.
[/rule]
# # default: Will match everything, since 'old' and 'new' aren't specified.
# # Set 'use_old=yes' to signal no change.
[rule]
use_old=yes
[/rule]
[/terrain_mask]
[terrain]
x=12
y=12
terrain=Ds
layer=base
[/terrain]
[label]
x,y = 11,14
text = "Sunken"
[/label]
[label]
x,y = 10,14
text = "Still there"
[/label]
[/event]
[event]
name=start
[set_menu_item]

View file

@ -873,7 +873,7 @@ void map_editor::perform_fill_hexes(std::set<gamemap::location> &fill_hexes,
if (map_.on_board(*it, true)) {
undo_action.add_terrain(map_.get_terrain(*it), terrain, *it);
if (terrain.base == t_translation::NO_LAYER) {
map_.set_overlay(*it, terrain);
map_.set_terrain(*it, terrain, gamemap::OVERLAY);
}
else {
map_.set_terrain(*it, terrain);
@ -1002,7 +1002,7 @@ void map_editor::redo() {
action.redo_terrains().begin();
it != action.redo_terrains().end(); ++it) {
if (it->second.base == t_translation::NO_LAYER) {
map_.set_overlay(it->first, it->second);
map_.set_terrain(it->first, it->second, gamemap::OVERLAY);
}
else {
map_.set_terrain(it->first, it->second);
@ -1232,10 +1232,10 @@ void map_editor::draw_terrain(const t_translation::t_terrain terrain,
if(final_terrain != old_terrain) {
undo_action.add_terrain(old_terrain, final_terrain, *it);
if (final_terrain.base == t_translation::NO_LAYER) {
map_.set_overlay(*it, final_terrain);
map_.set_terrain(*it, final_terrain, gamemap::OVERLAY);
}
else if (one_layer_only) {
map_.set_base(*it, final_terrain);
map_.set_terrain(*it, final_terrain, gamemap::BASE);
}
else {
map_.set_terrain(*it, final_terrain);

View file

@ -339,7 +339,7 @@ void flood_fill(gamemap &map, const gamemap::location &start_loc,
log->push_back(std::make_pair(loc, terrain_to_fill));
}
if (fill_with.base == t_translation::NO_LAYER) {
map.set_overlay(loc, fill_with);
map.set_terrain(loc, fill_with, gamemap::OVERLAY);
}
else {
map.set_terrain(loc, fill_with);

View file

@ -1685,23 +1685,37 @@ void event_handler::handle_event_command(const queued_event& event_info,
if(terrain != t_translation::NONE_TERRAIN) {
gamemap::tmerge_mode mode = gamemap::BOTH;
if (cfg["layer"] == "base") {
mode = gamemap::BASE;
}
else if (cfg["layer"] == "overlay") {
mode = gamemap::OVERLAY;
}
for(std::vector<gamemap::location>::const_iterator loc = locs.begin(); loc != locs.end(); ++loc) {
preferences::encountered_terrains().insert(terrain);
const bool old_village = game_map->is_village(*loc);
const bool new_village = game_map->is_village(terrain);
const t_translation::t_terrain old_terrain = game_map->get_terrain(*loc);
const t_translation::t_terrain new_terrain = game_map->merge_terrains(old_terrain, terrain, mode, utils::string_bool(cfg["replace_if_failed"]) );
if (new_terrain != t_translation::NONE_TERRAIN) {
if(old_village && !new_village) {
int owner = village_owner(*loc, *teams);
if(owner != -1) {
(*teams)[owner].lose_village(*loc);
preferences::encountered_terrains().insert(new_terrain);
const bool old_village = game_map->is_village(*loc);
const bool new_village = game_map->is_village(new_terrain);
if(old_village && !new_village) {
int owner = village_owner(*loc, *teams);
if(owner != -1) {
(*teams)[owner].lose_village(*loc);
}
}
}
game_map->set_terrain(*loc,terrain);
const t_translation::t_list underlaying_list = game_map->underlying_union_terrain(*loc);
for (t_translation::t_list::const_iterator ut = underlaying_list.begin(); ut != underlaying_list.end(); ut++) {
preferences::encountered_terrains().insert(*ut);
};
game_map->set_terrain(*loc, new_terrain);
const t_translation::t_list underlaying_list = game_map->underlying_union_terrain(*loc);
for (t_translation::t_list::const_iterator ut = underlaying_list.begin(); ut != underlaying_list.end(); ut++) {
preferences::encountered_terrains().insert(*ut);
};
}
}
rebuild_screen_ = true;
}

View file

@ -511,11 +511,21 @@ void gamemap::overlay(const gamemap& m, const config& rules_cfg, const int xpos,
const config& cfg = **rule;
const t_translation::t_list& terrain = t_translation::read_list(cfg["terrain"]);
if(!terrain.empty()) {
set_terrain(location(x2,y2),terrain[0]);
} else if(utils::string_bool(cfg["use_old"]) != true) {
set_terrain(location(x2,y2),t);
tmerge_mode mode = BOTH;
if (cfg["layer"] == "base") {
mode = BASE;
}
else if (cfg["layer"] == "overlay") {
mode = OVERLAY;
}
t_translation::t_terrain new_terrain = t;
if(!terrain.empty()) {
new_terrain = terrain[0];
}
set_terrain(location(x2,y2), new_terrain, mode, utils::string_bool(cfg["replace_if_failed"]));
} else {
set_terrain(location(x2,y2),t);
}
@ -715,20 +725,21 @@ bool gamemap::location::matches_range(const std::string& xloc, const std::string
return true;
}
void gamemap::set_terrain(const gamemap::location& loc, const t_translation::t_terrain terrain)
{
void gamemap::set_terrain(const gamemap::location& loc, const t_translation::t_terrain terrain, const tmerge_mode mode, bool replace_if_failed) {
if(!on_board(loc, true)) {
// off the map: ignore request
return;
}
if(!try_merge_terrains(terrain)) {
t_translation::t_terrain new_terrain = merge_terrains(get_terrain(loc), terrain, mode, replace_if_failed);
if(new_terrain == t_translation::NONE_TERRAIN) {
return;
}
if(on_board(loc, false)) {
const bool old_village = is_village(loc);
const bool new_village = is_village(terrain);
const bool new_village = is_village(new_terrain);
if(old_village && !new_village) {
villages_.erase(std::remove(villages_.begin(),villages_.end(),loc),villages_.end());
@ -737,7 +748,7 @@ void gamemap::set_terrain(const gamemap::location& loc, const t_translation::t_t
}
}
tiles_[loc.x + border_size_][loc.y + border_size_] = terrain;
tiles_[loc.x + border_size_][loc.y + border_size_] = new_terrain;
// Update the off-map autogenerated tiles
location adj[6];
@ -748,27 +759,6 @@ void gamemap::set_terrain(const gamemap::location& loc, const t_translation::t_t
}
}
void gamemap::set_overlay(const gamemap::location& loc, const t_translation::t_terrain terrain)
{
if(!on_board(loc, true)) {
// off the map: ignore request
return;
}
set_terrain(loc, t_translation::t_terrain(tiles_[loc.x + border_size_][loc.y + border_size_].base, terrain.overlay));
}
void gamemap::set_base(const gamemap::location& loc, const t_translation::t_terrain terrain)
{
if(!on_board(loc, true)) {
// off the map: ignore request
return;
}
set_terrain(loc, t_translation::t_terrain(terrain.base, tiles_[loc.x + border_size_][loc.y + border_size_].overlay));
}
std::vector<gamemap::location> parse_location_range(const std::string& x, const std::string& y,
const gamemap *const map)
{
@ -853,3 +843,37 @@ bool gamemap::try_merge_terrains(const t_translation::t_terrain terrain) {
return true; // Terrain already exists, nothing to do
}
t_translation::t_terrain gamemap::merge_terrains(const t_translation::t_terrain old_t, const t_translation::t_terrain new_t, const tmerge_mode mode, bool replace_if_failed) {
t_translation::t_terrain result = t_translation::NONE_TERRAIN;
if(mode == OVERLAY) {
const t_translation::t_terrain t = t_translation::t_terrain(old_t.base, new_t.overlay);
if (try_merge_terrains(t)) {
result = t;
}
}
else if(mode == BASE) {
const t_translation::t_terrain t = t_translation::t_terrain(new_t.base, old_t.overlay);
if (try_merge_terrains(t)) {
result = t;
}
}
else if(mode == BOTH) {
if(new_t.base != t_translation::NO_LAYER && tcodeToTerrain_.count(new_t) > 0) {
result = new_t;
}
}
// if merging of overlay and base failed, and replace_if_failed is set,
// replace the terrain with the complete new terrain (if given)
// or with (default base)^(new overlay)
if(result == t_translation::NONE_TERRAIN && replace_if_failed && tcodeToTerrain_.count(new_t) > 0) {
if(new_t.base != t_translation::NO_LAYER) {
result = new_t;
}
else if (get_terrain_info(new_t).default_base() != t_translation::NONE_TERRAIN) {
result = get_terrain_info(new_t).terrain_with_default_base();
}
}
return result;
}

View file

@ -148,6 +148,12 @@ public:
IS_MASK
};
enum tmerge_mode {
BASE,
OVERLAY,
BOTH
};
//! Loads a map, with the given terrain configuration.
//! Data should be a series of lines, with each character
//! representing one hex on the map.
@ -215,17 +221,8 @@ public:
{ return terrainList_; }
//! Clobbers over the terrain at location 'loc', with the given terrain.
void set_terrain(const location& loc, const t_translation::t_terrain terrain);
//! clobbers over the overlay terrain at location 'loc', with the given terrain.
//! This method checks if the base and new overlay can be combined, or if
//! base+new overlay are already valid, if it isn't it will fail silently.
void set_overlay(const location& loc, const t_translation::t_terrain terrain);
//! clobbers over the base terrain at location 'loc', with the given terrain.
//! This method checks if the new base and old overlay can be combined, or if
//! new base+overlay are already valid, if it isn't it will fail silently.
void set_base(const location& loc, const t_translation::t_terrain terrain);
//! Uses mode and replace_if_failed like merge_terrains().
void set_terrain(const location& loc, const t_translation::t_terrain terrain, const tmerge_mode mode=BOTH, bool replace_if_failed = false);
//! Returns a list of the frequencies of different terrain types on the map,
//! with terrain nearer the center getting weighted higher.
@ -250,6 +247,14 @@ public:
//! The default border style for a map
static const tborder default_border;
//! Tries to merge old and new terrain using the merge_settings config
//! Relevant parameters are "layer" and "replace_conflicting"
//! "layer" specifies the layer that should be replaced (base or overlay, default is both).
//! If "replace_conflicting" is true the new terrain will replace the old one if merging failed
//! (using the default base if new terrain is an overlay terrain)
//! Will return the resulting terrain or NONE_TERRAIN if merging failed
t_translation::t_terrain merge_terrains(const t_translation::t_terrain old_t, const t_translation::t_terrain new_t, const tmerge_mode mode, bool replace_if_failed = false);
protected:
t_translation::t_map tiles_;
//! The size of the starting positions array is MAX_PLAYERS + 1,