]> git.jsancho.org Git - lugaru.git/blobdiff - Source/Objects/Person.cpp
Added .at usage to have clearer crash when dialogue contains invalid participant
[lugaru.git] / Source / Objects / Person.cpp
index af2f53bfc7b126164002b05c8e7bd0af334dbc62..874194b4a53419537c177aaf15352f9bf65002dd 100644 (file)
@@ -51,7 +51,7 @@ extern float woozy;
 extern float viewdistance;
 extern float blackout;
 extern int difficulty;
-extern bool decals;
+extern bool decalstoggle;
 extern float fadestart;
 extern bool freeze;
 extern bool winfreeze;
@@ -565,8 +565,8 @@ int Person::getIdle()
 {
     if (Dialog::inDialog() && (howactive == typeactive) && (creature == rabbittype))
         return talkidleanim;
-    if (hasvictim && (victim != this->shared_from_this())/*||(id==0&&attackkeydown)*/)
-        if (/*(id==0&&attackkeydown)||*/(!victim->dead && victim->aitype != passivetype &&
+    if (hasvictim && (victim != this->shared_from_this())) {
+        if ((!victim->dead && victim->aitype != passivetype &&
             victim->aitype != searchtype && aitype != passivetype && aitype != searchtype &&
             victim->id < Person::players.size())) {
             if ((aitype == playercontrolled && stunned <= 0 && weaponactive == -1) || pause) {
@@ -588,6 +588,7 @@ int Person::getIdle()
             if (aitype != playercontrolled && stunned <= 0 && creature != wolftype && !pause)
                 return fightsidestep;
         }
+    }
     if ((damage > permanentdamage || damage > damagetolerance * .8 || deathbleeding > 0) && creature != wolftype)
         return hurtidleanim;
     if (howactive == typesitting) return sitanim;
@@ -728,7 +729,7 @@ void Person::DoBlood(float howmuch, int which)
                     }
                 }
         }
-        if (decals) {
+        if (decalstoggle) {
             // FIXME: manipulating attributes
             bleeding = howmuch + (float)abs(Random() % 100) / 200 - .25;
             bleedxint = 0;
@@ -796,7 +797,7 @@ void Person::DoBloodBig(float howmuch, int which)
         Game::flash(.5, 0);
     }
 
-    if (bloodtoggle && decals && !Tutorial::active) {
+    if (bloodtoggle && decalstoggle && !Tutorial::active) {
         if (bleeding <= 0 && spurt) {
             spurt = 0;
             for (int i = 0; i < 3; i++) {
@@ -979,7 +980,7 @@ bool Person::DoBloodBigWhere(float howmuch, int which, XYZ where)
     float coordsx, coordsy;
     float total;
 
-    if (bloodtoggle && decals && !Tutorial::active) {
+    if (bloodtoggle && decalstoggle && !Tutorial::active) {
         where -= coords;
         if (!skeleton.free)
             where = DoRotation(where, 0, -yaw, 0);
@@ -1912,7 +1913,7 @@ void Person::Puff(int whichlabel)
 /* EFFECT
  * I think I added this in an attempt to clean up code
  */
-void Person::setAnimation(int animation)
+void Person::setTargetAnimation(int animation)
 {
     animTarget = animation;
     frameTarget = 0;
@@ -6089,7 +6090,7 @@ int Person::DrawSkeleton()
         }
         static XYZ mid;
         static float M[16];
-        static int i, k;
+        static int k;
         static int weaponattachmuscle;
         static int weaponrotatemuscle;
         static XYZ weaponpoint;
@@ -6129,19 +6130,19 @@ int Person::DrawSkeleton()
                 if (Animation::animations[animTarget].attack == 3)
                     targetheadyaw += 180;
             }
-            for (i = 0; i < skeleton.drawmodel.vertexNum; i++) {
+            for (int i = 0; i < skeleton.drawmodel.vertexNum; i++) {
                 skeleton.drawmodel.vertex[i] = 0;
                 skeleton.drawmodel.vertex[i].y = 999;
             }
-            for (i = 0; i < skeleton.drawmodellow.vertexNum; i++) {
+            for (int i = 0; i < skeleton.drawmodellow.vertexNum; i++) {
                 skeleton.drawmodellow.vertex[i] = 0;
                 skeleton.drawmodellow.vertex[i].y = 999;
             }
-            for (i = 0; i < skeleton.drawmodelclothes.vertexNum; i++) {
+            for (int i = 0; i < skeleton.drawmodelclothes.vertexNum; i++) {
                 skeleton.drawmodelclothes.vertex[i] = 0;
                 skeleton.drawmodelclothes.vertex[i].y = 999;
             }
-            for (unsigned i = 0; i < skeleton.muscles.size(); i++) {
+            for (unsigned int i = 0; i < skeleton.muscles.size(); i++) {
                 // convenience renames
                 const int p1 = skeleton.muscles[i].parent1->label;
                 const int p2 = skeleton.muscles[i].parent2->label;
@@ -6352,16 +6353,17 @@ int Person::DrawSkeleton()
             glDisable(GL_LIGHTING);
             glDisable(GL_TEXTURE_2D);
             glBegin(GL_POINTS);
-            if (playerdetail)
-                for (i = 0; i < skeleton.drawmodel.vertexNum; i++) {
+            if (playerdetail) {
+                for (int i = 0; i < skeleton.drawmodel.vertexNum; i++) {
                     XYZ &v0 = skeleton.drawmodel.vertex[i];
                     glVertex3f(v0.x, v0.y, v0.z);
                 }
+            }
             glEnd();
             glBegin(GL_LINES);
 
-            if (playerdetail)
-                for (i = 0; i < skeleton.drawmodel.TriangleNum; i++) {
+            if (playerdetail) {
+                for (unsigned int i = 0; i < skeleton.drawmodel.Triangles.size(); i++) {
                     XYZ &v0 = skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[i].vertex[0]];
                     XYZ &v1 = skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[i].vertex[1]];
                     XYZ &v2 = skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[i].vertex[2]];
@@ -6372,6 +6374,7 @@ int Person::DrawSkeleton()
                     glVertex3f(v2.x, v2.y, v2.z);
                     glVertex3f(v0.x, v0.y, v0.z);
                 }
+            }
 
             glEnd();
         }
@@ -6483,7 +6486,7 @@ int Person::DrawSkeleton()
 
         if (num_weapons > 0) {
             for (k = 0; k < num_weapons; k++) {
-                i = weaponids[k];
+                int i = weaponids[k];
                 if (weaponactive == k) {
                     if (weapons[i].getType() != staff) {
                         for (unsigned j = 0; j < skeleton.muscles.size(); j++) {
@@ -6721,7 +6724,6 @@ int Person::DrawSkeleton()
  */
 int Person::SphereCheck(XYZ *p1, float radius, XYZ *p, XYZ *move, float *rotate, Model *model)
 {
-    static int i, j;
     static float distance;
     static float olddistance;
     static int intersecting;
@@ -6739,14 +6741,14 @@ int Person::SphereCheck(XYZ *p1, float radius, XYZ *p, XYZ *move, float *rotate,
         return -1;
     if (*rotate)
         *p1 = DoRotation(*p1, 0, -*rotate, 0);
-    for (i = 0; i < 4; i++) {
-        for (j = 0; j < model->TriangleNum; j++) {
-            if (model->facenormals[j].y <= slopethreshold) {
+    for (int i = 0; i < 4; i++) {
+        for (unsigned int j = 0; j < model->Triangles.size(); j++) {
+            if (model->Triangles[j].facenormal.y <= slopethreshold) {
                 intersecting = 0;
-                distance = abs((model->facenormals[j].x * p1->x) + (model->facenormals[j].y * p1->y) + (model->facenormals[j].z * p1->z) - ((model->facenormals[j].x * model->vertex[model->Triangles[j].vertex[0]].x) + (model->facenormals[j].y * model->vertex[model->Triangles[j].vertex[0]].y) + (model->facenormals[j].z * model->vertex[model->Triangles[j].vertex[0]].z)));
+                distance = abs((model->Triangles[j].facenormal.x * p1->x) + (model->Triangles[j].facenormal.y * p1->y) + (model->Triangles[j].facenormal.z * p1->z) - ((model->Triangles[j].facenormal.x * model->vertex[model->Triangles[j].vertex[0]].x) + (model->Triangles[j].facenormal.y * model->vertex[model->Triangles[j].vertex[0]].y) + (model->Triangles[j].facenormal.z * model->vertex[model->Triangles[j].vertex[0]].z)));
                 if (distance < radius) {
-                    point = *p1 - model->facenormals[j] * distance;
-                    if (PointInTriangle( &point, model->facenormals[j], &model->vertex[model->Triangles[j].vertex[0]], &model->vertex[model->Triangles[j].vertex[1]], &model->vertex[model->Triangles[j].vertex[2]]))
+                    point = *p1 - model->Triangles[j].facenormal * distance;
+                    if (PointInTriangle( &point, model->Triangles[j].facenormal, &model->vertex[model->Triangles[j].vertex[0]], &model->vertex[model->Triangles[j].vertex[1]], &model->vertex[model->Triangles[j].vertex[2]]))
                         intersecting = 1;
                     if (!intersecting)
                         intersecting = sphere_line_intersection(&model->vertex[model->Triangles[j].vertex[0]],
@@ -6761,11 +6763,11 @@ int Person::SphereCheck(XYZ *p1, float radius, XYZ *p, XYZ *move, float *rotate,
                                                                 &model->vertex[model->Triangles[j].vertex[2]],
                                                                 p1, &radius);
                     end = *p1 - point;
-                    if (dotproduct(&model->facenormals[j], &end) > 0 && intersecting) {
+                    if (dotproduct(&model->Triangles[j].facenormal, &end) > 0 && intersecting) {
                         start = *p1;
                         end = *p1;
                         end.y -= radius;
-                        if (LineFacetd(&start, &end, &model->vertex[model->Triangles[j].vertex[0]], &model->vertex[model->Triangles[j].vertex[1]], &model->vertex[model->Triangles[j].vertex[2]], &model->facenormals[j], &point)) {
+                        if (LineFacetd(&start, &end, &model->vertex[model->Triangles[j].vertex[0]], &model->vertex[model->Triangles[j].vertex[1]], &model->vertex[model->Triangles[j].vertex[2]], &model->Triangles[j].facenormal, &point)) {
                             p1->y = point.y + radius;
                             if ((animTarget == jumpdownanim || isFlip())) {
                                 if (isFlip() && (frameTarget < 5 || targetFrame().label == 7 || targetFrame().label == 4))
@@ -6805,23 +6807,23 @@ int Person::SphereCheck(XYZ *p1, float radius, XYZ *p, XYZ *move, float *rotate,
                 }
             }
         }
-        for (j = 0; j < model->TriangleNum; j++) {
-            if (model->facenormals[j].y > slopethreshold) {
+        for (unsigned int j = 0; j < model->Triangles.size(); j++) {
+            if (model->Triangles[j].facenormal.y > slopethreshold) {
                 intersecting = 0;
                 start = *p1;
                 start.y -= radius / 4;
                 XYZ &v0 = model->vertex[model->Triangles[j].vertex[0]];
                 XYZ &v1 = model->vertex[model->Triangles[j].vertex[1]];
                 XYZ &v2 = model->vertex[model->Triangles[j].vertex[2]];
-                distance = abs((model->facenormals[j].x * start.x)
-                               + (model->facenormals[j].y * start.y)
-                               + (model->facenormals[j].z * start.z)
-                               - ((model->facenormals[j].x * v0.x)
-                                  + (model->facenormals[j].y * v0.y)
-                                  + (model->facenormals[j].z * v0.z)));
+                distance = abs((model->Triangles[j].facenormal.x * start.x)
+                               + (model->Triangles[j].facenormal.y * start.y)
+                               + (model->Triangles[j].facenormal.z * start.z)
+                               - ((model->Triangles[j].facenormal.x * v0.x)
+                                  + (model->Triangles[j].facenormal.y * v0.y)
+                                  + (model->Triangles[j].facenormal.z * v0.z)));
                 if (distance < radius * .5) {
-                    point = start - model->facenormals[j] * distance;
-                    if (PointInTriangle( &point, model->facenormals[j], &v0, &v1, &v2))
+                    point = start - model->Triangles[j].facenormal * distance;
+                    if (PointInTriangle( &point, model->Triangles[j].facenormal, &v0, &v1, &v2))
                         intersecting = 1;
                     if (!intersecting)
                         intersecting = sphere_line_intersection(v0.x, v0.y, v0.z, v1.x, v1.y, v1.z, p1->x, p1->y, p1->z, radius / 2);
@@ -6830,14 +6832,14 @@ int Person::SphereCheck(XYZ *p1, float radius, XYZ *p, XYZ *move, float *rotate,
                     if (!intersecting)
                         intersecting = sphere_line_intersection(v0.x, v0.y, v0.z, v2.x, v2.y, v2.z, p1->x, p1->y, p1->z, radius / 2);
                     end = *p1 - point;
-                    if (dotproduct(&model->facenormals[j], &end) > 0 && intersecting) {
+                    if (dotproduct(&model->Triangles[j].facenormal, &end) > 0 && intersecting) {
                         if ((animTarget == jumpdownanim || animTarget == jumpupanim || isFlip())) {
                             start = velocity;
-                            velocity -= DoRotation(model->facenormals[j], 0, *rotate, 0) * findLength(&velocity) * abs(normaldotproduct(velocity, DoRotation(model->facenormals[j], 0, *rotate, 0))); //(distance-radius*.5)/multiplier;
+                            velocity -= DoRotation(model->Triangles[j].facenormal, 0, *rotate, 0) * findLength(&velocity) * abs(normaldotproduct(velocity, DoRotation(model->Triangles[j].facenormal, 0, *rotate, 0))); //(distance-radius*.5)/multiplier;
                             if (findLengthfast(&start) < findLengthfast(&velocity))
                                 velocity = start;
                         }
-                        *p1 += model->facenormals[j] * (distance - radius * .5);
+                        *p1 += model->Triangles[j].facenormal * (distance - radius * .5);
                     }
                 }
                 if ((distance < olddistance || firstintersecting == -1) && intersecting) {
@@ -7237,7 +7239,7 @@ void Person::doAI()
 
                 if (aitype != passivetype) {
                     if (howactive == typesleeping)
-                        setAnimation(getupfromfrontanim);
+                        setTargetAnimation(getupfromfrontanim);
                     howactive = typeactive;
                 }
             }
@@ -7343,7 +7345,7 @@ void Person::doAI()
                         j = Object::checkcollide(test2, test);
                     if (j == -1) {
                         velocity = 0;
-                        setAnimation(getStop());
+                        setTargetAnimation(getStop());
                         targetyaw += 180;
                         stunned = .5;
                         //aitype=passivetype;
@@ -7658,15 +7660,17 @@ void Person::doAI()
                     if (Person::players[0]->animTarget != rabbitkickanim && Person::players[0]->weaponactive != -1) {
                         if (weapons[Person::players[0]->weaponids[0]].getType() == knife) {
                             if (isIdle() || isCrouch() || isRun() || isFlip()) {
-                                if (abs(Random() % 2) == 0)
-                                    setAnimation(backhandspringanim);
-                                else
-                                    setAnimation(rollanim);
+                                if (abs(Random() % 2) == 0) {
+                                    setTargetAnimation(backhandspringanim);
+                                } else {
+                                    setTargetAnimation(rollanim);
+                                }
                                 targetyaw += 90 * (abs(Random() % 2) * 2 - 1);
                                 wentforweapon = 0;
                             }
-                            if (animTarget == jumpupanim || animTarget == jumpdownanim)
-                                setAnimation(flipanim);
+                            if (animTarget == jumpupanim || animTarget == jumpdownanim) {
+                                setTargetAnimation(flipanim);
+                            }
                         }
                     }
                     forwardkeydown = 0;
@@ -7721,7 +7725,7 @@ void Person::doAI()
                         j = Object::checkcollide(test2, test);
                     if (j == -1) {
                         velocity = 0;
-                        setAnimation(getStop());
+                        setTargetAnimation(getStop());
                         targetyaw += 180;
                         stunned = .5;
                         aitype = pathfindtype;