diff options
Diffstat (limited to 'src/main.cpp')
-rw-r--r-- | src/main.cpp | 107 |
1 files changed, 61 insertions, 46 deletions
diff --git a/src/main.cpp b/src/main.cpp index 2ecde05d..1c05dbb7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,9 +1,8 @@ /* - * Aethyra + * The Mana World * Copyright (C) 2004 The Mana World Development Team * - * This file is part of Aethyra based on original code - * from The Mana World. + * This file is part of The Mana World. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -50,6 +49,8 @@ #include "player_relations.h" #include "serverinfo.h" #include "sound.h" +#include "statuseffect.h" +#include "units.h" #include "gui/button.h" #include "gui/char_server.h" @@ -187,7 +188,7 @@ void setUpdatesDir() if (updateHost.empty()) { updateHost = - config.getValue("updatehost", "http://www.aethyra.org/updates"); + config.getValue("updatehost", "http://updates.themanaworld.org/"); } // Remove any trailing slash at the end of the update host @@ -259,18 +260,23 @@ void setUpdatesDir() */ void init_engine(const Options &options) { - homeDir = std::string(PHYSFS_getUserDir()) + "/.aethyra"; + if (homeDir.empty()) +#if defined __APPLE__ + // Use Application Directory instead of .tmw + homeDir = std::string(PHYSFS_getUserDir()) + + "/Library/Application Support/The Mana World"; +#else + homeDir = std::string(PHYSFS_getUserDir()) + "/.tmw"; +#endif + #if defined WIN32 if (!CreateDirectory(homeDir.c_str(), 0) && GetLastError() != ERROR_ALREADY_EXISTS) #elif defined __APPLE__ - // Use Application Directory instead of .aethyra - homeDir = std::string(PHYSFS_getUserDir()) + - "/Library/Application Support/Aethyra"; if ((mkdir(homeDir.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0) && (errno != EEXIST)) #else - // Checking if /home/user/.Aethyra folder exists. + // Checking if /home/user/.tmw folder exists. if ((mkdir(homeDir.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0) && (errno != EEXIST)) #endif @@ -282,12 +288,12 @@ void init_engine(const Options &options) } // Set log file - logger->setLogFile(homeDir + std::string("/aethyra.log")); + logger->setLogFile(homeDir + std::string("/tmw.log")); #ifdef PACKAGE_VERSION - logger->log("Starting Aethyra Version %s", PACKAGE_VERSION); + logger->log("Starting The Mana World Version %s", PACKAGE_VERSION); #else - logger->log("Starting Aethyra - Version not defined")); + logger->log("Starting The Mana World - Version not defined"); #endif // Initialize SDL @@ -337,8 +343,8 @@ void init_engine(const Options &options) // Fill configuration with defaults logger->log("Initializing configuration..."); - config.setValue("host", "www.aethyra.org"); - config.setValue("port", 21001); + config.setValue("host", "www.themanaworld.org"); + config.setValue("port", 6901); config.setValue("hwaccel", 0); #if (defined __APPLE__ || defined WIN32) && defined USE_OPENGL config.setValue("opengl", 1); @@ -352,7 +358,7 @@ void init_engine(const Options &options) config.setValue("sfxVolume", 100); config.setValue("musicVolume", 60); config.setValue("fpslimit", 0); - config.setValue("updatehost", "http://www.aethyra.org/updates"); + config.setValue("updatehost", "http://updates.themanaworld.org"); config.setValue("customcursor", 1); config.setValue("ChatLogLength", 128); @@ -379,7 +385,7 @@ void init_engine(const Options &options) config.init(configPath); } - SDL_WM_SetCaption("Aethyra", NULL); + SDL_WM_SetCaption("The Mana World", NULL); #ifdef WIN32 static SDL_SysWMinfo pInfo; SDL_GetWMInfo(&pInfo); @@ -389,7 +395,7 @@ void init_engine(const Options &options) SetClassLong(pInfo.window, GCL_HICON, (LONG) icon); } #else - icon = IMG_Load(PKG_DATADIR "data/icons/aethyra.png"); + icon = IMG_Load(PKG_DATADIR "data/icons/tmw.png"); if (icon) { SDL_SetAlpha(icon, SDL_SRCALPHA, SDL_ALPHA_OPAQUE); @@ -404,10 +410,10 @@ void init_engine(const Options &options) Image::setLoadAsOpenGL(useOpenGL); // Create the graphics context - graphics = useOpenGL ? new OpenGLGraphics() : new Graphics(); + graphics = useOpenGL ? new OpenGLGraphics : new Graphics; #else // Create the graphics context - graphics = new Graphics(); + graphics = new Graphics; #endif const int width = (int) config.getValue("screenwidth", defaultScreenWidth); @@ -429,10 +435,10 @@ void init_engine(const Options &options) graphics->_beginDraw(); // Initialize the item shortcuts. - itemShortcut = new ItemShortcut(); + itemShortcut = new ItemShortcut; // Initialize the emote shortcuts. - emoteShortcut = new EmoteShortcut(); + emoteShortcut = new EmoteShortcut; gui = new Gui(graphics); state = LOGIN_STATE; /**< Initial game state */ @@ -486,6 +492,7 @@ void exit_engine() ItemDB::unload(); MonsterDB::unload(); NPCDB::unload(); + StatusEffect::unload(); ResourceManager::deleteInstance(); delete logger; @@ -496,13 +503,14 @@ void exit_engine() void printHelp() { std::cout - << _("aethyra") << std::endl << std::endl + << _("tmw") << std::endl << std::endl << _("Options: ") << std::endl << _(" -C --configfile : Configuration file to use") << std::endl << _(" -d --data : Directory to load game data from") << std::endl << _(" -D --default : Bypass the login process with default settings") << std::endl << _(" -h --help : Display this help") << std::endl + << _(" -S --homedir : Directory to use as home directory") << std::endl << _(" -H --updatehost : Use this update host") << std::endl << _(" -p --playername : Login with this player") << std::endl << _(" -P --password : Login with this password") << std::endl @@ -514,17 +522,16 @@ void printHelp() void printVersion() { #ifdef PACKAGE_VERSION - std::cout << _("Aethyra version ") << PACKAGE_VERSION << - std::endl; + std::cout << _("The Mana World version ") << PACKAGE_VERSION << std::endl; #else - std::cout << _("Aethyra version ") << + std::cout << _("The Mana World version ") << _("(local build?, PACKAGE_VERSION is not defined)") << std::endl; #endif } void parseOptions(int argc, char *argv[], Options &options) { - const char *optstring = "hvud:U:P:Dp:C:H:"; + const char *optstring = "hvud:U:P:Dp:C:H:S:"; const struct option long_options[] = { { "configfile", required_argument, 0, 'C' }, @@ -533,6 +540,7 @@ void parseOptions(int argc, char *argv[], Options &options) { "playername", required_argument, 0, 'p' }, { "password", required_argument, 0, 'P' }, { "help", no_argument, 0, 'h' }, + { "homedir", required_argument, 0, 'S' }, { "updatehost", required_argument, 0, 'H' }, { "skipupdate", no_argument, 0, 'u' }, { "username", required_argument, 0, 'U' }, @@ -579,6 +587,9 @@ void parseOptions(int argc, char *argv[], Options &options) case 'v': options.printVersion = true; break; + case 'S': + homeDir = optarg; + break; } } } @@ -656,16 +667,11 @@ void accountLogin(Network *network, LoginData *loginData) config.setValue("remember", loginData->remember); } -inline int MIN(int x, int y) -{ - return x < y ? x : y; -} - -void positionDialog(Window *dialog, int screenWidth, int screenHeight) +static void positionDialog(Window *dialog, int screenWidth, int screenHeight) { dialog->setPosition( - MIN(screenWidth * 5 / 8, screenWidth - dialog->getWidth()), - MIN(screenHeight * 5 / 8, screenHeight - dialog->getHeight())); + (screenWidth - dialog->getWidth()) / 2, + (screenHeight - dialog->getHeight()) / 2); } void charLogin(Network *network, LoginData *loginData) @@ -724,7 +730,7 @@ extern "C" char const *_nl_locale_name_default(void); /** Main */ int main(int argc, char *argv[]) { - logger = new Logger(); + logger = new Logger; Options options; @@ -744,11 +750,14 @@ int main(int argc, char *argv[]) #if ENABLE_NLS #ifdef WIN32 putenv(("LANG=" + std::string(_nl_locale_name_default())).c_str()); + // mingw doesn't like LOCALEDIR to be defined for some reason + bindtextdomain("tmw", "translations/"); +#else + bindtextdomain("tmw", LOCALEDIR); #endif setlocale(LC_MESSAGES, ""); - bindtextdomain("aethyra", LOCALEDIR); - bind_textdomain_codeset("aethyra", "UTF-8"); - textdomain("aethyra"); + bind_textdomain_codeset("tmw", "UTF-8"); + textdomain("tmw"); #endif // Initialize libxml2 and check for potential ABI mismatches between @@ -775,7 +784,7 @@ int main(int argc, char *argv[]) Game *game = NULL; Window *currentDialog = NULL; Image *login_wallpaper = NULL; - setupWindow = new Setup(); + setupWindow = new Setup; gcn::Container *top = static_cast<gcn::Container*>(gui->getTop()); #ifdef PACKAGE_VERSION @@ -803,13 +812,13 @@ int main(int argc, char *argv[]) if (!options.password.empty()) { loginData.password = options.password; } - loginData.hostname = config.getValue("host", "www.aethyra.org"); - loginData.port = (short)config.getValue("port", 21001); + loginData.hostname = config.getValue("host", "server.themanaworld.org"); + loginData.port = (short)config.getValue("port", 6901); loginData.remember = config.getValue("remember", 0); loginData.registerLogin = false; SDLNet_Init(); - Network *network = new Network(); + Network *network = new Network; // Set the most appropriate wallpaper, based on screen width int screenWidth = (int) config.getValue("screenwidth", defaultScreenWidth); @@ -827,7 +836,10 @@ int main(int argc, char *argv[]) else if (screenWidth >= 1600) wallpaperName = "graphics/images/login_wallpaper_1600x1200.png"; - login_wallpaper = ResourceManager::getInstance()-> getImage(wallpaperName); + if (!ResourceManager::getInstance()->exists(wallpaperName)) + wallpaperName = "graphics/images/login_wallpaper.png"; + + login_wallpaper = ResourceManager::getInstance()->getImage(wallpaperName); if (!login_wallpaper) logger->log("Couldn't load %s as wallpaper", wallpaperName.c_str()); @@ -877,7 +889,7 @@ int main(int argc, char *argv[]) if (graphics->getWidth() > login_wallpaper->getWidth() || graphics->getHeight() > login_wallpaper->getHeight()) { - graphics->setColor(gcn::Color(255, 255, 255)); + graphics->setColor(gcn::Color(64, 64, 64)); graphics->fillRectangle(gcn::Rectangle( 0, 0, graphics->getWidth(), graphics->getHeight())); } @@ -897,6 +909,8 @@ int main(int argc, char *argv[]) login_wallpaper->decRef(); login_wallpaper = ResourceManager::getInstance()-> getImage(wallpaperName); + // Load units + Units::loadUnits(); break; // Those states don't cause a network disconnect @@ -942,6 +956,7 @@ int main(int argc, char *argv[]) MonsterDB::load(); NPCDB::load(); EmoteDB::load(); + StatusEffect::load(); Being::load(); // Hairstyles state = CHAR_CONNECT_STATE; @@ -998,8 +1013,8 @@ int main(int argc, char *argv[]) case CHAR_SELECT_STATE: logger->log("State: CHAR_SELECT"); currentDialog = new CharSelectDialog(network, &charInfo, - (loginData.sex == 0) ? - GENDER_FEMALE : GENDER_MALE); + (loginData.sex == 0) ? + GENDER_FEMALE : GENDER_MALE); positionDialog(currentDialog, screenWidth, screenHeight); if (((CharSelectDialog*) currentDialog)-> |