X-Git-Url: https://git.jsancho.org/?a=blobdiff_plain;f=Source%2FGameTick.cpp;h=dbd6f0e3977541aba323b8ae2e6668b188aecd7f;hb=a99778b1da1ea16a6a87a00461cd2c4e36ab13a3;hp=92a36c992b99881b728470993711c5eb629f69c5;hpb=ce51a88a16d2e7af222929546d250eba4acb299d;p=lugaru.git diff --git a/Source/GameTick.cpp b/Source/GameTick.cpp index 92a36c9..dbd6f0e 100644 --- a/Source/GameTick.cpp +++ b/Source/GameTick.cpp @@ -840,13 +840,11 @@ bool Game::LoadLevel(const std::string& name, bool tutorial) } else { Person::players[i]->damagetolerance = 200; } - } - Game::LoadingScreen(); + Game::LoadingScreen(); - Person::players[i]->tempanimation = Animation("Tempanim", lowheight, neutral); + Person::players[i]->tempanimation = Animation("Tempanim", lowheight, neutral); - if (i == 0) { Person::players[i]->headmorphness = 0; Person::players[i]->targetheadmorphness = 1; Person::players[i]->headmorphstart = 0; @@ -1434,7 +1432,7 @@ void Game::ProcessDevInput() Person::players.back()->howactive = editoractive; Person::players.back()->whichskin = (int)(abs(Random() % 3)); - Person::players.back()->skeletonLoad(true); + Person::players.back()->skeletonLoad(); Person::players.back()->skeleton.drawmodelclothes.textureptr.load("Textures/Belt.png", 1); Person::players.back()->speed = 1 + (float)(Random() % 100) / 1000; @@ -1448,8 +1446,6 @@ void Game::ProcessDevInput() Person::players.back()->setProportions(1, 1, 1, 1); - Person::players.back()->tempanimation = Animation("Tempanim", lowheight, neutral); - Person::players.back()->damagetolerance = 200; Person::players.back()->protectionhead = Person::players[0]->protectionhead; @@ -1476,6 +1472,9 @@ void Game::ProcessDevInput() Person::players.back()->power = Person::players[0]->power; Person::players.back()->speedmult = Person::players[0]->speedmult; + if (Input::isKeyDown(SDL_SCANCODE_RSHIFT)) + Person::players.back()->isplayerfriend = true; + Person::players.back()->loaded = true; } @@ -1589,7 +1588,7 @@ void Game::ProcessDevInput() } /* Decrease size for next object */ - if (Input::isKeyDown(SDL_SCANCODE_DOWN) && !Input::isKeyDown(SDL_SCANCODE_LCTRL)) { + if (Input::isKeyDown(SDL_SCANCODE_DOWN) && Input::isKeyDown(SDL_SCANCODE_LSHIFT)) { editorsize -= multiplier; if (editorsize < .1) { editorsize = .1; @@ -1597,7 +1596,7 @@ void Game::ProcessDevInput() } /* Increase size for next object */ - if (Input::isKeyDown(SDL_SCANCODE_UP) && !Input::isKeyDown(SDL_SCANCODE_LCTRL)) { + if (Input::isKeyDown(SDL_SCANCODE_UP) && Input::isKeyDown(SDL_SCANCODE_LSHIFT)) { editorsize += multiplier; } @@ -1647,8 +1646,8 @@ void doJumpReversals() Person::players[i]->skeleton.oldfree == 0 && (Person::players[i]->animTarget == jumpupanim || Person::players[k]->animTarget == jumpupanim) && - (Person::players[i]->aitype == playercontrolled || - Person::players[k]->aitype == playercontrolled) && + (Person::players[i]->isPlayerControlled() || + Person::players[k]->isPlayerControlled()) && ((Person::players[i]->aitype == attacktypecutoff && Person::players[i]->stunned <= 0) || (Person::players[k]->aitype == attacktypecutoff && Person::players[k]->stunned <= 0))) { if (distsq(&Person::players[i]->coords, &Person::players[k]->coords) < 10 * sq((Person::players[i]->scale + Person::players[k]->scale) * 2.5) && @@ -1659,8 +1658,8 @@ void doJumpReversals() Person::players[k]->animTarget != getupfromfrontanim && Animation::animations[Person::players[k]->animTarget].height == middleheight && normaldotproduct(Person::players[i]->velocity, Person::players[k]->coords - Person::players[i]->coords) < 0 && - ((Person::players[k]->aitype == playercontrolled && Person::players[k]->attackkeydown) || - Person::players[k]->aitype != playercontrolled)) { + ((Person::players[k]->isPlayerControlled() && Person::players[k]->attackkeydown) || + !Person::players[k]->isPlayerControlled())) { Person::players[i]->victim = Person::players[k]; Person::players[i]->velocity = 0; Person::players[i]->animCurrent = jumpreversedanim; @@ -1699,8 +1698,8 @@ void doJumpReversals() Person::players[i]->animTarget != getupfromfrontanim && Animation::animations[Person::players[i]->animTarget].height == middleheight && normaldotproduct(Person::players[k]->velocity, Person::players[i]->coords - Person::players[k]->coords) < 0 && - ((Person::players[i]->aitype == playercontrolled && Person::players[i]->attackkeydown) || - Person::players[i]->aitype != playercontrolled)) { + ((Person::players[i]->isPlayerControlled() && Person::players[i]->attackkeydown) || + !Person::players[i]->isPlayerControlled())) { Person::players[k]->victim = Person::players[i]; Person::players[k]->velocity = 0; Person::players[k]->animCurrent = jumpreversedanim; @@ -1805,7 +1804,7 @@ void doAerialAcrobatics() for (unsigned int l = 0; l < terrain.patchobjects[Person::players[k]->whichpatchx][Person::players[k]->whichpatchz].size(); l++) { unsigned int i = terrain.patchobjects[Person::players[k]->whichpatchx][Person::players[k]->whichpatchz][l]; if (Object::objects[i]->type != rocktype || - Object::objects[i]->scale > .5 && Person::players[k]->aitype == playercontrolled || + Object::objects[i]->scale > .5 && Person::players[k]->isPlayerControlled() || Object::objects[i]->position.y > Person::players[k]->coords.y) { lowpoint = Person::players[k]->coords; if (Person::players[k]->animTarget != jumpupanim && @@ -1827,7 +1826,7 @@ void doAerialAcrobatics() tempcollide = 1; //wall jumps //TODO: refactor four similar blocks - if (Person::players[k]->aitype == playercontrolled && + if (Person::players[k]->isPlayerControlled() && (Person::players[k]->animTarget == jumpupanim || Person::players[k]->animTarget == jumpdownanim || Person::players[k]->isFlip()) && @@ -1983,7 +1982,7 @@ void doAerialAcrobatics() Person::players[k]->coords.y -= 1.35; Person::players[k]->collide = 1; - if ((Person::players[k]->grabdelay <= 0 || Person::players[k]->aitype != playercontrolled) && + if ((Person::players[k]->grabdelay <= 0 || !Person::players[k]->isPlayerControlled()) && (Person::players[k]->animCurrent != climbanim && Person::players[k]->animCurrent != hanganim && !Person::players[k]->isWallJump() || @@ -2161,7 +2160,7 @@ void doAttacks() playerrealattackkeydown = Input::isKeyDown(attackkey); } if ((Person::players[0]->parriedrecently <= 0 || - Person::players[0]->weaponactive == -1) && + !Person::players[0]->hasWeapon()) && (!oldattackkey || (realthreat && Person::players[0]->lastattack != swordslashanim && @@ -2193,8 +2192,24 @@ void doAttacks() Person::players[k]->attackkeydown = 0; } if (Person::players[k]->animTarget != rabbitrunninganim && Person::players[k]->animTarget != wolfrunninganim) { - if (Person::players[k]->aitype != playercontrolled) { - Person::players[k]->victim = Person::players[0]; + if (!Person::players[k]->isPlayerControlled()) { + if (Person::players[k]->isPlayerFriend()) { + bool found = false; + for (unsigned k2 = 1; k2 < Person::players.size(); k2++) { + if (k != k2 && + !Person::players[k2]->dead && + Person::players[k2]->aitype == attacktypecutoff) { + Person::players[k]->victim = Person::players[k2]; + found = true; + break; + } + } + if (!found) { + Person::players[k]->attackkeydown = 0; + } + } else { + Person::players[k]->victim = Person::players[0]; + } } //attack key pressed if (Person::players[k]->attackkeydown) { @@ -2248,7 +2263,7 @@ void doAttacks() Person::players[k]->animTarget == walkanim || Person::players[k]->animTarget == sneakanim || Person::players[k]->isCrouch())) { - const int attackweapon = Person::players[k]->weaponactive == -1 ? 0 : weapons[Person::players[k]->weaponids[Person::players[k]->weaponactive]].getType(); + const int attackweapon = (Person::players[k]->hasWeapon() ? weapons[Person::players[k]->weaponids[Person::players[k]->weaponactive]].getType() : 0); //normal attacks (?) Person::players[k]->hasvictim = 0; if (Person::players.size() > 1) { @@ -2275,7 +2290,7 @@ void doAttacks() Person::players[i]->animTarget != getupfromfrontanim) { Person::players[k]->victim = Person::players[i]; Person::players[k]->hasvictim = 1; - if (Person::players[k]->aitype == playercontrolled) { //human player + if (Person::players[k]->isPlayerControlled()) { //human player //sweep if (distance < 2.5 * sq(Person::players[k]->scale * 5) && Person::players[k]->crouchkeydown && @@ -2661,7 +2676,7 @@ void doAttacks() } } } - if (Person::players[k]->aitype == playercontrolled) { + if (Person::players[k]->isPlayerControlled()) { //rabbit kick if (Person::players[k]->attackkeydown && Person::players[k]->isRun() && @@ -2673,7 +2688,7 @@ void doAttacks() Person::players[k]->victim->animTarget != getupfrombackanim && Person::players[k]->victim->animTarget != getupfromfrontanim && Animation::animations[Person::players[k]->victim->animTarget].height != lowheight && - Person::players[k]->aitype != playercontrolled && //wat??? + !Person::players[k]->isPlayerControlled() && //wat??? normaldotproduct(Person::players[k]->facing, Person::players[k]->victim->coords - Person::players[k]->coords) > 0 && Person::players[k]->rabbitkickenabled) || Person::players[k]->jumpkeydown)) { @@ -3466,7 +3481,7 @@ void Game::Tick() Person::players[i]->targetheadyaw = yaw; Person::players[i]->targetheadpitch = pitch; } - if (i != 0 && Person::players[i]->aitype == playercontrolled && !Dialog::inDialog()) { + if (i != 0 && Person::players[i]->isPlayerControlled() && !Dialog::inDialog()) { if (!Animation::animations[Person::players[i]->animTarget].attack && Person::players[i]->animTarget != staggerbackhighanim && Person::players[i]->animTarget != staggerbackhardanim && @@ -3603,7 +3618,7 @@ void Game::Tick() //pick up weapon if (Person::players[i]->throwkeydown && !Person::players[i]->throwtogglekeydown) { - if (Person::players[i]->weaponactive == -1 && + if (!Person::players[i]->hasWeapon() && Person::players[i]->num_weapons < 2 && (Person::players[i]->isIdle() || Person::players[i]->isCrouch() || @@ -3611,19 +3626,19 @@ void Game::Tick() Person::players[i]->animTarget == rollanim || Person::players[i]->animTarget == backhandspringanim || Person::players[i]->isFlip() || - Person::players[i]->aitype != playercontrolled)) { + !Person::players[i]->isPlayerControlled())) { for (unsigned j = 0; j < weapons.size(); j++) { if ((weapons[j].velocity.x == 0 && weapons[j].velocity.y == 0 && weapons[j].velocity.z == 0 || - Person::players[i]->aitype == playercontrolled) && + Person::players[i]->isPlayerControlled()) && weapons[j].owner == -1 && - Person::players[i]->weaponactive == -1) { + !Person::players[i]->hasWeapon()) { if (distsqflat(&Person::players[i]->coords, &weapons[j].position) < 2) { if (distsq(&Person::players[i]->coords, &weapons[j].position) < 2) { if (Person::players[i]->isCrouch() || Person::players[i]->animTarget == sneakanim || Person::players[i]->isRun() || Person::players[i]->isIdle() || - Person::players[i]->aitype != playercontrolled) { + !Person::players[i]->isPlayerControlled()) { Person::players[i]->throwtogglekeydown = 1; Person::players[i]->setTargetAnimation(crouchremoveknifeanim); Person::players[i]->targetyaw = roughDirectionTo(Person::players[i]->coords, weapons[j].position); @@ -3634,11 +3649,11 @@ void Game::Tick() Person::players[i]->hasvictim = 0; if ((weapons[j].velocity.x == 0 && weapons[j].velocity.y == 0 && weapons[j].velocity.z == 0 || - Person::players[i]->aitype == playercontrolled) && + Person::players[i]->isPlayerControlled()) && weapons[j].owner == -1 || Person::players[i]->victim && weapons[j].owner == int(Person::players[i]->victim->id)) { - if (distsqflat(&Person::players[i]->coords, &weapons[j].position) < 2 && Person::players[i]->weaponactive == -1) { + if (distsqflat(&Person::players[i]->coords, &weapons[j].position) < 2 && !Person::players[i]->hasWeapon()) { if (distsq(&Person::players[i]->coords, &weapons[j].position) < 1 || Person::players[i]->victim) { if (weapons[j].getType() != staff) { emit_sound_at(knifedrawsound, Person::players[i]->coords, 128.); @@ -3651,7 +3666,7 @@ void Game::Tick() } } else if ((Person::players[i]->isIdle() || Person::players[i]->isFlip() || - Person::players[i]->aitype != playercontrolled) && + !Person::players[i]->isPlayerControlled()) && distsq(&Person::players[i]->coords, &weapons[j].position) < 5 && Person::players[i]->coords.y < weapons[j].position.y) { if (!Person::players[i]->isFlip()) { @@ -3664,14 +3679,14 @@ void Game::Tick() Person::players[i]->hasvictim = 0; for (unsigned k = 0; k < weapons.size(); k++) { - if (Person::players[i]->weaponactive == -1) { + if (!Person::players[i]->hasWeapon()) { if ((weapons[k].velocity.x == 0 && weapons[k].velocity.y == 0 && weapons[k].velocity.z == 0 || - Person::players[i]->aitype == playercontrolled) && + Person::players[i]->isPlayerControlled()) && weapons[k].owner == -1 || Person::players[i]->victim && weapons[k].owner == int(Person::players[i]->victim->id)) { if (distsqflat(&Person::players[i]->coords, &weapons[k].position) < 3 && - Person::players[i]->weaponactive == -1) { + !Person::players[i]->hasWeapon()) { if (weapons[k].getType() != staff) { emit_sound_at(knifedrawsound, Person::players[i]->coords, 128.); } @@ -3693,7 +3708,7 @@ void Game::Tick() Person::players[i]->animTarget == backhandspringanim) { if (Person::players.size() > 1) { for (unsigned j = 0; j < Person::players.size(); j++) { - if (Person::players[i]->weaponactive == -1) { + if (!Person::players[i]->hasWeapon()) { if (j != i) { if (Person::players[j]->num_weapons && Person::players[j]->skeleton.free && @@ -3794,7 +3809,7 @@ void Game::Tick() } } } - if (Person::players[i]->weaponactive != -1 && Person::players[i]->aitype == playercontrolled) { + if (Person::players[i]->hasWeapon() && Person::players[i]->isPlayerControlled()) { if (weapons[Person::players[i]->weaponids[0]].getType() == knife) { if (Person::players[i]->isIdle() || Person::players[i]->isRun() || @@ -3819,7 +3834,7 @@ void Game::Tick() Person::players[i]->targettilt2 = pitchTo(Person::players[i]->coords, Person::players[j]->coords); } if (Person::players[i]->isFlip()) { - if (Person::players[i]->weaponactive != -1) { + if (Person::players[i]->hasWeapon()) { Person::players[i]->throwtogglekeydown = 1; Person::players[i]->victim = Person::players[j]; XYZ aim; @@ -3845,7 +3860,7 @@ void Game::Tick() } } } - if (Person::players[i]->weaponactive != -1 && Person::players[i]->aitype == playercontrolled) { + if (Person::players[i]->hasWeapon() && Person::players[i]->isPlayerControlled()) { if (Person::players[i]->isCrouch() || Person::players[i]->animTarget == sneakanim) { Person::players[i]->throwtogglekeydown = 1; XYZ tempVelocity = Person::players[i]->velocity * .2; @@ -3870,16 +3885,16 @@ void Game::Tick() } //draw weapon - if (i == 0 || !Person::players[0]->dead || (Person::players[i]->weaponactive != -1)) { + if (i == 0 || !Person::players[0]->dead || (Person::players[i]->hasWeapon())) { if (Person::players[i]->drawkeydown && !Person::players[i]->drawtogglekeydown || (Person::players[i]->num_weapons == 2) && - (Person::players[i]->weaponactive == -1) && + (!Person::players[i]->hasWeapon()) && Person::players[i]->isIdle() || Person::players[0]->dead && - (Person::players[i]->weaponactive != -1) && + (Person::players[i]->hasWeapon()) && i != 0) { bool isgood = true; - if (Person::players[i]->weaponactive != -1) { + if (Person::players[i]->hasWeapon()) { if (weapons[Person::players[i]->weaponids[Person::players[i]->weaponactive]].getType() == staff) { isgood = false; } @@ -3890,8 +3905,8 @@ void Game::Tick() Person::players[i]->drawtogglekeydown = 1; } if ((Person::players[i]->isIdle() || - (Person::players[i]->aitype != playercontrolled && - Person::players[0]->weaponactive != -1 && + (!Person::players[i]->isPlayerControlled() && + Person::players[0]->hasWeapon() && Person::players[i]->isRun())) && Person::players[i]->num_weapons && weapons[Person::players[i]->weaponids[0]].getType() == sword) { @@ -3907,7 +3922,7 @@ void Game::Tick() } //clean weapon - if (Person::players[i]->weaponactive != -1) { + if (Person::players[i]->hasWeapon()) { if (Person::players[i]->isCrouch() && weapons[Person::players[i]->weaponids[Person::players[i]->weaponactive]].bloody && bloodtoggle && @@ -4085,7 +4100,7 @@ void Game::Tick() } Person::players[i]->frameTarget = 0; } - if (Person::players[i]->animTarget == hanganim /*&&(!Person::players[i]->forwardstogglekeydown||Person::players[i]->aitype!=playercontrolled)*/) { + if (Person::players[i]->animTarget == hanganim /*&&(!Person::players[i]->forwardstogglekeydown||!Person::players[i]->isPlayerControlled())*/) { Person::players[i]->setTargetAnimation(climbanim); Person::players[i]->frameTarget = 1; Person::players[i]->jumpclimb = 1; @@ -4246,7 +4261,7 @@ void Game::Tick() } if (target >= 0) { Person::players[i]->velocity.y = 1; - } else if (Person::players[i]->crouchkeydown || Person::players[i]->aitype != playercontrolled) { + } else if (Person::players[i]->crouchkeydown || !Person::players[i]->isPlayerControlled()) { Person::players[i]->velocity.y = 7; Person::players[i]->crouchtogglekeydown = 1; } else { @@ -4282,7 +4297,7 @@ void Game::Tick() (((!floatjump && !editorenabled) || !devtools) || - Person::players[i]->aitype != playercontrolled)) { + !Person::players[i]->isPlayerControlled())) { if (Person::players[i]->jumppower > multiplier * 6) { Person::players[i]->velocity.y += multiplier * 6; Person::players[i]->jumppower -= multiplier * 6; @@ -4488,6 +4503,7 @@ void Game::TickOnceAfter() Person::players[i]->aitype == gethelptype || Person::players[i]->aitype == searchtype) && !Person::players[i]->dead && + !Person::players[i]->isPlayerFriend() && (Person::players[i]->animTarget != sneakattackedanim && Person::players[i]->animTarget != knifesneakattackedanim && Person::players[i]->animTarget != swordsneakattackedanim)) { @@ -4638,7 +4654,7 @@ void Game::TickOnceAfter() } alldead = true; for (unsigned i = 1; i < Person::players.size(); i++) { - if (!Person::players[i]->dead && Person::players[i]->howactive < typedead1) { + if (!Person::players[i]->dead && Person::players[i]->howactive < typedead1 && !Person::players[i]->isPlayerFriend()) { alldead = false; break; }