]> git.jsancho.org Git - lugaru.git/blobdiff - Source/Objects/Weapons.cpp
Removed unused defines, changed method names case
[lugaru.git] / Source / Objects / Weapons.cpp
index a6a1786736897d38e198661869c2fe09fa9d148d..1cd4cea3f93c21ed6f77eac182afbc06b9354226 100644 (file)
@@ -27,6 +27,7 @@ along with Lugaru.  If not, see <http://www.gnu.org/licenses/>.
 #include "Audio/Sounds.hpp"
 #include "Game.hpp"
 #include "Level/Awards.hpp"
+#include "Tutorial.hpp"
 
 extern float multiplier;
 extern Terrain terrain;
@@ -42,14 +43,12 @@ extern bool cellophane;
 extern float texdetail;
 extern GLubyte bloodText[512 * 512 * 3];
 extern int bloodtoggle;
-extern Objects objects;
 extern bool autoslomo;
 extern float camerashake;
 extern float woozy;
 extern float viewdistance;
 extern float blackout;
 extern bool freeze;
-extern int tutoriallevel;
 extern int numthrowkill;
 
 Model Weapon::throwingknifemodel;
@@ -98,7 +97,44 @@ void Weapon::setType(int t)
     }
 }
 
-void Weapon::DoStuff(int i)
+/* Load weapons models and textures */
+void Weapon::Load()
+{
+    LOG("Loading weapon data...");
+
+    knifetextureptr.load("Textures/Knife.png", 0);
+    bloodknifetextureptr.load("Textures/BloodKnife.png", 0);
+    lightbloodknifetextureptr.load("Textures/BloodKnifeLight.png", 0);
+    swordtextureptr.load("Textures/Sword.jpg", 1);
+    bloodswordtextureptr.load("Textures/SwordBlood.jpg", 1);
+    lightbloodswordtextureptr.load("Textures/SwordBloodLight.jpg", 1);
+    stafftextureptr.load("Textures/Staff.jpg", 1);
+
+    throwingknifemodel.load("Models/ThrowingKnife.solid");
+    throwingknifemodel.Scale(.001, .001, .001);
+    throwingknifemodel.Rotate(90, 0, 0);
+    throwingknifemodel.Rotate(0, 90, 0);
+    throwingknifemodel.flat = 0;
+    throwingknifemodel.CalculateNormals(1);
+
+    swordmodel.load("Models/Sword.solid");
+    swordmodel.Scale(.001, .001, .001);
+    swordmodel.Rotate(90, 0, 0);
+    swordmodel.Rotate(0, 90, 0);
+    swordmodel.Rotate(0, 0, 90);
+    swordmodel.flat = 1;
+    swordmodel.CalculateNormals(1);
+
+    staffmodel.load("Models/Staff.solid");
+    staffmodel.Scale(.005, .005, .005);
+    staffmodel.Rotate(90, 0, 0);
+    staffmodel.Rotate(0, 90, 0);
+    staffmodel.Rotate(0, 0, 90);
+    staffmodel.flat = 1;
+    staffmodel.CalculateNormals(1);
+}
+
+void Weapon::doStuff(int i)
 {
     static int whichpatchx, whichpatchz, whichhit;
     static XYZ start, end, colpoint, normalrot, footvel, footpoint;
@@ -158,16 +194,16 @@ void Weapon::DoStuff(int i)
         whichpatchx = position.x / (terrain.size / subdivision * terrain.scale);
         whichpatchz = position.z / (terrain.size / subdivision * terrain.scale);
         if (whichpatchx > 0 && whichpatchz > 0 && whichpatchx < subdivision && whichpatchz < subdivision) {
-            if (terrain.patchobjectnum[whichpatchx][whichpatchz]) { // if there are objects where the weapon is
+            if (terrain.patchobjectnum[whichpatchx][whichpatchz]) { // if there are Object::objects where the weapon is
                 for (int j = 0; j < terrain.patchobjectnum[whichpatchx][whichpatchz]; j++) { // check for collision
                     int k = terrain.patchobjects[whichpatchx][whichpatchz][j];
                     start = oldtippoint;
                     end = tippoint;
-                    whichhit = objects.model[k].LineCheck(&start, &end, &colpoint, &objects.position[k], &objects.yaw[k]);
+                    whichhit = Object::objects[k]->model.LineCheck(&start, &end, &colpoint, &Object::objects[k]->position, &Object::objects[k]->yaw);
                     if (whichhit != -1) {
-                        if (objects.type[k] == treetrunktype) {
-                            objects.model[k].MakeDecal(breakdecal, DoRotation(colpoint - objects.position[k], 0, -objects.yaw[k], 0), .1, 1, Random() % 360);
-                            normalrot = DoRotation(objects.model[k].facenormals[whichhit], 0, objects.yaw[k], 0);
+                        if (Object::objects[k]->type == treetrunktype) {
+                            Object::objects[k]->model.MakeDecal(breakdecal, DoRotation(colpoint - Object::objects[k]->position, 0, -Object::objects[k]->yaw, 0), .1, 1, Random() % 360);
+                            normalrot = DoRotation(Object::objects[k]->model.Triangles[whichhit].facenormal, 0, Object::objects[k]->yaw, 0);
                             velocity = 0;
                             if (type == knife)
                                 position = colpoint - normalrot * .1;
@@ -249,16 +285,16 @@ void Weapon::DoStuff(int i)
                             Person::players[j]->jointVel(neck) += velocity * 2;
                             Person::players[j]->jointVel(rightshoulder) += velocity * 2;
                             Person::players[j]->jointVel(leftshoulder) += velocity * 2;
-                            if (bloodtoggle && tutoriallevel != 1)
+                            if (bloodtoggle && !Tutorial::active)
                                 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .8, .3);
-                            if (tutoriallevel == 1)
+                            if (Tutorial::active)
                                 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 1, 1, .8, .3);
                             footvel = tippoint - position;
                             Normalise(&footvel);
-                            if (bloodtoggle && tutoriallevel != 1)
+                            if (bloodtoggle && !Tutorial::active)
                                 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * -1, 1, 0, 0, .6, 1);
 
-                            if (tutoriallevel != 1) {
+                            if (!Tutorial::active) {
                                 if (Person::players[j]->weaponstuckwhere == 0)
                                     Person::players[j]->DoBloodBig(2, 205);
                                 if (Person::players[j]->weaponstuckwhere == 1)
@@ -416,7 +452,7 @@ void Weapon::DoStuff(int i)
                             if (type == staff) {
                                 start = tippoint - (position - tippoint) / 5;
                                 end = position + (position - tippoint) / 30;
-                                whichhit = objects.model[k].LineCheck(&start, &end, &colpoint, &objects.position[k], &objects.yaw[k]);
+                                whichhit = Object::objects[k]->model.LineCheck(&start, &end, &colpoint, &Object::objects[k]->position, &Object::objects[k]->yaw);
                                 if (whichhit != -1) {
                                     XYZ diff;
                                     diff = (colpoint - position);
@@ -431,7 +467,7 @@ void Weapon::DoStuff(int i)
                             } else {
                                 start = position - (tippoint - position) / 5;
                                 end = tippoint + (tippoint - position) / 30;
-                                whichhit = objects.model[k].LineCheck(&start, &end, &colpoint, &objects.position[k], &objects.yaw[k]);
+                                whichhit = Object::objects[k]->model.LineCheck(&start, &end, &colpoint, &Object::objects[k]->position, &Object::objects[k]->yaw);
                                 if (whichhit != -1) {
                                     XYZ diff;
                                     diff = (colpoint - tippoint);
@@ -448,11 +484,11 @@ void Weapon::DoStuff(int i)
 
                         start = oldposition;
                         end = position;
-                        whichhit = objects.model[k].LineCheck(&start, &end, &colpoint, &objects.position[k], &objects.yaw[k]);
+                        whichhit = Object::objects[k]->model.LineCheck(&start, &end, &colpoint, &Object::objects[k]->position, &Object::objects[k]->yaw);
                         if (whichhit != -1) {
                             hitsomething = 1;
                             position = colpoint;
-                            terrainnormal = DoRotation(objects.model[k].facenormals[whichhit], 0, objects.yaw[k], 0) * -1;
+                            terrainnormal = DoRotation(Object::objects[k]->model.Triangles[whichhit].facenormal, 0, Object::objects[k]->yaw, 0) * -1;
                             ReflectVector(&velocity, &terrainnormal);
                             position += terrainnormal * .002;
 
@@ -478,11 +514,11 @@ void Weapon::DoStuff(int i)
                         }
                         start = oldtippoint;
                         end = tippoint;
-                        whichhit = objects.model[k].LineCheck(&start, &end, &colpoint, &objects.position[k], &objects.yaw[k]);
+                        whichhit = Object::objects[k]->model.LineCheck(&start, &end, &colpoint, &Object::objects[k]->position, &Object::objects[k]->yaw);
                         if (whichhit != -1) {
                             hitsomething = 1;
                             tippoint = colpoint;
-                            terrainnormal = DoRotation(objects.model[k].facenormals[whichhit], 0, objects.yaw[k], 0) * -1;
+                            terrainnormal = DoRotation(Object::objects[k]->model.Triangles[whichhit].facenormal, 0, Object::objects[k]->yaw, 0) * -1;
                             ReflectVector(&tipvelocity, &terrainnormal);
                             tippoint += terrainnormal * .002;
 
@@ -507,7 +543,7 @@ void Weapon::DoStuff(int i)
                             }
                         }
 
-                        if ((objects.type[k] != boxtype && objects.type[k] != platformtype && objects.type[k] != walltype && objects.type[k] != weirdtype) || objects.pitch[k] != 0)
+                        if ((Object::objects[k]->type != boxtype && Object::objects[k]->type != platformtype && Object::objects[k]->type != walltype && Object::objects[k]->type != weirdtype) || Object::objects[k]->pitch != 0)
                             for (int m = 0; m < 2; m++) {
                                 mid = (position * (21 + (float)m * 10) + tippoint * (19 - (float)m * 10)) / 40;
                                 oldmid2 = mid;
@@ -515,11 +551,11 @@ void Weapon::DoStuff(int i)
 
                                 start = oldmid;
                                 end = mid;
-                                whichhit = objects.model[k].LineCheck(&start, &end, &colpoint, &objects.position[k], &objects.yaw[k]);
+                                whichhit = Object::objects[k]->model.LineCheck(&start, &end, &colpoint, &Object::objects[k]->position, &Object::objects[k]->yaw);
                                 if (whichhit != -1) {
                                     hitsomething = 1;
                                     mid = colpoint;
-                                    terrainnormal = DoRotation(objects.model[k].facenormals[whichhit], 0, objects.yaw[k], 0) * -1;
+                                    terrainnormal = DoRotation(Object::objects[k]->model.Triangles[whichhit].facenormal, 0, Object::objects[k]->yaw, 0) * -1;
                                     ReflectVector(&velocity, &terrainnormal);
 
                                     bounceness = terrainnormal * findLength(&velocity) * (abs(normaldotproduct(velocity, terrainnormal)));
@@ -550,11 +586,11 @@ void Weapon::DoStuff(int i)
 
                                 start = oldmid;
                                 end = mid;
-                                whichhit = objects.model[k].LineCheck(&start, &end, &colpoint, &objects.position[k], &objects.yaw[k]);
+                                whichhit = Object::objects[k]->model.LineCheck(&start, &end, &colpoint, &Object::objects[k]->position, &Object::objects[k]->yaw);
                                 if (whichhit != -1) {
                                     hitsomething = 1;
                                     mid = colpoint;
-                                    terrainnormal = DoRotation(objects.model[k].facenormals[whichhit], 0, objects.yaw[k], 0) * -1;
+                                    terrainnormal = DoRotation(Object::objects[k]->model.Triangles[whichhit].facenormal, 0, Object::objects[k]->yaw, 0) * -1;
                                     ReflectVector(&tipvelocity, &terrainnormal);
 
                                     bounceness = terrainnormal * findLength(&tipvelocity) * (abs(normaldotproduct(tipvelocity, terrainnormal)));
@@ -582,14 +618,14 @@ void Weapon::DoStuff(int i)
                         else {
                             start = position;
                             end = tippoint;
-                            whichhit = objects.model[k].LineCheck(&start, &end, &colpoint, &objects.position[k], &objects.yaw[k]);
+                            whichhit = Object::objects[k]->model.LineCheck(&start, &end, &colpoint, &Object::objects[k]->position, &Object::objects[k]->yaw);
                             if (whichhit != -1) {
                                 hitsomething = 1;
                                 closestdistance = -1;
                                 closestswordpoint = colpoint; //(position+tippoint)/2;
-                                point[0] = DoRotation(objects.model[k].vertex[objects.model[k].Triangles[whichhit].vertex[0]], 0, objects.yaw[k], 0) + objects.position[k];
-                                point[1] = DoRotation(objects.model[k].vertex[objects.model[k].Triangles[whichhit].vertex[1]], 0, objects.yaw[k], 0) + objects.position[k];
-                                point[2] = DoRotation(objects.model[k].vertex[objects.model[k].Triangles[whichhit].vertex[2]], 0, objects.yaw[k], 0) + objects.position[k];
+                                point[0] = DoRotation(Object::objects[k]->model.vertex[Object::objects[k]->model.Triangles[whichhit].vertex[0]], 0, Object::objects[k]->yaw, 0) + Object::objects[k]->position;
+                                point[1] = DoRotation(Object::objects[k]->model.vertex[Object::objects[k]->model.Triangles[whichhit].vertex[1]], 0, Object::objects[k]->yaw, 0) + Object::objects[k]->position;
+                                point[2] = DoRotation(Object::objects[k]->model.vertex[Object::objects[k]->model.Triangles[whichhit].vertex[2]], 0, Object::objects[k]->yaw, 0) + Object::objects[k]->position;
                                 if (DistancePointLine(&closestswordpoint, &point[0], &point[1], &distance, &colpoint )) {
                                     if (distance < closestdistance || closestdistance == -1) {
                                         closestpoint = colpoint;
@@ -921,11 +957,11 @@ void Weapons::DoStuff()
     //Move
     int i = 0;
     for (std::vector<Weapon>::iterator weapon = begin(); weapon != end(); ++weapon) {
-        weapon->DoStuff(i++);
+        weapon->doStuff(i++);
     }
 }
 
-void Weapon::Draw()
+void Weapon::draw()
 {
     static XYZ terrainlight;
     static GLfloat M[16];
@@ -1104,7 +1140,7 @@ int Weapons::Draw()
     glDepthMask(1);
 
     for (std::vector<Weapon>::iterator weapon = begin(); weapon != end(); ++weapon) {
-        weapon->Draw();
+        weapon->draw();
     }
     return 0;
 }
@@ -1112,15 +1148,3 @@ int Weapons::Draw()
 Weapons::Weapons()
 {
 }
-
-Weapons::~Weapons()
-{
-    Weapon::stafftextureptr.destroy();
-    Weapon::knifetextureptr.destroy();
-    Weapon::lightbloodknifetextureptr.destroy();
-    Weapon::bloodknifetextureptr.destroy();
-    Weapon::swordtextureptr.destroy();
-    Weapon::lightbloodswordtextureptr.destroy();
-    Weapon::bloodswordtextureptr.destroy();
-}
-