Created
June 7, 2009 02:33
-
-
Save droyo/125114 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int | |
blocked_shot(int e) | |
{ | |
int t, a, x, y; | |
double adx, ady, edx, edy, div; | |
/* AIship_track(e) returns direction of enemy movement */ | |
t = AIship_track(e); | |
/* AIship_aimdir(e) is an autoaim function that returns the | |
angle required to hit the enemy ship */ | |
a = AIship_aimdir(e); | |
adx = cos(rad(a)); | |
ady = sin(rad(a)); | |
edx = cos(rad(t)); | |
edy = sin(rad(t)); | |
/* find the intersection of two lines with Cramer's rule */ | |
div = det(adx, ady, edx, edy); | |
if (div == 0) { | |
/* enemy ship is flying straight away or at self */ | |
x = AIradar_x(e); | |
y = AIradar_y(e); | |
} else { | |
x = det(AIradar_x(e) - AIself_x(), AIradar_y(e) - AIself_y(), edx, edy) / div; | |
y = det(adx, ady, AIradar_x(e) - AIself_x(), AIradar_y(e) - AIself_y()) / div; | |
} | |
return AI_wallbetween(AIself_x(), AIself_y(), x, y) != -1; | |
} | |
/* determinant of a 2x2 matrix */ | |
double | |
det(double x1, double y1, double x2, double y2) | |
{ | |
return (x1 * y2) - (x2 * y1); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment