stratagus-cvs
[Top][All Lists]
Advanced

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

[Stratagus-CVS] stratagus/src clone/unit.c clone/unitcache.c ui...


From: Jimmy Salmon
Subject: [Stratagus-CVS] stratagus/src clone/unit.c clone/unitcache.c ui...
Date: Mon, 20 Oct 2003 19:06:05 -0400

CVSROOT:        /cvsroot/stratagus
Module name:    stratagus
Branch:         
Changes by:     Jimmy Salmon <address@hidden>   03/10/20 19:06:04

Modified files:
        src/clone      : unit.c unitcache.c 
        src/ui         : menus.c 

Log message:
        Removed IfDebug, some cleanup

Patches:
Index: stratagus/src/clone/unit.c
diff -u stratagus/src/clone/unit.c:1.310 stratagus/src/clone/unit.c:1.311
--- stratagus/src/clone/unit.c:1.310    Fri Oct 17 02:04:30 2003
+++ stratagus/src/clone/unit.c  Mon Oct 20 19:06:03 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: unit.c,v 1.310 2003/10/17 06:04:30 mr-russ Exp $
+//     $Id: unit.c,v 1.311 2003/10/20 23:06:03 jsalmon3 Exp $
 
 //@{
 
@@ -144,33 +144,33 @@
 global void ReleaseUnit(Unit* unit)
 {
     DebugLevel2Fn("%lu:Unit %p %d `%s'\n" _C_ GameCycle _C_
-           unit _C_ UnitNumber(unit) _C_ unit->Type->Ident);
+       unit _C_ UnitNumber(unit) _C_ unit->Type->Ident);
 
-    DebugCheck( !unit->Type );         // already free.
-    DebugCheck( unit->OrderCount!=1 );
-    RefsDebugCheck( unit->Orders[0].Goal );
+    DebugCheck(!unit->Type);           // already free.
+    DebugCheck(unit->OrderCount != 1);
+    RefsDebugCheck(unit->Orders[0].Goal);
 
     //
     // First release, remove from lists/tables.
     //
-    if( !unit->Destroyed ) {
+    if (!unit->Destroyed) {
        Unit* temp;
 
        //
        //      Remove the unit from the global units table.
        //
-       DebugCheck( *unit->UnitSlot!=unit );
-       temp=Units[--NumUnits];
-       temp->UnitSlot=unit->UnitSlot;
-       *unit->UnitSlot=temp;
-       Units[NumUnits]=NULL;
+       DebugCheck(*unit->UnitSlot != unit);
+       temp = Units[--NumUnits];
+       temp->UnitSlot = unit->UnitSlot;
+       *unit->UnitSlot = temp;
+       Units[NumUnits] = NULL;
        //
        //      Are more references remaining?
        //
-       unit->Destroyed=1;              // mark as destroyed
+       unit->Destroyed = 1;            // mark as destroyed
 
        // Mark building as can't be destroyed, since it's still seen
-       if( unit->Type->Building ) {
+       if (unit->Type->Building) {
            int i;
            int x;
            int y;
@@ -182,14 +182,14 @@
            x = unit->X;
            y = unit->Y;
            unit->Visible = 0x0000;
-           for( i=0; i < PlayerMax; i++ ) {
+           for (i = 0; i < PlayerMax; ++i) {
                w = w0 = unit->Type->TileWidth;
                h = unit->Type->TileHeight;
-               for( ; h-->0; ) {
-                   for( w=w0; w-->0; ) {
-                       if( !IsMapFieldVisible(&Players[i],x+w,y+h)
-                               && IsMapFieldExplored(&Players[i],x+w,y+h)
-                               && Players[i].Type == PlayerPerson ) {
+               for (; h-- > 0;) {
+                   for (w = w0; w-- > 0;) {
+                       if (!IsMapFieldVisible(&Players[i], x + w, y + h) &&
+                               IsMapFieldExplored(&Players[i], x + w, y + h) &&
+                               Players[i].Type == PlayerPerson) {
                            unit->Visible |= (1 << i);
                        }
                    }
@@ -197,13 +197,13 @@
            }
        }
 
-       if( unit->Type->Building && unit->Visible != 0x0000 ) {
+       if (unit->Type->Building && unit->Visible != 0x0000) {
            return;
        }
-       RefsDebugCheck( !unit->Refs );
-       if( --unit->Refs>0 ) {
-           DebugLevel2Fn("%lu:More references of %d #%d\n" _C_ GameCycle
-                   _C_ UnitNumber(unit) _C_ unit->Refs);
+       RefsDebugCheck(!unit->Refs);
+       if (--unit->Refs > 0) {
+           DebugLevel2Fn("%lu:More references of %d #%d\n" _C_ GameCycle _C_
+               UnitNumber(unit) _C_ unit->Refs);
            return;
        }
 #ifdef HIERARCHIC_PATHFINDER
@@ -212,20 +212,20 @@
     }
 
     // Update Corpse Cache
-    if( unit->Orders[0].Action == UnitActionDie ) {
-       if( unit->Type->Building ) {
+    if (unit->Orders[0].Action == UnitActionDie) {
+       if (unit->Type->Building) {
            DeadBuildingCacheRemove(unit);
        } else {
            CorpseCacheRemove(unit);
        }
     }
 
-    RefsDebugCheck( unit->Refs );
+    RefsDebugCheck(unit->Refs);
 
     //
     // Free used memory
     //
-    if( unit->Name ) {
+    if (unit->Name) {
        free(unit->Name);
     }
 
@@ -234,14 +234,14 @@
     // on the way. We must wait a little time before we could free the
     // memory.
     //
-    *ReleasedTail=unit;
-    ReleasedTail=&unit->Next;
-    unit->Refs=GameCycle+NetworkMaxLag;        // could be reuse after this 
time
-    IfDebug(
-           DebugLevel2Fn("%lu:No more references %d\n" _C_
-               GameCycle _C_ UnitNumber(unit));
-           // unit->Type=NULL;                 // for debugging.
-          );
+    *ReleasedTail = unit;
+    ReleasedTail = &unit->Next;
+    unit->Refs = GameCycle + NetworkMaxLag;    // could be reuse after this 
time
+#ifdef DEBUG
+    DebugLevel2Fn("%lu:No more references %d\n" _C_
+       GameCycle _C_ UnitNumber(unit));
+    // unit->Type = NULL;                      // for debugging.
+#endif
 }
 
 /**
@@ -1825,7 +1825,7 @@
  **    @param addx     Tile size in x.
  **    @param addy     Tile size in y.
  */
-global void DropOutNearest(Unit* unit,int gx,int gy,int addx,int addy)
+global void DropOutNearest(Unit* unit, int gx, int gy, int addx, int addy)
 {
     int x;
     int y;
@@ -1837,77 +1837,79 @@
     int n;
 
     DebugLevel3Fn("%d\n" _C_ UnitNumber(unit));
-    DebugCheck( !unit->Removed );
+    DebugCheck(!unit->Removed);
 
     // FIXME: better and quicker solution, to find the building.
-    x=y=-1;
-    if( unit->Container ) {
-       x=unit->Container->X;
-       y=unit->Container->Y;
+    x = y = -1;
+    if (unit->Container) {
+       x = unit->Container->X;
+       y = unit->Container->Y;
     } else {
-       x=unit->X;
-       y=unit->Y;
+       x = unit->X;
+       y = unit->Y;
     }
 
-    DebugCheck( x==-1 || y==-1 );
-    mask=UnitMovementMask(unit);
+    DebugCheck(x == -1 || y == -1);
+    mask = UnitMovementMask(unit);
 
-    bestd=99999;
-    IfDebug( bestx=besty=0; );         // keep the compiler happy
+    bestd = 99999;
+#ifdef DEBUG
+    bestx = besty = 0;         // keep the compiler happy
+#endif
 
     // FIXME: if we reach the map borders we can go fast up, left, ...
     --x;
-    for( ;; ) {
-       for( i=addy; i--; y++ ) {       // go down
-           if( CheckedCanMoveToMask(x,y,mask) ) {
-               n=MapDistance(gx,gy,x,y);
+    for (;;) {
+       for (i = addy; i--; ++y) {      // go down
+           if (CheckedCanMoveToMask(x, y, mask)) {
+               n = MapDistance(gx, gy, x, y);
                DebugLevel3("Distance %d,%d %d\n" _C_ x _C_ y _C_ n);
-               if( n<bestd ) {
-                   bestd=n;
-                   bestx=x;
-                   besty=y;
+               if (n < bestd) {
+                   bestd = n;
+                   bestx = x;
+                   besty = y;
                }
            }
        }
        ++addx;
-       for( i=addx; i--; x++ ) {       // go right
-           if( CheckedCanMoveToMask(x,y,mask) ) {
-               n=MapDistance(gx,gy,x,y);
+       for (i = addx; i--; ++x) {      // go right
+           if (CheckedCanMoveToMask(x, y, mask)) {
+               n = MapDistance(gx, gy, x, y);
                DebugLevel3("Distance %d,%d %d\n" _C_ x _C_ y _C_ n);
-               if( n<bestd ) {
-                   bestd=n;
-                   bestx=x;
-                   besty=y;
+               if (n < bestd) {
+                   bestd = n;
+                   bestx = x;
+                   besty = y;
                }
            }
        }
        ++addy;
-       for( i=addy; i--; y-- ) {       // go up
-           if( CheckedCanMoveToMask(x,y,mask) ) {
-               n=MapDistance(gx,gy,x,y);
+       for (i = addy; i--; --y) {      // go up
+           if (CheckedCanMoveToMask(x, y, mask)) {
+               n = MapDistance(gx, gy, x, y);
                DebugLevel3("Distance %d,%d %d\n" _C_ x _C_ y _C_ n);
-               if( n<bestd ) {
-                   bestd=n;
-                   bestx=x;
-                   besty=y;
+               if (n < bestd) {
+                   bestd = n;
+                   bestx = x;
+                   besty = y;
                }
            }
        }
        ++addx;
-       for( i=addx; i--; x-- ) {       // go left
-           if( CheckedCanMoveToMask(x,y,mask) ) {
-               n=MapDistance(gx,gy,x,y);
+       for (i = addx; i--; --x) {      // go left
+           if (CheckedCanMoveToMask(x, y, mask)) {
+               n = MapDistance(gx, gy, x, y);
                DebugLevel3("Distance %d,%d %d\n" _C_ x _C_ y _C_ n);
-               if( n<bestd ) {
-                   bestd=n;
-                   bestx=x;
-                   besty=y;
+               if (n < bestd) {
+                   bestd = n;
+                   bestx = x;
+                   besty = y;
                }
            }
        }
-       if( bestd!=99999 ) {
-           unit->Wait=1;               // unit should have action still
-           PlaceUnit(unit,bestx,besty);
+       if (bestd != 99999) {
+           unit->Wait = 1;             // unit should have action still
+           PlaceUnit(unit, bestx, besty);
            return;
        }
        ++addy;
@@ -2082,7 +2084,7 @@
  **
  **    @todo can't handle building units !1x1, needs a rewrite.
  */
-global int CanBuildUnitType(const Unit* unit,const UnitType* type,int x,int y)
+global int CanBuildUnitType(const Unit* unit, const UnitType* type, int x, int 
y)
 {
     int w;
     int h;
@@ -2090,89 +2092,91 @@
     int mask;
 
     // Terrain Flags don't matter.
-    if ( type->MustBuildOnTop ) {
-       return CanBuildHere(type,x,y);
+    if (type->MustBuildOnTop) {
+       return CanBuildHere(type, x, y);
     }
 
     //
     // Remove unit that is building!
     //
-    IfDebug( j=0; );
-    if( unit ) {
+#ifdef DEBUG
+    j = 0;
+#endif
+    if (unit) {
        // FIXME: This only works with 1x1 big units
-       DebugCheck( unit->Type->TileWidth!=1 || unit->Type->TileHeight!=1 );
-       j=unit->Type->FieldFlags;
-       TheMap.Fields[unit->X+unit->Y*TheMap.Width].Flags&=~j;
+       DebugCheck(unit->Type->TileWidth != 1 || unit->Type->TileHeight != 1);
+       j = unit->Type->FieldFlags;
+       TheMap.Fields[unit->X + unit->Y * TheMap.Width].Flags &= ~j;
     }
 
 #if 0
     // FIXME: Should be moved into unittype structure, and allow more types.
-    if( type->ShoreBuilding ) {
-       mask=MapFieldLandUnit
-           | MapFieldSeaUnit
-           | MapFieldBuilding  // already occuppied
-           | MapFieldWall
-           | MapFieldRocks
-           | MapFieldForest    // wall,rock,forest not 100% clear?
-           | MapFieldLandAllowed       // can't build on this
-           //| MapFieldUnpassable      // FIXME: I think shouldn't be used
-           | MapFieldNoBuilding;
-    } else if( type->Building ) {
-       switch( type->UnitType ) {
+    if (type->ShoreBuilding) {
+       mask = MapFieldLandUnit |
+           MapFieldSeaUnit |
+           MapFieldBuilding |  // already occuppied
+           MapFieldWall |
+           MapFieldRocks |
+           MapFieldForest |    // wall,rock,forest not 100% clear?
+           MapFieldLandAllowed |       // can't build on this
+           //MapFieldUnpassable |      // FIXME: I think shouldn't be used
+           MapFieldNoBuilding;
+    } else if (type->Building) {
+       switch (type->UnitType) {
            case UnitTypeLand:
-               mask=MapFieldLandUnit
-                   | MapFieldBuilding  // already occuppied
-                   | MapFieldWall
-                   | MapFieldRocks
-                   | MapFieldForest    // wall,rock,forest not 100% clear?
-                   | MapFieldCoastAllowed
-                   | MapFieldWaterAllowed      // can't build on this
-                   | MapFieldUnpassable        // FIXME: I think shouldn't be 
used
-                   | MapFieldNoBuilding;
+               mask = MapFieldLandUnit |
+                   MapFieldBuilding |  // already occuppied
+                   MapFieldWall |
+                   MapFieldRocks |
+                   MapFieldForest |    // wall,rock,forest not 100% clear?
+                   MapFieldCoastAllowed |
+                   MapFieldWaterAllowed |      // can't build on this
+                   MapFieldUnpassable |        // FIXME: I think shouldn't be 
used
+                   MapFieldNoBuilding;
                break;
            case UnitTypeNaval:
-               mask=MapFieldSeaUnit
-                   | MapFieldBuilding  // already occuppied
-                   | MapFieldCoastAllowed
-                   | MapFieldLandAllowed       // can't build on this
-                   | MapFieldUnpassable        // FIXME: I think shouldn't be 
used
-                   | MapFieldNoBuilding;
+               mask = MapFieldSeaUnit |
+                   MapFieldBuilding |  // already occuppied
+                   MapFieldCoastAllowed |
+                   MapFieldLandAllowed |       // can't build on this
+                   MapFieldUnpassable |        // FIXME: I think shouldn't be 
used
+                   MapFieldNoBuilding;
                break;
            case UnitTypeFly:
-               mask=MapFieldAirUnit;   // already occuppied
+               mask = MapFieldAirUnit; // already occuppied
                break;
            default:
                DebugLevel1Fn("Were moves this unit?\n");
-               if( unit ) {
-                   TheMap.Fields[unit->X+unit->Y*TheMap.Width].Flags|=j;
+               if (unit) {
+                   TheMap.Fields[unit->X + unit->Y * TheMap.Width].Flags |= j;
                }
                return 0;
        }
-    } else switch( type->UnitType ) {
+    } else switch (type->UnitType) {
        case UnitTypeLand:
-           mask=MapFieldLandUnit
-               | MapFieldBuilding      // already occuppied
-               | MapFieldWall
-               | MapFieldRocks
-               | MapFieldForest        // wall,rock,forest not 100% clear?
-               | MapFieldCoastAllowed
-               | MapFieldWaterAllowed  // can't build on this
-               | MapFieldUnpassable;   // FIXME: I think shouldn't be used
+           mask = MapFieldLandUnit |
+               MapFieldBuilding |      // already occuppied
+               MapFieldWall |
+               MapFieldRocks |
+               MapFieldForest |        // wall,rock,forest not 100% clear?
+               MapFieldCoastAllowed |
+               MapFieldWaterAllowed |  // can't build on this
+               MapFieldUnpassable;     // FIXME: I think shouldn't be used
            break;
        case UnitTypeNaval:
-           mask=MapFieldSeaUnit
-               | MapFieldBuilding      // already occuppied
-               | MapFieldCoastAllowed
-               | MapFieldLandAllowed   // can't build on this
-               | MapFieldUnpassable;   // FIXME: I think shouldn't be used
+           mask = MapFieldSeaUnit |
+               MapFieldBuilding |      // already occuppied
+               MapFieldCoastAllowed |
+               MapFieldLandAllowed |   // can't build on this
+               MapFieldUnpassable;     // FIXME: I think shouldn't be used
            break;
        case UnitTypeFly:
-           mask=MapFieldAirUnit;       // already occuppied
+           mask = MapFieldAirUnit;     // already occuppied
            break;
        default:
            DebugLevel1Fn("Were moves this unit?\n");
-           if( unit ) {
-               TheMap.Fields[unit->X+unit->Y*TheMap.Width].Flags|=j;
+           if (unit) {
+               TheMap.Fields[unit->X + unit->Y * TheMap.Width].Flags |= j;
            }
            return 0;
     }
@@ -2182,24 +2186,24 @@
 
 #endif
 
-    for( h=type->TileHeight; h--; ) {
-       for( w=type->TileWidth; w--; ) {
-           if( !CanBuildOn(x+w,y+h,mask) ) {
-               if( unit ) {
-                   TheMap.Fields[unit->X+unit->Y*TheMap.Width].Flags|=j;
+    for (h = type->TileHeight; h--;) {
+       for (w = type->TileWidth; w--;) {
+           if (!CanBuildOn(x + w, y + h, mask)) {
+               if (unit) {
+                   TheMap.Fields[unit->X + unit->Y * TheMap.Width].Flags |= j;
                }
                return 0;
            }
        }
     }
-    if( unit ) {
-       TheMap.Fields[unit->X+unit->Y*TheMap.Width].Flags|=j;
+    if (unit) {
+       TheMap.Fields[unit->X + unit->Y * TheMap.Width].Flags |= j;
     }
 
     //
     // We can build here: check distance to gold mine/oil patch!
     //
-    return CanBuildHere(type,x,y);
+    return CanBuildHere(type, x, y);
 }
 
 /*----------------------------------------------------------------------------
@@ -2213,10 +2217,10 @@
  **    @param x        OUT: Map X position of tile.
  **    @param y        OUT: Map Y position of tile.
  */
-global int FindWoodInSight(const Unit* unit,int* x,int* y)
+global int FindWoodInSight(const Unit* unit, int* x, int* y)
 {
-    return FindTerrainType(UnitMovementMask(unit),0,MapFieldForest,9999,
-           unit->Player,unit->X,unit->Y,x,y);
+    return FindTerrainType(UnitMovementMask(unit), 0, MapFieldForest, 9999,
+       unit->Player, unit->X, unit->Y, x, y);
 }
 
 /**
@@ -3718,7 +3722,7 @@
     int InRun, RunStart;
 
     CLprintf(file,"\n;;; -----------------------------------------\n");
-    CLprintf(file,";;; MODULE: units $Id: unit.c,v 1.310 2003/10/17 06:04:30 
mr-russ Exp $\n\n");
+    CLprintf(file,";;; MODULE: units $Id: unit.c,v 1.311 2003/10/20 23:06:03 
jsalmon3 Exp $\n\n");
 
     //
     // Local variables
Index: stratagus/src/clone/unitcache.c
diff -u stratagus/src/clone/unitcache.c:1.37 
stratagus/src/clone/unitcache.c:1.38
--- stratagus/src/clone/unitcache.c:1.37        Thu Sep 18 13:56:03 2003
+++ stratagus/src/clone/unitcache.c     Mon Oct 20 19:06:03 2003
@@ -33,7 +33,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: unitcache.c,v 1.37 2003/09/18 17:56:03 n0body Exp $
+//     $Id: unitcache.c,v 1.38 2003/10/20 23:06:03 jsalmon3 Exp $
 
 //@{
 
@@ -254,7 +254,7 @@
 **     Insert a new value into the quad-tree.
 **     Generate branches if needed.
 */
-local void QuadTreeInsert(QuadTree* tree,QuadTreeValue* value)
+local void QuadTreeInsert(QuadTree* tree, QuadTreeValue* value)
 {
     QuadTreeLeaf* leaf;
     QuadTreeNode** nodep;
@@ -263,33 +263,33 @@
 
     StatisticInsert(tree);
 
-    nodep=&tree->Root;
+    nodep = &tree->Root;
     //
     // Generate branches.
     //
-    for( level=tree->Levels-1; level>=0; level-- ) {
-       if( !*nodep ) {
+    for (level = tree->Levels - 1; level >= 0; --level) {
+       if (!*nodep) {
            StatisticNewNode(tree);
-           *nodep=NewQuadTreeNode();
+           *nodep = NewQuadTreeNode();
        }
-       branch=((QuadTreeValueXOf(value) >> level)&1)
-           | (((QuadTreeValueYOf(value) >> level)&1)<<1);
-       nodep=&(*nodep)->Next[branch];
+       branch = ((QuadTreeValueXOf(value) >> level) & 1) |
+           (((QuadTreeValueYOf(value) >> level) & 1) << 1);
+       nodep = &(*nodep)->Next[branch];
     }
 
     //
     // Insert at leaf.
     //
     StatisticNewLeaf(tree);
-    leaf=NewQuadTreeLeaf(value,(QuadTreeLeaf*)(*nodep));
-    IfDebug(
-       if( leaf->Next ) {
-           DebugLevel3("More...\n");
-           DebugLevel3("Leaf: %p %p," _C_ leaf _C_ leaf->Value);
-           DebugLevel3("Leaf: %p %p\n" _C_ leaf->Next _C_ leaf->Next->Value);
-       }
-    );
-    *nodep=(QuadTreeNode*)leaf;
+    leaf = NewQuadTreeLeaf(value, (QuadTreeLeaf*)(*nodep));
+#ifdef DEBUG
+    if (leaf->Next) {
+       DebugLevel3("More...\n");
+       DebugLevel3("Leaf: %p %p," _C_ leaf _C_ leaf->Value);
+       DebugLevel3("Leaf: %p %p\n" _C_ leaf->Next _C_ leaf->Next->Value);
+    }
+#endif
+    *nodep = (QuadTreeNode*)leaf;
 }
 
 /**
@@ -603,7 +603,11 @@
 */
 local void QuadTreePrintStatistic(QuadTree* tree)
 {
-    IfDebug(if (!tree) return;)
+#ifdef DEBUG
+    if (!tree) {
+       return;
+    }
+#endif
     DebugLevel0("Quad-Tree: %p Levels %d\n" _C_ tree _C_ tree->Levels);
     DebugLevel0("\tInserts %d, deletes %d\n"
        _C_ tree->Inserts _C_ tree->Deletes);
@@ -724,26 +728,26 @@
 **
 **     @return         Unit, if an unit of correct type is on the field.
 */
-global Unit* UnitCacheOnXY(int x,int y,unsigned type)
+global Unit* UnitCacheOnXY(int x, int y, unsigned type)
 {
     QuadTreeLeaf* leaf;
 
-    leaf=QuadTreeSearch(PositionCache,x,y);
-    while( leaf ) {
-       IfDebug(
-           // FIXME: the error isn't here!
-           if( !leaf->Value->Type ) {
-               DebugLevel0("Error UNIT %8p %08X %d,%d\n" _C_ leaf->Value
-                       _C_ UnitNumber(leaf->Value) _C_ leaf->Value->X _C_ 
leaf->Value->Y);
-               DebugLevel0("Removed unit in cache %d,%d!!!!\n" _C_ x _C_ y);
-               leaf=leaf->Next;
-               continue;
-           }
-       );
-       if( leaf->Value->Type->UnitType==type ) {
+    leaf = QuadTreeSearch(PositionCache, x, y);
+    while (leaf) {
+#ifdef DEBUG
+       // FIXME: the error isn't here!
+       if (!leaf->Value->Type) {
+           DebugLevel0("Error UNIT %8p %08X %d,%d\n" _C_ leaf->Value _C_
+               UnitNumber(leaf->Value) _C_ leaf->Value->X _C_ leaf->Value->Y);
+           DebugLevel0("Removed unit in cache %d,%d!!!!\n" _C_ x _C_ y);
+           leaf = leaf->Next;
+           continue;
+       }
+#endif
+       if (leaf->Value->Type->UnitType == type) {
            return leaf->Value;
        }
-       leaf=leaf->Next;
+       leaf = leaf->Next;
     }
     return NoUnitP;
 }
@@ -896,7 +900,7 @@
 **     @return         Returns the number of units found
 */
 //#include "rdtsc.h"
-global int UnitCacheSelect(int x1,int y1,int x2,int y2,Unit** table)
+global int UnitCacheSelect(int x1, int y1, int x2, int y2, Unit** table)
 {
     int x;
     int y;
@@ -904,53 +908,58 @@
     int i;
     Unit* unit;
     MapField* mf;
-
-//  int ts0=rdtsc(), ts1;
+//  int ts0 = rdtsc(), ts1;
 
     DebugLevel3Fn("%d,%d %d,%d\n" _C_ x1 _C_ y1 _C_ x2 _C_ y2);
     //
     // Units are inserted by origin position
     //
-    x=x1-4; if( x<0 ) x=0;             // Only for current unit-cache !!
-    y=y1-4; if( y<0 ) y=0;
+    x = x1 - 4;
+    if (x < 0) {
+       x = 0;          // Only for current unit-cache !!
+    }
+    y = y1 - 4;
+    if (y < 0) {
+       y = 0;
+    }
 
     //
     // Reduce to map limits. FIXME: should the caller check?
     //
-    if( x2>TheMap.Width ) {
-       x2=TheMap.Width;
+    if (x2 > TheMap.Width) {
+       x2 = TheMap.Width;
     }
-    if( y2>TheMap.Height ) {
-       y2=TheMap.Height;
+    if (y2 > TheMap.Height) {
+       y2 = TheMap.Height;
     }
 
-    for( n=0; y<y2; ++y ) {
-       mf=TheMap.Fields+y*TheMap.Width+x;
-       for( i=x; i<x2; ++i ) {
-
-           for( unit=mf->Here.Units; unit; unit=unit->Next ) {
-               IfDebug(
-                   if( !unit->Type ) {
-                       DebugLevel0Fn("%d,%d: %d, %d,%d\n"
-                           _C_ i _C_ y _C_ UnitNumber(unit) _C_ unit->X _C_ 
unit->Y);
-                       fflush(stdout);
-                   }
-               );
+    for (n = 0; y < y2; ++y) {
+       mf = TheMap.Fields + y * TheMap.Width + x;
+       for (i = x; i < x2; ++i) {
+
+           for (unit = mf->Here.Units; unit; unit = unit->Next) {
+#ifdef DEBUG
+               if (!unit->Type) {
+                   DebugLevel0Fn("%d,%d: %d, %d,%d\n" _C_ i _C_ y _C_
+                       UnitNumber(unit) _C_ unit->X _C_ unit->Y);
+                   fflush(stdout);
+               }
+#endif
                //
                //      Remove units, outside range.
                //
-               if( unit->X+unit->Type->TileWidth<=x1 || unit->X>x2
-                       || unit->Y+unit->Type->TileHeight<=y1 || unit->Y>y2 ) {
+               if (unit->X + unit->Type->TileWidth <= x1 || unit->X > x2 ||
+                       unit->Y + unit->Type->TileHeight <= y1 || unit->Y > y2) 
{
                    continue;
                }
-               table[n++]=unit;
+               table[n++] = unit;
            }
            ++mf;
        }
     }
 
-//  ts1 = rdtsc ();
-//  printf ("UnitCacheSelect on %dx%d took %d cycles\n", x2-x1, y2-y1, 
ts1-ts0);
+//  ts1 = rdtsc();
+//  printf("UnitCacheSelect on %dx%d took %d cycles\n", x2 - x1, y2 - y1, ts1 
- ts0);
 
     return n;
 }
@@ -964,9 +973,9 @@
 **
 **     @return         Returns the number of units found
 */
-global int UnitCacheOnTile(int x,int y,Unit** table)
+global int UnitCacheOnTile(int x, int y, Unit** table)
 {
-    return UnitCacheSelect(x,y,x+1,y+1,table);
+    return UnitCacheSelect(x, y, x + 1, y + 1, table);
 }
 
 /**
@@ -978,18 +987,18 @@
 **
 **     @return         Unit, if an unit of correct type is on the field.
 */
-global Unit* UnitCacheOnXY(int x,int y,unsigned type)
+global Unit* UnitCacheOnXY(int x, int y, unsigned type)
 {
     Unit* table[UnitMax];
     int n;
 
-    n = UnitCacheOnTile(x,y,table);
-    while( n-- ) {
-       if( (unsigned)table[n]->Type->UnitType==type ) {
+    n = UnitCacheOnTile(x, y, table);
+    while (n--) {
+       if ((unsigned)table[n]->Type->UnitType == type) {
            break;
        }
     }
-    if( n > -1 ) {
+    if (n > -1) {
        return table[n];
     } else {
        return NoUnitP;
Index: stratagus/src/ui/menus.c
diff -u stratagus/src/ui/menus.c:1.569 stratagus/src/ui/menus.c:1.570
--- stratagus/src/ui/menus.c:1.569      Sat Oct 18 12:35:19 2003
+++ stratagus/src/ui/menus.c    Mon Oct 20 19:06:04 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: menus.c,v 1.569 2003/10/18 16:35:19 jsalmon3 Exp $
+//     $Id: menus.c,v 1.570 2003/10/20 23:06:04 jsalmon3 Exp $
 
 //@{
 
@@ -2803,7 +2803,7 @@
 local void CampaignGameMenu(void)
 {
     int i;
-    Menu *menu;
+    Menu* menu;
 
     VideoLockScreen();
     MenusSetBackground();
@@ -2812,30 +2812,30 @@
 
     menu = FindMenu("menu-campaign-select");
     DebugLevel0Fn("%d campaigns available\n" _C_ NumCampaigns);
-    IfDebug(
-       for( i=0; i<NumCampaigns; ++i ) {
-           DebugLevel0Fn("Campaign %d: %16.16s: %s\n" _C_ i _C_
-               Campaigns[i].Ident _C_
-               Campaigns[i].Name);
-       }
-    );
+#ifdef DEBUG
+    for (i = 0; i < NumCampaigns; ++i) {
+       DebugLevel0Fn("Campaign %d: %16.16s: %s\n" _C_ i _C_
+           Campaigns[i].Ident _C_
+           Campaigns[i].Name);
+    }
+#endif
 
     //
     // Setup campaign name.
     //
-    for( i=0; i<NumCampaigns && i<4; ++i ) {
+    for (i = 0; i < NumCampaigns && i < 4; ++i) {
        char* s;
 
-       menu->Items[i].d.button.text=Campaigns[i].Name;
-       menu->Items[i].flags&=~MenuButtonDisabled;
+       menu->Items[i].d.button.text = Campaigns[i].Name;
+       menu->Items[i].flags &= ~MenuButtonDisabled;
 
-       if( (s=strchr(Campaigns[i].Name,'!')) ) {
-           menu->Items[i].d.button.hotkey=tolower(s[1]);
+       if ((s = strchr(Campaigns[i].Name, '!'))) {
+           menu->Items[i].d.button.hotkey = tolower(s[1]);
        }
     }
-    for( ; i<4; ++i ) {
-       menu->Items[i].d.button.text="Not available";
-       menu->Items[i].flags|=MenuButtonDisabled;
+    for (; i < 4; ++i) {
+       menu->Items[i].d.button.text = "Not available";
+       menu->Items[i].flags |= MenuButtonDisabled;
     }
 
     GuiGameStarted = 0;
@@ -2844,8 +2844,8 @@
        GameMenuReturn();
     }
 
-    for( i=0; i<4; ++i ) {
-       menu->Items[i].d.button.text=NULL;
+    for (i = 0; i < 4; ++i) {
+       menu->Items[i].d.button.text = NULL;
     }
 }
 




reply via email to

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