mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-25 22:42:04 +02:00
Fix potential edge cases in TIMES_STACK_SIZE updater
This commit is contained in:
@@ -43,7 +43,7 @@
|
||||
"anyOf" : [
|
||||
{
|
||||
"type" : "string",
|
||||
"enum" : [ "TIMES_HERO_LEVEL", "TIMES_STACK_LEVEL", "DIVIDE_STACK_LEVEL", "BONUS_OWNER_UPDATER", "TIMES_HERO_LEVEL_DIVIDE_STACK_LEVEL" ]
|
||||
"enum" : [ "TIMES_HERO_LEVEL", "TIMES_STACK_LEVEL", "DIVIDE_STACK_LEVEL", "BONUS_OWNER_UPDATER", "TIMES_STACK_SIZE", "TIMES_HERO_LEVEL_DIVIDE_STACK_LEVEL" ]
|
||||
},
|
||||
{
|
||||
"description" : "GROWS_WITH_LEVEL updater",
|
||||
|
||||
@@ -84,15 +84,25 @@ Usage:
|
||||
|
||||
Effect: Updates val to `val = clamp(val * floor(stackSize / stepSize), minimum, maximum)`, where stackSize is total number of creatures in current unit stack
|
||||
|
||||
Parameters `minimum` and `maximum` are optional and can be dropped if not needed
|
||||
Example of short form with default parameters:
|
||||
|
||||
Example:
|
||||
```json
|
||||
"updater" : "TIMES_STACK_SIZE"
|
||||
```
|
||||
|
||||
Example of long form with custom parameters:
|
||||
|
||||
```json
|
||||
"updater" : {
|
||||
"type" : "TIMES_STACK_SIZE",
|
||||
|
||||
// Optional, by default - unlimited
|
||||
"minimum" : 0,
|
||||
|
||||
// Optional, by default - unlimited
|
||||
"maximum" : 100,
|
||||
|
||||
// Optional, by default - 1
|
||||
"stepSize" : 2
|
||||
}
|
||||
```
|
||||
|
||||
@@ -119,7 +119,6 @@ std::shared_ptr<Bonus> TimesStackSizeUpdater::apply(const std::shared_ptr<Bonus>
|
||||
{
|
||||
auto newBonus = std::make_shared<Bonus>(*b);
|
||||
newBonus->val *= std::clamp(count / stepSize, minimum, maximum);
|
||||
newBonus->updater = nullptr; // prevent double-apply
|
||||
return newBonus;
|
||||
}
|
||||
|
||||
|
||||
@@ -89,9 +89,9 @@ class DLL_LINKAGE TimesStackSizeUpdater : public IUpdater
|
||||
{
|
||||
std::shared_ptr<Bonus> apply(const std::shared_ptr<Bonus> & b, int count) const;
|
||||
|
||||
int minimum;
|
||||
int maximum;
|
||||
int stepSize;
|
||||
int minimum = std::numeric_limits<int>::min();
|
||||
int maximum = std::numeric_limits<int>::max();
|
||||
int stepSize = 1;
|
||||
public:
|
||||
TimesStackSizeUpdater() = default;
|
||||
TimesStackSizeUpdater(int minimum, int maximum, int stepSize)
|
||||
|
||||
@@ -386,6 +386,7 @@ static TUpdaterPtr parseUpdater(const JsonNode & updaterJson)
|
||||
{"TIMES_HERO_LEVEL_DIVIDE_STACK_LEVEL", std::make_shared<TimesHeroLevelDivideStackLevelUpdater>()},
|
||||
{"DIVIDE_STACK_LEVEL", std::make_shared<DivideStackLevelUpdater>()},
|
||||
{"TIMES_STACK_LEVEL", std::make_shared<TimesStackLevelUpdater>()},
|
||||
{"TIMES_STACK_SIZE", std::make_shared<TimesStackSizeUpdater>()},
|
||||
{"BONUS_OWNER_UPDATER", std::make_shared<OwnerUpdater>()}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user