added 'delayed map sharing' for allies.

fixed bug where capturing a village wouldn't end one's turn.
This commit is contained in:
uid68803 2004-01-06 22:05:56 +00:00
parent ecd643a909
commit 0b09efaefa
8 changed files with 88 additions and 14 deletions

View file

@ -306,6 +306,7 @@ ggggggggggggggggggggffffffffffffffffff
recruit=Elvish Fighter,Elvish Archer,Mage,Elvish Shaman,Gryphon Rider,Thief,Elvish Scout
recruitment_pattern=fighter,fighter,scout
music="wesnoth-4.ogg"
terrain_liked=fwc
[/multiplayer_side]
[multiplayer_side]
@ -314,6 +315,7 @@ ggggggggggggggggggggffffffffffffffffff
recruit=Orcish Grunt,Troll Whelp,Wolf Rider,Orcish Archer,Orcish Assassin,Naga
recruitment_pattern=fighter,fighter,archer,scout
music="wesnoth-5.ogg"
terrain_liked=hmw
[/multiplayer_side]
[multiplayer_side]
@ -322,6 +324,7 @@ ggggggggggggggggggggffffffffffffffffff
recruit=Cavalry,Mage,Spearman,Fencer,Heavy Infantry,Horseman,Merman
recruitment_pattern=scout,fighter,fighter,fighter
music="wesnoth-2.ogg"
terrain_liked=gcs
[/multiplayer_side]
[multiplayer_side]
@ -330,4 +333,5 @@ ggggggggggggggggggggffffffffffffffffff
recruit=Skeleton,Skeleton Archer,Walking Corpse,Ghost,Vampire Bat,Dark Adept
recruitment_pattern=scout,fighter,fighter,archer
music="wesnoth-3.ogg"
terrain_liked=whc
[/multiplayer_side]

View file

@ -1088,7 +1088,7 @@ size_t move_unit(display* disp, const game_data& gamedata, const gamemap& map,
assert(!route.empty());
const unit_map::iterator ui = units.find(route.front());
unit_map::iterator ui = units.find(route.front());
assert(ui != units.end());
@ -1179,7 +1179,7 @@ size_t move_unit(display* disp, const game_data& gamedata, const gamemap& map,
u.set_movement(moves_left);
units.insert(std::pair<gamemap::location,unit>(steps.back(),u));
ui = units.insert(std::pair<gamemap::location,unit>(steps.back(),u)).first;
if(disp != NULL) {
disp->invalidate_unit();
disp->invalidate(steps.back());
@ -1191,7 +1191,7 @@ size_t move_unit(display* disp, const game_data& gamedata, const gamemap& map,
if(orig_tower_owner != team_num) {
get_tower(steps.back(),teams,team_num,units);
u.set_movement(0);
ui->second.set_movement(0);
}
}

View file

@ -545,6 +545,9 @@ int play_multiplayer(display& disp, game_data& units_data, config cfg,
//generate the random map
(*level_ptr)["map_data"] = generator->create_map(std::vector<std::string>());
map_changed = true;
//set the scenario to have placing of sides based on the terrain they prefer
(*level_ptr)["modify_placing"] = "true";
}
if(map_changed) {

View file

@ -383,8 +383,7 @@ void mp_connect::gui_update()
//Player Color
//Player Gold
std::string str;
str = side["gold"];
std::string str = side["gold"];
sliders_gold_[n].set_value((atoi(str.c_str()) - 20 + 0.0) / 979.0);
rect.x = (disp_->x() - width_) / 2 + 603;
rect.y = (disp_->y() - height_) / 2 + 55 + (30 * n);

View file

@ -29,6 +29,27 @@
#include <iostream>
#include <iterator>
namespace {
int placing_score(const config& side, const gamemap& map, const gamemap::location& pos)
{
int positions = 0, liked = 0;
const std::string& terrain_liked = side["terrain_liked"];
for(int i = pos.x-10; i != pos.x+10; ++i) {
for(int j = pos.y-10; j != pos.y+10; ++j) {
const gamemap::location pos(i,j);
if(map.on_board(pos)) {
++positions;
if(std::count(terrain_liked.begin(),terrain_liked.end(),map.underlying_terrain(map[i][j]))) {
++liked;
}
}
}
}
return (100*liked)/positions;
}
}
LEVEL_RESULT play_level(game_data& gameinfo, config& game_config,
config* level, CVideo& video,
game_state& state_of_game,
@ -56,6 +77,9 @@ LEVEL_RESULT play_level(game_data& gameinfo, config& game_config,
int first_human_team = -1;
const bool modify_placing = (*level)["modify_placing"] == "true";
std::set<int> taken_places;
const config::child_list& unit_cfg = level->get_children("side");
for(config::child_list::const_iterator ui = unit_cfg.begin(); ui != unit_cfg.end(); ++ui) {
@ -90,7 +114,27 @@ LEVEL_RESULT play_level(game_data& gameinfo, config& game_config,
}
}
const gamemap::location& start_pos = map.starting_position(new_unit.side());
int start = new_unit.side();
if(modify_placing) {
int best = -1, current = -1;
for(int i = 1; i <= unit_cfg.size(); ++i) {
if(taken_places.count(i))
continue;
const int res = placing_score(**ui,map,map.starting_position(i));
if(current == -1 || res > best) {
current = res;
best = i;
}
}
start = best;
taken_places.insert(start);
}
assert(start != -1);
const gamemap::location& start_pos = map.starting_position(start);
if(!start_pos.valid() && new_unit.side() == 1) {
throw gamestatus::load_game_failed("No starting position for side 1");
@ -367,12 +411,13 @@ LEVEL_RESULT play_level(game_data& gameinfo, config& game_config,
std::cerr << "finished networked...\n";
}
for(unit_map::iterator uit = units.begin();
uit != units.end(); ++uit) {
for(unit_map::iterator uit = units.begin(); uit != units.end(); ++uit) {
if(uit->second.side() == player_number)
uit->second.end_turn();
}
team_it->get_shared_maps();
game_events::pump();
check_victory(units,teams);

View file

@ -483,7 +483,7 @@ bool do_replay(display& disp, const gamemap& map, const game_data& gameinfo,
const gamemap::location src(*source);
const gamemap::location dst(*destination);
const std::map<gamemap::location,unit>::iterator u = units.find(src);
std::map<gamemap::location,unit>::iterator u = units.find(src);
if(u == units.end()) {
std::cerr << "unfound location for source of movement: "
<< (src.x+1) << "," << (src.y+1) << "-"
@ -526,11 +526,11 @@ bool do_replay(display& disp, const gamemap& map, const game_data& gameinfo,
disp.move_unit(rt->second.steps,current_unit);
current_unit.set_movement(rt->second.move_left);
units.insert(std::pair<gamemap::location,unit>(dst,current_unit));
u = units.insert(std::pair<gamemap::location,unit>(dst,current_unit)).first;
if(map.underlying_terrain(map[dst.x][dst.y]) == gamemap::TOWER) {
const int orig_owner = tower_owner(dst,teams) + 1;
if(orig_owner != team_num) {
current_unit.set_movement(0);
u->second.set_movement(0);
get_tower(dst,teams,team_num-1,units);
}
}

View file

@ -125,6 +125,7 @@ team::team_info::team_info(const config& cfg)
use_shroud = (cfg["shroud"] == "yes");
use_fog = (cfg["fog"] == "yes");
share_maps = (cfg["share_maps"] != "no");
music = cfg["music"];
}
@ -194,6 +195,7 @@ void team::team_info::write(config& cfg) const
cfg["shroud"] = use_shroud ? "yes" : "no";
cfg["fog"] = use_fog ? "yes" : "no";
cfg["share_maps"] = share_maps ? "yes" : "no";
if(music.empty() == false)
cfg["music"] = music;
@ -289,6 +291,26 @@ void team::new_turn()
gold_ += income();
}
void team::get_shared_maps()
{
if(teams == NULL || info_.team_name == "" || info_.share_maps == false)
return;
for(std::vector<team>::const_iterator t = teams->begin(); t != teams->end(); ++t) {
if(t->info_.team_name != info_.team_name)
continue;
const shroud_map& v = t->shroud_;
for(size_t x = 0; x != v.size(); ++x) {
for(size_t y = 0; y != v[x].size(); ++y) {
if(v[x][y]) {
clear_shroud(x,y);
}
}
}
}
}
void team::spend_gold(int amount)
{
gold_ -= amount;

View file

@ -55,7 +55,7 @@ public:
std::vector<target> targets;
bool use_shroud, use_fog;
bool use_shroud, use_fog, share_maps;
std::string music;
};
@ -73,6 +73,7 @@ public:
int gold() const;
int income() const;
void new_turn();
void get_shared_maps();
void spend_gold(int amount);
const std::set<std::string>& recruits() const;
@ -108,8 +109,8 @@ private:
int gold_;
std::set<gamemap::location> towers_;
std::vector<std::vector<bool> > shroud_;
std::vector<std::vector<bool> > fog_;
typedef std::vector<std::vector<bool> > shroud_map;
shroud_map shroud_, fog_;
team_info info_;
};