Skip to content

Commit 345fb74

Browse files
committed
Refactoring
1 parent 4c607ce commit 345fb74

3 files changed

Lines changed: 29 additions & 24 deletions

File tree

Source/diablo.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1404,7 +1404,17 @@ tl::expected<void, std::string> LoadLvlGFX()
14041404
pMegaTiles = std::move(*til);
14051405
}
14061406

1407-
ASSIGN_OR_RETURN(pSpecialCels, LoadCelWithStatus(active.specialCelsPath.c_str(), SpecialCelWidth));
1407+
// Special CELs: try active path, fall back to Tristram's if different.
1408+
auto specialCels = LoadCelWithStatus(active.specialCelsPath.c_str(), SpecialCelWidth);
1409+
if (!specialCels.has_value()) {
1410+
if (active.specialCelsPath != tristramAssets.specialCelsPath) {
1411+
ASSIGN_OR_RETURN(pSpecialCels, LoadCelWithStatus(tristramAssets.specialCelsPath.c_str(), SpecialCelWidth));
1412+
} else {
1413+
return tl::make_unexpected(std::move(specialCels.error()));
1414+
}
1415+
} else {
1416+
pSpecialCels = std::move(*specialCels);
1417+
}
14081418
return {};
14091419
}
14101420
case DTYPE_CATHEDRAL:

Source/loadsave.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2474,6 +2474,11 @@ tl::expected<void, std::string> LoadGame(bool firstflag)
24742474
{
24752475
FreeGameMem();
24762476

2477+
// Ensure Tristram is always registered before any level asset loading.
2478+
// For new games this is done by InitLevels() before RunGameLoop, but the
2479+
// load-game path skips that block, so we must initialize here.
2480+
InitializeTristram();
2481+
24772482
LoadHelper file(OpenSaveArchive(gSaveNumber), "game");
24782483
if (!file.IsValid()) {
24792484
return tl::make_unexpected(std::string(_("Unable to open save file archive")));

Source/stores.cpp

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -77,30 +77,20 @@ std::vector<std::pair<std::string, std::vector<TownerDialogOption>>> ExtraTowner
7777

7878
const char *TownerNameForTalkID(TalkID s)
7979
{
80-
const auto lookup = [](const _talker_id id) -> const char * {
81-
auto it = TownerShortNames.find(id);
82-
return it != TownerShortNames.end() ? it->second : nullptr;
83-
};
80+
_talker_id townerId;
8481
switch (s) {
85-
case TalkID::Smith:
86-
return lookup(TOWN_SMITH);
87-
case TalkID::Witch:
88-
return lookup(TOWN_WITCH);
89-
case TalkID::Boy:
90-
return lookup(TOWN_PEGBOY);
91-
case TalkID::Healer:
92-
return lookup(TOWN_HEALER);
93-
case TalkID::Storyteller:
94-
return lookup(TOWN_STORY);
95-
case TalkID::Tavern:
96-
return lookup(TOWN_TAVERN);
97-
case TalkID::Drunk:
98-
return lookup(TOWN_DRUNK);
99-
case TalkID::Barmaid:
100-
return lookup(TOWN_BMAID);
101-
default:
102-
return nullptr;
103-
}
82+
case TalkID::Smith: townerId = TOWN_SMITH; break;
83+
case TalkID::Witch: townerId = TOWN_WITCH; break;
84+
case TalkID::Boy: townerId = TOWN_PEGBOY; break;
85+
case TalkID::Healer: townerId = TOWN_HEALER; break;
86+
case TalkID::Storyteller: townerId = TOWN_STORY; break;
87+
case TalkID::Tavern: townerId = TOWN_TAVERN; break;
88+
case TalkID::Drunk: townerId = TOWN_DRUNK; break;
89+
case TalkID::Barmaid: townerId = TOWN_BMAID; break;
90+
default: return nullptr;
91+
}
92+
const auto it = TownerShortNames.find(townerId);
93+
return it != TownerShortNames.end() ? it->second : nullptr;
10494
}
10595

10696
/** Finds the entry for a towner in ExtraTownerOptions, or nullptr if none. */

0 commit comments

Comments
 (0)