stratagus-cvs
[Top][All Lists]
Advanced

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

[Stratagus-CVS] stratagus/src/action action_returngoods.c actio...


From: Jimmy Salmon
Subject: [Stratagus-CVS] stratagus/src/action action_returngoods.c actio...
Date: Fri, 03 Oct 2003 18:42:30 -0400

CVSROOT:        /cvsroot/stratagus
Module name:    stratagus
Branch:         
Changes by:     Jimmy Salmon <address@hidden>   03/10/03 18:42:30

Modified files:
        src/action     : action_returngoods.c action_stand.c 
                         action_still.c action_train.c action_unload.c 
                         action_upgradeto.c actions.c 

Log message:
        Cleanup

Patches:
Index: stratagus/src/action/action_returngoods.c
diff -u stratagus/src/action/action_returngoods.c:1.39 
stratagus/src/action/action_returngoods.c:1.40
--- stratagus/src/action/action_returngoods.c:1.39      Thu Sep 11 18:07:53 2003
+++ stratagus/src/action/action_returngoods.c   Fri Oct  3 18:42:30 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: action_returngoods.c,v 1.39 2003/09/11 22:07:53 n0body Exp $
+//     $Id: action_returngoods.c,v 1.40 2003/10/03 22:42:30 jsalmon3 Exp $
 
 //@{
 
@@ -63,34 +63,35 @@
     const UnitType* type;
     Unit* destu;
 
-    type=unit->Type;
+    type = unit->Type;
     //
     // Select target to return goods. 
     // 
     DebugCheck(!type->Harvester );
-    if ((!unit->CurrentResource)&&(!unit->Value)) {
+    if ((!unit->CurrentResource) && (!unit->Value)) {
        DebugLevel0("Unit can't return resources, it doesn't carry any.\n");
     }
-    if( !unit->Orders[0].Goal ) {
-       if( 
!(destu=FindDeposit(unit,unit->X,unit->Y,1000,unit->CurrentResource)) ) {
+    if (!unit->Orders[0].Goal) {
+       if (!(destu = FindDeposit(unit, unit->X, unit->Y, 1000,
+               unit->CurrentResource))) {
            DebugLevel3Fn("No deposit -> can't return\n");
-           unit->Orders[0].Action=UnitActionStill;
+           unit->Orders[0].Action = UnitActionStill;
            return;
        }
-       unit->Orders[0].Goal=destu;
-       RefsDebugCheck( !destu->Refs );
+       unit->Orders[0].Goal = destu;
+       RefsDebugCheck(!destu->Refs);
        ++destu->Refs;
     }
-    DebugLevel3("Return to %d=%d,%d\n"
-           _C_ UnitNumber(unit->Orders[0].Goal)
-           _C_ unit->Orders[0].X _C_ unit->Orders[0].Y);
-    unit->Orders[0].Action=UnitActionResource;
+    DebugLevel3("Return to %d=%d,%d\n" _C_
+       UnitNumber(unit->Orders[0].Goal) _C_
+       unit->Orders[0].X _C_ unit->Orders[0].Y);
+    unit->Orders[0].Action = UnitActionResource;
     // Somewhere on the way the loaded worker could have change Arg1
     // Bummer, go get the closest resource to the depot
-    unit->Orders[0].Arg1=(void*)-1;
+    unit->Orders[0].Arg1 = (void*)-1;
     NewResetPath(unit);
-    unit->SubAction=70;
-    unit->Wait=1;
+    unit->SubAction = 70;
+    unit->Wait = 1;
     return;
 }
 
Index: stratagus/src/action/action_stand.c
diff -u stratagus/src/action/action_stand.c:1.22 
stratagus/src/action/action_stand.c:1.23
--- stratagus/src/action/action_stand.c:1.22    Fri Jul 11 10:35:29 2003
+++ stratagus/src/action/action_stand.c Fri Oct  3 18:42:30 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: action_stand.c,v 1.22 2003/07/11 14:35:29 n0body Exp $
+//     $Id: action_stand.c,v 1.23 2003/10/03 22:42:30 jsalmon3 Exp $
 
 //@{
 
@@ -51,7 +51,7 @@
 */
 global void HandleActionStandGround(Unit* unit)
 {
-    ActionStillGeneric(unit,1);
+    ActionStillGeneric(unit, 1);
 }
 
 //@}
Index: stratagus/src/action/action_still.c
diff -u stratagus/src/action/action_still.c:1.71 
stratagus/src/action/action_still.c:1.72
--- stratagus/src/action/action_still.c:1.71    Sat Sep 20 05:03:40 2003
+++ stratagus/src/action/action_still.c Fri Oct  3 18:42:30 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: action_still.c,v 1.71 2003/09/20 09:03:40 mr-russ Exp $
+//     $Id: action_still.c,v 1.72 2003/10/03 22:42:30 jsalmon3 Exp $
 
 //@{
 
@@ -57,7 +57,7 @@
 **     @param unit     Unit pointer for action.
 **     @param ground   Flag: true if unit is standing ground.
 */
-global void ActionStillGeneric(Unit* unit,int ground)
+global void ActionStillGeneric(Unit* unit, int ground)
 {
     const UnitType* type;
     Unit* temp;
@@ -65,9 +65,9 @@
 
     DebugLevel3Fn(" %d\n" _C_ UnitNumber(unit));
 
-    if( unit->Removed ) {              // Removed units, do nothing?
+    if (unit->Removed) {               // Removed units, do nothing?
        // If peon is in building or unit is in transporter it is removed.
-       unit->Wait=CYCLES_PER_SECOND/6;
+       unit->Wait = CYCLES_PER_SECOND / 6;
        return;
     }
 
@@ -75,9 +75,9 @@
     // Animations
     //
 
-    type=unit->Type;
+    type = unit->Type;
 
-    if( unit->SubAction ) {
+    if (unit->SubAction) {
        //
        //      Attacking unit in attack range.
        //
@@ -86,39 +86,39 @@
        //
        //      Still animation
        //
-        DebugCheck( !type->Animations || !type->Animations->Still );
+        DebugCheck(!type->Animations || !type->Animations->Still);
 
-       UnitShowAnimation(unit,type->Animations->Still);
+       UnitShowAnimation(unit, type->Animations->Still);
 
        //
        //      FIXME: this a workaround for some bad code.
        //              UnitShowAnimation resets frame.
        //      FIXME: the frames are hardcoded they should be configurable
        //
-       if( unit->State==1 && type->GivesResource==GoldCost ) {
-           unit->Frame=unit->Data.Resource.Active ? 1 : 0;
+       if (unit->State == 1 && type->GivesResource == GoldCost) {
+           unit->Frame = unit->Data.Resource.Active ? 1 : 0;
        }
-       if( unit->State==1 && type->GivesResource==OilCost ) {
-           unit->Frame=unit->Data.Resource.Active ? 2 : 0;
+       if (unit->State == 1 && type->GivesResource == OilCost) {
+           unit->Frame = unit->Data.Resource.Active ? 2 : 0;
        }
        UnitMarkSeen(unit);
     }
 
-    if( !unit->Reset ) {               // animation can't be aborted here
+    if (!unit->Reset) {                // animation can't be aborted here
        return;
     }
 
     //
     // Some units, like critter are moving random around randomly
     //
-    if( type->RandomMovementProbability &&
-           ((SyncRand()%100)<=type->RandomMovementProbability)) {
+    if (type->RandomMovementProbability &&
+           ((SyncRand() % 100) <= type->RandomMovementProbability)) {
        int x;
        int y;
 
-       x=unit->X;
-       y=unit->Y;
-       switch( (SyncRand()>>12)&15 ) {
+       x = unit->X;
+       y = unit->Y;
+       switch ((SyncRand() >> 12) & 15) {
            case 0:     x++;            break;
            case 1:     y++;            break;
            case 2:     x--;            break;
@@ -128,28 +128,28 @@
            case 6:     y--; x++;       break;
            case 7:     x--; y--;       break;
            default:
-                   break;
+               break;
        }
-       if( x<0 ) {
-           x=0;
-       } else if( x>=TheMap.Width ) {
-           x=TheMap.Width-1;
-       }
-       if( y<0 ) {
-           y=0;
-       } else if( y>=TheMap.Height ) {
-           y=TheMap.Height-1;
+       if (x < 0) {
+           x = 0;
+       } else if (x >= TheMap.Width) {
+           x = TheMap.Width - 1;
+       }
+       if (y < 0) {
+           y = 0;
+       } else if (y >= TheMap.Height) {
+           y = TheMap.Height - 1;
        }
-       if( x!=unit->X || y!=unit->Y ) {
-           if( CheckedCanMoveToMask(x,y,TypeMovementMask(type)) ) {
+       if (x != unit->X || y != unit->Y) {
+           if (CheckedCanMoveToMask(x, y, TypeMovementMask(type))) {
                // FIXME: Don't use pathfinder for this, costs too much cpu.
-               unit->Orders[0].Action=UnitActionMove;
-               DebugCheck( unit->Orders[0].Goal );
-               unit->Orders[0].Goal=NoUnitP;
-               unit->Orders[0].RangeX=unit->Orders[0].RangeY=0;
-               unit->Orders[0].X=x;
-               unit->Orders[0].Y=y;
-               unit->State=0;
+               unit->Orders[0].Action = UnitActionMove;
+               DebugCheck(unit->Orders[0].Goal);
+               unit->Orders[0].Goal = NoUnitP;
+               unit->Orders[0].RangeX = unit->Orders[0].RangeY = 0;
+               unit->Orders[0].X = x;
+               unit->Orders[0].Y = y;
+               unit->State = 0;
            }
        }
        // NOTE: critter couldn't attack automatic through the return
@@ -159,65 +159,65 @@
     //
     // Auto cast spells
     //
-    if( unit->AutoCastSpell && AutoCastSpell(unit, unit->AutoCastSpell) ) {
+    if (unit->AutoCastSpell && AutoCastSpell(unit, unit->AutoCastSpell)) {
        return;
     }
 
     //
     // Cowards don't attack unless instructed.
     //
-    if( type->CanAttack && !type->Coward ) {
+    if (type->CanAttack && !type->Coward) {
        //
        //      Normal units react in reaction range.
        //
-       if( unit->Stats->Speed && !ground ) {
-           if( (goal=AttackUnitsInReactRange(unit)) ) {
+       if (unit->Stats->Speed && !ground) {
+           if ((goal = AttackUnitsInReactRange(unit))) {
                // Weak goal, can choose other unit, come back after attack
-               CommandAttack(unit,goal->X,goal->Y,NULL,FlushCommands);
-               DebugLevel3Fn(" %d Attacking in range %d\n"
-                       _C_ UnitNumber(unit) _C_ unit->SubAction);
-               DebugCheck( unit->SavedOrder.Action!=UnitActionStill );
-               DebugCheck( unit->SavedOrder.Goal );
-               unit->SavedOrder.Action=UnitActionAttack;
-               unit->SavedOrder.RangeX=unit->SavedOrder.RangeY=0;
-               unit->SavedOrder.X=unit->X;
-               unit->SavedOrder.Y=unit->Y;
-               unit->SavedOrder.Goal=NoUnitP;
+               CommandAttack(unit, goal->X, goal->Y, NULL, FlushCommands);
+               DebugLevel3Fn(" %d Attacking in range %d\n" _C_
+                   UnitNumber(unit) _C_ unit->SubAction);
+               DebugCheck(unit->SavedOrder.Action != UnitActionStill);
+               DebugCheck(unit->SavedOrder.Goal);
+               unit->SavedOrder.Action = UnitActionAttack;
+               unit->SavedOrder.RangeX = unit->SavedOrder.RangeY = 0;
+               unit->SavedOrder.X = unit->X;
+               unit->SavedOrder.Y = unit->Y;
+               unit->SavedOrder.Goal = NoUnitP;
            }
-       } else if( (goal=AttackUnitsInRange(unit)) ) {
+       } else if ((goal = AttackUnitsInRange(unit))) {
            DebugLevel3Fn(" %d #%d\n" _C_ UnitNumber(goal) _C_ goal->Refs);
            //
            //  Old goal destroyed.
            //
-           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 ) {
+           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;
+               unit->Orders[0].Goal = temp=NoUnitP;
            }
-           if( !unit->SubAction || temp!=goal ) {
+           if (!unit->SubAction || temp != goal) {
                // New target.
-               if( temp ) {
-                   DebugLevel3Fn(" old unit %d #%d\n"
-                           _C_ UnitNumber(temp) _C_ temp->Refs);
-                   RefsDebugCheck( !temp->Refs );
+               if (temp) {
+                   DebugLevel3Fn(" old unit %d #%d\n" _C_
+                       UnitNumber(temp) _C_ temp->Refs);
+                   RefsDebugCheck(!temp->Refs);
                    temp->Refs--;
-                   RefsDebugCheck( !temp->Refs );
+                   RefsDebugCheck(!temp->Refs);
                }
-               unit->Orders[0].Goal=goal;
-               RefsDebugCheck( !goal->Refs );
+               unit->Orders[0].Goal = goal;
+               RefsDebugCheck(!goal->Refs);
                goal->Refs++;
-               unit->Reset=0;
-               unit->State=0;
-               unit->SubAction=1;      // Mark attacking.
-               if( type->Stats->Speed ) {
+               unit->Reset = 0;
+               unit->State = 0;
+               unit->SubAction = 1;    // Mark attacking.
+               if (type->Stats->Speed) {
                    UnitHeadingFromDeltaXY(unit,
-                       goal->X+(goal->Type->TileWidth-1)/2-unit->X,
-                       goal->Y+(goal->Type->TileHeight-1)/2-unit->Y);
+                       goal->X + (goal->Type->TileWidth - 1) / 2 - unit->X,
+                       goal->Y + (goal->Type->TileHeight - 1) / 2 - unit->Y);
                    AnimateActionAttack(unit);
                }
            }
@@ -225,35 +225,35 @@
        }
     }
 
-    if( unit->SubAction ) {            // was attacking.
-       if( (temp=unit->Orders[0].Goal) ) {
-           if( temp->Destroyed ) {
-               RefsDebugCheck( !temp->Refs );
-               if( !--temp->Refs ) {
+    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 );
+               RefsDebugCheck(!temp->Refs);
                temp->Refs--;
-               RefsDebugCheck( !temp->Refs );
+               RefsDebugCheck(!temp->Refs);
            }
-           unit->Orders[0].Goal=NoUnitP;
+           unit->Orders[0].Goal = NoUnitP;
        }
-       unit->SubAction=unit->State=0;  // No attacking, restart
+       unit->SubAction = unit->State = 0;      // No attacking, restart
     }
 
     //
     // Land units are turning left/right.
     //
-    if( type->LandUnit ) {
-       switch( (MyRand()>>8)&0x0FF ) {
+    if (type->LandUnit) {
+       switch ((MyRand() >> 8) & 0x0FF) {
            case 0:                     // Turn clockwise
-               unit->Direction+=NextDirection;
+               unit->Direction += NextDirection;
                UnitUpdateHeading(unit);
                 CheckUnitToBeDrawn(unit);
                break;
            case 1:                     // Turn counter clockwise
-               unit->Direction-=NextDirection;
+               unit->Direction -= NextDirection;
                UnitUpdateHeading(unit);
                 CheckUnitToBeDrawn(unit);
                break;
@@ -266,8 +266,8 @@
     //
     // Sea and air units are floating up/down.
     // 
-    if( unit->Type->SeaUnit||unit->Type->AirUnit ) {
-       unit->IY=(MyRand()>>15)&1;
+    if (unit->Type->SeaUnit || unit->Type->AirUnit) {
+       unit->IY = (MyRand() >> 15) & 1;
     }
 }
 
@@ -278,7 +278,7 @@
 */
 global void HandleActionStill(Unit* unit)
 {
-    ActionStillGeneric(unit,0);
+    ActionStillGeneric(unit, 0);
 }
 
 //@}
Index: stratagus/src/action/action_train.c
diff -u stratagus/src/action/action_train.c:1.56 
stratagus/src/action/action_train.c:1.57
--- stratagus/src/action/action_train.c:1.56    Fri Sep  5 14:10:55 2003
+++ stratagus/src/action/action_train.c Fri Oct  3 18:42:30 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: action_train.c,v 1.56 2003/09/05 18:10:55 n0body Exp $
+//     $Id: action_train.c,v 1.57 2003/10/03 22:42:30 jsalmon3 Exp $
 
 //@{
 
@@ -66,153 +66,152 @@
     Player* player;
     int food;
 
-    player=unit->Player;
+    player = unit->Player;
     //
     // First entry
     //
-    if( !unit->SubAction ) {
-       unit->Data.Train.Ticks=0;
-       unit->Data.Train.What[0]=unit->Orders[0].Type;
-       unit->Data.Train.Count=1;
-       unit->SubAction=1;
+    if (!unit->SubAction) {
+       unit->Data.Train.Ticks = 0;
+       unit->Data.Train.What[0] = unit->Orders[0].Type;
+       unit->Data.Train.Count = 1;
+       unit->SubAction = 1;
     }
-    unit->Data.Train.Ticks+=SpeedTrain;
+    unit->Data.Train.Ticks += SpeedTrain;
     // FIXME: Should count down
-    if( unit->Data.Train.Ticks
-           >=unit->Data.Train.What[0]
-               ->Stats[player->Player].Costs[TimeCost] ) {
+    if (unit->Data.Train.Ticks >=

+           unit->Data.Train.What[0]->Stats[player->Player].Costs[TimeCost]) {
        //
        //      Check if there are still unit slots.
        //
-       if( NumUnits>=UnitMax  ) {
-           unit->Data.Train.Ticks=unit->Data.Train.What[0]
-                   ->Stats[player->Player].Costs[TimeCost];
-           unit->Reset=1;
-           unit->Wait=CYCLES_PER_SECOND/6;
+       if (NumUnits >= UnitMax ) {
+           unit->Data.Train.Ticks = 

+               unit->Data.Train.What[0]->Stats[player->Player].Costs[TimeCost];
+           unit->Reset = 1;
+           unit->Wait = CYCLES_PER_SECOND / 6;
            return;
        }
 
        //
        //      Check if enough food available.
        //
-       if( (food=!PlayerCheckFood(player,unit->Data.Train.What[0]))
-               || !PlayerCheckLimits(player,unit->Data.Train.What[0]) ) {
-           if( food && unit->Player->Ai ) {
-               AiNeedMoreFarms(unit,unit->Orders[0].Type);
+       if ((food = !PlayerCheckFood(player, unit->Data.Train.What[0])) ||

+               !PlayerCheckLimits(player, unit->Data.Train.What[0])) {
+           if (food && unit->Player->Ai) {
+               AiNeedMoreFarms(unit, unit->Orders[0].Type);
            }
 
-           unit->Data.Train.Ticks=unit->Data.Train.What[0]
-                   ->Stats[player->Player].Costs[TimeCost];
-           unit->Reset=1;
-           unit->Wait=CYCLES_PER_SECOND/6;
+           unit->Data.Train.Ticks = 

+               unit->Data.Train.What[0]->Stats[player->Player].Costs[TimeCost];
+           unit->Reset = 1;
+           unit->Wait = CYCLES_PER_SECOND / 6;
            return;
        }
 
-       nunit=MakeUnit(unit->Data.Train.What[0],player);
-       nunit->X=unit->X;
-       nunit->Y=unit->Y;
-       type=unit->Type;
+       nunit=MakeUnit(unit->Data.Train.What[0], player);
+       nunit->X = unit->X;
+       nunit->Y = unit->Y;
+       type = unit->Type;
 
        //  Some guy made DropOutOnSide set unit to belong to the building
        //  training it. This was an ugly hack, setting X and Y is enough,
        //  no need to add the unit only to be removed.
-       nunit->X=unit->X;
-       nunit->Y=unit->Y;
+       nunit->X = unit->X;
+       nunit->Y = unit->Y;
 
-       DropOutOnSide(nunit,LookingW,type->TileWidth,type->TileHeight);
+       DropOutOnSide(nunit, LookingW, type->TileWidth, type->TileHeight);
 
        // set life span
-       if( type->DecayRate ) {
-           nunit->TTL=GameCycle+type->DecayRate*6*CYCLES_PER_SECOND;
+       if (type->DecayRate) {
+           nunit->TTL = GameCycle + type->DecayRate * 6 * CYCLES_PER_SECOND;
        }
 
-       NotifyPlayer(player,NotifyYellow,nunit->X,nunit->Y,
-           "New %s ready",nunit->Type->Name);
-       if( player==ThisPlayer ) {
-           PlayUnitSound(nunit,VoiceReady);
+       NotifyPlayer(player, NotifyYellow, nunit->X, nunit->Y,
+           "New %s ready", nunit->Type->Name);
+       if (player == ThisPlayer) {
+           PlayUnitSound(nunit, VoiceReady);
        }
-       if( unit->Player->Ai ) {
-           AiTrainingComplete(unit,nunit);
+       if (unit->Player->Ai) {
+           AiTrainingComplete(unit, nunit);
        }
 
-       unit->Reset=unit->Wait=1;
+       unit->Reset = unit->Wait = 1;
 
-       if ( --unit->Data.Train.Count ) {
+       if (--unit->Data.Train.Count) {
            int z;
-           for( z = 0; z < unit->Data.Train.Count ; z++ ) {
-               unit->Data.Train.What[z]=unit->Data.Train.What[z+1];
+           for (z = 0; z < unit->Data.Train.Count; ++z) {
+               unit->Data.Train.What[z] = unit->Data.Train.What[z + 1];
            }
-           unit->Data.Train.Ticks=0;
+           unit->Data.Train.Ticks = 0;
        } else {
-           unit->Orders[0].Action=UnitActionStill;
-           unit->SubAction=0;
+           unit->Orders[0].Action = UnitActionStill;
+           unit->SubAction = 0;
        }
 
        //
        //      FIXME: we must check if the units supports the new order.
        //
-       if( (unit->NewOrder.Action==UnitActionResource
-               && !nunit->Type->Harvester)
-           || (unit->NewOrder.Action==UnitActionAttack
-               && !nunit->Type->CanAttack)
-           || (unit->NewOrder.Action==UnitActionBoard
-               && nunit->Type->UnitType!=UnitTypeLand) ) {
+       if ((unit->NewOrder.Action == UnitActionResource &&

+                   !nunit->Type->Harvester) ||

+               (unit->NewOrder.Action == UnitActionAttack &&

+                   !nunit->Type->CanAttack) ||

+               (unit->NewOrder.Action == UnitActionBoard &&

+                   nunit->Type->UnitType != UnitTypeLand)) {
            DebugLevel0Fn("Wrong order for unit\n");
             
            //nunit->Orders[0].Action=UnitActionStandStill;
             
             // Tell the unit to move instead of trying to harvest
-           nunit->Orders[0]=unit->NewOrder;
-           nunit->Orders[0].Action=UnitActionMove;
-           if( nunit->Orders[0].Goal ) {
-               RefsDebugCheck( !nunit->Orders[0].Goal->Refs );
+           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++;
            }
             
        } else {
-           if( unit->NewOrder.Goal ) {
-               if( unit->NewOrder.Goal->Destroyed ) {
+           if (unit->NewOrder.Goal) {
+               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 ) {
+                   RefsDebugCheck(!unit->NewOrder.Goal->Refs);
+                   if (!--unit->NewOrder.Goal->Refs) {
                        ReleaseUnit(unit->NewOrder.Goal);
                    }
-                   unit->NewOrder.Goal=NoUnitP;
-                   unit->NewOrder.Action=UnitActionStill;
+                   unit->NewOrder.Goal = NoUnitP;
+                   unit->NewOrder.Action = UnitActionStill;
                }
            }
 
-           nunit->Orders[0]=unit->NewOrder;
+           nunit->Orders[0] = unit->NewOrder;
 
            //
            // FIXME: Pending command uses any references?
            //
-           if( nunit->Orders[0].Goal ) {
-               RefsDebugCheck( !nunit->Orders[0].Goal->Refs );
+           if (nunit->Orders[0].Goal) {
+               RefsDebugCheck(!nunit->Orders[0].Goal->Refs);
                nunit->Orders[0].Goal->Refs++;
            }
        }
 
-       if( IsOnlySelected(unit) ) {
+       if (IsOnlySelected(unit)) {
 #ifndef NEW_UI
            UpdateButtonPanel();
-           MustRedraw|=RedrawPanels;
+           MustRedraw |= RedrawPanels;
 #else
            SelectedUnitChanged();
-           MustRedraw|=RedrawInfoPanel;
+           MustRedraw |= RedrawInfoPanel;
 #endif
        }
 
        return;
     }
 
-    if( IsOnlySelected(unit) ) {
-       MustRedraw|=RedrawInfoPanel;
+    if (IsOnlySelected(unit)) {
+       MustRedraw |= RedrawInfoPanel;
     }
 
-    unit->Reset=1;
-    unit->Wait=CYCLES_PER_SECOND/6;
+    unit->Reset = 1;
+    unit->Wait = CYCLES_PER_SECOND / 6;
 }
 
 //@}
Index: stratagus/src/action/action_unload.c
diff -u stratagus/src/action/action_unload.c:1.39 
stratagus/src/action/action_unload.c:1.40
--- stratagus/src/action/action_unload.c:1.39   Fri Aug  8 06:16:43 2003
+++ stratagus/src/action/action_unload.c        Fri Oct  3 18:42:30 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: action_unload.c,v 1.39 2003/08/08 10:16:43 martinxyz Exp $
+//     $Id: action_unload.c,v 1.40 2003/10/03 22:42:30 jsalmon3 Exp $
 
 //@{
 
@@ -75,42 +75,46 @@
 **
 **     @bug FIXME: Place unit only on fields reachable from the transporter
 */
-local int FindUnloadPosition(int x,int y,int *resx,int *resy,int mask)
+local int FindUnloadPosition(int x, int y, int* resx, int* resy, int mask)
 {
-    int i,n,addx,addy;
-    addx=addy=1;
+    int i;
+    int n;
+    int addx;
+    int addy;
+
+    addx = addy = 1;
     --x;
-    for( n=0; n<2; ++n ) {
+    for (n = 0; n < 2; ++n) {
         //  Nobody: There was some code here to check for unloading units that 
can
         //  only go on even tiles. It's useless, since we can only unload land 
units.
-       for( i=addy; i--; y++ ) {
-           if( CheckedCanMoveToMask(x,y,mask) ) {
-                *resx=x;
-                *resy=y;
+       for (i = addy; i--; ++y) {
+           if (CheckedCanMoveToMask(x, y, mask)) {
+                *resx = x;
+                *resy = y;
                return 1;
            }
        }
        ++addx;
-       for( i=addx; i--; x++ ) {
-           if( CheckedCanMoveToMask(x,y,mask) ) {
-                *resx=x;
-                *resy=y;
+       for (i = addx; i--; ++x) {
+           if (CheckedCanMoveToMask(x, y, mask)) {
+                *resx = x;
+                *resy = y;
                return 1;
            }
        }
        ++addy;
-       for( i=addy; i--; y-- ) {
-           if( CheckedCanMoveToMask(x,y,mask) ) {
-                *resx=x;
-                *resy=y;
+       for (i = addy; i--; --y) {
+           if (CheckedCanMoveToMask(x, y, mask)) {
+                *resx = x;
+                *resy = y;
                return 1;
            }
        }
        ++addx;
-       for( i=addx; i--; x-- ) {
-           if( CheckedCanMoveToMask(x,y,mask) ) {
-                *resx=x;
-                *resy=y;
+       for (i = addx; i--; --x) {
+           if (CheckedCanMoveToMask(x, y, mask)) {
+                *resx = x;
+                *resy = y;
                return 1;
            }
        }
@@ -130,15 +134,17 @@
 */
 global int UnloadUnit(Unit* unit)
 {
-    int x,y;
-    DebugCheck( !unit->Removed );
-    if ( !FindUnloadPosition(unit->X,unit->Y,&x,&y,UnitMovementMask(unit)) ) {
+    int x;
+    int y;
+
+    DebugCheck(!unit->Removed);
+    if (!FindUnloadPosition(unit->X, unit->Y, &x, &y, UnitMovementMask(unit))) 
{
         return 0;
     }
-    unit->X=x;
-    unit->Y=y;
-    unit->Wait=1;              // should be correct unit has still action
-    PlaceUnit(unit,x,y);
+    unit->X = x;
+    unit->Y = y;
+    unit->Wait = 1;            // should be correct unit has still action
+    PlaceUnit(unit, x, y);
     return 1;
 }
 
@@ -152,57 +158,62 @@
 **      @param  resy    coast y position
 **      @return 1 if a location was found, 0 otherwise
 */
-local int ClosestFreeCoast(int x,int y,int* resx,int* resy)
+local int ClosestFreeCoast(int x, int y, int* resx, int* resy)
 {
-    int i,addx,addy,nullx,nully,n;
-    addx=addy=1;
-    if( CoastOnMap(x,y) &&
-        FindUnloadPosition(x,y,&nullx,&nully,LandUnitMask) ) {
-        *resx=x;
-        *resy=y;
+    int i;
+    int addx;
+    int addy;
+    int nullx;
+    int nully;
+    int n;
+
+    addx = addy = 1;
+    if (CoastOnMap(x, y) &&
+           FindUnloadPosition(x, y, &nullx, &nully, LandUnitMask)) {
+        *resx = x;
+        *resy = y;
         return 1;
     }
-    x--;
+    --x;
     // The maximum distance to the coast. We have to stop somewhere...
-    n=20;
-    while (n--)
-    {
-       for( i=addy; i--; y++ ) {
-            if( x>=0 && y>=0 && x<TheMap.Width && y<TheMap.Height &&
-                CoastOnMap(x,y) && !UnitOnMapTile(x,y) &&
-                FindUnloadPosition(x,y,&nullx,&nully,LandUnitMask) ) {
-                *resx=x;
-                *resy=y;
+    n = 20;
+    while (n--) {
+       for (i = addy; i--; ++y) {
+            if (x >= 0 && y >= 0 && x < TheMap.Width && y < TheMap.Height &&
+                   CoastOnMap(x, y) && !UnitOnMapTile(x, y) &&
+                   FindUnloadPosition(x, y, &nullx, &nully, LandUnitMask)) {
+                *resx = x;
+                *resy = y;
                return 1;
            }
        }
        ++addx;
-       for( i=addx; i--; x++ ) {
-            if( x>=0 && y>=0 && x<TheMap.Width && y<TheMap.Height &&
-                CoastOnMap(x,y) && !UnitOnMapTile(x,y) &&
-                FindUnloadPosition(x,y,&nullx,&nully,LandUnitMask) ) {
-                *resx=x;
-                *resy=y;
+       for (i = addx; i--; ++x) {
+            if (x >= 0 && y >= 0 && x < TheMap.Width && y < TheMap.Height &&
+                   CoastOnMap(x, y) && !UnitOnMapTile(x ,y) &&
+                   FindUnloadPosition(x, y, &nullx, &nully, LandUnitMask)) {
+                *resx = x;
+                *resy = y;
                return 1;
            }
        }
        ++addy;
-       for( i=addy; i--; y-- ) {
-            if( x>=0 && y>=0 && x<TheMap.Width && y<TheMap.Height &&
-                CoastOnMap(x,y) && !UnitOnMapTile(x,y) &&
-                FindUnloadPosition(x,y,&nullx,&nully,LandUnitMask) ) {
-                *resx=x;
-                *resy=y;
+       for (i = addy; i--; --y) {
+            if (x >= 0 && y >= 0 && x < TheMap.Width && y < TheMap.Height &&
+                   CoastOnMap(x, y) && !UnitOnMapTile(x, y) &&
+                   FindUnloadPosition(x, y, &nullx, &nully, LandUnitMask)) {
+                *resx = x;
+                *resy = y;
                return 1;
            }
        }
        ++addx;
-       for( i=addx; i--; x-- ) {
-            if( x>=0 && y>=0 && x<TheMap.Width && y<TheMap.Height &&
-                CoastOnMap(x,y) && !UnitOnMapTile(x,y) &&
-                FindUnloadPosition(x,y,&nullx,&nully,LandUnitMask) ) {
-                *resx=x;
-                *resy=y;
+       for (i = addx; i--; --x) {
+            if (x >= 0 && y >= 0 && x < TheMap.Width && y < TheMap.Height &&
+                   CoastOnMap(x, y) && !UnitOnMapTile(x, y) &&
+                   FindUnloadPosition(x, y, &nullx, &nully, LandUnitMask)) {
+                *resx = x;
+                *resy = y;
                return 1;
            }
        }
@@ -222,7 +233,7 @@
 {
     DebugLevel3Fn("%p\n" _C_ unit->Orders[0].Goal);
     
-    switch( DoActionMove(unit) ) {     // reached end-point?
+    switch (DoActionMove(unit)) {      // reached end-point?
        case PF_UNREACHABLE:
            DebugLevel2Fn("COAST NOT REACHABLE\n");
            return -1;
@@ -232,14 +243,14 @@
            return 0;
     }
 
-    IfDebug(
-       if( !CoastOnMap(unit->X,unit->Y) ) {
-           DebugLevel2Fn("COAST NOT REACHED\n");
-           return -1;
-       }
-    )
+#ifdef DEBUG
+    if (!CoastOnMap(unit->X, unit->Y)) {
+       DebugLevel2Fn("COAST NOT REACHED\n");
+       return -1;
+    }
+#endif
 
-    DebugCheck( unit->Orders[0].Action!=UnitActionUnload );
+    DebugCheck(unit->Orders[0].Action != UnitActionUnload);
     return 1;
 }
 
@@ -250,63 +261,64 @@
 */
 local void LeaveTransporter(Unit* unit)
 {
-    int i,stillonboard;
+    int i;
+    int stillonboard;
     Unit* goal;
-    stillonboard=0;
 
-    goal=unit->Orders[0].Goal;
+    stillonboard = 0;
+    goal = unit->Orders[0].Goal;
     //
     // Goal is the specific unit unit that you want to unload.
     // This can be NULL, in case you want to unload everything.
     DebugLevel3Fn("Goal %p\n" _C_ goal);
-    if( goal ) {
-       unit->Orders[0].Goal=NoUnitP;
-       if( goal->Destroyed ) {
+    if (goal) {
+       unit->Orders[0].Goal = NoUnitP;
+       if (goal->Destroyed) {
            DebugLevel0Fn("destroyed unit\n");
-           RefsDebugCheck( !goal->Refs );
-           if( !--goal->Refs ) {
+           RefsDebugCheck(!goal->Refs);
+           if (!--goal->Refs) {
                ReleaseUnit(goal);
            }
            return;
        }
-       RefsDebugCheck( !goal->Refs );
+       RefsDebugCheck(!goal->Refs);
        --goal->Refs;
-       RefsDebugCheck( !goal->Refs );
-       goal->X=unit->X;
-       goal->Y=unit->Y;
+       RefsDebugCheck(!goal->Refs);
+       goal->X = unit->X;
+       goal->Y = unit->Y;
        // Try to unload the unit. If it doesn't work there is no problem.
        UnloadUnit(goal);
     } else {
        // Unload all units.
-       goal=unit->UnitInside;
-       for( i=unit->InsideCount; i; --i,goal=goal->NextContained) {
-           goal->X=unit->X;
-           goal->Y=unit->Y;
-           if( !UnloadUnit(goal) ) {
-               stillonboard++;
+       goal = unit->UnitInside;
+       for (i = unit->InsideCount; i; --i, goal = goal->NextContained) {
+           goal->X = unit->X;
+           goal->Y = unit->Y;
+           if (!UnloadUnit(goal)) {
+               ++stillonboard;
            }
        }
     }
-    if( IsOnlySelected(unit) ) {
+    if (IsOnlySelected(unit)) {
        SelectedUnitChanged();
-       MustRedraw|=RedrawInfoPanel;
+       MustRedraw |= RedrawInfoPanel;
     }
     
     // We still have some units to unload, find a piece of free coast.
     if (stillonboard) {
         //  We tell it to unload at it's current position. This can't be done,
         //  so it will search for a piece of free coast nearby.
-        unit->Orders[0].Action=UnitActionUnload;
-        unit->Orders[0].Goal=NoUnitP;
-        unit->Orders[0].X=unit->X;
-        unit->Orders[0].Y=unit->Y;
-        unit->SubAction=0;
-        unit->Reset=0;
-        unit->Wait=0;
+        unit->Orders[0].Action = UnitActionUnload;
+        unit->Orders[0].Goal = NoUnitP;
+        unit->Orders[0].X = unit->X;
+        unit->Orders[0].Y = unit->Y;
+        unit->SubAction = 0;
+        unit->Reset = 0;
+        unit->Wait = 0;
     } else {
-        unit->Wait=1;
-        unit->Orders[0].Action=UnitActionStill;
-        unit->SubAction=0;
+        unit->Wait = 1;
+        unit->Orders[0].Action = UnitActionStill;
+        unit->SubAction = 0;
     }
 }
 
@@ -317,40 +329,43 @@
 */
 global void HandleActionUnload(Unit* unit)
 {
-    int i,x,y;
+    int i;
+    int x;
+    int y;
 
-    DebugLevel3Fn("%p(%d) SubAction %d\n"
-           _C_ unit _C_ UnitNumber(unit) _C_ unit->SubAction);
+    DebugLevel3Fn("%p(%d) SubAction %d\n" _C_
+       unit _C_ UnitNumber(unit) _C_ unit->SubAction);
 
-    switch( unit->SubAction ) {
+    switch (unit->SubAction) {
        //
        //      Move the transporter
        //
        case 0:
-            if ( !unit->Orders[0].Goal ) {
-                if ( 
!ClosestFreeCoast(unit->Orders[0].X,unit->Orders[0].Y,&x,&y) ) {
+            if (!unit->Orders[0].Goal) {
+                if (!ClosestFreeCoast(unit->Orders[0].X, unit->Orders[0].Y,
+                       &x, &y)) {
                     // Sorry... I give up.
-                   unit->Orders[0].Action=UnitActionStill;
-                   unit->SubAction=0;
+                   unit->Orders[0].Action = UnitActionStill;
+                   unit->SubAction = 0;
                     return;
                 }
-                unit->Orders[0].X=x;
-                unit->Orders[0].Y=y;
+                unit->Orders[0].X = x;
+                unit->Orders[0].Y = y;
             }
             NewResetPath(unit);
-            unit->SubAction=1;
+            unit->SubAction = 1;
        case 1:
             //  The Goal is the unit that we have to unload.
-           if( !unit->Orders[0].Goal ) {
+           if (!unit->Orders[0].Goal) {
                 // We have to unload everything
-               if( (i=MoveToCoast(unit)) ) {
-                   if( i==-1 ) {
-                       if( ++unit->SubAction==1 ) {
-                           unit->Orders[0].Action=UnitActionStill;
-                           unit->SubAction=0;
+               if ((i = MoveToCoast(unit))) {
+                   if (i == -1) {
+                       if (++unit->SubAction == 1) {
+                           unit->Orders[0].Action = UnitActionStill;
+                           unit->SubAction = 0;
                        }
                    } else {
-                       unit->SubAction=2;
+                       unit->SubAction = 2;
                    }
                }
                break;
@@ -361,7 +376,7 @@
        case 2:
            // FIXME: show still animations ?
            LeaveTransporter(unit);
-            if ( unit->Orders[0].Action!=UnitActionStill ) {
+            if (unit->Orders[0].Action != UnitActionStill) {
                 HandleActionUnload(unit);
             }
            break;
Index: stratagus/src/action/action_upgradeto.c
diff -u stratagus/src/action/action_upgradeto.c:1.38 
stratagus/src/action/action_upgradeto.c:1.39
--- stratagus/src/action/action_upgradeto.c:1.38        Fri Aug  8 06:16:43 2003
+++ stratagus/src/action/action_upgradeto.c     Fri Oct  3 18:42:30 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: action_upgradeto.c,v 1.38 2003/08/08 10:16:43 martinxyz Exp $
+//     $Id: action_upgradeto.c,v 1.39 2003/10/03 22:42:30 jsalmon3 Exp $
 
 //@{
 
@@ -62,55 +62,55 @@
 
     DebugLevel3Fn(" %d\n" _C_ UnitNumber(unit));
 
-    player=unit->Player;
-    if( !unit->SubAction ) {           // first entry
-       unit->Data.UpgradeTo.Ticks=0;
-       unit->SubAction=1;
+    player = unit->Player;
+    if (!unit->SubAction) {            // first entry
+       unit->Data.UpgradeTo.Ticks = 0;
+       unit->SubAction = 1;
     }
-    type=unit->Orders[0].Type;
-    stats=&type->Stats[player->Player];
+    type = unit->Orders[0].Type;
+    stats = &type->Stats[player->Player];
 
     UnitMarkSeen(unit);
     // FIXME: Should count down here
-    unit->Data.UpgradeTo.Ticks+=SpeedUpgrade;
-    if( unit->Data.UpgradeTo.Ticks>=stats->Costs[TimeCost] ) {
+    unit->Data.UpgradeTo.Ticks += SpeedUpgrade;
+    if (unit->Data.UpgradeTo.Ticks >= stats->Costs[TimeCost]) {
 
-       unit->HP+=stats->HitPoints-unit->Type->Stats[player->Player].HitPoints;
+       unit->HP += stats->HitPoints - 
unit->Type->Stats[player->Player].HitPoints;
        // don't have such unit now
        player->UnitTypesCount[unit->Type->Type]--;
-       unit->Type=type;
-       unit->Stats=(UnitStats*)stats;
+       unit->Type = type;
+       unit->Stats = (UnitStats*)stats;
        // and we have new one...
        player->UnitTypesCount[unit->Type->Type]++;
-       UpdateForNewUnit(unit,1);
+       UpdateForNewUnit(unit, 1);
 
-       NotifyPlayer(player,NotifyGreen,unit->X,unit->Y,
-           "Upgrade to %s complete",unit->Type->Name );
-       if( unit->Player->Ai ) {
-           AiUpgradeToComplete(unit,type);
+       NotifyPlayer(player, NotifyGreen, unit->X, unit->Y,
+           "Upgrade to %s complete", unit->Type->Name);
+       if (unit->Player->Ai) {
+           AiUpgradeToComplete(unit, type);
        }
-       unit->Reset=unit->Wait=1;
-       unit->Orders[0].Action=UnitActionStill;
-       unit->SubAction=0;
+       unit->Reset = unit->Wait = 1;
+       unit->Orders[0].Action = UnitActionStill;
+       unit->SubAction = 0;
 
        //
        //      Update possible changed buttons.
        //
-       if( IsOnlySelected(unit) || player==ThisPlayer ) {
+       if (IsOnlySelected(unit) || player == ThisPlayer) {
            // could affect the buttons of any selected unit
            SelectedUnitChanged();
-           MustRedraw|=RedrawInfoPanel;
+           MustRedraw |= RedrawInfoPanel;
        }
 
        return;
     }
 
-    if( IsOnlySelected(unit) ) {
-       MustRedraw|=RedrawInfoPanel;
+    if (IsOnlySelected(unit)) {
+       MustRedraw |= RedrawInfoPanel;
     }
 
-    unit->Reset=1;
-    unit->Wait=CYCLES_PER_SECOND/6;
+    unit->Reset = 1;
+    unit->Wait = CYCLES_PER_SECOND / 6;
 }
 
 //@}
Index: stratagus/src/action/actions.c
diff -u stratagus/src/action/actions.c:1.98 stratagus/src/action/actions.c:1.99
--- stratagus/src/action/actions.c:1.98 Fri Oct  3 16:00:09 2003
+++ stratagus/src/action/actions.c      Fri Oct  3 18:42:30 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: actions.c,v 1.98 2003/10/03 20:00:09 jsalmon3 Exp $
+//     $Id: actions.c,v 1.99 2003/10/03 22:42:30 jsalmon3 Exp $
 
 //@{
 
@@ -74,48 +74,48 @@
 **
 **     @return                 The flags of the current script step.
 */
-global int UnitShowAnimation(Unit* unit,const Animation* animation)
+global int UnitShowAnimation(Unit* unit, const Animation* animation)
 {
     int state;
     int flags;
 
-    if( !(state=unit->State) ) {
-       unit->Frame=0;
+    if (!(state = unit->State)) {
+       unit->Frame = 0;
        UnitUpdateHeading(unit);                // FIXME: remove this!!
     }
 
     DebugLevel3Fn("State %2d " _C_ state);
-    DebugLevel3("Flags %2d Pixel %2d Frame %2d Wait %3d "
-           _C_ animation[state].Flags _C_ animation[state].Pixel
-           _C_ animation[state].Frame _C_ animation[state].Sleep);
+    DebugLevel3("Flags %2d Pixel %2d Frame %2d Wait %3d " _C_
+       animation[state].Flags _C_ animation[state].Pixel _C_
+       animation[state].Frame _C_ animation[state].Sleep);
     DebugLevel3("Heading %d +%d,%d\n" _C_ unit->Direction _C_ unit->IX _C_ 
unit->IY);
     
-    if( unit->Frame<0 ) {
-       unit->Frame-=animation[state].Frame;
+    if (unit->Frame < 0) {
+       unit->Frame -= animation[state].Frame;
     } else {
-       unit->Frame+=animation[state].Frame;
+       unit->Frame += animation[state].Frame;
     }
-    unit->IX+=animation[state].Pixel;
-    unit->IY+=animation[state].Pixel;
-    unit->Wait=animation[state].Sleep;
-    if( unit->Slow ) {                 // unit is slowed down
-       unit->Wait<<=1;
+    unit->IX += animation[state].Pixel;
+    unit->IY += animation[state].Pixel;
+    unit->Wait = animation[state].Sleep;
+    if (unit->Slow) {                  // unit is slowed down
+       unit->Wait <<= 1;
     }
-    if( unit->Haste && unit->Wait>1 ) {        // unit is accelerated
-       unit->Wait>>=1;
+    if (unit->Haste && unit->Wait > 1) {       // unit is accelerated
+       unit->Wait >>= 1;
     }
 
     // Anything changed the display?
-    if( (animation[state].Frame || animation[state].Pixel) ) {
+    if ((animation[state].Frame || animation[state].Pixel)) {
         CheckUnitToBeDrawn(unit);
     }
 
-    flags=animation[state].Flags;
-    if( flags&AnimationReset ) {       // Reset can check for other actions
-       unit->Reset=1;
+    flags = animation[state].Flags;
+    if (flags & AnimationReset) {      // Reset can check for other actions
+       unit->Reset = 1;
     }
-    if( flags&AnimationRestart ) {     // Restart animation script
-       unit->State=0;
+    if (flags & AnimationRestart) {    // Restart animation script
+       unit->State = 0;
     } else {
        ++unit->State;                  // Advance to next script
     }
@@ -136,7 +136,7 @@
 {
     DebugLevel1Fn("FIXME: Should not happen!\n");
     DebugLevel1Fn("FIXME: Unit (%d) %s has action none.!\n" _C_
-           UnitNumber(unit) _C_ unit->Type->Ident);
+       UnitNumber(unit) _C_ unit->Type->Ident);
 }
 
 /**
@@ -148,7 +148,7 @@
 {
     DebugLevel1Fn("FIXME: Not written!\n");
     DebugLevel1Fn("FIXME: Unit (%d) %s has action %d.!\n" _C_
-           UnitNumber(unit) _C_ unit->Type->Ident _C_ unit->Orders[0].Action);
+       UnitNumber(unit) _C_ unit->Type->Ident _C_ unit->Orders[0].Action);
 }
 
 /**
@@ -274,10 +274,10 @@
 
     // Get all the units around the unit
     nunits = SelectUnits(unit->X - unit->Stats->SightRange,
-               unit->Y - unit->Stats->SightRange,
-               unit->X + unit->Stats->SightRange+unit->Type->Width,
-               unit->Y + unit->Stats->SightRange+unit->Type->Height,
-               units);
+       unit->Y - unit->Stats->SightRange,
+       unit->X + unit->Stats->SightRange+unit->Type->Width,
+       unit->Y + unit->Stats->SightRange+unit->Type->Height,
+       units);
     // Mana and HP on units, 2 every time
     for (j = 0; j < nunits; ++j) {
        if (units[j] == unit) {
@@ -285,7 +285,7 @@
        }
 
        // Restore HP in everything but buildings (even in other player's units)
-       if (units[j]->Type->Organic && units[j]->HP < 
units[j]->Stats->HitPoints ) {
+       if (units[j]->Type->Organic && units[j]->HP < 
units[j]->Stats->HitPoints) {
            units[j]->HP++;
        }
 
@@ -308,18 +308,18 @@
        if (HitPointRegeneration && unit->HP<unit->Stats->HitPoints) {
            ++unit->HP;
 
-           if( unit->Selected ) {
-               MustRedraw|=RedrawInfoPanel;
+           if (unit->Selected) {
+               MustRedraw |= RedrawInfoPanel;
            }
        }
        
-       if( unit->Stats->RegenerationRate && unit->HP<unit->Stats->HitPoints ) {
-           unit->HP+=unit->Stats->RegenerationRate;
-           if( unit->HP > unit->Stats->HitPoints ) {
+       if (unit->Stats->RegenerationRate && unit->HP<unit->Stats->HitPoints) {
+           unit->HP += unit->Stats->RegenerationRate;
+           if (unit->HP > unit->Stats->HitPoints) {
                unit->HP = unit->Stats->HitPoints;
            }
 
-           if( unit->Selected ) {
+           if (unit->Selected) {
                MustRedraw|=RedrawInfoPanel;
            }
        }
@@ -338,68 +338,67 @@
     int deadunit;
     int flag;
 
-    if( unit->Type->CanCastSpell && unit->Mana!=unit->Type->_MaxMana ) {
+    if (unit->Type->CanCastSpell && unit->Mana!=unit->Type->_MaxMana) {
        unit->Mana++;
 
-       if( unit->Selected ) {
+       if (unit->Selected) {
            MustRedraw|=RedrawInfoPanel;
        }
     }
 
-    deadunit=0;
+    deadunit = 0;
     //
     // Look if the time to live is over.
     //
-    if( unit->TTL && unit->TTL<(GameCycle-unit->HP) ) {
-       DebugLevel0Fn("Unit must die %lu %lu!\n" _C_ unit->TTL
-               _C_ GameCycle);
-       if( --unit->HP<0 ) {
+    if (unit->TTL && unit->TTL < (GameCycle - unit->HP)) {
+       DebugLevel0Fn("Unit must die %lu %lu!\n" _C_ unit->TTL _C_ GameCycle);
+       if (--unit->HP < 0) {
            LetUnitDie(unit);
-           deadunit|=1;
+           deadunit |= 1;
        }
-       if( unit->Selected ) {
-           MustRedraw|=RedrawInfoPanel;
+       if (unit->Selected) {
+           MustRedraw |= RedrawInfoPanel;
        }
     }
 
     // some frames delayed done my color cycling
-    flag=1;
+    flag = 1;
     //
     // decrease spells effects time, if end redraw unit.
     //
-    if ( unit->Bloodlust ) {
+    if (unit->Bloodlust) {
        unit->Bloodlust--;
-       if( !flag && !unit->Bloodlust ) {
-           flag=CheckUnitToBeDrawn(unit);
+       if (!flag && !unit->Bloodlust) {
+           flag = CheckUnitToBeDrawn(unit);
        }
     }
-    if ( unit->Haste ) {
+    if (unit->Haste) {
        unit->Haste--;
-       if( !flag && !unit->Haste ) {
-           flag=CheckUnitToBeDrawn(unit);
+       if (!flag && !unit->Haste) {
+           flag = CheckUnitToBeDrawn(unit);
        }
     }
-    if ( unit->Slow ) {
+    if (unit->Slow) {
        unit->Slow--;
-       if( !flag && !unit->Slow ) {
-           flag=CheckUnitToBeDrawn(unit);
+       if (!flag && !unit->Slow) {
+           flag = CheckUnitToBeDrawn(unit);
        }
     }
-    if ( unit->Invisible ) {
+    if (unit->Invisible) {
        unit->Invisible--;
-       if( !flag && !unit->Invisible ) {
-           flag=CheckUnitToBeDrawn(unit);
+       if (!flag && !unit->Invisible) {
+           flag = CheckUnitToBeDrawn(unit);
        }
     }
-    if ( unit->UnholyArmor ) {
+    if (unit->UnholyArmor) {
        unit->UnholyArmor--;
-       if( !flag && !unit->UnholyArmor ) {
-           flag=CheckUnitToBeDrawn(unit);
+       if (!flag && !unit->UnholyArmor) {
+           flag = CheckUnitToBeDrawn(unit);
        }
     }
     DebugLevel3Fn("%d:%d,%d,%d,%d,%d\n" _C_ UnitNumber(unit) _C_
-           unit->Bloodlust _C_ unit->Haste _C_ unit->Slow _C_
-           unit->Invisible _C_ unit->UnholyArmor);
+       unit->Bloodlust _C_ unit->Haste _C_ unit->Slow _C_
+       unit->Invisible _C_ unit->UnholyArmor);
 
     return deadunit;
 }
@@ -413,14 +412,14 @@
 {
     int f;
 
-    if( !unit->Type->Building || unit->Removed || unit->Destroyed ) {
+    if (!unit->Type->Building || unit->Removed || unit->Destroyed) {
        return;
     }
 
     // don't burn buildings under construction
-    if( unit->Stats->HitPoints && unit->Orders[0].Action!=UnitActionBuilded ) {
+    if (unit->Stats->HitPoints && unit->Orders[0].Action!=UnitActionBuilded) {
        f = (100 * unit->HP) / unit->Stats->HitPoints;
-       if( f <= BurnBuildingPercent ) {
+       if (f <= BurnBuildingPercent) {
            HitUnit(NoUnitP, unit, BurnBuildingDamageRate);
        }
     }
@@ -438,17 +437,16 @@
     //
     // If current action is breakable proceed with next one.
     //
-    if( unit->Reset ) {
-       unit->Reset=0;
+    if (unit->Reset) {
+       unit->Reset = 0;
        //
        //      o Look if we have a new order and old finished.
        //      o Or the order queue should be flushed.
        //
-       if( unit->OrderCount>1
-               && (unit->Orders[0].Action==UnitActionStill || unit->OrderFlush)
-               ) {
+       if (unit->OrderCount > 1 &&
+               (unit->Orders[0].Action == UnitActionStill || 
unit->OrderFlush)) {
 
-           if( unit->Removed ) {       // FIXME: johns I see this as an error
+           if (unit->Removed) {        // FIXME: johns I see this as an error
                DebugLevel0Fn("Flushing removed unit\n");
                // This happens, if building with ALT+SHIFT.
                return;
@@ -457,25 +455,25 @@
            //
            //  Release pending references.
            //
-           if( unit->Orders[0].Goal ) {
+           if (unit->Orders[0].Goal) {
                //  If mining decrease the active count on the resource.
-               if ( unit->Orders[0].Action==UnitActionResource &&
-                       unit->SubAction==60) {
+               if (unit->Orders[0].Action == UnitActionResource &&
+                       unit->SubAction == 60) {
                    //  FIXME: SUB_GATHER_RESOURCE ?
                    unit->Orders[0].Goal->Data.Resource.Active--;
-                   DebugCheck(unit->Orders[0].Goal->Data.Resource.Active<0);
+                   DebugCheck(unit->Orders[0].Goal->Data.Resource.Active < 0);
                }
                //  Still shouldn't have a reference
-               DebugCheck( unit->Orders[0].Action==UnitActionStill );
-               RefsDebugCheck( !unit->Orders[0].Goal->Refs );
-               if( !--unit->Orders[0].Goal->Refs ) {
+               DebugCheck(unit->Orders[0].Action == UnitActionStill);
+               RefsDebugCheck(!unit->Orders[0].Goal->Refs);
+               if (!--unit->Orders[0].Goal->Refs) {
                    ReleaseUnit(unit->Orders[0].Goal);
                }
            }
            if (unit->CurrentResource) {
-               if (unit->Type->ResInfo[unit->CurrentResource]->LoseResources&&
-                       
unit->Value<unit->Type->ResInfo[unit->CurrentResource]->ResourceCapacity) {
-                   unit->Value=0;
+               if (unit->Type->ResInfo[unit->CurrentResource]->LoseResources &&
+                       unit->Value < 
unit->Type->ResInfo[unit->CurrentResource]->ResourceCapacity) {
+                   unit->Value = 0;
                }
            }
 
@@ -483,21 +481,21 @@
            //  Shift queue with structure assignment.
            //
            unit->OrderCount--;
-           unit->OrderFlush=0;
-           for ( z = 0; z < unit->OrderCount; z++ ) {
-               unit->Orders[z] = unit->Orders[z+1];
+           unit->OrderFlush = 0;
+           for (z = 0; z < unit->OrderCount; ++z) {
+               unit->Orders[z] = unit->Orders[z + 1];
            }
-           memset(unit->Orders+z,0,sizeof(*unit->Orders));
+           memset(unit->Orders + z, 0, sizeof(*unit->Orders));
 
            //
            //  Note subaction 0 should reset.
            //
-           unit->SubAction=unit->State=0;
-           unit->Wait=1;
+           unit->SubAction = unit->State = 0;
+           unit->Wait = 1;
 
-           if( IsOnlySelected(unit) ) {// update display for new action
+           if (IsOnlySelected(unit)) {// update display for new action
                SelectedUnitChanged();
-               MustRedraw|=RedrawInfoPanel;
+               MustRedraw |= RedrawInfoPanel;
            }
        }
     }
@@ -526,66 +524,65 @@
     int manathiscycle;
     int blinkthiscycle;
 
-    if( BurnBuildingPercent ) {
-       burnthiscycle=!(GameCycle%BurnBuildingWait);
+    if (BurnBuildingPercent) {
+       burnthiscycle = !(GameCycle % BurnBuildingWait);
     } else {
-       burnthiscycle=0;
+       burnthiscycle = 0;
     }
     // FIXME: Make configurable from CCL;
-    healthiscycle=!(GameCycle%CYCLES_PER_SECOND);
-    manathiscycle=!(GameCycle%CYCLES_PER_SECOND);
-    blinkthiscycle=!(GameCycle%CYCLES_PER_SECOND);
+    healthiscycle = !(GameCycle % CYCLES_PER_SECOND);
+    manathiscycle = !(GameCycle % CYCLES_PER_SECOND);
+    blinkthiscycle = !(GameCycle % CYCLES_PER_SECOND);
 
     //
     // Must copy table, units could be removed.
     //
-    tend=table+NumUnits;
-    memcpy(table,Units,sizeof(Unit*)*NumUnits);
+    tend = table + NumUnits;
+    memcpy(table, Units, sizeof(Unit*) * NumUnits);
 
     //
     // Do all actions
     //
-    for( tpos=table; tpos<tend; tpos++ ) {
-       unit=*tpos;
+    for (tpos = table; tpos < tend; ++tpos) {
+       unit = *tpos;
 
 #if defined(UNIT_ON_MAP) && 0          // debug unit store
         { const Unit* list;
 
-       list=TheMap.Fields[unit->Y*TheMap.Width+unit->X].Here.Units;
-       while( list ) {                         // find the unit
-           if( list==unit ) {
+       list = TheMap.Fields[unit->Y * TheMap.Width + unit->X].Here.Units;
+       while (list) {                          // find the unit
+           if (list == unit) {
                break;
            }
-           list=list->Next;
+           list = list->Next;
        }
-       if( !unit->Removed ) {
-           if( !list
-                   && (!unit->Type->Vanishes
-                       && !unit->Orders[0].Action==UnitActionDie) ) {
+       if (!unit->Removed) {
+           if (!list && (!unit->Type->Vanishes &&
+                   !unit->Orders[0].Action == UnitActionDie)) {
                DebugLevel0Fn("!removed not on map %d\n" _C_ UnitNumber(unit));
                abort();
            }
-       } else if( list ) {
+       } else if (list) {
            DebugLevel0Fn("remove on map %d\n" _C_ UnitNumber(unit));
            abort();
        }
-       list=unit->Next;
-       while( list ) {
-           if( list->X!=unit->X || list->Y!=unit->Y ) {
-               DebugLevel0Fn("Wrong X,Y %d %d,%d\n" _C_ UnitNumber(list)
-                       _C_ list->X _C_ list->Y);
+       list = unit->Next;
+       while (list) {
+           if (list->X != unit->X || list->Y != unit->Y) {
+               DebugLevel0Fn("Wrong X,Y %d %d,%d\n" _C_ UnitNumber(list) _C_
+                   list->X _C_ list->Y);
                abort();
            }
-           list=list->Next;
+           list = list->Next;
        } }
 #endif
-       if( unit->Destroyed ) {         // Ignore destroyed units
+       if (unit->Destroyed) {          // Ignore destroyed units
            DebugLevel0Fn("Destroyed unit %d in table, should be ok\n" _C_
-                   UnitNumber(unit));
+               UnitNumber(unit));
            continue;
        }
 
-       if( blinkthiscycle && unit->Blink ) {   // clear blink flag
+       if (blinkthiscycle && unit->Blink) {    // clear blink flag
            --unit->Blink;
        }
 
@@ -597,22 +594,22 @@
        }
 
        //FIXME: Need to configure this to work
-       if( 0 ) { //Condition for Area Heal
+       if (0) { //Condition for Area Heal
            IncrementAreaHealthMana(unit);
        }
-       if( healthiscycle ) {
+       if (healthiscycle) {
            IncrementUnitHealth(unit);
        }
-       if( burnthiscycle ) {
+       if (burnthiscycle) {
            BurnBuilding(unit);
        }
        
-       if( --unit->Wait ) {            // Wait until counter reached
+       if (--unit->Wait) {             // Wait until counter reached
            continue;
        }
 
        HandleUnitAction(unit);
-       DebugCheck( *tpos!=unit );      // Removed is evil.
+       DebugCheck(*tpos != unit);      // Removed is evil.
 
 #ifdef DEBUG_ACTIONS
        //
@@ -621,29 +618,29 @@
        {
        static FILE* logf;
 
-       if( !logf ) {
+       if (!logf) {
            time_t now;
            char buf[256];
 
-           sprintf(buf,"log_of_fc_%d.log",ThisPlayer->Player);
-           logf=fopen(buf,"wb");
-           if( !logf ) {
+           sprintf(buf, "log_of_fc_%d.log", ThisPlayer->Player);
+           logf = fopen(buf, "wb");
+           if (!logf) {
                return;
            }
-           fprintf(logf,";;; Log file generated by Stratagus Version "
+           fprintf(logf, ";;; Log file generated by Stratagus Version "
                    VERSION "\n");
            time(&now);
-           fprintf(logf,";;;\tDate: %s",ctime(&now));
-           fprintf(logf,";;;\tMap: %s\n\n",TheMap.Description);
+           fprintf(logf, ";;;\tDate: %s", ctime(&now));
+           fprintf(logf, ";;;\tMap: %s\n\n", TheMap.Description);
        }
 
-       fprintf(logf,"%lu: ",GameCycle);
-       fprintf(logf,"%d %s S%d/%d-%d P%d Refs %d: %X %d,%d %d,%d\n",
-           UnitNumber(unit),unit->Type ? unit->Type->Ident : "unit-killed",
-               unit->State,unit->SubAction,
-               unit->Orders[0].Action,
-               unit->Player ? unit->Player->Player : 
-1,unit->Refs,SyncRandSeed,
-               unit->X, unit->Y, unit->IX, unit->IY);
+       fprintf(logf, "%lu: ", GameCycle);
+       fprintf(logf, "%d %s S%d/%d-%d P%d Refs %d: %X %d,%d %d,%d\n",
+           UnitNumber(unit), unit->Type ? unit->Type->Ident : "unit-killed",
+           unit->State, unit->SubAction,
+           unit->Orders[0].Action,
+           unit->Player ? unit->Player->Player : -1, unit->Refs,SyncRandSeed,
+           unit->X, unit->Y, unit->IX, unit->IY);
                
        // SaveUnit(unit,logf);
        fflush(NULL);
@@ -652,11 +649,11 @@
        //
        //      Calculate some hash.
        //
-       SyncHash=(SyncHash<<5)|(SyncHash>>27);
-       SyncHash^=unit->Orders[0].Action<<18;
-       SyncHash^=unit->State<<12;
-       SyncHash^=unit->SubAction<<6;
-       SyncHash^=unit->Refs<<3;
+       SyncHash = (SyncHash << 5) | (SyncHash >> 27);
+       SyncHash ^= unit->Orders[0].Action << 18;
+       SyncHash ^= unit->State << 12;
+       SyncHash ^= unit->SubAction << 6;
+       SyncHash ^= unit->Refs << 3;
     }
 }
 
@@ -671,19 +668,19 @@
     Unit* unit;
     int i;
 
-    for (i=0; i<NumUnits; i++) {
-       unit=Units[i]; 
-       if (  unit->Type->PermanentCloak ) {
-           if( (unit->Visible&(1<<ThisPlayer->Player)) ) {
+    for (i = 0; i < NumUnits; ++i) {
+       unit = Units[i]; 
+       if (unit->Type->PermanentCloak) {
+           if ((unit->Visible & (1 << ThisPlayer->Player))) {
                CheckUnitToBeDrawn(unit);
            }
-           unit->Visible=0;
+           unit->Visible = 0;
        }
     }
-    for (i=0; i<NumUnits; ++i) {
-       unit=Units[i];
-       if( unit->Type->DetectCloak && !unit->Removed &&
-           unit->Orders[0].Action!=UnitActionBuilded ) {
+    for (i = 0; i < NumUnits; ++i) {
+       unit = Units[i];
+       if (unit->Type->DetectCloak && !unit->Removed &&
+               unit->Orders[0].Action != UnitActionBuilded) {
            MapDetectCloakedUnits(unit);
        }
     }




reply via email to

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