The AngleDir8() function is commonly used to set weapon->Dir, but it is inconsistent with unscripted eweapons when it comes to which directions Link can be facing in order to block them when the weapon's angle is close to a multiple of 90 degrees. A more consistent function would be something like this (-180 <= angle <= 180):
I think it would make a good addition to std.zh, though other functions that use AngleDir8() with weapon->Dir would need to be updated to fix the inconsistency.Code:int AngleDir8W(float angle) { if(angle == 0) return DIR_RIGHT; else if(angle == 90) return DIR_DOWN; else if(angle == -90) return DIR_UP; else if(angle == 180 || angle == -180) return DIR_LEFT; else if(angle < -90) return DIR_LEFTUP; else if(angle < 0) return DIR_RIGHTUP; else if(angle < 90) return DIR_RIGHTDOWN; else return DIR_LEFTDOWN; } int RadianAngleDir8W(float angle) { return AngleDir8W(angle*57.2958); }
EDIT: Maybe this could be improved. I'll do some testing with radian values.
EDIT 2: There are going to be roundoff errors when using radians, so I think there should be some tolerance for that with the non-diagonal directions. I'm not sure how much though.