From 415615a007532644b12a2d8b2debc270a31d61f6 Mon Sep 17 00:00:00 2001 From: Mark de Wever Date: Sun, 15 Jul 2007 09:06:13 +0000 Subject: [PATCH] [unstore_unit] can now try to level a unit... ...and does so by default this time added for real, the replay can also handle it (bug #7426). Also added a test case to the test scenario. --- changelog | 2 ++ data/scenario-test.cfg | 20 ++++++++++++++++++++ src/dialogs.cpp | 12 +++++++++--- src/dialogs.hpp | 5 ++++- src/game_events.cpp | 12 +++++++----- src/replay.cpp | 16 ++++++++++++++++ src/replay.hpp | 5 +++++ 7 files changed, 63 insertions(+), 9 deletions(-) diff --git a/changelog b/changelog index f2519131ddc..3352cb9d66f 100644 --- a/changelog +++ b/changelog @@ -29,6 +29,8 @@ Version 1.3.4+svn: * fix a bug where empty conditionals returned false * now [special_filter] supports [and],[or], and [not] (instead of just NOT) * now standard unit filter supports [and],[or], and [not] (was just [not]) + * [unstore_unit] can now try to level a unit and does so by default this + time added for real, the replay can also handle it(bug #7426) * miscellaneous and bug fixes * fix renames causing OOS when made after moves or recruits * fix a minor glitch when selecting the leftmost menu heading diff --git a/data/scenario-test.cfg b/data/scenario-test.cfg index ad4718b939a..8d263016a7e 100644 --- a/data/scenario-test.cfg +++ b/data/scenario-test.cfg @@ -114,6 +114,11 @@ Xu , Qxu , Qxu , Ql , Ql , Ql type="Thief" generate_description=yes [/unit] + [unit] + x,y=9,8 + type="Peasant" + generate_description=yes + [/unit] [/side] [side] @@ -549,4 +554,19 @@ _s, _s, _s, _s, Aa, Aa, _s, _s, _s, _s animate=yes [/kill] [/event] + + [label] + x,y=7,10 + text="Earn 100 XP!" + [/label] + + [event] + name=moveto + first_time_only=no + + {MODIFY_UNIT (side=1 + x=7 + y=10) experience 100} + [/event] + [/test] diff --git a/src/dialogs.cpp b/src/dialogs.cpp index a69102c8de3..caf0d93fce8 100644 --- a/src/dialogs.cpp +++ b/src/dialogs.cpp @@ -39,10 +39,12 @@ namespace dialogs { void advance_unit(const game_data& info, - const gamemap& map, + const gamemap& map, unit_map& units, gamemap::location loc, - game_display& gui, bool random_choice) + game_display& gui, + bool random_choice, + const bool add_replay_event) { unit_map::iterator u = units.find(loc); if(u == units.end() || u->second.advances() == false) @@ -107,6 +109,10 @@ void advance_unit(const game_data& info, res = advances.show(); } + if(add_replay_event) { + recorder.add_advancement(loc); + } + recorder.choose_option(res); LOG_DP << "animating advancement...\n"; @@ -118,7 +124,7 @@ void advance_unit(const game_data& info, if(u != units.end()) { // level 10 unit gives 80 XP and the highest mainline is level 5 if(u->second.experience() < 81) { - advance_unit(info, map, units, loc, gui, random_choice); + advance_unit(info, map, units, loc, gui, random_choice, add_replay_event); } else { LOG_STREAM(err, config) << "Unit has an too high amount of " << u->second.experience() << " XP left, cascade leveling disabled\n"; diff --git a/src/dialogs.hpp b/src/dialogs.hpp index f4d389e3332..a4aa4cb7eb8 100644 --- a/src/dialogs.hpp +++ b/src/dialogs.hpp @@ -35,8 +35,11 @@ namespace dialogs { // //note that 'loc' is not a reference, because deleting an item from the units map //(when replacing the unit that is being advanced) will possibly invalidate the reference +// +// the game only expects an advancement to be triggered by a fight, it the cause for +// advancement is different (eg unstore_unit) the add_replay_event should be set void advance_unit(const game_data& info, const gamemap& map,unit_map& units, gamemap::location loc, - game_display& gui, bool random_choice=false); + game_display& gui, bool random_choice=false, const bool add_replay_event=false); bool animate_unit_advancement(const game_data& info,unit_map& units, gamemap::location loc, game_display& gui, size_t choice); diff --git a/src/game_events.cpp b/src/game_events.cpp index e3fa4589945..90169601dbb 100644 --- a/src/game_events.cpp +++ b/src/game_events.cpp @@ -1910,8 +1910,11 @@ bool event_handler::handle_event_command(const queued_event& event_info, screen->float_label(loc,text,red,green,blue); } } - /* - if(utils::string_bool(cfg["advance"],true) && get_replay_source().at_end()) { + + std::string advance = cfg["advance"]; + std::cerr << "advance = " << advance << '\n'; + + if(utils::string_bool(cfg["advance"], true) && get_replay_source().at_end()) { //Try to advance the unit //FIXME: get player_number_ from the play_controller not from the WML vars @@ -1922,10 +1925,9 @@ bool event_handler::handle_event_command(const queued_event& event_info, const bool sel = (side == u.side() && (*teams)[side-1].is_human()); //The code in dialogs::advance_unit tests whether the unit can advance - dialogs::advance_unit(*game_data_ptr, *game_map, *units, loc, *screen, !sel); - recorder.add_advancement(); //FIXME: not yet implemented + dialogs::advance_unit(*game_data_ptr, *game_map, *units, loc, *screen, !sel, true); } - */ + } else { player_info *player=state_of_game->get_player((*teams)[u.side()-1].save_id()); diff --git a/src/replay.cpp b/src/replay.cpp index d99fe4dfff4..034622aa6bf 100644 --- a/src/replay.cpp +++ b/src/replay.cpp @@ -386,6 +386,17 @@ void replay::add_checksum_check(const gamemap::location& loc) config* const cmd = add_command(); add_unit_checksum(loc,cmd); } + +void replay::add_advancement(const gamemap::location& loc) +{ + config* const cmd = add_command(false); + + config val; + (*cmd)["undo"] = "no"; + loc.write(val); + cmd->add_child("advance_unit",val); +} + void replay::speak(const config& cfg) { config* const cmd = add_command(false); @@ -1064,6 +1075,11 @@ bool do_replay(game_display& disp, const gamemap& map, const game_data& gameinfo game_events::fire(event); } } + + } else if((child = cfg->child("advance_unit")) != NULL) { + const gamemap::location loc(*child, game_events::get_state_of_game()); + advancing_units.push_back(loc); + } else { if(! cfg->child("checksum")) { replay::throw_error("unrecognized action\n"); diff --git a/src/replay.hpp b/src/replay.hpp index 58d3c61aeb3..95909a28717 100644 --- a/src/replay.hpp +++ b/src/replay.hpp @@ -61,6 +61,11 @@ public: const gamemap::location& loc=gamemap::location::null_location); void add_unit_checksum(const gamemap::location& loc,config* const cfg); void add_checksum_check(const gamemap::location& loc); + /** + * Adds an advancement to the replay, the following option command + * determines which advancement option has been choosen + */ + void add_advancement(const gamemap::location& loc); void speak(const config& cfg); std::string build_chat_log(const std::string& team) const;