made multiplayer lobby work in modes below 1024x768

This commit is contained in:
uid68803 2004-01-01 15:35:55 +00:00
parent e33a45f397
commit 682376baad
7 changed files with 62 additions and 40 deletions

View file

@ -45,8 +45,8 @@ Defeat:
canrecruit=1 canrecruit=1
controller=ai controller=ai
recruitment_pattern=fighter recruitment_pattern=fighter
recruit=Swordsman,Heavy Infantry,Pikeman recruit=Swordsman,Heavy Infantry,Pikeman,Red Mage
gold=100 gold=200
enemy=3 enemy=3
[/side] [/side]
[side] [side]

View file

@ -2,7 +2,7 @@
name=Royal Guard name=Royal Guard
race=human race=human
image=human-royalguard.png image=human-royalguard.png
hitpoints=60 hitpoints=75
movement_type=smallfoot movement_type=smallfoot
movement=6 movement=6
experience=500 experience=500

View file

@ -6,7 +6,7 @@ ability=regenerates
hitpoints=55 hitpoints=55
movement_type=largefoot movement_type=largefoot
movement=5 movement=5
experience=36 experience=52
level=2 level=2
alignment=chaotic alignment=chaotic
advanceto=Troll Warrior advanceto=Troll Warrior

View file

@ -50,7 +50,7 @@ private:
std::string recruit_unit(const gamemap& map, int side, std::string recruit_unit(const gamemap& map, int side,
std::map<gamemap::location,unit>& units, unit& new_unit, std::map<gamemap::location,unit>& units, unit& new_unit,
gamemap::location recruit_location, display* disp, bool need_castle) gamemap::location recruit_location, display* disp, bool need_castle, bool full_movement)
{ {
std::cerr << "recruiting unit for side " << side << "\n"; std::cerr << "recruiting unit for side " << side << "\n";
typedef std::map<gamemap::location,unit> units_map; typedef std::map<gamemap::location,unit> units_map;
@ -89,8 +89,13 @@ std::string recruit_unit(const gamemap& map, int side,
return string_table["no_recruit_location"]; return string_table["no_recruit_location"];
} }
if(full_movement) {
new_unit.set_movement(new_unit.total_movement());
} else {
new_unit.set_movement(0); new_unit.set_movement(0);
new_unit.set_attacked(); new_unit.set_attacked();
}
units.insert(std::pair<gamemap::location,unit>( units.insert(std::pair<gamemap::location,unit>(
recruit_location,new_unit)); recruit_location,new_unit));

View file

@ -41,7 +41,7 @@
//describing why not will be returned. On success, the return string is empty //describing why not will be returned. On success, the return string is empty
std::string recruit_unit(const gamemap& map, int team, unit_map& units, std::string recruit_unit(const gamemap& map, int team, unit_map& units,
unit& u, gamemap::location preferred_location, unit& u, gamemap::location preferred_location,
display *disp=NULL, bool need_castle=true); display *disp=NULL, bool need_castle=true, bool full_movement=false);
//a structure which defines all the statistics for a potential //a structure which defines all the statistics for a potential
//battle that could take place. //battle that could take place.

View file

@ -542,7 +542,7 @@ void event_handler::handle_event_command(const queued_event& event_info, const s
std::vector<unit>& avail = state_of_game->available_units; std::vector<unit>& avail = state_of_game->available_units;
for(std::vector<unit>::iterator u = avail.begin(); u != avail.end(); ++u) { for(std::vector<unit>::iterator u = avail.begin(); u != avail.end(); ++u) {
if(u->matches_filter(cfg)) { if(u->matches_filter(cfg)) {
recruit_unit(*game_map,1,*units,*u,gamemap::location(),screen,false); recruit_unit(*game_map,1,*units,*u,gamemap::location(),screen,false,true);
avail.erase(u); avail.erase(u);
break; break;
} }
@ -677,12 +677,23 @@ void event_handler::handle_event_command(const queued_event& event_info, const s
} }
const std::string& lang_message = string_table[id]; const std::string& lang_message = string_table[id];
int option_chosen = gui::show_dialog(*screen,surface,caption, int option_chosen = -1;
//if we're not replaying, or if there is no choice to be made, show
//the dialog.
if(recorder.at_end() == false || options.empty()) {
option_chosen = gui::show_dialog(*screen,surface,caption,
lang_message.empty() ? cfg["message"] : lang_message, lang_message.empty() ? cfg["message"] : lang_message,
options.empty() ? gui::MESSAGE : gui::OK_ONLY, options.empty() ? gui::MESSAGE : gui::OK_ONLY,
options.empty() ? NULL : &options); options.empty() ? NULL : &options);
if(screen->update_locked() && options.empty() == false) { if(options.empty() == false) {
recorder.choose_option(option_chosen);
}
}
//otherwise if a choice has to be made, get it from the replay data
else if(options.empty() == false) {
const config* const action = recorder.get_next_action(); const config* const action = recorder.get_next_action();
if(action == NULL || action->get_children("choose").empty()) { if(action == NULL || action->get_children("choose").empty()) {
std::cerr << "choice expected but none found\n"; std::cerr << "choice expected but none found\n";
@ -695,11 +706,9 @@ void event_handler::handle_event_command(const queued_event& event_info, const s
const std::string& val = (*(action->get_children("choose").front()))["value"]; const std::string& val = (*(action->get_children("choose").front()))["value"];
option_chosen = atol(val.c_str()); option_chosen = atol(val.c_str());
} else if(options.empty() == false) {
recorder.choose_option(option_chosen);
} }
//implement the consequences of the choice
if(options.empty() == false) { if(options.empty() == false) {
assert(size_t(option_chosen) < menu_items.size()); assert(size_t(option_chosen) < menu_items.size());

View file

@ -14,16 +14,23 @@
#include <sstream> #include <sstream>
namespace {
int xscale(display& disp, int x)
{
return (x*disp.x())/1024;
}
int yscale(display& disp, int y)
{
return (y*disp.y())/768;
}
}
namespace lobby { namespace lobby {
RESULT enter(display& disp, config& game_data) RESULT enter(display& disp, config& game_data)
{ {
//prevent entry into the lobby if mode is less than 1024x768 const events::resize_lock prevent_resizing;
//FIXME: the lobby should be fixed properly
if(disp.x() < 1024 || disp.y() < 768) {
gui::show_dialog(disp,NULL,"","You currently cannot enter the lobby with a resolution of less than 1024x768 (we're working on this)",gui::OK_ONLY);
return QUIT;
}
CKey key; CKey key;
@ -31,7 +38,8 @@ RESULT enter(display& disp, config& game_data)
gui::textbox message_entry(disp,500); gui::textbox message_entry(disp,500);
const scoped_sdl_surface background(image::get_image("misc/lobby.png",image::UNSCALED)); scoped_sdl_surface background(image::get_image("misc/lobby.png",image::UNSCALED));
background.assign(scale_surface(background,disp.x(),disp.y()));
update_whole_screen(); update_whole_screen();
@ -39,8 +47,6 @@ RESULT enter(display& disp, config& game_data)
if(background != NULL) if(background != NULL)
SDL_BlitSurface(background, NULL, disp.video().getSurface(), NULL); SDL_BlitSurface(background, NULL, disp.video().getSurface(), NULL);
std::cerr << "game data: " << game_data.write() << "\n";
// Display Chats // Display Chats
std::stringstream text; std::stringstream text;
for(size_t n = messages.size() > 8 ? messages.size()-8 : 0; for(size_t n = messages.size() > 8 ? messages.size()-8 : 0;
@ -48,9 +54,11 @@ RESULT enter(display& disp, config& game_data)
text << messages[n] << "\n"; text << messages[n] << "\n";
} }
font::draw_text(&disp,disp.screen_area(),12,font::NORMAL_COLOUR, const SDL_Rect chat_area = { xscale(disp,19), yscale(disp,574), xscale(disp,832), yscale(disp,130) };
text.str(),19,574);
update_rect(19,574,832,130); font::draw_text(&disp,chat_area,12,font::NORMAL_COLOUR,
text.str(),xscale(disp,19),yscale(disp,574));
update_rect(chat_area);
// Game List GUI // Game List GUI
const config* const gamelist = game_data.child("gamelist"); const config* const gamelist = game_data.child("gamelist");
@ -88,17 +96,17 @@ RESULT enter(display& disp, config& game_data)
gui::menu users_menu(disp,users); gui::menu users_menu(disp,users);
// Set GUI locations // Set GUI locations
users_menu.set_loc(869,23); users_menu.set_loc(xscale(disp,869),yscale(disp,23));
users_menu.set_width(129); users_menu.set_width(xscale(disp,129));
update_rect(869,23,129,725); update_rect(xscale(disp,869),yscale(disp,23),xscale(disp,129),yscale(disp,725));
games_menu.set_loc(19,23); games_menu.set_loc(xscale(disp,19),yscale(disp,23));
games_menu.set_width(832); games_menu.set_width(xscale(disp,832));
update_rect(19,23,832,520); update_rect(xscale(disp,19),yscale(disp,23),xscale(disp,832),yscale(disp,520));
join_game.set_xy(19,545); join_game.set_xy(xscale(disp,19),yscale(disp,545));
new_game.set_xy(19+join_game.width()+5,545); new_game.set_xy(xscale(disp,19)+join_game.width()+5,yscale(disp,545));
quit_game.set_xy(19+join_game.width()+5+new_game.width()+5,545); quit_game.set_xy(xscale(disp,19)+join_game.width()+5+new_game.width()+5,yscale(disp,545));
message_entry.set_position(19,725); message_entry.set_position(xscale(disp,19),yscale(disp,725));
message_entry.set_width(832); message_entry.set_width(xscale(disp,832));
update_whole_screen(); update_whole_screen();