]> icculus.org git repositories - taylor/freespace2.git/blob - src/hud/hudartillery.cpp
More stuff compiles
[taylor/freespace2.git] / src / hud / hudartillery.cpp
1 /*
2  * $Logfile: /Freespace2/code/Hud/HudArtillery.cpp $
3  * $Revision$
4  * $Date$
5  * $Author$
6  *
7  *
8  * $Log$
9  * Revision 1.2  2002/05/03 13:34:33  theoddone33
10  * More stuff compiles
11  *
12  * Revision 1.1.1.1  2002/05/03 03:28:09  root
13  * Initial import.
14  *  
15  * 
16  * 5     6/01/99 8:35p Dave
17  * Finished lockarm weapons. Added proper supercap weapons/damage. Added
18  * awacs-set-radius sexpression.
19  * 
20  * 4     4/28/99 11:36p Dave
21  * Tweaked up subspace missile strike a bit,
22  * 
23  * 3     4/28/99 11:13p Dave
24  * Temporary checkin of artillery code.
25  * 
26  * 2     4/20/99 6:39p Dave
27  * Almost done with artillery targeting. Added support for downloading
28  * images on the PXO screen.
29  * 
30  * 1     4/20/99 12:00a Dave
31  * 
32  * 
33  * $NoKeywords: $
34  */
35
36 #include "hudartillery.h"
37 #include "ai.h"
38 #include "player.h"
39 #include "2d.h"
40 #include "alphacolors.h"
41
42 // -----------------------------------------------------------------------------------------------------------------------
43 // ARTILLERY DEFINES/VARS
44 //
45
46
47 // -----------------------------------------------------------------------------------------------------------------------
48 // ARTILLERY FUNCTIONS
49 //
50
51 #include "linklist.h"
52 #include "timer.h"
53 #include "parselo.h"
54 #include "multi.h"
55 #include "fireballs.h"
56 #include "freespace.h"
57
58 // test code for subspace missile strike -------------------------------------------
59
60
61 int Ssm_info_count = 0;
62 ssm_info Ssm_info[MAX_SSM_TYPES];
63
64 // list of active/free strikes
65 ssm_strike Ssm_strikes[MAX_SSM_STRIKES];
66 ssm_strike Ssm_free_list;
67 ssm_strike Ssm_used_list;
68 int Num_ssm_strikes = 0;
69
70 // game init
71 void ssm_init()
72 {       
73         ssm_info bogus, *s;
74         char weapon_name[NAME_LENGTH+1] = "";
75
76         read_file_text("ssm.tbl");
77         reset_parse();
78
79         // parse the table
80         Ssm_info_count = 0;
81         while(!optional_string("#end")){
82                 // another ssm definition
83                 if(optional_string("$SSM:")){
84                         // pointer to info struct
85                         if(Ssm_info_count >= MAX_SSM_TYPES){
86                                 s = &bogus;
87                         } else {
88                                 s = &Ssm_info[Ssm_info_count];
89                         }
90
91                         // name
92                         stuff_string(s->name, F_NAME, NULL);
93
94                         // stuff data
95                         required_string("+Weapon:");
96                         stuff_string(weapon_name, F_NAME, NULL);
97                         required_string("+Count:");
98                         stuff_int(&s->count);
99                         required_string("+WarpRadius:");
100                         stuff_float(&s->warp_radius);
101                         required_string("+WarpTime:");
102                         stuff_float(&s->warp_time);
103                         required_string("+Radius:");
104                         stuff_float(&s->radius);
105                         required_string("+Offset:");
106                         stuff_float(&s->offset);
107
108                         // see if we have a valid weapon
109                         s->weapon_info_index = -1;
110                         s->weapon_info_index = weapon_name_lookup(weapon_name);
111                         if(s->weapon_info_index >= 0){
112                                 // valid
113                                 Ssm_info_count++;
114                         }
115                 }
116         }
117 }
118
119 void ssm_get_random_start_pos(vector *out, vector *start, matrix *orient, int ssm_index)
120 {
121         vector temp;
122         ssm_info *s = &Ssm_info[ssm_index];
123
124         // get a random vector in the circle of the firing plane
125         vm_vec_random_in_circle(&temp, start, orient, s->radius, 1);
126
127         // offset it a bit
128         vm_vec_scale_add(out, &temp, &orient->fvec, s->offset);
129 }
130
131 // level init
132 void ssm_level_init()
133 {
134         int i;
135
136         Num_ssm_strikes = 0;
137         list_init( &Ssm_free_list );
138         list_init( &Ssm_used_list );
139
140         // Link all object slots into the free list
141         for (i=0; i<MAX_SSM_STRIKES; i++)       {
142                 list_append(&Ssm_free_list, &Ssm_strikes[i] );
143         }
144 }
145
146 // start a subspace missile effect
147 void ssm_create(vector *target, vector *start, int ssm_index, ssm_firing_info *override)
148 {       
149         ssm_strike *ssm;                
150         matrix dir;
151         int idx;
152
153         if (Num_ssm_strikes >= MAX_SSM_STRIKES ) {
154                 #ifndef NDEBUG
155                 mprintf(("Ssm creation failed - too many ssms!\n" ));
156                 #endif
157                 return;
158         }
159
160         // sanity
161         Assert(target != NULL);
162         if(target == NULL){
163                 return;
164         }
165         Assert(start != NULL);
166         if(start == NULL){
167                 return;
168         }
169         if((ssm_index < 0) || (ssm_index >= MAX_SSM_TYPES)){
170                 return;
171         }
172
173         // Find next available trail
174         ssm = GET_FIRST(&Ssm_free_list);
175         Assert( ssm != &Ssm_free_list );                // shouldn't have the dummy element
176
177         // remove trailp from the free list
178         list_remove( &Ssm_free_list, ssm );
179         
180         // insert trailp onto the end of used list
181         list_append( &Ssm_used_list, ssm );
182
183         // increment counter
184         Num_ssm_strikes++;      
185
186         // Init the ssm data
187
188         // override in multiplayer
189         if(override != NULL){
190                 ssm->sinfo = *override;
191         }
192         // single player or the server
193         else {
194                 // forward orientation
195                 vector temp;
196                 vm_vec_sub(&temp, target, start);
197                 vm_vec_normalize(&temp);
198                 vm_vector_2_matrix(&dir, &temp, NULL, NULL);
199
200                 // stuff info
201                 ssm->sinfo.ssm_index = ssm_index;
202                 ssm->sinfo.target = *target;
203                 for(idx=0; idx<Ssm_info[ssm_index].count; idx++){
204                         ssm->sinfo.delay_stamp[idx] = timestamp(200 + (int)frand_range(-199.0f, 1000.0f));
205                         ssm_get_random_start_pos(&ssm->sinfo.start_pos[idx], start, &dir, ssm_index);
206                 }
207
208                 // if we're the server, send a packet
209                 if(MULTIPLAYER_MASTER){
210                         //
211                 }
212         }
213
214         // clear timestamps, handles, etc
215         for(idx=0; idx<MAX_SSM_COUNT; idx++){
216                 ssm->done_flags[idx] = 0;
217                 ssm->fireballs[idx] = -1;
218         }
219 }
220
221 // delete a finished ssm effect
222 void ssm_delete(ssm_strike *ssm)
223 {
224         // remove objp from the used list
225         list_remove( &Ssm_used_list, ssm );
226
227         // add objp to the end of the free
228         list_append( &Ssm_free_list, ssm );
229
230         // decrement counter
231         Num_ssm_strikes--;
232
233         nprintf(("General", "Recycling SSM, %d left", Num_ssm_strikes));
234 }
235
236 // process subspace missile stuff
237 void ssm_process()
238 {
239         int idx, finished;
240         ssm_strike *moveup, *next_one;
241         ssm_info *si;
242         
243         // process all strikes  
244         moveup=GET_FIRST(&Ssm_used_list);
245         while ( moveup!=END_OF_LIST(&Ssm_used_list) )   {               
246                 // get the type
247                 if(moveup->sinfo.ssm_index < 0){
248                         continue;
249                 }
250                 si = &Ssm_info[moveup->sinfo.ssm_index];
251
252                 // check all the individual missiles
253                 finished = 1;
254                 for(idx=0; idx<si->count; idx++){
255                         // if this guy is not marked as done
256                         if(!moveup->done_flags[idx]){
257                                 finished = 0;                           
258
259                                 // if he already has the fireball effect
260                                 if(moveup->fireballs[idx] >= 0){
261                                         // if the warp effect is half done, fire the missile
262                                         if((1.0f - fireball_lifeleft_percent(&Objects[moveup->fireballs[idx]])) >= 0.5f){
263                                                 // get an orientation
264                                                 vector temp;
265                                                 matrix orient;
266
267                                                 vm_vec_sub(&temp, &moveup->sinfo.target, &moveup->sinfo.start_pos[idx]);
268                                                 vm_vec_normalize(&temp);
269                                                 vm_vector_2_matrix(&orient, &temp, NULL, NULL);
270
271                                                 // fire the missile and flash the screen
272                                                 weapon_create(&moveup->sinfo.start_pos[idx], &orient, si->weapon_info_index, -1, 1, -1, 1);
273
274                                                 // this makes this particular missile done
275                                                 moveup->done_flags[idx] = 1;
276                                         }
277                                 } 
278                                 // maybe create his warpin effect
279                                 else if((moveup->sinfo.delay_stamp[idx] >= 0) && timestamp_elapsed(moveup->sinfo.delay_stamp[idx])){
280                                         // get an orientation
281                                         vector temp;
282                                         matrix orient;
283
284                                         vm_vec_sub(&temp, &moveup->sinfo.target, &moveup->sinfo.start_pos[idx]);
285                                         vm_vec_normalize(&temp);
286                                         vm_vector_2_matrix(&orient, &temp, NULL, NULL);
287                                         moveup->fireballs[idx] = fireball_create(&moveup->sinfo.start_pos[idx], FIREBALL_WARP_EFFECT, -1, si->warp_radius, 0, &vmd_zero_vector, si->warp_time, 0, &orient);
288                                 }
289                         }
290                 }
291                 if(finished){
292                         next_one = GET_NEXT(moveup);                    
293                         ssm_delete(moveup);                                                                                                                     
294                         moveup = next_one;
295                         continue;
296                 }
297                 
298                 moveup=GET_NEXT(moveup);
299         }       
300 }
301
302
303 // test code for subspace missile strike -------------------------------------------
304
305 // level init
306 void hud_init_artillery()
307 {
308 }
309
310 // update all hud artillery related stuff
311 void hud_artillery_update()
312 {
313 }
314
315 // render all hud artillery related stuff
316 void hud_artillery_render()
317 {
318         // render how long the player has been painting his target      
319         if((Player_ai != NULL) && (Player_ai->artillery_objnum >= 0)){
320                 gr_set_color_fast(&Color_bright_blue);
321                 gr_printf(10, 50, "%f", Player_ai->artillery_lock_time);
322         }
323 }