removed changes which were causing crash

This commit is contained in:
Dave White 2003-11-12 14:15:35 +00:00
parent 46215e3588
commit ad64775682
6 changed files with 41 additions and 104 deletions

View file

@ -847,8 +847,8 @@ size_t move_unit(display* disp, const gamemap& map,
//if we can't get all the way there and have to set a go-to
if(steps.size() != route.size()) {
ui->second.add_goto(route.back());
u.add_goto(route.back());
ui->second.set_goto(route.back());
u.set_goto(route.back());
}
if(steps.size() < 2) {
@ -890,7 +890,7 @@ size_t move_unit(display* disp, const gamemap& map,
}
if(disp != NULL) {
disp->set_routes(std::vector<paths::route>());
disp->set_route(NULL);
disp->draw();
}
@ -975,7 +975,7 @@ bool unit_can_move(const gamemap::location& loc, const unit_map& units,
//units with goto commands that have already done their gotos this turn
//(i.e. don't have full movement left) should be red
if(u.movement_left() < u.total_movement() && !u.get_gotos().empty()) {
if(u.movement_left() < u.total_movement() && u.get_goto().valid()) {
return false;
}

View file

@ -1238,37 +1238,26 @@ void display::draw_tile(int x, int y, SDL_Surface* unit_image,
void display::draw_footstep(const gamemap::location& loc, int xloc, int yloc)
{
std::vector<paths::route>::const_iterator rt;
std::vector<gamemap::location>::const_iterator i;
for(rt = routes_.begin(); rt != routes_.end(); ++rt) {
i = std::find(rt->steps.begin(),rt->steps.end(),loc);
if(i != rt->steps.end())
break;
}
std::vector<gamemap::location>::const_iterator i =
std::find(route_.steps.begin(),route_.steps.end(),loc);
if(rt == routes_.end())
if(i == route_.steps.begin() || i == route_.steps.end())
return;
const paths::route& route = *rt;
const bool show_time = (i+1 == route_.steps.end());
if(i == route.steps.begin() || i == route.steps.end())
return;
const bool show_time = (i+1 == route.steps.end());
const bool left_foot = is_even(i - route.steps.begin());
const bool left_foot = is_even(i - route_.steps.begin());
//generally we want the footsteps facing toward the direction they're going
//to go next.
//if we're on the last step, then we want them facing according to where
//they came from, so we move i back by one
if(i+1 == route.steps.end() && i != route.steps.begin())
if(i+1 == route_.steps.end() && i != route_.steps.begin())
--i;
gamemap::location::DIRECTION direction = gamemap::location::NORTH;
if(i+1 != route.steps.end()) {
if(i+1 != route_.steps.end()) {
for(int n = 0; n != 6; ++n) {
direction = gamemap::location::DIRECTION(n);
if(i->get_direction(direction) == *(i+1)) {
@ -1313,9 +1302,9 @@ void display::draw_footstep(const gamemap::location& loc, int xloc, int yloc)
draw_unit(xloc,yloc,image,hflip,vflip,0.5);
if(show_time && route.move_left > 0 && route.move_left < 10) {
if(show_time && route_.move_left > 0 && route_.move_left < 10) {
static std::string str(1,'x');
str[0] = '0' + route.move_left + 1;
str[0] = '0' + route_.move_left + 1;
const SDL_Rect& text_area =
font::draw_text(NULL,screen_area(),18,font::BUTTON_COLOUR,str,0,0);
const int x = xloc + int(zoom_/2.0) - text_area.w/2;
@ -1565,12 +1554,9 @@ void display::set_paths(const paths* paths_list)
void display::invalidate_route()
{
for(std::vector<paths::route>::const_iterator r = routes_.begin();
r != routes_.end(); ++r) {
for(std::vector<gamemap::location>::const_iterator i = r->steps.begin();
i != r->steps.end(); ++i) {
invalidate(*i);
}
for(std::vector<gamemap::location>::const_iterator i = route_.steps.begin();
i != route_.steps.end(); ++i) {
invalidate(*i);
}
}
@ -1578,18 +1564,10 @@ void display::set_route(const paths::route* route)
{
invalidate_route();
routes_.clear();
if(route != NULL) {
routes_.push_back(*route);
invalidate_route();
}
}
void display::set_routes(const std::vector<paths::route>& routes)
{
invalidate_route();
routes_ = routes;
if(route != NULL)
route_ = *route;
else
route_.steps.clear();
invalidate_route();
}

View file

@ -71,7 +71,6 @@ public:
//route does not have to remain valid after being set
void set_route(const paths::route* route);
void set_routes(const std::vector<paths::route>& routes);
double get_location_x(const gamemap::location& loc) const;
double get_location_y(const gamemap::location& loc) const;
@ -178,7 +177,7 @@ private:
SDL_Surface* minimap_;
const paths* pathsList_;
std::vector<paths::route> routes_;
paths::route route_;
const gamestatus& status_;

View file

@ -74,12 +74,10 @@ void play_turn(game_data& gameinfo, game_state& state_of_game,
std::vector<gamemap::location> gotos;
for(unit_map::iterator ui = units.begin(); ui != units.end(); ++ui) {
const std::vector<gamemap::location>& go = ui->second.get_gotos();
while(!go.empty() && go.front() == ui->first)
ui->second.done_goto();
if(ui->second.get_goto() == ui->first)
ui->second.set_goto(gamemap::location());
if(!go.empty() && ui->second.side() == team_num &&
map.on_board(go.front()))
if(ui->second.side() == team_num && map.on_board(ui->second.get_goto()))
gotos.push_back(ui->first);
}
@ -96,8 +94,8 @@ void play_turn(game_data& gameinfo, game_state& state_of_game,
const std::set<gamemap::location>* const teleports =
u.type().teleports() ? &current_team.towers() : NULL;
paths::route route = a_star_search(ui->first,
ui->second.get_gotos().front(),10000.0,calc,teleports);
paths::route route = a_star_search(ui->first,ui->second.get_goto(),
10000.0,calc,teleports);
if(route.steps.empty())
continue;
@ -105,11 +103,8 @@ void play_turn(game_data& gameinfo, game_state& state_of_game,
route.move_left = route_turns_to_complete(ui->second,map,route);
gui.set_route(&route);
const int res = move_unit(&gui,map,units,teams,route.steps,
&recorder,&turn_data.undos());
if(size_t(res) == route.steps.size())
ui->second.done_goto();
move_unit(&gui,map,units,teams,route.steps,
&recorder,&turn_data.undos());
}
std::cerr << "done gotos\n";
@ -269,11 +264,6 @@ void turn_info::mouse_motion(const SDL_MouseMotionEvent& event)
const unit_map::const_iterator un = units_.find(selected_hex_);
if(un != units_.end()) {
std::vector<gamemap::location> gotos = un->second.get_gotos();
if(!key_[SDLK_LCTRL] && !key_[SDLK_RCTRL]) {
gotos.clear();
}
const shortest_path_calculator calc(un->second,current_team,
units_,map_);
const bool can_teleport = un->second.type().teleports();
@ -281,9 +271,8 @@ void turn_info::mouse_motion(const SDL_MouseMotionEvent& event)
const std::set<gamemap::location>* const teleports =
can_teleport ? &current_team.towers() : NULL;
current_route_ = a_star_search(
gotos.empty() ? selected_hex_ : gotos.back(),
new_hex,10000.0,calc,teleports);
current_route_ = a_star_search(selected_hex_,new_hex,
10000.0,calc,teleports);
current_route_.move_left =
route_turns_to_complete(un->second,map_,current_route_);
@ -492,9 +481,7 @@ void turn_info::left_click(const SDL_MouseButtonEvent& event)
enemy == units_.end() && !current_route_.steps.empty() &&
current_route_.steps.front() == selected_hex_) {
if(!key_[SDLK_LCTRL] && !key_[SDLK_RCTRL]) {
units_.find(selected_hex_)->second.set_goto(gamemap::location());
}
const size_t moves = move_unit(&gui_,map_,units_,teams_,
current_route_.steps,&recorder,&undo_stack_);
@ -545,8 +532,7 @@ void turn_info::left_click(const SDL_MouseButtonEvent& event)
selected_hex_ = hex;
gui_.select_hex(hex);
current_route_.steps.clear();
std::vector<paths::route> routes;
gui_.set_route(NULL);
const unit_map::iterator it = units_.find(hex);
if(it != units_.end() && it->second.side() == team_num_) {
@ -557,28 +543,21 @@ void turn_info::left_click(const SDL_MouseButtonEvent& event)
gui_.set_paths(&current_paths_);
unit u = it->second;
const std::vector<gamemap::location>& gotos = u.get_gotos();
for(std::vector<gamemap::location>::const_iterator g = gotos.begin();
g != gotos.end(); ++g) {
const gamemap::location go_to = u.get_goto();
if(map_.on_board(go_to)) {
const shortest_path_calculator calc(u,current_team,
units_,map_);
const std::set<gamemap::location>* const teleports =
teleport ? &current_team.towers() : NULL;
const gamemap::location& src = g == gotos.begin() ? it->first :
*(g-1);
paths::route route = a_star_search(src,*g,
paths::route route = a_star_search(it->first,go_to,
10000.0,calc,teleports);
route.move_left =
route_turns_to_complete(it->second,map_,route);
gui_.set_route(&route);
}
}
gui_.set_routes(routes);
}
}
@ -1019,8 +998,6 @@ void turn_info::recruit()
if(browse_)
return;
const command_disabler disable_commands;
team& current_team = teams_[team_num_-1];
std::vector<unit> sample_units;
@ -1086,8 +1063,6 @@ void turn_info::recall()
if(browse_)
return;
const command_disabler disable_commands;
team& current_team = teams_[team_num_-1];
//sort the available units into order by value

View file

@ -540,27 +540,14 @@ bool unit::is_guardian() const
return guardian_;
}
const std::vector<gamemap::location>& unit::get_gotos() const
const gamemap::location& unit::get_goto() const
{
return gotos_;
return goto_;
}
void unit::set_goto(const gamemap::location& new_goto)
{
gotos_.clear();
add_goto(new_goto);
}
void unit::add_goto(const gamemap::location& new_goto)
{
if(new_goto.valid())
gotos_.push_back(new_goto);
}
void unit::done_goto()
{
if(gotos_.empty() == false)
gotos_.erase(gotos_.begin());
goto_ = new_goto;
}
void unit::add_modification(const std::string& type,

View file

@ -95,10 +95,8 @@ public:
int value() const;
bool is_guardian() const;
const std::vector<gamemap::location>& get_gotos() const;
const gamemap::location& get_goto() const;
void set_goto(const gamemap::location& new_goto);
void add_goto(const gamemap::location& new_goto);
void done_goto();
int upkeep() const;
@ -143,7 +141,7 @@ private:
bool guardian_;
std::vector<gamemap::location> gotos_;
gamemap::location goto_;
bool loyal_;