- scriptified a_hereticimp.cpp.

- fixed the comparison against 0 simplification which did not negate the result for '=='.
This commit is contained in:
Christoph Oelckers 2016-11-02 11:44:48 +01:00
parent 8b21719068
commit 570572fcf2
4 changed files with 128 additions and 151 deletions

View file

@ -845,7 +845,6 @@ set( NOT_COMPILED_SOURCE_FILES
g_heretic/a_chicken.cpp g_heretic/a_chicken.cpp
g_heretic/a_dsparil.cpp g_heretic/a_dsparil.cpp
g_heretic/a_hereticartifacts.cpp g_heretic/a_hereticartifacts.cpp
g_heretic/a_hereticimp.cpp
g_heretic/a_hereticweaps.cpp g_heretic/a_hereticweaps.cpp
g_heretic/a_ironlich.cpp g_heretic/a_ironlich.cpp
g_heretic/a_knight.cpp g_heretic/a_knight.cpp

View file

@ -1,96 +0,0 @@
/*
#include "templates.h"
#include "actor.h"
#include "info.h"
#include "m_random.h"
#include "s_sound.h"
#include "p_local.h"
#include "gstrings.h"
#include "vm.h"
*/
static FRandom pr_impmsatk ("ImpMsAttack");
static FRandom pr_imp ("ImpExplode");
//----------------------------------------------------------------------------
//
// PROC A_ImpMsAttack
//
//----------------------------------------------------------------------------
DEFINE_ACTION_FUNCTION(AActor, A_ImpMsAttack)
{
PARAM_SELF_PROLOGUE(AActor);
if (!self->target || pr_impmsatk() > 64)
{
self->SetState (self->SeeState);
return 0;
}
A_SkullAttack(self, 12.);
return 0;
}
//----------------------------------------------------------------------------
//
// PROC A_ImpExplode
//
//----------------------------------------------------------------------------
DEFINE_ACTION_FUNCTION(AActor, A_ImpExplode)
{
PARAM_SELF_PROLOGUE(AActor);
AActor *chunk;
self->flags &= ~MF_NOGRAVITY;
chunk = Spawn("HereticImpChunk1", self->Pos(), ALLOW_REPLACE);
chunk->Vel.X = pr_imp.Random2() / 64.;
chunk->Vel.Y = pr_imp.Random2() / 64.;
chunk->Vel.Z = 9;
chunk = Spawn("HereticImpChunk2", self->Pos(), ALLOW_REPLACE);
chunk->Vel.X = pr_imp.Random2() / 64.;
chunk->Vel.Y = pr_imp.Random2() / 64.;
chunk->Vel.Z = 9;
if (self->special1 == 666)
{ // Extreme death crash
self->SetState (self->FindState("XCrash"));
}
return 0;
}
//----------------------------------------------------------------------------
//
// PROC A_ImpDeath
//
//----------------------------------------------------------------------------
DEFINE_ACTION_FUNCTION(AActor, A_ImpDeath)
{
PARAM_SELF_PROLOGUE(AActor);
self->flags &= ~MF_SOLID;
self->flags2 |= MF2_FLOORCLIP;
return 0;
}
//----------------------------------------------------------------------------
//
// PROC A_ImpXDeath1
//
//----------------------------------------------------------------------------
DEFINE_ACTION_FUNCTION(AActor, A_ImpXDeath1)
{
PARAM_SELF_PROLOGUE(AActor);
self->flags &= ~MF_SOLID;
self->flags |= MF_NOGRAVITY;
self->flags2 |= MF2_FLOORCLIP;
self->special1 = 666; // Flag the crash routine
return 0;
}

View file

@ -3091,7 +3091,9 @@ FxExpression *FxCompareEq::Resolve(FCompileContext& ctx)
} }
else else
{ {
// also simplify comparisons against zero. For these a bool cast on the other value will do just as well and create better code. // also simplify comparisons against zero. For these a bool cast/unary not on the other value will do just as well and create better code.
if (Operator != TK_ApproxEq)
{
if (left->isConstant()) if (left->isConstant())
{ {
bool leftisnull; bool leftisnull;
@ -3115,7 +3117,9 @@ FxExpression *FxCompareEq::Resolve(FCompileContext& ctx)
} }
if (leftisnull) if (leftisnull)
{ {
FxExpression *x = new FxBoolCast(right); FxExpression *x;
if (Operator == TK_Eq) x = new FxUnaryNotBoolean(right);
else x = new FxBoolCast(right);
right = nullptr; right = nullptr;
delete this; delete this;
return x->Resolve(ctx); return x->Resolve(ctx);
@ -3145,13 +3149,16 @@ FxExpression *FxCompareEq::Resolve(FCompileContext& ctx)
} }
if (rightisnull) if (rightisnull)
{ {
FxExpression *x = new FxBoolCast(left); FxExpression *x;
if (Operator == TK_Eq) x = new FxUnaryNotBoolean(left);
else x = new FxBoolCast(left);
left = nullptr; left = nullptr;
delete this; delete this;
return x->Resolve(ctx); return x->Resolve(ctx);
} }
} }
} }
}
Promote(ctx); Promote(ctx);
ValueType = TypeBool; ValueType = TypeBool;
return this; return this;

View file

@ -3,6 +3,8 @@
class HereticImp : Actor class HereticImp : Actor
{ {
bool extremecrash;
Default Default
{ {
Health 40; Health 40;
@ -26,12 +28,6 @@ class HereticImp : Actor
HitObituary "$OB_HERETICIMPHIT"; HitObituary "$OB_HERETICIMPHIT";
} }
native void A_ImpMsAttack();
native void A_ImpDeath();
native void A_ImpXDeath1();
native void A_ImpExplode();
States States
{ {
Spawn: Spawn:
@ -75,6 +71,77 @@ class HereticImp : Actor
IMPX Z -1; IMPX Z -1;
Stop; Stop;
} }
//----------------------------------------------------------------------------
//
// PROC A_ImpMsAttack
//
//----------------------------------------------------------------------------
void A_ImpMsAttack()
{
if (!target || random[ImpMSAtk]() > 64)
{
SetState (SeeState);
return;
}
A_SkullAttack(12);
}
//----------------------------------------------------------------------------
//
// PROC A_ImpExplode
//
//----------------------------------------------------------------------------
void A_ImpExplode()
{
Actor chunk;
bNoGravity = false;
chunk = Spawn("HereticImpChunk1", pos, ALLOW_REPLACE);
chunk.vel.x = random2[ImpExplode]() / 64.;
chunk.vel.y = random2[ImpExplode]() / 64.;
chunk.vel.z = 9;
chunk = Spawn("HereticImpChunk2", pos, ALLOW_REPLACE);
chunk.vel.x = random2[ImpExplode]() / 64.;
chunk.vel.y = random2[ImpExplode]() / 64.;
chunk.vel.z = 9;
if (extremecrash)
{
SetState ("XCrash");
}
}
//----------------------------------------------------------------------------
//
// PROC A_ImpDeath
//
//----------------------------------------------------------------------------
void A_ImpDeath()
{
bSolid = false;
bFloorClip = true;
}
//----------------------------------------------------------------------------
//
// PROC A_ImpXDeath1
//
//----------------------------------------------------------------------------
void A_ImpXDeath1()
{
bSolid = false;
bFloorClip = true;
bNoGravity = true;
extremecrash = true;
}
} }
// Heretic imp leader ------------------------------------------------------- // Heretic imp leader -------------------------------------------------------