Author: Not specified Language: text Description: Not specified Timestamp: 2013-06-13 17:32:51 +0000
1. // CHALLANGAR 1.0
2. // Designed for Dennis
3. // Usually beats standard Difficult AI
5.
6.
7.
8.
9. void targetward(bool hold) {
10.    int y = (hold) ? 1 : 0;
11.    if (target.x > self.x) right(1,y); else left(1,y);
12. }
13. void targetward() {
14.    targetward(true);
15. }
16.
17. void targetwardz(bool hold) {
18.    int y = (hold) ? 1 : 0;
19.    if (target.z > self.z) down(1,y); else up(1,y);
20. }
21. void targetwardz() {
22.    targetwardz(true);
23. }
24.
25. int max(int a, int b) { if (a>b) return a; else return b; }
26.
27. void get_to(int min_x, int max_x, int min_z, int max_z) {
28.    int dx = max(self.x - max_x, min_x - self.x);
29.    int dz = max(self.z - max_z, min_z - self.z);
30.    //int angle = atan2(float(dz), float(dx));
31.    int run = (dx > run_stop_distance || abs(self.x - target.x) < 100) ? 0 : 1;
32.
33.    if (self.x > max_x) left(1,run);
34.    else if (self.x < min_x) right(1,run);
35.
36.    if (self.z > max_z) up(1,run);
37.    else if (self.z < min_z) down(1,run);
38. }
39.
40. bool dash_from_left() {
41.    // if there's no room from the left, go from the right
42.    if (target.x < min_dash_dx) return false;
43.    // and conversely...
44.    if (bg_width - target.x < min_dash_dx) return true;
45.    // otherwise, just go from whatever side's closer
46.    return (self.x < target.x);
47. }
48. bool dash_from_top() {
49.    if (target.z - bg_zwidth1 < min_dash_dz) return false;
50.    if (bg_zwidth2 - target.z < min_dash_dz) return true;
51.    return (self.z < target.z);
52. }
53.
55.    // four acceptable regions to dash from
56.    int dx = abs(target.x - self.x);
57.    int dz = abs(target.z - self.z);
58.    return (self.state == 0 || self.state == 1 || self.state == 2 ||
59.            self.frame == 215) &&
60.           (target.state != 14 && target.blink < 2) &&
61.           ((min_dash_dx <= dx && dx <= max_dash_dx) &&
62.            (min_dash_dz <= dz && dz <= max_dash_dz) ||
63.            (facing_target() && self.state == 2));
64. }
65.
66. bool facing_target() {
67.    return (self.facing && target.x < self.x) ||
68.           (!self.facing && target.x > self.x);
69. }
70.
71. int about(int x) { return x + rand(x/10) - x/20; }
72.
73. int min_dash_dx;
74. int max_dash_dx;
75. int min_dash_dz;
76. int max_dash_dz;
78. int run_stop_distance;
79. float diagonal_run_angle; // not used due to lack of atan2
80.
81. void id() {
88.    diagonal_run_angle = 20.0; // not used due to lack of atan2
89.
90.    A(0,0); //reset keys
91.    D(0,0);
92.    J(0,0);
93.    up(0,0);
94.    down(0,0);
95.    left(0,0);
96.    right(0,0);
97.    print(min_dash_dx);
98.    for (int i = 0; i < 400; i++) { //target
99.      if (loadTarget(i) == 0 &&
100.          target.num != self.num &&
101.          target.hp > 0 &&
102.          target.id < 100 &&
103.          target.team != self.team) {
104.          break;
105.      }
106.    }
107.
109.       print("CHALLANGAR DEBUG: dashin'");
110.       if (self.state == 2 && facing_target()) {
111.          J();
112.          A();
113.          targetwardz();
114.       } else if (self.frame == 215) {
115.          print(" from flip");
116.          J();
117.          A();
118.          targetwardz();
119.          targetward();
120.       } else if (self.state == 2) {
121.          targetward(false);
122.          targetwardz(false);
123.       } else targetward(false);
124.    } else if (self.state == 12) {
125.       print("CHALLANGAR DEBUG: flippin'");
126.       J();
127.    } else {
128.       print("CHALLANGAR DEBUG: getting into position");
129.       int min_x, max_x, min_z, max_z;
130.       if (dash_from_left()) {
131.          print(" (left, ");
132.          min_x = target.x - max_dash_dx;
133.          max_x = target.x - min_dash_dx;
134.       } else {
135.          print(" (right, ");
136.          min_x = target.x + min_dash_dx;
137.          max_x = target.x + max_dash_dx;
138.       }
139.       if (dash_from_top()) {
140.          print("top)");
141.          min_z = target.z - max_dash_dz;
142.          max_z = target.z - min_dash_dz;
143.       } else {
144.          print("bottom)");
145.          min_z = target.z + min_dash_dz;
146.          max_z = target.z + max_dash_dz;
147.       }
148.       get_to(min_x, max_x, min_z, max_z);
149.    }
150.    print("\n");
151. }