TWINE: reduced scopes, const + data hiding

This commit is contained in:
Martin Gerhardy 2020-10-25 12:39:40 +01:00
parent 98df1b2020
commit d13e4b4088
13 changed files with 485 additions and 518 deletions

View File

@ -137,7 +137,7 @@ void Actor::setBehaviour(int32 behaviour) {
} }
void Actor::initSpriteActor(int32 actorIdx) { void Actor::initSpriteActor(int32 actorIdx) {
ActorStruct *localActor = &_engine->_scene->sceneActors[actorIdx]; ActorStruct *localActor = _engine->_scene->getActor(actorIdx);
if (localActor->staticFlags.bIsSpriteActor && localActor->sprite != -1 && localActor->entity != localActor->sprite) { if (localActor->staticFlags.bIsSpriteActor && localActor->sprite != -1 && localActor->entity != localActor->sprite) {
const int16 *ptr = (const int16 *)(_engine->_scene->spriteBoundingBoxPtr + localActor->sprite * 16 + 4); const int16 *ptr = (const int16 *)(_engine->_scene->spriteBoundingBoxPtr + localActor->sprite * 16 + 4);
@ -153,7 +153,7 @@ void Actor::initSpriteActor(int32 actorIdx) {
} }
int32 Actor::initBody(int32 bodyIdx, int32 actorIdx) { int32 Actor::initBody(int32 bodyIdx, int32 actorIdx) {
ActorStruct *localActor = &_engine->_scene->sceneActors[actorIdx]; ActorStruct *localActor = _engine->_scene->getActor(actorIdx);
uint8 *bodyPtr = localActor->entityDataPtr; uint8 *bodyPtr = localActor->entityDataPtr;
do { do {
@ -230,7 +230,7 @@ int32 Actor::initBody(int32 bodyIdx, int32 actorIdx) {
} }
void Actor::initModelActor(int32 bodyIdx, int16 actorIdx) { void Actor::initModelActor(int32 bodyIdx, int16 actorIdx) {
ActorStruct *localActor = &_engine->_scene->sceneActors[actorIdx]; ActorStruct *localActor = _engine->_scene->getActor(actorIdx);
if (localActor->staticFlags.bIsSpriteActor) { if (localActor->staticFlags.bIsSpriteActor) {
return; return;
} }
@ -320,7 +320,7 @@ void Actor::initModelActor(int32 bodyIdx, int16 actorIdx) {
} }
void Actor::initActor(int16 actorIdx) { void Actor::initActor(int16 actorIdx) {
ActorStruct *actor = &_engine->_scene->sceneActors[actorIdx]; ActorStruct *actor = _engine->_scene->getActor(actorIdx);
if (actor->staticFlags.bIsSpriteActor) { // if sprite actor if (actor->staticFlags.bIsSpriteActor) { // if sprite actor
if (actor->strengthOfHit != 0) { if (actor->strengthOfHit != 0) {
@ -359,7 +359,7 @@ void Actor::initActor(int16 actorIdx) {
} }
void Actor::resetActor(int16 actorIdx) { void Actor::resetActor(int16 actorIdx) {
ActorStruct *actor = &_engine->_scene->sceneActors[actorIdx]; ActorStruct *actor = _engine->_scene->getActor(actorIdx);
actor->body = 0; actor->body = 0;
actor->anim = kStanding; actor->anim = kStanding;
@ -410,8 +410,7 @@ void Actor::resetActor(int16 actorIdx) {
} }
void Actor::hitActor(int32 actorIdx, int32 actorIdxAttacked, int32 strengthOfHit, int32 angle) { void Actor::hitActor(int32 actorIdx, int32 actorIdxAttacked, int32 strengthOfHit, int32 angle) {
ActorStruct *actor = &_engine->_scene->sceneActors[actorIdxAttacked]; ActorStruct *actor = _engine->_scene->getActor(actorIdxAttacked);
if (actor->life <= 0) { if (actor->life <= 0) {
return; return;
} }
@ -455,7 +454,7 @@ void Actor::hitActor(int32 actorIdx, int32 actorIdxAttacked, int32 strengthOfHit
} }
void Actor::processActorCarrier(int32 actorIdx) { // CheckCarrier void Actor::processActorCarrier(int32 actorIdx) { // CheckCarrier
ActorStruct *actor = &_engine->_scene->sceneActors[actorIdx]; ActorStruct *actor = _engine->_scene->getActor(actorIdx);
if (!actor->staticFlags.bIsCarrierActor) { if (!actor->staticFlags.bIsCarrierActor) {
return; return;
} }
@ -467,7 +466,7 @@ void Actor::processActorCarrier(int32 actorIdx) { // CheckCarrier
} }
void Actor::processActorExtraBonus(int32 actorIdx) { // GiveExtraBonus void Actor::processActorExtraBonus(int32 actorIdx) { // GiveExtraBonus
ActorStruct *actor = &_engine->_scene->sceneActors[actorIdx]; ActorStruct *actor = _engine->_scene->getActor(actorIdx);
int32 numBonus = 0; int32 numBonus = 0;

View File

@ -360,7 +360,7 @@ int32 Animations::getBodyAnimIndex(int32 animIdx, int32 actorIdx) {
uint8 *costumePtr = NULL; uint8 *costumePtr = NULL;
ActorStruct *actor; ActorStruct *actor;
actor = &_engine->_scene->sceneActors[actorIdx]; actor = _engine->_scene->getActor(actorIdx);
bodyPtr = actor->entityDataPtr; bodyPtr = actor->entityDataPtr;
do { do {
@ -529,7 +529,7 @@ void Animations::processAnimActions(int32 actorIdx) {
ActorStruct *actor; ActorStruct *actor;
DataReader *data; DataReader *data;
actor = &_engine->_scene->sceneActors[actorIdx]; actor = _engine->_scene->getActor(actorIdx);
if (!actor->animExtraPtr) { if (!actor->animExtraPtr) {
return; // avoid null pointers return; // avoid null pointers
} }
@ -774,27 +774,28 @@ void Animations::processAnimActions(int32 actorIdx) {
} }
int32 Animations::initAnim(AnimationTypes newAnim, int16 animType, uint8 animExtra, int32 actorIdx) { int32 Animations::initAnim(AnimationTypes newAnim, int16 animType, uint8 animExtra, int32 actorIdx) {
ActorStruct *actor; ActorStruct *actor = _engine->_scene->getActor(actorIdx);
int32 animIndex; if (actor->entity == -1) {
actor = &_engine->_scene->sceneActors[actorIdx];
if (actor->entity == -1)
return 0; return 0;
}
if (actor->staticFlags.bIsSpriteActor) if (actor->staticFlags.bIsSpriteActor) {
return 0; return 0;
}
if (newAnim == actor->anim && actor->previousAnimIdx != -1) if (newAnim == actor->anim && actor->previousAnimIdx != -1) {
return 1; return 1;
}
if (animExtra == 255 && actor->animType != 2) if (animExtra == 255 && actor->animType != 2) {
animExtra = (uint8)actor->anim; animExtra = (uint8)actor->anim;
}
animIndex = getBodyAnimIndex(newAnim, actorIdx); int32 animIndex = getBodyAnimIndex(newAnim, actorIdx);
if (animIndex == -1) if (animIndex == -1) {
animIndex = getBodyAnimIndex(0, actorIdx); animIndex = getBodyAnimIndex(0, actorIdx);
}
if (animType != 4 && actor->animType == 2) { if (animType != 4 && actor->animType == 2) {
actor->animExtra = newAnim; actor->animExtra = newAnim;
@ -811,15 +812,17 @@ int32 Animations::initAnim(AnimationTypes newAnim, int16 animType, uint8 animExt
} }
} }
if (animType == 4) if (animType == 4) {
animType = 2; animType = 2;
}
if (actor->previousAnimIdx == -1) { // if no previous animation if (actor->previousAnimIdx == -1) { // if no previous animation
setAnimAtKeyframe(0, animTable[animIndex], _engine->_actor->bodyTable[actor->entity], &actor->animTimerData); setAnimAtKeyframe(0, animTable[animIndex], _engine->_actor->bodyTable[actor->entity], &actor->animTimerData);
} else { // interpolation between animations } else { // interpolation between animations
animBuffer2 += stockAnimation(animBuffer2, _engine->_actor->bodyTable[actor->entity], &actor->animTimerData); animBuffer2 += stockAnimation(animBuffer2, _engine->_actor->bodyTable[actor->entity], &actor->animTimerData);
if (animBuffer1 + 4488 < animBuffer2) if (animBuffer1 + 4488 < animBuffer2) {
animBuffer2 = animBuffer1; animBuffer2 = animBuffer1;
}
} }
actor->previousAnimIdx = animIndex; actor->previousAnimIdx = animIndex;
@ -845,17 +848,14 @@ int32 Animations::initAnim(AnimationTypes newAnim, int16 animType, uint8 animExt
} }
void Animations::processActorAnimations(int32 actorIdx) { // DoAnim void Animations::processActorAnimations(int32 actorIdx) { // DoAnim
int16 numKeyframe; ActorStruct *actor = _engine->_scene->getActor(actorIdx);
uint8 *animPtr;
ActorStruct *actor;
actor = &_engine->_scene->sceneActors[actorIdx];
currentlyProcessedActorIdx = actorIdx; currentlyProcessedActorIdx = actorIdx;
_engine->_movements->processActorPtr = actor; _engine->_movements->processActorPtr = actor;
if (actor->entity == -1) if (actor->entity == -1) {
return; return;
}
_engine->_movements->previousActorX = actor->collisionX; _engine->_movements->previousActorX = actor->collisionX;
_engine->_movements->previousActorY = actor->collisionY; _engine->_movements->previousActorY = actor->collisionY;
@ -959,7 +959,7 @@ void Animations::processActorAnimations(int32 actorIdx) { // DoAnim
} else { // 3D actor } else { // 3D actor
if (actor->previousAnimIdx != -1) { if (actor->previousAnimIdx != -1) {
int32 keyFramePassed; int32 keyFramePassed;
animPtr = animTable[actor->previousAnimIdx]; uint8 *animPtr = animTable[actor->previousAnimIdx];
keyFramePassed = verifyAnimAtKeyframe(actor->animPosition, animPtr, _engine->_actor->bodyTable[actor->entity], &actor->animTimerData); keyFramePassed = verifyAnimAtKeyframe(actor->animPosition, animPtr, _engine->_actor->bodyTable[actor->entity], &actor->animTimerData);
@ -996,7 +996,7 @@ void Animations::processActorAnimations(int32 actorIdx) { // DoAnim
processAnimActions(actorIdx); processAnimActions(actorIdx);
} }
numKeyframe = actor->animPosition; int16 numKeyframe = actor->animPosition;
if (numKeyframe == getNumKeyframes(animPtr)) { if (numKeyframe == getNumKeyframes(animPtr)) {
actor->dynamicFlags.bIsHitting = 0; actor->dynamicFlags.bIsHitting = 0;
@ -1036,13 +1036,13 @@ void Animations::processActorAnimations(int32 actorIdx) { // DoAnim
// actor standing on another actor // actor standing on another actor
if (actor->standOn != -1) { if (actor->standOn != -1) {
_engine->_movements->processActorX -= _engine->_scene->sceneActors[actor->standOn].collisionX; _engine->_movements->processActorX -= _engine->_scene->getActor(actor->standOn)->collisionX;
_engine->_movements->processActorY -= _engine->_scene->sceneActors[actor->standOn].collisionY; _engine->_movements->processActorY -= _engine->_scene->getActor(actor->standOn)->collisionY;
_engine->_movements->processActorZ -= _engine->_scene->sceneActors[actor->standOn].collisionZ; _engine->_movements->processActorZ -= _engine->_scene->getActor(actor->standOn)->collisionZ;
_engine->_movements->processActorX += _engine->_scene->sceneActors[actor->standOn].x; _engine->_movements->processActorX += _engine->_scene->getActor(actor->standOn)->x;
_engine->_movements->processActorY += _engine->_scene->sceneActors[actor->standOn].y; _engine->_movements->processActorY += _engine->_scene->getActor(actor->standOn)->y;
_engine->_movements->processActorZ += _engine->_scene->sceneActors[actor->standOn].z; _engine->_movements->processActorZ += _engine->_scene->getActor(actor->standOn)->z;
if (!_engine->_collision->standingOnActor(actorIdx, actor->standOn)) { if (!_engine->_collision->standingOnActor(actorIdx, actor->standOn)) {
actor->standOn = -1; // no longer standing on other actor actor->standOn = -1; // no longer standing on other actor

View File

@ -37,57 +37,59 @@ namespace TwinE {
Collision::Collision(TwinEEngine *engine) : _engine(engine) { Collision::Collision(TwinEEngine *engine) : _engine(engine) {
} }
int32 Collision::standingOnActor(int32 actorIdx1, int32 actorIdx2) { // CheckZvOnZv bool Collision::standingOnActor(int32 actorIdx1, int32 actorIdx2) {
int32 x1Left, y1Left, z1Left, x1Right, y1Right, z1Right; const ActorStruct *actor1 = _engine->_scene->getActor(actorIdx1);
int32 x2Left, y2Left, z2Left, x2Right, y2Right, z2Right; const ActorStruct *actor2 = _engine->_scene->getActor(actorIdx2);
ActorStruct *actor1;
ActorStruct *actor2;
actor1 = &_engine->_scene->sceneActors[actorIdx1];
actor2 = &_engine->_scene->sceneActors[actorIdx2];
// Current actor (actor 1) // Current actor (actor 1)
x1Left = _engine->_movements->processActorX + actor1->boudingBox.x.bottomLeft; const int32 x1Left = _engine->_movements->processActorX + actor1->boudingBox.x.bottomLeft;
x1Right = _engine->_movements->processActorX + actor1->boudingBox.x.topRight; const int32 x1Right = _engine->_movements->processActorX + actor1->boudingBox.x.topRight;
y1Left = _engine->_movements->processActorY + actor1->boudingBox.y.bottomLeft; const int32 y1Left = _engine->_movements->processActorY + actor1->boudingBox.y.bottomLeft;
y1Right = _engine->_movements->processActorY + actor1->boudingBox.y.topRight; const int32 y1Right = _engine->_movements->processActorY + actor1->boudingBox.y.topRight;
z1Left = _engine->_movements->processActorZ + actor1->boudingBox.z.bottomLeft; const int32 z1Left = _engine->_movements->processActorZ + actor1->boudingBox.z.bottomLeft;
z1Right = _engine->_movements->processActorZ + actor1->boudingBox.z.topRight; const int32 z1Right = _engine->_movements->processActorZ + actor1->boudingBox.z.topRight;
// Actor 2 // Actor 2
x2Left = actor2->x + actor2->boudingBox.x.bottomLeft; const int32 x2Left = actor2->x + actor2->boudingBox.x.bottomLeft;
x2Right = actor2->x + actor2->boudingBox.x.topRight; const int32 x2Right = actor2->x + actor2->boudingBox.x.topRight;
y2Left = actor2->y + actor2->boudingBox.y.bottomLeft; const int32 y2Left = actor2->y + actor2->boudingBox.y.bottomLeft;
y2Right = actor2->y + actor2->boudingBox.y.topRight; const int32 y2Right = actor2->y + actor2->boudingBox.y.topRight;
z2Left = actor2->z + actor2->boudingBox.z.bottomLeft; const int32 z2Left = actor2->z + actor2->boudingBox.z.bottomLeft;
z2Right = actor2->z + actor2->boudingBox.z.topRight; const int32 z2Right = actor2->z + actor2->boudingBox.z.topRight;
if (x1Left >= x2Right) if (x1Left >= x2Right) {
return 0; // not standing return false; // not standing
}
if (x1Right <= x2Left) if (x1Right <= x2Left) {
return 0; return false;
}
if (y1Left > (y2Right + 1)) if (y1Left > (y2Right + 1)) {
return 0; return false;
}
if (y1Left <= (y2Right - 0x100)) if (y1Left <= (y2Right - 0x100)) {
return 0; return false;
}
if (y1Right <= y2Left) if (y1Right <= y2Left) {
return 0; return false;
}
if (z1Left >= z2Right) if (z1Left >= z2Right) {
return 0; return false;
}
if (z1Right <= z2Left) if (z1Right <= z2Left) {
return 0; return false;
}
return 1; // standing return true; // standing
} }
int32 Collision::getAverageValue(int32 var0, int32 var1, int32 var2, int32 var3) { int32 Collision::getAverageValue(int32 var0, int32 var1, int32 var2, int32 var3) {
@ -103,15 +105,13 @@ int32 Collision::getAverageValue(int32 var0, int32 var1, int32 var2, int32 var3)
} }
void Collision::reajustActorPosition(int32 brickShape) { void Collision::reajustActorPosition(int32 brickShape) {
int32 brkX, brkY, brkZ;
if (!brickShape) { if (!brickShape) {
return; return;
} }
brkX = (collisionX << 9) - 0x100; int32 brkX = (collisionX << 9) - 0x100;
brkY = collisionY << 8; int32 brkY = collisionY << 8;
brkZ = (collisionZ << 9) - 0x100; int32 brkZ = (collisionZ << 9) - 0x100;
// double-side stairs // double-side stairs
if (brickShape >= kDoubleSideStairsTop1 && brickShape <= kDoubleSideStairsRight2) { if (brickShape >= kDoubleSideStairsTop1 && brickShape <= kDoubleSideStairsRight2) {
@ -201,37 +201,32 @@ void Collision::reajustActorPosition(int32 brickShape) {
} }
int32 Collision::checkCollisionWithActors(int32 actorIdx) { int32 Collision::checkCollisionWithActors(int32 actorIdx) {
int32 a, xLeft, xRight, yLeft, yRight, zLeft, zRight; ActorStruct *actor = _engine->_scene->getActor(actorIdx);
ActorStruct *actor, *actorTest;
actor = &_engine->_scene->sceneActors[actorIdx]; int32 xLeft = _engine->_movements->processActorX + actor->boudingBox.x.bottomLeft;
int32 xRight = _engine->_movements->processActorX + actor->boudingBox.x.topRight;
xLeft = _engine->_movements->processActorX + actor->boudingBox.x.bottomLeft; int32 yLeft = _engine->_movements->processActorY + actor->boudingBox.y.bottomLeft;
xRight = _engine->_movements->processActorX + actor->boudingBox.x.topRight; int32 yRight = _engine->_movements->processActorY + actor->boudingBox.y.topRight;
yLeft = _engine->_movements->processActorY + actor->boudingBox.y.bottomLeft; int32 zLeft = _engine->_movements->processActorZ + actor->boudingBox.z.bottomLeft;
yRight = _engine->_movements->processActorY + actor->boudingBox.y.topRight; int32 zRight = _engine->_movements->processActorZ + actor->boudingBox.z.topRight;
zLeft = _engine->_movements->processActorZ + actor->boudingBox.z.bottomLeft;
zRight = _engine->_movements->processActorZ + actor->boudingBox.z.topRight;
actor->collision = -1; actor->collision = -1;
for (a = 0; a < _engine->_scene->sceneNumActors; a++) { for (int32 a = 0; a < _engine->_scene->sceneNumActors; a++) {
actorTest = &_engine->_scene->sceneActors[a]; ActorStruct *actorTest = _engine->_scene->getActor(a);
// aviod current processed actor // aviod current processed actor
if (a != actorIdx && actorTest->entity != -1 && !actor->staticFlags.bComputeLowCollision && actorTest->standOn != actorIdx) { if (a != actorIdx && actorTest->entity != -1 && !actor->staticFlags.bComputeLowCollision && actorTest->standOn != actorIdx) {
int32 xLeftTest, xRightTest, yLeftTest, yRightTest, zLeftTest, zRightTest; const int32 xLeftTest = actorTest->x + actorTest->boudingBox.x.bottomLeft;
const int32 xRightTest = actorTest->x + actorTest->boudingBox.x.topRight;
xLeftTest = actorTest->x + actorTest->boudingBox.x.bottomLeft; const int32 yLeftTest = actorTest->y + actorTest->boudingBox.y.bottomLeft;
xRightTest = actorTest->x + actorTest->boudingBox.x.topRight; const int32 yRightTest = actorTest->y + actorTest->boudingBox.y.topRight;
yLeftTest = actorTest->y + actorTest->boudingBox.y.bottomLeft; const int32 zLeftTest = actorTest->z + actorTest->boudingBox.z.bottomLeft;
yRightTest = actorTest->y + actorTest->boudingBox.y.topRight; const int32 zRightTest = actorTest->z + actorTest->boudingBox.z.topRight;
zLeftTest = actorTest->z + actorTest->boudingBox.z.bottomLeft;
zRightTest = actorTest->z + actorTest->boudingBox.z.topRight;
if (xLeft < xRightTest && xRight > xLeftTest && yLeft < yRightTest && yRight > yLeftTest && zLeft < zRightTest && zRight > zLeftTest) { if (xLeft < xRightTest && xRight > xLeftTest && yLeft < yRightTest && yRight > yLeftTest && zLeft < zRightTest && zRight > zLeftTest) {
actor->collision = a; // mark as collision with actor a actor->collision = a; // mark as collision with actor a
@ -245,9 +240,7 @@ int32 Collision::checkCollisionWithActors(int32 actorIdx) {
_engine->_movements->processActorY = yRightTest - actor->boudingBox.y.bottomLeft + 1; _engine->_movements->processActorY = yRightTest - actor->boudingBox.y.bottomLeft + 1;
actor->standOn = a; actor->standOn = a;
} else { } else {
int32 newAngle; int32 newAngle = _engine->_movements->getAngleAndSetTargetActorDistance(_engine->_movements->processActorX, _engine->_movements->processActorZ, actorTest->x, actorTest->z);
newAngle = _engine->_movements->getAngleAndSetTargetActorDistance(_engine->_movements->processActorX, _engine->_movements->processActorZ, actorTest->x, actorTest->z);
if (actorTest->staticFlags.bCanBePushed && !actor->staticFlags.bCanBePushed) { if (actorTest->staticFlags.bCanBePushed && !actor->staticFlags.bCanBePushed) {
actorTest->lastY = 0; actorTest->lastY = 0;
@ -295,13 +288,11 @@ int32 Collision::checkCollisionWithActors(int32 actorIdx) {
} }
} }
} else { } else {
int32 newAngle;
if (standingOnActor(actorIdx, a)) { if (standingOnActor(actorIdx, a)) {
_engine->_actor->hitActor(actorIdx, a, 1, -1); _engine->_actor->hitActor(actorIdx, a, 1, -1);
} }
newAngle = _engine->_movements->getAngleAndSetTargetActorDistance(_engine->_movements->processActorX, _engine->_movements->processActorZ, actorTest->x, actorTest->z); int32 newAngle = _engine->_movements->getAngleAndSetTargetActorDistance(_engine->_movements->processActorX, _engine->_movements->processActorZ, actorTest->x, actorTest->z);
if (actorTest->staticFlags.bCanBePushed && !actor->staticFlags.bCanBePushed) { if (actorTest->staticFlags.bCanBePushed && !actor->staticFlags.bCanBePushed) {
actorTest->lastY = 0; actorTest->lastY = 0;
@ -363,21 +354,19 @@ int32 Collision::checkCollisionWithActors(int32 actorIdx) {
zLeft = _engine->_renderer->destZ + _engine->_movements->processActorZ + actor->boudingBox.z.bottomLeft; zLeft = _engine->_renderer->destZ + _engine->_movements->processActorZ + actor->boudingBox.z.bottomLeft;
zRight = _engine->_renderer->destZ + _engine->_movements->processActorZ + actor->boudingBox.z.topRight; zRight = _engine->_renderer->destZ + _engine->_movements->processActorZ + actor->boudingBox.z.topRight;
for (a = 0; a < _engine->_scene->sceneNumActors; a++) { for (int32 a = 0; a < _engine->_scene->sceneNumActors; a++) {
actorTest = &_engine->_scene->sceneActors[a]; const ActorStruct *actorTest = _engine->_scene->getActor(a);
// aviod current processed actor // aviod current processed actor
if (a != actorIdx && actorTest->entity != -1 && !actorTest->staticFlags.bIsHidden && actorTest->standOn != actorIdx) { if (a != actorIdx && actorTest->entity != -1 && !actorTest->staticFlags.bIsHidden && actorTest->standOn != actorIdx) {
int32 xLeftTest, xRightTest, yLeftTest, yRightTest, zLeftTest, zRightTest; const int32 xLeftTest = actorTest->x + actorTest->boudingBox.x.bottomLeft;
const int32 xRightTest = actorTest->x + actorTest->boudingBox.x.topRight;
xLeftTest = actorTest->x + actorTest->boudingBox.x.bottomLeft; const int32 yLeftTest = actorTest->y + actorTest->boudingBox.y.bottomLeft;
xRightTest = actorTest->x + actorTest->boudingBox.x.topRight; const int32 yRightTest = actorTest->y + actorTest->boudingBox.y.topRight;
yLeftTest = actorTest->y + actorTest->boudingBox.y.bottomLeft; const int32 zLeftTest = actorTest->z + actorTest->boudingBox.z.bottomLeft;
yRightTest = actorTest->y + actorTest->boudingBox.y.topRight; const int32 zRightTest = actorTest->z + actorTest->boudingBox.z.topRight;
zLeftTest = actorTest->z + actorTest->boudingBox.z.bottomLeft;
zRightTest = actorTest->z + actorTest->boudingBox.z.topRight;
if (xLeft < xRightTest && xRight > xLeftTest && yLeft < yRightTest && yRight > yLeftTest && zLeft < zRightTest && zRight > zLeftTest) { if (xLeft < xRightTest && xRight > xLeftTest && yLeft < yRightTest && yRight > yLeftTest && zLeft < zRightTest && zRight > zLeftTest) {
_engine->_actor->hitActor(actorIdx, a, actor->strengthOfHit, actor->angle + 0x200); _engine->_actor->hitActor(actorIdx, a, actor->strengthOfHit, actor->angle + 0x200);
@ -487,36 +476,29 @@ void Collision::stopFalling() { // ReceptionObj()
} }
int32 Collision::checkExtraCollisionWithActors(ExtraListStruct *extra, int32 actorIdx) { int32 Collision::checkExtraCollisionWithActors(ExtraListStruct *extra, int32 actorIdx) {
int32 a; int16 *spriteBounding = (int16 *)(_engine->_scene->spriteBoundingBoxPtr + extra->info0 * 16 + 4);
int32 xLeft, xRight, yLeft, yRight, zLeft, zRight;
int16 *spriteBounding;
ActorStruct *actorTest;
spriteBounding = (int16 *)(_engine->_scene->spriteBoundingBoxPtr + extra->info0 * 16 + 4); int32 xLeft = *(spriteBounding++) + extra->x;
int32 xRight = *(spriteBounding++) + extra->x;
xLeft = *(spriteBounding++) + extra->x; int32 yLeft = *(spriteBounding++) + extra->y;
xRight = *(spriteBounding++) + extra->x; int32 yRight = *(spriteBounding++) + extra->y;
yLeft = *(spriteBounding++) + extra->y; int32 zLeft = *(spriteBounding++) + extra->z;
yRight = *(spriteBounding++) + extra->y; int32 zRight = *(spriteBounding++) + extra->z;
zLeft = *(spriteBounding++) + extra->z; for (int32 a = 0; a < _engine->_scene->sceneNumActors; a++) {
zRight = *(spriteBounding++) + extra->z; ActorStruct *actorTest = _engine->_scene->getActor(a);
for (a = 0; a < _engine->_scene->sceneNumActors; a++) {
actorTest = &_engine->_scene->sceneActors[a];
if (a != actorIdx && actorTest->entity != -1) { if (a != actorIdx && actorTest->entity != -1) {
int32 xLeftTest, xRightTest, yLeftTest, yRightTest, zLeftTest, zRightTest; int32 xLeftTest = actorTest->x + actorTest->boudingBox.x.bottomLeft;
int32 xRightTest = actorTest->x + actorTest->boudingBox.x.topRight;
xLeftTest = actorTest->x + actorTest->boudingBox.x.bottomLeft; int32 yLeftTest = actorTest->y + actorTest->boudingBox.y.bottomLeft;
xRightTest = actorTest->x + actorTest->boudingBox.x.topRight; int32 yRightTest = actorTest->y + actorTest->boudingBox.y.topRight;
yLeftTest = actorTest->y + actorTest->boudingBox.y.bottomLeft; int32 zLeftTest = actorTest->z + actorTest->boudingBox.z.bottomLeft;
yRightTest = actorTest->y + actorTest->boudingBox.y.topRight; int32 zRightTest = actorTest->z + actorTest->boudingBox.z.topRight;
zLeftTest = actorTest->z + actorTest->boudingBox.z.bottomLeft;
zRightTest = actorTest->z + actorTest->boudingBox.z.topRight;
if (xLeft < xRightTest && xRight > xLeftTest && yLeft < yRightTest && yRight > yLeftTest && zLeft < zRightTest && zRight > zLeftTest) { if (xLeft < xRightTest && xRight > xLeftTest && yLeft < yRightTest && yRight > yLeftTest && zLeft < zRightTest && zRight > zLeftTest) {
if (extra->strengthOfHit != 0) { if (extra->strengthOfHit != 0) {
@ -532,15 +514,13 @@ int32 Collision::checkExtraCollisionWithActors(ExtraListStruct *extra, int32 act
} }
int32 Collision::checkExtraCollisionWithBricks(int32 X, int32 Y, int32 Z, int32 oldX, int32 oldY, int32 oldZ) { int32 Collision::checkExtraCollisionWithBricks(int32 X, int32 Y, int32 Z, int32 oldX, int32 oldY, int32 oldZ) {
int32 averageX, averageY, averageZ;
if (_engine->_grid->getBrickShape(oldX, oldY, oldZ)) { if (_engine->_grid->getBrickShape(oldX, oldY, oldZ)) {
return 1; return 1;
} }
averageX = ABS(X + oldX) / 2; int32 averageX = ABS(X + oldX) / 2;
averageY = ABS(Y + oldY) / 2; int32 averageY = ABS(Y + oldY) / 2;
averageZ = ABS(Z + oldZ) / 2; int32 averageZ = ABS(Z + oldZ) / 2;
if (_engine->_grid->getBrickShape(averageX, averageY, averageZ)) { if (_engine->_grid->getBrickShape(averageX, averageY, averageZ)) {
return 1; return 1;
@ -558,36 +538,31 @@ int32 Collision::checkExtraCollisionWithBricks(int32 X, int32 Y, int32 Z, int32
} }
int32 Collision::checkExtraCollisionWithExtra(ExtraListStruct *extra, int32 extraIdx) { int32 Collision::checkExtraCollisionWithExtra(ExtraListStruct *extra, int32 extraIdx) {
int32 i; int16 *spriteBounding = (int16 *)(_engine->_scene->spriteBoundingBoxPtr + extra->info0 * 16 + 4);
int32 xLeft, xRight, yLeft, yRight, zLeft, zRight;
int16 *spriteBounding;
spriteBounding = (int16 *)(_engine->_scene->spriteBoundingBoxPtr + extra->info0 * 16 + 4); int32 xLeft = *(spriteBounding++) + extra->x;
int32 xRight = *(spriteBounding++) + extra->x;
xLeft = *(spriteBounding++) + extra->x; int32 yLeft = *(spriteBounding++) + extra->y;
xRight = *(spriteBounding++) + extra->x; int32 yRight = *(spriteBounding++) + extra->y;
yLeft = *(spriteBounding++) + extra->y; int32 zLeft = *(spriteBounding++) + extra->z;
yRight = *(spriteBounding++) + extra->y; int32 zRight = *(spriteBounding++) + extra->z;
zLeft = *(spriteBounding++) + extra->z; for (int32 i = 0; i < EXTRA_MAX_ENTRIES; i++) {
zRight = *(spriteBounding++) + extra->z;
for (i = 0; i < EXTRA_MAX_ENTRIES; i++) {
ExtraListStruct *extraTest = &_engine->_extra->extraList[i]; ExtraListStruct *extraTest = &_engine->_extra->extraList[i];
if (i != extraIdx && extraTest->info0 != -1) { if (i != extraIdx && extraTest->info0 != -1) {
int32 xLeftTest, xRightTest, yLeftTest, yRightTest, zLeftTest, zRightTest;
// int16 * spriteBoundingTest; // int16 * spriteBoundingTest;
// spriteBoundingTest = (int16*)(_engine->_scene->spriteBoundingBoxPtr + extraTest->info0 * 16 + 4); // spriteBoundingTest = (int16*)(_engine->_scene->spriteBoundingBoxPtr + extraTest->info0 * 16 + 4);
xLeftTest = *(spriteBounding++) + extraTest->x; int32 xLeftTest = *(spriteBounding++) + extraTest->x;
xRightTest = *(spriteBounding++) + extraTest->x; int32 xRightTest = *(spriteBounding++) + extraTest->x;
yLeftTest = *(spriteBounding++) + extraTest->y; int32 yLeftTest = *(spriteBounding++) + extraTest->y;
yRightTest = *(spriteBounding++) + extraTest->y; int32 yRightTest = *(spriteBounding++) + extraTest->y;
zLeftTest = *(spriteBounding++) + extraTest->z; int32 zLeftTest = *(spriteBounding++) + extraTest->z;
zRightTest = *(spriteBounding++) + extraTest->z; int32 zRightTest = *(spriteBounding++) + extraTest->z;
if (xLeft < xLeftTest) { if (xLeft < xLeftTest) {
if (xLeft < xRightTest && xRight > xLeftTest && yLeft < yRightTest && yRight > yLeftTest && zLeft < zRightTest && zRight > zLeftTest) { if (xLeft < xRightTest && xRight > xLeftTest && yLeft < yRightTest && yRight > yLeftTest && zLeft < zRightTest && zRight > zLeftTest) {

View File

@ -53,11 +53,11 @@ public:
int32 causeActorDamage = 0; //fieldCauseDamage int32 causeActorDamage = 0; //fieldCauseDamage
/** /**
* Check if actor 1 is standing in actor2 * Check if actor 1 is standing in actor 2
* @param actorIdx1 Actor 1 index * @param actorIdx1 Actor 1 index
* @param actorIdx2 Actor 2 index * @param actorIdx2 Actor 2 index
*/ */
int32 standingOnActor(int32 actorIdx1, int32 actorIdx2); bool standingOnActor(int32 actorIdx1, int32 actorIdx2);
int32 getAverageValue(int32 var0, int32 var1, int32 var2, int32 var3); int32 getAverageValue(int32 var0, int32 var1, int32 var2, int32 var3);

View File

@ -22,6 +22,7 @@
#include "twine/extra.h" #include "twine/extra.h"
#include "common/util.h" #include "common/util.h"
#include "twine/actor.h"
#include "twine/collision.h" #include "twine/collision.h"
#include "twine/gamestate.h" #include "twine/gamestate.h"
#include "twine/grid.h" #include "twine/grid.h"
@ -103,56 +104,53 @@ static const int16 explodeCloudShapeTable[] = {
Extra::Extra(TwinEEngine *engine) : _engine(engine) {} Extra::Extra(TwinEEngine *engine) : _engine(engine) {}
int32 Extra::addExtra(int32 actorIdx, int32 X, int32 Y, int32 Z, int32 info0, int32 targetActor, int32 maxSpeed, int32 strengthOfHit) { int32 Extra::addExtra(int32 actorIdx, int32 x, int32 y, int32 z, int32 info0, int32 targetActor, int32 maxSpeed, int32 strengthOfHit) {
int32 i; for (int32 i = 0; i < EXTRA_MAX_ENTRIES; i++) {
for (i = 0; i < EXTRA_MAX_ENTRIES; i++) {
ExtraListStruct *extra = &extraList[i]; ExtraListStruct *extra = &extraList[i];
if (extra->info0 == -1) { if (extra->info0 != -1) {
extra->info0 = info0; continue;
extra->type = 0x80;
extra->info1 = 0;
extra->x = X;
extra->y = Y;
extra->z = Z;
extra->actorIdx = actorIdx;
extra->lifeTime = targetActor;
extra->destZ = maxSpeed;
extra->strengthOfHit = strengthOfHit;
_engine->_movements->setActorAngle(0, maxSpeed, 50, &extra->trackActorMove);
extra->angle = _engine->_movements->getAngleAndSetTargetActorDistance(X, Z, _engine->_scene->sceneActors[targetActor].x, _engine->_scene->sceneActors[targetActor].z);
return i;
} }
extra->info0 = info0;
extra->type = 0x80;
extra->info1 = 0;
extra->x = x;
extra->y = y;
extra->z = z;
extra->actorIdx = actorIdx;
extra->lifeTime = targetActor;
extra->destZ = maxSpeed;
extra->strengthOfHit = strengthOfHit;
_engine->_movements->setActorAngle(0, maxSpeed, 50, &extra->trackActorMove);
const ActorStruct *actor = _engine->_scene->getActor(targetActor);
extra->angle = _engine->_movements->getAngleAndSetTargetActorDistance(x, z, actor->x, actor->z);
return i;
} }
return -1; return -1;
} }
int32 Extra::addExtraExplode(int32 X, int32 Y, int32 Z) { int32 Extra::addExtraExplode(int32 x, int32 y, int32 z) {
int32 i; for (int32 i = 0; i < EXTRA_MAX_ENTRIES; i++) {
for (i = 0; i < EXTRA_MAX_ENTRIES; i++) {
ExtraListStruct *extra = &extraList[i]; ExtraListStruct *extra = &extraList[i];
if (extra->info0 == -1) { if (extra->info0 != -1) {
extra->info0 = 0x61; continue;
extra->type = 0x1001;
extra->info1 = 0;
extra->x = X;
extra->y = Y;
extra->z = Z;
extra->actorIdx = 0x28;
extra->lifeTime = _engine->lbaTime;
extra->strengthOfHit = 0;
return i;
} }
extra->info0 = 0x61;
extra->type = 0x1001;
extra->info1 = 0;
extra->x = x;
extra->y = y;
extra->z = z;
extra->actorIdx = 0x28;
extra->lifeTime = _engine->lbaTime;
extra->strengthOfHit = 0;
return i;
} }
return -1; return -1;
} }
void Extra::resetExtras() { void Extra::resetExtras() {
int32 i; for (int32 i = 0; i < EXTRA_MAX_ENTRIES; i++) {
for (i = 0; i < EXTRA_MAX_ENTRIES; i++) {
ExtraListStruct *extra = &extraList[i]; ExtraListStruct *extra = &extraList[i];
extra->info0 = -1; extra->info0 = -1;
extra->info1 = 1; extra->info1 = 1;
@ -179,129 +177,129 @@ void Extra::throwExtra(ExtraListStruct *extra, int32 var1, int32 var2, int32 var
extra->lifeTime = _engine->lbaTime; extra->lifeTime = _engine->lbaTime;
} }
void Extra::addExtraSpecial(int32 X, int32 Y, int32 Z, int32 type) { // InitSpecial void Extra::addExtraSpecial(int32 x, int32 y, int32 z, ExtraSpecialType type) { // InitSpecial
int32 i; const int16 flag = 0x8000 + type;
int16 flag = 0x8000 + type;
for (i = 0; i < EXTRA_MAX_ENTRIES; i++) { for (int32 i = 0; i < EXTRA_MAX_ENTRIES; i++) {
ExtraListStruct *extra = &extraList[i]; ExtraListStruct *extra = &extraList[i];
if (extra->info0 == -1) { if (extra->info0 != -1) {
extra->info0 = flag; continue;
extra->info1 = 0;
if (type == kHitStars) {
extra->type = 9;
extra->x = X;
extra->y = Y;
extra->z = Z;
// same as InitFly
throwExtra(extra, _engine->getRandomNumber(0x100) + 0x80, _engine->getRandomNumber(0x400), 50, 20);
extra->strengthOfHit = 0;
extra->lifeTime = _engine->lbaTime;
extra->actorIdx = 100;
return;
}
if (type == kExplodeCloud) {
extra->type = 1;
extra->x = X;
extra->y = Y;
extra->z = Z;
extra->strengthOfHit = 0;
extra->lifeTime = _engine->lbaTime;
extra->actorIdx = 5;
return;
}
} }
} extra->info0 = flag;
} extra->info1 = 0;
int32 Extra::addExtraBonus(int32 X, int32 Y, int32 Z, int32 param, int32 angle, int32 type, int32 bonusAmount) { // ExtraBonus if (type == kHitStars) {
int32 i; extra->type = 9;
for (i = 0; i < EXTRA_MAX_ENTRIES; i++) { extra->x = x;
ExtraListStruct *extra = &extraList[i]; extra->y = y;
if (extra->info0 == -1) { extra->z = z;
extra->info0 = type;
extra->type = 0x4071;
/*if(type == SPRITEHQR_KEY) {
extra->type = 0x4030;
}*/
extra->x = X;
extra->y = Y;
extra->z = Z;
// same as InitFly // same as InitFly
throwExtra(extra, param, angle, 40, 15); throwExtra(extra, _engine->getRandomNumber(0x100) + 0x80, _engine->getRandomNumber(0x400), 50, 20);
extra->strengthOfHit = 0; extra->strengthOfHit = 0;
extra->lifeTime = _engine->lbaTime; extra->lifeTime = _engine->lbaTime;
extra->actorIdx = 1000; extra->actorIdx = 100;
extra->info1 = bonusAmount;
return i;
} }
} if (type == kExplodeCloud) {
extra->type = 1;
return -1; extra->x = x;
} extra->y = y;
extra->z = z;
int32 Extra::addExtraThrow(int32 actorIdx, int32 X, int32 Y, int32 Z, int32 sprite, int32 var2, int32 var3, int32 var4, int32 var5, int32 strengthOfHit) { // ThrowExtra extra->strengthOfHit = 0;
int32 i;
for (i = 0; i < EXTRA_MAX_ENTRIES; i++) {
ExtraListStruct *extra = &extraList[i];
if (extra->info0 == -1) {
extra->info0 = sprite;
extra->type = 0x210C;
extra->x = X;
extra->y = Y;
extra->z = Z;
// same as InitFly
throwExtra(extra, var2, var3, var4, var5);
extra->strengthOfHit = strengthOfHit;
extra->lifeTime = _engine->lbaTime; extra->lifeTime = _engine->lbaTime;
extra->actorIdx = actorIdx; extra->actorIdx = 5;
extra->info1 = 0;
return i;
} }
break;
}
}
int32 Extra::addExtraBonus(int32 x, int32 y, int32 z, int32 param, int32 angle, int32 type, int32 bonusAmount) { // ExtraBonus
int32 i;
for (i = 0; i < EXTRA_MAX_ENTRIES; i++) {
ExtraListStruct *extra = &extraList[i];
if (extra->info0 != -1) {
continue;
}
extra->info0 = type;
extra->type = 0x4071;
/*if(type == SPRITEHQR_KEY) {
extra->type = 0x4030;
}*/
extra->x = x;
extra->y = y;
extra->z = z;
// same as InitFly
throwExtra(extra, param, angle, 40, 15);
extra->strengthOfHit = 0;
extra->lifeTime = _engine->lbaTime;
extra->actorIdx = 1000;
extra->info1 = bonusAmount;
return i;
} }
return -1; return -1;
} }
int32 Extra::addExtraAiming(int32 actorIdx, int32 X, int32 Y, int32 Z, int32 spriteIdx, int32 targetActorIdx, int32 maxSpeed, int32 strengthOfHit) { // ExtraSearch int32 Extra::addExtraThrow(int32 actorIdx, int32 x, int32 y, int32 z, int32 sprite, int32 var2, int32 var3, int32 var4, int32 var5, int32 strengthOfHit) { // ThrowExtra
int32 i; int32 i;
for (i = 0; i < EXTRA_MAX_ENTRIES; i++) { for (i = 0; i < EXTRA_MAX_ENTRIES; i++) {
ExtraListStruct *extra = &extraList[i]; ExtraListStruct *extra = &extraList[i];
if (extra->info0 == -1) { if (extra->info0 != -1) {
extra->info0 = spriteIdx; continue;
extra->type = 0x80;
extra->info1 = 0;
extra->x = X;
extra->y = Y;
extra->z = Z;
extra->actorIdx = actorIdx;
extra->lifeTime = targetActorIdx;
extra->destZ = maxSpeed;
extra->strengthOfHit = strengthOfHit;
_engine->_movements->setActorAngle(0, maxSpeed, 50, &extra->trackActorMove);
extra->angle = _engine->_movements->getAngleAndSetTargetActorDistance(X, Z, _engine->_scene->sceneActors[targetActorIdx].x, _engine->_scene->sceneActors[targetActorIdx].z);
return i;
} }
extra->info0 = sprite;
extra->type = 0x210C;
extra->x = x;
extra->y = y;
extra->z = z;
// same as InitFly
throwExtra(extra, var2, var3, var4, var5);
extra->strengthOfHit = strengthOfHit;
extra->lifeTime = _engine->lbaTime;
extra->actorIdx = actorIdx;
extra->info1 = 0;
return i;
}
return -1;
}
int32 Extra::addExtraAiming(int32 actorIdx, int32 x, int32 y, int32 z, int32 spriteIdx, int32 targetActorIdx, int32 maxSpeed, int32 strengthOfHit) { // ExtraSearch
int32 i;
for (i = 0; i < EXTRA_MAX_ENTRIES; i++) {
ExtraListStruct *extra = &extraList[i];
if (extra->info0 != -1) {
continue;
}
extra->info0 = spriteIdx;
extra->type = 0x80;
extra->info1 = 0;
extra->x = x;
extra->y = y;
extra->z = z;
extra->actorIdx = actorIdx;
extra->lifeTime = targetActorIdx;
extra->destZ = maxSpeed;
extra->strengthOfHit = strengthOfHit;
_engine->_movements->setActorAngle(0, maxSpeed, 50, &extra->trackActorMove);
const ActorStruct *actor = _engine->_scene->getActor(targetActorIdx);
extra->angle = _engine->_movements->getAngleAndSetTargetActorDistance(x, z, actor->x, actor->z);
return i;
} }
return -1; return -1;
@ -327,27 +325,28 @@ int32 Extra::addExtraAimingAtKey(int32 actorIdx, int32 x, int32 y, int32 z, int3
for (i = 0; i < EXTRA_MAX_ENTRIES; i++) { for (i = 0; i < EXTRA_MAX_ENTRIES; i++) {
ExtraListStruct *extra = &extraList[i]; ExtraListStruct *extra = &extraList[i];
if (extra->info0 == -1) { if (extra->info0 != -1) {
extra->info0 = spriteIdx; continue;
extra->type = 0x200;
extra->info1 = 0;
extra->x = x;
extra->y = y;
extra->z = z;
extra->actorIdx = extraIdx;
extra->destZ = 0x0FA0;
extra->strengthOfHit = 0;
_engine->_movements->setActorAngle(0, 0x0FA0, 50, &extra->trackActorMove);
extra->angle = _engine->_movements->getAngleAndSetTargetActorDistance(x, z, extraList[extraIdx].x, extraList[extraIdx].z);
return i;
} }
extra->info0 = spriteIdx;
extra->type = 0x200;
extra->info1 = 0;
extra->x = x;
extra->y = y;
extra->z = z;
extra->actorIdx = extraIdx;
extra->destZ = 0x0FA0;
extra->strengthOfHit = 0;
_engine->_movements->setActorAngle(0, 0x0FA0, 50, &extra->trackActorMove);
extra->angle = _engine->_movements->getAngleAndSetTargetActorDistance(x, z, extraList[extraIdx].x, extraList[extraIdx].z);
return i;
} }
return -1; return -1;
} }
void Extra::addExtraThrowMagicball(int32 X, int32 Y, int32 Z, int32 param1, int32 angle, int32 param2, int32 param3) { // ThrowMagicBall void Extra::addExtraThrowMagicball(int32 x, int32 y, int32 z, int32 param1, int32 angle, int32 param2, int32 param3) { // ThrowMagicBall
int32 ballSprite = -1; int32 ballSprite = -1;
int32 ballStrength = 0; int32 ballStrength = 0;
int32 extraIdx = -1; int32 extraIdx = -1;
@ -384,21 +383,21 @@ void Extra::addExtraThrowMagicball(int32 X, int32 Y, int32 Z, int32 param1, int3
switch (_engine->_gameState->magicBallNumBounce) { switch (_engine->_gameState->magicBallNumBounce) {
case 0: case 0:
_engine->_gameState->magicBallIdx = addExtraThrow(0, X, Y, Z, ballSprite, param1, angle, param2, param3, ballStrength); _engine->_gameState->magicBallIdx = addExtraThrow(0, x, y, z, ballSprite, param1, angle, param2, param3, ballStrength);
break; break;
case 1: case 1:
_engine->_gameState->magicBallAuxBounce = 4; _engine->_gameState->magicBallAuxBounce = 4;
_engine->_gameState->magicBallIdx = addExtraThrow(0, X, Y, Z, ballSprite, param1, angle, param2, param3, ballStrength); _engine->_gameState->magicBallIdx = addExtraThrow(0, x, y, z, ballSprite, param1, angle, param2, param3, ballStrength);
break; break;
case 2: case 2:
case 3: case 3:
case 4: case 4:
_engine->_gameState->magicBallNumBounce = 1; _engine->_gameState->magicBallNumBounce = 1;
_engine->_gameState->magicBallAuxBounce = 4; _engine->_gameState->magicBallAuxBounce = 4;
_engine->_gameState->magicBallIdx = addExtraThrow(0, X, Y, Z, ballSprite, param1, angle, param2, param3, ballStrength); _engine->_gameState->magicBallIdx = addExtraThrow(0, x, y, z, ballSprite, param1, angle, param2, param3, ballStrength);
break; break;
case 5: case 5:
_engine->_gameState->magicBallIdx = addExtraAimingAtKey(0, X, Y, Z, ballSprite, extraIdx); _engine->_gameState->magicBallIdx = addExtraAimingAtKey(0, x, y, z, ballSprite, extraIdx);
break; break;
} }
@ -407,22 +406,11 @@ void Extra::addExtraThrowMagicball(int32 X, int32 Y, int32 Z, int32 param1, int3
} }
} }
void Extra::drawSpecialShape(const int16 *shapeTable, int32 X, int32 Y, int32 color, int32 angle, int32 size) { void Extra::drawSpecialShape(const int16 *shapeTable, int32 x, int32 y, int32 color, int32 angle, int32 size) {
int16 currentShapeTable; int16 currentShapeTable = *(shapeTable++);
int16 var_8;
int16 temp1;
int32 computedX;
int32 computedY;
int32 oldComputedX;
int32 oldComputedY;
int32 numEntries;
int32 currentX;
int32 currentY;
currentShapeTable = *(shapeTable++); int16 var_8 = ((*(shapeTable++)) * size) >> 4;
int16 temp1 = ((*(shapeTable++)) * size) >> 4;
var_8 = ((*(shapeTable++)) * size) >> 4;
temp1 = ((*(shapeTable++)) * size) >> 4;
_engine->_redraw->renderLeft = 0x7D00; _engine->_redraw->renderLeft = 0x7D00;
_engine->_redraw->renderRight = -0x7D00; _engine->_redraw->renderRight = -0x7D00;
@ -431,52 +419,60 @@ void Extra::drawSpecialShape(const int16 *shapeTable, int32 X, int32 Y, int32 co
_engine->_movements->rotateActor(var_8, temp1, angle); _engine->_movements->rotateActor(var_8, temp1, angle);
computedX = _engine->_renderer->destX + X; int32 computedX = _engine->_renderer->destX + x;
computedY = _engine->_renderer->destZ + Y; int32 computedY = _engine->_renderer->destZ + y;
if (computedX < _engine->_redraw->renderLeft) if (computedX < _engine->_redraw->renderLeft) {
_engine->_redraw->renderLeft = computedX; _engine->_redraw->renderLeft = computedX;
}
if (computedX > _engine->_redraw->renderRight) if (computedX > _engine->_redraw->renderRight) {
_engine->_redraw->renderRight = computedX; _engine->_redraw->renderRight = computedX;
}
if (computedY < _engine->_redraw->renderTop) if (computedY < _engine->_redraw->renderTop) {
_engine->_redraw->renderTop = computedY; _engine->_redraw->renderTop = computedY;
}
if (computedY > _engine->_redraw->renderBottom) if (computedY > _engine->_redraw->renderBottom) {
_engine->_redraw->renderBottom = computedY; _engine->_redraw->renderBottom = computedY;
}
numEntries = 1; int32 numEntries = 1;
currentX = computedX; int32 currentX = computedX;
currentY = computedY; int32 currentY = computedY;
while (numEntries < currentShapeTable) { while (numEntries < currentShapeTable) {
var_8 = ((*(shapeTable++)) * size) >> 4; var_8 = ((*(shapeTable++)) * size) >> 4;
temp1 = ((*(shapeTable++)) * size) >> 4; temp1 = ((*(shapeTable++)) * size) >> 4;
oldComputedX = currentX; int32 oldComputedX = currentX;
oldComputedY = currentY; int32 oldComputedY = currentY;
_engine->_renderer->projPosX = currentX; _engine->_renderer->projPosX = currentX;
_engine->_renderer->projPosY = currentY; _engine->_renderer->projPosY = currentY;
_engine->_movements->rotateActor(var_8, temp1, angle); _engine->_movements->rotateActor(var_8, temp1, angle);
currentX = _engine->_renderer->destX + X; currentX = _engine->_renderer->destX + x;
currentY = _engine->_renderer->destZ + Y; currentY = _engine->_renderer->destZ + y;
if (currentX < _engine->_redraw->renderLeft) if (currentX < _engine->_redraw->renderLeft) {
_engine->_redraw->renderLeft = currentX; _engine->_redraw->renderLeft = currentX;
}
if (currentX > _engine->_redraw->renderRight) if (currentX > _engine->_redraw->renderRight) {
_engine->_redraw->renderRight = currentX; _engine->_redraw->renderRight = currentX;
}
if (currentY < _engine->_redraw->renderTop) if (currentY < _engine->_redraw->renderTop) {
_engine->_redraw->renderTop = currentY; _engine->_redraw->renderTop = currentY;
}
if (currentY > _engine->_redraw->renderBottom) if (currentY > _engine->_redraw->renderBottom) {
_engine->_redraw->renderBottom = currentY; _engine->_redraw->renderBottom = currentY;
}
_engine->_renderer->projPosX = currentX; _engine->_renderer->projPosX = currentX;
_engine->_renderer->projPosY = currentY; _engine->_renderer->projPosY = currentY;
@ -494,7 +490,7 @@ void Extra::drawSpecialShape(const int16 *shapeTable, int32 X, int32 Y, int32 co
_engine->_interface->drawLine(currentX, currentY, computedX, computedY, color); _engine->_interface->drawLine(currentX, currentY, computedX, computedY, color);
} }
void Extra::drawExtraSpecial(int32 extraIdx, int32 X, int32 Y) { void Extra::drawExtraSpecial(int32 extraIdx, int32 x, int32 y) {
int32 specialType; int32 specialType;
ExtraListStruct *extra = &extraList[extraIdx]; ExtraListStruct *extra = &extraList[extraIdx];
@ -502,7 +498,7 @@ void Extra::drawExtraSpecial(int32 extraIdx, int32 X, int32 Y) {
switch (specialType) { switch (specialType) {
case kHitStars: case kHitStars:
drawSpecialShape(hitStarsShapeTable, X, Y, 15, (_engine->lbaTime << 5) & 0x300, 4); drawSpecialShape(hitStarsShapeTable, x, y, 15, (_engine->lbaTime << 5) & 0x300, 4);
break; break;
case kExplodeCloud: { case kExplodeCloud: {
int32 cloudTime = 1 + _engine->lbaTime - extra->lifeTime; int32 cloudTime = 1 + _engine->lbaTime - extra->lifeTime;
@ -511,43 +507,42 @@ void Extra::drawExtraSpecial(int32 extraIdx, int32 X, int32 Y) {
cloudTime = 32; cloudTime = 32;
} }
drawSpecialShape(explodeCloudShapeTable, X, Y, 15, 0, cloudTime); drawSpecialShape(explodeCloudShapeTable, x, y, 15, 0, cloudTime);
} break; break;
}
} }
} }
void Extra::processMagicballBounce(ExtraListStruct *extra, int32 X, int32 Y, int32 Z) { void Extra::processMagicballBounce(ExtraListStruct *extra, int32 x, int32 y, int32 z) {
if (_engine->_grid->getBrickShape(X, extra->y, Z)) { if (_engine->_grid->getBrickShape(x, extra->y, z)) {
extra->destY = -extra->destY; extra->destY = -extra->destY;
} }
if (_engine->_grid->getBrickShape(extra->x, Y, Z)) { if (_engine->_grid->getBrickShape(extra->x, y, z)) {
extra->destX = -extra->destX; extra->destX = -extra->destX;
} }
if (_engine->_grid->getBrickShape(X, Y, extra->z)) { if (_engine->_grid->getBrickShape(x, y, extra->z)) {
extra->destZ = -extra->destZ; extra->destZ = -extra->destZ;
} }
extra->x = X; extra->x = x;
extra->lastX = X; extra->lastX = x;
extra->y = Y; extra->y = y;
extra->lastY = Y; extra->lastY = y;
extra->z = Z; extra->z = z;
extra->lastZ = Z; extra->lastZ = z;
extra->lifeTime = _engine->lbaTime; extra->lifeTime = _engine->lbaTime;
} }
/** Process extras */ /** Process extras */
void Extra::processExtras() { void Extra::processExtras() {
int32 i;
int32 currentExtraX = 0; int32 currentExtraX = 0;
int32 currentExtraY = 0; int32 currentExtraY = 0;
int32 currentExtraZ = 0; int32 currentExtraZ = 0;
int32 currentExtraSpeedX = 0; int32 currentExtraSpeedX = 0;
int32 currentExtraSpeedY = 0; int32 currentExtraSpeedY = 0;
for (i = 0; i < EXTRA_MAX_ENTRIES; i++) { for (int32 i = 0; i < EXTRA_MAX_ENTRIES; i++) {
ExtraListStruct *extra = &extraList[i]; ExtraListStruct *extra = &extraList[i];
if (extra->info0 != -1) { if (extra->info0 != -1) {
// process extra life time // process extra life time
@ -622,9 +617,10 @@ void Extra::processExtras() {
actorIdxAttacked = extra->lifeTime; actorIdxAttacked = extra->lifeTime;
actorIdx = extra->actorIdx; actorIdx = extra->actorIdx;
currentExtraX = _engine->_scene->sceneActors[actorIdxAttacked].x; const ActorStruct *actor = _engine->_scene->getActor(actorIdxAttacked);
currentExtraY = _engine->_scene->sceneActors[actorIdxAttacked].y + 1000; currentExtraX = actor->x;
currentExtraZ = _engine->_scene->sceneActors[actorIdxAttacked].z; currentExtraY = actor->y + 1000;
currentExtraZ = actor->z;
tmpAngle = _engine->_movements->getAngleAndSetTargetActorDistance(extra->x, extra->z, currentExtraX, currentExtraZ); tmpAngle = _engine->_movements->getAngleAndSetTargetActorDistance(extra->x, extra->z, currentExtraX, currentExtraZ);
angle = (tmpAngle - extra->angle) & 0x3FF; angle = (tmpAngle - extra->angle) & 0x3FF;
@ -640,32 +636,30 @@ void Extra::processExtras() {
extra->info0 = -1; extra->info0 = -1;
continue; continue;
} else { }
const int32 angle2 = _engine->_movements->getAngleAndSetTargetActorDistance(extra->y, 0, currentExtraY, _engine->_movements->targetActorDistance);
int32 pos = _engine->_movements->getRealAngle(&extra->trackActorMove); const int32 angle2 = _engine->_movements->getAngleAndSetTargetActorDistance(extra->y, 0, currentExtraY, _engine->_movements->targetActorDistance);
int32 pos = _engine->_movements->getRealAngle(&extra->trackActorMove);
if (!pos) {
pos = 1;
}
if (!pos) { _engine->_movements->rotateActor(pos, 0, angle2);
pos = 1; extra->y -= _engine->_renderer->destZ;
_engine->_movements->rotateActor(0, _engine->_renderer->destX, tmpAngle);
extra->x += _engine->_renderer->destX;
extra->z += _engine->_renderer->destZ;
_engine->_movements->setActorAngle(0, extra->destZ, 50, &extra->trackActorMove);
if (actorIdxAttacked == _engine->_collision->checkExtraCollisionWithActors(extra, actorIdx)) {
if (i == _engine->_gameState->magicBallIdx) {
_engine->_gameState->magicBallIdx = -1;
} }
_engine->_movements->rotateActor(pos, 0, angle2); extra->info0 = -1;
extra->y -= _engine->_renderer->destZ; continue;
_engine->_movements->rotateActor(0, _engine->_renderer->destX, tmpAngle);
extra->x += _engine->_renderer->destX;
extra->z += _engine->_renderer->destZ;
_engine->_movements->setActorAngle(0, extra->destZ, 50, &extra->trackActorMove);
if (actorIdxAttacked == _engine->_collision->checkExtraCollisionWithActors(extra, actorIdx)) {
if (i == _engine->_gameState->magicBallIdx) {
_engine->_gameState->magicBallIdx = -1;
}
extra->info0 = -1;
continue;
}
} }
} }
// process magic ball extra aiming for key // process magic ball extra aiming for key
@ -822,9 +816,8 @@ void Extra::processExtras() {
extra->info0 = -1; extra->info0 = -1;
continue; continue;
} else {
processMagicballBounce(extra, currentExtraX, currentExtraY, currentExtraZ);
} }
processMagicballBounce(extra, currentExtraX, currentExtraY, currentExtraZ);
} }
} else { } else {
extra->info0 = -1; extra->info0 = -1;
@ -876,27 +869,19 @@ void Extra::processExtras() {
if (_engine->_gameState->inventoryNumKashes > 999) { if (_engine->_gameState->inventoryNumKashes > 999) {
_engine->_gameState->inventoryNumKashes = 999; _engine->_gameState->inventoryNumKashes = 999;
} }
} } else if (extra->info0 == SPRITEHQR_LIFEPOINTS) {
if (extra->info0 == SPRITEHQR_LIFEPOINTS) {
_engine->_scene->sceneHero->life += extra->info1; _engine->_scene->sceneHero->life += extra->info1;
if (_engine->_scene->sceneHero->life > 50) { if (_engine->_scene->sceneHero->life > 50) {
_engine->_scene->sceneHero->life = 50; _engine->_scene->sceneHero->life = 50;
} }
} } else if (extra->info0 == SPRITEHQR_MAGICPOINTS && _engine->_gameState->magicLevelIdx) {
if (extra->info0 == SPRITEHQR_MAGICPOINTS && _engine->_gameState->magicLevelIdx) {
_engine->_gameState->inventoryMagicPoints += extra->info1 * 2; _engine->_gameState->inventoryMagicPoints += extra->info1 * 2;
if (_engine->_gameState->inventoryMagicPoints > _engine->_gameState->magicLevelIdx * 20) { if (_engine->_gameState->inventoryMagicPoints > _engine->_gameState->magicLevelIdx * 20) {
_engine->_gameState->inventoryMagicPoints = _engine->_gameState->magicLevelIdx * 20; _engine->_gameState->inventoryMagicPoints = _engine->_gameState->magicLevelIdx * 20;
} }
} } else if (extra->info0 == SPRITEHQR_KEY) {
if (extra->info0 == SPRITEHQR_KEY) {
_engine->_gameState->inventoryNumKeys += extra->info1; _engine->_gameState->inventoryNumKeys += extra->info1;
} } else if (extra->info0 == SPRITEHQR_CLOVERLEAF) {
if (extra->info0 == SPRITEHQR_CLOVERLEAF) {
_engine->_gameState->inventoryNumLeafs += extra->info1; _engine->_gameState->inventoryNumLeafs += extra->info1;
if (_engine->_gameState->inventoryNumLeafs > _engine->_gameState->inventoryNumLeafsBox) { if (_engine->_gameState->inventoryNumLeafs > _engine->_gameState->inventoryNumLeafsBox) {
_engine->_gameState->inventoryNumLeafs = _engine->_gameState->inventoryNumLeafsBox; _engine->_gameState->inventoryNumLeafs = _engine->_gameState->inventoryNumLeafsBox;

View File

@ -65,33 +65,33 @@ private:
TwinEEngine *_engine; TwinEEngine *_engine;
void throwExtra(ExtraListStruct *extra, int32 var1, int32 var2, int32 var3, int32 var4); void throwExtra(ExtraListStruct *extra, int32 var1, int32 var2, int32 var3, int32 var4);
void processMagicballBounce(ExtraListStruct *extra, int32 X, int32 Y, int32 Z); void processMagicballBounce(ExtraListStruct *extra, int32 x, int32 y, int32 z);
int32 findExtraKey(); int32 findExtraKey();
int32 addExtraAimingAtKey(int32 actorIdx, int32 X, int32 Y, int32 Z, int32 spriteIdx, int32 extraIdx); int32 addExtraAimingAtKey(int32 actorIdx, int32 x, int32 y, int32 z, int32 spriteIdx, int32 extraIdx);
void drawSpecialShape(const int16 *shapeTable, int32 X, int32 Y, int32 color, int32 angle, int32 size); void drawSpecialShape(const int16 *shapeTable, int32 x, int32 y, int32 color, int32 angle, int32 size);
public: public:
Extra(TwinEEngine *engine); Extra(TwinEEngine *engine);
ExtraListStruct extraList[EXTRA_MAX_ENTRIES]; ExtraListStruct extraList[EXTRA_MAX_ENTRIES];
int32 addExtra(int32 actorIdx, int32 X, int32 Y, int32 Z, int32 info0, int32 targetActor, int32 maxSpeed, int32 strengthOfHit); int32 addExtra(int32 actorIdx, int32 x, int32 y, int32 z, int32 info0, int32 targetActor, int32 maxSpeed, int32 strengthOfHit);
/** Add extra explosion /** Add extra explosion
@param X Explostion X coordinate @param x Explostion X coordinate
@param Y Explostion Y coordinate @param y Explostion Y coordinate
@param Z Explostion Z coordinate */ @param z Explostion Z coordinate */
int32 addExtraExplode(int32 X, int32 Y, int32 Z); int32 addExtraExplode(int32 x, int32 y, int32 z);
/** Reset all used extras */ /** Reset all used extras */
void resetExtras(); void resetExtras();
void addExtraSpecial(int32 X, int32 Y, int32 Z, int32 type); void addExtraSpecial(int32 x, int32 y, int32 z, ExtraSpecialType type);
int32 addExtraBonus(int32 X, int32 Y, int32 Z, int32 param, int32 angle, int32 type, int32 bonusAmount); int32 addExtraBonus(int32 x, int32 y, int32 z, int32 param, int32 angle, int32 type, int32 bonusAmount);
int32 addExtraThrow(int32 actorIdx, int32 X, int32 Y, int32 Z, int32 sprite, int32 var2, int32 var3, int32 var4, int32 var5, int32 strengthOfHit); int32 addExtraThrow(int32 actorIdx, int32 x, int32 y, int32 z, int32 sprite, int32 var2, int32 var3, int32 var4, int32 var5, int32 strengthOfHit);
int32 addExtraAiming(int32 actorIdx, int32 X, int32 Y, int32 Z, int32 spriteIdx, int32 targetActorIdx, int32 maxSpeed, int32 strengthOfHit); int32 addExtraAiming(int32 actorIdx, int32 x, int32 y, int32 z, int32 spriteIdx, int32 targetActorIdx, int32 maxSpeed, int32 strengthOfHit);
void addExtraThrowMagicball(int32 X, int32 Y, int32 Z, int32 param1, int32 angle, int32 param2, int32 param3); void addExtraThrowMagicball(int32 x, int32 y, int32 z, int32 param1, int32 angle, int32 param2, int32 param3);
void drawExtraSpecial(int32 extraIdx, int32 X, int32 Y); void drawExtraSpecial(int32 extraIdx, int32 x, int32 y);
/** Process extras */ /** Process extras */
void processExtras(); void processExtras();

View File

@ -259,13 +259,12 @@ void Movements::moveActor(int32 angleFrom, int32 angleTo, int32 speed, ActorMove
} }
void Movements::processActorMovements(int32 actorIdx) { void Movements::processActorMovements(int32 actorIdx) {
ActorStruct *actor = &_engine->_scene->sceneActors[actorIdx]; ActorStruct *actor = _engine->_scene->getActor(actorIdx);
if (actor->entity == -1) {
if (actor->entity == -1)
return; return;
}
if (actor->dynamicFlags.bIsFalling) { if (actor->dynamicFlags.bIsFalling) {
if (actor->controlMode != 1) { if (actor->controlMode != 1) {
return; return;
} }
@ -291,7 +290,8 @@ void Movements::processActorMovements(int32 actorIdx) {
case kNoMove: case kNoMove:
break; break;
case kManual: case kManual:
if (!actorIdx) { // take this out when we want to give manual movements to other characters than Hero // take this out when we want to give manual movements to other characters than Hero
if (actor == _engine->_scene->sceneHero) {
heroAction = 0; heroAction = 0;
// If press W for action // If press W for action
@ -333,12 +333,10 @@ void Movements::processActorMovements(int32 actorIdx) {
} }
} }
} else { } else {
if (_engine->_input->isActionActive(TwinEActionType::TurnRight)) {
_engine->_animations->initAnim(kRightPunch, 1, 0, actorIdx);
}
if (_engine->_input->isActionActive(TwinEActionType::TurnLeft)) { if (_engine->_input->isActionActive(TwinEActionType::TurnLeft)) {
_engine->_animations->initAnim(kLeftPunch, 1, 0, actorIdx); _engine->_animations->initAnim(kLeftPunch, 1, 0, actorIdx);
} else if (_engine->_input->isActionActive(TwinEActionType::TurnRight)) {
_engine->_animations->initAnim(kRightPunch, 1, 0, actorIdx);
} }
if (_engine->_input->toggleActionIfActive(TwinEActionType::MoveForward)) { if (_engine->_input->toggleActionIfActive(TwinEActionType::MoveForward)) {
@ -441,13 +439,15 @@ void Movements::processActorMovements(int32 actorIdx) {
break; break;
case kFollow: { case kFollow: {
int32 newAngle = getAngleAndSetTargetActorDistance(actor->x, actor->z, _engine->_scene->sceneActors[actor->followedActor].x, _engine->_scene->sceneActors[actor->followedActor].z); const ActorStruct* followedActor = _engine->_scene->getActor(actor->followedActor);
int32 newAngle = getAngleAndSetTargetActorDistance(actor->x, actor->z, followedActor->x, followedActor->z);
if (actor->staticFlags.bIsSpriteActor) { if (actor->staticFlags.bIsSpriteActor) {
actor->angle = newAngle; actor->angle = newAngle;
} else { } else {
moveActor(actor->angle, newAngle, actor->speed, &actor->move); moveActor(actor->angle, newAngle, actor->speed, &actor->move);
} }
} break; break;
}
case kTrack: case kTrack:
if (actor->positionInMoveScript == -1) { if (actor->positionInMoveScript == -1) {
actor->positionInMoveScript = 0; actor->positionInMoveScript = 0;
@ -456,10 +456,12 @@ void Movements::processActorMovements(int32 actorIdx) {
case kFollow2: // unused case kFollow2: // unused
case kTrackAttack: // unused case kTrackAttack: // unused
break; break;
case kSameXZ: case kSameXZ: {
actor->x = _engine->_scene->sceneActors[actor->followedActor].x; const ActorStruct* followedActor = _engine->_scene->getActor(actor->followedActor);
actor->z = _engine->_scene->sceneActors[actor->followedActor].z; actor->x = followedActor->x;
actor->z = followedActor->z;
break; break;
}
case kRandom: { case kRandom: {
if (!actor->dynamicFlags.bIsRotationByAnim) { if (!actor->dynamicFlags.bIsRotationByAnim) {
if (actor->brickShape & 0x80) { if (actor->brickShape & 0x80) {

View File

@ -26,10 +26,11 @@
#include "twine/actor.h" #include "twine/actor.h"
#include "twine/animations.h" #include "twine/animations.h"
#include "twine/collision.h" #include "twine/collision.h"
#include "twine/debug_scene.h"
#include "twine/grid.h" #include "twine/grid.h"
#include "twine/hqrdepack.h" #include "twine/hqrdepack.h"
#include "twine/interface.h"
#include "twine/input.h" #include "twine/input.h"
#include "twine/interface.h"
#include "twine/menu.h" #include "twine/menu.h"
#include "twine/movements.h" #include "twine/movements.h"
#include "twine/renderer.h" #include "twine/renderer.h"
@ -38,7 +39,6 @@
#include "twine/screens.h" #include "twine/screens.h"
#include "twine/sound.h" #include "twine/sound.h"
#include "twine/text.h" #include "twine/text.h"
#include "twine/debug_scene.h"
namespace TwinE { namespace TwinE {
@ -149,7 +149,7 @@ void Redraw::blitBackgroundAreas() {
const RedrawStruct *currentArea = currentRedrawList; const RedrawStruct *currentArea = currentRedrawList;
for (int32 i = 0; i < numOfRedrawBox; i++) { for (int32 i = 0; i < numOfRedrawBox; i++) {
_engine->_interface->blitBox(currentArea->left, currentArea->top, currentArea->right, currentArea->bottom, (const int8*)_engine->workVideoBuffer.getPixels(), currentArea->left, currentArea->top, (int8*)_engine->frontVideoBuffer.getPixels()); _engine->_interface->blitBox(currentArea->left, currentArea->top, currentArea->right, currentArea->bottom, (const int8 *)_engine->workVideoBuffer.getPixels(), currentArea->left, currentArea->top, (int8 *)_engine->frontVideoBuffer.getPixels());
currentArea++; currentArea++;
} }
} }
@ -233,10 +233,10 @@ void Redraw::redrawEngineActions(int32 bgRedraw) { // fullRedraw
// Process actors drawing list // Process actors drawing list
for (modelActorPos = 0; modelActorPos < _engine->_scene->sceneNumActors; modelActorPos++, spriteActorPos++, shadowActorPos++) { for (modelActorPos = 0; modelActorPos < _engine->_scene->sceneNumActors; modelActorPos++, spriteActorPos++, shadowActorPos++) {
actor = &_engine->_scene->sceneActors[modelActorPos]; actor = _engine->_scene->getActor(modelActorPos);
actor->dynamicFlags.bIsVisible = 0; // reset visible state actor->dynamicFlags.bIsVisible = 0; // reset visible state
if ((_engine->_grid->useCellingGrid == -1) || actor->y <= (*(int16 *)(_engine->_grid->cellingGridIdx * 24 + (int8 *)_engine->_scene->sceneZones + 8))) { if (_engine->_grid->useCellingGrid == -1 || actor->y <= (*(int16 *)(_engine->_grid->cellingGridIdx * 24 + (int8 *)_engine->_scene->sceneZones + 8))) {
// no redraw required // no redraw required
if (actor->staticFlags.bIsBackgrounded && bgRedraw == 0) { if (actor->staticFlags.bIsBackgrounded && bgRedraw == 0) {
// get actor position on screen // get actor position on screen
@ -259,7 +259,8 @@ void Redraw::redrawEngineActions(int32 bgRedraw) { // fullRedraw
// if actor is above another actor // if actor is above another actor
if (actor->standOn != -1) { if (actor->standOn != -1) {
tmpVal = _engine->_scene->sceneActors[actor->standOn].x - _engine->_grid->cameraX + _engine->_scene->sceneActors[actor->standOn].z - _engine->_grid->cameraZ + 2; const ActorStruct *standOnActor = _engine->_scene->getActor(actor->standOn);
tmpVal = standOnActor->x - _engine->_grid->cameraX + standOnActor->z - _engine->_grid->cameraZ + 2;
} }
if (actor->staticFlags.bIsSpriteActor) { if (actor->staticFlags.bIsSpriteActor) {
@ -346,7 +347,7 @@ void Redraw::redrawEngineActions(int32 bgRedraw) { // fullRedraw
do { do {
int32 actorIdx = drawList[pos].index & 0x3FF; int32 actorIdx = drawList[pos].index & 0x3FF;
ActorStruct *actor2 = &_engine->_scene->sceneActors[actorIdx]; ActorStruct *actor2 = _engine->_scene->getActor(actorIdx);
uint32 flags = ((uint32)drawList[pos].index) & 0xFC00; uint32 flags = ((uint32)drawList[pos].index) & 0xFC00;
// Drawing actors // Drawing actors
@ -393,7 +394,7 @@ void Redraw::redrawEngineActions(int32 bgRedraw) { // fullRedraw
addRedrawArea(_engine->_interface->textWindowLeft, _engine->_interface->textWindowTop, renderRight, renderBottom); addRedrawArea(_engine->_interface->textWindowLeft, _engine->_interface->textWindowTop, renderRight, renderBottom);
if (actor2->staticFlags.bIsBackgrounded && bgRedraw == 1) { if (actor2->staticFlags.bIsBackgrounded && bgRedraw == 1) {
_engine->_interface->blitBox(_engine->_interface->textWindowLeft, _engine->_interface->textWindowTop, renderRight, renderBottom, (const int8*)_engine->frontVideoBuffer.getPixels(), _engine->_interface->textWindowLeft, _engine->_interface->textWindowTop, (int8*)_engine->workVideoBuffer.getPixels()); _engine->_interface->blitBox(_engine->_interface->textWindowLeft, _engine->_interface->textWindowTop, renderRight, renderBottom, (const int8 *)_engine->frontVideoBuffer.getPixels(), _engine->_interface->textWindowLeft, _engine->_interface->textWindowTop, (int8 *)_engine->workVideoBuffer.getPixels());
} }
} }
} }
@ -479,7 +480,7 @@ void Redraw::redrawEngineActions(int32 bgRedraw) { // fullRedraw
addRedrawArea(_engine->_interface->textWindowLeft, _engine->_interface->textWindowTop, _engine->_interface->textWindowRight, _engine->_interface->textWindowBottom); addRedrawArea(_engine->_interface->textWindowLeft, _engine->_interface->textWindowTop, _engine->_interface->textWindowRight, _engine->_interface->textWindowBottom);
if (actor2->staticFlags.bIsBackgrounded && bgRedraw == 1) { if (actor2->staticFlags.bIsBackgrounded && bgRedraw == 1) {
_engine->_interface->blitBox(_engine->_interface->textWindowLeft, _engine->_interface->textWindowTop, _engine->_interface->textWindowRight, _engine->_interface->textWindowBottom, (const int8*)_engine->frontVideoBuffer.getPixels(), _engine->_interface->textWindowLeft, _engine->_interface->textWindowTop, (int8*)_engine->workVideoBuffer.getPixels()); _engine->_interface->blitBox(_engine->_interface->textWindowLeft, _engine->_interface->textWindowTop, _engine->_interface->textWindowRight, _engine->_interface->textWindowBottom, (const int8 *)_engine->frontVideoBuffer.getPixels(), _engine->_interface->textWindowLeft, _engine->_interface->textWindowTop, (int8 *)_engine->workVideoBuffer.getPixels());
} }
// show clipping area // show clipping area
@ -543,7 +544,7 @@ void Redraw::redrawEngineActions(int32 bgRedraw) { // fullRedraw
} }
break; break;
case koFollowActor: { case koFollowActor: {
ActorStruct *actor2 = &_engine->_scene->sceneActors[overlay->info1]; ActorStruct *actor2 = _engine->_scene->getActor(overlay->info1);
_engine->_renderer->projectPositionOnScreen(actor2->x - _engine->_grid->cameraX, actor2->y + actor2->boudingBox.y.topRight - _engine->_grid->cameraY, actor2->z - _engine->_grid->cameraZ); _engine->_renderer->projectPositionOnScreen(actor2->x - _engine->_grid->cameraX, actor2->y + actor2->boudingBox.y.topRight - _engine->_grid->cameraY, actor2->z - _engine->_grid->cameraZ);
@ -554,7 +555,8 @@ void Redraw::redrawEngineActions(int32 bgRedraw) { // fullRedraw
overlay->info0 = -1; overlay->info0 = -1;
continue; continue;
} }
} break; break;
}
} }
// process overlay type // process overlay type
@ -579,8 +581,8 @@ void Redraw::redrawEngineActions(int32 bgRedraw) { // fullRedraw
if (_engine->_interface->textWindowLeft <= _engine->_interface->textWindowRight && _engine->_interface->textWindowTop <= _engine->_interface->textWindowBottom) { if (_engine->_interface->textWindowLeft <= _engine->_interface->textWindowRight && _engine->_interface->textWindowTop <= _engine->_interface->textWindowBottom) {
addRedrawArea(_engine->_interface->textWindowLeft, _engine->_interface->textWindowTop, renderRight, renderBottom); addRedrawArea(_engine->_interface->textWindowLeft, _engine->_interface->textWindowTop, renderRight, renderBottom);
} }
break;
} break; }
case koNumber: { case koNumber: {
int32 textLength, textHeight; int32 textLength, textHeight;
char text[10]; char text[10];
@ -603,7 +605,8 @@ void Redraw::redrawEngineActions(int32 bgRedraw) { // fullRedraw
if (_engine->_interface->textWindowLeft <= _engine->_interface->textWindowRight && _engine->_interface->textWindowTop <= _engine->_interface->textWindowBottom) { if (_engine->_interface->textWindowLeft <= _engine->_interface->textWindowRight && _engine->_interface->textWindowTop <= _engine->_interface->textWindowBottom) {
addRedrawArea(_engine->_interface->textWindowLeft, _engine->_interface->textWindowTop, renderRight, renderBottom); addRedrawArea(_engine->_interface->textWindowLeft, _engine->_interface->textWindowTop, renderRight, renderBottom);
} }
} break; break;
}
case koNumberRange: { case koNumberRange: {
int32 textLength, textHeight, range; int32 textLength, textHeight, range;
char text[10]; char text[10];
@ -629,7 +632,8 @@ void Redraw::redrawEngineActions(int32 bgRedraw) { // fullRedraw
if (_engine->_interface->textWindowLeft <= _engine->_interface->textWindowRight && _engine->_interface->textWindowTop <= _engine->_interface->textWindowBottom) { if (_engine->_interface->textWindowLeft <= _engine->_interface->textWindowRight && _engine->_interface->textWindowTop <= _engine->_interface->textWindowBottom) {
addRedrawArea(_engine->_interface->textWindowLeft, _engine->_interface->textWindowTop, renderRight, renderBottom); addRedrawArea(_engine->_interface->textWindowLeft, _engine->_interface->textWindowTop, renderRight, renderBottom);
} }
} break; break;
}
case koInventoryItem: { case koInventoryItem: {
int32 item = overlay->info0; int32 item = overlay->info0;
@ -646,7 +650,8 @@ void Redraw::redrawEngineActions(int32 bgRedraw) { // fullRedraw
_engine->_menu->drawBox(10, 10, 69, 69); _engine->_menu->drawBox(10, 10, 69, 69);
addRedrawArea(10, 10, 69, 69); addRedrawArea(10, 10, 69, 69);
_engine->_gameState->initEngineProjections(); _engine->_gameState->initEngineProjections();
} break; break;
}
case koText: { case koText: {
char text[256]; char text[256];
@ -678,14 +683,15 @@ void Redraw::redrawEngineActions(int32 bgRedraw) { // fullRedraw
_engine->_interface->setClip(renderLeft, renderTop, renderRight, renderBottom); _engine->_interface->setClip(renderLeft, renderTop, renderRight, renderBottom);
_engine->_text->setFontColor(_engine->_scene->sceneActors[overlay->info1].talkColor); _engine->_text->setFontColor(_engine->_scene->getActor(overlay->info1)->talkColor);
_engine->_text->drawText(renderLeft, renderTop, text); _engine->_text->drawText(renderLeft, renderTop, text);
if (_engine->_interface->textWindowLeft <= _engine->_interface->textWindowRight && _engine->_interface->textWindowTop <= _engine->_interface->textWindowBottom) { if (_engine->_interface->textWindowLeft <= _engine->_interface->textWindowRight && _engine->_interface->textWindowTop <= _engine->_interface->textWindowBottom) {
addRedrawArea(_engine->_interface->textWindowLeft, _engine->_interface->textWindowTop, renderRight, renderBottom); addRedrawArea(_engine->_interface->textWindowLeft, _engine->_interface->textWindowTop, renderRight, renderBottom);
} }
} break; break;
}
} }
} }
} }
@ -724,7 +730,7 @@ void Redraw::redrawEngineActions(int32 bgRedraw) { // fullRedraw
void Redraw::drawBubble(int32 actorIdx) { void Redraw::drawBubble(int32 actorIdx) {
int32 spriteWidth, spriteHeight; int32 spriteWidth, spriteHeight;
uint8 *spritePtr; uint8 *spritePtr;
ActorStruct *actor = &_engine->_scene->sceneActors[actorIdx]; ActorStruct *actor = _engine->_scene->getActor(actorIdx);
// get actor position on screen // get actor position on screen
_engine->_renderer->projectPositionOnScreen(actor->x - _engine->_grid->cameraX, actor->y + actor->boudingBox.y.topRight - _engine->_grid->cameraY, actor->z - _engine->_grid->cameraZ); _engine->_renderer->projectPositionOnScreen(actor->x - _engine->_grid->cameraX, actor->y + actor->boudingBox.y.topRight - _engine->_grid->cameraY, actor->z - _engine->_grid->cameraZ);
@ -762,8 +768,8 @@ void Redraw::zoomScreenScale() {
zoomWorkVideoBuffer.copyFrom(_engine->workVideoBuffer); zoomWorkVideoBuffer.copyFrom(_engine->workVideoBuffer);
// TODO: this is broken // TODO: this is broken
const uint8 *src = (const uint8*)zoomWorkVideoBuffer.getPixels(); const uint8 *src = (const uint8 *)zoomWorkVideoBuffer.getPixels();
uint8 *dest = (uint8*)_engine->workVideoBuffer.getPixels(); uint8 *dest = (uint8 *)_engine->workVideoBuffer.getPixels();
for (int h = 0; h < zoomWorkVideoBuffer.h; h++) { for (int h = 0; h < zoomWorkVideoBuffer.h; h++) {
for (int w = 0; w < zoomWorkVideoBuffer.w; w++) { for (int w = 0; w < zoomWorkVideoBuffer.w; w++) {
*dest++ = *src; *dest++ = *src;

View File

@ -393,6 +393,12 @@ void Scene::changeScene() {
} }
} }
ActorStruct* Scene::getActor(int32 actorIdx) {
assert(actorIdx >= 0);
assert(actorIdx < NUM_MAX_ACTORS);
return &sceneActors[actorIdx];
}
void Scene::processEnvironmentSound() { void Scene::processEnvironmentSound() {
int16 s, currentAmb, decal, repeat; int16 s, currentAmb, decal, repeat;
int16 sampleIdx = -1; int16 sampleIdx = -1;

View File

@ -99,6 +99,8 @@ enum ZoneType {
kLadder = 6 // Hero can climb on it kLadder = 6 // Hero can climb on it
}; };
#define OWN_ACTOR_SCENE_INDEX 0
class TwinEEngine; class TwinEEngine;
class Scene { class Scene {
private: private:
@ -113,6 +115,9 @@ private:
/** Reset scene */ /** Reset scene */
void resetScene(); void resetScene();
// the first actor is the own hero
ActorStruct sceneActors[NUM_MAX_ACTORS];
public: public:
Scene(TwinEEngine *engine) : _engine(engine) {} Scene(TwinEEngine *engine) : _engine(engine) {}
@ -162,9 +167,8 @@ public:
// ACTORS // ACTORS
int32 sceneNumActors = 0; int32 sceneNumActors = 0;
// the first actor is the own hero
ActorStruct sceneActors[NUM_MAX_ACTORS];
ActorStruct *sceneHero = nullptr; ActorStruct *sceneHero = nullptr;
ActorStruct* getActor(int32 actorIdx);
/** Meca pinguin actor index */ /** Meca pinguin actor index */
int16 mecaPinguinIdx = 0; // currentPingouin int16 mecaPinguinIdx = 0; // currentPingouin

View File

@ -126,17 +126,16 @@ static int32 processLifeConditions(TwinEEngine *engine, ActorStruct *actor) {
break; break;
case kcCOL_OBJ: { case kcCOL_OBJ: {
int32 actorIdx = *(scriptPtr++); int32 actorIdx = *(scriptPtr++);
if (engine->_scene->sceneActors[actorIdx].life <= 0) { if (engine->_scene->getActor(actorIdx)->life <= 0) {
engine->_scene->currentScriptValue = -1; engine->_scene->currentScriptValue = -1;
} else { } else {
engine->_scene->currentScriptValue = engine->_scene->sceneActors[actorIdx].collision; engine->_scene->currentScriptValue = engine->_scene->getActor(actorIdx)->collision;
} }
} break; } break;
case kcDISTANCE: { case kcDISTANCE: {
ActorStruct *otherActor;
int32 actorIdx = *(scriptPtr++); int32 actorIdx = *(scriptPtr++);
conditionValueSize = 2; conditionValueSize = 2;
otherActor = &engine->_scene->sceneActors[actorIdx]; ActorStruct *otherActor = engine->_scene->getActor(actorIdx);
if (!otherActor->dynamicFlags.bIsDead) { if (!otherActor->dynamicFlags.bIsDead) {
if (ABS(actor->y - otherActor->y) >= 1500) { if (ABS(actor->y - otherActor->y) >= 1500) {
engine->_scene->currentScriptValue = MAX_TARGET_ACTOR_DISTANCE; engine->_scene->currentScriptValue = MAX_TARGET_ACTOR_DISTANCE;
@ -158,41 +157,37 @@ static int32 processLifeConditions(TwinEEngine *engine, ActorStruct *actor) {
break; break;
case kcZONE_OBJ: { case kcZONE_OBJ: {
int32 actorIdx = *(scriptPtr++); int32 actorIdx = *(scriptPtr++);
engine->_scene->currentScriptValue = engine->_scene->sceneActors[actorIdx].zone; engine->_scene->currentScriptValue = engine->_scene->getActor(actorIdx)->zone;
} break; } break;
case kcBODY: case kcBODY:
engine->_scene->currentScriptValue = actor->body; engine->_scene->currentScriptValue = actor->body;
break; break;
case kcBODY_OBJ: { case kcBODY_OBJ: {
int32 actorIdx = *(scriptPtr++); int32 actorIdx = *(scriptPtr++);
engine->_scene->currentScriptValue = engine->_scene->sceneActors[actorIdx].body; engine->_scene->currentScriptValue = engine->_scene->getActor(actorIdx)->body;
} break; } break;
case kcANIM: case kcANIM:
engine->_scene->currentScriptValue = actor->anim; engine->_scene->currentScriptValue = actor->anim;
break; break;
case kcANIM_OBJ: { case kcANIM_OBJ: {
int32 actorIdx = *(scriptPtr++); int32 actorIdx = *(scriptPtr++);
engine->_scene->currentScriptValue = engine->_scene->sceneActors[actorIdx].anim; engine->_scene->currentScriptValue = engine->_scene->getActor(actorIdx)->anim;
} break; } break;
case kcL_TRACK: case kcL_TRACK:
engine->_scene->currentScriptValue = actor->labelIdx; engine->_scene->currentScriptValue = actor->labelIdx;
break; break;
case kcL_TRACK_OBJ: { case kcL_TRACK_OBJ: {
int32 actorIdx = *(scriptPtr++); int32 actorIdx = *(scriptPtr++);
engine->_scene->currentScriptValue = engine->_scene->sceneActors[actorIdx].labelIdx; engine->_scene->currentScriptValue = engine->_scene->getActor(actorIdx)->labelIdx;
} break; } break;
case kcFLAG_CUBE: { case kcFLAG_CUBE: {
int32 flagIdx = *(scriptPtr++); int32 flagIdx = *(scriptPtr++);
engine->_scene->currentScriptValue = engine->_scene->sceneFlags[flagIdx]; engine->_scene->currentScriptValue = engine->_scene->sceneFlags[flagIdx];
} break; } break;
case kcCONE_VIEW: { case kcCONE_VIEW: {
int32 newAngle; int32 newAngle = 0;
int32 targetActorIdx; int32 targetActorIdx = *(scriptPtr++);
ActorStruct *targetActor; ActorStruct *targetActor = engine->_scene->getActor(targetActorIdx);
newAngle = 0;
targetActorIdx = *(scriptPtr++);
targetActor = &engine->_scene->sceneActors[targetActorIdx];
conditionValueSize = 2; conditionValueSize = 2;
@ -261,7 +256,7 @@ static int32 processLifeConditions(TwinEEngine *engine, ActorStruct *actor) {
break; break;
case kcLIFE_POINT_OBJ: { case kcLIFE_POINT_OBJ: {
int32 actorIdx = *(scriptPtr++); int32 actorIdx = *(scriptPtr++);
engine->_scene->currentScriptValue = engine->_scene->sceneActors[actorIdx].life; engine->_scene->currentScriptValue = engine->_scene->getActor(actorIdx)->life;
} break; } break;
case kcNUM_LITTLE_KEYS: case kcNUM_LITTLE_KEYS:
engine->_scene->currentScriptValue = engine->_gameState->inventoryNumKeys; engine->_scene->currentScriptValue = engine->_gameState->inventoryNumKeys;
@ -281,7 +276,7 @@ static int32 processLifeConditions(TwinEEngine *engine, ActorStruct *actor) {
ActorStruct *targetActor; ActorStruct *targetActor;
targetActorIdx = *(scriptPtr++); targetActorIdx = *(scriptPtr++);
targetActor = &engine->_scene->sceneActors[targetActorIdx]; targetActor = engine->_scene->getActor(targetActorIdx);
conditionValueSize = 2; conditionValueSize = 2;
@ -544,7 +539,7 @@ static int32 lSET_LIFE(TwinEEngine *engine, int32 actorIdx, ActorStruct *actor)
/*0x16*/ /*0x16*/
static int32 lSET_LIFE_OBJ(TwinEEngine *engine, int32 actorIdx, ActorStruct *actor) { static int32 lSET_LIFE_OBJ(TwinEEngine *engine, int32 actorIdx, ActorStruct *actor) {
int32 otherActorIdx = *(scriptPtr++); int32 otherActorIdx = *(scriptPtr++);
engine->_scene->sceneActors[otherActorIdx].positionInLifeScript = *((int16 *)scriptPtr); // offset engine->_scene->getActor(otherActorIdx)->positionInLifeScript = *((int16 *)scriptPtr); // offset
scriptPtr += 2; scriptPtr += 2;
return 0; return 0;
} }
@ -559,7 +554,7 @@ static int32 lSET_TRACK(TwinEEngine *engine, int32 actorIdx, ActorStruct *actor)
/*0x18*/ /*0x18*/
static int32 lSET_TRACK_OBJ(TwinEEngine *engine, int32 actorIdx, ActorStruct *actor) { static int32 lSET_TRACK_OBJ(TwinEEngine *engine, int32 actorIdx, ActorStruct *actor) {
int32 otherActorIdx = *(scriptPtr++); int32 otherActorIdx = *(scriptPtr++);
engine->_scene->sceneActors[otherActorIdx].positionInMoveScript = *((int16 *)scriptPtr); // offset engine->_scene->getActor(otherActorIdx)->positionInMoveScript = *((int16 *)scriptPtr); // offset
scriptPtr += 2; scriptPtr += 2;
return 0; return 0;
} }
@ -606,9 +601,9 @@ static int32 lSET_DIRMODE_OBJ(TwinEEngine *engine, int32 actorIdx, ActorStruct *
int32 otherActorIdx = *(scriptPtr++); int32 otherActorIdx = *(scriptPtr++);
int32 controlMode = *(scriptPtr++); int32 controlMode = *(scriptPtr++);
engine->_scene->sceneActors[otherActorIdx].controlMode = controlMode; engine->_scene->getActor(otherActorIdx)->controlMode = controlMode;
if (controlMode == kFollow) { if (controlMode == kFollow) {
engine->_scene->sceneActors[otherActorIdx].followedActor = *(scriptPtr++); engine->_scene->getActor(otherActorIdx)->followedActor = *(scriptPtr++);
} }
return 0; return 0;
@ -616,13 +611,13 @@ static int32 lSET_DIRMODE_OBJ(TwinEEngine *engine, int32 actorIdx, ActorStruct *
/*0x1D*/ /*0x1D*/
static int32 lCAM_FOLLOW(TwinEEngine *engine, int32 actorIdx, ActorStruct *actor) { static int32 lCAM_FOLLOW(TwinEEngine *engine, int32 actorIdx, ActorStruct *actor) {
int32 followedActorIdx; int32 followedActorIdx = *(scriptPtr++);
followedActorIdx = *(scriptPtr++);
if (engine->_scene->currentlyFollowedActor != followedActorIdx) { if (engine->_scene->currentlyFollowedActor != followedActorIdx) {
engine->_grid->newCameraX = engine->_scene->sceneActors[followedActorIdx].x >> 9; const ActorStruct* followedActor = engine->_scene->getActor(followedActorIdx);
engine->_grid->newCameraY = engine->_scene->sceneActors[followedActorIdx].y >> 8; engine->_grid->newCameraX = followedActor->x >> 9;
engine->_grid->newCameraZ = engine->_scene->sceneActors[followedActorIdx].z >> 9; engine->_grid->newCameraY = followedActor->y >> 8;
engine->_grid->newCameraZ = followedActor->z >> 9;
engine->_scene->currentlyFollowedActor = followedActorIdx; engine->_scene->currentlyFollowedActor = followedActorIdx;
engine->_redraw->reqBgRedraw = true; engine->_redraw->reqBgRedraw = true;
@ -668,7 +663,7 @@ static int32 lSET_COMPORTEMENT(TwinEEngine *engine, int32 actorIdx, ActorStruct
static int32 lSET_COMPORTEMENT_OBJ(TwinEEngine *engine, int32 actorIdx, ActorStruct *actor) { static int32 lSET_COMPORTEMENT_OBJ(TwinEEngine *engine, int32 actorIdx, ActorStruct *actor) {
int32 otherActorIdx = *(scriptPtr++); int32 otherActorIdx = *(scriptPtr++);
engine->_scene->sceneActors[otherActorIdx].positionInLifeScript = *((int16 *)scriptPtr); engine->_scene->getActor(otherActorIdx)->positionInLifeScript = *((int16 *)scriptPtr);
scriptPtr += 2; scriptPtr += 2;
return 0; return 0;
@ -694,10 +689,10 @@ static int32 lKILL_OBJ(TwinEEngine *engine, int32 actorIdx, ActorStruct *actor)
int32 otherActorIdx = *(scriptPtr++); int32 otherActorIdx = *(scriptPtr++);
engine->_actor->processActorCarrier(otherActorIdx); engine->_actor->processActorCarrier(otherActorIdx);
engine->_scene->sceneActors[otherActorIdx].dynamicFlags.bIsDead = 1; engine->_scene->getActor(otherActorIdx)->dynamicFlags.bIsDead = 1;
engine->_scene->sceneActors[otherActorIdx].entity = -1; engine->_scene->getActor(otherActorIdx)->entity = -1;
engine->_scene->sceneActors[otherActorIdx].zone = -1; engine->_scene->getActor(otherActorIdx)->zone = -1;
engine->_scene->sceneActors[otherActorIdx].life = 0; engine->_scene->getActor(otherActorIdx)->life = 0;
return 0; return 0;
} }
@ -790,7 +785,7 @@ static int32 lMESSAGE_OBJ(TwinEEngine *engine, int32 actorIdx, ActorStruct *acto
if (engine->_text->showDialogueBubble) { if (engine->_text->showDialogueBubble) {
engine->_redraw->drawBubble(otherActorIdx); engine->_redraw->drawBubble(otherActorIdx);
} }
engine->_text->setFontCrossColor(engine->_scene->sceneActors[otherActorIdx].talkColor); engine->_text->setFontCrossColor(engine->_scene->getActor(otherActorIdx)->talkColor);
engine->_scene->talkingActor = otherActorIdx; engine->_scene->talkingActor = otherActorIdx;
engine->_text->drawTextFullscreen(textIdx); engine->_text->drawTextFullscreen(textIdx);
engine->unfreezeTime(); engine->unfreezeTime();
@ -993,7 +988,7 @@ static int32 lSET_LIFE_POINT_OBJ(TwinEEngine *engine, int32 actorIdx, ActorStruc
int32 otherActorIdx = *(scriptPtr++); int32 otherActorIdx = *(scriptPtr++);
static int32 lifeValue = *(scriptPtr++); static int32 lifeValue = *(scriptPtr++);
engine->_scene->sceneActors[otherActorIdx].life = lifeValue; engine->_scene->getActor(otherActorIdx)->life = lifeValue;
return 0; return 0;
} }
@ -1003,10 +998,10 @@ static int32 lSUB_LIFE_POINT_OBJ(TwinEEngine *engine, int32 actorIdx, ActorStruc
int32 otherActorIdx = *(scriptPtr++); int32 otherActorIdx = *(scriptPtr++);
static int32 lifeValue = *(scriptPtr++); static int32 lifeValue = *(scriptPtr++);
engine->_scene->sceneActors[otherActorIdx].life -= lifeValue; engine->_scene->getActor(otherActorIdx)->life -= lifeValue;
if (engine->_scene->sceneActors[otherActorIdx].life < 0) { if (engine->_scene->getActor(otherActorIdx)->life < 0) {
engine->_scene->sceneActors[otherActorIdx].life = 0; engine->_scene->getActor(otherActorIdx)->life = 0;
} }
return 0; return 0;
@ -1016,7 +1011,7 @@ static int32 lSUB_LIFE_POINT_OBJ(TwinEEngine *engine, int32 actorIdx, ActorStruc
static int32 lHIT_OBJ(TwinEEngine *engine, int32 actorIdx, ActorStruct *actor) { static int32 lHIT_OBJ(TwinEEngine *engine, int32 actorIdx, ActorStruct *actor) {
int32 otherActorIdx = *(scriptPtr++); int32 otherActorIdx = *(scriptPtr++);
int32 strengthOfHit = *(scriptPtr++); int32 strengthOfHit = *(scriptPtr++);
engine->_actor->hitActor(actorIdx, otherActorIdx, strengthOfHit, engine->_scene->sceneActors[otherActorIdx].angle); engine->_actor->hitActor(actorIdx, otherActorIdx, strengthOfHit, engine->_scene->getActor(otherActorIdx)->angle);
return 0; return 0;
} }
@ -1107,17 +1102,17 @@ static int32 lBIG_MESSAGE(TwinEEngine *engine, int32 actorIdx, ActorStruct *acto
/*0x47*/ /*0x47*/
static int32 lINIT_PINGOUIN(TwinEEngine *engine, int32 actorIdx, ActorStruct *actor) { static int32 lINIT_PINGOUIN(TwinEEngine *engine, int32 actorIdx, ActorStruct *actor) {
int32 pingouinActor = *(scriptPtr++); int32 pingouinActor = *(scriptPtr++);
engine->_scene->sceneActors[pingouinActor].dynamicFlags.bIsDead = 1;
engine->_scene->mecaPinguinIdx = pingouinActor; engine->_scene->mecaPinguinIdx = pingouinActor;
engine->_scene->sceneActors[pingouinActor].entity = -1; ActorStruct* mecaPinguin = engine->_scene->getActor(pingouinActor);
engine->_scene->sceneActors[pingouinActor].zone = -1; mecaPinguin->dynamicFlags.bIsDead = 1;
mecaPinguin->entity = -1;
mecaPinguin->zone = -1;
return 0; return 0;
} }
/*0x48*/ /*0x48*/
static int32 lSET_HOLO_POS(TwinEEngine *engine, int32 actorIdx, ActorStruct *actor) { static int32 lSET_HOLO_POS(TwinEEngine *engine, int32 actorIdx, ActorStruct *actor) {
static int32 location = *(scriptPtr++); static int32 location = *(scriptPtr++);
engine->_holomap->setHolomapPosition(location); engine->_holomap->setHolomapPosition(location);
if (engine->_gameState->gameFlags[InventoryItems::kiHolomap]) { if (engine->_gameState->gameFlags[InventoryItems::kiHolomap]) {
engine->_redraw->addOverlay(koInventoryItem, 0, 0, 0, 0, koNormal, 3); engine->_redraw->addOverlay(koInventoryItem, 0, 0, 0, 0, koNormal, 3);
@ -1280,7 +1275,7 @@ static int32 lFADE_PAL_ALARM(TwinEEngine *engine, int32 actorIdx, ActorStruct *a
/*0x58*/ /*0x58*/
static int32 lEXPLODE_OBJ(TwinEEngine *engine, int32 actorIdx, ActorStruct *actor) { static int32 lEXPLODE_OBJ(TwinEEngine *engine, int32 actorIdx, ActorStruct *actor) {
int32 otherActorIdx = *(scriptPtr++); int32 otherActorIdx = *(scriptPtr++);
ActorStruct *otherActor = &engine->_scene->sceneActors[otherActorIdx]; ActorStruct *otherActor = engine->_scene->getActor(otherActorIdx);
engine->_extra->addExtraExplode(otherActor->x, otherActor->y, otherActor->z); // RECHECK this engine->_extra->addExtraExplode(otherActor->x, otherActor->y, otherActor->z); // RECHECK this
@ -1309,7 +1304,7 @@ static int32 lASK_CHOICE_OBJ(TwinEEngine *engine, int32 actorIdx, ActorStruct *a
if (engine->_text->showDialogueBubble) { if (engine->_text->showDialogueBubble) {
engine->_redraw->drawBubble(otherActorIdx); engine->_redraw->drawBubble(otherActorIdx);
} }
engine->_text->setFontCrossColor(engine->_scene->sceneActors[otherActorIdx].talkColor); engine->_text->setFontCrossColor(engine->_scene->getActor(otherActorIdx)->talkColor);
engine->_gameState->processGameChoices(choiceIdx); engine->_gameState->processGameChoices(choiceIdx);
engine->_gameState->numChoices = 0; engine->_gameState->numChoices = 0;
engine->unfreezeTime(); engine->unfreezeTime();
@ -1602,17 +1597,14 @@ ScriptLife::ScriptLife(TwinEEngine *engine) : _engine(engine) {
} }
void ScriptLife::processLifeScript(int32 actorIdx) { void ScriptLife::processLifeScript(int32 actorIdx) {
int32 end, scriptOpcode; ActorStruct *actor = _engine->_scene->getActor(actorIdx);
ActorStruct *actor;
actor = &_engine->_scene->sceneActors[actorIdx];
scriptPtr = actor->lifeScript + actor->positionInLifeScript; scriptPtr = actor->lifeScript + actor->positionInLifeScript;
end = -2; int32 end = -2;
do { do {
opcodePtr = scriptPtr; opcodePtr = scriptPtr;
scriptOpcode = *(scriptPtr++); int32 scriptOpcode = *(scriptPtr++);
if (scriptOpcode >= 0 && scriptOpcode < ARRAYSIZE(function_map)) { if (scriptOpcode >= 0 && scriptOpcode < ARRAYSIZE(function_map)) {
end = function_map[scriptOpcode].function(_engine, actorIdx, actor); end = function_map[scriptOpcode].function(_engine, actorIdx, actor);

View File

@ -583,17 +583,14 @@ ScriptMove::ScriptMove(TwinEEngine *engine) : _engine(engine) {
} }
void ScriptMove::processMoveScript(int32 actorIdx) { void ScriptMove::processMoveScript(int32 actorIdx) {
int32 scriptOpcode;
ActorStruct *actor;
continueMove = 1; continueMove = 1;
actor = &_engine->_scene->sceneActors[actorIdx]; ActorStruct *actor = _engine->_scene->getActor(actorIdx);
move = &actor->move; move = &actor->move;
do { do {
scriptPosition = actor->positionInMoveScript; scriptPosition = actor->positionInMoveScript;
scriptPtr = actor->moveScript + scriptPosition; scriptPtr = actor->moveScript + scriptPosition;
scriptOpcode = *(scriptPtr++); int32 scriptOpcode = *(scriptPtr++);
actor->positionInMoveScript++; actor->positionInMoveScript++;

View File

@ -295,7 +295,7 @@ void TwinEEngine::initAll() {
_redraw->bubbleSpriteIndex = SPRITEHQR_DIAG_BUBBLE_LEFT; _redraw->bubbleSpriteIndex = SPRITEHQR_DIAG_BUBBLE_LEFT;
_scene->sceneHero = &_scene->sceneActors[0]; _scene->sceneHero = _scene->getActor(OWN_ACTOR_SCENE_INDEX);
_redraw->renderRight = SCREEN_TEXTLIMIT_RIGHT; _redraw->renderRight = SCREEN_TEXTLIMIT_RIGHT;
_redraw->renderBottom = SCREEN_TEXTLIMIT_BOTTOM; _redraw->renderBottom = SCREEN_TEXTLIMIT_BOTTOM;
@ -328,7 +328,7 @@ void TwinEEngine::unfreezeTime() {
} }
void TwinEEngine::processActorSamplePosition(int32 actorIdx) { void TwinEEngine::processActorSamplePosition(int32 actorIdx) {
const ActorStruct *actor = &_scene->sceneActors[actorIdx]; const ActorStruct *actor = _scene->getActor(actorIdx);
const int32 channelIdx = _sound->getActorChannel(actorIdx); const int32 channelIdx = _sound->getActorChannel(actorIdx);
_sound->setSamplePosition(channelIdx, actor->x, actor->y, actor->z); _sound->setSamplePosition(channelIdx, actor->x, actor->y, actor->z);
} }
@ -446,7 +446,7 @@ int32 TwinEEngine::runGameEngine() { // mainLoopInteration
} }
break; break;
case kiPinguin: { case kiPinguin: {
ActorStruct *pinguin = &_scene->sceneActors[_scene->mecaPinguinIdx]; ActorStruct *pinguin = _scene->getActor(_scene->mecaPinguinIdx);
pinguin->x = _renderer->destX + _scene->sceneHero->x; pinguin->x = _renderer->destX + _scene->sceneHero->x;
pinguin->y = _scene->sceneHero->y; pinguin->y = _scene->sceneHero->y;
@ -532,9 +532,10 @@ int32 TwinEEngine::runGameEngine() { // mainLoopInteration
// Recenter Screen // Recenter Screen
if (_input->isActionActive(TwinEActionType::RecenterScreenOnTwinsen) && !disableScreenRecenter) { if (_input->isActionActive(TwinEActionType::RecenterScreenOnTwinsen) && !disableScreenRecenter) {
_grid->newCameraX = _scene->sceneActors[_scene->currentlyFollowedActor].x >> 9; const ActorStruct* currentlyFollowedActor = _scene->getActor(_scene->currentlyFollowedActor);
_grid->newCameraY = _scene->sceneActors[_scene->currentlyFollowedActor].y >> 8; _grid->newCameraX = currentlyFollowedActor->x >> 9;
_grid->newCameraZ = _scene->sceneActors[_scene->currentlyFollowedActor].z >> 9; _grid->newCameraY = currentlyFollowedActor->y >> 8;
_grid->newCameraZ = currentlyFollowedActor->z >> 9;
_redraw->reqBgRedraw = true; _redraw->reqBgRedraw = true;
} }
@ -578,13 +579,13 @@ int32 TwinEEngine::runGameEngine() { // mainLoopInteration
// Reset HitBy state // Reset HitBy state
for (int32 a = 0; a < _scene->sceneNumActors; a++) { for (int32 a = 0; a < _scene->sceneNumActors; a++) {
_scene->sceneActors[a].hitBy = -1; _scene->getActor(a)->hitBy = -1;
} }
_extra->processExtras(); _extra->processExtras();
for (int32 a = 0; a < _scene->sceneNumActors; a++) { for (int32 a = 0; a < _scene->sceneNumActors; a++) {
ActorStruct *actor = &_scene->sceneActors[a]; ActorStruct *actor = _scene->getActor(a);
if (!actor->dynamicFlags.bIsDead) { if (!actor->dynamicFlags.bIsDead) {
if (actor->life == 0) { if (actor->life == 0) {
@ -723,7 +724,7 @@ int32 TwinEEngine::runGameEngine() { // mainLoopInteration
// recenter screen automatically // recenter screen automatically
if (!disableScreenRecenter && !_debugGrid->useFreeCamera) { if (!disableScreenRecenter && !_debugGrid->useFreeCamera) {
ActorStruct *actor = &_scene->sceneActors[_scene->currentlyFollowedActor]; ActorStruct *actor = _scene->getActor(_scene->currentlyFollowedActor);
_renderer->projectPositionOnScreen(actor->x - (_grid->newCameraX << 9), _renderer->projectPositionOnScreen(actor->x - (_grid->newCameraX << 9),
actor->y - (_grid->newCameraY << 8), actor->y - (_grid->newCameraY << 8),
actor->z - (_grid->newCameraZ << 9)); actor->z - (_grid->newCameraZ << 9));