Skip to content

Commit

Permalink
fix(zq): upgrade combo 'move' code, more things now update on moving…
Browse files Browse the repository at this point in the history
… combos, add Combo overwrite warnings (#917)
  • Loading branch information
EmilyV99 committed Apr 5, 2024
1 parent 5c29d6f commit e8d9031
Show file tree
Hide file tree
Showing 11 changed files with 726 additions and 259 deletions.
4 changes: 2 additions & 2 deletions src/base/autocombo.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,12 @@ struct combo_auto

std::map<int32_t,byte> getMapping();

int32_t cid_display = 0;
int32_t cid_erase = 0;
private:
byte type = AUTOCOMBO_NONE;
byte arg = 0;
byte invalid_reasons = 0;
int32_t cid_display = 0;
int32_t cid_erase = 0;
std::pair<byte, byte> offsets;
};

Expand Down
89 changes: 89 additions & 0 deletions src/base/combo.h
Original file line number Diff line number Diff line change
Expand Up @@ -293,5 +293,94 @@ extern std::vector<newcombo> combobuf;

bool is_push_flag(int flag, optional<int> dir = nullopt);


struct BaseComboRef
{
string name;
bool no_move;
virtual int32_t getCombo() const = 0;
virtual void addCombo(int32_t offs) = 0;
virtual void setCombo(int32_t val) = 0;
BaseComboRef(string name = "")
: name(name), no_move(false)
{}
};
struct ComboRefPtr : public BaseComboRef
{
word* combo;
int32_t getCombo() const override {return *combo;}
void addCombo(int32_t offs) override {*combo += offs;}
void setCombo(int32_t val) override {*combo = val;}
ComboRefPtr()
: BaseComboRef(), combo(nullptr)
{}
ComboRefPtr(word* combo, string name = "")
: BaseComboRef(name), combo(combo)
{}
};
struct ComboRefPtr32 : public BaseComboRef
{
int32_t* combo;
int32_t getCombo() const override {return *combo;}
void addCombo(int32_t offs) override {*combo += offs;}
void setCombo(int32_t val) override {*combo = val;}
ComboRefPtr32()
: BaseComboRef(), combo(nullptr)
{}
ComboRefPtr32(int32_t* combo, string name = "")
: BaseComboRef(name), combo(combo)
{}
};
struct ComboRefPtr10k : public BaseComboRef
{
int32_t* combo;
int32_t getCombo() const override {return *combo/10000;}
void addCombo(int32_t offs) override {*combo += offs*10000;}
void setCombo(int32_t val) override {*combo = val*10000;}
ComboRefPtr10k()
: BaseComboRef(), combo(nullptr)
{}
ComboRefPtr10k(int32_t* combo, string name = "")
: BaseComboRef(name), combo(combo)
{}
};
struct ComboMoveList
{
vector<std::unique_ptr<BaseComboRef>> move_refs;
bitstring move_bits;
string msg;

ComboMoveList() = default;
ComboMoveList(string msg) : msg(msg) {}

template<class... Args>
ComboRefPtr* add_combo(word* combo, Args&&... args)
{
if(!combo || !*combo)
return nullptr;
return (ComboRefPtr*)move_refs.emplace_back(std::make_unique<ComboRefPtr>(combo, args...)).get();
}
template<class... Args>
ComboRefPtr32* add_combo(int32_t* combo, Args&&... args)
{
if(!combo || !*combo)
return nullptr;
return (ComboRefPtr32*)move_refs.emplace_back(std::make_unique<ComboRefPtr32>(combo, args...)).get();
}
template<class... Args>
ComboRefPtr10k* add_combo_10k(int32_t* combo, Args&&... args)
{
if(!combo || !*combo)
return nullptr;
return (ComboRefPtr10k*)move_refs.emplace_back(std::make_unique<ComboRefPtr10k>(combo, args...)).get();
}


#ifdef IS_EDITOR
bool process(bool is_dest, SuperSet const& combo_links, int _first, int _last);
void add_diff(int diff);
#endif
};

#endif

125 changes: 125 additions & 0 deletions src/base/containers.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,131 @@
#include <array>
#include <stdexcept>

struct SuperSet
{
std::set<int>* get(int v)
{
for(auto& s : superset)
{
if(s.contains(v))
return &s;
}
return nullptr;
}
std::set<int> const* get(int v) const
{
for(auto& s : superset)
{
if(s.contains(v))
return &s;
}
return nullptr;
}
std::set<int>* get_add(int v)
{
if(auto s = get(v))
return s;
if(banned_vals.contains(v))
return nullptr;
auto& s = superset.emplace_back();
s.insert(v);
return &s;
}
std::set<int>* add_to(int targ, int v)
{
if(banned_vals.contains(targ))
return get(v);
if(banned_vals.contains(v))
return get(targ);

auto s = get_add(targ);
if(auto s2 = get(v))
{
if(s != s2)
merge(*s,*s2);
}
else s->insert(v);
return s;
}
std::set<int>* add(std::set<int> const& s)
{
std::set<int>* ptr = nullptr;
for(int v : s)
{
if(banned_vals.contains(v))
continue;
if(ptr)
{
if(auto ptr2 = get(v))
{
if(ptr != ptr2)
merge(*ptr, *ptr2);
}
else
{
ptr->insert(v);
}
}
else
{
ptr = get_add(v);
}
}
return ptr;
}
void clear()
{
superset.clear();
}
size_t size() const
{
size_t sz = 0;
for(auto& s : superset)
sz += s.size();
return sz;
}
bool empty() const
{
return superset.empty();
}
bool remove(std::set<int>& s)
{
for(auto it = superset.begin(); it != superset.end();)
{
std::set<int>& s2 = *it;
if(&s == &s2)
{
superset.erase(it);
return true;
}
else ++it;
}
return false;
}
vector<std::set<int> const*> subset(std::set<int> const& s) const
{
vector<std::set<int> const*> ret;
for(auto& s2 : superset)
{
for(auto v : s)
if(s2.contains(v))
{
ret.emplace_back(&s2);
break;
}
}
return ret;
}
std::set<int> banned_vals = {0};
private:
vector<std::set<int>> superset;
void merge(std::set<int>& dest, std::set<int>& src)
{
dest.insert(src.begin(), src.end());
remove(src);
}
};

template<typename Sz,typename T>
class bounded_container
{
Expand Down
1 change: 1 addition & 0 deletions src/base/headers.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <string>
#include <vector>
#include <map>
#include <set>
#include "base/ints.h"
#include "base/general.h"

Expand Down
6 changes: 6 additions & 0 deletions src/dialog/zq_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ void OptionsDialog::loadOptions()
opts[OPT_ANIM_COMBOS] = AnimationOn ? 1 : 0;
opts[OPT_OW_PROT] = OverwriteProtection ? 1 : 0;
opts[OPT_TILE_PROT] = TileProtection ? 1 : 0;
opts[OPT_COMBO_PROT] = ComboProtection ? 1 : 0;
opts[OPT_RULESET] = RulesetDialog ? 1 : 0;
opts[OPT_TOOLTIPS] = EnableTooltips ? 1 : 0;
opts[OPT_TOOLTIP_HIGHLIGHT] = TooltipsHighlight ? 1 : 0;
Expand Down Expand Up @@ -167,6 +168,10 @@ void OptionsDialog::saveOption(int ind)
TileProtection = v;
zc_set_config("zquest", "tile_protection", v);
break;
case OPT_COMBO_PROT:
ComboProtection = v;
zc_set_config("zquest", "combo_protection", v);
break;
case OPT_GRIDCOL:
GridColor = v;
zc_set_config("zquest", "grid_color", v);
Expand Down Expand Up @@ -836,6 +841,7 @@ std::shared_ptr<GUI::Widget> OptionsDialog::view()
ROW_CHECK(OPT_ANIM_COMBOS, "Animate Combos"),
ROW_CHECK(OPT_OW_PROT, "Overwrite Protection"),
ROW_CHECK(OPT_TILE_PROT, "Tile Protection"),
ROW_CHECK(OPT_COMBO_PROT, "Combo Protection"),
//ROW_CHECK(OPT_STATIC_INVAL, "Use Static for Invalid Data"),
ROW_CHECK(OPT_RULESET, "Show Ruleset Dialog on New Quest"),
ROW_CHECK(OPT_PATTERNSEARCH, "Listers Use Pattern-Matching Search"),
Expand Down
2 changes: 1 addition & 1 deletion src/dialog/zq_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class OptionsDialog: public GUI::Dialog<OptionsDialog>
{
OPT_MOUSESCROLL, OPT_SAVEPATHS, OPT_PALCYCLE, OPT_FPS, OPT_COMB_BRUSH,
OPT_FLOAT_BRUSH, OPT_RELOAD_QUEST, OPT_MISALIGNS, OPT_ANIM_COMBOS, OPT_OW_PROT,
OPT_TILE_PROT, OPT_STATIC_INVAL, OPT_RULESET, OPT_TOOLTIPS,
OPT_TILE_PROT, OPT_COMBO_PROT, OPT_STATIC_INVAL, OPT_RULESET, OPT_TOOLTIPS,
OPT_TOOLTIP_HIGHLIGHT, OPT_PATTERNSEARCH, OPT_NEXTPREVIEW, OPT_INITSCR_WARN,
OPT_TOOLTIP_TIMER, OPT_MAPCURSOR,
//
Expand Down
9 changes: 8 additions & 1 deletion src/tiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2712,7 +2712,14 @@ int32_t tilesize(byte format)

void TileRefPtr::forEach(std::function<void(int32_t)> proc) const
{
auto t = *tile + offset();
auto t = getTile() + offset();
for(int x = 0; x < w; ++x)
for(int y = 0; y < h; ++y)
proc(t + x + y*TILES_PER_ROW);
}
void TileRefPtr10k::forEach(std::function<void(int32_t)> proc) const
{
auto t = getTile() + offset();
for(int x = 0; x < w; ++x)
for(int y = 0; y < h; ++y)
proc(t + x + y*TILES_PER_ROW);
Expand Down
34 changes: 26 additions & 8 deletions src/tiles.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,23 @@ struct TileRefPtr : public BaseTileRef
: BaseTileRef(w,h,name), tile(tile)
{}
};
struct TileRefPtr10k : public BaseTileRef
{
int32_t* tile;
int32_t getTile() const override {return *tile / 10000;}
void addTile(int32_t offs) override {*tile += offs * 10000;}
void setTile(int32_t val) override {*tile = val * 10000;}
void forEach(std::function<void(int32_t)> proc) const override;
TileRefPtr10k()
: BaseTileRef(), tile(nullptr)
{}
TileRefPtr10k(int32_t* tile, string name = "")
: BaseTileRef(name), tile(tile)
{}
TileRefPtr10k(int32_t* tile, uint w, uint h, string name = "")
: BaseTileRef(w,h,name), tile(tile)
{}
};
struct TileRefCombo : public BaseTileRef
{
newcombo* combo;
Expand Down Expand Up @@ -180,20 +197,21 @@ struct TileMoveList
{
if(!tile || !*tile)
return nullptr;
auto ptr = std::make_unique<TileRefPtr>(tile, args...);
auto ret = ptr.get();
move_refs.emplace_back(std::move(ptr));
return ret;
return (TileRefPtr*)move_refs.emplace_back(std::make_unique<TileRefPtr>(tile, args...)).get();
}
template<class... Args>
TileRefPtr10k* add_tile_10k(int32_t* tile, Args&&... args)
{
if(!tile || !*tile)
return nullptr;
return (TileRefPtr10k*)move_refs.emplace_back(std::make_unique<TileRefPtr10k>(tile, args...)).get();
}
template<class... Args>
TileRefCombo* add_combo(newcombo* combo, Args&&... args)
{
if(!combo || !combo->o_tile)
return nullptr;
auto ptr = std::make_unique<TileRefCombo>(combo, args...);
auto ret = ptr.get();
move_refs.emplace_back(std::move(ptr));
return ret;
return (TileRefCombo*)move_refs.emplace_back(std::make_unique<TileRefCombo>(combo, args...)).get();
}


Expand Down

0 comments on commit e8d9031

Please sign in to comment.