]> git.jsancho.org Git - lugaru.git/commitdiff
Refactor of weapon throwing in Weapon class. (named it thrown as throw is reserved...
authorCôme Chilliet <come@chilliet.eu>
Fri, 25 Nov 2016 05:20:29 +0000 (13:20 +0800)
committerCôme Chilliet <come@chilliet.eu>
Fri, 25 Nov 2016 07:43:24 +0000 (15:43 +0800)
Source/GameTick.cpp
Source/Person.cpp
Source/Weapons.cpp
Source/Weapons.h

index 4235adc5630cc425e42c0808c41c33bb36fac4f2..e1561147e3fd65a1a3b78709889681044d8190ed 100644 (file)
@@ -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];
index 81267bcc93355f1b446e145ae1e330fd8658729e..b1ebde7a0f9a0eb1fdbd745a36aeaf712da674a6 100644 (file)
@@ -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];
index 4b7936ae94ba75a5013346487cc98e04abe8f8df..5207997b005a07629198a69f4167c2ee9ddf1044 100644 (file)
@@ -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);
index 6ed7e002171f99cc57cf8c3c3378f75206eb9471..398530b75bd36b61da2193bc499191a8866d98fa 100644 (file)
@@ -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;