Skip to content

Commit

Permalink
fix(zq): upgrade tile+combo 'move' code, more things now update on mo…
Browse files Browse the repository at this point in the history
…ving tiles/combos

Also fixes some issues with 'undo'ing moves, and adds Combo Protection for in-use combos.
  • Loading branch information
EmilyV99 committed Apr 10, 2024
1 parent cecef8a commit 6aae56e
Show file tree
Hide file tree
Showing 18 changed files with 2,344 additions and 7,804 deletions.
1 change: 1 addition & 0 deletions modules/zquest/ZQuestMisc.txt
Expand Up @@ -29,6 +29,7 @@ src/zq/autocombo/pattern_replace.cpp
src/zq/render_hotkeys.cpp
src/zq/render_minimap.cpp
src/zq/render_tooltip.cpp
src/zq/moveinfo.cpp


## End of ZQuest Misc module
Expand Down
4 changes: 2 additions & 2 deletions src/base/autocombo.h
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
140 changes: 140 additions & 0 deletions src/base/containers.h
Expand Up @@ -5,6 +5,146 @@
#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;
}
template<typename T>
vector<std::set<int> const*> subset(std::map<int,T> const& s) const
{
vector<std::set<int> const*> ret;
for(auto& s2 : superset)
{
for(auto p : s)
if(s2.contains(p.first))
{
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
3 changes: 3 additions & 0 deletions src/base/general.h
Expand Up @@ -177,6 +177,8 @@ int wrap(int x,int low,int high);
#define NUM_INFOS 256
#define NUM_PAL_CYCLES 256
#define NUM_WARP_RINGS 9
#define NUM_BOTTLE_TYPES 64
#define NUM_BOTTLE_SHOPS 256

#define QSTPWD_LEN 256

Expand Down Expand Up @@ -325,6 +327,7 @@ enum class ScriptType {
// directions
enum direction { dir_invalid = -1, up, down, left, right, l_up, r_up, l_down, r_down };
static const char* dirstr[] = {"up","down","left","right","up-left","up-right","down-left","down-right"};
static const char* dirstr_proper[] = {"Up","Down","Left","Right","Up-Left","Up-Right","Down-Left","Down-Right"};
const direction oppositeDir[]= {down, up, right, left, r_down, l_down, r_up, l_up};
const direction normalDir[]={up,down,left,right,l_up,r_up,l_down,r_down,up,r_up,right,r_down,down,l_down,left,l_up};
const direction xDir[] = { dir_invalid,dir_invalid,left,right,left,right,left,right };
Expand Down
1 change: 1 addition & 0 deletions src/base/headers.h
Expand Up @@ -5,6 +5,7 @@
#include <string>
#include <vector>
#include <map>
#include <set>
#include "base/ints.h"
#include "base/general.h"

Expand Down
17 changes: 15 additions & 2 deletions src/base/misctypes.h
Expand Up @@ -92,6 +92,19 @@ struct bottletype
flags = 0;
next_type = 0;
}
bool is_blank() const
{
if(name[0])
return false;
for(int q = 0; q < 3; ++q)
{
if(counter[q] > -1 && amount[q] > 0)
return false;
if(next_type)
return false;
}
return true;
}
};

struct pondtype
Expand Down Expand Up @@ -216,8 +229,8 @@ struct miscQdata
int32_t zscript_last_compiled_version;
byte sprites[sprMAX];

bottletype bottle_types[64];
bottleshoptype bottle_shop_types[256];
bottletype bottle_types[NUM_BOTTLE_TYPES];
bottleshoptype bottle_shop_types[NUM_BOTTLE_SHOPS];

byte miscsfx[sfxMAX];
};
Expand Down
5 changes: 5 additions & 0 deletions src/base/util.cpp
Expand Up @@ -15,6 +15,11 @@ namespace fs = std::filesystem;

namespace util
{
string snip(string const& str, size_t length, string trail)
{
return str.size() > length ? str.substr(0,length)+trail : str;
}

void upperstr(string& str)
{
for(int32_t q = str.size() - 1; q >= 0; --q)
Expand Down
1 change: 1 addition & 0 deletions src/base/util.h
Expand Up @@ -23,6 +23,7 @@ namespace fs = std::filesystem;

namespace util
{
std::string snip(std::string const& str, size_t length, std::string trail = "...");
void upperstr(std::string& str);
void lowerstr(std::string& str);
void trimstr(std::string& str);
Expand Down
6 changes: 6 additions & 0 deletions src/dialog/zq_options.cpp
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
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

0 comments on commit 6aae56e

Please sign in to comment.