Colossal
08-31-2011, 11:29 PM
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):
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);
}
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.
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.
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);
}
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.
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.