fixed bug which could cause a crash when a unit advances

(as reported by Antonio Manrique Perez)
This commit is contained in:
uid68803 2003-12-29 14:46:53 +00:00
parent b99bb9fc8b
commit 6516d3f869
5 changed files with 50 additions and 12 deletions

View file

@ -194,7 +194,40 @@ Defeat:
message="There is no time for delay or idle chatter, onward!"
[/message]
[/command]
[command]
[set_variable]
name=killed_enemies
value=false
[/set_variable]
[/command]
[command]
[endlevel]
result=victory
[/endlevel]
[/command]
[/event]
[event]
name=victory
[message]
description=Kalenz
id=msg11_5b
message="We have defeated the foul Orcs guarding this land, but we must continue without rest. More will surely come!"
[/message]
[message]
description=Delfador
id=msg11_5c
message="Indeed we must not delay. I remember now, the mines in the North-East are the best way to enter!"
[/message]
[message]
speaker=narrator
id=msg11_5d
message="But Konrad's party was not alone in entering the mines..."
[/message]
[/event]
[event]
name=victory
[command]
[unit]
side=2
@ -227,11 +260,6 @@ Defeat:
[/message]
[/command]
[command]
[endlevel]
result=victory
[/endlevel]
[/command]
[/event]

View file

@ -808,9 +808,8 @@ unit get_advanced_unit(const game_data& info,
std::map<gamemap::location,unit>& units,
const gamemap::location& loc, const std::string& advance_to)
{
const std::map<std::string,unit_type>::const_iterator new_type =
info.unit_types.find(advance_to);
std::map<gamemap::location,unit>::iterator un = units.find(loc);
const std::map<std::string,unit_type>::const_iterator new_type = info.unit_types.find(advance_to);
const std::map<gamemap::location,unit>::iterator un = units.find(loc);
if(new_type != info.unit_types.end() && un != units.end()) {
return unit(&(new_type->second),un->second);
} else {
@ -821,9 +820,10 @@ unit get_advanced_unit(const game_data& info,
void advance_unit(const game_data& info,
std::map<gamemap::location,unit>& units,
const gamemap::location& loc, const std::string& advance_to)
gamemap::location loc, const std::string& advance_to)
{
const unit& new_unit = get_advanced_unit(info,units,loc,advance_to);
units.erase(loc);
units.insert(std::pair<gamemap::location,unit>(loc,new_unit));
}

View file

@ -119,9 +119,12 @@ unit get_advanced_unit(const game_data& info,
const gamemap::location& loc, const std::string& advance_to);
//function which will advance the unit at loc to 'advance_to'.
//note that 'loc' is not a reference, because if it were a reference, 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(const game_data& info,
std::map<gamemap::location,unit>& units,
const gamemap::location& loc, const std::string& advance_to);
gamemap::location loc, const std::string& advance_to);
//function which returns true iff the unit at loc is currently affected
//by leadership. (i.e. has a higher-level 'leadership' unit next to it)

View file

@ -28,7 +28,7 @@ namespace dialogs
void advance_unit(const game_data& info,
std::map<gamemap::location,unit>& units,
const gamemap::location& loc,
gamemap::location loc,
display& gui, bool random_choice)
{
std::map<gamemap::location,unit>::iterator u = units.find(loc);

View file

@ -21,9 +21,16 @@
namespace dialogs
{
//function to handle an advancing unit. If there is only one choice to advance
//to, the unit will be automatically advanced. If there is a choice, and 'random_choice'
//is true, then a unit will be selected at random. Otherwise, a dialog will be displayed
//asking the user what to advance to.
//
//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
void advance_unit(const game_data& info,
std::map<gamemap::location,unit>& units,
const gamemap::location& loc,
gamemap::location loc,
display& gui, bool random_choice=false);
void show_objectives(display& disp, config& level_info);