From 65f63e862cb08da9861695a45f452b85618ba744 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Thu, 16 May 2024 15:14:36 +0000 Subject: [PATCH] Tweaks to modding docs & error reporting based on discovered issues --- docs/modders/Map_Objects/Rewardable.md | 7 ++++++- lib/mapObjectConstructors/CRewardableConstructor.cpp | 8 +++++++- lib/modding/IdentifierStorage.cpp | 6 +++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/docs/modders/Map_Objects/Rewardable.md b/docs/modders/Map_Objects/Rewardable.md index a2895e284..ade882337 100644 --- a/docs/modders/Map_Objects/Rewardable.md +++ b/docs/modders/Map_Objects/Rewardable.md @@ -230,7 +230,12 @@ This property describes how object state should be reset. Objects without this f ## Appear Chance definition This property describes chance for reward to be selected. -When object is initialized on map load, game will roll a "dice" - random number in range 0-99, and pick all awards that have appear chance within selected number +When object is initialized on map load, game will roll a "dice" - random number in range 0-99, and pick all awards that have appear chance within selected number. +Note that object that uses appearChance MUST have continious range for every value in 0-99 range. For example, object with 3 different rewards may want to define them as +- `"min" : 0, "max" : 33` +- `"min" : 33, "max" : 66` +- `"min" : 66, "max" : 100` +In other words, min chance of second reward must be equal to max chance of previous reward ```jsonc "appearChance": diff --git a/lib/mapObjectConstructors/CRewardableConstructor.cpp b/lib/mapObjectConstructors/CRewardableConstructor.cpp index 72d61e796..83f24b01e 100644 --- a/lib/mapObjectConstructors/CRewardableConstructor.cpp +++ b/lib/mapObjectConstructors/CRewardableConstructor.cpp @@ -53,7 +53,13 @@ void CRewardableConstructor::configureObject(CGObjectInstance * object, CRandomG bonus.sid = BonusSourceID(rewardableObject->ID); } } - assert(!rewardableObject->configuration.info.empty()); + if (rewardableObject->configuration.info.empty()) + { + if (objectInfo.getParameters()["rewards"].isNull()) + logMod->error("Object %s has invalid configuration! No defined rewards found!", getJsonKey()); + else + logMod->error("Object %s has invalid configuration! Make sure that defined appear chances are continious!", getJsonKey()); + } } } diff --git a/lib/modding/IdentifierStorage.cpp b/lib/modding/IdentifierStorage.cpp index e07af3eba..09b0eed98 100644 --- a/lib/modding/IdentifierStorage.cpp +++ b/lib/modding/IdentifierStorage.cpp @@ -333,9 +333,13 @@ void CIdentifierStorage::registerObject(const std::string & scope, const std::st std::pair mapping = std::make_pair(fullID, data); if(!vstd::containsMapping(registeredObjects, mapping)) { - logMod->trace("registered %s as %s:%s", fullID, scope, identifier); + logMod->trace("registered '%s' as %s:%s", fullID, scope, identifier); registeredObjects.insert(mapping); } + else + { + logMod->trace("Duplicate object '%s' found!", fullID); + } } std::vector CIdentifierStorage::getPossibleIdentifiers(const ObjectCallback & request) const