This commit is contained in:
Christoph Oelckers 2016-09-04 01:46:49 +02:00
commit 4eda5f841e

View file

@ -3464,6 +3464,78 @@ class CommandIfWaterLevel : public SBarInfoNegatableFlowControl
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
class CommandIfCVarInt : public SBarInfoNegatableFlowControl
{
public:
CommandIfCVarInt(SBarInfo *script) : SBarInfoNegatableFlowControl(script),
equalcomp(false)
{
}
void ParseNegatable(FScanner &sc, bool fullScreenOffsets)
{
if(!sc.CheckToken(TK_StringConst))
{
sc.MustGetToken(TK_Identifier);
}
cvarname = sc.String;
cvar = FindCVar(cvarname, nullptr);
if (cvar != nullptr)
{
ECVarType cvartype = cvar->GetRealType();
if (cvartype == CVAR_Bool || cvartype == CVAR_Int)
{
sc.MustGetToken(',');
sc.MustGetToken(TK_IntConst);
value = sc.Number;
if (sc.CheckToken(','))
{
sc.MustGetToken(TK_Identifier);
if(sc.Compare("equal"))
{
equalcomp = true;
}
}
}
else
{
sc.ScriptError("Type mismatch: console variable '%s' is not of type 'bool' or 'int'.", cvarname);
}
}
else
{
sc.ScriptError("Unknown console variable '%s'.", cvarname);
}
}
void Tick(const SBarInfoMainBlock *block, const DSBarInfo *statusBar, bool hudChanged)
{
SBarInfoNegatableFlowControl::Tick(block, statusBar, hudChanged);
bool result = false;
cvar = GetCVar(statusBar->CPlayer->mo, cvarname);
if (cvar != nullptr)
{
int cvarvalue = cvar->GetGenericRep(CVAR_Int).Int;
result = equalcomp ? cvarvalue == value : cvarvalue >= value;
}
SetTruth(result, block, statusBar);
}
protected:
FString cvarname;
FBaseCVar *cvar;
int value;
bool equalcomp;
};
////////////////////////////////////////////////////////////////////////////////
static const char *SBarInfoCommandNames[] = static const char *SBarInfoCommandNames[] =
{ {
"drawimage", "drawnumber", "drawswitchableimage", "drawimage", "drawnumber", "drawswitchableimage",
@ -3474,7 +3546,7 @@ static const char *SBarInfoCommandNames[] =
"isselected", "usesammo", "usessecondaryammo", "isselected", "usesammo", "usessecondaryammo",
"hasweaponpiece", "inventorybarnotvisible", "hasweaponpiece", "inventorybarnotvisible",
"weaponammo", "ininventory", "alpha", "ifhealth", "weaponammo", "ininventory", "alpha", "ifhealth",
"ifinvulnerable", "ifwaterlevel", "ifinvulnerable", "ifwaterlevel", "ifcvarint",
NULL NULL
}; };
@ -3488,7 +3560,7 @@ enum SBarInfoCommands
SBARINFO_ISSELECTED, SBARINFO_USESAMMO, SBARINFO_USESSECONDARYAMMO, SBARINFO_ISSELECTED, SBARINFO_USESAMMO, SBARINFO_USESSECONDARYAMMO,
SBARINFO_HASWEAPONPIECE, SBARINFO_INVENTORYBARNOTVISIBLE, SBARINFO_HASWEAPONPIECE, SBARINFO_INVENTORYBARNOTVISIBLE,
SBARINFO_WEAPONAMMO, SBARINFO_ININVENTORY, SBARINFO_ALPHA, SBARINFO_IFHEALTH, SBARINFO_WEAPONAMMO, SBARINFO_ININVENTORY, SBARINFO_ALPHA, SBARINFO_IFHEALTH,
SBARINFO_IFINVULNERABLE, SBARINFO_IFWATERLEVEL, SBARINFO_IFINVULNERABLE, SBARINFO_IFWATERLEVEL, SBARINFO_IFCVARINT,
}; };
SBarInfoCommand *SBarInfoCommandFlowControl::NextCommand(FScanner &sc) SBarInfoCommand *SBarInfoCommandFlowControl::NextCommand(FScanner &sc)
@ -3524,6 +3596,7 @@ SBarInfoCommand *SBarInfoCommandFlowControl::NextCommand(FScanner &sc)
case SBARINFO_IFHEALTH: return new CommandIfHealth(script); case SBARINFO_IFHEALTH: return new CommandIfHealth(script);
case SBARINFO_IFINVULNERABLE: return new CommandIfInvulnerable(script); case SBARINFO_IFINVULNERABLE: return new CommandIfInvulnerable(script);
case SBARINFO_IFWATERLEVEL: return new CommandIfWaterLevel(script); case SBARINFO_IFWATERLEVEL: return new CommandIfWaterLevel(script);
case SBARINFO_IFCVARINT: return new CommandIfCVarInt(script);
} }
sc.ScriptError("Unknown command '%s'.\n", sc.String); sc.ScriptError("Unknown command '%s'.\n", sc.String);