Author: alink
Date: Fri Mar 21 05:31:19 2008
New Revision: 24924

URL: http://svn.gna.org/viewcvs/wesnoth?rev=24924&view=rev
Log:
Fix a small error in pathfinding cost which caused sub-optimal path when
traversing ZoC (spend more MP just to avoid ZoC, which was useless if the move
already need several turns). Probably not really useful for human but I prefer
cleaning the code before introducing new feature.

Modified:
    trunk/src/pathfind.cpp

Modified: trunk/src/pathfind.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/pathfind.cpp?rev=24924&r1=24923&r2=24924&view=diff
==============================================================================
--- trunk/src/pathfind.cpp (original)
+++ trunk/src/pathfind.cpp Fri Mar 21 05:31:19 2008
@@ -324,12 +324,19 @@
        if (remaining_movement < 0)
                remaining_movement = total_movement_ - (-remaining_movement) % 
total_movement_;
 
+       // we will always pay the terrain movement cost.
+       int cost = base_cost;
+
        // Supposing we had 2 movement left, and wanted to move onto a hex
        // which takes 3 movement, it's going to cost us 5 movement in total,
-       // since we sacrifice this turn's movement. Take that into account here.
-       int additional_cost = base_cost > remaining_movement ? 
remaining_movement : 0;
-
-       // The isDist check is obsolete and introduce a little inaccurancy.
+       // since we sacrifice this turn's movement. So check that.
+       bool need_new_turn = base_cost > remaining_movement;
+
+       // and if it happens, all remaining movements will be lost waiting the 
turn's end
+       if (need_new_turn)
+               cost += remaining_movement;
+
+       // FIXME: The isDist check is obsolete and introduce a little 
inaccurancy.
        // It comes trom the time when we returned getNoPathValue() in ZoC
        // But pathfinding calls with a small maximum path length
        // (like some AI stuff do) maybe rely on this.
@@ -337,10 +344,13 @@
                        && !unit_.get_ability_bool("skirmisher", loc)) {
                // Should cost us remaining movement.
                //               return getNoPathValue();
-               return total_movement_ + additional_cost;
-       }
-
-       return base_cost + additional_cost;
+
+               // the ZoC cost all remaining movements, but if we already use 
them
+               // in the sacrified turn, we will spend all our fresh total 
movement
+               cost += need_new_turn ? total_movement_ : remaining_movement;
+       }
+
+       return cost;
 }
 
 emergency_path_calculator::emergency_path_calculator(const unit& u, const 
gamemap& map)


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to