Skip to content

Commit

Permalink
Add skill Sunder.
Browse files Browse the repository at this point in the history
  • Loading branch information
andor9 committed Jan 6, 2016
1 parent a6bb74a commit e66b85f
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 48 deletions.
15 changes: 9 additions & 6 deletions deck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,10 +296,9 @@ void Deck::set_given_hand(const std::string& deck_string)
given_hand = id_marks.first;
}

void Deck::set_forts(const std::string& deck_string)
void Deck::add_forts(const std::string& deck_string)
{
auto && id_marks = string_to_ids(all_cards, deck_string, "fort_cards");
fort_cards.clear();
for (auto id: id_marks.first)
{
fort_cards.push_back(all_cards.by_id(id));
Expand Down Expand Up @@ -351,6 +350,10 @@ std::string Deck::medium_description() const
{
ios << "No commander";
}
for (const Card * card: fort_cards)
{
ios << ", " << card->m_name;
}
for(const Card * card: cards)
{
ios << ", " << card->m_name;
Expand Down Expand Up @@ -385,6 +388,10 @@ std::string Deck::long_description() const
{
ios << "No commander\n";
}
for (const Card * card: fort_cards)
{
show_upgrades(ios, card, card->m_top_level_card->m_level, "");
}
for(const Card* card: cards)
{
show_upgrades(ios, card, card->m_top_level_card->m_level, " ");
Expand All @@ -401,10 +408,6 @@ std::string Deck::long_description() const
show_upgrades(ios, card, card->m_top_level_card->m_level, " ");
}
}
for (const Card * card: fort_cards)
{
show_upgrades(ios, card, card->m_top_level_card->m_level, "");
}
ios << "\n";
return ios.str();
}
Expand Down
2 changes: 1 addition & 1 deletion deck.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class Deck
void shrink(const unsigned deck_len);
void set_vip_cards(const std::string& deck_string_);
void set_given_hand(const std::string& deck_string_);
void set_forts(const std::string& deck_string_);
void add_forts(const std::string& deck_string_);

Deck* clone() const;
std::string hash() const;
Expand Down
102 changes: 64 additions & 38 deletions sim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ inline void CardStatus::set(const Card& card)
m_protected = 0;
m_rallied = 0;
m_rush_attempted = false;
m_sundered = false;
m_weakened = 0;

std::memset(m_primary_skill_offset, 0, sizeof m_primary_skill_offset);
Expand Down Expand Up @@ -210,6 +211,7 @@ std::string CardStatus::description() const
// Status w/o value
if(m_jammed) { desc += ", jammed"; }
if(m_overloaded) { desc += ", overloaded"; }
if(m_sundered) { desc += ", sundered"; }
// Status w/ value
if(m_corroded_rate > 0) { desc += ", corroded " + to_string(m_corroded_rate); }
if(m_enfeebled > 0) { desc += ", enfeebled " + to_string(m_enfeebled); }
Expand Down Expand Up @@ -274,7 +276,8 @@ void prepend_on_death(Field* fd)
if (avenge_value > 0)
{
_DEBUG_MSG(1, "%s activates Avenge %u\n", status_description(adj_status).c_str(), avenge_value);
adj_status->m_attack += avenge_value;
if (! adj_status->m_sundered)
{ adj_status->m_attack += avenge_value; }
adj_status->m_max_hp += avenge_value;
adj_status->m_hp += avenge_value;
}
Expand Down Expand Up @@ -914,6 +917,7 @@ void turn_end_phase(Field* fd)
// end of the opponent's next turn for enemy units
status.m_jammed = false;
status.m_rallied = 0;
status.m_sundered = false;
status.m_weakened = 0;
status.m_inhibited = 0;
status.m_overloaded = false;
Expand Down Expand Up @@ -1018,7 +1022,8 @@ struct PerformAttack
unsigned flux_value = (def_status->skill(counter) - 1) / flux_denominator + 1;
_DEBUG_MSG(1, "Counterflux: %s heals itself and berserks for %u\n", status_description(def_status).c_str(), flux_value);
add_hp(fd, def_status, flux_value);
def_status->m_attack += flux_value;
if (! def_status->m_sundered)
{ def_status->m_attack += flux_value; }
}
}
unsigned corrosive_value = def_status->skill(corrosive);
Expand All @@ -1029,7 +1034,7 @@ struct PerformAttack
att_status->m_corroded_rate = corrosive_value;
}
unsigned berserk_value = att_status->skill(berserk);
if (att_status->m_hp > 0 && berserk_value > 0 && skill_check<berserk>(fd, att_status, nullptr))
if (att_status->m_hp > 0 && ! att_status->m_sundered && berserk_value > 0 && skill_check<berserk>(fd, att_status, nullptr))
{
// perform_skill_berserk
att_status->m_attack += berserk_value;
Expand All @@ -1048,7 +1053,7 @@ struct PerformAttack
}
do_leech<def_cardtype>();
unsigned valor_value = att_status->skill(valor);
if (valor_value > 0 && fd->bg_effects.count(heroism) && def_cardtype == CardType::assault && def_status->m_hp <= 0)
if (valor_value > 0 && ! att_status->m_sundered && fd->bg_effects.count(heroism) && def_cardtype == CardType::assault && def_status->m_hp <= 0)
{
_DEBUG_MSG(1, "Heroism: %s gain %u attack\n", status_description(att_status).c_str(), valor_value);
att_status->m_attack += valor_value;
Expand All @@ -1063,44 +1068,48 @@ struct PerformAttack
{
assert(att_status->m_card->m_type == CardType::assault);
att_dmg = pre_modifier_dmg;
if (att_dmg == 0) { return; }
if (att_dmg == 0)
{ return; }
std::string desc;
// enhance damage
unsigned legion_value = 0;
unsigned legion_base = att_status->skill(legion);
if (legion_base > 0)
if (! att_status->m_sundered)
{
auto & assaults = fd->tap->assaults;
legion_value += att_status->m_index > 0 && assaults[att_status->m_index - 1].m_hp > 0 && assaults[att_status->m_index - 1].m_faction == att_status->m_faction;
legion_value += att_status->m_index + 1 < assaults.size() && assaults[att_status->m_index + 1].m_hp > 0 && assaults[att_status->m_index + 1].m_faction == att_status->m_faction;
if (legion_value > 0 && skill_check<legion>(fd, att_status, nullptr))
// enhance damage
unsigned legion_base = att_status->skill(legion);
if (legion_base > 0)
{
legion_value *= legion_base;
if (debug_print > 0) { desc += "+" + to_string(legion_value) + "(legion)"; }
att_dmg += legion_value;
auto & assaults = fd->tap->assaults;
legion_value += att_status->m_index > 0 && assaults[att_status->m_index - 1].m_hp > 0 && assaults[att_status->m_index - 1].m_faction == att_status->m_faction;
legion_value += att_status->m_index + 1 < assaults.size() && assaults[att_status->m_index + 1].m_hp > 0 && assaults[att_status->m_index + 1].m_faction == att_status->m_faction;
if (legion_value > 0 && skill_check<legion>(fd, att_status, nullptr))
{
legion_value *= legion_base;
if (debug_print > 0) { desc += "+" + to_string(legion_value) + "(legion)"; }
att_dmg += legion_value;
}
}
unsigned rupture_value = att_status->skill(rupture);
if (rupture_value > 0)
{
if (debug_print > 0) { desc += "+" + to_string(rupture_value) + "(rupture)"; }
att_dmg += rupture_value;
}
unsigned venom_value = att_status->skill(venom);
if (venom_value > 0 && def_status->m_poisoned > 0)
{
if (debug_print > 0) { desc += "+" + to_string(venom_value) + "(venom)"; }
att_dmg += venom_value;
}
if (fd->bloodlust_value > 0)
{
if (debug_print > 0) { desc += "+" + to_string(fd->bloodlust_value) + "(bloodlust)"; }
att_dmg += fd->bloodlust_value;
}
if(def_status->m_enfeebled > 0)
{
if(debug_print > 0) { desc += "+" + to_string(def_status->m_enfeebled) + "(enfeebled)"; }
att_dmg += def_status->m_enfeebled;
}
}
unsigned rupture_value = att_status->skill(rupture);
if (rupture_value > 0)
{
if (debug_print > 0) { desc += "+" + to_string(rupture_value) + "(rupture)"; }
att_dmg += rupture_value;
}
unsigned venom_value = att_status->skill(venom);
if (venom_value > 0 && def_status->m_poisoned > 0)
{
if (debug_print > 0) { desc += "+" + to_string(venom_value) + "(venom)"; }
att_dmg += venom_value;
}
if (fd->bloodlust_value > 0)
{
if (debug_print > 0) { desc += "+" + to_string(fd->bloodlust_value) + "(bloodlust)"; }
att_dmg += fd->bloodlust_value;
}
if(def_status->m_enfeebled > 0)
{
if(debug_print > 0) { desc += "+" + to_string(def_status->m_enfeebled) + "(enfeebled)"; }
att_dmg += def_status->m_enfeebled;
}
// prevent damage
std::string reduced_desc;
Expand Down Expand Up @@ -1369,6 +1378,12 @@ inline bool skill_predicate<rush>(Field* fd, CardStatus* src, CardStatus* dst, c
return ! src->m_rush_attempted && dst->m_delay >= (src->m_card->m_type == CardType::assault && dst->m_index < src->m_index ? 2u : 1u);
}

template<>
inline bool skill_predicate<sunder>(Field* fd, CardStatus* src, CardStatus* dst, const SkillSpec& s)
{
return attack_power(dst) > 0 && is_active_next_turn(dst);
}

template<>
inline bool skill_predicate<weaken>(Field* fd, CardStatus* src, CardStatus* dst, const SkillSpec& s)
{
Expand Down Expand Up @@ -1475,6 +1490,13 @@ inline void perform_skill<strike>(Field* fd, CardStatus* src, CardStatus* dst, c
remove_hp(fd, dst, strike_dmg);
}

template<>
inline void perform_skill<sunder>(Field* fd, CardStatus* src, CardStatus* dst, const SkillSpec& s)
{
dst->m_sundered = true;
dst->m_weakened += std::min(s.x, attack_power(dst));
}

template<>
inline void perform_skill<weaken>(Field* fd, CardStatus* src, CardStatus* dst, const SkillSpec& s)
{
Expand Down Expand Up @@ -1571,6 +1593,9 @@ template<> std::vector<CardStatus*>& skill_targets<siege>(Field* fd, CardStatus*
template<> std::vector<CardStatus*>& skill_targets<strike>(Field* fd, CardStatus* src)
{ return(skill_targets_hostile_assault(fd, src)); }

template<> std::vector<CardStatus*>& skill_targets<sunder>(Field* fd, CardStatus* src)
{ return(skill_targets_hostile_assault(fd, src)); }

template<> std::vector<CardStatus*>& skill_targets<weaken>(Field* fd, CardStatus* src)
{ return(skill_targets_hostile_assault(fd, src)); }

Expand Down Expand Up @@ -1607,7 +1632,7 @@ bool check_and_perform_skill(Field* fd, CardStatus* src, CardStatus* dst, const
bool check_and_perform_valor(Field* fd, CardStatus* src)
{
unsigned valor_value = src->skill(valor);
if (valor_value > 0 && skill_check<valor>(fd, src, nullptr))
if (valor_value > 0 && ! src->m_sundered && skill_check<valor>(fd, src, nullptr))
{
unsigned opponent_player = opponent(src->m_player);
const CardStatus * dst = fd->players[opponent_player]->assaults.size() > src->m_index ?
Expand Down Expand Up @@ -1828,5 +1853,6 @@ void fill_skill_table()
skill_table[rush] = perform_targetted_allied_fast_rush;
skill_table[siege] = perform_targetted_hostile_fast<siege>;
skill_table[strike] = perform_targetted_hostile_fast<strike>;
skill_table[sunder] = perform_targetted_hostile_fast<sunder>;
skill_table[weaken] = perform_targetted_hostile_fast<weaken>;
}
1 change: 1 addition & 0 deletions sim.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ struct CardStatus
unsigned m_protected;
unsigned m_rallied;
bool m_rush_attempted;
bool m_sundered;
unsigned m_weakened;

signed m_primary_skill_offset[num_skills];
Expand Down
2 changes: 1 addition & 1 deletion tyrant.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef TYRANT_H_INCLUDED
#define TYRANT_H_INCLUDED

#define TYRANT_OPTIMIZER_VERSION "2.15.0"
#define TYRANT_OPTIMIZER_VERSION "2.16.0"

#include <string>
#include <sstream>
Expand Down
4 changes: 2 additions & 2 deletions tyrant_optimize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1673,7 +1673,7 @@ int main(int argc, char** argv)
{
try
{
your_deck->set_forts(opt_forts + ",");
your_deck->add_forts(opt_forts + ",");
}
catch(const std::runtime_error& e)
{
Expand Down Expand Up @@ -1893,7 +1893,7 @@ int main(int argc, char** argv)
{
try
{
enemy_deck->set_forts(opt_enemy_forts + ",");
enemy_deck->add_forts(opt_enemy_forts + ",");
}
catch(const std::runtime_error& e)
{
Expand Down

0 comments on commit e66b85f

Please sign in to comment.