stratagus-cvs
[Top][All Lists]
Advanced

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

[Stratagus-CVS] stratagus doc/ChangeLog.html src/action/action_...


From: Crestez Leonard
Subject: [Stratagus-CVS] stratagus doc/ChangeLog.html src/action/action_...
Date: Sun, 09 Nov 2003 17:13:59 -0500

CVSROOT:        /cvsroot/stratagus
Module name:    stratagus
Branch:         
Changes by:     Crestez Leonard <address@hidden>        03/11/09 17:13:58

Modified files:
        doc            : ChangeLog.html 
        src/action     : action_attack.c action_board.c action_build.c 
                         action_follow.c action_move.c action_repair.c 
                         action_resource.c action_returngoods.c 
                         action_spellcast.c action_still.c 
                         action_train.c action_unload.c actions.c 
                         command.c 
        src/ai         : ai_force.c ai_local.h ai_plan.c 
        src/clone      : spells.c unit.c 
        src/include    : actions.h unit.h unittype.h 
        src/map        : map.c 
        src/missile    : missile.c 

Log message:
        Major clean-up in checking goals that disappear and unit reference 
counting
        Fixed Bug #5992. I bet I added a lot of brand new ones.

Patches:
Index: stratagus/doc/ChangeLog.html
diff -u stratagus/doc/ChangeLog.html:1.570 stratagus/doc/ChangeLog.html:1.571
--- stratagus/doc/ChangeLog.html:1.570  Sun Nov  9 16:19:11 2003
+++ stratagus/doc/ChangeLog.html        Sun Nov  9 17:13:56 2003
@@ -2,7 +2,7 @@
 <html>
 <head>
 <!--
-----   $Id: ChangeLog.html,v 1.570 2003/11/09 21:19:11 mr-russ Exp $
+----   $Id: ChangeLog.html,v 1.571 2003/11/09 22:13:56 n0body Exp $
 
 ----   (c) Copyright 1998-2003 by Lutz Sammer
 
@@ -36,6 +36,8 @@
 <li>Future 2.00 Release<p>
     <ul>
     <li>++
+    <li>Major clean-up in checking goals that disappear and unit reference 
counting (from Crestez Leonard).
+    <li>Fixed Bug #5992: Little undesirable effects with invisibility and 
flameShield spell (from Crestez Leonard).
     <li>Fixed Bug #6443: Can't Load Selections from Save Game (from Russell 
Smith).
     <li>Fixed Bug #6301: Fog of War problem after using Holy Vision (from 
Russell Smith).
     <li>Fixed Bug #6306: DebugCheck at src/clone/unit_draw.c:895 (from Russell 
Smith).
Index: stratagus/src/action/action_attack.c
diff -u stratagus/src/action/action_attack.c:1.88 
stratagus/src/action/action_attack.c:1.89
--- stratagus/src/action/action_attack.c:1.88   Fri Oct 17 02:04:28 2003
+++ stratagus/src/action/action_attack.c        Sun Nov  9 17:13:56 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: action_attack.c,v 1.88 2003/10/17 06:04:28 mr-russ Exp $
+//     $Id: action_attack.c,v 1.89 2003/11/09 22:13:56 n0body Exp $
 
 //@{
 
@@ -122,7 +122,7 @@
     // Do we have a goal?
     //
     if ((goal = unit->Orders[0].Goal)) {
-       if (goal->Destroyed) {
+       if (GoalGone(unit, goal)) {
            //
            //  Goal is destroyed
            //
@@ -131,29 +131,14 @@
            unit->Orders[0].MinRange = 0;
            unit->Orders[0].Range = 0;
 
-           DebugLevel0Fn("destroyed unit %d\n" _C_ UnitNumber(goal));
-           RefsDebugCheck(!goal->Refs);
-           if (!--goal->Refs) {
-               ReleaseUnit(goal);
-           }
-
-           unit->Orders[0].Goal = goal = NoUnitP;
-       } else if (!goal->HP || goal->Orders[0].Action == UnitActionDie ||
-               goal->Removed) {
-           //
-           //  Goal is unusable, dies or has entered a building.
-           //
-           unit->Orders[0].X = goal->X + goal->Type->TileWidth / 2;
-           unit->Orders[0].Y = goal->Y + goal->Type->TileHeight / 2;
-           unit->Orders[0].MinRange = 0;
-           unit->Orders[0].Range = 0;
-
-           RefsDebugCheck(!goal->Refs);
-           --goal->Refs;
-           RefsDebugCheck(!goal->Refs);
+           DebugLevel0Fn("attack target %d(%s) gone for %d(%s)\n" _C_
+                   UnitNumber(goal) _C_ goal->Type->Name _C_
+                   UnitNumber(unit) _C_ unit->Type->Name);
+           RefsDecrease(goal);
 
            unit->Orders[0].Goal = goal = NoUnitP;
        }
+
        if (!goal) {
            //
            //  If we have a saved order continue this saved order.
@@ -209,8 +194,7 @@
                DebugCheck(unit->Orders[0].Goal);
                unit->SavedOrder = unit->Orders[0];
            }
-           RefsDebugCheck(goal->Destroyed || !goal->Refs);
-           goal->Refs++;
+           RefsIncrease(goal);
            unit->Orders[0].Goal = goal;
            unit->Orders[0].MinRange = unit->Type->MinAttackRange;
            unit->Orders[0].Range = unit->Stats->AttackRange;
@@ -227,11 +211,8 @@
     } else if (goal && (unit->SubAction & WEAK_TARGET)) {
        temp = AttackUnitsInReactRange(unit);
        if (temp && temp->Type->Priority > goal->Type->Priority) {
-           RefsDebugCheck(!goal->Refs);
-           goal->Refs--;
-           RefsDebugCheck(!goal->Refs);
-           RefsDebugCheck(temp->Destroyed || !temp->Refs);
-           temp->Refs++;
+           RefsDecrease(goal);
+           RefsIncrease(temp);
            if (unit->SavedOrder.Action == UnitActionStill) {
                // Save current command to come back.
                unit->SavedOrder = unit->Orders[0];
@@ -358,9 +339,7 @@
        unit->State = unit->SubAction = 0;
        DebugLevel3Fn("Returning to old task.\n");
        if (unit->Orders[0].Goal) {
-           RefsDebugCheck(!unit->Orders[0].Goal->Refs);
-           unit->Orders[0].Goal->Refs--;
-           RefsDebugCheck(!unit->Orders[0].Goal->Refs);
+           RefsDecrease(unit->Orders->Goal);
        }
        unit->Orders[0] = unit->SavedOrder;
        NewResetPath(unit);
@@ -465,8 +444,7 @@
                }
            }
 
-           RefsDebugCheck(goal->Destroyed || !goal->Refs);
-           goal->Refs++;
+           RefsIncrease(goal);
            DebugLevel3Fn("%d Unit in react range %d\n" _C_
                UnitNumber(unit) _C_ UnitNumber(goal));
            unit->Orders[0].Goal = goal;
@@ -483,11 +461,8 @@
        } else if (goal && (unit->SubAction & WEAK_TARGET)) {
            temp = AttackUnitsInReactRange(unit);
            if (temp && temp->Type->Priority > goal->Type->Priority) {
-               RefsDebugCheck(!goal->Refs);
-               goal->Refs--;
-               RefsDebugCheck(!goal->Refs);
-               RefsDebugCheck(temp->Destroyed || !temp->Refs);
-               temp->Refs++;
+               RefsDecrease(goal);
+               RefsIncrease(temp);
 
                if (unit->SavedOrder.Action == UnitActionStill) {
                    // Save current order to come back or to continue it.
Index: stratagus/src/action/action_board.c
diff -u stratagus/src/action/action_board.c:1.43 
stratagus/src/action/action_board.c:1.44
--- stratagus/src/action/action_board.c:1.43    Fri Oct 17 02:04:29 2003
+++ stratagus/src/action/action_board.c Sun Nov  9 17:13:56 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: action_board.c,v 1.43 2003/10/17 06:04:29 mr-russ Exp $
+//     $Id: action_board.c,v 1.44 2003/11/09 22:13:56 n0body Exp $
 
 //@{
 
@@ -97,20 +97,9 @@
         return 0;
     }
 
-    if (trans->Destroyed) {
-       DebugLevel0Fn("Destroyed transporter\n");
-       RefsDebugCheck(!trans->Refs);
-       if (!--trans->Refs) {
-           ReleaseUnit(trans);
-       }
-       unit->Orders[0].Goal = NoUnitP;
-       return 0;
-    } else if (trans->Removed ||
-           !trans->HP || trans->Orders[0].Action == UnitActionDie) {
-       DebugLevel0Fn("Unusable transporter\n");
-       RefsDebugCheck(!trans->Refs);
-       --trans->Refs;
-       RefsDebugCheck(!trans->Refs);
+    if (GoalGone(unit, trans)) {
+       DebugLevel0Fn("Transporter Gone\n");
+       RefsDecrease(trans);
        unit->Orders[0].Goal = NoUnitP;
        return 0;
     }
@@ -152,27 +141,14 @@
     unit->SubAction = 0;
 
     transporter = unit->Orders[0].Goal;
-    if (transporter->Destroyed) {
-       DebugLevel0Fn("Destroyed transporter\n");
-       RefsDebugCheck( !transporter->Refs );
-       if (!--transporter->Refs) {
-           ReleaseUnit(transporter);
-       }
-       unit->Orders[0].Goal = NoUnitP;
-       return;
-    } else if (transporter->Removed ||
-           !transporter->HP || transporter->Orders[0].Action == UnitActionDie) 
{
-       DebugLevel0Fn("Unuseable transporter\n");
-       RefsDebugCheck(!transporter->Refs);
-       --transporter->Refs;
-       RefsDebugCheck(!transporter->Refs);
+    if (GoalGone(unit,transporter)) {
+       DebugLevel0Fn("Transporter gone\n");
+       RefsDecrease(transporter);
        unit->Orders[0].Goal = NoUnitP;
        return;
     }
 
-    RefsDebugCheck(!transporter->Refs);
-    --transporter->Refs;
-    RefsDebugCheck(!transporter->Refs);
+    RefsDecrease(transporter);
     unit->Orders[0].Goal = NoUnitP;
 
     //
@@ -242,13 +218,7 @@
                        if (++unit->SubAction == 200) {
                            unit->Orders[0].Action = UnitActionStill;
                            if ((goal = unit->Orders[0].Goal)) {
-                               RefsDebugCheck(!goal->Refs);
-                               if (!--goal->Refs) {
-                                   RefsDebugCheck(!goal->Destroyed);
-                                   if (goal->Destroyed) {
-                                       ReleaseUnit(goal);
-                                   }
-                               }
+                               RefsDecrease(goal);
                                unit->Orders[0].Goal = NoUnitP;
                            }
                            unit->SubAction = 0;
Index: stratagus/src/action/action_build.c
diff -u stratagus/src/action/action_build.c:1.100 
stratagus/src/action/action_build.c:1.101
--- stratagus/src/action/action_build.c:1.100   Mon Oct 27 21:18:40 2003
+++ stratagus/src/action/action_build.c Sun Nov  9 17:13:56 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: action_build.c,v 1.100 2003/10/28 02:18:40 jsalmon3 Exp $
+//     $Id: action_build.c,v 1.101 2003/11/09 22:13:56 n0body Exp $
 
 //@{
 
@@ -276,8 +276,7 @@
        unit->Orders[0].Range = unit->Type->RepairRange;
        unit->SubAction = 0;
        unit->Wait = 1;
-       RefsDebugCheck(!build->Refs);
-       build->Refs++;
+       RefsIncrease(build);
        UnitMarkSeen(unit);
        //  Mark the new building seen.
        MapMarkUnitSight(build);
Index: stratagus/src/action/action_follow.c
diff -u stratagus/src/action/action_follow.c:1.33 
stratagus/src/action/action_follow.c:1.34
--- stratagus/src/action/action_follow.c:1.33   Tue Nov  4 17:54:34 2003
+++ stratagus/src/action/action_follow.c        Sun Nov  9 17:13:56 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: action_follow.c,v 1.33 2003/11/04 22:54:34 n0body Exp $
+//     $Id: action_follow.c,v 1.34 2003/11/09 22:13:56 n0body Exp $
 
 //@{
 
@@ -66,14 +66,10 @@
     //
     if (unit->SubAction == 128) {
        goal = unit->Orders[0].Goal;
-       if (!goal || goal->Destroyed || !goal->HP ||
-               goal->Orders[0].Action == UnitActionDie) {
-           DebugLevel0Fn("Goal dead\n");
+       if (!goal || GoalGone(unit,goal)) {
+           DebugLevel0Fn("Goal gone\n");
            if (goal) {
-               RefsDebugCheck(!goal->Refs);
-               if (!--goal->Refs && goal->Destroyed) {
-                   ReleaseUnit(goal);
-               }
+               RefsDecrease(goal);
            }
            unit->Orders[0].Goal = NoUnitP;
            unit->Wait = 1;
@@ -178,10 +174,7 @@
                            if (dest->NewOrder.Goal->Destroyed) {
                                // FIXME: perhaps we should use another dest?
                                DebugLevel0Fn("Destroyed unit in teleport 
unit\n");
-                               RefsDebugCheck(!dest->NewOrder.Goal->Refs);
-                               if (!--dest->NewOrder.Goal->Refs) {
-                                   ReleaseUnit(dest->NewOrder.Goal);
-                               }
+                               RefsDecrease(dest);
                                dest->NewOrder.Goal = NoUnitP;
                                dest->NewOrder.Action = UnitActionStill;
                            }
@@ -193,8 +186,7 @@
                        // FIXME: Pending command uses any references?
                        //
                        if (unit->Orders[0].Goal) {
-                           RefsDebugCheck(!unit->Orders[0].Goal->Refs);
-                           unit->Orders[0].Goal->Refs++;
+                           RefsIncrease(unit->Orders->Goal);
                        }
                    }
                }
@@ -222,30 +214,12 @@
     //
     // Target destroyed?
     //
-    if ((goal = unit->Orders[0].Goal) && goal->Destroyed) {
-       DebugLevel0Fn("Goal dead\n");
-       unit->Orders[0].X = goal->X + goal->Type->TileWidth / 2;
-       unit->Orders[0].Y = goal->Y + goal->Type->TileHeight / 2;
-       unit->Orders[0].Goal = NoUnitP;
-       RefsDebugCheck(!goal->Refs);
-       if (!--goal->Refs) {
-           ReleaseUnit(goal);
-       }
-       goal = NoUnitP;
-       NewResetPath(unit);
-    }
-    //
-    // Target removed?
-    //
-    if (unit->Type->Transporter && goal && goal->Removed) {
-       DebugLevel0Fn("Goal removed\n");
+    if ((goal = unit->Orders[0].Goal) && GoalGone(unit, goal)) {
+       DebugLevel0Fn("Goal gone\n");
        unit->Orders[0].X = goal->X + goal->Type->TileWidth / 2;
        unit->Orders[0].Y = goal->Y + goal->Type->TileHeight / 2;
        unit->Orders[0].Goal = NoUnitP;
-       RefsDebugCheck(!goal->Refs);
-       if (!--goal->Refs) {
-           ReleaseUnit(goal);
-       }
+       RefsDecrease(goal);
        goal = NoUnitP;
        NewResetPath(unit);
     }
Index: stratagus/src/action/action_move.c
diff -u stratagus/src/action/action_move.c:1.70 
stratagus/src/action/action_move.c:1.71
--- stratagus/src/action/action_move.c:1.70     Fri Oct 17 02:04:29 2003
+++ stratagus/src/action/action_move.c  Sun Nov  9 17:13:56 2003
@@ -21,7 +21,7 @@
 //     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 //     GNU General Public License for more details.
 //
-//     $Id: action_move.c,v 1.70 2003/10/17 06:04:29 mr-russ Exp $
+//     $Id: action_move.c,v 1.71 2003/11/09 22:13:56 n0body Exp $
 
 //@{
 
@@ -289,11 +289,7 @@
            unit->SubAction = 0;
            // Release target, if any.
            if ((goal = unit->Orders[0].Goal)) {
-               RefsDebugCheck(!goal->Refs);
-               if (!--goal->Refs) {
-                   DebugCheck(!goal->Destroyed);
-                   ReleaseUnit(goal);
-               }
+               RefsDecrease(goal);
                unit->Orders[0].Goal = NoUnitP;
            }
            unit->Orders[0].Action = UnitActionStill;
@@ -314,10 +310,7 @@
        unit->Orders[0].X = goal->X + goal->Type->TileWidth / 2;
        unit->Orders[0].Y = goal->Y + goal->Type->TileHeight / 2;
        unit->Orders[0].Goal = NoUnitP;
-       RefsDebugCheck(!goal->Refs);
-       if (!--goal->Refs) {
-           ReleaseUnit(goal);
-       }
+       RefsDecrease(goal);
        NewResetPath(unit);
     }
 }
Index: stratagus/src/action/action_repair.c
diff -u stratagus/src/action/action_repair.c:1.58 
stratagus/src/action/action_repair.c:1.59
--- stratagus/src/action/action_repair.c:1.58   Sun Nov  9 01:04:27 2003
+++ stratagus/src/action/action_repair.c        Sun Nov  9 17:13:56 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: action_repair.c,v 1.58 2003/11/09 06:04:27 n0body Exp $
+//     $Id: action_repair.c,v 1.59 2003/11/09 22:13:56 n0body Exp $
 
 //@{
 
@@ -105,10 +105,7 @@
                NotifyPlayer(player, NotifyYellow, unit->X, unit->Y, buf);
                if (player->Ai) {
                    // FIXME: call back to AI?
-                   RefsDebugCheck(!goal->Refs);
-                   if (!--goal->Refs) {
-                       ReleaseUnit(goal);
-                   }
+                   RefsDecrease(goal);
                    unit->Orders[0].Goal = NULL;
                    unit->Orders[0].Action = UnitActionStill;
                    unit->State = unit->SubAction = 0;
@@ -216,28 +213,14 @@
                // Check if goal is correct unit.
                // FIXME: should I do a function for this?
                if (goal) {
-                   if (goal->Destroyed) {
-                       DebugLevel0Fn("destroyed unit\n");
+                   if (GoalGone(unit, goal)) {
+                       DebugLevel0Fn("repair target gone. Booohooo\n");
                        unit->Orders[0].X = goal->X;
                        unit->Orders[0].Y = goal->Y;
-                       RefsDebugCheck(!goal->Refs);
-                       if (!--goal->Refs) {
-                           ReleaseUnit(goal);
-                       }
+                       RefsDecrease(goal);
                        // FIXME: should I clear this here?
                        unit->Orders[0].Goal = goal = NULL;
                        NewResetPath(unit);
-                   } else if (!goal->HP ||
-                           goal->Orders[0].Action == UnitActionDie ||
-                           goal->HP > goal->Stats->HitPoints) {
-                       unit->Orders[0].X = goal->X;
-                       unit->Orders[0].Y = goal->Y;
-                       RefsDebugCheck(!goal->Refs);
-                       --goal->Refs;
-                       RefsDebugCheck(!goal->Refs);
-                       unit->Orders[0].Goal = goal = NULL;
-                       // FIXME: should I clear this here?
-                       NewResetPath(unit);
                    }
                } else if (unit->Player->AiEnabled) {
                    // Ai players workers should stop if target is killed
@@ -259,9 +242,7 @@
                    CheckUnitToBeDrawn(unit);
                } else if (err < 0) {
                    if (goal) {         // release reference
-                       RefsDebugCheck(!goal->Refs);
-                       goal->Refs--;
-                       RefsDebugCheck(!goal->Refs);
+                       RefsDecrease(goal);
                        unit->Orders[0].Goal = NoUnitP;
                    }
                    unit->Orders[0].Action = UnitActionStill;
@@ -291,24 +272,14 @@
                // Check if goal is correct unit.
                // FIXME: should I do a function for this?
                if (goal) {
-                   if (goal->Destroyed) {
-                       DebugLevel0Fn("destroyed unit\n");
+                   if (GoalGone(unit, goal)) {
+                       DebugLevel0Fn("repair goal is gone\n");
                        unit->Orders[0].X = goal->X;
                        unit->Orders[0].Y = goal->Y;
-                       RefsDebugCheck(!goal->Refs);
-                       if (!--goal->Refs) {
-                           ReleaseUnit(goal);
-                       }
+                       RefsDecrease(goal);
                        // FIXME: should I clear this here?
                        unit->Orders[0].Goal = goal = NULL;
                        NewResetPath(unit);
-                   } else if (!goal->HP ||
-                           goal->Orders[0].Action == UnitActionDie) {
-                       // FIXME: should I clear this here?
-                       unit->Orders[0].X = goal->X;
-                       unit->Orders[0].Y = goal->Y;
-                       unit->Orders[0].Goal = goal = NULL;
-                       NewResetPath(unit);
                    }
                }
                if (goal) {
@@ -321,9 +292,7 @@
                //
                if (!goal || goal->HP >= goal->Stats->HitPoints) {
                    if (goal) {         // release reference
-                       RefsDebugCheck(!goal->Refs);
-                       goal->Refs--;
-                       RefsDebugCheck(!goal->Refs);
+                       RefsDecrease(goal);
                        unit->Orders[0].Goal = NULL;
                    }
                     unit->Orders[0].Action = UnitActionStill;
Index: stratagus/src/action/action_resource.c
diff -u stratagus/src/action/action_resource.c:1.66 
stratagus/src/action/action_resource.c:1.67
--- stratagus/src/action/action_resource.c:1.66 Fri Nov  7 16:21:12 2003
+++ stratagus/src/action/action_resource.c      Sun Nov  9 17:13:56 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: action_resource.c,v 1.66 2003/11/07 21:21:12 jsalmon3 Exp $
+//     $Id: action_resource.c,v 1.67 2003/11/09 22:13:56 n0body Exp $
 
 //@{
 
@@ -125,8 +125,7 @@
                break;
            default:
                // Goal gone or something.
-               if (!unit->Reset || !(goal->Destroyed || goal->Removed ||
-                       !goal->HP || goal->Orders[0].Action == UnitActionDie)) {
+               if (!unit->Reset || GoalGone(unit, goal)) {
                    return 0;
                }
                break;
@@ -174,25 +173,15 @@
     //
     // Target is dead, stop getting resources.
     //
-    if (goal->Destroyed || goal->Removed || !goal->HP ||
-           goal->Orders[0].Action==UnitActionDie) {
+    if (GoalGone(unit, goal)) {
        DebugLevel3Fn("Destroyed resource goal, stop gathering.\n");
-       RefsDebugCheck(!goal->Refs);
-       --goal->Refs;
-       if (goal->Destroyed) {
-           if (!goal->Refs) {
-               ReleaseUnit(goal);
-           }
-       } else {
-           RefsDebugCheck(!goal->Refs);
-       }
+       RefsDecrease(goal);
        //  Find an alternative, but don't look too far.
        unit->Orders[0].X = unit->Orders[0].Y = -1;
        if ((goal = FindResource(unit, unit->X, unit->Y, 10, 
unit->CurrentResource))) {
            unit->SubAction = SUB_START_RESOURCE;
            unit->Orders[0].Goal = goal;
-           RefsDebugCheck(!goal->Refs);
-           ++goal->Refs;
+           RefsIncrease(goal);
        } else {
            unit->Orders[0].Action = UnitActionStill;
            unit->Orders[0].Goal = NoUnitP;
@@ -239,10 +228,7 @@
     // Place unit inside the resource
     //
     if (!resinfo->HarvestFromOutside) {
-
-       RefsDebugCheck(!goal->Refs);
-       --goal->Refs;
-       RefsDebugCheck(!goal->Refs);
+       RefsDecrease(goal);
        unit->Orders[0].Goal = NoUnitP;
 
        RemoveUnit(unit, goal);
@@ -307,8 +293,7 @@
        //
        unit->Orders[0].Arg1 = (void*)((unit->X << 16) | unit->Y);
        unit->Orders[0].Goal = depot;
-       RefsDebugCheck(!depot->Refs);
-       ++depot->Refs;
+       RefsIncrease(depot);
        NewResetPath(unit);
        unit->SubAction = SUB_MOVE_TO_DEPOT;
        unit->Wait = unit->Reset = 1;
@@ -332,8 +317,7 @@
        unit->SubAction = SUB_START_RESOURCE;
        unit->Wait = unit->Reset = 1;
        unit->State = 0;
-       RefsDebugCheck(!uins->Orders[0].Goal->Refs);
-       ++unit->Orders[0].Goal->Refs;
+       RefsIncrease(unit->Orders[0].Goal);
     } else {
        DebugLevel0Fn("Unit %d just sits around confused.\n" _C_ unit->Slot);
        unit->Orders[0].Action = UnitActionStill;
@@ -424,10 +408,9 @@
            DebugCheck(source->Value > 655350);
 
            //
-           //  Target is dead, stop getting resources.
+           //  Target is not dead, getting resources.
            //
-           if (!(source->Destroyed || source->Removed || !source->HP ||
-                   source->Orders[0].Action == UnitActionDie)) {
+           if (!GoalGone(unit, source)) {
                //  Don't load more that there is.
                if (addload > source->Value) {
                    addload = source->Value;
@@ -447,8 +430,7 @@
            //  End of resource: destroy the resource.
            //  FIXME: implement depleted resources.
            //
-           if (source->Destroyed || source->Removed || !source->HP ||
-                   source->Orders[0].Action == UnitActionDie || source->Value 
== 0) {
+           if (GoalGone(unit, source) || (source->Value == 0)) {
                DebugLevel0Fn("Resource is destroyed for unit %d\n" _C_ 
unit->Slot);
                uins = source->UnitInside;
                //
@@ -460,8 +442,8 @@
                }
 
                //  Don't destroy the resource twice.
-               if (!(source->Destroyed || source->Removed || !source->HP ||
-                   source->Orders[0].Action == UnitActionDie)){
+               //  This only happens when it's empty.
+               if (!GoalGone(unit, source)){
                    LetUnitDie(source);
                    // FIXME: make the workers inside look for a new resource.
                }
@@ -552,8 +534,7 @@
                source->Type->TileWidth, source->Type->TileHeight);
        }
        unit->Orders[0].Goal = depot;
-       RefsDebugCheck(!depot->Refs);
-       ++depot->Refs;
+       RefsIncrease(depot);
        unit->Orders[0].Range = 1;
        unit->Orders[0].X = unit->Orders[0].Y = -1;
        unit->SubAction = SUB_MOVE_TO_DEPOT;
@@ -594,8 +575,7 @@
        case PF_REACHED:
            break;
        default:
-           if (!unit->Reset || !(goal->Destroyed || goal->Removed ||
-                   !goal->HP || goal->Orders[0].Action == UnitActionDie)) {
+           if (!unit->Reset || !GoalGone(unit, goal)) {
                return 0;
            }
            break;
@@ -604,22 +584,9 @@
     //
     // Target is dead, stop getting resources.
     //
-    if (goal->Destroyed) {
-       DebugLevel0Fn("Destroyed unit\n");
-       RefsDebugCheck(!goal->Refs);
-       if (!--goal->Refs) {
-           ReleaseUnit(goal);
-       }
-       unit->Orders[0].Goal = NoUnitP;
-       // FIXME: perhaps we should choose an alternative
-       unit->Orders[0].Action = UnitActionStill;
-       unit->SubAction = 0;
-       return 0;
-    } else if (goal->Removed || !goal->HP ||
-           goal->Orders[0].Action == UnitActionDie) {
-       RefsDebugCheck(!goal->Refs);
-       --goal->Refs;
-       RefsDebugCheck(!goal->Refs);
+    if (GoalGone(unit, goal)) {
+       DebugLevel0Fn("Destroyed depot\n");
+       RefsDecrease(goal);
        unit->Orders[0].Goal = NoUnitP;
        // FIXME: perhaps we should choose an alternative
        unit->Orders[0].Action = UnitActionStill;
@@ -637,9 +604,7 @@
        return 0;
     }
 
-    RefsDebugCheck(!goal->Refs);
-    --goal->Refs;
-    RefsDebugCheck(!goal->Refs);
+    RefsDecrease(goal);
     unit->Orders[0].Goal = NoUnitP;
 
     //
@@ -715,8 +680,7 @@
                goal->Y + goal->Type->TileHeight / 2,
                depot->Type->TileWidth, depot->Type->TileHeight);
            unit->Orders[0].Goal = goal;
-           RefsDebugCheck(!goal->Refs);
-           ++goal->Refs;
+           RefsIncrease(goal);
            unit->Orders[0].Range = 1;
            unit->Orders[0].X = unit->Orders[0].Y = -1;
        } else {
@@ -750,9 +714,7 @@
        unit->CurrentResource = 0;
     }
     if (unit->Orders[0].Goal) {
-       RefsDebugCheck(!unit->Orders[0].Goal->Refs);
-       --unit->Orders[0].Goal->Refs;
-       RefsDebugCheck(!unit->Orders[0].Goal->Refs);
+       RefsDecrease(unit->Orders->Goal);
        unit->Orders[0].Goal = NoUnitP;
     }
 }
Index: stratagus/src/action/action_returngoods.c
diff -u stratagus/src/action/action_returngoods.c:1.40 
stratagus/src/action/action_returngoods.c:1.41
--- stratagus/src/action/action_returngoods.c:1.40      Fri Oct  3 18:42:30 2003
+++ stratagus/src/action/action_returngoods.c   Sun Nov  9 17:13:56 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: action_returngoods.c,v 1.40 2003/10/03 22:42:30 jsalmon3 Exp $
+//     $Id: action_returngoods.c,v 1.41 2003/11/09 22:13:56 n0body Exp $
 
 //@{
 
@@ -79,8 +79,7 @@
            return;
        }
        unit->Orders[0].Goal = destu;
-       RefsDebugCheck(!destu->Refs);
-       ++destu->Refs;
+       RefsIncrease(destu);
     }
     DebugLevel3("Return to %d=%d,%d\n" _C_
        UnitNumber(unit->Orders[0].Goal) _C_
Index: stratagus/src/action/action_spellcast.c
diff -u stratagus/src/action/action_spellcast.c:1.36 
stratagus/src/action/action_spellcast.c:1.37
--- stratagus/src/action/action_spellcast.c:1.36        Thu Oct 23 21:58:33 2003
+++ stratagus/src/action/action_spellcast.c     Sun Nov  9 17:13:56 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: action_spellcast.c,v 1.36 2003/10/24 01:58:33 n0body Exp $
+//     $Id: action_spellcast.c,v 1.37 2003/11/09 22:13:56 n0body Exp $
 
 /*
 ** This is inherited from action_attack.c, actually spell casting will
@@ -156,11 +156,7 @@
            unit->State = unit->SubAction = 0;
 
            if (unit->Orders[0].Goal) { // Release references
-               RefsDebugCheck(!unit->Orders[0].Goal->Refs);
-               if (!--unit->Orders[0].Goal->Refs) {
-                   RefsDebugCheck(!unit->Orders[0].Goal->Destroyed);
-                   ReleaseUnit(unit->Orders[0].Goal);
-               }
+               RefsDecrease(unit->Orders->Goal);
                unit->Orders[0].Goal = NoUnitP;
            }
        }
@@ -211,11 +207,7 @@
                unit->SubAction = 0;
                unit->Wait = 1;
                if (unit->Orders[0].Goal) {
-                   RefsDebugCheck(!unit->Orders[0].Goal->Refs);
-                   if (!--unit->Orders[0].Goal->Refs) {
-                       RefsDebugCheck(!unit->Orders[0].Goal->Destroyed);
-                       ReleaseUnit(unit->Orders[0].Goal);
-                   }
+                   RefsDecrease(unit->Orders->Goal);
                    unit->Orders[0].Goal = NoUnitP;
                }
                return;
@@ -240,8 +232,7 @@
                flags = UnitShowAnimation(unit, unit->Type->Animations->Attack);
                if (flags & AnimationMissile) {
                    // FIXME: what todo, if unit/goal is removed?
-                   if (unit->Orders[0].Goal &&
-                           unit->Orders[0].Goal->Orders[0].Action == 
UnitActionDie) {
+                   if (unit->Orders[0].Goal && 
GoalGone(unit,unit->Orders->Goal)) {
                        unit->Value = 0;
                    } else {
                        spell = unit->Orders[0].Arg1;
@@ -254,8 +245,7 @@
                }
            } else {
                // FIXME: what todo, if unit/goal is removed?
-               if (unit->Orders[0].Goal &&
-                       unit->Orders[0].Goal->Orders[0].Action == 
UnitActionDie) {
+               if (unit->Orders[0].Goal && GoalGone(unit, unit->Orders->Goal)) 
{
                    unit->Value = 0;
                } else {
                    spell = unit->Orders[0].Arg1;
@@ -268,12 +258,7 @@
                unit->SubAction = 0;
                unit->Wait = 1;
                if (unit->Orders[0].Goal) {
-                   RefsDebugCheck(!unit->Orders[0].Goal->Refs);
-                   if (!--unit->Orders[0].Goal->Refs) {
-                       if (unit->Orders[0].Goal->Destroyed) {
-                           ReleaseUnit(unit->Orders[0].Goal);
-                       }
-                   }
+                   RefsDecrease(unit->Orders->Goal);
                    unit->Orders[0].Goal = NoUnitP;
                }
            }
Index: stratagus/src/action/action_still.c
diff -u stratagus/src/action/action_still.c:1.73 
stratagus/src/action/action_still.c:1.74
--- stratagus/src/action/action_still.c:1.73    Fri Oct 17 02:04:30 2003
+++ stratagus/src/action/action_still.c Sun Nov  9 17:13:56 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: action_still.c,v 1.73 2003/10/17 06:04:30 mr-russ Exp $
+//     $Id: action_still.c,v 1.74 2003/11/09 22:13:56 n0body Exp $
 
 //@{
 
@@ -191,26 +191,16 @@
            //
            temp = unit->Orders[0].Goal;
            if (temp && temp->Destroyed) {
-               DebugLevel3Fn(" destroyed unit %d #%d\n" _C_
-                   UnitNumber(temp) _C_ temp->Refs);
-               RefsDebugCheck(!temp->Refs);
-               if (!--temp->Refs) {
-                   ReleaseUnit(temp);
-               }
-               unit->Orders[0].Goal = temp=NoUnitP;
+               RefsDecrease(temp);
+               unit->Orders[0].Goal = temp = NoUnitP;
            }
            if (!unit->SubAction || temp != goal) {
                // New target.
                if (temp) {
-                   DebugLevel3Fn(" old unit %d #%d\n" _C_
-                       UnitNumber(temp) _C_ temp->Refs);
-                   RefsDebugCheck(!temp->Refs);
-                   temp->Refs--;
-                   RefsDebugCheck(!temp->Refs);
+                   RefsDecrease(temp);
                }
                unit->Orders[0].Goal = goal;
-               RefsDebugCheck(!goal->Refs);
-               goal->Refs++;
+               RefsIncrease(goal);
                unit->Reset = 0;
                unit->State = 0;
                unit->SubAction = 1;    // Mark attacking.
@@ -227,16 +217,7 @@
 
     if (unit->SubAction) {             // was attacking.
        if ((temp = unit->Orders[0].Goal)) {
-           if (temp->Destroyed) {
-               RefsDebugCheck(!temp->Refs);
-               if (!--temp->Refs) {
-                   ReleaseUnit(temp);
-               }
-           } else {
-               RefsDebugCheck(!temp->Refs);
-               temp->Refs--;
-               RefsDebugCheck(!temp->Refs);
-           }
+           RefsDecrease(temp);
            unit->Orders[0].Goal = NoUnitP;
        }
        unit->SubAction = unit->State = 0;      // No attacking, restart
Index: stratagus/src/action/action_train.c
diff -u stratagus/src/action/action_train.c:1.60 
stratagus/src/action/action_train.c:1.61
--- stratagus/src/action/action_train.c:1.60    Sun Nov  9 00:40:21 2003
+++ stratagus/src/action/action_train.c Sun Nov  9 17:13:56 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: action_train.c,v 1.60 2003/11/09 05:40:21 jsalmon3 Exp $
+//     $Id: action_train.c,v 1.61 2003/11/09 22:13:56 n0body Exp $
 
 //@{
 
@@ -164,8 +164,7 @@
            nunit->Orders[0] = unit->NewOrder;
            nunit->Orders[0].Action = UnitActionMove;
            if (nunit->Orders[0].Goal) {
-               RefsDebugCheck(!nunit->Orders[0].Goal->Refs);
-               nunit->Orders[0].Goal->Refs++;
+               RefsIncrease(nunit->Orders->Goal);
            }
             
        } else {
@@ -173,10 +172,7 @@
                if (unit->NewOrder.Goal->Destroyed) {
                    // FIXME: perhaps we should use another goal?
                    DebugLevel0Fn("Destroyed unit in train unit\n");
-                   RefsDebugCheck(!unit->NewOrder.Goal->Refs);
-                   if (!--unit->NewOrder.Goal->Refs) {
-                       ReleaseUnit(unit->NewOrder.Goal);
-                   }
+                   RefsDecrease(unit->NewOrder.Goal);
                    unit->NewOrder.Goal = NoUnitP;
                    unit->NewOrder.Action = UnitActionStill;
                }
@@ -188,8 +184,7 @@
            // FIXME: Pending command uses any references?
            //
            if (nunit->Orders[0].Goal) {
-               RefsDebugCheck(!nunit->Orders[0].Goal->Refs);
-               nunit->Orders[0].Goal->Refs++;
+               RefsIncrease(nunit->Orders->Goal);
            }
        }
 
Index: stratagus/src/action/action_unload.c
diff -u stratagus/src/action/action_unload.c:1.41 
stratagus/src/action/action_unload.c:1.42
--- stratagus/src/action/action_unload.c:1.41   Tue Oct  7 10:16:24 2003
+++ stratagus/src/action/action_unload.c        Sun Nov  9 17:13:56 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: action_unload.c,v 1.41 2003/10/07 14:16:24 mr-russ Exp $
+//     $Id: action_unload.c,v 1.42 2003/11/09 22:13:56 n0body Exp $
 
 //@{
 
@@ -333,16 +333,11 @@
     if (goal) {
        unit->Orders[0].Goal = NoUnitP;
        if (goal->Destroyed) {
-           DebugLevel0Fn("destroyed unit\n");
-           RefsDebugCheck(!goal->Refs);
-           if (!--goal->Refs) {
-               ReleaseUnit(goal);
-           }
+           DebugLevel0Fn("destroyed unit unloading?\n");
+           RefsDecrease(goal);
            return;
        }
-       RefsDebugCheck(!goal->Refs);
-       --goal->Refs;
-       RefsDebugCheck(!goal->Refs);
+       RefsDecrease(goal);
        goal->X = unit->X;
        goal->Y = unit->Y;
        // Try to unload the unit. If it doesn't work there is no problem.
Index: stratagus/src/action/actions.c
diff -u stratagus/src/action/actions.c:1.104 
stratagus/src/action/actions.c:1.105
--- stratagus/src/action/actions.c:1.104        Sun Oct 26 19:36:19 2003
+++ stratagus/src/action/actions.c      Sun Nov  9 17:13:56 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: actions.c,v 1.104 2003/10/27 00:36:19 n0body Exp $
+//     $Id: actions.c,v 1.105 2003/11/09 22:13:56 n0body Exp $
 
 //@{
 
@@ -58,6 +58,64 @@
 --     Functions
 ----------------------------------------------------------------------------*/
 
+/**
+**     Check if the unit can still *see* the goal or not
+**     This first of all checks dead/dying units, and then
+**     Invisibility, cloaking, going under fow and the like.
+**
+**
+**
+*/
+global int GoalGone(const Unit* unit, const Unit* goal)
+{
+    //
+    //  Check for dead/removed goals.
+    //
+    if (    //  Unit is marked destroyed
+           goal->Destroyed ||
+           //  Unit has 0 hp, dying
+           !goal->HP ||
+           //  Unit has action die, doesn't really live?
+           goal->Orders[0].Action == UnitActionDie ||
+           //  Unit is removed (inside something.)
+           goal->Removed) {
+       return 1;
+    }
+    //
+    // Check if we have an unit for this goal.
+    //
+    if (unit) {
+       //      SharedVision makes all the rest of the checks meaningless
+       if (IsSharedVision(unit->Player, goal) || unit->Player==goal->Player) {
+           return 0;
+       } else {
+           int x;
+           int y;
+           //  Goal is invisible (by spell)
+           if (goal->Invisible) {
+               return 1;
+           }
+           //  Goal is cloaked for this player
+           if (!(goal->Visible & (1 << unit->Player->Player))) {
+               return 1;
+           }
+           //
+           //  Check if under fog of war.
+           //
+           for (x = goal->X; x < goal->X + goal->Type->TileWidth; x++) {
+               for (y = goal->Y; y < goal->Y + goal->Type->TileHeight; y++) {
+                   if (IsMapFieldVisible(unit->Player, x, y)) {
+                       return 0;
+                   }
+               }
+           }
+           return 1;
+       }
+    } else {
+       return 0;
+    }
+}
+
 /*----------------------------------------------------------------------------
 --     Animation
 ----------------------------------------------------------------------------*/
@@ -437,10 +495,7 @@
                }
                //  Still shouldn't have a reference
                DebugCheck(unit->Orders[0].Action == UnitActionStill);
-               RefsDebugCheck(!unit->Orders[0].Goal->Refs);
-               if (!--unit->Orders[0].Goal->Refs) {
-                   ReleaseUnit(unit->Orders[0].Goal);
-               }
+               RefsDecrease(unit->Orders->Goal);
            }
            if (unit->CurrentResource) {
                if (unit->Type->ResInfo[unit->CurrentResource]->LoseResources &&
Index: stratagus/src/action/command.c
diff -u stratagus/src/action/command.c:1.115 
stratagus/src/action/command.c:1.116
--- stratagus/src/action/command.c:1.115        Wed Nov  5 04:30:46 2003
+++ stratagus/src/action/command.c      Sun Nov  9 17:13:56 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: command.c,v 1.115 2003/11/05 09:30:46 n0body Exp $
+//     $Id: command.c,v 1.116 2003/11/09 22:13:56 n0body Exp $
 
 //@{
 
@@ -62,11 +62,7 @@
 local void ReleaseOrder(Order* order)
 {
     if (order->Goal) {
-       RefsDebugCheck(!order->Goal->Refs);
-       if (!--order->Goal->Refs) {
-           DebugCheck(!order->Goal->Destroyed);
-           ReleaseUnit(order->Goal);
-       }
+       RefsDecrease(order->Goal);
        order->Goal = NoUnitP;
     }
 }
@@ -269,8 +265,7 @@
        } else {
            order->X = order->Y = -1;
            order->Goal = dest;
-           RefsDebugCheck(!dest->Refs);
-           dest->Refs++;
+           RefsIncrease(dest);
            order->Range = 1;
        }
        order->Type = NULL;
@@ -374,8 +369,7 @@
                order->X = order->Y = -1;
                order->Width = order->Height = 0;
                order->Goal = dest;
-               RefsDebugCheck(!dest->Refs);
-               dest->Refs++;
+               RefsIncrease(dest);
                order->Range = unit->Type->RepairRange;
            }
        } else {
@@ -438,8 +432,7 @@
                // Removed, Dying handled by action routine.
                order->X = order->Y = -1;
                order->Goal = attack;
-               RefsDebugCheck(!attack->Refs);
-               attack->Refs++;
+               RefsIncrease(attack);
                order->Range = unit->Stats->AttackRange;
                order->MinRange = unit->Type->MinAttackRange;
            }
@@ -589,8 +582,7 @@
        order->Action = UnitActionBoard;
        order->X = order->Y = -1;
        order->Goal = dest;
-       RefsDebugCheck(!dest->Refs);
-       dest->Refs++;
+       RefsIncrease(dest);
        order->Range = 1;
        order->Type = NULL;
        order->Arg1 = NULL;
@@ -630,8 +622,7 @@
        order->Goal = NoUnitP;
        if (what && !what->Destroyed) {
            order->Goal = what;
-           RefsDebugCheck(!what->Refs);
-           what->Refs++;
+           RefsIncrease(what);
        }
        order->Range = 0;
        order->Type = NULL;
@@ -801,8 +792,7 @@
        order->Action = UnitActionResource;
        order->X = order->Y = -1;
        order->Goal = dest;
-       RefsDebugCheck(!dest->Refs);
-       dest->Refs++;
+       RefsIncrease(dest);
        order->Range = 1;
        order->Type = NULL;
        order->Arg1 = NULL;
@@ -847,8 +837,7 @@
        //
        if (goal && !goal->Destroyed) {
            order->Goal = goal;
-           RefsDebugCheck(!goal->Refs);
-           goal->Refs++;
+           RefsIncrease(goal);
        }
        order->Range = 1;
        order->Type = NULL;
@@ -1220,8 +1209,7 @@
            } else {
                order->X = order->Y = -1;
                order->Goal = dest;
-               RefsDebugCheck(!dest->Refs);
-               dest->Refs++;
+               RefsIncrease(dest);
            }
        } else {
            order->X = x;
Index: stratagus/src/ai/ai_force.c
diff -u stratagus/src/ai/ai_force.c:1.40 stratagus/src/ai/ai_force.c:1.41
--- stratagus/src/ai/ai_force.c:1.40    Sat Nov  1 06:30:43 2003
+++ stratagus/src/ai/ai_force.c Sun Nov  9 17:13:56 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//      $Id: ai_force.c,v 1.40 2003/11/01 11:30:43 pludov Exp $
+//      $Id: ai_force.c,v 1.41 2003/11/09 22:13:56 n0body Exp $
 
 //@{
 
@@ -374,17 +374,12 @@
     prev = &AiPlayer->Force[force].Units;
     while ((aiunit = *prev)) {
        if (aiunit->Unit->Destroyed) {
-           RefsDebugCheck(!aiunit->Unit->Refs);
-           if (!--aiunit->Unit->Refs) {
-               ReleaseUnit(aiunit->Unit);
-           }
+           RefsDecrease(aiunit->Unit);
            *prev = aiunit->Next;
            free(aiunit);
            continue;
        } else if (!aiunit->Unit->HP || aiunit->Unit->Orders[0].Action == 
UnitActionDie) {
-           RefsDebugCheck(!aiunit->Unit->Refs);
-           --aiunit->Unit->Refs;
-           RefsDebugCheck(!aiunit->Unit->Refs);
+           RefsDecrease(aiunit->Unit);
            *prev = aiunit->Next;
            free(aiunit);
            continue;
@@ -413,9 +408,7 @@
            if (counter[aiunit->Unit->Type->Type] > 0) {
                DebugLevel3Fn("Release unit %s\n" _C_ 
aiunit->Unit->Type->Ident);
                counter[aiunit->Unit->Type->Type]--;
-               RefsDebugCheck(!aiunit->Unit->Refs);
-               --aiunit->Unit->Refs;
-               RefsDebugCheck(!aiunit->Unit->Refs);
+               RefsDecrease(aiunit->Unit);
                *prev = aiunit->Next;
 
                // Move this unit somewhere else...             
@@ -453,8 +446,7 @@
     aiu = AiPlayer->Force[force].Units;
     while (aiu) {
        // Decrease usage count
-       RefsDebugCheck(!aiu->Unit->Refs);
-       --aiu->Unit->Refs;
+       RefsDecrease(aiu->Unit);
 
        next_u = aiu->Next;
        free(aiu);
@@ -542,8 +534,7 @@
            aiunit->Next = AiPlayer->Force[force].Units;
            AiPlayer->Force[force].Units = aiunit;
            aiunit->Unit = unit;
-           RefsDebugCheck(unit->Destroyed || !unit->Refs);
-           ++unit->Refs;
+           RefsIncrease(unit);
            return;
        }
     }
@@ -554,8 +545,7 @@
     aiunit->Next = AiPlayer->Force[0].Units;
     AiPlayer->Force[0].Units = aiunit;
     aiunit->Unit = unit;
-    RefsDebugCheck(unit->Destroyed || !unit->Refs);
-    ++unit->Refs;
+    RefsIncrease(unit);
 }
 
 /**
Index: stratagus/src/ai/ai_local.h
diff -u stratagus/src/ai/ai_local.h:1.40 stratagus/src/ai/ai_local.h:1.41
--- stratagus/src/ai/ai_local.h:1.40    Fri Oct 31 04:14:45 2003
+++ stratagus/src/ai/ai_local.h Sun Nov  9 17:13:56 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//      $Id: ai_local.h,v 1.40 2003/10/31 09:14:45 pludov Exp $
+//      $Id: ai_local.h,v 1.41 2003/11/09 22:13:56 n0body Exp $
 
 #ifndef __AI_LOCAL_H__
 #define __AI_LOCAL_H__
@@ -63,7 +63,7 @@
 
     // nice flags
     //unsigned char     AllExplored : 1;/// Ai sees unexplored area
-    //unsigned char     AllVisibile : 1;/// Ai sees invisibile area
+    //unsigned char     AllVisbile : 1;/// Ai sees invisibile area
 
     SCM                        Script;         /// Main script (gc-protected!)
 };
Index: stratagus/src/ai/ai_plan.c
diff -u stratagus/src/ai/ai_plan.c:1.21 stratagus/src/ai/ai_plan.c:1.22
--- stratagus/src/ai/ai_plan.c:1.21     Sat Nov  1 06:30:43 2003
+++ stratagus/src/ai/ai_plan.c  Sun Nov  9 17:13:56 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//      $Id: ai_plan.c,v 1.21 2003/11/01 11:30:43 pludov Exp $
+//      $Id: ai_plan.c,v 1.22 2003/11/09 22:13:56 n0body Exp $
 
 //@{
 
@@ -582,8 +582,7 @@
            aiunit->Next = force->Units;
            force->Units = aiunit;
            aiunit->Unit = transporter;
-           RefsDebugCheck(transporter->Destroyed || !transporter->Refs);
-           ++transporter->Refs;
+           RefsIncrease(transporter);
        }
 
        DebugLevel0Fn("Can attack\n");
Index: stratagus/src/clone/spells.c
diff -u stratagus/src/clone/spells.c:1.122 stratagus/src/clone/spells.c:1.123
--- stratagus/src/clone/spells.c:1.122  Thu Nov  6 02:10:58 2003
+++ stratagus/src/clone/spells.c        Sun Nov  9 17:13:57 2003
@@ -27,7 +27,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: spells.c,v 1.122 2003/11/06 07:10:58 mr-russ Exp $
+//     $Id: spells.c,v 1.123 2003/11/09 22:13:57 n0body Exp $
 
 /*
 **     And when we cast our final spell
@@ -204,8 +204,7 @@
        x * TileSizeX + TileSizeX / 2, y * TileSizeY + TileSizeY / 2);*/
     //  Goal is used to link to destination circle of power
     caster->Goal = portal;
-    RefsDebugCheck(!portal->Refs || portal->Destroyed);
-    portal->Refs++;
+    RefsIncrease(portal);
     //FIXME: setting destination circle of power should use mana
     return 0;
 }
@@ -332,8 +331,7 @@
            // FIXME: not correct -- blizzard should continue even if mage is
            //       destroyed (though it will be quite short time...)
            mis->SourceUnit = caster;
-           RefsDebugCheck(!caster->Refs || caster->Destroyed);
-           caster->Refs++;
+           RefsIncrease(caster);
        }
     }
     return 1;
@@ -413,8 +411,7 @@
     missile->Damage = action->Data.SpawnMissile.Damage;
     missile->SourceUnit = caster;
     missile->TargetUnit = target;
-    RefsDebugCheck(!caster->Refs || caster->Destroyed);
-    caster->Refs++;
+    RefsIncrease(caster);
     return 1;
 }
 
Index: stratagus/src/clone/unit.c
diff -u stratagus/src/clone/unit.c:1.329 stratagus/src/clone/unit.c:1.330
--- stratagus/src/clone/unit.c:1.329    Sat Nov  8 21:42:05 2003
+++ stratagus/src/clone/unit.c  Sun Nov  9 17:13:57 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: unit.c,v 1.329 2003/11/09 02:42:05 n0body Exp $
+//     $Id: unit.c,v 1.330 2003/11/09 22:13:57 n0body Exp $
 
 //@{
 
@@ -138,6 +138,35 @@
 #endif
 
 /**
+**     Increase an unit's reference count.
+**
+**     @param unit     The unit
+*/
+global void RefsIncrease(Unit* unit)
+{
+    RefsDebugCheck(!unit->Refs || unit->Destroyed);
+    ++unit->Refs;
+}
+
+/**
+**     Decrease an unit's reference count.
+**
+**     @param unit     The unit
+*/
+global void RefsDecrease(Unit* unit)
+{
+    RefsDebugCheck(!unit->Refs);
+    if (unit->Destroyed) {
+       if (!--unit->Refs) {
+           ReleaseUnit(unit);
+       }
+    } else {
+       --unit->Refs;
+       RefsDebugCheck(!unit->Refs);
+    }
+}
+
+/**
 **     Release an unit.
 **
 **     The unit is only released, if all references are dropped.
@@ -151,7 +180,7 @@
 
     DebugCheck(!unit->Type);           // already free.
     DebugCheck(unit->OrderCount != 1);
-    RefsDebugCheck(unit->Orders[0].Goal);
+    DebugCheck(unit->Orders[0].Goal);
 
     //
     // First release, remove from lists/tables.
@@ -821,29 +850,17 @@
     //
     for (i = unit->OrderCount; i-- > 0;) {
        if (unit->Orders[i].Goal) {
-           RefsDebugCheck(!unit->Orders[i].Goal->Refs);
-           if (!--unit->Orders[i].Goal->Refs) {
-               RefsDebugCheck(!unit->Orders[i].Goal->Destroyed);
-               ReleaseUnit(unit->Orders[i].Goal);
-           }
+           RefsDecrease(unit->Orders[i].Goal);
            unit->Orders[i].Goal = NoUnitP;
        }
        unit->OrderCount = 1;
     }
     if (unit->NewOrder.Goal) {
-       RefsDebugCheck(!unit->NewOrder.Goal->Refs);
-       if (!--unit->NewOrder.Goal->Refs) {
-           DebugCheck(!unit->NewOrder.Goal->Destroyed);
-           ReleaseUnit(unit->NewOrder.Goal);
-       }
+       RefsDecrease(unit->NewOrder.Goal);
        unit->NewOrder.Goal = NoUnitP;
     }
     if (unit->SavedOrder.Goal) {
-       RefsDebugCheck(!unit->SavedOrder.Goal->Refs);
-       if (!--unit->SavedOrder.Goal->Refs) {
-           DebugCheck(!unit->SavedOrder.Goal->Destroyed);
-           ReleaseUnit(unit->SavedOrder.Goal);
-       }
+       RefsDecrease(unit->SavedOrder.Goal);
        unit->SavedOrder.Goal = NoUnitP;
     }
     unit->Orders[0].Action = UnitActionStill;
@@ -3755,7 +3772,7 @@
     int RunStart;
 
     CLprintf(file, "\n;;; -----------------------------------------\n");
-    CLprintf(file, ";;; MODULE: units $Id: unit.c,v 1.329 2003/11/09 02:42:05 
n0body Exp $\n\n");
+    CLprintf(file, ";;; MODULE: units $Id: unit.c,v 1.330 2003/11/09 22:13:57 
n0body Exp $\n\n");
 
     //
     // Local variables
Index: stratagus/src/include/actions.h
diff -u stratagus/src/include/actions.h:1.58 
stratagus/src/include/actions.h:1.59
--- stratagus/src/include/actions.h:1.58        Tue Oct 28 15:20:44 2003
+++ stratagus/src/include/actions.h     Sun Nov  9 17:13:57 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: actions.h,v 1.58 2003/10/28 20:20:44 n0body Exp $
+//     $Id: actions.h,v 1.59 2003/11/09 22:13:57 n0body Exp $
 
 #ifndef __ACTIONS_H__
 #define __ACTIONS_H__
@@ -181,7 +181,9 @@
 --     Actions:        actions.c
 ----------------------------------------------------------------------------*/
 
-    /// handle the animation of a unit
+    /// Check if a goal is gone/dead/invisible ?under-fow?
+extern int GoalGone(const Unit* unit, const Unit* goal);
+    /// Handle the animation of a unit
 extern int UnitShowAnimation(Unit* unit,const Animation* animation);
     /// Handle the actions of all units each game cycle
 extern void UnitActions(void);
Index: stratagus/src/include/unit.h
diff -u stratagus/src/include/unit.h:1.232 stratagus/src/include/unit.h:1.233
--- stratagus/src/include/unit.h:1.232  Sat Nov  8 21:42:05 2003
+++ stratagus/src/include/unit.h        Sun Nov  9 17:13:58 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: unit.h,v 1.232 2003/11/09 02:42:05 n0body Exp $
+//     $Id: unit.h,v 1.233 2003/11/09 22:13:58 n0body Exp $
 
 #ifndef __UNIT_H__
 #define __UNIT_H__
@@ -729,6 +729,10 @@
 extern void InitUnitsMemory(void);
     /// Free memory used by unit
 //extern void FreeUnitMemory(Unit* unit);
+    /// Increase an unit's reference count
+extern void RefsIncrease(Unit* unit);
+    /// Decrease an unit's reference count
+extern void RefsDecrease(Unit* unit);
     /// Release an unit
 extern void ReleaseUnit(Unit* unit);
     /// Initialize unit structure with default values
Index: stratagus/src/include/unittype.h
diff -u stratagus/src/include/unittype.h:1.128 
stratagus/src/include/unittype.h:1.129
--- stratagus/src/include/unittype.h:1.128      Sat Nov  8 21:42:05 2003
+++ stratagus/src/include/unittype.h    Sun Nov  9 17:13:58 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: unittype.h,v 1.128 2003/11/09 02:42:05 n0body Exp $
+//     $Id: unittype.h,v 1.129 2003/11/09 22:13:58 n0body Exp $
 
 #ifndef __UNITTYPE_H__
 #define __UNITTYPE_H__
@@ -306,7 +306,7 @@
 **
 **             Unit is a Building
 **
-**     UnitType::VisibileUnderFog
+**     UnitType::VisibleUnderFog
 **
 **             Unit is visible under fog of war.
 **
Index: stratagus/src/map/map.c
diff -u stratagus/src/map/map.c:1.60 stratagus/src/map/map.c:1.61
--- stratagus/src/map/map.c:1.60        Wed Oct 29 07:58:34 2003
+++ stratagus/src/map/map.c     Sun Nov  9 17:13:58 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: map.c,v 1.60 2003/10/29 12:58:34 mr-russ Exp $
+//     $Id: map.c,v 1.61 2003/11/09 22:13:58 n0body Exp $
 
 //@{
 
@@ -59,7 +59,7 @@
 global int ReplayRevealMap;            /// Reveal Map is replay
 
 /*----------------------------------------------------------------------------
---     Visibile and explored handling
+--     Visible and explored handling
 ----------------------------------------------------------------------------*/
 
 /**
Index: stratagus/src/missile/missile.c
diff -u stratagus/src/missile/missile.c:1.107 
stratagus/src/missile/missile.c:1.108
--- stratagus/src/missile/missile.c:1.107       Wed Nov  5 04:30:47 2003
+++ stratagus/src/missile/missile.c     Sun Nov  9 17:13:58 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: missile.c,v 1.107 2003/11/05 09:30:47 n0body Exp $
+//     $Id: missile.c,v 1.108 2003/11/09 22:13:58 n0body Exp $
 
 //@{
 
@@ -390,26 +390,10 @@
     // Release all unit references.
     //
     if ((unit = missile->SourceUnit)) {
-       RefsDebugCheck(!unit->Refs);
-       if (unit->Destroyed) {
-           if (!--unit->Refs) {
-               ReleaseUnit(unit);
-           }
-       } else {
-           --unit->Refs;
-           RefsDebugCheck(!unit->Refs);
-       }
+       RefsDecrease(unit);
     }
     if((unit = missile->TargetUnit)) {
-       RefsDebugCheck(!unit->Refs);
-       if (unit->Destroyed) {
-           if (!--unit->Refs) {
-               ReleaseUnit(unit);
-           }
-       } else {
-           --unit->Refs;
-           RefsDebugCheck(!unit->Refs);
-       }
+       RefsDecrease(unit);
     }
 
     //
@@ -603,12 +587,10 @@
     //
     if (goal) {
        missile->TargetUnit = goal;
-       RefsDebugCheck(!goal->Refs || goal->Destroyed);
-       goal->Refs++;
+       RefsIncrease(goal);
     }
     missile->SourceUnit = unit;
-    RefsDebugCheck(!unit->Refs || unit->Destroyed);
-    unit->Refs++;
+    RefsIncrease(unit);
 }
 
 /**
@@ -1038,8 +1020,7 @@
        mis->SourceUnit = missile->SourceUnit;
        // FIXME: should copy target also?
        if (mis->SourceUnit) {
-           RefsDebugCheck(!mis->SourceUnit->Refs);
-           mis->SourceUnit->Refs++;
+           RefsIncrease(mis->SourceUnit);
        }
 #endif
     }
@@ -1068,10 +1049,7 @@
            //
            goal = missile->TargetUnit;
            if (goal->Destroyed) {                      // Destroyed
-               RefsDebugCheck(!goal->Refs);
-               if (!--goal->Refs) {
-                   ReleaseUnit(goal);
-               }
+               RefsDecrease(goal);
                missile->TargetUnit = NoUnitP;
                return;
            }
@@ -1346,7 +1324,7 @@
 
     DebugCheck(file == NULL);
     CLprintf(file, "\n;;; -----------------------------------------\n");
-    CLprintf(file, ";;; MODULE: missile-types $Id: missile.c,v 1.107 
2003/11/05 09:30:47 n0body Exp $\n\n");
+    CLprintf(file, ";;; MODULE: missile-types $Id: missile.c,v 1.108 
2003/11/09 22:13:58 n0body Exp $\n\n");
 
     //
     // Original number to internal missile-type name.
@@ -1455,7 +1433,7 @@
 
     DebugCheck(file == NULL);
     CLprintf(file,"\n;;; -----------------------------------------\n");
-    CLprintf(file,";;; MODULE: missiles $Id: missile.c,v 1.107 2003/11/05 
09:30:47 n0body Exp $\n\n");
+    CLprintf(file,";;; MODULE: missiles $Id: missile.c,v 1.108 2003/11/09 
22:13:58 n0body Exp $\n\n");
 
     for (missiles = GlobalMissiles; *missiles; ++missiles) {
        SaveMissile(*missiles, file);




reply via email to

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