stratagus-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Stratagus-CVS] stratagus/src/unit unit.c


From: address@hidden
Subject: [Stratagus-CVS] stratagus/src/unit unit.c
Date: 24 Jan 2004 03:16:45 +1100

CVSROOT:        /home/strat
Module name:    stratagus
Changes by:      <address@hidden>       04/01/24 03:16:45

Modified files:
        src/unit       : unit.c 

Log message:
        Fix unit running away FPE bug.

Patches:
Index: stratagus/src/unit/unit.c
diff -u stratagus/src/unit/unit.c:1.370 stratagus/src/unit/unit.c:1.371
--- stratagus/src/unit/unit.c:1.370     Sat Jan 24 03:00:50 2004
+++ stratagus/src/unit/unit.c   Sat Jan 24 03:16:44 2004
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//      $Id: unit.c,v 1.370 2004/01/23 16:00:50 nobody_ Exp $
+//      $Id: unit.c,v 1.371 2004/01/23 16:16:44 nobody_ Exp $
 
 //@{
 
@@ -3071,7 +3071,7 @@
        //
        //              Attack units in range (which or the attacker?)
        //
-       if (!type->Coward) {
+       if (attacker && !type->Coward) {
                if (type->CanAttack && target->Stats->Speed) {
                        if (RevealAttacker && CanTarget(target->Type, 
attacker->Type)) {
                                // Reveal Unit that is attacking
@@ -3098,11 +3098,15 @@
        if (!type->Building) {
                int x;
                int y;
+               int d;
 
+               DebugLevel3Fn("Unit at %d, %d attacked from %d, %d, running 
away.\n" _C_
+                               target->X _C_ target->Y _C_ attacker->X _C_ 
attacker->Y);
                x = target->X - attacker->X;
                y = target->Y - attacker->Y;
-               x = target->X + (x * 5) / isqrt(x * x + y * y);
-               y = target->Y + (y * 5) / isqrt(x * x + y * y);
+               d = isqrt(x * x + y * y);
+               x = target->X + (x * 5) / d;
+               y = target->Y + (y * 5) / d;
                CommandStopUnit(target);
                CommandMove(target, x + (SyncRand() & 3), y + (SyncRand() & 3), 
0);
        }
@@ -3749,7 +3753,7 @@
        int j;
 
        CLprintf(file, "\n--- -----------------------------------------\n");
-       CLprintf(file, "--- MODULE: units $Id: unit.c,v 1.370 2004/01/23 
16:00:50 nobody_ Exp $\n\n");
+       CLprintf(file, "--- MODULE: units $Id: unit.c,v 1.371 2004/01/23 
16:16:44 nobody_ Exp $\n\n");
 
 #if 0
        //




reply via email to

[Prev in Thread] Current Thread [Next in Thread]