[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.
This commit is contained in:
Mark de Wever 2007-07-15 09:06:13 +00:00
parent d526785d45
commit 415615a007
7 changed files with 63 additions and 9 deletions

View file

@ -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

View file

@ -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]

View file

@ -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";

View file

@ -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);

View file

@ -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());

View file

@ -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");

View file

@ -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;