- }
- }
- 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;
- }
- }
- }
- }
- }
- //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;
- }
- if (target >= 0)
- player[target].Reverse();
- }
-
- if (player[i].collided < 1)
- player[i].jumpkeydown = 0;
- if (player[i].collided > .8 && player[i].jumppower >= 5 ||
- distsq(&player[i].coords, &player[0].coords) > 400 &&
- player[i].onterrain &&
- player[i].creature == rabbittype)
- player[i].jumpkeydown = 1;
- //TODO: why are we controlling the human?
- if (normaldotproduct(player[i].facing, player[0].coords - player[i].coords) > 0)
- player[0].jumpkeydown = 0;
- if (player[0].animTarget == jumpdownanim &&
- distsq(&player[0].coords, &player[i].coords) < 40)
- player[i].crouchkeydown = 1;
- if (player[i].jumpkeydown)
- player[i].attackkeydown = 0;
-
- if (tutoriallevel == 1)
- if (!canattack)
- player[i].attackkeydown = 0;
-
-
- XYZ facing = player[i].coords;
- XYZ flatfacing = player[0].coords;
- facing.y += player[i].jointPos(head).y * player[i].scale;
- flatfacing.y += player[0].jointPos(head).y * player[0].scale;
- if (player[i].occluded >= 2)
- if (-1 != checkcollide(facing, flatfacing)) {
- if (!player[i].pause)
- player[i].lastseentime -= .2;
- if (player[i].lastseentime <= 0 &&
- (player[i].creature != wolftype ||
- player[i].weaponstuck == -1)) {
- player[i].aitype = searchtype;
- player[i].lastchecktime = 12;
- player[i].lastseen = player[0].coords;
- player[i].lastseentime = 12;
- }
- } else
- player[i].lastseentime = 1;
- }
- }
- if (animation[player[0].animTarget].height == highheight &&
- (player[i].aitype == attacktypecutoff ||
- player[i].aitype == searchtype))
- if (player[0].coords.y > terrain.getHeight(player[0].coords.x, player[0].coords.z) + 10) {
- XYZ test = player[0].coords;
- test.y -= 40;
- if (-1 == checkcollide(player[0].coords, test))
- player[i].stunned = 1;
- }
- //stunned
- if (player[i].aitype == passivetype && !(player[i].numwaypoints > 1) ||
- player[i].stunned > 0 ||
- player[i].pause && player[i].damage > player[i].superpermanentdamage) {
- if (player[i].pause)
- player[i].lastseentime = 1;
- player[i].targetyaw = player[i].yaw;
- player[i].forwardkeydown = 0;
- player[i].leftkeydown = 0;
- player[i].backkeydown = 0;
- player[i].rightkeydown = 0;
- player[i].jumpkeydown = 0;
- player[i].attackkeydown = 0;
- player[i].crouchkeydown = 0;
- player[i].throwkeydown = 0;
- }
-
-
- XYZ facing;
- facing = 0;
- facing.z = -1;
-
- XYZ flatfacing = DoRotation(facing, 0, player[i].yaw + 180, 0);
- facing = flatfacing;
-
- if (player[i].aitype == attacktypecutoff) {
- player[i].targetheadyaw = 180 - roughDirectionTo(player[i].coords, player[0].coords);
- player[i].targetheadpitch = pitchTo(player[i].coords, player[0].coords);
- } else if (player[i].howactive >= typesleeping) {
- player[i].targetheadyaw = player[i].targetyaw;
- player[i].targetheadpitch = 0;
- } else {
- if (player[i].interestdelay <= 0) {
- player[i].interestdelay = .7 + (float)(abs(Random() % 100)) / 100;
- player[i].headtarget = player[i].coords;
- player[i].headtarget.x += (float)(abs(Random() % 200) - 100) / 100;
- player[i].headtarget.z += (float)(abs(Random() % 200) - 100) / 100;
- player[i].headtarget.y += (float)(abs(Random() % 200) - 100) / 300;
- player[i].headtarget += player[i].facing * 1.5;
- }
- player[i].targetheadyaw = 180 - roughDirectionTo(player[i].coords, player[i].headtarget);
- player[i].targetheadpitch = pitchTo(player[i].coords, player[i].headtarget);
- }
- }
-}
-
-
-
-void updateSettingsMenu()
-{
- char sbuf[256];
- if ((float)newscreenwidth > (float)newscreenheight * 1.61 || (float)newscreenwidth < (float)newscreenheight * 1.59)
- sprintf (sbuf, "Resolution: %d*%d", (int)newscreenwidth, (int)newscreenheight);
- else
- sprintf (sbuf, "Resolution: %d*%d (widescreen)", (int)newscreenwidth, (int)newscreenheight);
- Menu::setText(0, sbuf);
- if (newdetail == 0) Menu::setText(1, "Detail: Low");
- if (newdetail == 1) Menu::setText(1, "Detail: Medium");
- if (newdetail == 2) Menu::setText(1, "Detail: High");
- if (bloodtoggle == 0) Menu::setText(2, "Blood: Off");
- if (bloodtoggle == 1) Menu::setText(2, "Blood: On, low detail");
- if (bloodtoggle == 2) Menu::setText(2, "Blood: On, high detail (slower)");
- if (difficulty == 0) Menu::setText(3, "Difficulty: Easier");
- if (difficulty == 1) Menu::setText(3, "Difficulty: Difficult");
- if (difficulty == 2) Menu::setText(3, "Difficulty: Insane");
- Menu::setText(4, ismotionblur ? "Blur Effects: Enabled (less compatible)" : "Blur Effects: Disabled (more compatible)");
- Menu::setText(5, decals ? "Decals: Enabled (slower)" : "Decals: Disabled");
- Menu::setText(6, musictoggle ? "Music: Enabled" : "Music: Disabled");
- Menu::setText(9, invertmouse ? "Invert mouse: Yes" : "Invert mouse: No");
- sprintf (sbuf, "Mouse Speed: %d", (int)(usermousesensitivity * 5));
- Menu::setText(10, sbuf);
- sprintf (sbuf, "Volume: %d%%", (int)(volume * 100));
- Menu::setText(11, sbuf);
- Menu::setText(13, showdamagebar ? "Damage Bar: On" : "Damage Bar: Off");
- if (newdetail == detail && newscreenheight == (int)screenheight && newscreenwidth == (int)screenwidth)
- sprintf (sbuf, "Back");
- else
- sprintf (sbuf, "Back (some changes take effect next time Lugaru is opened)");
- Menu::setText(8, sbuf);
-}
-
-void updateStereoConfigMenu()
-{
- char sbuf[256];
- sprintf(sbuf, "Stereo mode: %s", StereoModeName(newstereomode));
- Menu::setText(0, sbuf);
- sprintf(sbuf, "Stereo separation: %.3f", stereoseparation);
- Menu::setText(1, sbuf);
- sprintf(sbuf, "Reverse stereo: %s", stereoreverse ? "Yes" : "No");
- Menu::setText(2, sbuf);
-}
-
-void updateControlsMenu()
-{
- Menu::setText(0, (string)"Forwards: " + (keyselect == 0 ? "_" : Input::keyToChar(forwardkey)));
- Menu::setText(1, (string)"Back: " + (keyselect == 1 ? "_" : Input::keyToChar(backkey)));
- Menu::setText(2, (string)"Left: " + (keyselect == 2 ? "_" : Input::keyToChar(leftkey)));
- Menu::setText(3, (string)"Right: " + (keyselect == 3 ? "_" : Input::keyToChar(rightkey)));
- Menu::setText(4, (string)"Crouch: " + (keyselect == 4 ? "_" : Input::keyToChar(crouchkey)));
- Menu::setText(5, (string)"Jump: " + (keyselect == 5 ? "_" : Input::keyToChar(jumpkey)));
- Menu::setText(6, (string)"Draw: " + (keyselect == 6 ? "_" : Input::keyToChar(drawkey)));
- Menu::setText(7, (string)"Throw: " + (keyselect == 7 ? "_" : Input::keyToChar(throwkey)));
- Menu::setText(8, (string)"Attack: " + (keyselect == 8 ? "_" : Input::keyToChar(attackkey)));
- if (debugmode)
- Menu::setText(9, (string)"Console: " + (keyselect == 9 ? "_" : Input::keyToChar(consolekey)));
-}
-
-/*
-Values of mainmenu :
-1 Main menu
-2 Menu pause (resume/end game)
-3 Option menu
-4 Controls configuration menu
-5 Main game menu (choose level or challenge)
-6 Deleting user menu
-7 User managment menu (select/add)
-8 Choose difficulty menu
-9 Challenge level selection menu
-10 End of the campaign congratulation (is that really a menu?)
-11 Same that 9 ??? => unused
-18 stereo configuration
-*/
-
-void Game::LoadMenu()
-{
- Menu::clearMenu();
- switch (mainmenu) {
- case 1:
- case 2:
- Menu::addImage(0, Mainmenuitems[0], 150, 480 - 128, 256, 128);
- Menu::addButtonImage(1, Mainmenuitems[mainmenu == 1 ? 1 : 5], 18, 480 - 152 - 32, 128, 32);
- Menu::addButtonImage(2, Mainmenuitems[2], 18, 480 - 228 - 32, 112, 32);
- Menu::addButtonImage(3, Mainmenuitems[mainmenu == 1 ? 3 : 6], 18, 480 - 306 - 32, mainmenu == 1 ? 68 : 132, 32);
- break;
- case 3:
- Menu::addButton( 0, "", 10 + 20, 440);
- Menu::addButton( 1, "", 10 + 60, 405);
- Menu::addButton( 2, "", 10 + 70, 370);
- Menu::addButton( 3, "", 10 + 20 - 1000, 335 - 1000);
- Menu::addButton( 4, "", 10 , 335);
- Menu::addButton( 5, "", 10 + 60, 300);
- Menu::addButton( 6, "", 10 + 70, 265);
- Menu::addButton( 9, "", 10 , 230);
- Menu::addButton(10, "", 20 , 195);
- Menu::addButton(11, "", 10 + 60, 160);
- Menu::addButton(13, "", 30 , 125);
- Menu::addButton( 7, "-Configure Controls-", 10 + 15, 90);
- Menu::addButton(12, "-Configure Stereo -", 10 + 15, 55);
- Menu::addButton(8, "Back", 10, 10);
- updateSettingsMenu();
- break;
- case 4:
- Menu::addButton(0, "", 10 , 400);
- Menu::addButton(1, "", 10 + 40, 360);
- Menu::addButton(2, "", 10 + 40, 320);
- Menu::addButton(3, "", 10 + 30, 280);
- Menu::addButton(4, "", 10 + 20, 240);
- Menu::addButton(5, "", 10 + 40, 200);
- Menu::addButton(6, "", 10 + 40, 160);
- Menu::addButton(7, "", 10 + 30, 120);
- Menu::addButton(8, "", 10 + 20, 80);
- if (debugmode)
- Menu::addButton(9, "", 10 + 10, 40);
- Menu::addButton(debugmode ? 10 : 9, "Back", 10, 10);
- updateControlsMenu();
- break;
- case 5: {
- LoadCampaign();
- Menu::addLabel(-1, accountactive->getName(), 5, 400);
- Menu::addButton(1, "Tutorial", 5, 300);
- Menu::addButton(2, "Challenge", 5, 240);
- Menu::addButton(3, "Delete User", 400, 10);
- Menu::addButton(4, "Main Menu", 5, 10);
- Menu::addButton(5, "Change User", 5, 180);
- Menu::addButton(6, "Campaign : " + accountactive->getCurrentCampaign(), 200, 420);
-
- //show campaign map
- //with (2,-5) offset from old code
- Menu::addImage(-1, Mainmenuitems[7], 150 + 2, 60 - 5, 400, 400);
- //show levels
- int numlevels = accountactive->getCampaignChoicesMade();
- numlevels += numlevels > 0 ? campaignlevels[numlevels - 1].nextlevel.size() : 1;
- for (int i = 0; i < numlevels; i++) {
- XYZ midpoint = campaignlevels[i].getCenter();
- float itemsize = campaignlevels[i].getWidth();
- const bool active = i >= accountactive->getCampaignChoicesMade();
- if (!active)
- itemsize /= 2;
-
- if (i >= 1) {
- XYZ start = campaignlevels[i - 1].getCenter();
- Menu::addMapLine(start.x, start.y, midpoint.x - start.x, midpoint.y - start.y, 0.5, active ? 1 : 0.5, active ? 1 : 0.5, 0, 0);
- }
- Menu::addMapMarker(NB_CAMPAIGN_MENU_ITEM + i, Mapcircletexture,
- midpoint.x - itemsize / 2, midpoint.y - itemsize / 2, itemsize, itemsize, active ? 1 : 0.5, 0, 0);
-
- if (active) {
- Menu::addMapLabel(-2, campaignlevels[i].description,
- campaignlevels[i].getStartX() + 10,
- campaignlevels[i].getStartY() - 4);
- }
- }
- }
- break;
- case 6:
- Menu::addLabel(-1, "Are you sure you want to delete this user?", 10, 400);
- Menu::addButton(1, "Yes", 10, 360);
- Menu::addButton(2, "No", 10, 320);
- break;
- case 7:
- if (Account::getNbAccounts() < 8)
- Menu::addButton(0, "New User", 10, 400);
- else
- Menu::addLabel(0, "No More Users", 10, 400);
- Menu::addLabel(-2, "", 20, 400);
- Menu::addButton(Account::getNbAccounts() + 1, "Back", 10, 10);
- for (int i = 0; i < Account::getNbAccounts(); i++)
- Menu::addButton(i + 1, Account::get(i)->getName(), 10, 340 - 20 * (i + 1));
- break;
- case 8:
- Menu::addButton(0, "Easier", 10, 400);
- Menu::addButton(1, "Difficult", 10, 360);
- Menu::addButton(2, "Insane", 10, 320);
- break;
- case 9:
- for (int i = 0; i < numchallengelevels; i++) {
- char temp[255];
- string name = "";
- sprintf (temp, "Level %d", i + 1);
- for (int j = strlen(temp); j < 17; j++)
- strcat(temp, " ");
- name += temp;
- sprintf (temp, "%d", (int)accountactive->getHighScore(i));
- for (int j = strlen(temp); j < (32 - 17); j++)
- strcat(temp, " ");
- name += temp;
- sprintf (temp, "%d:", (int)(((int)accountactive->getFastTime(i) - (int)(accountactive->getFastTime(i)) % 60) / 60));
- if ((int)(accountactive->getFastTime(i)) % 60 < 10)
- strcat(temp, "0");
- name += temp;
- sprintf (temp, "%d", (int)(accountactive->getFastTime(i)) % 60);
- name += temp;
-
- Menu::addButton(i, name, 10, 400 - i * 25, i > accountactive->getProgress() ? 0.5 : 1, 0, 0);
- }
-
- Menu::addButton(-1, " High Score Best Time", 10, 440);
- Menu::addButton(numchallengelevels, "Back", 10, 10);
- break;
- case 10: {
- Menu::addLabel(0, "Congratulations!", 220, 330);
- Menu::addLabel(1, "You have avenged your family and", 140, 300);
- Menu::addLabel(2, "restored peace to the island of Lugaru.", 110, 270);
- Menu::addButton(3, "Back", 10, 10);
- char sbuf[256];
- sprintf(sbuf, "Your score: %d", (int)accountactive->getCampaignScore());
- Menu::addLabel(4, sbuf, 190, 200);
- sprintf(sbuf, "Highest score: %d", (int)accountactive->getCampaignHighScore());
- Menu::addLabel(5, sbuf, 190, 180);
- }
- break;
- case 18:
- Menu::addButton(0, "", 70, 400);
- Menu::addButton(1, "", 10, 360);
- Menu::addButton(2, "", 40, 320);
- Menu::addButton(3, "Back", 10, 10);
- updateStereoConfigMenu();
- break;
- }
-}
-
-extern SDL_Rect **resolutions;
-
-void MenuTick()
-{
- //menu buttons
- selected = Menu::getSelected(mousecoordh * 640 / screenwidth, 480 - mousecoordv * 480 / screenheight);