-
Notifications
You must be signed in to change notification settings - Fork 11
/
Car_Behaviour.cpp
executable file
·4439 lines (3505 loc) · 125 KB
/
Car_Behaviour.cpp
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
/**************************************************************************
Car Behaviour.cpp - Functions relating to player's car behaviour
NOTE: Best to always start a car off on a straight (non-diagonal) piece
NOTE: All statics and globals that have been initialised will need to be
reinitialised when the car is repositioned on the track (e.g. at
start of race and when put back on track after coming off)
NOTE: player_x and player_z are in PC StuntCarRacer format
player_y is currently in Amiga StuntCarRacer format
Angles have the same magnitude but are unsigned.
And sin/cos/tan also need alteration (divide by 2)
/* OUTSTANDING ISSUES / IMPROVEMENTS :-
1. SOME FUNCTIONS CONTAIN LOGIC THAT IS DEPENDANT UPON THE ORDER THAT THE
TRACK PIECES ARE STORED IN (I.E. WHETHER THE PIECE NUMBERS INCREMENT
AROUND THE TRACK IN A CLOCKWISE OR ANTI-CLOCKWISE MANNER)
LINES THAT HAVE ALREADY BEEN IDENTIFIED HAVE THE COMMENT :-
// DIRECTION DEPENDANT
- NEED TO IMPLEMENT A TRACK DIRECTION VALUE (1 OR -1) THAT IS EITHER
STORED WITH THE TRACK DEFINITION OR CALCULATED AT THE START OF A RACE.
THE LOGIC WOULD THEN USE THIS VALUE RATHER THAN JUST ADDING OR
SUBTRACTING 1.
**************************************************************************/
/*
* Unfortunately these HIGHER_FRAME_RATE changes didn't work...
*
//#define HIGHER_FRAME_RATE // to cater for four times frame rate
// 10/12/1998 - engine_z_acceleration not now reduced (to enable car to jump as before)
// - could try limiting the top speed instead (should be better)
// or try REDUCTION of 202, INCREASE of 306
*/
/* ============= */
/* Include files */
/* ============= */
#include "dxstdafx.h"
#include <stdlib.h>
#include "StuntCarRacer.h"
#include "Car_Behaviour.h"
#include "Opponent_Behaviour.h"
#include "Track.h"
#include "3D_Engine.h"
#include "XBOXController.h"
/* ===== */
/* Debug */
/* ===== */
//#define USE_AMIGA_RECORDING
//#define TEST_AMIGA_UER
//#define PLAY_AMIGA_RECORDING
#if defined(DEBUG) || defined(_DEBUG)
extern FILE *out;
extern bool bTestKey;
#endif
/* ========= */
/* Constants */
/* ========= */
#ifndef linux
#define FALSE 0
#define TRUE 1
#endif
#define MAX_AMIGA_VOLUME 64
#define DIRECTX_VOLUME_FACTOR 100 // Volume units are in hundredths of decibels
// car behaviour definitions
#define GRAVITY_ACCELERATION 317 // used to be called CAR_WEIGHT
#define ROAD_WIDTH 0x0180
#define SURFACE_SIZE 1024 // used when interpolating (Amiga StuntCarRacer used 256, but 1024 is smoother!)
#define LOG_SURFACE_SIZE 10 // to base 2
#define OFF_ROAD_HEIGHT 0x1000
#define OFF_TRACK_LIMIT 64 // count after which player is put back on track
#define WRECKED (wreck_wheel_height_reduction != 0)
#define NOT_WRECKED (wreck_wheel_height_reduction == 0)
#define LOCAL_Y_FACTOR 4
/* =========== */
/* Global data */
/* =========== */
long player_current_piece = 0; // use as players_road_section
long player_current_segment = 0;
long players_distance_into_section = 0;
long players_road_x_position = 0;
long rear_wheel_surface_x_position = 0;
bool drop_start_done = TRUE;
long touching_road = FALSE;
long player_y;
long player_z_speed = 0;
long front_left_damage = 0,
front_right_damage = 0,
rear_damage = 0;
long damaged = 0;
long new_damage = 0;
long nholes = 0;
long car_collision_x_acceleration,
car_collision_y_acceleration,
car_collision_z_acceleration;
long boostReserve = 0, boostUnit = 0;
long playerLapNumber;
static CXBOXController P1Controller(1);
#if defined(DEBUG) || defined(_DEBUG)
//long CCPIECE, CCSEGMENT, CCSURFACEX, CCSURFACEZ;
bool debug_position = FALSE;
#endif
extern IDirectSoundBuffer8 *WreckSoundBuffer;
extern IDirectSoundBuffer8 *GroundedSoundBuffer;
extern IDirectSoundBuffer8 *CreakSoundBuffer;
extern IDirectSoundBuffer8 *SmashSoundBuffer;
extern IDirectSoundBuffer8 *OffRoadSoundBuffer;
extern bool bSuperLeague;
/* =========== */
/* Static data */
/* =========== */
static long player_x,
player_z;
static long player_x_angle = 0,
player_y_angle = 0,
player_z_angle = 0;
static long player_world_x_speed = 0,
player_world_y_speed = 0,
player_world_z_speed = 0;
static long player_x_speed = 0,
player_y_speed = 0;
static long accelerate, brake;
static long accelerating = FALSE; // to remember previous control state
long engine_power = 240; // (240 standard, 320 super)
long boost_unit_value = 16; // (16 standard, 12 super)
static long left_right_value;
static long engine_z_acceleration;
/*static*/ long boost_activated;
static long rear_wheel_x_offset, rear_wheel_z_offset;
static long front_left_wheel_x_offset, front_left_wheel_z_offset;
static long front_right_wheel_x_offset, front_right_wheel_z_offset;
static long front_left_road_height = OFF_ROAD_HEIGHT;
static long front_right_road_height = OFF_ROAD_HEIGHT;
static long rear_road_height = OFF_ROAD_HEIGHT;
// wheel heights
static long front_left_actual_height;
static long front_right_actual_height;
static long rear_actual_height;
static long off_left, off_right;
static long wheel_off_road, distance_off_road;
static long at_side_byte, which_side_byte;
static long smaller_limit_required = FALSE;
static long wreck_wheel_height_reduction = 0; // 0x200 if wrecked
// set the on_chains flag to FALSE for now (won't implement chains at first)
static long on_chains = FALSE;
static long player_distance_off_road; // used to determine the value below
static long off_map_status = 0; // not set exactly like Amiga StuntCarRacer
static long off_track_count = 0;
static long gravity_x_acceleration,
gravity_y_acceleration,
gravity_z_acceleration;
static long grounded_delay = 0;
static long grounded_count = 0;
static long damage_value = 0;
static long damaged_count = 0;
long front_left_amount_below_road = 0,
front_right_amount_below_road = 0,
rear_amount_below_road = 0;
long front_left_wheel_speed = 0,
front_right_wheel_speed = 0;
long leftwheel_angle = 0, rightwheel_angle = 0;
static long old_front_left_difference = 0,
old_front_right_difference = 0,
old_rear_difference = 0;
static long smashed_countdown = 0;
static long car_to_road_collision_z_acceleration;
static long player_x_acceleration,
player_y_acceleration,
player_z_acceleration;
static long total_world_x_acceleration,
total_world_y_acceleration,
total_world_z_acceleration;
static long player_x_rotation_speed = 0,
player_y_rotation_speed = 0,
player_z_rotation_speed = 0;
static long player_final_x_rotation_speed,
player_final_y_rotation_speed,
player_final_z_rotation_speed;
static long player_x_rotation_acceleration,
player_y_rotation_acceleration,
player_z_rotation_acceleration;
static long Replay = FALSE, ReplayRequested = FALSE, ReplayLooping = FALSE, ReplayFinished = FALSE;
#ifdef USE_AMIGA_RECORDING
static bool ReplayAmigaRecording = FALSE;
static bool StartOfAmigaRecording = FALSE;
static long AmigaRecordingFrame = 0;
#endif
/* ===================== */
/* Function declarations */
/* ===================== */
static void CarControl (DWORD input);
static void BoostPower (long boost_flag,
long accelerate,
long brake);
static void CarMovement (void);
static long GetPieceUsingMap (long x, long z, long *piece_out);
static void CalcXZRelativeToPiece (long x, long z, long piece, long *rx_out, long *rz_out);
static void CalculateWheelXZOffsets (void);
static void CalculateRoadWheelHeights (void);
static void CalculateRoadWheelHeight (long height, long *height_out);
static void CalculateIfCarOffRoad (long *height);
static void CalculateWorldRoadHeight (long wheel, long x, long z, long *y_out);
static void GetSurfaceCoords (long piece, long segment);
static long CalcDistanceOffRoad (long x, long z,
long ox, long oz,
long ux, long uz,
long vx, long vz,
long *ex, long *ez);
static void CalcSurfacePosition (long piece,
long x, long z,
long ox, long oz,
long ux, long uz,
long vx, long vz,
long *sx, long *sz,
long *road_x,
long *segment_out);
static void CalculateActualWheelHeights (void);
static void CalculateXZSpeeds (void);
static void CalculateGravityAcceleration (void);
static void CarCollisionDetection (void);
static void CalculateWheelCollision (long road_height,
long actual_height,
long *height_difference_out,
long *old_difference_in_out,
long *amount_below_road_in_out,
long *damage_in_out);
static void CalculateCarCollisionAcceleration (long average_amount_below_road);
static void CalculateInclinationSinCos (long inclination_in,
long *inclination_sin_out,
long *inclination_cos_out);
static void LiftCarOntoTrack (void);
static void CalculateTotalAcceleration (void);
static long GetTwiceCollisionYAcceleration (void);
static void CalculateXAcceleration (void);
static void CalculateSteering (void);
static void CalculateSteeringAcceleration (long steering_amount);
static void AlignCarWithRoad (void);
static void AdjustSteeringAcceleration (void);
static void IdentifyPiece (long x, long z, long *piece_in_out);
static void GetPieceCoords (long piece);
static void CalculateWorldAcceleration (void);
static void ReduceWorldAcceleration (void);
static void CalculateXZRotationAcceleration (void);
static void UpdatePlayersRotationSpeed (void);
static void CalculateFinalRotationSpeed (void);
static void UpdatePlayersWorldSpeed (void);
static void UpdatePlayersPosition (void);
static long CalcSectionYAngle (long piece,
long x,
long z);
static void CalcCurveMeasurements (long piece,
long x,
long z,
long *y_angle_out,
long *radius_out,
double *distance_from_centre_out);
static void PositionCarAbovePiece (long piece);
static void UpdateEngineRevs (void);
static void DrawDustClouds (void);
static void DrawSparks (void);
static void SetWheelRotationSpeed();
#ifdef NOT_USED
static void RewindRecording (void);
static void Record (DWORD input);
static void PlayBack (DWORD *input);
static void ReadRecordedFile (void);
#endif
#ifdef USE_AMIGA_RECORDING
static bool OpenAmigaRecording( void );
#endif
/* ======================================================================================= */
/* Function: ResetPlayer */
/* */
/* Description: Reset all car behaviour variables to their initial state */
/* ======================================================================================= */
void ResetPlayer (void)
{
// resets almost everything at the moment, just to make sure
player_x = 0;
player_y = 0;
player_z = 0;
player_x_angle = 0;
player_y_angle = 0;
player_z_angle = 0;
player_world_x_speed = 0;
player_world_y_speed = 0;
player_world_z_speed = 0;
// calculated
player_x_speed = 0;
player_y_speed = 0;
player_z_speed = 0;
accelerating = FALSE;
engine_power = (bSuperLeague)?320:240; // (240 standard, 320 super)
boost_unit_value = (bSuperLeague)?12:16; // (16 standard, 12 super)
// calculated
left_right_value = 0;
engine_z_acceleration = 0;
boost_activated = 0;
// calculated
rear_wheel_x_offset = 0, rear_wheel_z_offset = 0;
front_left_wheel_x_offset = 0, front_left_wheel_z_offset = 0;
front_right_wheel_x_offset = 0, front_right_wheel_z_offset = 0;
front_left_road_height = OFF_ROAD_HEIGHT;
front_right_road_height = OFF_ROAD_HEIGHT;
rear_road_height = OFF_ROAD_HEIGHT;
// calculated
front_left_actual_height = 0;
front_right_actual_height = 0;
rear_actual_height = 0;
// calculated
off_left = 0, off_right = 0;
wheel_off_road = 0, distance_off_road = 0;
at_side_byte = 0, which_side_byte = 0;
smaller_limit_required = FALSE;
wreck_wheel_height_reduction = 0; // 0x200 if wrecked
drop_start_done = TRUE;
touching_road = FALSE;
// set the on_chains flag to FALSE for now (won't implement chains at first)
on_chains = FALSE;
// calculated
player_distance_off_road = 0;
off_map_status = 0;
//off_track_count = 0; // now done in CarBehaviour
// calculated
gravity_x_acceleration = 0;
gravity_y_acceleration = 0;
gravity_z_acceleration = 0;
grounded_delay = 0;
// calculated
grounded_count = 0;
damage_value = 0;
damaged_count = 0;
damaged = 0;
front_left_amount_below_road = 0;
front_right_amount_below_road = 0;
rear_amount_below_road = 0;
old_front_left_difference = 0;
old_front_right_difference = 0;
old_rear_difference = 0;
front_left_damage = 0;
front_right_damage = 0;
rear_damage = 0;
new_damage = 0;
smashed_countdown = 0;
nholes = 0;
// calculated
car_collision_x_acceleration = 0;
car_collision_y_acceleration = 0;
car_collision_z_acceleration = 0;
car_to_road_collision_z_acceleration = 0;
// calculated
player_x_acceleration = 0;
player_y_acceleration = 0;
player_z_acceleration = 0;
// calculated
total_world_x_acceleration = 0;
total_world_y_acceleration = 0;
total_world_z_acceleration = 0;
player_x_rotation_speed = 0;
player_y_rotation_speed = 0;
player_z_rotation_speed = 0;
// calculated
player_final_x_rotation_speed = 0;
player_final_y_rotation_speed = 0;
player_final_z_rotation_speed = 0;
// calculated
player_x_rotation_acceleration = 0;
player_y_rotation_acceleration = 0;
player_z_rotation_acceleration = 0;
return;
}
/* ======================================================================================= */
/* Function: CarBehaviour */
/* */
/* Description: */
/* ======================================================================================= */
// eventually make access functions for the following, remove extern definitions
extern bool bNewGame;
extern long TrackID;
extern TRACK_PIECE Track[MAX_PIECES_PER_TRACK];
extern long Track_Map[NUM_TRACK_CUBES][NUM_TRACK_CUBES]; // [x][z]
extern long NumTrackPieces;
extern long PlayersStartPiece;
extern long StartLinePiece;
extern long HalfALapPiece;
long INITIALISE_PLAYER = TRUE;
void CarBehaviour (DWORD input,
long *x,
long *y,
long *z,
long *x_angle,
long *y_angle,
long *z_angle)
{
static long first_time = TRUE;
// temporarily set player values to values provided when required
if (INITIALISE_PLAYER)
{
INITIALISE_PLAYER = FALSE;
if (! Replay)
{
player_x = *x;
player_y = -(*y / LOCAL_Y_FACTOR);
player_z = *z;
player_x_angle = (*x_angle);
player_y_angle = (*y_angle);
player_z_angle = (*z_angle);
}
}
// reset player and control action replay as required
if ((off_track_count > OFF_TRACK_LIMIT) ||
(bNewGame) ||
(ReplayRequested))
{
ResetPlayer();
if (bNewGame || ReplayRequested)
{
// reset all animated objects
ResetDrawBridge();
ReplayFinished = FALSE;
}
if (off_track_count > OFF_TRACK_LIMIT)
{
PositionCarAbovePiece(player_current_piece);
}
else
{
PositionCarAbovePiece(PlayersStartPiece);
}
drop_start_done = FALSE;
if (bNewGame)
{
// reset action replay recording
// Replay = FALSE;
// RewindRecording();
#ifdef USE_AMIGA_RECORDING
CloseAmigaRecording(); // So that play will start from beginning
ReplayAmigaRecording = TRUE;
#endif
}
#ifdef NOT_USED
if (ReplayRequested)
{
// begin action replay if requested
Replay = TRUE;
}
#endif
off_track_count = 0;
// ReplayRequested = FALSE;
}
//VALUE1 = Replay;
#ifdef NOT_USED
// replay doesn't currently work on DrawBridge - doesn't know starting DrawBridge frame
if (ReplayFinished)
{
if (ReplayLooping)
{
RewindRecording();
ReplayRequested = TRUE;
}
return;
}
if (! Replay)
{
Record(input);
}
else
{
// override user input with recorded value
PlayBack(&input);
}
#endif
CarControl(input);
CarMovement();
UpdateEngineRevs();
if (touching_road) drop_start_done = TRUE; // Amiga StuntCarRacer does this differently
// output player values for use by functions that draw the world
*x = player_x;
*y = -(player_y * LOCAL_Y_FACTOR);
*z = player_z;
// following checks angles don't exceed limits
*x_angle = (player_x_angle & (MAX_ANGLE - 1));
*y_angle = (player_y_angle & (MAX_ANGLE - 1));
*z_angle = (player_z_angle & (MAX_ANGLE - 1));
// Reverse x and z angle because StuntCarRacer's DrawWorld rotates around x and z in
// the opposite direction to the trig. coefficients calculated by StuntCarRacer's
// CarBehaviour (i.e. clockwise becomes anti-clockwise or vice-versa)
*x_angle = (-player_x_angle & (MAX_ANGLE - 1));
*z_angle = (-player_z_angle & (MAX_ANGLE - 1));
first_time = FALSE;
//VALUE1++; // frame counter
}
/* ======================================================================================= */
/* Function: LimitViewpointY */
/* */
/* Description: Limit viewpoint Y value to prevent it going below or too close to road */
/* (i.e. prevent road 'tearing') */
/* ======================================================================================= */
#define Y_ADJUSTMENT_THRESHOLD 0x480
void LimitViewpointY (long *y)
{
long saved_player_z_speed = player_z_speed;
short sin_x, cos_x;
short sin_z, cos_z;
long ry = 0, ly = 0;
// VALUE1 = (bTestKey ? 1 : 0);
// calculate required sin.cos values using player x, y and z angles
CalcYXZTrigCoefficients(player_x_angle,
player_y_angle,
player_z_angle);
player_z_speed = 0xA00; // prevent CalculateRoadWheelHeight from averaging current and previous heights
CalculateWheelXZOffsets();
CalculateRoadWheelHeights();
CalculateActualWheelHeights();
player_z_speed = saved_player_z_speed; // restore original value
/*
VALUE1 = front_left_road_height;
VALUE2 = front_left_actual_height;
VALUE3 = front_left_road_height - front_left_actual_height;
*/
/*
VALUE1 = front_right_road_height;
VALUE2 = front_right_actual_height;
VALUE3 = front_right_road_height - front_right_actual_height;
*/
GetSinCos(player_x_angle, &sin_x, &cos_x); // cosine not used
GetSinCos(player_z_angle, &sin_z, &cos_z); // cosine not used
// VALUE1 = player_y;
// VALUE1 = front_right_road_height - front_right_actual_height;
// VALUE2 = VALUE3 = 0;
if ((front_right_road_height - front_right_actual_height) > Y_ADJUSTMENT_THRESHOLD)
{
// Use the CalculateActualWheelHeights() calculations in reverse, with road height, to calculate adjusted player_y
/*
front_right_actual_height = player_y;
front_right_actual_height += ((long)sin_x << (4+15-LOG_PRECISION));
front_right_actual_height -= ((long)sin_z << (3+15-LOG_PRECISION));
front_right_actual_height >>= 8;
*/
#if 0
if (bTestKey)
ry = front_right_road_height << 8;
else
#endif
ry = (front_right_road_height - Y_ADJUSTMENT_THRESHOLD) << 8;
ry += ((long)sin_z << (3+15-LOG_PRECISION));
ry -= ((long)sin_x << (4+15-LOG_PRECISION));
// VALUE2 = ry;
}
// VALUE1 = front_left_road_height - front_left_actual_height;
// VALUE2 = VALUE3 = 0;
if ((front_left_road_height - front_left_actual_height) > Y_ADJUSTMENT_THRESHOLD)
{
// Use the CalculateActualWheelHeights() calculations in reverse, with road height, to calculate adjusted player_y
/*
front_left_actual_height = player_y;
front_left_actual_height += ((long)sin_x << (4+15-LOG_PRECISION));
front_left_actual_height += ((long)sin_z << (3+15-LOG_PRECISION));
front_left_actual_height >>= 8;
*/
#if 0
if (bTestKey)
ly = front_left_road_height << 8;
else
#endif
ly = (front_left_road_height - Y_ADJUSTMENT_THRESHOLD) << 8;
ly -= ((long)sin_z << (3+15-LOG_PRECISION));
ly -= ((long)sin_x << (4+15-LOG_PRECISION));
// VALUE3 = ly;
}
if (ry)
{
if (ly)
{
*y = -(((ry + ly) * LOCAL_Y_FACTOR) / 2); // use average of two values
// VALUE1 = 1;
}
else
{
*y = -(ry * LOCAL_Y_FACTOR);
// VALUE1 = 2;
}
}
else if (ly)
{
*y = -(ly * LOCAL_Y_FACTOR);
// VALUE1 = 3;
}
}
/*
// Old method...
// 19/09/2007 attempt to limit player_y to prevent road disappearing. Doesn't work completely on Draw Bridge track
long front_road_height = (front_left_road_height + front_right_road_height) << (8-1);
// long front_road_height = 0;
VALUE1 = player_y;
VALUE2 = front_road_height;
if (player_y > front_road_height)
{
//*y = -(player_y * LOCAL_Y_FACTOR);
VALUE3 = 0;
}
else
{
*y = -(front_road_height * LOCAL_Y_FACTOR);
VALUE3 = 1;
}
*/
/* ======================================================================================= */
/* Function: CarControl */
/* */
/* Description: */
/* ======================================================================================= */
static void CarControl (DWORD input)
{
// Keys that control car are :-
// Left = left, Right = right
// Up = Accelerate, Down = Brake
// (X) = Accelerate, (B) = Brake on Pandora
// SPACE = boost
// (R) = boost on Pandora
//
// Note: Can't accelerate without boost when using keyboard,
// because HASH key is changed to be brake - see below
long left = (input & KEY_P1_LEFT),
right = (input & KEY_P1_RIGHT),
boost = (input & KEY_P1_BOOST);
accelerate = (input & KEY_P1_ACCEL);
brake = (input & KEY_P1_BRAKE);
// if none of the resulting keys are pressed then read joystick
#ifdef linux
#warning TODO
#else
if( !input )
{
if(P1Controller.IsConnected())
{
// easier to read...
const XINPUT_GAMEPAD &pad = P1Controller.GetState().Gamepad;
if(pad.bRightTrigger)
{
accelerate = TRUE;
}
if(pad.wButtons & XINPUT_GAMEPAD_A)
{
boost = TRUE;
}
if(pad.wButtons & XINPUT_GAMEPAD_B || pad.bLeftTrigger)
{
brake = TRUE; // select brake
accelerate = FALSE;
}
if( abs(pad.sThumbLX) > XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE )
{
(pad.sThumbLX < 0) ? (left = TRUE) : (right = TRUE);
}
}
}
#endif
left_right_value = 0;
if ((touching_road) && (! on_chains))
{
if (left)
left_right_value = -15;
if (right)
left_right_value = 15;
}
long boost_flag; // active low
if (boost)
boost_flag = FALSE;
else
boost_flag = TRUE;
if ((player_z_speed < 120*256) && (! on_chains) && (NOT_WRECKED))
{
if (accelerate)
{
engine_z_acceleration = engine_power;
accelerating = TRUE;
}
else
if (brake)
{
engine_z_acceleration = -240;
accelerating = FALSE;
}
else
if (accelerating)
{
// car keeps accelerating even when control released
engine_z_acceleration = engine_power;
accelerating = TRUE; // already TRUE
}
else
engine_z_acceleration = 0;
}
else
engine_z_acceleration = 0;
BoostPower(boost_flag,
accelerate,
brake);
#ifdef PLAY_AMIGA_RECORDING
GetRecordedAmigaWord(&left_right_value);
GetRecordedAmigaWord(&engine_z_acceleration);
//VALUE1 = engine_z_acceleration;
#endif
return;
}
static void BoostPower (long boost_flag,
long accelerate,
long brake)
{
boost_activated = 0;
if ((! boost_flag) && (NOT_WRECKED))
{
if (accelerating || (accelerate || brake))
{
if (boostReserve > 0)
{
--boostUnit;
if (boostUnit < 0)
{
boostUnit = boost_unit_value;
--boostReserve;
}
boost_activated = 0x80;
engine_z_acceleration *= 2;
}
}
}
return;
}
/* ======================================================================================= */
/* Function: CarMovement */
/* */
/* Description: */
/* ======================================================================================= */
static void CarMovement (void)
{
// currently uses player_x/y/z and player_x/y/z_angle
//calculate required sin.cos values using player x, y and z angles
CalcYXZTrigCoefficients(player_x_angle,
player_y_angle,
player_z_angle);
//fprintf(out, "player_x_angle %d\n", player_x_angle);
//fprintf(out, "player_y_angle %d\n", player_y_angle);
//fprintf(out, "player_z_angle %d\n", player_z_angle);
CalculateWheelXZOffsets();
CalculateRoadWheelHeights();
CalculateActualWheelHeights();
CalculateXZSpeeds();
SetWheelRotationSpeed();
CalculateGravityAcceleration();
CarCollisionDetection();
//if (B.1bb72 != 0) // always set
{
CalculateTotalAcceleration();
CalculateSteering();
CalculateWorldAcceleration();
ReduceWorldAcceleration();
CalculateXZRotationAcceleration();
UpdatePlayersRotationSpeed();
CalculateFinalRotationSpeed();
}
UpdatePlayersWorldSpeed();
UpdatePlayersPosition();
#ifdef PLAY_AMIGA_RECORDING
if (StartOfAmigaRecording)
{
GetRecordedAmigaLong(&player_x); player_x *= (PC_FACTOR * 4);
GetRecordedAmigaLong(&player_y);
GetRecordedAmigaLong(&player_z); player_z *= (PC_FACTOR * 4);
GetRecordedAmigaWord(&player_x_angle);
GetRecordedAmigaWord(&player_y_angle);
GetRecordedAmigaWord(&player_z_angle);
++AmigaRecordingFrame;
if (AmigaRecordingFrame > 0)
StartOfAmigaRecording = FALSE;
}
else
{
// throw values away
long temp;
GetRecordedAmigaLong(&temp);
GetRecordedAmigaLong(&temp);
GetRecordedAmigaLong(&temp);
GetRecordedAmigaWord(&temp);
GetRecordedAmigaWord(&temp);
GetRecordedAmigaWord(&temp);
}
#endif
// 23/08/1998 - extra bit to set flags
if (player_distance_off_road >= (256-ROAD_WIDTH/2))
{
off_map_status = 0x80;
}
else
{
off_map_status = 0;
off_track_count = 0;
smaller_limit_required = FALSE;
}
if ((off_map_status != 0) && (touching_road) && (player_y < 0x1000000))
{
off_track_count++;
smaller_limit_required = TRUE;
}
//VALUE1 = player_z_speed;
//VALUE1 = player_current_piece;
//VALUE1 = Track[player_current_piece].coords[0].y;
//long temp = Track[player_current_piece].numSegments;
//VALUE2 = Track[player_current_piece].coords[(temp*4)].y;