OptionsGame.cpp

Go to the documentation of this file.
00001 ////////////////////////////////////////////////////////////////////////////////
00002 //    Scorched3D (c) 2000-2009
00003 //
00004 //    This file is part of Scorched3D.
00005 //
00006 //    Scorched3D is free software; you can redistribute it and/or modify
00007 //    it under the terms of the GNU General Public License as published by
00008 //    the Free Software Foundation; either version 2 of the License, or
00009 //    (at your option) any later version.
00010 //
00011 //    Scorched3D is distributed in the hope that it will be useful,
00012 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //    GNU General Public License for more details.
00015 //
00016 //    You should have received a copy of the GNU General Public License
00017 //    along with Scorched3D; if not, write to the Free Software
00018 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 ////////////////////////////////////////////////////////////////////////////////
00020 
00021 #include <common/OptionsGame.h>
00022 #include <common/Defines.h>
00023 #include <string.h>
00024 
00025 static OptionEntryEnum::EnumEntry scoreEnum[] =
00026 {
00027         { "ScoreWins", 0 },
00028         { "ScoreKills", 1 },
00029         { "ScoreMoney", 2 },
00030         { "", -1 }
00031 };
00032 
00033 static OptionEntryEnum::EnumEntry turnEnum[] =
00034 {
00035         { "TurnSimultaneous", 0 },
00036         { "TurnSequentialLooserFirst", 1 },
00037         { "TurnSequentialRandom", 2 },
00038         { "", -1 }
00039 };
00040 
00041 static OptionEntryEnum::EnumEntry windForceEnum[] =
00042 {
00043         { "WindRandom", 0 },
00044         { "WindNone", 1 },
00045         { "Wind1", 2 },
00046         { "Wind2", 3 },
00047         { "Wind3", 4 },
00048         { "Wind4", 5 },
00049         { "Wind5", 6 },
00050         { "WindBreezy", 7 },
00051         { "WindGale", 8 },
00052         { "", -1 }
00053 };
00054 
00055 static OptionEntryEnum::EnumEntry windTypeEnum[] =
00056 {
00057         { "WindOnRound", 0 },
00058         { "WindOnMove", 1 },
00059         { "", -1 }
00060 };
00061 
00062 static OptionEntryEnum::EnumEntry wallEnum[] =
00063 {
00064         { "WallRandom", 0 },
00065         { "WallConcrete", 1 },
00066         { "WallBouncy", 2 },
00067         { "WallWrapAround", 3 },
00068         { "WallNone", 4 },
00069         { "WallActive", 5 },
00070         { "WallInactive", 6},
00071         { "", -1 }
00072 };
00073 
00074 static OptionEntryEnum::EnumEntry weapScaleEnum[] =
00075 {
00076         { "ScaleSmall", 0 },
00077         { "ScaleMedium", 1 },
00078         { "ScaleLarge", 2 },
00079         { "", -1 }
00080 };
00081 
00082 static OptionEntryEnum::EnumEntry resignEnum[] =
00083 {
00084         { "ResignStart", 0 },
00085         { "ResignEnd", 1 },
00086         { "ResignDueToHealth", 2 },
00087         { "", -1 }
00088 };
00089 
00090 static OptionEntryEnum::EnumEntry movementRestrictionEnum[] =
00091 {
00092         { "MovementRestrictionNone", 0 },
00093         { "MovementRestrictionLand", 1 },
00094         { "MovementRestrictionLandOrAbove", 2 },
00095         { "", -1 }
00096 };
00097 
00098 static OptionEntryEnum::EnumEntry teamBallanceEnum[] =
00099 {
00100         { "TeamBallanceNone", 0 },
00101         { "TeamBallanceAuto", 1 },
00102         { "TeamBallanceBotsVs", 2 },
00103         { "TeamBallanceAutoByScore", 3 },
00104         { "TeamBallanceAutoByBots", 4 },
00105         { "", -1 }
00106 };
00107 
00108 static OptionEntryStringEnum::EnumEntry economyEnum[] =
00109 {
00110         { "EconomyFreeMarket" },
00111         { "EconomyNone" },
00112         { "" }
00113 };
00114 
00115 static OptionEntryStringEnum::EnumEntry serverFileLoggerEnum[] =
00116 {
00117         { "none" },
00118         { "file" },
00119         { "" }
00120 };
00121 
00122 static OptionEntryStringEnum::EnumEntry statsLoggerEnum[] =
00123 {
00124         { "none" },
00125         { "file" },
00126         { "mysql" },
00127         { "" }
00128 };
00129 
00130 static OptionEntryStringEnum::EnumEntry authHandlerEnum[] =
00131 {
00132         { "none" },
00133         { "prefered" },
00134         { "forumlogin" },
00135         { "minkills" },
00136         { "" }
00137 };
00138 
00139 OptionsGame::OptionsGame() :
00140         physicsFPS_(options_, "PhysicsFPS",
00141                 "The speed at which the physics engine will calculate steps", 0, 66, 20, 100, 1),
00142         tutorial_(options_, "Tutorial",
00143                 "The tutorial to load for this game", 0, ""),
00144         scorePerMoney_(options_, "ScorePerMoney",
00145                 "The amount of score awarded for 100 money units earned", 0, 0, 0, 100, 2),
00146         scorePerAssist_(options_, "ScorePerAssist",
00147                 "The amount of score awarded for each kill assist", 0, 2, 0, 50, 1),
00148         scorePerKill_(options_, "ScorePerKill",
00149                 "The amount of score awarded for each kill", 0, 10, 0, 50, 1),
00150         scoreWonForRound_(options_, "ScoreWonForRound",
00151                 "The amount of score awarded for round won", 0, 250, 0, 1000, 50),
00152         scoreWonForLives_(options_, "ScoreWonForLives",
00153                 "The amount of score awarded for lives left", 0, 0, 0, 1000, 50),
00154         teams_(options_, "Teams",
00155                 "The number of teams (1 == no teams)", 0, 1, 1, 4, 1),
00156         startArmsLevel_(options_, "StartArmsLevel",
00157                 "The largest weapon type allowed (on round 1)", 0, 10, 0, 10, 1),
00158         endArmsLevel_(options_, "EndArmsLevel",
00159                 "The largest weapon type allowed (on the last round)", 0, 10, 0, 10, 1),
00160         maxNumberWeapons_(options_, "MaxNumberWeapons",
00161                 "The number of each weapon the player is allowed", 0, 90, 0, 500, 10),
00162         maxLandscapeSize_(options_, "MaxLandscapeSize",
00163                 "The largest landscape (in bytes) that will be sent to the clients", 0, 200000),
00164         startTime_(options_, "StartTime", 
00165                 "The amount of time before a new game starts", 0, 0, 0, 90, 5),
00166         shotTime_(options_, "ShotTime", 
00167                 "The amount of time each player has for each shot", 0, 0, 0, 90, 5),
00168         buyingTime_(options_, "BuyingTime", 
00169                 "The amount of time each player has to buy weapons and use auto defense", 0, 0, 0, 90, 5),
00170         allowedMissedMoves_(options_, "AllowedMissedMoves",
00171                 "The number of moves a player is allowed to miss (due to the shot timer)", 0, 3, 0, 10, 1),
00172         roundScoreTime_(options_, "RoundScoreTime", 
00173                 "The amount of time to show the end of each round for", 0, 5, 0, 30, 1),
00174         scoreTime_(options_, "ScoreTime", 
00175                 "The amount of time to show the end of match scores for", 0, 15, 0, 90, 5),
00176         keepAliveTime_(options_, "KeepAliveTime",
00177                 "The amount of time between each client keep alive message", 0, 2, 0, 30, 1),
00178         keepAliveTimeoutTime_(options_, "KeepAliveTimeoutTIme",
00179                 "The amount of time the server will allow without receiving a keep alive message", 0, 0, 0, 90, 5),
00180         idleKickTime_(options_, "IdleKickTime",
00181                 "The amount of time to give clients to respond after level loading before kicking them", 0, 60, 0, 90, 5),
00182         idleShotKickTime_(options_, "IdleShotKickTime",
00183                 "The amount of time to give clients to respond after shots before kicking them", 0, 45, 0, 90, 5),
00184         minFallingDistance_(options_, "MinFallingDistance",
00185                 "The minimum distance that can be made with no damage (value is divided by 10)", 0, 5, 0, 100, 5),
00186         maxClimbingDistance_(options_, "MaxClimbingDistance",
00187                 "The maximum distance that a tank can climb per movement square (divided by 10)", 0, 8, 0, 20, 1),
00188         playerLives_(options_, "PlayerLives",
00189                 "The number of lives that each player tank has", 0, 1, 0, 10, 1),
00190         gravity_(options_, "Gravity",
00191                 "The gravity used by the physics engine", 0, -10, -25, 0, 1),
00192         maxRoundTurns_(options_, "MaxNumberOfRoundTurns",
00193                 "The maximum number of turns all players are allowed in each round (0 = infinite)", 0, 15, 0, 50, 1),
00194         numberOfRounds_(options_, "NumberOfRounds", 
00195                 "The number of rounds to play in each game", 0, 5, 1, 50, 1),
00196         numberOfPlayers_(options_, "NumberOfPlayers", 
00197                 "The maximum number of players to allow", 0, 2, 2, 24, 1),
00198         numberOfMinPlayers_(options_, "NumberOfMinPlayers", 
00199                 "The minimum number of players to allow", 0, 2, 2, 24, 1),
00200         removeBotsAtPlayers_(options_, "RemoveBotsAtPlayers",
00201                 "The number of players to allow before remvoing bots", 0, 0, 0, 24, 1),
00202         limitPowerByHealth_(options_, "LimitPowerByHealth", 
00203                 "Show power is limited by the amount of health a player has", 0, true),
00204         residualPlayers_(options_, "ResidualPlayers",
00205                 "Players that leave will have the same state when reconnecting", 0, true),
00206         autoSendSyncCheck_(options_, "AutoSendSyncCheck",
00207                 "Automatically send a sync check at the end of each shot", 0, false),
00208         actionSyncCheck_(options_, "ActionSyncCheck",
00209                 "Gather enhanced action syncchecking", 0, false),
00210         resignMode_(options_, "ResignMode",
00211                 "When does a players resign take place", 0, int(ResignEnd), resignEnum),
00212         movementRestriction_(options_, "MovementRestriction",
00213                 "Where a tank is allowed to move to", 0, int(MovementRestrictionNone), movementRestrictionEnum),
00214         teamBallance_(options_, "TeamBallance",
00215                 "The mode of team auto-ballancing performed for team games", 0, int(TeamBallanceNone), teamBallanceEnum),
00216         turnType_(options_, "TurnType", 
00217                 "The player turn mode", 0,      int(TurnSequentialLooserFirst), turnEnum), // Data, default, min, max
00218         moneyBuyOnRound_(options_, "MoneyBuyOnRound", 
00219                 "The first round players are allowed to buy on", 0 ,2, 1, 50, 1),
00220         moneyWonForRound_(options_, "MoneyWonForRound", 
00221                 "The money awarded for each won round", 0, 5000, 0, 100000, 1000),
00222         moneyWonForLives_(options_, "MoneyWonForLives",
00223                 "The money awarded for each life remaining", 0, 5000, 0, 100000, 1000),
00224         moneyPerKillPoint_(options_, "MoneyWonPerKillPoint", 
00225                 "The money awarded for each person killed * weapon used", 0, 750, 0, 2000, 50),
00226         moneyPerMultiKillPoint_(options_, "MoneyWonPerMultiKillPoint", 
00227                 "The extra money awarded for each person multi-killed * weapon used * multi-kill", 0, 0, 0, 2000, 50),
00228         moneyPerAssistPoint_(options_, "MoneyWonPerAssistPoint", 
00229                 "The money awarded for each kill assist * weapon used", 0, 250, 0, 2000, 50),
00230         moneyPerHitPoint_(options_, "MoneyWonPerHitPoint", 
00231                 "The money awarded for each person hit * weapon used", 0, 250, 0, 2000, 50),
00232         moneyPerRound_(options_, "MoneyPerRound", 
00233                 "The money given at the end of each round", 0, 0, 0, 250000, 5000),
00234         moneyPerHealthPoint_(options_, "MoneyPerHealthPoint",
00235                 "The money awarded is proportional to the amount of health removed", 0, true),
00236         moneyStarting_(options_, "MoneyStarting", 
00237                 "The money each player starts with", 0, 10000, 0, 500000, 10000),
00238         moneyInterest_(options_, "MoneyInterest", 
00239                 "The interest awarded at the end of each round", 0, 15, 0, 100, 5),
00240         freeMarketAdjustment_(options_, "FreeMarketAdjustment",
00241                 "The scale of the adjustment changes made by the free market", 0, 100),
00242         freeMarketLimits_(options_, "FreeMarketLimits",
00243                 "The scale of the max/min prices (*1.5) allowed by the free market e.g. 2 is a 300% increase/reduction", 0, 2),
00244         windForce_(options_, "WindForce", 
00245                 "The force of the wind", 0, int(WindRandom), windForceEnum),
00246         windType_(options_, "WindType", 
00247                 "When the wind changes", 0, int(WindOnRound), windTypeEnum),
00248         wallType_(options_, "WallType", 
00249                 "The type of walls allowed", 0, int(WallRandom), wallEnum),
00250         weapScale_(options_, "WeaponScale", 
00251                 "The scale of the weapons used", 0, int(ScaleMedium), weapScaleEnum),
00252         statsLogger_(options_, "StatsLogger",
00253                 "The type of player stats to be logged", 0, "none", statsLoggerEnum),
00254         serverFileLogger_(options_, "ServerLogger",
00255         "The type of server events to be logged to file", 0, "none", serverFileLoggerEnum),
00256         portNo_(options_, "PortNo", 
00257                 "The port to start the server on", 0, S3D::ScorchedPort),
00258         managementPortNo_(options_, "ManagementPortNo", 
00259                 "The port to start the managament web server on (0 = management off)", 0, 0),
00260         serverName_(options_, "ServerName", 
00261                 "The name of the server to start", 0, "No Name"),
00262         mod_(options_, "Mod", 
00263                 "The name of currently running Scorched3D mod", 0, "none"),
00264         motd_(options_, "MOTD",
00265                 "The message of the day", 0, 
00266                 "Scorched3D : Copyright 2004 Gavin Camp\n"
00267                 "For updates and news visit:\n"
00268                 "http://www.scorched3d.co.uk",
00269                 true),
00270         modDownloadSpeed_(options_, "ModDownloadSpeed",
00271                 "Max download speed of mods in bytes per second (0 == no mod download)", 0, 0, 0, 500000, 5000),
00272         maxAvatarSize_(options_, "MaxAvatarSize",
00273                 "Max size allowed for avatars in bytes (0 == no avatars)", 0, 5000),
00274         economy_(options_, "Economy", 
00275                 "Speicifies the name of the economy to use", 0, "EconomyFreeMarket", economyEnum),
00276         landscapes_(options_, "Landscapes", 
00277                 "Colon seperated list of landscape names", 0, ""),
00278         serverPassword_(options_, "ServerPassword", 
00279                 "The password for this server (empty password = no password)", OptionEntry::DataProtected, ""),
00280         allowSameIP_(options_, "AllowSameIP",
00281                 "Allow scorched clients from same machine/NAT router to connect.", 0, true),
00282         allowSameUniqueId_(options_, "AllowSameUniqueId",
00283                 "Allow scorched clients with same unique id to connect.", 0, true),
00284         publishServer_(options_, "PublishServer",
00285                 "Allow other scorched net clients to see this server.  Do not use for LAN games.", 0, false),
00286         publishAddress_(options_, "PublishAddress",
00287                 "IP address to publish to scorched net clients (auto-detected if not given).", 0, "AutoDetect"),
00288         botNamePrefix_(options_, "BotNamePrefix", 
00289                 "Prepend and bot name with the specified text", 0, "(Bot) "),
00290         giveAllWeapons_(options_, "GiveAllWeapons",
00291                 "Start the game will all the weapons", 0, false),
00292         registeredUserNames_(options_, "RegisteredUserNames",
00293                 "Only allow authenticated players to use their own player names", 0, false),
00294         allowMultiLingualChat_(options_, "AllowMultiLingualChat",
00295                 "Allow internaltional (non-latin) characters in chat", 0, true),
00296         allowMultiLingualNames_(options_, "AllowMultiLingualNames",
00297                 "Allow internaltional (non-latin) characters in names", 0, true),
00298         authHandler_(options_, "AuthHandler",
00299                 "Only allow authenticated players to connect", 0, "none", authHandlerEnum),
00300         cycleMaps_(options_, "CycleMaps",
00301                 "Cycle through the maps instead of choosing them using a random probablity", 0, false),
00302         delayedDefenseActivation_(options_, "DelayedDefenseActivation",
00303                 "Changes to shields and parachutes are only seen after the aiming phase", 0, false),
00304         randomizeBotNames_(options_, "RandomizeBotNames",
00305                 "Choose random bot names instread of sequential names", 0, false),
00306         computersDeathTalk_(options_, "ComputersDeathTalk",
00307                 "The percentage chance the computers will say something when killed", 0, 100, 0, 100, 10),
00308         computersAttackTalk_(options_, "ComputersAttackTalk",
00309                 "The percentage chance the computers will say something when shooting", 0, 25, 0, 100, 10),
00310         debugFeatures_(options_, "DebugFeatures",
00311                 "Set to \"true\" to enable debugging features such as InfoGrid", 0, false),
00312 
00313 
00314         // Deprecated options
00315         depricatedMasterListServer_(options_, "MasterListServer",
00316                 "The master list server for scorched3d", OptionEntry::DataDepricated, "scorched3d.sourceforge.net"),
00317         depricatedMasterListServerURI_(options_, "MasterListServerURI",
00318                 "The URI on the master list server for scorched3d", OptionEntry::DataDepricated, "/scorched"),
00319         depricatedServerAdminPassword_(options_, "ServerAdminPassword", 
00320                 "The admin password for this server (empty password = no access)", OptionEntry::DataDepricated, ""),
00321         depricatedMaxArmsLevel_(options_, "MaxArmsLevel",
00322                 "", OptionEntry::DataDepricated, 10, 0, 10, 1),
00323         depricatedAutoBallanceTeams_(options_, "AutoBallanceTeams",
00324                 "", OptionEntry::DataDepricated, true),
00325         depricatedScoreType_(options_, "ScoreType",
00326                 "How the winnder is choosen", OptionEntry::DataDepricated, 0, scoreEnum)
00327 {
00328         char buffer[128];
00329         for (int i=0; i<24; i++)
00330         {
00331                 snprintf(buffer, 128, "PlayerType%i", i+1);
00332                 playerType_[i] = new OptionEntryString(playerTypeOptions_,
00333                         buffer,
00334                         "The type of the player e.g. human, computer etc..", 0,
00335                         "Human");
00336         }
00337 }
00338 
00339 OptionsGame::~OptionsGame()
00340 {
00341         
00342 }
00343 
00344 bool OptionsGame::writeToBuffer(NetBuffer &buffer,
00345         bool useProtected,
00346         bool usePlayerTypes)
00347 {
00348         std::list<OptionEntry *> saveOptions;
00349         if (usePlayerTypes) saveOptions = playerTypeOptions_;
00350         std::list<OptionEntry *>::iterator itor;
00351         for (itor = options_.begin();
00352                 itor != options_.end();
00353                 itor++)
00354         {
00355                 OptionEntry *entry = *itor;
00356                 saveOptions.push_back(entry);
00357         }
00358 
00359         if (!OptionEntryHelper::writeToBuffer(
00360                 saveOptions, buffer, useProtected)) return false;
00361         return true;
00362 }
00363 
00364 bool OptionsGame::readFromBuffer(NetBufferReader &reader,
00365         bool useProtected,
00366         bool usePlayerTypes)
00367 {
00368         std::list<OptionEntry *> saveOptions;
00369         if (usePlayerTypes) saveOptions = playerTypeOptions_;
00370         std::list<OptionEntry *>::iterator itor;
00371         for (itor = options_.begin();
00372                 itor != options_.end();
00373                 itor++)
00374         {
00375                 OptionEntry *entry = *itor;
00376                 saveOptions.push_back(entry);
00377         }
00378 
00379         if (!OptionEntryHelper::readFromBuffer(
00380                 saveOptions, reader, useProtected)) return false;
00381         return true;
00382 }
00383 
00384 bool OptionsGame::writeOptionsToXML(XMLNode *node)
00385 {
00386         if (!OptionEntryHelper::writeToXML(options_, node)) return false;
00387         return true;
00388 }
00389 
00390 bool OptionsGame::readOptionsFromXML(XMLNode *node)
00391 {
00392         if (!OptionEntryHelper::readFromXML(options_, node)) return false;
00393         return true;
00394 }
00395 
00396 bool OptionsGame::writeOptionsToFile(const std::string &filePath)
00397 {
00398         std::list<OptionEntry *> saveOptions = 
00399                 playerTypeOptions_; // Note: The players are also saved
00400         std::list<OptionEntry *>::iterator itor;
00401         for (itor = options_.begin();
00402                 itor != options_.end();
00403                 itor++)
00404         {
00405                 OptionEntry *entry = *itor;
00406                 saveOptions.push_back(entry);
00407         } 
00408 
00409         if (!OptionEntryHelper::writeToFile(saveOptions, filePath)) return false;
00410         return true;
00411 }
00412 
00413 bool OptionsGame::readOptionsFromFile(const std::string &filePath)
00414 {
00415         std::list<OptionEntry *> saveOptions = 
00416                 playerTypeOptions_; // Note: The players are also saved
00417         std::list<OptionEntry *>::iterator itor;
00418         for (itor = options_.begin();
00419                 itor != options_.end();
00420                 itor++)
00421         {
00422                 OptionEntry *entry = *itor;
00423                 saveOptions.push_back(entry);
00424         } 
00425 
00426         if (!OptionEntryHelper::readFromFile(saveOptions, filePath)) return false;
00427         return true;
00428 }
00429 
00430 std::list<OptionEntry *> &OptionsGame::getPlayerTypeOptions()
00431 {
00432         return playerTypeOptions_;
00433 }
00434 
00435 std::list<OptionEntry *> &OptionsGame::getOptions()
00436 {
00437         return options_;
00438 }

Generated on Mon Feb 16 15:14:49 2009 for Scorched3D by  doxygen 1.5.3