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 the
6  * source.
7  *
8 */
9 
10 
11 
12 #ifndef _FIREBALLS_H
13 #define _FIREBALLS_H
14 
15 #include "globalincs/pstypes.h"
16 #include "model/modelrender.h"
17 #include "gamesnd/gamesnd.h"
18 
19 class object;
20 class ship_info;
21 class asteroid_info;
22 
23 // values correspond to the fireball render types
24 #define FIREBALL_MEDIUM_EXPLOSION	0
25 #define FIREBALL_LARGE_EXPLOSION	1
26 #define FIREBALL_WARP_EFFECT		2
27 
28 // these values correspond to the fireball.tbl default entries
29 #define FIREBALL_EXPLOSION_MEDIUM	0		// Used for the 4 little explosions before a ship explodes
30 #define FIREBALL_WARP				1		// Used for the warp in / warp out effect
31 #define FIREBALL_KNOSSOS			2		// Used for the KNOSSOS warp in / warp out effect
32 #define FIREBALL_ASTEROID			3
33 #define FIREBALL_EXPLOSION_LARGE1	4		// Used for the big explosion when a ship breaks into pieces
34 #define FIREBALL_EXPLOSION_LARGE2	5		// Used for the big explosion when a ship breaks into pieces
35 
36 #define MAX_FIREBALL_TYPES			32		// The maximum number of fireballs that can be defined
37 #define NUM_DEFAULT_FIREBALLS		6
38 
39 #define MAX_FIREBALL_LOD						4
40 
41 #define FIREBALL_NUM_LARGE_EXPLOSIONS 2
42 
43 #define MAX_FIREBALLS	200
44 
45 extern int fireball_used[MAX_FIREBALL_TYPES];
46 
47 // all this moved here by Goober5000 because it makes more sense in the H file
48 typedef struct fireball_lod {
49 	char	filename[MAX_FILENAME_LEN];
50 	int		bitmap_id;
51 	int		num_frames;
52 	int		fps;
53 } fireball_lod;
54 
55 typedef struct fireball_info {
56 	char				unique_id[NAME_LENGTH];
57 	int					lod_count;
58 	fireball_lod		lod[MAX_FIREBALL_LOD];
59 	float				exp_color[3];	// red, green, blue
60 
61 	char	warp_glow[NAME_LENGTH];
62 	int		warp_glow_bitmap;
63 	char	warp_ball[NAME_LENGTH];
64 	int		warp_ball_bitmap;
65 	char	warp_model[NAME_LENGTH];
66 	int		warp_model_id;
67 } fireball_info;
68 
69 extern fireball_info Fireball_info[MAX_FIREBALL_TYPES];
70 extern int Num_fireball_types;
71 
72 // flag values for fireball struct flags member
73 #define	FBF_WARP_CLOSE_SOUND_PLAYED		(1<<0)
74 #define	FBF_WARP_CAPITAL_SIZE			(1<<1)
75 #define	FBF_WARP_CRUISER_SIZE			(1<<2)
76 #define FBF_WARP_3D						(1<<3)	// Goober5000
77 #define FBF_WARP_VIA_SEXP				(1<<4)	// Goober5000
78 
79 typedef struct fireball {
80 	int		objnum;					// If -1 this object is unused
81 	int		fireball_info_index;	// Index into Fireball_info array
82 	int		fireball_render_type;
83 	int		current_bitmap;
84 	int		orient;					// For fireballs, which orientation.  For warps, 0 is warpin, 1 is warpout
85 	int		flags;					// see #define FBF_*
86 	char	lod;					// current LOD
87 	float	time_elapsed;			// in seconds
88 	float	total_time;				// total lifetime of animation in seconds
89 
90 	// for warp-effect - Goober5000
91 	gamesnd_id warp_open_sound_index;
92 	gamesnd_id warp_close_sound_index;
93 	float	warp_open_duration;
94 	float	warp_close_duration;
95 } fireball;
96 // end move
97 
98 extern SCP_vector<fireball> Fireballs;
99 
100 extern bool fireballs_inited;
101 
102 void fireball_init();
103 void fireball_render(object* obj, model_draw_list *scene);
104 void fireball_delete( object * obj );
105 void fireball_process_post(object * obj, float frame_time);
106 
107 // This does not load all the data, just the filenames and such.  Only used by FRED.
108 void fireball_parse_tbl();
109 
110 int fireball_info_lookup(const char *unique_id);
111 
112 // reverse is for warp_in/out effects
113 // velocity: If not NULL, the fireball will move at a constant velocity.
114 // warp_lifetime: If warp_lifetime > 0.0f then makes the explosion loop so it lasts this long.  Only works for warp effect
115 int fireball_create(vec3d *pos, int fireball_type, int render_type, int parent_obj, float size, bool reverse=false, vec3d *velocity=nullptr, float warp_lifetime=0.0f, int ship_class=-1, matrix *orient=nullptr, int low_res=0, int extra_flags=0, gamesnd_id warp_open_sound=gamesnd_id(), gamesnd_id warp_close_sound=gamesnd_id(), float warp_open_duration=-1.0f, float warp_close_duration=-1.0f);
116 
117 void fireball_close();
118 
119 // Returns 1 if you can remove this fireball
120 int fireball_is_perishable(object * obj);
121 
122 // Returns 1 if this fireball is a warp
123 int fireball_is_warp(object * obj);
124 
125 // Returns life left of a fireball in seconds
126 float fireball_lifeleft( object *obj );
127 
128 // Returns life left of a fireball in percent
129 float fireball_lifeleft_percent( object *obj );
130 
131 // returns the lighting color (in [0...1] range) to use for explosion
132 void fireball_get_color(int idx, float *red, float *green, float *blue);
133 
134 // returns the index of the fireball bitmap for this ship. -1 if there is none.
135 int fireball_ship_explosion_type(ship_info *sip);
136 
137 // returns the index of the fireball bitmap for this asteroid. -1 if there is none.
138 int fireball_asteroid_explosion_type(asteroid_info *aip);
139 
140 // returns the intensity of a wormhole
141 float fireball_wormhole_intensity( fireball *fb );
142 
143 // Goober5000
144 extern int Knossos_warp_ani_used;
145 
146 extern bool Fireball_use_3d_warp;
147 
148 // Cyborg - get a count of how many valid fireballs are in the mission.
149 int fireball_get_count();
150 
151 #endif /* _FIREBALLS_H */
152