Skip to content

Commit

Permalink
fix(zq): "Used Tiles" completely failing to calculate
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilyV99 committed Apr 26, 2024
1 parent 7d9ceee commit 009d591
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 28 deletions.
15 changes: 15 additions & 0 deletions src/zq/moveinfo.cpp
Original file line number Diff line number Diff line change
@@ -1,22 +1,37 @@
#include "moveinfo.h"
#include "tiles.h"



void BaseTileRef::forEach(std::function<void(int32_t)> proc) const
{
for(auto [ex_t,w,h] : extra_rects)
{
auto t = ex_t + getTile() + offset();
for(int x = 0; x < w; ++x)
for(int y = 0; y < h; ++y)
proc(t + x + (y*w));
}
}
void TileRefPtr::forEach(std::function<void(int32_t)> proc) const
{
BaseTileRef::forEach(proc);
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
{
BaseTileRef::forEach(proc);
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 TileRefCombo::forEach(std::function<void(int32_t)> proc) const
{
BaseTileRef::forEach(proc);
reset_combo_animation(*combo);
do
{
Expand Down
31 changes: 20 additions & 11 deletions src/zq/moveinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ struct BaseTileRef
virtual int32_t getTile() const = 0;
virtual void addTile(int32_t offs) = 0;
virtual void setTile(int32_t val) = 0;
virtual void forEach(std::function<void(int32_t)> proc) const = 0;
virtual void forEach(std::function<void(int32_t)> proc) const;
BaseTileRef(string name = "", bool no_move = false, int xoff = 0, int yoff = 0,
vector<std::tuple<int,int,int>> rects = {})
: name(name), w(1), h(1), no_move(no_move), xoff(xoff), yoff(yoff), extra_rects(std::move(rects))
Expand Down Expand Up @@ -122,18 +122,23 @@ struct TileMoveProcess
};
struct TileMoveList
{
enum class Mode
{
MOVE, CHECK_ALL
};
vector<std::unique_ptr<BaseTileRef>> move_refs;

string msg; //message for the overwrite warning
std::ostringstream warning_list; //list of overwrite warnings
bool warning_flood; //if the overwrite warnings ran out of space
Mode mode;

//The processes to check tiles with
optional<TileMoveProcess> source_process;
TileMoveProcess dest_process;

TileMoveList(TileMoveProcess dest_p, optional<TileMoveProcess> src_p = nullopt, string msg = "")
: move_refs(), msg(msg), warning_list(), warning_flood(false),
TileMoveList(TileMoveProcess dest_p, optional<TileMoveProcess> src_p = nullopt, Mode mode = Mode::MOVE, string msg = "")
: move_refs(), msg(msg), warning_list(), warning_flood(false), mode(mode),
source_process(src_p), dest_process(dest_p)
{}

Expand Down Expand Up @@ -163,14 +168,18 @@ struct TileMoveList
//Adds 'ref', either to 'move_refs' or 'warning_list' as appropriate based on the process rules.
void add_ref(std::unique_ptr<BaseTileRef> ref)
{
if(source_process)
if(process(false, ref, *source_process))
return;
process(true, ref, dest_process);
if(mode == Mode::MOVE)
{
if(source_process)
if(process(ref, *source_process))
return;
process(ref, dest_process, true);
}
else process(ref, dest_process); //Mode::CHECK_ALL
}

//Returns true if 'ref' was moved to the 'move_refs'
bool process(bool is_dest, std::unique_ptr<BaseTileRef>& ref, TileMoveProcess const& proc);
bool process(std::unique_ptr<BaseTileRef>& ref, TileMoveProcess const& proc, bool is_dest = false);
//Checks overwrite protection
bool check_prot();
//Adds 'diff' to every tile in 'move_refs'
Expand Down Expand Up @@ -279,13 +288,13 @@ struct ComboMoveList
void add_ref(std::unique_ptr<BaseComboRef> ref)
{
if(source_process)
if(process(false, ref, *source_process))
if(process(ref, *source_process))
return;
process(true, ref, dest_process);
process(ref, dest_process, true);
}

//Returns true if 'ref' was moved to the 'move_refs'
bool process(bool is_dest, std::unique_ptr<BaseComboRef>& ref, ComboMoveProcess const& proc);
bool process(std::unique_ptr<BaseComboRef>& ref, ComboMoveProcess const& proc, bool is_dest = false);
//Checks overwrite protection
bool check_prot();
//Adds 'diff' to every combo in 'move_refs'
Expand Down
40 changes: 23 additions & 17 deletions src/zq/zq_tiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6136,7 +6136,7 @@ int32_t quick_select_3(int32_t a, int32_t b, int32_t c, int32_t d)
return a==0?b:a==1?c:d;
}

bool TileMoveList::process(bool is_dest, std::unique_ptr<BaseTileRef>& ref, TileMoveProcess const& proc)
bool TileMoveList::process(std::unique_ptr<BaseTileRef>& ref, TileMoveProcess const& proc, bool is_dest)
{
TileRefCombo* combo_ref = dynamic_cast<TileRefCombo*>(ref.get());
int i = ti_none;
Expand Down Expand Up @@ -6177,7 +6177,12 @@ bool TileMoveList::process(bool is_dest, std::unique_ptr<BaseTileRef>& ref, Tile

if(i != ti_none && ref->getTile() != 0)
{
if(i==ti_broken || is_dest || (i==ti_encompass && ref->no_move))
if(mode == Mode::CHECK_ALL)
{
move_refs.emplace_back(std::move(ref));
return true;
}
else if(i==ti_broken || is_dest || (i==ti_encompass && ref->no_move))
{
if(warning_flood || warning_list.tellp() >= 65000)
{
Expand Down Expand Up @@ -6216,7 +6221,7 @@ void TileMoveList::add_diff(int diff)
}

//from 'combo.h'
bool ComboMoveList::process(bool is_dest, std::unique_ptr<BaseComboRef>& ref, ComboMoveProcess const& proc)
bool ComboMoveList::process(std::unique_ptr<BaseComboRef>& ref, ComboMoveProcess const& proc, bool is_dest)
{
int i = ti_none;
auto c = ref->getCombo();
Expand Down Expand Up @@ -6343,7 +6348,7 @@ void ComboMoveList::add_diff(int diff)
ref->addCombo(diff);
}

bool _handle_tile_move(TileMoveProcess dest_process, optional<TileMoveProcess> source_process, int diff, TileMoveUndo* on_undo, std::function<void(int32_t)> every_proc)
bool _handle_tile_move(TileMoveProcess dest_process, optional<TileMoveProcess> source_process, int diff, TileMoveUndo* on_undo = nullptr, std::function<void(int32_t)> every_proc = nullptr, TileMoveList::Mode mode = TileMoveList::Mode::MOVE)
{
bool BSZ2 = get_qr(qr_BSZELDA);
bool move = source_process.has_value();
Expand All @@ -6356,7 +6361,7 @@ bool _handle_tile_move(TileMoveProcess dest_process, optional<TileMoveProcess> s
//Combos
{
auto& movelist = vec.emplace_back(std::make_unique<TileMoveList>(
dest_process, source_process,
dest_process, source_process, mode,
move
? "The tiles used by the following combos will be partially cleared by the move."
: "The tiles used by the following combos will be partially or completely overwritten by this process."
Expand Down Expand Up @@ -6387,7 +6392,7 @@ bool _handle_tile_move(TileMoveProcess dest_process, optional<TileMoveProcess> s
//Items
{
auto& movelist = vec.emplace_back(std::make_unique<TileMoveList>(
dest_process, source_process,
dest_process, source_process, mode,
move
? "The tiles used by the following items will be partially cleared by the move."
: "The tiles used by the following items will be partially or completely overwritten by this process."
Expand Down Expand Up @@ -6419,7 +6424,7 @@ bool _handle_tile_move(TileMoveProcess dest_process, optional<TileMoveProcess> s
//Weapon sprites
{
auto& movelist = vec.emplace_back(std::make_unique<TileMoveList>(
dest_process, source_process,
dest_process, source_process, mode,
move
? "The tiles used by the following weapons will be partially cleared by the move."
: "The tiles used by the following weapons will be partially or completely overwritten by this process."
Expand Down Expand Up @@ -6537,7 +6542,7 @@ bool _handle_tile_move(TileMoveProcess dest_process, optional<TileMoveProcess> s
//Player sprites
{
auto& movelist = vec.emplace_back(std::make_unique<TileMoveList>(
dest_process, source_process,
dest_process, source_process, mode,
move
? "The tiles used by the following player sprites will be partially cleared by the move."
: "The tiles used by the following player sprites will be partially or completely overwritten by this process."
Expand Down Expand Up @@ -6676,7 +6681,7 @@ bool _handle_tile_move(TileMoveProcess dest_process, optional<TileMoveProcess> s
//Map Styles
{
auto& movelist = vec.emplace_back(std::make_unique<TileMoveList>(
dest_process, source_process,
dest_process, source_process, mode,
move
? "The tiles used by the following map styles will be partially cleared by the move."
: "The tiles used by the following map styles will be partially or completely overwritten by this process."
Expand All @@ -6693,7 +6698,7 @@ bool _handle_tile_move(TileMoveProcess dest_process, optional<TileMoveProcess> s
//Game Icons
{
auto& movelist = vec.emplace_back(std::make_unique<TileMoveList>(
dest_process, source_process,
dest_process, source_process, mode,
move
? "The tiles used by the following game icons will be partially cleared by the move."
: "The tiles used by the following game icons will be partially or completely overwritten by this process."
Expand All @@ -6706,7 +6711,7 @@ bool _handle_tile_move(TileMoveProcess dest_process, optional<TileMoveProcess> s
//DMaps
{
auto& movelist = vec.emplace_back(std::make_unique<TileMoveList>(
dest_process, source_process,
dest_process, source_process, mode,
move
? "The tiles used by the following dmaps will be partially cleared by the move."
: "The tiles used by the following dmaps will be partially or completely overwritten by this process."
Expand All @@ -6725,7 +6730,7 @@ bool _handle_tile_move(TileMoveProcess dest_process, optional<TileMoveProcess> s
//Enemies
{
auto& movelist = vec.emplace_back(std::make_unique<TileMoveList>(
dest_process, source_process,
dest_process, source_process, mode,
move
? "The tiles used by the following enemies will be partially cleared by the move."
: "The tiles used by the following enemies will be partially or completely overwritten by this process."
Expand Down Expand Up @@ -6811,7 +6816,7 @@ bool _handle_tile_move(TileMoveProcess dest_process, optional<TileMoveProcess> s
//Subscreens
{
auto& movelist = vec.emplace_back(std::make_unique<TileMoveList>(
dest_process, source_process,
dest_process, source_process, mode,
move
? "The tiles used by the following subscreen widgets will be partially cleared by the move."
: "The tiles used by the following subscreen widgets will be partially or completely overwritten by this process."
Expand Down Expand Up @@ -6853,7 +6858,7 @@ bool _handle_tile_move(TileMoveProcess dest_process, optional<TileMoveProcess> s
//Strings
{
auto& movelist = vec.emplace_back(std::make_unique<TileMoveList>(
dest_process, source_process,
dest_process, source_process, mode,
move
? "The tiles used by the following strings will be partially cleared by the move."
: "The tiles used by the following strings will be partially or completely overwritten by this process."
Expand Down Expand Up @@ -6881,17 +6886,18 @@ bool _handle_tile_move(TileMoveProcess dest_process, optional<TileMoveProcess> s
}
bool handle_tile_move(TileMoveProcess dest_process)
{
return _handle_tile_move(dest_process, nullopt, 0, nullptr, nullptr);
return _handle_tile_move(dest_process, nullopt, 0);
}
bool handle_tile_move(TileMoveProcess dest_process, TileMoveProcess source_process, int diff, TileMoveUndo& on_undo)
{
return _handle_tile_move(dest_process, source_process, diff, &on_undo, nullptr);
return _handle_tile_move(dest_process, source_process, diff, &on_undo);
}
void for_every_used_tile(std::function<void(int32_t)> proc)
{
reset_combo_animations();
reset_combo_animations2();
_handle_tile_move({}, nullopt, 0, nullptr, proc);
TileMoveProcess all_tiles {.rect = false, ._first = 0, ._last = NEWMAXTILES-1};
_handle_tile_move(all_tiles, nullopt, 0, nullptr, proc, TileMoveList::Mode::CHECK_ALL);
}

bool _handle_combo_move(ComboMoveProcess dest_process, optional<ComboMoveProcess> source_process, int diff, ComboMoveUndo* on_undo)
Expand Down

0 comments on commit 009d591

Please sign in to comment.