Repository navigation
Expand file tree
/
Copy pathfirst_person_weapons.c
More file actions
2419 lines (2174 loc) · 78.5 KB
/
Copy pathfirst_person_weapons.c
File metadata and controls
2419 lines (2174 loc) · 78.5 KB
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
/*
FIRST_PERSON_WEAPONS.C
symbols in this file:
000CBC60 0020:
_animation_update_render_only (0000)
000CBC80 0040:
_first_person_weapons_initialize (0000)
000CBCC0 0010:
_first_person_weapons_dispose (0000)
000CBCD0 0050:
_first_person_weapons_initialize_for_new_map (0000)
000CBD20 0010:
_first_person_weapons_dispose_from_old_map (0000)
000CBD30 00c0:
_code_000cbd30 (0000)
000CBDF0 0110:
_code_000cbdf0 (0000)
000CBF00 0120:
_code_000cbf00 (0000)
000CC020 0040:
_code_000cc020 (0000)
000CC060 00a0:
_code_000cc060 (0000)
000CC100 00b0:
_code_000cc100 (0000)
000CC1B0 00e0:
_code_000cc1b0 (0000)
000CC290 0060:
_code_000cc290 (0000)
000CC2F0 0040:
_code_000cc2f0 (0000)
000CC330 0080:
_code_000cc330 (0000)
000CC3B0 0290:
_first_person_weapon_draw (0000)
000CC640 0080:
_first_person_weapon_get_local_index (0000)
000CC6C0 00d0:
_first_person_weapon_get_marker_by_name (0000)
000CC790 00e0:
_first_person_weapon_center_flashlight (0000)
000CC870 00d0:
_first_person_weapon_adjust_light (0000)
000CC940 00c0:
_first_person_weapon_get_node_matrix (0000)
000CCA00 00b0:
_code_000cca00 (0000)
000CCAB0 0560:
_code_000ccab0 (0000)
000CD010 00b0:
_first_person_weapon_render_update (0000)
000CD0C0 0040:
_first_person_weapon_get_marker_by_name_render (0000)
000CD100 02b0:
_code_000cd100 (0000)
000CD3B0 0260:
_code_000cd3b0 (0000)
000CD610 0060:
_code_000cd610 (0000)
000CD670 0220:
_code_000cd670 (0000)
000CD890 0050:
_first_person_weapon_message_from_unit (0000)
000CD8E0 0040:
_first_person_weapon_message_from_weapon (0000)
000CD920 0170:
_code_000cd920 (0000)
000CDA90 0600:
_code_000cda90 (0000)
000CE090 00f0:
_first_person_weapons_update (0000)
0027076C 0015:
??_C@_0BF@MEAEHHHF@first_person_weapons?$AA@ (0000)
00270784 0030:
??_C@_0DA@LGOECHKB@c?3?2halo?2SOURCE?2interface?2first_p@ (0000)
002707B4 0015:
??_C@_0BF@LKJCKPFC@first?5person?5weapons?$AA@ (0000)
002707CC 0028:
??_C@_0CI@FFNKKBPO@first_person_weapon?9?$DOweapon_inde@ (0000)
002707F8 0059:
??_C@_0FJ@DFINBDBK@animation_graph_node_index?$DO?$DN0?5?$CG?$CG@ (0000)
00270854 000b:
??_C@_0L@HGCOMEEN@flashlight?$AA@ (0000)
00270860 0039:
??_C@_0DJ@KDPHKICA@node_index?$DO?$DN0?5?$CG?$CG?5node_index?$DManim@ (0000)
0027089C 0035:
??_C@_0DF@COECBIGL@local?5player?5?$CFd?0?5weapon?5?$CI0x?$CFx?$CJ?0?5@ (0000)
002708D8 00a5:
??_C@_0KF@OCJNMLNK@first_person_weapon?9?$DOshotgun_rel@ (0000)
00270980 0004:
__real@c1f00000 (0000)
00453CC8 0004:
_bss_00453cc8 (0000)
*/
/* ---------- headers */
#define REAL_MATH_EXTERNAL_SIGNED_ANGULAR_DIFFERENCE
#define REAL_MATH_EXTERNAL_REAL_LOCAL_RANDOM
#define REAL_MATH_EXTERNAL_REAL_LOCAL_RANDOM_RANGE
#include "interface/first_person_weapons.h"
#include "cache/predicted_resources.h"
#include "camera/director.h"
#include "cseries/cseries.h"
#include "cseries/errors.h"
#include "effects/effects.h"
#include "effects/particles.h"
#include "game/game_globals.h"
#include "game/players.h"
#include "items/weapon_datum_flags.h"
#include "items/weapon_definitions.h"
#include "items/weapons.h"
#include "models/model_animation_definitions.h"
#include "models/model_definitions.h"
#include "models/models.h"
#include "networking/network_connection.h"
#include "objects/objects.h"
#include "rasterizer/rasterizer.h" /* port: rasterizer_memory_alloc */
#include "rasterizer/rasterizer_model_types.h"
#include "render/render.h"
#include "saved games/game_state.h"
#include "scenario/scenario.h"
#include "sound/game_sound.h"
#include "sound/sound_manager.h"
#include "units/units.h"
#include "view_fov.h" /* port: port/linux/game/view_fov.c */
#include "viewmodel_shield.h" /* port: port/linux/game/viewmodel_shield.c */
/* ---------- constants */
enum
{
_render_model_first_person_bit = 3,
};
enum
{
NUMBER_OF_FIRST_PERSON_WEAPON_OVERLAY_FRAMES = 9,
FIRST_PERSON_WEAPON_RELOAD_SETTLE_TICKS = 44,
};
#define FIRST_PERSON_WEAPON_FIRING_PUSH_BACK_VELOCITY 0.05f
enum first_person_weapon_state
{
_first_person_weapon_state_idle = 0,
_first_person_weapon_state_overheating,
_first_person_weapon_state_overheating_again,
_first_person_weapon_state_overheated,
_first_person_weapon_state_charged,
_first_person_weapon_state_posing,
_first_person_weapon_state_primary_fire,
_first_person_weapon_state_secondary_fire,
_first_person_weapon_state_primary_misfire,
_first_person_weapon_state_secondary_misfire,
_first_person_weapon_state_melee,
_first_person_weapon_state_light_on,
_first_person_weapon_state_light_off,
_first_person_weapon_state_reload_while_empty,
_first_person_weapon_state_reload_while_full,
_first_person_weapon_state_shotgun_enter_reload,
_first_person_weapon_state_shotgun_exit_reload_empty,
_first_person_weapon_state_shotgun_exit_reload_full,
_first_person_weapon_state_put_away,
_first_person_weapon_state_ready,
_first_person_weapon_state_throw_grenade,
_first_person_weapon_state_throw_grenade_overheated,
_first_person_weapon_state_overheated_exit,
_first_person_weapon_state_overheating_super_recoil,
NUMBER_OF_FIRST_PERSON_WEAPON_STATES,
};
enum
{
_render_model_effect_type_none = 0,
_render_model_effect_type_active_camouflage,
};
enum
{
animation_update_kind_render_only = 0,
};
enum animation_update_result
{
_animation_no_key_frame = 0,
_animation_key_frame,
_animation_will_restart_on_next_frame,
};
/* ---------- macros */
/* ---------- structures */
struct shader;
/* Kept TU-private because moving this recovered layout into a shared header perturbs VC7 output. */
struct animation_state_continuous
{
short index;
word pad;
real frame_index;
};
/* Recovered animation-graph block layouts used only by this translation unit. */
struct animation_graph_sound_reference
{
struct tag_reference sound;
long unused;
};
typedef char verify_animation_graph_sound_reference_size[
sizeof(struct animation_graph_sound_reference) == 0x14 ? 1 : -1];
struct animation_graph_first_person_weapon_animations
{
long unused[4];
struct tag_block animations; // animation_graph_animation_index
};
typedef char verify_animation_graph_first_person_weapon_animations_size[
sizeof(struct animation_graph_first_person_weapon_animations) == 0x1C ? 1 : -1];
/* Only the leading name is consumed here; the remaining bytes preserve the January layout. */
struct animation_graph_node
{
char name[TAG_STRING_LENGTH+1];
byte reserved0020[0x20];
};
typedef char verify_animation_graph_node_size[
sizeof(struct animation_graph_node) == 0x40 ? 1 : -1];
typedef char verify_render_model_effect_size[
sizeof(struct render_model_effect) == 0x28 ? 1 : -1];
struct first_person_weapon
{
boolean visible;
byte reserved0001[3];
long unit_index;
long weapon_index;
short state;
short ticks_until_pose;
short ticks_idle;
short ticks_until_predict;
short overlay_animation_index;
struct animation_state state_animation;
struct animation_state moving_animation;
short reserved001e;
struct animation_state_continuous overcharged_jitter_animation;
real firing_push_back;
real firing_push_back_velocity;
real_vector2d position;
real_vector2d position_velocity;
real_vector2d turning;
real_vector2d turning_velocity;
boolean rendered;
byte reserved0051[3];
real_vector3d render_forward;
real_euler_angles2d render_facing;
real_euler_angles2d last_render_facing;
real_point3d render_position;
real_point3d last_render_position;
short interpolation_frame_index;
short interpolation_frame_count;
real_orientation node_orientations[MAXIMUM_NODES_PER_ANIMATION];
real_orientation original_node_orientations[MAXIMUM_NODES_PER_ANIMATION];
struct real_matrix4x3 node_matrices[MAXIMUM_NODES_PER_ANIMATION];
boolean weapon_node_remapping_table_valid;
byte reserved1d8d;
short weapon_node_remapping_table[MAXIMUM_NODES_PER_ANIMATION];
boolean hands_node_remapping_table_valid;
byte reserved1e0f;
short hands_node_remapping_table[MAXIMUM_NODES_PER_ANIMATION];
boolean shotgun_empty;
byte reserved1e91;
short shotgun_shells_to_reload;
short shotgun_reload_type;
short reserved1e96;
long current_sound_index;
short current_sound_state;
byte reserved1e9e[2];
};
typedef char verify_first_person_weapon_size[
sizeof(struct first_person_weapon) == 0x1EA0 ? 1 : -1];
typedef char verify_first_person_weapon_node_matrices_offset[
offsetof(struct first_person_weapon, node_matrices) == 0x108C ? 1 : -1];
typedef char verify_first_person_weapon_rendered_offset[
offsetof(struct first_person_weapon, rendered) == 0x50 ? 1 : -1];
typedef char verify_first_person_weapon_node_orientations_offset[
offsetof(struct first_person_weapon, node_orientations) == 0x8C ? 1 : -1];
typedef char verify_first_person_weapon_node_remapping_table_offset[
offsetof(struct first_person_weapon, weapon_node_remapping_table) == 0x1D8E ? 1 : -1];
typedef char verify_first_person_weapon_shotgun_empty_offset[
offsetof(struct first_person_weapon, shotgun_empty) == 0x1E90 ? 1 : -1];
typedef char verify_first_person_weapon_current_sound_index_offset[
offsetof(struct first_person_weapon, current_sound_index) == 0x1E98 ? 1 : -1];
typedef char verify_first_person_weapon_current_sound_state_offset[
offsetof(struct first_person_weapon, current_sound_state) == 0x1E9C ? 1 : -1];
typedef char verify_weapon_first_person_animations_index_offset[
offsetof(
struct weapon_definition,
weapon.interface_definition.first_person_animations.index) == 0x478 ? 1 : -1];
typedef char verify_weapon_flags_offset[
offsetof(struct weapon_datum, weapon.flags) == 0x1DC ? 1 : -1];
typedef char verify_weapon_type_offset[
offsetof(struct weapon_definition, weapon.weapon_type) == 0x4E2 ? 1 : -1];
typedef char verify_animation_graph_first_person_weapon_animations_offset[
offsetof(struct animation_graph, first_person_weapon_animations) == 0x48 ? 1 : -1];
typedef char verify_unit_flags_offset[
offsetof(struct unit_datum, unit.flags) == 0x1B4 ? 1 : -1];
typedef char verify_unit_active_camouflage_offset[
offsetof(struct unit_datum, unit.active_camouflage) == 0x32C ? 1 : -1];
typedef char verify_object_outgoing_function_values_offset[
offsetof(struct object_datum, object.outgoing_function_values) == 0xE4 ? 1 : -1];
typedef char verify_object_outgoing_change_colors_offset[
offsetof(struct object_datum, object.outgoing_change_colors) == 0x168 ? 1 : -1];
typedef char verify_game_globals_first_person_interface_offset[
offsetof(struct game_globals, first_person_interface) == 0x17C ? 1 : -1];
typedef char verify_animation_graph_nodes_offset[
offsetof(struct animation_graph, nodes) == 0x68 ? 1 : -1];
/* ---------- prototypes */
static void first_person_weapon_set_visibility(
short local_player_index,
boolean visible);
static void first_person_weapon_build_node_matrices(
short local_player_index);
static boolean first_person_weapon_animation_fits(
struct animation_graph const *animation_graph,
struct animation const *animation);
static void first_person_weapon_predict(
short local_player_index);
static void first_person_weapon_start_interpolation(
short local_player_index,
short frame_count);
static void first_person_weapon_set_state(
short local_player_index,
short new_state,
boolean reset_sounds);
static void first_person_weapon_switch_weapons(
short local_player_index);
static void first_person_weapon_forget_weapon(
short local_player_index);
static void first_person_weapon_new_unit(
short local_player_index,
long unit_index);
static void first_person_weapon_message(
short local_player_index,
short message_type);
static void first_person_weapon_next_state(
short local_player_index);
static void first_person_weapon_update(
short local_player_index);
static boolean model_build_remapping_table_for_animation_graph(
long model_index,
long animation_graph_index,
short *node_remapping_table);
static void weapon_play_first_person_weapon_sound(
long weapon_index,
short message_type);
static long first_person_weapon_state_from_weapon_message(
short message_type);
static long first_person_animation_type_from_weapon_state(
short state);
static void model_remap_node_matrices_to_match_animation_graph(
long model_index,
struct real_matrix4x3 *model_node_matrices,
long animation_graph_index,
struct real_matrix4x3 const *node_matrices,
short const *node_remapping_table);
static struct first_person_weapon *first_person_weapon_get(
short local_player_index);
static short first_person_weapon_index_from_weapon_index(
long weapon_index);
static short first_person_weapon_index_from_unit_index(
long unit_index);
/* port/linux/game/pal_tags.c's */
boolean pal_tags_first_person_advance(short local_player_index, long graph_index, short animation_index,
short frame_index);
real pal_tags_first_person_fraction(short local_player_index, long graph_index, short animation_index,
short frame_index);
/* ---------- globals */
static struct first_person_weapon *first_person_weapons;
/* ---------- public code */
short animation_update_render_only(
long animation_graph_index,
struct animation_state *state,
long *sound_index)
{
return animation_update_internal(
0,
animation_graph_index,
state,
sound_index);
}
void first_person_weapons_initialize(
void)
{
first_person_weapons = (struct first_person_weapon *)game_state_malloc(
"first person weapons",
NULL,
sizeof(*first_person_weapons) * MAXIMUM_NUMBER_OF_LOCAL_PLAYERS);
match_assert(
"c:\\halo\\SOURCE\\interface\\first_person_weapons.c",
240,
first_person_weapons);
return;
}
void first_person_weapons_dispose(
void)
{
return;
}
void first_person_weapons_initialize_for_new_map(
void)
{
short local_player_index;
for (local_player_index=0; local_player_index<MAXIMUM_NUMBER_OF_LOCAL_PLAYERS; local_player_index++)
{
csmemset(
&first_person_weapons[local_player_index],
0,
sizeof(first_person_weapons[local_player_index]));
first_person_weapons[local_player_index].unit_index= NONE;
first_person_weapons[local_player_index].current_sound_index= NONE;
first_person_weapons[local_player_index].current_sound_state= NONE;
}
return;
}
void first_person_weapons_dispose_from_old_map(
void)
{
return;
}
long first_person_weapon_get_local_index(
long weapon_index)
{
short local_player_index;
for (local_player_index=0; local_player_index<MAXIMUM_NUMBER_OF_LOCAL_PLAYERS; local_player_index++)
{
struct first_person_weapon *first_person_weapon= first_person_weapon_get(local_player_index);
if (first_person_weapon->weapon_index==weapon_index && first_person_weapon->visible)
{
break;
}
}
return (local_player_index==MAXIMUM_NUMBER_OF_LOCAL_PLAYERS) ? NONE : local_player_index;
}
void first_person_weapon_draw(
void)
{
/* port: not drawn with display.viewmodel_visible off (view_fov.c) */
if (!viewmodel_is_visible())
return;
if (render.local_player_index!=NONE)
{
struct first_person_weapon *first_person_weapon= first_person_weapon_get(render.local_player_index);
if (local_player_get_player_index(render.local_player_index)!=NONE)
{
long unit_index= player_get(
local_player_get_player_index(render.local_player_index))->unit_index;
if (unit_index!=NONE &&
first_person_weapon->visible &&
first_person_weapon->unit_index!=NONE &&
first_person_weapon->weapon_index!=NONE)
{
struct unit_datum *unit= unit_get(unit_index);
struct weapon_datum *weapon= weapon_get(first_person_weapon->weapon_index);
struct weapon_definition *weapon_definition= weapon_definition_get(weapon->definition_index);
if (weapon_definition->weapon.interface_definition.first_person_animations.index!=NONE)
{
struct real_matrix4x3 model_node_matrices[MAXIMUM_NODES_PER_ANIMATION];
struct render_model_effect model_effect;
struct game_globals_first_person_interface *first_person_interface=
TAG_BLOCK_GET_ELEMENT(
&scenario_get_game_globals()->first_person_interface,
0,
struct game_globals_first_person_interface);
struct animation_graph *animation_graph= animation_graph_definition_get(
weapon_definition->weapon.interface_definition.first_person_animations.index);
struct render_lighting *lighting= object_get_cached_render_lighting(unit_index, FLT_MAX);
real values[NUMBER_OF_OUTGOING_OBJECT_FUNCTIONS];
real const *weapon_functions = weapon->object.outgoing_function_values;
real const *unit_functions = unit->object.outgoing_function_values;
real *kept;
/* port: the tick's functions, moved into this frame, so the
charge clicks with the picture instead of once a tick; kept
in the rasterizer's memory for the frame, as the groups drawn
later read them (render_objects.c) */
object_function_values_for_render(first_person_weapon->weapon_index, values);
if ((kept = rasterizer_memory_alloc(values, sizeof(values))) != NULL)
weapon_functions = kept;
object_function_values_for_render(unit_index, values);
if ((kept = rasterizer_memory_alloc(values, sizeof(values))) != NULL)
unit_functions = kept;
model_effect.modifier_shader= NULL;
if (TEST_FLAG(unit->unit.flags, _unit_active_camouflaged_bit) ||
unit->unit.active_camouflage>0.0f)
{
model_effect.type= _render_model_effect_type_active_camouflage;
model_effect.intensity= unit->unit.active_camouflage;
model_effect.parameter= unit->unit.active_camouflage_super_amount;
model_effect.source_object_index= unit_index;
model_effect.source_object_centroid= render.camera.position;
}
else
{
model_effect.type= _render_model_effect_type_none;
}
if (first_person_weapon->weapon_node_remapping_table_valid &&
weapon_definition->weapon.interface_definition.first_person_model.index!=NONE)
{
model_remap_node_matrices_to_match_animation_graph(
weapon_definition->weapon.interface_definition.first_person_model.index,
model_node_matrices,
weapon_definition->weapon.interface_definition.first_person_animations.index,
first_person_weapon->node_matrices,
first_person_weapon->weapon_node_remapping_table);
render_model(
weapon_definition->weapon.interface_definition.first_person_model.index,
0.0f,
model_node_matrices,
NULL,
weapon->object.outgoing_change_colors,
weapon_functions,
lighting,
&render.camera.position,
0.0f,
&model_effect,
first_person_weapon->weapon_index,
0,
FLAG(_render_model_first_person_bit));
}
if (first_person_weapon->hands_node_remapping_table_valid &&
first_person_interface->hands.index!=NONE)
{
model_remap_node_matrices_to_match_animation_graph(
first_person_interface->hands.index,
model_node_matrices,
weapon_definition->weapon.interface_definition.first_person_animations.index,
first_person_weapon->node_matrices,
first_person_weapon->hands_node_remapping_table);
/* port: only the posed hands receive the shield modifier (viewmodel_shield.c). */
viewmodel_shield_apply(render.local_player_index, unit_index,
first_person_interface->hands.index, model_node_matrices, unit_functions, &model_effect);
render_model(
first_person_interface->hands.index,
0.0f,
model_node_matrices,
NULL,
unit->object.outgoing_change_colors,
unit_functions,
lighting,
&render.camera.position,
0.0f,
&model_effect,
first_person_weapon->weapon_index,
0,
FLAG(_render_model_first_person_bit));
}
}
}
}
}
return;
}
short first_person_weapon_get_marker_by_name(
long weapon_index,
char const *name,
struct object_marker *markers,
short maximum_marker_count)
{
short marker_count= 0;
struct weapon_datum *weapon= weapon_try_and_get(weapon_index);
if (weapon)
{
short local_player_index= first_person_weapon_index_from_weapon_index(weapon_index);
if (local_player_index!=NONE &&
director_get_perspective(local_player_index)==_director_perspective_first_person)
{
struct first_person_weapon *first_person_weapon= first_person_weapon_get(local_player_index);
struct weapon_definition *weapon_definition= weapon_definition_get(weapon->definition_index);
if (first_person_weapon->weapon_node_remapping_table_valid &&
weapon_definition->weapon.interface_definition.first_person_model.index!=NONE &&
weapon_definition->weapon.interface_definition.first_person_animations.index!=NONE)
{
marker_count= model_get_marker_by_name(
weapon_definition->weapon.interface_definition.first_person_model.index,
name,
NULL,
first_person_weapon->weapon_node_remapping_table,
(short)animation_graph_definition_get(
weapon_definition->weapon.interface_definition.first_person_animations.index)->nodes.count,
first_person_weapon->node_matrices,
FALSE,
markers,
maximum_marker_count);
}
}
}
return marker_count;
}
void first_person_weapon_render_update(
void)
{
if (render.local_player_index!=NONE)
{
struct first_person_weapon *first_person_weapon= first_person_weapon_get(render.local_player_index);
if (first_person_weapon->unit_index!=NONE &&
first_person_weapon->weapon_index!=NONE)
{
boolean visible= director_get_perspective(render.local_player_index)==_director_perspective_first_person &&
player_control_get_zoom_level(render.local_player_index)==NONE;
first_person_weapon_set_visibility(render.local_player_index, visible);
if (first_person_weapon->visible)
{
first_person_weapon_build_node_matrices(render.local_player_index);
}
}
}
return;
}
short first_person_weapon_get_marker_by_name_render(
long weapon_index,
char const *name,
struct object_marker *markers,
short maximum_marker_count)
{
if (render.local_player_index==first_person_weapon_index_from_weapon_index(weapon_index))
{
return first_person_weapon_get_marker_by_name(
weapon_index,
name,
markers,
maximum_marker_count);
}
return 0;
}
boolean first_person_weapon_center_flashlight(
long unit_index,
real_point3d *position,
real_vector3d *forward,
real_vector3d *up)
{
short local_player_index= first_person_weapon_index_from_unit_index(unit_index);
boolean centered= FALSE; /* port: returned */
if (local_player_index!=NONE)
{
struct first_person_weapon *first_person_weapon= first_person_weapon_get(local_player_index);
if (first_person_weapon->visible)
{
struct object_marker marker;
if (first_person_weapon_get_marker_by_name(
first_person_weapon->weapon_index,
"flashlight",
&marker,
1)>0)
{
position->x= marker.matrix.position.x - marker.matrix.forward.i*0.5f;
position->y= marker.matrix.position.y - marker.matrix.forward.j*0.5f;
position->z= marker.matrix.position.z - marker.matrix.forward.k*0.5f;
*forward= marker.matrix.forward;
*up= marker.matrix.up;
centered= TRUE;
}
}
}
return centered;
}
boolean first_person_weapon_adjust_light(
long weapon_index,
char const *marker_name,
real_point3d *position,
real_vector3d *forward,
real_vector3d *up)
{
struct weapon_datum *weapon= weapon_get(weapon_index);
struct unit_datum *unit= unit_get(weapon->object.parent_object_index);
long player_index= unit->unit.player_index;
boolean adjusted= FALSE;
if (player_index!=NONE)
{
struct player_datum *player= player_get(player_index);
short local_player_index= player->local_player_index;
struct object_marker marker;
if (local_player_index!=NONE &&
local_player_index==render.local_player_index &&
first_person_weapon_get(local_player_index)->visible &&
first_person_weapon_get_marker_by_name(weapon_index, marker_name, &marker, 1)>0)
{
*position= marker.matrix.position;
*forward= marker.matrix.forward;
*up= marker.matrix.up;
adjusted= TRUE;
}
}
return adjusted;
}
void first_person_weapon_message_from_unit(
long unit_index,
short message_type)
{
short local_player_index= first_person_weapon_index_from_unit_index(unit_index);
first_person_weapon_message(local_player_index, message_type);
if (local_player_index==NONE)
{
struct unit_datum *unit= unit_get(unit_index);
/* port: the weapon in hand's object (not its slot's number, which
played some other object's sound) */
if (unit->unit.current_weapon_index>=0 &&
unit->unit.current_weapon_index<MAXIMUM_WEAPONS_PER_UNIT)
{
weapon_play_first_person_weapon_sound(
unit->unit.weapon_object_indices[unit->unit.current_weapon_index],
message_type);
}
}
return;
}
void first_person_weapon_message_from_weapon(
long weapon_index,
short message_type)
{
short local_player_index= first_person_weapon_index_from_weapon_index(weapon_index);
first_person_weapon_message(local_player_index, message_type);
if (local_player_index==NONE)
{
weapon_play_first_person_weapon_sound(weapon_index, message_type);
}
return;
}
struct real_matrix4x3 *first_person_weapon_get_node_matrix(
short local_player_index,
short node_index)
{
struct first_person_weapon *first_person_weapon;
struct weapon_datum *weapon;
struct weapon_definition *weapon_definition;
struct animation_graph *animation_graph;
match_assert(
"c:\\halo\\SOURCE\\interface\\first_person_weapons.c",
1433,
local_player_index>=0 && local_player_index<MAXIMUM_NUMBER_OF_LOCAL_PLAYERS);
first_person_weapon = &first_person_weapons[local_player_index];
/* port: the last matrices built when the weapon is gone (an effect or
particle on it asking before first_person_weapon_forget_weapon stopped
them was a NULL weapon, and a crash) */
weapon = first_person_weapon->weapon_index!=NONE ? weapon_try_and_get(first_person_weapon->weapon_index) : NULL;
if (!weapon)
{
return &first_person_weapon->node_matrices[
node_index>=0 && node_index<MAXIMUM_NODES_PER_ANIMATION ? node_index : 0];
}
weapon_definition = weapon_definition_get(weapon->definition_index);
animation_graph = animation_graph_definition_get(
weapon_definition->weapon.interface_definition.first_person_animations.index);
match_assert(
"c:\\halo\\SOURCE\\interface\\first_person_weapons.c",
718,
node_index>=0 && node_index<animation_graph->nodes.count);
return &first_person_weapon->node_matrices[node_index];
}
void first_person_weapons_update(
void)
{
short local_player_index;
for (local_player_index=0; local_player_index<MAXIMUM_NUMBER_OF_LOCAL_PLAYERS; local_player_index++)
{
long player_index= local_player_get_player_index(local_player_index);
if (player_index!=NONE)
{
struct first_person_weapon *first_person_weapon= first_person_weapon_get(local_player_index);
long unit_index= player_get(player_index)->unit_index;
if (first_person_weapon->unit_index!=unit_index)
{
first_person_weapon_new_unit(local_player_index, unit_index);
}
if (first_person_weapon->weapon_index==NONE)
{
first_person_weapon_switch_weapons(local_player_index);
}
first_person_weapon_update(local_player_index);
}
}
return;
}
/* ---------- private code */
static void first_person_weapon_set_visibility(
short local_player_index,
boolean visible)
{
struct first_person_weapon *first_person_weapon= first_person_weapon_get(local_player_index);
if (visible!=first_person_weapon->visible)
{
if (visible)
{
match_assert(
"c:\\halo\\SOURCE\\interface\\first_person_weapons.c",
1555,
first_person_weapon->weapon_index!=NONE);
effects_start_on_first_person_weapon(local_player_index, first_person_weapon->weapon_index);
}
else
{
effects_stop_on_first_person_weapon(local_player_index);
particles_stop_on_first_person_weapon(local_player_index);
}
first_person_weapon->visible= visible;
}
return;
}
/* port: the weapon dropped or deleted: hidden first, which stops the effects
and particles that follow it in first person (they asked for the weapon's
nodes, and found none, until the next update switched weapons; the
renderer shows the next weapon again) */
static void first_person_weapon_forget_weapon(
short local_player_index)
{
first_person_weapon_set_visibility(local_player_index, FALSE);
first_person_weapon_get(local_player_index)->weapon_index= NONE;
return;
}
/* port: MCC equipment replacement invalidates the cached weapon before deletion. */
#include "mcc_first_person.inl" /* port: port/linux/game/mcc_first_person.inl */
static void first_person_weapon_predict(
short local_player_index)
{
struct first_person_weapon *first_person_weapon= first_person_weapon_get(local_player_index);
if (first_person_weapon->weapon_index!=NONE)
{
struct weapon_datum *weapon= weapon_get(first_person_weapon->weapon_index);
struct weapon_definition *weapon_definition= weapon_definition_get(weapon->definition_index);
predicted_resources_precache(&weapon_definition->weapon.predicted_resources);
}
first_person_weapon->ticks_until_predict= TICKS_PER_SECOND;
return;
}
static void first_person_weapon_start_interpolation(
short local_player_index,
short frame_count)
{
struct first_person_weapon *first_person_weapon= first_person_weapon_get(local_player_index);
struct weapon_datum *weapon= weapon_get(first_person_weapon->weapon_index);
struct weapon_definition *weapon_definition= weapon_definition_get(weapon->definition_index);
struct animation_graph *animation_graph= animation_graph_definition_get(
weapon_definition->weapon.interface_definition.first_person_animations.index);
/* port: no more nodes than the weapon's orientations hold (a map's count) */
csmemcpy(
first_person_weapon->original_node_orientations,
first_person_weapon->node_orientations,
PIN(animation_graph->nodes.count, 0, MAXIMUM_NODES_PER_ANIMATION)*sizeof(real_orientation));
if (frame_count>=first_person_weapon->interpolation_frame_count-
first_person_weapon->interpolation_frame_index)
{
first_person_weapon->interpolation_frame_index= 0;
first_person_weapon->interpolation_frame_count= frame_count;
}
return;
}
static void first_person_weapon_set_state(
short local_player_index,
short new_state,
boolean reset_sounds)
{
struct first_person_weapon *first_person_weapon= first_person_weapon_get(local_player_index);
if (first_person_weapon->weapon_index!=NONE)
{
struct weapon_datum *weapon= weapon_get(first_person_weapon->weapon_index);
if (TEST_FLAG(weapon->weapon.flags, _weapon_overheated_bit))
{
switch (new_state)
{
case _first_person_weapon_state_ready:
new_state= _first_person_weapon_state_overheating_again;
break;
case _first_person_weapon_state_throw_grenade:
new_state= _first_person_weapon_state_throw_grenade_overheated;
break;
}
}
}
switch (new_state)
{
case _first_person_weapon_state_ready:
if (first_person_weapon->state==_first_person_weapon_state_ready)
{
new_state= NONE;
}
break;
case _first_person_weapon_state_light_off:
case _first_person_weapon_state_light_on:
if (first_person_weapon->state!=_first_person_weapon_state_idle &&
first_person_weapon->state!=_first_person_weapon_state_posing)
{
new_state= NONE;
}
break;
case _first_person_weapon_state_primary_fire:
case _first_person_weapon_state_secondary_fire:
case _first_person_weapon_state_primary_misfire:
case _first_person_weapon_state_secondary_misfire:
if (first_person_weapon->state!=_first_person_weapon_state_idle &&
first_person_weapon->state!=_first_person_weapon_state_posing &&
first_person_weapon->state!=_first_person_weapon_state_primary_fire &&
first_person_weapon->state!=_first_person_weapon_state_charged &&
first_person_weapon->state!=_first_person_weapon_state_shotgun_enter_reload &&
first_person_weapon->state!=_first_person_weapon_state_overheated_exit &&
first_person_weapon->state!=_first_person_weapon_state_shotgun_exit_reload_empty &&
first_person_weapon->state!=_first_person_weapon_state_shotgun_exit_reload_full &&
first_person_weapon->state!=_first_person_weapon_state_reload_while_empty &&
first_person_weapon->state!=_first_person_weapon_state_reload_while_full)
{
new_state= NONE;
}