tod_manager.hpp

Go to the documentation of this file.
00001 /*
00002    Copyright (C) 2009 - 2012 by Eugen Jiresch
00003    Part of the Battle for Wesnoth Project http://www.wesnoth.org/
00004 
00005    This program is free software; you can redistribute it and/or modify
00006    it under the terms of the GNU General Public License as published by
00007    the Free Software Foundation; either version 2 of the License, or
00008    (at your option) any later version.
00009    This program is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY.
00011 
00012    See the COPYING file for more details.
00013  */
00014 #ifndef TOD_MANAGER_HPP_INCLUDED
00015 #define TOD_MANAGER_HPP_INCLUDED
00016 
00017 #include "map_location.hpp"
00018 #include "config.hpp"
00019 #include "time_of_day.hpp"
00020 #include "savegame_config.hpp"
00021 
00022 class game_state;
00023 class gamemap;
00024 class unit_map;
00025 
00026 //time of day and turn functionality
00027 class tod_manager : public savegame::savegame_config
00028 {
00029     public:
00030     explicit tod_manager(const config& scenario_cfg = config(), const int num_turns = -1);
00031         ~tod_manager() {}
00032         tod_manager& operator=(const tod_manager& manager);
00033 
00034         config to_config() const;
00035 
00036         /**
00037          * Returns global time of day for the passed turn.
00038          * for_turn = 0 means current turn
00039          */
00040         const time_of_day& get_time_of_day(int for_turn = 0) const {
00041             return get_time_of_day_turn(times_, for_turn ? for_turn : turn_, currentTime_);
00042         }
00043 
00044         /**
00045          * Returns time of day for the passed turn at a location.
00046          * tod areas matter, for_turn = 0 means current turn
00047          * ignoring illumination
00048          */
00049         const time_of_day& get_time_of_day(const map_location& loc,
00050                 int for_turn = 0) const;
00051 
00052         /**
00053          * Returns time of day object for the passed turn at a location.
00054          * tod areas matter, for_turn = 0 means current turn
00055          * taking account of illumination caused by units
00056          */
00057         const time_of_day get_illuminated_time_of_day(const map_location& loc,
00058                 int for_turn = 0) const;
00059 
00060         const time_of_day& get_previous_time_of_day() const;
00061 
00062         static bool is_start_ToD(const std::string&);
00063 
00064         /**
00065          * Replace the time of day schedule
00066          */
00067         void replace_schedule(const config& time_cfg);
00068 
00069         /**
00070          * Adds a new local time area from config, making it follow its own
00071          * time-of-day sequence.
00072          *
00073          * @param cfg                 Config object containing x,y range/list of
00074          *                            locations and desired [time] information.
00075          */
00076         void add_time_area(const config& cfg);
00077 
00078         /**
00079          * Adds a new local time area from a set of locations, making those
00080          * follow a different time-of-day sequence.
00081          *
00082          * @param id                  Identifier string to associate this time area
00083          *                            with.
00084          * @param locs                Set of locations to be affected.
00085          * @param time_cfg            Config object containing [time] information.
00086          */
00087         void add_time_area(const std::string& id, const std::set<map_location>& locs,
00088                 const config& time_cfg);
00089 
00090         /**
00091          * Removes a time area from config, making it follow the scenario's
00092          * normal time-of-day sequence.
00093          *
00094          * @param id                  Identifier of time_area to remove. Supply an
00095          *                            empty one to remove all local time areas.
00096          */
00097         void remove_time_area(const std::string& id);
00098 
00099         bool has_time_area() const {return !areas_.empty();};
00100 
00101         const std::vector<time_of_day> times() const {return times_;}
00102 
00103         //turn functions
00104         int turn() const { return turn_; }
00105         int number_of_turns() const {return num_turns_;}
00106         void modify_turns(const std::string& mod);
00107         void set_number_of_turns(int num);
00108 
00109         /** Dynamically change the current turn number. */
00110         void set_turn(const int num, const bool increase_limit_if_needed = true);
00111 
00112         /**
00113          * Function to move to the next turn.
00114          *
00115          * @returns                   True if time has not expired.
00116          */
00117         bool next_turn();
00118 
00119         /**
00120          * Function to check the end of turns.
00121          *
00122          * @returns                   True if time has not expired.
00123          */
00124         bool is_time_left();
00125     private:
00126         int get_start_ToD(const config& level) const;
00127 
00128         /**
00129          * Returns time of day object in the turn "nturn".
00130          *
00131          * Correct time is calculated from current time.
00132          */
00133         const time_of_day& get_time_of_day_turn(const std::vector<time_of_day>& times, int nturn, const int current_time) const;
00134 
00135         /**
00136          * Computes for the main time or a time area the index of its times where we're currently at.
00137          * number_of_times: size of that main time or time area's times vector
00138          * for_turn_number: for which current turn
00139          * current_time: the main or time area's current time
00140          */
00141         int calculate_current_time(
00142             const int number_of_times,
00143             const int for_turn_number,
00144             const int current_time,
00145             const bool only_to_allowed_range = false) const;
00146 
00147         /**
00148          * For a change of the current turn number, sets the current times of the main time
00149          * and all time areas.
00150          */
00151         void set_new_current_times(const int new_current_turn_number);
00152 
00153 
00154         struct area_time_of_day {
00155             area_time_of_day() :
00156                 xsrc(),
00157                 ysrc(),
00158                 id(),
00159                 times(),
00160                 hexes(),
00161                 currentTime(0)
00162             {}
00163 
00164             std::string xsrc, ysrc;
00165             std::string id;
00166             std::vector<time_of_day> times;
00167             std::set<map_location> hexes;
00168             int currentTime;
00169         };
00170 
00171         //index of the times vector of the main time where we're currently at
00172         int currentTime_;
00173         std::vector<time_of_day> times_;
00174         std::vector<area_time_of_day> areas_;
00175 
00176         // current turn
00177         int turn_;
00178         //turn limit
00179         int num_turns_;
00180 };
00181 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by doxygen 1.7.1 on Fri May 25 2012 01:03:12 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs