From d67f3dc0e14c195e650e732e8477c1ac4085e9de Mon Sep 17 00:00:00 2001 From: Javier Sancho Date: Wed, 21 Feb 2018 16:33:44 +0100 Subject: [PATCH] Use victim to attack, not player 0 --- Source/Objects/Person.cpp | 134 +++++++++++++++++++------------------- 1 file changed, 67 insertions(+), 67 deletions(-) diff --git a/Source/Objects/Person.cpp b/Source/Objects/Person.cpp index daba275..5a735c3 100644 --- a/Source/Objects/Person.cpp +++ b/Source/Objects/Person.cpp @@ -7333,9 +7333,9 @@ void Person::doAI() } pause = 0; - if (distsqflat(&Person::players[0]->coords, &coords) < 30 && - Person::players[0]->coords.y > coords.y + 2 && - !Person::players[0]->onterrain) { + if (distsqflat(&victim->coords, &coords) < 30 && + victim->coords.y > coords.y + 2 && + !victim->onterrain) { pause = 1; } @@ -7489,17 +7489,17 @@ void Person::doAI() if ((!Tutorial::active || cananger) && hostile && !isPlayerFriend() && - !Person::players[0]->dead && - distsq(&coords, &Person::players[0]->coords) < 400 && + !victim->dead && + distsq(&coords, &victim->coords) < 400 && occluded < 25) { - if (distsq(&coords, &Person::players[0]->coords) < 12 && - Animation::animations[Person::players[0]->animTarget].height != lowheight && + if (distsq(&coords, &victim->coords) < 12 && + Animation::animations[victim->animTarget].height != lowheight && !Game::editorenabled && - (Person::players[0]->coords.y < coords.y + 5 || Person::players[0]->onterrain)) { + (victim->coords.y < coords.y + 5 || victim->onterrain)) { aitype = attacktypecutoff; } - if (distsq(&coords, &Person::players[0]->coords) < 30 && - Animation::animations[Person::players[0]->animTarget].height == highheight && + if (distsq(&coords, &victim->coords) < 30 && + Animation::animations[victim->animTarget].height == highheight && !Game::editorenabled) { aitype = attacktypecutoff; } @@ -7627,15 +7627,15 @@ void Person::doAI() if (howactive < typesleeping && ((!Tutorial::active || cananger) && hostile) && !isPlayerFriend() && - !Person::players[0]->dead && - distsq(&coords, &Person::players[0]->coords) < 400 && + !victim->dead && + distsq(&coords, &victim->coords) < 400 && occluded < 25) { - if (distsq(&coords, &Person::players[0]->coords) < 12 && - Animation::animations[Person::players[0]->animTarget].height != lowheight && !Game::editorenabled) { + if (distsq(&coords, &victim->coords) < 12 && + Animation::animations[victim->animTarget].height != lowheight && !Game::editorenabled) { aitype = attacktypecutoff; } - if (distsq(&coords, &Person::players[0]->coords) < 30 && - Animation::animations[Person::players[0]->animTarget].height == highheight && !Game::editorenabled) { + if (distsq(&coords, &victim->coords) < 30 && + Animation::animations[victim->animTarget].height == highheight && !Game::editorenabled) { aitype = attacktypecutoff; } @@ -7813,29 +7813,29 @@ void Person::doAI() } } - if (!Person::players[0]->dead && + if (!victim->dead && !isPlayerFriend() && losupdatedelay < 0 && !Game::editorenabled && occluded < 2 && ((!Tutorial::active || cananger) && hostile)) { losupdatedelay = .2; - if (distsq(&coords, &Person::players[0]->coords) < 4 && Animation::animations[animTarget].height != lowheight) { + if (distsq(&coords, &victim->coords) < 4 && Animation::animations[animTarget].height != lowheight) { aitype = attacktypecutoff; lastseentime = 1; } if (abs(Random() % 2) || Animation::animations[animTarget].height != lowheight) { //TODO: factor out canSeePlayer() - if (distsq(&coords, &Person::players[0]->coords) < 400) { - if (normaldotproduct(facing, Person::players[0]->coords - coords) > 0) { + if (distsq(&coords, &victim->coords) < 400) { + if (normaldotproduct(facing, victim->coords - coords) > 0) { if ((Object::checkcollide( DoRotation(jointPos(head), 0, yaw, 0) * scale + coords, - DoRotation(Person::players[0]->jointPos(head), 0, Person::players[0]->yaw, 0) * - Person::players[0]->scale + - Person::players[0]->coords) == -1) || - (Person::players[0]->animTarget == hanganim && normaldotproduct(Person::players[0]->facing, coords - Person::players[0]->coords) < 0)) { + DoRotation(victim->jointPos(head), 0, victim->yaw, 0) * + victim->scale + + victim->coords) == -1) || + (victim->animTarget == hanganim && normaldotproduct(victim->facing, coords - victim->coords) < 0)) { /* //TODO: changed j to 0 on a whim, make sure this is correct (Person::players[j]->animTarget==hanganim&&normaldotproduct( Person::players[j]->facing,coords-Person::players[j]->coords)<0) @@ -7896,7 +7896,7 @@ void Person::doAI() } else { ally = 0; } - lastseen = Person::players[0]->coords; + lastseen = victim->coords; lastseentime = 12; } @@ -8000,13 +8000,13 @@ void Person::doAI() lastseentime = 12; - if (!Person::players[0]->dead && !isPlayerFriend() && ((!Tutorial::active || cananger) && hostile)) { + if (!victim->dead && !isPlayerFriend() && ((!Tutorial::active || cananger) && hostile)) { if (ally < 0 || hasWeapon() || lastchecktime <= 0) { aitype = attacktypecutoff; lastseentime = 1; } } - if (!Person::players[0]->dead) { + if (!victim->dead) { if (ally >= 0) { if (weapons[ally].owner != -1 || distsq(&coords, &weapons[ally].position) > 16) { @@ -8063,18 +8063,18 @@ void Person::doAI() aiupdatedelay -= multiplier; //dodge or reverse rabbit kicks, knife throws, flips if (damage < damagetolerance * 2 / 3) { - if ((Person::players[0]->animTarget == rabbitkickanim || - Person::players[0]->animTarget == knifethrowanim || - (Person::players[0]->isFlip() && - normaldotproduct(Person::players[0]->facing, Person::players[0]->coords - coords) < 0)) && - !Person::players[0]->skeleton.free && + if ((victim->animTarget == rabbitkickanim || + victim->animTarget == knifethrowanim || + (victim->isFlip() && + normaldotproduct(victim->facing, victim->coords - coords) < 0)) && + !victim->skeleton.free && (aiupdatedelay < .1)) { attackkeydown = 0; if (isIdle()) { crouchkeydown = 1; } - if (Person::players[0]->animTarget != rabbitkickanim && Person::players[0]->hasWeapon()) { - if (weapons[Person::players[0]->weaponids[0]].getType() == knife) { + if (victim->animTarget != rabbitkickanim && victim->hasWeapon()) { + if (weapons[victim->weaponids[0]].getType() == knife) { if (isIdle() || isCrouch() || isRun() || isFlip()) { if (abs(Random() % 2) == 0) { setTargetAnimation(backhandspringanim); @@ -8094,11 +8094,11 @@ void Person::doAI() } } //get confused by flips - if (Person::players[0]->isFlip() && - !Person::players[0]->skeleton.free && - Person::players[0]->animTarget != walljumprightkickanim && - Person::players[0]->animTarget != walljumpleftkickanim) { - if (distsq(&Person::players[0]->coords, &coords) < 25) { + if (victim->isFlip() && + !victim->skeleton.free && + victim->animTarget != walljumprightkickanim && + victim->animTarget != walljumpleftkickanim) { + if (distsq(&victim->coords, &coords) < 25) { if ((1 - damage / damagetolerance) > .5) { stunned = 1; } @@ -8127,8 +8127,8 @@ void Person::doAI() if (damage < damagetolerance / 2) { if (Animation::animations[animTarget].height != highheight) { if (damage < damagetolerance * .5 && - ((Person::players[0]->animTarget == walljumprightkickanim || - Person::players[0]->animTarget == walljumpleftkickanim) && + ((victim->animTarget == walljumprightkickanim || + victim->animTarget == walljumpleftkickanim) && ((aiupdatedelay < .15 && difficulty == 2) || (aiupdatedelay < .08 && @@ -8167,9 +8167,9 @@ void Person::doAI() } } //lose sight of player in the air (?) - if (Person::players[0]->coords.y > coords.y + 5 && - Animation::animations[Person::players[0]->animTarget].height != highheight && - !Person::players[0]->onterrain) { + if (victim->coords.y > coords.y + 5 && + Animation::animations[victim->animTarget].height != highheight && + !victim->onterrain) { aitype = pathfindtype; finalfinaltarget = waypoints[waypoint]; finalpathfindpoint = -1; @@ -8194,23 +8194,23 @@ void Person::doAI() } rabbitkickenabled = Random() % 2; //chase player - XYZ rotatetarget = Person::players[0]->coords + Person::players[0]->velocity; - XYZ targetpoint = Person::players[0]->coords; + XYZ rotatetarget = victim->coords + victim->velocity; + XYZ targetpoint = victim->coords; 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; + distsq(&victim->coords, &coords) < distsq(&rotatetarget, &coords)) { + targetpoint += victim->velocity * + findDistance(&victim->coords, &coords) / vellength; } targetyaw = roughDirectionTo(coords, targetpoint); lookyaw = targetyaw; aiupdatedelay = .2 + fabs((float)(Random() % 100) / 1000); - if (distsq(&coords, &Person::players[0]->coords) > 5 && (!Person::players[0]->hasWeapon() || hasWeapon())) { + if (distsq(&coords, &victim->coords) > 5 && (!victim->hasWeapon() || hasWeapon())) { forwardkeydown = 1; - } else if ((distsq(&coords, &Person::players[0]->coords) > 16 || - distsq(&coords, &Person::players[0]->coords) < 9) && - Person::players[0]->hasWeapon()) { + } else if ((distsq(&coords, &victim->coords) > 16 || + distsq(&coords, &victim->coords) < 9) && + victim->hasWeapon()) { forwardkeydown = 1; } else if (Random() % 6 == 0 || (creature == wolftype && Random() % 3 == 0)) { forwardkeydown = 1; @@ -8218,7 +8218,7 @@ void Person::doAI() forwardkeydown = 0; } //chill out around the corpse - if (Person::players[0]->dead) { + if (victim->dead) { forwardkeydown = 0; if (Random() % 10 == 0) { forwardkeydown = 1; @@ -8249,7 +8249,7 @@ void Person::doAI() } else { attackkeydown = 0; } - if (isRun() && Random() % 6 && distsq(&coords, &Person::players[0]->coords) > 7) { + if (isRun() && Random() % 6 && distsq(&coords, &victim->coords) > 7) { attackkeydown = 0; } @@ -8305,17 +8305,17 @@ void Person::doAI() jumpkeydown = 0; } if (collided > .8 && jumppower >= 5 || - distsq(&coords, &Person::players[0]->coords) > 400 && + distsq(&coords, &victim->coords) > 400 && onterrain && creature == rabbittype) { jumpkeydown = 1; } //TODO: why are we controlling the human? - if (normaldotproduct(facing, Person::players[0]->coords - coords) > 0) { - Person::players[0]->jumpkeydown = 0; + if (normaldotproduct(facing, victim->coords - coords) > 0) { + victim->jumpkeydown = 0; } - if (Person::players[0]->animTarget == jumpdownanim && - distsq(&Person::players[0]->coords, &coords) < 40) { + if (victim->animTarget == jumpdownanim && + distsq(&victim->coords, &coords) < 40) { crouchkeydown = 1; } if (jumpkeydown) { @@ -8329,9 +8329,9 @@ void Person::doAI() } XYZ facing = coords; - XYZ flatfacing = Person::players[0]->coords; + XYZ flatfacing = victim->coords; facing.y += jointPos(head).y * scale; - flatfacing.y += Person::players[0]->jointPos(head).y * Person::players[0]->scale; + flatfacing.y += victim->jointPos(head).y * victim->scale; if (occluded >= 2) { if (-1 != Object::checkcollide(facing, flatfacing)) { if (!pause) { @@ -8342,7 +8342,7 @@ void Person::doAI() weaponstuck == -1)) { aitype = searchtype; lastchecktime = 12; - lastseen = Person::players[0]->coords; + lastseen = victim->coords; lastseentime = 12; } } else { @@ -8351,13 +8351,13 @@ void Person::doAI() } } } - if (Animation::animations[Person::players[0]->animTarget].height == highheight && + if (Animation::animations[victim->animTarget].height == highheight && (aitype == attacktypecutoff || aitype == searchtype)) { - if (Person::players[0]->coords.y > terrain.getHeight(Person::players[0]->coords.x, Person::players[0]->coords.z) + 10) { - XYZ test = Person::players[0]->coords; + if (victim->coords.y > terrain.getHeight(victim->coords.x, victim->coords.z) + 10) { + XYZ test = victim->coords; test.y -= 40; - if (-1 == Object::checkcollide(Person::players[0]->coords, test)) { + if (-1 == Object::checkcollide(victim->coords, test)) { stunned = 1; } } -- 2.39.2