-
Notifications
You must be signed in to change notification settings - Fork 34
/
anim.c
3415 lines (2803 loc) · 99.7 KB
/
anim.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 "game/anim.h"
#include <stdio.h>
#include <string.h>
#include "game/art.h"
#include "plib/color/color.h"
#include "game/combat.h"
#include "game/combatai.h"
#include "game/combat_defs.h"
#include "plib/gnw/input.h"
#include "game/critter.h"
#include "plib/gnw/debug.h"
#include "game/display.h"
#include "game/game.h"
#include "game/gconfig.h"
#include "game/gmouse.h"
#include "game/gsound.h"
#include "plib/gnw/rect.h"
#include "game/intface.h"
#include "game/item.h"
#include "game/map.h"
#include "game/object.h"
#include "game/perk.h"
#include "game/proto.h"
#include "game/protinst.h"
#include "game/roll.h"
#include "game/scripts.h"
#include "game/stat.h"
#include "game/textobj.h"
#include "game/tile.h"
#include "game/trait.h"
#include "plib/gnw/svga.h"
#include "plib/gnw/vcr.h"
#define ANIMATION_SEQUENCE_LIST_CAPACITY 32
#define ANIMATION_DESCRIPTION_LIST_CAPACITY 55
#define ANIMATION_SAD_LIST_CAPACITY 24
#define ANIMATION_SEQUENCE_FORCED 0x01
typedef enum AnimationKind {
ANIM_KIND_MOVE_TO_OBJECT = 0,
ANIM_KIND_MOVE_TO_TILE = 1,
ANIM_KIND_MOVE_TO_TILE_STRAIGHT = 2,
ANIM_KIND_MOVE_TO_TILE_STRAIGHT_AND_WAIT_FOR_COMPLETE = 3,
ANIM_KIND_ANIMATE = 4,
ANIM_KIND_ANIMATE_REVERSED = 5,
ANIM_KIND_ANIMATE_AND_HIDE = 6,
ANIM_KIND_ROTATE_TO_TILE = 7,
ANIM_KIND_ROTATE_CLOCKWISE = 8,
ANIM_KIND_ROTATE_COUNTER_CLOCKWISE = 9,
ANIM_KIND_HIDE = 10,
ANIM_KIND_CALLBACK = 11,
ANIM_KIND_CALLBACK3 = 12,
ANIM_KIND_SET_FLAG = 14,
ANIM_KIND_UNSET_FLAG = 15,
ANIM_KIND_TOGGLE_FLAT = 16,
ANIM_KIND_SET_FID = 17,
ANIM_KIND_TAKE_OUT_WEAPON = 18,
ANIM_KIND_SET_LIGHT_DISTANCE = 19,
ANIM_KIND_MOVE_ON_STAIRS = 20,
ANIM_KIND_CHECK_FALLING = 23,
ANIM_KIND_TOGGLE_OUTLINE = 24,
ANIM_KIND_ANIMATE_FOREVER = 25,
ANIM_KIND_26 = 26,
ANIM_KIND_27 = 27,
ANIM_KIND_NOOP = 28,
} AnimationKind;
typedef enum AnimationSequenceFlags {
// Specifies that the animation sequence has high priority, it cannot be
// cleared.
ANIM_SEQ_PRIORITIZED = 0x01,
// Specifies that the animation sequence started combat animation mode and
// therefore should balance it with appropriate finish call.
ANIM_SEQ_COMBAT_ANIM_STARTED = 0x02,
// Specifies that the animation sequence is reserved (TODO: explain what it
// actually means).
ANIM_SEQ_RESERVED = 0x04,
// Specifies that the animation sequence is in the process of adding actions
// to it (that is in the middle of begin/end calls).
ANIM_SEQ_ACCUMULATING = 0x08,
// TODO: Add description.
ANIM_SEQ_0x10 = 0x10,
// TODO: Add description.
ANIM_SEQ_0x20 = 0x20,
// Specifies that the animation sequence is negligible and will be end
// immediately when a new animation sequence is requested for the same
// object.
ANIM_SEQ_INSIGNIFICANT = 0x40,
// Specifies that the animation sequence should not return to ANIM_STAND
// when it's completed.
ANIM_SEQ_NO_STAND = 0x80,
} AnimationSequenceFlags;
typedef enum AnimationSadFlags {
// Specifies that the animation should play from end to start.
ANIM_SAD_REVERSE = 0x01,
// Specifies that the animation should use straight movement mode (as
// opposed to normal movement mode).
ANIM_SAD_STRAIGHT = 0x02,
// Specifies that no frame change should occur during animation.
ANIM_SAD_NO_ANIM = 0x04,
// Specifies that the animation should be played fully from start to finish.
//
// NOTE: This flag is only used together with straight movement mode to
// implement knockdown. Without this flag when the knockdown distance is
// short, say 1 or 2 tiles, knockdown animation might not be completed by
// the time critter reached it's destination. With this flag set animation
// will be played to it's final frame.
ANIM_SAD_WAIT_FOR_COMPLETION = 0x10,
// Unknown, set once, never read.
ANIM_SAD_0x20 = 0x20,
// Specifies that the owner of the animation should be hidden when animation
// is completed.
ANIM_SAD_HIDE_ON_END = 0x40,
// Specifies that the animation should never end.
ANIM_SAD_FOREVER = 0x80,
} AnimationSadFlags;
typedef struct AnimationDescription {
int kind;
union {
Object* owner;
// - ANIM_KIND_CALLBACK
// - ANIM_KIND_CALLBACK3
void* param2;
};
union {
// - ANIM_KIND_MOVE_TO_OBJECT
Object* destination;
// - ANIM_KIND_CALLBACK
void* param1;
};
union {
// - ANIM_KIND_MOVE_TO_TILE
// - ANIM_KIND_ANIMATE_AND_MOVE_TO_TILE_STRAIGHT
// - ANIM_KIND_MOVE_TO_TILE_STRAIGHT
struct {
int tile;
int elevation;
};
// ANIM_KIND_SET_FID
int fid;
// ANIM_KIND_TAKE_OUT_WEAPON
int weaponAnimationCode;
// ANIM_KIND_SET_LIGHT_DISTANCE
int lightDistance;
// ANIM_KIND_TOGGLE_OUTLINE
bool outline;
};
int anim;
int delay;
// ANIM_KIND_CALLBACK
AnimationCallback* callback;
// ANIM_KIND_CALLBACK3
AnimationCallback3* callback3;
union {
// - ANIM_KIND_SET_FLAG
// - ANIM_KIND_UNSET_FLAG
unsigned int objectFlag;
// - ANIM_KIND_HIDE
// - ANIM_KIND_CALLBACK
unsigned int extendedFlags;
};
union {
// - ANIM_KIND_MOVE_TO_TILE
// - ANIM_KIND_MOVE_TO_OBJECT
int actionPoints;
// ANIM_KIND_26
int animationSequenceIndex;
// ANIM_KIND_CALLBACK3
void* param3;
};
CacheEntry* artCacheKey;
} AnimationDescription;
typedef struct AnimationSequence {
int field_0;
// Index of current animation in [animations] array or -1 if animations in
// this sequence is not playing.
int animationIndex;
// Number of scheduled animations in [animations] array.
int length;
unsigned int flags;
AnimationDescription animations[ANIMATION_DESCRIPTION_LIST_CAPACITY];
} AnimationSequence;
typedef struct PathNode {
int tile;
int from;
// actual type is likely char
int rotation;
int field_C;
int field_10;
} PathNode;
// TODO: I don't know what `sad` means, but it's definitely better than
// `STRUCT_530014`. Find a better name.
typedef struct AnimationSad {
unsigned int flags;
Object* obj;
int fid; // fid
int anim;
// Timestamp (in game ticks) when animation last occurred.
unsigned int animationTimestamp;
// Number of ticks per frame (taking art's fps and overall animation speed
// settings into account).
unsigned int ticksPerFrame;
int animationSequenceIndex;
int field_1C; // length of field_28
int field_20; // current index in field_28
int field_24;
union {
unsigned char rotations[3200];
StraightPathNode field_28[200];
};
} AnimationSad;
static_assert(sizeof(AnimationSad) == 3240, "wrong size");
static int anim_free_slot(int a1);
static int anim_preload(Object* object, int fid, CacheEntry** cacheEntryPtr);
static void anim_cleanup();
static int anim_set_check(int a1);
static int anim_set_continue(int a1, int a2);
static int anim_set_end(int a1);
static bool anim_can_use_door(Object* critter, Object* door);
static int anim_move_to_object(Object* from, Object* to, int a3, int anim, int animationSequenceIndex);
static int make_stair_path(Object* object, int from, int fromElevation, int to, int toElevation, StraightPathNode* a6, Object** obstaclePtr);
static int anim_move_to_tile(Object* obj, int tile_num, int elev, int a4, int anim, int animationSequenceIndex);
static int anim_move(Object* obj, int tile, int elev, int a3, int anim, int a5, int animationSequenceIndex);
static int anim_move_straight_to_tile(Object* obj, int tile, int elevation, int anim, int animationSequenceIndex, int flags);
static void object_move(int index);
static void object_straight_move(int index);
static int anim_animate(Object* obj, int anim, int animationSequenceIndex, int flags);
static void object_anim_compact();
static int anim_turn_towards(Object* obj, int delta, int animationSequenceIndex);
static int check_gravity(int tile, int elevation);
// 0x510718
static int curr_sad = 0;
// 0x51071C
static int curr_anim_set = -1;
// 0x510720
static bool anim_in_init = false;
// 0x510724
static bool anim_in_anim_stop = false;
// 0x510728
static bool anim_in_bk = false;
// 0x530014
static AnimationSad sad[ANIMATION_SAD_LIST_CAPACITY];
// 0x542FD4
static PathNode dad[2000];
// 0x54CC14
static AnimationSequence anim_set[ANIMATION_SEQUENCE_LIST_CAPACITY];
// 0x561814
static unsigned char seen[5000];
// 0x562B9C
static PathNode child[2000];
// 0x56C7DC
static int curr_anim_counter;
// anim_init
// 0x413A20
void anim_init()
{
anim_in_init = true;
anim_reset();
anim_in_init = false;
}
// 0x413A40
void anim_reset()
{
if (!anim_in_init) {
// NOTE: Uninline.
anim_stop();
}
curr_sad = 0;
curr_anim_set = -1;
for (int index = 0; index < ANIMATION_SEQUENCE_LIST_CAPACITY; index++) {
anim_set[index].field_0 = -1000;
anim_set[index].flags = 0;
}
}
// 0x413AB8
void anim_exit()
{
// NOTE: Uninline.
anim_stop();
}
// 0x413AF4
int register_begin(int requestOptions)
{
if (curr_anim_set != -1) {
return -1;
}
if (anim_in_anim_stop) {
return -1;
}
int v1 = anim_free_slot(requestOptions);
if (v1 == -1) {
return -1;
}
AnimationSequence* animationSequence = &(anim_set[v1]);
animationSequence->flags |= ANIM_SEQ_ACCUMULATING;
if ((requestOptions & ANIMATION_REQUEST_RESERVED) != 0) {
animationSequence->flags |= ANIM_SEQ_RESERVED;
}
if ((requestOptions & ANIMATION_REQUEST_INSIGNIFICANT) != 0) {
animationSequence->flags |= ANIM_SEQ_INSIGNIFICANT;
}
if ((requestOptions & ANIMATION_REQUEST_NO_STAND) != 0) {
animationSequence->flags |= ANIM_SEQ_NO_STAND;
}
curr_anim_set = v1;
curr_anim_counter = 0;
return 0;
}
// 0x413B80
static int anim_free_slot(int requestOptions)
{
int v1 = -1;
int v2 = 0;
for (int index = 0; index < ANIMATION_SEQUENCE_LIST_CAPACITY; index++) {
AnimationSequence* animationSequence = &(anim_set[index]);
if (animationSequence->field_0 != -1000 || (animationSequence->flags & ANIM_SEQ_ACCUMULATING) != 0 || (animationSequence->flags & ANIM_SEQ_0x20) != 0) {
if (!(animationSequence->flags & ANIM_SEQ_RESERVED)) {
v2++;
}
} else if (v1 == -1 && ((requestOptions & ANIMATION_REQUEST_0x100) == 0 || (animationSequence->flags & ANIM_SEQ_0x10) == 0)) {
v1 = index;
}
}
if (v1 == -1) {
if ((requestOptions & ANIMATION_REQUEST_RESERVED) != 0) {
debug_printf("Unable to begin reserved animation!\n");
}
return -1;
} else if ((requestOptions & ANIMATION_REQUEST_RESERVED) != 0 || v2 < 20) {
return v1;
}
return -1;
}
// 0x413C20
int register_priority(int a1)
{
if (curr_anim_set == -1) {
return -1;
}
if (a1 == 0) {
return -1;
}
anim_set[curr_anim_set].flags |= ANIM_SEQ_PRIORITIZED;
return 0;
}
// 0x413C4C
int register_clear(Object* a1)
{
for (int animationSequenceIndex = 0; animationSequenceIndex < ANIMATION_SEQUENCE_LIST_CAPACITY; animationSequenceIndex++) {
AnimationSequence* animationSequence = &(anim_set[animationSequenceIndex]);
if (animationSequence->field_0 == -1000) {
continue;
}
int animationDescriptionIndex;
for (animationDescriptionIndex = 0; animationDescriptionIndex < animationSequence->length; animationDescriptionIndex++) {
AnimationDescription* animationDescription = &(animationSequence->animations[animationDescriptionIndex]);
if (a1 != animationDescription->owner || animationDescription->kind == 11) {
continue;
}
break;
}
if (animationDescriptionIndex == animationSequence->length) {
continue;
}
if ((animationSequence->flags & ANIM_SEQ_PRIORITIZED) != 0) {
return -2;
}
anim_set_end(animationSequenceIndex);
return 0;
}
return -1;
}
// 0x413CCC
int register_end()
{
if (curr_anim_set == -1) {
return -1;
}
AnimationSequence* animationSequence = &(anim_set[curr_anim_set]);
animationSequence->field_0 = 0;
animationSequence->length = curr_anim_counter;
animationSequence->animationIndex = -1;
animationSequence->flags &= ~ANIM_SEQ_ACCUMULATING;
animationSequence->animations[0].delay = 0;
if (isInCombat()) {
combat_anim_begin();
animationSequence->flags |= ANIM_SEQ_COMBAT_ANIM_STARTED;
}
int v1 = curr_anim_set;
curr_anim_set = -1;
if (!(animationSequence->flags & ANIM_SEQ_0x10)) {
anim_set_continue(v1, 1);
}
return 0;
}
// NOTE: Inlined.
//
// 0x413D6C
static int anim_preload(Object* object, int fid, CacheEntry** cacheEntryPtr)
{
*cacheEntryPtr = NULL;
if (art_ptr_lock(fid, cacheEntryPtr) != NULL) {
art_ptr_unlock(*cacheEntryPtr);
*cacheEntryPtr = NULL;
return 0;
}
return -1;
}
// 0x413D98
static void anim_cleanup()
{
if (curr_anim_set == -1) {
return;
}
for (int index = 0; index < ANIMATION_SEQUENCE_LIST_CAPACITY; index++) {
anim_set[index].flags &= ~(ANIM_SEQ_ACCUMULATING | ANIM_SEQ_0x10);
}
AnimationSequence* animationSequence = &(anim_set[curr_anim_set]);
for (int index = 0; index < curr_anim_counter; index++) {
AnimationDescription* animationDescription = &(animationSequence->animations[index]);
if (animationDescription->artCacheKey != NULL) {
art_ptr_unlock(animationDescription->artCacheKey);
}
if (animationDescription->kind == ANIM_KIND_CALLBACK && animationDescription->callback == gsnd_anim_sound) {
gsound_delete_sfx(animationDescription->param1);
}
}
curr_anim_set = -1;
}
// 0x413E2C
int check_registry(Object* obj)
{
if (curr_anim_set == -1) {
return -1;
}
if (curr_anim_counter >= ANIMATION_DESCRIPTION_LIST_CAPACITY) {
return -1;
}
if (obj == NULL) {
return 0;
}
for (int animationSequenceIndex = 0; animationSequenceIndex < ANIMATION_SEQUENCE_LIST_CAPACITY; animationSequenceIndex++) {
AnimationSequence* animationSequence = &(anim_set[animationSequenceIndex]);
if (animationSequenceIndex != curr_anim_set && animationSequence->field_0 != -1000) {
for (int animationDescriptionIndex = 0; animationDescriptionIndex < animationSequence->length; animationDescriptionIndex++) {
AnimationDescription* animationDescription = &(animationSequence->animations[animationDescriptionIndex]);
if (obj == animationDescription->owner && animationDescription->kind != 11) {
if ((animationSequence->flags & ANIM_SEQ_INSIGNIFICANT) == 0) {
return -1;
}
anim_set_end(animationSequenceIndex);
}
}
}
}
return 0;
}
// Returns -1 if object is playing some animation.
//
// 0x413EC8
int anim_busy(Object* a1)
{
if (curr_anim_counter >= ANIMATION_DESCRIPTION_LIST_CAPACITY || a1 == NULL) {
return 0;
}
for (int animationSequenceIndex = 0; animationSequenceIndex < ANIMATION_SEQUENCE_LIST_CAPACITY; animationSequenceIndex++) {
AnimationSequence* animationSequence = &(anim_set[animationSequenceIndex]);
if (animationSequenceIndex != curr_anim_set && animationSequence->field_0 != -1000) {
for (int animationDescriptionIndex = 0; animationDescriptionIndex < animationSequence->length; animationDescriptionIndex++) {
AnimationDescription* animationDescription = &(animationSequence->animations[animationDescriptionIndex]);
if (a1 != animationDescription->owner) {
continue;
}
if (animationDescription->kind == ANIM_KIND_CALLBACK) {
continue;
}
if (animationSequence->length == 1 && animationDescription->anim == ANIM_STAND) {
continue;
}
return -1;
}
}
}
return 0;
}
// 0x413F5C
int register_object_move_to_object(Object* owner, Object* destination, int actionPoints, int delay)
{
if (check_registry(owner) == -1 || actionPoints == 0) {
anim_cleanup();
return -1;
}
if (owner->tile == destination->tile && owner->elevation == destination->elevation) {
return 0;
}
AnimationDescription* animationDescription = &(anim_set[curr_anim_set].animations[curr_anim_counter]);
animationDescription->kind = ANIM_KIND_MOVE_TO_OBJECT;
animationDescription->anim = ANIM_WALK;
animationDescription->owner = owner;
animationDescription->destination = destination;
animationDescription->actionPoints = actionPoints;
animationDescription->delay = delay;
int fid = art_id(FID_TYPE(owner->fid), owner->fid & 0xFFF, animationDescription->anim, (owner->fid & 0xF000) >> 12, owner->rotation + 1);
// NOTE: Uninline.
if (anim_preload(owner, fid, &(animationDescription->artCacheKey)) == -1) {
anim_cleanup();
return -1;
}
curr_anim_counter++;
return register_object_turn_towards(owner, destination->tile);
}
// 0x41405C
int register_object_run_to_object(Object* owner, Object* destination, int actionPoints, int delay)
{
if (check_registry(owner) == -1 || actionPoints == 0) {
anim_cleanup();
return -1;
}
if (owner->tile == destination->tile && owner->elevation == destination->elevation) {
return 0;
}
if (critterIsOverloaded(owner)) {
if (isPartyMember(owner)) {
char formattedText[92];
MessageListItem messageListItem;
if (owner == obj_dude) {
// You are overloaded.
strcpy(formattedText, getmsg(&misc_message_file, &messageListItem, 8000));
} else {
// %s is overloaded.
sprintf(formattedText,
getmsg(&misc_message_file, &messageListItem, 8001),
critter_name(owner));
}
display_print(formattedText);
}
return register_object_move_to_object(owner, destination, actionPoints, delay);
}
AnimationDescription* animationDescription = &(anim_set[curr_anim_set].animations[curr_anim_counter]);
animationDescription->kind = ANIM_KIND_MOVE_TO_OBJECT;
animationDescription->owner = owner;
animationDescription->destination = destination;
if ((FID_TYPE(owner->fid) == OBJ_TYPE_CRITTER && (owner->data.critter.combat.results & DAM_CRIP_LEG_ANY) != 0)
|| (owner == obj_dude && is_pc_flag(0) && !perk_level(obj_dude, PERK_SILENT_RUNNING))
|| (!art_exists(art_id(FID_TYPE(owner->fid), owner->fid & 0xFFF, ANIM_RUNNING, 0, owner->rotation + 1)))) {
animationDescription->anim = ANIM_WALK;
} else {
animationDescription->anim = ANIM_RUNNING;
}
animationDescription->actionPoints = actionPoints;
animationDescription->delay = delay;
int fid = art_id(FID_TYPE(owner->fid), owner->fid & 0xFFF, animationDescription->anim, (owner->fid & 0xF000) >> 12, owner->rotation + 1);
// NOTE: Uninline.
if (anim_preload(owner, fid, &(animationDescription->artCacheKey)) == -1) {
anim_cleanup();
return -1;
}
curr_anim_counter++;
return register_object_turn_towards(owner, destination->tile);
}
// 0x414294
int register_object_move_to_tile(Object* owner, int tile, int elevation, int actionPoints, int delay)
{
if (check_registry(owner) == -1 || actionPoints == 0) {
anim_cleanup();
return -1;
}
if (tile == owner->tile && elevation == owner->elevation) {
return 0;
}
AnimationDescription* animationDescription = &(anim_set[curr_anim_set].animations[curr_anim_counter]);
animationDescription->kind = ANIM_KIND_MOVE_TO_TILE;
animationDescription->anim = ANIM_WALK;
animationDescription->owner = owner;
animationDescription->tile = tile;
animationDescription->elevation = elevation;
animationDescription->actionPoints = actionPoints;
animationDescription->delay = delay;
int fid = art_id(FID_TYPE(owner->fid), owner->fid & 0xFFF, animationDescription->anim, (owner->fid & 0xF000) >> 12, owner->rotation + 1);
// NOTE: Uninline.
if (anim_preload(owner, fid, &(animationDescription->artCacheKey)) == -1) {
anim_cleanup();
return -1;
}
curr_anim_counter++;
return 0;
}
// 0x414394
int register_object_run_to_tile(Object* owner, int tile, int elevation, int actionPoints, int delay)
{
if (check_registry(owner) == -1 || actionPoints == 0) {
anim_cleanup();
return -1;
}
if (tile == owner->tile && elevation == owner->elevation) {
return 0;
}
if (critterIsOverloaded(owner)) {
if (isPartyMember(owner)) {
MessageListItem messageListItem;
char formattedText[72];
if (owner == obj_dude) {
// You are overloaded.
strcpy(formattedText, getmsg(&misc_message_file, &messageListItem, 8000));
} else {
// %s is overloaded.
sprintf(formattedText,
getmsg(&misc_message_file, &messageListItem, 8001),
critter_name(owner));
}
display_print(formattedText);
}
return register_object_move_to_tile(owner, tile, elevation, actionPoints, delay);
}
AnimationDescription* animationDescription = &(anim_set[curr_anim_set].animations[curr_anim_counter]);
animationDescription->kind = ANIM_KIND_MOVE_TO_TILE;
animationDescription->owner = owner;
animationDescription->tile = tile;
animationDescription->elevation = elevation;
if ((FID_TYPE(owner->fid) == OBJ_TYPE_CRITTER && (owner->data.critter.combat.results & DAM_CRIP_LEG_ANY) != 0)
|| (owner == obj_dude && is_pc_flag(0) && !perk_level(obj_dude, PERK_SILENT_RUNNING))
|| (!art_exists(art_id(FID_TYPE(owner->fid), owner->fid & 0xFFF, ANIM_RUNNING, 0, owner->rotation + 1)))) {
animationDescription->anim = ANIM_WALK;
} else {
animationDescription->anim = ANIM_RUNNING;
}
animationDescription->actionPoints = actionPoints;
animationDescription->delay = delay;
int fid = art_id(FID_TYPE(owner->fid), owner->fid & 0xFFF, animationDescription->anim, (owner->fid & 0xF000) >> 12, owner->rotation + 1);
// NOTE: Uninline.
if (anim_preload(owner, fid, &(animationDescription->artCacheKey)) == -1) {
anim_cleanup();
return -1;
}
curr_anim_counter++;
return 0;
}
// 0x4145D0
int register_object_move_straight_to_tile(Object* object, int tile, int elevation, int anim, int delay)
{
if (check_registry(object) == -1) {
anim_cleanup();
return -1;
}
if (tile == object->tile && elevation == object->elevation) {
return 0;
}
AnimationSequence* animationSequence = &(anim_set[curr_anim_set]);
AnimationDescription* animationDescription = &(animationSequence->animations[curr_anim_counter]);
animationDescription->kind = ANIM_KIND_MOVE_TO_TILE_STRAIGHT;
animationDescription->owner = object;
animationDescription->tile = tile;
animationDescription->elevation = elevation;
animationDescription->anim = anim;
animationDescription->delay = delay;
int fid = art_id(FID_TYPE(object->fid), object->fid & 0xFFF, animationDescription->anim, (object->fid & 0xF000) >> 12, object->rotation + 1);
// NOTE: Uninline.
if (anim_preload(object, fid, &(animationDescription->artCacheKey)) == -1) {
anim_cleanup();
return -1;
}
curr_anim_counter++;
return 0;
}
// 0x4146C4
int register_object_animate_and_move_straight(Object* owner, int tile, int elevation, int anim, int delay)
{
if (check_registry(owner) == -1) {
anim_cleanup();
return -1;
}
if (tile == owner->tile && elevation == owner->elevation) {
return 0;
}
AnimationSequence* animationSequence = &(anim_set[curr_anim_set]);
AnimationDescription* animationDescription = &(animationSequence->animations[curr_anim_counter]);
animationDescription->kind = ANIM_KIND_MOVE_TO_TILE_STRAIGHT_AND_WAIT_FOR_COMPLETE;
animationDescription->owner = owner;
animationDescription->tile = tile;
animationDescription->elevation = elevation;
animationDescription->anim = anim;
animationDescription->delay = delay;
int fid = art_id(FID_TYPE(owner->fid), owner->fid & 0xFFF, animationDescription->anim, (owner->fid & 0xF000) >> 12, owner->rotation + 1);
// NOTE: Uninline.
if (anim_preload(owner, fid, &(animationDescription->artCacheKey)) == -1) {
anim_cleanup();
return -1;
}
curr_anim_counter++;
return 0;
}
// NOTE: Unused.
//
// 0x4147B
int register_object_move_on_stairs(Object* owner, Object* stairs, int delay)
{
int anim;
int destTile;
int destElevation;
AnimationSequence* animationSequence;
AnimationDescription* animationDescription;
int fid;
if (check_registry(owner) == -1) {
anim_cleanup();
return -1;
}
if (owner->elevation == stairs->elevation) {
anim = ANIM_UP_STAIRS_LEFT;
destTile = stairs->tile + 4;
destElevation = stairs->elevation + 1;
} else {
anim = ANIM_DOWN_STAIRS_RIGHT;
destTile = stairs->tile + 200;
destElevation = stairs->elevation;
}
if (destTile == owner->tile && destElevation == owner->elevation) {
return 0;
}
animationSequence = &(anim_set[curr_anim_set]);
animationDescription = &(animationSequence->animations[curr_anim_counter]);
animationDescription->kind = ANIM_KIND_MOVE_ON_STAIRS;
animationDescription->owner = owner;
animationDescription->tile = destTile;
animationDescription->elevation = destElevation;
animationDescription->anim = anim;
animationDescription->delay = delay;
fid = art_id(FID_TYPE(owner->fid), owner->fid & 0xFFF, animationDescription->anim, (owner->fid & 0xF000) >> 12, owner->rotation + 1);
// NOTE: Uninline
if (anim_preload(owner, fid, &(animationDescription->artCacheKey)) == -1) {
anim_cleanup();
return -1;
}
curr_anim_counter++;
return 0;
}
// NOTE: Unused.
//
// 0x4148F0
int register_object_check_falling(Object* owner, int delay)
{
AnimationSequence* animationSequence;
AnimationDescription* animationDescription;
int fid;
if (check_registry(owner) == -1) {
anim_cleanup();
return -1;
}
animationSequence = &(anim_set[curr_anim_set]);
animationDescription = &(animationSequence->animations[curr_anim_counter]);
animationDescription->kind = ANIM_KIND_CHECK_FALLING;
animationDescription->anim = ANIM_FALLING;
animationDescription->owner = owner;
animationDescription->delay = delay;
fid = art_id(FID_TYPE(owner->fid), owner->fid & 0xFFF, animationDescription->anim, (owner->fid & 0xF000) >> 12, owner->rotation + 1);
// NOTE: Uninline
if (anim_preload(owner, fid, &(animationDescription->artCacheKey)) == -1) {
anim_cleanup();
return -1;
}
curr_anim_counter++;
return 0;
}
// 0x4149D0
int register_object_animate(Object* owner, int anim, int delay)
{
if (check_registry(owner) == -1) {
anim_cleanup();
return -1;
}
AnimationSequence* animationSequence = &(anim_set[curr_anim_set]);
AnimationDescription* animationDescription = &(animationSequence->animations[curr_anim_counter]);
animationDescription->kind = ANIM_KIND_ANIMATE;
animationDescription->owner = owner;
animationDescription->anim = anim;
animationDescription->delay = delay;
int fid = art_id(FID_TYPE(owner->fid), owner->fid & 0xFFF, animationDescription->anim, (owner->fid & 0xF000) >> 12, owner->rotation + 1);
// NOTE: Uninline.
if (anim_preload(owner, fid, &(animationDescription->artCacheKey)) == -1) {
anim_cleanup();
return -1;
}
curr_anim_counter++;
return 0;
}
// 0x414AA8
int register_object_animate_reverse(Object* owner, int anim, int delay)
{
if (check_registry(owner) == -1) {
anim_cleanup();
return -1;
}
AnimationSequence* animationSequence = &(anim_set[curr_anim_set]);
AnimationDescription* animationDescription = &(animationSequence->animations[curr_anim_counter]);
animationDescription->kind = ANIM_KIND_ANIMATE_REVERSED;
animationDescription->owner = owner;
animationDescription->anim = anim;
animationDescription->delay = delay;
animationDescription->artCacheKey = NULL;
int fid = art_id(FID_TYPE(owner->fid), owner->fid & 0xFFF, animationDescription->anim, (owner->fid & 0xF000) >> 12, owner->rotation + 1);
// NOTE: Uninline.
if (anim_preload(owner, fid, &(animationDescription->artCacheKey)) == -1) {
anim_cleanup();
return -1;
}
curr_anim_counter++;
return 0;
}
// 0x414B7C
int register_object_animate_and_hide(Object* owner, int anim, int delay)
{
if (check_registry(owner) == -1) {