Author: anonymissimus
Date: Fri Feb 25 19:57:01 2011
New Revision: 48636

URL: http://svn.gna.org/viewcvs/wesnoth?rev=48636&view=rev
Log:
add fire_event=yes|no key to [unstore_unit] for advance/post advance events if 
there is an advancement

Modified:
    trunk/src/actions.cpp
    trunk/src/actions.hpp
    trunk/src/dialogs.cpp
    trunk/src/dialogs.hpp
    trunk/src/game_events.cpp

Modified: trunk/src/actions.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/actions.cpp?rev=48636&r1=48635&r2=48636&view=diff
==============================================================================
--- trunk/src/actions.cpp (original)
+++ trunk/src/actions.cpp Fri Feb 25 19:57:01 2011
@@ -1945,7 +1945,7 @@
        return new_unit;
 }
 
-void advance_unit(map_location loc, const std::string &advance_to)
+void advance_unit(map_location loc, const std::string &advance_to, const bool 
&fire_event)
 {
        unit_map::unit_iterator u = resources::units->find(loc);
        if(!u.valid()) {
@@ -1953,16 +1953,20 @@
        }
        // original_type is not a reference, since the unit may disappear at 
any moment.
        std::string original_type = u->type_id();
-       LOG_NG << "firing advance event at " << loc <<"\n";
-
-       game_events::fire("advance",loc);
-
-       if (!u.valid() || u->experience() < u->max_experience() ||
-           u->type_id() != original_type)
+
+       if(fire_event)
        {
-               LOG_NG << "WML has invalidated the advancing unit, abort\n";
-               return;
-       }
+               LOG_NG << "firing advance event at " << loc <<"\n";
+               game_events::fire("advance",loc);
+
+               if (!u.valid() || u->experience() < u->max_experience() ||
+                       u->type_id() != original_type)
+               {
+                       LOG_NG << "WML has invalidated the advancing unit, 
abort\n";
+                       return;
+               }
+       }
+
 
        loc = u->get_location();
        unit new_unit = get_advanced_unit(*u, advance_to);
@@ -1972,8 +1976,11 @@
        LOG_CF << "Added '" << new_unit.type_id() << "' to encountered units\n";
 
        resources::units->replace(loc, new_unit);
-       LOG_NG << "firing post_advance event at " << loc << "\n";
-       game_events::fire("post_advance",loc);
+       if(fire_event)
+       {
+               LOG_NG << "firing post_advance event at " << loc << "\n";
+               game_events::fire("post_advance",loc);
+       }
 
        resources::whiteboard->on_gamestate_change();
 }

Modified: trunk/src/actions.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/actions.hpp?rev=48636&r1=48635&r2=48636&view=diff
==============================================================================
--- trunk/src/actions.hpp (original)
+++ trunk/src/actions.hpp Fri Feb 25 19:57:01 2011
@@ -295,7 +295,7 @@
  * we couldn't safely pass in a reference to the item in the map
  * that we're going to delete, since deletion would invalidate the reference.
  */
-void advance_unit(map_location loc, const std::string &advance_to);
+void advance_unit(map_location loc, const std::string &advance_to, const bool 
&fire_event = true);
 
 /**
  * function which tests if the unit at loc is currently affected by leadership.

Modified: trunk/src/dialogs.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/dialogs.cpp?rev=48636&r1=48635&r2=48636&view=diff
==============================================================================
--- trunk/src/dialogs.cpp (original)
+++ trunk/src/dialogs.cpp Fri Feb 25 19:57:01 2011
@@ -176,7 +176,7 @@
        }
 }
 
-bool animate_unit_advancement(const map_location &loc, size_t choice)
+bool animate_unit_advancement(const map_location &loc, size_t choice, const 
bool &fire_event)
 {
        const events::command_disabler cmd_disabler;
 
@@ -211,20 +211,27 @@
        if(choice < options.size()) {
                // chosen_unit is not a reference, since the unit may disappear 
at any moment.
                std::string chosen_unit = options[choice];
-               ::advance_unit(loc, chosen_unit);
+               ::advance_unit(loc, chosen_unit, fire_event);
        } else {
                unit amla_unit(*u);
                const config &mod_option = mod_options[choice - options.size()];
 
-               LOG_NG << "firing advance event (AMLA)\n";
-               game_events::fire("advance",loc);
+               if(fire_event)
+               {
+                       LOG_NG << "firing advance event (AMLA)\n";
+                       game_events::fire("advance",loc);
+               }
 
                amla_unit.set_experience(amla_unit.experience() - 
amla_unit.max_experience());
                amla_unit.add_modification("advance",mod_option);
                resources::units->replace(loc, amla_unit);
 
-               LOG_NG << "firing post_advance event (AMLA)\n";
-               game_events::fire("post_advance",loc);
+               if(fire_event)
+               {
+                       LOG_NG << "firing post_advance event (AMLA)\n";
+                       game_events::fire("post_advance",loc);
+               }
+
        }
 
        u = resources::units->find(loc);

Modified: trunk/src/dialogs.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/dialogs.hpp?rev=48636&r1=48635&r2=48636&view=diff
==============================================================================
--- trunk/src/dialogs.hpp (original)
+++ trunk/src/dialogs.hpp Fri Feb 25 19:57:01 2011
@@ -57,7 +57,7 @@
  * to be used to implement advances from any nonstandard situation. It does
  * not add a replay.
  */
-bool animate_unit_advancement(const map_location &loc, size_t choice);
+bool animate_unit_advancement(const map_location &loc, size_t choice, const 
bool &fire_event = true);
 
 void show_objectives(const config &level, const std::string &objectives);
 

Modified: trunk/src/game_events.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/game_events.cpp?rev=48636&r1=48635&r2=48636&view=diff
==============================================================================
--- trunk/src/game_events.cpp (original)
+++ trunk/src/game_events.cpp Fri Feb 25 19:57:01 2011
@@ -2049,7 +2049,7 @@
                                        (*resources::teams)[side - 
1].is_human();
                                config selected = 
mp_sync::get_user_choice("choose",
                                        unstore_unit_advance_choice(total_opt, 
loc, use_dialog));
-                               dialogs::animate_unit_advancement(loc, 
selected["value"]);
+                               dialogs::animate_unit_advancement(loc, 
selected["value"], cfg["fire_event"].to_bool(false));
                        }
                } else {
                        team& t = (*resources::teams)[u.side()-1];


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

Reply via email to