From a6b7ce00c2a92f8c4bd5a050cc4134eaeb27b245 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 21 Jun 2017 11:39:59 +0200 Subject: [PATCH] - made DropItem fully read-only by changing the two places which messed around with DropItem.Amount to use a local variable instead. The pointers themselves should have been declared read-only from the start but for that it is too late, so now all its members are. --- wadsrc/static/zscript/base.txt | 2 +- wadsrc/static/zscript/doom/bossbrain.txt | 14 ++++++++++---- wadsrc/static/zscript/shared/randomspawner.txt | 9 ++++++--- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/wadsrc/static/zscript/base.txt b/wadsrc/static/zscript/base.txt index d6f7f318ea..726e46fccc 100644 --- a/wadsrc/static/zscript/base.txt +++ b/wadsrc/static/zscript/base.txt @@ -449,7 +449,7 @@ struct DropItem native native readonly DropItem Next; native readonly name Name; native readonly int Probability; - native int Amount; + native readonly int Amount; } class SpotState : Object native diff --git a/wadsrc/static/zscript/doom/bossbrain.txt b/wadsrc/static/zscript/doom/bossbrain.txt index 5b87182c9a..fadc280e3d 100644 --- a/wadsrc/static/zscript/doom/bossbrain.txt +++ b/wadsrc/static/zscript/doom/bossbrain.txt @@ -318,11 +318,12 @@ extend class Actor { if (di.Name != 'None') { - if (di.Amount < 0) + int amt = di.Amount; + if (amt < 0) { - di.Amount = 1; // default value is -1, we need a positive value. + amt = 1; // default value is -1, we need a positive value. } - n += di.Amount; // this is how we can weight the list. + n += amt; // this is how we can weight the list. } } di = drop; @@ -331,7 +332,12 @@ extend class Actor { if (di.Name != 'none') { - n -= di.Amount; // logically, none of the -1 values have survived by now. + int amt = di.Amount; + if (amt < 0) + { + amt = 1; + } + n -= amt; } if ((di.Next != null) && (n >= 0)) { diff --git a/wadsrc/static/zscript/shared/randomspawner.txt b/wadsrc/static/zscript/shared/randomspawner.txt index b6e28cc371..7488fdd4d1 100644 --- a/wadsrc/static/zscript/shared/randomspawner.txt +++ b/wadsrc/static/zscript/shared/randomspawner.txt @@ -48,8 +48,9 @@ class RandomSpawner : Actor { if (!nomonsters || !IsMonster(di)) { - if (di.Amount < 0) di.Amount = 1; // default value is -1, we need a positive value. - n += di.Amount; // this is how we can weight the list. + int amt = di.Amount; + if (amt < 0) amt = 1; // default value is -1, we need a positive value. + n += amt; // this is how we can weight the list. } di = di.Next; } @@ -69,7 +70,9 @@ class RandomSpawner : Actor if (di.Name != 'None' && (!nomonsters || !IsMonster(di))) { - n -= di.Amount; + int amt = di.Amount; + if (amt < 0) amt = 1; + n -= amt; if ((di.Next != null) && (n > -1)) di = di.Next; else