Skip to content

Commit

Permalink
do not write unchanged unit attributes
Browse files Browse the repository at this point in the history
This should make savefiles smaller. Note that this does not effect all
games since some wml codes will disable this optimisation.
  • Loading branch information
gfgtdf committed Nov 10, 2018
1 parent 3c63b1e commit 66a282a
Show file tree
Hide file tree
Showing 5 changed files with 212 additions and 68 deletions.
2 changes: 1 addition & 1 deletion src/game_board.cpp
Expand Up @@ -341,7 +341,7 @@ void game_board::write_config(config & cfg) const
if(i.side() == side_num) {
config& u = side.add_child("unit");
i.get_location().write(u);
i.write(u);
i.write(u, false);
}
}
//recall list
Expand Down
4 changes: 3 additions & 1 deletion src/units/attack_type.cpp
Expand Up @@ -60,7 +60,8 @@ attack_type::attack_type(const config& cfg) :
accuracy_(cfg["accuracy"]),
movement_used_(cfg["movement_used"].to_int(100000)),
parry_(cfg["parry"]),
specials_(cfg.child_or_empty("specials"))
specials_(cfg.child_or_empty("specials")),
changed_(true)
{
if (description_.empty())
description_ = translation::egettext(id_.c_str());
Expand Down Expand Up @@ -213,6 +214,7 @@ bool attack_type::apply_modification(const config& cfg)
if( !matches_filter(cfg) )
return false;

set_changed(true);
const std::string& set_name = cfg["set_name"];
const t_string& set_desc = cfg["set_description"];
const std::string& set_type = cfg["set_type"];
Expand Down
33 changes: 21 additions & 12 deletions src/units/attack_type.hpp
Expand Up @@ -53,18 +53,18 @@ class attack_type : public std::enable_shared_from_this<attack_type>
double defense_weight() const { return defense_weight_; }
const config &specials() const { return specials_; }

void set_name(const t_string& value) { description_ = value; }
void set_id(const std::string& value) { id_ = value; }
void set_type(const std::string& value) { type_ = value; }
void set_icon(const std::string& value) { icon_ = value; }
void set_range(const std::string& value) { range_ = value; }
void set_accuracy(int value) { accuracy_ = value; }
void set_parry(int value) { parry_ = value; }
void set_damage(int value) { damage_ = value; }
void set_num_attacks(int value) { num_attacks_ = value; }
void set_attack_weight(double value) { attack_weight_ = value; }
void set_defense_weight(double value) { defense_weight_ = value; }
void set_specials(config value) { specials_ = value; }
void set_name(const t_string& value) { description_ = value; set_changed(true); }
void set_id(const std::string& value) { id_ = value; set_changed(true); }
void set_type(const std::string& value) { type_ = value; set_changed(true); }
void set_icon(const std::string& value) { icon_ = value; set_changed(true); }
void set_range(const std::string& value) { range_ = value; set_changed(true); }
void set_accuracy(int value) { accuracy_ = value; set_changed(true); }
void set_parry(int value) { parry_ = value; set_changed(true); }
void set_damage(int value) { damage_ = value; set_changed(true); }
void set_num_attacks(int value) { num_attacks_ = value; set_changed(true); }
void set_attack_weight(double value) { attack_weight_ = value; set_changed(true); }
void set_defense_weight(double value) { defense_weight_ = value; set_changed(true); }
void set_specials(config value) { specials_ = value; set_changed(true); }

// In action/attack.cpp
std::pair<int, bool> combat_ability(const std::string& ability, int abil_value = 0, bool backstab_pos = false) const;
Expand Down Expand Up @@ -151,6 +151,14 @@ class attack_type : public std::enable_shared_from_this<attack_type>
specials_context_t specials_context_for_listing(bool attacking = true) const {
return specials_context_t(*this, attacking);
}
void set_changed(bool value)
{
changed_ = value;
}
bool get_changed() const
{
return changed_;
}
private:

t_string description_;
Expand All @@ -168,6 +176,7 @@ class attack_type : public std::enable_shared_from_this<attack_type>
int movement_used_;
int parry_;
config specials_;
bool changed_;
};

using attack_list = std::vector<attack_ptr>;
Expand Down

0 comments on commit 66a282a

Please sign in to comment.