VedVid / RAWIG

RAWIG (Roguelike Architecture, Written In Go) is ready to modify and expand roguelike architecture.
BSD 2-Clause "Simplified" License
16 stars 3 forks source link

ranged combat #88

Closed VedVid closed 5 years ago

VedVid commented 5 years ago

NextTarget by TK_TAB: usually work well, but in some circumstances it will stuck on one enemy and won't switch to another

image

VedVid commented 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)
            }
VedVid commented 5 years ago

it returns "targets: 1; monster != nil"

why len(targets) != 2?

VedVid commented 5 years ago

MonstersInFov returns proper values
Problematic is MonstersInRange function that returns [] [POINTER] instead of [POINTER] [POINTER]

VedVid commented 5 years ago

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

VedVid commented 5 years ago

Distance is 4 and 6 instead of 3 and 4

VedVid commented 5 years ago

Strange is that in close range (ie 2 and 3) results are ok

VedVid commented 5 years ago

Source of problems in DistanceBetween?

VedVid commented 5 years ago

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

VedVid commented 5 years ago

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.

VedVid commented 5 years ago

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.

VedVid commented 5 years ago

Fixed by 0063f457ecfba657f5984c5b80d0947e3cf3992a but it's ugly and inefficient hack