Author: fendrin
Date: Mon Nov  7 19:23:48 2011
New Revision: 51918

URL: http://svn.gna.org/viewcvs/wesnoth?rev=51918&view=rev
Log:
fix bug #18931 and bug #18929
Makes the replay engine aware of the multiple leader recall/recruit stuff.

Modified:
    trunk/src/actions.hpp
    trunk/src/ai/actions.cpp
    trunk/src/menu_events.cpp
    trunk/src/replay.cpp
    trunk/src/replay.hpp

Modified: trunk/src/actions.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/actions.hpp?rev=51918&r1=51917&r2=51918&view=diff
==============================================================================
--- trunk/src/actions.hpp (original)
+++ trunk/src/actions.hpp Mon Nov  7 19:23:48 2011
@@ -356,6 +356,7 @@
                        starting_moves(sm),
                        original_village_owner(orig),
                        recall_loc(),
+                       recall_from(),
                        type(NONE),
                        affected_unit(u),
                        countdown_time_bonus(timebonus),
@@ -363,12 +364,13 @@
                {
                }
 
-       undo_action(const unit& u, const map_location& loc,
+       undo_action(const unit& u, const map_location& loc, const map_location& 
from,
                const ACTION_TYPE action_type=NONE) :
                        route(),
                        starting_moves(),
                        original_village_owner(),
                        recall_loc(loc),
+                       recall_from(from),
                        type(action_type),
                        affected_unit(u),
                        countdown_time_bonus(1),
@@ -379,6 +381,7 @@
        int starting_moves;
        int original_village_owner;
        map_location recall_loc;
+       map_location recall_from;
        ACTION_TYPE type;
        unit affected_unit;
        int countdown_time_bonus;

Modified: trunk/src/ai/actions.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/ai/actions.cpp?rev=51918&r1=51917&r2=51918&view=diff
==============================================================================
--- trunk/src/ai/actions.cpp (original)
+++ trunk/src/ai/actions.cpp Mon Nov  7 19:23:48 2011
@@ -680,7 +680,7 @@
        } else {
 
                unit &un = *rec;
-               recorder.add_recall(un.id(), recall_location_);
+               recorder.add_recall(un.id(), recall_location_, recall_from_);
                place_recruit(un, recall_location_, recall_from_, true, true);
                statistics::recall_unit(un);
                my_team.spend_gold(my_team.recall_cost());
@@ -881,15 +881,14 @@
        // However, we're not sure if the transaction will be successful,
        // so use a replay_undo object to cancel it if we don't get
        // a confirmation for the transaction.
-       recorder.add_recruit(num_,recruit_location_);
+       recorder.add_recruit(num_,recruit_location_,recruit_from_);
        replay_undo replay_guard(recorder);
        const unit_type *u = unit_types.find(unit_name_);
        const events::command_disabler disable_commands;
-       map_location recruit_from = map_location::null_location;
-       const std::string recruit_err = find_recruit_location(get_side(), 
recruit_location_, recruit_from, u->id());
+       const std::string recruit_err = find_recruit_location(get_side(), 
recruit_location_, recruit_from_, u->id());
        if(recruit_err.empty()) {
                const unit new_unit(u, get_side(), true);
-               place_recruit(new_unit, recruit_location_, recruit_from, false, 
preferences::show_ai_moves());
+               place_recruit(new_unit, recruit_location_, recruit_from_, 
false, preferences::show_ai_moves());
                statistics::recruit_unit(new_unit);
                get_my_team().spend_gold(u->cost());
                // Confirm the transaction - i.e. don't undo recruitment
@@ -905,7 +904,6 @@
                set_error(AI_ACTION_FAILURE);
        }
 
-
 }
 
 

Modified: trunk/src/menu_events.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/menu_events.cpp?rev=51918&r1=51917&r2=51918&view=diff
==============================================================================
--- trunk/src/menu_events.cpp (original)
+++ trunk/src/menu_events.cpp Mon Nov  7 19:23:48 2011
@@ -116,7 +116,7 @@
                // Remove the item from filter_textbox memory
                filter_.delete_item(index);
                //add dismissal to the undo stack
-               resources::undo_stack->push_back(undo_action(u, map_location(), 
undo_action::DISMISS));
+               resources::undo_stack->push_back(undo_action(u, map_location(), 
map_location(), undo_action::DISMISS));
 
                //remove the unit from the recall list
                std::vector<unit>& recall_list = (*resources::teams)[u.side() 
-1].recall_list();
@@ -803,7 +803,7 @@
 
        if (!resources::whiteboard->save_recruit(name, side_num, loc)) {
                //create a unit with traits
-               recorder.add_recruit(recruit_num, loc);
+               recorder.add_recruit(recruit_num, loc, recruited_from);
                const unit new_unit(u_type, side_num, true);
                place_recruit(new_unit, loc, recruited_from, false, true);
                current_team.spend_gold(u_type->cost());
@@ -822,7 +822,7 @@
                        || new_unit.type()->has_random_traits()) {
                        clear_undo_stack(side_num);
                } else {
-                       resources::undo_stack->push_back(undo_action(new_unit, 
loc, undo_action::RECRUIT));
+                       resources::undo_stack->push_back(undo_action(new_unit, 
loc, recruited_from, undo_action::RECRUIT));
                }
 
                gui_->recalculate_minimap();
@@ -1034,7 +1034,7 @@
        }
 
        recall_list_team.erase(it);
-       recorder.add_recall(un.id(), recall_location);
+       recorder.add_recall(un.id(), recall_location, recall_from);
        place_recruit(un, recall_location, recall_from, true, true);
        statistics::recall_unit(un);
        current_team.spend_gold(current_team.recall_cost());
@@ -1043,7 +1043,7 @@
        if (shroud_cleared) {
                clear_undo_stack(side_num);
        } else {
-               resources::undo_stack->push_back(undo_action(un, 
recall_location, undo_action::RECALL));
+               resources::undo_stack->push_back(undo_action(un, 
recall_location, recall_from, undo_action::RECALL));
        }
 
        resources::redo_stack->clear();
@@ -1206,7 +1206,7 @@
                } else {
                        // Redo recall
 
-                       recorder.add_recall(action.affected_unit.id(), 
action.recall_loc);
+                       recorder.add_recall(action.affected_unit.id(), 
action.recall_loc, action.recall_from);
                        map_location loc = action.recall_loc;
                        map_location from = map_location::null_location;
                        const events::command_disabler disable_commands;
@@ -1234,6 +1234,7 @@
        } else if(action.is_recruit()) {
                // Redo recruit action
                map_location loc = action.recall_loc;
+               map_location from = action.recall_from;
                const std::string name = action.affected_unit.type_id();
 
                //search for the unit to be recruited in recruits
@@ -1252,9 +1253,8 @@
                        ++recruit_num;
                }
                last_recruit_ = name;
-               recorder.add_recruit(recruit_num,loc);
+               recorder.add_recruit(recruit_num,loc,from);
                const events::command_disabler disable_commands;
-               map_location from = map_location::null_location;
                const std::string &msg = find_recruit_location(side_num, loc, 
from, action.affected_unit.type_id());
                if(msg.empty()) {
                        const unit new_unit = action.affected_unit;

Modified: trunk/src/replay.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/replay.cpp?rev=51918&r1=51917&r2=51918&view=diff
==============================================================================
--- trunk/src/replay.cpp (original)
+++ trunk/src/replay.cpp Mon Nov  7 19:23:48 2011
@@ -187,26 +187,28 @@
        cmd->add_child("start");
 }
 
-void replay::add_recruit(int value, const map_location& loc)
+void replay::add_recruit(int value, const map_location& loc, const 
map_location& from)
 {
        config* const cmd = add_command();
 
        config val;
        val["value"] = value;
        loc.write(val);
+       config& leader_position = val.add_child("from");
+       from.write(leader_position);
 
        cmd->add_child("recruit",val);
 }
 
-void replay::add_recall(const std::string& unit_id, const map_location& loc)
+void replay::add_recall(const std::string& unit_id, const map_location& loc, 
const map_location& from)
 {
        config* const cmd = add_command();
 
        config val;
-
        val["value"] = unit_id;
-
        loc.write(val);
+       config& leader_position = val.add_child("from");
+       from.write(leader_position);
 
        cmd->add_child("recall",val);
 }
@@ -890,8 +892,12 @@
                        int val = child["value"];
 
                        map_location loc(child, resources::state_of_game);
-
-                       const std::set<std::string>& recruits = 
current_team.recruits();
+                       map_location from(child.child_or_empty("from"), 
resources::state_of_game);
+
+                       unit_map::unit_iterator u = 
resources::units->find(from);
+
+                       std::set<std::string> recruits = 
current_team.recruits();
+                       recruits.insert((u->recruits()).begin(), 
(u->recruits()).end());
 
                        if(val < 0 || static_cast<size_t>(val) >= 
recruits.size()) {
                                std::stringstream errbuf;
@@ -912,7 +918,6 @@
                                continue;
                        }
 
-                       map_location from = map_location::null_location;
                        const std::string res = find_recruit_location(side_num, 
loc, from, u_type->id());
                        const unit new_unit(u_type, side_num, true);
                        if (res.empty()) {

Modified: trunk/src/replay.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/replay.hpp?rev=51918&r1=51917&r2=51918&view=diff
==============================================================================
--- trunk/src/replay.hpp (original)
+++ trunk/src/replay.hpp Mon Nov  7 19:23:48 2011
@@ -45,8 +45,8 @@
        bool is_skipping() const;
 
        void add_start();
-       void add_recruit(int unit_index, const map_location& loc);
-       void add_recall(const std::string& unit_id, const map_location& loc);
+       void add_recruit(int unit_index, const map_location& loc, const 
map_location& from);
+       void add_recall(const std::string& unit_id, const map_location& loc, 
const map_location& from);
        void add_disband(const std::string& unit_id);
        void add_countdown_update(int value,int team);
        void add_movement(const std::vector<map_location>& steps);


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

Reply via email to