xyz Okay nice, thanks. I was just about to stop programming for the night because I like ending on a completed problem, but this is something that'll mess around with now. I also realized what I was doing before didn't really matter because there would be effectively 2 if statements being checked, and all I was doing was forcing the 3 good iterations to check 2 extra if statements. I was actually adding more baggage.
Edit:
So, I messed around with what you suggested, I figured out how I'd push them to the stack, however, for the first part I am unsure how to append all the in between hexes into the output array. Currently I store the rotation_cd within the stack in order to check if I can rotate, without that I don't know how to keep track of rotation_cd. Here is what I have..
var stack: Array[Step]
var output: Array[Vector2i]
func push_next_steps(current: Step, ship_rotation):
const directions = [Vector2i(-1,0),Vector2i(0,-1),Vector2i(1,-1),Vector2i(1,0),Vector2i(0,1),Vector2i(-1,1),Vector2i(-1,0),Vector2i(0,-1)]
const face_dir = [null,Vector2(0.5,0),Vector2(0.5,0.5),Vector2(-0.5,0.5),Vector2(-0.5,0),Vector2(-0.5,-0.5),Vector2(0.5,-0.5),null]
const face_dir2 = [Vector2(0.5,-0.5),Vector2(0.5,0),Vector2(0.5,0.5),Vector2(-0.5,0.5),Vector2(-0.5,0),Vector2(-0.5,-0.5),Vector2(0.5,-0.5),Vector2(0.5,0)]
if current.movement_points > 0:
for i in 8:
if i == face_dir.find(current.ship_face):
if current.rotation_cd == ship_rotation:
stack.push_back(Step.new(current.position + directions[i], current.movement_points - 1, current.rotation_cd, current.ship_face))
else:
stack.push_back(Step.new(current.position + directions[i], current.movement_points - 1, current.rotation_cd + 1, current.ship_face))
if i == face_dir.find(current.ship_face) +1 or i == face_dir.find(current.ship_face) -1:
if current.rotation_cd == ship_rotation:
stack.push_back(Step.new(current.position + directions[i], current.movement_points - 1, 1, face_dir2[i]))
return stack
func get_movement_area(start_position: Vector2i, movement_points: int, rotation_cd: int, ship_face: Vector2, ship_rotation: int):
stack = [Step.new(start_position, movement_points, rotation_cd, ship_face)]
while not stack.is_empty():
var current = stack.pop_front()
output.append(current.position)
for next in push_next_steps(current, ship_rotation):
pass
return output