- }
- const bool hasstaff = attackweapon == staff;
- if (k == 0 && numplayers > 1)
- for (int i = 0; i < numplayers; i++) {
- if (i == k)continue;
- if ((playerrealattackkeydown || player[i].dead || !hasstaff) &&
- animation[player[k].animTarget].attack == neutral) {
- const float distance = distsq(&player[k].coords, &player[i].coords);
- if (!player[i].dead || !realthreat || (!attackweapon && player[k].crouchkeydown))
- if (player[i].skeleton.free)
- if (distance < 3.5 * sq(player[k].scale * 5) &&
- (player[i].dead ||
- player[i].skeleton.longdead > 1000 ||
- player[k].isRun() ||
- hasstaff ||
- (attackweapon &&
- (player[i].skeleton.longdead > 2000 ||
- player[i].damage > player[i].damagetolerance / 8 ||
- player[i].bloodloss > player[i].damagetolerance / 2) &&
- distance < 1.5 * sq(player[k].scale * 5)))) {
- player[k].victim = &player[i];
- player[k].hasvictim = 1;
- if (attackweapon && tutoriallevel != 1) {
- //crouchstab
- if (player[k].crouchkeydown && attackweapon == knife && distance < 1.5 * sq(player[k].scale * 5))
- player[k].animTarget = crouchstabanim;
- //swordgroundstab
- if (player[k].crouchkeydown && distance < 1.5 * sq(player[k].scale * 5) && attackweapon == sword)
- player[k].animTarget = swordgroundstabanim;
- //staffgroundsmash
- if (distance < 3.5 * sq(player[k].scale * 5) && attackweapon == staff)
- player[k].animTarget = staffgroundsmashanim;
- }
- if (distance < 2.5 &&
- player[k].crouchkeydown &&
- player[k].animTarget != crouchstabanim &&
- !attackweapon &&
- player[i].dead &&
- player[i].skeleton.free &&
- player[i].skeleton.longdead > 1000) {
- player[k].animTarget = killanim;
- //TODO: refactor this out, what does it do?
- for (int j = 0; j < terrain.numdecals; j++) {
- if ((terrain.decaltype[j] == blooddecal || terrain.decaltype[j] == blooddecalslow) &&
- terrain.decalalivetime[j] < 2)
- terrain.DeleteDecal(j);
- }
- for (int l = 0; l < objects.numobjects; l++) {
- if (objects.model[l].type == decalstype)
- for (int j = 0; j < objects.model[l].numdecals; j++) {
- if ((objects.model[l].decaltype[j] == blooddecal ||
- objects.model[l].decaltype[j] == blooddecalslow) &&
- objects.model[l].decalalivetime[j] < 2)
- objects.model[l].DeleteDecal(j);
- }
- }
- }
- if (!player[i].dead || musictype != 2)
- if (distance < 3.5 &&
- (player[k].isRun() || player[k].isIdle() && player[k].attackkeydown) &&
- player[k].staggerdelay <= 0 &&
- (player[i].dead ||
- player[i].skeleton.longdead < 300 &&
- player[k].lastattack != spinkickanim &&
- player[i].skeleton.free) &&
- (!player[i].dead || musictype != stream_fighttheme)) {
- player[k].animTarget = dropkickanim;
- for (int j = 0; j < terrain.numdecals; j++) {
- if ((terrain.decaltype[j] == blooddecal || terrain.decaltype[j] == blooddecalslow) &&
- terrain.decalalivetime[j] < 2) {
- terrain.DeleteDecal(j);
- }
- }
- for (int l = 0; l < objects.numobjects; l++) {
- if (objects.model[l].type == decalstype)
- for (int j = 0; j < objects.model[l].numdecals; j++) {
- if ((objects.model[l].decaltype[j] == blooddecal ||
- objects.model[l].decaltype[j] == blooddecalslow) &&
- objects.model[l].decalalivetime[j] < 2) {
- objects.model[l].DeleteDecal(j);
- }
- }
- }
- }
- }
- if (animation[player[k].animTarget].attack == normalattack &&
- player[k].victim == &player[i] &&
- (!player[i].skeleton.free ||
- player[k].animTarget == killanim ||
- player[k].animTarget == crouchstabanim ||
- player[k].animTarget == swordgroundstabanim ||
- player[k].animTarget == staffgroundsmashanim ||
- player[k].animTarget == dropkickanim)) {
- oldattackkey = 1;
- player[k].frameTarget = 0;
- player[k].target = 0;
-
- XYZ targetpoint = player[i].coords;
- if (player[k].animTarget == crouchstabanim ||
- player[k].animTarget == swordgroundstabanim ||
- player[k].animTarget == staffgroundsmashanim) {
- targetpoint += (player[i].jointPos(abdomen) +
- player[i].jointPos(neck)) / 2 *
- player[i].scale;
- }
- player[k].targetyaw = roughDirectionTo(player[k].coords, targetpoint);
- player[k].targettilt2 = pitchTo(player[k].coords, targetpoint);
-
- if (player[k].animTarget == crouchstabanim || player[k].animTarget == swordgroundstabanim) {
- player[k].targetyaw += (float)(abs(Random() % 100) - 50) / 4;
- }
-
- if (player[k].animTarget == staffgroundsmashanim)
- player[k].targettilt2 += 10;
-
- player[k].lastattack3 = player[k].lastattack2;
- player[k].lastattack2 = player[k].lastattack;
- player[k].lastattack = player[k].animTarget;
-
- if (player[k].animTarget == swordgroundstabanim) {
- player[k].targetyaw += 30;
- }
- }
- }
- }
- if (!player[k].hasvictim) {
- //find victim
- for (int i = 0; i < numplayers; i++) {
- if (i == k || !(i == 0 || k == 0))continue;
- if (!player[i].skeleton.free) {
- if (player[k].hasvictim) {
- if (distsq(&player[k].coords, &player[i].coords) <
- distsq(&player[k].coords, &player[k].victim->coords))
- player[k].victim = &player[i];
- } else {
- player[k].victim = &player[i];
- player[k].hasvictim = 1;
- }
- }
- }
- }
- if (player[k].aitype == playercontrolled)
- //rabbit kick
- if (player[k].attackkeydown &&
- player[k].isRun() &&
- player[k].wasRun() &&
- ((player[k].hasvictim &&
- distsq(&player[k].coords, &player[k].victim->coords) < 12 * sq(player[k].scale * 5) &&
- distsq(&player[k].coords, &player[k].victim->coords) > 7 * sq(player[k].scale * 5) &&
- !player[k].victim->skeleton.free &&
- player[k].victim->animTarget != getupfrombackanim &&
- player[k].victim->animTarget != getupfromfrontanim &&
- animation[player[k].victim->animTarget].height != lowheight &&
- player[k].aitype != playercontrolled && //wat???
- normaldotproduct(player[k].facing, player[k].victim->coords - player[k].coords) > 0 &&
- player[k].rabbitkickenabled) ||
- player[k].jumpkeydown)) {
- oldattackkey = 1;
- player[k].setAnimation(rabbitkickanim);
- }
- //update counts
- if (animation[player[k].animTarget].attack && k == 0) {
- numattacks++;
- switch (attackweapon) {
- case 0:
- numunarmedattack++;
- break;
- case knife:
- numknifeattack++;
- break;
- case sword:
- numswordattack++;
- break;
- case staff:
- numstaffattack++;
- break;
- }
- }
- }
- }
- }
- }
-}
-
-void doPlayerCollisions()
-{
- static XYZ rotatetarget;
- static float collisionradius;
- if (numplayers > 1)
- for (int k = 0; k < numplayers; k++)
- for (int i = k + 1; i < numplayers; i++) {
- //neither player is part of a reversal
- if ((animation[player[i].animTarget].attack != reversed &&
- animation[player[i].animTarget].attack != reversal &&
- animation[player[k].animTarget].attack != reversed &&
- animation[player[k].animTarget].attack != reversal) || (i != 0 && k != 0))
- if ((animation[player[i].animCurrent].attack != reversed &&
- animation[player[i].animCurrent].attack != reversal &&
- animation[player[k].animCurrent].attack != reversed &&
- animation[player[k].animCurrent].attack != reversal) || (i != 0 && k != 0))
- //neither is sleeping
- if (player[i].howactive <= typesleeping && player[k].howactive <= typesleeping)
- if (player[i].howactive != typesittingwall && player[k].howactive != typesittingwall)
- //in same patch, neither is climbing
- if (player[i].whichpatchx == player[k].whichpatchx &&
- player[i].whichpatchz == player[k].whichpatchz &&
- player[k].skeleton.oldfree == player[k].skeleton.free &&
- player[i].skeleton.oldfree == player[i].skeleton.free &&
- player[i].animTarget != climbanim &&
- player[i].animTarget != hanganim &&
- player[k].animTarget != climbanim &&
- player[k].animTarget != hanganim)
- //players are close (bounding box test)
- if (player[i].coords.y > player[k].coords.y - 3)
- if (player[i].coords.y < player[k].coords.y + 3)
- if (player[i].coords.x > player[k].coords.x - 3)
- if (player[i].coords.x < player[k].coords.x + 3)
- if (player[i].coords.z > player[k].coords.z - 3)
- if (player[i].coords.z < player[k].coords.z + 3) {
- //spread fire from player to player
- if (distsq(&player[i].coords, &player[k].coords)
- < 3 * sq((player[i].scale + player[k].scale) * 2.5)) {
- if (player[i].onfire || player[k].onfire) {
- if (!player[i].onfire)player[i].CatchFire();
- if (!player[k].onfire)player[k].CatchFire();
- }
- }
-
- XYZ tempcoords1 = player[i].coords;
- XYZ tempcoords2 = player[k].coords;
- if (!player[i].skeleton.oldfree)
- tempcoords1.y += player[i].jointPos(abdomen).y * player[i].scale;
- if (!player[k].skeleton.oldfree)
- tempcoords2.y += player[k].jointPos(abdomen).y * player[k].scale;
- collisionradius = 1.2 * sq((player[i].scale + player[k].scale) * 2.5);
- if (player[0].hasvictim)
- if (player[0].animTarget == rabbitkickanim && (k == 0 || i == 0) && !player[0].victim->skeleton.free)
- collisionradius = 3;
- if ((!player[i].skeleton.oldfree || !player[k].skeleton.oldfree) &&
- (distsq(&tempcoords1, &tempcoords2) < collisionradius ||
- distsq(&player[i].coords, &player[k].coords) < collisionradius)) {
- //jump down on a dead body
- if (k == 0 || i == 0) {
- int l = i ? i : k;
- if (player[0].animTarget == jumpdownanim &&
- !player[0].skeleton.oldfree &&
- !player[0].skeleton.free &&
- player[l].skeleton.oldfree &&
- player[l].skeleton.free &&
- player[l].dead &&
- player[0].lastcollide <= 0 &&
- fabs(player[l].coords.y - player[0].coords.y) < .2 &&
- distsq(&player[0].coords, &player[l].coords) < .7 * sq((player[l].scale + player[0].scale) * 2.5)) {
- player[0].coords.y = player[l].coords.y;
- player[l].velocity = player[0].velocity;
- player[l].skeleton.free = 0;
- player[l].yaw = 0;
- player[l].RagDoll(0);
- player[l].DoDamage(20);
- camerashake += .3;
- player[l].skeleton.longdead = 0;
- player[0].lastcollide = 1;
- }
- }
-
- if ( (player[i].skeleton.oldfree == 1 && findLengthfast(&player[i].velocity) > 1) ||
- (player[k].skeleton.oldfree == 1 && findLengthfast(&player[k].velocity) > 1) ||
- (player[i].skeleton.oldfree == 0 && player[k].skeleton.oldfree == 0)) {
- rotatetarget = player[k].velocity - player[i].velocity;
- if ((player[i].animTarget != getupfrombackanim && player[i].animTarget != getupfromfrontanim ||
- player[i].skeleton.free) &&
- (player[k].animTarget != getupfrombackanim && player[k].animTarget != getupfromfrontanim ||
- player[k].skeleton.free))
- if ((((k != 0 && findLengthfast(&rotatetarget) > 150 ||
- k == 0 && findLengthfast(&rotatetarget) > 50 && player[0].rabbitkickragdoll) &&
- normaldotproduct(rotatetarget, player[k].coords - player[i].coords) > 0) &&
- (k == 0 ||
- k != 0 && player[i].skeleton.oldfree == 1 && animation[player[k].animCurrent].attack == neutral ||
- /*i!=0&&*/player[k].skeleton.oldfree == 1 && animation[player[i].animCurrent].attack == neutral)) ||
- (player[i].animTarget == jumpupanim || player[i].animTarget == jumpdownanim || player[i].isFlip()) &&
- (player[k].animTarget == jumpupanim || player[k].animTarget == jumpdownanim || player[k].isFlip()) &&
- k == 0 && !player[i].skeleton.oldfree && !player[k].skeleton.oldfree) {
- //If hit by body
- if ( (i != 0 || player[i].skeleton.free) &&
- (k != 0 || player[k].skeleton.free) ||
- (animation[player[i].animTarget].height == highheight &&
- animation[player[k].animTarget].height == highheight)) {
- if (tutoriallevel != 1) {
- emit_sound_at(heavyimpactsound, player[i].coords);
- }
-
- player[i].RagDoll(0);
- if (player[i].damage > player[i].damagetolerance - findLengthfast(&rotatetarget) / 4 && !player[i].dead) {
- award_bonus(0, aimbonus);
- }
- player[i].DoDamage(findLengthfast(&rotatetarget) / 4);
- player[k].RagDoll(0);
- if (player[k].damage > player[k].damagetolerance - findLengthfast(&rotatetarget) / 4 && !player[k].dead) {
- award_bonus(0, aimbonus); // Huh, again?
- }
- player[k].DoDamage(findLengthfast(&rotatetarget) / 4);
-
- for (int j = 0; j < player[i].skeleton.num_joints; j++) {
- player[i].skeleton.joints[j].velocity = player[i].skeleton.joints[j].velocity / 5 + player[k].velocity;
- }
- for (int j = 0; j < player[k].skeleton.num_joints; j++) {
- player[k].skeleton.joints[j].velocity = player[k].skeleton.joints[j].velocity / 5 + player[i].velocity;
- }
-
- }
- }
- if ( (animation[player[i].animTarget].attack == neutral ||
- animation[player[i].animTarget].attack == normalattack) &&
- (animation[player[k].animTarget].attack == neutral ||
- animation[player[k].animTarget].attack == normalattack)) {
- //If bumped
- if (player[i].skeleton.oldfree == 0 && player[k].skeleton.oldfree == 0) {
- if (distsq(&player[k].coords, &player[i].coords) < .5 * sq((player[i].scale + player[k].scale) * 2.5)) {
- rotatetarget = player[k].coords - player[i].coords;
- Normalise(&rotatetarget);
- player[k].coords = (player[k].coords + player[i].coords) / 2;
- player[i].coords = player[k].coords - rotatetarget * fast_sqrt(.6) / 2
- * sq((player[i].scale + player[k].scale) * 2.5);
- player[k].coords += rotatetarget * fast_sqrt(.6) / 2 * sq((player[i].scale + player[k].scale) * 2.5);
- if (player[k].howactive == typeactive || hostile)
- if (player[k].isIdle()) {
- if (player[k].howactive < typesleeping)
- player[k].setAnimation(player[k].getStop());
- else if (player[k].howactive == typesleeping)
- player[k].setAnimation(getupfromfrontanim);
- if (!editorenabled)
- player[k].howactive = typeactive;
- }
- if (player[i].howactive == typeactive || hostile)
- if (player[i].isIdle()) {
- if (player[i].howactive < typesleeping)
- player[i].setAnimation(player[k].getStop());
- else
- player[i].setAnimation(getupfromfrontanim);
- if (!editorenabled)
- player[i].howactive = typeactive;
- }
- }
- //jump down on player
- if (hostile) {
- if (k == 0 && i != 0 && player[k].animTarget == jumpdownanim &&
- !player[i].isCrouch() &&
- player[i].animTarget != rollanim &&
- !player[k].skeleton.oldfree && !
- player[k].skeleton.free &&
- player[k].lastcollide <= 0 &&
- player[k].velocity.y < -10) {
- player[i].velocity = player[k].velocity;
- player[k].velocity = player[k].velocity * -.5;
- player[k].velocity.y = player[i].velocity.y;
- player[i].DoDamage(20);
- player[i].RagDoll(0);
- player[k].lastcollide = 1;
- award_bonus(k, AboveBonus);
- }
- if (i == 0 && k != 0 && player[i].animTarget == jumpdownanim &&
- !player[k].isCrouch() &&
- player[k].animTarget != rollanim &&
- !player[i].skeleton.oldfree &&
- !player[i].skeleton.free &&
- player[i].lastcollide <= 0 &&
- player[i].velocity.y < -10) {
- player[k].velocity = player[i].velocity;
- player[i].velocity = player[i].velocity * -.3;
- player[i].velocity.y = player[k].velocity.y;
- player[k].DoDamage(20);
- player[k].RagDoll(0);
- player[i].lastcollide = 1;
- award_bonus(i, AboveBonus);
- }
- }
- }
- }
- }
- player[i].CheckKick();
- player[k].CheckKick();
- }
- }
- }
-}
-
-void doAI(int i)
-{
- static bool connected;
- if (player[i].aitype != playercontrolled && indialogue == -1) {
- player[i].jumpclimb = 0;
- //disable movement in editor
- if (editorenabled)
- player[i].stunned = 1;
-
- player[i].pause = 0;
- if (distsqflat(&player[0].coords, &player[i].coords) < 30 &&
- player[0].coords.y > player[i].coords.y + 2 &&
- !player[0].onterrain)
- player[i].pause = 1;
-
- //pathfinding
- if (player[i].aitype == pathfindtype) {
- if (player[i].finalpathfindpoint == -1) {
- float closestdistance;
- float tempdist;
- int closest;
- XYZ colpoint;
- closest = -1;
- closestdistance = -1;
- for (int j = 0; j < numpathpoints; j++)
- if (closest == -1 || distsq(&player[i].finalfinaltarget, &pathpoint[j]) < closestdistance) {
- closestdistance = distsq(&player[i].finalfinaltarget, &pathpoint[j]);
- closest = j;
- player[i].finaltarget = pathpoint[j];
- }
- player[i].finalpathfindpoint = closest;
- for (int j = 0; j < numpathpoints; j++)
- for (int k = 0; k < numpathpointconnect[j]; k++) {
- DistancePointLine(&player[i].finalfinaltarget, &pathpoint[j], &pathpoint[pathpointconnect[j][k]], &tempdist, &colpoint );
- if (sq(tempdist) < closestdistance)
- if (findDistance(&colpoint, &pathpoint[j]) + findDistance(&colpoint, &pathpoint[pathpointconnect[j][k]]) <
- findDistance(&pathpoint[j], &pathpoint[pathpointconnect[j][k]]) + .1) {
- closestdistance = sq(tempdist);
- closest = j;
- player[i].finaltarget = colpoint;
- }
- }
- player[i].finalpathfindpoint = closest;
-
- }
- if (player[i].targetpathfindpoint == -1) {
- float closestdistance;
- float tempdist;
- int closest;
- XYZ colpoint;
- closest = -1;
- closestdistance = -1;
- if (player[i].lastpathfindpoint == -1) {
- for (int j = 0; j < numpathpoints; j++) {
- if (j != player[i].lastpathfindpoint)
- if (closest == -1 || (distsq(&player[i].coords, &pathpoint[j]) < closestdistance)) {
- closestdistance = distsq(&player[i].coords, &pathpoint[j]);
- closest = j;
- }
- }
- player[i].targetpathfindpoint = closest;
- for (int j = 0; j < numpathpoints; j++)
- if (j != player[i].lastpathfindpoint)
- for (int k = 0; k < numpathpointconnect[j]; k++) {
- DistancePointLine(&player[i].coords, &pathpoint[j], &pathpoint[pathpointconnect[j][k]], &tempdist, &colpoint );
- if (sq(tempdist) < closestdistance) {
- if (findDistance(&colpoint, &pathpoint[j]) + findDistance(&colpoint, &pathpoint[pathpointconnect[j][k]]) <
- findDistance(&pathpoint[j], &pathpoint[pathpointconnect[j][k]]) + .1) {
- closestdistance = sq(tempdist);
- closest = j;
- }
- }
- }
- player[i].targetpathfindpoint = closest;
- } else {
- for (int j = 0; j < numpathpoints; j++)
- if (j != player[i].lastpathfindpoint &&
- j != player[i].lastpathfindpoint2 &&
- j != player[i].lastpathfindpoint3 &&
- j != player[i].lastpathfindpoint4) {
- connected = 0;
- if (numpathpointconnect[j])
- for (int k = 0; k < numpathpointconnect[j]; k++)
- if (pathpointconnect[j][k] == player[i].lastpathfindpoint)
- connected = 1;
- if (!connected)
- if (numpathpointconnect[player[i].lastpathfindpoint])
- for (int k = 0; k < numpathpointconnect[player[i].lastpathfindpoint]; k++)
- if (pathpointconnect[player[i].lastpathfindpoint][k] == j)
- connected = 1;
- if (connected) {
- tempdist = findPathDist(j, player[i].finalpathfindpoint);
- if (closest == -1 || tempdist < closestdistance) {
- closestdistance = tempdist;
- closest = j;
- }
- }
- }
- player[i].targetpathfindpoint = closest;
- }
- }
- player[i].losupdatedelay -= multiplier;
-
- player[i].targetyaw = roughDirectionTo(player[i].coords, pathpoint[player[i].targetpathfindpoint]);
- player[i].lookyaw = player[i].targetyaw;
-
- //reached target point
- if (distsqflat(&player[i].coords, &pathpoint[player[i].targetpathfindpoint]) < .6) {
- player[i].lastpathfindpoint4 = player[i].lastpathfindpoint3;
- player[i].lastpathfindpoint3 = player[i].lastpathfindpoint2;
- player[i].lastpathfindpoint2 = player[i].lastpathfindpoint;
- player[i].lastpathfindpoint = player[i].targetpathfindpoint;
- if (player[i].lastpathfindpoint2 == -1)
- player[i].lastpathfindpoint2 = player[i].lastpathfindpoint;
- if (player[i].lastpathfindpoint3 == -1)
- player[i].lastpathfindpoint3 = player[i].lastpathfindpoint2;
- if (player[i].lastpathfindpoint4 == -1)
- player[i].lastpathfindpoint4 = player[i].lastpathfindpoint3;
- player[i].targetpathfindpoint = -1;
- }
- if ( distsqflat(&player[i].coords, &player[i].finalfinaltarget) <
- distsqflat(&player[i].coords, &player[i].finaltarget) ||
- distsqflat(&player[i].coords, &player[i].finaltarget) < .6 * sq(player[i].scale * 5) ||
- player[i].lastpathfindpoint == player[i].finalpathfindpoint) {
- player[i].aitype = passivetype;
- }
-
- player[i].forwardkeydown = 1;
- player[i].leftkeydown = 0;
- player[i].backkeydown = 0;
- player[i].rightkeydown = 0;
- player[i].crouchkeydown = 0;
- player[i].attackkeydown = 0;
- player[i].throwkeydown = 0;
-
- if (player[i].avoidcollided > .8 && !player[i].jumpkeydown && player[i].collided < .8)
- player[i].targetyaw += 90 * (player[i].whichdirection * 2 - 1);
-
- if (player[i].collided < 1 || player[i].animTarget != jumpupanim)
- player[i].jumpkeydown = 0;
- if ((player[i].collided > .8 && player[i].jumppower >= 5))
- player[i].jumpkeydown = 1;
-
- if ((tutoriallevel != 1 || cananger) &&
- hostile &&
- !player[0].dead &&
- distsq(&player[i].coords, &player[0].coords) < 400 &&
- player[i].occluded < 25) {
- if (distsq(&player[i].coords, &player[0].coords) < 12 &&
- animation[player[0].animTarget].height != lowheight &&
- !editorenabled &&
- (player[0].coords.y < player[i].coords.y + 5 || player[0].onterrain))
- player[i].aitype = attacktypecutoff;
- if (distsq(&player[i].coords, &player[0].coords) < 30 &&
- animation[player[0].animTarget].height == highheight &&
- !editorenabled)
- player[i].aitype = attacktypecutoff;
-
- if (player[i].losupdatedelay < 0 && !editorenabled && player[i].occluded < 2) {
- player[i].losupdatedelay = .2;
- for (int j = 0; j < numplayers; j++)
- if (j == 0 || player[j].skeleton.free || player[j].aitype != passivetype)
- if (abs(Random() % 2) || animation[player[j].animTarget].height != lowheight || j != 0)
- if (distsq(&player[i].coords, &player[j].coords) < 400)
- if (normaldotproduct(player[i].facing, player[j].coords - player[i].coords) > 0)
- if (player[j].coords.y < player[i].coords.y + 5 || player[j].onterrain)
- if (!player[j].isWallJump() && -1 == checkcollide(
- DoRotation(player[i].jointPos(head), 0, player[i].yaw, 0)
- *player[i].scale + player[i].coords,
- DoRotation(player[j].jointPos(head), 0, player[j].yaw, 0)
- *player[j].scale + player[j].coords) ||
- (player[j].animTarget == hanganim &&
- normaldotproduct(player[j].facing, player[i].coords - player[j].coords) < 0)) {
- player[i].aitype = searchtype;
- player[i].lastchecktime = 12;
- player[i].lastseen = player[j].coords;
- player[i].lastseentime = 12;
- }
- }
- }
- if (player[i].aitype == attacktypecutoff && musictype != 2)
- if (player[i].creature != wolftype) {
- player[i].stunned = .6;
- player[i].surprised = .6;
- }
- }
-
- if (player[i].aitype != passivetype && leveltime > .5)
- player[i].howactive = typeactive;
-
- if (player[i].aitype == passivetype) {
- player[i].aiupdatedelay -= multiplier;
- player[i].losupdatedelay -= multiplier;
- player[i].lastseentime += multiplier;
- player[i].pausetime -= multiplier;
- if (player[i].lastseentime > 1)
- player[i].lastseentime = 1;
-
- if (player[i].aiupdatedelay < 0) {
- if (player[i].numwaypoints > 1 && player[i].howactive == typeactive && player[i].pausetime <= 0) {
- player[i].targetyaw = roughDirectionTo(player[i].coords, player[i].waypoints[player[i].waypoint]);
- player[i].lookyaw = player[i].targetyaw;
- player[i].aiupdatedelay = .05;
-
- if (distsqflat(&player[i].coords, &player[i].waypoints[player[i].waypoint]) < 1) {
- if (player[i].waypointtype[player[i].waypoint] == wppause)
- player[i].pausetime = 4;
- player[i].waypoint++;
- if (player[i].waypoint > player[i].numwaypoints - 1)
- player[i].waypoint = 0;
-
- }
- }
-
- if (player[i].numwaypoints > 1 && player[i].howactive == typeactive && player[i].pausetime <= 0)
- player[i].forwardkeydown = 1;
- else
- player[i].forwardkeydown = 0;
- player[i].leftkeydown = 0;
- player[i].backkeydown = 0;
- player[i].rightkeydown = 0;
- player[i].crouchkeydown = 0;
- player[i].attackkeydown = 0;
- player[i].throwkeydown = 0;
-
- if (player[i].avoidcollided > .8 && !player[i].jumpkeydown && player[i].collided < .8) {
- if (!player[i].avoidsomething)
- player[i].targetyaw += 90 * (player[i].whichdirection * 2 - 1);
- else {
- XYZ leftpos, rightpos;
- float leftdist, rightdist;
- leftpos = player[i].coords + DoRotation(player[i].facing, 0, 90, 0);
- rightpos = player[i].coords - DoRotation(player[i].facing, 0, 90, 0);
- leftdist = distsq(&leftpos, &player[i].avoidwhere);
- rightdist = distsq(&rightpos, &player[i].avoidwhere);
- if (leftdist < rightdist)
- player[i].targetyaw += 90;
- else
- player[i].targetyaw -= 90;
- }
- }
- }
- if (player[i].collided < 1 || player[i].animTarget != jumpupanim)
- player[i].jumpkeydown = 0;
- if ((player[i].collided > .8 && player[i].jumppower >= 5))
- player[i].jumpkeydown = 1;
-
-
- //hearing sounds
- if (!editorenabled) {
- if (player[i].howactive <= typesleeping)
- if (numenvsounds > 0 && (tutoriallevel != 1 || cananger) && hostile)
- for (int j = 0; j < numenvsounds; j++) {
- float vol = player[i].howactive == typesleeping ? envsoundvol[j] - 14 : envsoundvol[j];
- if (vol > 0 && distsq(&player[i].coords, &envsound[j]) <
- 2 * (vol + vol * (player[i].creature == rabbittype) * 3))
- player[i].aitype = attacktypecutoff;
- }
-
- if (player[i].aitype != passivetype) {
- if (player[i].howactive == typesleeping)
- player[i].setAnimation(getupfromfrontanim);
- player[i].howactive = typeactive;
- }
- }
-
- if (player[i].howactive < typesleeping &&
- ((tutoriallevel != 1 || cananger) && hostile) &&
- !player[0].dead &&
- distsq(&player[i].coords, &player[0].coords) < 400 &&
- player[i].occluded < 25) {
- if (distsq(&player[i].coords, &player[0].coords) < 12 &&
- animation[player[0].animTarget].height != lowheight && !editorenabled)
- player[i].aitype = attacktypecutoff;
- if (distsq(&player[i].coords, &player[0].coords) < 30 &&
- animation[player[0].animTarget].height == highheight && !editorenabled)
- player[i].aitype = attacktypecutoff;
-
- //wolf smell
- if (player[i].creature == wolftype) {
- XYZ windsmell;
- for (int j = 0; j < numplayers; j++) {
- if (j == 0 || (player[j].dead && player[j].bloodloss > 0)) {
- float smelldistance = 50;
- if (j == 0 && player[j].num_weapons > 0) {
- if (weapons[player[j].weaponids[0]].bloody)
- smelldistance = 100;
- if (player[j].num_weapons == 2)
- if (weapons[player[j].weaponids[1]].bloody)
- smelldistance = 100;
- }
- if (j != 0)
- smelldistance = 100;
- windsmell = windvector;
- Normalise(&windsmell);
- windsmell = windsmell * 2 + player[j].coords;
- if (distsq(&player[i].coords, &windsmell) < smelldistance && !editorenabled)
- player[i].aitype = attacktypecutoff;
- }
- }
- }
-
- if (player[i].howactive < typesleeping && player[i].losupdatedelay < 0 && !editorenabled && player[i].occluded < 2) {
- player[i].losupdatedelay = .2;
- for (int j = 0; j < numplayers; j++) {
- if (j == 0 || player[j].skeleton.free || player[j].aitype != passivetype) {
- if (abs(Random() % 2) || animation[player[j].animTarget].height != lowheight || j != 0)
- if (distsq(&player[i].coords, &player[j].coords) < 400)
- if (normaldotproduct(player[i].facing, player[j].coords - player[i].coords) > 0)
- if ((-1 == checkcollide(
- DoRotation(player[i].jointPos(head), 0, player[i].yaw, 0)*
- player[i].scale + player[i].coords,
- DoRotation(player[j].jointPos(head), 0, player[j].yaw, 0)*
- player[j].scale + player[j].coords) &&
- !player[j].isWallJump()) ||
- (player[j].animTarget == hanganim &&
- normaldotproduct(player[j].facing, player[i].coords - player[j].coords) < 0)) {
- player[i].lastseentime -= .2;
- if (j == 0 && animation[player[j].animTarget].height == lowheight)
- player[i].lastseentime -= .4;
- else
- player[i].lastseentime -= .6;
- }
- if (player[i].lastseentime <= 0) {
- player[i].aitype = searchtype;
- player[i].lastchecktime = 12;
- player[i].lastseen = player[j].coords;
- player[i].lastseentime = 12;