Skip to content

Commit

Permalink
Fix #68 #67 #66 (#71)
Browse files Browse the repository at this point in the history
* more comments

* Allow (barrier) protect on structures

Closes: #68
Closes: #67

* update: changelog

* fix: comment

* no stasis on structs only protect from barrier

* fix: db speedup test

* add: db debug load/write msgs

* update: changelog

* Less time to test db sim scaling

* Factor of 3 gain by db on my local system

* Redirect stdout again

* Take a bit better care of memory for tests

* Increate BGE coverage

* Manually clear card pointers...

* Redirect stdout again

* Force init in tests

* Fix tests producing OOM from too many logging...

* Lowered log priority

* More tests coverage

* rm weird copy

* Fix segfault on missing operations

* update: changelog

* fix: test decks
  • Loading branch information
APN-Pucky authored Mar 15, 2024
1 parent 6946458 commit af75bc7
Show file tree
Hide file tree
Showing 14 changed files with 187 additions and 350 deletions.
16 changes: 15 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,23 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added

- more tests of skills and bges (#66, #71)

### Fixed

- `all="0"` in xmls is treated as no all attribute (#70)
- structures now can have barrier (#71)
- test of db scaling did not write to db (#71)
- memory leak in test runs (#71)
- segfault on missing operation (#71)

## [6.5.0] - 2023-07-11

- Updated Subdue skill now cancels an attack, if subdue reduces the attack to 0
- Updated Subdue skill now cancels an attack, if subdue reduces the attack to 0
- Update corrosive skill
- Added options `update-corrosive-protect-armor` and `no-update-corrosive-protect-armor` to toggle new behaviour (default: updated)

Expand Down
14 changes: 14 additions & 0 deletions cards.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,22 @@ std::list<std::string> get_abbreviations(const std::string& name)

//------------------------------------------------------------------------------
Cards::~Cards()
{
//for (Card* c: all_cards) { delete(c); }
clear();
}

void Cards::clear()
{
for (Card* c: all_cards) { delete(c); }
all_cards.clear();
cards_by_id.clear();
player_cards.clear();
cards_by_name.clear();
player_commanders.clear();
player_assaults.clear();
player_structures.clear();
visible_cardset.clear();
}

const Card* Cards::by_id(unsigned id) const
Expand Down
2 changes: 2 additions & 0 deletions cards.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ class Cards
std::map<std::string, std::string> player_cards_abbr;
std::unordered_set<unsigned> visible_cardset;
std::unordered_set<std::string> ambiguous_names;

const Card* by_id(unsigned id) const;
void clear();
void organize();
void fix_dominion_recipes();
void add_card(Card* card, const std::string & name);
Expand Down
5 changes: 5 additions & 0 deletions deck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,11 @@ DeckEncoder encode_deck = encode_deck_ext_b64;

namespace range = boost::range;

Decks::~Decks()
{
decks.clear();
}

void Deck::set(const std::vector<unsigned>& ids, const std::map<signed, char> &marks)
{
commander = nullptr;
Expand Down
8 changes: 6 additions & 2 deletions deck.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,15 @@ typedef std::map<std::string, long double> DeckList;
class Decks
{
public:
void add_deck(Deck* deck, const std::string& deck_name);
Deck* find_deck_by_name(const std::string& deck_name);
~Decks();

std::list<Deck> decks;
std::map<std::pair<DeckType::DeckType, unsigned>, Deck*> by_type_id;
std::map<std::string, Deck*> by_name;

void add_deck(Deck* deck, const std::string& deck_name);
Deck* find_deck_by_name(const std::string& deck_name);

};

#endif
24 changes: 17 additions & 7 deletions sim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1435,6 +1435,8 @@ void turn_end_phase(Field* fd)
{
continue;
}
// reset the structure's (barrier) protect
status.m_protected = 0;
status.m_evaded = 0; // so far only useful in Inactive turn
}
}
Expand Down Expand Up @@ -1608,6 +1610,7 @@ struct PerformAttack
{
unsigned pre_modifier_dmg = att_status->attack_power();
// Bug fix? 2023-04-03 a card with zero attack power can not attack and won't trigger subdue
// Confirmed subdue behaviour by MK 2023-07-12
if(pre_modifier_dmg == 0) { return 0; }


Expand Down Expand Up @@ -2289,12 +2292,25 @@ inline void perform_skill<Skill::fortify>(Field* fd, CardStatus* src, CardStatus
{
dst->ext_hp(s.x);
}

template<>
inline void perform_skill<Skill::siege>(Field* fd, CardStatus* src, CardStatus* dst, const SkillSpec& s)
{
//only structures can be sieged
_DEBUG_ASSERT(dst->m_card->m_type != CardType::assault);
_DEBUG_ASSERT(dst->m_card->m_type != CardType::commander);
unsigned siege_dmg = remove_absorption(fd,dst,s.x);
// structure should not have protect normally..., but let's allow it for barrier support
siege_dmg = safe_minus(siege_dmg, src->m_overloaded ? 0 : dst->m_protected);
remove_hp(fd, dst, siege_dmg);
}

template<>
inline void perform_skill<Skill::mortar>(Field* fd, CardStatus* src, CardStatus* dst, const SkillSpec& s)
{
if (dst->m_card->m_type == CardType::structure)
{
remove_hp(fd, dst, remove_absorption(fd,dst,s.x));
perform_skill<Skill::siege>(fd, src, dst, s);
}
else
{
Expand Down Expand Up @@ -2355,12 +2371,6 @@ inline void perform_skill<Skill::rush>(Field* fd, CardStatus* src, CardStatus* d
}
}

template<>
inline void perform_skill<Skill::siege>(Field* fd, CardStatus* src, CardStatus* dst, const SkillSpec& s)
{
remove_hp(fd, dst, remove_absorption(fd,dst,s.x));
}

template<>
inline void perform_skill<Skill::strike>(Field* fd, CardStatus* src, CardStatus* dst, const SkillSpec& s)
{
Expand Down
2 changes: 1 addition & 1 deletion sim.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ struct CardStatus
const Card* m_card;
unsigned m_index;
unsigned m_action_index;
Field* m_field;
Field* m_field; // only needed for fixes/updated skills in attack power calculation
unsigned m_player;
unsigned m_delay;
unsigned m_hp;
Expand Down
Loading

0 comments on commit af75bc7

Please sign in to comment.