mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2024-11-11 15:22:15 +00:00
- Pick can now hold unlimited numbers to choose from.
- I.e. pick(1,4,12,16)
This commit is contained in:
parent
785f72d6eb
commit
3f3aab42f1
3 changed files with 36 additions and 33 deletions
|
@ -374,6 +374,9 @@ static FxExpression *ParseExpression0 (FScanner &sc, const PClass *cls)
|
|||
else if (sc.CheckToken(TK_Pick))
|
||||
{
|
||||
FRandom *rng;
|
||||
TArray<FxExpression*> list;
|
||||
list.Clear();
|
||||
int index = 0;
|
||||
|
||||
if (sc.CheckToken('['))
|
||||
{
|
||||
|
@ -387,12 +390,17 @@ static FxExpression *ParseExpression0 (FScanner &sc, const PClass *cls)
|
|||
}
|
||||
sc.MustGetToken('(');
|
||||
|
||||
FxExpression *min = ParseExpressionM(sc, cls);
|
||||
sc.MustGetToken(',');
|
||||
FxExpression *max = ParseExpressionM(sc, cls);
|
||||
sc.MustGetToken(')');
|
||||
while (!(sc.CheckToken(')')))
|
||||
{
|
||||
FxExpression *min = ParseExpressionM(sc, cls);
|
||||
list.Push(min);
|
||||
if (sc.CheckToken(')'))
|
||||
break;
|
||||
else
|
||||
sc.MustGetToken(',');
|
||||
}
|
||||
|
||||
return new FxPick(rng, min, max, sc);
|
||||
return new FxPick(rng, list, sc);
|
||||
}
|
||||
else if (sc.CheckToken(TK_FRandom))
|
||||
{
|
||||
|
|
|
@ -563,11 +563,11 @@ class FxPick : public FxExpression
|
|||
{
|
||||
protected:
|
||||
FRandom * rng;
|
||||
FxExpression *min, *max;
|
||||
TArray<FxExpression*> min;
|
||||
|
||||
public:
|
||||
|
||||
FxPick(FRandom *, FxExpression *mi, FxExpression *ma, const FScriptPosition &pos);
|
||||
FxPick(FRandom *, TArray<FxExpression*> mi, const FScriptPosition &pos);
|
||||
~FxPick();
|
||||
FxExpression *Resolve(FCompileContext&);
|
||||
|
||||
|
|
|
@ -1696,15 +1696,17 @@ ExpVal FxRandom::EvalExpression (AActor *self)
|
|||
//
|
||||
//
|
||||
//==========================================================================
|
||||
FxPick::FxPick(FRandom * r, FxExpression *mi, FxExpression *ma, const FScriptPosition &pos)
|
||||
FxPick::FxPick(FRandom * r, TArray<FxExpression*> mi, const FScriptPosition &pos)
|
||||
: FxExpression(pos)
|
||||
{
|
||||
if (mi != NULL && ma != NULL)
|
||||
int index = 0;
|
||||
int max = mi.Size();
|
||||
if (max > 0)
|
||||
{
|
||||
min = new FxIntCast(mi);
|
||||
max = new FxIntCast(ma);
|
||||
for (index = 0; index < max; index++)
|
||||
min.Push(new FxIntCast(mi[index]));
|
||||
}
|
||||
else min = max = NULL;
|
||||
else min.Clear();
|
||||
rng = r;
|
||||
ValueType = VAL_Int;
|
||||
}
|
||||
|
@ -1717,8 +1719,7 @@ FxPick::FxPick(FRandom * r, FxExpression *mi, FxExpression *ma, const FScriptPos
|
|||
|
||||
FxPick::~FxPick()
|
||||
{
|
||||
SAFE_DELETE(min);
|
||||
SAFE_DELETE(max);
|
||||
min.Clear();
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
|
@ -1729,12 +1730,17 @@ FxPick::~FxPick()
|
|||
|
||||
FxExpression *FxPick::Resolve(FCompileContext &ctx)
|
||||
{
|
||||
int index = 0;
|
||||
CHECKRESOLVED();
|
||||
if (min && max)
|
||||
int max = min.Size();
|
||||
if (max > 0)
|
||||
{
|
||||
RESOLVE(min, ctx);
|
||||
RESOLVE(max, ctx);
|
||||
ABORT(min && max);
|
||||
for (index = 0; index < max; index++)
|
||||
{
|
||||
RESOLVE(min[index], ctx);
|
||||
ABORT(min[index]);
|
||||
}
|
||||
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
@ -1750,22 +1756,11 @@ ExpVal FxPick::EvalExpression(AActor *self)
|
|||
{
|
||||
ExpVal val;
|
||||
val.Type = VAL_Int;
|
||||
|
||||
if (min != NULL && max != NULL)
|
||||
int max = min.Size();
|
||||
if (max > 0)
|
||||
{
|
||||
int minval = min->EvalExpression(self).GetInt();
|
||||
int maxval = max->EvalExpression(self).GetInt();
|
||||
|
||||
if (maxval < minval)
|
||||
{
|
||||
swapvalues(maxval, minval);
|
||||
}
|
||||
|
||||
val.Int = (*rng)(2); //rng->operator()(2); //(maxval - minval + 1) + minval;
|
||||
if (val.Int > 0)
|
||||
val.Int = maxval;
|
||||
else
|
||||
val.Int = minval;
|
||||
int select = (*rng)(max);
|
||||
val.Int = min[select]->EvalExpression(self).GetInt();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue