Implement unit instance recall costs.

Actually allows for the unit instance recall costs to be used. Proper
taking of the gold and undoing the cost for each unit is implemented
and works.  At advancement if the unit's current recall matches their
unit_type's recall_cost then it takes the new unit_type's recall_cost
otherwise it keeps whatever value it currently has until it fails this
check.  Recall costs are also now persistant and will carry over from
one scenario into the next as well.

If a cost is not set, it will continue to use the team/side/default
costs, these changes should not affect the current workings when
dealing with unaltered scenarios, and unit config files.  I repeat This
will not affect or change the currently way things work UNLESS a user
alters a file or includes the new recall_cost (as in copies and
modifies a unit in the scenario unit files) for a unit instance in
their scenario file(s).
This commit is contained in:
Aishiko 2014-03-17 17:49:15 -04:00
parent a723d5fa59
commit c6d11a5f5e
5 changed files with 38 additions and 3 deletions

View file

@ -1001,8 +1001,17 @@ bool recall_unit(const std::string & id, team & current_team,
// (Use recall.id() instead, if needed.)
// Place the recall.
bool mutated = place_recruit(recall, loc, from, current_team.recall_cost(),
// We also check to see if a custom unit level recall has been set if not,
// we use the team's recall cost otherwise the unit's.
bool mutated;
if (recall.recall_cost() < 0) {
mutated = place_recruit(recall, loc, from, current_team.recall_cost(),
true, show);
}
else {
mutated = place_recruit(recall, loc, from, recall.recall_cost(),
true, show);
}
statistics::recall_unit(recall);
// To speed things a bit, don't bother with the undo stack during

View file

@ -626,7 +626,13 @@ bool undo_list::recall_action::undo(int side, undo_list & /*undos*/)
const unit &un = *un_it;
statistics::un_recall_unit(un);
current_team.spend_gold(-current_team.recall_cost());
int cost = statistics::un_recall_unit_cost(un);
if (cost < 0) {
current_team.spend_gold(-current_team.recall_cost());
}
else {
current_team.spend_gold(-cost);
}
current_team.recall_list().push_back(un);
// invalidate before erasing allow us

View file

@ -499,6 +499,13 @@ void un_recruit_unit(const unit& u)
s.recruit_cost -= u.cost();
}
int un_recall_unit_cost(const unit& u) // this really belongs elsewhere, perhaps in undo.cpp
{ // but I'm too lazy to do it at the moment
stats& s = get_stats(u.side_id());
s.recalls[u.type_id()]--;
return u.recall_cost();
}
void advance_unit(const unit& u)
{

View file

@ -99,6 +99,7 @@ namespace statistics
void recall_unit(const unit& u);
void un_recall_unit(const unit& u);
void un_recruit_unit(const unit& u);
int un_recall_unit_cost(const unit& u);
void advance_unit(const unit& u);

View file

@ -836,6 +836,13 @@ void unit::advance_to(const config &old_cfg, const unit_type &u_type,
undead_variation_ = new_type.undead_variation();
max_experience_ = new_type.experience_needed(false);
level_ = new_type.level();
recall_cost_ = new_type.recall_cost();
/* Need to add a check to see if the unit's old cost is equal
to the unit's old unit_type cost first. If it is change the cost
otherwise keep the old cost. */
if(old_type.recall_cost() == recall_cost_) {
recall_cost_ = new_type.recall_cost();
}
alignment_ = new_type.alignment();
alpha_ = new_type.alpha();
max_hit_points_ = new_type.hitpoints();
@ -1530,7 +1537,12 @@ bool unit::internal_matches_filter(const vconfig& cfg, const map_location& loc,
if (!cfg_canrecruit.blank() && cfg_canrecruit.to_bool() != can_recruit()) {
return false;
}
config::attribute_value cfg_recall_cost = cfg["recall_cost"];
if (!cfg_recall_cost.blank() && cfg_recall_cost.to_int(-1) != recall_cost_) {
return false;
}
config::attribute_value cfg_level = cfg["level"];
if (!cfg_level.blank() && cfg_level.to_int(-1) != level_) {
return false;