- lowpointtarget = lowpoint + DoRotation(player[k].facing, 0, 90, 0) * 1.5;
- whichhit = objects.model[i].LineCheck(&lowpoint, &lowpointtarget, &colpoint, &objects.position[i], &objects.yaw[i]);
- if (whichhit != -1 && fabs(objects.model[i].facenormals[whichhit].y) < .3) {
- player[k].setAnimation(walljumprightanim);
- emit_sound_at(movewhooshsound, player[k].coords);
- if (k == 0)pause_sound(whooshsound);
-
- lowpointtarget = DoRotation(objects.model[i].facenormals[whichhit], 0, objects.yaw[i], 0);
- player[k].yaw = -asin(0 - lowpointtarget.x) * 180 / M_PI;
- if (lowpointtarget.z < 0)player[k].yaw = 180 - player[k].yaw;
- player[k].targetyaw = player[k].yaw;
- player[k].lowyaw = player[k].yaw;
- if (k == 0)numwallflipped++;
- } else {
- lowpoint = tempcoords1;
- lowpointtarget = lowpoint + player[k].facing * 2;
- whichhit = objects.model[i].LineCheck(&lowpoint, &lowpointtarget, &colpoint, &objects.position[i], &objects.yaw[i]);
- if (whichhit != -1 && fabs(objects.model[i].facenormals[whichhit].y) < .3) {
- player[k].setAnimation(walljumpbackanim);
- emit_sound_at(movewhooshsound, player[k].coords);
- if (k == 0)pause_sound(whooshsound);
-
- lowpointtarget = DoRotation(objects.model[i].facenormals[whichhit], 0, objects.yaw[i], 0);
- player[k].yaw = -asin(0 - lowpointtarget.x) * 180 / M_PI;
- if (lowpointtarget.z < 0)player[k].yaw = 180 - player[k].yaw;
- player[k].targetyaw = player[k].yaw;
- player[k].lowyaw = player[k].yaw;
- if (k == 0)numwallflipped++;
- } else {
- lowpoint = tempcoords1;
- lowpointtarget = lowpoint - player[k].facing * 2;
- whichhit = objects.model[i].LineCheck(&lowpoint, &lowpointtarget, &colpoint, &objects.position[i], &objects.yaw[i]);
- if (whichhit != -1 && fabs(objects.model[i].facenormals[whichhit].y) < .3) {
- player[k].setAnimation(walljumpfrontanim);
- emit_sound_at(movewhooshsound, player[k].coords);
- if (k == 0)pause_sound(whooshsound);
-
- lowpointtarget = DoRotation(objects.model[i].facenormals[whichhit], 0, objects.yaw[i], 0);
- player[k].yaw = -asin(0 - lowpointtarget.x) * 180 / M_PI;
- if (lowpointtarget.z < 0)player[k].yaw = 180 - player[k].yaw;
- player[k].yaw += 180;
- player[k].targetyaw = player[k].yaw;
- player[k].lowyaw = player[k].yaw;
- if (k == 0)numwallflipped++;
- }
- }
- }
- }
- }
- }
- } else if (objects.type[i] == rocktype) {
- lowpoint2 = player[k].coords;
- lowpoint = player[k].coords;
- lowpoint.y += 2;
- if (objects.model[i].LineCheck(&lowpoint, &lowpoint2, &colpoint, &objects.position[i], &objects.yaw[i]) != -1) {
- player[k].coords = colpoint;
- player[k].collide = 1;
- tempcollide = 1;
-
- if (player[k].animTarget == jumpdownanim || player[k].isFlip()) {
- //flipped into a rock
- if (player[k].isFlip() && animation[player[k].animTarget].label[player[k].frameTarget] == 7)
- player[k].RagDoll(0);
-
- if (player[k].animTarget == jumpupanim) {
- player[k].jumppower = -4;
- player[k].animTarget = player[k].getIdle();
- }
- player[k].target = 0;
- player[k].frameTarget = 0;
- player[k].onterrain = 1;
-
- if (player[k].id == 0) {
- pause_sound(whooshsound);
- OPENAL_SetVolume(channels[whooshsound], 0);
- }
-
- //landing
- if ((player[k].animTarget == jumpdownanim || player[k].isFlip()) && !player[k].wasLanding()) {
- if (player[k].isFlip())
- player[k].jumppower = -4;
- player[k].animTarget = player[k].getLanding();
- emit_sound_at(landsound, player[k].coords, 128.);
- if (k == 0) {
- envsound[numenvsounds] = player[k].coords;
- envsoundvol[numenvsounds] = 16;
- envsoundlife[numenvsounds] = .4;
- numenvsounds++;
- }
-
- }
- }
- }
- }
- }
-
- if (tempcollide && (/*player[k].jumptogglekeydown*/1 == 1 || player[k].aitype != playercontrolled))
- for (int l = 0; l < terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz]; l++) {
- int i = terrain.patchobjects[player[k].whichpatchx][player[k].whichpatchz][l];
- lowpoint = player[k].coords;
- lowpoint.y += 1.35;
- if (objects.type[i] != rocktype)
- if (player[k].SphereCheck(&lowpoint, 1.33, &colpoint, &objects.position[i], &objects.yaw[i], &objects.model[i]) != -1) {
- if (player[k].animTarget != jumpupanim &&
- player[k].animTarget != jumpdownanim &&
- player[k].onterrain)
- player[k].avoidcollided = 1;
- player[k].coords = lowpoint;
- player[k].coords.y -= 1.35;
- player[k].collide = 1;
-
- if ((player[k].grabdelay <= 0 || player[k].aitype != playercontrolled) &&
- (player[k].animCurrent != climbanim &&
- player[k].animCurrent != hanganim &&
- !player[k].isWallJump() ||
- player[k].animTarget == jumpupanim ||
- player[k].animTarget == jumpdownanim)) {
- lowpoint = player[k].coords;
- objects.model[i].SphereCheckPossible(&lowpoint, 1.5, &objects.position[i], &objects.yaw[i]);
- lowpoint = player[k].coords;
- lowpoint.y += .05;
- facing = 0;
- facing.z = -1;
- facing = DoRotation(facing, 0, player[k].targetyaw + 180, 0);
- lowpointtarget = lowpoint + facing * 1.4;
- whichhit = objects.model[i].LineCheckPossible(&lowpoint, &lowpointtarget, &colpoint, &objects.position[i], &objects.yaw[i]);
- if (whichhit != -1) {
- lowpoint = player[k].coords;
- lowpoint.y += .1;
- lowpointtarget = lowpoint + facing * 1.4;
- lowpoint2 = lowpoint;
- lowpointtarget2 = lowpointtarget;
- lowpoint3 = lowpoint;
- lowpointtarget3 = lowpointtarget;
- lowpoint4 = lowpoint;
- lowpointtarget4 = lowpointtarget;
- lowpoint5 = lowpoint;
- lowpointtarget5 = lowpointtarget;
- lowpoint6 = lowpoint;
- lowpointtarget6 = lowpointtarget;
- lowpoint7 = lowpoint;
- lowpointtarget7 = lowpoint;
- lowpoint2.x += .1;
- lowpointtarget2.x += .1;
- lowpoint3.z += .1;
- lowpointtarget3.z += .1;
- lowpoint4.x -= .1;
- lowpointtarget4.x -= .1;
- lowpoint5.z -= .1;
- lowpointtarget5.z -= .1;
- lowpoint6.y += 45 / 13;
- lowpointtarget6.y += 45 / 13;
- lowpointtarget6 += facing * .6;
- lowpointtarget7.y += 90 / 13;
- whichhit = objects.model[i].LineCheckPossible(&lowpoint, &lowpointtarget, &colpoint, &objects.position[i], &objects.yaw[i]);
- if (objects.friction[i] > .5)
- if (whichhit != -1) {
- if (whichhit != -1 && player[k].animTarget != jumpupanim && player[k].animTarget != jumpdownanim)
- player[k].collided = 1;
- if (checkcollide(lowpoint7, lowpointtarget7) == -1)
- if (checkcollide(lowpoint6, lowpointtarget6) == -1)
- if ( objects.model[i].LineCheckPossible(&lowpoint2, &lowpointtarget2,
- &colpoint, &objects.position[i], &objects.yaw[i]) != -1 &&
- objects.model[i].LineCheckPossible(&lowpoint3, &lowpointtarget3,
- &colpoint, &objects.position[i], &objects.yaw[i]) != -1 &&
- objects.model[i].LineCheckPossible(&lowpoint4, &lowpointtarget4,
- &colpoint, &objects.position[i], &objects.yaw[i]) != -1 &&
- objects.model[i].LineCheckPossible(&lowpoint5, &lowpointtarget5,
- &colpoint, &objects.position[i], &objects.yaw[i]) != -1)
- for (int j = 0; j < 45; j++) {
- lowpoint = player[k].coords;
- lowpoint.y += (float)j / 13;
- lowpointtarget = lowpoint + facing * 1.4;
- if (objects.model[i].LineCheckPossible(&lowpoint, &lowpointtarget,
- &colpoint2, &objects.position[i], &objects.yaw[i]) == -1) {
- if (j <= 6 || j <= 25 && player[k].animTarget == jumpdownanim)
- break;
- if (player[k].animTarget == jumpupanim || player[k].animTarget == jumpdownanim) {
- lowpoint = DoRotation(objects.model[i].facenormals[whichhit], 0, objects.yaw[k], 0);
- lowpoint = player[k].coords;
- lowpoint.y += (float)j / 13;
- lowpointtarget = lowpoint + facing * 1.3;
- flatfacing = player[k].coords;
- player[k].coords = colpoint - DoRotation(objects.model[i].facenormals[whichhit], 0, objects.yaw[k], 0) * .01;
- player[k].coords.y = lowpointtarget.y - .07;
- player[k].currentoffset = (flatfacing - player[k].coords) / player[k].scale;
-
- if (j > 10 || !player[k].isRun()) {
- if (player[k].animTarget == jumpdownanim || player[k].animTarget == jumpupanim) {
- if (k == 0)
- pause_sound(whooshsound);
- }
- emit_sound_at(jumpsound, player[k].coords, 128.);
-
- lowpointtarget = DoRotation(objects.model[i].facenormals[whichhit], 0, objects.yaw[i], 0);
- player[k].yaw = -asin(0 - lowpointtarget.x) * 180 / M_PI;
- if (lowpointtarget.z < 0)
- player[k].yaw = 180 - player[k].yaw;
- player[k].targetyaw = player[k].yaw;
- player[k].lowyaw = player[k].yaw;
-
- //player[k].velocity=lowpointtarget*.03;
- player[k].velocity = 0;
-
- //climb ledge (?)
- if (player[k].animTarget == jumpupanim) {
- player[k].animTarget = climbanim;
- player[k].jumppower = 0;
- player[k].jumpclimb = 1;
- }
- player[k].transspeed = 6;
- player[k].target = 0;
- player[k].frameTarget = 1;
- //hang ledge (?)
- if (j > 25) {
- player[k].setAnimation(hanganim);
- player[k].jumppower = 0;
- }
- }
- break;
- }
- }
- }
- }
- }
- }
- }
- }
- if (player[k].collide <= 0) {
- //in the air
- if (!player[k].onterrain &&
- player[k].animTarget != jumpupanim &&
- player[k].animTarget != jumpdownanim &&
- player[k].animTarget != climbanim &&
- player[k].animTarget != hanganim &&
- !player[k].isWallJump() &&
- !player[k].isFlip()) {
- if (player[k].animCurrent != climbanim &&
- player[k].animCurrent != tempanim &&
- player[k].animTarget != backhandspringanim &&
- (player[k].animTarget != rollanim ||
- player[k].frameTarget < 2 ||
- player[k].frameTarget > 6)) {
- //stagger off ledge (?)
- if (player[k].animTarget == staggerbackhighanim || player[k].animTarget == staggerbackhardanim)
- player[k].RagDoll(0);
- player[k].setAnimation(jumpdownanim);
-
- if (!k)
- emit_sound_at(whooshsound, player[k].coords, 128.);
- }
- //gravity
- player[k].velocity.y += gravity;
- }
- }
- }
- player[k].realoldcoords = player[k].coords;
- }
-}
-
-void doAttacks()
-{
- static XYZ relative;
- static int randattack;
- static bool playerrealattackkeydown = 0;
-
- if (!Input::isKeyDown(attackkey))
- oldattackkey = 0;
- if (oldattackkey)
- player[0].attackkeydown = 0;
- if (oldattackkey)
- playerrealattackkeydown = 0;
- if (!oldattackkey)
- playerrealattackkeydown = Input::isKeyDown(attackkey);
- if ((player[0].parriedrecently <= 0 ||
- player[0].weaponactive == -1) &&
- (!oldattackkey ||
- (realthreat &&
- player[0].lastattack != swordslashanim &&
- player[0].lastattack != knifeslashstartanim &&
- player[0].lastattack != staffhitanim &&
- player[0].lastattack != staffspinhitanim)))
- player[0].attackkeydown = Input::isKeyDown(attackkey);
- if (Input::isKeyDown(attackkey) &&
- !oldattackkey &&
- !player[0].backkeydown) {
- for (int k = 0; k < numplayers; k++) {
- if ((player[k].animTarget == swordslashanim ||
- player[k].animTarget == staffhitanim ||
- player[k].animTarget == staffspinhitanim) &&
- player[0].animCurrent != dodgebackanim &&
- !player[k].skeleton.free)
- player[k].Reverse();
- }
- }
-
- if (!hostile || indialogue != -1)player[0].attackkeydown = 0;
-
- for (int k = 0; k < numplayers; k++) {
- if (indialogue != -1)player[k].attackkeydown = 0;
- if (player[k].animTarget != rabbitrunninganim && player[k].animTarget != wolfrunninganim) {
- if (player[k].aitype != playercontrolled)
- player[k].victim = &player[0];
- //attack key pressed
- if (player[k].attackkeydown) {
- //dodge backward
- if (player[k].backkeydown &&
- player[k].animTarget != backhandspringanim &&
- (player[k].isIdle() ||
- player[k].isStop() ||
- player[k].isRun() ||
- player[k].animTarget == walkanim)) {
- if (player[k].jumppower <= 1) {
- player[k].jumppower -= 2;
- } else {
- for (int i = 0; i < numplayers; i++) {
- if (i == k)continue;
- if (player[i].animTarget == swordslashanim ||
- player[i].animTarget == knifeslashstartanim ||
- player[i].animTarget == staffhitanim ||
- player[i].animTarget == staffspinhitanim)
- if (distsq(&player[k].coords, &player[i].coords) < 6.5 && !player[i].skeleton.free) {
- player[k].setAnimation(dodgebackanim);
- player[k].targetyaw = roughDirectionTo(player[k].coords, player[i].coords);
- player[k].targettilt2 = pitchTo(player[k].coords, player[i].coords);
- }
- }
- if (player[k].animTarget != dodgebackanim) {
- if (k == 0)numflipped++;
- player[k].setAnimation(backhandspringanim);
- player[k].targetyaw = -yaw + 180;
- if (player[k].leftkeydown)
- player[k].targetyaw -= 45;
- if (player[k].rightkeydown)
- player[k].targetyaw += 45;
- player[k].yaw = player[k].targetyaw;
- player[k].jumppower -= 2;
- }
- }
- }
- //attack
- if (!animation[player[k].animTarget].attack &&
- !player[k].backkeydown &&
- (player[k].isIdle() ||
- player[k].isRun() ||
- player[k].animTarget == walkanim ||
- player[k].animTarget == sneakanim ||
- player[k].isCrouch())) {
- const int attackweapon = player[k].weaponactive == -1 ? 0 : weapons[player[k].weaponids[player[k].weaponactive]].getType();
- //normal attacks (?)
- player[k].hasvictim = 0;
- if (numplayers > 1)
- for (int i = 0; i < numplayers; i++) {
- if (i == k || !(k == 0 || i == 0))continue;
- if (!player[k].hasvictim)
- if (animation[player[k].animTarget].attack != reversal) {
- //choose an attack
- const float distance = distsq(&player[k].coords, &player[i].coords);
- if (distance < 4.5 &&
- !player[i].skeleton.free &&
- player[i].howactive < typedead1 &&
- player[i].animTarget != jumpreversedanim &&
- player[i].animTarget != rabbitkickreversedanim &&
- player[i].animTarget != rabbitkickanim &&
- player[k].animTarget != rabbitkickanim &&
- player[i].animTarget != getupfrombackanim &&
- (player[i].animTarget != staggerbackhighanim &&
- (player[i].animTarget != staggerbackhardanim ||
- animation[staggerbackhardanim].label[player[i].frameTarget] == 6)) &&
- player[i].animTarget != jumpdownanim &&
- player[i].animTarget != jumpupanim &&
- player[i].animTarget != getupfromfrontanim) {
- player[k].victim = &player[i];
- player[k].hasvictim = 1;
- if (player[k].aitype == playercontrolled) { //human player
- //sweep
- if (distance < 2.5 * sq(player[k].scale * 5) &&
- player[k].crouchkeydown &&
- animation[player[i].animTarget].height != lowheight)
- player[k].animTarget = sweepanim;
- //winduppunch
- else if (distance < 1.5 * sq(player[k].scale * 5) &&
- animation[player[i].animTarget].height != lowheight &&
- !player[k].forwardkeydown &&
- !player[k].leftkeydown &&
- !player[k].rightkeydown &&
- !player[k].crouchkeydown &&
- !attackweapon &&
- !reversaltrain)
- player[k].animTarget = winduppunchanim;
- //upunch
- else if (distance < 2.5 * sq(player[k].scale * 5) &&
- animation[player[i].animTarget].height != lowheight &&
- !player[k].forwardkeydown &&
- !player[k].leftkeydown &&
- !player[k].rightkeydown &&
- !player[k].crouchkeydown &&
- !attackweapon)
- player[k].animTarget = upunchanim;
- //knifefollow
- else if (distance < 2.5 * sq(player[k].scale * 5) &&
- player[i].staggerdelay > 0 &&
- attackweapon == knife &&
- player[i].bloodloss > player[i].damagetolerance / 2)
- player[k].animTarget = knifefollowanim;
- //knifeslashstart
- else if (distance < 2.5 * sq(player[k].scale * 5) &&
- animation[player[i].animTarget].height != lowheight &&
- !player[k].forwardkeydown &&
- !player[k].leftkeydown &&
- !player[k].rightkeydown &&
- !player[k].crouchkeydown &&
- attackweapon == knife &&
- player[k].weaponmissdelay <= 0)
- player[k].animTarget = knifeslashstartanim;
- //swordslash
- else if (distance < 4.5 * sq(player[k].scale * 5) &&
- animation[player[i].animTarget].height != lowheight &&
- !player[k].crouchkeydown &&
- attackweapon == sword &&
- player[k].weaponmissdelay <= 0)
- player[k].animTarget = swordslashanim;
- //staffhit
- else if (distance < 4.5 * sq(player[k].scale * 5) &&
- animation[player[i].animTarget].height != lowheight &&
- !player[k].crouchkeydown &&
- attackweapon == staff &&
- player[k].weaponmissdelay <= 0 &&
- !player[k].leftkeydown &&
- !player[k].rightkeydown &&
- !player[k].forwardkeydown)
- player[k].animTarget = staffhitanim;
- //staffspinhit
- else if (distance < 4.5 * sq(player[k].scale * 5) &&
- animation[player[i].animTarget].height != lowheight &&
- !player[k].crouchkeydown &&
- attackweapon == staff &&
- player[k].weaponmissdelay <= 0)
- player[k].animTarget = staffspinhitanim;
- //spinkick
- else if (distance < 2.5 * sq(player[k].scale * 5) &&
- animation[player[i].animTarget].height != lowheight)
- player[k].animTarget = spinkickanim;
- //lowkick
- else if (distance < 2.5 * sq(player[k].scale * 5) &&
- animation[player[i].animTarget].height == lowheight &&
- animation[player[k].animTarget].attack != normalattack)
- player[k].animTarget = lowkickanim;
- } else { //AI player
- if (distance < 4.5 * sq(player[k].scale * 5)) {
- randattack = abs(Random() % 5);
- if (!attackweapon && distance < 2.5 * sq(player[k].scale * 5)) {
- //sweep
- if (randattack == 0 && animation[player[i].animTarget].height != lowheight)
- player[k].animTarget = sweepanim;
- //upunch
- else if (randattack == 1 && animation[player[i].animTarget].height != lowheight &&
- !attackweapon)
- player[k].animTarget = upunchanim;
- //spinkick
- else if (randattack == 2 && animation[player[i].animTarget].height != lowheight)
- player[k].animTarget = spinkickanim;
- //lowkick
- else if (animation[player[i].animTarget].height == lowheight)
- player[k].animTarget = lowkickanim;
- }
- if (attackweapon) {
- //sweep
- if ((tutoriallevel != 1 || !attackweapon) &&
- distance < 2.5 * sq(player[k].scale * 5) &&
- randattack == 0 &&
- animation[player[i].animTarget].height != lowheight)
- player[k].animTarget = sweepanim;
- //knifeslashstart
- else if (distance < 2.5 * sq(player[k].scale * 5) &&
- attackweapon == knife &&
- player[k].weaponmissdelay <= 0)
- player[k].animTarget = knifeslashstartanim;
- //swordslash
- else if (!(player[0].victim == &player[i] &&
- player[0].hasvictim &&
- player[0].animTarget == swordslashanim) &&
- attackweapon == sword &&
- player[k].weaponmissdelay <= 0)
- player[k].animTarget = swordslashanim;
- //staffhit
- else if (!(player[0].victim == &player[i] &&
- player[0].hasvictim &&
- player[0].animTarget == swordslashanim) &&
- attackweapon == staff &&
- player[k].weaponmissdelay <= 0 &&
- randattack < 3)
- player[k].animTarget = staffhitanim;
- //staffspinhit
- else if (!(player[0].victim == &player[i] &&
- player[0].hasvictim &&
- player[0].animTarget == swordslashanim) &&
- attackweapon == staff &&
- player[k].weaponmissdelay <= 0 &&
- randattack >= 3)
- player[k].animTarget = staffspinhitanim;
- //spinkick
- else if ((tutoriallevel != 1 || !attackweapon) &&
- distance < 2.5 * sq(player[k].scale * 5) &&
- randattack == 1 &&
- animation[player[i].animTarget].height != lowheight)
- player[k].animTarget = spinkickanim;
- //lowkick
- else if (distance < 2.5 * sq(player[k].scale * 5) &&
- animation[player[i].animTarget].height == lowheight &&
- animation[player[k].animTarget].attack != normalattack)
- player[k].animTarget = lowkickanim;
- }
- }
- }
- //upunch becomes wolfslap
- if (player[k].animTarget == upunchanim && player[k].creature == wolftype)
- player[k].animTarget = wolfslapanim;
- }
- //sneak attacks
- if ((k == 0) && (tutoriallevel != 1 || tutorialstage == 22) &&
- player[i].howactive < typedead1 &&
- distance < 1.5 * sq(player[k].scale * 5) &&
- !player[i].skeleton.free &&
- player[i].animTarget != getupfrombackanim &&
- player[i].animTarget != getupfromfrontanim &&
- (player[i].stunned > 0 && player[k].madskills ||
- player[i].surprised > 0 ||
- player[i].aitype == passivetype ||
- attackweapon && player[i].stunned > 0) &&
- normaldotproduct(player[i].facing, player[i].coords - player[k].coords) > 0) {
- //sneakattack
- if (!attackweapon) {
- player[k].animCurrent = sneakattackanim;
- player[k].animTarget = sneakattackanim;
- player[i].animCurrent = sneakattackedanim;
- player[i].animTarget = sneakattackedanim;
- player[k].oldcoords = player[k].coords;
- player[k].coords = player[i].coords;
- }
- //knifesneakattack
- if (attackweapon == knife) {
- player[k].animCurrent = knifesneakattackanim;
- player[k].animTarget = knifesneakattackanim;
- player[i].animCurrent = knifesneakattackedanim;
- player[i].animTarget = knifesneakattackedanim;
- player[i].oldcoords = player[i].coords;
- player[i].coords = player[k].coords;
- }
- //swordsneakattack
- if (attackweapon == sword) {
- player[k].animCurrent = swordsneakattackanim;
- player[k].animTarget = swordsneakattackanim;
- player[i].animCurrent = swordsneakattackedanim;
- player[i].animTarget = swordsneakattackedanim;
- player[i].oldcoords = player[i].coords;
- player[i].coords = player[k].coords;
- }
- if (attackweapon != staff) {
- player[k].victim = &player[i];
- player[k].hasvictim = 1;
- player[i].targettilt2 = 0;
- player[i].frameTarget = 1;
- player[i].frameCurrent = 0;
- player[i].target = 0;
- player[i].velocity = 0;
- player[k].targettilt2 = player[i].targettilt2;
- player[k].frameCurrent = player[i].frameCurrent;
- player[k].frameTarget = player[i].frameTarget;
- player[k].target = player[i].target;
- player[k].velocity = 0;
- player[k].targetyaw = player[i].yaw;
- player[k].yaw = player[i].yaw;
- player[i].targetyaw = player[i].yaw;
- }
- }
- if (animation[player[k].animTarget].attack == normalattack &&
- player[k].victim == &player[i] &&
- (!player[i].skeleton.free)) {
- oldattackkey = 1;
- player[k].frameTarget = 0;
- player[k].target = 0;
-
- player[k].targetyaw = roughDirectionTo(player[k].coords, player[i].coords);
- player[k].targettilt2 = pitchTo(player[k].coords, player[i].coords);
- player[k].lastattack3 = player[k].lastattack2;
- player[k].lastattack2 = player[k].lastattack;
- player[k].lastattack = player[k].animTarget;
- }
- if (player[k].animTarget == knifefollowanim &&
- player[k].victim == &player[i]) {
- oldattackkey = 1;
- player[k].targetyaw = roughDirectionTo(player[k].coords, player[i].coords);
- player[k].targettilt2 = pitchTo(player[k].coords, player[i].coords);
- player[k].victim = &player[i];
- player[k].hasvictim = 1;
- player[i].animTarget = knifefollowedanim;
- player[i].animCurrent = knifefollowedanim;
- player[i].targettilt2 = 0;
- player[i].targettilt2 = player[k].targettilt2;
- player[i].frameTarget = 1;
- player[i].frameCurrent = 0;
- player[i].target = 0;
- player[i].velocity = 0;
- player[k].animCurrent = knifefollowanim;
- player[k].animTarget = knifefollowanim;
- player[k].targettilt2 = player[i].targettilt2;
- player[k].frameCurrent = player[i].frameCurrent;
- player[k].frameTarget = player[i].frameTarget;
- player[k].target = player[i].target;
- player[k].velocity = 0;
- player[k].oldcoords = player[k].coords;
- player[i].coords = player[k].coords;
- player[i].targetyaw = player[k].targetyaw;
- player[i].yaw = player[k].targetyaw;
- player[k].yaw = player[k].targetyaw;
- player[i].yaw = player[k].targetyaw;
- }
- }
- }
- const bool hasstaff = attackweapon == staff;
- if (k == 0 && numplayers > 1)
- for (int i = 0; i < numplayers; i++) {
- if (i == k)continue;
- if ((playerrealattackkeydown || player[i].dead || !hasstaff) &&
- animation[player[k].animTarget].attack == neutral) {
- const float distance = distsq(&player[k].coords, &player[i].coords);
- if (!player[i].dead || !realthreat || (!attackweapon && player[k].crouchkeydown))
- if (player[i].skeleton.free)
- if (distance < 3.5 * sq(player[k].scale * 5) &&
- (player[i].dead ||
- player[i].skeleton.longdead > 1000 ||
- player[k].isRun() ||
- hasstaff ||
- (attackweapon &&
- (player[i].skeleton.longdead > 2000 ||
- player[i].damage > player[i].damagetolerance / 8 ||
- player[i].bloodloss > player[i].damagetolerance / 2) &&
- distance < 1.5 * sq(player[k].scale * 5)))) {
- player[k].victim = &player[i];
- player[k].hasvictim = 1;
- if (attackweapon && tutoriallevel != 1) {
- //crouchstab
- if (player[k].crouchkeydown && attackweapon == knife && distance < 1.5 * sq(player[k].scale * 5))
- player[k].animTarget = crouchstabanim;
- //swordgroundstab
- if (player[k].crouchkeydown && distance < 1.5 * sq(player[k].scale * 5) && attackweapon == sword)
- player[k].animTarget = swordgroundstabanim;
- //staffgroundsmash
- if (distance < 3.5 * sq(player[k].scale * 5) && attackweapon == staff)
- player[k].animTarget = staffgroundsmashanim;
- }
- if (distance < 2.5 &&
- player[k].crouchkeydown &&
- player[k].animTarget != crouchstabanim &&
- !attackweapon &&
- player[i].dead &&
- player[i].skeleton.free &&
- player[i].skeleton.longdead > 1000) {
- player[k].animTarget = killanim;
- //TODO: refactor this out, what does it do?
- for (int j = 0; j < terrain.numdecals; j++) {
- if ((terrain.decaltype[j] == blooddecal || terrain.decaltype[j] == blooddecalslow) &&
- terrain.decalalivetime[j] < 2)
- terrain.DeleteDecal(j);
- }
- for (int l = 0; l < objects.numobjects; l++) {
- if (objects.model[l].type == decalstype)
- for (int j = 0; j < objects.model[l].numdecals; j++) {
- if ((objects.model[l].decaltype[j] == blooddecal ||
- objects.model[l].decaltype[j] == blooddecalslow) &&
- objects.model[l].decalalivetime[j] < 2)
- objects.model[l].DeleteDecal(j);
- }
- }
- }
- if (!player[i].dead || musictype != 2)
- if (distance < 3.5 &&
- (player[k].isRun() || player[k].isIdle() && player[k].attackkeydown) &&
- player[k].staggerdelay <= 0 &&
- (player[i].dead ||
- player[i].skeleton.longdead < 300 &&
- player[k].lastattack != spinkickanim &&
- player[i].skeleton.free) &&
- (!player[i].dead || musictype != stream_fighttheme)) {
- player[k].animTarget = dropkickanim;
- for (int j = 0; j < terrain.numdecals; j++) {
- if ((terrain.decaltype[j] == blooddecal || terrain.decaltype[j] == blooddecalslow) &&
- terrain.decalalivetime[j] < 2) {
- terrain.DeleteDecal(j);
- }
- }
- for (int l = 0; l < objects.numobjects; l++) {
- if (objects.model[l].type == decalstype)
- for (int j = 0; j < objects.model[l].numdecals; j++) {
- if ((objects.model[l].decaltype[j] == blooddecal ||
- objects.model[l].decaltype[j] == blooddecalslow) &&
- objects.model[l].decalalivetime[j] < 2) {
- objects.model[l].DeleteDecal(j);
- }
- }
- }
- }
- }
- if (animation[player[k].animTarget].attack == normalattack &&
- player[k].victim == &player[i] &&
- (!player[i].skeleton.free ||
- player[k].animTarget == killanim ||
- player[k].animTarget == crouchstabanim ||
- player[k].animTarget == swordgroundstabanim ||
- player[k].animTarget == staffgroundsmashanim ||
- player[k].animTarget == dropkickanim)) {
- oldattackkey = 1;
- player[k].frameTarget = 0;
- player[k].target = 0;
-
- XYZ targetpoint = player[i].coords;
- if (player[k].animTarget == crouchstabanim ||
- player[k].animTarget == swordgroundstabanim ||
- player[k].animTarget == staffgroundsmashanim) {
- targetpoint += (player[i].jointPos(abdomen) +
- player[i].jointPos(neck)) / 2 *
- player[i].scale;
- }
- player[k].targetyaw = roughDirectionTo(player[k].coords, targetpoint);
- player[k].targettilt2 = pitchTo(player[k].coords, targetpoint);
-
- if (player[k].animTarget == crouchstabanim || player[k].animTarget == swordgroundstabanim) {
- player[k].targetyaw += (float)(abs(Random() % 100) - 50) / 4;
- }
-
- if (player[k].animTarget == staffgroundsmashanim)
- player[k].targettilt2 += 10;
-
- player[k].lastattack3 = player[k].lastattack2;
- player[k].lastattack2 = player[k].lastattack;
- player[k].lastattack = player[k].animTarget;
-
- if (player[k].animTarget == swordgroundstabanim) {
- player[k].targetyaw += 30;
- }
- }
- }
- }
- if (!player[k].hasvictim) {
- //find victim
- for (int i = 0; i < numplayers; i++) {
- if (i == k || !(i == 0 || k == 0))continue;
- if (!player[i].skeleton.free) {
- if (player[k].hasvictim) {
- if (distsq(&player[k].coords, &player[i].coords) <
- distsq(&player[k].coords, &player[k].victim->coords))
- player[k].victim = &player[i];
- } else {
- player[k].victim = &player[i];
- player[k].hasvictim = 1;
- }
- }
- }
- }
- if (player[k].aitype == playercontrolled)
- //rabbit kick
- if (player[k].attackkeydown &&
- player[k].isRun() &&
- player[k].wasRun() &&
- ((player[k].hasvictim &&
- distsq(&player[k].coords, &player[k].victim->coords) < 12 * sq(player[k].scale * 5) &&
- distsq(&player[k].coords, &player[k].victim->coords) > 7 * sq(player[k].scale * 5) &&
- !player[k].victim->skeleton.free &&
- player[k].victim->animTarget != getupfrombackanim &&
- player[k].victim->animTarget != getupfromfrontanim &&
- animation[player[k].victim->animTarget].height != lowheight &&
- player[k].aitype != playercontrolled && //wat???
- normaldotproduct(player[k].facing, player[k].victim->coords - player[k].coords) > 0 &&
- player[k].rabbitkickenabled) ||
- player[k].jumpkeydown)) {
- oldattackkey = 1;
- player[k].setAnimation(rabbitkickanim);
- }
- //update counts
- if (animation[player[k].animTarget].attack && k == 0) {
- numattacks++;
- switch (attackweapon) {
- case 0:
- numunarmedattack++;
- break;
- case knife:
- numknifeattack++;
- break;
- case sword:
- numswordattack++;
- break;
- case staff:
- numstaffattack++;
- break;
- }
- }
- }
- }
- }
- }
-}
-
-void doPlayerCollisions()
-{
- static XYZ rotatetarget;
- static float collisionradius;
- if (numplayers > 1)
- for (int k = 0; k < numplayers; k++)
- for (int i = k + 1; i < numplayers; i++) {
- //neither player is part of a reversal
- if ((animation[player[i].animTarget].attack != reversed &&
- animation[player[i].animTarget].attack != reversal &&
- animation[player[k].animTarget].attack != reversed &&
- animation[player[k].animTarget].attack != reversal) || (i != 0 && k != 0))
- if ((animation[player[i].animCurrent].attack != reversed &&
- animation[player[i].animCurrent].attack != reversal &&
- animation[player[k].animCurrent].attack != reversed &&
- animation[player[k].animCurrent].attack != reversal) || (i != 0 && k != 0))
- //neither is sleeping
- if (player[i].howactive <= typesleeping && player[k].howactive <= typesleeping)
- if (player[i].howactive != typesittingwall && player[k].howactive != typesittingwall)
- //in same patch, neither is climbing
- if (player[i].whichpatchx == player[k].whichpatchx &&
- player[i].whichpatchz == player[k].whichpatchz &&
- player[k].skeleton.oldfree == player[k].skeleton.free &&
- player[i].skeleton.oldfree == player[i].skeleton.free &&
- player[i].animTarget != climbanim &&
- player[i].animTarget != hanganim &&
- player[k].animTarget != climbanim &&
- player[k].animTarget != hanganim)
- //players are close (bounding box test)
- if (player[i].coords.y > player[k].coords.y - 3)
- if (player[i].coords.y < player[k].coords.y + 3)
- if (player[i].coords.x > player[k].coords.x - 3)
- if (player[i].coords.x < player[k].coords.x + 3)
- if (player[i].coords.z > player[k].coords.z - 3)
- if (player[i].coords.z < player[k].coords.z + 3) {
- //spread fire from player to player
- if (distsq(&player[i].coords, &player[k].coords)
- < 3 * sq((player[i].scale + player[k].scale) * 2.5)) {
- if (player[i].onfire || player[k].onfire) {
- if (!player[i].onfire)player[i].CatchFire();
- if (!player[k].onfire)player[k].CatchFire();
- }
- }
-
- XYZ tempcoords1 = player[i].coords;
- XYZ tempcoords2 = player[k].coords;
- if (!player[i].skeleton.oldfree)
- tempcoords1.y += player[i].jointPos(abdomen).y * player[i].scale;
- if (!player[k].skeleton.oldfree)
- tempcoords2.y += player[k].jointPos(abdomen).y * player[k].scale;
- collisionradius = 1.2 * sq((player[i].scale + player[k].scale) * 2.5);
- if (player[0].hasvictim)
- if (player[0].animTarget == rabbitkickanim && (k == 0 || i == 0) && !player[0].victim->skeleton.free)
- collisionradius = 3;
- if ((!player[i].skeleton.oldfree || !player[k].skeleton.oldfree) &&
- (distsq(&tempcoords1, &tempcoords2) < collisionradius ||
- distsq(&player[i].coords, &player[k].coords) < collisionradius)) {
- //jump down on a dead body
- if (k == 0 || i == 0) {
- int l = i ? i : k;
- if (player[0].animTarget == jumpdownanim &&
- !player[0].skeleton.oldfree &&
- !player[0].skeleton.free &&
- player[l].skeleton.oldfree &&
- player[l].skeleton.free &&
- player[l].dead &&
- player[0].lastcollide <= 0 &&
- fabs(player[l].coords.y - player[0].coords.y) < .2 &&
- distsq(&player[0].coords, &player[l].coords) < .7 * sq((player[l].scale + player[0].scale) * 2.5)) {
- player[0].coords.y = player[l].coords.y;
- player[l].velocity = player[0].velocity;
- player[l].skeleton.free = 0;
- player[l].yaw = 0;
- player[l].RagDoll(0);
- player[l].DoDamage(20);
- camerashake += .3;
- player[l].skeleton.longdead = 0;
- player[0].lastcollide = 1;
- }
- }
-
- if ( (player[i].skeleton.oldfree == 1 && findLengthfast(&player[i].velocity) > 1) ||
- (player[k].skeleton.oldfree == 1 && findLengthfast(&player[k].velocity) > 1) ||
- (player[i].skeleton.oldfree == 0 && player[k].skeleton.oldfree == 0)) {
- rotatetarget = player[k].velocity - player[i].velocity;
- if ((player[i].animTarget != getupfrombackanim && player[i].animTarget != getupfromfrontanim ||
- player[i].skeleton.free) &&
- (player[k].animTarget != getupfrombackanim && player[k].animTarget != getupfromfrontanim ||
- player[k].skeleton.free))
- if ((((k != 0 && findLengthfast(&rotatetarget) > 150 ||
- k == 0 && findLengthfast(&rotatetarget) > 50 && player[0].rabbitkickragdoll) &&
- normaldotproduct(rotatetarget, player[k].coords - player[i].coords) > 0) &&
- (k == 0 ||
- k != 0 && player[i].skeleton.oldfree == 1 && animation[player[k].animCurrent].attack == neutral ||
- /*i!=0&&*/player[k].skeleton.oldfree == 1 && animation[player[i].animCurrent].attack == neutral)) ||
- (player[i].animTarget == jumpupanim || player[i].animTarget == jumpdownanim || player[i].isFlip()) &&
- (player[k].animTarget == jumpupanim || player[k].animTarget == jumpdownanim || player[k].isFlip()) &&
- k == 0 && !player[i].skeleton.oldfree && !player[k].skeleton.oldfree) {
- //If hit by body
- if ( (i != 0 || player[i].skeleton.free) &&
- (k != 0 || player[k].skeleton.free) ||
- (animation[player[i].animTarget].height == highheight &&
- animation[player[k].animTarget].height == highheight)) {
- if (tutoriallevel != 1) {
- emit_sound_at(heavyimpactsound, player[i].coords);
- }
-
- player[i].RagDoll(0);
- if (player[i].damage > player[i].damagetolerance - findLengthfast(&rotatetarget) / 4 && !player[i].dead) {
- award_bonus(0, aimbonus);
- }
- player[i].DoDamage(findLengthfast(&rotatetarget) / 4);
- player[k].RagDoll(0);
- if (player[k].damage > player[k].damagetolerance - findLengthfast(&rotatetarget) / 4 && !player[k].dead) {
- award_bonus(0, aimbonus); // Huh, again?
- }
- player[k].DoDamage(findLengthfast(&rotatetarget) / 4);
-
- for (int j = 0; j < player[i].skeleton.num_joints; j++) {
- player[i].skeleton.joints[j].velocity = player[i].skeleton.joints[j].velocity / 5 + player[k].velocity;
- }
- for (int j = 0; j < player[k].skeleton.num_joints; j++) {
- player[k].skeleton.joints[j].velocity = player[k].skeleton.joints[j].velocity / 5 + player[i].velocity;
- }
-
- }
- }
- if ( (animation[player[i].animTarget].attack == neutral ||
- animation[player[i].animTarget].attack == normalattack) &&
- (animation[player[k].animTarget].attack == neutral ||
- animation[player[k].animTarget].attack == normalattack)) {
- //If bumped
- if (player[i].skeleton.oldfree == 0 && player[k].skeleton.oldfree == 0) {
- if (distsq(&player[k].coords, &player[i].coords) < .5 * sq((player[i].scale + player[k].scale) * 2.5)) {
- rotatetarget = player[k].coords - player[i].coords;
- Normalise(&rotatetarget);
- player[k].coords = (player[k].coords + player[i].coords) / 2;
- player[i].coords = player[k].coords - rotatetarget * fast_sqrt(.6) / 2
- * sq((player[i].scale + player[k].scale) * 2.5);
- player[k].coords += rotatetarget * fast_sqrt(.6) / 2 * sq((player[i].scale + player[k].scale) * 2.5);
- if (player[k].howactive == typeactive || hostile)
- if (player[k].isIdle()) {
- if (player[k].howactive < typesleeping)
- player[k].setAnimation(player[k].getStop());
- else if (player[k].howactive == typesleeping)
- player[k].setAnimation(getupfromfrontanim);
- if (!editorenabled)
- player[k].howactive = typeactive;
- }
- if (player[i].howactive == typeactive || hostile)
- if (player[i].isIdle()) {
- if (player[i].howactive < typesleeping)
- player[i].setAnimation(player[k].getStop());
- else
- player[i].setAnimation(getupfromfrontanim);
- if (!editorenabled)
- player[i].howactive = typeactive;
- }
- }
- //jump down on player
- if (hostile) {
- if (k == 0 && i != 0 && player[k].animTarget == jumpdownanim &&
- !player[i].isCrouch() &&
- player[i].animTarget != rollanim &&
- !player[k].skeleton.oldfree && !
- player[k].skeleton.free &&
- player[k].lastcollide <= 0 &&
- player[k].velocity.y < -10) {
- player[i].velocity = player[k].velocity;
- player[k].velocity = player[k].velocity * -.5;
- player[k].velocity.y = player[i].velocity.y;
- player[i].DoDamage(20);
- player[i].RagDoll(0);
- player[k].lastcollide = 1;
- award_bonus(k, AboveBonus);
- }
- if (i == 0 && k != 0 && player[i].animTarget == jumpdownanim &&
- !player[k].isCrouch() &&
- player[k].animTarget != rollanim &&
- !player[i].skeleton.oldfree &&
- !player[i].skeleton.free &&
- player[i].lastcollide <= 0 &&
- player[i].velocity.y < -10) {
- player[k].velocity = player[i].velocity;
- player[i].velocity = player[i].velocity * -.3;
- player[i].velocity.y = player[k].velocity.y;
- player[k].DoDamage(20);
- player[k].RagDoll(0);
- player[i].lastcollide = 1;
- award_bonus(i, AboveBonus);
- }
- }
- }
- }
- }
- player[i].CheckKick();
- player[k].CheckKick();
- }
- }
- }
-}
-
-void doAI(int i)
-{
- static bool connected;
- if (player[i].aitype != playercontrolled && indialogue == -1) {
- player[i].jumpclimb = 0;
- //disable movement in editor
- if (editorenabled)
- player[i].stunned = 1;
-
- player[i].pause = 0;
- if (distsqflat(&player[0].coords, &player[i].coords) < 30 &&
- player[0].coords.y > player[i].coords.y + 2 &&
- !player[0].onterrain)
- player[i].pause = 1;
-
- //pathfinding
- if (player[i].aitype == pathfindtype) {
- if (player[i].finalpathfindpoint == -1) {
- float closestdistance;
- float tempdist;
- int closest;
- XYZ colpoint;
- closest = -1;
- closestdistance = -1;
- for (int j = 0; j < numpathpoints; j++)
- if (closest == -1 || distsq(&player[i].finalfinaltarget, &pathpoint[j]) < closestdistance) {
- closestdistance = distsq(&player[i].finalfinaltarget, &pathpoint[j]);
- closest = j;
- player[i].finaltarget = pathpoint[j];
- }
- player[i].finalpathfindpoint = closest;
- for (int j = 0; j < numpathpoints; j++)
- for (int k = 0; k < numpathpointconnect[j]; k++) {
- DistancePointLine(&player[i].finalfinaltarget, &pathpoint[j], &pathpoint[pathpointconnect[j][k]], &tempdist, &colpoint );
- if (sq(tempdist) < closestdistance)
- if (findDistance(&colpoint, &pathpoint[j]) + findDistance(&colpoint, &pathpoint[pathpointconnect[j][k]]) <
- findDistance(&pathpoint[j], &pathpoint[pathpointconnect[j][k]]) + .1) {
- closestdistance = sq(tempdist);
- closest = j;
- player[i].finaltarget = colpoint;
- }
- }
- player[i].finalpathfindpoint = closest;
-
- }
- if (player[i].targetpathfindpoint == -1) {
- float closestdistance;
- float tempdist;
- int closest;
- XYZ colpoint;
- closest = -1;
- closestdistance = -1;
- if (player[i].lastpathfindpoint == -1) {
- for (int j = 0; j < numpathpoints; j++) {
- if (j != player[i].lastpathfindpoint)
- if (closest == -1 || (distsq(&player[i].coords, &pathpoint[j]) < closestdistance)) {
- closestdistance = distsq(&player[i].coords, &pathpoint[j]);
- closest = j;
- }
- }
- player[i].targetpathfindpoint = closest;
- for (int j = 0; j < numpathpoints; j++)
- if (j != player[i].lastpathfindpoint)
- for (int k = 0; k < numpathpointconnect[j]; k++) {
- DistancePointLine(&player[i].coords, &pathpoint[j], &pathpoint[pathpointconnect[j][k]], &tempdist, &colpoint );
- if (sq(tempdist) < closestdistance) {
- if (findDistance(&colpoint, &pathpoint[j]) + findDistance(&colpoint, &pathpoint[pathpointconnect[j][k]]) <
- findDistance(&pathpoint[j], &pathpoint[pathpointconnect[j][k]]) + .1) {
- closestdistance = sq(tempdist);
- closest = j;
- }
- }
- }
- player[i].targetpathfindpoint = closest;
- } else {
- for (int j = 0; j < numpathpoints; j++)
- if (j != player[i].lastpathfindpoint &&
- j != player[i].lastpathfindpoint2 &&
- j != player[i].lastpathfindpoint3 &&
- j != player[i].lastpathfindpoint4) {
- connected = 0;
- if (numpathpointconnect[j])
- for (int k = 0; k < numpathpointconnect[j]; k++)
- if (pathpointconnect[j][k] == player[i].lastpathfindpoint)
- connected = 1;
- if (!connected)
- if (numpathpointconnect[player[i].lastpathfindpoint])
- for (int k = 0; k < numpathpointconnect[player[i].lastpathfindpoint]; k++)
- if (pathpointconnect[player[i].lastpathfindpoint][k] == j)
- connected = 1;
- if (connected) {
- tempdist = findPathDist(j, player[i].finalpathfindpoint);
- if (closest == -1 || tempdist < closestdistance) {
- closestdistance = tempdist;
- closest = j;
- }
- }
- }
- player[i].targetpathfindpoint = closest;
- }
- }
- player[i].losupdatedelay -= multiplier;
-
- player[i].targetyaw = roughDirectionTo(player[i].coords, pathpoint[player[i].targetpathfindpoint]);
- player[i].lookyaw = player[i].targetyaw;
-
- //reached target point
- if (distsqflat(&player[i].coords, &pathpoint[player[i].targetpathfindpoint]) < .6) {
- player[i].lastpathfindpoint4 = player[i].lastpathfindpoint3;
- player[i].lastpathfindpoint3 = player[i].lastpathfindpoint2;
- player[i].lastpathfindpoint2 = player[i].lastpathfindpoint;
- player[i].lastpathfindpoint = player[i].targetpathfindpoint;
- if (player[i].lastpathfindpoint2 == -1)
- player[i].lastpathfindpoint2 = player[i].lastpathfindpoint;
- if (player[i].lastpathfindpoint3 == -1)
- player[i].lastpathfindpoint3 = player[i].lastpathfindpoint2;
- if (player[i].lastpathfindpoint4 == -1)
- player[i].lastpathfindpoint4 = player[i].lastpathfindpoint3;
- player[i].targetpathfindpoint = -1;
- }
- if ( distsqflat(&player[i].coords, &player[i].finalfinaltarget) <
- distsqflat(&player[i].coords, &player[i].finaltarget) ||
- distsqflat(&player[i].coords, &player[i].finaltarget) < .6 * sq(player[i].scale * 5) ||
- player[i].lastpathfindpoint == player[i].finalpathfindpoint) {
- player[i].aitype = passivetype;
- }
-
- player[i].forwardkeydown = 1;
- player[i].leftkeydown = 0;
- player[i].backkeydown = 0;
- player[i].rightkeydown = 0;
- player[i].crouchkeydown = 0;
- player[i].attackkeydown = 0;
- player[i].throwkeydown = 0;
-
- if (player[i].avoidcollided > .8 && !player[i].jumpkeydown && player[i].collided < .8)
- player[i].targetyaw += 90 * (player[i].whichdirection * 2 - 1);
-
- if (player[i].collided < 1 || player[i].animTarget != jumpupanim)
- player[i].jumpkeydown = 0;
- if ((player[i].collided > .8 && player[i].jumppower >= 5))
- player[i].jumpkeydown = 1;
-
- if ((tutoriallevel != 1 || cananger) &&
- hostile &&
- !player[0].dead &&
- distsq(&player[i].coords, &player[0].coords) < 400 &&
- player[i].occluded < 25) {
- if (distsq(&player[i].coords, &player[0].coords) < 12 &&
- animation[player[0].animTarget].height != lowheight &&
- !editorenabled &&
- (player[0].coords.y < player[i].coords.y + 5 || player[0].onterrain))
- player[i].aitype = attacktypecutoff;
- if (distsq(&player[i].coords, &player[0].coords) < 30 &&
- animation[player[0].animTarget].height == highheight &&
- !editorenabled)
- player[i].aitype = attacktypecutoff;
-
- if (player[i].losupdatedelay < 0 && !editorenabled && player[i].occluded < 2) {
- player[i].losupdatedelay = .2;
- for (int j = 0; j < numplayers; j++)
- if (j == 0 || player[j].skeleton.free || player[j].aitype != passivetype)
- if (abs(Random() % 2) || animation[player[j].animTarget].height != lowheight || j != 0)
- if (distsq(&player[i].coords, &player[j].coords) < 400)
- if (normaldotproduct(player[i].facing, player[j].coords - player[i].coords) > 0)
- if (player[j].coords.y < player[i].coords.y + 5 || player[j].onterrain)
- if (!player[j].isWallJump() && -1 == checkcollide(
- DoRotation(player[i].jointPos(head), 0, player[i].yaw, 0)
- *player[i].scale + player[i].coords,
- DoRotation(player[j].jointPos(head), 0, player[j].yaw, 0)
- *player[j].scale + player[j].coords) ||
- (player[j].animTarget == hanganim &&
- normaldotproduct(player[j].facing, player[i].coords - player[j].coords) < 0)) {
- player[i].aitype = searchtype;
- player[i].lastchecktime = 12;
- player[i].lastseen = player[j].coords;
- player[i].lastseentime = 12;
- }
- }
- }
- if (player[i].aitype == attacktypecutoff && musictype != 2)
- if (player[i].creature != wolftype) {
- player[i].stunned = .6;
- player[i].surprised = .6;
- }
- }
-
- if (player[i].aitype != passivetype && leveltime > .5)
- player[i].howactive = typeactive;
-
- if (player[i].aitype == passivetype) {
- player[i].aiupdatedelay -= multiplier;
- player[i].losupdatedelay -= multiplier;
- player[i].lastseentime += multiplier;
- player[i].pausetime -= multiplier;
- if (player[i].lastseentime > 1)
- player[i].lastseentime = 1;
-
- if (player[i].aiupdatedelay < 0) {
- if (player[i].numwaypoints > 1 && player[i].howactive == typeactive && player[i].pausetime <= 0) {
- player[i].targetyaw = roughDirectionTo(player[i].coords, player[i].waypoints[player[i].waypoint]);
- player[i].lookyaw = player[i].targetyaw;
- player[i].aiupdatedelay = .05;
-
- if (distsqflat(&player[i].coords, &player[i].waypoints[player[i].waypoint]) < 1) {
- if (player[i].waypointtype[player[i].waypoint] == wppause)
- player[i].pausetime = 4;
- player[i].waypoint++;
- if (player[i].waypoint > player[i].numwaypoints - 1)
- player[i].waypoint = 0;
-
- }
- }
-
- if (player[i].numwaypoints > 1 && player[i].howactive == typeactive && player[i].pausetime <= 0)
- player[i].forwardkeydown = 1;
- else
- player[i].forwardkeydown = 0;
- player[i].leftkeydown = 0;
- player[i].backkeydown = 0;
- player[i].rightkeydown = 0;
- player[i].crouchkeydown = 0;
- player[i].attackkeydown = 0;
- player[i].throwkeydown = 0;
-
- if (player[i].avoidcollided > .8 && !player[i].jumpkeydown && player[i].collided < .8) {
- if (!player[i].avoidsomething)
- player[i].targetyaw += 90 * (player[i].whichdirection * 2 - 1);
- else {
- XYZ leftpos, rightpos;
- float leftdist, rightdist;
- leftpos = player[i].coords + DoRotation(player[i].facing, 0, 90, 0);
- rightpos = player[i].coords - DoRotation(player[i].facing, 0, 90, 0);
- leftdist = distsq(&leftpos, &player[i].avoidwhere);
- rightdist = distsq(&rightpos, &player[i].avoidwhere);
- if (leftdist < rightdist)
- player[i].targetyaw += 90;
- else
- player[i].targetyaw -= 90;
- }
- }
- }
- if (player[i].collided < 1 || player[i].animTarget != jumpupanim)
- player[i].jumpkeydown = 0;
- if ((player[i].collided > .8 && player[i].jumppower >= 5))
- player[i].jumpkeydown = 1;
-
-
- //hearing sounds
- if (!editorenabled) {
- if (player[i].howactive <= typesleeping)
- if (numenvsounds > 0 && (tutoriallevel != 1 || cananger) && hostile)
- for (int j = 0; j < numenvsounds; j++) {
- float vol = player[i].howactive == typesleeping ? envsoundvol[j] - 14 : envsoundvol[j];
- if (vol > 0 && distsq(&player[i].coords, &envsound[j]) <
- 2 * (vol + vol * (player[i].creature == rabbittype) * 3))
- player[i].aitype = attacktypecutoff;
- }
-
- if (player[i].aitype != passivetype) {
- if (player[i].howactive == typesleeping)
- player[i].setAnimation(getupfromfrontanim);
- player[i].howactive = typeactive;
- }
- }
-
- if (player[i].howactive < typesleeping &&
- ((tutoriallevel != 1 || cananger) && hostile) &&
- !player[0].dead &&
- distsq(&player[i].coords, &player[0].coords) < 400 &&
- player[i].occluded < 25) {
- if (distsq(&player[i].coords, &player[0].coords) < 12 &&
- animation[player[0].animTarget].height != lowheight && !editorenabled)
- player[i].aitype = attacktypecutoff;
- if (distsq(&player[i].coords, &player[0].coords) < 30 &&
- animation[player[0].animTarget].height == highheight && !editorenabled)
- player[i].aitype = attacktypecutoff;
-
- //wolf smell
- if (player[i].creature == wolftype) {
- XYZ windsmell;
- for (int j = 0; j < numplayers; j++) {
- if (j == 0 || (player[j].dead && player[j].bloodloss > 0)) {
- float smelldistance = 50;
- if (j == 0 && player[j].num_weapons > 0) {
- if (weapons[player[j].weaponids[0]].bloody)
- smelldistance = 100;
- if (player[j].num_weapons == 2)
- if (weapons[player[j].weaponids[1]].bloody)
- smelldistance = 100;
- }
- if (j != 0)
- smelldistance = 100;
- windsmell = windvector;
- Normalise(&windsmell);
- windsmell = windsmell * 2 + player[j].coords;
- if (distsq(&player[i].coords, &windsmell) < smelldistance && !editorenabled)
- player[i].aitype = attacktypecutoff;
- }
- }
- }
-
- if (player[i].howactive < typesleeping && player[i].losupdatedelay < 0 && !editorenabled && player[i].occluded < 2) {
- player[i].losupdatedelay = .2;
- for (int j = 0; j < numplayers; j++) {
- if (j == 0 || player[j].skeleton.free || player[j].aitype != passivetype) {
- if (abs(Random() % 2) || animation[player[j].animTarget].height != lowheight || j != 0)
- if (distsq(&player[i].coords, &player[j].coords) < 400)
- if (normaldotproduct(player[i].facing, player[j].coords - player[i].coords) > 0)
- if ((-1 == checkcollide(
- DoRotation(player[i].jointPos(head), 0, player[i].yaw, 0)*
- player[i].scale + player[i].coords,
- DoRotation(player[j].jointPos(head), 0, player[j].yaw, 0)*
- player[j].scale + player[j].coords) &&
- !player[j].isWallJump()) ||
- (player[j].animTarget == hanganim &&
- normaldotproduct(player[j].facing, player[i].coords - player[j].coords) < 0)) {
- player[i].lastseentime -= .2;
- if (j == 0 && animation[player[j].animTarget].height == lowheight)
- player[i].lastseentime -= .4;
- else
- player[i].lastseentime -= .6;
- }
- if (player[i].lastseentime <= 0) {
- player[i].aitype = searchtype;
- player[i].lastchecktime = 12;
- player[i].lastseen = player[j].coords;
- player[i].lastseentime = 12;
- }
- }
- }
- }
- }
- //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;