/*************************************************************************** State.cpp - description ------------------- begin : Mon Aug 12 2003 copyright : (C) 2003 by upi email : upi@apocalypse.rulez.org ***************************************************************************/ #include "../config.h" #include "gfx.h" #include "common.h" #include "State.h" #include "SDL_keysym.h" #include "SDL_mixer.h" #include #include //include #include "Backend.h" #include "MszPerl.h" extern PerlInterpreter* my_perl; SState g_oState; std::string GetConfigHeader() { std::string sHeader( "Simple config file " ); sHeader += PACKAGE " " VERSION; return sHeader; } std::string GetConfigFilename() { #ifdef _WINDOWS if ( NULL != g_oState.m_pcArgv0 ) { return std::string(g_oState.m_pcArgv0) + ".ini"; } return "c:\\openmortal.ini"; #else return std::string(getenv("HOME")) + "/.openmortalrc"; #endif } SState::SState() { // 1. SET THE TRIVIAL DEFAULTS m_enGameMode = IN_DEMO; m_bQuitFlag = false; m_pcArgv0 = NULL; m_iNumPlayers = 2; m_enTeamMode = Team_ONE_VS_ONE; m_iTeamSize = 5; m_bTeamMultiselect = false; m_iGameTime = 60; m_iHitPoints = 100; m_iGameSpeed = 12; #ifdef _WINDOWS #ifdef _DEBUG m_bFullscreen = false; #else m_bFullscreen = true; #endif #else m_bFullscreen = false; #endif m_iChannels = 2; m_iMixingRate = MIX_DEFAULT_FREQUENCY; m_iMixingBits = 2; m_iMusicVolume = 50; m_iSoundVolume = 100; static const int aiDefaultKeys[MAXPLAYERS][9] = { { SDLK_UP, SDLK_DOWN, SDLK_LEFT, SDLK_RIGHT, SDLK_PAGEDOWN, SDLK_DELETE, SDLK_INSERT, SDLK_END, SDLK_HOME }, { SDLK_w, SDLK_s, SDLK_a, SDLK_d, SDLK_x, SDLK_f, SDLK_r, SDLK_g, SDLK_t }, { SDLK_u, SDLK_j, SDLK_h, SDLK_k, SDLK_i, SDLK_b, SDLK_n, SDLK_m, SDLK_COMMA }, { SDLK_F2, SDLK_F3, SDLK_F4, SDLK_F5, SDLK_F6, SDLK_F7, SDLK_F8, SDLK_F9, SDLK_F10 }, }; for ( int i=0; iformat->BitsPerPixel <= 8 ); SDL_Color aoPalette[256]; int iNumColors = 0; if ( bPaletted ) { iNumColors = gamescreen->format->palette->ncolors; if ( iNumColors > 256 ) iNumColors = 256; for ( int i=0; iformat->palette->colors[i].r; aoPalette[i].g = gamescreen->format->palette->colors[i].g; aoPalette[i].b = gamescreen->format->palette->colors[i].b; aoPalette[i].unused = 0; } } SetVideoMode( gamescreen->w > 640, m_bFullscreen ); if ( bPaletted ) { SDL_SetPalette( gamescreen, SDL_LOGPAL | SDL_PHYSPAL, aoPalette, 0, iNumColors ); } } void SState::SetLanguage( const char* a_pcLanguage ) { if ( m_acLanguage != a_pcLanguage ) { strncpy( m_acLanguage, a_pcLanguage, 9 ); m_acLanguage[9] = 0; } g_oBackend.PerlEvalF( "SetLanguage('%s');", m_acLanguage ); SV* poSv = get_sv("LanguageNumber", FALSE); if (poSv) { m_iLanguageCode = SvIV( poSv ); } else { m_iLanguageCode = 0; } } void SState::SetServer( const char* a_pcServer ) { if ( a_pcServer ) { strncpy( m_acLatestServer, a_pcServer, 255 ); m_acLatestServer[255] = 0; m_bServer = false; } else { m_bServer = true; } } void SState::Load() { std::string sFilename = GetConfigFilename(); g_oBackend.PerlEvalF( "ParseConfig('%s');", sFilename.c_str() ); SV* poSv; // poSv = get_sv("", FALSE); if (poSv) m_ = SvIV( poSv ); poSv = get_sv("NUMPLAYERS", FALSE); if (poSv) m_iNumPlayers = SvIV( poSv ); poSv = get_sv("TEAMMODE", FALSE); if (poSv) m_enTeamMode = (TTeamModeEnum) SvIV( poSv ); poSv = get_sv("TEAMSIZE", FALSE); if (poSv) m_iTeamSize = SvIV( poSv ); poSv = get_sv("TEAMMULTISELECT", FALSE); if (poSv) m_bTeamMultiselect = SvIV( poSv ); poSv = get_sv("GAMETIME", FALSE); if (poSv) m_iGameTime = SvIV( poSv ); poSv = get_sv("HITPOINTS", FALSE); if (poSv) m_iHitPoints = SvIV( poSv ); poSv = get_sv("GAMESPEED", FALSE); if (poSv) m_iGameSpeed = SvIV( poSv ); poSv = get_sv("FULLSCREEN", FALSE); if (poSv) m_bFullscreen = SvIV( poSv ); poSv = get_sv("CHANNELS", FALSE); if (poSv) m_iChannels = SvIV( poSv ); poSv = get_sv("MIXINGRATE", FALSE); if (poSv) m_iMixingRate = SvIV( poSv ); poSv = get_sv("MIXINGBITS", FALSE); if (poSv) m_iMixingBits = SvIV( poSv ); poSv = get_sv("MUSICVOLUME", FALSE); if (poSv) m_iMusicVolume = SvIV( poSv ); poSv = get_sv("SOUNDVOLUME", FALSE); if (poSv) m_iSoundVolume = SvIV( poSv ); poSv = get_sv("LANGUAGE", FALSE); if (poSv) { strncpy( m_acLanguage, SvPV_nolen( poSv ), 9 ); m_acLanguage[9] = 0; } poSv = get_sv("LATESTSERVER", FALSE); if (poSv) { strncpy( m_acLatestServer, SvPV_nolen( poSv ), 255 ); m_acLatestServer[255] = 0; } poSv = get_sv("SERVER", FALSE); if (poSv) m_bServer = SvIV( poSv ); poSv = get_sv("NICK", FALSE); if (poSv) { strncpy( m_acNick, SvPV_nolen( poSv ), 127 ); m_acNick[127] = 0; } char pcBuffer[1024]; for ( int i=0; i