forked from raduprv/Eternal-Lands
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathactors.h
569 lines (504 loc) · 17.6 KB
/
actors.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
/*!
* \file
* \ingroup display
* \brief This file holds information about actors appearance etc. used for displaying the actors.
*/
#ifndef __ACTORS_H__
#define __ACTORS_H__
extern int yourself; /*!< This variable holds the actor_id (as the server sees it, not the position in the actors_list) of your character.*/
extern int you_sit; /*!< Specifies if you are currently sitting down.*/
extern int sit_lock; /*!< The sit_lock variable holds you in a sitting position.*/
extern float name_zoom; /*!< The name_zoom defines how large the text used for drawing the names should be*/
/*!
* \name Actor types
* Defines the colour of the name.
*/
/*! \{ */
#define HUMAN 1 /*!< Draw the actors name in white*/
#define NPC 2 /*!< Draw the actors name in blue*/
#define COMPUTER_CONTROLLED_HUMAN 3 /*!< Draw the actors name in white*/
#define PKABLE_HUMAN 4 /*!< Draw the actors name in red*/
#define PKABLE_COMPUTER_CONTROLLED 5 /*!< Draw the actors name in red*/
/*! \} */
/*! Max text len to display into bubbles overhead*/
#define MAX_CURRENT_DISPLAYED_TEXT_LEN 60
/*!
* \name Glow colours
* The colours used for giving the items a glowing halo
*/
/*! \{ */
/*! The colours used in the glowing swords (magic, thermal, ice, fire)*/
typedef struct
{
float r; /*!< Red (0<=r<=1)*/
float g; /*!< Green (0<=g<=1)*/
float b; /*!< Blue (0<=b<=1)*/
}glow_color;
//GLOWS
#define GLOW_NONE 0 /*!< RGB: 0.0, 0.0, 0.0*/
#define GLOW_FIRE 1 /*!< RGB: 0.5, 0.1, 0.1*/
#define GLOW_COLD 2 /*!< RGB: 0.1, 0.1, 0.5*/
#define GLOW_THERMAL 3 /*!< RGB: 0.5, 0.1, 0.5*/
#define GLOW_MAGIC 4 /*!< RGB: 0.5, 0.4, 0.0*/
extern glow_color glow_colors[10]; /*!< Holds the glow colours defined in GLOW_**/
/*! \} */
/*!
* The near_actor structure holds information about the actors within range. It is filled once every frame.
*/
struct near_actor {
int actor;//offset in the actors_list
int dist;//distance from our actor
int ghost;//If it's a ghost or not
};
extern int no_near_actors;
extern struct near_actor near_actors[1000];
/*!
* The enhanced actor structure holds information about the actors md2 extensions such as if the actor is wearing any armour, weapons etc.
*/
typedef struct
{
#ifdef CUSTOM_LOOK
int uniq_id;
int guild_id;
#endif
int legs_meshindex;
int head_meshindex;
int torso_meshindex;
int weapon_meshindex;
int shield_meshindex;
int helmet_meshindex;
int cape_meshindex;
/*! \name The extended md2s (for more complex models that can carry and remove weapons, armour etc.)*/
/*! \{ */
//md2 *legs;
//md2 *head;
//md2 *torso;
//md2 *weapon;
//md2 *shield;
//md2 *helmet;
//md2 *cape;
/*! \} */
/*! \name The texture names*/
/*! \{ */
char pants_tex[256];
char boots_tex[256];
char torso_tex[256];
char arms_tex[256];
char hands_tex[256];
char head_tex[256];
char hair_tex[256];
char weapon_tex[256];
char shield_tex[256];
char helmet_tex[256];
char cape_tex[256];
char hands_tex_save[256];
/*! \} */
/*! \name Specifies the glow of each worn item*/
/*! \{ */
int weapon_glow;
int shield_glow;
int helmet_glow;
int cape_glow;
int legs_glow;
/*! \} */
}enhanced_actor;
/*! Sets the main model type*/
typedef struct
{
char model_name[256];
char skin_name[256];
int glow;
int mesh_index;
}body_part;
/*! Sets the weapon type (including animation frame names)*/
typedef struct
{
char model_name[256];
char skin_name[256];
int glow;
int mesh_index;
struct cal_anim cal_attack_up_1_frame;
struct cal_anim cal_attack_up_2_frame;
struct cal_anim cal_attack_down_1_frame;
struct cal_anim cal_attack_down_2_frame;
}weapon_part;
/*! Defines the main models looks*/
typedef struct
{
char model_name[256];
char arms_name[256];
char torso_name[256];
int mesh_index;
}shirt_part;
/*! Sets the models hands and head*/
typedef struct
{
char hands_name[256];
char head_name[256];
int mesh_index;
}skin_part;
/*! Sets the models hair name*/
typedef struct
{
char hair_name[256];
int mesh_index;
}hair_part;
/*! Holds info about the boots md2*/
typedef struct
{
char boots_name[256];
int glow;
int mesh_index;
}boots_part;
/*! Holds info about the legs type*/
typedef struct
{
char legs_name[256];
char model_name[256];
int glow;
int mesh_index;
}legs_part;
/*! A structure used when loading the actor definitions
* \sa init_actor_defs*/
typedef struct cal_anim_group
{
char name[32];
int count;
struct cal_anim anim[16];
} wtf_is_this;
typedef struct
{
/*! \name Model data*/
/*! \{ */
char skin_name[256];
char file_name[256];
/*! \} */
float scale;
float mesh_scale;
float skel_scale;
char skeleton_name[256];
struct CalCoreModel *coremodel;
//Animation indexes
struct cal_anim_group idle_group[16];//16 animation groups
int group_count;
struct cal_anim cal_walk_frame;
struct cal_anim cal_run_frame;
struct cal_anim cal_die1_frame;
struct cal_anim cal_die2_frame;
struct cal_anim cal_pain1_frame;
struct cal_anim cal_pain2_frame;
struct cal_anim cal_pick_frame;
struct cal_anim cal_drop_frame;
struct cal_anim cal_idle1_frame;
struct cal_anim cal_idle2_frame;
struct cal_anim cal_idle_sit_frame;
struct cal_anim cal_harvest_frame;
struct cal_anim cal_attack_cast_frame;
struct cal_anim cal_attack_ranged_frame;
struct cal_anim cal_sit_down_frame;
struct cal_anim cal_stand_up_frame;
struct cal_anim cal_in_combat_frame;
struct cal_anim cal_out_combat_frame;
struct cal_anim cal_combat_idle_frame;
struct cal_anim cal_attack_up_1_frame;
struct cal_anim cal_attack_up_2_frame;
struct cal_anim cal_attack_up_3_frame;
struct cal_anim cal_attack_up_4_frame;
struct cal_anim cal_attack_down_1_frame;
struct cal_anim cal_attack_down_2_frame;
/*! \name The different body parts (different head shapes, different armour/weapon shapes etc.)*/
/*! \{ */
body_part head[5];
body_part shield[10];
body_part cape[20];
body_part helmet[20];
weapon_part weapon[80];
/*! \} */
/*! \name Clothing*/
/*! \{ */
shirt_part shirt[22];
skin_part skin[4];
hair_part hair[9];
boots_part boots[20];
legs_part legs[16];
/*! \} */
/*! \name The current actors walk/run speeds*/
/*! \{ */
double walk_speed;
double run_speed;
char ghost;
/*! \} */
} actor_types;
/*!
* This structure holds data that is frequently accessed by both the timer and render thread. On each new frame the data is copied from the actor structure, partly to prevent timing issues, partly to make sure that the same picture is rendered throughout all frames in the scene.
*/
typedef struct
{
int have_tmp; /*!< Specifies if the temporary structure is ready*/
/*! \name Actor positions*/
/*! \{ */
double x_pos; /*!< The actors x position*/
double y_pos; /*!< The actors y position*/
double z_pos; /*!< The actors z position*/
/*! \} */
/*! \name Actors tile position*/
/*! \{ */
short x_tile_pos; /*!< The actors x tile position - i.e. used for getting the heightmap from the map file at the actors position*/
short y_tile_pos; /*!< The actors y tile position - i.e. used for getting the heightmap from the map file at the actors position*/
/*! \} */
/*! \name Actors rotation*/
/*! \{ */
float x_rot; /*!< The actors x rotation...*/
float y_rot; /*!< The actors y rotation.*/
float z_rot; /*!< The actors z position*/
/*! \} */
} tmp_actor_data;
/*! The main actor structure.*/
#define MAX_CMD_QUEUE 20
typedef struct
{
/*! \name Misc.*/
/*! \{ */
int actor_id; /*!< The actor ID from the server*/
int actor_type; /*!< Specifies the type of actor (race, sex etc.)*/
tmp_actor_data tmp; /*!< The actors temporary data used for rendering*/
/*! \} */
struct CalModel *calmodel;
struct cal_anim cur_anim;
struct cal_anim cur_idle_anims[16];
int IsOnIdle;
float anim_time;
/*! \name Actors positions
* \brief Updated in the timer thread
*/
/*! \{ */
double x_pos; /*!< Specifies the x position of the actor */
double y_pos; /*!< Specifies the y position of the actor */
double z_pos; /*!< Specifies the z position of the actor */
int x_tile_pos; /*!< Specifies the x tile position - updated in the timer thread*/
int y_tile_pos; /*!< Specifies the y tile position - updated in the timer thread \n*/
/*! \} */
/*! \name Actor rotation*/
/*! \{ */
float x_rot; /*!< Sets the current x rotation*/
float y_rot; /*!< Sets the current y rotation*/
float z_rot; /*!< Sets the current z rotation*/
/*! \} */
/*! \name Actors worn item IDs*/
/*! \{ */
int boots; /*!< Sets the boots ID (loaded from the actor_defs array)*/
int hair; /*!< Sets the hair ID (loaded from the actor_defs array)*/
int skin; /*!< Sets the skin ID (loaded from the actor_defs array)*/
int pants; /*!< Sets the pants ID (loaded from the actor_defs array)*/
int shirt; /*!< Sets the shirt ID (loaded from the actor_defs array)*/
int cur_weapon; /*!< Sets the current weapon of the actor*/
int cur_shield; /*!< Sets the current shield of the actor*/
/*! \} */
/*! \{ */
int is_enhanced_model; /*!< Specifies if we have the enhanced_actor structure below*/
enhanced_actor *body_parts; /*!< A pointer to the enhanced actor extension (holds information about weapons, helmets etc)*/
/*! \} */
/*! \{ */
//md2 *model_data; /*!< Is a pointer to the md2 model data loaded when the actor was first added*/
char remapped_colors; /*!< If the actors colours are remapped it will holds the texture in actor->texture_id*/
int texture_id; /*!< Sets the texture ID, if the remapped_colors==1 - remember to glDeleteTextures*/
char skin_name[256]; /*!< Sets the skin name*/
char actor_name[256]; /*!< Sets the actors name - holds the guild name as well after a special 127+color character*/
/*! \} */
/*! \name Command queue and current animations*/
/*! \{ */
char que[MAX_CMD_QUEUE+1]; /*!< Holds the current command queue*/
char last_command; /*!< Holds the last command*/
char busy; /*!< if the actor is busy executing the current command*/
char sitting; /*!< Specifies if the actor is currently sitting*/
char fighting; /*!< Specifies if the actor is currently fighting*/
/*! \} */
/*!
* \name Movement
*/
/*! \{ */
double move_x_speed; /*!< Sets the current movement speed in the x direction (used for updating the actor in the timer thread)*/
double move_y_speed; /*!< Sets the current movement speed in the y direction (used for updating the actor in the timer thread)*/
double move_z_speed; /*!< Sets the current movement speed in the z direction (used for updating the actor in the timer thread)*/
int movement_frames_left; /*!< Specifies how many movement frames the actor has to do before it goes idle*/
float rotate_x_speed; /*!< Sets the x rotation speed (used for updating the actor in the timer thread)*/
float rotate_y_speed; /*!< Sets the y rotation speed (used for updating the actor in the timer thread)*/
float rotate_z_speed; /*!< Sets the z rotation speed (used for updating the actor in the timer thread)*/
int rotate_frames_left; /*!< Specifies how many rotation frames it needs to do*/
int after_move_frames_left; /*!< When the actor is done moving, it does a small animation before idleing - specifies how many frames it needs to render of that animation*/
/*! \} */
/*! \name Misc. animations*/
/*! \{ */
char moving; /*!< Specifies if the actor is currently on the move*/
char rotating; /*!< Specifies if the actor is currently rotating*/
char stop_animation; /*!< Don't loop trough the current animation (like for die, jump, etc.)*/
char stand_idle; /*!< Sets the actor in an idle stand position*/
char sit_idle; /*!< Sets the actor in an idle sit position*/
char dead; /*!< Used when the actor is dead (render the dead position)*/
int damage; /*!< Sets the damage the actor has been given*/
int damage_ms; /*!< Defines the remaining time in which the actor damage will be shown*/
int last_health_loss; /*!< Defines the time of damage*/
int cur_health; /*!< Sets the current health of the actor*/
int max_health; /*!< Sets the maximum health of the actor*/
char ghost; /*!< Sets the actor type to ghost (Disable lightning, enable blending (GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA))*/
int kind_of_actor; /*!< Defines the kind_of_actor (NPC, HUMAN, COMPUTER_CONTROLLED_HUMAN, PKABLE, PKABLE_COMPUTER_CONTROLLED)*/
/*! \} */
/*! \name Overhead text (text bubbles)*/
/*! \{ */
char current_displayed_text[MAX_CURRENT_DISPLAYED_TEXT_LEN]; /*!< If the text is displayed in a bubble over the actor, this holds the text*/
int current_displayed_text_time_left; /*!< Defines the remaining time the overhead text should be displayed*/
/*! \} */
/*! \name Unused variables*/
/*! \{ */
double x_speed; /*!< Unused?*/
double y_speed; /*!< Unused?*/
double z_speed; /*!< Unused?*/
/*! \} */
}actor;
extern SDL_mutex *actors_lists_mutex; /*!< Used for locking between the timer and main threads*/
extern actor *actors_list[1000]; /*!< A list holding all of the actors*/
extern actor *your_actor; /*!< A pointer to your own character, if available. Shares a mutex with \see actors_list */
extern int max_actors; /*!< The current number of actors in the actors_list + 1*/
extern actor_types actors_defs[100]; /*!< The actor definitions*/
/*!
* \ingroup display_actors
* \brief Gets the frame number in the md2 file from the current frame
*
* Gets the frame number in the md2 file from the current frame - called when displaying the given actor.
*
* \param model_data The MD2 model data, we wish to find the position of the cur_frame in
* \param cur_frame The name of the current frame.
* \retval int Returns the position of the frame on succes, -1 on failure (if the given frame was not found)
*/
//int get_frame_number(const md2 *model_data, const char *cur_frame);
/*!
* \ingroup display_actors
* \brief Draws the actors banner (healthbar, name, etc)
*
* This function is used for drawing the healthbar, the name, the damage, the healthpoints (cur/max) and the text bubbles
*
* \param actor_id Is a pointer to the actor we wish to draw
* \param offset_z Is the z offset, found by the current MD2 frames max_z.
*
* \callgraph
*/
void draw_actor_banner(actor * actor_id, float offset_z);
/*!
* \ingroup display_actors
* \brief Draws a halo around the md2 with the colours given by r g b
*
* Draws a halo around the model given by the md2 pointer and the cur_frame. The r g b values define what colour the halo will be
*
* \param model_data A pointer to the md2 model data
* \param cur_frame The current frame in the model_data
* \param r (0<=r<=1)
* \param g (0<=g<=1)
* \param b (0<=b<=1)
*
* \callgraph
*/
//void draw_model_halo(md2 *model_data,char *cur_frame, float r, float g, float b);
/*!
* \ingroup display_actors
* \brief Draws the model from the data given by the md2*
*
* Draws the cur_frame of the md2 model pointed to with model_data. The ghost parameter is not used yet.
*
* \param model_data A pointer to the md2 model
* \param cur_frame The current frame
* \param ghost Whether the model is a "ghost" or not
*
* \callgraph
*/
//void draw_model(md2 *model_data,char *cur_frame, int ghost);
/*!
* \ingroup display_actors
* \brief The main actor loop - draws all actors within range
*
* The function draws the actor if it's within a range of 12*12
*
* \callgraph
*/
void display_actors();
/*!
* \ingroup network_actors
* \brief Adds an actor from the in_data
*
* 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
*
* \param in_data The data from the server
*
* \callgraph
*/
void add_actor_from_server(char * in_data);
//void draw_interface_body_part(md2 *model_data);
/*!
* \ingroup display_actors
* \brief Inititates the actors_list (sets all pointers to NULL).
*
* Sets all actor pointers in the actors_list to NULL and creates the actors_list mutex.
*
* \sa actors_list
* \sa LOCK_ACTORS_LISTS
*/
extern void init_actors_lists();
#ifdef MUTEX_DEBUG
/*!
* \ingroup mutex
* \name Actor list thread synchronization
*/
/*! @{ */
#define LOCK_ACTORS_LISTS() \
{\
fprintf(stderr,"Last locked by: %s %s %d\n",__FILE__,__FUNCTION__,__LINE__);\
if(SDL_LockMutex(actors_lists_mutex)==-1)fprintf(stderr,"We're fucked!! The mutex on %s %s %d was not locked even though we asked it to!\n",__FILE__,__FUNCTION__,__LINE__);\
}
#define UNLOCK_ACTORS_LISTS() \
{\
fprintf(stderr,"Last unlocked by: %s %s %d\n",__FILE__,__FUNCTION__,__LINE__);\
if(SDL_UnlockMutex(actors_lists_mutex)==-1)fprintf(stderr,"We're fucked!! The mutex on %s %s %d was not unlocked even though we asked it to!\n",__FILE__,__FUNCTION__,__LINE__);\
}
/*! @} */
#else
/*!
* \ingroup mutex
* \name Actor list thread synchronization
*/
/*! @{ */
#define LOCK_ACTORS_LISTS() SDL_LockMutex(actors_lists_mutex)
#define UNLOCK_ACTORS_LISTS() SDL_UnlockMutex(actors_lists_mutex)
/*! @} */
#endif
/*!
* \ingroup network_text
* \brief Adds the text to the actor given by actor_ptr
*
* Adds text from the actor to overhead text.
*
* \param actor_ptr A pointer to the actor
* \param text The text we wish to add to the current_displayed_text buffer in the actors structure.
*/
void add_displayed_text_to_actor( actor * actor_ptr, const char* text );
/*!
* \ingroup misc_utils
* \brief Gets a pointer to the actor given by the actor_id
*
* The function is used for getting a pointer to the actor with the given actor_id (the server-side actor id).
*
* \param actor_id The server-side actor_id - NOT the position in the actors_list
* \retval actor* A pointer to the actor with the given ID. If the actor is not found it returns NULL
* \sa pf_get_our_actor
*/
actor * get_actor_ptr_from_id( int actor_id );
/*!
* \ingroup display_actors
* \brief Gets the max Z of the given actor
*
* Gets the max Z of the given actor.
*
* \param act A pointer to the actor
* \retval float The max Z
*/
float cal_get_maxz2(actor *act);
void end_actors_lists(void);
#endif