- 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.
This commit is contained in:
Christoph Oelckers 2017-06-21 11:39:59 +02:00
parent bdc99d9768
commit a6b7ce00c2
3 changed files with 17 additions and 8 deletions

View file

@ -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

View file

@ -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))
{

View file

@ -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