#the goal of this function is to make the forward key ALWAYS correspond to the bulldozer driving straight forward
#easier said than done... this broke my brain temporarily

scoreboard players operation @s math = @s faceDirection

execute if entity @s[scores={left_right=1..}] run tag @s add lr1
execute if entity @s[scores={left_right=..-1}] run tag @s add lrn1
execute if entity @s[scores={up_down=1..}] run tag @s add ud1
execute if entity @s[scores={up_down=..-1}] run tag @s add udn1

#freecam mode is an absolute nightmare for this
execute if entity @s[tag=freecam,scores={rot_yaw=225..314,faceDirection=1}] run scoreboard players set @s math 7
execute if entity @s[tag=freecam,scores={rot_yaw=225..314,faceDirection=3}] run scoreboard players set @s math 1
execute if entity @s[tag=freecam,scores={rot_yaw=225..314,faceDirection=5}] run scoreboard players set @s math 3
execute if entity @s[tag=freecam,scores={rot_yaw=225..314,faceDirection=7}] run scoreboard players set @s math 5

execute if entity @s[tag=freecam,scores={rot_yaw=315..,faceDirection=1}] run scoreboard players set @s math 5
execute if entity @s[tag=freecam,scores={rot_yaw=315..,faceDirection=3}] run scoreboard players set @s math 7
execute if entity @s[tag=freecam,scores={rot_yaw=315..,faceDirection=5}] run scoreboard players set @s math 1
execute if entity @s[tag=freecam,scores={rot_yaw=315..,faceDirection=7}] run scoreboard players set @s math 3

execute if entity @s[tag=freecam,scores={rot_yaw=0..44,faceDirection=1}] run scoreboard players set @s math 5
execute if entity @s[tag=freecam,scores={rot_yaw=0..44,faceDirection=3}] run scoreboard players set @s math 7
execute if entity @s[tag=freecam,scores={rot_yaw=0..44,faceDirection=5}] run scoreboard players set @s math 1
execute if entity @s[tag=freecam,scores={rot_yaw=0..44,faceDirection=7}] run scoreboard players set @s math 3

execute if entity @s[tag=freecam,scores={rot_yaw=45..134,faceDirection=1}] run scoreboard players set @s math 3
execute if entity @s[tag=freecam,scores={rot_yaw=45..134,faceDirection=3}] run scoreboard players set @s math 5
execute if entity @s[tag=freecam,scores={rot_yaw=45..134,faceDirection=5}] run scoreboard players set @s math 7
execute if entity @s[tag=freecam,scores={rot_yaw=45..134,faceDirection=7}] run scoreboard players set @s math 1

#hack our inputs to get the alternate control scheme
execute if score @s math matches 1 run function bd:movement/alternate_control/1
execute if score @s math matches 3 run function bd:movement/alternate_control/3
execute if score @s math matches 5 run function bd:movement/alternate_control/5
execute if score @s math matches 7 run function bd:movement/alternate_control/7

tag @s remove lr1
tag @s remove lrn1
tag @s remove ud1
tag @s remove udn1