forked from raduprv/Eternal-Lands
-
Notifications
You must be signed in to change notification settings - Fork 0
/
actors.c
1744 lines (1506 loc) · 50.4 KB
/
actors.c
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
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <SDL.h>
#include "actors.h"
#include "actor_scripts.h"
#include "asc.h"
#include "bbox_tree.h"
#include "buffs.h"
#include "cal.h"
#include "cursors.h"
#include "draw_scene.h"
#include "errors.h"
#include "gl_init.h"
#include "global.h"
#include "interface.h"
#include "load_gl_extensions.h"
#include "map.h"
#include "missiles.h"
#include "new_actors.h"
#include "platform.h"
#include "shadows.h"
#include "textures.h"
#include "translate.h"
#include "vmath.h"
#ifdef CLUSTER_INSIDES
#include "cluster.h"
#endif
#include "eye_candy_wrapper.h"
#include "minimap.h"
#include "actor_init.h"
#ifdef FSAA
#include "fsaa/fsaa.h"
#endif /* FSAA */
#ifdef ELC
#define DRAW_ORTHO_INGAME_NORMAL(x, y, z, our_string, max_lines) draw_ortho_ingame_string(x, y, z, (const Uint8*)our_string, max_lines, INGAME_FONT_X_LEN*10.0, INGAME_FONT_Y_LEN*10.0)
#define DRAW_INGAME_NORMAL(x, y, our_string, max_lines) draw_ingame_string(x, y, (const Uint8*)our_string, max_lines, INGAME_FONT_X_LEN, INGAME_FONT_Y_LEN)
#define DRAW_INGAME_SMALL(x, y, our_string, max_lines) draw_ingame_string(x, y, (const Uint8*)our_string, max_lines, SMALL_INGAME_FONT_X_LEN, SMALL_INGAME_FONT_Y_LEN)
#define DRAW_INGAME_ALT(x, y, our_string, max_lines) draw_ingame_string(x, y, (const Uint8*)our_string, max_lines, ALT_INGAME_FONT_X_LEN, ALT_INGAME_FONT_Y_LEN)
#endif
actor *actors_list[MAX_ACTORS];
int max_actors=0;
SDL_mutex *actors_lists_mutex = NULL; //used for locking between the timer and main threads
actor *your_actor = NULL;
actor_types actors_defs[MAX_ACTOR_DEFS];
attached_actors_types attached_actors_defs[MAX_ACTOR_DEFS];
void draw_actor_overtext( actor* actor_ptr ); /* forward declaration */
int no_near_actors=0;
#ifdef NEW_SOUND
int no_near_enhanced_actors = 0;
float distanceSq_to_near_enhanced_actors;
#endif // NEW_SOUND
near_actor near_actors[MAX_ACTORS];
#ifdef MUTEX_DEBUG
Uint32 have_actors_lock = 0;
#endif
int cm_mouse_over_banner = 0; /* use to trigger banner context menu */
//Threading support for actors_lists
void init_actors_lists()
{
int i;
actors_lists_mutex=SDL_CreateMutex();
LOCK_ACTORS_LISTS(); //lock it to avoid timing issues
for (i=0; i < MAX_ACTORS; i++)
actors_list[i] = NULL;
UNLOCK_ACTORS_LISTS(); // release now that we are done
}
//return the ID (number in the actors_list[]) of the new allocated actor
int add_actor (int actor_type, char * skin_name, float x_pos, float y_pos, float z_pos, float z_rot, float scale, char remappable, short skin_color, short hair_color, short eyes_color, short shirt_color, short pants_color, short boots_color, int actor_id)
{
int texture_id;
int i;
int k;
actor *our_actor;
#ifdef CLUSTER_INSIDES
int x, y;
#endif
#ifdef EXTRA_DEBUG
ERR();
#endif
#ifdef NEW_TEXTURES
if (actors_defs[actor_type].ghost)
{
texture_id = load_texture_cached(skin_name, tt_mesh);
}
else
{
if (!remappable)
{
texture_id = load_texture_cached(skin_name, tt_mesh);
}
else
{
LOG_ERROR("remapped skin for %s", skin_name);
exit(-1);
}
}
#else /* NEW_TEXTURES */
if(actors_defs[actor_type].ghost) texture_id= load_texture_cache_deferred(skin_name, 150);
else if(!remappable)texture_id= load_texture_cache_deferred(skin_name, -1);
else
{
LOG_ERROR("remapped skin for %s", skin_name);
//texture_id=load_bmp8_remapped_skin(skin_name,150,skin_color,hair_color,eyes_color,shirt_color,pants_color,boots_color);
exit(-1);
}
#endif /* NEW_TEXTURES */
our_actor = calloc(1, sizeof(actor));
memset(our_actor->current_displayed_text, 0, MAX_CURRENT_DISPLAYED_TEXT_LEN);
our_actor->current_displayed_text_time_left = 0;
our_actor->is_enhanced_model=0;
our_actor->remapped_colors=remappable;
our_actor->actor_id=actor_id;
our_actor->cur_anim_sound_cookie = 0;
our_actor->cal_h_rot_start = 0.0;
our_actor->cal_h_rot_end = 0.0;
our_actor->cal_v_rot_start = 0.0;
our_actor->cal_v_rot_end = 0.0;
our_actor->cal_rotation_blend = -1.0;
our_actor->cal_rotation_speed = 0.0;
our_actor->are_bones_rotating = 0;
our_actor->in_aim_mode = 0;
our_actor->range_actions_count = 0;
our_actor->delayed_item_changes_count = 0;
our_actor->x_pos=x_pos;
our_actor->y_pos=y_pos;
our_actor->z_pos=z_pos;
our_actor->scale=scale;
our_actor->x_speed=0;
our_actor->y_speed=0;
our_actor->z_speed=0;
our_actor->x_rot=0;
our_actor->y_rot=0;
our_actor->z_rot=z_rot;
our_actor->last_range_attacker_id = -1;
//reset the script related things
our_actor->move_x_speed=0;
our_actor->move_y_speed=0;
our_actor->move_z_speed=0;
our_actor->rotate_x_speed=0;
our_actor->rotate_y_speed=0;
our_actor->rotate_z_speed=0;
our_actor->movement_time_left=0;
our_actor->moving=0;
our_actor->rotating=0;
our_actor->busy=0;
our_actor->last_command=nothing;
#ifdef ANIMATION_SCALING
our_actor->animation_scale = 1.0f;
#endif /* ANIMATION_SCALING*/
/* load the texture in case it's not already loaded and look if it has
* an alpha map */
#ifdef NEW_TEXTURES
our_actor->has_alpha = get_texture_alpha(texture_id);
#else
get_texture_id(texture_id);
our_actor->has_alpha=texture_cache[texture_id].has_alpha;
#endif
//clear the que
for(k=0;k<MAX_CMD_QUEUE;k++) our_actor->que[k]=nothing;
//clear emotes
for(k=0;k<MAX_EMOTE_QUEUE;k++) {
our_actor->emote_que[k].emote=NULL;
our_actor->emote_que[k].origin=NO_EMOTE;
our_actor->emote_que[k].create_time=0;
}
memset(&our_actor->cur_emote,0,sizeof(emote_anim));
memset(&our_actor->poses,0,sizeof(emote_data*)*4);
for(k=0;k<MAX_EMOTE_FRAME;k++) our_actor->cur_emote.frames[k].anim_index=-1;
our_actor->cur_emote.idle.anim_index=-1;
our_actor->cur_emote_sound_cookie=0;
our_actor->texture_id=texture_id;
our_actor->skin=skin_color;
our_actor->hair=hair_color;
our_actor->eyes=eyes_color;
our_actor->pants=pants_color;
our_actor->boots=boots_color;
our_actor->shirt=shirt_color;
our_actor->stand_idle=0;
our_actor->sit_idle=0;
our_actor->attached_actor = -1;
our_actor->attachment_shift[0] = our_actor->attachment_shift[1] = our_actor->attachment_shift[2] = 0.0;
for (i = 0; i < NUM_BUFFS; i++)
{
our_actor->ec_buff_reference[i] = NULL;
}
#ifdef CLUSTER_INSIDES
x = (int) (our_actor->x_pos / 0.5f);
y = (int) (our_actor->y_pos / 0.5f);
our_actor->cluster = get_cluster (x, y);
#endif
//find a free spot, in the actors_list
LOCK_ACTORS_LISTS();
for(i=0;i<max_actors;i++)
{
if(!actors_list[i])break;
}
if(actor_id == yourself)
set_our_actor (our_actor);
actors_list[i]=our_actor;
if(i>=max_actors)max_actors=i+1;
//It's unlocked later
ec_add_actor_obstruction(our_actor, 3.0);
return i;
}
void add_actor_attachment(int actor_id, int attachment_type)
{
int i;
actor *parent = NULL;
for (i = 0; i < max_actors; ++i)
if (actors_list[i]->actor_id == actor_id)
{
parent = actors_list[i];
break;
}
if (!parent)
LOG_ERROR("unable to add an attached actor: actor with id %d doesn't exist!", actor_id);
else if(attachment_type < 0 || attachment_type >= MAX_ACTOR_DEFS || (attachment_type > 0 && actors_defs[attachment_type].actor_type != attachment_type) )
LOG_ERROR("unable to add an attached actor: illegal/missing actor definition %d", attachment_type);
else
{
int id = add_actor(attachment_type, actors_defs[attachment_type].skin_name,
parent->x_pos, parent->y_pos, parent->z_pos, parent->z_rot, get_actor_scale(parent),
0, 0, 0, 0, 0, 0, 0, -1);
actors_list[id]->attached_actor = i;
parent->attached_actor = id;
actors_list[id]->async_fighting = 0;
actors_list[id]->async_x_tile_pos = parent->async_x_tile_pos;
actors_list[id]->async_y_tile_pos = parent->async_y_tile_pos;
actors_list[id]->async_z_rot = parent->async_z_rot;
actors_list[id]->x_tile_pos=parent->x_tile_pos;
actors_list[id]->y_tile_pos=parent->y_tile_pos;
actors_list[id]->buffs=parent->buffs & BUFF_DOUBLE_SPEED; // the attachment can only have this buff
actors_list[id]->actor_type=attachment_type;
actors_list[id]->damage=0;
actors_list[id]->damage_ms=0;
actors_list[id]->sitting=0;
actors_list[id]->fighting=0;
//test only
actors_list[id]->max_health=0;
actors_list[id]->cur_health=0;
actors_list[id]->ghost=actors_defs[attachment_type].ghost;
actors_list[id]->dead=0;
actors_list[id]->stop_animation=1;//helps when the actor is dead...
actors_list[id]->kind_of_actor=0;
if (attached_actors_defs[attachment_type].actor_type[parent->actor_type].is_holder)
actors_list[id]->step_duration = actors_defs[attachment_type].step_duration;
else
actors_list[id]->step_duration = parent->step_duration;
if (actors_list[id]->buffs & BUFF_DOUBLE_SPEED)
actors_list[id]->step_duration /= 2;
actors_list[id]->z_pos = get_actor_z(actors_list[id]);
//printf("attached actor n°%d of type %d to actor n°%d with id %d\n", id, attachment_type, i, actor_id);
if (actors_defs[attachment_type].coremodel!=NULL) {
//Setup cal3d model
actors_list[id]->calmodel = model_new(actors_defs[attachment_type].coremodel);
//Attach meshes
if(actors_list[id]->calmodel) {
model_attach_mesh(actors_list[id], actors_defs[attachment_type].shirt[0].mesh_index);
set_on_idle(id);
build_actor_bounding_box(actors_list[id]);
if (use_animation_program)
set_transformation_buffers(actors_list[id]);
}
}
else
actors_list[id]->calmodel=NULL;
UNLOCK_ACTORS_LISTS();
}
}
void remove_actor_attachment(int actor_id)
{
int i;
LOCK_ACTORS_LISTS();
for (i = 0; i < max_actors; ++i)
if (actors_list[i]->actor_id == actor_id)
{
int att = actors_list[i]->attached_actor;
actors_list[i]->attached_actor = -1;
actors_list[i]->attachment_shift[0] = 0.0;
actors_list[i]->attachment_shift[1] = 0.0;
actors_list[i]->attachment_shift[2] = 0.0;
free_actor_data(att);
free(actors_list[att]);
actors_list[att]=NULL;
if(att==max_actors-1)max_actors--;
else {
//copy the last one down and fill in the hole
max_actors--;
actors_list[att]=actors_list[max_actors];
actors_list[max_actors]=NULL;
if (actors_list[att] && actors_list[att]->attached_actor >= 0)
actors_list[actors_list[att]->attached_actor]->attached_actor = att;
}
break;
}
UNLOCK_ACTORS_LISTS();
}
void set_health_color(float percent, float multiplier, float a)
{
float r,g;
r=(1.0f-percent)*2.0f;
g=(percent/1.25f)*2.0f;
if(r<0.0f)r=0.0f;
else if(r>1.0f)r=1.0f;
if(g<0.0f)g=0.0f;
else if(g>1.0f)g=1.0f;
glColor4f(r*multiplier,g*multiplier,0.0f, a);
}
void set_mana_color(float percent, float multiplier, float a)
{
float c;
c=0.6f - percent*0.6f;
if(c<0.0f)c=0.0f;
else if(c>1.0f)c=1.0f;
glColor4f(c,c,2.0f, a);
}
void draw_actor_banner(actor * actor_id, float offset_z)
{
unsigned char str[60];
unsigned char temp[255];
GLdouble model[16],proj[16];
GLint view[4];
GLdouble hx,hy,hz,a_bounce;
float font_scale = 1.0f/ALT_INGAME_FONT_X_LEN;
double healthbar_x=0.0f;
double healthbar_y=0.0f;
double healthbar_z=offset_z+0.1;
double health_str_x_len=ALT_INGAME_FONT_X_LEN*12.0*name_zoom*3*font_scale;
double healthbar_x_len_converted=0;
double healthbar_x_len_loss=0;
double healthbar_x_loss_fade=1.0f;
//we use health bar variables if possible, all the extras we need for ether bar are:
double ether_str_x_len = 0;
double etherbar_x_len_converted=0;
GLdouble ey;
//some general values valid for whole banner
double bar_x_len = 0;
double bar_y_len=ALT_INGAME_FONT_Y_LEN*12.0*name_zoom*font_scale;
float banner_width = 0.0f;
int num_lines;
//define inner display_xxxxx variables to have more control over displaying inside this function
//necesary to implement instance mode makes code a bit more easy to understand imho
int display_hp = view_hp;
int display_names = view_names;
int display_health_bar = view_health_bar;
int display_ether_bar = view_ether_bar;
int display_ether = view_ether;
int display_banner_alpha = use_alpha_banner;
//some general info about "what's going on" - allows not to repeat complex conditions later
int displaying_me = 0;
int displaying_other_player = 0;
int display_health_line = 0;
int display_ether_line = 0;
//if first person, dont draw banner
actor *me = get_our_actor();
if (me && me->actor_id==actor_id->actor_id) {
displaying_me = 1;
};
if (displaying_me && first_person) return;
//if not drawing me, can't display ether and ether bar
if (!displaying_me) {
display_ether_bar = 0;
display_ether = 0;
}
//if instance mode enabled, overwrite default view banner view options according to it
if (view_mode_instance) {
//for my banner - use standard banner settings
if (!actor_id->is_enhanced_model) {
//creatures
display_hp = im_creature_view_hp;
display_names = im_creature_view_names;
display_health_bar = im_creature_view_hp_bar;
display_banner_alpha = im_creature_banner_bg;
//TODO: it shows healthbar above mule & summons too - probably no way to solve this issue
} else if (!displaying_me && actor_id->is_enhanced_model){
//other players
displaying_other_player = (actor_id->kind_of_actor != NPC);
display_hp = im_other_player_view_hp;
display_names = im_other_player_view_names;
display_health_bar = im_other_player_view_hp_bar;
display_banner_alpha = im_other_player_banner_bg;
}
}
//Figure out where the point just above the actor's head is in the viewport
//See if Projection and viewport can be saved elsewhere to prevent doing this so often
//MODELVIEW is hopeless
glGetDoublev(GL_MODELVIEW_MATRIX, model);
glGetDoublev(GL_PROJECTION_MATRIX, proj);
glGetIntegerv(GL_VIEWPORT, view);
// Input adjusted healthbar_y value to scale hy according to actor scale
gluProject(healthbar_x, healthbar_y, healthbar_z * actor_id->scale * actors_defs[actor_id->actor_type].actor_scale + 0.02, model, proj, view, &hx, &hy, &hz);
//Save World-view and Projection matrices to allow precise raster placement of quads
glPushMatrix();
glLoadIdentity();
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
//Don't forget that the viewport is expressed in X+W,Y+H, or point-displacement,
//versus the Ortho projection which expects x1,x2,y1,y2, or absolute coordinates
glOrtho(view[0],view[2]+view[0],view[1],view[3]+view[1],0.0f,-1.0f);
glColor3f (1.0f, 0.0f, 0.0f);
glDepthFunc(GL_ALWAYS);
if(actor_id->damage_ms){
if(floatingmessages_enabled){
float a=(float)(cur_time-actor_id->last_health_loss)/2000.0f;
if(actor_id->damage>0){
sprintf((char*)str,"%i",actor_id->damage);
glColor4f(1.0f, 0.1f, 0.2f, 1.0-(a*a));
} else {
sprintf((char*)str,"%i",-actor_id->damage);
glColor4f(0.3f, 1.0f, 0.3f, 1.0-(a*a));
}
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
//Make damage numbers bounce on the actor's head. Owie!
a*=2000;
a_bounce=0;
if (a < 500){
a_bounce = 50.0 - 0.0002 * powf(a,2);
} else if ( a < 950.0){
a_bounce = 0.09*(a-500.0) - .0002 * powf((a-500.0), 2);
} else if ( a < 1355.0 ){
a_bounce = 0.081*(a-950.0) - .0002 * powf((a-950.0), 2);
} else if ( a < 1720 ){
a_bounce = 0.0730*(a-1355.0) - .0002 * powf((a-1355.0), 2);
} else {
a_bounce = 0.0640*(a-1720.0) - .0002 * powf((a-1720.0), 2);
}
/* Schmurk: actually we never reach this code as long as there's
* an exit condition at the beginning of the function */
if ((first_person)&&(actor_id->actor_id==yourself)){
float x,y;
x = window_width/2.0 -(((float)get_string_width(str) * (font_scale*0.17*name_zoom)))*0.5f;
y = a_bounce + window_height/2.0-40.0;
draw_ortho_ingame_string(x, y, 0, str, 1, font_scale*.14, font_scale*.21);
}
else
{
float font_scale2 = font_scale*powf(1.0f+((float)abs(actor_id->damage)/2.0f)/1000.0f, 4.0);
draw_ortho_ingame_string(hx-(((float)get_string_width(str) * (font_scale2*0.17*name_zoom)))*0.5f, a_bounce+hy+10.0f, 0, str, 1, font_scale2*.14, font_scale2*.21);
} glDisable(GL_BLEND);
}
else
{ //No floating messages
sprintf((char*)str,"%i",actor_id->damage);
glColor3f (1.0f, 0.3f, 0.3f);
DRAW_ORTHO_INGAME_NORMAL(-0.1f,healthbar_z/2.0f,0,str,1.0f);
}
if (view_mode_instance && im_other_player_show_banner_on_damage && displaying_other_player && !display_hp && !display_health_bar && actor_id->damage>0) {
display_hp = 1;
display_names = 1;
}
}
glDepthFunc(GL_LESS);
//figure out which lines should we display and how many lines total do we show
display_health_line = (actor_id->kind_of_actor != NPC && (display_hp || display_health_bar) && actor_id->cur_health > 0 && actor_id->max_health > 0);
display_ether_line = ((display_ether || display_ether_bar) && displaying_me && your_info.ethereal_points.base > 0 );
num_lines = display_names + display_health_line + display_ether_line;
if (view_mode_instance && displaying_me) {
//make your bar a bit more above everything else so you can see it good enough
//and got no problems with attacking mobs
hy += view_mode_instance_banner_height*bar_y_len;
} else if (displaying_me && display_health_line && display_ether_line) {
hy += 1.5*bar_y_len;
}
//calculate "y" positions of ether lines
ey = hy -(display_health_line * bar_y_len);
// Schmurk: same here, we actually never reach this code
if (!((first_person)&&(actor_id->actor_id==yourself)))
{
if(actor_id->actor_name[0] && (display_names || display_health_line || display_ether_line)){
set_font(name_font); // to variable length
if(display_names){
float font_size_x=font_scale*SMALL_INGAME_FONT_X_LEN;
float font_size_y=font_scale*SMALL_INGAME_FONT_Y_LEN;
if(actor_id->kind_of_actor==NPC){
glColor3f(0.3f,0.8f,1.0f);
} else if(actor_id->kind_of_actor==HUMAN || actor_id->kind_of_actor==COMPUTER_CONTROLLED_HUMAN){
if(map_type == 2){
glColor3f(0.6f,0.9f,0.9f);
} else {
glColor3f(1.0f,1.0f,1.0f);
}
} else if(actor_id->is_enhanced_model && (actor_id->kind_of_actor==PKABLE_HUMAN || actor_id->kind_of_actor==PKABLE_COMPUTER_CONTROLLED)){
glColor3f(1.0f,0.0f,0.0f);
} else {
glColor3f(1.0f,1.0f,0.0f);
}
safe_snprintf ((char*)temp, sizeof (temp), "%s", actor_id->actor_name);
banner_width = ((float)get_string_width((unsigned char*)actor_id->actor_name)*(font_size_x*name_zoom))/2.0;
draw_ortho_ingame_string(hx-banner_width, hy+bar_y_len/2.0f, hz, temp, 1, font_size_x, font_size_y);
}
if (view_buffs)
{
draw_buffs(actor_id->actor_id, hx, hy, hz);
}
if( (!actor_id->dead) && (actor_id->kind_of_actor != NPC) && (display_health_line || display_ether_line)){
unsigned char hp[200];
unsigned char mana[200];
// make the heath bar the same length as the the health text so they are balanced
// use the same length health bar, even if not displaying the health text
sprintf((char*)hp,"%u/%u", actor_id->cur_health, actor_id->max_health);
health_str_x_len = (float)get_string_width(hp)*(ALT_INGAME_FONT_X_LEN*name_zoom*font_scale);
//do the same with mana if we want to display it
if (display_ether || display_ether_bar) {
sprintf((char*)mana,"%u/%u", your_info.ethereal_points.cur, your_info.ethereal_points.base);
ether_str_x_len=(float)get_string_width(mana)*(ALT_INGAME_FONT_X_LEN*name_zoom*font_scale);
}
//set bar length to longer one (mana or health) - not really clean solution
if (ether_str_x_len > health_str_x_len) {
bar_x_len = ether_str_x_len;
} else {
bar_x_len = health_str_x_len;
}
if (display_hp || display_ether) {
float hp_off=(bar_x_len - health_str_x_len)/2.0;
float eth_off=(bar_x_len - ether_str_x_len)/2.0;
float disp;
disp=(bar_x_len/2.0);
if(display_health_bar){
hp_off+=5.0+disp;
}
if(display_ether_bar){
eth_off+=5.0+disp;
}
if (display_hp && (disp+hp_off > banner_width)) {
banner_width = disp + hp_off;
}
if (display_ether && (disp+eth_off > banner_width)) {
banner_width = disp + eth_off;
}
if (display_hp) {
//choose color for the health
set_health_color((float)actor_id->cur_health/(float)actor_id->max_health, 1.0f, 1.0f);
draw_ortho_ingame_string(hx-disp+hp_off, hy-bar_y_len/3.0f, hz, hp, 1, ALT_INGAME_FONT_X_LEN*font_scale, ALT_INGAME_FONT_Y_LEN*font_scale);
}
if (display_ether) {
set_mana_color((float)your_info.ethereal_points.cur / (float)your_info.ethereal_points.base, 1.0f, 1.0f);
draw_ortho_ingame_string(hx-disp+eth_off, ey-bar_y_len/3.0f, hz, mana, 1, ALT_INGAME_FONT_X_LEN*font_scale, ALT_INGAME_FONT_Y_LEN*font_scale);
}
}
}
set_font(0); // back to fixed pitch
}
}
//draw the health bar
glDisable(GL_TEXTURE_2D);
if(display_health_bar && display_health_line && (!actor_id->dead) && (actor_id->kind_of_actor != NPC)){
float percentage = (float)actor_id->cur_health/(float)actor_id->max_health;
float off;
if(percentage>110.0f) //deal with massive bars by trimming at 110%
percentage = 110.0f;
if (display_hp){
off = bar_x_len + 5.0f;
} else {
off = bar_x_len / 2.0f;
}
if(actor_id->last_health_loss && cur_time-actor_id->last_health_loss<1000){//only when using floatingmessages
if(actor_id->damage>0){
healthbar_x_len_converted=bar_x_len*percentage;
healthbar_x_len_loss=bar_x_len*(float)((float)actor_id->damage/(float)actor_id->max_health);
healthbar_x_loss_fade=1.0f-((float)(cur_time-actor_id->last_health_loss)/1000.0f);
} else {
healthbar_x_len_converted=bar_x_len*(float)((float)(actor_id->cur_health+actor_id->damage)/(float)actor_id->max_health);
healthbar_x_len_loss=bar_x_len*(float)((float)(-actor_id->damage)/(float)actor_id->max_health);
healthbar_x_loss_fade=((float)(cur_time-actor_id->last_health_loss)/1000.0f);
}
} else {
healthbar_x_len_converted=bar_x_len*percentage;
actor_id->last_health_loss=0;
}
if (bar_x_len / 2.0f > banner_width) {
banner_width = bar_x_len / 2.0f;
}
hx-=off;
//choose tint color
set_health_color(percentage, 0.5f, 1.0f);
glBegin(GL_QUADS);
glVertex3d(hx,hy,hz);
glVertex3d(hx+healthbar_x_len_converted,hy,hz);
set_health_color(percentage, 1.0f, 1.0f);
glVertex3d(hx+healthbar_x_len_converted,hy+bar_y_len/3.0,hz);
glVertex3d(hx,hy+bar_y_len/3.0,hz);
glEnd();
if(healthbar_x_len_loss){
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
set_health_color(percentage, 0.5f, healthbar_x_loss_fade);
glBegin(GL_QUADS);
glVertex3d(hx+healthbar_x_len_converted, hy, hz);
glVertex3d(hx+healthbar_x_len_converted+healthbar_x_len_loss, hy, hz);
set_health_color(percentage, 1.0f, healthbar_x_loss_fade);
glVertex3d(hx+healthbar_x_len_converted+healthbar_x_len_loss, hy+bar_y_len/3.0,hz);
glVertex3d(hx+healthbar_x_len_converted, hy+bar_y_len/3.0,hz);
glEnd();
glDisable(GL_BLEND);
}
//draw the frame
glDepthFunc(GL_LEQUAL);
glColor3f (0.0f, 0.0f, 0.0f);
glBegin(GL_LINE_LOOP);
glVertex3f (hx-1.0, hy-1.0, hz);
glVertex3f (hx+bar_x_len+1.0, hy-1.0,hz);
glVertex3f (hx+bar_x_len+1.0, hy+bar_y_len/3.0+1.0,hz);
glVertex3f (hx-1.0, hy+bar_y_len/3.0+1.0,hz);
glEnd();
hx+=off;
}
if (display_ether_bar && display_ether_line) {
float percentage = (float)your_info.ethereal_points.cur / (float)your_info.ethereal_points.base;
float off;
if(percentage>110.0f) //deal with massive bars by trimming at 110%
percentage = 110.0f;
if (display_ether){
off = bar_x_len + 5.0f;
} else {
off = bar_x_len / 2.0f;
}
if (bar_x_len / 2.0f > banner_width) {
banner_width = bar_x_len / 2.0f;
}
hx-=off;
set_mana_color(percentage, 0.5f, 1.0f);
etherbar_x_len_converted = percentage * bar_x_len;
glBegin(GL_QUADS);
glVertex3d(hx,ey,hz);
glVertex3d(hx+etherbar_x_len_converted,ey,hz);
set_mana_color(percentage, 1.0f, 1.0f);
glVertex3d(hx+etherbar_x_len_converted,ey+bar_y_len/3.0,hz);
glVertex3d(hx,ey+bar_y_len/3.0,hz);
glEnd();
set_health_color(percentage, 1.0f, 1.0f);
glDepthFunc(GL_LEQUAL);
glColor3f (0.0f, 0.0f, 0.0f);
glBegin(GL_LINE_LOOP);
glVertex3f (hx-1.0, ey-1.0 , hz);
glVertex3f (hx+bar_x_len+1.0, ey-1.0,hz);
glVertex3f (hx+bar_x_len+1.0, ey+bar_y_len/3.0+1.0,hz);
glVertex3f (hx-1.0, ey+bar_y_len/3.0+1.0,hz);
glEnd();
hx+=off;
}
// draw the alpha background (if ness)
if (display_banner_alpha && banner_width > 0) {
//if banner width > 0 there MUST be something displayed in the banner
float start_y = hy;
start_y += ((!display_health_line && !display_ether_line && display_names) ?bar_y_len-6.0 :-5.0);
start_y -= (num_lines == 3 || (num_lines==2 && !display_names)) ? bar_y_len:0.0;
banner_width += 3;
glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_SRC_ALPHA);
glColor4f(0.0f, 0.0f, 0.0f, 0.6f);
glBegin(GL_QUADS);
glVertex3f (hx-banner_width, start_y, hz + 0.0001);
glVertex3f (hx+banner_width, start_y, hz + 0.0001);
glVertex3f (hx+banner_width, start_y+bar_y_len*num_lines+2, hz + 0.0001);
glVertex3f (hx-banner_width, start_y+bar_y_len*num_lines+2, hz + 0.0001);
glEnd();
glDisable(GL_BLEND);
}
glEnable(GL_TEXTURE_2D);
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
if ((actor_id->current_displayed_text_time_left>0)&&(actor_id->current_displayed_text[0] != 0)){
draw_actor_overtext( actor_id );
}
if(floatingmessages_enabled)drawactor_floatingmessages(actor_id->actor_id, healthbar_z);
/* set cm_mouse_over_banner true if the mouse is over your banner, or a box where it might be */
if (actor_id->actor_id == yourself)
{
/* use the same calculation as for the alpha background but have a fallback if no banner shown */
int xoff = (banner_width > 0) ?banner_width: 60;
float start_y = hy;
start_y += ((!display_health_line && !display_ether_line && display_names) ?bar_y_len-6.0 :-5.0);
start_y -= (num_lines == 3 || (num_lines==2 && !display_names)) ? bar_y_len:0.0;
if ((mouse_x > hx-xoff) && (mouse_x < hx+xoff) &&
(window_height-mouse_y > start_y) && (window_height-mouse_y < start_y+bar_y_len*((num_lines>0)?num_lines:3)))
cm_mouse_over_banner = 1;
else
cm_mouse_over_banner = 0;
}
glColor3f(1,1,1);
#ifdef OPENGL_TRACE
CHECK_GL_ERRORS();
#endif //OPENGL_TRACE
}
void draw_bubble(float x_left, float x_right, float x_leg_left, float x_leg_right, float y_top, float y_bottom, float y_actor)
{
const float r=0.1f;
const float mul=M_PI/180.0f;
int angle;
glEnable(GL_BLEND);
glColor4f(1.0f, 1.0f, 1.0f, 0.5f);
glBlendFunc(GL_NONE, GL_SRC_ALPHA);
glBegin(GL_POLYGON);
for(angle=90;angle<180;angle+=10){
float rad=-mul*angle;
glVertex3f(x_left+cos(rad)*r-r, 0.01f, y_bottom+r+sin(rad)*r);
}
for(angle=180;angle<270;angle+=10){
float rad=-mul*angle;
glVertex3f(x_left+cos(rad)*r-r, 0.01f, y_top-r+sin(rad)*r);
}
for(angle=270;angle<360;angle+=10){
float rad=-mul*angle;
glVertex3f(x_right+cos(rad)*r+r, 0.01f, y_top-r+sin(rad)*r);
}
for(angle=0;angle<90;angle+=10){
float rad=-mul*angle;
glVertex3f(x_right+cos(rad)*r+r, 0.01f, y_bottom+sin(rad)*r+r);
}
glEnd();
glBegin(GL_POLYGON);
glVertex3f(x_leg_right, 0.01f, y_bottom+0.02);
glVertex3f(x_leg_right, 0.01f, y_actor);
glVertex3f(x_leg_left, 0.01f, y_bottom+0.02);
glEnd();
glDisable(GL_BLEND);
#ifdef OPENGL_TRACE
CHECK_GL_ERRORS();
#endif //OPENGL_TRACE
}
//-- Logan Dugenoux [5/26/2004]
void draw_actor_overtext( actor* actor_ptr )
{
float z, w, h;
float x_left, x_right, x_leg_left, x_leg_right, y_top, y_bottom, y_actor;
float textwidth;
float textheight;
float margin;
//-- decrease display time
actor_ptr->current_displayed_text_time_left -= (cur_time-last_time);
if(!(SDL_GetAppState()&SDL_APPACTIVE)) return; // not actually drawing, fake it
textwidth = ((float)get_string_width((unsigned char*)(actor_ptr->current_displayed_text))*(SMALL_INGAME_FONT_X_LEN*zoom_level*name_zoom/3.0))/12.0;
textheight = (0.06f*zoom_level/3.0)*4;
margin = 0.02f*zoom_level;
z = 1.2f;// distance over the player
if (actor_ptr->sitting) z = 0.8f; // close if he's sitting
w = textwidth+margin*2;
h = textheight+margin*2;
x_left=-w/2.0f;
x_right=w/2.0f;
x_leg_left=-0.3f;
x_leg_right=0.0f;
y_top=z+0.7f+h;
y_bottom=z+0.7f;
y_actor=z+0.2f;
glDisable(GL_TEXTURE_2D);
draw_bubble(x_left+0.01f, x_right-0.01f, x_leg_left, x_leg_right, y_top-0.01f, y_bottom+0.01f, y_actor+0.01f);
glEnable(GL_TEXTURE_2D);
//---
// Draw text
glColor3f(0.77f,0.57f,0.39f);
DRAW_INGAME_SMALL(x_left+margin, y_bottom+margin,actor_ptr->current_displayed_text,1);
//glDepthFunc(GL_LESS);
if (actor_ptr->current_displayed_text_time_left<=0)
{ // clear if needed
actor_ptr->current_displayed_text_time_left = 0;
actor_ptr->current_displayed_text[0] = 0;
}
#ifdef OPENGL_TRACE
CHECK_GL_ERRORS();
#endif //OPENGL_TRACE
}
void draw_actor_without_banner(actor * actor_id, Uint32 use_lightning, Uint32 use_textures, Uint32 use_glow)
{
double x_pos,y_pos,z_pos;
float x_rot,y_rot,z_rot;
//if first person, dont draw actor
actor *me = get_our_actor();
if (me&&me->actor_id==actor_id->actor_id&&first_person) return;
if (use_textures)
{
#ifdef NEW_TEXTURES
if (actor_id->is_enhanced_model)
{
if (bind_actor_texture(actor_id->texture_id, &actor_id->has_alpha) == 0)
{
return;
}
}
else
{
if (!actor_id->remapped_colors)
{
bind_texture(actor_id->texture_id);
}
else
{
if (bind_actor_texture(actor_id->texture_id, &actor_id->has_alpha) == 0)
{
return;
}
}
}
#else /* NEW_TEXTURES */
if (actor_id->is_enhanced_model)
{
bind_texture_id(actor_id->texture_id);
}
else
{
if (!actor_id->remapped_colors)
{
get_and_set_texture_id(actor_id->texture_id);
}
else
{
bind_texture_id(actor_id->texture_id);
}
}
#endif /* NEW_TEXTURES */
}
glPushMatrix();//we don't want to affect the rest of the scene
x_pos = actor_id->x_pos;
y_pos = actor_id->y_pos;
z_pos = actor_id->z_pos;
if (z_pos == 0.0f)
{
//actor is walking, as opposed to flying, get the height underneath
z_pos = get_tile_height(actor_id->x_tile_pos, actor_id->y_tile_pos);
}
x_rot = actor_id->x_rot;
y_rot = actor_id->y_rot;
z_rot = 180 - actor_id->z_rot;
glTranslatef(x_pos + 0.25f, y_pos + 0.25f, z_pos);
glRotatef(z_rot, 0.0f, 0.0f, 1.0f);
glRotatef(x_rot, 1.0f, 0.0f, 0.0f);
glRotatef(y_rot, 0.0f, 1.0f, 0.0f);
if (actor_id->attached_actor >= 0)
glTranslatef(actor_id->attachment_shift[0], actor_id->attachment_shift[1], actor_id->attachment_shift[2]);
if (use_animation_program)
{
cal_render_actor_shader(actor_id, use_lightning, use_textures, use_glow);
}
else
{
cal_render_actor(actor_id, use_lightning, use_textures, use_glow);
}
//now, draw their damage & nametag
glPopMatrix(); // restore the matrix
#ifdef OPENGL_TRACE
CHECK_GL_ERRORS();
#endif //OPENGL_TRACE
}