/* * radar.c */ #include #include "defs.h" #include "globals.h" #include "tank.h" #include "missile.h" #include "radarbmp.c" GsSPRITE radar[2]; GsIMAGE rimg[2]; void initRadar(void) { int i; u_short tpage; RECT rect; for(i = 0; i < 2; i++) { memset(&radar[i], 0x00, sizeof(GsSPRITE)); radar[i].r = 0x80; radar[i].g = 0x80; radar[i].b = 0x80; radar[i].scalex = ONE; radar[i].scaley = ONE; radar[i].x = -96; radar[i].y = -48; radar[i].w = 36; radar[i].h = 36; radar[i].attribute = (1 << 24) | (1 << 28) | (1 << 30); rect.x = 320 + (i * 64); rect.y = 0; rect.w = 36/2; rect.h = 36; LoadImage(&rect, (u_long *)rbmap[i]); tpage = GetTPage(1, 0, 320 + (i * 64), 0); rect.x = 320 + 128 + (i * 16); rect.y = 0; rect.w = 16; rect.h = 1; LoadImage(&rect, (u_long *)rclut); radar[i].tpage = tpage; radar[i].cx = 320 + 128 + (i * 16); radar[i].cy = 0; } } typedef struct { long tx, tz; // target x and z long ix, iz; // incoming x and z } radar_str; static radar_str vectrex[2] = {{17, 17, 17, 17}, {17, 17, 17, 17}}; // this is passed the raw distance from the tank to its target void RadarTarget(int i, long x, long z, short a) { SVECTOR pnt; VECTOR tgt; MATRIX ltw; GsCOORDINATE2 dir; long tx, tz; short c; tx = vectrex[i].tx; tz = vectrex[i].tz; rbmap[i][tz][tx] = 0, rbmap[i][tz][tx+1] = 0, rbmap[i][tz+1][tx] = 0, rbmap[i][tz+1][tx+1] = 0; tx = vectrex[i].ix; tz = vectrex[i].iz; rbmap[i][tz][tx] = 0;//, rbmap[i][tz][tx+1] = 0, rbmap[i][tz+1][tx] = 0, rbmap[i][tz+1][tx+1] = 0; tx = 17; tz = 17; rbmap[i][tz][tx] = 1, rbmap[i][tz][tx+1] = 1, rbmap[i][tz+1][tx] = 1, rbmap[i][tz+1][tx+1] = 1; dir = *BTanks[i].coord2; RotMatrixY(-2*a, &(dir.coord)); GsGetLw(&dir, <w); setVector(&pnt, x, 0, z); ApplyMatrix(<w, &pnt, &tgt); // FntPrint("To Target: %d, %d (%d)\n", x, z, a); x = tgt.vx; z = -tgt.vz; // FntPrint("Vector: %d, %d\n", x, z); tx = (x >> 9); tz = (z >> 9); c = 1; if(tx > 15) tx = 15, c = 2; if(tx < -15) tx = -15, c = 2; if(tz > 15) tz = 15, c = 2; if(tz < -15) tz = -15, c = 2; tx += 17; tz += 17; rbmap[i][tz][tx] = c, rbmap[i][tz][tx+1] = c, rbmap[i][tz+1][tx] = c, rbmap[i][tz+1][tx+1] = c; vectrex[i].tx = tx; vectrex[i].tz = tz; } void RadarTargetI(int i, long x, long z, long xi, long zi, short a) { SVECTOR pnt; VECTOR tgt; MATRIX ltw; GsCOORDINATE2 dir; long tx, tz; short c; tx = vectrex[i].tx; tz = vectrex[i].tz; rbmap[i][tz][tx] = 0, rbmap[i][tz][tx+1] = 0, rbmap[i][tz+1][tx] = 0, rbmap[i][tz+1][tx+1] = 0; tx = vectrex[i].ix; tz = vectrex[i].iz; rbmap[i][tz][tx] = 0;//, rbmap[i][tz][tx+1] = 0, rbmap[i][tz+1][tx] = 0, rbmap[i][tz+1][tx+1] = 0; tx = 17; tz = 17; rbmap[i][tz][tx] = 1, rbmap[i][tz][tx+1] = 1, rbmap[i][tz+1][tx] = 1, rbmap[i][tz+1][tx+1] = 1; dir = *BTanks[i].coord2; RotMatrixY(-2*a, &(dir.coord)); GsGetLw(&dir, <w); setVector(&pnt, x, 0, z); ApplyMatrix(<w, &pnt, &tgt); x = tgt.vx; z = -tgt.vz; tx = (x >> 9); tz = (z >> 9); c = 1; if(tx > 15) tx = 15, c = 2; if(tx < -15) tx = -15, c = 2; if(tz > 15) tz = 15, c = 2; if(tz < -15) tz = -15, c = 2; tx += 17; tz += 17; rbmap[i][tz][tx] = c, rbmap[i][tz][tx+1] = c, rbmap[i][tz+1][tx] = c, rbmap[i][tz+1][tx+1] = c; vectrex[i].tx = tx; vectrex[i].tz = tz; // now the incoming missile setVector(&pnt, xi, 0, zi); ApplyMatrix(<w, &pnt, &tgt); xi = tgt.vx; zi = -tgt.vz; tx = (xi >> 9); tz = (zi >> 9); c = 3; if(tx > 15) tx = 15, c = 2; if(tx < -15) tx = -15, c = 2; if(tz > 15) tz = 15, c = 2; if(tz < -15) tz = -15, c = 2; tx += 17; tz += 17; rbmap[i][tz][tx] = c;//, rbmap[i][tz][tx+1] = c, rbmap[i][tz+1][tx] = c, rbmap[i][tz+1][tx+1] = c; vectrex[i].ix = tx; vectrex[i].iz = tz; } void RadarTargetF(int i, long x, long z, long xi, long zi, short a) { SVECTOR pnt; VECTOR tgt; MATRIX ltw; GsCOORDINATE2 dir; long tx, tz; short c; tx = vectrex[i].tx; tz = vectrex[i].tz; rbmap[i][tz][tx] = 0, rbmap[i][tz][tx+1] = 0, rbmap[i][tz+1][tx] = 0, rbmap[i][tz+1][tx+1] = 0; tx = vectrex[i].ix; tz = vectrex[i].iz; rbmap[i][tz][tx] = 0;//, rbmap[i][tz][tx+1] = 0, rbmap[i][tz+1][tx] = 0, rbmap[i][tz+1][tx+1] = 0; tx = 17; tz = 17; rbmap[i][tz][tx] = 1, rbmap[i][tz][tx+1] = 1, rbmap[i][tz+1][tx] = 1, rbmap[i][tz+1][tx+1] = 1; dir = *BTanks[i].coord2; RotMatrixY(-2*a, &(dir.coord)); GsGetLw(&dir, <w); setVector(&pnt, x, 0, z); ApplyMatrix(<w, &pnt, &tgt); x = tgt.vx; z = -tgt.vz; tx = (x >> 9); tz = (z >> 9); c = 1; if(tx > 15) tx = 15, c = 2; if(tx < -15) tx = -15, c = 2; if(tz > 15) tz = 15, c = 2; if(tz < -15) tz = -15, c = 2; tx += 17; tz += 17; rbmap[i][tz][tx] = c, rbmap[i][tz][tx+1] = c, rbmap[i][tz+1][tx] = c, rbmap[i][tz+1][tx+1] = c; vectrex[i].tx = tx; vectrex[i].tz = tz; // now the incoming missile setVector(&pnt, xi, 0, zi); ApplyMatrix(<w, &pnt, &tgt); xi = tgt.vx; zi = -tgt.vz; tx = (xi >> 9); tz = (zi >> 9); c = 5; if(tx > 15) tx = 15, c = 2; if(tx < -15) tx = -15, c = 2; if(tz > 15) tz = 15, c = 2; if(tz < -15) tz = -15, c = 2; tx += 17; tz += 17; rbmap[i][tz][tx] = c;//, rbmap[i][tz][tx+1] = c, rbmap[i][tz+1][tx] = c, rbmap[i][tz+1][tx+1] = c; vectrex[i].ix = tx; vectrex[i].iz = tz; } void RadarTargetM(int i, long x, long z, short a) { SVECTOR pnt; VECTOR tgt; MATRIX ltw; GsCOORDINATE2 dir; long tx, tz; short c; tx = vectrex[i].tx; tz = vectrex[i].tz; rbmap[i][tz][tx] = 0, rbmap[i][tz][tx+1] = 0, rbmap[i][tz+1][tx] = 0, rbmap[i][tz+1][tx+1] = 0; tx = vectrex[i].ix; tz = vectrex[i].iz; rbmap[i][tz][tx] = 0;//, rbmap[i][tz][tx+1] = 0, rbmap[i][tz+1][tx] = 0, rbmap[i][tz+1][tx+1] = 0; tx = 17; tz = 17; rbmap[i][tz][tx] = 3, rbmap[i][tz][tx+1] = 3, rbmap[i][tz+1][tx] = 3, rbmap[i][tz+1][tx+1] = 3; dir = *BTanks[i].coord2; RotMatrixY(-2*a, &(dir.coord)); GsGetLw(&dir, <w); setVector(&pnt, x, 0, z); ApplyMatrix(<w, &pnt, &tgt); x = tgt.vx; z = -tgt.vz; tx = (x >> 9); tz = (z >> 9); c = 1; if(tx > 15) tx = 15, c = 2; if(tx < -15) tx = -15, c = 2; if(tz > 15) tz = 15, c = 2; if(tz < -15) tz = -15, c = 2; tx += 17; tz += 17; rbmap[i][tz][tx] = c, rbmap[i][tz][tx+1] = c, rbmap[i][tz+1][tx] = c, rbmap[i][tz+1][tx+1] = c; vectrex[i].tx = tx; vectrex[i].tz = tz; } void RadarScramble(int i) { int j, k; for(j = 0; j < 32; j++) for(k = 0; k < 32; k++) rbmap[i][j+2][k+2] = rand() & 0xd; } void RadarClear(int i) { int j, k; for(j = 0; j < 32; j++) for(k = 0; k < 32; k++) rbmap[i][j+2][k+2] = 0; } void drawRadar(int i) { RECT rect; rect.x = 320 + (i * 64); rect.y = 0; rect.w = 36/2; rect.h = 36; LoadImage(&rect, (u_long *)rbmap[i]); GsSortFastSprite(&(radar[i]), &OT[buffIdx], 0); }