|
|
1.1 ! root 1: #include <jerq.h> ! 2: #include "rock.h" ! 3: #include "event.h" ! 4: #include "ship.h" ! 5: extern Point pos, vel; ! 6: extern int xflag; ! 7: extern Bitmap *rockseq[]; ! 8: /* batcomp calls are spread around, but all functions are here */ ! 9: ! 10: int curthreat; /* rocknum of worst guy */ ! 11: extern int death; ! 12: extern int costheta, sintheta; ! 13: int curtime = 10000; /* and when he hits us */ ! 14: long curdist = 1000000; /* if not threat, dist of worst guy */ ! 15: extern int score; ! 16: int computer, compbut; ! 17: int screens; ! 18: ! 19: batcomp(r) /* called from moverock */ ! 20: register Rock *r; ! 21: { int a, b, c, d; ! 22: long dist, u, t; ! 23: if(death) ! 24: return; ! 25: a = r->x.x - pos.x; ! 26: b = r->x.y - pos.y; ! 27: c = r->v.x - vel.x; /* our velocity has to be scaled */ ! 28: d = r->v.y - vel.y; ! 29: /* only understands current region, not lattice */ ! 30: t = (long)a * c + (long)b * d; ! 31: u = (long)c * c + (long)d * d + 1; /* don't divide by zero */ ! 32: dist = (long)b * c - (long)a * d; ! 33: dist *= dist; ! 34: dist /= u; ! 35: if(curthreat != -1 && rock[curthreat].hash == -1) ! 36: curthreat = -1, curtime = 10000, curdist = 1000000; ! 37: t = -t/u; ! 38: if(t >= -3 && dist <= r->r * r->r + RADSHIP * RADSHIP *2) { ! 39: if(curthreat == -1 || t < curtime && t >= 0) { ! 40: curtime = t; ! 41: curthreat = r - rock; ! 42: } ! 43: return; ! 44: } ! 45: if(curthreat == r - rock) ! 46: curdist = dist; ! 47: dist = (long)a * a + (long)b * b; ! 48: if(curthreat == -1 || dist < curdist && t >= 0) { ! 49: curdist = dist; ! 50: curthreat = r - rock; ! 51: } ! 52: if(screens & curtime < 20) { ! 53: curtime = 10000; ! 54: split(r); ! 55: explode(r->x); ! 56: killrock(r); ! 57: score -= 6; ! 58: } ! 59: } ! 60: int velb = 24; ! 61: int invb = 1; ! 62: #define RET(n) return(compbut = dir[n]) ! 63: #define LEFT 6 ! 64: #define RIGHT 3 ! 65: char dir[16] = {LEFT, LEFT, RIGHT, RIGHT, LEFT, RIGHT, LEFT, RIGHT, LEFT, LEFT, RIGHT}; ! 66: strat() ! 67: { register Rock *r = rock + curthreat; ! 68: int a, b, c, d, x; ! 69: int tbul, trock; ! 70: if(r->hash == -1) { ! 71: curthreat = -1; ! 72: curtime = 10000; ! 73: curdist = 1000000; ! 74: } ! 75: compbut = 0; ! 76: if(curthreat == -1) ! 77: return(0); ! 78: a = r->x.x - pos.x + r->v.x; ! 79: b = r->x.y - pos.y + r->v.y; ! 80: c = r->v.x; /* we'd better be at rest */ ! 81: d = r->v.y; ! 82: if(m(a, costheta) + m(b, sintheta) < 0) ! 83: RET(0); /* not close */ ! 84: x = m(c, sintheta) - m(d, costheta); ! 85: tbul = ((long)b * c - (long)a * d); ! 86: /* tbul / xVELB/INV is the actual time */ ! 87: trock = m(b, costheta) - m(a, sintheta); ! 88: /* trock / x is the actual time */ ! 89: if(x < 0) { ! 90: if(tbul >= 0) ! 91: RET(1); ! 92: else if(trock > 0) ! 93: RET(2); ! 94: else if(trock * velb > tbul * invb) ! 95: RET(3); ! 96: else ! 97: RET(4); ! 98: } ! 99: else if(x > 0) { ! 100: if(tbul <= 0 && trock > 0) ! 101: RET(5); ! 102: else if(trock < 0) ! 103: RET(6); ! 104: else if(trock * velb > tbul * invb) ! 105: RET(7); ! 106: else ! 107: RET(8); ! 108: } ! 109: else if(trock < 0) ! 110: RET(9); ! 111: else ! 112: RET(10); ! 113: right: ! 114: return(compbut = 3); ! 115: left: ! 116: return(compbut = 6); ! 117: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.