Author: jhinrichs
Date: Wed Jul 30 20:19:40 2008
New Revision: 28271

URL: http://svn.gna.org/viewcvs/wesnoth?rev=28271&view=rev
Log:
This fixes a bug reported by ShadowMaster, which made Wesnoth process the 
[advancefrom] WML tag wrong. It originated from missing information caused by 
lazy loading of unit types.
It might also very well fix bug #11731 (Wesnoth segfaults on AI turn when any 
unit has incorrect advanceto=), at least those cases, where it is not caused by 
wrong unit WML.

Modified:
    trunk/src/log.cpp
    trunk/src/log.hpp
    trunk/src/unit_types.cpp
    trunk/src/unit_types.hpp

Modified: trunk/src/log.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/log.cpp?rev=28271&r1=28270&r2=28271&view=diff
==============================================================================
--- trunk/src/log.cpp (original)
+++ trunk/src/log.cpp Wed Jul 30 20:19:40 2008
@@ -53,7 +53,7 @@
        engine("engine"), network("network"), mp_server("server"),
        filesystem("filesystem"), audio("audio"), notifs("notifs"),
        replay("replay"), help("help"), gui("gui"), gui_parse("gui_parse"),
-       gui_draw("gui_draw"), gui_event("gui_event"), editor("editor");
+       gui_draw("gui_draw"), gui_event("gui_event"), editor("editor"), 
wml("wml");
 
 log_domain::log_domain(char const *name) : domain_(log_domains.size())
 {
@@ -118,7 +118,7 @@
                }
                if (show_names) {
                        std::cerr << name_ << ' ' << d.name_ << ": ";
-               }                       
+               }
                return std::cerr;
        }
 }
@@ -130,7 +130,7 @@
        ticks_ = SDL_GetTicks();
        (*output_) << "BEGIN: " << str_ << "\n";
        ++indent;
-}      
+}
 
 void scope_logger::do_log_exit()
 {
@@ -139,7 +139,7 @@
        do_indent();
        if (timestamp) (*output_) << get_timestamp(time(NULL));
        (*output_) << "END: " << str_ << " (took " << ticks << "ms)\n";
-}      
+}
 
 void scope_logger::do_indent() const
 {

Modified: trunk/src/log.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/log.hpp?rev=28271&r1=28270&r2=28271&view=diff
==============================================================================
--- trunk/src/log.hpp (original)
+++ trunk/src/log.hpp Wed Jul 30 20:19:40 2008
@@ -51,14 +51,14 @@
        int severity_;
 public:
        logger(char const *name, int severity): name_(name), 
severity_(severity) {}
-       std::ostream &operator()(log_domain const &domain, 
+       std::ostream &operator()(log_domain const &domain,
                bool show_names = true, bool do_indent = false) const;
 
        bool dont_log(log_domain const &domain) const
        {
                logd const &d = log_domains[domain.domain_];
                return severity_ > d.severity_;
-       }       
+       }
 };
 
 void timestamps(bool);
@@ -66,8 +66,8 @@
 
 extern logger err, warn, info, debug;
 extern log_domain general, ai, config, display, engine, network, mp_server,
-       filesystem, audio, notifs, replay, help, gui, gui_parse, gui_draw, 
-       gui_event, editor;
+       filesystem, audio, notifs, replay, help, gui, gui_parse, gui_draw,
+       gui_event, editor, wml;
 
 class scope_logger
 {

Modified: trunk/src/unit_types.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/unit_types.cpp?rev=28271&r1=28270&r2=28271&view=diff
==============================================================================
--- trunk/src/unit_types.cpp (original)
+++ trunk/src/unit_types.cpp Wed Jul 30 20:19:40 2008
@@ -1056,6 +1056,8 @@
         // we insert an empty unit_type and build it after the copy (for 
performance)
         std::pair<unit_type_map::iterator,bool> insertion =
             insert(std::pair<const std::string,unit_type>(id,unit_type()));
+        unit_type_map::iterator itor = types_.find(id);
+        itor->second.set_config(**i.first);
         //     if (!insertion.second)
         // TODO: else { warning for multiple units with same id}
         lg::info(lg::config) << "added " << id << " to unit_type list 
(unit_type_data.unit_types)\n";
@@ -1082,11 +1084,14 @@
         // we insert an empty unit_type and build it after the copy (for 
performance)
         std::pair<unit_type_map::iterator,bool> insertion =
             insert(std::pair<const std::string,unit_type>(id,unit_type()));
+
         //     if (!insertion.second)
         // TODO: else { warning for multiple units with same id}
         lg::info(lg::config) << "added " << id << " to unit_type list 
(unit_type_data.unit_types)\n";
                std::cerr << "warning: UnitWML [unit] tag will be removed in 
1.5.3, run wmllint on WML defining " << id << " to convert it to using 
[unit_type]" << std::endl;
        }
+
+       build_all(unit_type::NOT_BUILT);
 }
 
 unit_type_data::unit_type_map::const_iterator 
unit_type_data::unit_type_map_wrapper::find(const std::string& key, 
unit_type::BUILD_STATUS status) const
@@ -1145,9 +1150,14 @@
     if (key == "dummy_unit")
         return ut->second;
 
+    DBG_UT << "Building unit type " << ut->first << ", level " << status << 
"\n";
+
     const config& unit_cfg = find_config(key);
 
     switch (status){
+        case unit_type::NOT_BUILT:
+            add_advancement(unit_cfg, ut->second);
+            break;
         case unit_type::HELP_INDEX:
             //build the stuff that is needed to feed the help index
             if (ut->second.build_status() == unit_type::NOT_BUILT)
@@ -1208,6 +1218,8 @@
         // Fix up advance_from references
         from_unit->second.add_advancement(to_unit, xp);
 
+        DBG_UT << "Added advancement ([advancefrom]) from " << from << " to " 
<< to_unit.id() << "\n";
+
         // Store what unit this type advances from
                to_unit.add_advancesfrom(from);
     }

Modified: trunk/src/unit_types.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/unit_types.hpp?rev=28271&r1=28270&r2=28271&view=diff
==============================================================================
--- trunk/src/unit_types.hpp (original)
+++ trunk/src/unit_types.hpp Wed Jul 30 20:19:40 2008
@@ -250,6 +250,8 @@
     BUILD_STATUS build_status() const { return build_status_; }
 
        const std::vector<tportrait>& portraits() const { return portraits_; }
+
+       void set_config(config& cfg) { cfg_ = cfg; }
 private:
        void operator=(const unit_type& o);
 
@@ -340,7 +342,7 @@
                                types_(),
                                dummy_unit_map_(),
                                movement_types_(),
-                               races_(), 
+                               races_(),
                                unit_traits_(),
                                unit_cfg_(0)
                        {}


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

Reply via email to