]> git.jsancho.org Git - lugaru.git/commitdiff
Friends help player with its enemies
authorJavier Sancho <jsf@jsancho.org>
Wed, 21 Feb 2018 15:14:29 +0000 (16:14 +0100)
committerJavier Sancho <jsf@jsancho.org>
Wed, 21 Feb 2018 15:14:29 +0000 (16:14 +0100)
Source/GameTick.cpp
Source/Objects/Person.cpp

index ed1aed93a4c4ed8ff8a0652efbf8234c5120a20d..c627e514765cd71dcdff4a7d741f3b501d2f0ea3 100644 (file)
@@ -2193,7 +2193,23 @@ void doAttacks()
         }
         if (Person::players[k]->animTarget != rabbitrunninganim && Person::players[k]->animTarget != wolfrunninganim) {
             if (!Person::players[k]->isPlayerControlled()) {
-                Person::players[k]->victim = Person::players[0];
+                if (Person::players[k]->isPlayerFriend()) {
+                    bool found = false;
+                    for (unsigned k2 = 1; k2 < Person::players.size(); k2++) {
+                        if (k != k2 &&
+                            !Person::players[k2]->dead &&
+                            Person::players[k2]->aitype == attacktypecutoff) {
+                            Person::players[k]->victim = Person::players[k2];
+                            found = true;
+                            break;
+                        }
+                    }
+                    if (!found) {
+                        Person::players[k]->attackkeydown = 0;
+                    }
+                } else {
+                    Person::players[k]->victim = Person::players[0];
+                }
             }
             //attack key pressed
             if (Person::players[k]->attackkeydown) {
@@ -4487,6 +4503,7 @@ void Game::TickOnceAfter()
                  Person::players[i]->aitype == gethelptype ||
                  Person::players[i]->aitype == searchtype) &&
                 !Person::players[i]->dead &&
+                !Person::players[i]->isPlayerFriend() &&
                 (Person::players[i]->animTarget != sneakattackedanim &&
                  Person::players[i]->animTarget != knifesneakattackedanim &&
                  Person::players[i]->animTarget != swordsneakattackedanim)) {
index 52c8fc466975df0dac947d754adbe708fa30aae8..daba2752fd74e8dc7716328b0dc3dd18084a94aa 100644 (file)
@@ -8381,25 +8381,30 @@ 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;
+        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;