1 /*
2     GL-117
3     Copyright 2001, 2002 Thomas A. Drexl aka heptargon
4 
5     This file is part of GL-117.
6 
7     GL-117 is free software; you can redistribute it and/or modify
8     it under the terms of the GNU General Public License as published by
9     the Free Software Foundation; either version 2 of the License, or
10     (at your option) any later version.
11 
12     GL-117 is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15     GNU General Public License for more details.
16 
17     You should have received a copy of the GNU General Public License
18     along with GL-117; if not, write to the Free Software
19     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20 */
21 
22 /* This file includes all AI objects instancing models. */
23 
24 #ifndef IS_AIOBJECT_H
25 #define IS_AIOBJECT_H
26 
27 #include "common.h" // ok
28 #include "model.h" // ok
29 #include "effects.h" // ok
30 
31 // id values of objects
32 // non-AI air objects
33 #define CANNON1 0
34 #define ASTEROID 50
35 #define FLARE1 80
36 #define CHAFF1 85
37 #define CANNON2 99
38 // missiles
39 #define MISSILE1 100
40 #define MISSILE_AIR1 100
41 #define MISSILE_AIR2 101
42 #define MISSILE_AIR3 102
43 #define MISSILE_GROUND1 103
44 #define MISSILE_GROUND2 104
45 #define MISSILE_DF1 105
46 #define MISSILE_FF1 106
47 #define MISSILE_FF2 107
48 #define MISSILE_MINE1 180
49 #define MISSILE2 199
50 // air units
51 #define AIR 200
52 #define FIGHTER1 200
53 #define FIGHTER_FALCON 200
54 #define FIGHTER_SWALLOW 201
55 #define FIGHTER_HAWK 202
56 #define FIGHTER_HAWK2 203
57 #define FIGHTER_BUZZARD 204
58 #define FIGHTER_CROW 205
59 #define FIGHTER_PHOENIX 206
60 #define FIGHTER_REDARROW 207
61 #define FIGHTER_BLACKBIRD 208
62 #define FIGHTER_STORM 209
63 #define FIGHTER_PILOTED2 249
64 #define FIGHTER_TRANSPORT 280
65 #define FIGHTER_TRANSPORT2 281
66 #define FIGHTER2 299
67 // moving ground units from here
68 #define MOVING_GROUND 500
69 #define TANK1 700
70 #define TANK_AIR1 700
71 #define TANK_GROUND1 710
72 #define TANK_TRSAM1 711
73 #define TANK_PICKUP1 780
74 #define TANK_TRUCK1 790
75 #define TANK_TRUCK2 791
76 #define TANK2 799
77 // moving water units from here
78 #define MOVING_WATER 800
79 #define SHIP1 800
80 #define SHIP_CRUISER 800
81 #define SHIP_DESTROYER1 810
82 #define SHIP2 899
83 // static ground units from here
84 #define STATIC_GROUND 1000
85 #define FLAK1 1000
86 #define FLAK_AIR1 1000
87 #define FLARAK_AIR1 1010
88 #define FLAK2 1099
89 // passive static units from here
90 #define STATIC_PASSIVE 10000
91 #define STATIC_TENT1 10000
92 #define STATIC_TENT4 10003
93 #define STATIC_CONTAINER1 10100
94 #define STATIC_HALL1 10200
95 #define STATIC_HALL2 10201
96 #define STATIC_OILRIG1 10300
97 #define STATIC_COMPLEX1 10301
98 #define STATIC_RADAR1 10302
99 #define STATIC_BASE1 10303
100 #define STATIC_DEPOT1 10304
101 #define STATIC_BARRIER1 10400
102 
103 class DynamicObj : public CSpaceObj
104 {
105   public:
106   int id; // object type: FLARAK_AIR1, STATIC_TENT1, FIGHTER_SWALLOW, ...
107 //  bool controls;
108   bool active; // deactivated means no AI, no collision control and so on
109   // easymodel==1 is the ancient core of the game ;-)
110   // 1 means that theta will directly alter phi! Computer AI uses this model!
111   // 2 means the realistic model with ailerons, elevator, rudder
112   int easymodel;
113   int ttl; // time to live: cannon and missiles will only live a short time, missiles will sink when ttl<=0
114   int immunity; // immunity means the object cannot collide with others, needed for shooting missiles/cannon
115   float impact; // this value will be subtracted from the other objects shield when colliding
116   // Imagine a carthesian coordinate system in the landscape, the y-axis pointing up
117   float phi; // angle in x-z plane (polar coordinates)
118   float gamma; // orthogonal angle (polar coordinates)
119   float theta; // roll angle of the fighter!
120   float thrust; // current thrust, not the speed itself!
121   float realspeed; // the current speed, we only want to calculate this once per time step
122   float forcex, forcez, forcey; // the force vectors (orthogonal, should be clear)
123   float braking; // far away from reality: this factorizes the last speed vector with the current conditions (see move method)
124   float manoeverability; // how fast a fighter can alter its direction
125   float nimbility; // how fast a fighter responds to alterations of recXXX (recommended XXX)
126   float maxthrust; // maximum throttle value
127   float rectheta; // roll angle the fighter/object wants to reach
128   float recthrust; // throttle the fighter/object wants to reach
129   float recheight; // height above ground the fighter wants to reach
130   float recgamma; // elevation the fighter wants to reach
131   float maxtheta; // a maximum roll angle the object may achieve, easymodel==1 only!
132   float maxgamma; // a maximum elevation the object may achieve, easymodel==1 only!
133   float elevatoreffect; // number between 1.0 and -0.5, as diving should be less
134   float ruddereffect;
135   float rolleffect;
136   float recelevatoreffect; // number between 1.0 and -0.5, as diving should be less
137   float recruddereffect;
138   float recrolleffect;
139   int party; // usually 0 for enemies, 1 for allieds
140   int points, fighterkills, shipkills, tankkills, otherkills; // statistics
141   int sink; // ships will not explode but sink
142   bool killed; // statistics
143   Space *space; // in which space is this object, there is only one ;-)
144   DynamicObj *source; // missiles must keep track of the object they have been fired from -> statistics
145   int bomber; // act as bomber and prefer groud targets
146   char net [100];
147   int realism;
148   float accx, accy, accz;
149 
150   float shield, maxshield; // current and initial/maximum shield
151 
152   int net_write ();
153   void net_read ();
154   void activate ();
155   void deactivate ();
156   void dinit ();
157   DynamicObj ();
158   DynamicObj (Space *space2, CModel *o2, float zoom2);
159   void thrustUp ();
160   void thrustDown ();
161   float distance (DynamicObj *target);
162   float distanceXZ (DynamicObj *target);
163   // check whether the object is exploding or sinking and deactivate if necessary
164   void checkExplosion (Uint32 dt);
165   // check the objects shield value and explode/sink if necessary
166   void checkShield ();
167   // check whether the object collides on the ground and alter gamma and y-translation
168   void crashGround (Uint32 dt);
169   // check for collision, simplified model, each model is surrounded by a cube
170   // this works pretty well, but we must use more than one model for complex models or scenes
171   void collide (DynamicObj *d, Uint32 dt); // d must be the medium (laser, missile)
172   void setExplosion (float maxzoom, int len);
173   void setBlackSmoke (float maxzoom, int len);
174   // return heading difference towards enemy
175   int getAngle (DynamicObj *o);
176   // return elevation difference towards enemy
177   int getAngleH (DynamicObj *o);
178   // check for a looping, this is tricky :-)
179   bool checkLooping ();
180   void move (Uint32 dt);
181 };
182 
183 const int missiletypes = 8;
184 const int missileracks = 6;
185 
186 class AIObj : public DynamicObj
187 {
188   protected:
189   public:
190   bool ai; // AI on/off
191   bool autofire; // cannon fire on/off
192   DynamicObj *target; // targeted object
193   int acttype; // object is doing some action (Immelmann, Loop, ... not yet implemented)
194   // three intellience characteristics which make up a pilot: 0 = best, 400 = worst
195   int intelligence; // valid for every AI object: manoevers, fire rate (tanks), ...
196   int aggressivity; // valid for fighters: fly low, stay near and behind enemy
197   int precision; // valid for fighters: heading calculation
198   // manoevers disable any other AI consideration
199   int manoevertheta, manoeverheight, manoeverthrust;
200   int idle; // counter how long AI object does the same thing (to change direction)
201   int firemissilettl; // minimum time to wait between shooting missiles
202   int firecannonttl; // minimum time to wait between shooting cannon
203   int smokettl; // minimum time to wait between setting smoke elements
204   int missiletype; // only relevant for the player, describes type: AAM, AGM, DF
205   int missiles [missiletypes]; // number of missiles of each type
206   int missilerack [missileracks]; // number of missile racks
207   int missilerackn [missileracks]; // number of missile racks
208   float aw; // current heading difference to target
209   int score; // final score
210   float dtheta, dgamma; // theta/gamma alteration (smooth piloting)
211   float disttarget; // current distance to target
212   int flares;
213   int chaffs;
214   int fireflarettl;
215   int firechaffttl;
216   int ammo;
217   int ttf; // time to fire missile, targeting mechanism
218   CSmoke *smoke; // bright smoke behind the object (fighter&missiles)
219   Uint32 timer;
220   int statfirepower; // firepower (missiles) statistics, number of stars
221   bool dualshot; // one or two cannons?
222   int manoeverstate; // changes to realistic manoevers and turns off easymodel
223 
224   void aiinit (); // initialize variables
225   void missileCount ();
226   void newinit (int id, int party, int intelligence, int precision, int aggressivity); // init new AI object
227   void newinit (int id, int party, int intelligence); // init new AI object (esp. non-fighter)
228   AIObj ();
229   AIObj (Space *space2, CModel *o2, float zoom2);
230   ~AIObj ();
231   void initValues (DynamicObj *dobj, float phi); // init values to shoot cannon or missile
232   void fireCannon (DynamicObj *laser, float phi);
233   void fireCannon (DynamicObj **laser, float phi);
234   void fireCannon (DynamicObj **laser);
235   void fireMissile2 (int id, AIObj *missile, AIObj *target);
236   void fireFlare2 (DynamicObj *flare);
237   void fireChaff2 (DynamicObj *chaff);
238   int firstMissile (); // select first missile type
239   int nextMissile (int from); // select next missile type (cyclic)
240   bool haveMissile (int id); // missile of type id left?
241   bool haveMissile (); // missile of type missiletype left?
242   void decreaseMissile (int id); // decrease missiles by one
243   bool fireMissile (int id, AIObj **missile, AIObj *target);
244   bool fireMissile (AIObj **missile, AIObj *target);
245   bool fireMissile (int id, AIObj **missile);
246   bool fireMissile (AIObj **missile);
247   bool fireFlare (DynamicObj **flare, AIObj **missile);
248   bool fireChaff (DynamicObj **chaff, AIObj **missile);
249   bool fireMissileAir (AIObj **missile, AIObj *target);
250   bool selectMissileAir (AIObj **missile);
251   bool fireMissileAirFF (AIObj **missile, AIObj *target);
252   bool selectMissileAirFF (AIObj **missile);
253   bool fireMissileGround (AIObj **missile);
254   bool selectMissileGround (AIObj **missile);
255   void targetNearestGroundEnemy (AIObj **f);
256   void targetNearestEnemy (AIObj **f);
257   void targetNextEnemy (AIObj **f);
258   void targetLockingEnemy (AIObj **f);
259   void targetNext (AIObj **f);
260   void targetPrevious (AIObj **f);
261   void aiAction (Uint32 dt, AIObj **f, AIObj **m, DynamicObj **c, DynamicObj **flare, DynamicObj **chaff); // core AI method
262 };
263 
264 #endif
265