]> git.jsancho.org Git - lugaru.git/blobdiff - Source/Objects/Person.cpp
Friends help player with its enemies
[lugaru.git] / Source / Objects / Person.cpp
index 2a4d4ae1b9f4e1f320394c3d63547b4e84b426bb..daba2752fd74e8dc7716328b0dc3dd18084a94aa 100644 (file)
@@ -8362,6 +8362,7 @@ void Person::doAI()
                 }
             }
         }
+
         //stunned
         if (aitype == passivetype && !(numwaypoints > 1) ||
             stunned > 0 ||
@@ -8380,6 +8381,32 @@ void Person::doAI()
             throwkeydown = 0;
         }
 
+        if (stunned < 1 && isPlayerFriend()) {
+            // friends follow player
+            if (!Person::players[0]->dead &&
+                distsq(&coords, &Person::players[0]->coords) > 5) {
+                XYZ rotatetarget = Person::players[0]->coords + Person::players[0]->velocity;
+                XYZ targetpoint = Person::players[0]->coords;
+                velocity = (targetpoint - coords);
+                velocity.y += 2;
+                float vellength = findLength(&velocity);
+                if (vellength != 0 &&
+                    distsq(&Person::players[0]->coords, &coords) < distsq(&rotatetarget, &coords)) {
+                    targetpoint += Person::players[0]->velocity *
+                                   findDistance(&Person::players[0]->coords, &coords) / vellength;
+                }
+                targetyaw = roughDirectionTo(coords, targetpoint);
+                lookyaw = targetyaw;
+                forwardkeydown = 1;
+                aitype = pathfindtype;
+            }
+
+            // friends help player with its enemies
+            if (Game::musictype == stream_fighttheme) {
+              aitype = attacktypecutoff;
+            }
+        }
+
         XYZ facing;
         facing = 0;
         facing.z = -1;