2 * Copyright (C) Volition, Inc. 1999. All rights reserved.
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
10 * $Logfile: /Freespace2/code/Hud/HudArtillery.cpp $
17 * Revision 1.6 2005/10/01 22:04:58 taylor
18 * fix FS1 (de)briefing voices, the directory names are different in FS1
19 * hard code the table values so that the fs1.vp file isn't needed
20 * hard code a mission fix for sm2-08a since a have no idea how to fix it otherwise
21 * generally cleanup some FS1 code
22 * fix volume sliders in the options screen that never went all the way up
24 * Revision 1.5 2002/06/17 06:33:09 relnev
25 * ryan's struct patch for gcc 2.95
27 * Revision 1.4 2002/06/09 04:41:21 relnev
28 * added copyright header
30 * Revision 1.3 2002/05/07 03:16:45 theoddone33
31 * The Great Newline Fix
33 * Revision 1.2 2002/05/03 13:34:33 theoddone33
36 * Revision 1.1.1.1 2002/05/03 03:28:09 root
40 * 5 6/01/99 8:35p Dave
41 * Finished lockarm weapons. Added proper supercap weapons/damage. Added
42 * awacs-set-radius sexpression.
44 * 4 4/28/99 11:36p Dave
45 * Tweaked up subspace missile strike a bit,
47 * 3 4/28/99 11:13p Dave
48 * Temporary checkin of artillery code.
50 * 2 4/20/99 6:39p Dave
51 * Almost done with artillery targeting. Added support for downloading
52 * images on the PXO screen.
54 * 1 4/20/99 12:00a Dave
60 #include "hudartillery.h"
64 #include "alphacolors.h"
66 // -----------------------------------------------------------------------------------------------------------------------
67 // ARTILLERY DEFINES/VARS
71 // -----------------------------------------------------------------------------------------------------------------------
72 // ARTILLERY FUNCTIONS
79 #include "fireballs.h"
80 #include "freespace.h"
82 // test code for subspace missile strike -------------------------------------------
85 int Ssm_info_count = 0;
86 ssm_info Ssm_info[MAX_SSM_TYPES];
88 // list of active/free strikes
89 ssm_strike Ssm_strikes[MAX_SSM_STRIKES];
90 ssm_strike Ssm_free_list;
91 ssm_strike Ssm_used_list;
92 int Num_ssm_strikes = 0;
99 char weapon_name[NAME_LENGTH+1] = "";
101 read_file_text("ssm.tbl");
106 while(!optional_string("#end")){
107 // another ssm definition
108 if(optional_string("$SSM:")){
109 // pointer to info struct
110 if(Ssm_info_count >= MAX_SSM_TYPES){
113 s = &Ssm_info[Ssm_info_count];
117 stuff_string(s->name, F_NAME, NULL);
120 required_string("+Weapon:");
121 stuff_string(weapon_name, F_NAME, NULL);
122 required_string("+Count:");
123 stuff_int(&s->count);
124 required_string("+WarpRadius:");
125 stuff_float(&s->warp_radius);
126 required_string("+WarpTime:");
127 stuff_float(&s->warp_time);
128 required_string("+Radius:");
129 stuff_float(&s->radius);
130 required_string("+Offset:");
131 stuff_float(&s->offset);
133 // see if we have a valid weapon
134 s->weapon_info_index = -1;
135 s->weapon_info_index = weapon_name_lookup(weapon_name);
136 if(s->weapon_info_index >= 0){
148 void ssm_get_random_start_pos(vector *out, vector *start, matrix *orient, int ssm_index)
151 ssm_info *s = &Ssm_info[ssm_index];
153 // get a random vector in the circle of the firing plane
154 vm_vec_random_in_circle(&temp, start, orient, s->radius, 1);
157 vm_vec_scale_add(out, &temp, &orient->v.fvec, s->offset);
161 void ssm_level_init()
166 list_init( &Ssm_free_list );
167 list_init( &Ssm_used_list );
169 // Link all object slots into the free list
170 for (i=0; i<MAX_SSM_STRIKES; i++) {
171 list_append(&Ssm_free_list, &Ssm_strikes[i] );
175 // start a subspace missile effect
176 void ssm_create(vector *target, vector *start, int ssm_index, ssm_firing_info *override)
182 if (Num_ssm_strikes >= MAX_SSM_STRIKES ) {
184 mprintf(("Ssm creation failed - too many ssms!\n" ));
190 Assert(target != NULL);
194 Assert(start != NULL);
198 if((ssm_index < 0) || (ssm_index >= MAX_SSM_TYPES)){
202 // Find next available trail
203 ssm = GET_FIRST(&Ssm_free_list);
204 Assert( ssm != &Ssm_free_list ); // shouldn't have the dummy element
206 // remove trailp from the free list
207 list_remove( &Ssm_free_list, ssm );
209 // insert trailp onto the end of used list
210 list_append( &Ssm_used_list, ssm );
217 // override in multiplayer
218 if(override != NULL){
219 ssm->sinfo = *override;
221 // single player or the server
223 // forward orientation
225 vm_vec_sub(&temp, target, start);
226 vm_vec_normalize(&temp);
227 vm_vector_2_matrix(&dir, &temp, NULL, NULL);
230 ssm->sinfo.ssm_index = ssm_index;
231 ssm->sinfo.target = *target;
232 for(idx=0; idx<Ssm_info[ssm_index].count; idx++){
233 ssm->sinfo.delay_stamp[idx] = timestamp(200 + (int)frand_range(-199.0f, 1000.0f));
234 ssm_get_random_start_pos(&ssm->sinfo.start_pos[idx], start, &dir, ssm_index);
237 // if we're the server, send a packet
238 if(MULTIPLAYER_MASTER){
243 // clear timestamps, handles, etc
244 for(idx=0; idx<MAX_SSM_COUNT; idx++){
245 ssm->done_flags[idx] = 0;
246 ssm->fireballs[idx] = -1;
250 // delete a finished ssm effect
251 void ssm_delete(ssm_strike *ssm)
253 // remove objp from the used list
254 list_remove( &Ssm_used_list, ssm );
256 // add objp to the end of the free
257 list_append( &Ssm_free_list, ssm );
262 nprintf(("General", "Recycling SSM, %d left", Num_ssm_strikes));
265 // process subspace missile stuff
269 ssm_strike *moveup, *next_one;
272 // process all strikes
273 moveup=GET_FIRST(&Ssm_used_list);
274 while ( moveup!=END_OF_LIST(&Ssm_used_list) ) {
276 if(moveup->sinfo.ssm_index < 0){
279 si = &Ssm_info[moveup->sinfo.ssm_index];
281 // check all the individual missiles
283 for(idx=0; idx<si->count; idx++){
284 // if this guy is not marked as done
285 if(!moveup->done_flags[idx]){
288 // if he already has the fireball effect
289 if(moveup->fireballs[idx] >= 0){
290 // if the warp effect is half done, fire the missile
291 if((1.0f - fireball_lifeleft_percent(&Objects[moveup->fireballs[idx]])) >= 0.5f){
292 // get an orientation
296 vm_vec_sub(&temp, &moveup->sinfo.target, &moveup->sinfo.start_pos[idx]);
297 vm_vec_normalize(&temp);
298 vm_vector_2_matrix(&orient, &temp, NULL, NULL);
300 // fire the missile and flash the screen
301 weapon_create(&moveup->sinfo.start_pos[idx], &orient, si->weapon_info_index, -1, 1, -1, 1);
303 // this makes this particular missile done
304 moveup->done_flags[idx] = 1;
307 // maybe create his warpin effect
308 else if((moveup->sinfo.delay_stamp[idx] >= 0) && timestamp_elapsed(moveup->sinfo.delay_stamp[idx])){
309 // get an orientation
313 vm_vec_sub(&temp, &moveup->sinfo.target, &moveup->sinfo.start_pos[idx]);
314 vm_vec_normalize(&temp);
315 vm_vector_2_matrix(&orient, &temp, NULL, NULL);
316 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);
321 next_one = GET_NEXT(moveup);
327 moveup=GET_NEXT(moveup);
332 // test code for subspace missile strike -------------------------------------------
335 void hud_init_artillery()
339 // update all hud artillery related stuff
340 void hud_artillery_update()
344 // render all hud artillery related stuff
345 void hud_artillery_render()
347 // render how long the player has been painting his target
348 if((Player_ai != NULL) && (Player_ai->artillery_objnum >= 0)){
349 gr_set_color_fast(&Color_bright_blue);
350 gr_printf(10, 50, "%f", Player_ai->artillery_lock_time);