2006-06-20 21:21:52 +00:00
|
|
|
/*
|
|
|
|
** thingdef_exp.cpp
|
|
|
|
**
|
|
|
|
** Expression parsing / runtime evaluating support
|
|
|
|
**
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
** Copyright 2005 Jan Cholasta
|
|
|
|
** All rights reserved.
|
|
|
|
**
|
|
|
|
** Redistribution and use in source and binary forms, with or without
|
|
|
|
** modification, are permitted provided that the following conditions
|
|
|
|
** are met:
|
|
|
|
**
|
|
|
|
** 1. Redistributions of source code must retain the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer.
|
|
|
|
** 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer in the
|
|
|
|
** documentation and/or other materials provided with the distribution.
|
|
|
|
** 3. The name of the author may not be used to endorse or promote products
|
|
|
|
** derived from this software without specific prior written permission.
|
|
|
|
** 4. When not used as part of ZDoom or a ZDoom derivative, this code will be
|
|
|
|
** covered by the terms of the GNU General Public License as published by
|
|
|
|
** the Free Software Foundation; either version 2 of the License, or (at
|
|
|
|
** your option) any later version.
|
|
|
|
**
|
|
|
|
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
|
2006-04-16 03:31:40 +00:00
|
|
|
#include "actor.h"
|
2006-04-15 15:00:29 +00:00
|
|
|
#include "sc_man.h"
|
2006-06-20 21:21:52 +00:00
|
|
|
#include "tarray.h"
|
|
|
|
#include "templates.h"
|
|
|
|
#include "vectors.h"
|
|
|
|
#include "cmdlib.h"
|
|
|
|
#include "i_system.h"
|
|
|
|
#include "m_random.h"
|
|
|
|
#include "a_pickups.h"
|
2006-08-16 20:56:06 +00:00
|
|
|
#include "thingdef.h"
|
|
|
|
#include "p_lnspec.h"
|
2006-06-20 21:21:52 +00:00
|
|
|
|
|
|
|
void InitExpressions ();
|
|
|
|
void ClearExpressions ();
|
|
|
|
|
2006-11-26 12:13:12 +00:00
|
|
|
FRandom pr_exrandom ("EX_Random");
|
2006-06-20 21:21:52 +00:00
|
|
|
|
|
|
|
enum ExpOp
|
|
|
|
{
|
|
|
|
EX_NOP,
|
|
|
|
|
|
|
|
EX_Const,
|
|
|
|
EX_Var,
|
|
|
|
|
|
|
|
EX_Compl, // ~exp
|
|
|
|
EX_Not, // !exp
|
|
|
|
// EX_Plus, // +exp
|
|
|
|
EX_Minus, // -exp
|
|
|
|
EX_Mul, // exp * exp
|
|
|
|
EX_Div, // exp / exp
|
|
|
|
EX_Mod, // exp % exp
|
|
|
|
EX_Add, // exp + exp
|
|
|
|
EX_Sub, // exp - exp
|
|
|
|
EX_LShift, // exp << exp
|
|
|
|
EX_RShift, // exp >> exp
|
|
|
|
EX_LT, // exp < exp
|
|
|
|
EX_GT, // exp > exp
|
|
|
|
EX_LE, // exp <= exp
|
|
|
|
EX_GE, // exp >= exp
|
|
|
|
EX_Eq, // exp == exp
|
|
|
|
EX_NE, // exp != exp
|
|
|
|
EX_And, // exp & exp
|
|
|
|
EX_Xor, // exp ^ exp
|
|
|
|
EX_Or, // exp | exp
|
|
|
|
EX_LogAnd, // exp && exp
|
|
|
|
EX_LogOr, // exp || exp
|
|
|
|
EX_Cond, // exp ? exp : exp
|
|
|
|
|
|
|
|
EX_Random, // random (min, max)
|
2006-11-26 12:13:12 +00:00
|
|
|
EX_Random2, // random2 ([mask])
|
2006-06-20 21:21:52 +00:00
|
|
|
EX_Sin, // sin (angle)
|
|
|
|
EX_Cos, // cos (angle)
|
2006-08-16 20:56:06 +00:00
|
|
|
EX_ActionSpecial,
|
|
|
|
EX_Right,
|
2006-06-20 21:21:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum ExpValType
|
|
|
|
{
|
|
|
|
VAL_Int,
|
|
|
|
VAL_Float,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ExpVal
|
|
|
|
{
|
|
|
|
ExpValType Type;
|
|
|
|
union
|
|
|
|
{
|
|
|
|
int Int;
|
|
|
|
float Float;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef ExpVal (*ExpVarGet) (AActor *, int);
|
|
|
|
|
|
|
|
ExpVal GetAlpha (AActor *actor, int id)
|
|
|
|
{
|
|
|
|
ExpVal val;
|
|
|
|
val.Type = VAL_Float;
|
|
|
|
val.Float = FIXED2FLOAT (actor->alpha);
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
ExpVal GetAngle (AActor *actor, int id)
|
|
|
|
{
|
|
|
|
ExpVal val;
|
|
|
|
val.Type = VAL_Float;
|
|
|
|
val.Float = (float)actor->angle / ANGLE_1;
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
ExpVal GetArgs (AActor *actor, int id)
|
|
|
|
{
|
|
|
|
ExpVal val;
|
|
|
|
val.Type = VAL_Int;
|
|
|
|
val.Int = actor->args[id];
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
ExpVal GetCeilingZ (AActor *actor, int id)
|
|
|
|
{
|
|
|
|
ExpVal val;
|
|
|
|
val.Type = VAL_Float;
|
|
|
|
val.Float = FIXED2FLOAT (actor->ceilingz);
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
ExpVal GetFloorZ (AActor *actor, int id)
|
|
|
|
{
|
|
|
|
ExpVal val;
|
|
|
|
val.Type = VAL_Float;
|
|
|
|
val.Float = FIXED2FLOAT (actor->floorz);
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
ExpVal GetHealth (AActor *actor, int id)
|
|
|
|
{
|
|
|
|
ExpVal val;
|
|
|
|
val.Type = VAL_Int;
|
|
|
|
val.Int = actor->health;
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
ExpVal GetPitch (AActor *actor, int id)
|
|
|
|
{
|
|
|
|
ExpVal val;
|
|
|
|
val.Type = VAL_Float;
|
|
|
|
val.Float = (float)actor->pitch / ANGLE_1;
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
ExpVal GetSpecial (AActor *actor, int id)
|
|
|
|
{
|
|
|
|
ExpVal val;
|
|
|
|
val.Type = VAL_Int;
|
|
|
|
val.Int = actor->special;
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
ExpVal GetTID (AActor *actor, int id)
|
|
|
|
{
|
|
|
|
ExpVal val;
|
|
|
|
val.Type = VAL_Int;
|
|
|
|
val.Int = actor->tid;
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
ExpVal GetTIDToHate (AActor *actor, int id)
|
|
|
|
{
|
|
|
|
ExpVal val;
|
|
|
|
val.Type = VAL_Int;
|
|
|
|
val.Int = actor->TIDtoHate;
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
ExpVal GetWaterLevel (AActor *actor, int id)
|
|
|
|
{
|
|
|
|
ExpVal val;
|
|
|
|
val.Type = VAL_Int;
|
|
|
|
val.Int = actor->waterlevel;
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
ExpVal GetX (AActor *actor, int id)
|
|
|
|
{
|
|
|
|
ExpVal val;
|
|
|
|
val.Type = VAL_Float;
|
|
|
|
val.Float = FIXED2FLOAT (actor->x);
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
ExpVal GetY (AActor *actor, int id)
|
|
|
|
{
|
|
|
|
ExpVal val;
|
|
|
|
val.Type = VAL_Float;
|
|
|
|
val.Float = FIXED2FLOAT (actor->y);
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
ExpVal GetZ (AActor *actor, int id)
|
|
|
|
{
|
|
|
|
ExpVal val;
|
|
|
|
val.Type = VAL_Float;
|
|
|
|
val.Float = FIXED2FLOAT (actor->z);
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2006-07-16 01:25:29 +00:00
|
|
|
static struct FExpVar
|
2006-06-20 21:21:52 +00:00
|
|
|
{
|
2006-11-29 04:51:16 +00:00
|
|
|
ENamedName name; // identifier
|
2006-06-20 21:21:52 +00:00
|
|
|
int array; // array size (0 if not an array)
|
|
|
|
ExpVarGet get;
|
|
|
|
} ExpVars[] = {
|
2006-11-29 04:51:16 +00:00
|
|
|
{ NAME_Alpha, 0, GetAlpha },
|
|
|
|
{ NAME_Angle, 0, GetAngle },
|
|
|
|
{ NAME_Args, 5, GetArgs },
|
|
|
|
{ NAME_CeilingZ, 0, GetCeilingZ },
|
|
|
|
{ NAME_FloorZ, 0, GetFloorZ },
|
|
|
|
{ NAME_Health, 0, GetHealth },
|
|
|
|
{ NAME_Pitch, 0, GetPitch },
|
|
|
|
{ NAME_Special, 0, GetSpecial },
|
|
|
|
{ NAME_TID, 0, GetTID },
|
|
|
|
{ NAME_TIDtoHate, 0, GetTIDToHate },
|
|
|
|
{ NAME_WaterLevel, 0, GetWaterLevel },
|
|
|
|
{ NAME_X, 0, GetX },
|
|
|
|
{ NAME_Y, 0, GetY },
|
|
|
|
{ NAME_Z, 0, GetZ },
|
2006-06-20 21:21:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ExpData;
|
2006-11-29 04:51:16 +00:00
|
|
|
static ExpVal EvalExpression (ExpData *data, AActor *self, const PClass *cls);
|
2006-04-15 15:00:29 +00:00
|
|
|
|
2006-06-20 21:21:52 +00:00
|
|
|
struct ExpData
|
|
|
|
{
|
|
|
|
ExpData ()
|
|
|
|
{
|
|
|
|
Type = EX_NOP;
|
|
|
|
Value.Type = VAL_Int;
|
|
|
|
Value.Int = 0;
|
2006-11-26 12:13:12 +00:00
|
|
|
RNG = NULL;
|
2006-08-16 20:56:06 +00:00
|
|
|
for (int i = 0; i < 2; i++)
|
2006-06-20 21:21:52 +00:00
|
|
|
Children[i] = NULL;
|
|
|
|
}
|
|
|
|
~ExpData ()
|
|
|
|
{
|
2006-08-16 20:56:06 +00:00
|
|
|
for (int i = 0; i < 2; i++)
|
2006-06-20 21:21:52 +00:00
|
|
|
{
|
|
|
|
if (Children[i])
|
|
|
|
{
|
2006-10-20 01:58:26 +00:00
|
|
|
delete Children[i];
|
2006-06-20 21:21:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Try to evaluate constant expression
|
2006-11-29 04:51:16 +00:00
|
|
|
void EvalConst (const PClass *cls)
|
2006-06-20 21:21:52 +00:00
|
|
|
{
|
|
|
|
if (Type == EX_NOP || Type == EX_Const || Type == EX_Var)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (Type == EX_Compl || Type == EX_Not || /*Type == EX_Plus || */Type == EX_Minus)
|
|
|
|
{
|
|
|
|
if (Children[0]->Type == EX_Const)
|
|
|
|
{
|
2006-11-29 04:51:16 +00:00
|
|
|
Value = EvalExpression (this, NULL, cls);
|
2006-06-20 21:21:52 +00:00
|
|
|
Type = EX_Const;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (Type == EX_Cond)
|
|
|
|
{
|
|
|
|
if (Children[0]->Type == EX_Const)
|
|
|
|
{
|
|
|
|
bool cond = (Children[0]->Value.Type == VAL_Int) ? (Children[0]->Value.Int != 0) : (Children[0]->Value.Float != 0);
|
2006-08-16 20:56:06 +00:00
|
|
|
ExpData *data = Children[1]->Children[cond];
|
|
|
|
delete Children[1]->Children[!cond];
|
|
|
|
delete Children[1];
|
|
|
|
delete Children[0];
|
2006-06-20 21:21:52 +00:00
|
|
|
|
|
|
|
Type = data->Type;
|
|
|
|
Value = data->Value;
|
2006-08-16 20:56:06 +00:00
|
|
|
for (int i = 0; i < 2; i++)
|
2006-06-20 21:21:52 +00:00
|
|
|
{
|
|
|
|
Children[i] = data->Children[i];
|
|
|
|
data->Children[i] = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
delete data;
|
|
|
|
}
|
|
|
|
}
|
2006-10-20 01:58:26 +00:00
|
|
|
else if (Type != EX_Random && Type != EX_Sin && Type != EX_Cos && Type != EX_ActionSpecial)
|
2006-06-20 21:21:52 +00:00
|
|
|
{
|
|
|
|
if (Children[0]->Type == EX_Const && Children[1]->Type == EX_Const)
|
|
|
|
{
|
2006-11-29 04:51:16 +00:00
|
|
|
Value = EvalExpression (this, NULL, NULL);
|
2006-06-20 21:21:52 +00:00
|
|
|
Type = EX_Const;
|
2006-10-21 04:38:57 +00:00
|
|
|
delete Children[0]; Children[0] = NULL;
|
|
|
|
delete Children[1]; Children[1] = NULL;
|
2006-06-20 21:21:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bool Compare (ExpData *other)
|
|
|
|
{
|
|
|
|
if (!other)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (Type != other->Type ||
|
|
|
|
Value.Type != other->Value.Type ||
|
2006-11-26 12:13:12 +00:00
|
|
|
Value.Float != other->Value.Float ||
|
|
|
|
RNG != other->RNG)
|
2006-06-20 21:21:52 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2006-08-16 20:56:06 +00:00
|
|
|
for (int i = 0; i < 2; i++)
|
2006-06-20 21:21:52 +00:00
|
|
|
{
|
|
|
|
if (Children[i] && !Children[i]->Compare (other->Children[i]))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
ExpOp Type;
|
|
|
|
ExpVal Value;
|
2006-08-16 20:56:06 +00:00
|
|
|
ExpData *Children[2];
|
2006-11-26 12:13:12 +00:00
|
|
|
FRandom *RNG; // only used by random and random2
|
2006-06-20 21:21:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
TArray<ExpData *> StateExpressions;
|
|
|
|
|
|
|
|
//
|
|
|
|
// ParseExpression
|
|
|
|
// [GRB] Parses an expression and stores it into Expression array
|
|
|
|
//
|
|
|
|
|
2006-11-29 04:51:16 +00:00
|
|
|
static ExpData *ParseExpressionM (const PClass *cls);
|
|
|
|
static ExpData *ParseExpressionL (const PClass *cls);
|
|
|
|
static ExpData *ParseExpressionK (const PClass *cls);
|
|
|
|
static ExpData *ParseExpressionJ (const PClass *cls);
|
|
|
|
static ExpData *ParseExpressionI (const PClass *cls);
|
|
|
|
static ExpData *ParseExpressionH (const PClass *cls);
|
|
|
|
static ExpData *ParseExpressionG (const PClass *cls);
|
|
|
|
static ExpData *ParseExpressionF (const PClass *cls);
|
|
|
|
static ExpData *ParseExpressionE (const PClass *cls);
|
|
|
|
static ExpData *ParseExpressionD (const PClass *cls);
|
|
|
|
static ExpData *ParseExpressionC (const PClass *cls);
|
|
|
|
static ExpData *ParseExpressionB (const PClass *cls);
|
|
|
|
static ExpData *ParseExpressionA (const PClass *cls);
|
|
|
|
|
|
|
|
int ParseExpression (bool _not, PClass *cls)
|
2006-04-15 15:00:29 +00:00
|
|
|
{
|
2006-06-20 21:21:52 +00:00
|
|
|
static bool inited=false;
|
|
|
|
|
|
|
|
if (!inited)
|
|
|
|
{
|
|
|
|
InitExpressions ();
|
|
|
|
atterm (ClearExpressions);
|
|
|
|
inited=true;
|
|
|
|
}
|
|
|
|
|
2006-11-29 04:51:16 +00:00
|
|
|
ExpData *data = ParseExpressionM (cls);
|
2006-06-20 21:21:52 +00:00
|
|
|
|
2006-04-15 15:00:29 +00:00
|
|
|
if (_not)
|
|
|
|
{
|
2006-06-20 21:21:52 +00:00
|
|
|
ExpData *tmp = data;
|
|
|
|
data = new ExpData;
|
|
|
|
data->Type = EX_Not;
|
|
|
|
data->Children[0] = tmp;
|
2006-11-29 04:51:16 +00:00
|
|
|
data->EvalConst (cls);
|
2006-06-20 21:21:52 +00:00
|
|
|
}
|
|
|
|
|
2006-07-16 01:25:29 +00:00
|
|
|
for (unsigned int i = 0; i < StateExpressions.Size (); i++)
|
2006-06-20 21:21:52 +00:00
|
|
|
{
|
|
|
|
if (StateExpressions[i]->Compare (data))
|
|
|
|
{
|
|
|
|
delete data;
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return StateExpressions.Push (data);
|
|
|
|
}
|
|
|
|
|
2006-11-29 04:51:16 +00:00
|
|
|
static ExpData *ParseExpressionM (const PClass *cls)
|
2006-06-20 21:21:52 +00:00
|
|
|
{
|
2006-11-29 04:51:16 +00:00
|
|
|
ExpData *tmp = ParseExpressionL (cls);
|
2006-06-20 21:21:52 +00:00
|
|
|
|
2006-11-29 04:51:16 +00:00
|
|
|
if (SC_CheckToken('?'))
|
2006-06-20 21:21:52 +00:00
|
|
|
{
|
|
|
|
ExpData *data = new ExpData;
|
|
|
|
data->Type = EX_Cond;
|
|
|
|
data->Children[0] = tmp;
|
2006-08-16 20:56:06 +00:00
|
|
|
ExpData *choices = new ExpData;
|
|
|
|
data->Children[1] = choices;
|
|
|
|
choices->Type = EX_Right;
|
2006-11-29 04:51:16 +00:00
|
|
|
choices->Children[0] = ParseExpressionM (cls);
|
|
|
|
SC_MustGetToken(':');
|
|
|
|
choices->Children[1] = ParseExpressionM (cls);
|
|
|
|
data->EvalConst (cls);
|
2006-06-20 21:21:52 +00:00
|
|
|
return data;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-11-29 04:51:16 +00:00
|
|
|
static ExpData *ParseExpressionL (const PClass *cls)
|
2006-06-20 21:21:52 +00:00
|
|
|
{
|
2006-11-29 04:51:16 +00:00
|
|
|
ExpData *tmp = ParseExpressionK (cls);
|
2006-06-20 21:21:52 +00:00
|
|
|
|
2006-11-29 04:51:16 +00:00
|
|
|
if (SC_CheckToken(TK_OrOr))
|
2006-06-20 21:21:52 +00:00
|
|
|
{
|
|
|
|
ExpData *data = new ExpData;
|
|
|
|
data->Type = EX_LogOr;
|
|
|
|
data->Children[0] = tmp;
|
2006-11-29 04:51:16 +00:00
|
|
|
data->Children[1] = ParseExpressionL (cls);
|
|
|
|
data->EvalConst (cls);
|
2006-06-20 21:21:52 +00:00
|
|
|
return data;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-11-29 04:51:16 +00:00
|
|
|
static ExpData *ParseExpressionK (const PClass *cls)
|
2006-06-20 21:21:52 +00:00
|
|
|
{
|
2006-11-29 04:51:16 +00:00
|
|
|
ExpData *tmp = ParseExpressionJ (cls);
|
2006-06-20 21:21:52 +00:00
|
|
|
|
2006-11-29 04:51:16 +00:00
|
|
|
if (SC_CheckToken(TK_AndAnd))
|
2006-06-20 21:21:52 +00:00
|
|
|
{
|
|
|
|
ExpData *data = new ExpData;
|
|
|
|
data->Type = EX_LogAnd;
|
|
|
|
data->Children[0] = tmp;
|
2006-11-29 04:51:16 +00:00
|
|
|
data->Children[1] = ParseExpressionK (cls);
|
|
|
|
data->EvalConst (cls);
|
2006-06-20 21:21:52 +00:00
|
|
|
return data;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-11-29 04:51:16 +00:00
|
|
|
static ExpData *ParseExpressionJ (const PClass *cls)
|
2006-06-20 21:21:52 +00:00
|
|
|
{
|
2006-11-29 04:51:16 +00:00
|
|
|
ExpData *tmp = ParseExpressionI (cls);
|
2006-06-20 21:21:52 +00:00
|
|
|
|
2006-11-29 04:51:16 +00:00
|
|
|
if (SC_CheckToken('|'))
|
2006-06-20 21:21:52 +00:00
|
|
|
{
|
|
|
|
ExpData *data = new ExpData;
|
|
|
|
data->Type = EX_Or;
|
|
|
|
data->Children[0] = tmp;
|
2006-11-29 04:51:16 +00:00
|
|
|
data->Children[1] = ParseExpressionJ (cls);
|
|
|
|
data->EvalConst (cls);
|
2006-06-20 21:21:52 +00:00
|
|
|
return data;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-11-29 04:51:16 +00:00
|
|
|
static ExpData *ParseExpressionI (const PClass *cls)
|
2006-06-20 21:21:52 +00:00
|
|
|
{
|
2006-11-29 04:51:16 +00:00
|
|
|
ExpData *tmp = ParseExpressionH (cls);
|
2006-06-20 21:21:52 +00:00
|
|
|
|
2006-11-29 04:51:16 +00:00
|
|
|
if (SC_CheckToken('^'))
|
2006-06-20 21:21:52 +00:00
|
|
|
{
|
|
|
|
ExpData *data = new ExpData;
|
|
|
|
data->Type = EX_Xor;
|
|
|
|
data->Children[0] = tmp;
|
2006-11-29 04:51:16 +00:00
|
|
|
data->Children[1] = ParseExpressionI (cls);
|
|
|
|
data->EvalConst (cls);
|
2006-06-20 21:21:52 +00:00
|
|
|
return data;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-11-29 04:51:16 +00:00
|
|
|
static ExpData *ParseExpressionH (const PClass *cls)
|
2006-06-20 21:21:52 +00:00
|
|
|
{
|
2006-11-29 04:51:16 +00:00
|
|
|
ExpData *tmp = ParseExpressionG (cls);
|
2006-06-20 21:21:52 +00:00
|
|
|
|
2006-11-29 04:51:16 +00:00
|
|
|
if (SC_CheckToken('&'))
|
2006-06-20 21:21:52 +00:00
|
|
|
{
|
|
|
|
ExpData *data = new ExpData;
|
|
|
|
data->Type = EX_And;
|
|
|
|
data->Children[0] = tmp;
|
2006-11-29 04:51:16 +00:00
|
|
|
data->Children[1] = ParseExpressionH (cls);
|
|
|
|
data->EvalConst (cls);
|
2006-06-20 21:21:52 +00:00
|
|
|
return data;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-11-29 04:51:16 +00:00
|
|
|
static ExpData *ParseExpressionG (const PClass *cls)
|
2006-06-20 21:21:52 +00:00
|
|
|
{
|
2006-11-29 04:51:16 +00:00
|
|
|
ExpData *tmp = ParseExpressionF (cls);
|
2006-06-20 21:21:52 +00:00
|
|
|
ExpData *data = new ExpData;
|
|
|
|
|
2006-11-29 04:51:16 +00:00
|
|
|
if (SC_CheckToken(TK_Eq))
|
2006-06-20 21:21:52 +00:00
|
|
|
{
|
|
|
|
data->Type = EX_Eq;
|
|
|
|
}
|
2006-11-29 04:51:16 +00:00
|
|
|
else if (SC_CheckToken(TK_Neq))
|
2006-06-20 21:21:52 +00:00
|
|
|
{
|
|
|
|
data->Type = EX_NE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
delete data;
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
data->Children[0] = tmp;
|
2006-11-29 04:51:16 +00:00
|
|
|
data->Children[1] = ParseExpressionG (cls);
|
|
|
|
data->EvalConst (cls);
|
2006-06-20 21:21:52 +00:00
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2006-11-29 04:51:16 +00:00
|
|
|
static ExpData *ParseExpressionF (const PClass *cls)
|
2006-06-20 21:21:52 +00:00
|
|
|
{
|
2006-11-29 04:51:16 +00:00
|
|
|
ExpData *tmp = ParseExpressionE (cls);
|
2006-06-20 21:21:52 +00:00
|
|
|
ExpData *data = new ExpData;
|
|
|
|
|
2006-11-29 04:51:16 +00:00
|
|
|
if (SC_CheckToken('<'))
|
2006-06-20 21:21:52 +00:00
|
|
|
{
|
|
|
|
data->Type = EX_LT;
|
|
|
|
}
|
2006-11-29 04:51:16 +00:00
|
|
|
else if (SC_CheckToken('>'))
|
2006-06-20 21:21:52 +00:00
|
|
|
{
|
|
|
|
data->Type = EX_GT;
|
|
|
|
}
|
2006-11-29 04:51:16 +00:00
|
|
|
else if (SC_CheckToken(TK_Leq))
|
2006-06-20 21:21:52 +00:00
|
|
|
{
|
|
|
|
data->Type = EX_LE;
|
|
|
|
}
|
2006-11-29 04:51:16 +00:00
|
|
|
else if (SC_CheckToken(TK_Geq))
|
2006-06-20 21:21:52 +00:00
|
|
|
{
|
|
|
|
data->Type = EX_GE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
delete data;
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
data->Children[0] = tmp;
|
2006-11-29 04:51:16 +00:00
|
|
|
data->Children[1] = ParseExpressionF (cls);
|
|
|
|
data->EvalConst (cls);
|
2006-06-20 21:21:52 +00:00
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2006-11-29 04:51:16 +00:00
|
|
|
static ExpData *ParseExpressionE (const PClass *cls)
|
2006-06-20 21:21:52 +00:00
|
|
|
{
|
2006-11-29 04:51:16 +00:00
|
|
|
ExpData *tmp = ParseExpressionD (cls);
|
2006-06-20 21:21:52 +00:00
|
|
|
ExpData *data = new ExpData;
|
|
|
|
|
2006-11-29 04:51:16 +00:00
|
|
|
if (SC_CheckToken(TK_LShift))
|
2006-06-20 21:21:52 +00:00
|
|
|
{
|
|
|
|
data->Type = EX_LShift;
|
|
|
|
}
|
2006-11-29 04:51:16 +00:00
|
|
|
else if (SC_CheckToken(TK_RShift))
|
2006-06-20 21:21:52 +00:00
|
|
|
{
|
|
|
|
data->Type = EX_RShift;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
delete data;
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
data->Children[0] = tmp;
|
2006-11-29 04:51:16 +00:00
|
|
|
data->Children[1] = ParseExpressionE (cls);
|
|
|
|
data->EvalConst (cls);
|
2006-06-20 21:21:52 +00:00
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2006-11-29 04:51:16 +00:00
|
|
|
static ExpData *ParseExpressionD (const PClass *cls)
|
2006-06-20 21:21:52 +00:00
|
|
|
{
|
2006-11-29 04:51:16 +00:00
|
|
|
ExpData *tmp = ParseExpressionC (cls);
|
2006-06-20 21:21:52 +00:00
|
|
|
ExpData *data = new ExpData;
|
|
|
|
|
2006-11-29 04:51:16 +00:00
|
|
|
if (SC_CheckToken('+'))
|
2006-06-20 21:21:52 +00:00
|
|
|
{
|
|
|
|
data->Type = EX_Add;
|
|
|
|
}
|
2006-11-29 04:51:16 +00:00
|
|
|
else if (SC_CheckToken('-'))
|
2006-06-20 21:21:52 +00:00
|
|
|
{
|
|
|
|
data->Type = EX_Sub;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
delete data;
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
data->Children[0] = tmp;
|
2006-11-29 04:51:16 +00:00
|
|
|
data->Children[1] = ParseExpressionD (cls);
|
|
|
|
data->EvalConst (cls);
|
2006-06-20 21:21:52 +00:00
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2006-11-29 04:51:16 +00:00
|
|
|
static ExpData *ParseExpressionC (const PClass *cls)
|
2006-06-20 21:21:52 +00:00
|
|
|
{
|
2006-11-29 04:51:16 +00:00
|
|
|
ExpData *tmp = ParseExpressionB (cls);
|
2006-06-20 21:21:52 +00:00
|
|
|
ExpData *data = new ExpData;
|
|
|
|
|
2006-11-29 04:51:16 +00:00
|
|
|
if (SC_CheckToken('*'))
|
2006-06-20 21:21:52 +00:00
|
|
|
{
|
|
|
|
data->Type = EX_Mul;
|
|
|
|
}
|
2006-11-29 04:51:16 +00:00
|
|
|
else if (SC_CheckToken('/'))
|
2006-06-20 21:21:52 +00:00
|
|
|
{
|
|
|
|
data->Type = EX_Div;
|
|
|
|
}
|
2006-11-29 04:51:16 +00:00
|
|
|
else if (SC_CheckToken('%'))
|
2006-06-20 21:21:52 +00:00
|
|
|
{
|
|
|
|
data->Type = EX_Mod;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
delete data;
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
data->Children[0] = tmp;
|
2006-11-29 04:51:16 +00:00
|
|
|
data->Children[1] = ParseExpressionC (cls);
|
|
|
|
data->EvalConst (cls);
|
2006-06-20 21:21:52 +00:00
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2006-11-29 04:51:16 +00:00
|
|
|
static ExpData *ParseExpressionB (const PClass *cls)
|
2006-06-20 21:21:52 +00:00
|
|
|
{
|
|
|
|
ExpData *data = new ExpData;
|
|
|
|
|
2006-11-29 04:51:16 +00:00
|
|
|
if (SC_CheckToken('~'))
|
2006-06-20 21:21:52 +00:00
|
|
|
{
|
|
|
|
data->Type = EX_Compl;
|
|
|
|
}
|
2006-11-29 04:51:16 +00:00
|
|
|
else if (SC_CheckToken('!'))
|
2006-06-20 21:21:52 +00:00
|
|
|
{
|
|
|
|
data->Type = EX_Not;
|
|
|
|
}
|
2006-11-29 04:51:16 +00:00
|
|
|
else if (SC_CheckToken('-'))
|
2006-06-20 21:21:52 +00:00
|
|
|
{
|
|
|
|
data->Type = EX_Minus;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-11-29 04:51:16 +00:00
|
|
|
SC_CheckToken('+');
|
2006-06-20 21:21:52 +00:00
|
|
|
delete data;
|
2006-11-29 04:51:16 +00:00
|
|
|
return ParseExpressionA (cls);
|
2006-06-20 21:21:52 +00:00
|
|
|
}
|
|
|
|
|
2006-11-29 04:51:16 +00:00
|
|
|
data->Children[0] = ParseExpressionA (cls);
|
|
|
|
data->EvalConst (cls);
|
2006-06-20 21:21:52 +00:00
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2006-11-29 04:51:16 +00:00
|
|
|
static ExpData *ParseExpressionA (const PClass *cls)
|
2006-06-20 21:21:52 +00:00
|
|
|
{
|
2006-11-29 04:51:16 +00:00
|
|
|
if (SC_CheckToken('('))
|
2006-06-20 21:21:52 +00:00
|
|
|
{
|
2006-11-29 04:51:16 +00:00
|
|
|
ExpData *data = ParseExpressionM (cls);
|
|
|
|
SC_MustGetToken(')');
|
2006-06-20 21:21:52 +00:00
|
|
|
return data;
|
|
|
|
}
|
2006-11-29 04:51:16 +00:00
|
|
|
else if (SC_CheckToken(TK_IntConst))
|
2006-06-20 21:21:52 +00:00
|
|
|
{
|
|
|
|
ExpData *data = new ExpData;
|
2006-11-29 04:51:16 +00:00
|
|
|
data->Type = EX_Const;
|
|
|
|
data->Value.Type = VAL_Int;
|
|
|
|
data->Value.Int = sc_Number;
|
2006-06-20 21:21:52 +00:00
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
2006-11-29 04:51:16 +00:00
|
|
|
else if (SC_CheckToken(TK_FloatConst))
|
2006-11-26 12:13:12 +00:00
|
|
|
{
|
2006-11-29 04:51:16 +00:00
|
|
|
ExpData *data = new ExpData;
|
|
|
|
data->Type = EX_Const;
|
|
|
|
data->Value.Type = VAL_Float;
|
|
|
|
data->Value.Float = sc_Float;
|
2006-11-26 12:13:12 +00:00
|
|
|
|
2006-11-29 04:51:16 +00:00
|
|
|
return data;
|
|
|
|
}
|
|
|
|
else if (SC_CheckToken(TK_Class))
|
|
|
|
{
|
|
|
|
// Accept class'SomeClassName'.SomeConstant
|
|
|
|
SC_MustGetToken(TK_NameConst);
|
|
|
|
cls = PClass::FindClass (sc_Name);
|
|
|
|
if (cls == NULL)
|
2006-11-26 12:13:12 +00:00
|
|
|
{
|
2006-11-29 04:51:16 +00:00
|
|
|
SC_ScriptError ("Unknown class '%s'", sc_String);
|
2006-11-26 12:13:12 +00:00
|
|
|
}
|
2006-11-29 04:51:16 +00:00
|
|
|
SC_MustGetToken('.');
|
|
|
|
SC_MustGetToken(TK_Identifier);
|
|
|
|
PSymbol *sym = cls->Symbols.FindSymbol (sc_Name, true);
|
|
|
|
if (sym != NULL && sym->SymbolType == SYM_Const)
|
2006-11-26 12:13:12 +00:00
|
|
|
{
|
2006-11-29 04:51:16 +00:00
|
|
|
ExpData *data = new ExpData;
|
|
|
|
data->Type = EX_Const;
|
|
|
|
data->Value.Type = VAL_Int;
|
|
|
|
data->Value.Int = static_cast<PSymbolConst *>(sym)->Value;
|
|
|
|
return data;
|
2006-11-26 12:13:12 +00:00
|
|
|
}
|
2006-11-29 04:51:16 +00:00
|
|
|
else
|
2006-11-26 12:13:12 +00:00
|
|
|
{
|
2006-11-29 04:51:16 +00:00
|
|
|
SC_ScriptError ("'%s' is not a constant value in class '%s'", sc_String, cls->TypeName.GetChars());
|
|
|
|
return NULL;
|
2006-11-26 12:13:12 +00:00
|
|
|
}
|
|
|
|
}
|
2006-11-29 04:51:16 +00:00
|
|
|
else if (SC_CheckToken(TK_Identifier))
|
2006-06-20 21:21:52 +00:00
|
|
|
{
|
2006-11-29 04:51:16 +00:00
|
|
|
switch (sc_Name)
|
|
|
|
{
|
|
|
|
case NAME_Random:
|
|
|
|
{
|
|
|
|
FRandom *rng;
|
2006-06-20 21:21:52 +00:00
|
|
|
|
2006-11-29 04:51:16 +00:00
|
|
|
if (SC_CheckToken('['))
|
|
|
|
{
|
|
|
|
SC_MustGetToken(TK_Identifier);
|
|
|
|
rng = FRandom::StaticFindRNG(sc_String);
|
|
|
|
SC_MustGetToken(']');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rng = &pr_exrandom;
|
|
|
|
}
|
|
|
|
SC_MustGetToken('(');
|
2006-06-20 21:21:52 +00:00
|
|
|
|
2006-11-29 04:51:16 +00:00
|
|
|
ExpData *data = new ExpData;
|
|
|
|
data->Type = EX_Random;
|
|
|
|
data->RNG = rng;
|
2006-06-20 21:21:52 +00:00
|
|
|
|
2006-11-29 04:51:16 +00:00
|
|
|
data->Children[0] = ParseExpressionM (cls);
|
|
|
|
SC_MustGetToken(',');
|
|
|
|
data->Children[1] = ParseExpressionM (cls);
|
|
|
|
SC_MustGetToken(')');
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
break;
|
2006-06-20 21:21:52 +00:00
|
|
|
|
2006-11-29 04:51:16 +00:00
|
|
|
case NAME_Random2:
|
|
|
|
{
|
|
|
|
FRandom *rng;
|
2006-06-20 21:21:52 +00:00
|
|
|
|
2006-11-29 04:51:16 +00:00
|
|
|
if (SC_CheckToken('['))
|
|
|
|
{
|
|
|
|
SC_MustGetToken(TK_Identifier);
|
|
|
|
rng = FRandom::StaticFindRNG(sc_String);
|
|
|
|
SC_MustGetToken(']');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rng = &pr_exrandom;
|
|
|
|
}
|
2006-06-20 21:21:52 +00:00
|
|
|
|
2006-11-29 04:51:16 +00:00
|
|
|
SC_MustGetToken('(');
|
2006-06-20 21:21:52 +00:00
|
|
|
|
2006-11-29 04:51:16 +00:00
|
|
|
ExpData *data = new ExpData;
|
|
|
|
data->Type = EX_Random2;
|
|
|
|
data->RNG = rng;
|
2006-06-20 21:21:52 +00:00
|
|
|
|
2006-11-29 04:51:16 +00:00
|
|
|
if (!SC_CheckToken(')'))
|
|
|
|
{
|
|
|
|
data->Children[0] = ParseExpressionM(cls);
|
|
|
|
SC_MustGetToken(')');
|
|
|
|
}
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
break;
|
2006-06-20 21:21:52 +00:00
|
|
|
|
2006-11-29 04:51:16 +00:00
|
|
|
case NAME_Sin:
|
|
|
|
{
|
|
|
|
SC_MustGetToken('(');
|
2006-08-16 20:56:06 +00:00
|
|
|
|
2006-11-29 04:51:16 +00:00
|
|
|
ExpData *data = new ExpData;
|
|
|
|
data->Type = EX_Sin;
|
2006-06-20 21:21:52 +00:00
|
|
|
|
2006-11-29 04:51:16 +00:00
|
|
|
data->Children[0] = ParseExpressionM (cls);
|
2006-08-16 20:56:06 +00:00
|
|
|
|
2006-11-29 04:51:16 +00:00
|
|
|
SC_MustGetToken(')');
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
break;
|
2006-08-16 20:56:06 +00:00
|
|
|
|
2006-11-29 04:51:16 +00:00
|
|
|
case NAME_Cos:
|
|
|
|
{
|
|
|
|
SC_MustGetToken('(');
|
2006-08-16 20:56:06 +00:00
|
|
|
|
2006-11-29 04:51:16 +00:00
|
|
|
ExpData *data = new ExpData;
|
|
|
|
data->Type = EX_Cos;
|
2006-08-16 20:56:06 +00:00
|
|
|
|
2006-11-29 04:51:16 +00:00
|
|
|
data->Children[0] = ParseExpressionM (cls);
|
2006-08-16 20:56:06 +00:00
|
|
|
|
2006-11-29 04:51:16 +00:00
|
|
|
SC_MustGetToken(')');
|
2006-08-16 20:56:06 +00:00
|
|
|
return data;
|
|
|
|
}
|
2006-11-29 04:51:16 +00:00
|
|
|
break;
|
2006-08-16 20:56:06 +00:00
|
|
|
|
2006-11-29 04:51:16 +00:00
|
|
|
default:
|
2006-06-20 21:21:52 +00:00
|
|
|
{
|
2006-11-29 04:51:16 +00:00
|
|
|
int specnum, min_args, max_args;
|
|
|
|
|
|
|
|
// Check if this is an action special
|
|
|
|
strlwr (sc_String);
|
|
|
|
specnum = FindLineSpecialEx (sc_String, &min_args, &max_args);
|
|
|
|
if (specnum != 0)
|
2006-06-20 21:21:52 +00:00
|
|
|
{
|
2006-11-29 04:51:16 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
SC_MustGetToken('(');
|
|
|
|
|
|
|
|
ExpData *data = new ExpData, **left;
|
|
|
|
data->Type = EX_ActionSpecial;
|
|
|
|
data->Value.Int = specnum;
|
|
|
|
|
|
|
|
data->Children[0] = ParseExpressionM (cls);
|
|
|
|
left = &data->Children[1];
|
|
|
|
|
|
|
|
for (i = 1; i < 5 && SC_CheckToken(','); ++i)
|
|
|
|
{
|
|
|
|
ExpData *right = new ExpData;
|
|
|
|
right->Type = EX_Right;
|
|
|
|
right->Children[0] = ParseExpressionM (cls);
|
|
|
|
*left = right;
|
|
|
|
left = &right->Children[1];
|
|
|
|
}
|
|
|
|
*left = NULL;
|
|
|
|
SC_MustGetToken(')');
|
|
|
|
if (i < min_args)
|
|
|
|
SC_ScriptError ("Not enough arguments to action special");
|
|
|
|
if (i > max_args)
|
|
|
|
SC_ScriptError ("Too many arguments to action special");
|
|
|
|
|
|
|
|
return data;
|
2006-06-20 21:21:52 +00:00
|
|
|
}
|
|
|
|
|
2006-11-29 04:51:16 +00:00
|
|
|
// Check if this is a constant
|
|
|
|
if (cls != NULL)
|
|
|
|
{
|
|
|
|
PSymbol *sym = cls->Symbols.FindSymbol (sc_Name, true);
|
|
|
|
if (sym != NULL && sym->SymbolType == SYM_Const)
|
|
|
|
{
|
|
|
|
ExpData *data = new ExpData;
|
|
|
|
data->Type = EX_Const;
|
|
|
|
data->Value.Type = VAL_Int;
|
|
|
|
data->Value.Int = static_cast<PSymbolConst *>(sym)->Value;
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
}
|
2006-06-20 21:21:52 +00:00
|
|
|
|
2006-11-29 04:51:16 +00:00
|
|
|
// Check if it's a variable we understand
|
|
|
|
int varid = -1;
|
|
|
|
for (size_t i = 0; i < countof(ExpVars); i++)
|
|
|
|
{
|
|
|
|
if (sc_Name == ExpVars[i].name)
|
|
|
|
{
|
|
|
|
varid = (int)i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2006-06-20 21:21:52 +00:00
|
|
|
|
2006-11-29 04:51:16 +00:00
|
|
|
if (varid == -1)
|
|
|
|
SC_ScriptError ("Unknown value '%s'", sc_String);
|
2006-06-20 21:21:52 +00:00
|
|
|
|
2006-11-29 04:51:16 +00:00
|
|
|
ExpData *data = new ExpData;
|
|
|
|
data->Type = EX_Var;
|
|
|
|
data->Value.Type = VAL_Int;
|
|
|
|
data->Value.Int = varid;
|
2006-06-20 21:21:52 +00:00
|
|
|
|
2006-11-29 04:51:16 +00:00
|
|
|
if (ExpVars[varid].array)
|
|
|
|
{
|
|
|
|
SC_MustGetToken('[');
|
|
|
|
data->Children[0] = ParseExpressionM (cls);
|
|
|
|
SC_MustGetToken(']');
|
|
|
|
}
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
break;
|
2006-06-20 21:21:52 +00:00
|
|
|
}
|
2006-11-29 04:51:16 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SC_ScriptError ("Unexpected token %s", SC_TokenName(sc_TokenType, sc_String));
|
|
|
|
return NULL;
|
2006-04-15 15:00:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-06-20 21:21:52 +00:00
|
|
|
//
|
|
|
|
// EvalExpression
|
|
|
|
// [GRB] Evaluates previously stored expression
|
|
|
|
//
|
|
|
|
|
2006-11-29 04:51:16 +00:00
|
|
|
int EvalExpressionI (int id, AActor *self, const PClass *cls)
|
2006-04-15 15:00:29 +00:00
|
|
|
{
|
2006-07-16 01:25:29 +00:00
|
|
|
if (StateExpressions.Size() <= (unsigned int)id) return 0;
|
2006-06-20 21:21:52 +00:00
|
|
|
|
2006-11-29 04:51:16 +00:00
|
|
|
if (cls == NULL && self != NULL)
|
|
|
|
{
|
|
|
|
cls = self->GetClass();
|
|
|
|
}
|
|
|
|
|
|
|
|
ExpVal val = EvalExpression (StateExpressions[id], self, cls);
|
2006-06-20 21:21:52 +00:00
|
|
|
|
|
|
|
switch (val.Type)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
case VAL_Int:
|
|
|
|
return val.Int;
|
|
|
|
case VAL_Float:
|
|
|
|
return (int)val.Float;
|
|
|
|
}
|
2006-04-15 15:00:29 +00:00
|
|
|
}
|
|
|
|
|
2006-11-29 04:51:16 +00:00
|
|
|
bool EvalExpressionN(int id, AActor *self, const PClass *cls)
|
2006-04-15 15:00:29 +00:00
|
|
|
{
|
2006-11-29 04:51:16 +00:00
|
|
|
return !EvalExpressionI(id, self, cls);
|
2006-04-15 15:00:29 +00:00
|
|
|
}
|
|
|
|
|
2006-11-29 04:51:16 +00:00
|
|
|
float EvalExpressionF (int id, AActor *self, const PClass *cls)
|
2006-04-15 15:00:29 +00:00
|
|
|
{
|
2006-07-16 01:25:29 +00:00
|
|
|
if (StateExpressions.Size() <= (unsigned int)id) return 0.f;
|
2006-06-20 21:21:52 +00:00
|
|
|
|
2006-11-29 04:51:16 +00:00
|
|
|
if (cls == NULL && self != NULL)
|
|
|
|
{
|
|
|
|
cls = self->GetClass();
|
|
|
|
}
|
|
|
|
|
|
|
|
ExpVal val = EvalExpression (StateExpressions[id], self, cls);
|
2006-06-20 21:21:52 +00:00
|
|
|
|
|
|
|
switch (val.Type)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
case VAL_Int:
|
|
|
|
return (float)val.Int;
|
|
|
|
case VAL_Float:
|
|
|
|
return val.Float;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-11-29 04:51:16 +00:00
|
|
|
static ExpVal EvalExpression (ExpData *data, AActor *self, const PClass *cls)
|
2006-06-20 21:21:52 +00:00
|
|
|
{
|
|
|
|
ExpVal val;
|
2006-11-29 04:51:16 +00:00
|
|
|
|
2006-06-20 21:21:52 +00:00
|
|
|
switch (data->Type)
|
|
|
|
{
|
2006-07-16 01:25:29 +00:00
|
|
|
case EX_NOP:
|
2006-10-31 00:47:05 +00:00
|
|
|
assert (data->Type != EX_NOP);
|
|
|
|
val = data->Value;
|
2006-07-16 01:25:29 +00:00
|
|
|
break;
|
2006-06-20 21:21:52 +00:00
|
|
|
case EX_Const:
|
|
|
|
val = data->Value;
|
|
|
|
break;
|
|
|
|
case EX_Var:
|
|
|
|
if (!self)
|
|
|
|
{
|
|
|
|
I_FatalError ("Missing actor data");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int id = 0;
|
|
|
|
if (ExpVars[data->Value.Int].array)
|
|
|
|
{
|
2006-11-29 04:51:16 +00:00
|
|
|
ExpVal idval = EvalExpression (data->Children[0], self, cls);
|
2006-06-20 21:21:52 +00:00
|
|
|
id = ((idval.Type == VAL_Int) ? idval.Int : (int)idval.Float) % ExpVars[data->Value.Int].array;
|
|
|
|
}
|
|
|
|
|
|
|
|
val = ExpVars[data->Value.Int].get (self, id);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case EX_Compl:
|
|
|
|
{
|
2006-11-29 04:51:16 +00:00
|
|
|
ExpVal a = EvalExpression (data->Children[0], self, cls);
|
2006-06-20 21:21:52 +00:00
|
|
|
|
|
|
|
val.Type = VAL_Int;
|
|
|
|
val.Int = ~((a.Type == VAL_Int) ? a.Int : (int)a.Float);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case EX_Not:
|
|
|
|
{
|
2006-11-29 04:51:16 +00:00
|
|
|
ExpVal a = EvalExpression (data->Children[0], self, cls);
|
2006-06-20 21:21:52 +00:00
|
|
|
|
|
|
|
val.Type = VAL_Int;
|
|
|
|
val.Int = !((a.Type == VAL_Int) ? a.Int : (int)a.Float);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case EX_Minus:
|
|
|
|
{
|
2006-11-29 04:51:16 +00:00
|
|
|
val = EvalExpression (data->Children[0], self, cls);
|
2006-06-20 21:21:52 +00:00
|
|
|
|
|
|
|
if (val.Type == VAL_Int)
|
|
|
|
val.Int = -val.Int;
|
|
|
|
else
|
|
|
|
val.Float = -val.Float;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case EX_Mul:
|
|
|
|
{
|
2006-11-29 04:51:16 +00:00
|
|
|
ExpVal a = EvalExpression (data->Children[0], self, cls);
|
|
|
|
ExpVal b = EvalExpression (data->Children[1], self, cls);
|
2006-06-20 21:21:52 +00:00
|
|
|
|
|
|
|
if (a.Type == VAL_Int)
|
|
|
|
{
|
|
|
|
if (b.Type == VAL_Int)
|
|
|
|
{
|
|
|
|
val.Type = VAL_Int;
|
|
|
|
val.Int = a.Int * b.Int;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
val.Type = VAL_Float;
|
|
|
|
val.Float = a.Int * b.Float;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
val.Type = VAL_Float;
|
|
|
|
if (b.Type == VAL_Int)
|
|
|
|
val.Float = a.Float * b.Int;
|
|
|
|
else
|
|
|
|
val.Float = a.Float * b.Float;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case EX_Div:
|
|
|
|
{
|
2006-11-29 04:51:16 +00:00
|
|
|
ExpVal a = EvalExpression (data->Children[0], self, cls);
|
|
|
|
ExpVal b = EvalExpression (data->Children[1], self, cls);
|
2006-06-20 21:21:52 +00:00
|
|
|
|
|
|
|
if (b.Int == 0)
|
|
|
|
{
|
|
|
|
I_FatalError ("Division by zero");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (a.Type == VAL_Int)
|
|
|
|
{
|
|
|
|
if (b.Type == VAL_Int)
|
|
|
|
{
|
|
|
|
val.Type = VAL_Int;
|
|
|
|
val.Int = a.Int / b.Int;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
val.Type = VAL_Float;
|
|
|
|
val.Float = a.Int / b.Float;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
val.Type = VAL_Float;
|
|
|
|
if (b.Type == VAL_Int)
|
|
|
|
val.Float = a.Float / b.Int;
|
|
|
|
else
|
|
|
|
val.Float = a.Float / b.Float;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case EX_Mod:
|
|
|
|
{
|
2006-11-29 04:51:16 +00:00
|
|
|
ExpVal a = EvalExpression (data->Children[0], self, cls);
|
|
|
|
ExpVal b = EvalExpression (data->Children[1], self, cls);
|
2006-06-20 21:21:52 +00:00
|
|
|
|
|
|
|
if (b.Int == 0)
|
|
|
|
{
|
|
|
|
I_FatalError ("Division by zero");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (a.Type == VAL_Int)
|
|
|
|
{
|
|
|
|
if (b.Type == VAL_Int)
|
|
|
|
{
|
|
|
|
val.Type = VAL_Int;
|
|
|
|
val.Int = a.Int % b.Int;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
val.Type = VAL_Float;
|
|
|
|
val.Float = fmodf (a.Int, b.Float);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
val.Type = VAL_Float;
|
|
|
|
if (b.Type == VAL_Int)
|
|
|
|
val.Float = fmodf (a.Float, b.Int);
|
|
|
|
else
|
|
|
|
val.Float = fmodf (a.Float, b.Float);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case EX_Add:
|
|
|
|
{
|
2006-11-29 04:51:16 +00:00
|
|
|
ExpVal a = EvalExpression (data->Children[0], self, cls);
|
|
|
|
ExpVal b = EvalExpression (data->Children[1], self, cls);
|
2006-06-20 21:21:52 +00:00
|
|
|
|
|
|
|
if (a.Type == VAL_Int)
|
|
|
|
{
|
|
|
|
if (b.Type == VAL_Int)
|
|
|
|
{
|
|
|
|
val.Type = VAL_Int;
|
|
|
|
val.Int = a.Int + b.Int;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
val.Type = VAL_Float;
|
|
|
|
val.Float = a.Int + b.Float;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
val.Type = VAL_Float;
|
|
|
|
if (b.Type == VAL_Int)
|
|
|
|
val.Float = a.Float + b.Int;
|
|
|
|
else
|
|
|
|
val.Float = a.Float + b.Float;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case EX_Sub:
|
|
|
|
{
|
2006-11-29 04:51:16 +00:00
|
|
|
ExpVal a = EvalExpression (data->Children[0], self, cls);
|
|
|
|
ExpVal b = EvalExpression (data->Children[1], self, cls);
|
2006-06-20 21:21:52 +00:00
|
|
|
|
|
|
|
if (a.Type == VAL_Int)
|
|
|
|
{
|
|
|
|
if (b.Type == VAL_Int)
|
|
|
|
{
|
|
|
|
val.Type = VAL_Int;
|
|
|
|
val.Int = a.Int - b.Int;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
val.Type = VAL_Float;
|
|
|
|
val.Float = a.Int - b.Float;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
val.Type = VAL_Float;
|
|
|
|
if (b.Type == VAL_Int)
|
|
|
|
val.Float = a.Float - b.Int;
|
|
|
|
else
|
|
|
|
val.Float = a.Float - b.Float;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case EX_LShift:
|
|
|
|
{
|
2006-11-29 04:51:16 +00:00
|
|
|
ExpVal a = EvalExpression (data->Children[0], self, cls);
|
|
|
|
ExpVal b = EvalExpression (data->Children[1], self, cls);
|
2006-06-20 21:21:52 +00:00
|
|
|
|
|
|
|
val.Type = VAL_Int;
|
|
|
|
|
|
|
|
if (a.Type == VAL_Int)
|
|
|
|
{
|
|
|
|
if (b.Type == VAL_Int)
|
|
|
|
val.Int = a.Int << b.Int;
|
|
|
|
else
|
|
|
|
val.Int = a.Int << (int)b.Float;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (b.Type == VAL_Int)
|
|
|
|
val.Int = (int)a.Float << b.Int;
|
|
|
|
else
|
|
|
|
val.Int = (int)a.Float << (int)b.Float;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case EX_RShift:
|
|
|
|
{
|
2006-11-29 04:51:16 +00:00
|
|
|
ExpVal a = EvalExpression (data->Children[0], self, cls);
|
|
|
|
ExpVal b = EvalExpression (data->Children[1], self, cls);
|
2006-06-20 21:21:52 +00:00
|
|
|
|
|
|
|
val.Type = VAL_Int;
|
|
|
|
|
|
|
|
if (a.Type == VAL_Int)
|
|
|
|
{
|
|
|
|
if (b.Type == VAL_Int)
|
|
|
|
val.Int = a.Int >> b.Int;
|
|
|
|
else
|
|
|
|
val.Int = a.Int >> (int)b.Float;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (b.Type == VAL_Int)
|
|
|
|
val.Int = (int)a.Float >> b.Int;
|
|
|
|
else
|
|
|
|
val.Int = (int)a.Float >> (int)b.Float;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case EX_LT:
|
|
|
|
{
|
2006-11-29 04:51:16 +00:00
|
|
|
ExpVal a = EvalExpression (data->Children[0], self, cls);
|
|
|
|
ExpVal b = EvalExpression (data->Children[1], self, cls);
|
2006-06-20 21:21:52 +00:00
|
|
|
|
|
|
|
val.Type = VAL_Int;
|
|
|
|
|
|
|
|
if (a.Type == VAL_Int)
|
|
|
|
{
|
|
|
|
if (b.Type == VAL_Int)
|
|
|
|
val.Int = a.Int < b.Int;
|
|
|
|
else
|
|
|
|
val.Int = a.Int < b.Float;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (b.Type == VAL_Int)
|
|
|
|
val.Int = a.Float < b.Int;
|
|
|
|
else
|
|
|
|
val.Int = a.Float < b.Float;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case EX_GT:
|
|
|
|
{
|
2006-11-29 04:51:16 +00:00
|
|
|
ExpVal a = EvalExpression (data->Children[0], self, cls);
|
|
|
|
ExpVal b = EvalExpression (data->Children[1], self, cls);
|
2006-06-20 21:21:52 +00:00
|
|
|
|
|
|
|
val.Type = VAL_Int;
|
|
|
|
|
|
|
|
if (a.Type == VAL_Int)
|
|
|
|
{
|
|
|
|
if (b.Type == VAL_Int)
|
|
|
|
val.Int = a.Int > b.Int;
|
|
|
|
else
|
|
|
|
val.Int = a.Int > b.Float;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (b.Type == VAL_Int)
|
|
|
|
val.Int = a.Float > b.Int;
|
|
|
|
else
|
|
|
|
val.Int = a.Float > b.Float;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case EX_LE:
|
|
|
|
{
|
2006-11-29 04:51:16 +00:00
|
|
|
ExpVal a = EvalExpression (data->Children[0], self, cls);
|
|
|
|
ExpVal b = EvalExpression (data->Children[1], self, cls);
|
2006-06-20 21:21:52 +00:00
|
|
|
|
|
|
|
val.Type = VAL_Int;
|
|
|
|
|
|
|
|
if (a.Type == VAL_Int)
|
|
|
|
{
|
|
|
|
if (b.Type == VAL_Int)
|
|
|
|
val.Int = a.Int <= b.Int;
|
|
|
|
else
|
|
|
|
val.Int = a.Int <= b.Float;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (b.Type == VAL_Int)
|
|
|
|
val.Int = a.Float <= b.Int;
|
|
|
|
else
|
|
|
|
val.Int = a.Float <= b.Float;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case EX_GE:
|
|
|
|
{
|
2006-11-29 04:51:16 +00:00
|
|
|
ExpVal a = EvalExpression (data->Children[0], self, cls);
|
|
|
|
ExpVal b = EvalExpression (data->Children[1], self, cls);
|
2006-06-20 21:21:52 +00:00
|
|
|
|
|
|
|
val.Type = VAL_Int;
|
|
|
|
|
|
|
|
if (a.Type == VAL_Int)
|
|
|
|
{
|
|
|
|
if (b.Type == VAL_Int)
|
|
|
|
val.Int = a.Int >= b.Int;
|
|
|
|
else
|
|
|
|
val.Int = a.Int >= b.Float;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (b.Type == VAL_Int)
|
|
|
|
val.Int = a.Float >= b.Int;
|
|
|
|
else
|
|
|
|
val.Int = a.Float >= b.Float;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case EX_Eq:
|
|
|
|
{
|
2006-11-29 04:51:16 +00:00
|
|
|
ExpVal a = EvalExpression (data->Children[0], self, cls);
|
|
|
|
ExpVal b = EvalExpression (data->Children[1], self, cls);
|
2006-06-20 21:21:52 +00:00
|
|
|
|
|
|
|
val.Type = VAL_Int;
|
|
|
|
|
|
|
|
if (a.Type == VAL_Int)
|
|
|
|
{
|
|
|
|
if (b.Type == VAL_Int)
|
|
|
|
val.Int = a.Int == b.Int;
|
|
|
|
else
|
|
|
|
val.Int = a.Int == b.Float;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (b.Type == VAL_Int)
|
|
|
|
val.Int = a.Float == b.Int;
|
|
|
|
else
|
|
|
|
val.Int = a.Float == b.Float;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case EX_NE:
|
|
|
|
{
|
2006-11-29 04:51:16 +00:00
|
|
|
ExpVal a = EvalExpression (data->Children[0], self, cls);
|
|
|
|
ExpVal b = EvalExpression (data->Children[1], self, cls);
|
2006-06-20 21:21:52 +00:00
|
|
|
|
|
|
|
val.Type = VAL_Int;
|
|
|
|
|
|
|
|
if (a.Type == VAL_Int)
|
|
|
|
{
|
|
|
|
if (b.Type == VAL_Int)
|
|
|
|
val.Int = a.Int != b.Int;
|
|
|
|
else
|
|
|
|
val.Int = a.Int != b.Float;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (b.Type == VAL_Int)
|
|
|
|
val.Int = a.Float != b.Int;
|
|
|
|
else
|
|
|
|
val.Int = a.Float != b.Float;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case EX_And:
|
|
|
|
{
|
2006-11-29 04:51:16 +00:00
|
|
|
ExpVal a = EvalExpression (data->Children[0], self, cls);
|
|
|
|
ExpVal b = EvalExpression (data->Children[1], self, cls);
|
2006-06-20 21:21:52 +00:00
|
|
|
|
|
|
|
val.Type = VAL_Int;
|
|
|
|
|
|
|
|
if (a.Type == VAL_Int)
|
|
|
|
{
|
|
|
|
if (b.Type == VAL_Int)
|
|
|
|
val.Int = a.Int & b.Int;
|
|
|
|
else
|
|
|
|
val.Int = a.Int & (int)b.Float;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (b.Type == VAL_Int)
|
|
|
|
val.Int = (int)a.Float & b.Int;
|
|
|
|
else
|
|
|
|
val.Int = (int)a.Float & (int)b.Float;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case EX_Xor:
|
|
|
|
{
|
2006-11-29 04:51:16 +00:00
|
|
|
ExpVal a = EvalExpression (data->Children[0], self, cls);
|
|
|
|
ExpVal b = EvalExpression (data->Children[1], self, cls);
|
2006-06-20 21:21:52 +00:00
|
|
|
|
|
|
|
val.Type = VAL_Int;
|
|
|
|
|
|
|
|
if (a.Type == VAL_Int)
|
|
|
|
{
|
|
|
|
if (b.Type == VAL_Int)
|
|
|
|
val.Int = a.Int ^ b.Int;
|
|
|
|
else
|
|
|
|
val.Int = a.Int ^ (int)b.Float;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (b.Type == VAL_Int)
|
|
|
|
val.Int = (int)a.Float ^ b.Int;
|
|
|
|
else
|
|
|
|
val.Int = (int)a.Float ^ (int)b.Float;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case EX_Or:
|
|
|
|
{
|
2006-11-29 04:51:16 +00:00
|
|
|
ExpVal a = EvalExpression (data->Children[0], self, cls);
|
|
|
|
ExpVal b = EvalExpression (data->Children[1], self, cls);
|
2006-06-20 21:21:52 +00:00
|
|
|
|
|
|
|
val.Type = VAL_Int;
|
|
|
|
|
|
|
|
if (a.Type == VAL_Int)
|
|
|
|
{
|
|
|
|
if (b.Type == VAL_Int)
|
|
|
|
val.Int = a.Int | b.Int;
|
|
|
|
else
|
|
|
|
val.Int = a.Int | (int)b.Float;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (b.Type == VAL_Int)
|
|
|
|
val.Int = (int)a.Float | b.Int;
|
|
|
|
else
|
|
|
|
val.Int = (int)a.Float | (int)b.Float;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case EX_LogAnd:
|
|
|
|
{
|
2006-11-29 04:51:16 +00:00
|
|
|
ExpVal a = EvalExpression (data->Children[0], self, cls);
|
|
|
|
ExpVal b = EvalExpression (data->Children[1], self, cls);
|
2006-06-20 21:21:52 +00:00
|
|
|
|
|
|
|
val.Type = VAL_Int;
|
|
|
|
|
|
|
|
if (a.Type == VAL_Int)
|
|
|
|
{
|
|
|
|
if (b.Type == VAL_Int)
|
|
|
|
val.Int = a.Int && b.Int;
|
|
|
|
else
|
|
|
|
val.Int = a.Int && b.Float;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (b.Type == VAL_Int)
|
|
|
|
val.Int = a.Float && b.Int;
|
|
|
|
else
|
|
|
|
val.Int = a.Float && b.Float;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case EX_LogOr:
|
|
|
|
{
|
2006-11-29 04:51:16 +00:00
|
|
|
ExpVal a = EvalExpression (data->Children[0], self, cls);
|
|
|
|
ExpVal b = EvalExpression (data->Children[1], self, cls);
|
2006-06-20 21:21:52 +00:00
|
|
|
|
|
|
|
val.Type = VAL_Int;
|
|
|
|
|
|
|
|
if (a.Type == VAL_Int)
|
|
|
|
{
|
|
|
|
if (b.Type == VAL_Int)
|
|
|
|
val.Int = a.Int || b.Int;
|
|
|
|
else
|
|
|
|
val.Int = a.Int || b.Float;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (b.Type == VAL_Int)
|
|
|
|
val.Int = a.Float || b.Int;
|
|
|
|
else
|
|
|
|
val.Int = a.Float || b.Float;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case EX_Cond:
|
|
|
|
{
|
2006-11-29 04:51:16 +00:00
|
|
|
ExpVal a = EvalExpression (data->Children[0], self, cls);
|
2006-06-20 21:21:52 +00:00
|
|
|
|
2006-08-16 20:56:06 +00:00
|
|
|
if (a.Type == VAL_Float)
|
|
|
|
a.Int = (int)a.Float;
|
|
|
|
|
2006-11-29 04:51:16 +00:00
|
|
|
val = EvalExpression (data->Children[1]->Children[!!a.Int], self, cls);
|
2006-06-20 21:21:52 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EX_Random:
|
|
|
|
{
|
2006-11-29 04:51:16 +00:00
|
|
|
ExpVal a = EvalExpression (data->Children[0], self, cls);
|
|
|
|
ExpVal b = EvalExpression (data->Children[1], self, cls);
|
2006-06-20 21:21:52 +00:00
|
|
|
|
|
|
|
int min = (a.Type == VAL_Int) ? a.Int : (int)a.Float;
|
|
|
|
int max = (b.Type == VAL_Int) ? b.Int : (int)b.Float;
|
|
|
|
|
|
|
|
val.Type = VAL_Int;
|
|
|
|
|
|
|
|
if (max < min)
|
|
|
|
{
|
|
|
|
swap (max, min);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (max - min > 255)
|
|
|
|
{
|
|
|
|
int num1,num2,num3,num4;
|
|
|
|
|
2006-11-26 12:13:12 +00:00
|
|
|
num1 = (*data->RNG)();
|
|
|
|
num2 = (*data->RNG)();
|
|
|
|
num3 = (*data->RNG)();
|
|
|
|
num4 = (*data->RNG)();
|
2006-06-20 21:21:52 +00:00
|
|
|
|
|
|
|
val.Int = ((num1 << 24) | (num2 << 16) | (num3 << 8) | num4);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-11-26 12:13:12 +00:00
|
|
|
val.Int = (*data->RNG)();
|
2006-06-20 21:21:52 +00:00
|
|
|
}
|
|
|
|
val.Int %= (max - min + 1);
|
|
|
|
val.Int += min;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2006-11-26 12:13:12 +00:00
|
|
|
case EX_Random2:
|
|
|
|
{
|
|
|
|
if (data->Children[0] == NULL)
|
|
|
|
{
|
|
|
|
val.Type = VAL_Int;
|
|
|
|
val.Int = data->RNG->Random2();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-11-29 04:51:16 +00:00
|
|
|
ExpVal a = EvalExpression (data->Children[0], self, cls);
|
2006-11-26 12:13:12 +00:00
|
|
|
val.Type = VAL_Int;
|
|
|
|
val.Int = data->RNG->Random2((a.Type == VAL_Int) ? a.Int : (int)a.Float);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2006-06-20 21:21:52 +00:00
|
|
|
case EX_Sin:
|
|
|
|
{
|
2006-11-29 04:51:16 +00:00
|
|
|
ExpVal a = EvalExpression (data->Children[0], self, cls);
|
2006-07-16 01:25:29 +00:00
|
|
|
angle_t angle = (a.Type == VAL_Int) ? (a.Int * ANGLE_1) : angle_t(a.Float * ANGLE_1);
|
2006-06-20 21:21:52 +00:00
|
|
|
|
|
|
|
val.Type = VAL_Float;
|
|
|
|
val.Float = FIXED2FLOAT (finesine[angle>>ANGLETOFINESHIFT]);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EX_Cos:
|
|
|
|
{
|
2006-11-29 04:51:16 +00:00
|
|
|
ExpVal a = EvalExpression (data->Children[0], self, cls);
|
2006-07-16 01:25:29 +00:00
|
|
|
angle_t angle = (a.Type == VAL_Int) ? (a.Int * ANGLE_1) : angle_t(a.Float * ANGLE_1);
|
2006-06-20 21:21:52 +00:00
|
|
|
|
|
|
|
val.Type = VAL_Float;
|
|
|
|
val.Float = FIXED2FLOAT (finecosine[angle>>ANGLETOFINESHIFT]);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2006-08-16 20:56:06 +00:00
|
|
|
case EX_ActionSpecial:
|
|
|
|
{
|
|
|
|
int parms[5] = { 0, 0, 0, 0 };
|
|
|
|
int i = 0;
|
|
|
|
ExpData *parm = data;
|
|
|
|
|
|
|
|
while (parm != NULL && i < 5)
|
|
|
|
{
|
2006-11-29 04:51:16 +00:00
|
|
|
ExpVal val = EvalExpression (parm->Children[0], self, cls);
|
2006-08-16 20:56:06 +00:00
|
|
|
if (val.Type == VAL_Int)
|
|
|
|
{
|
|
|
|
parms[i] = val.Int;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
parms[i] = (int)val.Float;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
parm = parm->Children[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
val.Type = VAL_Int;
|
|
|
|
val.Int = LineSpecials[data->Value.Int] (NULL, self, false,
|
|
|
|
parms[0], parms[1], parms[2], parms[3], parms[4]);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EX_Right:
|
|
|
|
// This should never be a top-level expression.
|
|
|
|
assert (data->Type != EX_Right);
|
|
|
|
break;
|
2006-06-20 21:21:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// InitExpressions
|
|
|
|
// [GRB] Set up expression data
|
|
|
|
//
|
|
|
|
|
|
|
|
void InitExpressions ()
|
|
|
|
{
|
|
|
|
// StateExpressions[0] always is const 0;
|
|
|
|
ExpData *data = new ExpData;
|
|
|
|
data->Type = EX_Const;
|
|
|
|
data->Value.Type = VAL_Int;
|
|
|
|
data->Value.Int = 0;
|
|
|
|
|
|
|
|
StateExpressions.Push (data);
|
2006-04-15 15:00:29 +00:00
|
|
|
}
|
|
|
|
|
2006-06-20 21:21:52 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// ClearExpressions
|
|
|
|
// [GRB] Free all expression data
|
|
|
|
//
|
|
|
|
|
|
|
|
void ClearExpressions ()
|
|
|
|
{
|
|
|
|
ExpData *data;
|
|
|
|
|
|
|
|
while (StateExpressions.Pop (data))
|
|
|
|
delete data;
|
|
|
|
}
|