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