00001
00025 #include <stdio.h>
00026 #include <stdlib.h>
00027 #include <string.h>
00028
00029 #include "actor.h"
00030 #include "lbaengine.h"
00031 #include "scene.h"
00032 #include "hqrdepack.h"
00033 #include "resources.h"
00034
00035 void preload_sprites()
00036 {
00037 int i;
00038 int numEntries = hqr_num_entries(HQR_SPRITES_FILE)-1;
00039
00040 for(i=0; i<numEntries; i++)
00041 {
00042
00043 spriteSizeTable[i] = hqr_entry_size(HQR_SPRITES_FILE,i);
00044 if(spriteTable[i])
00045 free(spriteTable[i]);
00046 spriteTable[i] = (unsigned char*)malloc(spriteSizeTable[i]);
00047 if(!spriteTable[i])
00048 {
00049 printf("SPRITE WARNING: unable to allocate brick memory!!\n");
00050 return;
00051 }
00052 hqr_get_entry(spriteTable[i], HQR_SPRITES_FILE, i);
00053 }
00054 }
00055
00056 void init_sprite_actor(int spriteIdx, int actorIdx)
00057 {
00058 ActorStruct *localActor = &sceneActors[actorIdx];
00059
00060 if (localActor->staticFlags.bIsSpriteActor && spriteIdx != -1 && localActor->entity != spriteIdx)
00061 {
00062 short int *ptr = (short int *) (spriteBoundingBoxPtr + spriteIdx * 16 + 4);
00063
00064 localActor->entity = spriteIdx;
00065 localActor->boudingBox.X.bottomLeft = *(ptr++);
00066 localActor->boudingBox.X.topRight = *(ptr++);
00067 localActor->boudingBox.Y.bottomLeft = *(ptr++);
00068 localActor->boudingBox.Y.topRight = *(ptr++);
00069 localActor->boudingBox.Z.bottomLeft = *(ptr++);
00070 localActor->boudingBox.Z.topRight = *(ptr++);
00071 }
00072 }
00073
00074 void init_actor(short int actorIdx)
00075 {
00076 ActorStruct *localActor = &sceneActors[actorIdx];
00077
00078 if (localActor->staticFlags.bIsSpriteActor)
00079 {
00080 if (localActor->strengthOfHit != 0)
00081 {
00082 localActor->dinamicFlags.bUnk0002 = 1;
00083 }
00084
00085 localActor->entity = -1;
00086
00087 init_sprite_actor(localActor->sprite, actorIdx);
00088
00089 set_actor_angle_safe(0, 0, 0, &localActor->time);
00090
00091 if (localActor->staticFlags.bUsesClipping)
00092 {
00093 localActor->lastX = localActor->X;
00094 localActor->lastY = localActor->Y;
00095 localActor->lastZ = localActor->Z;
00096 }
00097
00098 }
00099
00100 else
00101 {
00102 localActor->entity = -1;
00103
00104
00105
00106 localActor->previousAnimIdx = -1;
00107 localActor->field_78 = 0;
00108
00109 if (localActor->entity != -1)
00110 {
00111
00112 }
00113
00114 set_actor_angle_safe(localActor->angle, localActor->angle, 0, &localActor->time);
00115 }
00116
00117 localActor->positionInMoveScript = -1;
00118 localActor->labelIdx = -1;
00119 localActor->positionInActorScript = 0;
00120 }
00121
00122
00123 void set_actor_angle_safe(short int startAngle, short int endAngle, short int stepAngle, TimeStruct * timePtr)
00124 {
00125 timePtr->from = startAngle & 0x3FF;
00126 timePtr->to = endAngle & 0x3FF;
00127 timePtr->numOfStep = stepAngle & 0x3FF;
00128 timePtr->timeOfChange = lbaTime;
00129 }
00130
00131 void clear_real_angle(ActorStruct * ptr)
00132 {
00133 set_actor_angle_safe(ptr->angle, ptr->angle, 0, &ptr->time);
00134 }
00135
00136 void set_actor_angle(short int startAngle, short int endAngle, short int stepAngle, TimeStruct * timePtr)
00137 {
00138 timePtr->from = startAngle;
00139 timePtr->to = endAngle;
00140 timePtr->numOfStep = stepAngle;
00141 timePtr->timeOfChange = lbaTime;
00142 }
00143
00144
00145 int get_real_angle(TimeStruct * angleData)
00146 {
00147 int timePassed;
00148 int remainingAngle;
00149
00150 if (angleData->numOfStep)
00151 {
00152 timePassed = lbaTime - angleData->timeOfChange;
00153
00154 if (timePassed >= angleData->numOfStep)
00155 {
00156 angleData->numOfStep = 0;
00157 return (angleData->to);
00158 }
00159
00160 remainingAngle = angleData->to - angleData->from;
00161
00162 if (remainingAngle < -0x200)
00163 {
00164 remainingAngle += 0x400;
00165 }
00166 else if (remainingAngle > 0x200)
00167 {
00168 remainingAngle -= 0x400;
00169 }
00170
00171 remainingAngle *= timePassed;
00172 remainingAngle /= angleData->numOfStep;
00173 remainingAngle += angleData->from;
00174
00175 return (remainingAngle);
00176 }
00177
00178 return (angleData->to);
00179 }
00180
00181 int get_real_value(TimeStruct * angleData)
00182 {
00183 int tempAngle;
00184
00185 if (!angleData->numOfStep)
00186 return (angleData->to);
00187
00188 if (!(lbaTime - angleData->timeOfChange < angleData->numOfStep))
00189 {
00190 angleData->numOfStep = 0;
00191 return (angleData->to);
00192 }
00193
00194 tempAngle = angleData->to - angleData->from;
00195 tempAngle *= lbaTime - angleData->timeOfChange;
00196 tempAngle /= angleData->numOfStep;
00197
00198 return (tempAngle + angleData->from);
00199 }