]> git.jsancho.org Git - lugaru.git/blobdiff - Source/Objects/Person.cpp
Friends always follow the player
[lugaru.git] / Source / Objects / Person.cpp
index d0e8f083742ffd22baf8a5b7b864382d29f0af66..52c8fc466975df0dac947d754adbe708fa30aae8 100644 (file)
@@ -169,6 +169,7 @@ Person::Person()
 
     victim(nullptr)
     , hasvictim(false)
+    , isplayerfriend(false)
     ,
 
     updatedelay(0)
@@ -7487,6 +7488,7 @@ void Person::doAI()
 
             if ((!Tutorial::active || cananger) &&
                 hostile &&
+                !isPlayerFriend() &&
                 !Person::players[0]->dead &&
                 distsq(&coords, &Person::players[0]->coords) < 400 &&
                 occluded < 25) {
@@ -7604,7 +7606,7 @@ void Person::doAI()
             //hearing sounds
             if (!Game::editorenabled) {
                 if (howactive <= typesleeping) {
-                    if (numenvsounds > 0 && (!Tutorial::active || cananger) && hostile) {
+                  if (numenvsounds > 0 && (!Tutorial::active || cananger) && !isPlayerFriend() && hostile) {
                         for (int j = 0; j < numenvsounds; j++) {
                             float vol = howactive == typesleeping ? envsoundvol[j] - 14 : envsoundvol[j];
                             if (vol > 0 && distsq(&coords, &envsound[j]) < 2 * (vol + vol * (creature == rabbittype) * 3)) {
@@ -7624,6 +7626,7 @@ void Person::doAI()
 
             if (howactive < typesleeping &&
                 ((!Tutorial::active || cananger) && hostile) &&
+                !isPlayerFriend() &&
                 !Person::players[0]->dead &&
                 distsq(&coords, &Person::players[0]->coords) < 400 &&
                 occluded < 25) {
@@ -7802,7 +7805,7 @@ void Person::doAI()
                 jumpkeydown = 1;
             }
 
-            if (numenvsounds > 0 && ((!Tutorial::active || cananger) && hostile)) {
+            if (numenvsounds > 0 && ((!Tutorial::active || cananger) && !isPlayerFriend() && hostile)) {
                 for (int k = 0; k < numenvsounds; k++) {
                     if (distsq(&coords, &envsound[k]) < 2 * (envsoundvol[k] + envsoundvol[k] * (creature == rabbittype) * 3)) {
                         aitype = attacktypecutoff;
@@ -7811,6 +7814,7 @@ void Person::doAI()
             }
 
             if (!Person::players[0]->dead &&
+                !isPlayerFriend() &&
                 losupdatedelay < 0 &&
                 !Game::editorenabled &&
                 occluded < 2 &&
@@ -7996,7 +8000,7 @@ void Person::doAI()
 
                 lastseentime = 12;
 
-                if (!Person::players[0]->dead && ((!Tutorial::active || cananger) && hostile)) {
+                if (!Person::players[0]->dead && !isPlayerFriend() && ((!Tutorial::active || cananger) && hostile)) {
                     if (ally < 0 || hasWeapon() || lastchecktime <= 0) {
                         aitype = attacktypecutoff;
                         lastseentime = 1;
@@ -8358,6 +8362,7 @@ void Person::doAI()
                 }
             }
         }
+
         //stunned
         if (aitype == passivetype && !(numwaypoints > 1) ||
             stunned > 0 ||
@@ -8376,6 +8381,27 @@ void Person::doAI()
             throwkeydown = 0;
         }
 
+        // friends follow player
+        if (stunned < 1 &&
+            isPlayerFriend() &&
+            !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 = searchtype;
+        }
+
         XYZ facing;
         facing = 0;
         facing.z = -1;
@@ -8389,6 +8415,9 @@ void Person::doAI()
         } else if (howactive >= typesleeping) {
             targetheadyaw = targetyaw;
             targetheadpitch = 0;
+        } else if (isPlayerFriend()) {
+            targetheadyaw = 180 - roughDirectionTo(coords, Person::players[0]->coords);
+            targetheadpitch = pitchTo(coords, Person::players[0]->coords);
         } else {
             if (interestdelay <= 0) {
                 interestdelay = .7 + (float)(abs(Random() % 100)) / 100;