add team share_vision=all/shroud/none

previously there were 2 flags share_view=yes/no and share_maps=yes/no,
but only 3 possible settings (share both, share none, only share shroud)
(so share_maps= was ignored if share_viewv=yes). This made the wml code and
the c++ code needlessly complicated.

Now these 2 flags are replaced by share_vision=all/shroud/none
This commit is contained in:
gfgtdf 2015-06-03 21:57:59 +02:00
parent 9fb687bb93
commit 49219ad0fd
8 changed files with 50 additions and 52 deletions

View file

@ -176,6 +176,7 @@
team_name=elves
user_team_name=_"Rebels"
fog=yes
share_view=no
[/side]
[event]

View file

@ -21,6 +21,7 @@
id=alice
fog=yes
team_name=West
share_vision=shroud
[/side]
[side]
side=2
@ -30,6 +31,7 @@
id=bob
fog=yes
team_name=East
share_vision=shroud
[/side]
[side]
side=3
@ -39,6 +41,7 @@
id=dave
fog=yes
team_name=East
share_vision=shroud
[/side]
[side]
side=4
@ -48,6 +51,7 @@
id=charlie
fog=yes
team_name=West
share_vision=shroud
[/side]
{EVENTS}

View file

@ -16,6 +16,7 @@
#include "editor/action/action.hpp"
#include "map_context.hpp"
#include "config_assign.hpp"
#include "display.hpp"
#include "filesystem.hpp"
#include "gettext.hpp"
@ -209,9 +210,12 @@ void map_context::set_side_setup(int side, const std::string& team_name, const s
t.set_base_income(income);
t.set_hidden(hidden);
t.set_fog(fog);
t.set_share_maps(share_maps);
t.set_shroud(shroud);
t.set_share_view(share_view);
//TODO: USE team::SHARE_VISION in editor too.
t.handle_legacy_share_vision(config_of
("share_maps", share_maps)
("share_view", share_view)
);
t.set_village_gold(village_gold);
t.set_village_support(village_support);
actions_since_save_++;

View file

@ -1082,11 +1082,6 @@ config side_engine::new_config() const
res["color"] = get_color(color_);
res["gold"] = gold_;
res["income"] = income_;
//share view default to true here to restore the previous behavior.
res["share_view"] = res["share_view"].to_bool(true);
}
if (parent_.params_.use_map_settings && !parent_.params_.saved_game) {

View file

@ -3161,22 +3161,7 @@ int game_lua_kernel::intf_modify_side(lua_State *L)
// Not needed.
//invalidate_screen = true;
}
// Add shared view to current team
config::attribute_value share_view = cfg["share_view"];
if (!share_view.empty()){
tm.set_share_view(share_view.to_bool(true));
team::clear_caches();
invalidate_screen = true;
}
// Add shared maps to current team
// IMPORTANT: this MUST happen *after* share_view is changed
config::attribute_value share_maps = cfg["share_maps"];
if (!share_maps.empty()){
tm.set_share_maps(share_maps.to_bool(true));
team::clear_caches();
invalidate_screen = true;
}
tm.handle_legacy_share_vision(cfg.get_parsed_config());
// Suppress end turn confirmations?
config::attribute_value setc = cfg["suppress_end_turn_confirmation"];
if ( !setc.empty() ) {

View file

@ -72,6 +72,7 @@ static int impl_side_get(lua_State *L)
return_string_attrib("color", t.color());
return_cstring_attrib("controller", t.controller().to_string().c_str());
return_string_attrib("defeat_condition", t.defeat_condition().to_string());
return_string_attrib("share_vision", t.share_vision().to_string());
return_bool_attrib("lost", t.lost());
if (strcmp(m, "recruit") == 0) {

View file

@ -63,7 +63,7 @@ const boost::container::flat_set<std::string> team::attributes = boost::assign::
("flag_icon")("fog")("fog_data")("gold")("hidden")("income")
("no_leader")("objectives")("objectives_changed")("persistent")("lost")
("recall_cost")("recruit")("save_id")("scroll_to_leader")
("share_maps")("share_view")("shroud")("shroud_data")("start_gold")
("share_vision")("share_maps")("share_view")("shroud")("shroud_data")("start_gold")
("suppress_end_turn_confirmation")
("team_name")("user_team_name")("village_gold")("village_support")
// Multiplayer attributes.
@ -99,8 +99,7 @@ team::team_info::team_info() :
controller(),
defeat_condition(team::DEFEAT_CONDITION::NO_LEADER),
proxy_controller(team::PROXY_CONTROLLER::PROXY_HUMAN),
share_maps(false),
share_view(false),
share_vision(team::SHARE_VISION::ALL),
disallow_observers(false),
allow_player(false),
chose_random(false),
@ -212,13 +211,27 @@ void team::team_info::read(const config &cfg)
// Share_view and share_maps can't both be enabled,
// so share_view overrides share_maps.
share_view = cfg["share_view"].to_bool();
share_maps = !share_view && cfg["share_maps"].to_bool(true);
share_vision = cfg["share_vision"].to_enum<team::SHARE_VISION>(team::SHARE_VISION::ALL);
handle_legacy_share_vision(cfg);
LOG_NG << "team_info::team_info(...): team_name: " << team_name
<< ", share_maps: " << share_maps << ", share_view: " << share_view << ".\n";
<< ", share_vision: " << share_vision << ".\n";
}
void team::team_info::handle_legacy_share_vision(const config& cfg)
{
if(cfg.has_attribute("share_view") || cfg.has_attribute("share_maps"))
{
if(cfg["share_view"].to_bool()) {
share_vision = team::SHARE_VISION::ALL;
}
else if(cfg["share_maps"].to_bool(true)) {
share_vision = team::SHARE_VISION::SHROUD;
}
else {
share_vision = team::SHARE_VISION::NONE;
}
}
}
void team::team_info::write(config& cfg) const
{
cfg["gold"] = gold;
@ -249,8 +262,8 @@ void team::team_info::write(config& cfg) const
cfg["scroll_to_leader"] = scroll_to_leader;
cfg["controller"] = controller;
cfg["recruit"] = utils::join(can_recruit);
cfg["share_maps"] = share_maps;
cfg["share_view"] = share_view;
cfg["share_vision"] = share_vision;
cfg["color"] = color;
cfg["persistent"] = persistent;
cfg["lost"] = lost;
@ -459,17 +472,6 @@ bool team::calculate_is_enemy(size_t index) const
return true;
}
void team::set_share_maps( bool share_maps ){
// Share_view and share_maps can't both be enabled,
// so share_view overrides share_maps.
// If you want to change them, be sure to change share_view FIRST
info_.share_maps = !info_.share_view && share_maps;
}
void team::set_share_view( bool share_view ){
info_.share_view = share_view;
}
namespace
{
team::CONTROLLER unified_controller(team::CONTROLLER c)

View file

@ -72,6 +72,12 @@ public:
(ALWAYS, "always")
)
MAKE_ENUM(SHARE_VISION,
(ALL, "all")
(SHROUD, "shroud")
(NONE, "none")
)
private:
class shroud_map {
public:
@ -139,8 +145,7 @@ private:
PROXY_CONTROLLER proxy_controller; // when controller == HUMAN, the proxy controller determines what input method is actually used.
// proxy controller is an interface property, not gamestate. it is not synced, not known to server.
// also not saved in save game file
bool share_maps, share_view;
SHARE_VISION share_vision;
bool disallow_observers;
bool allow_player;
bool chose_random;
@ -158,6 +163,7 @@ private:
bool carryover_add;
bool carryover_bonus;
int carryover_gold;
void handle_legacy_share_vision(const config& cfg);
};
static const int default_team_gold_;
@ -363,11 +369,6 @@ public:
void log_recruitable() const;
/**set the share maps attribute */
void set_share_maps( bool share_maps );
/**set the share view attribute */
void set_share_view( bool share_view );
/** clear the shroud, fog, and enemies cache for all teams*/
static void clear_caches();
@ -376,9 +377,14 @@ public:
config to_config() const;
bool share_maps() const { return info_.share_maps; }
bool share_view() const { return info_.share_view; }
bool share_maps() const { return info_.share_vision != SHARE_VISION::NONE ; }
bool share_view() const { return info_.share_vision == SHARE_VISION::ALL; }
SHARE_VISION share_vision() const { return info_.share_vision; }
void handle_legacy_share_vision(const config& cfg)
{
info_.handle_legacy_share_vision(cfg);
}
std::string allied_human_teams() const;
private: