Add FRandomPick
- This is RandomPick but for floats. Considering what RandomPick translates into in the scripting branch, I hope I don't regret not using type inference on RandomPick instead of creating a new keyword.
This commit is contained in:
parent
173dbd6bce
commit
8e0151b4c1
5 changed files with 30 additions and 10 deletions
|
|
@ -1774,15 +1774,24 @@ ExpVal FxRandom::EvalExpression (AActor *self)
|
|||
//
|
||||
//
|
||||
//==========================================================================
|
||||
FxRandomPick::FxRandomPick(FRandom * r, TArray<FxExpression*> mi, const FScriptPosition &pos)
|
||||
FxRandomPick::FxRandomPick(FRandom * r, TArray<FxExpression*> mi, bool floaty, const FScriptPosition &pos)
|
||||
: FxExpression(pos)
|
||||
{
|
||||
for (unsigned int index = 0; index < mi.Size(); index++)
|
||||
{
|
||||
min.Push(new FxIntCast(mi[index]));
|
||||
FxExpression *casted;
|
||||
if (floaty)
|
||||
{
|
||||
casted = new FxFloatCast(mi[index]);
|
||||
}
|
||||
else
|
||||
{
|
||||
casted = new FxIntCast(mi[index]);
|
||||
}
|
||||
min.Push(casted);
|
||||
}
|
||||
rng = r;
|
||||
ValueType = VAL_Int;
|
||||
ValueType = floaty ? VAL_Float : VAL_Int;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
|
|
@ -1822,17 +1831,25 @@ FxExpression *FxRandomPick::Resolve(FCompileContext &ctx)
|
|||
ExpVal FxRandomPick::EvalExpression(AActor *self)
|
||||
{
|
||||
ExpVal val;
|
||||
val.Type = VAL_Int;
|
||||
int max = min.Size();
|
||||
if (max > 0)
|
||||
{
|
||||
int select = (*rng)(max);
|
||||
val.Int = min[select]->EvalExpression(self).GetInt();
|
||||
val = min[select]->EvalExpression(self);
|
||||
}
|
||||
/* Is a default even important when the parser requires at least one
|
||||
* choice? Why do we do this? */
|
||||
else if (ValueType == VAL_Int)
|
||||
{
|
||||
val.Type = VAL_Int;
|
||||
val.Int = (*rng)();
|
||||
}
|
||||
else
|
||||
{
|
||||
val.Int = (*rng)();
|
||||
val.Type = VAL_Float;
|
||||
val.Float = (*rng)(0x40000000) / double(0x40000000);
|
||||
}
|
||||
assert(val.Type == ValueType);
|
||||
return val;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue