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

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

[Wesnoth-cvs-commits] wesnoth/src unit_types.cpp unit_types.hpp


From: John McNabb
Subject: [Wesnoth-cvs-commits] wesnoth/src unit_types.cpp unit_types.hpp
Date: Fri, 27 May 2005 13:24:13 -0400

CVSROOT:        /cvsroot/wesnoth
Module name:    wesnoth
Branch:         
Changes by:     John McNabb <address@hidden>    05/05/27 17:24:12

Modified files:
        src            : unit_types.cpp unit_types.hpp 

Log message:
        added [advancefrom] tag, patch 3625

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/unit_types.cpp.diff?tr1=1.102&tr2=1.103&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/unit_types.hpp.diff?tr1=1.68&tr2=1.69&r1=text&r2=text

Patches:
Index: wesnoth/src/unit_types.cpp
diff -u wesnoth/src/unit_types.cpp:1.102 wesnoth/src/unit_types.cpp:1.103
--- wesnoth/src/unit_types.cpp:1.102    Thu May 12 18:08:26 2005
+++ wesnoth/src/unit_types.cpp  Fri May 27 17:24:12 2005
@@ -1,4 +1,4 @@
-/* $Id: unit_types.cpp,v 1.102 2005/05/12 18:08:26 ott Exp $ */
+/* $Id: unit_types.cpp,v 1.103 2005/05/27 17:24:12 darthfool Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -534,7 +534,8 @@
       leadership_(o.leadership_), illuminates_(o.illuminates_),
       skirmish_(o.skirmish_), teleport_(o.teleport_),
       nightvision_(o.nightvision_), steadfast_(o.steadfast_),
-      can_advance_(o.can_advance_), alignment_(o.alignment_),
+      advances_to_(o.advances_to_), experience_needed_(o.experience_needed_),
+      alignment_(o.alignment_),
       movementType_(o.movementType_), possibleTraits_(o.possibleTraits_),
       genders_(o.genders_), defensive_animations_(o.defensive_animations_),
       teleport_animations_(o.teleport_animations_), 
death_animations_(o.death_animations_)
@@ -654,7 +655,11 @@
                movementType_.set_parent(&(it->second));
        }
 
-       can_advance_ = advances_to().empty() == false;
+       const std::string& advance_to_val = cfg_["advanceto"];
+       if(advance_to_val != "null" && advance_to_val != "")
+               advances_to_ = utils::split(advance_to_val);
+
+       experience_needed_=lexical_cast_default<int>(cfg_["experience"],500);
 
        const config::child_list& defends = cfg_.get_children("defend");
        for(config::child_list::const_iterator d = defends.begin(); d != 
defends.end(); ++d) {
@@ -892,16 +897,12 @@
 
 int unit_type::experience_needed() const
 {
-       return 
(lexical_cast_default<int>(cfg_["experience"],500)*experience_modifier)/100;
+       return (experience_needed_ * experience_modifier) /100;
 }
 
 std::vector<std::string> unit_type::advances_to() const
 {
-       const std::string& val = cfg_["advanceto"];
-       if(val == "null" || val == "")
-               return std::vector<std::string>();
-       else
-               return utils::split(val);
+    return advances_to_;
 }
 
 const config::child_list& unit_type::modification_advancements() const
@@ -1010,7 +1011,7 @@
 
 bool unit_type::can_advance() const
 {
-       return can_advance_;
+       return !advances_to_.empty();
 }
 
 bool unit_type::has_zoc() const
@@ -1146,6 +1147,38 @@
        }
 }
 
+void unit_type::add_advancement(const unit_type &to_unit,int xp)
+{
+       const std::string &to_id =  to_unit.cfg_["id"];
+       const std::string &from_id =  cfg_["id"];
+
+       // add extra advancement path to this unit type
+       lg::info(lg::config) << "adding advancement from " << from_id << " to " 
<< to_id << "\n";
+       advances_to_.push_back(to_id);
+       if(xp>0 && experience_needed_>xp) experience_needed_=xp;
+
+       // add advancements to gendered subtypes, if supported by to_unit
+       for(int gender=0; gender<=1; ++gender) {
+               if(gender_types_[gender] == NULL) continue;
+               if(to_unit.gender_types_[gender] == NULL) {
+                       lg::warn(lg::config) << to_id << " does not support 
gender " << gender << "\n";
+                       continue;
+               }                       
+               lg::info(lg::config) << "gendered advancement " << gender << ": 
";
+               
gender_types_[gender]->add_advancement(*(to_unit.gender_types_[gender]),xp);
+       }
+
+       // add advancements to variation subtypes
+       // since these are still a rare and special-purpose feature,
+       // we assume that the unit designer knows what they're doing,
+       // and don't block advancements that would remove a variation
+       for(variations_map::iterator v=variations_.begin(); 
+           v!=variations_.end(); ++v) {
+               lg::info(lg::config) << "variation advancement: ";
+               v->second->add_advancement(to_unit,xp);
+       }
+}
+
 game_data::game_data()
 {}
 
@@ -1179,6 +1212,27 @@
                const unit_type 
u_type(**j.first,movement_types,races,unit_traits);
                
unit_types.insert(std::pair<std::string,unit_type>(u_type.id(),u_type));
        }
+
+        // fix up advance_from references
+        for(config::const_child_itors k = cfg.child_range("unit");
+            k.first != k.second; ++k.first)
+          for(config::const_child_itors af = 
(*k.first)->child_range("advancefrom");
+            af.first != af.second; ++af.first) {
+                const std::string &to = (**k.first)["id"];
+                const std::string &from = (**af.first)["unit"];
+                const int xp = 
lexical_cast_default<int>((**af.first)["experience"],0);
+ 
+                unit_type_map::iterator from_unit = unit_types.find(from);
+                unit_type_map::iterator to_unit = unit_types.find(to);
+                if(from_unit==unit_types.end()) {
+                  lg::warn(lg::config) << "unknown unit " << from << " in 
advancefrom\n";
+                        continue;
+                }
+                wassert(to_unit!=unit_types.end());
+ 
+                from_unit->second.add_advancement(to_unit->second,xp);
+        }
+
 }
 
 void game_data::clear()
Index: wesnoth/src/unit_types.hpp
diff -u wesnoth/src/unit_types.hpp:1.68 wesnoth/src/unit_types.hpp:1.69
--- wesnoth/src/unit_types.hpp:1.68     Sat Apr 23 21:55:38 2005
+++ wesnoth/src/unit_types.hpp  Fri May 27 17:24:12 2005
@@ -1,4 +1,4 @@
-/* $Id: unit_types.hpp,v 1.68 2005/04/23 21:55:38 silene Exp $ */
+/* $Id: unit_types.hpp,v 1.69 2005/05/27 17:24:12 darthfool Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -163,6 +163,11 @@
 
        ~unit_type();
 
+        // adds an additional advancement path to a unit type
+        // this is used to implement the [advancefrom] tag
+        void add_advancement(const unit_type &advance_to,int experience);
+
+
        const unit_type& get_gender_unit_type(unit_race::GENDER gender) const;
        const unit_type& get_variation(const std::string& name) const;
         //info on the type of unit that the unit reanimates as
@@ -278,7 +283,9 @@
        bool teleport_;
        bool nightvision_;
        bool steadfast_;
-       bool can_advance_;
+        std::vector<std::string> advances_to_;
+        int experience_needed_;
+
        ALIGNMENT alignment_;
 
        unit_movement_type movementType_;




reply via email to

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