Units/Attack Type: moved the specials_context_t ctors to the more relevant file

This commit is contained in:
Charles Dang 2018-04-24 15:01:28 +11:00
parent a1c440510c
commit 1749de1521
2 changed files with 96 additions and 96 deletions

View file

@ -772,102 +772,6 @@ std::string attack_type::weapon_specials(bool only_active, bool is_backstab) con
return res;
}
/**
* Sets the context under which specials will be checked for being active.
* This version is appropriate if both units in a combat are known.
* @param[in] self A reference to the unit with this weapon.
* @param[in] other A reference to the other unit in the combat.
* @param[in] unit_loc The location of the unit with this weapon.
* @param[in] other_loc The location of the other unit in the combat.
* @param[in] attacking Whether or not the unit with this weapon is the attacker.
* @param[in] other_attack The attack used by the other unit.
*/
attack_type::specials_context_t::specials_context_t(const attack_type& weapon,
const_attack_ptr other_attack,
unit_const_ptr self,
unit_const_ptr other,
const map_location& unit_loc,
const map_location& other_loc,
bool attacking)
: parent(weapon.shared_from_this())
{
weapon.self_ = self;
weapon.other_ = other;
weapon.self_loc_ = unit_loc;
weapon.other_loc_ = other_loc;
weapon.is_attacker_ = attacking;
weapon.other_attack_ = other_attack;
weapon.is_for_listing_ = false;
}
/**
* Sets the context under which specials will be checked for being active.
* This version is appropriate if there is no specific combat being considered.
* @param[in] self A reference to the unit with this weapon.
* @param[in] loc The location of the unit with this weapon.
* @param[in] attacking Whether or not the unit with this weapon is the attacker.
*/
attack_type::specials_context_t::specials_context_t(
const attack_type& weapon, unit_const_ptr self, const map_location& loc, bool attacking)
: parent(weapon.shared_from_this())
{
weapon.self_ = self;
weapon.other_ = nullptr;
weapon.self_loc_ = loc;
weapon.other_loc_ = map_location::null_location();
weapon.is_attacker_ = attacking;
weapon.other_attack_ = nullptr;
weapon.is_for_listing_ = false;
}
/**
* Sets the context under which specials will be checked for being active.
* This version is appropriate for theoretical units of a particular type.
* @param[in] self_type A reference to the type of the unit with this weapon.
* @param[in] loc The location of the unit with this weapon.
* @param[in] attacking Whether or not the unit with this weapon is the attacker.
*/
attack_type::specials_context_t::specials_context_t(
const attack_type& weapon, const unit_type& self_type, const map_location& loc, bool attacking)
: parent(weapon.shared_from_this())
{
UNUSED(self_type);
weapon.self_ = nullptr;
weapon.other_ = nullptr;
weapon.self_loc_ = loc;
weapon.other_loc_ = map_location::null_location();
weapon.is_attacker_ = attacking;
weapon.other_attack_ = nullptr;
weapon.is_for_listing_ = false;
}
attack_type::specials_context_t::specials_context_t(const attack_type& weapon)
: parent(weapon.shared_from_this())
{
weapon.is_for_listing_ = true;
}
attack_type::specials_context_t::~specials_context_t()
{
if(was_moved) {
return;
}
parent->self_ = nullptr;
parent->other_ = nullptr;
parent->self_loc_ = map_location::null_location();
parent->other_loc_ = map_location::null_location();
parent->is_attacker_ = false;
parent->other_attack_ = nullptr;
parent->is_for_listing_ = false;
}
attack_type::specials_context_t::specials_context_t(attack_type::specials_context_t&& other)
: parent(other.parent)
{
other.was_moved = true;
}
/**
* Calculates the number of attacks this weapon has, considering specials.
* This returns two numbers because of the swarm special. The actual number of

View file

@ -491,3 +491,99 @@ void attack_type::write(config& cfg) const
cfg["parry"] = parry_;
cfg.add_child("specials", specials_);
}
/**
* Sets the context under which specials will be checked for being active.
* This version is appropriate if both units in a combat are known.
* @param[in] self A reference to the unit with this weapon.
* @param[in] other A reference to the other unit in the combat.
* @param[in] unit_loc The location of the unit with this weapon.
* @param[in] other_loc The location of the other unit in the combat.
* @param[in] attacking Whether or not the unit with this weapon is the attacker.
* @param[in] other_attack The attack used by the other unit.
*/
attack_type::specials_context_t::specials_context_t(const attack_type& weapon,
const_attack_ptr other_attack,
unit_const_ptr self,
unit_const_ptr other,
const map_location& unit_loc,
const map_location& other_loc,
bool attacking)
: parent(weapon.shared_from_this())
{
weapon.self_ = self;
weapon.other_ = other;
weapon.self_loc_ = unit_loc;
weapon.other_loc_ = other_loc;
weapon.is_attacker_ = attacking;
weapon.other_attack_ = other_attack;
weapon.is_for_listing_ = false;
}
/**
* Sets the context under which specials will be checked for being active.
* This version is appropriate if there is no specific combat being considered.
* @param[in] self A reference to the unit with this weapon.
* @param[in] loc The location of the unit with this weapon.
* @param[in] attacking Whether or not the unit with this weapon is the attacker.
*/
attack_type::specials_context_t::specials_context_t(
const attack_type& weapon, unit_const_ptr self, const map_location& loc, bool attacking)
: parent(weapon.shared_from_this())
{
weapon.self_ = self;
weapon.other_ = nullptr;
weapon.self_loc_ = loc;
weapon.other_loc_ = map_location::null_location();
weapon.is_attacker_ = attacking;
weapon.other_attack_ = nullptr;
weapon.is_for_listing_ = false;
}
/**
* Sets the context under which specials will be checked for being active.
* This version is appropriate for theoretical units of a particular type.
* @param[in] self_type A reference to the type of the unit with this weapon.
* @param[in] loc The location of the unit with this weapon.
* @param[in] attacking Whether or not the unit with this weapon is the attacker.
*/
attack_type::specials_context_t::specials_context_t(
const attack_type& weapon, const unit_type& self_type, const map_location& loc, bool attacking)
: parent(weapon.shared_from_this())
{
UNUSED(self_type);
weapon.self_ = nullptr;
weapon.other_ = nullptr;
weapon.self_loc_ = loc;
weapon.other_loc_ = map_location::null_location();
weapon.is_attacker_ = attacking;
weapon.other_attack_ = nullptr;
weapon.is_for_listing_ = false;
}
attack_type::specials_context_t::specials_context_t(const attack_type& weapon)
: parent(weapon.shared_from_this())
{
weapon.is_for_listing_ = true;
}
attack_type::specials_context_t::~specials_context_t()
{
if(was_moved) {
return;
}
parent->self_ = nullptr;
parent->other_ = nullptr;
parent->self_loc_ = map_location::null_location();
parent->other_loc_ = map_location::null_location();
parent->is_attacker_ = false;
parent->other_attack_ = nullptr;
parent->is_for_listing_ = false;
}
attack_type::specials_context_t::specials_context_t(attack_type::specials_context_t&& other)
: parent(other.parent)
{
other.was_moved = true;
}