Skip to content

Commit

Permalink
loadLabels: Tweak logging
Browse files Browse the repository at this point in the history
past-due committed Nov 5, 2023
1 parent d3619af commit c129ab0
Showing 3 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/game.cpp
Original file line number Diff line number Diff line change
@@ -3271,7 +3271,7 @@ bool loadGame(const char *pGameToLoad, bool keepObjects, bool freeMem, bool User
// Load labels
aFileName[fileExten] = '\0';
strcat(aFileName, "labels.json");
loadLabels(aFileName, fixedMapIdToGeneratedId, moduleToBuilding);
loadLabels(aFileName, fixedMapIdToGeneratedId, moduleToBuilding, UserSaveGame);

//if user save game then reset the time - BEWARE IF YOU USE IT
if ((gameType == GTYPE_SAVE_START) ||
16 changes: 12 additions & 4 deletions src/qtscript.cpp
Original file line number Diff line number Diff line change
@@ -2019,13 +2019,13 @@ bool scripting_engine::saveGroups(nlohmann::json &result, wzapi::scripting_insta
// Label system (function defined in qtscript.h header)
//

bool loadLabels(const char *filename, const std::unordered_map<UDWORD, UDWORD>& fixedMapIdToGeneratedId, std::array<std::unordered_map<UDWORD, UDWORD>, MAX_PLAYER_SLOTS>& moduleToBuilding)
bool loadLabels(const char *filename, const std::unordered_map<UDWORD, UDWORD>& fixedMapIdToGeneratedId, std::array<std::unordered_map<UDWORD, UDWORD>, MAX_PLAYER_SLOTS>& moduleToBuilding, bool UserSaveGame)
{
return scripting_engine::instance().loadLabels(filename, fixedMapIdToGeneratedId, moduleToBuilding);
return scripting_engine::instance().loadLabels(filename, fixedMapIdToGeneratedId, moduleToBuilding, UserSaveGame);
}

// Load labels
bool scripting_engine::loadLabels(const char *filename, const std::unordered_map<UDWORD, UDWORD>& fixedMapIdToGeneratedId, std::array<std::unordered_map<UDWORD, UDWORD>, MAX_PLAYER_SLOTS>& moduleToBuilding)
bool scripting_engine::loadLabels(const char *filename, const std::unordered_map<UDWORD, UDWORD>& fixedMapIdToGeneratedId, std::array<std::unordered_map<UDWORD, UDWORD>, MAX_PLAYER_SLOTS>& moduleToBuilding, bool UserSaveGame)
{
int groupidx = -1;

@@ -2106,7 +2106,15 @@ bool scripting_engine::loadLabels(const char *filename, const std::unordered_map
p.player = player;
p.triggered = ini.value("triggered", -1).toInt(); // deactivated by default
p.subscriber = ini.value("subscriber", ALL_PLAYERS).toInt();
ASSERT(IdToObject((OBJECT_TYPE)p.type, p.id, p.player) != nullptr, "Failed to find object that label references: %s", label.c_str());
auto checkFoundObject = IdToObject((OBJECT_TYPE)p.type, p.id, p.player);
if (!UserSaveGame)
{
ASSERT(checkFoundObject != nullptr, "Failed to find object that label references: %s", label.c_str());
}
else if (checkFoundObject == nullptr)
{
debug(LOG_SAVEGAME, "Failed to find object that label references (probably destroyed before save): %s", label.c_str());
}
labels[label] = p;
}
else if (list[i].startsWith("group"))
4 changes: 2 additions & 2 deletions src/qtscript.h
Original file line number Diff line number Diff line change
@@ -221,7 +221,7 @@ struct generic_script_object
};

/// Load map labels
bool loadLabels(const char *filename, const std::unordered_map<UDWORD, UDWORD>& fixedMapIdToGeneratedId, std::array<std::unordered_map<UDWORD, UDWORD>, MAX_PLAYER_SLOTS>& moduleToBuilding);
bool loadLabels(const char *filename, const std::unordered_map<UDWORD, UDWORD>& fixedMapIdToGeneratedId, std::array<std::unordered_map<UDWORD, UDWORD>, MAX_PLAYER_SLOTS>& moduleToBuilding, bool UserSaveGame);

/// Write map labels to savegame
bool writeLabels(const char *filename);
@@ -319,7 +319,7 @@ class scripting_engine
// MARK: LABELS
public:
/// Load map labels
bool loadLabels(const char *filename, const std::unordered_map<UDWORD, UDWORD>& fixedMapIdToGeneratedId, std::array<std::unordered_map<UDWORD, UDWORD>, MAX_PLAYER_SLOTS>& moduleToBuilding);
bool loadLabels(const char *filename, const std::unordered_map<UDWORD, UDWORD>& fixedMapIdToGeneratedId, std::array<std::unordered_map<UDWORD, UDWORD>, MAX_PLAYER_SLOTS>& moduleToBuilding, bool UserSaveGame);

/// Write map labels to savegame
bool writeLabels(const char *filename);

0 comments on commit c129ab0

Please sign in to comment.