Add single unit instance recall_costs
Add the variables, lua, and wml support variables to allow a scenario designer the ability to define different from the standard recall costs or team recall costs for both individual units and unit types. from least to highest order of precendent we'll have default, team/side, unit_type, and finally individual units. The tag in the scenarios and in the unit config files is recall_cost=int.
This commit is contained in:
parent
0763670a3f
commit
a723d5fa59
6 changed files with 38 additions and 3 deletions
|
@ -242,6 +242,7 @@ function wml_actions.unit_worth(cfg)
|
|||
local ut = wesnoth.unit_types[u.type]
|
||||
local hp = u.hitpoints / u.max_hitpoints
|
||||
local xp = u.experience / u.max_experience
|
||||
local recall_cost = unit.recall_cost
|
||||
local best_adv = ut.cost
|
||||
for w in string.gmatch(ut.__cfg.advances_to, "[^%s,][^,]*") do
|
||||
local uta = wesnoth.unit_types[w]
|
||||
|
@ -251,6 +252,7 @@ function wml_actions.unit_worth(cfg)
|
|||
wesnoth.set_variable("next_cost", best_adv)
|
||||
wesnoth.set_variable("health", math.floor(hp * 100))
|
||||
wesnoth.set_variable("experience", math.floor(xp * 100))
|
||||
wesnoth.set_variable("recall_cost", ut.recall_cost)
|
||||
wesnoth.set_variable("unit_worth", math.floor(math.max(ut.cost * hp, best_adv * xp)))
|
||||
end
|
||||
|
||||
|
@ -1008,6 +1010,7 @@ function wml_actions.transform_unit(cfg)
|
|||
else
|
||||
local hitpoints = unit.hitpoints
|
||||
local experience = unit.experience
|
||||
local recall_cost = unit.recall_cost
|
||||
local status = helper.get_child( unit.__cfg, "status" )
|
||||
|
||||
unit.experience = unit.max_experience
|
||||
|
@ -1017,6 +1020,7 @@ function wml_actions.transform_unit(cfg)
|
|||
|
||||
unit.hitpoints = hitpoints
|
||||
unit.experience = experience
|
||||
recall_cost = unit.recall_cost
|
||||
|
||||
for key, value in pairs(status) do unit.status[key] = value end
|
||||
if unit.status.unpoisonable then unit.status.poisoned = nil end
|
||||
|
|
|
@ -465,6 +465,7 @@ static int impl_unit_type_get(lua_State *L)
|
|||
return_int_attrib("max_experience", ut.experience_needed());
|
||||
return_int_attrib("cost", ut.cost());
|
||||
return_int_attrib("level", ut.level());
|
||||
return_int_attrib("recall_cost", ut.recall_cost());
|
||||
return_cfgref_attrib("__cfg", ut.get_cfg());
|
||||
return 0;
|
||||
}
|
||||
|
@ -560,6 +561,7 @@ static int impl_unit_get(lua_State *L)
|
|||
return_int_attrib("max_hitpoints", u.max_hitpoints());
|
||||
return_int_attrib("experience", u.experience());
|
||||
return_int_attrib("max_experience", u.max_experience());
|
||||
return_int_attrib("recall_cost", u.recall_cost());
|
||||
return_int_attrib("moves", u.movement_left());
|
||||
return_int_attrib("max_moves", u.total_movement());
|
||||
return_int_attrib("max_attacks", u.max_attacks());
|
||||
|
@ -618,6 +620,7 @@ static int impl_unit_set(lua_State *L)
|
|||
modify_int_attrib("moves", u.set_movement(value));
|
||||
modify_int_attrib("hitpoints", u.set_hitpoints(value));
|
||||
modify_int_attrib("experience", u.set_experience(value));
|
||||
modify_int_attrib("recall_cost", u.set_recall_cost(value));
|
||||
modify_int_attrib("attacks_left", u.set_attacks(value));
|
||||
modify_bool_attrib("resting", u.set_resting(value));
|
||||
modify_tstring_attrib("name", u.set_name(value));
|
||||
|
|
25
src/unit.cpp
25
src/unit.cpp
|
@ -136,6 +136,7 @@ unit::unit(const unit& o):
|
|||
experience_(o.experience_),
|
||||
max_experience_(o.max_experience_),
|
||||
level_(o.level_),
|
||||
recall_cost_(o.recall_cost_),
|
||||
canrecruit_(o.canrecruit_),
|
||||
recruit_list_(o.recruit_list_),
|
||||
alignment_(o.alignment_),
|
||||
|
@ -224,6 +225,7 @@ unit::unit(const config &cfg, bool use_traits, const vconfig* vcfg) :
|
|||
experience_(0),
|
||||
max_experience_(0),
|
||||
level_(0),
|
||||
recall_cost_(cfg["recall_cost"].to_int(-1)),
|
||||
canrecruit_(cfg["canrecruit"].to_bool()),
|
||||
recruit_list_(),
|
||||
alignment_(),
|
||||
|
@ -354,6 +356,12 @@ unit::unit(const config &cfg, bool use_traits, const vconfig* vcfg) :
|
|||
if (const config::attribute_value *v = cfg.get("description")) {
|
||||
cfg_["description"] = *v;
|
||||
}
|
||||
if (const config::attribute_value *v = cfg.get("recall_cost")) {
|
||||
recall_cost_ = *v;
|
||||
}
|
||||
else {
|
||||
recall_cost_ = type_->recall_cost();
|
||||
}
|
||||
if (const config::attribute_value *v = cfg.get("cost")) {
|
||||
unit_value_ = *v;
|
||||
}
|
||||
|
@ -462,6 +470,16 @@ unit::unit(const config &cfg, bool use_traits, const vconfig* vcfg) :
|
|||
resting_ = cfg["resting"].to_bool();
|
||||
unrenamable_ = cfg["unrenamable"].to_bool();
|
||||
|
||||
/* We need to check to make sure that the cfg is not blank and if it
|
||||
is and the unit_type gives a default of 0 then treat as if the unit's
|
||||
type had a value of -1 so it will use the team recall cost. */
|
||||
if(cfg["recall_cost"] > 0) {
|
||||
recall_cost_ = cfg["recall_cost"].to_int(-1);
|
||||
}
|
||||
|
||||
if(cfg["recall_cost"] > 0) {
|
||||
recall_cost_ = cfg["recall_cost"];
|
||||
}
|
||||
const std::string& align = cfg["alignment"];
|
||||
if(align == "lawful") {
|
||||
alignment_ = unit_type::LAWFUL;
|
||||
|
@ -492,7 +510,7 @@ unit::unit(const config &cfg, bool use_traits, const vconfig* vcfg) :
|
|||
static char const *internalized_attrs[] = { "type", "id", "name",
|
||||
"gender", "random_gender", "variation", "role", "ai_special",
|
||||
"side", "underlying_id", "overlays", "facing", "race",
|
||||
"level", "undead_variation", "max_attacks",
|
||||
"level", "recall_cost", "undead_variation", "max_attacks",
|
||||
"attacks_left", "alpha", "zoc", "flying", "cost",
|
||||
"max_hitpoints", "max_moves", "vision", "jamming", "max_experience",
|
||||
"advances_to", "hitpoints", "goto_x", "goto_y", "moves",
|
||||
|
@ -552,6 +570,7 @@ unit::unit(const unit_type &u_type, int side, bool real_unit,
|
|||
experience_(0),
|
||||
max_experience_(0),
|
||||
level_(0),
|
||||
recall_cost_(-1),
|
||||
canrecruit_(false),
|
||||
recruit_list_(),
|
||||
alignment_(),
|
||||
|
@ -1663,7 +1682,8 @@ void unit::write(config& cfg) const
|
|||
|
||||
cfg["experience"] = experience_;
|
||||
cfg["max_experience"] = max_experience_;
|
||||
|
||||
cfg["recall_cost"] = recall_cost_;
|
||||
|
||||
cfg["side"] = side_;
|
||||
|
||||
cfg["type"] = type_id();
|
||||
|
@ -3217,6 +3237,7 @@ std::string get_checksum(const unit& u) {
|
|||
"ignore_race_traits",
|
||||
"ignore_global_traits",
|
||||
"level",
|
||||
"recall_cost",
|
||||
"max_attacks",
|
||||
"max_experience",
|
||||
"max_hitpoints",
|
||||
|
|
|
@ -147,7 +147,9 @@ public:
|
|||
int experience() const { return experience_; }
|
||||
int max_experience() const { return max_experience_; }
|
||||
void set_experience(int xp) { experience_ = xp; }
|
||||
void set_recall_cost(int recall_cost) { recall_cost_ = recall_cost; }
|
||||
int level() const { return level_; }
|
||||
int recall_cost() const { return recall_cost_; }
|
||||
void remove_movement_ai();
|
||||
void remove_attacks_ai();
|
||||
|
||||
|
@ -450,6 +452,7 @@ private:
|
|||
int experience_;
|
||||
int max_experience_;
|
||||
int level_;
|
||||
int recall_cost_;
|
||||
bool canrecruit_;
|
||||
std::vector<std::string> recruit_list_;
|
||||
unit_type::ALIGNMENT alignment_;
|
||||
|
|
|
@ -416,6 +416,7 @@ unit_type::unit_type(const config &cfg, const std::string & parent_id) :
|
|||
hp_bar_scaling_(0.0),
|
||||
xp_bar_scaling_(0.0),
|
||||
level_(0),
|
||||
recall_cost_(),
|
||||
movement_(0),
|
||||
vision_(-1),
|
||||
jamming_(0),
|
||||
|
@ -567,6 +568,7 @@ void unit_type::build_help_index(const movement_type_map &mv_types,
|
|||
description_ = cfg_["description"];
|
||||
hitpoints_ = cfg_["hitpoints"].to_int(1);
|
||||
level_ = cfg_["level"];
|
||||
recall_cost_ = cfg_["recall_cost"].to_int(-1);
|
||||
movement_ = cfg_["movement"].to_int(1);
|
||||
vision_ = cfg_["vision"].to_int(-1);
|
||||
jamming_ = cfg_["jamming"].to_int(0);
|
||||
|
@ -1069,7 +1071,7 @@ const config & unit_type::build_unit_cfg() const
|
|||
static char const *unit_type_attrs[] = { "attacks", "base_ids", "die_sound",
|
||||
"experience", "flies", "healed_sound", "hide_help", "hitpoints",
|
||||
"id", "ignore_race_traits", "inherit", "movement", "movement_type",
|
||||
"name", "num_traits", "variation_id", "variation_name" };
|
||||
"name", "num_traits", "variation_id", "variation_name", "recall_cost" };
|
||||
BOOST_FOREACH(const char *attr, unit_type_attrs) {
|
||||
unit_cfg_.remove_attribute(attr);
|
||||
}
|
||||
|
|
|
@ -189,6 +189,7 @@ public:
|
|||
double hp_bar_scaling() const { return hp_bar_scaling_; }
|
||||
double xp_bar_scaling() const { return xp_bar_scaling_; }
|
||||
int level() const { return level_; }
|
||||
int recall_cost() const { return recall_cost_;}
|
||||
int movement() const { return movement_; }
|
||||
int vision() const { return vision_ < 0 ? movement() : vision_; }
|
||||
/// If @a base_value is set to true, do not fall back to movement().
|
||||
|
@ -301,6 +302,7 @@ private:
|
|||
int hitpoints_;
|
||||
double hp_bar_scaling_, xp_bar_scaling_;
|
||||
int level_;
|
||||
int recall_cost_;
|
||||
int movement_;
|
||||
int vision_;
|
||||
int jamming_;
|
||||
|
|
Loading…
Add table
Reference in a new issue