1 /*!
2 * \file
3 * \ingroup display
4 * \brief This file holds information about actors appearance etc. used for displaying the actors.
5 */
6 #ifndef __ACTORS_H__
7 #define __ACTORS_H__
8
9 #ifdef MUTEX_DEBUG
10 #include <assert.h>
11 #include <stdlib.h>
12 #include <SDL.h>
13 #endif
14 #include <SDL_mutex.h>
15 #include "bbox_tree.h"
16 #include "cal_types.h"
17 #include "chat.h"
18 #include "client_serv.h"
19 #include "platform.h"
20 #include "tiles.h"
21 #include "buffs.h"
22 #include "eye_candy_types.h"
23 #include "hash.h"
24
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28
29 #define MAX_FILE_PATH 128 // the max chars allowed int a path/filename for actor textures/masks
30 #define MAX_ACTOR_DEFS 256
31 #define MAX_ACTORS 1000 /*!< The maximum number of actors the client can hold */
32 #define ACTOR_DEF_NAME_SIZE 256
33
34 extern int yourself; /*!< This variable holds the actor_id (as the server sees it, not the position in the actors_list) of your character.*/
35 extern int you_sit; /*!< Specifies if you are currently sitting down.*/
36 extern int sit_lock; /*!< The sit_lock variable holds you in a sitting position.*/
37 extern int use_alpha_banner; /*!< Use_alpha_banner defines if an alpha background is drawn behind the name/health banner.*/
38
39 /*!
40 * \name Actor types
41 * Defines the colour of the name.
42 */
43 /*! \{ */
44 #define HUMAN 1 /*!< Draw the actors name in white*/
45 #define NPC 2 /*!< Draw the actors name in blue*/
46 #define COMPUTER_CONTROLLED_HUMAN 3 /*!< Draw the actors name in white*/
47 #define PKABLE_HUMAN 4 /*!< Draw the actors name in red*/
48 #define PKABLE_COMPUTER_CONTROLLED 5 /*!< Draw the actors name in red*/
49 /*! \} */
50
51 /*! The maximum number of lines in the overhead text */
52 #define MAX_CURRENT_DISPLAYED_TEXT_LINES 3
53 /*! Max text len to display into bubbles overhead */
54 #define MAX_CURRENT_DISPLAYED_TEXT_LEN (MAX_TEXT_MESSAGE_LENGTH + MAX_CURRENT_DISPLAYED_TEXT_LINES + 1)
55
56 // default duration in ms of a step when an actor is walking
57 #define DEFAULT_STEP_DURATION 250
58
59 /*!
60 * \name Glow colours
61 * The colours used for giving the items a glowing halo
62 */
63 /*! \{ */
64 /*! The colours used in the glowing swords (magic, thermal, ice, fire)*/
65 typedef struct
66 {
67 float r; /*!< Red (0<=r<=1)*/
68 float g; /*!< Green (0<=g<=1)*/
69 float b; /*!< Blue (0<=b<=1)*/
70 }glow_color;
71
72 //GLOWS
73 #define GLOW_NONE 0 /*!< RGB: 0.0, 0.0, 0.0*/
74 #define GLOW_FIRE 1 /*!< RGB: 0.5, 0.1, 0.1*/
75 #define GLOW_COLD 2 /*!< RGB: 0.1, 0.1, 0.5*/
76 #define GLOW_THERMAL 3 /*!< RGB: 0.5, 0.1, 0.5*/
77 #define GLOW_MAGIC 4 /*!< RGB: 0.5, 0.4, 0.0*/
78 extern glow_color glow_colors[10]; /*!< Holds the glow colours defined in GLOW_**/
79 /*! \} */
80
81 /*!
82 * The near_actor structure holds information about the actors within range. It is filled once every frame.
83 */
84 typedef struct {
85 int actor;//offset in the actors_list
86 int select;
87 int buffs; // The buffs on this actor
88 int type;
89 int alpha;
90 int ghost;//If it's a ghost or not
91 } near_actor;
92
93 extern int no_near_actors;
94 #ifdef NEW_SOUND
95 extern int no_near_enhanced_actors;
96 extern float distanceSq_to_near_enhanced_actors;
97 #endif // NEW_SOUND
98 extern near_actor near_actors[MAX_ACTORS];
99
100 /*!
101 * The enhanced actor structure holds information about the actors extensions such as if the actor is wearing any armour, weapons etc.
102 */
103 typedef struct
104 {
105 int uniq_id;
106 int guild_id;
107 int guild_tag_color;
108
109 int legs_meshindex;
110 int head_meshindex;
111 int torso_meshindex;
112 int weapon_meshindex;
113 int shield_meshindex;
114 int helmet_meshindex;
115 int neck_meshindex;
116 int cape_meshindex;
117 int boots_meshindex;
118
119 /*! \name The texture names*/
120 /*! \{ */
121 char pants_tex[MAX_FILE_PATH];
122 char pants_mask[MAX_FILE_PATH];
123
124 char boots_tex[MAX_FILE_PATH];
125 char boots_mask[MAX_FILE_PATH];
126
127 char torso_tex[MAX_FILE_PATH];
128 char arms_tex[MAX_FILE_PATH];
129 char torso_mask[MAX_FILE_PATH];
130 char arms_mask[MAX_FILE_PATH];
131
132 char hands_tex[MAX_FILE_PATH];
133 char head_tex[MAX_FILE_PATH];
134 char hands_mask[MAX_FILE_PATH];
135 char head_mask[MAX_FILE_PATH];
136
137 char head_base[MAX_FILE_PATH];
138 char body_base[MAX_FILE_PATH];
139 char arms_base[MAX_FILE_PATH];
140 char legs_base[MAX_FILE_PATH];
141 char boots_base[MAX_FILE_PATH];
142
143 char hair_tex[MAX_FILE_PATH];
144 char eyes_tex[MAX_FILE_PATH];
145 char weapon_tex[MAX_FILE_PATH];
146 char shield_tex[MAX_FILE_PATH];
147 char helmet_tex[MAX_FILE_PATH];
148 char neck_tex[MAX_FILE_PATH];
149 char cape_tex[MAX_FILE_PATH];
150 char hands_tex_save[MAX_FILE_PATH];
151 /*! \} */
152
153 /*! \name Specifies the glow of each worn item*/
154 /*! \{ */
155 int weapon_glow;
156 int shield_glow;
157 int helmet_glow;
158 int neck_glow;
159 int cape_glow;
160 int legs_glow;
161 /*! \} */
162
163 }enhanced_actor;
164
165 /*! Sets the main model type*/
166 typedef struct
167 {
168 char model_name[MAX_FILE_PATH];
169 char skin_name[MAX_FILE_PATH];
170 char skin_mask[MAX_FILE_PATH];
171 int glow;
172 int mesh_index;
173 }body_part;
174
175 /*! Sets the shield type*/
176 typedef struct
177 {
178 char model_name[MAX_FILE_PATH];
179 char skin_name[MAX_FILE_PATH];
180 char skin_mask[MAX_FILE_PATH];
181 int glow;
182 int mesh_index;
183
184 int missile_type; /*!< The type of equipped missiles (>=0 if a quiver is equipped, -1 if a regular shield is equipped) */
185
186 }shield_part;
187
188 /*! Sets the weapon type (including animation frame names)*/
189 typedef struct
190 {
191 char model_name[MAX_FILE_PATH];
192 char skin_name[MAX_FILE_PATH];
193 char skin_mask[MAX_FILE_PATH];
194 int glow;
195 int mesh_index;
196 int turn_horse;
197 int unarmed;
198
199 struct cal_anim cal_frames[NUM_WEAPON_FRAMES];
200
201 }weapon_part;
202
203 /*! Defines the main models looks*/
204 typedef struct
205 {
206 char model_name[MAX_FILE_PATH];
207 char arms_name[MAX_FILE_PATH];
208 char torso_name[MAX_FILE_PATH];
209 char arms_mask[MAX_FILE_PATH];
210 char torso_mask[MAX_FILE_PATH];
211 int mesh_index;
212
213 }shirt_part;
214
215 /*! Sets the models hands and head*/
216 typedef struct
217 {
218 char hands_name[MAX_FILE_PATH];
219 char head_name[MAX_FILE_PATH];
220 char arms_name[MAX_FILE_PATH];
221 char body_name[MAX_FILE_PATH];
222 char legs_name[MAX_FILE_PATH];
223 char feet_name[MAX_FILE_PATH];
224 int mesh_index;
225
226 }skin_part;
227
228 /*! Sets the models hair name*/
229 typedef struct
230 {
231 char hair_name[MAX_FILE_PATH];
232 int mesh_index;
233
234 }hair_part;
235
236 /*! Sets the models eyes name*/
237 typedef struct
238 {
239 char eyes_name[MAX_FILE_PATH];
240 int mesh_index;
241
242 }eyes_part;
243
244 /*! Holds info about the boots */
245 typedef struct
246 {
247 char boots_name[MAX_FILE_PATH];
248 char model_name[MAX_FILE_PATH];
249 char boots_mask[MAX_FILE_PATH];
250 int glow;
251 int mesh_index;
252
253 }boots_part;
254
255 /*! Holds info about the legs type*/
256 typedef struct
257 {
258 char legs_name[MAX_FILE_PATH];
259 char model_name[MAX_FILE_PATH];
260 char legs_mask[MAX_FILE_PATH];
261 int glow;
262 int mesh_index;
263
264 }legs_part;
265
266 /*! A structure used when loading the actor definitions
267 * \sa init_actor_defs*/
268
269 typedef struct cal_anim_group
270 {
271 char name[32];
272 int count;
273 struct cal_anim anim[16];
274 } cal_animations;
275
276 #ifdef NEW_SOUND
277 typedef struct
278 {
279 int sound;
280 float scale;
281 } act_extra_sound;
282 #endif // NEW_SOUND
283
284 typedef struct
285 {
286 int is_holder; /*!< Specifies if this type of actor hold the actor to which it is attached or if he is held */
287 int parent_bone_id; /*!< The bone to use on the actor to which it is attached */
288 int local_bone_id; /*!< The bone to use on the actor that is attached */
289 float shift[3]; /*!< The shift to apply to the actor that is held */
290 struct cal_anim cal_frames[NUM_ATTACHED_ACTOR_FRAMES];
291 } attachment_props;
292
293 /*!
294 * Structure containing how an actor type is attached to all other actors types
295 */
296 typedef struct
297 {
298 attachment_props actor_type[MAX_ACTOR_DEFS]; /*!< Attachment properties for each kind of actor */
299 } attached_actors_types;
300
301 typedef enum {
302 ACTOR_HEAD_SIZE = 0,
303 ACTOR_SHIELD_SIZE,
304 ACTOR_CAPE_SIZE,
305 ACTOR_HELMET_SIZE,
306 ACTOR_WEAPON_SIZE,
307 ACTOR_SHIRT_SIZE,
308 ACTOR_SKIN_SIZE,
309 ACTOR_HAIR_SIZE,
310 ACTOR_BOOTS_SIZE,
311 ACTOR_LEGS_SIZE,
312 ACTOR_NECK_SIZE,
313 ACTOR_EYES_SIZE,
314 ACTOR_NUM_PARTS
315 } actor_parts_enum;
316
317 typedef struct
318 {
319 /*! \name Model data*/
320 /*! \{ */
321 int actor_type;
322 char actor_name[66];
323 char skin_name[MAX_FILE_PATH];
324 char file_name[256];
325 /*! \} */
326
327 float actor_scale;
328 float scale;
329 float mesh_scale;
330 float skel_scale;
331
332 struct CalCoreModel *coremodel;
333 struct CalHardwareModel* hardware_model;
334 GLuint vertex_buffer;
335 GLuint index_buffer;
336 GLenum index_type;
337 Uint32 index_size;
338 //Animation indexes
339 struct cal_anim_group idle_group[16];//16 animation groups
340 int group_count;
341
342 struct cal_anim cal_frames[NUM_ACTOR_FRAMES];
343 hash_table *emote_frames;
344
345 int skeleton_type;
346
347 #ifdef NEW_SOUND
348 // Extra sounds
349 act_extra_sound battlecry;
350 #endif // NEW_SOUND
351
352 /*! \name The different body parts (different head shapes, different armour/weapon shapes etc.)*/
353 /*! \{ */
354 body_part *head;
355 shield_part *shield;
356 body_part *cape;
357 body_part *helmet;
358 body_part *neck;
359 weapon_part *weapon;
360 /*! \} */
361
362 /*! \name Clothing*/
363 /*! \{ */
364 shirt_part *shirt;
365 skin_part *skin;
366 hair_part *hair;
367 eyes_part *eyes;
368 boots_part *boots;
369 legs_part *legs;
370 /*! \} */
371
372 /*! \name The current actors walk/run speeds*/
373 /*! \{ */
374 double walk_speed; // unused
375 double run_speed; // unused
376 char ghost;
377 /*! \} */
378
379 int step_duration;
380
381 } actor_types;
382
383 typedef struct
384 {
385 float aim_position[3]; /*!< Position of the target to aim at */
386 float fire_position[3]; /*!< Position of the target to fire at */
387 int aim_actor; /*!< Actor ID to aim at */
388 int fire_actor; /*!< Actor ID to fire at */
389 char shot_type; /*!< The type of the shot (0: normal, 1: missed, 2: critical) */
390 char reload; /*!< To tell if the char must reload after the next fire */
391 char state; /*!< The state of the action (0: aim needed, 1: aim done, 2: fire needed, 3: fire done) */
392 } range_action;
393
394 #define MY_HORSE(a) (actors_list[actors_list[a]->attached_actor])
395 #define MY_HORSE_ID(a) (actors_list[a]->attached_actor)
396 #define HAS_HORSE(a) ((MY_HORSE_ID(a)>=0)&&(MY_HORSE(a)->actor_id<0))
397 #define IS_HORSE(a) (actors_list[a]->attached_actor>=0&&actors_list[a]->actor_id<0)
398 #define ACTOR(a) (actors_list[a])
399 #define ACTOR_WEAPON(a) (&(actors_defs[ACTOR(a)->actor_type].weapon[ACTOR(a)->cur_weapon]))
400
401 #define HORSE_FIGHT_ROTATION 60
402 #define HORSE_RANGE_ROTATION 45
403 #define HORSE_FIGHT_TIME 180
404 void rotate_actor_and_horse(int id, int mul);
405
406
407
408 #define MAX_EMOTE_LEN 20
409 #define MAX_EMOTE_FRAME 8
410
411 #define EMOTE_SITTING 0
412 #define EMOTE_WALKING 1
413 #define EMOTE_RUNNING 2
414 #define EMOTE_STANDING 3
415
416 #define EMOTE_ACTOR_TYPES 13
417 #define EMOTE_TIMEOUT 2000
418 #define EMOTE_CMDS_HASH 100
419
420
421 #define EMOTE_BARE_L 2
422 #define EMOTE_BARE_R 4
423
424 //ugliest mapping functions ever :/
emote_actor_type(int actor_type)425 static __inline__ int emote_actor_type(int actor_type){
426 switch(actor_type){
427 case human_female: return 0;
428 case human_male: return 1;
429 case elf_female: return 2;
430 case elf_male: return 3;
431 case dwarf_female: return 4;
432 case dwarf_male: return 5;
433 case orchan_female: return 6;
434 case orchan_male: return 7;
435 case gnome_female: return 8;
436 case gnome_male: return 9;
437 case draegoni_female: return 10;
438 case draegoni_male: return 11;
439 default: return 12; //all other mobs
440 }
441 }
442
443
444 typedef struct _emote_frame {
445 int nframes;
446 int ids[MAX_EMOTE_FRAME];
447 struct _emote_frame *next;
448 } emote_frame;
449
450 typedef struct _emote_type
451 {
452 int id;
453 char barehanded;
454 unsigned char pose;
455 int timeout; //default 2 sec
456 emote_frame *anims[EMOTE_ACTOR_TYPES][4][2];
457 char name[20];
458 char desc[80];
459 } emote_data;
460
461
462 typedef struct _emote_anim {
463 Uint32 start_time;
464 Uint32 max_duration;
465 int nframes;
466 char active;
467 struct cal_anim frames[MAX_EMOTE_FRAME];
468 struct cal_anim idle;
469 emote_frame *flow;
470 } emote_anim;
471
472 typedef struct _emote_dict {
473 char command[MAX_EMOTE_LEN+1]; // The command to trigger the emote
474 emote_data *emote;
475 } emote_dict;
476
477 extern hash_table *emote_cmds; //used to search through emotes commands
478 extern hash_table *emotes; //used to store emotes
479
480
481 #define NO_EMOTE 0
482 #define SERVER_EMOTE 1
483 #define CLIENT_EMOTE 2
484 typedef struct _emote_command {
485 Uint32 create_time;
486 emote_data *emote;
487 char origin;
488 } emote_command;
489
490
491 #define MAX_EMOTE_QUEUE 20
492 #define EMOTE_MOTION(act) ((act->buffs & BUFF_DOUBLE_SPEED) ? (EMOTE_RUNNING):(EMOTE_WALKING))
493
494 /*! The main actor structure.*/
495 #define MAX_CMD_QUEUE 31
496 #define MAX_RANGE_ACTION_QUEUE 16
497 #define MAX_ITEM_CHANGES_QUEUE 16
498 typedef struct
499 {
500 /*! \name Misc.*/
501 /*! \{ */
502 int actor_id; /*!< The actor ID from the server*/
503 int actor_type; /*!< Specifies the type of actor (race, sex etc.)*/
504 /*! \} */
505
506 struct CalModel *calmodel;
507 struct cal_anim cur_anim;
508 emote_anim cur_emote; //current performed emote
509 emote_data *poses[4]; //current emote ids for idle states (standing, walking...)
510 emote_command emote_que[MAX_EMOTE_QUEUE+1]; /*!< Holds the queued emotes*/
511 unsigned int cur_emote_sound_cookie; /*!< The currently played emote sound*/
512
513 #ifdef MORE_EMOTES
514 int startIdle;
515 int endIdle;
516 int idleTime;
517 int idleDuration;
518 #endif
519
520 unsigned int cur_anim_sound_cookie; /*!< The currently played animation sound*/
521 struct cal_anim cur_idle_anims[16];
522 int IsOnIdle;
523 float anim_time;
524 Uint32 last_anim_update;
525 AABBOX bbox;
526
527 /*! \name Range mode parameters */
528 /*! \{ */
529 float cal_h_rot_start; /*!< The starting horizontal rotation */
530 float cal_h_rot_end; /*!< The ending horizontal rotation */
531 float cal_v_rot_start; /*!< The starting vertical rotation */
532 float cal_v_rot_end; /*!< The ending vertical rotation */
533 float cal_rotation_blend; /*!< The blend to applay between the starting and the ending rotations */
534 float cal_rotation_speed; /*!< The speed of the rotation */
535 int cal_last_rotation_time; /*!< The last time when the rotation has been updated */
536 char are_bones_rotating; /*!< To tell if the char is rotating */
537 char in_aim_mode; /*!< To tell if the char is already aiming something (0: not in aim mode; 1: in aim mode; 2: leaving aim mode) */
538 range_action range_actions[MAX_RANGE_ACTION_QUEUE]; /*!< Stores the actions to be done */
539 int range_actions_count; /*<! The number of actions stored */
540
541 int delayed_item_changes[MAX_ITEM_CHANGES_QUEUE]; /*!< Used to delay a sword/shield equip while in range mode (-1: item removed; >= 0: item equipped) */
542 int delayed_item_type_changes[MAX_ITEM_CHANGES_QUEUE]; /*!< Used to delay a sword/shield equip while in range mode */
543 int delayed_item_changes_count; /*!< The number of delayed items */
544 char delay_texture_item_changes; /*!< To tell if the item changes should get delayed */
545 /*! \} */
546
547 /*! \name Actors positions
548 * \brief Updated in the timer thread
549 */
550 /*! \{ */
551 double x_pos; /*!< Specifies the x position of the actor */
552 double y_pos; /*!< Specifies the y position of the actor */
553 double z_pos; /*!< Specifies the z position of the actor */
554 float scale; /*!< Specidies the custom scaling for the actor model */
555
556 int x_tile_pos; /*!< Specifies the x tile position - updated in the timer thread*/
557 int y_tile_pos; /*!< Specifies the y tile position - updated in the timer thread \n*/
558 /*! \} */
559
560 /*! \name Actor rotation*/
561 /*! \{ */
562 float x_rot; /*!< Sets the current x rotation*/
563 float y_rot; /*!< Sets the current y rotation*/
564 float z_rot; /*!< Sets the current z rotation*/
565 /*! \} */
566
567 float max_z;
568
569 /*! \name Actors worn item IDs*/
570 /*! \{ */
571 int boots; /*!< Sets the boots ID (loaded from the actor_defs array)*/
572 int hair; /*!< Sets the hair ID (loaded from the actor_defs array)*/
573 int eyes; /*!< Sets the eyes ID (loaded from the actor_defs array)*/
574 int skin; /*!< Sets the skin ID (loaded from the actor_defs array)*/
575 int pants; /*!< Sets the pants ID (loaded from the actor_defs array)*/
576 int shirt; /*!< Sets the shirt ID (loaded from the actor_defs array)*/
577 int cur_weapon; /*!< Sets the current weapon of the actor*/
578 int cur_shield; /*!< Sets the current shield of the actor*/
579 /*! \} */
580
581 /*! \{ */
582 int is_enhanced_model; /*!< Specifies if we have the enhanced_actor structure below*/
583 enhanced_actor *body_parts; /*!< A pointer to the enhanced actor extension (holds information about weapons, helmets etc)*/
584 /*! \} */
585
586 /*! \{ */
587 char remapped_colors; /*!< If the actors colours are remapped it will holds the texture in actor->texture_id*/
588 GLuint texture_id; /*!< Sets the texture ID, if the remapped_colors==1 - remember to glDeleteTextures*/
589 char skin_name[256]; /*!< Sets the skin name*/
590 char actor_name[ACTOR_DEF_NAME_SIZE]; /*!< Sets the actors name - holds the guild name as well after a special 127+color character*/
591 /*! \} */
592
593 /*! \name Command queue and current animations*/
594 /*! \{ */
595 actor_commands que[MAX_CMD_QUEUE+1]; /*!< Holds the current command queue*/
596 #ifdef ANIMATION_SCALING
597 float animation_scale; /*!< scale factor for animations */
598 #endif /* ANIMATION_SCALING */
599 char last_command; /*!< Holds the last command*/
600 char busy; /*!< if the actor is busy executing the current command*/
601 char sitting; /*!< Specifies if the actor is currently sitting*/
602 char fighting; /*!< Specifies if the actor is currently fighting*/
603 /*! \} */
604
605 /*!
606 * \name Movement
607 */
608 /*! \{ */
609 double move_x_speed; /*!< Sets the current movement speed in the x direction (used for updating the actor in the timer thread)*/
610 double move_y_speed; /*!< Sets the current movement speed in the y direction (used for updating the actor in the timer thread)*/
611 double move_z_speed; /*!< Sets the current movement speed in the z direction (used for updating the actor in the timer thread)*/
612 int movement_time_left; /*!< Specifies the time left for the actor movement before it goes in idle */
613 float rotate_x_speed; /*!< Sets the x rotation speed (used for updating the actor in the timer thread)*/
614 float rotate_y_speed; /*!< Sets the y rotation speed (used for updating the actor in the timer thread)*/
615 float rotate_z_speed; /*!< Sets the z rotation speed (used for updating the actor in the timer thread)*/
616 int rotate_time_left; /*!< Specifies the time left for the actor rotation before it goes in idle */
617 /*! \} */
618
619 /*! \name Misc. animations*/
620 /*! \{ */
621 char horse_rotated;
622 char moving; /*!< Specifies if the actor is currently on the move*/
623 char rotating; /*!< Specifies if the actor is currently rotating*/
624 char stop_animation; /*!< Don't loop trough the current animation (like for die, jump, etc.)*/
625 char stand_idle; /*!< Sets the actor in an idle stand position*/
626 char sit_idle; /*!< Sets the actor in an idle sit position*/
627 char dead; /*!< Used when the actor is dead (render the dead position)*/
628 int damage; /*!< Sets the damage the actor has been given*/
629 int damage_ms; /*!< Defines the remaining time in which the actor damage will be shown*/
630 int last_health_loss; /*!< Defines the time of damage*/
631 Uint16 cur_health; /*!< Sets the current health of the actor*/
632 Uint16 max_health; /*!< Sets the maximum health of the actor*/
633 char ghost; /*!< Sets the actor type to ghost (Disable lightning, enable blending (GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA))*/
634 char has_alpha; /*!< is alpha blending needed for this actor? */
635 int kind_of_actor; /*!< Defines the kind_of_actor (NPC, HUMAN, COMPUTER_CONTROLLED_HUMAN, PKABLE, PKABLE_COMPUTER_CONTROLLED)*/
636 Uint32 buffs; /*!< Contains the buffs on this actor as bits (currently only invisibility)*/
637 /*! \} */
638
639 /*! \name Overhead text (text bubbles)*/
640 /*! \{ */
641 char current_displayed_text[MAX_CURRENT_DISPLAYED_TEXT_LEN]; /*!< If the text is displayed in a bubble over the actor, this holds the text*/
642 int current_displayed_text_lines; /*!< The number of lines of text */
643 int current_displayed_text_time_left; /*!< Defines the remaining time the overhead text should be displayed*/
644 /*! \} */
645
646 /*! \name Unused variables*/
647 /*! \{ */
648 double x_speed; /*!< Unused?*/
649 double y_speed; /*!< Unused?*/
650 double z_speed; /*!< Unused?*/
651 /*! \} */
652
653 int async_fighting;
654 int async_x_tile_pos;
655 int async_y_tile_pos;
656 int async_z_rot;
657 int last_range_attacker_id;
658
659 int step_duration;
660
661 int attached_actor;
662 float attachment_shift[3];
663
664 #ifdef CLUSTER_INSIDES
665 short cluster;
666 #endif
667 ec_reference ec_buff_reference[NUM_BUFFS];
668 }actor;
669
670 #define DEFAULT_RENDER_PASS 0
671 #define REFLECTION_RENDER_PASS 1
672 #define DEPTH_RENDER_PASS 2
673 #define SHADOW_RENDER_PASS 3
674 #define SELECTION_RENDER_PASS 4
675
676 extern SDL_mutex *actors_lists_mutex; /*!< Used for locking between the timer and main threads*/
677 extern actor *actors_list[MAX_ACTORS]; /*!< A list holding all of the actors*/
678 extern actor *your_actor; /*!< A pointer to your own character, if available. Shares a mutex with \see actors_list */
679 extern int max_actors; /*!< The current number of actors in the actors_list + 1*/
680 extern actor_types actors_defs[MAX_ACTOR_DEFS]; /*!< The actor definitions*/
681
682 extern attached_actors_types attached_actors_defs[MAX_ACTOR_DEFS]; /*!< The definitions for the attached actors */
683
684
is_actor_barehanded(actor * act,int hand)685 static __inline__ int is_actor_barehanded(actor *act, int hand){
686 if(hand==EMOTE_BARE_L)
687 return (act->cur_shield==SHIELD_NONE||act->cur_shield==QUIVER_ARROWS||act->cur_shield==QUIVER_BOLTS);
688 else
689 return (act->cur_weapon==WEAPON_NONE||act->cur_weapon==GLOVE_FUR||act->cur_weapon==GLOVE_LEATHER);
690 }
691
692
693 /*!
694 * \ingroup display_actors
695 * \brief Draws the actors banner (healthbar, name, etc)
696 *
697 * This function is used for drawing the healthbar, the name, the damage, the healthpoints (cur/max) and the text bubbles
698 *
699 * \param actor_id Is a pointer to the actor we wish to draw
700 * \param offset_z Is the z offset, found by the current MD2 frames max_z.
701 *
702 * \callgraph
703 */
704 void draw_actor_banner(actor * actor_id, float offset_z);
705
706 /*!
707 * \ingroup display_actors
708 * \brief The main actor loop - draws all actors within range
709 *
710 * The function draws the actor if it's within a range of 12*12
711 *
712 * \callgraph
713 */
714 void display_actors(int banner, int render_pass);
715
716 void add_actor_attachment (int actor_id, int attachment_type);
717
718 void remove_actor_attachment (int actor_id);
719
720 /*!
721 * \ingroup network_actors
722 * \brief Adds an actor from the in_data
723 *
724 * Is called when the client gets an ADD_NEW_ACTOR command from the server. Parses the data pointed to by in_data, then adds the actor to the actors list
725 *
726 * \param in_data The data from the server
727 * \param len The length of the supplied data
728 *
729 * \callgraph
730 */
731 void add_actor_from_server (const char * in_data, int len);
732
733 /*!
734 * \ingroup display_actors
735 * \brief Inititates the actors_list (sets all pointers to NULL).
736 *
737 * Sets all actor pointers in the actors_list to NULL and creates the actors_list mutex.
738 *
739 * \sa actors_list
740 * \sa LOCK_ACTORS_LISTS
741 */
742 extern void init_actors_lists();
743
744 #ifdef MUTEX_DEBUG
745 extern SDL_threadID have_actors_lock;
746 /*!
747 * \ingroup mutex
748 * \name Actor list thread synchronization
749 */
750 /*! @{ */
751 #define LOCK_ACTORS_LISTS() \
752 {\
753 fprintf(stderr,"Last locked by: %s %s %d\n",__FILE__,__FUNCTION__,__LINE__);\
754 if(SDL_LockMutex(actors_lists_mutex)==-1) {fprintf(stderr,"The mutex on %s %s %d was not locked even though we asked it to!\n",__FILE__,__FUNCTION__,__LINE__); abort(); }\
755 assert(have_actors_lock==0); have_actors_lock=SDL_ThreadID(); \
756 }
757 #define UNLOCK_ACTORS_LISTS() \
758 {\
759 fprintf(stderr,"Last unlocked by: %s %s %d\n",__FILE__,__FUNCTION__,__LINE__);\
760 assert(have_actors_lock); assert(have_actors_lock==SDL_ThreadID()); have_actors_lock=0; \
761 if(SDL_UnlockMutex(actors_lists_mutex)==-1) {fprintf(stderr,"The mutex on %s %s %d was not unlocked even though we asked it to!\n",__FILE__,__FUNCTION__,__LINE__); abort(); }\
762 }
763 /*! @} */
764 #else
765 /*!
766 * \ingroup mutex
767 * \name Actor list thread synchronization
768 */
769 /*! @{ */
770 #define LOCK_ACTORS_LISTS() SDL_LockMutex(actors_lists_mutex)
771 #define UNLOCK_ACTORS_LISTS() SDL_UnlockMutex(actors_lists_mutex)
772 /*! @} */
773 #endif
774
775 /*!
776 * \ingroup network_text
777 * \brief Adds the text to the actor given by actor_ptr
778 *
779 * Adds text from the actor to overhead text.
780 *
781 * \param actor_ptr A pointer to the actor
782 * \param text The text we wish to add to the current_displayed_text buffer in the actors structure.
783 */
784 void add_displayed_text_to_actor( actor * actor_ptr, const char* text);
785
786 /*!
787 * \ingroup misc_utils
788 * \brief Gets a pointer to the actor given by the actor_id
789 *
790 * The function is used for getting a pointer to the actor with the given actor_id (the server-side actor id).
791 *
792 * \param actor_id The server-side actor_id - NOT the position in the actors_list
793 * \retval actor* A pointer to the actor with the given ID. If the actor is not found it returns NULL
794 * \sa get_our_actor
795 */
796 actor * get_actor_ptr_from_id( int actor_id );
797
798 void end_actors_lists(void);
799
800 int on_the_move (const actor *act);
801
802 /*!
803 * \ingroup display_actors
804 * \brief Return actor close clicked coords.
805 *
806 * \param tile_x the x coord of the clicked tile
807 * \param tile_y the y coord of the clicked tile
808 * \param max_distance the maximum distance between the clicked coord and the actor
809 *
810 * \callgraph
811 * \retval the actor id or -1 for no actor
812 *
813 */
814 int get_closest_actor(int tile_x, int tile_y, float max_distance);
815
816 /*!
817 * \ingroup display_actors
818 * \brief Return a pointer to your own character, if available
819 *
820 * Return a pointer to your own character, if available. This inline
821 * function simply returns \ref your_actor.
822 *
823 * \return A pointer to your character, or NULL if that is not available.
824 */
get_our_actor()825 static __inline__ actor *get_our_actor ()
826 {
827 return your_actor;
828 }
829
830 /*!
831 * \ingroup display_actors
832 * \brief Set the pointer to your own character
833 *
834 * Set the pointer to your own character to \a act.
835 *
836 * \param act New pointer to your character.
837 */
set_our_actor(actor * act)838 static __inline__ void set_our_actor (actor *act)
839 {
840 your_actor = act;
841 }
842
843 /*!
844 * \brief Get the Z position of an actor according to its position on the height map
845 * \param a the actor
846 * \return the Z position of the actor
847 */
get_actor_z(actor * a)848 static __inline__ float get_actor_z(actor *a)
849 {
850 return get_tile_height(a->x_tile_pos, a->y_tile_pos);
851 }
852
853 /*!
854 * \brief Get the scale factor of an actor
855 * \param a the actor
856 * \return the scale factor of the actor
857 */
get_actor_scale(actor * a)858 static __inline__ float get_actor_scale(actor *a)
859 {
860 float scale = a->scale;
861 scale *= actors_defs[a->actor_type].actor_scale;
862 return scale;
863 }
864
865 /*!
866 * \brief Computes the rotation matrix of an actor
867 * \param in_act the actor
868 * \param out_rot the resulting matrix (3x3 matrix: 9 floats)
869 */
870 void get_actor_rotation_matrix(actor *in_act, float *out_rot);
871
872 /*!
873 * \brief Transforms a local position on a char to an absolute position
874 * \param in_act the actor
875 * \param in_local_pos the local position
876 * \param in_act_rot the rotation matrix of the actor (computed inside if NULL)
877 * \param out_pos the resulting position
878 */
879 void transform_actor_local_position_to_absolute(actor *in_act, float *in_local_pos, float *in_act_rot, float *out_pos);
880
881 void draw_actor_without_banner(actor * actor_id, Uint32 use_lightning, Uint32 use_textures, Uint32 use_glow);
882
883 /*!
884 * \brief Remember this last summoned creature.
885 *
886 * \param summoned_name The name of the summoned creature
887 */
888 void remember_new_summoned(const char *summoned_name);
889
890 /*!
891 * \brief Check if a new actor is the last summoned by the player. The actor mutex must be already held.
892 *
893 * \param new_actor Pointer to the new actor
894 */
895 void check_if_new_actor_last_summoned(actor *new_actor);
896
897 /*!
898 * \brief Get the actor ID of the last summoned creature
899 *
900 * \return The id or -1 of none remembered or no longer present.
901 */
902 int get_id_last_summoned(void);
903
is_actor_held(actor * act)904 static __inline__ int is_actor_held(actor *act)
905 {
906 return ((act->attached_actor >= 0) &&
907 ((act->actor_id < 0 && // the actor is the attachment
908 !attached_actors_defs[act->actor_type].actor_type[actors_list[act->attached_actor]->actor_type].is_holder) ||
909 (act->actor_id >= 0 && // the actor is the parent of the attachment
910 attached_actors_defs[actors_list[act->attached_actor]->actor_type].actor_type[act->actor_type].is_holder)));
911 }
912
get_attachment_props_if_held(actor * act)913 static __inline__ attachment_props* get_attachment_props_if_held(actor *act)
914 {
915 if (act->attached_actor < 0)
916 return NULL;
917 else if (act->actor_id < 0 && // the actor is the attachment
918 !attached_actors_defs[act->actor_type].actor_type[actors_list[act->attached_actor]->actor_type].is_holder)
919 return &attached_actors_defs[act->actor_type].actor_type[actors_list[act->attached_actor]->actor_type];
920 else if (act->actor_id >= 0 && // the actor is the parent of the attachment
921 attached_actors_defs[actors_list[act->attached_actor]->actor_type].actor_type[act->actor_type].is_holder)
922 return &attached_actors_defs[actors_list[act->attached_actor]->actor_type].actor_type[act->actor_type];
923 else
924 return NULL;
925 }
926
get_held_actor_motion_frame(actor * act)927 static __inline__ int get_held_actor_motion_frame(actor *act)
928 {
929 if (act->attached_actor < 0)
930 return cal_attached_walk_frame;
931 else if (actors_list[act->attached_actor]->buffs & BUFF_DOUBLE_SPEED)
932 return cal_attached_run_frame;
933 else
934 return cal_attached_walk_frame;
935 }
936
get_actor_motion_frame(actor * act)937 static __inline__ int get_actor_motion_frame(actor *act)
938 {
939 return act->buffs & BUFF_DOUBLE_SPEED ? cal_actor_run_frame : cal_actor_walk_frame;
940 }
941
942 #ifdef __cplusplus
943 } // extern "C"
944 #endif
945
946 #endif // __ACTORS_H__
947