#include #include "MyPad.h" #include "Arena.h" #include "tmd.h" #define RAW_ARENA_DATA 0x80090000 #define TEXA_ADDRESS 0x8009b000 #define TEXB_ADDRESS 0x8009c800 #define TEXC_ADDRESS 0x8009e000 #define TEXD_ADDRESS 0x8009f800 #define MECH_TEX_ADDRESS 0x800a1000 #define RAW_ENEMY_DATA 0x800b0000 #define GUN_ADDRESS 0x800b0300 #define HK_ADDRESS 0x800b0638 #define TMD_DYNAMIC_START 0x800c0000 #define OT_LENGTH 9 #define PACKETMAX 8192 #define PACKETMAX2 (PACKETMAX*24) #define SCREEN_WIDTH 320 #define SCREEN_HEIGHT 240 #define MAX_ENEMIES 255 #define OPTIONS 6 #define NUM_ENEMY_TYPES 2 #define ENEMY_GUN 0 #define ENEMY_HK 1 // Macros #define Greater(a, b) ( (a) = ((a) < (b)) ? (b) : (a) ) #define Less(a, b) ( (a) = ((a) > (b)) ? (b) : (a) ) #define LimitRange(a, b, c) ( ((a)<(b)) ? (b) : ((a)>(c) ? (c) : (a)) ) #define Abs(a) ( ((a) < 0) ? (-(a)) : (a) ) #define SetVector(v, x, y, z) \ (v)->vx = (x), \ (v)->vy = (y), \ (v)->vz = (z) // Struct for flashing cursor typedef struct { int x, z; u_char glow, mode, repeat; u_long pi, vi; int enemyType; } Cursor; typedef struct { short y0, y1, y2, y3; u_char r0, g0, b0; u_char r1, g1, b1; u_char tNum; } ClipBoard; typedef struct { u_char x, z; u_char type; } EnemyInfo; typedef struct { GsDOBJ2 handler; VECTOR pos; SVECTOR rot; GsCOORDINATE2 coord; u_char alive; } EnemyHandler; typedef struct { short num; EnemyInfo info[MAX_ENEMIES]; EnemyHandler handler[MAX_ENEMIES]; } EnemyStack; typedef struct { u_char num; EnemyInfo *enemy; } EnemySaveFormat; // General PS crap GsOT WorldOT[2]; GsOT_TAG OTTags[2][1<>6)+(cursor.z>>6)*64)*2; cursor.vi = (cursor.x>>6)+((cursor.z>>6)*65); cursor.mode = 0; cursor.enemyType = 0; // Init view GsSetProjection(1500); view.vpy = 500; view.vry = 0; view.vry = 0; view.rz = 180*ONE; view.super = WORLD; GsSetRefView2(&view); BuildArena(); do { pad = ReadPad(); activeBuff = GsGetActiveBuff(); GsSetWorkBase((PACKET *)packetArea[activeBuff]); GsClearOt(0, 0, &WorldOT[activeBuff]); // Pad repeat delay if (pad == 0) cursor.repeat = 7; else { cursor.repeat++; if (cursor.repeat >= 8) cursor.repeat = 0; } DealWithPad(pad); // Set view direction temp.m[0][0] = 0; temp.m[2][0] = 1600; tmp = (*(bb0+4))-128; if (Abs(tmp) > 20) { if (tmp < 0) rot += tmp+20; else rot += tmp-20; } RotMatrixY(rot, &temp); view.vrx = cursor.x+32-(temp.m[0][0]>>3); view.vrz = cursor.z+32-(temp.m[2][0]>>3); view.vpx = cursor.x+temp.m[0][0]+32; view.vpz = cursor.z+temp.m[2][0]+32; vx = LimitRange(cursor.x+32+(temp.m[0][0]>>4), 0, 63<<6); vz = LimitRange(cursor.z+32+(temp.m[2][0]>>4), 0, 63<<6); tmp = ((vx>>6)+(vz>>6)*65); //view.vpy = (Blend(vx, vz, rawBlocks[tmp].y, rawBlocks[tmp+1].y, rawBlocks[tmp+65].y, rawBlocks[tmp+66].y)<<3)+800; //(rawBlocks[((vx>>6)+(vz>>6)*65)].y<<3)+800; view.vry = (rawBlocks[cursor.vi].y+rawBlocks[cursor.vi+1].y+rawBlocks[cursor.vi+65].y+rawBlocks[cursor.vi+66].y)>>3; view.vpy = view.vry+800; // Draw arena GsSetRefView2(&view); DrawArena(activeBuff, view.vrx>>6, view.vrz>>6); DrawEnemies(WorldOT, activeBuff, view.vrx>>6, view.vrz>>6); DrawSync(0); vSync = VSync(0); GsSwapDispBuff(); GsSortClear(0, 0, 0, &WorldOT[activeBuff]); GsDrawOt(&WorldOT[activeBuff]); PrintHelp(cursor.mode); FntPrint(0, "%d\n", vSync); FntFlush(0); } while ((pad != PADLstart+PADLselect) && (pad != PADRselect+PADRstart)); *(u_char *)RAW_ENEMY_DATA = (u_char )enemyStack.num; tmp = 0; for (i=0; i copy colour\n"); FntPrint(1, "O -> copy height\n"); FntPrint(1, "S -> copy texture\n"); FntPrint(1, "X -> paste\n"); break; case 1: FntPrint(1, "OTX -> RGB L\n"); FntPrint(1, "S -> type\n"); break; case 2: FntPrint(1, "OTX -> RGB R\n"); FntPrint(1, "S -> type\n"); break; case 3: FntPrint(1, "OTX -> RGB LR\n"); FntPrint(1, "S -> type\n"); break; case 4: FntPrint(1, "X -> pick tex\n"); FntPrint(1, "O -> rot tex\n"); FntPrint(1, "T -> flip tex\n"); FntPrint(1, "S -> type\n"); break; case 5: FntPrint(1, "X -> place enemy\n"); FntPrint(1, "T -> remove enemy\n"); FntPrint(1, "OS -> pick enemy\n"); break; default: FntPrint(1, "eh?\n"); break; } FntFlush(1); FntPrint(2, "%d, %d\n", cursor.x>>6, cursor.z>>6); FntPrint(2, "%d %d\n%d %d\n", rawBlocks[cursor.vi].y, rawBlocks[cursor.vi+1].y, rawBlocks[cursor.vi+65].y, rawBlocks[cursor.vi+66].y); FntPrint(2, "%d,%d,%d\n", rawBlocks[cursor.vi].r0, rawBlocks[cursor.vi].g0, rawBlocks[cursor.vi].b0); FntPrint(2, "%d,%d,%d\n", rawBlocks[cursor.vi].r1, rawBlocks[cursor.vi].g1, rawBlocks[cursor.vi].b1); FntPrint(2, "%d\n", enemyStack.num); if (rawBlocks[cursor.vi].type == 0) FntPrint(2, "\\\n"); else FntPrint(2, "/\n"); FntFlush(2); } // Edit arena void DealWithPad(u_long pad) { u_char flag=0, colFlag=0; u_char tex, rot, flipX, flipY; if ((pad & PADLL3) || (pad & PADLR3)) cursor.repeat = 0; // Change heights if (pad & PADLL1) { flag = 1; if (cursor.repeat==0 || cursor.repeat==4) { if (pad & PADLup) { vertexLut[cursor.vi].vy += 4; rawBlocks[cursor.vi].y += 4; } if (pad & PADLdown) { vertexLut[cursor.vi].vy -= 4; rawBlocks[cursor.vi].y -= 4; } } } if (pad & PADLL2) { flag = 1; if (cursor.repeat==0 || cursor.repeat==4) { if (pad & PADLup) { vertexLut[cursor.vi+65].vy += 4; rawBlocks[cursor.vi+65].y += 4; } if (pad & PADLdown) { vertexLut[cursor.vi+65].vy -= 4; rawBlocks[cursor.vi+65].y -= 4; } } } if (pad & PADLR1) { flag = 1; if (cursor.repeat==0 || cursor.repeat==4) { if (pad & PADLup) { vertexLut[cursor.vi+1].vy += 4; rawBlocks[cursor.vi+1].y += 4; } if (pad & PADLdown) { vertexLut[cursor.vi+1].vy -= 4; rawBlocks[cursor.vi+1].y -= 4; } } } if (pad & PADLR2) { flag = 1; if (cursor.repeat==0 || cursor.repeat==4) { if (pad & PADLup) { vertexLut[cursor.vi+66].vy += 4; rawBlocks[cursor.vi+66].y += 4; } if (pad & PADLdown) { vertexLut[cursor.vi+66].vy -= 4; rawBlocks[cursor.vi+66].y -= 4; } } } if (cursor.mode == 0) { // Copy colours to clipboard if (pad & PADLT) { flag = 1; copyType = 1; clipBoard.r0 = rawBlocks[cursor.vi].r0; clipBoard.g0 = rawBlocks[cursor.vi].g0; clipBoard.b0 = rawBlocks[cursor.vi].b0; clipBoard.r1 = rawBlocks[cursor.vi].r1; clipBoard.g1 = rawBlocks[cursor.vi].g1; clipBoard.b1 = rawBlocks[cursor.vi].b1; } // Copy heights to clipboard if (pad & PADLO) { flag = 1; copyType = 2; clipBoard.y0 = vertexLut[cursor.vi].vy; clipBoard.y1 = vertexLut[cursor.vi+1].vy; clipBoard.y2 = vertexLut[cursor.vi+66].vy; clipBoard.y3 = vertexLut[cursor.vi+65].vy; } if (pad & PADLS) { copyType = 3; clipBoard.tNum = rawBlocks[cursor.vi].tNum; } // Paste cliboard contents to map if (pad & PADLX) { if (copyType == 1) { rawBlocks[cursor.vi].r0 = clipBoard.r0; rawBlocks[cursor.vi].g0 = clipBoard.g0; rawBlocks[cursor.vi].b0 = clipBoard.b0; rawBlocks[cursor.vi].r1 = clipBoard.r1; rawBlocks[cursor.vi].g1 = clipBoard.g1; rawBlocks[cursor.vi].b1 = clipBoard.b1; } if (copyType == 2) { vertexLut[cursor.vi].vy = clipBoard.y0; vertexLut[cursor.vi+1].vy = clipBoard.y1; vertexLut[cursor.vi+66].vy = clipBoard.y2; vertexLut[cursor.vi+65].vy = clipBoard.y3; rawBlocks[cursor.vi].y = clipBoard.y0; rawBlocks[cursor.vi+1].y = clipBoard.y1; rawBlocks[cursor.vi+66].y = clipBoard.y2; rawBlocks[cursor.vi+65].y = clipBoard.y3; } if (copyType == 3) rawBlocks[cursor.vi].tNum = clipBoard.tNum; } } if (cursor.mode==1 || cursor.mode==3) { // Change RGB left if (pad & PADLX) { colFlag = 1; flag = 1; if (cursor.repeat==0 || cursor.repeat==4) { if (pad & PADLup) rawBlocks[cursor.vi].b1 += 4; if (pad & PADLdown) rawBlocks[cursor.vi].b1 -= 4; } } if (pad & PADLO) { colFlag = 1; flag = 1; if (cursor.repeat==0 || cursor.repeat==4) { if (pad & PADLup) rawBlocks[cursor.vi].r1 += 4; if (pad & PADLdown) rawBlocks[cursor.vi].r1 -= 4; } } if (pad & PADLT) { colFlag = 1; flag = 1; if (cursor.repeat==0 || cursor.repeat==4) { if (pad & PADLup) rawBlocks[cursor.vi].g1 += 4; if (pad & PADLdown) rawBlocks[cursor.vi].g1 -= 4; } } } if (cursor.mode == 2) { // Change RGB right if (pad & PADLX) { colFlag = 1; flag = 1; if (cursor.repeat==0 || cursor.repeat==4) { if (pad & PADLup) rawBlocks[cursor.vi].b0 += 4; if (pad & PADLdown) rawBlocks[cursor.vi].b0 -= 4; } } if (pad & PADLO) { colFlag = 1; flag = 1; if (cursor.repeat==0 || cursor.repeat==4) { if (pad & PADLup) rawBlocks[cursor.vi].r0 += 4; if (pad & PADLdown) rawBlocks[cursor.vi].r0 -= 4; } } if (pad & PADLT) { colFlag = 1; flag = 1; if (cursor.repeat==0 || cursor.repeat==4) { if (pad & PADLup) rawBlocks[cursor.vi].g0 += 4; if (pad & PADLdown) rawBlocks[cursor.vi].g0 -= 4; } } } if (cursor.mode == 3) { if ((pad & PADLX) || (pad & PADLT) || (pad & PADLO)) { rawBlocks[cursor.vi].r0 = rawBlocks[cursor.vi].r1; rawBlocks[cursor.vi].b0 = rawBlocks[cursor.vi].b1; rawBlocks[cursor.vi].g0 = rawBlocks[cursor.vi].g1; } } if (cursor.mode!=0 && cursor.mode!=5) { // Change orientation of tri polys if (pad & PADLS) { flag = 1; if (cursor.repeat == 0) { rawBlocks[cursor.vi].type ^= 1; if (rawBlocks[cursor.vi].type == 0) { primitiveLut[cursor.pi].vert0 = cursor.vi; primitiveLut[cursor.pi].vert1 = cursor.vi+1; primitiveLut[cursor.pi].vert2 = cursor.vi+66; primitiveLut[cursor.pi+1].vert0 = cursor.vi; primitiveLut[cursor.pi+1].vert1 = cursor.vi+66; primitiveLut[cursor.pi+1].vert2 = cursor.vi+65; } else { primitiveLut[cursor.pi].vert0 = cursor.vi+1; primitiveLut[cursor.pi].vert1 = cursor.vi+66; primitiveLut[cursor.pi].vert2 = cursor.vi+65; primitiveLut[cursor.pi+1].vert0 = cursor.vi; primitiveLut[cursor.pi+1].vert1 = cursor.vi+1; primitiveLut[cursor.pi+1].vert2 = cursor.vi+65; } } } } if (cursor.mode == 4) { // Change texture of tile tex = rawBlocks[cursor.vi].tNum & 15; rot = (rawBlocks[cursor.vi].tNum>>4) & 3; flipX = (rawBlocks[cursor.vi].tNum>>6) & 1; flipY = (rawBlocks[cursor.vi].tNum>>7) & 1; if (pad & PADLX) { flag = 1; colFlag = 1; if (cursor.repeat==0) { if (pad & PADLup) tex = (tex-4) & 15; if (pad & PADLdown) tex = (tex+4) & 15; if (pad & PADLleft) tex = (tex-1) & 15; if (pad & PADLright) tex = (tex+1) & 15; } } if (pad & PADLO) { flag = 1; colFlag = 1; if (cursor.repeat==0) { if (pad & PADLleft) rot = (rot+1) & 3; if (pad & PADLright) rot = (rot-1) & 3; } } if (pad & PADLT) { flag = 1; colFlag = 1; if (cursor.repeat==0) { if (pad & PADLup) flipY ^= 1; if (pad & PADLdown) flipY ^= 1; if (pad & PADLleft) flipX ^= 1; if (pad & PADLright) flipX ^= 1; } } rawBlocks[cursor.vi].tNum = tex + (rot<<4) + (flipX<<6) + (flipY<<7); } if (cursor.mode == 5) { if (pad & PADLS) { if (cursor.repeat==0) { cursor.enemyType--; if (cursor.enemyType < 0) cursor.enemyType = NUM_ENEMY_TYPES-1; if (enemyMap[cursor.x>>6][cursor.z>>6]) { RemoveEnemy(); AddEnemy(); } } } if (pad & PADLO) { if (cursor.repeat==0) { cursor.enemyType++; if (cursor.enemyType >= NUM_ENEMY_TYPES) cursor.enemyType = 0; if (enemyMap[cursor.x>>6][cursor.z>>6]) { RemoveEnemy(); AddEnemy(); } } } if (pad & PADLX) { if (enemyStack.num < MAX_ENEMIES-1) AddEnemy(); } if (pad & PADLT) { if (enemyStack.num > 0) RemoveEnemy(); } } SetTex(cursor.pi, cursor.vi); // Set current patch colour primitiveLut[cursor.pi].r0 = rawBlocks[cursor.vi].r0; primitiveLut[cursor.pi].g0 = rawBlocks[cursor.vi].g0; primitiveLut[cursor.pi].b0 = rawBlocks[cursor.vi].b0; primitiveLut[cursor.pi+1].r0 = rawBlocks[cursor.vi].r1; primitiveLut[cursor.pi+1].g0 = rawBlocks[cursor.vi].g1; primitiveLut[cursor.pi+1].b0 = rawBlocks[cursor.vi].b1; if (flag==0 && cursor.repeat==0) { if (pad & PADLstart) { if (cursor.mode >= OPTIONS-1) cursor.mode = 0; else cursor.mode++; } if (pad & PADLselect) { if (cursor.mode == 0) cursor.mode = OPTIONS-1; else cursor.mode--; } if (pad & PADLleft) cursor.x -= 64; if (pad & PADLright) cursor.x += 64; if (pad & PADLup) cursor.z -= 64; if (pad & PADLdown) cursor.z += 64; cursor.x = LimitRange(cursor.x, 0, 63<<6); cursor.z = LimitRange(cursor.z, 0, 63<<6); cursor.pi = ((cursor.x>>6)+(cursor.z>>6)*64)*2; cursor.vi = (cursor.x>>6)+((cursor.z>>6)*65); } // Flash cursor if (colFlag == 0) { cursor.glow += 8; primitiveLut[cursor.pi].r0 = LimitRange(((primitiveLut[cursor.pi].r0+16)*cursor.glow)>>6, 0, 255); primitiveLut[cursor.pi].g0 = LimitRange(((primitiveLut[cursor.pi].g0+16)*cursor.glow)>>6, 0, 255); primitiveLut[cursor.pi].b0 = LimitRange(((primitiveLut[cursor.pi].b0+16)*cursor.glow)>>6, 0, 255); primitiveLut[cursor.pi+1].r0 = LimitRange(((primitiveLut[cursor.pi+1].r0+16)*cursor.glow)>>6, 0, 255); primitiveLut[cursor.pi+1].g0 = LimitRange(((primitiveLut[cursor.pi+1].g0+16)*cursor.glow)>>6, 0, 255); primitiveLut[cursor.pi+1].b0 = LimitRange(((primitiveLut[cursor.pi+1].b0+16)*cursor.glow)>>6, 0, 255); } } int Blend(int x, int y, int a, int b, int c, int d) { int t1, t2; x = x & 63; y = y & 63; t1 = a*64+x*(b-a); t2 = c*64+x*(d-c); return ((t1*64+y*(t2-t1))>>12); } void ProperInitialiseTexture(long TIMdata, GsIMAGE *imageInfo) { RECT rect; GsGetTimInfo((u_long *)(TIMdata+4), imageInfo); rect.x = imageInfo->px; rect.y = imageInfo->py; rect.w = imageInfo->pw; rect.h = imageInfo->ph; LoadImage(&rect, imageInfo->pixel); DrawSync(0); if ((imageInfo->pmode>>3) & 0x01) { rect.x = imageInfo->cx; rect.y = imageInfo->cy; rect.w = imageInfo->cw; rect.h = imageInfo->ch; LoadImage(&rect, imageInfo->clut); DrawSync(0); } } void SetTex(u_long pi, u_long vi) { u_char tex, rot, flipX, flipY; tex = rawBlocks[vi].tNum & 15; rot = (rawBlocks[vi].tNum>>4) & 3; flipX = (rawBlocks[vi].tNum>>6) & 1; flipY = (rawBlocks[vi].tNum>>7) & 1; primitiveLut[pi].cba = (640>>4) + ((257+((tex>>2)&3))<<6); primitiveLut[pi+1].cba = (640>>4) + ((257+((tex>>2)&3))<<6); if (rawBlocks[vi].type == 0) { primitiveLut[pi].u0 = arenaTexture[rawBlocks[vi].tNum & 15].x[(0+rot)&3]-320; primitiveLut[pi].v0 = arenaTexture[rawBlocks[vi].tNum & 15].y[(0+rot)&3]; primitiveLut[pi].u1 = arenaTexture[rawBlocks[vi].tNum & 15].x[(1+rot)&3]-320; primitiveLut[pi].v1 = arenaTexture[rawBlocks[vi].tNum & 15].y[(1+rot)&3]; primitiveLut[pi].u2 = arenaTexture[rawBlocks[vi].tNum & 15].x[(2+rot)&3]-320; primitiveLut[pi].v2 = arenaTexture[rawBlocks[vi].tNum & 15].y[(2+rot)&3]; primitiveLut[pi+1].u0 = arenaTexture[rawBlocks[vi].tNum & 15].x[(0+rot)&3]-320; primitiveLut[pi+1].v0 = arenaTexture[rawBlocks[vi].tNum & 15].y[(0+rot)&3]; primitiveLut[pi+1].u1 = arenaTexture[rawBlocks[vi].tNum & 15].x[(2+rot)&3]-320; primitiveLut[pi+1].v1 = arenaTexture[rawBlocks[vi].tNum & 15].y[(2+rot)&3]; primitiveLut[pi+1].u2 = arenaTexture[rawBlocks[vi].tNum & 15].x[(3+rot)&3]-320; primitiveLut[pi+1].v2 = arenaTexture[rawBlocks[vi].tNum & 15].y[(3+rot)&3]; } else { primitiveLut[pi].u0 = arenaTexture[rawBlocks[vi].tNum & 15].x[(1+rot)&3]-320; primitiveLut[pi].v0 = arenaTexture[rawBlocks[vi].tNum & 15].y[(1+rot)&3]; primitiveLut[pi].u1 = arenaTexture[rawBlocks[vi].tNum & 15].x[(2+rot)&3]-320; primitiveLut[pi].v1 = arenaTexture[rawBlocks[vi].tNum & 15].y[(2+rot)&3]; primitiveLut[pi].u2 = arenaTexture[rawBlocks[vi].tNum & 15].x[(3+rot)&3]-320; primitiveLut[pi].v2 = arenaTexture[rawBlocks[vi].tNum & 15].y[(3+rot)&3]; primitiveLut[pi+1].u0 = arenaTexture[rawBlocks[vi].tNum & 15].x[(0+rot)&3]-320; primitiveLut[pi+1].v0 = arenaTexture[rawBlocks[vi].tNum & 15].y[(0+rot)&3]; primitiveLut[pi+1].u1 = arenaTexture[rawBlocks[vi].tNum & 15].x[(1+rot)&3]-320; primitiveLut[pi+1].v1 = arenaTexture[rawBlocks[vi].tNum & 15].y[(1+rot)&3]; primitiveLut[pi+1].u2 = arenaTexture[rawBlocks[vi].tNum & 15].x[(3+rot)&3]-320; primitiveLut[pi+1].v2 = arenaTexture[rawBlocks[vi].tNum & 15].y[(3+rot)&3]; } if (flipX) { if (rawBlocks[vi].type == 0) { Swap(&primitiveLut[pi].u0, &primitiveLut[pi].u1); Swap(&primitiveLut[pi].v0, &primitiveLut[pi].v1); Swap(&primitiveLut[pi+1].u1, &primitiveLut[pi+1].u2); Swap(&primitiveLut[pi+1].v1, &primitiveLut[pi+1].v2); primitiveLut[pi].u2 = primitiveLut[pi+1].u1; primitiveLut[pi].v2 = primitiveLut[pi+1].v1; primitiveLut[pi+1].u0 = primitiveLut[pi].u0; primitiveLut[pi+1].v0 = primitiveLut[pi].v0; } else { Swap(&primitiveLut[pi].u1, &primitiveLut[pi].u2); Swap(&primitiveLut[pi].v1, &primitiveLut[pi].v2); Swap(&primitiveLut[pi+1].u0, &primitiveLut[pi+1].u1); Swap(&primitiveLut[pi+1].v0, &primitiveLut[pi+1].v1); primitiveLut[pi].u0 = primitiveLut[pi+1].u1; primitiveLut[pi].v0 = primitiveLut[pi+1].v1; primitiveLut[pi+1].u2 = primitiveLut[pi].u2; primitiveLut[pi+1].v2 = primitiveLut[pi].v2; } } if (flipY) { if (rawBlocks[vi].type == 0) { Swap(&primitiveLut[pi].u1, &primitiveLut[pi].u2); Swap(&primitiveLut[pi].v1, &primitiveLut[pi].v2); Swap(&primitiveLut[pi+1].u0, &primitiveLut[pi+1].u2); Swap(&primitiveLut[pi+1].v0, &primitiveLut[pi+1].v2); primitiveLut[pi].u0 = primitiveLut[pi+1].u0; primitiveLut[pi].v0 = primitiveLut[pi+1].v0; primitiveLut[pi+1].u1 = primitiveLut[pi].u2; primitiveLut[pi+1].v1 = primitiveLut[pi].v2; } else { Swap(&primitiveLut[pi].u0, &primitiveLut[pi].u1); Swap(&primitiveLut[pi].v0, &primitiveLut[pi].v1); Swap(&primitiveLut[pi+1].u0, &primitiveLut[pi+1].u2); Swap(&primitiveLut[pi+1].v0, &primitiveLut[pi+1].v2); primitiveLut[pi].u2 = primitiveLut[pi+1].u2; primitiveLut[pi].v2 = primitiveLut[pi+1].v2; primitiveLut[pi+1].u1 = primitiveLut[pi].u0; primitiveLut[pi+1].v1 = primitiveLut[pi].v0; } } } void Swap(u_char *a, u_char *b) { u_char temp; temp = *a; *a = *b; *b = temp; } void AddEnemy(void) { int i, height, picked; u_long *pointer; EnemyInfo *info; EnemyHandler *handler; for (i=0; i>6)==enemyStack.info[i].x && (cursor.z>>6)==enemyStack.info[i].z) return; } } info = &enemyStack.info[picked]; handler = &enemyStack.handler[picked]; enemyStack.num++; info->x = cursor.x>>6; info->z = cursor.z>>6; info->type = cursor.enemyType; handler->alive = 1; enemyMap[info->x][info->z] = picked+1; height = BlendHeight((info->x<<6)+32, (info->z<<6)+32); SetVector(&handler->pos, ((info->x)<<6)+32, height+8, ((info->z)<<6)+32); SetVector(&handler->rot, 0, 0, 2048); GsInitCoordinate2(WORLD, &handler->coord); switch (info->type) { case ENEMY_GUN: pointer = (u_long *)GUN_ADDRESS; break; case ENEMY_HK: pointer = (u_long *)HK_ADDRESS; break; default : enemyStack.num--; return; } pointer++; GsMapModelingData(pointer); pointer += 2; GsLinkObject4((u_long )pointer, &handler->handler, 0); handler->handler.attribute = 0; } void RemoveEnemy(void) { int i; for (i=0; i>6)==enemyStack.info[i].x && (cursor.z>>6)==enemyStack.info[i].z) { enemyMap[cursor.x>>6][cursor.z>>6] = 0; enemyStack.handler[i].alive = 0; enemyStack.num--; break; } } } } void DrawEnemies(GsOT *ot, int activeBuff, int x, int z) { MATRIX tmpls, tmplw; EnemyHandler *handler; EnemyInfo *info; int si, sj, ei, ej, i, j, index, height; si = x-8; ei = x+8; sj = z-8; ej = z+8; Less(ei, 63); Less(ej, 63); Greater(si, 0); Greater(sj, 0); for (j=sj; j<=ej; j++) { index = si+(j<<6); for (i=si; i<=ei; i++) { if (enemyMap[i][j]) { handler = &enemyStack.handler[enemyMap[i][j]-1]; info = &enemyStack.info[enemyMap[i][j]-1]; height = BlendHeight((info->x<<6)+32, (info->z<<6)+32); SetVector(&handler->pos, ((info->x)<<6)+32, height, ((info->z)<<6)+32); UpdateCoord(&handler->pos, &handler->rot, &handler->coord); GsGetLws(&handler->coord, &tmplw, &tmpls); GsSetLightMatrix(&tmplw); GsSetLsMatrix(&tmpls); GsSortObject4(&handler->handler, &ot[activeBuff], 1, getScratchAddr(0)); } } } } int BlendHeight(int x, int z) { int i = ((x>>6)+(z>>6)*65); short a=rawBlocks[i].y, b=rawBlocks[i+1].y; short c=rawBlocks[i+65].y, d=rawBlocks[i+66].y; x = x & 63; z = z & 63; if (rawBlocks[i].type == 0) { if (x > z) return Blend(x, z, a, b, d+a-b, d); else return Blend(x, z, a, d+a-c, c, d); } else { if (63-x > z) return Blend(x, z, a, b, c, c+b-a); else return Blend(x, z, c+b-d, b, c, d); } } void UpdateCoord(VECTOR *pos, SVECTOR *rot, GsCOORDINATE2 *coordSystem) { ResetMatrix(coordSystem->coord.m); RotMatrixX(rot->vx, &coordSystem->coord); RotMatrixZ(rot->vz, &coordSystem->coord); RotMatrixY(rot->vy, &coordSystem->coord); coordSystem->coord.t[0] = pos->vx; coordSystem->coord.t[1] = pos->vy; coordSystem->coord.t[2] = pos->vz; coordSystem->flg = 0; } void ResetMatrix(short m[3][3]) { m[0][0] = m[1][1] = m[2][2] = ONE; m[0][1] = m[0][2] = m[1][0] = 0; m[1][2] = m[2][0] = m[2][1] = 0; } u_long ReadPad(void) { return(~(*(bb0+3) | *(bb0+2) << 8 | *(bb1+3) << 16 | *(bb1+2) << 24)); }