Author: cjhopman
Date: Mon Apr 13 22:20:13 2009
New Revision: 34884

URL: http://svn.gna.org/viewcvs/wesnoth?rev=34884&view=rev
Log:
added --rng-seed command line option to specify the seed for the rng.

Modified:
    trunk/changelog
    trunk/src/game.cpp

Modified: trunk/changelog
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/changelog?rev=34884&r1=34883&r2=34884&view=diff
==============================================================================
--- trunk/changelog (original)
+++ trunk/changelog Mon Apr 13 22:20:13 2009
@@ -2,6 +2,8 @@
  * General:
    * The add-ons directory, <preferences>/data/campaigns, has been renamed
      and it is now <preferences>/data/add-ons
+   * Added --rng-seed command line option to specify a value to seed the random
+     number generator with.
  * AI:
    * Fixed incorrect handling of poisoning attacks when suggesting best attack
      in user interface

Modified: trunk/src/game.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/game.cpp?rev=34884&r1=34883&r2=34884&view=diff
==============================================================================
--- trunk/src/game.cpp (original)
+++ trunk/src/game.cpp Mon Apr 13 22:20:13 2009
@@ -386,6 +386,8 @@
                } else if(val == "--no-delay") {
                        game_config::no_delay = true;
                } else if (val.substr(0, 6) == "--log-") {
+               } else if (val == "--rng-seed") {
+                       ++arg_;
                } else if(val == "--nosound") {
                        no_sound = true;
                } else if(val == "--nomusic") {
@@ -1774,6 +1776,8 @@
                        << "  --nosound                    runs the game 
without sounds and music.\n"
                        << "  --path                       prints the path to 
the data directory and exits.\n"
                        << "  -r, --resolution XxY         sets the screen 
resolution. Example: -r 800x600\n"
+                       << "  --rng-seed <number>          seeds the random 
number generator with number\n"
+                       << "                               Example: --rng-seed 
0\n"
                        << "  --smallgui                   allows to use screen 
resolutions down to 800x480\n"
                        << "                               and resizes a few 
interface elements.\n"
                        << "  -s, --server [<host>]        connects to the host 
if specified\n"
@@ -1861,7 +1865,13 @@
                } else if(val == "--logdomains") {
                        std::cout << lg::list_logdomains() << "\n";
                        return 0;
-               }
+               } else if(val == "--rng-seed") {
+                       if (argc <= ++arg) {
+                               std::cerr << "format of \" " << val << " " << 
argv[arg] << " \" is bad\n";
+                               return 2;
+                       }
+                       srand(lexical_cast_default<unsigned int>(argv[arg]));
+               }
        }
 
        // Not the most intuitive solution, but I wanted to leave current 
semantics for now
@@ -1895,12 +1905,13 @@
  */
 static int do_gameloop(int argc, char** argv)
 {
+       srand(time(NULL));
+       
        int finished = process_command_args(argc, argv);
        if(finished != -1) {
                return finished;
        }
 
-       srand(time(NULL));
 
        game_controller game(argc,argv);
        const int start_ticks = SDL_GetTicks();


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to