]> git.jsancho.org Git - lugaru.git/blobdiff - Source/Weapons.cpp
Refactor of weapon throwing in Weapon class. (named it thrown as throw is reserved...
[lugaru.git] / Source / Weapons.cpp
index 1c66d4bc627be73950cdf933b96d026905f161b8..5207997b005a07629198a69f4167c2ee9ddf1044 100644 (file)
@@ -1,22 +1,23 @@
 /*
 Copyright (C) 2003, 2010 - Wolfire Games
+Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file)
 
 This file is part of Lugaru.
 
-Lugaru is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-as published by the Free Software Foundation; either version 2
-of the License, or (at your option) any later version.
+This file is part of Lugaru.
 
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+Lugaru is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
 
-See the GNU General Public License for more details.
+Lugaru is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+along with Lugaru.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 /**> HEADER FILES <**/
@@ -42,7 +43,6 @@ extern float texdetail;
 extern GLubyte bloodText[512 * 512 * 3];
 extern int bloodtoggle;
 extern Objects objects;
-extern bool osx;
 extern bool autoslomo;
 extern float camerashake;
 extern float woozy;
@@ -214,12 +214,12 @@ void Weapon::DoStuff(int i)
         }
 
         if (velocity.x || velocity.y || velocity.z) {
-            for (int j = 0; j < numplayers; j++) {
+            for (unsigned j = 0; j < Person::players.size(); j++) {
                 footvel = 0;
                 footpoint = DoRotation((Person::players[j]->jointPos(abdomen) + Person::players[j]->jointPos(neck)) / 2, 0, Person::players[j]->yaw, 0) * Person::players[j]->scale + Person::players[j]->coords;
                 if (owner == -1 && distsqflat(&position, &Person::players[j]->coords) < 1.5 &&
                         distsq(&position, &Person::players[j]->coords) < 4 && Person::players[j]->weaponstuck == -1 &&
-                        !Person::players[j]->skeleton.free && j != oldowner) {
+                        !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)) {
@@ -1078,6 +1078,27 @@ void Weapon::Draw()
     }
 }
 
+void Weapon::drop(XYZ v, XYZ tv, bool sethitsomething)
+{
+    owner = -1;
+    velocity = v;
+    tipvelocity = tv;
+    missed = 1;
+    if (sethitsomething) {
+        hitsomething = 0;
+    }
+    freetime = 0;
+    firstfree = 1;
+    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);