mirror of
https://github.com/wesnoth/wesnoth
synced 2025-04-26 20:04:11 +00:00
made it so all players can see enemy's possible movements in multiplayer
This commit is contained in:
parent
90b276735c
commit
1f7988569d
2
Makefile
2
Makefile
@ -8,7 +8,7 @@ SDL_CFLAGS=`sdl-config --cflags` `freetype-config --cflags`
|
||||
SDL_LIBS=`sdl-config --libs` `freetype-config --libs` -lSDL_mixer -lSDL_ttf -lSDL_image -lSDL_net
|
||||
LIBS=${SDL_LIBS} -lstdc++
|
||||
INCLUDES=-I. -Isrc -Isrc/tools -Isrc/widgets
|
||||
OBJS=src/actions.o src/ai.o src/ai_attack.o src/ai_move.o src/config.o src/dialogs.o src/display.o src/filesystem.o src/font.o src/game.o src/game_config.o src/game_events.o src/gamestatus.o src/hotkeys.o src/intro.o src/key.o src/language.o src/log.o src/map.o src/multiplayer.o src/network.o src/pathfind.o src/playlevel.o src/playturn.o src/preferences.o src/replay.o src/sdl_utils.o src/show_dialog.o src/sound.o src/team.o src/terrain.o src/tooltips.o src/unit.o src/unit_types.o src/video.o src/widgets/button.o src/widgets/menu.o src/widgets/slider.o src/widgets/textbox.o
|
||||
OBJS=src/actions.o src/ai.o src/ai_attack.o src/ai_move.o src/config.o src/dialogs.o src/display.o src/filesystem.o src/font.o src/game.o src/game_config.o src/game_events.o src/gamestatus.o src/hotkeys.o src/intro.o src/key.o src/language.o src/log.o src/map.o src/multiplayer.o src/multiplayer_client.o src/network.o src/pathfind.o src/playlevel.o src/playturn.o src/preferences.o src/replay.o src/sdl_utils.o src/show_dialog.o src/sound.o src/team.o src/terrain.o src/tooltips.o src/unit.o src/unit_types.o src/video.o src/widgets/button.o src/widgets/menu.o src/widgets/slider.o src/widgets/textbox.o
|
||||
|
||||
MAKE_TRANS_OBJS=src/tools/make_translation.o src/config.o src/filesystem.o src/log.o
|
||||
MERGE_TRANS_OBJS=src/tools/merge_translations.o src/config.o src/filesystem.o src/log.o
|
||||
|
@ -134,6 +134,7 @@ position_vacant="Available"
|
||||
|
||||
host_game="Host Multiplayer Game"
|
||||
join_game="Join Networked Multiplayer Game"
|
||||
create_new_game="Create Game"
|
||||
|
||||
quit_message="Do you really want to quit?"
|
||||
|
||||
|
@ -1022,7 +1022,7 @@ void display::draw_tile(int x, int y, SDL_Surface* unit_image,
|
||||
}
|
||||
|
||||
const int maxlen = static_cast<int>(zoom_) - xoffset*2;
|
||||
int len = ((xend - xdst) > maxlen) ? maxlen : xend - xdst;
|
||||
int len = minimum(xend - xdst,maxlen);
|
||||
|
||||
const int neoffset = ne_xpos+ne_xoffset;
|
||||
const int seoffset = se_xpos+se_xoffset;
|
||||
@ -1040,14 +1040,22 @@ void display::draw_tile(int x, int y, SDL_Surface* unit_image,
|
||||
}
|
||||
|
||||
const int srcy = minimum<int>(yloc,surface->h-1);
|
||||
assert(srcy >= 0);
|
||||
|
||||
surface_lock srclock(surface);
|
||||
short* startsrc = srclock.pixels() + srcy*(surface->w+xpad) +
|
||||
(xoffset > xsrc ? xoffset:xsrc);
|
||||
maximum(xoffset,xsrc);
|
||||
short* endsrc = startsrc + len;
|
||||
|
||||
assert(startsrc >= srclock.pixels() &&
|
||||
endsrc <= srclock.pixels() + (surface->w+xpad)*surface->h);
|
||||
if(!(startsrc >= srclock.pixels() &&
|
||||
endsrc <= srclock.pixels() + (surface->w+xpad)*surface->h)) {
|
||||
std::cerr << "CRITICAL ERROR: overwrite at " << __FILE__ << ","
|
||||
<< __LINE__ << "\n"
|
||||
<< "len: " << len << "\n"
|
||||
<< "width: " << surface->w << "\n"
|
||||
<< "x: " << x << "\n"
|
||||
<< "y: " << y << "\n";
|
||||
}
|
||||
|
||||
surface_lock dstlock(dst);
|
||||
short* startdst = dstlock.pixels() + j*dst->w + xdst;
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include "language.hpp"
|
||||
#include "log.hpp"
|
||||
#include "multiplayer.hpp"
|
||||
#include "multiplayer_client.hpp"
|
||||
#include "network.hpp"
|
||||
#include "playlevel.hpp"
|
||||
#include "replay.hpp"
|
||||
@ -76,7 +77,8 @@ int connection_acceptor::do_action()
|
||||
|
||||
sock = 0;
|
||||
|
||||
//if the problem isn't related to any specific connection
|
||||
//if the problem isn't related to any specific connection,
|
||||
//it's a general error and we should just re-throw the error
|
||||
if(!e.socket) {
|
||||
throw e;
|
||||
}
|
||||
@ -209,109 +211,6 @@ bool accept_network_connections(display& disp, config& players)
|
||||
|
||||
}
|
||||
|
||||
void play_multiplayer_client(display& disp, game_data& units_data, config& cfg,
|
||||
game_state& state)
|
||||
{
|
||||
const network::manager net_manager;
|
||||
|
||||
std::string host;
|
||||
const int res = gui::show_dialog(disp,NULL,"","",
|
||||
gui::OK_CANCEL,NULL,NULL,
|
||||
string_table["remote_host"] + ": ",&host);
|
||||
if(res != 0 || host.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
network::connection sock;
|
||||
|
||||
sock = network::connect(host);
|
||||
config sides;
|
||||
|
||||
network::connection data_res = network::receive_data(sides,0,10000);
|
||||
|
||||
if(!data_res) {
|
||||
throw network::error(string_table["connection_timeout"]);
|
||||
}
|
||||
|
||||
std::map<int,int> choice_map;
|
||||
std::vector<std::string> choices;
|
||||
|
||||
std::vector<config*>& sides_list = sides.children["side"];
|
||||
for(std::vector<config*>::iterator s = sides_list.begin();
|
||||
s != sides_list.end(); ++s) {
|
||||
if((*s)->values["controller"] == "network" &&
|
||||
(*s)->values["taken"] != "yes") {
|
||||
choice_map[choices.size()] = 1 + s - sides_list.begin();
|
||||
choices.push_back((*s)->values["name"] + " - " +
|
||||
(*s)->values["type"]);
|
||||
}
|
||||
}
|
||||
|
||||
const int choice = gui::show_dialog(disp,NULL,"","Choose side:",
|
||||
gui::OK_CANCEL,&choices);
|
||||
if(choice < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const int team_num = choice_map[choice];
|
||||
|
||||
//send our choice of team to the server
|
||||
{
|
||||
config response;
|
||||
std::stringstream stream;
|
||||
stream << team_num;
|
||||
response.values["side"] = stream.str();
|
||||
network::send_data(response);
|
||||
}
|
||||
|
||||
bool got_side = false;
|
||||
|
||||
for(;;) {
|
||||
config reply;
|
||||
data_res = network::receive_data(reply,0,100);
|
||||
if(data_res) {
|
||||
if(reply.values["failed"] == "yes") {
|
||||
got_side = false;
|
||||
break;
|
||||
} else if(reply.values["side_secured"].size() > 0) {
|
||||
got_side = true;
|
||||
} else if(reply.children["start_game"].empty() == false) {
|
||||
break;
|
||||
} else {
|
||||
sides = reply;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!got_side) {
|
||||
throw network::error("Choice of team unavailable.");
|
||||
}
|
||||
|
||||
//we want to make the network/human players look right from our
|
||||
//perspective
|
||||
{
|
||||
std::vector<config*>& sides_list = sides.children["side"];
|
||||
for(std::vector<config*>::iterator side = sides_list.begin();
|
||||
side != sides_list.end(); ++side) {
|
||||
string_map& values = (*side)->values;
|
||||
if(team_num-1 == side - sides_list.begin())
|
||||
values["controller"] = "human";
|
||||
else
|
||||
values["controller"] = "network";
|
||||
}
|
||||
}
|
||||
|
||||
std::cerr << "starting game\n";
|
||||
|
||||
state.starting_pos = sides;
|
||||
|
||||
recorder.set_save_info(state);
|
||||
|
||||
std::vector<config*> story;
|
||||
play_level(units_data,cfg,&sides,disp.video(),state,story);
|
||||
recorder.clear();
|
||||
}
|
||||
|
||||
void play_multiplayer(display& disp, game_data& units_data, config& cfg,
|
||||
game_state& state)
|
||||
{
|
||||
|
@ -169,10 +169,18 @@ void play_turn(game_data& gameinfo, game_state& state_of_game,
|
||||
if(u != units.end() && u->second.side() != team_num) {
|
||||
const bool ignore_zocs = u->second.type().is_skirmisher();
|
||||
const bool teleport = u->second.type().teleports();
|
||||
|
||||
//temporarily set moves to full to see how far
|
||||
//it could move
|
||||
const int movement = u->second.movement_left();
|
||||
u->second.set_movement(u->second.total_movement());
|
||||
current_paths = paths(map,gameinfo,units,new_hex,teams,
|
||||
ignore_zocs,teleport);
|
||||
gui.set_paths(¤t_paths);
|
||||
enemy_paths = true;
|
||||
|
||||
//restore unit's movement
|
||||
u->second.set_movement(movement);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user