Author: anonymissimus
Date: Sun May 22 23:23:33 2011
New Revision: 49632
URL: http://svn.gna.org/viewcvs/wesnoth?rev=49632&view=rev
Log:
fixed random_start_time=<comma-separated integer list> being treated as
random_start_time=yes
There are major problems related to this function remaining:
- bug #15948
- The start time randomization result gets written into a const config&
in order to sent it to network clients in a mp game.
Modified:
trunk/src/tod_manager.cpp
trunk/src/tod_manager.hpp
Modified: trunk/src/tod_manager.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/tod_manager.cpp?rev=49632&r1=49631&r2=49632&view=diff
==============================================================================
--- trunk/src/tod_manager.cpp (original)
+++ trunk/src/tod_manager.cpp Sun May 22 23:23:33 2011
@@ -49,7 +49,12 @@
time_of_day::parse_times(time_cfg,times_);
- set_start_ToD(const_cast<config&>(time_cfg), turn_);
+ currentTime_ = get_start_ToD(time_cfg);
+ //TODO:
+ //Very bad, since we're pretending to not modify the cfg. Needed to
transfer the result
+ //to the network clients in a mp game, otherwise we have OOS.
+ config& non_const_config = const_cast<config&>(time_cfg);
+ non_const_config["current_tod"] = currentTime_;
}
tod_manager& tod_manager::operator=(const tod_manager& manager)
@@ -191,45 +196,34 @@
}
}
-void tod_manager::set_start_ToD(config &level, int current_turn)
-{
- if (!level["current_tod"].empty())
- {
- currentTime_ = calculate_current_time(times_.size(),
current_turn, level["current_tod"], true);
- return;
- }
- std::string random_start_time = level["random_start_time"];
- if (tod_manager::is_start_ToD(random_start_time))
- {
- std::vector<std::string> start_strings =
- utils::split(random_start_time, ',',
utils::STRIP_SPACES | utils::REMOVE_EMPTY);
-
- if (utils::string_bool(random_start_time,false))
- {
- // We had boolean value
- currentTime_ = calculate_current_time(times_.size(),
current_turn, rand(), true);
- }
- else
- {
- const int index =
calculate_current_time(start_strings.size(),
- current_turn, rand(), true);
- currentTime_ = calculate_current_time(
- times_.size(),
- current_turn,
- lexical_cast_default<int,
std::string>(start_strings[index], 1) - 1,
- true
- );
- }
- }
- else
- {
- // We have to set right ToD for oldsaves
- currentTime_ = calculate_current_time(times_.size(),
current_turn, currentTime_);
- }
- // Setting ToD to level data
-
- level["current_tod"] = currentTime_;
-
+const int tod_manager::get_start_ToD(const config &level) const
+{
+ const config::attribute_value& current_tod = level["current_tod"];
+ if (!current_tod.blank())
+ {
+ return calculate_current_time(times_.size(), turn_,
current_tod.to_int(0), true);
+ }
+
+ const int default_result = calculate_current_time(times_.size(), turn_,
currentTime_);
+
+ const config::attribute_value& cfg_random_start_time =
level["random_start_time"];
+ if(!cfg_random_start_time.blank()) {
+ const std::string& random_start_time =
cfg_random_start_time.str();
+ //TODO:
+ //Here there is danger of OOS (bug #15948)
+ //But this randomization is needed on the other hand to make
the "random start time" option
+ //in the mp game selection screen work.
+
+ //process the random_start_time string, which can be boolean
yes/no true/false or a
+ //comma-separated string of integers >= 1 referring to the
times_ array indices
+ const std::vector<std::string>& random_start_time_strings =
utils::split(random_start_time);
+ const int random_index =
calculate_current_time(random_start_time_strings.size(), turn_, rand(), true);
+ const int given_current_time = lexical_cast_default<int,
std::string>(random_start_time_strings[random_index], 0) - 1;
+ if(given_current_time >= 0) return
calculate_current_time(times_.size(), turn_, given_current_time, true);
+ if(cfg_random_start_time.to_bool(false)) return
calculate_current_time(times_.size(), turn_, rand(), true);
+ }
+
+ return default_result;
}
const time_of_day& tod_manager::get_time_of_day_turn(const
std::vector<time_of_day>& times, int nturn, const int current_time) const
Modified: trunk/src/tod_manager.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/tod_manager.hpp?rev=49632&r1=49631&r2=49632&view=diff
==============================================================================
--- trunk/src/tod_manager.hpp (original)
+++ trunk/src/tod_manager.hpp Sun May 22 23:23:33 2011
@@ -115,7 +115,7 @@
*/
bool is_time_left();
private:
- void set_start_ToD(config&, int current_turn);
+ const int get_start_ToD(const config& level) const;
/**
* Returns time of day object in the turn "nturn".
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits