Skip to content

Commit

Permalink
fix: some more subscreen related replay errors
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilyV99 committed Aug 20, 2023
1 parent bc9f8ab commit b25433e
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 65 deletions.
6 changes: 2 additions & 4 deletions src/gamedata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,7 @@ void gamedata::set_counter(word change, byte c)
if(c>=MAX_COUNTERS) // Sanity check
return;

if(replay_version_check(0,19))
flushItemCache(true);
flushItemCache(true);

if(game!=NULL)
{
Expand All @@ -170,8 +169,7 @@ void gamedata::change_counter(int16_t change, byte c)
if(c>=MAX_COUNTERS) // Sanity check
return;

if(replay_version_check(0,19))
flushItemCache(true);
flushItemCache(true);

if(game!=NULL)
{
Expand Down
105 changes: 50 additions & 55 deletions src/subscr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3175,11 +3175,11 @@ bool displaysubscreenitem(int32_t itemtype, int32_t d, int32_t id)
if((itemtype == itype_bomb &&
!(game->get_bombs()
// Remote Bombs: the bomb icon can still be used when an undetonated bomb is onscreen.
|| (itemsbuf[current_item_id(itype_bomb)].misc1==0 && Lwpns.idCount(wLitBomb)>0)
|| (itemsbuf[current_item_id(itype_bomb,replay_version_check(0,19))].misc1==0 && Lwpns.idCount(wLitBomb)>0)
|| current_item_power(itype_bombbag)))
|| (itemtype == itype_sbomb &&
!(game->get_sbombs()
|| (itemsbuf[current_item_id(itype_sbomb)].misc1==0 && Lwpns.idCount(wLitSBomb)>0)
|| (itemsbuf[current_item_id(itype_sbomb,replay_version_check(0,19))].misc1==0 && Lwpns.idCount(wLitSBomb)>0)
|| (current_item_power(itype_bombbag)
&& itemsbuf[current_item_id(itype_bombbag)].flags & ITEM_FLAG1))))
return false;
Expand Down Expand Up @@ -3256,7 +3256,7 @@ void subscreenitem(BITMAP *dest, int32_t x, int32_t y, int32_t itemtype)
}
}
}

//Item Override stuff here
if((itemtype & 0x8000) &&
(get_app_id() == App::zelda ? game->item[itemtype&0xFFF] : true) &&
Expand Down Expand Up @@ -4341,58 +4341,53 @@ void putBmap(BITMAP *dest, int32_t x, int32_t y,bool showmap, bool showrooms, bo

void load_Sitems()
{
Sitems.clear();

// HC Pieces
if(QMisc.colors.HCpieces_tile)
{
// item *HCP = new item((zfix)(inventory_x[5]-ofs),(zfix)y,MAXITEMS,0,0);
item *HCP = new item((zfix)0,(zfix)0,(zfix)0,iHCPiece,0,0);

if(HCP)
{
int32_t hcpphc = game->get_hcp_per_hc();
HCP->tile = QMisc.colors.HCpieces_tile + vbound(game->get_HCpieces(),0,hcpphc > 0 ? hcpphc-1 : 0);
HCP->o_tile = HCP->tile;
HCP->cs = QMisc.colors.HCpieces_cset;
HCP->frames = 0;
add_subscr_item(HCP);
}
}

if(has_item(itype_map, get_dlevel()))
{
add_subscr_item(new item((zfix)0,(zfix)0,(zfix)0,iMap,0,0));
}

if(has_item(itype_compass, get_dlevel()))
{
add_subscr_item(new item((zfix)0,(zfix)0,(zfix)0,iCompass,0,0));
}

if(has_item(itype_bosskey, get_dlevel()))
{
add_subscr_item(new item((zfix)0,(zfix)0,(zfix)0,iBossKey,0,0));
}

for(int32_t i=0; i<itype_max; i++)
{
//special case: ignore the dmap-specific items processed above. -DD
if(i == itype_map || i == itype_compass || i == itype_bosskey)
continue;

// Display the ring even if it has run out of magic.
if(current_item_id(i,false)>-1)
{
int32_t j = current_item_id(i,false);
//al_trace("About to check itemsbuf[j].tile in subscreen.cpp, line 4634, loop[%d]\n",j);
if(itemsbuf[j].tile)
add_subscr_item(new item((zfix)0, (zfix)0,(zfix)0,j,0,0));
}
}
//al_trace("Finished load_Sitems(%d)\n",0);

new_sel=true;
Sitems.clear();

// HC Pieces
if(QMisc.colors.HCpieces_tile)
{
// item *HCP = new item((zfix)(inventory_x[5]-ofs),(zfix)y,MAXITEMS,0,0);
item *HCP = new item((zfix)0,(zfix)0,(zfix)0,iHCPiece,0,0);

if(HCP)
{
int32_t hcpphc = game->get_hcp_per_hc();
HCP->tile = QMisc.colors.HCpieces_tile + vbound(game->get_HCpieces(),0,hcpphc > 0 ? hcpphc-1 : 0);
HCP->o_tile = HCP->tile;
HCP->cs = QMisc.colors.HCpieces_cset;
HCP->frames = 0;
add_subscr_item(HCP);
}
}

if(has_item(itype_map, get_dlevel()))
{
add_subscr_item(new item((zfix)0,(zfix)0,(zfix)0,iMap,0,0));
}

if(has_item(itype_compass, get_dlevel()))
{
add_subscr_item(new item((zfix)0,(zfix)0,(zfix)0,iCompass,0,0));
}

if(has_item(itype_bosskey, get_dlevel()))
{
add_subscr_item(new item((zfix)0,(zfix)0,(zfix)0,iBossKey,0,0));
}

for(int32_t i=0; i<itype_max; i++)
{
//special case: ignore the dmap-specific items processed above. -DD
if(i == itype_map || i == itype_compass || i == itype_bosskey)
continue;
int j = current_item_id(i,false);
// Display the ring even if it has run out of magic.
if(j>-1 && itemsbuf[j].tile)
add_subscr_item(new item((zfix)0, (zfix)0,(zfix)0,j,0,0));
}
//al_trace("Finished load_Sitems(%d)\n",0);

new_sel=true;
}

void update_subscreens(int32_t dmap)
Expand Down
16 changes: 10 additions & 6 deletions src/zc/zc_sys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2256,7 +2256,6 @@ int32_t current_item(int32_t item_type) //item currently being used
std::map<int32_t, int32_t> itemcache;
std::map<int32_t, int32_t> itemcache_cost;

// Not actually used by anything at the moment...
void removeFromItemCache(int32_t itemclass)
{
itemcache.erase(itemclass);
Expand All @@ -2265,7 +2264,10 @@ void removeFromItemCache(int32_t itemclass)

void flushItemCache(bool justcost)
{
if(!justcost) itemcache.clear();
if(justcost && replay_version_check(0,19))
return;
if(!justcost)
itemcache.clear();
itemcache_cost.clear();

//also fix the active subscreen if items were deleted -DD
Expand All @@ -2279,14 +2281,15 @@ void flushItemCache(bool justcost)
// This is used often, so it should be as direct as possible.
int32_t _c_item_id_internal(int32_t itemtype, bool checkmagic, bool jinx_check)
{
auto& cost_cache = replay_version_check(19) ? itemcache_cost : itemcache;
if(jinx_check)
{
if(!(HeroSwordClk() || HeroItemClk()))
jinx_check = false; //not jinxed
}
if (itemtype != itype_ring && !jinx_check) // Rings must always be checked, as must jinx checks...
{
auto& cache = checkmagic ? itemcache_cost : itemcache;
auto& cache = checkmagic ? cost_cache : itemcache;
auto res = cache.find(itemtype);

if(res != cache.end())
Expand Down Expand Up @@ -2324,9 +2327,10 @@ int32_t _c_item_id_internal(int32_t itemtype, bool checkmagic, bool jinx_check)

if(!jinx_check) //Can't cache jinx_check results
{
itemcache[itemtype] = result;
if(checkmagic || result < 0 || checkmagiccost(result))
itemcache_cost[itemtype] = result;
if (!checkmagic)
itemcache[itemtype] = result;
if (checkmagic || result < 0 || checkmagiccost(result))
cost_cache[itemtype] = result;
}
return result;
}
Expand Down

0 comments on commit b25433e

Please sign in to comment.