1 #ifndef __MISSILES_H__
2 #define __MISSILES_H__
3
4 #include "actors.h"
5 #include "cal3d_wrapper.h"
6
7 #ifdef __cplusplus
8 extern "C" {
9 #endif
10
11 #define MAX_MISSILES 1024
12 #define MAX_MISSILES_DEFS 16
13
14 typedef enum {
15 MISSED_SHOT = 0,
16 NORMAL_SHOT = 1,
17 CRITICAL_SHOT = 2
18 } MissileShotType;
19
20 typedef enum {
21 REGULAR_MISSILE = 0,
22 MAGIC_MISSILE = 1,
23 FIRE_MISSILE = 2,
24 ICE_MISSILE = 3,
25 EXPLOSIVE_MISSILE = 4
26 } MissileEffectType;
27
28 /*!
29 * \brief Structure that handle flying missiles
30 */
31 typedef struct
32 {
33 int type; /*!< The type of the missile: corresponds to the quiver type */
34 MissileShotType shot_type; /*!< Specifies the type of the shot (normal, missed...) */
35 float position[3]; /*!< The position of the missile */
36 float direction[3]; /*!< The direction of the missile */
37 float speed; /*!< The speed of the missile */
38 float trace_length; /*!< The length of the trace let by the missile */
39 float covered_distance; /*!< The distance covered by the missile */
40 float remaining_distance; /*!< The remaining distance to cover */
41 } missile;
42
43 typedef struct
44 {
45 char lost_mesh[MAX_FILE_PATH]; /*!< The name of the mesh used for lost missiles */
46 float length; /*!< Length of the missile mesh: used to know the position from where to launch the missile */
47 float trace_length; /*!< Length of the trace that the missile leaves behind it */
48 float speed; /*!< Speed of the missile */
49 MissileEffectType effect; /*!< Special effect to use for the missile */
50 } missile_type;
51
52 extern int missiles_count;
53 extern missile missiles_list[MAX_MISSILES];
54 extern missile_type missiles_defs[MAX_MISSILES_DEFS];
55
56 #ifdef DEBUG
57 extern int enable_client_aiming;
58 #endif // DEBUG
59
60 #ifdef MISSILES_DEBUG
61 /*!
62 * \brief Log a message in the file config_dir/missiles_log.txt
63 * \param format the format of the message to log (same options than printf)
64 * \param ... data corresponding to the format
65 */
66 void missiles_log_message_func(const char *format, ...);
67
68 #define missiles_log_message(format, ...) (missiles_log_message_func("%s: %d: " format, __FUNCTION__, __LINE__, __VA_ARGS__))
69 #else // MISSILES_DEBUG
70 #define missiles_log_message(format, ...)
71 #endif // MISSILES_DEBUG
72
get_missile_ptr_from_id(int id)73 static __inline__ missile *get_missile_ptr_from_id(int id)
74 {
75 return ((id >= 0 && id < missiles_count) ? &missiles_list[id] : NULL);
76 }
77
78 /*!
79 * \brief Removes all the missiles
80 */
81 void missiles_clear();
82
83 /*!
84 * \brief Adds a new missile
85 * \param type the type of the missile
86 * \param origin the origin coordinates of the missile
87 * \param target the target coordinates of the missile
88 * \param shift allows to tune if the missile should stop before or after the target
89 * \param shot_type tells if the shot is missed, normal or critical (will be drawn diferently)
90 */
91 int missiles_add(int type,
92 float origin[3],
93 float target[3],
94 float shift,
95 MissileShotType shot_type);
96
97 /*!
98 * \brief Computes the next position for all missiles
99 */
100 void missiles_update();
101
102 /*!
103 * \brief Draws all the missiles
104 */
105 void missiles_draw();
106
107 /*!
108 * \brief Adds a new arrow (calls add_missile)
109 * \param a the actor throwing the arrow
110 * \param target the target
111 * \param shot_type the type of the shot (normal, missed, critical)
112 */
113 int missiles_fire_arrow(actor *a, float target[3], MissileShotType shot_type);
114
115 /*!
116 * \brief Computes the rotations to apply to a char when aiming something
117 * \param out_h_rot the returned horizontal rotation
118 * \param out_v_rot the returned vertical rotation
119 * \param in_act the actor
120 * \param in_target the target
121 * \return the rotation to apply to the whole char to face the target
122 *
123 * The rotations stored in out_h_rot and out_v_rot have to be applied to bones of the
124 * char in order to have a fine orientation. The horizontal orientation should stay
125 * between -22.5 and +22.5 degrees.
126 */
127 float missiles_compute_actor_rotation(float *out_h_rot, float *out_v_rot,
128 actor *in_act, float *in_target);
129
130 /*!
131 * \brief Rotates bones of an actor according to what is defined in its structure
132 * \param a the actor
133 */
134 void missiles_rotate_actor_bones(actor *a);
135
136 /*!
137 * \brief Cleans the range action queue of an actor from the finished actions
138 * \param act the actor
139 */
140 void missiles_clean_range_actions_queue(actor *act);
141
142 /*!
143 * \brief Tells an actor to aim at another actor
144 * \param actor1_id the ID of the current actor
145 * \param actor2_id the ID of the other actor
146 */
147 void missiles_aim_at_b(int actor1_id, int actor2_id);
148
149 /*!
150 * \brief Tells an actor to aim at a target
151 * \param actor_id the ID of the actor
152 * \param target the target
153 */
154 void missiles_aim_at_xyz(int actor_id, float *target);
155
156 /*!
157 * \brief Tells an actor to fire an arrow on another actor
158 * \param actor1_id the ID of the current actor
159 * \param actor2_id the ID of the other actor
160 */
161 void missiles_fire_a_to_b(int actor1_id, int actor2_id);
162
163 /*!
164 * \brief Tells an actor to fire an arrow on a target
165 * \param actor_id the ID of the actor
166 * \param target the target
167 */
168 void missiles_fire_a_to_xyz(int actor_id, float *target);
169
170 /*!
171 * \brief Fires a missile from a position to an actor
172 * \param origin the origin
173 * \param actor_id the actor
174 */
175 void missiles_fire_xyz_to_b(float *origin, int actor_id);
176
177 /*!
178 * \brief Initializes the missiles definitions
179 */
180 void missiles_init_defs();
181
182 extern int range_total_shots;
183 extern int range_success_hits;
184 extern int range_critical_hits;
185
186 #ifdef __cplusplus
187 } // extern "C"
188 #endif
189
190 #endif // __MISSILES_H__
191