2 * $Logfile: /Freespace2/code/Hud/HudArtillery.cpp $
9 * Revision 1.2 2002/05/03 13:34:33 theoddone33
12 * Revision 1.1.1.1 2002/05/03 03:28:09 root
16 * 5 6/01/99 8:35p Dave
17 * Finished lockarm weapons. Added proper supercap weapons/damage. Added
18 * awacs-set-radius sexpression.
20 * 4 4/28/99 11:36p Dave
21 * Tweaked up subspace missile strike a bit,
23 * 3 4/28/99 11:13p Dave
24 * Temporary checkin of artillery code.
26 * 2 4/20/99 6:39p Dave
27 * Almost done with artillery targeting. Added support for downloading
28 * images on the PXO screen.
30 * 1 4/20/99 12:00a Dave
36 #include "hudartillery.h"
40 #include "alphacolors.h"
42 // -----------------------------------------------------------------------------------------------------------------------
43 // ARTILLERY DEFINES/VARS
47 // -----------------------------------------------------------------------------------------------------------------------
48 // ARTILLERY FUNCTIONS
55 #include "fireballs.h"
56 #include "freespace.h"
58 // test code for subspace missile strike -------------------------------------------
61 int Ssm_info_count = 0;
62 ssm_info Ssm_info[MAX_SSM_TYPES];
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;
74 char weapon_name[NAME_LENGTH+1] = "";
76 read_file_text("ssm.tbl");
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){
88 s = &Ssm_info[Ssm_info_count];
92 stuff_string(s->name, F_NAME, NULL);
95 required_string("+Weapon:");
96 stuff_string(weapon_name, F_NAME, NULL);
97 required_string("+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);
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){
119 void ssm_get_random_start_pos(vector *out, vector *start, matrix *orient, int ssm_index)
122 ssm_info *s = &Ssm_info[ssm_index];
124 // get a random vector in the circle of the firing plane
125 vm_vec_random_in_circle(&temp, start, orient, s->radius, 1);
128 vm_vec_scale_add(out, &temp, &orient->fvec, s->offset);
132 void ssm_level_init()
137 list_init( &Ssm_free_list );
138 list_init( &Ssm_used_list );
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] );
146 // start a subspace missile effect
147 void ssm_create(vector *target, vector *start, int ssm_index, ssm_firing_info *override)
153 if (Num_ssm_strikes >= MAX_SSM_STRIKES ) {
155 mprintf(("Ssm creation failed - too many ssms!\n" ));
161 Assert(target != NULL);
165 Assert(start != NULL);
169 if((ssm_index < 0) || (ssm_index >= MAX_SSM_TYPES)){
173 // Find next available trail
174 ssm = GET_FIRST(&Ssm_free_list);
175 Assert( ssm != &Ssm_free_list ); // shouldn't have the dummy element
177 // remove trailp from the free list
178 list_remove( &Ssm_free_list, ssm );
180 // insert trailp onto the end of used list
181 list_append( &Ssm_used_list, ssm );
188 // override in multiplayer
189 if(override != NULL){
190 ssm->sinfo = *override;
192 // single player or the server
194 // forward orientation
196 vm_vec_sub(&temp, target, start);
197 vm_vec_normalize(&temp);
198 vm_vector_2_matrix(&dir, &temp, NULL, NULL);
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);
208 // if we're the server, send a packet
209 if(MULTIPLAYER_MASTER){
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;
221 // delete a finished ssm effect
222 void ssm_delete(ssm_strike *ssm)
224 // remove objp from the used list
225 list_remove( &Ssm_used_list, ssm );
227 // add objp to the end of the free
228 list_append( &Ssm_free_list, ssm );
233 nprintf(("General", "Recycling SSM, %d left", Num_ssm_strikes));
236 // process subspace missile stuff
240 ssm_strike *moveup, *next_one;
243 // process all strikes
244 moveup=GET_FIRST(&Ssm_used_list);
245 while ( moveup!=END_OF_LIST(&Ssm_used_list) ) {
247 if(moveup->sinfo.ssm_index < 0){
250 si = &Ssm_info[moveup->sinfo.ssm_index];
252 // check all the individual missiles
254 for(idx=0; idx<si->count; idx++){
255 // if this guy is not marked as done
256 if(!moveup->done_flags[idx]){
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
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);
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);
274 // this makes this particular missile done
275 moveup->done_flags[idx] = 1;
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
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);
292 next_one = GET_NEXT(moveup);
298 moveup=GET_NEXT(moveup);
303 // test code for subspace missile strike -------------------------------------------
306 void hud_init_artillery()
310 // update all hud artillery related stuff
311 void hud_artillery_update()
315 // render all hud artillery related stuff
316 void hud_artillery_render()
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);