From 65748e01b54fd8c4e1b5dd8de7d99f430d10870c Mon Sep 17 00:00:00 2001 From: =?utf8?q?C=C3=B4me=20Chilliet?= Date: Fri, 25 Nov 2016 13:20:29 +0800 Subject: [PATCH] Refactor of weapon throwing in Weapon class. (named it thrown as throw is reserved keyword) --- Source/GameTick.cpp | 8 +------- Source/Person.cpp | 9 +-------- Source/Weapons.cpp | 7 +++++++ Source/Weapons.h | 1 + 4 files changed, 10 insertions(+), 15 deletions(-) diff --git a/Source/GameTick.cpp b/Source/GameTick.cpp index 4235adc..e156114 100644 --- a/Source/GameTick.cpp +++ b/Source/GameTick.cpp @@ -6550,18 +6550,12 @@ void Game::Tick() Person::players[i]->throwtogglekeydown = 1; Person::players[i]->victim = Person::players[j]; XYZ aim; - weapons[Person::players[i]->weaponids[0]].owner = -1; aim = Person::players[i]->victim->coords + DoRotation(Person::players[i]->victim->jointPos(abdomen), 0, Person::players[i]->victim->yaw, 0) * Person::players[i]->victim->scale + Person::players[i]->victim->velocity * findDistance(&Person::players[i]->victim->coords, &Person::players[i]->coords) / 50 - (Person::players[i]->coords + DoRotation(Person::players[i]->jointPos(righthand), 0, Person::players[i]->yaw, 0) * Person::players[i]->scale); Normalise(&aim); aim = DoRotation(aim, (float)abs(Random() % 30) - 15, (float)abs(Random() % 30) - 15, 0); - weapons[Person::players[i]->weaponids[0]].velocity = aim * 50; - weapons[Person::players[i]->weaponids[0]].tipvelocity = aim * 50; - weapons[Person::players[i]->weaponids[0]].missed = 0; - weapons[Person::players[i]->weaponids[0]].freetime = 0; - weapons[Person::players[i]->weaponids[0]].firstfree = 1; - weapons[Person::players[i]->weaponids[0]].physics = 0; + weapons[Person::players[i]->weaponids[0]].thrown(aim * 50, false); Person::players[i]->num_weapons--; if (Person::players[i]->num_weapons) { Person::players[i]->weaponids[0] = Person::players[i]->weaponids[Person::players[i]->num_weapons]; diff --git a/Source/Person.cpp b/Source/Person.cpp index 81267bc..b1ebde7 100644 --- a/Source/Person.cpp +++ b/Source/Person.cpp @@ -2625,16 +2625,9 @@ void Person::DoAnimations() if (weaponactive != -1) { escapednum = 0; XYZ aim; - weapons[weaponids[0]].owner = -1; 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); Normalise(&aim); - weapons[weaponids[0]].velocity = aim * 50; - weapons[weaponids[0]].tipvelocity = aim * 50; - weapons[weaponids[0]].missed = 0; - weapons[weaponids[0]].hitsomething = 0; - weapons[weaponids[0]].freetime = 0; - weapons[weaponids[0]].firstfree = 1; - weapons[weaponids[0]].physics = 0; + weapons[weaponids[0]].thrown(aim * 50); num_weapons--; if (num_weapons) { weaponids[0] = weaponids[num_weapons]; diff --git a/Source/Weapons.cpp b/Source/Weapons.cpp index 4b7936a..5207997 100644 --- a/Source/Weapons.cpp +++ b/Source/Weapons.cpp @@ -1092,6 +1092,13 @@ void Weapon::drop(XYZ v, XYZ tv, bool sethitsomething) physics = 1; } +void Weapon::thrown(XYZ v, bool sethitsomething) +{ + drop(v, v, sethitsomething); + missed = 0; + physics = 0; +} + int Weapons::Draw() { glAlphaFunc(GL_GREATER, 0.9); diff --git a/Source/Weapons.h b/Source/Weapons.h index 6ed7e00..398530b 100644 --- a/Source/Weapons.h +++ b/Source/Weapons.h @@ -67,6 +67,7 @@ public: void setType(int); void drop(XYZ velocity, XYZ tipvelocity, bool sethitsomething = true); + void thrown(XYZ velocity, bool sethitsomething = true); int owner; XYZ position; -- 2.39.5