X-Git-Url: https://git.jsancho.org/?a=blobdiff_plain;f=Source%2FObjects%2FPerson.cpp;h=5a735c3a0cf5d50ff66f9ab4bb843171449b3a73;hb=d67f3dc0e14c195e650e732e8477c1ac4085e9de;hp=1187fb7ba76a6d3db2e29c4ece4ba1db35b17ebc;hpb=35048f2f8374d1457a5cef19ea3af599037b6935;p=lugaru.git diff --git a/Source/Objects/Person.cpp b/Source/Objects/Person.cpp index 1187fb7..5a735c3 100644 --- a/Source/Objects/Person.cpp +++ b/Source/Objects/Person.cpp @@ -169,6 +169,7 @@ Person::Person() victim(nullptr) , hasvictim(false) + , isplayerfriend(false) , updatedelay(0) @@ -441,12 +442,12 @@ void Person::changeCreatureType(person_type type) { creature = type; whichskin = 0; - skeletonLoad(type == rabbittype); + skeletonLoad(); scale = PersonType::types[creature].defaultScale; damagetolerance = PersonType::types[creature].defaultDamageTolerance; } -void Person::skeletonLoad(bool clothes) +void Person::skeletonLoad() { skeleton.id = id; skeleton.Load( @@ -462,7 +463,7 @@ void Person::skeletonLoad(bool clothes) PersonType::types[creature].modelFileNames[6], PersonType::types[creature].lowModelFileName, PersonType::types[creature].modelClothesFileName, - clothes); + PersonType::types[creature].clothes); skeleton.drawmodel.textureptr.load(PersonType::types[creature].skins[whichskin], 1, &skeleton.skinText[0], &skeleton.skinsize); } @@ -596,14 +597,14 @@ int Person::getIdle() if ((!victim->dead && victim->aitype != passivetype && victim->aitype != searchtype && aitype != passivetype && aitype != searchtype && victim->id < Person::players.size())) { - if ((aitype == playercontrolled && stunned <= 0 && weaponactive == -1) || pause) { + if ((isPlayerControlled() && (stunned <= 0) && !hasWeapon()) || pause) { return PersonType::types[creature].animFightIdle; } - if (aitype == playercontrolled && stunned <= 0 && weaponactive != -1) { + if (isPlayerControlled() && (stunned <= 0) && hasWeapon()) { if (weapons[weaponids[weaponactive]].getType() == knife) { return knifefightidleanim; } - if (weapons[weaponids[weaponactive]].getType() == sword && victim->weaponactive != -1) { + if (weapons[weaponids[weaponactive]].getType() == sword && victim->hasWeapon()) { return swordfightidlebothanim; } if (weapons[weaponids[weaponactive]].getType() == sword) { @@ -613,13 +614,13 @@ int Person::getIdle() return swordfightidleanim; } } - if (aitype != playercontrolled && stunned <= 0 && creature != wolftype && !pause) { + if (!isPlayerControlled() && (stunned <= 0) && creature != wolftype) { return fightsidestep; } } } - if ((damage > permanentdamage || damage > damagetolerance * .8 || deathbleeding > 0) && creature != wolftype) { - return hurtidleanim; + if ((damage > permanentdamage || damage > damagetolerance * .8 || deathbleeding > 0) && PersonType::types[creature].hasAnimHurtIdle()) { + return PersonType::types[creature].animHurtIdle; } if (howactive == typesitting) { return sitanim; @@ -658,7 +659,7 @@ int Person::getCrouch() */ int Person::getRun() { - if (superruntoggle && (weaponactive == -1)) { + if (superruntoggle && (!hasWeapon())) { return PersonType::types[creature].animRunning; } else { return PersonType::types[creature].animRun; @@ -786,7 +787,7 @@ void Person::DoBloodBig(float howmuch, int which) } if (!Tutorial::active || id == 0) { - if (aitype != playercontrolled && howmuch > 0) { + if (!isPlayerControlled() && howmuch > 0) { // play pain sounds int whichsound = -1; @@ -966,7 +967,7 @@ void Person::DoBloodBig(float howmuch, int which) deathbleeding += bleeding; bloodloss += bleeding * 3; - if (!Tutorial::active && aitype != playercontrolled && bloodloss > damagetolerance * 2 / 3 && bloodloss < damagetolerance && creature == rabbittype) { + if (!Tutorial::active && !isPlayerControlled() && bloodloss > damagetolerance * 2 / 3 && bloodloss < damagetolerance && creature == rabbittype) { if (abs(Random() % 2) == 0) { aitype = gethelptype; lastseentime = 12; @@ -1175,7 +1176,7 @@ bool Person::DoBloodBigWhere(float howmuch, int which, XYZ where) deathbleeding += bleeding; bloodloss += bleeding * 3; - if (!Tutorial::active && aitype != playercontrolled && bloodloss > damagetolerance * 2 / 3 && bloodloss < damagetolerance && creature == rabbittype) { + if (!Tutorial::active && !isPlayerControlled() && bloodloss > damagetolerance * 2 / 3 && bloodloss < damagetolerance && creature == rabbittype) { if (abs(Random() % 2) == 0) { aitype = gethelptype; lastseentime = 12; @@ -1195,7 +1196,7 @@ bool Person::DoBloodBigWhere(float howmuch, int which, XYZ where) */ void Person::Reverse() { - if (!((victim->aitype == playercontrolled || hostiletime > 1 || staggerdelay <= 0) && victim->animTarget != jumpupanim && victim->animTarget != jumpdownanim && (!Tutorial::active || cananger) && hostile)) { + if (!((victim->isPlayerControlled() || hostiletime > 1 || staggerdelay <= 0) && victim->animTarget != jumpupanim && victim->animTarget != jumpdownanim && (!Tutorial::active || cananger) && hostile)) { return; } @@ -1228,7 +1229,7 @@ void Person::Reverse() victim->animTarget = upunchreversalanim; } if (animTarget == staffhitanim && distsq(&victim->coords, &coords) < 2 && ((victim->id == 0 && victim->crouchkeydown) || Random() % 4 == 0)) { - if (victim->weaponactive != -1) { + if (victim->hasWeapon()) { victim->throwtogglekeydown = 1; XYZ tempVelocity = victim->velocity * .2; if (tempVelocity.x == 0) { @@ -1255,7 +1256,7 @@ void Person::Reverse() victim->animTarget = staffhitreversalanim; } if (animTarget == staffspinhitanim && distsq(&victim->coords, &coords) < 2 && ((victim->id == 0 && victim->crouchkeydown) || Random() % 2 == 0)) { - if (victim->weaponactive != -1) { + if (victim->hasWeapon()) { victim->throwtogglekeydown = 1; XYZ tempVelocity = victim->velocity * .2; if (tempVelocity.x == 0) { @@ -1281,7 +1282,7 @@ void Person::Reverse() victim->animTarget = staffspinhitreversalanim; } if (animTarget == swordslashanim && distsq(&victim->coords, &coords) < 2 && ((victim->id == 0 && victim->crouchkeydown) || Random() % 4 == 0)) { - if (victim->weaponactive != -1) { + if (victim->hasWeapon()) { victim->throwtogglekeydown = 1; XYZ tempVelocity = victim->velocity * .2; if (tempVelocity.x == 0) { @@ -1307,7 +1308,7 @@ void Person::Reverse() victim->animTarget = swordslashreversalanim; } if (animTarget == knifeslashstartanim && distsq(&victim->coords, &coords) < 2 && (victim->id == 0 || Random() % 4 == 0)) { - if (victim->weaponactive != -1) { + if (victim->hasWeapon()) { victim->throwtogglekeydown = 1; XYZ tempVelocity = victim->velocity * .2; if (tempVelocity.x == 0) { @@ -1360,7 +1361,7 @@ void Person::Reverse() victim->victim = this->shared_from_this(); victim->targetyaw = targetyaw + 180; } - if ((animTarget == swordslashanim || animTarget == staffhitanim || animTarget == staffspinhitanim) && victim->weaponactive != -1) { + if ((animTarget == swordslashanim || animTarget == staffhitanim || animTarget == staffspinhitanim) && victim->hasWeapon()) { animTarget = swordslashparriedanim; parriedrecently = .4; victim->parriedrecently = 0; @@ -1371,7 +1372,7 @@ void Person::Reverse() victim->targetyaw = targetyaw + 180; if (abs(Random() % 20) == 0 || weapons[victim->weaponids[victim->weaponactive]].getType() == knife) { - if (victim->weaponactive != -1) { + if (victim->hasWeapon()) { if (weapons[victim->weaponids[0]].getType() == staff || weapons[weaponids[0]].getType() == staff) { if (weapons[victim->weaponids[0]].getType() == staff) { weapons[victim->weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250; @@ -1408,7 +1409,7 @@ void Person::Reverse() } if (abs(Random() % 20) == 0) { - if (weaponactive != -1) { + if (hasWeapon()) { if (weapons[victim->weaponids[0]].getType() == staff || weapons[weaponids[0]].getType() == staff) { if (weapons[victim->weaponids[0]].getType() == staff) { weapons[victim->weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250; @@ -1493,7 +1494,7 @@ void Person::Reverse() velocity = 0; victim->velocity = 0; - if (aitype != playercontrolled) { + if (!isPlayerControlled()) { feint = 0; if (escapednum < 2) { int chances = ((difficulty == 2) ? 3 : ((difficulty == 1) ? 5 : 10)); @@ -1553,7 +1554,7 @@ void Person::DoDamage(float howmuch) if (aitype == passivetype && damage < damagetolerance && ((!Tutorial::active || cananger) && hostile)) { aitype = attacktypecutoff; } - if (!Tutorial::active && aitype != playercontrolled && damage < damagetolerance && damage > damagetolerance * 2 / 3 && creature == rabbittype) { + if (!Tutorial::active && !isPlayerControlled() && damage < damagetolerance && damage > damagetolerance * 2 / 3 && creature == rabbittype) { if (abs(Random() % 2) == 0) { aitype = gethelptype; lastseentime = 12; @@ -1596,7 +1597,7 @@ void Person::DoDamage(float howmuch) // play sounds if (!Tutorial::active || id == 0) { - if (speechdelay <= 0 && !dead && aitype != playercontrolled) { + if (speechdelay <= 0 && !dead && !isPlayerControlled()) { int whichsound = -1; if (creature == wolftype) { @@ -1889,7 +1890,7 @@ void Person::RagDoll(bool checkcollision) // drop weapon if (Random() % 2 == 0) { - if (weaponactive != -1 && animTarget != rabbitkickanim && num_weapons > 0) { + if (hasWeapon() && animTarget != rabbitkickanim && num_weapons > 0) { weapons[weaponids[0]].drop(jointVel(righthand) * scale * -.3, jointVel(righthand) * scale); weapons[weaponids[0]].velocity.x += .01; num_weapons--; @@ -2047,11 +2048,11 @@ void Person::DoAnimations() } if (!crouchkeydown || (isLanding() || isLandhard()) || (wasLanding() || wasLandhard())) { crouchtogglekeydown = 0; - if (aitype == playercontrolled) { + if (isPlayerControlled()) { feint = 0; } } else { - if (!crouchtogglekeydown && Animation::animations[animTarget].attack == reversed && aitype == playercontrolled && (escapednum < 2 || reversaltrain)) { + if (!crouchtogglekeydown && Animation::animations[animTarget].attack == reversed && isPlayerControlled() && (escapednum < 2 || reversaltrain)) { feint = 1; } if (!isFlip()) { @@ -2090,8 +2091,7 @@ void Person::DoAnimations() if (victim->aitype == gethelptype) { victim->DoDamage(victim->damagetolerance - victim->damage); } - //victim->DoDamage(30); - if (creature == wolftype) { + if (PersonType::types[creature].hasClaws) { DoBloodBig(0, 255); emit_sound_at(clawslicesound, victim->coords); victim->spurt = 1; @@ -2102,20 +2102,15 @@ void Person::DoAnimations() } } - if (!drawtogglekeydown && drawkeydown && (weaponactive == -1 || num_weapons == 1) && (targetFrame().label || (animTarget != animCurrent && animCurrent == rollanim)) && num_weapons > 0 && creature != wolftype) { + if (!drawtogglekeydown && drawkeydown && (!hasWeapon() || num_weapons == 1) && (targetFrame().label || (animTarget != animCurrent && animCurrent == rollanim)) && num_weapons > 0 && creature != wolftype) { if (weapons[weaponids[0]].getType() == knife) { - if (weaponactive == -1) { + if (!hasWeapon()) { weaponactive = 0; + emit_sound_at(knifedrawsound, coords, 128); } else if (weaponactive == 0) { weaponactive = -1; - } - - if (weaponactive == -1) { emit_sound_at(knifesheathesound, coords); } - if (weaponactive != -1) { - emit_sound_at(knifedrawsound, coords, 128); - } } drawtogglekeydown = 1; } @@ -2156,7 +2151,7 @@ void Person::DoAnimations() whichsound = footstepsound4; } } - if (targetFrame().label == 4 && (weaponactive == -1 || (animTarget != knifeslashstartanim && animTarget != knifethrowanim && animTarget != crouchstabanim && animTarget != swordgroundstabanim && animTarget != knifefollowanim))) { + if (targetFrame().label == 4 && (!hasWeapon() || (animTarget != knifeslashstartanim && animTarget != knifethrowanim && animTarget != crouchstabanim && animTarget != swordgroundstabanim && animTarget != knifefollowanim))) { if (Animation::animations[animTarget].attack != neutral) { unsigned r = abs(Random() % 3); if (r == 0) { @@ -2206,7 +2201,7 @@ void Person::DoAnimations() if (animTarget != crouchstabanim && animTarget != swordgroundstabanim && animTarget != staffgroundsmashanim) { if ((targetFrame().label && (targetFrame().label < 5 || targetFrame().label == 8))) { int whichsound = -1; - if (targetFrame().label == 4 && aitype != playercontrolled) { + if (targetFrame().label == 4 && !isPlayerControlled()) { if (Animation::animations[animTarget].attack != neutral) { unsigned r = abs(Random() % 4); whichsound = PersonType::types[creature].soundsAttack[r]; @@ -2236,7 +2231,7 @@ void Person::DoAnimations() if (animCurrent == removeknifeanim && currentFrame().label == 5) { for (unsigned i = 0; i < weapons.size(); i++) { if (weapons[i].owner == -1) { - if (distsqflat(&coords, &weapons[i].position) < 4 && weaponactive == -1) { + if (distsqflat(&coords, &weapons[i].position) < 4 && !hasWeapon()) { if (distsq(&coords, &weapons[i].position) >= 1) { if (weapons[i].getType() != staff) { emit_sound_at(knifedrawsound, coords, 128.); @@ -2262,7 +2257,7 @@ void Person::DoAnimations() } } if ((weapons[i].owner == -1) || (hasvictim && (weapons[i].owner == int(victim->id)) && victim->skeleton.free)) { - if (willwork && distsqflat(&coords, &weapons[i].position) < 3 && weaponactive == -1) { + if (willwork && distsqflat(&coords, &weapons[i].position) < 3 && !hasWeapon()) { if (distsq(&coords, &weapons[i].position) < 1 || hasvictim) { bool fleshstuck = false; if (weapons[i].owner != -1) { @@ -2336,8 +2331,9 @@ void Person::DoAnimations() } if (animCurrent == drawleftanim && currentFrame().label == 5) { - if (weaponactive == -1) { + if (!hasWeapon()) { weaponactive = 0; + emit_sound_at(knifedrawsound, coords, 128.); } else if (weaponactive == 0) { weaponactive = -1; if (num_weapons == 2) { @@ -2346,13 +2342,8 @@ void Person::DoAnimations() weaponids[0] = weaponids[1]; weaponids[1] = buffer; } - } - if (weaponactive == -1) { emit_sound_at(knifesheathesound, coords, 128.); } - if (weaponactive != -1) { - emit_sound_at(knifedrawsound, coords, 128.); - } } if ((animCurrent == walljumprightkickanim && animTarget == walljumprightkickanim) || (animCurrent == walljumpleftkickanim && animTarget == walljumpleftkickanim)) { @@ -2446,17 +2437,17 @@ void Person::DoAnimations() if (id == 0) { camerashake += .4; } - if (Random() % 2 || creature == wolftype) { + if (Random() % 2 || PersonType::types[creature].hasClaws) { victim->spurt = 1; DoBlood(.2, 250); - if (creature == wolftype) { + if (PersonType::types[creature].hasClaws) { DoBloodBig(0, 250); } } if (!Tutorial::active) { emit_sound_at(heavyimpactsound, victim->coords, 128.); } - if (creature == wolftype) { + if (PersonType::types[creature].hasClaws) { emit_sound_at(clawslicesound, victim->coords, 128.); victim->spurt = 1; victim->DoBloodBig(2 / victim->armorhead, 175); @@ -2484,14 +2475,14 @@ void Person::DoAnimations() if (id == 0) { camerashake += .4; } - if (Random() % 2 || creature == wolftype) { + if (Random() % 2 || PersonType::types[creature].hasClaws) { victim->spurt = 1; - if (creature == wolftype) { + if (PersonType::types[creature].hasClaws) { DoBloodBig(0, 235); } } emit_sound_at(whooshhitsound, victim->coords); - if (creature == wolftype) { + if (PersonType::types[creature].hasClaws) { emit_sound_at(clawslicesound, victim->coords, 128.); victim->spurt = 1; victim->DoBloodBig(2, 175); @@ -2524,7 +2515,7 @@ void Person::DoAnimations() if (!Tutorial::active) { emit_sound_at(heavyimpactsound, victim->coords, 160.); } - if (creature == wolftype) { + if (PersonType::types[creature].hasClaws) { emit_sound_at(clawslicesound, victim->coords, 128.); victim->spurt = 1; victim->DoBloodBig(2 / victim->armorhead, 175); @@ -2561,7 +2552,7 @@ void Person::DoAnimations() if (!Tutorial::active) { emit_sound_at(heavyimpactsound, victim->coords, 160.); } - if (creature == wolftype) { + if (PersonType::types[creature].hasClaws) { emit_sound_at(clawslicesound, victim->coords, 128.); victim->spurt = 1; victim->DoBloodBig(2 / victim->armorhead, 175); @@ -3018,7 +3009,7 @@ void Person::DoAnimations() camerashake += .4; } - if (weaponactive != -1) { + if (hasWeapon()) { if (weapons[victim->weaponids[0]].getType() == staff || weapons[weaponids[0]].getType() == staff) { if (weapons[victim->weaponids[0]].getType() == staff) { weapons[victim->weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250; @@ -3038,7 +3029,7 @@ void Person::DoAnimations() } if (animCurrent == knifethrowanim && currentFrame().label == 5) { - if (weaponactive != -1) { + if (hasWeapon()) { escapednum = 0; XYZ aim; aim = victim->coords + DoRotation(victim->jointPos(abdomen), 0, victim->yaw, 0) * victim->scale + victim->velocity * findDistance(&victim->coords, &coords) / 50 - (coords + DoRotation(jointPos(righthand), 0, yaw, 0) * scale); @@ -3065,7 +3056,7 @@ void Person::DoAnimations() emit_sound_at(knifeslicesound, victim->coords); } //victim->jointVel(abdomen)+=relative*damagemult*200; - if (Animation::animations[victim->animTarget].attack && (victim->aitype != playercontrolled || victim->animTarget == knifeslashstartanim) && (victim->creature == rabbittype || victim->deathbleeding <= 0)) { + if (Animation::animations[victim->animTarget].attack && (!victim->isPlayerControlled() || victim->animTarget == knifeslashstartanim) && (victim->creature == rabbittype || victim->deathbleeding <= 0)) { if (victim->id != 0 || difficulty == 2) { victim->frameTarget = 0; victim->animTarget = staggerbackhardanim; @@ -3075,7 +3066,7 @@ void Person::DoAnimations() } victim->lowreversaldelay = 0; victim->highreversaldelay = 0; - if (aitype != playercontrolled) { + if (!isPlayerControlled()) { weaponmissdelay = .6; } @@ -3111,7 +3102,7 @@ void Person::DoAnimations() } if (animCurrent == swordslashanim && currentFrame().label == 5 && victim->animTarget != rollanim) { if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 6.5 && victim->animTarget != dodgebackanim) { - if (victim->weaponactive == -1 || normaldotproduct(victim->facing, victim->coords - coords) > 0 || (Random() % 2 == 0)) { + if (!victim->hasWeapon() || normaldotproduct(victim->facing, victim->coords - coords) > 0 || (Random() % 2 == 0)) { award_bonus(id, Slashbonus); escapednum = 0; if (!Tutorial::active) { @@ -3154,7 +3145,7 @@ void Person::DoAnimations() Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 2, 1, 1, 1, .3, 1); } } else { - if (victim->weaponactive != -1) { + if (victim->hasWeapon()) { if (weapons[victim->weaponids[0]].getType() == staff || weapons[weaponids[0]].getType() == staff) { if (weapons[victim->weaponids[0]].getType() == staff) { weapons[victim->weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250; @@ -3202,7 +3193,7 @@ void Person::DoAnimations() if (id == 0) { camerashake += .4; } - if (Random() % 2 || creature == wolftype) { + if (Random() % 2 || PersonType::types[creature].hasClaws) { victim->spurt = 1; } emit_sound_at(staffheadsound, victim->coords); @@ -3237,7 +3228,7 @@ void Person::DoAnimations() if (id == 0) { camerashake += .4; } - if (Random() % 2 || creature == wolftype) { + if (Random() % 2 || PersonType::types[creature].hasClaws) { victim->spurt = 1; } emit_sound_at(staffheadsound, victim->coords); @@ -3272,7 +3263,7 @@ void Person::DoAnimations() if (id == 0) { camerashake += .4; } - if (Random() % 2 || creature == wolftype) { + if (Random() % 2 || PersonType::types[creature].hasClaws) { victim->spurt = 1; } emit_sound_at(staffbodysound, victim->coords); @@ -3345,7 +3336,7 @@ void Person::DoAnimations() if (victim->howactive == typesleeping) { victim->DoDamage(damagemult * 150 / victim->protectionhead); } - if (creature == wolftype) { + if (PersonType::types[creature].hasClaws) { emit_sound_at(clawslicesound, victim->coords, 128.); victim->spurt = 1; victim->DoBloodBig(2 / victim->armorhead, 175); @@ -3367,7 +3358,7 @@ void Person::DoAnimations() } victim->Puff(abdomen); victim->DoDamage(damagemult * 30 / victim->protectionhigh); - if (creature == wolftype) { + if (PersonType::types[creature].hasClaws) { emit_sound_at(clawslicesound, victim->coords, 128.); victim->spurt = 1; victim->DoBloodBig(2 / victim->armorhigh, 170); @@ -3450,7 +3441,7 @@ void Person::DoAnimations() if (!Tutorial::active) { emit_sound_at(heavyimpactsound, victim->coords, 128.); } - if (creature == wolftype) { + if (PersonType::types[creature].hasClaws) { emit_sound_at(clawslicesound, victim->coords, 128); victim->spurt = 1; victim->DoBloodBig(2 / victim->armorhigh, 170); @@ -3471,7 +3462,7 @@ void Person::DoAnimations() } if ((animTarget == swordslashreversalanim || animTarget == knifeslashreversalanim || animTarget == staffhitreversalanim || animTarget == staffspinhitreversalanim) && Animation::animations[animTarget].frames[frameCurrent].label == 5) { - if (victim->weaponactive != -1 && victim->num_weapons > 0) { + if (victim->hasWeapon() && victim->num_weapons > 0) { if (weapons[victim->weaponids[victim->weaponactive]].owner == int(victim->id)) { takeWeapon(victim->weaponids[victim->weaponactive]); victim->num_weapons--; @@ -3562,17 +3553,17 @@ void Person::DoAnimations() award_bonus(id, Reversal); bool doslice; - doslice = 0; - if (weaponactive != -1 || creature == wolftype) { - doslice = 1; - } - if (creature == rabbittype && weaponactive != -1) { - if (weapons[weaponids[0]].getType() == staff) { - doslice = 0; - } + if (hasWeapon()) { + doslice = (weapons[weaponids[0]].getType() != staff); + } else { + doslice = PersonType::types[creature].hasClaws; } if (doslice) { - if (weaponactive != -1) { + if (!hasWeapon()) { + emit_sound_at(clawslicesound, victim->coords, 128.); + victim->spurt = 1; + victim->DoBloodBig(2 / victim->armorhigh, 175); + } else { victim->DoBloodBig(2 / victim->armorhigh, 225); emit_sound_at(knifeslicesound, victim->coords); if (bloodtoggle && !weapons[weaponids[weaponactive]].bloody) { @@ -3580,11 +3571,6 @@ void Person::DoAnimations() } weapons[weaponids[weaponactive]].blooddrip += 3; } - if (weaponactive == -1 && creature == wolftype) { - emit_sound_at(clawslicesound, victim->coords, 128.); - victim->spurt = 1; - victim->DoBloodBig(2 / victim->armorhigh, 175); - } } } @@ -3656,17 +3642,17 @@ void Person::DoAnimations() victim->damage = victim->damagetolerance; victim->permanentdamage = victim->damagetolerance - 1; bool doslice; - doslice = 0; - if (weaponactive != -1 || creature == wolftype) { - doslice = 1; - } - if (creature == rabbittype && weaponactive != -1) { - if (weapons[weaponids[0]].getType() == staff) { - doslice = 0; - } + if (hasWeapon()) { + doslice = (weapons[weaponids[0]].getType() != staff); + } else { + doslice = PersonType::types[creature].hasClaws; } if (doslice) { - if (weaponactive != -1) { + if (!hasWeapon()) { + emit_sound_at(clawslicesound, victim->coords, 128.); + victim->spurt = 1; + victim->DoBloodBig(2, 175); + } else { victim->DoBloodBig(200, 225); emit_sound_at(knifeslicesound, victim->coords); if (bloodtoggle) { @@ -3674,18 +3660,12 @@ void Person::DoAnimations() } weapons[weaponids[weaponactive]].blooddrip += 5; } - - if (creature == wolftype && weaponactive == -1) { - emit_sound_at(clawslicesound, victim->coords, 128.); - victim->spurt = 1; - victim->DoBloodBig(2, 175); - } } award_bonus(id, spinecrusher); } if (hasvictim && (animCurrent == knifefollowanim || animCurrent == knifesneakattackanim) && currentFrame().label == 5) { - if (weaponactive != -1 && victim->bloodloss < victim->damagetolerance) { + if (hasWeapon() && victim->bloodloss < victim->damagetolerance) { escapednum = 0; if (animTarget == knifefollowanim) { victim->DoBloodBig(200, 210); @@ -3741,7 +3721,7 @@ void Person::DoAnimations() victim->skeleton.joints[i].velocity = 0; } } - if (weaponactive != -1 && Animation::animations[victim->animTarget].attack != reversal) { + if (hasWeapon() && Animation::animations[victim->animTarget].attack != reversal) { emit_sound_at(fleshstabremovesound, victim->coords); if (bloodtoggle) { weapons[weaponids[weaponactive]].bloody = 2; @@ -3763,7 +3743,7 @@ void Person::DoAnimations() } if (hasvictim && (animCurrent == swordsneakattackanim) && currentFrame().label == 5) { - if (weaponactive != -1 && victim->bloodloss < victim->damagetolerance) { + if (hasWeapon() && victim->bloodloss < victim->damagetolerance) { award_bonus(id, backstab); escapednum = 0; @@ -3797,7 +3777,7 @@ void Person::DoAnimations() for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) { victim->skeleton.joints[i].velocity = 0; } - if (weaponactive != -1) { + if (hasWeapon()) { emit_sound_at(fleshstabremovesound, victim->coords); if (bloodtoggle) { weapons[weaponids[weaponactive]].bloody = 2; @@ -3827,23 +3807,23 @@ void Person::DoAnimations() victim->spurt = 1; DoBlood(.2, 240); } - if (weaponactive == -1) { + if (!hasWeapon()) { if (!Tutorial::active) { emit_sound_at(heavyimpactsound, victim->coords, 128.); } } bool doslice; - doslice = 0; - if (weaponactive != -1 || creature == wolftype) { - doslice = 1; - } - if (creature == rabbittype && weaponactive != -1) { - if (weapons[weaponids[0]].getType() == staff) { - doslice = 0; - } + if (hasWeapon()) { + doslice = (weapons[weaponids[0]].getType() != staff); + } else { + doslice = PersonType::types[creature].hasClaws; } if (doslice) { - if (weaponactive != -1) { + if (!hasWeapon()) { + emit_sound_at(clawslicesound, victim->coords, 128.); + victim->spurt = 1; + victim->DoBloodBig(2 / victim->armorhead, 175); + } else { victim->DoBloodBig(2 / victim->armorhead, 225); emit_sound_at(knifeslicesound, victim->coords); if (bloodtoggle && !weapons[weaponids[weaponactive]].bloody) { @@ -3851,11 +3831,6 @@ void Person::DoAnimations() } weapons[weaponids[weaponactive]].blooddrip += 3; } - if (weaponactive == -1 && creature == wolftype) { - emit_sound_at(clawslicesound, victim->coords, 128.); - victim->spurt = 1; - victim->DoBloodBig(2 / victim->armorhead, 175); - } } award_bonus(id, Reversal); @@ -3942,8 +3917,9 @@ void Person::DoAnimations() if (animCurrent == crouchdrawrightanim) { animTarget = getCrouch(); } - if (weaponactive == -1) { + if (!hasWeapon()) { weaponactive = 0; + emit_sound_at(knifedrawsound, coords, 128.); } else if (weaponactive == 0) { weaponactive = -1; if (num_weapons == 2) { @@ -3952,14 +3928,8 @@ void Person::DoAnimations() weaponids[0] = weaponids[1]; weaponids[1] = buffer; } - } - - if (weaponactive == -1) { emit_sound_at(knifesheathesound, coords, 128.); } - if (weaponactive != -1) { - emit_sound_at(knifedrawsound, coords, 128.); - } } if (animCurrent == rollanim) { animTarget = getCrouch(); @@ -4313,7 +4283,7 @@ void Person::DoAnimations() animTarget = getIdle(); lastfeint = 0; } - if (animCurrent == blockhighleftanim && aitype != playercontrolled) { + if (animCurrent == blockhighleftanim && !isPlayerControlled()) { animTarget = blockhighleftstrikeanim; } if (animCurrent == knifeslashstartanim || animCurrent == knifethrowanim || animCurrent == swordslashanim || animCurrent == staffhitanim || animCurrent == staffgroundsmashanim || animCurrent == staffspinhitanim) { @@ -4535,7 +4505,7 @@ void Person::DoStuff() targetoffset = 0; } - if (num_weapons == 1 && weaponactive != -1) { + if (num_weapons == 1 && hasWeapon()) { weaponstuck = -1; } @@ -4582,7 +4552,7 @@ void Person::DoStuff() frameTarget = 0; } } - if (weaponactive == -1 && num_weapons > 0) { + if (!hasWeapon() && num_weapons > 0) { if (weapons[weaponids[0]].getType() == staff) { weaponactive = 0; } @@ -4694,7 +4664,7 @@ void Person::DoStuff() deathbleeding = 0; } if (bloodloss > damagetolerance && Animation::animations[animTarget].attack == neutral) { - if (weaponactive != -1) { + if (hasWeapon()) { weapons[weaponids[0]].drop(velocity * scale * -.3, velocity * scale); weapons[weaponids[0]].velocity.x += .01; num_weapons--; @@ -5125,7 +5095,7 @@ void Person::DoStuff() RagDoll(0); - if (weaponactive != -1) { + if (hasWeapon()) { weapons[weaponids[0]].drop(velocity * scale * -.3, velocity * scale); weapons[weaponids[0]].velocity.x += .01; num_weapons--; @@ -5182,7 +5152,7 @@ void Person::DoStuff() if (permanentdamage > damagetolerance && dead != 2) { DoBlood(1, 255); - if (weaponactive != -1) { + if (hasWeapon()) { weapons[weaponids[0]].drop(velocity * scale * -.3, velocity * scale); weapons[weaponids[0]].velocity.x += .01; num_weapons--; @@ -5716,7 +5686,7 @@ void Person::DoStuff() if (Tutorial::active && id != 0) { play = 0; } - if (play && aitype != playercontrolled) { + if (play && !isPlayerControlled()) { int whichsound = -1; if (speechdelay <= 0) { unsigned int i = abs(Random() % 4); @@ -5902,7 +5872,7 @@ void Person::DoStuff() } } - if (weaponactive != -1) { + if (hasWeapon()) { if (weapons[weaponids[weaponactive]].getType() != staff) { righthandmorphstart = 1; righthandmorphend = 1; @@ -6026,19 +5996,10 @@ void Person::DoStuff() } else if (isRun()) { velocity += facing * multiplier * speed * 700 * scale; velspeed = findLength(&velocity); - if (creature == rabbittype) { - if (velspeed > speed * 55 * scale) { - velocity /= velspeed; - velspeed = speed * 55 * scale; - velocity *= velspeed; - } - } - if (creature == wolftype) { - if (velspeed > speed * 75 * scale) { - velocity /= velspeed; - velspeed = speed * 75 * scale; - velocity *= velspeed; - } + if (velspeed > speed * PersonType::types[creature].maxRunSpeed * scale) { + velocity /= velspeed; + velspeed = speed * PersonType::types[creature].maxRunSpeed * scale; + velocity *= velspeed; } velocity.y += gravity * multiplier * 20; ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z)); @@ -7364,7 +7325,7 @@ bool Person::addClothes(const int& clothesId) void Person::doAI() { - if (aitype != playercontrolled && !Dialog::inDialog()) { + if (!isPlayerControlled() && !Dialog::inDialog()) { jumpclimb = 0; //disable movement in editor if (Game::editorenabled) { @@ -7372,9 +7333,9 @@ void Person::doAI() } pause = 0; - if (distsqflat(&Person::players[0]->coords, &coords) < 30 && - Person::players[0]->coords.y > coords.y + 2 && - !Person::players[0]->onterrain) { + if (distsqflat(&victim->coords, &coords) < 30 && + victim->coords.y > coords.y + 2 && + !victim->onterrain) { pause = 1; } @@ -7527,17 +7488,18 @@ void Person::doAI() if ((!Tutorial::active || cananger) && hostile && - !Person::players[0]->dead && - distsq(&coords, &Person::players[0]->coords) < 400 && + !isPlayerFriend() && + !victim->dead && + distsq(&coords, &victim->coords) < 400 && occluded < 25) { - if (distsq(&coords, &Person::players[0]->coords) < 12 && - Animation::animations[Person::players[0]->animTarget].height != lowheight && + if (distsq(&coords, &victim->coords) < 12 && + Animation::animations[victim->animTarget].height != lowheight && !Game::editorenabled && - (Person::players[0]->coords.y < coords.y + 5 || Person::players[0]->onterrain)) { + (victim->coords.y < coords.y + 5 || victim->onterrain)) { aitype = attacktypecutoff; } - if (distsq(&coords, &Person::players[0]->coords) < 30 && - Animation::animations[Person::players[0]->animTarget].height == highheight && + if (distsq(&coords, &victim->coords) < 30 && + Animation::animations[victim->animTarget].height == highheight && !Game::editorenabled) { aitype = attacktypecutoff; } @@ -7644,7 +7606,7 @@ void Person::doAI() //hearing sounds if (!Game::editorenabled) { if (howactive <= typesleeping) { - if (numenvsounds > 0 && (!Tutorial::active || cananger) && hostile) { + if (numenvsounds > 0 && (!Tutorial::active || cananger) && !isPlayerFriend() && hostile) { for (int j = 0; j < numenvsounds; j++) { float vol = howactive == typesleeping ? envsoundvol[j] - 14 : envsoundvol[j]; if (vol > 0 && distsq(&coords, &envsound[j]) < 2 * (vol + vol * (creature == rabbittype) * 3)) { @@ -7664,15 +7626,16 @@ void Person::doAI() if (howactive < typesleeping && ((!Tutorial::active || cananger) && hostile) && - !Person::players[0]->dead && - distsq(&coords, &Person::players[0]->coords) < 400 && + !isPlayerFriend() && + !victim->dead && + distsq(&coords, &victim->coords) < 400 && occluded < 25) { - if (distsq(&coords, &Person::players[0]->coords) < 12 && - Animation::animations[Person::players[0]->animTarget].height != lowheight && !Game::editorenabled) { + if (distsq(&coords, &victim->coords) < 12 && + Animation::animations[victim->animTarget].height != lowheight && !Game::editorenabled) { aitype = attacktypecutoff; } - if (distsq(&coords, &Person::players[0]->coords) < 30 && - Animation::animations[Person::players[0]->animTarget].height == highheight && !Game::editorenabled) { + if (distsq(&coords, &victim->coords) < 30 && + Animation::animations[victim->animTarget].height == highheight && !Game::editorenabled) { aitype = attacktypecutoff; } @@ -7842,7 +7805,7 @@ void Person::doAI() jumpkeydown = 1; } - if (numenvsounds > 0 && ((!Tutorial::active || cananger) && hostile)) { + if (numenvsounds > 0 && ((!Tutorial::active || cananger) && !isPlayerFriend() && hostile)) { for (int k = 0; k < numenvsounds; k++) { if (distsq(&coords, &envsound[k]) < 2 * (envsoundvol[k] + envsoundvol[k] * (creature == rabbittype) * 3)) { aitype = attacktypecutoff; @@ -7850,28 +7813,29 @@ void Person::doAI() } } - if (!Person::players[0]->dead && + if (!victim->dead && + !isPlayerFriend() && losupdatedelay < 0 && !Game::editorenabled && occluded < 2 && ((!Tutorial::active || cananger) && hostile)) { losupdatedelay = .2; - if (distsq(&coords, &Person::players[0]->coords) < 4 && Animation::animations[animTarget].height != lowheight) { + if (distsq(&coords, &victim->coords) < 4 && Animation::animations[animTarget].height != lowheight) { aitype = attacktypecutoff; lastseentime = 1; } if (abs(Random() % 2) || Animation::animations[animTarget].height != lowheight) { //TODO: factor out canSeePlayer() - if (distsq(&coords, &Person::players[0]->coords) < 400) { - if (normaldotproduct(facing, Person::players[0]->coords - coords) > 0) { + if (distsq(&coords, &victim->coords) < 400) { + if (normaldotproduct(facing, victim->coords - coords) > 0) { if ((Object::checkcollide( DoRotation(jointPos(head), 0, yaw, 0) * scale + coords, - DoRotation(Person::players[0]->jointPos(head), 0, Person::players[0]->yaw, 0) * - Person::players[0]->scale + - Person::players[0]->coords) == -1) || - (Person::players[0]->animTarget == hanganim && normaldotproduct(Person::players[0]->facing, coords - Person::players[0]->coords) < 0)) { + DoRotation(victim->jointPos(head), 0, victim->yaw, 0) * + victim->scale + + victim->coords) == -1) || + (victim->animTarget == hanganim && normaldotproduct(victim->facing, coords - victim->coords) < 0)) { /* //TODO: changed j to 0 on a whim, make sure this is correct (Person::players[j]->animTarget==hanganim&&normaldotproduct( Person::players[j]->facing,coords-Person::players[j]->coords)<0) @@ -7932,7 +7896,7 @@ void Person::doAI() } else { ally = 0; } - lastseen = Person::players[0]->coords; + lastseen = victim->coords; lastseentime = 12; } @@ -8036,13 +8000,13 @@ void Person::doAI() lastseentime = 12; - if (!Person::players[0]->dead && ((!Tutorial::active || cananger) && hostile)) { - if (ally < 0 || weaponactive != -1 || lastchecktime <= 0) { + if (!victim->dead && !isPlayerFriend() && ((!Tutorial::active || cananger) && hostile)) { + if (ally < 0 || hasWeapon() || lastchecktime <= 0) { aitype = attacktypecutoff; lastseentime = 1; } } - if (!Person::players[0]->dead) { + if (!victim->dead) { if (ally >= 0) { if (weapons[ally].owner != -1 || distsq(&coords, &weapons[ally].position) > 16) { @@ -8099,18 +8063,18 @@ void Person::doAI() aiupdatedelay -= multiplier; //dodge or reverse rabbit kicks, knife throws, flips if (damage < damagetolerance * 2 / 3) { - if ((Person::players[0]->animTarget == rabbitkickanim || - Person::players[0]->animTarget == knifethrowanim || - (Person::players[0]->isFlip() && - normaldotproduct(Person::players[0]->facing, Person::players[0]->coords - coords) < 0)) && - !Person::players[0]->skeleton.free && + if ((victim->animTarget == rabbitkickanim || + victim->animTarget == knifethrowanim || + (victim->isFlip() && + normaldotproduct(victim->facing, victim->coords - coords) < 0)) && + !victim->skeleton.free && (aiupdatedelay < .1)) { attackkeydown = 0; if (isIdle()) { crouchkeydown = 1; } - if (Person::players[0]->animTarget != rabbitkickanim && Person::players[0]->weaponactive != -1) { - if (weapons[Person::players[0]->weaponids[0]].getType() == knife) { + if (victim->animTarget != rabbitkickanim && victim->hasWeapon()) { + if (weapons[victim->weaponids[0]].getType() == knife) { if (isIdle() || isCrouch() || isRun() || isFlip()) { if (abs(Random() % 2) == 0) { setTargetAnimation(backhandspringanim); @@ -8130,11 +8094,11 @@ void Person::doAI() } } //get confused by flips - if (Person::players[0]->isFlip() && - !Person::players[0]->skeleton.free && - Person::players[0]->animTarget != walljumprightkickanim && - Person::players[0]->animTarget != walljumpleftkickanim) { - if (distsq(&Person::players[0]->coords, &coords) < 25) { + if (victim->isFlip() && + !victim->skeleton.free && + victim->animTarget != walljumprightkickanim && + victim->animTarget != walljumpleftkickanim) { + if (distsq(&victim->coords, &coords) < 25) { if ((1 - damage / damagetolerance) > .5) { stunned = 1; } @@ -8163,8 +8127,8 @@ void Person::doAI() if (damage < damagetolerance / 2) { if (Animation::animations[animTarget].height != highheight) { if (damage < damagetolerance * .5 && - ((Person::players[0]->animTarget == walljumprightkickanim || - Person::players[0]->animTarget == walljumpleftkickanim) && + ((victim->animTarget == walljumprightkickanim || + victim->animTarget == walljumpleftkickanim) && ((aiupdatedelay < .15 && difficulty == 2) || (aiupdatedelay < .08 && @@ -8203,9 +8167,9 @@ void Person::doAI() } } //lose sight of player in the air (?) - if (Person::players[0]->coords.y > coords.y + 5 && - Animation::animations[Person::players[0]->animTarget].height != highheight && - !Person::players[0]->onterrain) { + if (victim->coords.y > coords.y + 5 && + Animation::animations[victim->animTarget].height != highheight && + !victim->onterrain) { aitype = pathfindtype; finalfinaltarget = waypoints[waypoint]; finalpathfindpoint = -1; @@ -8223,30 +8187,30 @@ void Person::doAI() animTarget != backhandspringanim && animTarget != dodgebackanim) { //draw weapon - if (weaponactive == -1 && num_weapons > 0) { + if (!hasWeapon() && num_weapons > 0) { drawkeydown = Random() % 2; } else { drawkeydown = 0; } rabbitkickenabled = Random() % 2; //chase player - XYZ rotatetarget = Person::players[0]->coords + Person::players[0]->velocity; - XYZ targetpoint = Person::players[0]->coords; + XYZ rotatetarget = victim->coords + victim->velocity; + XYZ targetpoint = victim->coords; float vellength = findLength(&velocity); if (vellength != 0 && - distsq(&Person::players[0]->coords, &coords) < distsq(&rotatetarget, &coords)) { - targetpoint += Person::players[0]->velocity * - findDistance(&Person::players[0]->coords, &coords) / vellength; + distsq(&victim->coords, &coords) < distsq(&rotatetarget, &coords)) { + targetpoint += victim->velocity * + findDistance(&victim->coords, &coords) / vellength; } targetyaw = roughDirectionTo(coords, targetpoint); lookyaw = targetyaw; aiupdatedelay = .2 + fabs((float)(Random() % 100) / 1000); - if (distsq(&coords, &Person::players[0]->coords) > 5 && (Person::players[0]->weaponactive == -1 || weaponactive != -1)) { + if (distsq(&coords, &victim->coords) > 5 && (!victim->hasWeapon() || hasWeapon())) { forwardkeydown = 1; - } else if ((distsq(&coords, &Person::players[0]->coords) > 16 || - distsq(&coords, &Person::players[0]->coords) < 9) && - Person::players[0]->weaponactive != -1) { + } else if ((distsq(&coords, &victim->coords) > 16 || + distsq(&coords, &victim->coords) < 9) && + victim->hasWeapon()) { forwardkeydown = 1; } else if (Random() % 6 == 0 || (creature == wolftype && Random() % 3 == 0)) { forwardkeydown = 1; @@ -8254,7 +8218,7 @@ void Person::doAI() forwardkeydown = 0; } //chill out around the corpse - if (Person::players[0]->dead) { + if (victim->dead) { forwardkeydown = 0; if (Random() % 10 == 0) { forwardkeydown = 1; @@ -8280,17 +8244,17 @@ void Person::doAI() targetyaw += 90 * (whichdirection * 2 - 1); } //attack!!! - if (Random() % 2 == 0 || weaponactive != -1 || creature == wolftype) { + if (Random() % 2 == 0 || hasWeapon() || creature == wolftype) { attackkeydown = 1; } else { attackkeydown = 0; } - if (isRun() && Random() % 6 && distsq(&coords, &Person::players[0]->coords) > 7) { + if (isRun() && Random() % 6 && distsq(&coords, &victim->coords) > 7) { attackkeydown = 0; } //TODO: wat - if (aitype != playercontrolled && + if (!isPlayerControlled() && (isIdle() || isCrouch() || isRun())) { @@ -8306,9 +8270,9 @@ void Person::doAI() Person::players[j]->lastattack3 == Person::players[j]->animTarget && (Random() % 2 == 0 || difficulty == 2) || (isIdle() || isRun()) && - Person::players[j]->weaponactive != -1 || + Person::players[j]->hasWeapon() || Person::players[j]->animTarget == swordslashanim && - weaponactive != -1 || + hasWeapon() || Person::players[j]->animTarget == staffhitanim || Person::players[j]->animTarget == staffspinhitanim)) { if (distsq(&Person::players[j]->coords, &Person::players[j]->victim->coords) < 4 && @@ -8323,7 +8287,7 @@ void Person::doAI() Person::players[j]->animTarget == knifeslashstartanim || Person::players[j]->animTarget == swordslashanim && (distsq(&Person::players[j]->coords, &coords) < 2 || - weaponactive != -1))) { + hasWeapon()))) { if (target >= 0) { target = -1; } else { @@ -8341,17 +8305,17 @@ void Person::doAI() jumpkeydown = 0; } if (collided > .8 && jumppower >= 5 || - distsq(&coords, &Person::players[0]->coords) > 400 && + distsq(&coords, &victim->coords) > 400 && onterrain && creature == rabbittype) { jumpkeydown = 1; } //TODO: why are we controlling the human? - if (normaldotproduct(facing, Person::players[0]->coords - coords) > 0) { - Person::players[0]->jumpkeydown = 0; + if (normaldotproduct(facing, victim->coords - coords) > 0) { + victim->jumpkeydown = 0; } - if (Person::players[0]->animTarget == jumpdownanim && - distsq(&Person::players[0]->coords, &coords) < 40) { + if (victim->animTarget == jumpdownanim && + distsq(&victim->coords, &coords) < 40) { crouchkeydown = 1; } if (jumpkeydown) { @@ -8365,9 +8329,9 @@ void Person::doAI() } XYZ facing = coords; - XYZ flatfacing = Person::players[0]->coords; + XYZ flatfacing = victim->coords; facing.y += jointPos(head).y * scale; - flatfacing.y += Person::players[0]->jointPos(head).y * Person::players[0]->scale; + flatfacing.y += victim->jointPos(head).y * victim->scale; if (occluded >= 2) { if (-1 != Object::checkcollide(facing, flatfacing)) { if (!pause) { @@ -8378,7 +8342,7 @@ void Person::doAI() weaponstuck == -1)) { aitype = searchtype; lastchecktime = 12; - lastseen = Person::players[0]->coords; + lastseen = victim->coords; lastseentime = 12; } } else { @@ -8387,17 +8351,18 @@ void Person::doAI() } } } - if (Animation::animations[Person::players[0]->animTarget].height == highheight && + if (Animation::animations[victim->animTarget].height == highheight && (aitype == attacktypecutoff || aitype == searchtype)) { - if (Person::players[0]->coords.y > terrain.getHeight(Person::players[0]->coords.x, Person::players[0]->coords.z) + 10) { - XYZ test = Person::players[0]->coords; + if (victim->coords.y > terrain.getHeight(victim->coords.x, victim->coords.z) + 10) { + XYZ test = victim->coords; test.y -= 40; - if (-1 == Object::checkcollide(Person::players[0]->coords, test)) { + if (-1 == Object::checkcollide(victim->coords, test)) { stunned = 1; } } } + //stunned if (aitype == passivetype && !(numwaypoints > 1) || stunned > 0 || @@ -8416,6 +8381,32 @@ void Person::doAI() throwkeydown = 0; } + if (stunned < 1 && isPlayerFriend()) { + // friends follow player + if (!Person::players[0]->dead && + distsq(&coords, &Person::players[0]->coords) > 5) { + XYZ rotatetarget = Person::players[0]->coords + Person::players[0]->velocity; + XYZ targetpoint = Person::players[0]->coords; + velocity = (targetpoint - coords); + velocity.y += 2; + float vellength = findLength(&velocity); + if (vellength != 0 && + distsq(&Person::players[0]->coords, &coords) < distsq(&rotatetarget, &coords)) { + targetpoint += Person::players[0]->velocity * + findDistance(&Person::players[0]->coords, &coords) / vellength; + } + targetyaw = roughDirectionTo(coords, targetpoint); + lookyaw = targetyaw; + forwardkeydown = 1; + aitype = pathfindtype; + } + + // friends help player with its enemies + if (Game::musictype == stream_fighttheme) { + aitype = attacktypecutoff; + } + } + XYZ facing; facing = 0; facing.z = -1; @@ -8429,6 +8420,9 @@ void Person::doAI() } else if (howactive >= typesleeping) { targetheadyaw = targetyaw; targetheadpitch = 0; + } else if (isPlayerFriend()) { + targetheadyaw = 180 - roughDirectionTo(coords, Person::players[0]->coords); + targetheadpitch = pitchTo(coords, Person::players[0]->coords); } else { if (interestdelay <= 0) { interestdelay = .7 + (float)(abs(Random() % 100)) / 100; @@ -8443,3 +8437,10 @@ void Person::doAI() } } } + +bool Person::catchKnife() +{ + return + ((PersonType::types[creature].knifeCatchingType == 0) && (Random() % 2 != 0) && (!hasWeapon()) && (aitype == attacktypecutoff)) || + ((PersonType::types[creature].knifeCatchingType == 1) && (Random() % 3 != 0) && (!hasWeapon()) && (isIdle() || isRun() || animTarget == walkanim)); +}