]> git.jsancho.org Git - lugaru.git/commitdiff
AI: Prevent division by 0 when enemy has no velocity
authorRémi Verschelde <rverschelde@gmail.com>
Sat, 28 Jan 2017 14:26:00 +0000 (15:26 +0100)
committerRémi Verschelde <rverschelde@gmail.com>
Sat, 28 Jan 2017 14:33:20 +0000 (15:33 +0100)
Fixes #45.

Source/Objects/Person.cpp

index 7f279de859696dee81965ddddcb5b369c65c695e..1ac664c896b2dab753eab5890b0e4ce61d7e9715 100644 (file)
@@ -8451,8 +8451,8 @@ void Person::doAI()
                 //chase player
                 XYZ rotatetarget = Person::players[0]->coords + Person::players[0]->velocity;
                 XYZ targetpoint = Person::players[0]->coords;
-                if (distsq(&Person::players[0]->coords, &coords) <
-                    distsq(&rotatetarget, &coords)) {
+                if (findLength(&velocity) != 0 &&
+                    distsq(&Person::players[0]->coords, &coords) < distsq(&rotatetarget, &coords)) {
                     targetpoint += Person::players[0]->velocity *
                                    findDistance(&Person::players[0]->coords, &coords) / findLength(&velocity);
                 }