[Widelands-cvs] widelands/src building.cc,1.103,1.104 building_statistics_menu.cc,1.8,1.9 building_u
Status: Beta
Brought to you by:
sirver
Update of /cvsroot/widelands/widelands/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18130/src Modified Files: building.cc building_statistics_menu.cc building_ui.cc constants.h constructionsite.cc criterr.cc event_allow_building.cc event_conquer_area.cc event_factory.cc event_message_box.cc event_message_box_message_box.cc event_move_view.cc event_set_null_trigger.cc event_unhide_area.cc event_unhide_objective.cc fieldaction.cc game.cc game_chat_menu.cc game_debug_ui.cc game_main_menu.cc game_main_menu_load_game.cc game_main_menu_save_game.cc game_options_menu.cc game_server_proto_packet_chatmessage.cc game_server_proto_packet_connect.cc game_server_proto_packet_getroominfo.cc game_server_proto_packet_getuserinfo.cc general_statistics_menu.cc interactive_player.cc main.cc map_objective_manager.h map_variable_manager.cc minimap.cc network.cc playerdescrgroup.cc productionsite.cc profile.cc s2map.cc sound_handler.cc stock_menu.cc system.cc system.h trainingsite.cc tribe.cc trigger_building.cc trigger_factory.cc trigger_null.cc trigger_time.cc ware.cc ware_statistics_menu.cc waresdisplay.cc watchwindow.cc wlapplication.cc wlapplication.h worker.cc world.cc Log Message: - WLApplication patch #6/12 Move i18n code into WLApplication. This only looks big, it changes a lot of includes. Index: game_debug_ui.cc =================================================================== RCS file: /cvsroot/widelands/widelands/src/game_debug_ui.cc,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- game_debug_ui.cc 7 Nov 2005 17:49:23 -0000 1.11 +++ game_debug_ui.cc 29 Apr 2006 15:00:52 -0000 1.12 @@ -31,6 +31,7 @@ #include "ui_panel.h" #include "ui_tabpanel.h" #include "ui_window.h" +#include "wlapplication.h" /* ============================================================================== Index: minimap.cc =================================================================== RCS file: /cvsroot/widelands/widelands/src/minimap.cc,v retrieving revision 1.38 retrieving revision 1.39 diff -u -d -r1.38 -r1.39 --- minimap.cc 22 Feb 2006 13:06:06 -0000 1.38 +++ minimap.cc 29 Apr 2006 15:00:52 -0000 1.39 @@ -26,6 +26,7 @@ #include "minimap.h" #include "rendertarget.h" #include "ui_button.h" +#include "wlapplication.h" /* ============================================================================== Index: ware.cc =================================================================== RCS file: /cvsroot/widelands/widelands/src/ware.cc,v retrieving revision 1.25 retrieving revision 1.26 diff -u -d -r1.25 -r1.26 --- ware.cc 7 Nov 2005 20:52:30 -0000 1.25 +++ ware.cc 29 Apr 2006 15:00:53 -0000 1.26 @@ -27,6 +27,7 @@ #include "wexception.h" #include "worker.h" #include "system.h" +#include "wlapplication.h" /* ============================================================================== Index: event_unhide_objective.cc =================================================================== RCS file: /cvsroot/widelands/widelands/src/event_unhide_objective.cc,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- event_unhide_objective.cc 17 Apr 2006 07:33:02 -0000 1.4 +++ event_unhide_objective.cc 29 Apr 2006 15:00:52 -0000 1.5 @@ -26,6 +26,7 @@ #include "map.h" #include "map_objective_manager.h" #include "profile.h" +#include "wlapplication.h" static const int EVENT_VERSION = 1; Index: game_main_menu.cc =================================================================== RCS file: /cvsroot/widelands/widelands/src/game_main_menu.cc,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- game_main_menu.cc 19 Feb 2006 16:04:37 -0000 1.7 +++ game_main_menu.cc 29 Apr 2006 15:00:52 -0000 1.8 @@ -30,6 +30,7 @@ #include "ui_button.h" #include "ui_textarea.h" #include "ware_statistics_menu.h" +#include "wlapplication.h" /* ============================================================================== @@ -51,19 +52,19 @@ { m_player=plr; m_windows = windows; - + int spacing = 5; int posy = 2*spacing; int posx = 2*spacing; - + // UIButtons int buttonw = (get_inner_w()-7*spacing) / 4; UIButton* b=new UIButton(this, posx, posy, buttonw, 34, 4, 1); b->set_pic(g_gr->get_picture( PicMod_Game, "pics/menu_general_stats.png" )); b->clickedid.set(this, &GameMainMenu::clicked); posx += buttonw + spacing; - + b=new UIButton(this, posx, posy, buttonw, 34, 4, 2); b->set_pic(g_gr->get_picture( PicMod_Game, "pics/menu_ware_stats.png" )); b->clickedid.set(this, &GameMainMenu::clicked); @@ -73,32 +74,32 @@ b->set_pic(g_gr->get_picture( PicMod_Game, "pics/menu_building_stats.png" )); b->clickedid.set(this, &GameMainMenu::clicked); posx += buttonw + spacing; - + b=new UIButton(this, posx, posy, buttonw, 34, 4, 4); b->set_pic(g_gr->get_picture( PicMod_Game, "pics/menu_stock.png" )); b->clickedid.set(this, &GameMainMenu::clicked); posx = 2*spacing; posy += 45; - + buttonw = (get_inner_w()-5*spacing) / 2; b=new UIButton(this, posx, posy, buttonw, 34, 4, 25); b->set_pic(g_gr->get_picture( PicMod_Game, "pics/menu_objectives.png" )); b->clickedid.set(this, &GameMainMenu::clicked); posx += buttonw + spacing; - + b=new UIButton(this, posx, posy, buttonw, 34, 4, 30); b->set_pic(g_gr->get_picture( PicMod_Game, "pics/menu_chat.png" )); b->clickedid.set(this, &GameMainMenu::clicked); posx = 2*spacing; posy += 45; - + buttonw = (get_inner_w()-4*spacing); b=new UIButton(this, posx, posy, buttonw, 34, 4, 50); b->set_pic(g_gr->get_picture( PicMod_Game, "pics/menu_options_menu.png" )); b->clickedid.set(this, &GameMainMenu::clicked); posx = 2*spacing; posy += 40; - + set_inner_size(get_inner_w(), posy+5); if (get_usedefaultpos()) center_to_parent(); @@ -109,7 +110,7 @@ case 1: // General Statistics if (m_windows->general_stats.window) - delete m_windows->general_stats.window; + delete m_windows->general_stats.window; else new General_Statistics_Menu(m_player, &m_windows->general_stats); break; @@ -117,7 +118,7 @@ case 2: // Wares statistics if (m_windows->ware_stats.window) - delete m_windows->ware_stats.window; + delete m_windows->ware_stats.window; else new Ware_Statistics_Menu(m_player, &m_windows->ware_stats); break; @@ -125,7 +126,7 @@ case 3: // Buildings statistics if (m_windows->building_stats.window) - delete m_windows->building_stats.window; + delete m_windows->building_stats.window; else new Building_Statistics_Menu(m_player, &m_windows->building_stats); break; @@ -133,23 +134,23 @@ case 4: // Global Stock if (m_windows->stock.window) - delete m_windows->stock.window; + delete m_windows->stock.window; else new Stock_Menu(m_player, &m_windows->stock); break; case 25: - // Mission Objectives + // Mission Objectives if (m_windows->objectives.window) - delete m_windows->objectives.window; + delete m_windows->objectives.window; else new GameObjectivesMenu(m_player, &m_windows->objectives, m_player->get_game()); break; - + case 30: // Chat Window if (m_windows->chat.window) - delete m_windows->chat.window; + delete m_windows->chat.window; else new GameChatMenu(m_player, &m_windows->chat, m_player->get_game()->get_netgame()); break; @@ -157,7 +158,7 @@ case 50: // Options Menu if (m_windows->options.window) - delete m_windows->options.window; + delete m_windows->options.window; else new GameOptionsMenu(m_player, &m_windows->options, m_windows); break; Index: trigger_null.cc =================================================================== RCS file: /cvsroot/widelands/widelands/src/trigger_null.cc,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- trigger_null.cc 17 Apr 2006 07:33:02 -0000 1.8 +++ trigger_null.cc 29 Apr 2006 15:00:53 -0000 1.9 @@ -23,6 +23,7 @@ #include "game.h" #include "profile.h" #include "system.h" +#include "wlapplication.h" static const int TRIGGER_VERSION = 1; Index: game_server_proto_packet_getroominfo.cc =================================================================== RCS file: /cvsroot/widelands/widelands/src/game_server_proto_packet_getroominfo.cc,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- game_server_proto_packet_getroominfo.cc 25 Nov 2005 20:27:54 -0000 1.7 +++ game_server_proto_packet_getroominfo.cc 29 Apr 2006 15:00:52 -0000 1.8 @@ -25,6 +25,7 @@ #include "util.h" #include "wexception.h" #include "system.h" +#include "wlapplication.h" /* * Constructor @@ -67,13 +68,13 @@ gsc->server_message( buffer ); return; } - + assert(flags == RI_ACK) ; ushort nrusers = buf->get_16(); std::vector< std::string > users; - + for(uint i = 0; i < nrusers; i++) { users.push_back( buf->get_string() ); } Index: event_conquer_area.cc =================================================================== RCS file: /cvsroot/widelands/widelands/src/event_conquer_area.cc,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- event_conquer_area.cc 17 Apr 2006 07:33:01 -0000 1.7 +++ event_conquer_area.cc 29 Apr 2006 15:00:52 -0000 1.8 @@ -25,6 +25,7 @@ #include "map.h" #include "profile.h" #include "system.h" +#include "wlapplication.h" static const int EVENT_VERSION = 1; Index: game_main_menu_save_game.cc =================================================================== RCS file: /cvsroot/widelands/widelands/src/game_main_menu_save_game.cc,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- game_main_menu_save_game.cc 17 Apr 2006 07:33:02 -0000 1.10 +++ game_main_menu_save_game.cc 29 Apr 2006 15:00:52 -0000 1.11 @@ -30,6 +30,7 @@ #include "ui_listselect.h" #include "ui_modal_messagebox.h" #include "ui_textarea.h" +#include "wlapplication.h" /* =============== Index: event_message_box.cc =================================================================== RCS file: /cvsroot/widelands/widelands/src/event_message_box.cc,v retrieving revision 1.15 retrieving revision 1.16 diff -u -d -r1.15 -r1.16 --- event_message_box.cc 17 Apr 2006 07:33:01 -0000 1.15 +++ event_message_box.cc 29 Apr 2006 15:00:52 -0000 1.16 @@ -29,6 +29,7 @@ #include "profile.h" #include "trigger_null.h" #include "util.h" +#include "wlapplication.h" static const int EVENT_VERSION = 1; Index: wlapplication.cc =================================================================== RCS file: /cvsroot/widelands/widelands/src/wlapplication.cc,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- wlapplication.cc 29 Apr 2006 13:57:23 -0000 1.5 +++ wlapplication.cc 29 Apr 2006 15:00:53 -0000 1.6 @@ -33,32 +33,12 @@ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -/* -=============== -get_playback_offset - -Returns the position in the playback file -=============== -*/ -int get_playback_offset() -{ - assert(WLApplication::get()->get_playback()); - - return ftell(WLApplication::get()->get_play_file()); -} - -/* -=============== -write_record_char -read_record_char -write_record_int -read_record_int -write_record_code -read_record_code - -Simple wrapper functions to make stdio file access less painful -=============== +/** + * Simple wrapper functions to make stdio file access less painful + * + * These will vanish when IO handling gets moved to C++ streams */ +//@{ void write_record_char(char v) { assert(WLApplication::get()->get_rec_file()); @@ -115,8 +95,9 @@ if (filecode != code) throw wexception("%08X: Bad code %02X during playback (%02X expected). Mismatching executable versions?", - get_playback_offset()-1, filecode, code); + WLApplication::get()->get_playback_offset()-1, filecode, code); } +//@} /* Notes on the implementation @@ -165,7 +146,7 @@ * \param argc The number of command line arguments * \param argv Array of command line arguments */ -WLApplication::WLApplication(int argc, char **argv):argc(argc),argv(argv) +WLApplication::WLApplication(int argc, char **argv):m_argc(argc),m_argv(argv) {} @@ -190,7 +171,7 @@ //create the filesystem abstraction //must be first - we wouldn't even find the config file g_fs = LayeredFileSystem::Create(); - setup_searchpaths(argc, argv); + setup_searchpaths(m_argc, m_argv); g_fh = new Font_Handler(); @@ -222,6 +203,86 @@ g_fs = 0; } +/** + * Grab a given TextDomain. We keep a stack + * if a new one is grabbed, it is pushed on the stack. + * On release, it is dropped and the previous + * one is re-grabbed instead. + * + * So when a tribe loads, it grabs it's textdomain + * loads all data and releases it -> we're back in + * widelands domain. Negative: We can't translate error + * messages. Who cares? + */ +void WLApplication::grab_textdomain( const char* domain) +{ + bind_textdomain_codeset (domain, "UTF-8"); + bindtextdomain( domain, LOCALE_PATH ); + textdomain(domain); + + m_textdomains.push_back( domain ); +} + +/** + * See \ref grab_textdomain() + */ +void WLApplication::release_textdomain() +{ + m_textdomains.pop_back(); + + //don't try to get the previous TD when the very first one ('widelands') just got dropped + if (m_textdomains.size()>0) { + const char* domain = m_textdomains.back().c_str(); + bind_textdomain_codeset (domain, "UTF-8"); + bindtextdomain( domain, LOCALE_PATH ); + textdomain(domain); + } +} + +/** + * Set The locale to the given string + */ +void WLApplication::set_locale( const char* str ) { + if( !str ) + str = ""; + + // Somehow setlocale doesn't behave same on + // some systems. +#ifdef __BEOS__ + setenv ("LANG", str, 1); + setenv ("LC_ALL", str, 1); +#endif +#ifdef __APPLE__ + setenv ("LANGUAGE", str, 1); + setenv ("LC_ALL", str, 1); +#endif + +#ifdef _WIN32 + const std::string env = std::string("LANG=") + str; + putenv(env.c_str()); +#endif + + setlocale(LC_ALL, str); //call to libintl + m_locale=str; + + if( m_textdomains.size() ) { + const char* domain = m_textdomains.back().c_str(); + bind_textdomain_codeset (domain, "UTF-8"); + bindtextdomain( domain, LOCALE_PATH ); + textdomain(domain); + } +} + +/** + * Returns the position in the playback file + */ +int WLApplication::get_playback_offset() +{ + assert(get_playback()); + + return ftell(get_play_file()); +} + bool WLApplication::init_settings() { Section *s=0; @@ -236,8 +297,8 @@ } // Set Locale and grab default domain - Sys_SetLocale( s->get_string( "language" )); - Sys_GrabTextdomain("widelands"); + set_locale( s->get_string( "language" )); + grab_textdomain("widelands"); // Input sys.should_die = false; @@ -278,7 +339,7 @@ void WLApplication::shutdown_settings() { // To be proper, release our textdomain - Sys_ReleaseTextdomain(); + release_textdomain(); // overwrite the old config file g_options.write("config", true); @@ -373,6 +434,9 @@ return true; } +/** + * Close any open journal file + */ void WLApplication::shutdown_recordplaybackfile() { if (m_record) { @@ -392,8 +456,8 @@ */ bool WLApplication::parse_command_line() { - for(int i = 1; i < argc; i++) { - std::string opt=argv[i]; + for(int i = 1; i < m_argc; i++) { + std::string opt=m_argv[i]; std::string value=""; //special case for help because it allows single-dash-options Index: network.cc =================================================================== RCS file: /cvsroot/widelands/widelands/src/network.cc,v retrieving revision 1.23 retrieving revision 1.24 diff -u -d -r1.23 -r1.24 --- network.cc 25 Nov 2005 19:28:24 -0000 1.23 +++ network.cc 29 Apr 2006 15:00:52 -0000 1.24 @@ -38,7 +38,7 @@ #include "fullscreen_menu_launchgame.h" #include "ui_window.h" #include "ui_table.h" - +#include "wlapplication.h" #define CHECK_SYNC_INTERVAL 2000 #define DELAY_PROBE_INTERVAL 10000 @@ -69,12 +69,12 @@ class Cmd_NetCheckSync:public BaseCommand { private: NetGame* netgame; - + public: Cmd_NetCheckSync (int dt, NetGame* ng) : BaseCommand (dt) { netgame=ng; } - + virtual void execute (Game* g); - + // Write these commands to a file (for savegames) virtual void Write(FileWrite*, Editor_Game_Base*, Widelands_Map_Map_Object_Saver*); virtual void Read(FileRead*, Editor_Game_Base*, Widelands_Map_Map_Object_Loader*); @@ -86,18 +86,18 @@ class NetStatusWindow:public UIWindow { public: NetStatusWindow (UIPanel*); - + void add_player (int); void set_ready (int); - + private: struct Entry { UITable_Entry* entry; int plnum; }; - + UITable* table; - + std::vector<Entry> entries; }; @@ -121,9 +121,9 @@ net_game_time=0; playernum=0; phase=PH_SETUP; - + players_changed=false; - + statuswnd=0; } @@ -134,10 +134,10 @@ void NetGame::run () { game=new Game(); - + game->enqueue_command ( new Cmd_NetCheckSync(game->get_gametime()+CHECK_SYNC_INTERVAL, this)); - + game->run_multi_player (this); delete game; @@ -147,16 +147,16 @@ void NetGame::begin_game () { int i; - + phase=PH_PREGAME; - + statuswnd=new NetStatusWindow(game->get_ipl()); statuswnd->center_to_parent (); - + for (i=0;i<MAX_PLAYERS;i++) if (player_human & (1<<i)) statuswnd->add_player (i+1); - + statuswnd->set_ready (playernum); player_ready=1<<(playernum-1); } @@ -169,11 +169,11 @@ NetGame::Chat_Message NetGame::get_chat_message () { assert (!chat_msg_queue.empty()); - + Chat_Message msg=chat_msg_queue.front(); - + chat_msg_queue.pop (); - + return msg; } @@ -183,7 +183,7 @@ uint NetGame::get_max_frametime () { uint game_time=game->get_gametime(); - + assert (game_time<=net_game_time); return net_game_time - game_time; @@ -192,7 +192,7 @@ void NetGame::disconnect_player (int plnum) { printf ("Player %d has been disconnected\n", plnum); - + // TODO: Let the computer take over this player } @@ -202,19 +202,19 @@ { IPaddress myaddr; int i; - + // create a listening socket SDLNet_ResolveHost (&myaddr, NULL, WIDELANDS_PORT); svsock=SDLNet_TCP_Open(&myaddr); - + sockset=SDLNet_AllocSocketSet(16); serializer=new Serializer(); - + playernum=1; - + net_delay=INITIAL_NETWORK_DELAY; next_ping_due=0; - + for (i=0;i<8;i++) net_delay_history[i]=INITIAL_NETWORK_DELAY; @@ -224,11 +224,11 @@ NetHost::~NetHost () { SDLNet_FreeSocketSet (sockset); - + // close all open sockets if (svsock!=0) SDLNet_TCP_Close (svsock); - + for (unsigned int i=0;i<clients.size();i++) SDLNet_TCP_Close (clients[i].sock); } @@ -238,19 +238,19 @@ void NetHost::update_map () { Map* map=game->get_map(); - + promoter->set_map (map?map->get_name():"none"); - + serializer->begin_packet (); serializer->putchar (NETCMD_SELECTMAP); serializer->putstr (map?map->get_filename():""); serializer->end_packet (); - + for (unsigned int i=0;i<clients.size();i++) serializer->send (clients[i].sock); - + playerdescr[0]->set_player_type (Player::playerLocal); - + send_player_info (); } @@ -258,24 +258,24 @@ { Player* pl; int i; - + player_enabled=0; player_human=0; - + for (i=0;i<MAX_PLAYERS;i++) if ((pl=game->get_player(i+1))!=0) { player_enabled|=1<<i; - + if (pl->get_type()!=Player::playerAI) player_human|=1<<i; } - + serializer->begin_packet (); serializer->putchar (NETCMD_PLAYERINFO); serializer->putchar (player_enabled); serializer->putchar (player_human); serializer->end_packet (); - + for (unsigned int i=0;i<clients.size();i++) serializer->send (clients[i].sock); } @@ -286,21 +286,21 @@ { delete promoter; promoter=0; - + SDLNet_TCP_Close (svsock); svsock=0; - + common_rand_seed=rand(); game->logic_rand_seed (common_rand_seed); - + serializer->begin_packet (); serializer->putchar (NETCMD_BEGIN_PREGAME); serializer->putlong (common_rand_seed); serializer->end_packet (); - + for (unsigned int i=0;i<clients.size();i++) serializer->send (clients[i].sock); - + NetGame::begin_game (); } @@ -308,40 +308,40 @@ { TCPsocket sock; unsigned int i,j; - + if (promoter!=0) promoter->run (); - + // if we are in the game initiation phase, check for new connections while (svsock!=0 && (sock=SDLNet_TCP_Accept(svsock))!=0) { Player* pl=0; - + for (i=1;i<=MAX_PLAYERS;i++) if ((pl=game->get_player(i))!=0 && pl->get_type()==Player::playerAI) break; - + if (pl==0) { // sorry, but there no room on this map for any more players SDLNet_TCP_Close (sock); continue; } - + SDLNet_TCP_AddSocket (sockset, sock); - + const char* tribe=pl->get_tribe()->get_name(); - + game->remove_player (i); game->add_player (i, Player::playerRemote, tribe, _("I have no name")); - + Client peer; peer.sock=sock; peer.deserializer=new Deserializer(); peer.playernum=i; clients.push_back (peer); - + players_changed=true; - + playerdescr[i-1]->set_player_type (Player::playerRemote); - + serializer->begin_packet (); serializer->putchar (NETCMD_HELLO); serializer->putchar (i); @@ -351,33 +351,33 @@ serializer->putstr (map?map->get_filename():""); serializer->end_packet (); serializer->send (peer.sock); - + send_player_info (); } - + // check if we hear anything from our peers while (SDLNet_CheckSockets(sockset, 0) > 0) for (i=0;i<clients.size();i++) if (SDLNet_SocketReady(clients[i].sock)) { if (!clients[i].deserializer->read_packet(clients[i].sock)) continue; - + // the network connection to this player has been closed SDLNet_TCP_DelSocket (sockset, clients[i].sock); SDLNet_TCP_Close (clients[i].sock); - + disconnect_player (clients[i].playernum); serializer->begin_packet (); serializer->putchar (NETCMD_DISCONNECT_PLAYER); serializer->putchar (clients[i].playernum); serializer->end_packet (); - + clients.erase (clients.begin()+i); - + for (i=0;i<clients.size();i++) serializer->send (clients[i].sock); - + break; } @@ -388,24 +388,24 @@ case NETCMD_READY: assert (phase==PH_PREGAME); assert (statuswnd!=0); - + statuswnd->set_ready (clients[i].playernum); - + player_ready|=1<<(clients[i].playernum-1); - + serializer->begin_packet (); serializer->putchar (NETCMD_PREGAME_STATUS); serializer->putchar (player_ready); - + if (player_ready==player_human) { serializer->putchar (NETCMD_BEGIN_GAME); phase=PH_INGAME; - + delete statuswnd; statuswnd=0; } - + serializer->end_packet (); for (j=0;j<clients.size();j++) @@ -416,13 +416,13 @@ printf ("Duplicate pong received\n"); continue; } - + clients[i].lag=std::max( (SDL_GetTicks() - last_ping_sent), (ulong)1); pongs_received++; - + if (pongs_received==clients.size()) update_network_delay (); - + break; case NETCMD_PLAYERCOMMAND: cmds.push (PlayerCommand::deserialize(clients[i].deserializer)); @@ -438,17 +438,17 @@ // uchar plrnum = clients[i].deserializer->getchar(); clients[i].deserializer->getstr (buffer, 256); - + msg.msg=buffer; msg.plrnum=clients[i].playernum; - + send_chat_message_int (msg); } break; default: throw wexception("Invalid network data received"); } - + // Do not send out packets too often. // The length of the interval should be set // according to the network speed and lag. @@ -463,45 +463,45 @@ PlayerCommand* cmd=cmds.front(); cmds.pop (); - + log ("player command from player %d\n", cmd->get_sender()); - + serializer->putchar (NETCMD_PLAYERCOMMAND); cmd->serialize (serializer); - + cmd->set_duetime (net_game_time); game->enqueue_command (cmd); } // update network time net_game_time=std::max((game->get_gametime()+net_delay), net_game_time); - + serializer->putchar (NETCMD_ADVANCETIME); serializer->putlong (net_game_time); - + serializer->end_packet (); - + // send the packet to all peers for (i=0;i<clients.size();i++) serializer->send (clients[i].sock); } - + // see if it is time to check network lag again if (phase==PH_INGAME && SDL_GetTicks()>=next_ping_due) { printf ("Ping!\n"); - + last_ping_sent=SDL_GetTicks(); next_ping_due=last_ping_sent + DELAY_PROBE_INTERVAL; pongs_received=0; - + serializer->begin_packet (); serializer->putchar (NETCMD_PING); serializer->end_packet (); - + // send the packet to all peers for (i=0;i<clients.size();i++) { serializer->send (clients[i].sock); - + clients[i].lag=0; } } @@ -510,13 +510,13 @@ void NetHost::send_chat_message_int (const Chat_Message msg) { unsigned int i; - + serializer->begin_packet (); serializer->putchar (NETCMD_CHATMESSAGE); serializer->putchar (msg.plrnum); serializer->putstr (msg.msg.c_str()); serializer->end_packet (); - + for (i=0;i<clients.size();i++) serializer->send (clients[i].sock); @@ -527,34 +527,34 @@ { ulong tmp[8]; unsigned int i; - + for (i=7;i>0;i--) net_delay_history[i]=net_delay_history[i-1]; - + net_delay_history[0]=MINIMUM_NETWORK_DELAY; - + for (i=0;i<clients.size();i++) if (clients[i].lag>net_delay_history[0]) net_delay_history[0]=clients[i].lag; - + // add a safety margin (25%) net_delay_history[0]+=net_delay_history[0]/4; - + for (i=0;i<8;i++) tmp[i]=net_delay_history[i]; - + std::sort (tmp, tmp+8); - + // forget the two slowest and the two fastest probes // average the remaining four - + net_delay=0; - + for (i=2;i<6;i++) net_delay+=tmp[i]; - + net_delay/=4; - + printf ("network delay is now %dms\n", (int) net_delay); } @@ -567,46 +567,46 @@ { // FIXME: send_chat_message should take a string rather than a Chat_Message msg.plrnum=playernum; - + send_chat_message_int (msg); } void NetHost::send_game_message (const char* msg) { Chat_Message cm; - + cm.plrnum=0; // not a player but 'the game' cm.msg=msg; - + send_chat_message_int (cm); } void NetHost::syncreport (uint sync) { unsigned int i; - + mysyncreports.push (sync); - + // TODO: Check whether the list of pending syncreports is getting too // long. This might happen if a client is not sending syncreports. - + // Now look whether there is at least one syncreport from everyone. // If so, make sure they match. for (i=0;i<clients.size();i++) if (clients[i].syncreports.empty()) return; - + sync=mysyncreports.front(); mysyncreports.pop(); - + for (i=0;i<clients.size();i++) { if (clients[i].syncreports.front()!=sync) throw wexception("Synchronization lost"); // TODO: handle this more gracefully - + clients[i].syncreports.pop(); } - + printf ("synchronization is good so far\n"); } @@ -617,17 +617,17 @@ sock=SDLNet_TCP_Open(svaddr); if (sock==0) throw wexception("SDLNet_TCP_Open failed: %s", SDLNet_GetError()); - + sockset=SDLNet_AllocSocketSet(1); SDLNet_TCP_AddSocket (sockset, sock); - + serializer=new Serializer(); deserializer=new Deserializer(); - + deserializer->read_packet (sock); if (deserializer->getchar()!=NETCMD_HELLO) throw wexception("Invalid network data received"); - + playernum=deserializer->getchar(); } @@ -635,9 +635,9 @@ { delete serializer; delete deserializer; - + SDLNet_FreeSocketSet (sockset); - + if (sock!=0) SDLNet_TCP_Close (sock); } @@ -645,7 +645,7 @@ void NetClient::begin_game () { NetGame::begin_game (); - + serializer->begin_packet (); serializer->putchar (NETCMD_READY); serializer->end_packet (); @@ -655,7 +655,7 @@ void NetClient::handle_network () { int i; - + // What does this do here? It probably doesn't belong here. NetGGZ::ref()->data(); @@ -663,22 +663,22 @@ while (sock!=0 && SDLNet_CheckSockets(sockset, 0) > 0) { if (!deserializer->read_packet(sock)) continue; - + // lost network connection SDLNet_TCP_DelSocket (sockset, sock); SDLNet_TCP_Close (sock); sock=0; - + disconnect (); } - + while (deserializer->avail()) switch (deserializer->getchar()) { case NETCMD_DISCONNECT: SDLNet_TCP_DelSocket (sockset, sock); SDLNet_TCP_Close (sock); sock=0; - + disconnect (); break; case NETCMD_DISCONNECT_PLAYER: @@ -689,7 +689,7 @@ char buffer[256]; deserializer->getstr (buffer,sizeof(buffer)); log ("Map '%s' selected\n", buffer); - + game->load_map (buffer); playerdescr[playernum-1]->set_player_type (Player::playerLocal); launch_menu->refresh (); @@ -698,7 +698,7 @@ case NETCMD_PLAYERINFO: player_enabled=deserializer->getchar(); player_human=deserializer->getchar(); - + for (i=0;i<MAX_PLAYERS;i++) if (i!=playernum-1) if (player_enabled & (1<<i)) { @@ -711,10 +711,10 @@ case NETCMD_PREGAME_STATUS: { uchar ready=deserializer->getchar(); - + assert (phase==PH_PREGAME); assert (statuswnd!=0); - + for (i=0;i<MAX_PLAYERS;i++) if (ready & ~player_ready & (1<<i)) statuswnd->set_ready (i+1); @@ -723,27 +723,27 @@ case NETCMD_BEGIN_PREGAME: common_rand_seed=deserializer->getlong(); game->logic_rand_seed (common_rand_seed); - + assert (launch_menu!=0); launch_menu->start_clicked(); - + phase=PH_PREGAME; break; case NETCMD_BEGIN_GAME: assert (statuswnd!=0); delete statuswnd; statuswnd=0; - + phase=PH_INGAME; break; case NETCMD_PING: // got a ping, reply with a pong serializer->begin_packet (); serializer->putchar (NETCMD_PONG); serializer->end_packet (); - + if (sock!=0) serializer->send (sock); - + printf ("Pong!\n"); break; case NETCMD_ADVANCETIME: @@ -761,7 +761,7 @@ char buffer[256]; uchar player; Chat_Message msg; - + player=deserializer->getchar(); deserializer->getstr (buffer, 256); @@ -782,7 +782,7 @@ serializer->putchar (NETCMD_PLAYERCOMMAND); cmd->serialize (serializer); serializer->end_packet (); - + if (sock!=0) serializer->send (sock); } @@ -793,12 +793,12 @@ serializer->putchar (NETCMD_CHATMESSAGE); // don't send player number because we cannot send a chat message -// from someone else (other than us) +// from someone else (other than us) // serializer->putchar(msg.plrnum); serializer->putstr (msg.msg.c_str()); serializer->end_packet (); - + if (sock!=0) serializer->send (sock); } @@ -809,7 +809,7 @@ serializer->putchar (NETCMD_SYNCREPORT); serializer->putlong (sync); serializer->end_packet (); - + if (sock!=0) serializer->send (sock); } @@ -817,11 +817,11 @@ void NetClient::disconnect () { int i; - + for (i=1;i<=MAX_PLAYERS;i++) if (game->get_player(i)!=0 && game->get_player(i)->get_type()==Player::playerRemote) disconnect_player (i); - + // Since we are now independent of the host, we are not bound to network // time anymore (nor are we receiving NETCMD_ADVANCETIME packets). net_game_time=INT_MAX; @@ -841,21 +841,21 @@ { char buffer[64]; Entry entry; - + snprintf (buffer, 64, "%s %d", _("Player"), num); - + entry.plnum=num; entry.entry=new UITable_Entry(table, 0); entry.entry->set_string (0, buffer); entry.entry->set_string (1, _("Waiting")); - + entries.push_back (entry); } void NetStatusWindow::set_ready (int num) { unsigned int i; - + for (i=0;i<entries.size();i++) if (entries[i].plnum==num) entries[i].entry->set_string (1, _("Ready")); @@ -881,9 +881,9 @@ void Serializer::end_packet () { int length=buffer.size(); - + assert (length<0x10000); - + // update packet length buffer[0]=length >> 8; buffer[1]=length & 0xFF; @@ -893,7 +893,7 @@ { while (*str) putchar (*str++); - + putchar (0); } @@ -916,7 +916,7 @@ { unsigned char buffer[256]; int length,amount,i; - + // read packet length (including length field) if (SDLNet_TCP_Recv(sock, buffer, 2) < 2) return -1; @@ -925,48 +925,48 @@ length-=2; // subtract 2 bytes for the length field assert (length>=0); - + // read packet data in chunks of 256 bytes while (length>0) { amount=std::min( length, 256 ); - + SDLNet_TCP_Recv (sock, buffer, amount); - + for (i=0;i<amount;i++) queue.push (buffer[i]); - + length-=amount; } - + return 0; } short Deserializer::getshort () { short val; - + val=getchar() << 8; val|=getchar() & 0xFF; - + return val; } long Deserializer::getlong () { long val; - + val=getchar() << 24; val|=(getchar() & 0xFF) << 16; val|=(getchar() & 0xFF) << 8; val|=getchar() & 0xFF; - + return val; } void Deserializer::getstr (char* buffer, int maxlength) { int i; - + for (i=0;(buffer[i]=getchar())!=0;i++) if (i==maxlength) throw wexception("Deserializer: string too long"); @@ -976,9 +976,9 @@ { // because the random number generator is made dependant // on the command queue, it is a good indicator for synchronization - + netgame->syncreport (g->logic_rand()); - + g->enqueue_command (new Cmd_NetCheckSync(get_duetime()+CHECK_SYNC_INTERVAL, netgame)); } Index: system.cc =================================================================== RCS file: /cvsroot/widelands/widelands/src/system.cc,v retrieving revision 1.57 retrieving revision 1.58 diff -u -d -r1.57 -r1.58 --- system.cc 29 Apr 2006 13:57:23 -0000 1.57 +++ system.cc 29 Apr 2006 15:00:53 -0000 1.58 @@ -34,8 +34,6 @@ #include "constants.h" #include "network_ggz.h" -static std::vector<std::string> l_textdomains; - Graphic *g_gr; extern int get_playback_offset(); @@ -49,82 +47,6 @@ struct SYS sys; /* - * Localisation functions - */ - -/* - * Grab a given TextDomain. We keep a stack - * if a new one is grabbed, it is pushed on the stack - * on releasing it is dropped and the previous - * one is re-grabbed instead. - * - * So when a tribe loads, it grabs it's textdomain - * loads all data and releases it -> we're back in - * widelands domain. Negative: We can't translate error - * messages. Who cares? - */ -void Sys_GrabTextdomain( const char* domain) { - bind_textdomain_codeset (domain, "UTF-8"); - bindtextdomain( domain, LOCALE_PATH ); - textdomain(domain); - - l_textdomains.push_back( domain ); -} - -void Sys_ReleaseTextdomain( void ) { - l_textdomains.pop_back(); - - if (l_textdomains.size()>0) { //don't try to get the previous TD when the very first one ('widelands') just got dropped - const char* domain = l_textdomains.back().c_str(); - bind_textdomain_codeset (domain, "UTF-8"); - bindtextdomain( domain, LOCALE_PATH ); - textdomain(domain); - } -} - -/* - * Set The locale to the given string - */ -void Sys_SetLocale( const char* str ) { - if( !str ) - str = ""; - - // Somehow setlocale doesn't behave same on - // some systems. -#ifdef __BEOS__ - setenv ("LANG", str, 1); - setenv ("LC_ALL", str, 1); -#endif -#ifdef __APPLE__ - setenv ("LANGUAGE", str, 1); - setenv ("LC_ALL", str, 1); -#endif - -#ifdef _WIN32 - const std::string env = std::string("LANG=") + str; - putenv(env.c_str()); -#endif - - setlocale(LC_ALL, str); - sys.locale=str; - - if( l_textdomains.size() ) { - const char* domain = l_textdomains.back().c_str(); - bind_textdomain_codeset (domain, "UTF-8"); - bindtextdomain( domain, LOCALE_PATH ); - textdomain(domain); - } -} - -/* - * Get the current locale - */ -std::string Sys_GetLocale() -{ - return sys.locale; -} - -/* =============== Sys_ShouldDie @@ -244,7 +166,7 @@ break; default: - throw wexception("%08X: Unknown event type %02X in playback.", get_playback_offset()-1, code); + throw wexception("%08X: Unknown event type %02X in playback.", WLApplication::get()->get_playback_offset()-1, code); } haveevent = true; @@ -254,7 +176,7 @@ haveevent = false; } else - throw wexception("%08X: Bad code %02X in event playback.", get_playback_offset()-1, code); + throw wexception("%08X: Bad code %02X in event playback.", WLApplication::get()->get_playback_offset()-1, code); } else { Index: watchwindow.cc =================================================================== RCS file: /cvsroot/widelands/widelands/src/watchwindow.cc,v retrieving revision 1.18 retrieving revision 1.19 diff -u -d -r1.18 -r1.19 --- watchwindow.cc 17 Apr 2006 07:33:02 -0000 1.18 +++ watchwindow.cc 29 Apr 2006 15:00:53 -0000 1.19 @@ -29,6 +29,7 @@ #include "ui_signal.h" #include "ui_window.h" #include "watchwindow.h" +#include "wlapplication.h" #include <vector> #define NUM_VIEWS 5 Index: tribe.cc =================================================================== RCS file: /cvsroot/widelands/widelands/src/tribe.cc,v retrieving revision 1.33 retrieving revision 1.34 diff -u -d -r1.33 -r1.34 --- tribe.cc 26 Feb 2006 13:22:23 -0000 1.33 +++ tribe.cc 29 Apr 2006 15:00:53 -0000 1.34 @@ -25,11 +25,11 @@ #include "profile.h" #include "world.h" #include "soldier.h" -#include "system.h" #include "tribe.h" #include "util.h" #include "warehouse.h" #include "wexception.h" +#include "wlapplication.h" #include "worker.h" using namespace std; @@ -47,7 +47,7 @@ // Grab the localisation text domain sprintf( directory, "tribe_%s", name ); - Sys_GrabTextdomain( directory ); + WLApplication::get()->grab_textdomain( directory ); snprintf(directory, sizeof(directory), "tribes/%s", name); @@ -58,7 +58,7 @@ parse_bobs(directory); parse_root_conf(directory); - Sys_ReleaseTextdomain( ); + WLApplication::get()->release_textdomain( ); } catch(std::exception &e) { Index: event_allow_building.cc =================================================================== RCS file: /cvsroot/widelands/widelands/src/event_allow_building.cc,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- event_allow_building.cc 17 Apr 2006 07:33:01 -0000 1.4 +++ event_allow_building.cc 29 Apr 2006 15:00:52 -0000 1.5 @@ -27,6 +27,7 @@ #include "player.h" #include "profile.h" #include "tribe.h" +#include "wlapplication.h" static const int EVENT_VERSION = 1; Index: productionsite.cc =================================================================== RCS file: /cvsroot/widelands/widelands/src/productionsite.cc,v retrieving revision 1.28 retrieving revision 1.29 diff -u -d -r1.28 -r1.29 --- productionsite.cc 6 Jan 2006 21:25:48 -0000 1.28 +++ productionsite.cc 29 Apr 2006 15:00:52 -0000 1.29 @@ -35,6 +35,7 @@ #include "ware.h" #include "world.h" #include "sound_handler.h" +#include "wlapplication.h" static const size_t STATISTICS_VECTOR_LENGTH = 10; @@ -118,7 +119,7 @@ remove_spaces(&workers[i]); split_string(workers[i],&amounts,"*"); uint j; - for(j=0; j<amounts.size(); j++) + for(j=0; j<amounts.size(); j++) remove_spaces(&amounts[j]); int amount=1; @@ -131,7 +132,7 @@ Worker_Info m= { amounts[0], amount }; m_workers.push_back(m); } - + // Get programs while(sglobal->get_next_string("program", &string)) { ProductionProgram* program = 0; @@ -234,10 +235,10 @@ sprintf(buf, "Waiting for %i workers!", (int)m_worker_requests.size()); return buf; } - + if (m_statistics_changed) calc_statistics(); - + if (m_stop) return "(stopped)"; return m_statistics_buf; @@ -319,8 +320,8 @@ std::vector<ProductionSite_Descr::Worker_Info>* info=get_descr()->get_workers(); uint i; int j; - for(i=0; i<info->size(); i++) - for(j=0; j< ((*info)[i]).how_many; j++) + for(i=0; i<info->size(); i++) + for(j=0; j< ((*info)[i]).how_many; j++) request_worker((Game*)g, ((*info)[i]).name.c_str()); } @@ -365,7 +366,7 @@ if(m_worker_requests[i]) m_worker_requests[i]->set_economy(e); } - + if (e) { for(i = 0; i < m_input_queues.size(); i++) m_input_queues[i]->add_to_economy(e); @@ -397,7 +398,7 @@ Worker* w = m_workers[i]; m_workers[i] = 0; - if(g->get_objects()->object_still_available(w)) + if(g->get_objects()->object_still_available(w)) w->set_location(0); } m_workers.resize(0); @@ -442,7 +443,7 @@ =============== ProductionSite::request_worker -Issue the worker requests +Issue the worker requests =============== */ void ProductionSite::request_worker(Game* g, const char* worker) @@ -471,15 +472,15 @@ assert(w->get_location(g) == psite); uint i=0; - for(i=0; i<psite->m_worker_requests.size(); i++) - if(rq==psite->m_worker_requests[i]) break; - + for(i=0; i<psite->m_worker_requests.size(); i++) + if(rq==psite->m_worker_requests[i]) break; + psite->m_worker_requests.erase(psite->m_worker_requests.begin() + i); psite->m_workers.push_back(w); delete rq; - + bool set_worker_idle=true; if(psite->can_start_working() && w==psite->m_workers[0]) set_worker_idle=false; @@ -625,7 +626,7 @@ { std::vector<std::string> wares; split_string(action->sparam1, &wares, ","); - + uint j=0; bool found=false; for(j=0; j<wares.size(); j++) { @@ -658,7 +659,7 @@ m_program_time = schedule_act(g, 10); return; } - + case ProductionAction::actProduce: { molog(" Produce(%s)\n", action->sparam1.c_str()); @@ -671,9 +672,9 @@ // For statistics, inform the user that a ware was produced // Ware statistics are only cached for the interactive user // since other tribes would have other types of wares - if(g->get_ipl()->get_player_number()==get_owner()->get_player_number()) - g->get_ipl()->ware_produced(wareid); - + if(g->get_ipl()->get_player_number()==get_owner()->get_player_number()) + g->get_ipl()->ware_produced(wareid); + m_workers[0]->set_carried_item(g,item); // get the worker to drop the item off @@ -735,9 +736,9 @@ // how much is digged int digged_percentage=100; - if(totalstart) - digged_percentage = 100 - (totalres*100 / totalstart); - if(!totalres) + if(totalstart) + digged_percentage = 100 - (totalres*100 / totalstart); + if(!totalres) digged_percentage=100; molog(" Mine has already digged %i percent (%i/%i)!\n", digged_percentage, totalres, totalstart); @@ -957,7 +958,7 @@ case ProductionAction::actPlayFX: { g_sound_handler.play_fx(action->sparam1, m_position, action->iparam1); - + program_step(); m_program_timer = true; m_program_time = schedule_act(g, 10); @@ -986,13 +987,13 @@ /* * returns true if this production site could - * theoretically start working (if all workers + * theoretically start working (if all workers * are present) */ bool ProductionSite::can_start_working(void) { - if(m_worker_requests.size()) + if(m_worker_requests.size()) return false; - + return true; } @@ -1154,12 +1155,12 @@ add_statistics_value(success); // if succesfull, the workers gain experience - if(success) { + if(success) { uint i=0; - for(i=0; i<m_workers.size(); i++) + for(i=0; i<m_workers.size(); i++) m_workers[i]->gain_experience(g); } - + m_program_timer = true; m_program_time = schedule_act(g, m_post_timer); } Index: waresdisplay.cc =================================================================== RCS file: /cvsroot/widelands/widelands/src/waresdisplay.cc,v retrieving revision 1.13 retrieving revision 1.14 diff -u -d -r1.13 -r1.14 --- waresdisplay.cc 12 Feb 2006 12:50:46 -0000 1.13 +++ waresdisplay.cc 29 Apr 2006 15:00:53 -0000 1.14 @@ -27,6 +27,7 @@ #include "ui_textarea.h" #include "waresdisplay.h" #include "worker.h" +#include "wlapplication.h" /* ============================================================================== @@ -81,7 +82,7 @@ if(index > (m_warelists[0]->get_nrwareids())) { m_curware->set_text(""); - } + } else { if(m_type == WORKER) { index--; @@ -106,7 +107,7 @@ { // If you register something twice, it is counted twice. Not my problem m_warelists.push_back(wares); - + int rows, height; rows = (wares->get_nrwareids() + WaresPerRow - 1) / WaresPerRow; @@ -115,7 +116,7 @@ set_size(get_inner_w(), height+30); m_curware->set_pos(0, get_inner_h()-25); m_curware->set_size(get_inner_w(), 20); - + m_type = type; @@ -146,7 +147,7 @@ int number = m_player->get_tribe()->get_nrwares(); bool is_worker = false; - if( m_type == WORKER ) { + if( m_type == WORKER ) { number = m_player->get_tribe()->get_nrworkers(); is_worker = true; } @@ -198,9 +199,9 @@ int picid = g_gr->get_picture( PicMod_Game, "pics/ware_list_bg.png" ); int w, h; g_gr->get_picture_size(picid, &w, &h); - - dst->blit(x, y, picid); - + + dst->blit(x, y, picid); + int posx = x + (w - WARE_MENU_PIC_W)/2; int posy = y + 1; // Draw it Index: playerdescrgroup.cc =================================================================== RCS file: /cvsroot/widelands/widelands/src/playerdescrgroup.cc,v retrieving revision 1.15 retrieving revision 1.16 diff -u -d -r1.15 -r1.16 --- playerdescrgroup.cc 7 Feb 2006 13:58:35 -0000 1.15 +++ playerdescrgroup.cc 29 Apr 2006 15:00:52 -0000 1.16 @@ -26,17 +26,18 @@ #include "ui_checkbox.h" #include "tribe.h" #include "wexception.h" +#include "wlapplication.h" static const char* default_names[MAX_PLAYERS+1] = { - "", + "", _("Player 1"), - _("Player 2"), - _("Player 3"), - _("Player 4"), - _("Player 5"), - _("Player 6"), - _("Player 7"), - _("Player 8"), + _("Player 2"), + _("Player 3"), + _("Player 4"), + _("Player 5"), + _("Player 6"), + _("Player 7"), + _("Player 8"), }; void PlayerDescriptionGroup::allow_changes(changemode_t t) { @@ -73,7 +74,7 @@ Tribe_Descr::get_all_tribes(&m_tribes); m_btnPlayerTribe->set_title(m_tribes[m_current_tribe].c_str()); - + set_player_type (Player::playerAI); } @@ -85,7 +86,7 @@ void PlayerDescriptionGroup::set_enabled(bool enable) { if(!m_allow_changes) return; - + if (enable == m_enabled) return; @@ -103,7 +104,7 @@ m_game->add_player(m_plnum, m_playertype, m_tribes[m_current_tribe].c_str(), default_names[m_plnum]); m_game->get_player(m_plnum)->init(m_game,0); // Small initializes } - + const char* string = 0; switch(m_playertype) { case Player::playerLocal: @@ -195,10 +196,10 @@ return; m_playertype=type; - + if (m_enabled) { m_btnPlayerType->set_title((type!=Player::playerAI)?_("Human"):_("Computer")); - + m_game->remove_player (m_plnum); m_game->add_player (m_plnum, m_playertype, m_tribes[m_current_tribe].c_str(), default_names[m_plnum]); m_game->get_player(m_plnum)->init(m_game,0); // Small initializes Index: worker.cc =================================================================== RCS file: /cvsroot/widelands/widelands/src/worker.cc,v retrieving revision 1.104 retrieving revision 1.105 diff -u -d -r1.104 -r1.105 --- worker.cc 6 Mar 2006 16:02:26 -0000 1.104 +++ worker.cc 29 Apr 2006 15:00:53 -0000 1.105 @@ -39,7 +39,7 @@ #include "worker_program.h" #include "world.h" #include "sound_handler.h" - +#include "wlapplication.h" Cmd_Incorporate::Cmd_Incorporate(int t, Worker* w) : BaseCommand(t) { Index: game_chat_menu.cc =================================================================== RCS file: /cvsroot/widelands/widelands/src/game_chat_menu.cc,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- game_chat_menu.cc 25 Nov 2005 11:17:04 -0000 1.3 +++ game_chat_menu.cc 29 Apr 2006 15:00:52 -0000 1.4 @@ -31,8 +31,9 @@ #include "ui_multilineeditbox.h" #include "ui_textarea.h" #include "util.h" +#include "wlapplication.h" -#define CHAT_MSG_WAIT_TIME 1000 +#define CHAT_MSG_WAIT_TIME 1000 /* ============================================================================== @@ -54,16 +55,16 @@ { m_player=plr; m_netgame = netgame; - + int spacing = 5; int posy = 35; - + // Caption new UITextarea(this, 0, spacing, get_inner_w(), 20, _("Chat Menu"), Align_Center); - - // What has been said? - m_chatbox = new UIMultiline_Textarea(this, spacing, posy, get_inner_w()-spacing*2, 150, "", Align_Left, 1); - + + // What has been said? + m_chatbox = new UIMultiline_Textarea(this, spacing, posy, get_inner_w()-spacing*2, 150, "", Align_Left, 1); + posy += 150+spacing+spacing; m_editbox = new UIMultiline_Editbox(this, spacing, posy, get_inner_w()-spacing*2, 85, ""); posy += 85 + spacing + spacing; @@ -76,11 +77,11 @@ // Textbox new UITextarea(this, 80+2*spacing, posy, 120, STATEBOX_HEIGHT, _("Show messages as overlays:"), Align_CenterLeft); UICheckbox* cb = new UICheckbox(this, get_inner_w()-STATEBOX_WIDTH-spacing, posy); - + cb->set_state( m_player->show_chat_overlay() ); cb->changedto.set(this, &GameChatMenu::cb_changed); posy += STATEBOX_HEIGHT + spacing; - + set_inner_size(get_inner_w(), posy+5); if (get_usedefaultpos()) center_to_parent(); @@ -104,14 +105,14 @@ const std::vector<NetGame::Chat_Message>* msges = m_player->get_chatmsges(); std::string str; - + for( uint i = 0; i < msges->size(); i++) { str += m_player->get_game()->get_player((*msges)[i].plrnum)->get_name(); str += ": "; str += (*msges)[i].msg; str += "\n"; } - + m_chatbox->set_text( str.c_str() ); } @@ -124,10 +125,10 @@ void GameChatMenu::clicked(int n) { std::string str = m_editbox->get_text(); - + if( str.size() && m_netgame ) { NetGame::Chat_Message t; - + t.plrnum = m_player->get_player_number(); t.msg = str; m_netgame->send_chat_message( t ); Index: game_server_proto_packet_getuserinfo.cc =================================================================== RCS file: /cvsroot/widelands/widelands/src/game_server_proto_packet_getuserinfo.cc,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- game_server_proto_packet_getuserinfo.cc 25 Nov 2005 20:27:54 -0000 1.8 +++ game_server_proto_packet_getuserinfo.cc 29 Apr 2006 15:00:52 -0000 1.9 @@ -25,6 +25,7 @@ #include "util.h" #include "wexception.h" #include "system.h" +#include "wlapplication.h" /* * Constructor @@ -68,7 +69,7 @@ return; } - assert(flags == UI_ACK); + assert(flags == UI_ACK); std::string game = buf->get_string(); std::string room = buf->get_string(); Index: stock_menu.cc =================================================================== RCS file: /cvsroot/widelands/widelands/src/stock_menu.cc,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- stock_menu.cc 25 Nov 2005 11:17:04 -0000 1.4 +++ stock_menu.cc 29 Apr 2006 15:00:53 -0000 1.5 @@ -23,6 +23,7 @@ #include "transport.h" #include "ui_button.h" #include "waresdisplay.h" +#include "wlapplication.h" /* =============== @@ -40,9 +41,9 @@ m_waresdisplay = new WaresDisplay(this, 0, 0, parent->get_game(), parent->get_player()); // Add with wares fill_waredisplay_with_wares(); - + set_inner_size(m_waresdisplay->get_w(), 0); - + int spacing = 5; int nr_buttons = 4; // one more, turn page button is bigger int button_w = (get_inner_w() - (nr_buttons+1)*spacing) / nr_buttons; @@ -60,7 +61,7 @@ b->clickedid.set(this, &Stock_Menu::clicked); posx += button_w*2 + 2*spacing; posy += 25 + spacing; - + set_inner_size(get_inner_w(), posy); } @@ -93,13 +94,13 @@ // Switch page switch_page(); } - + } - + } /* - * Switch to the next page, that is, show + * Switch to the next page, that is, show * wares -> workers -> soldier */ void Stock_Menu::switch_page(void) { @@ -121,7 +122,7 @@ */ void Stock_Menu::think() { - if(m_curpage == 0) + if(m_curpage == 0) fill_waredisplay_with_wares(); else if(m_curpage == 1) fill_waredisplay_with_workers(); Index: game_main_menu_load_game.cc =================================================================== RCS file: /cvsroot/widelands/widelands/src/game_main_menu_load_game.cc,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- game_main_menu_load_game.cc 25 Nov 2005 11:17:04 -0000 1.5 +++ game_main_menu_load_game.cc 29 Apr 2006 15:00:52 -0000 1.6 @@ -27,6 +27,7 @@ #include "ui_listselect.h" #include "ui_modal_messagebox.h" #include "ui_textarea.h" +#include "wlapplication.h" /* =============== @@ -73,7 +74,7 @@ UIButton* but= new UIButton(this, get_inner_w()/2-spacing-80, posy, 80, 20, 4, 1); but->clickedid.set(this, &Game_Main_Menu_Load_Game::clicked); but->set_title(_("OK")); - but->set_enabled(false); + but->set_enabled(false); m_ok_btn=but; but= new UIButton(this, get_inner_w()/2+spacing, posy, 80, 20, 4, 0); but->clickedid.set(this, &Game_Main_Menu_Load_Game::clicked); @@ -110,12 +111,12 @@ std::string filename=static_cast<const char*>(m_ls->get_selection()); // Ok, load this map - if(load_game(filename)) + if(load_game(filename)) die(); } else if(id==0) { // Cancel die(); - } + } } /* @@ -125,7 +126,7 @@ const char* name=static_cast<const char*>(m_ls->get_selection()); FileSystem* fs = g_fs->MakeSubFileSystem( name ); - + Game_Loader gl(fs, m_parent->get_game()); Game_Preload_Data_Packet gpdp; gl.preload_game(&gpdp); // This has worked before, no problem @@ -158,22 +159,22 @@ * fill the file list */ void Game_Main_Menu_Load_Game::fill_list(void) { - // Fill it with all files we find. + // Fill it with all files we find. g_fs->FindFiles(m_curdir, "*", &m_gamefiles, 1); - + Game_Preload_Data_Packet gpdp; - + for(filenameset_t::iterator pname = m_gamefiles.begin(); pname != m_gamefiles.end(); pname++) { const char *name = pname->c_str(); - + Game_Loader* gl = 0; FileSystem* fs = 0; try { - fs = g_fs->MakeSubFileSystem( name ); + fs = g_fs->MakeSubFileSystem( name ); gl = new Game_Loader(fs,m_parent->get_game()); gl->preload_game(&gpdp); - + char* fname = strdup(FS_Filename(name)); FS_StripExtension(fname); m_ls->add_entry(fname, reinterpret_cast<void*>(const_cast<char*>(name))); @@ -182,12 +183,12 @@ } catch(wexception& ) { // we simply skip illegal entries } - if( gl ) + if( gl ) delete gl; - if( fs ) + if( fs ) delete fs; } - + if(m_ls->get_nr_entries()) m_ls->select(0); } @@ -206,7 +207,7 @@ * should stay open */ bool Game_Main_Menu_Load_Game::load_game(std::string filename) { - + Game_Loader* gl = 0; FileSystem* fs = 0; try { @@ -225,7 +226,7 @@ } if( gl ) delete gl; - if( fs ) + if( fs ) delete fs; die(); Index: trigger_building.cc =================================================================== RCS file: /cvsroot/widelands/widelands/src/trigger_building.cc,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- trigger_building.cc 17 Apr 2006 07:33:02 -0000 1.6 +++ trigger_building.cc 29 Apr 2006 15:00:53 -0000 1.7 @@ -28,6 +28,7 @@ #include "profile.h" #include "trigger_building.h" #include "util.h" +#include "wlapplication.h" static const int TRIGGER_VERSION = 1; Index: criterr.cc =================================================================== RCS file: /cvsroot/widelands/widelands/src/criterr.cc,v retrieving revision 1.26 retrieving revision 1.27 diff -u -d -r1.26 -r1.27 --- criterr.cc 17 Apr 2006 07:33:00 -0000 1.26 +++ criterr.cc 29 Apr 2006 15:00:52 -0000 1.27 @@ -27,6 +27,7 @@ #include "ui_button.h" #include "ui_textarea.h" #include "ui_panel.h" +#include "wlapplication.h" #ifdef WIN32 #include <windows.h> Index: event_unhide_area.cc =================================================================== RCS file: /cvsroot/widelands/widelands/src/event_unhide_area.cc,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- event_unhide_area.cc 17 Apr 2006 07:33:02 -0000 1.7 +++ event_unhide_area.cc 29 Apr 2006 15:00:52 -0000 1.8 @@ -26,6 +26,7 @@ #include "player.h" #include "profile.h" #include "system.h" +#include "wlapplication.h" static const int EVENT_VERSION = 1; Index: game_server_proto_packet_chatmessage.cc =================================================================== RCS file: /cvsroot/widelands/widelands/src/game_server_proto_packet_chatmessage.cc,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- game_server_proto_packet_chatmessage.cc 25 Nov 2005 20:27:54 -0000 1.7 +++ game_server_proto_packet_chatmessage.cc 29 Apr 2006 15:00:52 -0000 1.8 @@ -25,6 +25,7 @@ #include "util.h" #include "wexception.h" #include "system.h" +#include "wlapplication.h" /* * Constructor @@ -66,13 +67,13 @@ char buffer[1024]; snprintf(buffer, 1024, _("Server replied illegally to ChatMessage package. Should have sent %i but sent %i. Ignored"), CM_ACK, answer); - + gsc->server_message( buffer ); } } /* - * Read from network + * Read from network */ void Game_Server_Protocol_Packet_ChatMessage::recv(Game_Server_Connection* gsc, Network_Buffer* buffer) { m_flags = buffer->get_8(); Index: s2map.cc =================================================================== RCS file: /cvsroot/widelands/widelands/src/s2map.cc,v retrieving revision 1.58 retrieving revision 1.59 diff -u -d -r1.58 -r1.59 --- s2map.cc 7 Nov 2005 20:52:30 -0000 1.58 +++ s2map.cc 29 Apr 2006 15:00:52 -0000 1.59 @@ -26,6 +26,7 @@ #include "types.h" #include "world.h" #include "system.h" +#include "wlapplication.h" using std::cerr; using std::ios; @@ -560,7 +561,7 @@ } int real_amount=((int)(2.86*(float)amount)); f->set_resources(nres,real_amount); - f->set_starting_res_amount(real_amount); + f->set_starting_res_amount(real_amount); } } Index: wlapplication.h =================================================================== RCS file: /cvsroot/widelands/widelands/src/wlapplication.h,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- wlapplication.h 29 Apr 2006 13:57:23 -0000 1.5 +++ wlapplication.h 29 Apr 2006 15:00:53 -0000 1.6 @@ -20,16 +20,33 @@ #ifndef WLAPPLICATION_H #define WLAPPLICATION_H +/// A macro to make i18n more readable +#define _( str ) WLApplication::translate( str ) + +/** + * Note:There is no need for a destructor, just make sure you call + * \ref shutdown(). + * + * \todo Document that record/playback files are journals + */ class WLApplication { public: static WLApplication *get(int argc=0, char **argv=0); void run(); - bool init(); void shutdown(); + //Locale handling + static const char* translate( const char* str ) {return gettext( str );} + void grab_textdomain( const char* ); + void release_textdomain(); + void ... [truncated message content] |