Author: silene
Date: Sun Apr 19 20:54:11 2009
New Revision: 35063

URL: http://svn.gna.org/viewcvs/wesnoth?rev=35063&view=rev
Log:
Stored gold and income as integers. Clarified naming of team interface.

Modified:
    trunk/src/game_events.cpp
    trunk/src/scripting/lua.cpp
    trunk/src/team.cpp
    trunk/src/team.hpp
    trunk/src/unit.cpp

Modified: trunk/src/game_events.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/game_events.cpp?rev=35063&r1=35062&r2=35063&view=diff
==============================================================================
--- trunk/src/game_events.cpp (original)
+++ trunk/src/game_events.cpp Sun Apr 19 20:54:11 2009
@@ -889,7 +889,7 @@
                        }
                        // Modify income
                        if(!income.empty()) {
-                               
(*teams)[team_index].set_income(lexical_cast_default<int>(income));
+                               
(*teams)[team_index].set_base_income(lexical_cast_default<int>(income) + 
game_config::base_income);
                        }
                        // Modify total gold
                        if(!gold.empty()) {
@@ -962,8 +962,8 @@
                                state_of_game->get_variable(var_name+".shroud") 
= side_data["shroud"];
                                state_of_game->get_variable(var_name+".hidden") 
= side_data["hidden"];
 
-                               state_of_game->get_variable(var_name+".income") 
= lexical_cast_default<std::string>((*teams)[team_index].income(),"");
-                               
state_of_game->get_variable(var_name+".village_gold") = 
lexical_cast_default<std::string>((*teams)[team_index].village_gold(),"");
+                               state_of_game->get_variable(var_name+".income") 
= str_cast((*teams)[team_index].total_income());
+                               
state_of_game->get_variable(var_name+".village_gold") = 
str_cast((*teams)[team_index].village_gold());
                                state_of_game->get_variable(var_name+".name") = 
(*teams)[team_index].name();
                                
state_of_game->get_variable(var_name+".team_name") = 
(*teams)[team_index].team_name();
                                
state_of_game->get_variable(var_name+".user_team_name") = 
(*teams)[team_index].user_team_name();

Modified: trunk/src/scripting/lua.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/scripting/lua.cpp?rev=35063&r1=35062&r2=35063&view=diff
==============================================================================
--- trunk/src/scripting/lua.cpp (original)
+++ trunk/src/scripting/lua.cpp Sun Apr 19 20:54:11 2009
@@ -632,7 +632,8 @@
        return_int_attrib("gold", t.gold());
        return_tstring_attrib("objectives", t.objectives());
        return_int_attrib("village_gold", t.village_gold());
-       return_int_attrib("income", t.income());
+       return_int_attrib("base_income", t.base_income());
+       return_int_attrib("total_income", t.total_income());
        return_bool_attrib("objectives_changed", t.objectives_changed());
        return 0;
 }

Modified: trunk/src/team.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/team.cpp?rev=35063&r1=35062&r2=35063&view=diff
==============================================================================
--- trunk/src/team.cpp (original)
+++ trunk/src/team.cpp Sun Apr 19 20:54:11 2009
@@ -78,10 +78,10 @@
 
 team::team_info::team_info(const config& cfg) :
                name(cfg["name"]),
-               gold(cfg["gold"]),
-               start_gold(),
-               income(cfg["income"]),
-               income_per_village(),
+               gold(lexical_cast_default<int>(cfg["gold"])),
+               start_gold(0),
+               income(lexical_cast_default<int>(cfg["income"])),
+               income_per_village(0),
                average_price(0),
                number_of_possible_recruits_to_force_recruit(),
                can_recruit(),
@@ -174,11 +174,11 @@
        // at the start of a scenario "start_gold" is not set, we need to take 
the
        // value from the gold setting (or fall back to the gold default)
        if (!cfg["start_gold"].empty())
-               start_gold = cfg["start_gold"];
-       else if (!this->gold.empty())
-               start_gold = this->gold;
+               start_gold = lexical_cast_default<int>(cfg["start_gold"]);
+       else if (!cfg["gold"].empty())
+               start_gold = gold;
        else
-               start_gold = str_cast(default_team_gold);
+               start_gold = default_team_gold;
 
        if(team_name.empty()) {
                team_name = cfg["side"];
@@ -254,9 +254,9 @@
        if(!ai_memory_.empty()) cfg.add_child("ai_memory", ai_memory_ );
        cfg["ai_algorithm"] = 
ai_manager::get_active_ai_algorithm_type_for_side(side);
 
-       cfg["gold"] = gold;
-       cfg["start_gold"] = start_gold;
-       cfg["income"] = income;
+       cfg["gold"] = str_cast(gold);
+       cfg["start_gold"] = str_cast(start_gold);
+       cfg["income"] = str_cast(income);
        cfg["name"] = name;
        cfg["team_name"] = team_name;
        cfg["user_team_name"] = user_team_name;
@@ -374,12 +374,12 @@
 
        // To ensure some mimimum starting gold,
        // gold is the maximum of 'gold' and what is given in the config file
-       if(info_.gold.empty() == false)
-       {
-               gold_ = std::max(gold,::atoi(info_.gold.c_str()));
-               if (gold_ != ::atoi(info_.gold.c_str()))
-                       info_.start_gold = str_cast(gold) + " (" + 
info_.start_gold + ")";
-       }
+       gold_ = std::max(gold, info_.gold);
+       if (gold_ != info_.gold)
+               info_.start_gold = gold;
+       // Old code was doing:
+       // info_.start_gold = str_cast(gold) + " (" + info_.start_gold + ")";
+       // Was it correct?
 
        // Load in the villages the side controls at the start
        foreach (const config &v, cfg.child_range("village"))

Modified: trunk/src/team.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/team.hpp?rev=35063&r1=35062&r2=35063&view=diff
==============================================================================
--- trunk/src/team.hpp (original)
+++ trunk/src/team.hpp Sun Apr 19 20:54:11 2009
@@ -70,9 +70,9 @@
                team_info(const config& cfg);
                void write(config& cfg) const;
                std::string name;
-               std::string gold;
-               std::string start_gold;
-               std::string income;
+               int gold;
+               int start_gold;
+               int income;
                int income_per_village;
                size_t average_price;
                float number_of_possible_recruits_to_force_recruit;
@@ -139,20 +139,17 @@
                { return villages_.count(loc) > 0; }
 
        int gold() const { return gold_; }
-       std::string start_gold() const { return info_.start_gold; }
-       int base_income() const
-               { return atoi(info_.income.c_str()) + game_config::base_income; 
}
+       int start_gold() const { return info_.start_gold; }
+       int base_income() const { return info_.income + 
game_config::base_income; }
        int village_gold() const { return info_.income_per_village; }
        void set_village_gold(int income) { info_.income_per_village = income; }
-       int income() const
-               { return atoi(info_.income.c_str()) + 
villages_.size()*info_.income_per_village+game_config::base_income; }
-       void new_turn() { gold_ += income(); }
+       int total_income() const { return base_income() + villages_.size() * 
info_.income_per_village; }
+       void new_turn() { gold_ += total_income(); }
        void set_time_of_day(int turn, const struct time_of_day& tod);
        void get_shared_maps();
        void set_gold(int amount) { gold_ = amount; }
        void spend_gold(const int amount) { gold_ -= amount; }
-       void set_income(const int amount)
-               { info_.income = lexical_cast<std::string>(amount); }
+       void set_base_income(int amount) { info_.income = amount - 
game_config::base_income; }
        int countdown_time() const {  return countdown_time_; }
        void set_countdown_time(const int amount)
                { countdown_time_ = amount; }

Modified: trunk/src/unit.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/unit.cpp?rev=35063&r1=35062&r2=35063&view=diff
==============================================================================
--- trunk/src/unit.cpp (original)
+++ trunk/src/unit.cpp Sun Apr 19 20:54:11 2009
@@ -3047,7 +3047,7 @@
        res.upkeep = team_upkeep(units,side);
        res.villages = tm.villages().size();
        res.expenses = std::max<int>(0,res.upkeep - res.villages);
-       res.net_income = tm.income() - res.expenses;
+       res.net_income = tm.total_income() - res.expenses;
        res.gold = tm.gold();
        res.teamname = tm.user_team_name();
        return res;


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

Reply via email to