{$CLEO .cs}

//-------------MAIN---------------
thread 'APCamphibius'
0000: NOP  

// NOTE Heigh in water depend of the '% submerged' in handling.cfg

:AMPHIBI_11
wait 0 
if 
   Player.Defined($PLAYER_CHAR)
else_jump @AMPHIBI_11 
if 
   Actor.DrivingVehicleType($PLAYER_ACTOR, #APC)
else_jump @AMPHIBI_11 
03C0: 5@ = actor $PLAYER_ACTOR car 

:AMPHIBI_58
wait 0 
if 
   Player.Defined($PLAYER_CHAR)
else_jump @AMPHIBI_1170 
if 
   not Car.Wrecked(5@)
else_jump @AMPHIBI_1170 
if 
   Actor.Driving($PLAYER_ACTOR)
else_jump @AMPHIBI_1170 
0407: store_coords_to 11@ 12@ 13@ from_car 5@ with_offset 0.0 0.0 0.0 

// control heigh in water
13@ -= 1.0 
092E: get_water_height_at 11@ 12@ flag 0 store_to 10@ 
if 
  10@ > -100.0 
else_jump @AMPHIBI_58 
if 
0025:   10@ > 13@ // (float) 
else_jump @AMPHIBI_58 

wait 500 
9@ = Car.Angle(5@)
02F6: 11@ = sine 9@ // (float) 
02F7: 12@ = cosine 9@ // (float) 
11@ *= 0.01 
12@ *= 0.01 
11@ *= -1.0 
07D5: set_car 5@ velocity_in_direction_XYZ 11@ 12@ 0.01 rotation_velocitiesXY 0.0 0.0 unk 0.0 

:AMPHIBI_292
wait 20 
if 
   Player.Defined($PLAYER_CHAR)
else_jump @AMPHIBI_1170 
if 
   Actor.Driving($PLAYER_ACTOR)
else_jump @AMPHIBI_1170 
0407: store_coords_to 11@ 12@ 13@ from_car 5@ with_offset 0.0 0.0 0.0 

// control heigh in water
13@ -= 1.0 
092E: get_water_height_at 11@ 12@ flag 0 store_to 10@ 
if 
  10@ > -100.0 
else_jump @AMPHIBI_58 
if 
0025:   10@ > 13@ // (float) 
else_jump @AMPHIBI_58 
9@ = Car.Angle(5@)
if 
00E1:   player 0 pressed_key 16 
else_jump @AMPHIBI_537 
Car.Angle(5@) = 9@
02F6: 11@ = sine 9@ // (float) 
02F7: 12@ = cosine 9@ // (float) 
11@ *= 0.01 
12@ *= 0.01 
11@ *= -1.0 
07D5: set_car 5@ velocity_in_direction_XYZ 11@ 12@ 0.01 rotation_velocitiesXY 0.0 0.0 unk 0.0 
jump @AMPHIBI_733 

:AMPHIBI_537
if 
00E1:   player 0 pressed_key 14 
else_jump @AMPHIBI_656 
9@ = Car.Angle(5@)
9@ += 180.0 
02F6: 11@ = sine 9@ // (float) 
02F7: 12@ = cosine 9@ // (float) 
11@ *= 0.01 
12@ *= 0.01 
11@ *= -1.0 
07D5: set_car 5@ velocity_in_direction_XYZ 11@ 12@ 0.01 rotation_velocitiesXY 0.0 0.0 unk 0.0 
jump @AMPHIBI_733 

:AMPHIBI_656
02F6: 11@ = sine 9@ // (float) 
02F7: 12@ = cosine 9@ // (float) 
11@ *= 0.001 
12@ *= 0.001 
11@ *= -1.0 
07D5: set_car 5@ velocity_in_direction_XYZ 11@ 12@ 0.007 rotation_velocitiesXY 0.0 0.0 unk 0.0 

:AMPHIBI_733
if 
00E1:   player 0 pressed_key 0 
else_jump @AMPHIBI_848 
0494: get_joystick 0 data_to 0@ 1@ 8@ 3@ 
if 
  0@ == 0 
else_jump @AMPHIBI_791 
jump @AMPHIBI_848 

:AMPHIBI_791
if 
  0@ > 0 
else_jump @AMPHIBI_823 
gosub @AMPHIBI_1143 
jump @AMPHIBI_848 

:AMPHIBI_823
if 
  0 > 0@ 
else_jump @AMPHIBI_848 
gosub @AMPHIBI_1123 

:AMPHIBI_848
if 
00E1:   player 0 pressed_key 15 
else_jump @AMPHIBI_292 
Car.LockInCurrentPosition(5@) = True
0633: AS_actor $PLAYER_ACTOR exit_car 

:AMPHIBI_877
wait 0 
if 
   Player.Defined($PLAYER_CHAR)
else_jump @AMPHIBI_1170 
if 
   not Actor.InCar($PLAYER_ACTOR, 5@)
else_jump @AMPHIBI_877 
wait 500 

:AMPHIBI_921
wait 0 
if 
   Player.Defined($PLAYER_CHAR)
else_jump @AMPHIBI_1170 
if 
   not Car.Wrecked(5@)
else_jump @AMPHIBI_1170 
if and
  $ONMISSION == 0 
82BF:   not car 5@ sunk 
0202:   actor $PLAYER_ACTOR near_car 5@ radius 70.0 70.0 flag 0 
else_jump @AMPHIBI_1163 
if 
   Actor.Driving($PLAYER_ACTOR)
else_jump @AMPHIBI_1049 
if 
   Actor.InCar($PLAYER_ACTOR, 5@)
else_jump @AMPHIBI_1163 
Car.LockInCurrentPosition(5@) = False
jump @AMPHIBI_58 

:AMPHIBI_1049
if and
00E1:   player 0 pressed_key 15 
0202:   actor $PLAYER_ACTOR near_car 5@ radius 7.0 7.0 flag 0 
else_jump @AMPHIBI_921 

:AMPHIBI_1086
wait 0 
80E1:   not player 0 pressed_key 15 
else_jump @AMPHIBI_1086 
036A: put_actor $PLAYER_ACTOR in_car 5@ 
wait 500 
jump @AMPHIBI_921 

:AMPHIBI_1123
// degrade speed rotation
9@ += 1.0 
Car.Angle(5@) = 9@
return 

:AMPHIBI_1143
// degrade speed rotation
9@ -= 1.0 
Car.Angle(5@) = 9@
return 

:AMPHIBI_1163
Car.LockInCurrentPosition(5@) = False

:AMPHIBI_1170
Car.RemoveReferences(5@)
jump @AMPHIBI_11 