mail[Wesnoth-commits] r24923 - in /trunk: data/ src/


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by dragonking on March 21, 2008 - 05:00:
Author: dragonking
Date: Fri Mar 21 05:00:25 2008
New Revision: 24923

URL: http://svn.gna.org/viewcvs/wesnoth?rev=24923&view=rev
Log:
Added unit formulas.We can now put into [unit] [/unit]: 
formula=''...''  which specify custom unit-formula
[ai_vars] ... [/ai_vars] which specify AI variables for that unit
Formulas for units are executed at begining of the turn. Basic example can be 
found in scenario-formula.cfg 
Run: wesnoth --test formula --debug to see it in action

Modified:
    trunk/data/scenario-formula.cfg
    trunk/src/callable_objects.cpp
    trunk/src/formula_ai.cpp
    trunk/src/formula_ai.hpp
    trunk/src/formula_callable.hpp
    trunk/src/unit.cpp
    trunk/src/unit.hpp
    trunk/src/wesconfig.h

Modified: trunk/data/scenario-formula.cfg
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/data/scenario-formula.cfg?rev=24923&r1=24922&r2=24923&view=diff
==============================================================================
--- trunk/data/scenario-formula.cfg (original)
+++ trunk/data/scenario-formula.cfg Fri Mar 21 05:00:25 2008
@@ -56,6 +56,29 @@
         canrecruit=1
         recruit=Skeleton,Skeleton Archer,Walking Corpse,Ghost,Vampire 
Bat,Dark Adept,Ghoul
         gold=100
+
+        [unit]
+            x,y=4,23
+            type="Orcish Archer"
+            generate_description=yes
+               formula="recruit('Skeleton Archer')"    
+               [ai_vars]
+                       number=2
+                       text="'some string'"
+                       list=[ 2, 3, 4]
+               [/ai_vars]
+        [/unit]
+        [unit]
+            x,y=16,23
+            type="Orcish Archer"
+            generate_description=yes
+               formula="move(me.loc, loc(me.loc.x, me.loc.y - 1))"
+               [ai_vars]
+                       number=2
+                       text="'some string'"
+                       list=[ 2, 3, 4]
+               [/ai_vars]
+        [/unit]
         ai_algorithm=formula_ai
         [ai]
             [function]

Modified: trunk/src/callable_objects.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/callable_objects.cpp?rev=24923&r1=24922&r2=24923&view=diff
==============================================================================
--- trunk/src/callable_objects.cpp (original)
+++ trunk/src/callable_objects.cpp Fri Mar 21 05:00:25 2008
@@ -105,6 +105,8 @@
                return variant(side_ == u_.side());
        } else if(key == "value") {
                return variant(u_.cost());
+       } else if(key == "vars") {
+               return variant(u_.formula_vars());
        } else {
                return variant();
        }

Modified: trunk/src/formula_ai.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/formula_ai.cpp?rev=24923&r1=24922&r2=24923&view=diff
==============================================================================
--- trunk/src/formula_ai.cpp (original)
+++ trunk/src/formula_ai.cpp Fri Mar 21 05:00:25 2008
@@ -549,7 +549,21 @@
        recruit_formula_ = 
game_logic::formula::create_optional_formula(current_team().ai_parameters()["recruit"],
 &function_table);
        move_formula_ = 
game_logic::formula::create_optional_formula(current_team().ai_parameters()["move"],
 &function_table);
 
-       while(make_move()) {
+       //execute units formulas first
+       for(unit_map::const_iterator i = units_.begin(); i != units_.end(); 
++i) {
+               if( (i->second.side() == get_info().team_num) && 
i->second.has_formula()) 
+               {
+                       game_logic::const_formula_ptr formula(new 
game_logic::formula(i->second.get_formula(), &function_table));
+                       game_logic::map_formula_callable callable(this);
+                       callable.add_ref();
+                       callable.add("me", variant(new unit_callable(*i, 
current_team(), get_info().team_num)));
+                       make_move(formula, callable);
+               }
+       }
+
+       game_logic::map_formula_callable callable(this);
+       callable.add_ref();
+       while(make_move(move_formula_,callable)) {
        }
 }
 
@@ -611,16 +625,17 @@
        move_maps_valid_ = true;
 }
 
-bool formula_ai::make_move()
-{
-       if(!move_formula_) {
+bool formula_ai::make_move(game_logic::const_formula_ptr formula_, const 
game_logic::formula_callable& variables)
+{
+       if(!formula_) {
                return false;
        }
 
        move_maps_valid_ = false;
 
        std::cerr << "do move...\n";
-       const variant var = move_formula_->execute(*this);
+       const variant var = formula_->execute(variables);
+       //const variant var = formula_->execute(*this);
        std::vector<variant> vars;
        if(var.is_list()) {
                for(int n = 0; n != var.num_elements(); ++n) {

Modified: trunk/src/formula_ai.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/formula_ai.hpp?rev=24923&r1=24922&r2=24923&view=diff
==============================================================================
--- trunk/src/formula_ai.hpp (original)
+++ trunk/src/formula_ai.hpp Fri Mar 21 05:00:25 2008
@@ -44,7 +44,7 @@
 
 private:
        void do_recruitment();
-       bool make_move();
+       bool make_move(game_logic::const_formula_ptr formula_, const 
game_logic::formula_callable& variables);
        virtual variant get_value(const std::string& key) const;
        virtual void get_inputs(std::vector<game_logic::formula_input>* 
inputs) const;
        game_logic::const_formula_ptr recruit_formula_;

Modified: trunk/src/formula_callable.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/formula_callable.hpp?rev=24923&r1=24922&r2=24923&view=diff
==============================================================================
--- trunk/src/formula_callable.hpp (original)
+++ trunk/src/formula_callable.hpp Fri Mar 21 05:00:25 2008
@@ -106,11 +106,21 @@
        {}
 };
 
+
+
 class map_formula_callable : public formula_callable {
 public:
        explicit map_formula_callable(const formula_callable* fallback=NULL);
        map_formula_callable& add(const std::string& key, const variant& 
value);
        void set_fallback(const formula_callable* fallback) { fallback_ = 
fallback; }
+       bool empty() const { return values_.empty(); }
+       void clear() { values_.clear(); }
+
+       typedef std::map<std::string,variant>::const_iterator const_iterator;
+
+       const_iterator begin() const { return values_.begin(); }
+       const_iterator end() const { return values_.end(); }
+
 private:
        variant get_value(const std::string& key) const;
        void get_inputs(std::vector<formula_input>* inputs) const;

Modified: trunk/src/unit.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/unit.cpp?rev=24923&r1=24922&r2=24923&view=diff
==============================================================================
--- trunk/src/unit.cpp (original)
+++ trunk/src/unit.cpp Fri Mar 21 05:00:25 2008
@@ -114,6 +114,9 @@
            gender_(o.gender_),
 
            alpha_(o.alpha_),
+
+           unit_formula_(o.unit_formula_),
+           formula_vars_(o.formula_vars_),
 
            recruits_(o.recruits_),
 
@@ -1316,6 +1319,24 @@
                cfg_["profile"] = cfg["profile"];
        }
 
+       //support for unit formulas and unit-specyfic variables in [ai_vars]
+       unit_formula_ = cfg["formula"];
+
+       const config* ai_vars = cfg.child("ai_vars");
+       if (ai_vars)
+       {               
+               formula_vars_.clear();
+               
+               variant var;
+               for(string_map::const_iterator i = ai_vars->values.begin(); i 
!= ai_vars->values.end(); ++i) 
+               { 
+                       var.serialize_from_string(i->second);
+                       formula_vars_.add(i->first, var);
+               }
+       }       
+       //remove ai_vars from private cfg 
+       cfg_.clear_children("ai_vars");
+
        std::map<std::string,unit_type>::const_iterator uti = 
gamedata_->unit_types.find(cfg["type"]);
        const unit_type* ut = NULL;
 
@@ -1483,6 +1504,29 @@
        cfg["side"] = sd.str();
 
        cfg["type"] = type_id();
+
+       //support for unit formulas and unit-specyfic variables in [ai_vars]
+       if (has_formula())
+               cfg["formula"] = unit_formula_;
+
+
+       if (!formula_vars_.empty())
+       {
+               cfg.add_child("ai_vars");
+               config* ai_vars = cfg.child("ai_vars");
+
+               std::string str;
+               for(game_logic::map_formula_callable::const_iterator i = 
formula_vars_.begin(); i != formula_vars_.end(); ++i) 
+               { 
+                       i->second.serialize_to_string(str);
+                       if (!str.empty())
+                       {
+                               (*ai_vars)[i->first] = str;
+                               str.clear();
+                       }
+               }
+       }
+
 
        cfg["gender"] = gender_string(gender_);
 

Modified: trunk/src/unit.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/unit.hpp?rev=24923&r1=24922&r2=24923&view=diff
==============================================================================
--- trunk/src/unit.hpp (original)
+++ trunk/src/unit.hpp Fri Mar 21 05:00:25 2008
@@ -24,6 +24,7 @@
 #include "team.hpp"
 #include "unit_types.hpp"
 #include "unit_map.hpp"
+#include "formula_callable.hpp"
 
 class game_display;
 class gamestatus;
@@ -258,6 +259,10 @@
        bool has_ability_type(const std::string& ability) const;
        bool abilities_affects_adjacent() const;
 
+       const game_logic::map_formula_callable* formula_vars() const { return 
&formula_vars_; }
+       bool has_formula() const { return !unit_formula_.empty(); }
+       const std::string& get_formula() const { return unit_formula_; }
+
        void reset_modifications();
        void backup_state();
        void apply_modifications();
@@ -323,6 +328,9 @@
        unit_race::GENDER gender_;
 
        fixed_t alpha_;
+
+       std::string unit_formula_;
+       game_logic::map_formula_callable formula_vars_;
 
        std::vector<std::string> recruits_;
 

Modified: trunk/src/wesconfig.h
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/wesconfig.h?rev=24923&r1=24922&r2=24923&view=diff
==============================================================================
--- trunk/src/wesconfig.h (original)
+++ trunk/src/wesconfig.h Fri Mar 21 05:00:25 2008
@@ -1,4 +1,3 @@
-
 #ifndef WESCONFIG_H_INCLUDED
 #define WESCONFIG_H_INCLUDED
 
@@ -6,14 +5,14 @@
 //! Some defines: VERSION, PACKAGE, MIN_SAVEGAME_VERSION
 //!
 //! DO NOT MODIFY THIS FILE !!!
-//! modify SConstruct otherwise the settings will be overwritten.
+//! modify configure.ac otherwise the settings will be overwritten.
 
 
 
 #ifdef HAVE_CONFIG_H
 # include "config.h"
 #else
-# define VERSION "1.3.14+svn"
+# define VERSION "1.5.0-svn"
 # define PACKAGE "wesnoth"
 # ifndef LOCALEDIR
 #  define LOCALEDIR "translations"
@@ -21,7 +20,7 @@
 #endif
 
 /**
- * Some older savegames of Wesnoth cannot be loaded anymore,
+ * Some older savegames of Wesnoth can't be loaded anymore,
  * this variable defines the minimum required version.
  * It is only to be updated upon changes that break *all* saves/replays
  * (break as in crash wesnoth, not compatibility issues like stat changes)




Related Messages


Powered by MHonArc, Updated Fri Mar 21 06:01:36 2008