Add basic support to define waypoints via a hotkey "Add waypoint"
Seems to work fine, but no visual indication yet (besides the bended path) Don't affect the normal pathfinding interface, so this WIP is safe.
This commit is contained in:
parent
7a73db2965
commit
a879b7adad
6 changed files with 53 additions and 2 deletions
|
@ -45,6 +45,7 @@ const struct {
|
|||
} hotkey_list_[] = {
|
||||
{ hotkey::HOTKEY_CYCLE_UNITS, "cycle", N_("Next Unit"), false, hotkey::SCOPE_GAME },
|
||||
{ hotkey::HOTKEY_CYCLE_BACK_UNITS, "cycleback", N_("Previous Unit"), false, hotkey::SCOPE_GAME },
|
||||
{ hotkey::HOTKEY_ADD_WAYPOINT, "addwaypoint", N_("Add waypoint"), false, hotkey::SCOPE_GAME },
|
||||
{ hotkey::HOTKEY_UNIT_HOLD_POSITION, "holdposition", N_("Hold Position"), false, hotkey::SCOPE_GAME },
|
||||
{ hotkey::HOTKEY_END_UNIT_TURN, "endunitturn", N_("End Unit Turn"), false, hotkey::SCOPE_GAME },
|
||||
{ hotkey::HOTKEY_LEADER, "leader", N_("Leader"), false, hotkey::SCOPE_GAME },
|
||||
|
@ -680,6 +681,9 @@ bool command_executor::execute_command(HOTKEY_COMMAND command, int /*index*/)
|
|||
case HOTKEY_ENDTURN:
|
||||
end_turn();
|
||||
break;
|
||||
case HOTKEY_ADD_WAYPOINT:
|
||||
add_waypoint();
|
||||
break;
|
||||
case HOTKEY_UNIT_HOLD_POSITION:
|
||||
unit_hold_position();
|
||||
break;
|
||||
|
|
|
@ -41,7 +41,8 @@ enum scope {
|
|||
|
||||
|
||||
enum HOTKEY_COMMAND {
|
||||
HOTKEY_CYCLE_UNITS,HOTKEY_CYCLE_BACK_UNITS, HOTKEY_UNIT_HOLD_POSITION,
|
||||
HOTKEY_CYCLE_UNITS,HOTKEY_CYCLE_BACK_UNITS,
|
||||
HOTKEY_ADD_WAYPOINT, HOTKEY_UNIT_HOLD_POSITION,
|
||||
HOTKEY_END_UNIT_TURN, HOTKEY_LEADER,
|
||||
HOTKEY_UNDO, HOTKEY_REDO,
|
||||
HOTKEY_ZOOM_IN, HOTKEY_ZOOM_OUT, HOTKEY_ZOOM_DEFAULT,
|
||||
|
@ -241,6 +242,7 @@ public:
|
|||
virtual void cycle_back_units() {}
|
||||
virtual void end_turn() {}
|
||||
virtual void goto_leader() {}
|
||||
virtual void add_waypoint() {}
|
||||
virtual void unit_hold_position() {}
|
||||
virtual void end_unit_turn() {}
|
||||
virtual void undo() {}
|
||||
|
|
|
@ -343,7 +343,40 @@ marked_route mouse_handler::get_route(unit_map::const_iterator un, map_location
|
|||
allowed_teleports.insert(*i);
|
||||
}
|
||||
}
|
||||
plain_route route = a_star_search(un->first, go_to, 10000.0, &calc, map_.w(), map_.h(), &allowed_teleports);
|
||||
|
||||
plain_route route;
|
||||
|
||||
if (waypoints_.empty()) {
|
||||
// standard shortest path
|
||||
route = a_star_search(un->first, go_to, 10000.0, &calc, map_.w(), map_.h(), &allowed_teleports);
|
||||
} else {
|
||||
// initialize the main route with the first step
|
||||
route.steps.push_back(un->first);
|
||||
route.move_cost = 0;
|
||||
|
||||
// maybe reserve head and tail and reinitialize it each time ?
|
||||
waypoints_.push_front(un->first);
|
||||
waypoints_.push_back(go_to);
|
||||
|
||||
std::list<map_location>::const_iterator wsrc = waypoints_.begin(),
|
||||
wdst = ++waypoints_.begin();
|
||||
|
||||
for(; wdst != waypoints_.end(); ++wsrc, ++wdst) {
|
||||
if (*wsrc==*wdst) continue;
|
||||
plain_route inter_route = a_star_search(*wsrc, *wdst, 10000.0, &calc, map_.w(), map_.h(), &allowed_teleports);
|
||||
if(inter_route.steps.size()>=1) {
|
||||
// add to the main route but skip the head (already in)
|
||||
route.steps.insert(route.steps.end(),
|
||||
inter_route.steps.begin()+1,inter_route.steps.end());
|
||||
route.move_cost+=inter_route.move_cost;
|
||||
}
|
||||
}
|
||||
|
||||
// restore waypoints_ by removing temporary source and destination
|
||||
waypoints_.pop_front();
|
||||
waypoints_.pop_back();
|
||||
}
|
||||
|
||||
return mark_route(route, un->second, viewing_team(), units_,teams_,map_);
|
||||
}
|
||||
|
||||
|
@ -459,6 +492,7 @@ void mouse_handler::select_hex(const map_location& hex, const bool browse) {
|
|||
gui().select_hex(hex);
|
||||
gui().clear_attack_indicator();
|
||||
gui().set_route(NULL);
|
||||
waypoints_.clear();
|
||||
show_partial_move_ = false;
|
||||
|
||||
unit_map::iterator u = find_unit(hex);
|
||||
|
|
|
@ -57,6 +57,9 @@ public:
|
|||
void set_undo(const bool undo) { undo_ = undo; }
|
||||
|
||||
unit_map::iterator selected_unit();
|
||||
|
||||
void add_waypoint(const map_location& loc) {waypoints_.push_back(loc);}
|
||||
void clear_waypoints() {waypoints_.clear();}
|
||||
marked_route get_route(unit_map::const_iterator un, map_location go_to, team &team);
|
||||
protected:
|
||||
/**
|
||||
|
@ -111,6 +114,7 @@ private:
|
|||
map_location selected_hex_;
|
||||
map_location next_unit_;
|
||||
marked_route current_route_;
|
||||
std::list<map_location> waypoints_;
|
||||
paths current_paths_;
|
||||
bool enemy_paths_;
|
||||
int path_turns_;
|
||||
|
|
|
@ -178,6 +178,11 @@ void playsingle_controller::continue_move(){
|
|||
menu_handler_.continue_move(mouse_handler_, player_number_);
|
||||
}
|
||||
|
||||
void playsingle_controller::add_waypoint(){
|
||||
if (!browse_)
|
||||
mouse_handler_.add_waypoint(mouse_handler_.get_last_hex());
|
||||
}
|
||||
|
||||
void playsingle_controller::unit_hold_position(){
|
||||
if (!browse_)
|
||||
menu_handler_.unit_hold_position(mouse_handler_, player_number_);
|
||||
|
@ -973,6 +978,7 @@ bool playsingle_controller::can_execute_command(hotkey::HOTKEY_COMMAND command,
|
|||
{
|
||||
bool res = true;
|
||||
switch (command){
|
||||
case hotkey::HOTKEY_ADD_WAYPOINT:
|
||||
case hotkey::HOTKEY_UNIT_HOLD_POSITION:
|
||||
case hotkey::HOTKEY_END_UNIT_TURN:
|
||||
case hotkey::HOTKEY_RECRUIT:
|
||||
|
|
|
@ -50,6 +50,7 @@ public:
|
|||
virtual void change_side();
|
||||
virtual void label_terrain(bool);
|
||||
virtual void continue_move();
|
||||
virtual void add_waypoint();
|
||||
virtual void unit_hold_position();
|
||||
virtual void end_unit_turn();
|
||||
virtual void user_command();
|
||||
|
|
Loading…
Add table
Reference in a new issue