Author: euschn
Date: Thu Jun 25 17:03:01 2009
New Revision: 36406
URL: http://svn.gna.org/viewcvs/wesnoth?rev=36406&view=rev
Log:
removed class gamestatus
Modified:
trunk/src/gamestatus.cpp
trunk/src/gamestatus.hpp
Modified: trunk/src/gamestatus.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gamestatus.cpp?rev=36406&r1=36405&r2=36406&view=diff
==============================================================================
--- trunk/src/gamestatus.cpp (original)
+++ trunk/src/gamestatus.cpp Thu Jun 25 17:03:01 2009
@@ -169,270 +169,6 @@
return uuid.str();
}
#endif
-
-void gamestatus::add_time_area(const config& cfg)
-{
- areas_.push_back(area_time_of_day());
- area_time_of_day &area = areas_.back();
- area.id = cfg["id"];
- area.xsrc = cfg["x"];
- area.ysrc = cfg["y"];
- std::vector<map_location> const& locs = parse_location_range(area.xsrc,
area.ysrc);
- std::copy(locs.begin(), locs.end(), std::inserter(area.hexes,
area.hexes.end()));
- time_of_day::parse_times(cfg, area.times);
-}
-
-void gamestatus::add_time_area(const std::string& id, const
std::set<map_location>& locs,
- const config& time_cfg)
-{
- areas_.push_back(area_time_of_day());
- area_time_of_day& area = areas_.back();
- area.id = id;
- area.hexes = locs;
- time_of_day::parse_times(time_cfg, area.times);
-}
-
-void gamestatus::remove_time_area(const std::string& area_id)
-{
- if(area_id.empty()) {
- areas_.clear();
- } else {
- // search for all time areas that match the id.
- std::vector<area_time_of_day>::iterator i = areas_.begin();
- while(i != areas_.end()) {
- if((*i).id == area_id) {
- i = areas_.erase(i);
- } else {
- ++i;
- }
- }
- }
-}
-
-gamestatus::gamestatus(const config& time_cfg, int num_turns, game_state*
s_o_g) :
- teams(0),
- times_(),
- areas_(),
- turn_(1),
- numTurns_(num_turns),
- currentTime_(0),
- state_of_game_(s_o_g)
-{
- std::string turn_at = time_cfg["turn_at"];
- std::string current_tod = time_cfg["current_tod"];
- std::string random_start_time = time_cfg["random_start_time"];
- if (s_o_g)
- {
- turn_at = utils::interpolate_variables_into_string(turn_at, *s_o_g);
- current_tod =
utils::interpolate_variables_into_string(current_tod, *s_o_g);
-
- }
-
- if(turn_at.empty() == false) {
- turn_ = atoi(turn_at.c_str());
- }
-
- time_of_day::parse_times(time_cfg,times_);
-
- set_start_ToD(const_cast<config&>(time_cfg),s_o_g);
-
- foreach (const config &t, time_cfg.child_range("time_area")) {
- this->add_time_area(t);
- }
-}
-
-void gamestatus::write(config& cfg) const
-{
- std::stringstream buf;
- buf << turn_;
- cfg["turn_at"] = buf.str();
- buf.str(std::string());
- buf << numTurns_;
- cfg["turns"] = buf.str();
- buf.str(std::string());
- buf << currentTime_;
- cfg["current_tod"] = buf.str();
-
- std::vector<time_of_day>::const_iterator t;
- for(t = times_.begin(); t != times_.end(); ++t) {
- t->write(cfg.add_child("time"));
- }
-
-
- for(std::vector<area_time_of_day>::const_iterator i = areas_.begin(); i
!= areas_.end(); ++i) {
- config& area = cfg.add_child("time_area");
- area["x"] = i->xsrc;
- area["y"] = i->ysrc;
- for(t = i->times.begin(); t != i->times.end(); ++t) {
- t->write(area.add_child("time"));
- }
-
- }
-}
-
-time_of_day gamestatus::get_time_of_day_turn(int nturn) const
-{
- VALIDATE(times_.size(), _("No time of day has been defined."));
-
- int time = (currentTime_ + nturn - turn())% times_.size();
-
- if (time < 0)
- {
- time += times_.size();
- }
-
- return times_[time];
-}
-
-time_of_day gamestatus::get_time_of_day() const
-{
- VALIDATE(times_.size(), _("No time of day has been defined."));
-
- return times_[currentTime_];
-}
-
-time_of_day gamestatus::get_previous_time_of_day() const
-{
- return get_time_of_day_turn(turn()-1);
-}
-
-time_of_day gamestatus::get_time_of_day(int illuminated, const map_location&
loc, int n_turn) const
-{
- time_of_day res = get_time_of_day_turn(n_turn);
-
- if(loc.valid()) {
- for(std::vector<area_time_of_day>::const_iterator i =
areas_.begin(); i != areas_.end(); ++i) {
- if(i->hexes.count(loc) == 1) {
-
- VALIDATE(i->times.size(), _("No time of day has
been defined."));
-
- res = i->times[(n_turn-1)%i->times.size()];
- break;
- }
- }
- }
-
- if(illuminated) {
- res.bonus_modified=illuminated;
- res.lawful_bonus += illuminated;
- }
- return res;
-}
-
-time_of_day gamestatus::get_time_of_day(int illuminated, const map_location&
loc) const
-{
- return get_time_of_day(illuminated,loc,turn());
-}
-
-bool gamestatus::set_time_of_day(int newTime)
-{
- // newTime can come from network so have to take run time test
- if( newTime >= static_cast<int>(times_.size())
- || newTime < 0)
- {
- return false;
- }
-
- currentTime_ = newTime;
-
- return true;
-}
-
-bool gamestatus::is_start_ToD(const std::string& random_start_time)
-{
- return !random_start_time.empty()
- && utils::string_bool(random_start_time, true);
-}
-
-void gamestatus::set_start_ToD(config &level, game_state* s_o_g)
-{
- if (!level["current_tod"].empty())
- {
- set_time_of_day(atoi(level["current_tod"].c_str()));
- return;
- }
- std::string random_start_time = level["random_start_time"];
- if (s_o_g)
- {
- random_start_time =
utils::interpolate_variables_into_string(random_start_time, *s_o_g);
- }
- if (gamestatus::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
- set_time_of_day(rand()%times_.size());
- }
- else
- {
-
set_time_of_day(atoi(start_strings[rand()%start_strings.size()].c_str()) - 1);
- }
- }
- else
- {
- // We have to set right ToD for oldsaves
-
- set_time_of_day((turn() - 1) % times_.size());
- }
- // Setting ToD to level data
-
- std::stringstream buf;
- buf << currentTime_;
- level["current_tod"] = buf.str();
-
-}
-
-void gamestatus::next_time_of_day()
-{
- VALIDATE(times_.size(), _("No time of day has been defined."));
-
- currentTime_ = (currentTime_ + 1)%times_.size();
-}
-
-size_t gamestatus::turn() const
-{
- return turn_;
-}
-
-int gamestatus::number_of_turns() const
-{
- return numTurns_;
-}
-void gamestatus::modify_turns(const std::string& mod)
-{
- numTurns_ = std::max<int>(utils::apply_modifier(numTurns_,mod,0),-1);
-}
-void gamestatus::add_turns(int num)
-{
- numTurns_ = std::max<int>(numTurns_ + num,-1);
-}
-
-void gamestatus::set_turn(unsigned int num)
-{
- VALIDATE(times_.size(), _("No time of day has been defined."));
- const unsigned int old_num = turn_;
- // Correct ToD
- currentTime_ = (num - 1) % times_.size();
- if (currentTime_ < 0) {
- currentTime_ += times_.size();
- }
- if(static_cast<int>(num) > numTurns_ && numTurns_ != -1) {
- this->add_turns(numTurns_ - num);
- }
- turn_ = num;
-
- LOG_NG << "changed current turn number from " << old_num << " to " <<
num << '\n';
-}
-
-bool gamestatus::next_turn()
-{
- next_time_of_day();
- ++turn_;
- return numTurns_ == -1 || turn_ <= size_t(numTurns_);
-}
static player_info read_player(const config &cfg)
{
Modified: trunk/src/gamestatus.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gamestatus.hpp?rev=36406&r1=36405&r2=36406&view=diff
==============================================================================
--- trunk/src/gamestatus.hpp (original)
+++ trunk/src/gamestatus.hpp Thu Jun 25 17:03:01 2009
@@ -185,131 +185,6 @@
game_classification classification_;
};
-/**
- * Contains the global status of the game.
- *
- * Namely the current turn, the number of turns, and the time of day.
- */
-class gamestatus
-{
-public:
- /**
- * Reads turns and time information from parameters.
- *
- * It sets random starting ToD and current_tod to config.
- */
- gamestatus(const config& time_cfg, int num_turns, game_state* s_o_g =
NULL);
- void write(config& cfg) const;
-
- /** Returns time of day object for current turn. */
- time_of_day get_time_of_day() const;
- time_of_day get_previous_time_of_day() const;
- time_of_day get_time_of_day(int illuminated, const map_location& loc)
const;
-
- /**
- * Returns time of day object in the turn.
- *
- * It first tries to look for specified. If no area time specified in
- * location, it returns global time.
- */
- time_of_day get_time_of_day(int illuminated, const map_location& loc,
int n_turn) const;
-
- /**
- * Sets global time of day in this turn.
- *
- * Time is a number between 0 and n-1, where n is number of ToDs.
- */
- bool set_time_of_day(int newTime);
- size_t turn() const;
- int number_of_turns() const;
- void modify_turns(const std::string& mod);
- void add_turns(int num);
-
- /** Dynamically change the current turn number. */
- void set_turn(unsigned int num);
-
- /**
- * Function to move to the next turn.
- *
- * @returns True if time has not expired.
- */
- bool next_turn();
-
- static bool is_start_ToD(const std::string&);
-
- /**
- * Adds a new local time area from config, making it follow its own
- * time-of-day sequence.
- *
- * @param cfg Config object containing x,y range/list of
- * locations and desired [time] information.
- */
- void add_time_area(const config& cfg);
-
- /**
- * Adds a new local time area from a set of locations, making those
- * follow a different time-of-day sequence.
- *
- * @param id Identifier string to associate this time
area
- * with.
- * @param locs Set of locations to be affected.
- * @param time_cfg Config object containing [time]
information.
- */
- void add_time_area(const std::string& id, const std::set<map_location>&
locs,
- const config& time_cfg);
-
- /**
- * Removes a time area from config, making it follow the scenario's
- * normal time-of-day sequence.
- *
- * @param id Identifier of time_area to remove. Supply
an
- * empty one to remove all local time areas.
- */
- void remove_time_area(const std::string& id);
-
- /**
- * @todo FIXME: since gamestatus may be constructed with NULL
game_state* (by default),
- * you should not rely on this function to return the current
game_state.
- */
- const game_state& sog() const{return(*state_of_game_);}
-
- std::vector<team> *teams;
-
-private:
- void set_start_ToD(config&, game_state*);
-
- /**
- * Returns time of day object in the turn.
- *
- * Correct time is calculated from current time.
- */
- time_of_day get_time_of_day_turn(int nturn) const;
- void next_time_of_day();
-
- std::vector<time_of_day> times_;
-
- struct area_time_of_day {
- area_time_of_day() :
- xsrc(),
- ysrc(),
- id(),
- times(),
- hexes()
- {}
-
- std::string xsrc, ysrc;
- std::string id;
- std::vector<time_of_day> times;
- std::set<map_location> hexes;
- };
-
- std::vector<area_time_of_day> areas_;
-
- size_t turn_;
- int numTurns_;
- int currentTime_;
- const game_state* state_of_game_;
-};
std::string generate_game_uuid();
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits