mail[Wesnoth-commits] r28490 - in /trunk/src: game_events.cpp gamestatus.cpp gamestatus.hpp


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by shadowm2006 on August 12, 2008 - 19:45:
Author: shadowmaster
Date: Tue Aug 12 19:45:51 2008
New Revision: 28490

URL: http://svn.gna.org/viewcvs/wesnoth?rev=28490&view=rev
Log:
* Made it possible to change current *turn* with WML ([modify_turns] 
current=XXX)

Modified:
    trunk/src/game_events.cpp
    trunk/src/gamestatus.cpp
    trunk/src/gamestatus.hpp

Modified: trunk/src/game_events.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/game_events.cpp?rev=28490&r1=28489&r2=28490&view=diff
==============================================================================
--- trunk/src/game_events.cpp (original)
+++ trunk/src/game_events.cpp Tue Aug 12 19:45:51 2008
@@ -797,13 +797,26 @@
        {
                std::string value = cfg["value"];
                std::string add = cfg["add"];
+               std::string current = cfg["current"];
                assert(state_of_game != NULL);
                assert(status_ptr != NULL);
                if(add != "") {
                        status_ptr->modify_turns(add);
                } else {
                        status_ptr->add_turns(-status_ptr->number_of_turns());
+                       //!@todo FIXME: why 50 is a good default for this?
                        
status_ptr->add_turns(lexical_cast_default<int>(value,50));
+               }
+               // change current turn only after applying mods
+               if(!current.empty()) {
+                       const int new_turn_number = 
lexical_cast_default<int>(current,1);
+                       const unsigned int new_turn_number_u = 
static_cast<unsigned int>(new_turn_number);
+                       if(new_turn_number < 1 || new_turn_number > 
status_ptr->number_of_turns()) {
+                               ERR_NG << "attempted to change current turn 
number to one out of range (" << new_turn_number << ")\n";
+                       } else if(new_turn_number_u != status_ptr->turn()) {
+                               status_ptr->set_turn(new_turn_number_u);
+                               (screen)->new_turn();
+                       }
                }
        }
 

Modified: trunk/src/gamestatus.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gamestatus.cpp?rev=28490&r1=28489&r2=28490&view=diff
==============================================================================
--- trunk/src/gamestatus.cpp (original)
+++ trunk/src/gamestatus.cpp Tue Aug 12 19:45:51 2008
@@ -393,6 +393,22 @@
        numTurns_ = maximum<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(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()
 {

Modified: trunk/src/gamestatus.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gamestatus.hpp?rev=28490&r1=28489&r2=28490&view=diff
==============================================================================
--- trunk/src/gamestatus.hpp (original)
+++ trunk/src/gamestatus.hpp Tue Aug 12 19:45:51 2008
@@ -195,8 +195,11 @@
        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 iff time has expired.
+       //! Returns true if time has not expired.
        bool next_turn();
 
        static bool is_start_ToD(const std::string&);




Related Messages


Powered by MHonArc, Updated Tue Aug 12 20:01:50 2008