Skip to content

Commit

Permalink
fix explosions breaking old replays
Browse files Browse the repository at this point in the history
  • Loading branch information
NQNStudios committed Jan 16, 2025
1 parent 9b1bd65 commit f384b1f
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/game/boe.combat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1599,7 +1599,8 @@ void do_combat_cast(location target) {
if(ashes_loc.x > 0){
// If ashes are going to appear, there'd better be a visible blast on the spot.
if(!hit_ashes_loc){
add_explosion(ashes_loc,0,0,get_boom_type(eDamageType::FIRE),1,0);
// the last argument is true so this doesn't break RNG of older replays:
add_explosion(ashes_loc,0,0,get_boom_type(eDamageType::FIRE),1,0,true);
}

univ.town.set_ash(ashes_loc.x,ashes_loc.y,true);
Expand Down
4 changes: 4 additions & 0 deletions src/game/boe.main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,10 @@ static void process_args(int argc, char* argv[]) {
cli.writeToStream(std::cout);
exit(0);
}
// This obsolete preference should always be true unless running an old replay
if(!replay){
set_pref("DrawTerrainFrills", true);
}
if(replay){
if(record_to){
std::cout << "Warning: flag --record conflicts with --replay and will be ignored." << std::endl;
Expand Down
6 changes: 4 additions & 2 deletions src/game/boe.newgraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,9 @@ void mondo_boom(location l,short type,short snd) {
end_missile_anim();
}

void add_explosion(location dest,short val_to_place,short place_type,short boom_type,short x_adj,short y_adj) {
void add_explosion(location dest,short val_to_place,short place_type,short boom_type,short x_adj,short y_adj, bool use_unique_ran) {
if(!get_bool_pref("DrawTerrainFrills", true))
return;
if(!boom_anim_active)
return;
// lose redundant explosions
Expand All @@ -316,7 +318,7 @@ void add_explosion(location dest,short val_to_place,short place_type,short boom_
for(short i = 0; i < 30; i++)
if(store_booms[i].boom_type < 0) {
have_boom = true;
store_booms[i].offset = (i == 0) ? 0 : -1 * get_ran(1,0,2);
store_booms[i].offset = (i == 0) ? 0 : -1 * get_ran(1,0,2,use_unique_ran);
store_booms[i].dest = dest;
store_booms[i].val_to_place = val_to_place;
store_booms[i].place_type = place_type;
Expand Down
2 changes: 1 addition & 1 deletion src/game/boe.newgraph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void run_a_missile(location from,location fire_to,miss_num_t miss_type,short pat
void run_a_boom(location boom_where,short type,short x_adj,short y_adj,short snd = -1);
void mondo_boom(location l,short type,short snd = -1);
void add_missile(location dest,miss_num_t missile_type,short path_type,short x_adj,short y_adj);
void add_explosion(location dest,short val_to_place,short place_type,short boom_type,short x_adj,short y_adj);
void add_explosion(location dest,short val_to_place,short place_type,short boom_type,short x_adj,short y_adj, bool use_unique_ran = false);
void do_missile_anim(short num_steps,location missile_origin,short sound_num) ;
void do_explosion_anim(short sound_num,short expand,short snd = -1);
void click_shop_rect(rectangle area_rect);
Expand Down
8 changes: 6 additions & 2 deletions src/mathutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,20 @@
#include "mathutil.hpp"

std::mt19937 game_rand;
std::mt19937 unique_rand;

short get_ran (short times,short min,short max){
short get_ran (short times,short min,short max, bool use_unique_ran){
long unsigned int store;
short to_ret = 0;

if(max < min) max = min;
if(max == min) return times * min;

for(short i = 1; i < times + 1; i++) {
store = game_rand();
if(use_unique_ran)
store = unique_rand();
else
store = game_rand();
to_ret += min + (store % (max - min + 1));
}
return to_ret;
Expand Down
3 changes: 2 additions & 1 deletion src/mathutil.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ using std::abs;

extern std::mt19937 game_rand;

short get_ran(short times, short min, short max);
// unique_ran: pass true for get_ran() calls that would break replay compatibility
short get_ran(short times, short min, short max, bool use_unique_ran = false);
short max(short a,short b);
short min(short a,short b);
short minmax(short min,short max,short k);
Expand Down
15 changes: 13 additions & 2 deletions src/tools/prefs.mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ typedef NS_ENUM(NSInteger) {
@"UIScale": @(kFloat),
@"UIScaleMap": @(kFloat)
};
// Some legacy preferences influenced RNG and must be
// known by replays
NSDictionary* prefsToReplay = @{
@"DrawTerrainFrills": @(kBool)
};

bool prefsLoaded = false;

Expand Down Expand Up @@ -133,11 +138,17 @@ static bool load_prefs(std::istream& istream) {

std::string key = line.substr(0, key_end + 1), val = line.substr(val_beg);
NSString* pref_key = [NSString stringWithUTF8String: key.c_str()];
NSInteger type;
// Skip obsolete preferences from legacy replays
if([prefsToRecord valueForKey: pref_key] == nil){
continue;
if([prefsToReplay valueForKey: pref_key] == nil){
continue;
}else{
type = [prefsToReplay[pref_key] integerValue];
}
}else{
type = [prefsToRecord[pref_key] integerValue];
}
NSInteger type = [prefsToRecord[pref_key] integerValue];
switch((int)type) {
case kBool:
if(val == "true") set_pref(key, true);
Expand Down

0 comments on commit f384b1f

Please sign in to comment.