wesnoth-cvs-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Wesnoth-cvs-commits] wesnoth/src ai.cpp pathfind.cpp unit.cpp map.hp...


From: David White
Subject: [Wesnoth-cvs-commits] wesnoth/src ai.cpp pathfind.cpp unit.cpp map.hp...
Date: Fri, 21 Jan 2005 15:16:43 -0500

CVSROOT:        /cvsroot/wesnoth
Module name:    wesnoth
Branch:         
Changes by:     David White <address@hidden>    05/01/21 20:16:43

Modified files:
        src            : ai.cpp pathfind.cpp unit.cpp map.hpp 
                         pathfind.hpp pathutils.hpp 
Added files:
        src            : astarnode.hpp 

Log message:
        added Redsun's pathfinding patch

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/astarnode.hpp?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/ai.cpp.diff?tr1=1.130&tr2=1.131&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/pathfind.cpp.diff?tr1=1.53&tr2=1.54&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/unit.cpp.diff?tr1=1.113&tr2=1.114&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/map.hpp.diff?tr1=1.28&tr2=1.29&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/pathfind.hpp.diff?tr1=1.34&tr2=1.35&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/pathutils.hpp.diff?tr1=1.1&tr2=1.2&r1=text&r2=text

Patches:
Index: wesnoth/src/ai.cpp
diff -u wesnoth/src/ai.cpp:1.130 wesnoth/src/ai.cpp:1.131
--- wesnoth/src/ai.cpp:1.130    Fri Jan 21 20:07:30 2005
+++ wesnoth/src/ai.cpp  Fri Jan 21 20:16:43 2005
@@ -1,4 +1,4 @@
-/* $Id: ai.cpp,v 1.130 2005/01/21 20:07:30 Sirp Exp $ */
+/* $Id: ai.cpp,v 1.131 2005/01/21 20:16:43 Sirp Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -2008,4 +2008,4 @@
        const config& parms = current_team().ai_parameters();
        attack_depth_ = 
maximum<int>(1,lexical_cast_default<int>(parms["attack_depth"],5));
        return attack_depth_;
-}
\ No newline at end of file
+}
Index: wesnoth/src/map.hpp
diff -u wesnoth/src/map.hpp:1.28 wesnoth/src/map.hpp:1.29
--- wesnoth/src/map.hpp:1.28    Tue Oct 19 20:49:09 2004
+++ wesnoth/src/map.hpp Fri Jan 21 20:16:43 2005
@@ -1,4 +1,4 @@
-/* $Id: map.hpp,v 1.28 2004/10/19 20:49:09 gruikya Exp $ */
+/* $Id: map.hpp,v 1.29 2005/01/21 20:16:43 Sirp Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -28,12 +28,13 @@
 public:
 
        typedef char TERRAIN;
+       enum { NB_TERRAIN = 256, ADD_INDEX_TERRAIN = 128 };
 
        //some types of terrain which must be known, and can't just be loaded
        //in dynamically because they're special. It's asserted that there will
        //be corresponding entries for these types of terrain in the terrain
        //configuration file.
-       enum { FOGGED = '~', VOID_TERRAIN = ' ', KEEP = 'K', CASTLE = 'C', 
VILLAGE = 't', FOREST = 'f' };
+       enum { FOGGED = '~', VOID_TERRAIN = ' ', KEEP = 'K', CASTLE = 'C', 
VILLAGE = 't', FOREST = 'f', DEEP_SEA = 's', SEA = 'c' };
 
        //the name of the terrain is the terrain itself, the underlying terrain
        //is the name of the terrain for game-logic purposes. I.e. if the 
terrain
@@ -59,7 +60,12 @@
 
                void write(config& cfg) const;
 
-               bool valid() const { return x >= 0 && y >= 0; }
+               inline bool valid() const { return x >= 0 && y >= 0; }
+               
+               inline bool valid(const int parWidth, const int parHeight) const
+               { 
+                       return ((x >= 0) && (y >= 0) && (x < parWidth) && (y < 
parHeight));
+               }
 
                int x, y;
 
Index: wesnoth/src/pathfind.cpp
diff -u wesnoth/src/pathfind.cpp:1.53 wesnoth/src/pathfind.cpp:1.54
--- wesnoth/src/pathfind.cpp:1.53       Fri Jan 21 20:07:30 2005
+++ wesnoth/src/pathfind.cpp    Fri Jan 21 20:16:43 2005
@@ -1,4 +1,4 @@
-/* $Id: pathfind.cpp,v 1.53 2005/01/21 20:07:30 Sirp Exp $ */
+/* $Id: pathfind.cpp,v 1.54 2005/01/21 20:16:43 Sirp Exp $ */
 /*
 Copyright (C) 2003 by David White <address@hidden>
 Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -637,4 +637,4 @@
        int additional_cost = base_cost > remaining_movement ? 
remaining_movement : 0;
 
        return base_cost + additional_cost;
-}
\ No newline at end of file
+}
Index: wesnoth/src/pathfind.hpp
diff -u wesnoth/src/pathfind.hpp:1.34 wesnoth/src/pathfind.hpp:1.35
--- wesnoth/src/pathfind.hpp:1.34       Sun Dec  5 22:14:29 2004
+++ wesnoth/src/pathfind.hpp    Fri Jan 21 20:16:43 2005
@@ -1,4 +1,4 @@
-/* $Id: pathfind.hpp,v 1.34 2004/12/05 22:14:29 silene Exp $ */
+/* $Id: pathfind.hpp,v 1.35 2005/01/21 20:16:43 Sirp Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -56,10 +56,17 @@
                         const std::vector<team>& teams,
                const gamemap::location& loc,const team& current_team,int side);
 
+struct cost_calculator
+{
+       virtual double cost(const gamemap::location& loc, const double so_far, 
const bool isDst) const = 0;
+       virtual ~cost_calculator() {}
+       inline double getNoPathValue(void) const { return (42424242.0); }
+};
+
 //object which contains all the possible locations a unit can move to, with
 //associated best routes to those locations.
 struct paths
-{
+{      
        paths() {}
 
        //construct a list of paths for the unit at loc.
@@ -83,26 +90,25 @@
        };
 
        typedef std::map<gamemap::location,route> routes_map;
-       routes_map routes;
+       routes_map routes;              
 };
 
+paths::route a_star_search(gamemap::location const &src, gamemap::location 
const &dst,
+                                                                               
                         double stop_at, cost_calculator const *costCalculator,
+                                                                               
                         const size_t parWidth, const size_t parHeight,
+                                                                               
                         std::set<gamemap::location> const *teleports = NULL);
+
 //function which, given a unit and a route the unit can move on, will
 //return the number of turns it will take the unit to traverse the route.
 int route_turns_to_complete(const unit& u, const gamemap& map,
                             const paths::route& rt);
 
-struct cost_calculator
-{
-       virtual double cost(const gamemap::location& loc, double so_far) const 
= 0;
-       virtual ~cost_calculator() {}
-};
-
 struct shortest_path_calculator : cost_calculator
 {
        shortest_path_calculator(const unit& u, const team& t,
                                 const unit_map& units, const 
std::vector<team>& teams,
                                 const gamemap& map, const gamestatus& status);
-       virtual double cost(const gamemap::location& loc, double so_far) const;
+       virtual double cost(const gamemap::location& loc, const double so_far, 
const bool isDst) const;
 
 private:
        const unit& unit_;
@@ -113,8 +119,4 @@
        const gamestatus& status_;
 };
 
-paths::route a_star_search(gamemap::location const &src, gamemap::location 
const &dst,
-                           double stop_at, cost_calculator const *obj,
-                           std::set<gamemap::location> const *teleports = 
NULL);
-
 #endif
Index: wesnoth/src/pathutils.hpp
diff -u wesnoth/src/pathutils.hpp:1.1 wesnoth/src/pathutils.hpp:1.2
--- wesnoth/src/pathutils.hpp:1.1       Thu Sep  2 15:41:09 2004
+++ wesnoth/src/pathutils.hpp   Fri Jan 21 20:16:43 2005
@@ -1,3 +1,20 @@
+/* $Id: pathutils.hpp,v 1.2 2005/01/21 20:16:43 Sirp Exp $ */
+/*
+Copyright (C) 2003 by David White <address@hidden>
+Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License.
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY.
+
+See the COPYING file for more details.
+*/
+
+#ifndef PATHUTILS_H_INCLUDED
+#define PATHUTILS_H_INCLUDED
+
+#include "global.hpp"
 #include "map.hpp"
 
 //function which tells if two locations are adjacent.
@@ -10,3 +27,6 @@
 //function which gives the number of hexes between two tiles (i.e. the minimum
 //number of hexes that have to be traversed to get from one hex to the other)
 size_t distance_between(const gamemap::location& a, const gamemap::location& 
b);
+
+#endif
+
Index: wesnoth/src/unit.cpp
diff -u wesnoth/src/unit.cpp:1.113 wesnoth/src/unit.cpp:1.114
--- wesnoth/src/unit.cpp:1.113  Wed Jan 19 20:11:34 2005
+++ wesnoth/src/unit.cpp        Fri Jan 21 20:16:43 2005
@@ -1,4 +1,4 @@
-/* $Id: unit.cpp,v 1.113 2005/01/19 20:11:34 silene Exp $ */
+/* $Id: unit.cpp,v 1.114 2005/01/21 20:16:43 Sirp Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -308,7 +308,8 @@
                set_flag("ambush");
        if(type().has_ability("nightstalk"))
                set_flag("nightstalk");
-
+       if(type().has_ability("submerge"))
+               set_flag("submerge");
        if(stone())
                set_attacked();
 }
@@ -429,12 +430,25 @@
        bool is_inv = false;
 
        static const std::string forest_invisible("ambush");
-       
if(std::count(terrain.begin(),terrain.end(),static_cast<gamemap::TERRAIN>(gamemap::FOREST))
 && has_flag(forest_invisible)) {
+       if ((has_flag(forest_invisible)) &&
+               (std::count(terrain.begin(), terrain.end(), gamemap::FOREST))) {
                is_inv = true;
        }
-       static const std::string night_invisible("nightstalk");
-       if((lawful_bonus < 0) && has_flag(night_invisible)) {
-               is_inv = true;
+       else
+       {
+               static const std::string night_invisible("nightstalk");
+               if ((lawful_bonus < 0) && has_flag(night_invisible)) {
+                       is_inv = true;
+               }
+               else
+               {
+                       static const std::string sea_invisible("submerge");
+                       if ((has_flag(sea_invisible)) &&
+                               ((std::count(terrain.begin(), terrain.end(), 
gamemap::SEA)) ||
+                               (std::count(terrain.begin(), terrain.end(), 
gamemap::DEEP_SEA)))) {
+                                       is_inv = true;
+                               }
+               }
        }
 
        if(is_inv){
@@ -465,11 +479,11 @@
 bool unit::incapacitated() const
 {
        return stone();
-}
-
-bool unit::emits_zoc() const
-{
-       return type().has_zoc() && stone() == false;
+}
+
+bool unit::emits_zoc() const
+{
+       return type().has_zoc() && stone() == false;
 }
 
 bool unit::matches_filter(const config& cfg) const
@@ -809,13 +823,6 @@
 
 int unit::movement_cost(const gamemap& map, gamemap::TERRAIN terrain) const
 {
-//don't allow level 0 units to take villages - removed until AI
-//is smart enough to deal with this.
-//     if(type_->level() == 0 && map.is_village(terrain))
-//             return 100;
-
-
-
        const int res = type_->movement_type().movement_cost(map,terrain);
 
        static const std::string slowed_string("slowed");
@@ -826,8 +833,7 @@
        return res;
 }
 
-int unit::defense_modifier(const gamemap& map,
-                              gamemap::TERRAIN terrain) const
+int unit::defense_modifier(const gamemap& map, gamemap::TERRAIN terrain) const
 {
        return type_->movement_type().defense_modifier(map,terrain);
 }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]