From 265236f7b4d05d576a4a6fd81823abff5f3f757b Mon Sep 17 00:00:00 2001 From: =?utf8?q?C=C3=B4me=20Chilliet?= Date: Sat, 19 Aug 2017 02:01:08 +0200 Subject: [PATCH] Moved knife catching test to a method and removed hardcoded rabbittype test --- Source/Objects/Person.cpp | 7 +++++++ Source/Objects/Person.hpp | 2 ++ Source/Objects/PersonType.cpp | 2 ++ Source/Objects/PersonType.hpp | 1 + Source/Objects/Weapons.cpp | 3 +-- 5 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Source/Objects/Person.cpp b/Source/Objects/Person.cpp index 0ca911a..8898cac 100644 --- a/Source/Objects/Person.cpp +++ b/Source/Objects/Person.cpp @@ -8417,3 +8417,10 @@ void Person::doAI() } } } + +bool Person::catchKnife() +{ + return + ((PersonType::types[creature].knifeCatchingType == 0) && (Random() % 2 != 0) && (weaponactive == -1) && (aitype == attacktypecutoff)) || + ((PersonType::types[creature].knifeCatchingType == 1) && (Random() % 3 != 0) && (weaponactive == -1) && (isIdle() || isRun() || animTarget == walkanim)); +} diff --git a/Source/Objects/Person.hpp b/Source/Objects/Person.hpp index 0bacf77..9492fb7 100644 --- a/Source/Objects/Person.hpp +++ b/Source/Objects/Person.hpp @@ -400,6 +400,8 @@ public: void addClothes(); void doAI(); + + bool catchKnife(); }; const int maxplayers = 10; diff --git a/Source/Objects/PersonType.cpp b/Source/Objects/PersonType.cpp index c1a3aec..0cf880c 100644 --- a/Source/Objects/PersonType.cpp +++ b/Source/Objects/PersonType.cpp @@ -81,6 +81,7 @@ void PersonType::Load() types[wolftype].hasClaws = true; types[wolftype].clothes = false; types[wolftype].maxRunSpeed = 75; + types[wolftype].knifeCatchingType = 1; /* Rabbit */ types[rabbittype].proportions[0] = 1.2; @@ -137,4 +138,5 @@ void PersonType::Load() types[rabbittype].hasClaws = false; types[rabbittype].clothes = true; types[rabbittype].maxRunSpeed = 55; + types[rabbittype].knifeCatchingType = 0; } diff --git a/Source/Objects/PersonType.hpp b/Source/Objects/PersonType.hpp index b60fc19..f981113 100644 --- a/Source/Objects/PersonType.hpp +++ b/Source/Objects/PersonType.hpp @@ -63,6 +63,7 @@ public: bool hasClaws; bool clothes; unsigned int maxRunSpeed; + unsigned int knifeCatchingType; GLubyte bloodText[512 * 512 * 3] = { 0 }; diff --git a/Source/Objects/Weapons.cpp b/Source/Objects/Weapons.cpp index 846ccad..015fb91 100644 --- a/Source/Objects/Weapons.cpp +++ b/Source/Objects/Weapons.cpp @@ -259,8 +259,7 @@ void Weapon::doStuff(int i) distsq(&position, &Person::players[j]->coords) < 4 && Person::players[j]->weaponstuck == -1 && !Person::players[j]->skeleton.free && (int(j) != oldowner)) { if ((Person::players[j]->aitype != attacktypecutoff || abs(Random() % 6) == 0 || (Person::players[j]->animTarget != backhandspringanim && Person::players[j]->animTarget != rollanim && Person::players[j]->animTarget != flipanim && Random() % 2 == 0)) && !missed) { - if ((Person::players[j]->creature == wolftype && Random() % 3 != 0 && Person::players[j]->weaponactive == -1 && (Person::players[j]->isIdle() || Person::players[j]->isRun() || Person::players[j]->animTarget == walkanim)) || - (Person::players[j]->creature == rabbittype && Random() % 2 == 0 && Person::players[j]->aitype == attacktypecutoff && Person::players[j]->weaponactive == -1)) { + if (Person::players[j]->catchKnife()) { emit_sound_at(knifedrawsound, Person::players[j]->coords, 128.); Person::players[j]->animTarget = removeknifeanim; -- 2.39.5