Author: fendrin
Date: Sun Jan 17 23:51:49 2010
New Revision: 40736

URL: http://svn.gna.org/viewcvs/wesnoth?rev=40736&view=rev
Log:
Introduced a new class teleport_group.

Modified:
    branches/fendrin_pathfind/src/game_events.cpp
    branches/fendrin_pathfind/src/map.hpp
    branches/fendrin_pathfind/src/pathfind.cpp
    branches/fendrin_pathfind/src/pathfind.hpp

Modified: branches/fendrin_pathfind/src/game_events.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/branches/fendrin_pathfind/src/game_events.cpp?rev=40736&r1=40735&r2=40736&view=diff
==============================================================================
--- branches/fendrin_pathfind/src/game_events.cpp (original)
+++ branches/fendrin_pathfind/src/game_events.cpp Sun Jan 17 23:51:49 2010
@@ -839,22 +839,10 @@
 //TODO move to the right place
 WML_HANDLER_FUNCTION(tunnel, /*event_info*/, cfg)
 {
-       vconfig::child_list source_elements = cfg.get_children("source");
-       std::set<map_location> source;
-       terrain_filter filter_source(source_elements.front(), 
*resources::units);
-       filter_source.restrict_size(game_config::max_loop);
-       filter_source.get_locations(source);
-
-       vconfig::child_list dest_elements = cfg.get_children("dest");
-       std::set<map_location> dest;
-       terrain_filter filter_dest(dest_elements.front(), *resources::units);
-       filter_dest.restrict_size(game_config::max_loop);
-       filter_dest.get_locations(dest);
-
-       gamemap *game_map = resources::game_map;
-
-       game_map->set_tunnel(std::make_pair(source, dest));
        //TODO add recording to the savefile
+       ERR_WML << cfg.get_config().debug();
+       teleport_group blah = teleport_group(cfg);
+       resources::game_map->set_tunnel(blah);
 }
 
 WML_HANDLER_FUNCTION(modify_ai, /*event_info*/, cfg)

Modified: branches/fendrin_pathfind/src/map.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/branches/fendrin_pathfind/src/map.hpp?rev=40736&r1=40735&r2=40736&view=diff
==============================================================================
--- branches/fendrin_pathfind/src/map.hpp (original)
+++ branches/fendrin_pathfind/src/map.hpp Sun Jan 17 23:51:49 2010
@@ -30,7 +30,8 @@
 
 
 //TODO clean up
-typedef std::pair<std::set<map_location>, std::set<map_location> > 
teleport_group;
+#include "pathfind.hpp"
+//typedef std::pair<std::set<map_location>, std::set<map_location> > 
teleport_pair;
 
 /**
  * Encapsulates the map of the game.
@@ -42,10 +43,6 @@
 class gamemap
 {
 public:
-
-       //TODO cleanup
-//     teleport_map get_teleport_locations(const unit &u, const unit_map 
&units,
-//                     const team &viewing_team, bool see_all, bool 
ignore_units);
 
        // The name of the terrain is the terrain itself,
        // The underlying terrain is the name of the terrain for game-logic 
purposes.

Modified: branches/fendrin_pathfind/src/pathfind.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/branches/fendrin_pathfind/src/pathfind.cpp?rev=40736&r1=40735&r2=40736&view=diff
==============================================================================
--- branches/fendrin_pathfind/src/pathfind.cpp (original)
+++ branches/fendrin_pathfind/src/pathfind.cpp Sun Jan 17 23:51:49 2010
@@ -38,11 +38,63 @@
 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_() {
+
+       //TODO error handling
+//     vconfig::child_list source_elements = cfg.get_children("source");
+//     source_ = terrain_filter(source_elements.front(), *resources::units);
+//     source_.restrict_size(game_config::max_loop);
+
+//     vconfig::child_list target_elements = cfg.get_children("target");
+//     target_ = terrain_filter(target_elements.front(), *resources::units);
+//     target_.restrict_size(game_config::max_loop);
+
+
+
+//                     std::set<map_location> dest;
+//                     terrain_filter filter_dest(dest_elements.front(), 
*resources::units);
+//                     filter_dest.restrict_size(game_config::max_loop);
+//
+//                     gamemap *game_map = resources::game_map;
+//
+//                     game_map->set_tunnel(std::make_pair(source, dest));
+//                     //TODO add recording to the savefile
+
+teleport_group::teleport_group(vconfig cfg) :
+               source_filter_(cfg.get_children("source").front(), 
*resources::units),
+               target_filter_(cfg.get_children("target").front(), 
*resources::units),
+               unit_filter_(cfg.get_children("filter").front()),
+               cfg_(cfg)
+               {
+//     source_filter_(cfg.get_children("source").front(), *resources::units);
+//     target_filter_(cfg.get_children("target").front(), *resources::units);
+//     unit_filter_(cfg.get_children("filter").front());
+//     cfg_(cfg);
+                       ERR_PF << cfg.get_config().debug();
+                       ERR_PF << cfg_.get_config().debug();
+                       //TODO error handling.
+}
+
+void teleport_group::get_teleport_pair(teleport_pair& loc_pair, const unit& u) 
{
+       if (u.matches_filter(unit_filter_, u.get_location())) {
+               source_filter_.get_locations(loc_pair.first);
+               target_filter_.get_locations(loc_pair.second);
+       }
+}
+
+config teleport_group::to_config() const {
+       return cfg_.get_config();
+}
+
+teleport_map::teleport_map(std::vector<teleport_group> groups, const unit& u) 
: teleport_map_(), sources_(), destinations_(), empty_() {
 
        for (std::vector<teleport_group>::iterator it = groups.begin(); it != 
groups.end(); ++it) {
-               sources_.push_back(it->first);
-               destinations_.push_back(it->second);
+
+               teleport_pair locations;
+
+               it->get_teleport_pair(locations, u);
+
+               sources_.push_back(locations.first);
+               destinations_.push_back(locations.second);
        }
 
        std::vector<std::set<map_location> >::iterator destinations_it = 
destinations_.begin();
@@ -190,15 +242,15 @@
 
        std::vector<teleport_group> groups = std::vector<teleport_group>();
 
-       teleport_group village_group = std::make_pair(villages, villages);
-
-       groups.push_back(village_group);
+//     teleport_pair village_pair = std::make_pair(villages, villages);
+
+//     groups.push_back(village_group);
 
        const std::vector<teleport_group>& custom_groups = 
resources::game_map->tunnels();
 
        groups.insert(groups.end(), custom_groups.begin(), custom_groups.end());
 
-       const teleport_map res = teleport_map(groups);
+       const teleport_map res = teleport_map(groups, u);
        return res;
 }
 

Modified: branches/fendrin_pathfind/src/pathfind.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/branches/fendrin_pathfind/src/pathfind.hpp?rev=40736&r1=40735&r2=40736&view=diff
==============================================================================
--- branches/fendrin_pathfind/src/pathfind.hpp (original)
+++ branches/fendrin_pathfind/src/pathfind.hpp Sun Jan 17 23:51:49 2010
@@ -33,12 +33,61 @@
 #include <vector>
 #include <functional>
 
-typedef std::pair<std::set<map_location>, std::set<map_location> > 
teleport_group;
+
+
+/*
+ *
+ */
+typedef std::pair<std::set<map_location>, std::set<map_location> > 
teleport_pair;
+/*
+ *
+ */
+#include "config.hpp"
+#include "terrain_filter.hpp"
+#include "savegame_config.hpp"
+class teleport_group : public savegame::savegame_config
+{
+public:
+       teleport_group(vconfig cfg);
+
+       /*
+        * Fills the argument loc_pair if the unit u matches the groups filter.
+        */
+       void get_teleport_pair(teleport_pair& loc_pair, const unit& u);
+
+       //from savegame_config -- why doesn't the compiler force me to 
implement it?
+       config to_config() const;
+
+private:
+
+       //TODO think about terrain_filter uses pathfinding? Endless loop?
+       terrain_filter source_filter_;
+       terrain_filter target_filter_;
+       vconfig unit_filter_;
+       vconfig cfg_;
+};
+
+//     vconfig::child_list source_elements = cfg.get_children("source");
+//             std::set<map_location> source;
+//             terrain_filter filter_source(source_elements.front(), 
*resources::units);
+//             filter_source.restrict_size(game_config::max_loop);
+//             filter_source.get_locations(source);
+//
+//             vconfig::child_list dest_elements = cfg.get_children("dest");
+//             std::set<map_location> dest;
+//             terrain_filter filter_dest(dest_elements.front(), 
*resources::units);
+//             filter_dest.restrict_size(game_config::max_loop);
+//             filter_dest.get_locations(dest);
+//
+//             gamemap *game_map = resources::game_map;
+//
+//             game_map->set_tunnel(std::make_pair(source, dest));
+//             //TODO add recording to the savefile
 
 class teleport_map
 {
 public:
-       teleport_map(std::vector<teleport_group> teleport_groups);
+       teleport_map(std::vector<teleport_group> teleport_groups, const unit& 
u);
        teleport_map() : teleport_map_(), sources_(), destinations_(), empty_() 
{};
        teleport_map(const teleport_map &other);
        teleport_map& operator=(const teleport_map &other);


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

Reply via email to