Closed VedVid closed 5 years ago
} else if key == blt.TK_TAB {
fmt.Println("targets: ", len(targets))
monster := FindMonsterByXY(targetX, targetY, cs)
if monster != nil {
fmt.Println("monster != nil")
target = NextTarget(monster, targets)
} else {
fmt.Println("monster == nil")
target = NextTarget(target, targets)
}
it returns "targets: 1; monster != nil"
why len(targets) != 2?
MonstersInFov returns proper values
Problematic is MonstersInRange function that returns [] [POINTER] instead of [POINTER] [POINTER]
In MonstersInRange one of monsters is out of range: DistanceBetween(player, monster) > length (that is set to FOVLength, ie 5), but the distance should be 4
Distance is 4 and 6 instead of 3 and 4
Strange is that in close range (ie 2 and 3) results are ok
Source of problems in DistanceBetween?
Interesting: I pressed "F" once, and it seems that DistanceBetween is called 4 times! And with different parameters! at first, it's 3, 3, 6, 3 and 3, 3, 6, 6, then 3, 3, 7, 3 and 3, 3, 7, 7
I should do more tests: DistanceBetween(3, 3, 6, 6) returns ~4,24 instead of 3, and (3, 3, 7, 7) returns ~5,66 instead of 4.
The forumula is OK. The "true" distance between 3, 3 and 6, 6 is 4,24. But in tiles there is 3. Due to clarity, I'd prefer to use 3.
Fixed by 0063f457ecfba657f5984c5b80d0947e3cf3992a but it's ugly and inefficient hack
NextTarget by TK_TAB: usually work well, but in some circumstances it will stuck on one enemy and won't switch to another