Author: fendrin
Date: Mon Jan 11 18:55:01 2010
New Revision: 40662

URL: http://svn.gna.org/viewcvs/wesnoth?rev=40662&view=rev
Log:
Fixed the normal pathfinding again. Mage teleport and custom teleport is still 
segfaulting.

Modified:
    branches/fendrin_pathfind/src/astarsearch.cpp
    branches/fendrin_pathfind/src/pathfind.cpp
    branches/fendrin_pathfind/src/pathfind.hpp

Modified: branches/fendrin_pathfind/src/astarsearch.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/branches/fendrin_pathfind/src/astarsearch.cpp?rev=40662&r1=40661&r2=40662&view=diff
==============================================================================
--- branches/fendrin_pathfind/src/astarsearch.cpp (original)
+++ branches/fendrin_pathfind/src/astarsearch.cpp Mon Jan 11 18:55:01 2010
@@ -85,10 +85,10 @@
                if (!teleports->empty()) {
 
                        double new_srch = 1.0;
-                       std::vector<std::set<map_location> >* sources = 
teleports->get_sources();
-
-                       std::vector<std::set<map_location> >::iterator it = 
sources->begin();
-                       for(; it != sources->end(); ++it) {
+                       std::vector<std::set<map_location> > sources = 
teleports->get_sources();
+
+                       std::vector<std::set<map_location> >::iterator it = 
sources.begin();
+                       for(; it != sources.end(); ++it) {
                                for(std::set<map_location>::iterator it2 = 
it->begin(); it2 != it->end(); it2++) {
                                        const double tmp_srch = heuristic(c, 
*it2);
                                        if (tmp_srch < new_srch) { new_srch = 
tmp_srch; }
@@ -96,11 +96,11 @@
                        }
 
                        double new_dsth = 1.0;
-                       std::vector<std::set<map_location> >* destinations = 
teleports->get_destinations();
-
-                       it = destinations->begin();
-
-                       for(; it != destinations->end(); ++it) {
+                       std::vector<std::set<map_location> > destinations = 
teleports->get_destinations();
+
+                       it = destinations.begin();
+
+                       for(; it != destinations.end(); ++it) {
                                std::set<map_location>::iterator it2;
                                for(it2 = it->begin(); it2 != it->end(); ++it2) 
{
                                        const double tmp_dsth = heuristic(*it2, 
dst);
@@ -183,6 +183,8 @@
        std::vector<int> pq;
        pq.push_back(index(src));
 
+       ERR_PF << "Expandiere den Knoten: " << pq.front() << "\n";
+
        while (!pq.empty()) {
                node& n = nodes[pq.front()];
 
@@ -202,28 +204,27 @@
                int i;
                if (!teleports->empty()) {
 
-                       std::set<map_location>* allowed_teleports = 
teleports->get_adjacents(n.curr);
+                       std::set<map_location> allowed_teleports = 
teleports->get_adjacents(n.curr);
 
 //                     teleports_iterator = teleports->get_adjacents(n.curr);
-
 //                     i = teleports_iterator != teleports->end() ? 
(*(teleports_iterator->second)).size() + 6 : 6;
 
-                       i = allowed_teleports->size();
-
+                       i = allowed_teleports.size() +6;
                        locs = std::vector<map_location>(i);
 
 //                     if (teleports_iterator != teleports->end() ) {
-                       std::copy(allowed_teleports->begin(), 
allowed_teleports->end(), locs.begin() + 6);
+                       std::copy(allowed_teleports.begin(), 
allowed_teleports.end(), locs.begin() + 6);
 //                     }
 
-               } else { locs = std::vector<map_location>(6); i = 6;}
+               } else
+               { locs = std::vector<map_location>(6); i = 6;}
 
                get_adjacent_tiles(n.curr, &locs[0]);
 
                for (; i-- > 0;) {
 
-                       if (i == 6) {
-                               ERR_PF << "bin am teleporter";
+                       if (i != 5) {
+                               ERR_PF << "Keine normale anzahl\n";
                        }
 
                        if (!locs[i].valid(width, height)) continue;

Modified: branches/fendrin_pathfind/src/pathfind.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/branches/fendrin_pathfind/src/pathfind.cpp?rev=40662&r1=40661&r2=40662&view=diff
==============================================================================
--- branches/fendrin_pathfind/src/pathfind.cpp (original)
+++ branches/fendrin_pathfind/src/pathfind.cpp Mon Jan 11 18:55:01 2010
@@ -38,7 +38,38 @@
 static lg::log_domain log_engine("engine");
 #define ERR_PF LOG_STREAM(err, log_engine)
 
-
+teleport_map::teleport_map(std::vector<teleport_group> groups) : 
teleport_map_(), sources_(), destinations_(), empty_() {
+
+       sources_.push_back(std::set<map_location>() );
+
+       for (std::vector<teleport_group>::iterator i = groups.begin(); i != 
groups.end(); i++) {
+               sources_.push_back(i->first);
+               destinations_.push_back(i->second);
+               for(std::set<map_location>::iterator it = i->first.begin(); it 
!= i->first.end(); it++) {
+                       teleport_map_.insert(std::make_pair(*it, &(i->second)));
+               }
+       }
+
+//     foreach (const teleport_group& group, groups) {
+//             sources_.insert(group.first);
+//             destinations_.insert(group.second);
+//     }
+}
+
+//TODO move to the right place
+const std::set<map_location>& teleport_map::get_adjacents(map_location loc) 
const {
+
+       if (teleport_map_.count(loc) == 0) {
+//             const std::set<map_location> ret = sources_[0];
+               return empty_;
+       } else {
+//             const std::set<map_location>& ret = 
*(teleport_map_.find(loc)->second);
+               return *(teleport_map_.find(loc)->second);
+       }
+
+//     return ret;
+//     return teleport_map_.count(loc) == 0 ? &(sources_[0]) : 
*(teleport_map_.find(loc)->second);
+}
 
 
 
@@ -115,7 +146,7 @@
        const unit_map &units, const team &viewing_team,
        bool see_all, bool ignore_units)
 {
-       std::set<map_location> villages;
+       std::set<map_location> villages = std::set<map_location>();
        if (u.get_ability_bool("teleport")) {
                const team &current_team = (*resources::teams)[u.side() - 1];
                const map_location &loc = u.get_location();
@@ -132,9 +163,11 @@
                }
        }
 
-       std::vector<teleport_group> groups;
-
-       groups[0] = std::make_pair(villages, villages);
+       std::vector<teleport_group> groups = std::vector<teleport_group>();
+
+       teleport_group village_group = std::make_pair(villages, villages);
+
+       groups.push_back(village_group);
 
 //     std::map<map_location, std::set<map_location>* > res;
 //     foreach (const map_location &v, villages)
@@ -277,9 +310,9 @@
                pq.pop_back();
                n.in = search_counter;
 
-               std::set<map_location>* allowed_teleports = 
teleports.get_adjacents(n.curr);
-               std::vector<map_location> locs(6 + allowed_teleports->size());
-               std::copy(allowed_teleports->begin(), allowed_teleports->end(), 
locs.begin() + 6);
+               std::set<map_location> allowed_teleports = 
teleports.get_adjacents(n.curr);
+               std::vector<map_location> locs(6 + allowed_teleports.size());
+               std::copy(allowed_teleports.begin(), allowed_teleports.end(), 
locs.begin() + 6);
                get_adjacent_tiles(n.curr, &locs[0]);
                for (int i = locs.size(); i-- > 0; ) {
                        if (!locs[i].valid(map.w(), map.h())) continue;

Modified: branches/fendrin_pathfind/src/pathfind.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/branches/fendrin_pathfind/src/pathfind.hpp?rev=40662&r1=40661&r2=40662&view=diff
==============================================================================
--- branches/fendrin_pathfind/src/pathfind.hpp (original)
+++ branches/fendrin_pathfind/src/pathfind.hpp Mon Jan 11 18:55:01 2010
@@ -39,19 +39,19 @@
 {
 public:
        teleport_map(std::vector<teleport_group> teleport_groups);
-       teleport_map() : teleport_map_(), sources_(), destinations_() {};
-
-       std::set<map_location>* get_adjacents(map_location loc) const;
+       teleport_map() : teleport_map_(), sources_(), destinations_(), empty_() 
{};
+
+       const std::set<map_location>& get_adjacents(map_location loc) const;
        bool empty() const { return sources_.empty(); }
 
-
-       std::vector<std::set<map_location> > const* get_sources() const {return 
&sources_; };
-       std::vector<std::set<map_location> > const* get_destinations() const 
{return &destinations_; };
+       const std::vector<std::set<map_location> >& get_sources() const {return 
sources_; };
+       const std::vector<std::set<map_location> >& get_destinations() const 
{return destinations_; };
 
 private:
        std::map<map_location, std::set<map_location>* > teleport_map_;
        std::vector<std::set<map_location> > sources_;
        std::vector<std::set<map_location> > destinations_;
+       std::set<map_location> empty_;
 
 /*
        class teleport_group {


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

Reply via email to