From: Javier Sancho Date: Wed, 21 Feb 2018 15:14:29 +0000 (+0100) Subject: Friends help player with its enemies X-Git-Url: https://git.jsancho.org/?a=commitdiff_plain;h=e069918736630bf740df60442891b66f93b564e9;p=lugaru.git Friends help player with its enemies --- diff --git a/Source/GameTick.cpp b/Source/GameTick.cpp index ed1aed9..c627e51 100644 --- a/Source/GameTick.cpp +++ b/Source/GameTick.cpp @@ -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)) { diff --git a/Source/Objects/Person.cpp b/Source/Objects/Person.cpp index 52c8fc4..daba275 100644 --- a/Source/Objects/Person.cpp +++ b/Source/Objects/Person.cpp @@ -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;