- Added IfHealth based on Blue Shadow's patch.

This commit is contained in:
Braden Obrzut 2014-09-12 00:49:09 -04:00
parent 0223b7f460
commit 27ebfa783e

View file

@ -3431,6 +3431,46 @@ class CommandAlpha : public SBarInfoMainBlock
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
class CommandIfHealth : public SBarInfoCommandFlowControl
{
public:
CommandIfHealth(SBarInfo *script) : SBarInfoCommandFlowControl(script),
negate(false), percentage(false)
{
}
void Parse(FScanner &sc, bool fullScreenOffsets)
{
if (sc.CheckToken(TK_Identifier))
{
if (sc.Compare("not"))
negate = true;
else
sc.ScriptError("Expected 'not', but got '%s' instead.", sc.String);
}
sc.MustGetToken(TK_IntConst);
percentage = sc.CheckToken('%');
hpamount = sc.Number;
SBarInfoCommandFlowControl::Parse(sc, fullScreenOffsets);
}
void Tick(const SBarInfoMainBlock *block, const DSBarInfo *statusBar, bool hudChanged)
{
SBarInfoCommandFlowControl::Tick(block, statusBar, hudChanged);
int phealth = percentage ? statusBar->CPlayer->mo->health * 100 / statusBar->CPlayer->mo->GetMaxHealth() : statusBar->CPlayer->mo->health;
SetTruth((phealth >= hpamount) ^ negate, block, statusBar);
}
protected:
bool negate;
bool percentage;
int hpamount;
};
////////////////////////////////////////////////////////////////////////////////
static const char *SBarInfoCommandNames[] = static const char *SBarInfoCommandNames[] =
{ {
"drawimage", "drawnumber", "drawswitchableimage", "drawimage", "drawnumber", "drawswitchableimage",
@ -3440,7 +3480,7 @@ static const char *SBarInfoCommandNames[] =
"gamemode", "playerclass", "playertype", "aspectratio", "gamemode", "playerclass", "playertype", "aspectratio",
"isselected", "usesammo", "usessecondaryammo", "isselected", "usesammo", "usessecondaryammo",
"hasweaponpiece", "inventorybarnotvisible", "hasweaponpiece", "inventorybarnotvisible",
"weaponammo", "ininventory", "alpha", "weaponammo", "ininventory", "alpha", "ifhealth",
NULL NULL
}; };
@ -3453,7 +3493,7 @@ enum SBarInfoCommands
SBARINFO_GAMEMODE, SBARINFO_PLAYERCLASS, SBARINFO_PLAYERTYPE, SBARINFO_ASPECTRATIO, SBARINFO_GAMEMODE, SBARINFO_PLAYERCLASS, SBARINFO_PLAYERTYPE, SBARINFO_ASPECTRATIO,
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_WEAPONAMMO, SBARINFO_ININVENTORY, SBARINFO_ALPHA, SBARINFO_IFHEALTH,
}; };
SBarInfoCommand *SBarInfoCommandFlowControl::NextCommand(FScanner &sc) SBarInfoCommand *SBarInfoCommandFlowControl::NextCommand(FScanner &sc)
@ -3486,6 +3526,7 @@ SBarInfoCommand *SBarInfoCommandFlowControl::NextCommand(FScanner &sc)
case SBARINFO_WEAPONAMMO: return new CommandWeaponAmmo(script); case SBARINFO_WEAPONAMMO: return new CommandWeaponAmmo(script);
case SBARINFO_ININVENTORY: return new CommandInInventory(script); case SBARINFO_ININVENTORY: return new CommandInInventory(script);
case SBARINFO_ALPHA: return new CommandAlpha(script); case SBARINFO_ALPHA: return new CommandAlpha(script);
case SBARINFO_IFHEALTH: return new CommandIfHealth(script);
} }
sc.ScriptError("Unknown command '%s'.\n", sc.String); sc.ScriptError("Unknown command '%s'.\n", sc.String);