forked from raduprv/Eternal-Lands
-
Notifications
You must be signed in to change notification settings - Fork 0
/
actor_scripts.c
4831 lines (4315 loc) · 162 KB
/
actor_scripts.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 <string.h>
#include <time.h>
#include "actor_scripts.h"
#include "actors.h"
#include "asc.h"
#include "cal.h"
#include "cal3d_wrapper.h"
#include "counters.h"
#include "cursors.h"
#include "draw_scene.h"
#include "errors.h"
#include "gamewin.h"
#include "global.h"
#include "hud.h"
#include "init.h"
#include "interface.h"
#include "missiles.h"
#include "new_actors.h"
#include "multiplayer.h"
#include "new_character.h"
#include "particles.h"
#include "pathfinder.h"
#include "platform.h"
#include "skeletons.h"
#ifdef NEW_SOUND
#include "sound.h"
#endif // NEW_SOUND
#include "spells.h"
#include "text.h"
#include "tiles.h"
#include "timers.h"
#include "translate.h"
#include "eye_candy_wrapper.h"
#include "minimap.h"
#include "io/elfilewrapper.h"
#include "io/cal3d_io_wrapper.h"
#include "actor_init.h"
#ifdef NEW_TEXTURES
#include "textures.h"
#endif /* NEW_TEXTURES */
#ifndef EXT_ACTOR_DICT
const dict_elem skin_color_dict[] =
{ { "brown" , SKIN_BROWN },
{ "normal", SKIN_NORMAL },
{ "pale" , SKIN_PALE },
{ "tan" , SKIN_TAN },
{ "darkblue", SKIN_DARK_BLUE }, // Elf's only
{ "dark_blue", SKIN_DARK_BLUE }, // Elf's only, synonym
{ "white" , SKIN_WHITE }, // Draegoni only
{ NULL , -1 }
};
const dict_elem glow_mode_dict[] =
{ { "none" , GLOW_NONE },
{ "fire" , GLOW_FIRE },
{ "ice" , GLOW_COLD },
{ "thermal", GLOW_THERMAL },
{ "magic" , GLOW_MAGIC },
{ NULL , -1 }
};
const dict_elem head_number_dict[] =
{ { "1" , HEAD_1 },
{ "2" , HEAD_2 },
{ "3" , HEAD_3 },
{ "4" , HEAD_4 },
{ "5" , HEAD_5 },
{ NULL, -1 }
};
int actor_part_sizes[ACTOR_NUM_PARTS] = {10, 40, 50, 100, 100, 100, 10, 20, 40, 60, 20, 20}; // Elements according to actor_parts_enum
#else // EXT_ACTOR_DICT
#define MAX_SKIN_COLORS 7
#define MAX_GLOW_MODES 5
#define MAX_HEAD_NUMBERS 5
dict_elem skin_color_dict[MAX_SKIN_COLORS];
dict_elem head_number_dict[MAX_GLOW_MODES];
dict_elem glow_mode_dict[MAX_HEAD_NUMBERS];
int num_skin_colors = 0;
int num_head_numbers = 0;
int num_glow_modes = 0;
int actor_part_sizes[ACTOR_NUM_PARTS];
#endif // EXT_ACTOR_DICT
//Forward declarations
int cal_load_weapon_mesh (actor_types *act, const char *fn, const char *kind);
int cal_load_mesh(actor_types *act, const char *fn, const char *kind);
void unqueue_cmd(int i);
#ifdef NEW_SOUND
int parse_actor_sounds(actor_types *act, const xmlNode *cfg);
#endif //NEW_SOUND
hash_table *emote_cmds = NULL;
hash_table *emotes = NULL;
int parse_actor_frames(actor_types *act, const xmlNode *cfg, const xmlNode *defaults);
#ifdef MORE_ATTACHED_ACTORS_DEBUG
static int thecount=0;
#endif
void unfreeze_horse(int i){
if(HAS_HORSE(i)&&MY_HORSE(i)->que[0]==wait_cmd) {
//printf("%i, horse out of wait\n",thecount);
unqueue_cmd(MY_HORSE_ID(i));
MY_HORSE(i)->busy=0;
set_on_idle(MY_HORSE_ID(i));
}
}
void cal_actor_set_random_idle(int id)
{
struct CalMixer *mixer;
int i;
int random_anim;
int random_anim_index;
if (actors_list[id]->calmodel==NULL) return;
//LOG_TO_CONSOLE(c_green2,"Randomizing");
//if (actors_list[id]->cur_anim.anim_index==anim.anim_index) return;
srand( (unsigned)time( NULL ) );
mixer=CalModel_GetMixer(actors_list[id]->calmodel);
//Stop previous animation if needed
if (actors_list[id]->IsOnIdle!=1){
if ((actors_list[id]->cur_anim.anim_index!=-1)&&(actors_list[id]->cur_anim.kind==0)) {
CalMixer_ClearCycle(mixer,actors_list[id]->cur_anim.anim_index,0.05);
}
if ((actors_list[id]->cur_anim.anim_index!=-1)&&(actors_list[id]->cur_anim.kind==1)) {
CalMixer_RemoveAction(mixer,actors_list[id]->cur_anim.anim_index);
}
}
for (i=0;i<actors_defs[actors_list[id]->actor_type].group_count;++i) {
random_anim=rand()%(actors_defs[actors_list[id]->actor_type].idle_group[i].count+1);
if (random_anim<actors_defs[actors_list[id]->actor_type].idle_group[i].count) random_anim_index=actors_defs[actors_list[id]->actor_type].idle_group[i].anim[random_anim].anim_index;
else random_anim_index=-1;
if (actors_list[id]->IsOnIdle==1) {
if (actors_list[id]->cur_idle_anims[i].anim_index!=random_anim_index)
CalMixer_ClearCycle(mixer,actors_list[id]->cur_idle_anims[i].anim_index,2.0);
}
if (actors_list[id]->cur_idle_anims[i].anim_index!=random_anim_index)
if (random_anim_index>=0) CalMixer_BlendCycle(mixer,random_anim_index,0.5,0.05);
//safe_snprintf(str, sizeof(str),"%d",random_anim);
//LOG_TO_CONSOLE(c_green2,str);
actors_list[id]->cur_idle_anims[i].anim_index=random_anim_index;
//anim.anim_index,1.0,0.05);else
}
//if (anim.kind==0) CalMixer_BlendCycle(mixer,anim.anim_index,1.0,0.05);else
//CalMixer_ExecuteAction(mixer,anim.anim_index,0.0,0.0);
//actors_list[id]->cur_anim=anim;
//actors_list[id]->anim_time=0.0;
CalModel_Update(actors_list[id]->calmodel,0.0001);//Make changes take effect now
build_actor_bounding_box(actors_list[id]);
if (use_animation_program)
{
set_transformation_buffers(actors_list[id]);
}
actors_list[id]->IsOnIdle= 1;
actors_list[id]->cur_anim.duration= 0;
actors_list[id]->anim_time= 0.0;
actors_list[id]->last_anim_update= cur_time;
actors_list[id]->cur_anim.anim_index= -1;
#ifdef NEW_SOUND
if (check_sound_loops(actors_list[id]->cur_anim_sound_cookie))
stop_sound(actors_list[id]->cur_anim_sound_cookie);
#endif // NEW_SOUND
actors_list[id]->cur_anim_sound_cookie= 0;
//if (actors_list[id]->cur_anim.anim_index==-1) actors_list[id]->busy=0;
}
float unwindAngle_Degrees( float fAngle )
{
fAngle -= 360.0f * (int)( fAngle / 360.0f );
if( fAngle < 0.0f )
{
fAngle += 360.0f;
}
return fAngle;
}
float get_rotation_vector( float fStartAngle, float fEndAngle )
{
float ccw = unwindAngle_Degrees( fStartAngle - fEndAngle );
float cw = unwindAngle_Degrees( fEndAngle - fStartAngle );
if(cw<ccw)return cw;
else return -ccw;
}
int get_motion_vector(int move_cmd, int *dx, int *dy)
{
int result = 1;
switch(move_cmd) {
case move_n:
case run_n:
*dx = 0;
*dy = 1;
break;
case move_s:
case run_s:
*dx = 0;
*dy = -1;
break;
case move_e:
case run_e:
*dx = 1;
*dy = 0;
break;
case move_w:
case run_w:
*dx = -1;
*dy = 0;
break;
case move_ne:
case run_ne:
*dx = 1;
*dy = 1;
break;
case move_se:
case run_se:
*dx = 1;
*dy = -1;
break;
case move_sw:
case run_sw:
*dx = -1;
*dy = -1;
break;
case move_nw:
case run_nw:
*dx = -1;
*dy = 1;
break;
default:
*dx = 0;
*dy = 0;
result = 0;
break;
}
return result;
}
#ifdef ANIMATION_SCALING
static Uint32 update_actor_animation_speed(actor* a, const float time_diff)
{
float scale, seconds;
Uint32 i, animations;
if (a == 0)
{
return 0;
}
animations = 0;
for (i = 0; i < MAX_CMD_QUEUE; i++)
{
if ((a->que[i] != nothing) && (a->que[i] != wait_cmd))
{
animations++;
}
}
scale = a->animation_scale;
seconds = time_diff / 2000.0f;
if (animations > 2)
{
animations -= 2;
}
else
{
animations = 1;
}
if (scale > animations)
{
scale = max2f(scale - seconds, animations);
}
else
{
if (scale < animations)
{
scale = min2f(scale + seconds, animations);
}
}
a->animation_scale = scale;
return scale * time_diff;
}
#endif /* ANIMATION_SCALING */
void animate_actors()
{
#ifdef ANIMATION_SCALING
static int last_update = 0;
int i, actors_time_diff, time_diff, tmp_time_diff;
actors_time_diff = cur_time - last_update;
#else /* ANIMATION_SCALING */
int i;
static int last_update= 0;
int time_diff = cur_time-last_update;
int tmp_time_diff;
#endif /* ANIMATION_SCALING */
// lock the actors_list so that nothing can interere with this look
LOCK_ACTORS_LISTS(); //lock it to avoid timing issues
for(i=0; i<max_actors; i++) {
if(actors_list[i]) {
#ifdef ANIMATION_SCALING
time_diff = update_actor_animation_speed(actors_list[i], actors_time_diff);
#endif /* ANIMATION_SCALING */
if(actors_list[i]->moving) {
#ifdef ANIMATION_SCALING
tmp_time_diff = min2i(actors_list[i]->movement_time_left + 40, time_diff);
actors_list[i]->x_pos += actors_list[i]->move_x_speed * tmp_time_diff;
actors_list[i]->y_pos += actors_list[i]->move_y_speed * tmp_time_diff;
actors_list[i]->z_pos += actors_list[i]->move_z_speed * tmp_time_diff;
#else /* ANIMATION_SCALING */
if (time_diff <= actors_list[i]->movement_time_left+40) {
actors_list[i]->x_pos += actors_list[i]->move_x_speed*time_diff;
actors_list[i]->y_pos += actors_list[i]->move_y_speed*time_diff;
actors_list[i]->z_pos += actors_list[i]->move_z_speed*time_diff;
}
else {
actors_list[i]->x_pos += actors_list[i]->move_x_speed*actors_list[i]->movement_time_left;
actors_list[i]->y_pos += actors_list[i]->move_y_speed*actors_list[i]->movement_time_left;
actors_list[i]->z_pos += actors_list[i]->move_z_speed*actors_list[i]->movement_time_left;
}
#endif /* ANIMATION_SCALING */
actors_list[i]->movement_time_left -= time_diff;
if(actors_list[i]->movement_time_left <= 0){ //we moved all the way
Uint8 last_command;
int dx, dy;
actors_list[i]->moving= 0; //don't move next time, ok?
//now, we need to update the x/y_tile_pos, and round off
//the x/y_pos according to x/y_tile_pos
last_command= actors_list[i]->last_command;
//if(HAS_HORSE(i)) {MY_HORSE(i)->busy=0; if(actors_list[i]->actor_id==yourself) printf("%i, %s wakes up Horse\n",thecount, ACTOR(i)->actor_name);}
if (get_motion_vector(last_command, &dx, &dy)) {
actors_list[i]->x_tile_pos += dx;
actors_list[i]->y_tile_pos += dy;
actors_list[i]->busy = 0;
//if(actors_list[i]->actor_id==yourself) printf("%i, unbusy(moved)\n", thecount);
//if(actors_list[i]->actor_id<0) printf("%i, unbusy horse(moved)\n", thecount);
if (actors_list[i]->que[0] >= move_n &&
actors_list[i]->que[0] <= move_nw) {
next_command();
}
else {
actors_list[i]->x_pos= actors_list[i]->x_tile_pos*0.5;
actors_list[i]->y_pos= actors_list[i]->y_tile_pos*0.5;
actors_list[i]->z_pos= get_actor_z(actors_list[i]);
}
} else {
actors_list[i]->busy = 0;
//if(actors_list[i]->actor_id==yourself) printf("%i, unbusy(moved2)\n", thecount);
//if(actors_list[i]->actor_id<0) printf("%i, unbusy horse(moved2)\n", thecount);
}
}
} //moving
if(actors_list[i]->rotating) {
#ifdef ANIMATION_SCALING
tmp_time_diff = min2i(actors_list[i]->rotate_time_left, time_diff);
actors_list[i]->rotate_time_left -= time_diff;
//we rotated all the way
if (actors_list[i]->rotate_time_left <= 0)
{
actors_list[i]->rotating = 0;//don't rotate next time, ok?
}
#else /* ANIMATION_SCALING */
actors_list[i]->rotate_time_left -= time_diff;
if (actors_list[i]->rotate_time_left <= 0) { //we rotated all the way
actors_list[i]->rotating= 0;//don't rotate next time, ok?
tmp_time_diff = time_diff + actors_list[i]->rotate_time_left;
/*
#ifdef MORE_ATTACHED_ACTORS
if(actors_list[i]->actor_id==yourself) printf("%i, rot: %i\n",thecount,actors_list[i]->rotating);
if(actors_list[i]->actor_id<0) printf("%i, (horse) rot: %i\n",thecount,actors_list[i]->rotating);
#endif
*/
}
else {
tmp_time_diff = time_diff;
}
#endif /* ANIMATION_SCALING */
actors_list[i]->x_rot+= actors_list[i]->rotate_x_speed*tmp_time_diff;
actors_list[i]->y_rot+= actors_list[i]->rotate_y_speed*tmp_time_diff;
actors_list[i]->z_rot+= actors_list[i]->rotate_z_speed*tmp_time_diff;
if(actors_list[i]->z_rot >= 360) {
actors_list[i]->z_rot -= 360;
} else if (actors_list[i]->z_rot <= 0) {
actors_list[i]->z_rot += 360;
}
//if(actors_list[i]->actor_id==yourself) printf("%i, rotating: z_rot %f, status %i-%i\n",thecount,actors_list[i]->z_rot,actors_list[i]->rotating,actors_list[i]->moving);
//if(actors_list[i]->actor_id<0) printf("%i, rotating (horse): z_rot %f, status %i-%i\n",thecount,actors_list[i]->z_rot,actors_list[i]->rotating,actors_list[i]->moving);
}//rotating
#ifdef ANIMATION_SCALING
actors_list[i]->anim_time += (time_diff*actors_list[i]->cur_anim.duration_scale)/1000.0;
#else /* ANIMATION_SCALING */
actors_list[i]->anim_time += ((cur_time-last_update)*actors_list[i]->cur_anim.duration_scale)/1000.0;
#endif /* ANIMATION_SCALING */
/*if(ACTOR(i)->anim_time>=ACTOR(i)->cur_anim.duration) {
if (HAS_HORSE(i)||IS_HORSE(i)) {
if(MY_HORSE(i)->anim_time<MY_HORSE(i)->cur_anim.duration) {
MY_HORSE(i)->anim_time=MY_HORSE(i)->cur_anim.duration;
printf("%i, ANIMATION FORCED\n",thecount);
}
}
}*/
#ifndef DYNAMIC_ANIMATIONS
if (actors_list[i]->calmodel!=NULL){
//check if emote animation is ended, then remove it
handle_cur_emote(actors_list[i]);
#ifdef MORE_EMOTES
if(ACTOR(i)->startIdle!=ACTOR(i)->endIdle){
if(do_transition(ACTOR(i))) {
ACTOR(i)->stand_idle=ACTOR(i)->sit_idle=0; //force set_on_idle
set_on_idle(i);
}
}
#endif
#ifdef ANIMATION_SCALING
CalModel_Update(actors_list[i]->calmodel, (time_diff * actors_list[i]->cur_anim.duration_scale) / 1000.0f);
#else /* ANIMATION_SCALING */
CalModel_Update(actors_list[i]->calmodel, (((cur_time-last_update)*actors_list[i]->cur_anim.duration_scale)/1000.0));
#endif /* ANIMATION_SCALING */
build_actor_bounding_box(actors_list[i]);
{
int wasbusy = ACTOR(i)->busy;
missiles_rotate_actor_bones(actors_list[i]);
if (ACTOR(i)->busy!=wasbusy&&HAS_HORSE(i)) {
//if(actors_list[i]->actor_id==yourself) printf("%i, %s is no more busy due to missiles_rotate_actor_bones!! Setting the horse free...\n",thecount, ACTOR(i)->actor_name);
unfreeze_horse(i);
}
}
if (use_animation_program)
{
set_transformation_buffers(actors_list[i]);
}
}
#endif //DYNAMIC_ANIMATIONS
}
}
// unlock the actors_list since we are done now
UNLOCK_ACTORS_LISTS();
last_update = cur_time;
}
void unqueue_cmd(int i){
int k;
int max_queue=0;
//move que down with one command
for(k=0;k<MAX_CMD_QUEUE-1;k++) {
if(k>max_queue && actors_list[i]->que[k]!=nothing)max_queue=k;
actors_list[i]->que[k]=actors_list[i]->que[k+1];
}
actors_list[i]->que[k]=nothing;
}
void print_queue(actor *act) {
int k;
printf(" Actor %s queue:",act->actor_name);
printf(" -->");
for(k=0; k<MAX_CMD_QUEUE; k++){
if(act->que[k]==enter_combat) printf("IC");
if(act->que[k]==leave_combat) printf("LC");
if(act->que[k]>=move_n&&act->que[k]<=move_nw) printf("M");
if(act->que[k]>=turn_n&&act->que[k]<=turn_nw) printf("R");
printf("%2i|",act->que[k]);
}
printf("\n");
/*for(k=0; k<MAX_RANGE_ACTION_QUEUE; k++){
printf("%2i-%2i|",act->range_actions[k].shot_type,act->range_actions[k].state);
}
printf("\n");
*/
if (act->attached_actor >= 0) {
printf(" Horse %s queue:",act->actor_name);
printf(" -->");
for(k=0; k<MAX_CMD_QUEUE; k++){
if(actors_list[act->attached_actor]->que[k]==enter_combat) printf("IC");
if(actors_list[act->attached_actor]->que[k]==leave_combat) printf("LC");
if(actors_list[act->attached_actor]->que[k]>=move_n&&actors_list[act->attached_actor]->que[k]<=move_nw) printf("M");
if(actors_list[act->attached_actor]->que[k]>=turn_n&&actors_list[act->attached_actor]->que[k]<=turn_nw) printf("R");
printf("%2i|",actors_list[act->attached_actor]->que[k]);
}
printf("\n");
}
}
void attached_info(int i, int c){
if(actors_list[i]->actor_id==yourself&&actors_list[i]->que[0]!=nothing) {
printf("%i---------> DOING: %i -----------\n",c,actors_list[i]->que[0]);
print_queue(actors_list[i]);
}
if(actors_list[i]->actor_id<0&&MY_HORSE(i)->actor_id==yourself&&actors_list[i]->que[0]!=wait_cmd&&actors_list[i]->que[0]!=nothing){
printf("%i---------> DOING (horse): %i ---\n",c,actors_list[i]->que[0]);
print_queue(actors_list[actors_list[i]->attached_actor]);
}
}
void flush_delayed_item_changes(actor *a)
{
int item;
for (item = 0; item < a->delayed_item_changes_count; ++item) {
if (a->delayed_item_changes[item] < 0) {
missiles_log_message("%s (%d): unwearing item type %d now\n",
a->actor_name,
a->actor_id,
a->delayed_item_type_changes[item]);
unwear_item_from_actor(a->actor_id,
a->delayed_item_type_changes[item]);
}
else {
missiles_log_message("%s (%d): wearing item type %d now\n",
a->actor_name,
a->actor_id,
a->delayed_item_type_changes[item]);
actor_wear_item(a->actor_id,
a->delayed_item_type_changes[item],
a->delayed_item_changes[item]);
}
}
a->delayed_item_changes_count = 0;
}
int coun= 0;
void move_to_next_frame()
{
int i;
//int numFrames=0;
//char frame_exists;
//struct CalMixer *mixer;
//char str[255];
LOCK_ACTORS_LISTS();
for(i=0;i<max_actors;i++) {
if(actors_list[i]!=NULL) {
if (actors_list[i]->calmodel!=NULL) {
if ((ACTOR(i)->stop_animation==1)&&(ACTOR(i)->anim_time>=ACTOR(i)->cur_anim.duration)){
//if(actors_list[i]->actor_id==yourself) printf("%i, unbusy: anim %i, anim_time %f, duration %f\n",thecount,actors_list[i]->cur_anim.anim_index,actors_list[i]->anim_time,actors_list[i]->cur_anim.duration);
//if(actors_list[i]->actor_id<0&&MY_HORSE(i)->actor_id==yourself) printf("%i, (horse) unbusy: anim %i, anim_time %f, duration %f\n",thecount,actors_list[i]->cur_anim.anim_index,actors_list[i]->anim_time,actors_list[i]->cur_anim.duration);
if(HAS_HORSE(i)) {
//rotations during idle animation like when server sends turn_n..turn_nw
//need to be synchronized on the minimum remaining animation time between
//the idle of the horse and the actor.
if(
/*(MY_HORSE(i)->anim_time<MY_HORSE(i)->cur_anim.duration)&&*/
MY_HORSE(i)->cur_anim.kind==cycle){
//MY_HORSE(i)->anim_time=MY_HORSE(i)->cur_anim.duration;
MY_HORSE(i)->busy=0;
MY_HORSE(i)->in_aim_mode=0;
set_on_idle(MY_HORSE_ID(i));
//MY_HORSE(i)->stop_animation=0;
//if(actors_list[i]->actor_id==yourself) printf("%i, %s stops Horse\n",thecount, ACTOR(i)->actor_name);
}
} else if (IS_HORSE(i)) {
if(MY_HORSE(i)->anim_time<MY_HORSE(i)->cur_anim.duration) {
//wait for actor
//if(MY_HORSE(i)->actor_id==yourself) printf("%i, Horse waits for %s\n",thecount, MY_HORSE(i)->actor_name);
continue;
}
}
actors_list[i]->busy=0;
if (actors_list[i]->in_aim_mode == 2) {
// we really leave the aim mode only when the animation is finished
actors_list[i]->in_aim_mode = 0;
missiles_log_message("%s (%d): leaving range mode finished!\n",
actors_list[i]->actor_name, actors_list[i]->actor_id);
#ifndef NEW_TEXTURES
// then we do all the item changes that have been delayed
flush_delayed_item_changes(actors_list[i]);
#endif /* NEW_TEXTURES */
}
}
}
#ifdef NEW_TEXTURES
if (actors_list[i]->in_aim_mode == 0)
{
if (actors_list[i]->is_enhanced_model != 0)
{
if (get_actor_texture_ready(actors_list[i]->texture_id))
{
use_ready_actor_texture(actors_list[i]->texture_id);
}
}
if (actors_list[i]->delayed_item_changes_count > 0)
{
// we really leave the aim mode only when the animation is finished
actors_list[i]->delay_texture_item_changes = 0;
// then we do all the item changes that have been delayed
flush_delayed_item_changes(actors_list[i]);
actors_list[i]->delay_texture_item_changes = 1;
}
}
#endif /* NEW_TEXTURES */
// we change the idle animation only when the previous one is finished
if (actors_list[i]->stand_idle && actors_list[i]->anim_time >= actors_list[i]->cur_anim.duration - 0.2)
{
if (!is_actor_held(actors_list[i]))
{
set_on_idle(i);
}
}
if (actors_list[i]->cur_anim.anim_index==-1) {
actors_list[i]->busy=0;
//if(actors_list[i]->actor_id==yourself) printf("%i, unbusy(-1)\n", thecount);
//if(actors_list[i]->actor_id<0) printf("%i, unbusy horse(-1)\n", thecount);
}
//first thing, decrease the damage time, so we will see the damage splash only for 2 seconds
if(actors_list[i]->damage_ms) {
actors_list[i]->damage_ms-=80;
if(actors_list[i]->damage_ms<0)actors_list[i]->damage_ms=0;
}
//9 frames, not moving, and another command is queued farther on (based on how long we've done this action)
if(!actors_list[i]->moving && !actors_list[i]->rotating){
/* actors_list[i]->stop_animation=1; //force stopping, not looping
actors_list[i]->busy=0; //ok, take the next command
LOG_TO_CONSOLE(c_green2,"FREE");
//Idle here?
*/
}
if(actors_list[i]->stop_animation) {
//we are done with this guy
//Should we go into idle here?
}
if(!ACTOR(i)->busy){
if(ACTOR(i)->attached_actor>=0&&ACTOR(i)->actor_id>=0&&
(
(ACTOR(i)->last_command>=enter_aim_mode&&ACTOR(i)->last_command<=aim_mode_fire)||
(ACTOR(i)->last_command>=enter_combat&&ACTOR(i)->last_command<=leave_combat)
)
) {
unfreeze_horse(i);
}
}
if(HAS_HORSE(i)&&ACTOR(i)->in_aim_mode==3) { //when no_action==1
ACTOR(i)->in_aim_mode=0;
unfreeze_horse(i);
//printf("%i,Unfreeze after no_action==1\n",thecount);
}
}
}
UNLOCK_ACTORS_LISTS();
}
struct cal_anim *get_pose(actor *a, int pose_id, int pose_type, int held) {
hash_entry *he,*eh;
emote_data *pose;
eh=hash_get(emotes,(NULL+pose_id));
pose = eh->item;
he=hash_get(actors_defs[a->actor_type].emote_frames, (NULL+pose->anims[pose_type][0][held]->ids[0]));
if (he) return (struct cal_anim*) he->item;
else return NULL;
}
struct cal_anim *get_pose_frame(int actor_type, actor *a, int pose_type, int held){
hash_entry *he;
int a_type=emote_actor_type(actor_type);
//find the pose. Pose is the first anim of the first frame
if (a->poses[pose_type]) {
//printf("getting pose for %s\n",a->actor_name);
he=hash_get(actors_defs[actor_type].emote_frames, (NULL+a->poses[pose_type]->anims[a_type][0][held]->ids[0]));
if (he) return (struct cal_anim*) he->item;
}
//no pose or no emote..set defaults
if (!a->poses[pose_type]) {
//printf("no pose for %s\n",a->actor_name);
switch(pose_type){
case EMOTE_SITTING:
return &actors_defs[a->actor_type].cal_frames[cal_actor_idle_sit_frame];
case EMOTE_STANDING:
if(held) {
attachment_props *att_props = get_attachment_props_if_held(a);
if (att_props)
return &att_props->cal_frames[cal_attached_idle_frame];
} else
// 75% chance to do idle1
if (actors_defs[a->actor_type].cal_frames[cal_actor_idle2_frame].anim_index != -1
&& RAND(0, 3) == 0){
return &actors_defs[a->actor_type].cal_frames[cal_actor_idle2_frame]; //idle2
} else {
return &actors_defs[a->actor_type].cal_frames[cal_actor_idle1_frame]; //idle1
}
case EMOTE_RUNNING:
if(held) {
attachment_props *att_props = get_attachment_props_if_held(a);
if (att_props)
return &att_props->cal_frames[cal_attached_run_frame/*get_held_actor_motion_frame(a)*/];
} else
return &actors_defs[actor_type].cal_frames[cal_actor_run_frame/*get_actor_motion_frame(a)*/];
case EMOTE_WALKING:
if(held) {
attachment_props *att_props = get_attachment_props_if_held(a);
if (att_props)
return &att_props->cal_frames[cal_attached_walk_frame/*get_held_actor_motion_frame(a)*/];
} else
return &actors_defs[actor_type].cal_frames[cal_actor_walk_frame/*get_actor_motion_frame(a)*/];
default:
return NULL;
break;
}
}
return NULL;
}
void set_on_idle(int actor_idx)
{
actor *a = actors_list[actor_idx];
if(!a->dead) {
a->stop_animation=0;
//we have an emote idle, ignore the rest
if(a->cur_emote.idle.anim_index>=0)
return;
if(a->fighting){
if(a->attached_actor>=0) {
//both for horses and actors
if(IS_HORSE(actor_idx))
cal_actor_set_anim(actor_idx,actors_defs[a->actor_type].cal_frames[cal_actor_combat_idle_frame]);
else if (ACTOR_WEAPON(actor_idx)->turn_horse&&ACTOR(actor_idx)->horse_rotated) cal_actor_set_anim(actor_idx,actors_defs[a->actor_type].cal_frames[cal_actor_combat_idle_held_frame]);
else cal_actor_set_anim(actor_idx,actors_defs[a->actor_type].cal_frames[cal_actor_combat_idle_held_unarmed_frame]);
} else
cal_actor_set_anim(actor_idx,actors_defs[a->actor_type].cal_frames[cal_actor_combat_idle_frame]);
}
else if (a->in_aim_mode == 1) {
if(a->actor_id<0){
//ranging horse
if(a->cur_anim.anim_index!=actors_defs[a->actor_type].cal_frames[cal_actor_idle1_frame].anim_index&&
a->cur_anim.anim_index!=actors_defs[a->actor_type].cal_frames[cal_actor_idle2_frame].anim_index){
//printf("%i, horse on idle from %i\n",thecount, a->cur_anim.anim_index);
cal_actor_set_anim(actor_idx, *get_pose_frame(a->actor_type,a,EMOTE_STANDING,0));
}
} else if(a->attached_actor>=0) {
cal_actor_set_anim(actor_idx,actors_defs[a->actor_type].weapon[a->cur_weapon].cal_frames[cal_weapon_range_idle_held_frame]);
} else
cal_actor_set_anim(actor_idx,actors_defs[a->actor_type].weapon[a->cur_weapon].cal_frames[cal_weapon_range_idle_frame]);
}
else if(!a->sitting) {
// we are standing, see if we can activate a stand idle
if(!a->stand_idle||a->cur_anim.anim_index<0){
if (actors_defs[a->actor_type].group_count == 0){
//if(a->actor_id<0) printf("%i, horse on standing idle from %i\n",thecount, a->cur_anim.anim_index);
attachment_props *att_props = get_attachment_props_if_held(a);
if (att_props) {
struct cal_anim *ca=get_pose_frame(a->actor_type,a,EMOTE_STANDING,1);
cal_actor_set_anim(actor_idx, *ca);
}
else {
struct cal_anim *ca=get_pose_frame(a->actor_type,a,EMOTE_STANDING,0);
cal_actor_set_anim(actor_idx, *ca);
}
//printf("setting standing pose\n");
}
else
{
cal_actor_set_random_idle(actor_idx);
a->IsOnIdle=1;
}
a->stand_idle=1;
}
} else {
// we are sitting, see if we can activate the sit idle
if(!a->sit_idle||a->cur_anim.anim_index<0) {
cal_actor_set_anim(actor_idx, *get_pose_frame(a->actor_type,a,EMOTE_SITTING,0));
//printf("setting sitting pose\n");
a->sit_idle=1;
}
}
}
}
void unqueue_emote(actor *act){
int k,max_queue = 0;
// Move queue down one command
for (k = 0; k < MAX_EMOTE_QUEUE - 1; k++) {
if (k > max_queue && act->emote_que[k].origin != NO_EMOTE)
max_queue = k;
act->emote_que[k] = act->emote_que[k+1];
}
act->emote_que[k].origin = NO_EMOTE;
}
int handle_emote_command(int act_id, emote_command *command)
{
actor *act=actors_list[act_id];
struct cal_anim *pose[4];
//check if emote is null. If so, reset emote anims
if(!command->emote){
//printf("reset emotes of actor %i\n",act->actor_id);
cal_reset_emote_anims(act,1);
unqueue_emote(act);
return 1;
}
//check if emote is timed out
//printf("Handle emote %i created at %i for actor %i\n",command->emote->id,command->create_time,act->actor_id);
if(command->create_time+command->emote->timeout<cur_time){
//timed out
//printf("Emote %i timed out\n",command->emote->id);
unqueue_emote(act);
return 1;
} else if(!act->cur_emote.active){
//there is still time to do it, and no emote going on:
//check current frame, actor_type and emote flags
int idle=0,actor_type,held;
//struct cal_anim *defs;
emote_frame *frames;
//barehanded?
if((command->emote->barehanded&EMOTE_BARE_R)&&!is_actor_barehanded(act,EMOTE_BARE_R)){
//printf("Remove weapon to play, waiting...\n");
return 0;
}
if((command->emote->barehanded&EMOTE_BARE_L)&&!is_actor_barehanded(act,EMOTE_BARE_L)){
//printf("Remove shield to play, waiting...\n");
return 0;
}
held = (is_actor_held(act))?1:0;
//printf("actor %i is held: %i\n",act_id,held);
pose[EMOTE_STANDING] = get_pose_frame(act->actor_type,act,EMOTE_STANDING,held);
pose[EMOTE_WALKING] = get_pose_frame(act->actor_type,act,EMOTE_WALKING,held);
pose[EMOTE_SITTING] = get_pose_frame(act->actor_type,act,EMOTE_SITTING,held);
pose[EMOTE_RUNNING] = get_pose_frame(act->actor_type,act,EMOTE_RUNNING,held);
#ifdef MORE_EMOTES
if(command->emote->pose<=EMOTE_STANDING) {
//we have a pose
hash_entry *he;
he=hash_get(actors_defs[actor_type].emote_frames, (NULL+command->emote->anims[act->actor_type][0][held]->ids[0]));
start_transition(act,((struct cal_anim*) he->item)->anim_index,300);
act->poses[command->emote->pose]=command->emote;
unqueue_emote(act);
return 0;
}
#endif
/*printf("STANDING --> a: %i, c: %i\n",pose[EMOTE_STANDING]->anim_index, act->cur_anim.anim_index);
printf("WALKING --> a: %i, c: %i\n",pose[EMOTE_WALKING]->anim_index, act->cur_anim.anim_index);
printf("SITTING --> a: %i, c: %i\n",pose[EMOTE_SITTING]->anim_index, act->cur_anim.anim_index);
printf("RUNNING --> a: %i, c: %i\n",pose[EMOTE_RUNNING]->anim_index, act->cur_anim.anim_index);
*/
if(pose[EMOTE_STANDING]&&pose[EMOTE_STANDING]->anim_index==act->cur_anim.anim_index) idle=EMOTE_STANDING;
else
if(pose[EMOTE_WALKING]&&pose[EMOTE_WALKING]->anim_index==act->cur_anim.anim_index) idle=EMOTE_WALKING;
else
if(pose[EMOTE_RUNNING]&&pose[EMOTE_RUNNING]->anim_index==act->cur_anim.anim_index) idle=EMOTE_RUNNING;
else
if(pose[EMOTE_SITTING]&&pose[EMOTE_SITTING]->anim_index==act->cur_anim.anim_index) idle=EMOTE_SITTING;
else if(act->cur_anim.anim_index<0) {
//we have an emote idle. Remove it and try again
cal_reset_emote_anims(act,1);
set_on_idle(act_id);
return 0;
} else {
//printf("No suitable state for !held\n");
unqueue_emote(act);
return 1;
}
actor_type=emote_actor_type(act->actor_type);
frames=command->emote->anims[actor_type][idle][held];
//we have a emote and not already playing one
//printf("we have anim...actor: %i, held: %i, frames: %p, idle: %i\n",act->actor_id, held,frames,idle);
if (!frames) {
//not ready yet, try later
//printf("but not ready yet\n");
return 0;
} else {
//ready! set emote and unqueue
//printf("ready!!\n");
cal_actor_set_emote_anim(act, frames);
if(HAS_HORSE(act_id)) {
MY_HORSE(act_id)->cur_emote.active=1; //synch with horse!!
//cal_actor_set_emote_anim(MY_HORSE(act_id), frames);
}
//printf("unqueue\n");
unqueue_emote(act);
//LOG_TO_CONSOLE(c_green2, "Emote command");
return 0;
}
}
return 0;
}
void rotate_actor_and_horse_by(int id, int mul, float angle){
//printf("%i. ACTOR %s (rotating: %i): time left -> %i, z speed -> %f\n",thecount,ACTOR(id)->actor_name,actors_list[id]->rotating,actors_list[id]->rotate_time_left,actors_list[id]->rotate_z_speed);
if(!ACTOR(id)->rotating){
ACTOR(id)->rotate_z_speed=(float)mul*angle/(float)HORSE_FIGHT_TIME;
ACTOR(id)->rotate_time_left=HORSE_FIGHT_TIME;
ACTOR(id)->rotating=1;
ACTOR(id)->stop_animation=1;
ACTOR(id)->horse_rotated=(mul<0) ? (1):(0); //<0 enter fight, >=0 leave fight
MY_HORSE(id)->rotate_z_speed=(float)mul*angle/(float)HORSE_FIGHT_TIME;
MY_HORSE(id)->rotate_time_left=HORSE_FIGHT_TIME;
MY_HORSE(id)->rotating=1;
MY_HORSE(id)->stop_animation=1;
}
}
void rotate_actor_and_horse(int id, int mul){
rotate_actor_and_horse_by(id,mul,HORSE_FIGHT_ROTATION);
}
void rotate_actor_and_horse_range(int id, int mul){
rotate_actor_and_horse_by(id,mul,HORSE_RANGE_ROTATION);
}
//in case the actor is not busy, and has commands in it's que, execute them
void next_command()
{
int i, index;
int max_queue=0;
#ifdef MORE_ATTACHED_ACTORS_DEBUG
thecount++;
#endif
for(i=0;i<max_actors;i++){
if(!actors_list[i])continue;//actor exists?
if(actors_list[i]->que[0]>=emote_cmd
&&actors_list[i]->que[0]<wait_cmd
){
int k;
add_emote_to_actor(actors_list[i]->actor_id,actors_list[i]->que[0]);
//actors_list[i]->stop_animation=1;
//move que down with one command