mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2024-11-15 16:56:00 -05:00
60 lines
1.7 KiB
Go
60 lines
1.7 KiB
Go
package d2cof
|
|
|
|
type directionCount int
|
|
|
|
const (
|
|
four directionCount = 4 << iota
|
|
eight
|
|
sixteen
|
|
thirtyTwo
|
|
sixtyFour
|
|
)
|
|
|
|
// Dir64ToCof returns the cof direction based on the actual direction
|
|
func Dir64ToCof(direction, numDirections int) int {
|
|
var dir4 = [64]int{
|
|
0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1,
|
|
1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2,
|
|
2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3,
|
|
3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0}
|
|
|
|
var dir8 = [64]int{
|
|
0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2,
|
|
2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4,
|
|
4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6,
|
|
6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 0, 0, 0, 0}
|
|
|
|
var dir16 = [64]int{
|
|
0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4,
|
|
4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8,
|
|
8, 8, 9, 9, 9, 9, 10, 10, 10, 10, 11, 11, 11, 11, 12, 12,
|
|
12, 12, 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 0, 0}
|
|
|
|
var dir32 = [64]int{
|
|
0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8,
|
|
8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16,
|
|
16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 23, 24,
|
|
24, 25, 25, 26, 26, 27, 27, 28, 28, 29, 29, 30, 30, 31, 31, 0}
|
|
|
|
var dir64 = [64]int{
|
|
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
|
|
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
|
|
32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
|
|
48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63}
|
|
|
|
switch directionCount(numDirections) {
|
|
case four:
|
|
return dir4[direction]
|
|
case eight:
|
|
return dir8[direction]
|
|
case sixteen:
|
|
return dir16[direction]
|
|
case thirtyTwo:
|
|
return dir32[direction]
|
|
case sixtyFour:
|
|
return dir64[direction]
|
|
default:
|
|
return 0
|
|
}
|
|
}
|