- useCondition +

This commit is contained in:
Christoph Oelckers 2021-08-29 00:56:14 +02:00
parent 24a11b3f2f
commit c65c936d27
3 changed files with 33 additions and 22 deletions

View file

@ -756,7 +756,7 @@ void callbackCondition(DBloodActor* actor, int)
evn.index_ = pCond->obj[i].index_; evn.index_ = pCond->obj[i].index_;
evn.cmd = pCond->obj[i].cmd; evn.cmd = pCond->obj[i].cmd;
evn.funcID = kCallbackCondition; evn.funcID = kCallbackCondition;
useCondition(&sprite[pXSprite->reference], pXSprite, evn); useCondition(actor, evn);
} }
evPostActor(actor, pXSprite->busyTime, kCallbackCondition); evPostActor(actor, pXSprite->busyTime, kCallbackCondition);

View file

@ -1165,7 +1165,7 @@ void nnExtProcessSuperSprites()
evn.cmd = (int8_t)pXCond->command; evn.cmd = (int8_t)pXCond->command;
evn.type = OBJ_SPRITE; evn.type = OBJ_SPRITE;
evn.funcID = kCallbackMax; evn.funcID = kCallbackMax;
useCondition(&pCond->actor->s(), pXCond, evn); useCondition(pCond->actor, evn);
} }
else if (pCond->length > 0) else if (pCond->length > 0)
{ {
@ -1178,7 +1178,7 @@ void nnExtProcessSuperSprites()
evn.cmd = pCond->obj[k].cmd; evn.cmd = pCond->obj[k].cmd;
evn.type = pCond->obj[k].type; evn.type = pCond->obj[k].type;
evn.funcID = kCallbackMax; evn.funcID = kCallbackMax;
useCondition(&pCond->actor->s(), pXCond, evn); useCondition(pCond->actor, evn);
} }
} }
@ -5526,7 +5526,7 @@ bool modernTypeOperateSprite(DBloodActor* actor, EVENT event)
case kModernCondition: case kModernCondition:
case kModernConditionFalse: case kModernConditionFalse:
if (!pXSprite->isTriggered) useCondition(pSprite, pXSprite, event); if (!pXSprite->isTriggered) useCondition(actor, event);
return true; return true;
// add spawn random dude feature - works only if at least 2 data fields are not empty. // add spawn random dude feature - works only if at least 2 data fields are not empty.
@ -5742,7 +5742,7 @@ bool modernTypeOperateSprite(DBloodActor* actor, EVENT event)
if (pXSprite->state == 0) SetSpriteState(actor, 1); if (pXSprite->state == 0) SetSpriteState(actor, 1);
[[fallthrough]]; [[fallthrough]];
case kCmdRepeat: case kCmdRepeat:
useRandomItemGen(pSprite, pXSprite); useRandomItemGen(actor);
if (pXSprite->busyTime > 0) if (pXSprite->busyTime > 0)
evPostActor(actor, (120 * pXSprite->busyTime) / 10, kCmdRepeat); evPostActor(actor, (120 * pXSprite->busyTime) / 10, kCmdRepeat);
break; break;
@ -6128,12 +6128,16 @@ void useSequentialTx(DBloodActor* sourceactor, COMMAND_ID cmd, bool setState)
// //
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
int useCondition(spritetype* pSource, XSPRITE* pXSource, EVENT event) int useCondition(DBloodActor* sourceactor, const EVENT& event)
{ {
auto sourceactor = &bloodActors[pSource->index]; spritetype* pSource = &sourceactor->s();
int objType = event.type; auto pXSource = &sourceactor->x();
int objType = event.type;
int objIndex = event.index_; int objIndex = event.index_;
bool srcIsCondition = false; bool srcIsCondition = false;
if (objType == OBJ_SPRITE && event.actor == nullptr) return -1;
if (objType == OBJ_SPRITE) objIndex = event.actor->s().index; // need this below for calling nnExtTriggerObject
if (objType == OBJ_SPRITE && event.actor != sourceactor) if (objType == OBJ_SPRITE && event.actor != sourceactor)
srcIsCondition = (sprite[objIndex].type == kModernCondition || sprite[objIndex].type == kModernConditionFalse); srcIsCondition = (sprite[objIndex].type == kModernCondition || sprite[objIndex].type == kModernConditionFalse);
@ -6196,7 +6200,7 @@ int useCondition(spritetype* pSource, XSPRITE* pXSource, EVENT event)
// send command to rx bucket // send command to rx bucket
if (pXSource->txID) if (pXSource->txID)
evSendActor(&bloodActors[pSource->index], pXSource->txID, (COMMAND_ID)pXSource->command); evSendActor(sourceactor, pXSource->txID, (COMMAND_ID)pXSource->command);
if (pSource->flags) { if (pSource->flags) {
@ -6219,14 +6223,26 @@ int useCondition(spritetype* pSource, XSPRITE* pXSource, EVENT event)
return pXSource->state; return pXSource->state;
} }
void useRandomItemGen(spritetype* pSource, XSPRITE* pXSource) { //---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void useRandomItemGen(DBloodActor* actor)
{
spritetype* pSource = &actor->s();
XSPRITE* pXSource = &actor->x();
// let's first search for previously dropped items and remove it // let's first search for previously dropped items and remove it
if (pXSource->dropMsg > 0) { if (pXSource->dropMsg > 0)
{
BloodStatIterator it(kStatItem); BloodStatIterator it(kStatItem);
while (auto iactor = it.Next()) while (auto iactor = it.Next())
{ {
spritetype* pItem = &iactor->s(); spritetype* pItem = &iactor->s();
if ((unsigned int)pItem->type == pXSource->dropMsg && pItem->x == pSource->x && pItem->y == pSource->y && pItem->z == pSource->z) { if ((unsigned int)pItem->type == pXSource->dropMsg && pItem->x == pSource->x && pItem->y == pSource->y && pItem->z == pSource->z)
{
gFX.fxSpawnActor((FX_ID)29, pSource->sectnum, pSource->x, pSource->y, pSource->z, 0); gFX.fxSpawnActor((FX_ID)29, pSource->sectnum, pSource->x, pSource->y, pSource->z, 0);
pItem->type = kSpriteDecoration; pItem->type = kSpriteDecoration;
actPostSprite(iactor, kStatFree); actPostSprite(iactor, kStatFree);
@ -6236,16 +6252,15 @@ void useRandomItemGen(spritetype* pSource, XSPRITE* pXSource) {
} }
// then drop item // then drop item
auto dropactor = randomDropPickupObject(&bloodActors[pSource->index], pXSource->dropMsg); auto dropactor = randomDropPickupObject(actor, pXSource->dropMsg);
if (dropactor != NULL) if (dropactor != nullptr)
{ {
auto pDrop = &dropactor->s(); auto pDrop = &dropactor->s();
clampSprite(pDrop); clampSprite(pDrop);
// check if generator affected by physics // check if generator affected by physics
if (debrisGetIndex(&bloodActors[pSource->index]) != -1) if (debrisGetIndex(actor) != -1)
{ {
dropactor->addX(); dropactor->addX();
int nIndex = debrisGetFreeIndex(); int nIndex = debrisGetFreeIndex();
@ -6258,12 +6273,8 @@ void useRandomItemGen(spritetype* pSource, XSPRITE* pXSource) {
if (nIndex >= gPhysSpritesCount) gPhysSpritesCount++; if (nIndex >= gPhysSpritesCount) gPhysSpritesCount++;
getSpriteMassBySize(dropactor); // create mass cache getSpriteMassBySize(dropactor); // create mass cache
} }
} }
} }
} }
void useUniMissileGen(XSPRITE* pXSource, spritetype* pSprite) { void useUniMissileGen(XSPRITE* pXSource, spritetype* pSprite) {

View file

@ -321,7 +321,7 @@ void aiFightActivateDudes(int rx);
// ------------------------------------------------------------------------- // // ------------------------------------------------------------------------- //
void useSlopeChanger(XSPRITE* pXSource, int objType, int objIndex); void useSlopeChanger(XSPRITE* pXSource, int objType, int objIndex);
void damageSprites(DBloodActor* pXSource, DBloodActor* pSprite); void damageSprites(DBloodActor* pXSource, DBloodActor* pSprite);
void useRandomItemGen(spritetype* pSource, XSPRITE* pXSource); void useRandomItemGen(DBloodActor* pSource);
void useUniMissileGen(XSPRITE* pXSource, spritetype* pSprite); void useUniMissileGen(XSPRITE* pXSource, spritetype* pSprite);
void useSoundGen(XSPRITE* pXSource, spritetype* pSprite); void useSoundGen(XSPRITE* pXSource, spritetype* pSprite);
void useIncDecGen(XSPRITE* pXSource, short objType, int objIndex); void useIncDecGen(XSPRITE* pXSource, short objType, int objIndex);
@ -371,7 +371,7 @@ bool incDecGoalValueIsReached(XSPRITE* pXSprite);
int getSpriteMassBySize(DBloodActor* pSprite); int getSpriteMassBySize(DBloodActor* pSprite);
bool ceilIsTooLow(DBloodActor* pSprite); bool ceilIsTooLow(DBloodActor* pSprite);
void levelEndLevelCustom(int nLevel); void levelEndLevelCustom(int nLevel);
int useCondition(spritetype* pSource, XSPRITE* pXSource, EVENT event); int useCondition(DBloodActor*, const EVENT& event);
bool condPush(XSPRITE* pXSprite, int objType, int objIndex); bool condPush(XSPRITE* pXSprite, int objType, int objIndex);
bool condRestore(XSPRITE* pXSprite); bool condRestore(XSPRITE* pXSprite);
bool condCmp(int val, int arg1, int arg2, int comOp); bool condCmp(int val, int arg1, int arg2, int comOp);