#
# creature_camera.txt
#

#Input variables
#
#default_distance
#min_pitch
#max_pitch
#direction
#distance
#pitch
#yaw
#edge_distance_x
#edge_distance_y
#avatar_speed
#anchor_delta_x
#anchor_delta_y
#mouse_move_x
#mouse_move_y
#in_combat - 0 is no, 1 is yes

#Output variables
#
#default_distance
#min_pitch
#max_pitch
#distance
#pitch
#yaw
#anchor_delta_x
#anchor_delta_y

 default_distance = 20
 min_pitch = 20
 max_pitch = 50

#local vars
 autopitch_min = 20
 autopitch_max = 50
 combatautopitch_min = 40
 combatautopitch_max = 80
 max_distance =  70
 min_distance = 15
 transition_distance = 50


distance = distance - direction*8

if (distance < min_distance)
 distance = min_distance
 if (in_combat == 1) pitch = combatautopitch_min endif
 if (in_combat == 0) pitch = autopitch_min endif

else if (distance > max_distance)
 distance = max_distance
 if (in_combat == 1) pitch = combatautopitch_max endif
 if (in_combat == 0) pitch = autopitch_max endif

else if (distance < transition_distance)
 if (in_combat == 1) pitch = combatautopitch_min endif
 if (in_combat == 0) pitch = autopitch_min endif
 
else
 fraction = (distance-transition_distance)/(max_distance-transition_distance)
 if (in_combat == 1) pitch = combatautopitch_min + (combatautopitch_max-combatautopitch_min) * fraction endif
 if (in_combat == 0) pitch = autopitch_min + (autopitch_max-autopitch_min) * fraction endif
 max_pitch = 90
 min_pitch = 40

endif 
endif
endif


#edge rotation
fraction_x = edge_distance_x/32

if (edge_distance_x > 0 and edge_distance_x < 32)
 yaw = yaw - (1-fraction_x)*3
else if (edge_distance_x < 0 and edge_distance_x > -32)
 yaw = yaw + (fraction_x+1)*3
endif
endif

#move camera behind avatar when avatar is moving
if (avatar_speed > 0)
  yaw = yaw * 0.9
endif