]> git.jsancho.org Git - lugaru.git/commitdiff
Refactored weapon taking in Person::takeWeapon
authorCôme Chilliet <come@chilliet.eu>
Fri, 25 Nov 2016 05:41:54 +0000 (13:41 +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/Person.h
Source/Weapons.cpp

index e1561147e3fd65a1a3b78709889681044d8190ed..4da057ed2b74006d4444487bd1c2e1db793b06d9 100644 (file)
@@ -6370,12 +6370,7 @@ void Game::Tick()
                                                             if (weapons[j].getType() != staff)
                                                                 emit_sound_at(knifedrawsound, Person::players[i]->coords, 128.);
 
-                                                            Person::players[i]->weaponactive = 0;
-                                                            weapons[j].owner = Person::players[i]->id;
-                                                            if (Person::players[i]->num_weapons > 0)
-                                                                Person::players[i]->weaponids[Person::players[i]->num_weapons] = Person::players[i]->weaponids[0];
-                                                            Person::players[i]->num_weapons++;
-                                                            Person::players[i]->weaponids[0] = j;
+                                                            Person::players[i]->takeWeapon(j);
                                                         }
                                             }
                                         } else if ((Person::players[i]->isIdle() ||
@@ -6404,12 +6399,7 @@ void Game::Tick()
                                                                 if (weapons[k].getType() != staff)
                                                                     emit_sound_at(knifedrawsound, Person::players[i]->coords, 128.);
 
-                                                                Person::players[i]->weaponactive = 0;
-                                                                weapons[k].owner = Person::players[i]->id;
-                                                                if (Person::players[i]->num_weapons > 0)
-                                                                    Person::players[i]->weaponids[Person::players[i]->num_weapons] = Person::players[i]->weaponids[0];
-                                                                Person::players[i]->num_weapons++;
-                                                                Person::players[i]->weaponids[0] = k;
+                                                                Person::players[i]->takeWeapon(k);
                                                             }
                                                 }
                                             }
@@ -6461,7 +6451,6 @@ void Game::Tick()
                                                             if (fleshstuck)
                                                                 emit_sound_at(fleshstabremovesound, Person::players[i]->coords, 128.);
 
-                                                            Person::players[i]->weaponactive = 0;
                                                             if (weapons[k].owner != -1) {
                                                                 if (Person::players[i]->victim->num_weapons == 1)
                                                                     Person::players[i]->victim->num_weapons = 0;
@@ -6509,12 +6498,7 @@ void Game::Tick()
                                                                 Person::players[i]->victim->jointVel(rightshoulder) += relative * 6;
                                                                 Person::players[i]->victim->jointVel(leftshoulder) += relative * 6;
                                                             }
-                                                            weapons[k].owner = i;
-                                                            if (Person::players[i]->num_weapons > 0) {
-                                                                Person::players[i]->weaponids[Person::players[i]->num_weapons] = Person::players[i]->weaponids[0];
-                                                            }
-                                                            Person::players[i]->num_weapons++;
-                                                            Person::players[i]->weaponids[0] = k;
+                                                            Person::players[i]->takeWeapon(k);
                                                         }
                                                     }
                                                 }
index b1ebde7a0f9a0eb1fdbd745a36aeaf712da674a6..3e0f52807d6cbbc60397baa42a0fec7d1da92368 100644 (file)
@@ -1857,13 +1857,7 @@ void Person::DoAnimations()
                                     emit_sound_at(knifedrawsound, coords, 128.);
                                 }
 
-                                weaponactive = 0;
-                                weapons[i].owner = id;
-                                if (num_weapons > 0) {
-                                    weaponids[num_weapons] = weaponids[0];
-                                }
-                                num_weapons++;
-                                weaponids[0] = i;
+                                takeWeapon(i);
                             }
                         }
                 }
@@ -1894,9 +1888,7 @@ void Person::DoAnimations()
                                         emit_sound_at(knifedrawsound, coords, 128.);
                                     }
                                 }
-                                weaponactive = 0;
                                 if (weapons[i].owner != -1) {
-
                                     victim = Person::players[weapons[i].owner];
                                     if (victim->num_weapons == 1)
                                         victim->num_weapons = 0;
@@ -1941,12 +1933,7 @@ void Person::DoAnimations()
                                     victim->jointVel(rightshoulder) += relative * 6;
                                     victim->jointVel(leftshoulder) += relative * 6;
                                 }
-                                weapons[i].owner = id;
-                                if (num_weapons > 0) {
-                                    weaponids[num_weapons] = weaponids[0];
-                                }
-                                num_weapons++;
-                                weaponids[0] = i;
+                                takeWeapon(i);
                             }
                         }
                 }
@@ -3060,13 +3047,7 @@ void Person::DoAnimations()
                 if ((animTarget == swordslashreversalanim || animTarget == knifeslashreversalanim || animTarget == staffhitreversalanim || animTarget == staffspinhitreversalanim) && animation[animTarget].label[frameCurrent] == 5) {
                     if (victim->weaponactive != -1 && victim->num_weapons > 0) {
                         if (weapons[victim->weaponids[victim->weaponactive]].owner == int(victim->id)) {
-                            weapons[victim->weaponids[victim->weaponactive]].owner = id;
-                            weaponactive = 0;
-                            if (num_weapons > 0) {
-                                weaponids[num_weapons] = weaponids[victim->weaponactive];
-                            }
-                            num_weapons++;
-                            weaponids[0] = victim->weaponids[victim->weaponactive];
+                            takeWeapon(victim->weaponids[victim->weaponactive]);
                             victim->num_weapons--;
                             if (victim->num_weapons > 0) {
                                 victim->weaponids[victim->weaponactive] = victim->weaponids[victim->num_weapons];
@@ -6591,3 +6572,14 @@ int Person::SphereCheck(XYZ *p1, float radius, XYZ *p, XYZ *move, float *rotate,
     return firstintersecting;
 }
 
+void Person::takeWeapon(int weaponId)
+{
+    weaponactive = 0;
+    weapons[weaponId].owner = id;
+    if (num_weapons > 0) {
+        weaponids[num_weapons] = weaponids[0];
+    }
+    num_weapons++;
+    weaponids[0] = weaponId;
+}
+
index 9f5e7298b898116cac45c6a42a35c282ad105e6d..235f14d624f335dffa3ef722e2208e8342e5efe9 100644 (file)
@@ -393,6 +393,8 @@ public:
     void setAnimation(int);
     void DoAnimations();
     void RagDoll(bool checkcollision);
+
+    void takeWeapon (int weaponId);
 };
 
 const int maxplayers = 10;
index 5207997b005a07629198a69f4167c2ee9ddf1044..d876320c51b3608227d6413331d0ac57084da166 100644 (file)
@@ -225,16 +225,10 @@ void Weapon::DoStuff(int i)
                                 (Person::players[j]->creature == rabbittype && Random() % 2 == 0 && Person::players[j]->aitype == attacktypecutoff && Person::players[j]->weaponactive == -1)) {
                             emit_sound_at(knifedrawsound, Person::players[j]->coords, 128.);
 
-                            Person::players[j]->weaponactive = 0;
                             Person::players[j]->animTarget = removeknifeanim;
                             Person::players[j]->frameTarget = 1;
                             Person::players[j]->target = 1;
-                            owner = Person::players[j]->id;
-                            if (Person::players[j]->num_weapons > 0) {
-                                Person::players[j]->weaponids[Person::players[j]->num_weapons] = Person::players[j]->weaponids[0];
-                            }
-                            Person::players[j]->num_weapons++;
-                            Person::players[j]->weaponids[0] = i;
+                            Person::players[j]->takeWeapon(i);
 
                             Person::players[j]->aitype = attacktypecutoff;
                         } else {