Author: alink
Date: Sat Nov 21 22:33:37 2009
New Revision: 39859
URL: http://svn.gna.org/viewcvs/wesnoth?rev=39859&view=rev
Log:
Fix bug #14796 : keep waypoints for multi-turns moves.
Also add more ways to remove them (since they are not auto cleared anymore):
- when double selecting an unit (as/because it was already done for goto)
- hotkey toggle any waypoint, not only the last one. This allow easier tweaking
but make it harder to draw loop (which was not really useful or UI-clear anyway)
Modified:
trunk/src/actions.cpp
trunk/src/mouse_events.cpp
trunk/src/mouse_events.hpp
trunk/src/pathfind.cpp
trunk/src/pathfind.hpp
trunk/src/unit.cpp
trunk/src/unit.hpp
Modified: trunk/src/actions.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/actions.cpp?rev=39859&r1=39858&r2=39859&view=diff
==============================================================================
--- trunk/src/actions.cpp (original)
+++ trunk/src/actions.cpp Sat Nov 21 22:33:37 2009
@@ -2092,6 +2092,12 @@
moves_left -= cost;
+ //remove used waypoints
+ std::list<map_location>& waypoints = ui->second.waypoints();
+ if(!waypoints.empty() && waypoints.front() == *step) {
+ waypoints.pop_front();
+ }
+
// If we use fog or shroud, see if we have sighted an enemy
unit,
// in which case we should stop immediately.
// Cannot use check shroud, because also need to check if delay
shroud is on.
Modified: trunk/src/mouse_events.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/mouse_events.cpp?rev=39859&r1=39858&r2=39859&view=diff
==============================================================================
--- trunk/src/mouse_events.cpp (original)
+++ trunk/src/mouse_events.cpp Sat Nov 21 22:33:37 2009
@@ -60,7 +60,6 @@
selected_hex_(),
next_unit_(),
current_route_(),
- waypoints_(),
current_paths_(),
enemy_paths_(false),
path_turns_(0),
@@ -324,11 +323,18 @@
}
void mouse_handler::add_waypoint(const map_location& loc) {
- if(!waypoints_.empty() && waypoints_.back() == loc) {
- waypoints_.pop_back();
+ unit_map::iterator u = find_unit(selected_hex_);
+ if(u == units_.end() || u->second.side() != side_num_)
+ return;
+
+ std::list<map_location>& waypoints = u->second.waypoints();
+ std::list<map_location>::iterator i = std::find(waypoints.begin(),
waypoints.end(), loc);
+ if(i != waypoints.end()){
+ waypoints.erase(i);
} else {
- waypoints_.push_back(loc);
- }
+ waypoints.push_back(loc);
+ }
+
// we need to update the route, simulate a mouse move for the moment
// (browse is supposed false here, 0,0 are dummy values)
mouse_motion(0,0, false, true);
@@ -343,8 +349,8 @@
un->second, units_, viewing_team());
plain_route route;
-
- if (waypoints_.empty()) {
+
+ if (un->second.waypoints().empty()) {
// standard shortest path
route = a_star_search(un->first, go_to, 10000.0, &calc,
map_.w(), map_.h(), &allowed_teleports);
} else {
@@ -352,12 +358,16 @@
route.steps.push_back(un->first);
route.move_cost = 0;
- const int wsize = waypoints_.size();
- for(int w = -1; w < wsize; ++w){
- const map_location& src = w < 0 ? un->first :
waypoints_[w];
- const map_location& dst = w+1 < wsize ? waypoints_[w+1]
: go_to;
- if (src==dst) continue;
- plain_route inter_route = a_star_search(src, dst,
10000.0, &calc, map_.w(), map_.h(), &allowed_teleports);
+ //copy waypoints and add first source and last destination
+ std::list<map_location> waypoints = un->second.waypoints();
+ waypoints.push_front(un->first);
+ waypoints.push_back(go_to);
+
+ std::list<map_location>::iterator src = waypoints.begin(),
+ dst = ++waypoints.begin();
+ for(; dst != waypoints.end(); ++src,++dst){
+ if (*src == *dst) continue;
+ plain_route inter_route = a_star_search(*src, *dst,
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(),
@@ -367,7 +377,7 @@
}
}
- return mark_route(route, waypoints_, un->second, viewing_team(),
units_,teams_,map_);
+ return mark_route(route, un->second.waypoints(), un->second,
viewing_team(), units_,teams_,map_);
}
void mouse_handler::mouse_press(const SDL_MouseButtonEvent& event, const bool
browse)
@@ -401,9 +411,10 @@
unit_map::iterator u = find_unit(selected_hex_);
//if the unit is selected and then itself clicked on,
- //any goto command is cancelled
+ //any goto command and waypoints are cancelled
if(u != units_.end() && !browse && selected_hex_ == hex &&
u->second.side() == side_num_) {
u->second.set_goto(map_location());
+ u->second.waypoints().clear();
}
unit_map::iterator clicked_u = find_unit(hex);
@@ -505,7 +516,6 @@
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);
Modified: trunk/src/mouse_events.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/mouse_events.hpp?rev=39859&r1=39858&r2=39859&view=diff
==============================================================================
--- trunk/src/mouse_events.hpp (original)
+++ trunk/src/mouse_events.hpp Sat Nov 21 22:33:37 2009
@@ -122,7 +122,6 @@
map_location selected_hex_;
map_location next_unit_;
marked_route current_route_;
- std::vector<map_location> waypoints_;
paths current_paths_;
bool enemy_paths_;
int path_turns_;
Modified: trunk/src/pathfind.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/pathfind.cpp?rev=39859&r1=39858&r2=39859&view=diff
==============================================================================
--- trunk/src/pathfind.cpp (original)
+++ trunk/src/pathfind.cpp Sat Nov 21 22:33:37 2009
@@ -381,7 +381,7 @@
}
marked_route mark_route(const plain_route &rt,
- const std::vector<map_location>& waypoints, const unit &u,
+ const std::list<map_location>& waypoints, const unit &u,
const team &viewing_team, const unit_map &units,
const std::vector<team> &teams, const gamemap &map)
{
@@ -395,8 +395,8 @@
const team& unit_team = teams[u.side()-1];
bool zoc = false;
- std::vector<map_location>::const_iterator i = rt.steps.begin(),
- w = waypoints.begin();
+ std::vector<map_location>::const_iterator i = rt.steps.begin();
+ std::list<map_location>::const_iterator w = waypoints.begin();
// TODO fix the name confusion with waypoints and route.waypoints
for (; i !=rt.steps.end(); i++) {
Modified: trunk/src/pathfind.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/pathfind.hpp?rev=39859&r1=39858&r2=39859&view=diff
==============================================================================
--- trunk/src/pathfind.hpp (original)
+++ trunk/src/pathfind.hpp Sat Nov 21 22:33:37 2009
@@ -151,7 +151,7 @@
* Marks a route @a rt with waypoints assuming that a @unit u travels along it.
*/
marked_route mark_route(const plain_route &rt,
- const std::vector<map_location>& waypoints, const unit &u,
+ const std::list<map_location>& waypoints, const unit &u,
const team &viewing_team, const unit_map &units,
const std::vector<team> &teams, const gamemap &map);
Modified: trunk/src/unit.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/unit.cpp?rev=39859&r1=39858&r2=39859&view=diff
==============================================================================
--- trunk/src/unit.cpp (original)
+++ trunk/src/unit.cpp Sat Nov 21 22:33:37 2009
@@ -217,6 +217,7 @@
unit_value_(),
goto_(),
interrupted_move_(),
+ waypoints_(),
flying_(false),
is_fearless_(false),
is_healthy_(false),
@@ -295,6 +296,7 @@
unit_value_(),
goto_(),
interrupted_move_(),
+ waypoints_(),
flying_(false),
is_fearless_(false),
is_healthy_(false),
@@ -399,6 +401,7 @@
unit_value_(),
goto_(),
interrupted_move_(),
+ waypoints_(),
flying_(false),
is_fearless_(false),
is_healthy_(false),
@@ -820,7 +823,8 @@
// Set the goto-command to be going to no-where
goto_ = map_location();
-
+ waypoints_.clear();
+
remove_temporary_modifications();
heal_all();
@@ -1498,6 +1502,8 @@
}
goto_.x = lexical_cast_default<int>(cfg["goto_x"]) - 1;
goto_.y = lexical_cast_default<int>(cfg["goto_y"]) - 1;
+ waypoints_.clear();
+
if(cfg["moves"] != "") {
movement_ = lexical_cast_default<int>(cfg["moves"]);
if(movement_ < 0) {
Modified: trunk/src/unit.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/unit.hpp?rev=39859&r1=39858&r2=39859&view=diff
==============================================================================
--- trunk/src/unit.hpp (original)
+++ trunk/src/unit.hpp Sat Nov 21 22:33:37 2009
@@ -33,6 +33,7 @@
#include <string>
#include <vector>
+#include <list>
class unit_ability_list
{
@@ -222,6 +223,8 @@
const map_location& get_goto() const { return goto_; }
void set_goto(const map_location& new_goto) { goto_ = new_goto; }
+ const std::list<map_location>& waypoints() const { return waypoints_; }
+ std::list<map_location>& waypoints() { return waypoints_; }
int upkeep() const;
bool loyal() const {return cfg_["upkeep"]=="loyal"; }
@@ -419,6 +422,8 @@
t_string traits_description_;
int unit_value_;
map_location goto_, interrupted_move_;
+ std::list<map_location> waypoints_;
+
bool flying_, is_fearless_, is_healthy_;
string_map modification_descriptions_;
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits