- }
- }
- }
- }
-}
-
-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;
- }
- }
- }
- }
- }
- //alerted surprise
- if (player[i].aitype == attacktypecutoff && musictype != 2) {
- if (player[i].creature != wolftype) {
- player[i].stunned = .6;
- player[i].surprised = .6;
- }
- if (player[i].creature == wolftype) {
- player[i].stunned = .47;
- player[i].surprised = .47;
- }
- numseen++;
- }
- }
-
- //search for player
- int j;
- if (player[i].aitype == searchtype) {
- player[i].aiupdatedelay -= multiplier;
- player[i].losupdatedelay -= multiplier;
- if (!player[i].pause)
- player[i].lastseentime -= multiplier;
- player[i].lastchecktime -= multiplier;
-
- if (player[i].isRun() && !player[i].onground) {
- if (player[i].coords.y > terrain.getHeight(player[i].coords.x, player[i].coords.z) + 10) {
- XYZ test2 = player[i].coords + player[i].facing;
- test2.y += 5;
- XYZ test = player[i].coords + player[i].facing;
- test.y -= 10;
- j = checkcollide(test2, test, player[i].laststanding);
- if (j == -1)
- j = checkcollide(test2, test);
- if (j == -1) {
- player[i].velocity = 0;
- player[i].setAnimation(player[i].getStop());
- player[i].targetyaw += 180;
- player[i].stunned = .5;
- //player[i].aitype=passivetype;
- player[i].aitype = pathfindtype;
- player[i].finalfinaltarget = player[i].waypoints[player[i].waypoint];
- player[i].finalpathfindpoint = -1;
- player[i].targetpathfindpoint = -1;
- player[i].lastpathfindpoint = -1;
- player[i].lastpathfindpoint2 = -1;
- player[i].lastpathfindpoint3 = -1;
- player[i].lastpathfindpoint4 = -1;
- } else player[i].laststanding = j;
- }
- }
- //check out last seen location
- if (player[i].aiupdatedelay < 0) {
- player[i].targetyaw = roughDirectionTo(player[i].coords, player[i].lastseen);
- player[i].lookyaw = player[i].targetyaw;
- player[i].aiupdatedelay = .05;
- player[i].forwardkeydown = 1;
-
- if (distsqflat(&player[i].coords, &player[i].lastseen) < 1 * sq(player[i].scale * 5) || player[i].lastchecktime < 0) {
- player[i].forwardkeydown = 0;
- player[i].aiupdatedelay = 1;
- player[i].lastseen.x += (float(Random() % 100) - 50) / 25;
- player[i].lastseen.z += (float(Random() % 100) - 50) / 25;
- player[i].lastchecktime = 3;
- }
-
- 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;
-
- if (numenvsounds > 0 && ((tutoriallevel != 1 || cananger) && hostile))
- for (int k = 0; k < numenvsounds; k++) {
- if (distsq(&player[i].coords, &envsound[k]) < 2 * (envsoundvol[k] + envsoundvol[k] * (player[i].creature == rabbittype) * 3)) {
- player[i].aitype = attacktypecutoff;
- }
- }
-
- if (!player[0].dead &&
- player[i].losupdatedelay < 0 &&
- !editorenabled &&
- player[i].occluded < 2 &&
- ((tutoriallevel != 1 || cananger) && hostile)) {
- player[i].losupdatedelay = .2;
- if (distsq(&player[i].coords, &player[0].coords) < 4 && animation[player[i].animTarget].height != lowheight) {
- player[i].aitype = attacktypecutoff;
- player[i].lastseentime = 1;
- }
- if (abs(Random() % 2) || animation[player[i].animTarget].height != lowheight)
- //TODO: factor out canSeePlayer()
- if (distsq(&player[i].coords, &player[0].coords) < 400)
- if (normaldotproduct(player[i].facing, player[0].coords - player[i].coords) > 0)
- if ((checkcollide(
- DoRotation(player[i].jointPos(head), 0, player[i].yaw, 0)*
- player[i].scale + player[i].coords,
- DoRotation(player[0].jointPos(head), 0, player[0].yaw, 0)*
- player[0].scale + player[0].coords) == -1) ||
- (player[0].animTarget == hanganim && normaldotproduct(
- player[0].facing, player[i].coords - player[0].coords) < 0)) {
- /* //TODO: changed j to 0 on a whim, make sure this is correct
- (player[j].animTarget==hanganim&&normaldotproduct(
- player[j].facing,player[i].coords-player[j].coords)<0)
- */
- player[i].aitype = attacktypecutoff;
- player[i].lastseentime = 1;
- }
- }
- //player escaped
- if (player[i].lastseentime < 0) {
- //player[i].aitype=passivetype;
- numescaped++;
- player[i].aitype = pathfindtype;
- player[i].finalfinaltarget = player[i].waypoints[player[i].waypoint];
- player[i].finalpathfindpoint = -1;
- player[i].targetpathfindpoint = -1;
- player[i].lastpathfindpoint = -1;
- player[i].lastpathfindpoint2 = -1;
- player[i].lastpathfindpoint3 = -1;
- player[i].lastpathfindpoint4 = -1;
- }
- }
-
- if (player[i].aitype != gethelptype)
- player[i].runninghowlong = 0;
-
- //get help from buddies
- if (player[i].aitype == gethelptype) {
- player[i].runninghowlong += multiplier;
- player[i].aiupdatedelay -= multiplier;
-
- if (player[i].aiupdatedelay < 0 || player[i].ally == 0) {
- player[i].aiupdatedelay = .2;
-
- //find closest ally
- //TODO: factor out closest search somehow
- if (!player[i].ally) {
- int closest = -1;
- float closestdist = -1;
- for (int k = 0; k < numplayers; k++) {
- if (k != i && k != 0 && !player[k].dead &&
- player[k].howactive < typedead1 &&
- !player[k].skeleton.free &&
- player[k].aitype == passivetype) {
- float distance = distsq(&player[i].coords, &player[k].coords);
- if (closestdist == -1 || distance < closestdist) {
- closestdist = distance;
- closest = k;
- }
- closest = k;
- }
- }
- if (closest != -1)
- player[i].ally = closest;
- else
- player[i].ally = 0;
- player[i].lastseen = player[0].coords;
- player[i].lastseentime = 12;
- }
-
-
- player[i].lastchecktime = 12;
-
- XYZ facing = player[i].coords;
- XYZ flatfacing = player[player[i].ally].coords;
- facing.y += player[i].jointPos(head).y * player[i].scale;
- flatfacing.y += player[player[i].ally].jointPos(head).y * player[player[i].ally].scale;
- if (-1 != checkcollide(facing, flatfacing))
- player[i].lastseentime -= .1;
-
- //no available ally, run back to player
- if (player[i].ally <= 0 ||
- player[player[i].ally].skeleton.free ||
- player[player[i].ally].aitype != passivetype ||
- player[i].lastseentime <= 0) {
- player[i].aitype = searchtype;
- player[i].lastseentime = 12;
- }
-
- //seek out ally
- if (player[i].ally > 0) {
- player[i].targetyaw = roughDirectionTo(player[i].coords, player[player[i].ally].coords);
- player[i].lookyaw = player[i].targetyaw;
- player[i].aiupdatedelay = .05;
- player[i].forwardkeydown = 1;
-
- if (distsqflat(&player[i].coords, &player[player[i].ally].coords) < 3) {
- player[i].aitype = searchtype;
- player[i].lastseentime = 12;
- player[player[i].ally].aitype = searchtype;
- if (player[player[i].ally].lastseentime < player[i].lastseentime) {
- player[player[i].ally].lastseen = player[i].lastseen;
- player[player[i].ally].lastseentime = player[i].lastseentime;
- player[player[i].ally].lastchecktime = player[i].lastchecktime;
- }
- }
-
- 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;
- }
- }
- }
-
- player[i].leftkeydown = 0;
- player[i].backkeydown = 0;
- player[i].rightkeydown = 0;
- player[i].crouchkeydown = 0;
- player[i].attackkeydown = 0;
- }
- 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;
- }
-
- //retreiving a weapon on the ground
- if (player[i].aitype == getweapontype) {
- player[i].aiupdatedelay -= multiplier;
- player[i].lastchecktime -= multiplier;
-
- if (player[i].aiupdatedelay < 0) {
- player[i].aiupdatedelay = .2;
-
- //ALLY IS WEPON
- if (player[i].ally < 0) {
- int closest = -1;
- float closestdist = -1;
- for (int k = 0; k < weapons.size(); k++)
- if (weapons[k].owner == -1) {
- float distance = distsq(&player[i].coords, &weapons[k].position);
- if (closestdist == -1 || distance < closestdist) {
- closestdist = distance;
- closest = k;
- }
- closest = k;
- }
- if (closest != -1)
- player[i].ally = closest;
- else
- player[i].ally = -1;
- }
-
- player[i].lastseentime = 12;
-
- if (!player[0].dead && ((tutoriallevel != 1 || cananger) && hostile))
- if (player[i].ally < 0 || player[i].weaponactive != -1 || player[i].lastchecktime <= 0) {
- player[i].aitype = attacktypecutoff;
- player[i].lastseentime = 1;
- }
- if (!player[0].dead)
- if (player[i].ally >= 0) {
- if (weapons[player[i].ally].owner != -1 ||
- distsq(&player[i].coords, &weapons[player[i].ally].position) > 16) {
- player[i].aitype = attacktypecutoff;
- player[i].lastseentime = 1;
- }
- //TODO: factor these out as moveToward()
- player[i].targetyaw = roughDirectionTo(player[i].coords, weapons[player[i].ally].position);
- player[i].lookyaw = player[i].targetyaw;
- player[i].aiupdatedelay = .05;
- player[i].forwardkeydown = 1;
-
-
- 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;
- }
- }
- }
-
- player[i].leftkeydown = 0;
- player[i].backkeydown = 0;
- player[i].rightkeydown = 0;
- player[i].attackkeydown = 0;
- player[i].throwkeydown = 1;
- player[i].crouchkeydown = 0;
- if (player[i].animTarget != crouchremoveknifeanim &&
- player[i].animTarget != removeknifeanim)
- player[i].throwtogglekeydown = 0;
- player[i].drawkeydown = 0;
- }
- 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 (player[i].aitype == attacktypecutoff) {
- player[i].aiupdatedelay -= multiplier;
- //dodge or reverse rabbit kicks, knife throws, flips
- if (player[i].damage < player[i].damagetolerance * 2 / 3)
- if ((player[0].animTarget == rabbitkickanim ||
- player[0].animTarget == knifethrowanim ||
- (player[0].isFlip() &&
- normaldotproduct(player[0].facing, player[0].coords - player[i].coords) < 0)) &&
- !player[0].skeleton.free &&
- (player[i].aiupdatedelay < .1)) {
- player[i].attackkeydown = 0;
- if (player[i].isIdle())
- player[i].crouchkeydown = 1;
- if (player[0].animTarget != rabbitkickanim && player[0].weaponactive != -1) {
- if (weapons[player[0].weaponids[0]].getType() == knife) {
- if (player[i].isIdle() || player[i].isCrouch() || player[i].isRun() || player[i].isFlip()) {
- if (abs(Random() % 2 == 0))
- player[i].setAnimation(backhandspringanim);
- else
- player[i].setAnimation(rollanim);
- player[i].targetyaw += 90 * (abs(Random() % 2) * 2 - 1);
- player[i].wentforweapon = 0;
- }
- if (player[i].animTarget == jumpupanim || player[i].animTarget == jumpdownanim)
- player[i].setAnimation(flipanim);
- }
- }
- player[i].forwardkeydown = 0;
- player[i].aiupdatedelay = .02;
- }
- //get confused by flips
- if (player[0].isFlip() &&
- !player[0].skeleton.free &&
- player[0].animTarget != walljumprightkickanim &&
- player[0].animTarget != walljumpleftkickanim) {
- if (distsq(&player[0].coords, &player[i].coords) < 25)
- if ((1 - player[i].damage / player[i].damagetolerance) > .5)
- player[i].stunned = 1;
- }
- //go for weapon on the ground
- if (player[i].wentforweapon < 3)
- for (int k = 0; k < weapons.size(); k++)
- if (player[i].creature != wolftype)
- if (player[i].num_weapons == 0 &&
- weapons[k].owner == -1 &&
- weapons[i].velocity.x == 0 &&
- weapons[i].velocity.z == 0 &&
- weapons[i].velocity.y == 0) {
- if (distsq(&player[i].coords, &weapons[k].position) < 16) {
- player[i].wentforweapon++;
- player[i].lastchecktime = 6;
- player[i].aitype = getweapontype;
- player[i].ally = -1;
- }
- }
- //dodge/reverse walljump kicks
- if (player[i].damage < player[i].damagetolerance / 2)
- if (animation[player[i].animTarget].height != highheight)
- if (player[i].damage < player[i].damagetolerance * .5 &&
- ((player[0].animTarget == walljumprightkickanim ||
- player[0].animTarget == walljumpleftkickanim) &&
- ((player[i].aiupdatedelay < .15 &&
- difficulty == 2) ||
- (player[i].aiupdatedelay < .08 &&
- difficulty != 2)))) {
- player[i].crouchkeydown = 1;
- }
- //walked off a ledge (?)
- if (player[i].isRun() && !player[i].onground)
- if (player[i].coords.y > terrain.getHeight(player[i].coords.x, player[i].coords.z) + 10) {
- XYZ test2 = player[i].coords + player[i].facing;
- test2.y += 5;
- XYZ test = player[i].coords + player[i].facing;
- test.y -= 10;
- j = checkcollide(test2, test, player[i].laststanding);
- if (j == -1)
- j = checkcollide(test2, test);
- if (j == -1) {
- player[i].velocity = 0;
- player[i].setAnimation(player[i].getStop());
- player[i].targetyaw += 180;
- player[i].stunned = .5;
- player[i].aitype = pathfindtype;
- player[i].finalfinaltarget = player[i].waypoints[player[i].waypoint];
- player[i].finalpathfindpoint = -1;
- player[i].targetpathfindpoint = -1;
- player[i].lastpathfindpoint = -1;
- player[i].lastpathfindpoint2 = -1;
- player[i].lastpathfindpoint3 = -1;
- player[i].lastpathfindpoint4 = -1;
- } else
- player[i].laststanding = j;
- }
- //lose sight of player in the air (?)
- if (player[0].coords.y > player[i].coords.y + 5 &&
- animation[player[0].animTarget].height != highheight &&
- !player[0].onterrain) {
- player[i].aitype = pathfindtype;
- player[i].finalfinaltarget = player[i].waypoints[player[i].waypoint];
- player[i].finalpathfindpoint = -1;
- player[i].targetpathfindpoint = -1;
- player[i].lastpathfindpoint = -1;
- player[i].lastpathfindpoint2 = -1;
- player[i].lastpathfindpoint3 = -1;
- player[i].lastpathfindpoint4 = -1;
- }
- //it's time to think (?)
- if (player[i].aiupdatedelay < 0 &&
- !animation[player[i].animTarget].attack &&
- player[i].animTarget != staggerbackhighanim &&
- player[i].animTarget != staggerbackhardanim &&
- player[i].animTarget != backhandspringanim &&
- player[i].animTarget != dodgebackanim) {
- //draw weapon
- if (player[i].weaponactive == -1 && player[i].num_weapons > 0)
- player[i].drawkeydown = Random() % 2;
- else
- player[i].drawkeydown = 0;
- player[i].rabbitkickenabled = Random() % 2;
- //chase player
- XYZ rotatetarget = player[0].coords + player[0].velocity;
- XYZ targetpoint = player[0].coords;
- if (distsq(&player[0].coords, &player[i].coords) <
- distsq(&rotatetarget, &player[i].coords))
- targetpoint += player[0].velocity *
- findDistance(&player[0].coords, &player[i].coords) / findLength(&player[i].velocity);
- player[i].targetyaw = roughDirectionTo(player[i].coords, targetpoint);
- player[i].lookyaw = player[i].targetyaw;
- player[i].aiupdatedelay = .2 + fabs((float)(Random() % 100) / 1000);
-
- if (distsq(&player[i].coords, &player[0].coords) > 5 && (player[0].weaponactive == -1 || player[i].weaponactive != -1))
- player[i].forwardkeydown = 1;
- else if ((distsq(&player[i].coords, &player[0].coords) > 16 ||
- distsq(&player[i].coords, &player[0].coords) < 9) &&
- player[0].weaponactive != -1)
- player[i].forwardkeydown = 1;
- else if (Random() % 6 == 0 || (player[i].creature == wolftype && Random() % 3 == 0))
- player[i].forwardkeydown = 1;
- else
- player[i].forwardkeydown = 0;
- //chill out around the corpse
- if (player[0].dead) {
- player[i].forwardkeydown = 0;
- if (Random() % 10 == 0)
- player[i].forwardkeydown = 1;
- if (Random() % 100 == 0) {
- player[i].aitype = pathfindtype;
- player[i].finalfinaltarget = player[i].waypoints[player[i].waypoint];
- player[i].finalpathfindpoint = -1;
- player[i].targetpathfindpoint = -1;
- player[i].lastpathfindpoint = -1;
- player[i].lastpathfindpoint2 = -1;
- player[i].lastpathfindpoint3 = -1;
- player[i].lastpathfindpoint4 = -1;
- }
- }
- player[i].leftkeydown = 0;
- player[i].backkeydown = 0;
- player[i].rightkeydown = 0;
- player[i].crouchkeydown = 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);
- //attack!!!
- if (Random() % 2 == 0 || player[i].weaponactive != -1 || player[i].creature == wolftype)
- player[i].attackkeydown = 1;
- else
- player[i].attackkeydown = 0;
- if (player[i].isRun() && Random() % 6 && distsq(&player[i].coords, &player[0].coords) > 7)
- player[i].attackkeydown = 0;
-
- //TODO: wat
- if (player[i].aitype != playercontrolled &&
- (player[i].isIdle() ||
- player[i].isCrouch() ||
- player[i].isRun())) {
- int target = -2;
- for (int j = 0; j < numplayers; j++)
- if (j != i && !player[j].skeleton.free &&
- player[j].hasvictim &&
- (tutoriallevel == 1 && reversaltrain ||
- Random() % 2 == 0 && difficulty == 2 ||
- Random() % 4 == 0 && difficulty == 1 ||
- Random() % 8 == 0 && difficulty == 0 ||
- player[j].lastattack2 == player[j].animTarget &&
- player[j].lastattack3 == player[j].animTarget &&
- (Random() % 2 == 0 || difficulty == 2) ||
- (player[i].isIdle() || player[i].isRun()) &&
- player[j].weaponactive != -1 ||
- player[j].animTarget == swordslashanim &&
- player[i].weaponactive != -1 ||
- player[j].animTarget == staffhitanim ||
- player[j].animTarget == staffspinhitanim))
- if (distsq(&player[j].coords, &player[j].victim->coords) < 4 &&
- player[j].victim == &player[i] &&
- (player[j].animTarget == sweepanim ||
- player[j].animTarget == spinkickanim ||
- player[j].animTarget == staffhitanim ||
- player[j].animTarget == staffspinhitanim ||
- player[j].animTarget == winduppunchanim ||
- player[j].animTarget == upunchanim ||
- player[j].animTarget == wolfslapanim ||
- player[j].animTarget == knifeslashstartanim ||
- player[j].animTarget == swordslashanim &&
- (distsq(&player[j].coords, &player[i].coords) < 2 ||
- player[i].weaponactive != -1))) {
- if (target >= 0)
- target = -1;
- else
- target = j;