stratagus-cvs
[Top][All Lists]
Advanced

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

[Stratagus-CVS] stratagus/src ai/ai_building.c ai/ai_force.c ai...


From: ludovic p
Subject: [Stratagus-CVS] stratagus/src ai/ai_building.c ai/ai_force.c ai...
Date: Sun, 26 Oct 2003 15:36:53 -0000

CVSROOT:        /cvsroot/stratagus
Module name:    stratagus
Branch:         
Changes by:     ludovic p <address@hidden>      03/10/26 10:34:59

Modified files:
        src/ai         : ai_building.c ai_force.c ai_local.h ai_magic.c 
                         ai_plan.c ai_resource.c ai_rules.c ccl_ai.c 
                         new_ai.c 
        src/clone      : ccl_helpers.c 
        src/include    : ccl_helpers.h 

Log message:
        Fixed spacing in AI

Patches:
Index: stratagus/src/ai/ai_building.c
diff -u stratagus/src/ai/ai_building.c:1.42 stratagus/src/ai/ai_building.c:1.43
--- stratagus/src/ai/ai_building.c:1.42 Fri Oct 24 02:28:54 2003
+++ stratagus/src/ai/ai_building.c      Sun Oct 26 10:34:58 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//      $Id: ai_building.c,v 1.42 2003/10/24 06:28:54 mr-russ Exp $
+//      $Id: ai_building.c,v 1.43 2003/10/26 15:34:58 pludov Exp $
 
 //@{
 
@@ -75,46 +75,43 @@
     --x;
     --y;
 
-    for (i = 0; i < w; ++i) {  // Top row
+    for (i = 0; i < w; ++i) {          // Top row
        // FIXME: (pludov) slow, worse,...
        if (x + i < 0 || x + i > TheMap.Width) {
            continue;
        }
-       if (!(x + i == worker->X && y == worker->Y ) && y >= 0 &&
+       if (!(x + i == worker->X && y == worker->Y) && y >= 0 &&
            TheMap.Fields[x + i + y * TheMap.Width].Flags &
-               (MapFieldUnpassable | MapFieldWall | MapFieldRocks |
-                   MapFieldForest | MapFieldBuilding)) {
+           (MapFieldUnpassable | MapFieldWall | MapFieldRocks |
+               MapFieldForest | MapFieldBuilding)) {
            return 0;
-       }                       // Bot row
-       if (!(x + i == worker->X && y + h == worker->Y ) && y + h < 
TheMap.Height &&
+       }                               // Bot row
+       if (!(x + i == worker->X && y + h == worker->Y) && y + h < 
TheMap.Height &&
            TheMap.Fields[x + i + (y + h) * TheMap.Width].Flags &
-               (MapFieldUnpassable | MapFieldWall | MapFieldRocks |
-                   MapFieldForest | MapFieldBuilding)) {
+           (MapFieldUnpassable | MapFieldWall | MapFieldRocks |
+               MapFieldForest | MapFieldBuilding)) {
            return 0;
        }
     }
 
     ++y;
     h -= 2;
-    for (i = 0; i < h; ++i) {  // Left row
+    for (i = 0; i < h; ++i) {          // Left row
        // FIXME: (pludov) slow, worse,...
        if (y + i < 0 || y + i > TheMap.Height) {
            continue;
        }
-       if (!( x == worker->X && ( y + i ) == worker->Y ) && x >= 0 &&
-            TheMap.Fields[x + ( y + i ) * TheMap.Width].Flags & ( 
MapFieldUnpassable |
-                                                                  MapFieldWall 
| MapFieldRocks
-                                                                  | 
MapFieldForest |
-                                                                  
MapFieldBuilding ) ) {
+       if (!(x == worker->X && (y + i) == worker->Y) && x >= 0 &&
+           TheMap.Fields[x + (y + i) * TheMap.Width].Flags & 
(MapFieldUnpassable |
+               MapFieldWall | MapFieldRocks | MapFieldForest | 
MapFieldBuilding)) {
            return 0;
-       }                       // Right row
-       if ( !( ( x + w ) == worker->X && ( y + i ) == worker->Y ) && ( x + w ) 
< TheMap.Width
-            && TheMap.Fields[x + w +
-                             ( y +
-                               i ) *
-                             TheMap.Width].
-            Flags & ( MapFieldUnpassable | MapFieldWall | MapFieldRocks | 
MapFieldForest |
-                      MapFieldBuilding ) ) {
+       }                               // Right row
+       if (!((x + w) == worker->X && (y + i) == worker->Y) && (x + w) < 
TheMap.Width
+           && TheMap.Fields[x + w +
+               (y + i) *
+               TheMap.Width].
+           Flags & (MapFieldUnpassable | MapFieldWall | MapFieldRocks | 
MapFieldForest |
+               MapFieldBuilding)) {
            return 0;
        }
     }
@@ -134,8 +131,8 @@
 **
 **     @note   This can be done faster, use flood fill.
 */
-local int AiFindBuildingPlace2( const Unit * worker, const UnitType * type,
-                               int *dx, int *dy, int flag )
+local int AiFindBuildingPlace2(const Unit * worker, const UnitType * type,
+    int *dx, int *dy, int flag)
 {
     int wx;
     int wy;
@@ -155,44 +152,44 @@
 
     state = 0;
     end = y + addy - 1;
-    for ( ;; ) {               // test rectangles around the place
-       switch ( state ) {
-       case 0:
-           if ( y++ == end ) {
-               ++state;
-               end = x + addx++;
-           }
-           break;
-       case 1:
-           if ( x++ == end ) {
-               ++state;
-               end = y - addy++;
-           }
-           break;
-       case 2:
-           if ( y-- == end ) {
-               ++state;
-               end = x - addx++;
-           }
-           break;
-       case 3:
-           if ( x-- == end ) {
-               state = 0;
-               end = y + addy++;
-               if ( addx >= TheMap.Width && addy >= TheMap.Height ) {
-                   return 0;
+    for (;;) {                         // test rectangles around the place
+       switch (state) {
+           case 0:
+               if (y++ == end) {
+                   ++state;
+                   end = x + addx++;
                }
-           }
-           break;
+               break;
+           case 1:
+               if (x++ == end) {
+                   ++state;
+                   end = y - addy++;
+               }
+               break;
+           case 2:
+               if (y-- == end) {
+                   ++state;
+                   end = x - addx++;
+               }
+               break;
+           case 3:
+               if (x-- == end) {
+                   state = 0;
+                   end = y + addy++;
+                   if (addx >= TheMap.Width && addy >= TheMap.Height) {
+                       return 0;
+                   }
+               }
+               break;
        }
 
-       // FIXME: this check outside the map could be speeded up.
-       if ( y < 0 || x < 0 || y >= TheMap.Height || x >= TheMap.Width ) {
+       // FIXME: this check outside the map could be speeded up.
+       if (y < 0 || x < 0 || y >= TheMap.Height || x >= TheMap.Width) {
            continue;
        }
-       if ( CanBuildUnitType( worker, type, x, y ) &&
-            ( !flag || AiCheckSurrounding( worker, type, x, y ) ) &&
-            PlaceReachable( worker, x, y, 1 ) ) {
+       if (CanBuildUnitType(worker, type, x, y) &&
+           (!flag || AiCheckSurrounding(worker, type, x, y)) &&
+           PlaceReachable(worker, x, y, 1)) {
            *dx = x;
            *dy = y;
            return 1;
@@ -215,17 +212,15 @@
 **     @param flag     Flag if surrounding must be free.
 **     @return         True if place found, false if no found.
 */
-local int AiFindBuildingPlace2( const Unit * worker, const UnitType * type,
-                               int ox, int oy, int *dx, int *dy, int flag )
+local int AiFindBuildingPlace2(const Unit * worker, const UnitType * type,
+    int ox, int oy, int *dx, int *dy, int flag)
 {
     static const int xoffset[] = { 0, -1, +1, 0, -1, +1, -1, +1 };
     static const int yoffset[] = { -1, 0, 0, +1, -1, -1, +1, +1 };
-    struct
-    {
+    struct {
        unsigned short X;
        unsigned short Y;
-    }
-    *points;
+    }     *points;
     int size;
     int x;
     int y;
@@ -240,103 +235,103 @@
     unsigned char *m;
     unsigned char *matrix;
 
-    points = malloc( TheMap.Width * TheMap.Height );
-    size = TheMap.Width * TheMap.Height / sizeof ( *points );
+    points = malloc(TheMap.Width * TheMap.Height);
+    size = TheMap.Width * TheMap.Height / sizeof (*points);
 
     x = ox;
     y = oy;
-   //
-   //  Look if we can build at current place.
-   //
-    if ( CanBuildUnitType( worker, type, x, y ) &&
-        ( !flag || AiCheckSurrounding( worker, type, x, y ) ) ) {
+    //
+    //  Look if we can build at current place.
+    //
+    if (CanBuildUnitType(worker, type, x, y) &&
+       (!flag || AiCheckSurrounding(worker, type, x, y))) {
        *dx = x;
        *dy = y;
-       free( points );
+       free(points);
        return 1;
     }
-   //
-   //  Make movement matrix.
-   //
+    //
+    //  Make movement matrix.
+    //
     matrix = CreateMatrix();
     w = TheMap.Width + 2;
 
-    mask = UnitMovementMask( worker );
-   // Ignore all possible mobile units.
-    mask &= ~( MapFieldLandUnit | MapFieldAirUnit | MapFieldSeaUnit );
+    mask = UnitMovementMask(worker);
+    // Ignore all possible mobile units.
+    mask &= ~(MapFieldLandUnit | MapFieldAirUnit | MapFieldSeaUnit);
 
     points[0].X = x;
     points[0].Y = y;
-   // also use the bottom right
-    if ( type->TileWidth > 1 && x + type->TileWidth - 1 < TheMap.Width &&
-        y + type->TileHeight - 1 < TheMap.Height ) {
+    // also use the bottom right
+    if (type->TileWidth > 1 && x + type->TileWidth - 1 < TheMap.Width &&
+       y + type->TileHeight - 1 < TheMap.Height) {
        points[1].X = x + type->TileWidth - 1;
        points[1].Y = y + type->TileWidth - 1;
-       ep = wp = 2;            // start with two points
+       ep = wp = 2;                    // start with two points
     } else {
-       ep = wp = 1;            // start with one point
+       ep = wp = 1;                    // start with one point
     }
     matrix += w + w + 2;
     rp = 0;
-    matrix[x + y * w] = 1;     // mark start point
+    matrix[x + y * w] = 1;             // mark start point
 
-   //
-   //  Pop a point from stack, push all neighbours which could be entered.
-   //
-    for ( ;; ) {
-       while ( rp != ep ) {
+    //
+    //  Pop a point from stack, push all neighbours which could be entered.
+    //
+    for (;;) {
+       while (rp != ep) {
            rx = points[rp].X;
            ry = points[rp].Y;
-           for ( i = 0; i < 8; ++i ) { // mark all neighbors
+           for (i = 0; i < 8; ++i) {   // mark all neighbors
                x = rx + xoffset[i];
                y = ry + yoffset[i];
                m = matrix + x + y * w;
-               if ( *m ) {     // already checked
+               if (*m) {               // already checked
                    continue;
                }
 
-               DebugLevel3Fn( "Checking to build %s(%s) at %d,%d\n" _C_
-                              type->Ident _C_ type->Name _C_ x _C_ y );
+               DebugLevel3Fn("Checking to build %s(%s) at %d,%d\n" _C_
+                   type->Ident _C_ type->Name _C_ x _C_ y);
 
-              //
-              //      Look if we can build here.
-              //
-               if ( CanBuildUnitType( worker, type, x, y ) &&
-                    ( !flag || AiCheckSurrounding( worker, type, x, y ) ) ) {
+               //
+               //      Look if we can build here.
+               //
+               if (CanBuildUnitType(worker, type, x, y) &&
+                   (!flag || AiCheckSurrounding(worker, type, x, y))) {
                    *dx = x;
                    *dy = y;
-                   free( points );
-                   DebugLevel3Fn( "Found a building place!!!\n" );
+                   free(points);
+                   DebugLevel3Fn("Found a building place!!!\n");
                    return 1;
                }
 
-               if ( CanMoveToMask( x, y, mask ) ) {    // reachable
+               if (CanMoveToMask(x, y, mask)) {        // reachable
                    *m = 1;
                    points[wp].X = x;   // push the point
                    points[wp].Y = y;
-                   if ( ++wp >= size ) {       // round about
+                   if (++wp >= size) { // round about
                        wp = 0;
                    }
-               } else {        // unreachable
+               } else {                // unreachable
                    *m = 99;
                }
            }
 
-           if ( ++rp >= size ) {       // round about
+           if (++rp >= size) {         // round about
                rp = 0;
            }
        }
 
-       //
-       //      Continue with next frame.
-       //
-       if ( rp == wp ) {       // unreachable, no more points available
+       //
+       //      Continue with next frame.
+       //
+       if (rp == wp) {                 // unreachable, no more points available
            break;
        }
        ep = wp;
     }
 
-    free( points );
+    free(points);
 
     return 0;
 }
@@ -362,16 +357,14 @@
 **     @todo   FIXME: This is slow really slow, using two flood fills, is not
 **             a perfect solution.
 */
-local int AiFindHallPlace( const Unit * worker, const UnitType * type, int 
*dx, int *dy )
+local int AiFindHallPlace(const Unit * worker, const UnitType * type, int *dx, 
int *dy)
 {
     static const int xoffset[] = { 0, -1, +1, 0, -1, +1, -1, +1 };
     static const int yoffset[] = { -1, 0, 0, +1, -1, -1, +1, +1 };
-    struct
-    {
+    struct {
        unsigned short X;
        unsigned short Y;
-    }
-    *points;
+    }     *points;
     int size;
     int x;
     int y;
@@ -393,11 +386,11 @@
     destx = x = worker->X;
     desty = y = worker->Y;
     size = TheMap.Width * TheMap.Height / 4;
-    points = malloc( size * sizeof ( *points ) );
+    points = malloc(size * sizeof (*points));
 
-   //
-   //  Make movement matrix. FIXME: can create smaller matrix.
-   //
+    //
+    //  Make movement matrix. FIXME: can create smaller matrix.
+    //
     morg = MakeMatrix();
     w = TheMap.Width + 2;
     matrix = morg + w + w + 2;
@@ -405,29 +398,29 @@
     points[0].X = x;
     points[0].Y = y;
     rp = 0;
-    matrix[x + y * w] = 1;     // mark start point
-    ep = wp = 1;               // start with one point
+    matrix[x + y * w] = 1;             // mark start point
+    ep = wp = 1;                       // start with one point
 
-    mask = UnitMovementMask( worker );
+    mask = UnitMovementMask(worker);
 
-   //
-   //  Pop a point from stack, push all neighbors which could be entered.
-   //
-    for ( ;; ) {
-       while ( rp != ep ) {
+    //
+    //  Pop a point from stack, push all neighbors which could be entered.
+    //
+    for (;;) {
+       while (rp != ep) {
            rx = points[rp].X;
            ry = points[rp].Y;
-           for ( i = 0; i < 8; ++i ) { // mark all neighbors
+           for (i = 0; i < 8; ++i) {   // mark all neighbors
                x = rx + xoffset[i];
                y = ry + yoffset[i];
                m = matrix + x + y * w;
-               if ( *m ) {     // already checked
+               if (*m) {               // already checked
                    continue;
                }
-              //
-              //      Look if there is a mine
-              //
-               if ( ( mine = ResourceOnMap( x, y, GoldCost ) ) ) {
+               //
+               //      Look if there is a mine
+               //
+               if ((mine = ResourceOnMap(x, y, GoldCost))) {
                    int buildings;
                    int j;
                    int minx;
@@ -439,82 +432,82 @@
 
                    buildings = 0;
 
-                  //
-                  //  Check units around mine
-                  //
+                   //
+                   //  Check units around mine
+                   //
                    minx = mine->X - 5;
-                   if ( minx < 0 ) {
+                   if (minx < 0) {
                        minx = 0;
                    }
                    miny = mine->Y - 5;
-                   if ( miny < 0 ) {
+                   if (miny < 0) {
                        miny = 0;
                    }
                    maxx = mine->X + mine->Type->TileWidth + 5;
-                   if ( maxx > TheMap.Width ) {
+                   if (maxx > TheMap.Width) {
                        maxx = TheMap.Width;
                    }
                    maxy = mine->Y + mine->Type->TileHeight + 5;
-                   if ( maxy > TheMap.Height ) {
+                   if (maxy > TheMap.Height) {
                        maxy = TheMap.Height;
                    }
 
-                   nunits = SelectUnits( minx, miny, maxx, maxy, units );
-                   for ( j = 0; j < nunits; ++j ) {
-                      // Enemy near mine
-                       if ( AiPlayer->Player->Enemy & ( 1 << 
units[j]->Player->Player ) ) {
+                   nunits = SelectUnits(minx, miny, maxx, maxy, units);
+                   for (j = 0; j < nunits; ++j) {
+                       // Enemy near mine
+                       if (AiPlayer->Player->Enemy & (1 << 
units[j]->Player->Player)) {
                            break;
                        }
-                      // Town hall near mine
-                       if ( units[j]->Type->CanStore[GoldCost] ) {
+                       // Town hall near mine
+                       if (units[j]->Type->CanStore[GoldCost]) {
                            break;
                        }
-                      // Town hall may not be near but we may be using it, 
check
-                      // for 2 buildings near it and assume it's been used
-                       if ( units[j]->Type->Building &&
-                            !units[j]->Type->GivesResource == GoldCost ) {
+                       // Town hall may not be near but we may be using it, 
check
+                       // for 2 buildings near it and assume it's been used
+                       if (units[j]->Type->Building &&
+                           !units[j]->Type->GivesResource == GoldCost) {
                            ++buildings;
-                           if ( buildings == 2 ) {
+                           if (buildings == 2) {
                                break;
                            }
                        }
                    }
-                   if ( j == nunits ) {
-                       if ( AiFindBuildingPlace2( worker, type, x, y, dx, dy, 
0 ) ) {
-                           free( morg );
-                           free( points );
+                   if (j == nunits) {
+                       if (AiFindBuildingPlace2(worker, type, x, y, dx, dy, 
0)) {
+                           free(morg);
+                           free(points);
                            return 1;
                        }
                    }
                }
 
-               if ( CanMoveToMask( x, y, mask ) ) {    // reachable
+               if (CanMoveToMask(x, y, mask)) {        // reachable
                    *m = 1;
                    points[wp].X = x;   // push the point
                    points[wp].Y = y;
-                   if ( ++wp >= size ) {       // round about
+                   if (++wp >= size) { // round about
                        wp = 0;
                    }
-               } else {        // unreachable
+               } else {                // unreachable
                    *m = 99;
                }
            }
-           if ( ++rp >= size ) {       // round about
+           if (++rp >= size) {         // round about
                rp = 0;
            }
        }
 
-       //
-       //      Continue with next frame.
-       //
-       if ( rp == wp ) {       // unreachable, no more points available
+       //
+       //      Continue with next frame.
+       //
+       if (rp == wp) {                 // unreachable, no more points available
            break;
        }
        ep = wp;
     }
 
-    free( morg );
-    free( points );
+    free(morg);
+    free(points);
     return 0;
 }
 
@@ -530,16 +523,15 @@
 **     @todo   FIXME: This is slow really slow, using two flood fills, is not
 **             a perfect solution.
 */
-local int AiFindLumberMillPlace( const Unit * worker, const UnitType * type, 
int *dx, int *dy )
+local int AiFindLumberMillPlace(const Unit * worker, const UnitType * type, 
int *dx,
+    int *dy)
 {
     static const int xoffset[] = { 0, -1, +1, 0, -1, +1, -1, +1 };
     static const int yoffset[] = { -1, 0, 0, +1, -1, -1, +1, +1 };
-    struct
-    {
+    struct {
        unsigned short X;
        unsigned short Y;
-    }
-    *points;
+    }     *points;
     int size;
     int x;
     int y;
@@ -558,11 +550,11 @@
     x = worker->X;
     y = worker->Y;
     size = TheMap.Width * TheMap.Height / 4;
-    points = malloc( size * sizeof ( *points ) );
+    points = malloc(size * sizeof (*points));
 
-   //
-   //  Make movement matrix.
-   //
+    //
+    //  Make movement matrix.
+    //
     morg = MakeMatrix();
     w = TheMap.Width + 2;
     matrix = morg + w + w + 2;
@@ -570,64 +562,64 @@
     points[0].X = x;
     points[0].Y = y;
     rp = 0;
-    matrix[x + y * w] = 1;     // mark start point
-    ep = wp = 1;               // start with one point
+    matrix[x + y * w] = 1;             // mark start point
+    ep = wp = 1;                       // start with one point
 
-    mask = UnitMovementMask( worker );
+    mask = UnitMovementMask(worker);
 
-   //
-   //  Pop a point from stack, push all neightbors which could be entered.
-   //
-    for ( ;; ) {
-       while ( rp != ep ) {
+    //
+    //  Pop a point from stack, push all neightbors which could be entered.
+    //
+    for (;;) {
+       while (rp != ep) {
            rx = points[rp].X;
            ry = points[rp].Y;
-           for ( i = 0; i < 8; ++i ) { // mark all neighbors
+           for (i = 0; i < 8; ++i) {   // mark all neighbors
                x = rx + xoffset[i];
                y = ry + yoffset[i];
                m = matrix + x + y * w;
-               if ( *m ) {     // already checked
+               if (*m) {               // already checked
                    continue;
                }
-              //
-              //      Look if there is wood
-              //
-               if ( ForestOnMap( x, y ) ) {
-                   if ( AiFindBuildingPlace2( worker, type, x, y, dx, dy, 1 ) 
) {
-                       free( morg );
-                       free( points );
+               //
+               //      Look if there is wood
+               //
+               if (ForestOnMap(x, y)) {
+                   if (AiFindBuildingPlace2(worker, type, x, y, dx, dy, 1)) {
+                       free(morg);
+                       free(points);
                        return 1;
                    }
                }
 
-               if ( CanMoveToMask( x, y, mask ) ) {    // reachable
+               if (CanMoveToMask(x, y, mask)) {        // reachable
                    *m = 1;
                    points[wp].X = x;   // push the point
                    points[wp].Y = y;
-                   if ( ++wp >= size ) {       // round about
+                   if (++wp >= size) { // round about
                        wp = 0;
                    }
-               } else {        // unreachable
+               } else {                // unreachable
                    *m = 99;
                }
            }
 
-           if ( ++rp >= size ) {       // round about
+           if (++rp >= size) {         // round about
                rp = 0;
            }
        }
 
-       //
-       //      Continue with next frame.
-       //
-       if ( rp == wp ) {       // unreachable, no more points available
+       //
+       //      Continue with next frame.
+       //
+       if (rp == wp) {                 // unreachable, no more points available
            break;
        }
        ep = wp;
     }
 
-    free( morg );
-    free( points );
+    free(morg);
+    free(points);
     return 0;
 }
 
@@ -643,34 +635,36 @@
 **     @todo   Better and faster way to find building place of oil platforms
 **             Special routines for special buildings.
 */
-global int AiFindBuildingPlace( const Unit * worker, const UnitType * type, 
int *dx, int *dy )
+global int AiFindBuildingPlace(const Unit * worker, const UnitType * type, int 
*dx,
+    int *dy)
 {
 
-   //
-   //  Find a good place for a new hall
-   //
-    DebugLevel0Fn( "Want to build a %s(%s)\n" _C_ type->Ident _C_ type->Name );
-    if ( type->CanStore[GoldCost] && AiFindHallPlace( worker, type, dx, dy ) ) 
{
-       DebugLevel0Fn( "Found place for town hall (%s,%s)\n" _C_ type->Ident 
_C_ type->Name );
+    //
+    //  Find a good place for a new hall
+    //
+    DebugLevel0Fn("Want to build a %s(%s)\n" _C_ type->Ident _C_ type->Name);
+    if (type->CanStore[GoldCost] && AiFindHallPlace(worker, type, dx, dy)) {
+       DebugLevel0Fn("Found place for town hall (%s,%s)\n" _C_ type->Ident _C_ 
type->
+           Name);
        return 1;
     }
-   //
-   //  Find a place near wood for a lumber mill
-   //
-    if ( type->CanStore[WoodCost] && AiFindLumberMillPlace( worker, type, dx, 
dy ) ) {
+    //
+    //  Find a place near wood for a lumber mill
+    //
+    if (type->CanStore[WoodCost] && AiFindLumberMillPlace(worker, type, dx, 
dy)) {
        return 1;
     }
-   //
-   //  Platforms can only be built on oil patches
-   //
-    if ( type->GivesResource != OilCost &&
-        AiFindBuildingPlace2( worker, type, worker->X, worker->Y, dx, dy, 1 ) 
) {
+    //
+    //  Platforms can only be built on oil patches
+    //
+    if (type->GivesResource != OilCost &&
+       AiFindBuildingPlace2(worker, type, worker->X, worker->Y, dx, dy, 1)) {
        return 1;
     }
-   // FIXME: Should do this if all units can't build better!
-    return AiFindBuildingPlace2( worker, type, worker->X, worker->Y, dx, dy, 0 
);
+    // FIXME: Should do this if all units can't build better!
+    return AiFindBuildingPlace2(worker, type, worker->X, worker->Y, dx, dy, 0);
 
-   // return 0;
+    // return 0;
 }
 
 //@}
Index: stratagus/src/ai/ai_force.c
diff -u stratagus/src/ai/ai_force.c:1.35 stratagus/src/ai/ai_force.c:1.36
--- stratagus/src/ai/ai_force.c:1.35    Thu Oct 23 14:38:34 2003
+++ stratagus/src/ai/ai_force.c Sun Oct 26 10:34:58 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//      $Id: ai_force.c,v 1.35 2003/10/23 18:38:34 n0body Exp $
+//      $Id: ai_force.c,v 1.36 2003/10/26 15:34:58 pludov Exp $
 
 //@{
 
@@ -63,20 +63,20 @@
 **     @param force            the force to count unit
 **     @param countByType      array[UnitTypeMax+1] of int
 */
-global void AiForceCountUnits( int force, int *countByType )
+global void AiForceCountUnits(int force, int *countByType)
 {
     int type;
     AiUnit *aiunit;
-    memset( countByType, 0, sizeof ( int ) * ( UnitTypeMax + 1 ) );
+    memset(countByType, 0, sizeof (int) * (UnitTypeMax + 1));
 
-   // FIXME: Should I use equivalent unit types?
+    // FIXME: Should I use equivalent unit types?
     aiunit = AiPlayer->Force[force].Units;
-    while ( aiunit ) {
-       if ( ( !aiunit->Unit->Destroyed ) &&
-            ( aiunit->Unit->HP ) && ( aiunit->Unit->Orders[0].Action != 
UnitActionDie ) ) {
+    while (aiunit) {
+       if ((!aiunit->Unit->Destroyed) &&
+           (aiunit->Unit->HP) && (aiunit->Unit->Orders[0].Action != 
UnitActionDie)) {
            type = aiunit->Unit->Type->Type;
 
-           DebugCheck( ( type < 0 ) || ( type > UnitTypeMax ) );
+           DebugCheck((type < 0) || (type > UnitTypeMax));
            countByType[type]++;
        }
        aiunit = aiunit->Next;
@@ -90,16 +90,16 @@
 **     @param countByType      array[UnitTypeMax+1] of int
 **     @return                 The number of missing unit
 */
-global int AiForceSubstractWant( int force, int *countByType )
+global int AiForceSubstractWant(int force, int *countByType)
 {
     int missing;
     const AiUnitType *aitype;
 
     missing = 0;
     aitype = AiPlayer->Force[force].UnitTypes;
-    while ( aitype ) {
+    while (aitype) {
        countByType[aitype->Type->Type] -= aitype->Want;
-       if ( countByType[aitype->Type->Type] < 0 ) {
+       if (countByType[aitype->Type->Type] < 0) {
            missing -= countByType[aitype->Type->Type];
        }
        aitype = aitype->Next;
@@ -114,31 +114,31 @@
 **     @param src the force from which units are taken
 **     @param dst the force into which units go
 */
-global void AiForceTransfert( int src, int dst )
+global void AiForceTransfert(int src, int dst)
 {
     AiUnit **prev;
     AiUnit *aiunit;
 
     int counter[UnitTypeMax + 1];
 
-   //
-   //  Count units in dest force.
-   //
-    AiForceCountUnits( dst, counter );
-
-   //
-   //  Check the dest force requirements.
-   //    
-    if ( AiForceSubstractWant( dst, counter ) == 0 ) {
-       // Nothing missing => abort.
+    //
+    //  Count units in dest force.
+    //
+    AiForceCountUnits(dst, counter);
+
+    //
+    //  Check the dest force requirements.
+    //    
+    if (AiForceSubstractWant(dst, counter) == 0) {
+       // Nothing missing => abort.
        return;
     }
-   // Iterate the source force, moving needed units into dest...
+    // Iterate the source force, moving needed units into dest...
     prev = &AiPlayer->Force[src].Units;
-    while ( *prev ) {
-       aiunit = ( *prev );
-       if ( counter[aiunit->Unit->Type->Type] < 0 ) {
-          // move in dest force...
+    while (*prev) {
+       aiunit = (*prev);
+       if (counter[aiunit->Unit->Type->Type] < 0) {
+           // move in dest force...
            *prev = aiunit->Next;
 
            aiunit->Next = AiPlayer->Force[dst].Units;
@@ -146,7 +146,7 @@
 
            counter[aiunit->Unit->Type->Type]++;
        } else {
-          // Just iterate
+           // Just iterate
            prev = &aiunit->Next;
        }
     }
@@ -157,66 +157,66 @@
 **
 **     @param force    Force number.
 */
-global void AiCleanForce( int force )
+global void AiCleanForce(int force)
 {
     AiUnit **prev;
     AiUnit *aiunit;
     int counter[UnitTypeMax + 1];
     int unit_released;
 
-   //
-   //  Release all killed units.
-   //
+    //
+    //  Release all killed units.
+    //
     prev = &AiPlayer->Force[force].Units;
-    while ( ( aiunit = *prev ) ) {
-       if ( aiunit->Unit->Destroyed ) {
-           RefsDebugCheck( !aiunit->Unit->Refs );
-           if ( !--aiunit->Unit->Refs ) {
-               ReleaseUnit( aiunit->Unit );
+    while ((aiunit = *prev)) {
+       if (aiunit->Unit->Destroyed) {
+           RefsDebugCheck(!aiunit->Unit->Refs);
+           if (!--aiunit->Unit->Refs) {
+               ReleaseUnit(aiunit->Unit);
            }
            *prev = aiunit->Next;
-           free( aiunit );
+           free(aiunit);
            continue;
-       } else if ( !aiunit->Unit->HP || aiunit->Unit->Orders[0].Action == 
UnitActionDie ) {
-           RefsDebugCheck( !aiunit->Unit->Refs );
+       } else if (!aiunit->Unit->HP || aiunit->Unit->Orders[0].Action == 
UnitActionDie) {
+           RefsDebugCheck(!aiunit->Unit->Refs);
            --aiunit->Unit->Refs;
-           RefsDebugCheck( !aiunit->Unit->Refs );
+           RefsDebugCheck(!aiunit->Unit->Refs);
            *prev = aiunit->Next;
-           free( aiunit );
+           free(aiunit);
            continue;
        }
        prev = &aiunit->Next;
     }
 
-   //
-   //  Count units in force.
-   //
-    AiForceCountUnits( force, counter );
-
-   //
-   //  Look if the force is complete.
-   //
-    AiPlayer->Force[force].Completed = ( AiForceSubstractWant( force, counter 
) == 0 );
-
-   // Don't prune the 0 force in any case 
-    if ( force > 0 ) {
-       //
-       //      Release units too much in force.
-       //
+    //
+    //  Count units in force.
+    //
+    AiForceCountUnits(force, counter);
+
+    //
+    //  Look if the force is complete.
+    //
+    AiPlayer->Force[force].Completed = (AiForceSubstractWant(force, counter) 
== 0);
+
+    // Don't prune the 0 force in any case 
+    if (force > 0) {
+       //
+       //      Release units too much in force.
+       //
        unit_released = 0;
-       prev = ( &AiPlayer->Force[force].Units );
-       while ( ( aiunit = ( *prev ) ) ) {
-           if ( counter[aiunit->Unit->Type->Type] > 0 ) {
-               DebugLevel0Fn( "Release unit %s\n" _C_ 
aiunit->Unit->Type->Ident );
+       prev = (&AiPlayer->Force[force].Units);
+       while ((aiunit = (*prev))) {
+           if (counter[aiunit->Unit->Type->Type] > 0) {
+               DebugLevel0Fn("Release unit %s\n" _C_ 
aiunit->Unit->Type->Ident);
                counter[aiunit->Unit->Type->Type]--;
-               RefsDebugCheck( !aiunit->Unit->Refs );
+               RefsDebugCheck(!aiunit->Unit->Refs);
                --aiunit->Unit->Refs;
-               RefsDebugCheck( !aiunit->Unit->Refs );
+               RefsDebugCheck(!aiunit->Unit->Refs);
                *prev = aiunit->Next;
 
-              // Move this unit somewhere else...             
-               AiAssignToForce( aiunit->Unit );
-               free( aiunit );
+               // Move this unit somewhere else...             
+               AiAssignToForce(aiunit->Unit);
+               free(aiunit);
 
                continue;
            }
@@ -224,7 +224,7 @@
        }
     }
 
-    DebugLevel3Fn( "%d complete %d\n" _C_ force _C_ 
AiPlayer->Force[force].Completed );
+    DebugLevel3Fn("%d complete %d\n" _C_ force _C_ 
AiPlayer->Force[force].Completed);
 }
 
 /**
@@ -233,23 +233,23 @@
 **
 **     @param force    the force to erase
 */
-global void AiEraseForce( int force )
+global void AiEraseForce(int force)
 {
     AiUnitType *aiut, *next;
     AiUnit *aiu, *next_u;
 
     aiut = AiPlayer->Force[force].UnitTypes;
-    while ( aiut ) {
+    while (aiut) {
        next = aiut->Next;
-       free( aiut );
+       free(aiut);
        aiut = next;
     }
     AiPlayer->Force[force].UnitTypes = 0;
 
     aiu = AiPlayer->Force[force].Units;
-    while ( aiu ) {
+    while (aiu) {
        next_u = aiu->Next;
-       free( aiu );
+       free(aiu);
        aiu = next_u;
     }
     AiPlayer->Force[force].Units = 0;
@@ -260,15 +260,15 @@
 /**
 **     Cleanup units in forces.
 */
-global void AiCleanForces( void )
+global void AiCleanForces(void)
 {
     int force;
 
-   //
-   //  Release all killed units.
-   //
-    for ( force = 0; force < AI_MAX_FORCES; ++force ) {
-       AiCleanForce( force );
+    //
+    //  Release all killed units.
+    //
+    for (force = 0; force < AI_MAX_FORCES; ++force) {
+       AiCleanForce(force);
     }
 }
 
@@ -280,26 +280,26 @@
 **     @param type     Type to check.
 **     @return         Returns true if it fits & update completed flag, false 
otherwise.
 */
-local int AiCheckBelongsToForce( int force, const UnitType * type )
+local int AiCheckBelongsToForce(int force, const UnitType * type)
 {
     int counter[UnitTypeMax + 1];
     int missing;
 
-   //
-   //  Count units in force.
-   //
-    AiForceCountUnits( force, counter );
-
-   //
-   //  Look what should be in the force.
-   //
-    missing = AiForceSubstractWant( force, counter );
-    AiPlayer->Force[force].Completed = ( missing == 0 );
-
-    if ( counter[type->Type] < 0 ) {
-       // Ok we will put this unit in this force !
-       // Just one missing...
-       if ( ( counter[type->Type] == -1 ) && ( missing == 1 ) ) {
+    //
+    //  Count units in force.
+    //
+    AiForceCountUnits(force, counter);
+
+    //
+    //  Look what should be in the force.
+    //
+    missing = AiForceSubstractWant(force, counter);
+    AiPlayer->Force[force].Completed = (missing == 0);
+
+    if (counter[type->Type] < 0) {
+       // Ok we will put this unit in this force !
+       // Just one missing...
+       if ((counter[type->Type] == -1) && (missing == 1)) {
            AiPlayer->Force[force].Completed = 1;
        }
        return 1;
@@ -312,38 +312,38 @@
 **
 **     @param unit     Unit to assign to force.
 */
-global void AiAssignToForce( Unit * unit )
+global void AiAssignToForce(Unit * unit)
 {
     AiUnit *aiunit;
     int force;
 
-   //
-   //  Check to which force it belongs
-   //
-    for ( force = 0; force < AI_MAX_FORCES; ++force ) {
-       // care of populate from scratch only.
-       if ( AiPlayer->Force[force].PopulateMode != AiForcePopulateFromScratch 
) {
+    //
+    //  Check to which force it belongs
+    //
+    for (force = 0; force < AI_MAX_FORCES; ++force) {
+       // care of populate from scratch only.
+       if (AiPlayer->Force[force].PopulateMode != AiForcePopulateFromScratch) {
            continue;
        }
 
-       if ( AiCheckBelongsToForce( force, unit->Type ) ) {
-           aiunit = malloc( sizeof ( *aiunit ) );
+       if (AiCheckBelongsToForce(force, unit->Type)) {
+           aiunit = malloc(sizeof (*aiunit));
            aiunit->Next = AiPlayer->Force[force].Units;
            AiPlayer->Force[force].Units = aiunit;
            aiunit->Unit = unit;
-           RefsDebugCheck( unit->Destroyed || !unit->Refs );
+           RefsDebugCheck(unit->Destroyed || !unit->Refs);
            ++unit->Refs;
            return;
        }
     }
 
-   // Add to the 0 force !
-   // ( we overflow the 0 force here, so completed does not need update )
-    aiunit = malloc( sizeof ( *aiunit ) );
+    // Add to the 0 force !
+    // ( we overflow the 0 force here, so completed does not need update )
+    aiunit = malloc(sizeof (*aiunit));
     aiunit->Next = AiPlayer->Force[0].Units;
     AiPlayer->Force[0].Units = aiunit;
     aiunit->Unit = unit;
-    RefsDebugCheck( unit->Destroyed || !unit->Refs );
+    RefsDebugCheck(unit->Destroyed || !unit->Refs);
     ++unit->Refs;
 }
 
@@ -352,28 +352,28 @@
 **
 **     @param force    the force to complete
 */
-global void AiForceComplete( int force )
+global void AiForceComplete(int force)
 {
     int j;
 
-    for ( j = 0; j < AI_MAX_FORCES; ++j ) {
-       // Don't complete with self ...
-       if ( j == force ) {
+    for (j = 0; j < AI_MAX_FORCES; ++j) {
+       // Don't complete with self ...
+       if (j == force) {
            continue;
        }
-       // Complete only with "reusable" forces.
-       if ( !AiPlayer->Force[j].UnitsReusable ) {
+       // Complete only with "reusable" forces.
+       if (!AiPlayer->Force[j].UnitsReusable) {
            continue;
        }
-       // Honor "populate from attack" 
-       if ( ( AiPlayer->Force[force].PopulateMode == AiForcePopulateFromAttack 
) &&
-            ( !AiPlayer->Force[j].Role == AiForceRoleAttack ) ) {
+       // Honor "populate from attack" 
+       if ((AiPlayer->Force[force].PopulateMode == AiForcePopulateFromAttack) 
&&
+           (!AiPlayer->Force[j].Role == AiForceRoleAttack)) {
            continue;
        }
-       // Complete the force automatically...
-       AiForceTransfert( j, force );
+       // Complete the force automatically...
+       AiForceTransfert(j, force);
 
-       if ( AiPlayer->Force[force].Completed ) {
+       if (AiPlayer->Force[force].Completed) {
            break;
        }
     }
@@ -389,41 +389,41 @@
 **     @param count    the number of unit to add
 **     @return         the number of unit still missing ( or 0 if successfull )
 */
-global int AiEnroleSpecificUnitType( int force, UnitType * ut, int count )
+global int AiEnroleSpecificUnitType(int force, UnitType * ut, int count)
 {
     AiForce *dstForce;
     int src_force;
     AiUnit *aiUnit, **prev;;
 
     dstForce = AiPlayer->Force + force;
-    for ( src_force = 0; src_force < AI_MAX_FORCES; src_force++ ) {
-       if ( src_force == force ) {
+    for (src_force = 0; src_force < AI_MAX_FORCES; src_force++) {
+       if (src_force == force) {
            continue;
        }
-       // Only populate with reserve 
-       if ( !AiPlayer->Force[src_force].UnitsReusable ) {
+       // Only populate with reserve 
+       if (!AiPlayer->Force[src_force].UnitsReusable) {
            continue;
        }
-       // Don't populate attack force with defend reserve.
-       if ( ( AiPlayer->Force[src_force].Role == AiForceRoleDefend ) &&
-            ( AiPlayer->Force[force].PopulateMode == AiForcePopulateFromAttack 
) ) {
+       // Don't populate attack force with defend reserve.
+       if ((AiPlayer->Force[src_force].Role == AiForceRoleDefend) &&
+           (AiPlayer->Force[force].PopulateMode == AiForcePopulateFromAttack)) 
{
            continue;
        }
 
        aiUnit = AiPlayer->Force[src_force].Units;
        prev = &AiPlayer->Force[src_force].Units;
-       while ( aiUnit ) {
-          // FIXME : comparaison should match equivalent unit as well
-           if ( aiUnit->Unit->Type == ut ) {
+       while (aiUnit) {
+           // FIXME : comparaison should match equivalent unit as well
+           if (aiUnit->Unit->Type == ut) {
                *prev = aiUnit->Next;
 
-              // Move to dstForce 
+               // Move to dstForce 
                AiPlayer->Force[src_force].Completed = 0;
                aiUnit->Next = dstForce->Units;
                dstForce->Units = aiUnit;
 
                count--;
-               if ( !count ) {
+               if (!count) {
                    return 0;
                }
            }
@@ -438,29 +438,29 @@
 **     Make sure that current force requirement are superior to actual 
assigned unit count
 **
 */
-local void AiFinalizeForce( int force )
+local void AiFinalizeForce(int force)
 {
     int i;
     int unitcount[UnitTypeMax + 1];
     AiUnitType *aitype;
 
-    AiForceCountUnits( force, unitcount );
+    AiForceCountUnits(force, unitcount);
     aitype = AiPlayer->Force[force].UnitTypes;
-    while ( aitype ) {
-       if ( unitcount[aitype->Type->Type] > aitype->Want ) {
+    while (aitype) {
+       if (unitcount[aitype->Type->Type] > aitype->Want) {
            aitype->Want = unitcount[aitype->Type->Type];
            unitcount[aitype->Type->Type] = 0;
        }
        aitype = aitype->Next;
     }
 
-    for ( i = 0; i <= UnitTypeMax; i++ ) {
-       if ( unitcount[i] > 0 ) {
-           aitype = ( AiUnitType * ) malloc( sizeof ( AiUnitType ) );
+    for (i = 0; i <= UnitTypeMax; i++) {
+       if (unitcount[i] > 0) {
+           aitype = (AiUnitType *) malloc(sizeof (AiUnitType));
            aitype->Want = unitcount[i];
            aitype->Type = UnitTypes[i];
 
-          // Insert into force.
+           // Insert into force.
            aitype->Next = AiPlayer->Force[force].UnitTypes;
            AiPlayer->Force[force].UnitTypes = aitype;
        }
@@ -475,7 +475,7 @@
 **     @param ucount   Size of the utypes array        
 **     @return         -1 if not possible, 0 if force ready.
 */
-global int AiCreateSpecificForce( int *power, int *unittypes, int 
unittypescount )
+global int AiCreateSpecificForce(int *power, int *unittypes, int 
unittypescount)
 {
     int id, maxPower, forceUpdated;
     UnitType *ut;
@@ -484,37 +484,36 @@
     curpower[0] = power[0];
     curpower[1] = power[1];
     curpower[2] = power[2];
-    AiEraseForce( AiScript->ownForce );
+    AiEraseForce(AiScript->ownForce);
 
     do {
        forceUpdated = 0;
-       maxPower = ( curpower[0] > curpower[1] ?
-                    ( curpower[0] > curpower[2] ? 0 : 2 ) :
-                    ( curpower[1] > curpower[2] ? 1 : 2 ) );
+       maxPower = (curpower[0] > curpower[1] ?
+           (curpower[0] > curpower[2] ? 0 : 2) : (curpower[1] > curpower[2] ? 
1 : 2));
 
-       for ( id = 0; id < unittypescount; id++ ) {
+       for (id = 0; id < unittypescount; id++) {
            ut = UnitTypes[unittypes[id]];
-           if ( !( ut->CanTarget & ( 1 << maxPower ) ) ) {
+           if (!(ut->CanTarget & (1 << maxPower))) {
                continue;
            }
-          // Try to respond to the most important power ...
-           if ( AiEnroleSpecificUnitType( AiScript->ownForce, ut, 1 ) == 1 ) {
+           // Try to respond to the most important power ...
+           if (AiEnroleSpecificUnitType(AiScript->ownForce, ut, 1) == 1) {
                continue;
            }
 
-           curpower[maxPower] -= AiUnittypeForce( ut );
+           curpower[maxPower] -= AiUnittypeForce(ut);
            forceUpdated = 1;
-           maxPower = ( curpower[0] > curpower[1] ?
-                        ( curpower[0] > curpower[2] ? 0 : 2 ) :
-                        ( curpower[1] > curpower[2] ? 1 : 2 ) );
-           if ( curpower[maxPower] <= 0 ) {
-               AiFinalizeForce( AiScript->ownForce );
+           maxPower = (curpower[0] > curpower[1] ?
+               (curpower[0] > curpower[2] ? 0 : 2) :
+               (curpower[1] > curpower[2] ? 1 : 2));
+           if (curpower[maxPower] <= 0) {
+               AiFinalizeForce(AiScript->ownForce);
                return 0;
            }
        }
-    } while ( forceUpdated );
-   // Sth missing...
-    AiFinalizeForce( AiScript->ownForce );
+    } while (forceUpdated);
+    // Sth missing...
+    AiFinalizeForce(AiScript->ownForce);
     return -1;
 }
 
@@ -522,7 +521,7 @@
 /**
 **     Assign free units to force.
 */
-global void AiAssignFreeUnitsToForce( void )
+global void AiAssignFreeUnitsToForce(void)
 {
     Unit *table[UnitMax];
     int n;
@@ -534,17 +533,17 @@
     AiCleanForces();
 
     n = AiPlayer->Player->TotalNumUnits;
-    memcpy( table, AiPlayer->Player->Units, sizeof ( *AiPlayer->Player->Units 
) * n );
+    memcpy(table, AiPlayer->Player->Units, sizeof (*AiPlayer->Player->Units) * 
n);
 
-   //
-   //  Remove all units already in forces.
-   //
-    for ( f = 0; f < AI_MAX_FORCES; ++f ) {
+    //
+    //  Remove all units already in forces.
+    //
+    for (f = 0; f < AI_MAX_FORCES; ++f) {
        aiunit = AiPlayer->Force[f].Units;
-       while ( aiunit ) {
+       while (aiunit) {
            unit = aiunit->Unit;
-           for ( i = 0; i < n; ++i ) {
-               if ( table[i] == unit ) {
+           for (i = 0; i < n; ++i) {
+               if (table[i] == unit) {
                    table[i] = table[--n];
                }
            }
@@ -552,12 +551,12 @@
        }
     }
 
-   //
-   //  Try to assign the remaining units.
-   //
-    for ( i = 0; i < n; ++i ) {
-       if ( table[i]->Active ) {
-           AiAssignToForce( table[i] );
+    //
+    //  Try to assign the remaining units.
+    //
+    for (i = 0; i < n; ++i) {
+       if (table[i]->Active) {
+           AiAssignToForce(table[i]);
        }
     }
 }
@@ -569,23 +568,23 @@
 **     @param x        X tile map position to be attacked.
 **     @param y        Y tile map position to be attacked.
 */
-global void AiAttackWithForceAt( int force, int x, int y )
+global void AiAttackWithForceAt(int force, int x, int y)
 {
     const AiUnit *aiunit;
 
-    AiCleanForce( force );
+    AiCleanForce(force);
 
-    if ( ( aiunit = AiPlayer->Force[force].Units ) ) {
+    if ((aiunit = AiPlayer->Force[force].Units)) {
        AiPlayer->Force[force].Attacking = 1;
 
-       //
-       //      Send all units in the force to enemy.
-       //
-       while ( aiunit ) {
-           if ( aiunit->Unit->Type->CanAttack ) {
-               CommandAttack( aiunit->Unit, x, y, NULL, FlushCommands );
+       //
+       //      Send all units in the force to enemy.
+       //
+       while (aiunit) {
+           if (aiunit->Unit->Type->CanAttack) {
+               CommandAttack(aiunit->Unit, x, y, NULL, FlushCommands);
            } else {
-               CommandMove( aiunit->Unit, x, y, FlushCommands );
+               CommandMove(aiunit->Unit, x, y, FlushCommands);
            }
 
            aiunit = aiunit->Next;
@@ -598,33 +597,33 @@
 **
 **     @param force    Force number to attack with.
 */
-global void AiAttackWithForce( int force )
+global void AiAttackWithForce(int force)
 {
     const AiUnit *aiunit;
     const Unit *enemy;
     int x;
     int y;
 
-    AiCleanForce( force );
+    AiCleanForce(force);
 
     AiPlayer->Force[force].Attacking = 0;
-    if ( ( aiunit = AiPlayer->Force[force].Units ) ) {
+    if ((aiunit = AiPlayer->Force[force].Units)) {
        AiPlayer->Force[force].Attacking = 1;
-       DebugLevel3Fn( "FORCE %d started ( AiAttackWithForce )\n" _C_ force );
+       DebugLevel3Fn("FORCE %d started ( AiAttackWithForce )\n" _C_ force);
 
        enemy = NoUnitP;
-       while ( aiunit && !enemy ) {    // Use an unit that can attack
-           if ( aiunit->Unit->Type->CanAttack ) {
-               enemy = AttackUnitsInDistance( aiunit->Unit, MaxMapWidth );
+       while (aiunit && !enemy) {      // Use an unit that can attack
+           if (aiunit->Unit->Type->CanAttack) {
+               enemy = AttackUnitsInDistance(aiunit->Unit, MaxMapWidth);
            }
            aiunit = aiunit->Next;
        }
 
-       if ( !enemy ) {
-           DebugLevel0Fn( "Need to plan an attack with transporter\n" );
-           if ( !AiPlayer->Force[force].State && !AiPlanAttack( 
&AiPlayer->Force[force] ) ) {
-               DebugLevel0Fn( "Can't transport, look for walls\n" );
-               if ( !AiFindWall( &AiPlayer->Force[force] ) ) {
+       if (!enemy) {
+           DebugLevel0Fn("Need to plan an attack with transporter\n");
+           if (!AiPlayer->Force[force].State && 
!AiPlanAttack(&AiPlayer->Force[force])) {
+               DebugLevel0Fn("Can't transport, look for walls\n");
+               if (!AiFindWall(&AiPlayer->Force[force])) {
                    AiPlayer->Force[force].Attacking = 0;
                }
            }
@@ -634,15 +633,15 @@
        x = enemy->X;
        y = enemy->Y;
 
-       //
-       //      Send all units in the force to enemy.
-       //
+       //
+       //      Send all units in the force to enemy.
+       //
        aiunit = AiPlayer->Force[force].Units;
-       while ( aiunit ) {
-           if ( aiunit->Unit->Type->CanAttack ) {
-               CommandAttack( aiunit->Unit, x, y, NULL, FlushCommands );
+       while (aiunit) {
+           if (aiunit->Unit->Type->CanAttack) {
+               CommandAttack(aiunit->Unit, x, y, NULL, FlushCommands);
            } else {
-               CommandMove( aiunit->Unit, x, y, FlushCommands );
+               CommandMove(aiunit->Unit, x, y, FlushCommands);
            }
            aiunit = aiunit->Next;
        }
@@ -654,14 +653,14 @@
 **
 **     @param  force   the force to send home.
 */
-global void AiGroupForceNear( int force, int targetX, int targetY )
+global void AiGroupForceNear(int force, int targetX, int targetY)
 {
     const AiUnit *aiunit;
     const AiUnit *groupunit;
     int unitdst, groupdst;
 
-   // Step 1 : find the unit closest to the force hotspot
-    AiCleanForce( force );
+    // Step 1 : find the unit closest to the force hotspot
+    AiCleanForce(force);
 
     groupdst = -1;
 
@@ -669,14 +668,14 @@
 
     aiunit = AiPlayer->Force[force].Units;
 
-   // Sanity : don't group force with only one unit !
-    if ( ( !aiunit ) || ( !aiunit->Next ) ) {
+    // Sanity : don't group force with only one unit !
+    if ((!aiunit) || (!aiunit->Next)) {
        return;
     }
 
-    while ( aiunit ) {
-       unitdst = abs( aiunit->Unit->X - targetX ) + abs( aiunit->Unit->Y - 
targetY );
-       if ( ( unitdst < groupdst ) || ( !groupunit ) ) {
+    while (aiunit) {
+       unitdst = abs(aiunit->Unit->X - targetX) + abs(aiunit->Unit->Y - 
targetY);
+       if ((unitdst < groupdst) || (!groupunit)) {
            groupunit = aiunit;
            groupdst = unitdst;
        }
@@ -686,14 +685,15 @@
 
     AiPlayer->Force[force].Attacking = 1;
 
-   // Order units to attack near the "group" unit...
+    // Order units to attack near the "group" unit...
     aiunit = AiPlayer->Force[force].Units;
-    while ( aiunit ) {
-       if ( aiunit->Unit->Type->CanAttack ) {
-           CommandAttack( aiunit->Unit, groupunit->Unit->X, 
groupunit->Unit->Y, NULL,
-                          FlushCommands );
+    while (aiunit) {
+       if (aiunit->Unit->Type->CanAttack) {
+           CommandAttack(aiunit->Unit, groupunit->Unit->X, groupunit->Unit->Y, 
NULL,
+               FlushCommands);
        } else {
-           CommandMove( aiunit->Unit, groupunit->Unit->X, groupunit->Unit->Y, 
FlushCommands );
+           CommandMove(aiunit->Unit, groupunit->Unit->X, groupunit->Unit->Y,
+               FlushCommands);
        }
        aiunit = aiunit->Next;
     }
@@ -709,10 +709,10 @@
 **     @param rsltx    X destination
 **     @param rslyx    Y destination
 */
-local void AiFindHome( int ground, int x, int y, int *rsltx, int *rslty )
+local void AiFindHome(int ground, int x, int y, int *rsltx, int *rslty)
 {
-   // Find in the player unit's the closer to
-   // FIXME : TODO
+    // Find in the player unit's the closer to
+    // FIXME : TODO
     *rsltx = AiPlayer->Player->StartX;
     *rslty = AiPlayer->Player->StartY;
 }
@@ -722,28 +722,28 @@
 **
 **     @param  force   the force to send home.
 */
-global void AiSendForceHome( int force )
+global void AiSendForceHome(int force)
 {
     const AiUnit *aiunit;
     int i, type;
     int x[3], y[3];
 
-    AiCleanForce( force );
+    AiCleanForce(force);
     aiunit = AiPlayer->Force[force].Units;
 
-    for ( i = 0; i < 3; i++ ) {
+    for (i = 0; i < 3; i++) {
        x[i] = -1;
        y[i] = -1;
     }
 
-    while ( aiunit ) {
+    while (aiunit) {
        type = aiunit->Unit->Type->UnitType;
 
-       if ( x[type] == -1 ) {
-           AiFindHome( type, aiunit->Unit->X, aiunit->Unit->Y, &x[type], 
&y[type] );
+       if (x[type] == -1) {
+           AiFindHome(type, aiunit->Unit->X, aiunit->Unit->Y, &x[type], 
&y[type]);
        }
 
-       CommandMove( aiunit->Unit, x[type], y[type], FlushCommands );
+       CommandMove(aiunit->Unit, x[type], y[type], FlushCommands);
 
        aiunit = aiunit->Next;
     }
@@ -763,7 +763,7 @@
 **             We must the transporter land on a new position.
 **             Or the board action will be better written.
 */
-local void AiLoadForce( AiForce * force )
+local void AiLoadForce(AiForce * force)
 {
     AiUnit *aiunit;
     Unit *table[UnitMax];
@@ -772,46 +772,46 @@
     int o;
     int f;
 
-   //
-   //  Find all transporters.
-   //
+    //
+    //  Find all transporters.
+    //
     n = 0;
     aiunit = force->Units;
-    while ( aiunit ) {
-       if ( aiunit->Unit->Type->Transporter ) {
+    while (aiunit) {
+       if (aiunit->Unit->Type->Transporter) {
            table[n++] = aiunit->Unit;
        }
        aiunit = aiunit->Next;
     }
 
-    if ( !n ) {
-       DebugLevel0Fn( "No transporter, lost or error in code?\n" );
+    if (!n) {
+       DebugLevel0Fn("No transporter, lost or error in code?\n");
        force->MustTransport = 0;
        force->State = 0;
        return;
     }
-   //
-   //  Load all on transporter.
-   //
+    //
+    //  Load all on transporter.
+    //
     f = o = i = 0;
     aiunit = force->Units;
-    while ( aiunit ) {
+    while (aiunit) {
        Unit *unit;
 
        unit = aiunit->Unit;
-       if ( !unit->Type->Transporter && unit->Type->UnitType == UnitTypeLand ) 
{
-           if ( !unit->Removed ) {
+       if (!unit->Type->Transporter && unit->Type->UnitType == UnitTypeLand) {
+           if (!unit->Removed) {
                f = 1;
-               if ( unit->Orders[0].Action != UnitActionBoard ) {
-                   if ( UnitIdle( table[i] ) ) {
-                       DebugLevel0Fn( "Send transporter %d\n" _C_ i );
-                       CommandFollow( table[i], unit, FlushCommands );
+               if (unit->Orders[0].Action != UnitActionBoard) {
+                   if (UnitIdle(table[i])) {
+                       DebugLevel0Fn("Send transporter %d\n" _C_ i);
+                       CommandFollow(table[i], unit, FlushCommands);
                    }
-                   CommandBoard( unit, table[i], FlushCommands );
+                   CommandBoard(unit, table[i], FlushCommands);
                    ++o;
-                  // FIXME
-                   if ( o == table[i]->Type->MaxOnBoard ) {
-                       DebugLevel0Fn( "FIXME: next transporter for AI 
boarding\n" );
+                   // FIXME
+                   if (o == table[i]->Type->MaxOnBoard) {
+                       DebugLevel0Fn("FIXME: next transporter for AI 
boarding\n");
                        return;
                    }
                }
@@ -820,8 +820,8 @@
        aiunit = aiunit->Next;
     }
 
-    if ( !f ) {
-       DebugLevel0Fn( "All are loaded\n" );
+    if (!f) {
+       DebugLevel0Fn("All are loaded\n");
        ++force->State;
     }
 }
@@ -836,21 +836,23 @@
 **             at an unfortified coast. If we send more transporters they
 **             should land on different positions.
 */
-local void AiSendTransporter( AiForce * force )
+local void AiSendTransporter(AiForce * force)
 {
     AiUnit *aiunit;
 
-   //
-   //  Find all transporters.
-   //
+    //
+    //  Find all transporters.
+    //
     aiunit = force->Units;
-    while ( aiunit ) {
-       //      Transporter to unload units
-       if ( aiunit->Unit->Type->Transporter ) {
-           CommandUnload( aiunit->Unit, force->GoalX, force->GoalY, NoUnitP, 
FlushCommands );
-          //      Ships to defend transporter
-       } else if ( aiunit->Unit->Type->UnitType == UnitTypeNaval ) {
-           CommandAttack( aiunit->Unit, force->GoalX, force->GoalY, NoUnitP, 
FlushCommands );
+    while (aiunit) {
+       //      Transporter to unload units
+       if (aiunit->Unit->Type->Transporter) {
+           CommandUnload(aiunit->Unit, force->GoalX, force->GoalY, NoUnitP,
+               FlushCommands);
+           //      Ships to defend transporter
+       } else if (aiunit->Unit->Type->UnitType == UnitTypeNaval) {
+           CommandAttack(aiunit->Unit, force->GoalX, force->GoalY, NoUnitP,
+               FlushCommands);
        }
        aiunit = aiunit->Next;
     }
@@ -864,25 +866,25 @@
 **     @param force    Force pointer.
 **
 */
-local void AiWaitLanded( AiForce * force )
+local void AiWaitLanded(AiForce * force)
 {
     AiUnit *aiunit;
     int i;
 
-    DebugLevel0Fn( "Waiting\n" );
-   //
-   //  Find all transporters.
-   //
+    DebugLevel0Fn("Waiting\n");
+    //
+    //  Find all transporters.
+    //
     i = 1;
     aiunit = force->Units;
-    while ( aiunit ) {
-       if ( aiunit->Unit->Type->Transporter ) {
-           if ( UnitIdle( aiunit->Unit ) ) {
-               DebugLevel0Fn( "Unloading\n" );
-              // Don't tell empty transporters to unload.
-               if ( aiunit->Unit->InsideCount ) {
-                   CommandUnload( aiunit->Unit, force->GoalX, force->GoalY,
-                                  NoUnitP, FlushCommands );
+    while (aiunit) {
+       if (aiunit->Unit->Type->Transporter) {
+           if (UnitIdle(aiunit->Unit)) {
+               DebugLevel0Fn("Unloading\n");
+               // Don't tell empty transporters to unload.
+               if (aiunit->Unit->InsideCount) {
+                   CommandUnload(aiunit->Unit, force->GoalX, force->GoalY,
+                       NoUnitP, FlushCommands);
                    i = 0;
                }
            } else {
@@ -891,8 +893,8 @@
        }
        aiunit = aiunit->Next;
     }
-    if ( i ) {
-       ++force->State;         // all unloaded
+    if (i) {
+       ++force->State;                 // all unloaded
     }
 }
 
@@ -902,75 +904,76 @@
 **
 **     @param force    Force pointer.
 */
-local void AiForceAttacks( AiForce * force )
+local void AiForceAttacks(AiForce * force)
 {
     const AiUnit *aiunit;
 
-    if ( ( aiunit = force->Units ) ) {
-       while ( aiunit ) {
-          // Still some action
-           if ( !UnitIdle( aiunit->Unit ) ) {
+    if ((aiunit = force->Units)) {
+       while (aiunit) {
+           // Still some action
+           if (!UnitIdle(aiunit->Unit)) {
                break;
            }
            aiunit = aiunit->Next;
        }
-       // Must mark the attack as terminated 
-       if ( !aiunit ) {
-           DebugLevel3Fn( "FORCE stopped ( AiForceAttacks, unitactionstill 
)\n" );
-           DebugLevel3Fn( "force target was %d %d\n" _C_ force->GoalX _C_ 
force->GoalY );
-           DebugLevel3Fn( "unit pos was %d %d\n" _C_ force->Units->Unit->X _C_ 
force->Units->
-                          Unit->Y );
+       // Must mark the attack as terminated 
+       if (!aiunit) {
+           DebugLevel3Fn("FORCE stopped ( AiForceAttacks, unitactionstill 
)\n");
+           DebugLevel3Fn("force target was %d %d\n" _C_ force->GoalX _C_ 
force->GoalY);
+           DebugLevel3Fn("unit pos was %d %d\n" _C_ force->Units->Unit->X _C_ 
force->
+               Units->Unit->Y);
 
            force->Attacking = 0;
-          // AiAttackWithForce(force-AiPlayer->Force);
+           // AiAttackWithForce(force-AiPlayer->Force);
        }
     } else {
-       DebugLevel3Fn( "FORCE stopped ( AiAttackWithForce, no unit )\n" );
+       DebugLevel3Fn("FORCE stopped ( AiAttackWithForce, no unit )\n");
        force->Attacking = 0;
     }
 }
 
-global void AiForceHelpMe( int force, const Unit * attacker, Unit * defender )
+global void AiForceHelpMe(int force, const Unit * attacker, Unit * defender)
 {
     AiForce *aiForce;
     AiUnit *rescue;
 
     aiForce = AiPlayer->Force + force;
 
-   // Don't handle special cases
-    if ( aiForce->State > 0 ) {
+    // Don't handle special cases
+    if (aiForce->State > 0) {
        return;
     }
 
-    switch ( aiForce->HelpMode ) {
-    case AiForceDontHelp:
-       // Don't react (easy)
-       return;
+    switch (aiForce->HelpMode) {
+       case AiForceDontHelp:
+           // Don't react (easy)
+           return;
 
-    case AiForceHelpForce:
-       // Send all idles units to help
-       rescue = aiForce->Units;
-       while ( rescue ) {
-          // TODO : check that dead units does appear there
-           if ( UnitIdle( rescue->Unit ) ) {
-              // This unit attack !
-               if ( rescue->Unit->Type->CanAttack ) {
-                   CommandAttack( rescue->Unit, attacker->X, attacker->Y, NULL,
-                                  FlushCommands );
-               } else {
-                   CommandMove( rescue->Unit, attacker->X, attacker->Y, 
FlushCommands );
+       case AiForceHelpForce:
+           // Send all idles units to help
+           rescue = aiForce->Units;
+           while (rescue) {
+               // TODO : check that dead units does appear there
+               if (UnitIdle(rescue->Unit)) {
+                   // This unit attack !
+                   if (rescue->Unit->Type->CanAttack) {
+                       CommandAttack(rescue->Unit, attacker->X, attacker->Y, 
NULL,
+                           FlushCommands);
+                   } else {
+                       CommandMove(rescue->Unit, attacker->X, attacker->Y,
+                           FlushCommands);
+                   }
+                   // Now the force is attacking ( again )
+                   aiForce->Attacking = 1;
                }
-              // Now the force is attacking ( again )
-               aiForce->Attacking = 1;
+               rescue = rescue->Next;
            }
-           rescue = rescue->Next;
-       }
-       break;
+           break;
 
-    default:
-       // the usual way : create a defense force, send it, ...
-       AiFindDefendScript( attacker->X, attacker->Y );
-       break;
+       default:
+           // the usual way : create a defense force, send it, ...
+           AiFindDefendScript(attacker->X, attacker->Y);
+           break;
     }
 }
 
@@ -979,52 +982,51 @@
 **
 **     @param force    Force pointer.
 */
-local void AiGuideAttackForce( AiForce * force )
+local void AiGuideAttackForce(AiForce * force)
 {
-    enum
-    { StartState = 1, TransporterLoaded, WaitLanded, AttackNow };
+    enum { StartState = 1, TransporterLoaded, WaitLanded, AttackNow };
 
-    switch ( force->State ) {
-       //
-       //  Load units on transporters.
-       //
-    case StartState:
-       AiLoadForce( force );
-       break;
-    case TransporterLoaded:
-       AiSendTransporter( force );
-       break;
-    case WaitLanded:
-       AiWaitLanded( force );
-       break;
-    case AttackNow:
-       force->State = 0;
-       AiAttackWithForce( force - AiPlayer->Force );
-       break;
+    switch (force->State) {
+           //
+           //  Load units on transporters.
+           //
+       case StartState:
+           AiLoadForce(force);
+           break;
+       case TransporterLoaded:
+           AiSendTransporter(force);
+           break;
+       case WaitLanded:
+           AiWaitLanded(force);
+           break;
+       case AttackNow:
+           force->State = 0;
+           AiAttackWithForce(force - AiPlayer->Force);
+           break;
 
-       //
-       //  Attacking!
-       //
-    case 0:
-       AiForceAttacks( force );
-       break;
+           //
+           //  Attacking!
+           //
+       case 0:
+           AiForceAttacks(force);
+           break;
     }
 }
 
 /**
 **     Entry point of force manager, perodic called.
 */
-global void AiForceManager( void )
+global void AiForceManager(void)
 {
     int force;
 
-   //
-   //  Look if our defenders still have enemies in range.
-   //
-    for ( force = 0; force < AI_MAX_FORCES; ++force ) {
-       if ( AiPlayer->Force[force].Attacking ) {
-           AiCleanForce( force );
-           AiGuideAttackForce( &AiPlayer->Force[force] );
+    //
+    //  Look if our defenders still have enemies in range.
+    //
+    for (force = 0; force < AI_MAX_FORCES; ++force) {
+       if (AiPlayer->Force[force].Attacking) {
+           AiCleanForce(force);
+           AiGuideAttackForce(&AiPlayer->Force[force]);
        }
     }
     AiAssignFreeUnitsToForce();
Index: stratagus/src/ai/ai_local.h
diff -u stratagus/src/ai/ai_local.h:1.37 stratagus/src/ai/ai_local.h:1.38
--- stratagus/src/ai/ai_local.h:1.37    Thu Oct 23 14:38:34 2003
+++ stratagus/src/ai/ai_local.h Sun Oct 26 10:34:58 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//      $Id: ai_local.h,v 1.37 2003/10/23 18:38:34 n0body Exp $
+//      $Id: ai_local.h,v 1.38 2003/10/26 15:34:58 pludov Exp $
 
 #ifndef __AI_LOCAL_H__
 #define __AI_LOCAL_H__
@@ -47,131 +47,117 @@
 ----------------------------------------------------------------------------*/
 
 /**
-**     Ai Type typedef.
+**     Ai Type typedef
 */
 typedef struct _ai_type_ AiType;
 
 /**
 **     Ai Type structure.
 */
-struct _ai_type_
-{
-    AiType *Next;              /// Next ai type
-
-    char *Name;                        /// Name of this ai
-    char *Race;                        /// for this race
-    char *Class;               /// class of this ai
-
-   // nice flags
-   //unsigned char     AllExplored : 1;        /// Ai sees unexplored area
-   //unsigned char     AllVisibile : 1;        /// Ai sees invisibile area
+struct _ai_type_{
+    AiType*            Next;           /// Next ai type
 
-    SCM Script;                        /// Main script (gc-protected!)
+    char*              Name;           /// Name of this ai
+    char*              Race;           /// for this race
+    char*              Class;          /// class of this ai
+
+    // nice flags
+    //unsigned char     AllExplored : 1;/// Ai sees unexplored area
+    //unsigned char     AllVisibile : 1;/// Ai sees invisibile area
+
+    SCM                        Script;         /// Main script (gc-protected!)
 };
 
 /**
 **     AI unit-type table with counter in front.
 */
-typedef struct _ai_unittype_table_
-{
-    int Count;                 /// elements in table
-    UnitType *Table[1];                /// the table
-}
-AiUnitTypeTable;
+typedef struct _ai_unittype_table_ {
+    int                        Count;          /// elements in table
+    UnitType*          Table[1];       /// the table
+} AiUnitTypeTable;
 
 /**
-**     Ai unit-type typedef.
+**     Ai unit-type typedef
 */
 typedef struct _ai_unit_type_ AiUnitType;
 
 /**
 **     Ai unit-type in a force.
 */
-struct _ai_unit_type_
-{
-    AiUnitType *Next;          /// next unit-type
-    int Want;                  /// number of this unit-type wanted
-    UnitType *Type;            /// unit-type self
+struct _ai_unit_type_ {
+    AiUnitType*        Next;           /// next unit-type
+    int                        Want;           /// number of this unit-type 
wanted
+    UnitType*          Type;           /// unit-type self
 };
 
 /**
-**     Ai unit typedef.
+**     AIUnit typedef
 */
 typedef struct _ai_unit_ AiUnit;
 
 /**
 **     Ai unit in a force.
 */
-struct _ai_unit_
-{
-    AiUnit *Next;              /// next unit
-    Unit *Unit;                        /// unit self
+struct _ai_unit_ {
+    AiUnit*            Next;           /// next unit
+    Unit*              Unit;           /// unit self
 };
 
 /**
 **     Roles for forces
 */
-enum _ai_force_role_
-{
-    AiForceRoleAttack,         /// Force should attack
-    AiForceRoleDefend,         /// Force should defend
+enum _ai_force_role_ {
+    AiForceRoleAttack,                 /// Force should attack
+    AiForceRoleDefend,                 /// Force should defend
 };
 
 
 /**
 **     Ways to populate a force 
 */
-enum _ai_force_populate_mode_
-{
-    AiForceDontPopulate,       /// Force won't receive any unit
-    AiForcePopulateFromScratch,        /// Force unit's will be builded
-    AiForcePopulateFromAttack, /// Force will receive units from idle attack 
force only - nothing builded
-    AiForcePopulateAny         /// Force will receive units from any idle 
force - nothing builded
+enum _ai_force_populate_mode_ {
+    AiForceDontPopulate,               /// Force won't receive any unit
+    AiForcePopulateFromScratch,                /// Force unit's will be builded
+    AiForcePopulateFromAttack,         /// Force will receive units from idle 
attack force only - nothing builded
+    AiForcePopulateAny                 /// Force will receive units from any 
idle force - nothing builded
 };
 
 /**
 **     How to react when an unit is attacked in a force
 */
-enum _ai_force_help_mode_
-{
-    AiForceDontHelp,           /// Don't react to attack on this force
-    AiForceHelpForce,          /// Send idle units to defend
-    AiForceHelpFull            /// Create a defend force, send it, ...
+enum _ai_force_help_mode_ {
+    AiForceDontHelp,                   /// Don't react to attack on this force
+    AiForceHelpForce,                  /// Send idle units to defend
+    AiForceHelpFull                    /// Create a defend force, send it, ...
 };
 
 /**
-**     AI force typedef.
-*/
-typedef struct _ai_force_ AiForce;
-
-/**
 **     Define an AI force.
 **
 **     A force is a group of units belonging together.
 */
-struct _ai_force_
-{
-    char Completed;            /// Flag saying force is complete build
-    char Attacking;            /// Is this force attacking ( aka not idle )
-    char Role;                 /// Role of the force
-    char PopulateMode;         /// Which forces can be used to fill this force 
?
-    char UnitsReusable;                /// Indicate moving units of this force 
into others is allowed.    
-    char HelpMode;             /// How to react to treat in this force ?
-
-    AiUnitType *UnitTypes;     /// Count and types of unit-type
-    AiUnit *Units;             /// Units in the force
-
-   //
-   // If attacking
-   //
-    int State;                 /// Attack state
-    int GoalX;                 /// Attack point X tile map position
-    int GoalY;                 /// Attack point Y tile map position
-    int MustTransport;         /// Flag must use transporter
-};
+typedef struct _ai_force_ {
+    char               Completed;      /// Flag saying force is complete build
+    char               Attacking;      /// Is this force attacking ( aka not 
idle )
+    char               Role;           /// Role of the force
+    char               PopulateMode;   /// Which forces can be used to fill 
this force ?
+    char               UnitsReusable;  /// Indicate moving units of this force 
into others is allowed.    
+    char               HelpMode;       /// How to react to treat in this force 
?
+
+    AiUnitType*                UnitTypes;      /// Count and types of unit-type
+    AiUnit*            Units;          /// Units in the force
+
+    //
+    // If attacking
+    //
+    int                        State;          /// Attack state
+    int                        GoalX;          /// Attack point X tile map 
position
+    int                        GoalY;          /// Attack point Y tile map 
position
+    int                        MustTransport;  /// Flag must use transporter
+} AiForce;
 
 /**
-**     AI build queue typedef.
+**     AI build queue typedef
 */
 typedef struct _ai_build_queue_ AiBuildQueue;
 
@@ -180,39 +166,34 @@
 **
 **     List of orders for the resource manager to handle
 */
-struct _ai_build_queue_
-{
-    AiBuildQueue *Next;                /// next request
-    int Want;                  /// requested number
-    int Made;                  /// builded number
-    UnitType *Type;            /// unit-type
+struct _ai_build_queue_ {
+    AiBuildQueue*      Next;           /// next request
+    int                        Want;           /// requested number
+    int                        Made;           /// builded number
+    UnitType*          Type;           /// unit-type
 };
 
-
-typedef struct _ai_running_script_ AiRunningScript;
-
 /**
 **     AI running script ( with state, ... )
 */
-struct _ai_running_script_
-{
-    SCM Script;                        /// Script executed
-    unsigned long SleepCycles; /// Cycles to sleep
-    char ident[10];            /// Debugging !
-    int HotSpot_X;             /// Hot spot ( for defense, attack, ... )
-    int HotSpot_Y;
-    int HotSpot_Ray;
+typedef struct _ai_running_script_ {
+    SCM                        Script;         /// Script executed
+    unsigned long      SleepCycles;    /// Cycles to sleep
+    char               ident[10];      /// Debugging !
+    int                        HotSpot_X;      /// Hot spot ( for defense, 
attack, ... )
+    int                        HotSpot_Y;
+    int                        HotSpot_Ray;
 
-    int ownForce;              /// A force ID ( the n° of the script... )
+    int                        ownForce;       /// A force ID ( the n° of the 
script... )
 
-   // Total number of ressource gauges
+    // Total number of ressource gauges
 #define RESSOURCE_COUNT 3
-   // Total number of forces gauges
+    // Total number of forces gauges
 #define FORCE_COUNT    11
 
 #define GAUGE_NB (3+(RESSOURCE_COUNT*2)+(FORCE_COUNT*6))
-    int *gauges;               /// Gauges values ( initially 0 )               
-};
+    int*               gauges;         /// Gauges values ( initially 0 )       
        
+} AiRunningScript;
 
 /**
 **     Ai script action 
@@ -221,18 +202,20 @@
 **
 **     Linked list.
 */
-typedef struct _ai_script_action_ AiScriptAction;
+typedef struct _ai_script_action_ {
+    SCM                        Action;         /// Scheme description, in the 
form : 
+                                       /// '((name evaluate-lambda run-script) 
... )
 
-struct _ai_script_action_
-{
-    SCM Action;                        /// Scheme description, in the form : 
-   /// '((name evaluate-lambda run-script) ... )
+    int                        Defensive;      /// Is this action usable for 
defense
+    int                        Offensive;      /// Is this action usable for 
attack
 
-    int Defensive;             /// Is this action usable for defense
-    int Offensive;             /// Is this action usable for attack
+    /// TODO : hotspot_kind : set if the hotspot should contain path from base 
     
+} AiScriptAction;
 
-   /// TODO : hotspot_kind : set if the hotspot should contain path from base  
    
-};
+/**
+**     AiActionEvaluation typedef
+*/
+typedef struct _ai_action_evaluation_ AiActionEvaluation;
 
 /**
 **     Ai action evaluation 
@@ -243,85 +226,77 @@
 **     From time to time, the best unfired try is fired.
 **     
 */
-typedef struct _ai_action_evaluation_ AiActionEvaluation;
+struct _ai_action_evaluation_ {
+    AiScriptAction*    aiScriptAction; /// Action evaluated
 
-struct _ai_action_evaluation_
-{
-    AiScriptAction *aiScriptAction;
+    int                        hotSpotX;       /// X position of the hotspot, 
or -1
+    int                        hotSpotY;       /// Y position of the hotspot, 
or -1
 
-    int hotSpotX;
-    int hotSpotY;
+    int                        hotSpotValue;   /// Value of the hotspot ( 
total points to get... )
 
-   // Value of the hotspot ( total points to get... )
-    int hotSpotValue;
+    int                        value;          /// Result of the evaluation ( 
ressources needed... )
 
-   // Evaluation of the script ( ressources needed... )
-    int value;
-
-    AiActionEvaluation *Next;
+    AiActionEvaluation*        Next;           /// Next in linked list
 };
 
 /**
 **     AI variables.
 */
-typedef struct _player_ai_
-{
-    Player *Player;            /// Engine player structure
+typedef struct _player_ai_ {
+    Player*            Player;         /// Engine player structure
 
-    AiType *AiType;            /// AI type of this player AI
+    AiType*            AiType;         /// AI type of this player AI
 
-   // controller
+    // controller
 #define AI_MAX_RUNNING_SCRIPTS 5       /// ( generic, attack, defend, ... )
 #define AI_MAIN_SCRIPT 0
-    AiRunningScript Scripts[AI_MAX_RUNNING_SCRIPTS];
+    AiRunningScript Scripts[AI_MAX_RUNNING_SCRIPTS];/// All running scripts
 
-   // Ai "memory"
-#define AI_MEMORY_SIZE 30      /// Max number of keept evaluation ( => 30 sec )
-    AiActionEvaluation *FirstEvaluation;
-    AiActionEvaluation *LastEvaluation;
-    int EvaluationCount;
+    // Ai "memory"
+#define AI_MEMORY_SIZE 30              /// Max number of keept evaluation ( => 
30 sec )
+    AiActionEvaluation*        FirstEvaluation;/// begining of linked list of 
evaluation
+    AiActionEvaluation*        LastEvaluation; /// end of linked list of 
evaluation
+    int                        EvaluationCount;/// size of linked list of 
evaluation
 
-    int ScriptDebug;           /// Flag script debuging on/off
+    int                        ScriptDebug;    /// Flag script debuging on/off
 
-    int AutoAttack;            /// Are attack started automatically ?
+    int                        AutoAttack;     /// Are attack started 
automatically ?
 
-   // forces
-#define AI_MAX_FORCES  10      /// How many forces are supported
+    // forces
+#define AI_MAX_FORCES  10              /// How many forces are supported
 #define AI_GENERIC_FORCES      (AI_MAX_FORCES-AI_MAX_RUNNING_SCRIPTS)  /// How 
many forces are useable in the main script
     AiForce Force[AI_MAX_FORCES];      /// Forces controlled by AI
 
-   // resource manager
-    int Reserve[MaxCosts];     /// Resources to keep in reserve
-    int Used[MaxCosts];                /// Used resources
-    int Needed[MaxCosts];      /// Needed resources
-    int Collect[MaxCosts];     /// Collect % of resources
-    int NeededMask;            /// Mask for needed resources
-
-    int NeedFood;              /// Flag need food
-
-   /// number of elements in UnitTypeRequests
-    int UnitTypeRequestsCount;
-   /// unit-types to build/train requested and priority list
-    AiUnitTypeTable *UnitTypeRequests;
-   /// number of elements in UpgradeRequests
-    int UpgradeToRequestsCount;
-   /// Upgrade to unit-type requested and priority list
-    UnitType **UpgradeToRequests;
-   /// number of elements in ResearchRequests
-    int ResearchRequestsCount;
-   /// Upgrades requested and priority list
-    Upgrade **ResearchRequests;
-
-   /// What the resource manager should build
-    AiBuildQueue *UnitTypeBuilded;
-
-   /// Last building checked for repair in this turn
-    int LastRepairBuilding;
-   /// Number of workers that unsuccessfully tried to repair a building
-    unsigned TriedRepairWorkers[UnitMax];
-
-}
-PlayerAi;
+    // resource manager
+    int                        Reserve[MaxCosts];/// Resources to keep in 
reserve
+    int                        Used[MaxCosts]; /// Used resources
+    int                        Needed[MaxCosts];/// Needed resources
+    int                        Collect[MaxCosts];/// Collect % of resources
+    int                        NeededMask;     /// Mask for needed resources
+
+    int                        NeedFood;       /// Flag need food
+
+    /// number of elements in UnitTypeRequests
+    int                        UnitTypeRequestsCount;
+    /// unit-types to build/train requested and priority list
+    AiUnitTypeTable*   UnitTypeRequests;
+    /// number of elements in UpgradeRequests
+    int                        UpgradeToRequestsCount;
+    /// Upgrade to unit-type requested and priority list
+    UnitType**         UpgradeToRequests;
+    /// number of elements in ResearchRequests
+    int                        ResearchRequestsCount;
+    /// Upgrades requested and priority list
+    Upgrade**          ResearchRequests;
+
+    /// What the resource manager should build
+    AiBuildQueue*      UnitTypeBuilded;
+
+    /// Last building checked for repair in this turn
+    int                        LastRepairBuilding;
+    /// Number of workers that unsuccessfully tried to repair a building
+    unsigned           TriedRepairWorkers[UnitMax];
+} PlayerAi;
 
 /**
 **     AI Helper.
@@ -330,67 +305,65 @@
 **     building or upgrade or spell, it could lookup in this tables to find
 **     where it could be trained, builded or researched.
 */
-typedef struct _ai_helper_
-{
+typedef struct _ai_helper_ {
     /**
     ** The index is the unit that should be trained, giving a table of all
     ** units/buildings which could train this unit.
     */
-    int TrainCount;
-    AiUnitTypeTable **Train;
+    int                        TrainCount;
+    AiUnitTypeTable**  Train;
     /**
     ** The index is the unit that should be build, giving a table of all
     ** units/buildings which could build this unit.
     */
-    int BuildCount;
-    AiUnitTypeTable **Build;
+    int                        BuildCount;
+    AiUnitTypeTable**  Build;
     /**
     ** The index is the upgrade that should be made, giving a table of all
     ** units/buildings which could do the upgrade.
     */
-    int UpgradeCount;
-    AiUnitTypeTable **Upgrade;
+    int                        UpgradeCount;
+    AiUnitTypeTable**  Upgrade;
     /**
     ** The index is the research that should be made, giving a table of all
     ** units/buildings which could research this upgrade.
     */
-    int ResearchCount;
-    AiUnitTypeTable **Research;
+    int                        ResearchCount;
+    AiUnitTypeTable**  Research;
     /**
     ** The index is the unit that should be repaired, giving a table of all
     ** units/buildings which could repair this unit.
     */
-    int RepairCount;
-    AiUnitTypeTable **Repair;
+    int                        RepairCount;
+    AiUnitTypeTable**  Repair;
     /**
     ** The index is the unit-limit that should be solved, giving a table of all
     ** units/buildings which could reduce this unit-limit.
     */
-    int UnitLimitCount;
-    AiUnitTypeTable **UnitLimit;
+    int                        UnitLimitCount;
+    AiUnitTypeTable**  UnitLimit;
     /**
     ** The index is the unit that should be made, giving a table of all
     ** units/buildings which are equivalent.
     */
-    int EquivCount;
-    AiUnitTypeTable **Equiv;
-}
-AiHelper;
+    int                        EquivCount;
+    AiUnitTypeTable**  Equiv;
+} AiHelper;
 
 /*----------------------------------------------------------------------------
 --     Variables
 ----------------------------------------------------------------------------*/
 
-extern AiType *AiTypes;                /// List of all AI types
-extern AiHelper AiHelpers;     /// AI helper variables
+extern AiType* AiTypes;                        /// List of all AI types
+extern AiHelper AiHelpers;             /// AI helper variables
 
 #define MaxAiScriptActions     64      /// How many AiScriptActions are 
supported
-extern int AiScriptActionNum;  /// Current number of AiScriptAction
-extern AiScriptAction AiScriptActions[MaxAiScriptActions];     /// All 
availables AI script actions   
+extern int AiScriptActionNum;          /// Current number of AiScriptAction
+extern AiScriptAction AiScriptActions[MaxAiScriptActions];/// All availables 
AI script actions   
 
-extern PlayerAi *AiPlayer;     /// Current AI player
-extern AiRunningScript *AiScript;
-extern char **AiTypeWcNames;   /// pud num to internal string mapping
+extern PlayerAi* AiPlayer;             /// Current AI player
+extern AiRunningScript* AiScript;      /// Currently running script
+extern char** AiTypeWcNames;           /// pud num to internal string mapping
 
 /*----------------------------------------------------------------------------
 --     Functions
@@ -400,107 +373,107 @@
 //      Resource manager
 //
     /// Add unit-type request to resource manager
-extern void AiAddUnitTypeRequest( UnitType * type, int count );
+extern void AiAddUnitTypeRequest(UnitType * type, int count);
     /// Add upgrade-to request to resource manager
-extern void AiAddUpgradeToRequest( UnitType * type );
+extern void AiAddUpgradeToRequest(UnitType * type);
     /// Add research request to resource manager
-extern void AiAddResearchRequest( Upgrade * upgrade );
+extern void AiAddResearchRequest(Upgrade * upgrade);
     /// Periodic called resource manager handler
-extern void AiResourceManager( void );
+extern void AiResourceManager(void);
     /// Count the number of builder unit available for the given unittype
-extern int AiCountUnitBuilders( UnitType * type );
+extern int AiCountUnitBuilders(UnitType * type);
 
 //
 //      Buildings
 //
     /// Find nice building place
-extern int AiFindBuildingPlace( const Unit *, const UnitType *, int *, int * );
+extern int AiFindBuildingPlace(const Unit *, const UnitType *, int *, int *);
 
 //
 //      Forces
 //
     /// Cleanup units in force
-extern void AiCleanForces( void );
+extern void AiCleanForces(void);
     /// Cleanup units in the given force
-extern void AiCleanForce( int force );
+extern void AiCleanForce(int force);
     /// Remove everything in the given force
-extern void AiEraseForce( int force );
+extern void AiEraseForce(int force);
     /// Assign a new unit to a force
-extern void AiAssignToForce( Unit * unit );
+extern void AiAssignToForce(Unit * unit);
     /// Assign a free units to a force
-extern void AiAssignFreeUnitsToForce( void );
+extern void AiAssignFreeUnitsToForce(void);
     /// Complete a force with units form another
-extern void AiForceTransfert( int src, int dst );
+extern void AiForceTransfert(int src, int dst);
     /// Group a force on the nearest unit to target
-extern void AiGroupForceNear( int force, int targetx, int targety );
+extern void AiGroupForceNear(int force, int targetx, int targety);
     /// Attack with force at position
-extern void AiAttackWithForceAt( int force, int x, int y );
+extern void AiAttackWithForceAt(int force, int x, int y);
     /// Attack with force
-extern void AiAttackWithForce( int force );
+extern void AiAttackWithForce(int force);
     /// Send force home
-extern void AiSendForceHome( int force );
+extern void AiSendForceHome(int force);
     /// Evaluate the cost to build a force (time to build + ressources)
-extern int AiEvaluateForceCost( int force, int total );
+extern int AiEvaluateForceCost(int force, int total);
     /// Complete a force from existing units.
-extern void AiForceComplete( int force );
+extern void AiForceComplete(int force);
     /// Enrole one or more units of a type in a force
-extern int AiEnroleSpecificUnitType( int force, UnitType * ut, int count );
+extern int AiEnroleSpecificUnitType(int force, UnitType * ut, int count);
     /// Create a force from existing units, ready to respond to the powers
-extern int AiCreateSpecificForce( int *power, int *unittypes, int 
unittypescount );
+extern int AiCreateSpecificForce(int *power, int *unittypes, int 
unittypescount);
     /// Force's unit is attacked.
-extern void AiForceHelpMe( int force, const Unit * attacker, Unit * defender );
+extern void AiForceHelpMe(int force, const Unit * attacker, Unit * defender);
     /// Periodic called force manager handler
-extern void AiForceManager( void );
+extern void AiForceManager(void);
     /// Calculate the number of unit produced for each wanted unittype   
-extern void AiForceCountUnits( int force, int *unittypeCount );
+extern void AiForceCountUnits(int force, int *unittypeCount);
     /// Substract the number of unit wanted for each unittype
-extern int AiForceSubstractWant( int force, int *unittypeCount );
+extern int AiForceSubstractWant(int force, int *unittypeCount);
+
 //
 //      Plans
 //
     /// Find a wall to attack
-extern int AiFindWall( AiForce * force );
+extern int AiFindWall(AiForce * force);
     /// Plan the an attack
-extern int AiPlanAttack( AiForce * force );
+extern int AiPlanAttack(AiForce * force);
 
 //
 //      Scripts
 //
        /// Run a script ( for the current AiPlayer )
-extern void AiRunScript( int script, SCM list, int hotSpotX, int hotSpotY, int 
hotSpotRay );
+extern void AiRunScript(int script, SCM list, int hotSpotX, int hotSpotY, int 
hotSpotRay);
        /// Find a script for defense.
-extern void AiFindDefendScript( int attackX, int attackY );
+extern void AiFindDefendScript(int attackX, int attackY);
        /// Check if attack is possible
-extern void AiPeriodicAttack();
+extern void AiPeriodicAttack(void);
+
 //
 //      Gauges
 //
     /// Compute gauges for the current RunningScript
-extern void AiComputeCurrentScriptGauges();
+extern void AiComputeCurrentScriptGauges(void);
     /// Output gauges values
-extern void AiDebugGauges();
+extern void AiDebugGauges(void);
     /// Give the value of a specific gauge, for the current RunningScript
-extern int AiGetGaugeValue( int gauge );
+extern int AiGetGaugeValue(int gauge);
     /// Find a gauge given its identifier. 
-extern int AiFindGaugeId( SCM id );
+extern int AiFindGaugeId(SCM id);
     /// return the force of the unittype.
-extern int AiUnittypeForce( UnitType * unitType );
+extern int AiUnittypeForce(UnitType * unitType);
 
 //
 //      Magic
 //
     /// Check for magic
-extern void AiCheckMagic( void );
-
+extern void AiCheckMagic(void);
 
 //
 //      Ccl helpers
 //
 
     /// Save/Load a PlayerAi structure ( see ccl_helpers.h for details )
-extern void IOPlayerAiFullPtr( SCM form, void *binaryform, void *para );
-
+extern void IOPlayerAiFullPtr(SCM form, void *binaryform, void *para);
 
 //@}
 
-#endif                         // !__AI_LOCAL_H__
+#endif         // !__AI_LOCAL_H__
Index: stratagus/src/ai/ai_magic.c
diff -u stratagus/src/ai/ai_magic.c:1.21 stratagus/src/ai/ai_magic.c:1.22
--- stratagus/src/ai/ai_magic.c:1.21    Thu Oct 23 14:38:34 2003
+++ stratagus/src/ai/ai_magic.c Sun Oct 26 10:34:58 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//      $Id: ai_magic.c,v 1.21 2003/10/23 18:38:34 n0body Exp $
+//      $Id: ai_magic.c,v 1.22 2003/10/26 15:34:58 pludov Exp $
 
 //@{
 
@@ -54,7 +54,7 @@
 **     Check what computer units can do with magic.
 **     In fact, turn on autocast for AI.
 */
-global void AiCheckMagic( void )
+global void AiCheckMagic(void)
 {
     int i, j;
     int n;
@@ -67,22 +67,22 @@
 
     n = AiPlayer->Player->TotalNumUnits;
     units = AiPlayer->Player->Units;
-    player = AiPlayer->Player; /*units[0]->Player */
-    for ( i = 0; i < n; ++i ) {
+    player = AiPlayer->Player;         /*units[0]->Player */
+    for (i = 0; i < n; ++i) {
        unit = units[i];
-       //  Check only magic units
-       if ( unit->Type->CanCastSpell ) {
-           for ( j = 0; j < SpellTypeCount; ++j ) {
-              //  Check if we can cast this spell. SpellIsAvailable checks for 
upgrades.
-               if ( unit->Type->CanCastSpell[j] && SpellIsAvailable( player, j 
) &&
-                    ( SpellTypeById( j )->AutoCast || SpellTypeById( j 
)->AICast ) ) {
+       //  Check only magic units
+       if (unit->Type->CanCastSpell) {
+           for (j = 0; j < SpellTypeCount; ++j) {
+               //  Check if we can cast this spell. SpellIsAvailable checks 
for upgrades.
+               if (unit->Type->CanCastSpell[j] && SpellIsAvailable(player, j) 
&&
+                   (SpellTypeById(j)->AutoCast || SpellTypeById(j)->AICast)) {
 #ifdef DEBUG
-                   success =   // Follow on next line (AutoCastSpell).
+                   success =           // Follow on next line (AutoCastSpell).
 #endif
-                       AutoCastSpell( unit, SpellTypeById( j ) );
-                   DebugLevel3Fn( "Mage '%s' cast '%s' : %s\n" _C_
-                                  unit->Type->Ident _C_
-                                  SpellTypeById( j )->Ident _C_ success ? 
"success" : "fail" );
+                       AutoCastSpell(unit, SpellTypeById(j));
+                   DebugLevel3Fn("Mage '%s' cast '%s' : %s\n" _C_
+                       unit->Type->Ident _C_
+                       SpellTypeById(j)->Ident _C_ success ? "success" : 
"fail");
                }
            }
        }
Index: stratagus/src/ai/ai_plan.c
diff -u stratagus/src/ai/ai_plan.c:1.18 stratagus/src/ai/ai_plan.c:1.19
--- stratagus/src/ai/ai_plan.c:1.18     Thu Oct 23 14:38:34 2003
+++ stratagus/src/ai/ai_plan.c  Sun Oct 26 10:34:58 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//      $Id: ai_plan.c,v 1.18 2003/10/23 18:38:34 n0body Exp $
+//      $Id: ai_plan.c,v 1.19 2003/10/26 15:34:58 pludov Exp $
 
 //@{
 
@@ -63,7 +63,7 @@
 **
 **     @return         Returns ideal target on map tile.
 */
-local Unit *EnemyOnMapTile( const Unit * source, int tx, int ty )
+local Unit *EnemyOnMapTile(const Unit * source, int tx, int ty)
 {
     Unit *table[UnitMax];
     Unit *unit;
@@ -72,34 +72,34 @@
     int n;
     int i;
 
-    n = SelectUnitsOnTile( tx, ty, table );
+    n = SelectUnitsOnTile(tx, ty, table);
     best = NoUnitP;
-    for ( i = 0; i < n; ++i ) {
+    for (i = 0; i < n; ++i) {
        unit = table[i];
-       // unusable unit ?
-       // if( UnitUnusable(unit) ) can't attack constructions
-       // FIXME: did SelectUnitsOnTile already filter this?
-       // Invisible and not Visible
-       if ( unit->Removed || unit->Invisible || !unit->HP
-            || !( unit->Visible & ( 1 << source->Player->Player ) )
-            || unit->Orders[0].Action == UnitActionDie ) {
+       // unusable unit ?
+       // if( UnitUnusable(unit) ) can't attack constructions
+       // FIXME: did SelectUnitsOnTile already filter this?
+       // Invisible and not Visible
+       if (unit->Removed || unit->Invisible || !unit->HP
+           || !(unit->Visible & (1 << source->Player->Player))
+           || unit->Orders[0].Action == UnitActionDie) {
            continue;
        }
        type = unit->Type;
-       if ( tx < unit->X || tx >= unit->X + type->TileWidth
-            || ty < unit->Y || ty >= unit->Y + type->TileHeight ) {
+       if (tx < unit->X || tx >= unit->X + type->TileWidth
+           || ty < unit->Y || ty >= unit->Y + type->TileHeight) {
            continue;
        }
-       if ( !CanTarget( source->Type, unit->Type ) ) {
+       if (!CanTarget(source->Type, unit->Type)) {
            continue;
        }
-       if ( !IsEnemy( source->Player, unit ) ) {       // a friend or neutral
+       if (!IsEnemy(source->Player, unit)) {   // a friend or neutral
            continue;
        }
-       //
-       //      Choose the best target.
-       //
-       if ( !best || best->Type->Priority < unit->Type->Priority ) {
+       //
+       //      Choose the best target.
+       //
+       if (!best || best->Type->Priority < unit->Type->Priority) {
            best = unit;
        }
     }
@@ -114,16 +114,14 @@
 **
 **     @note only works for water transporters!
 */
-local void AiMarkWaterTransporter( const Unit * unit, unsigned char *matrix )
+local void AiMarkWaterTransporter(const Unit * unit, unsigned char *matrix)
 {
     static const int xoffset[] = { 0, -1, +1, 0, -1, +1, -1, +1 };
     static const int yoffset[] = { -1, 0, 0, +1, -1, -1, +1, +1 };
-    struct
-    {
+    struct {
        unsigned short X;
        unsigned short Y;
-    }
-    *points;
+    }     *points;
     int size;
     int x;
     int y;
@@ -141,72 +139,72 @@
     y = unit->Y;
     w = TheMap.Width + 2;
     matrix += w + w + 2;
-    if ( matrix[x + y * w] ) { // already marked
-       DebugLevel0( "Done\n" );
+    if (matrix[x + y * w]) {           // already marked
+       DebugLevel0("Done\n");
        return;
     }
 
-    points = malloc( TheMap.Width * TheMap.Height );
-    size = TheMap.Width * TheMap.Height / sizeof ( *points );
+    points = malloc(TheMap.Width * TheMap.Height);
+    size = TheMap.Width * TheMap.Height / sizeof (*points);
 
-   //
-   //  Make movement matrix.
-   //
-    mask = UnitMovementMask( unit );
-   // Ignore all possible mobile units.
-    mask &= ~( MapFieldLandUnit | MapFieldAirUnit | MapFieldSeaUnit );
+    //
+    //  Make movement matrix.
+    //
+    mask = UnitMovementMask(unit);
+    // Ignore all possible mobile units.
+    mask &= ~(MapFieldLandUnit | MapFieldAirUnit | MapFieldSeaUnit);
 
     points[0].X = x;
     points[0].Y = y;
     rp = 0;
-    matrix[x + y * w] = 66;    // mark start point
-    ep = wp = 1;               // start with one point
+    matrix[x + y * w] = 66;            // mark start point
+    ep = wp = 1;                       // start with one point
 
-   //
-   //  Pop a point from stack, push all neightbors which could be entered.
-   //
-    for ( ;; ) {
-       while ( rp != ep ) {
+    //
+    //  Pop a point from stack, push all neightbors which could be entered.
+    //
+    for (;;) {
+       while (rp != ep) {
            rx = points[rp].X;
            ry = points[rp].Y;
-           for ( i = 0; i < 8; ++i ) { // mark all neighbors
+           for (i = 0; i < 8; ++i) {   // mark all neighbors
                x = rx + xoffset[i];
                y = ry + yoffset[i];
                m = matrix + x + y * w;
-               if ( *m ) {     // already checked
+               if (*m) {               // already checked
                    continue;
                }
 
-               if ( CanMoveToMask( x, y, mask ) ) {    // reachable
+               if (CanMoveToMask(x, y, mask)) {        // reachable
 
                    *m = 66;
                    points[wp].X = x;   // push the point
                    points[wp].Y = y;
-                   if ( ++wp >= size ) {       // round about
+                   if (++wp >= size) { // round about
                        wp = 0;
                    }
-                  /*      Must be checked multiple
-                     } else {                     // unreachable
-                     *m=99;
-                   */
+                   /*      Must be checked multiple
+                      } else {                     // unreachable
+                      *m=99;
+                    */
                }
            }
 
-           if ( ++rp >= size ) {       // round about
+           if (++rp >= size) {         // round about
                rp = 0;
            }
        }
 
-       //
-       //      Continue with next frame.
-       //
-       if ( rp == wp ) {       // unreachable, no more points available
+       //
+       //      Continue with next frame.
+       //
+       if (rp == wp) {                 // unreachable, no more points available
            break;
        }
        ep = wp;
     }
 
-    free( points );
+    free(points);
 }
 
 /**
@@ -220,17 +218,16 @@
 **
 **     @return         True if target found.
 */
-local int AiFindTarget( const Unit * unit, unsigned char *matrix, int *dx, int 
*dy, int *ds )
+local int AiFindTarget(const Unit * unit, unsigned char *matrix, int *dx, int 
*dy,
+    int *ds)
 {
     static const int xoffset[] = { 0, -1, +1, 0, -1, +1, -1, +1 };
     static const int yoffset[] = { -1, 0, 0, +1, -1, -1, +1, +1 };
-    struct
-    {
+    struct {
        unsigned short X;
        unsigned short Y;
        unsigned char State;
-    }
-    *points;
+    }     *points;
     int size;
     int x;
     int y;
@@ -242,123 +239,121 @@
     int ep;
     int i;
     int w;
-    enum
-    { OnWater, OnLand, OnIsle }
-    state;
+    enum { OnWater, OnLand, OnIsle } state;
     unsigned char *m;
 
     size = TheMap.Width * TheMap.Height / 2;
-    points = malloc( size * sizeof ( *points ) );
+    points = malloc(size * sizeof (*points));
 
     x = unit->X;
     y = unit->Y;
 
     w = TheMap.Width + 2;
-    mask = UnitMovementMask( unit );
-   // Ignore all possible mobile units.
-    mask &= ~( MapFieldLandUnit | MapFieldAirUnit | MapFieldSeaUnit );
+    mask = UnitMovementMask(unit);
+    // Ignore all possible mobile units.
+    mask &= ~(MapFieldLandUnit | MapFieldAirUnit | MapFieldSeaUnit);
 
     points[0].X = x;
     points[0].Y = y;
     points[0].State = OnLand;
     matrix += w + w + 2;
     rp = 0;
-    matrix[x + y * w] = 1;     // mark start point
-    ep = wp = 1;               // start with one point
+    matrix[x + y * w] = 1;             // mark start point
+    ep = wp = 1;                       // start with one point
 
-   //
-   //  Pop a point from stack, push all neightbors which could be entered.
-   //
-    for ( ;; ) {
-       while ( rp != ep ) {
+    //
+    //  Pop a point from stack, push all neightbors which could be entered.
+    //
+    for (;;) {
+       while (rp != ep) {
            rx = points[rp].X;
            ry = points[rp].Y;
            state = points[rp].State;
-           for ( i = 0; i < 8; ++i ) { // mark all neighbors
+           for (i = 0; i < 8; ++i) {   // mark all neighbors
                x = rx + xoffset[i];
                y = ry + yoffset[i];
                m = matrix + x + y * w;
 
-               if ( state != OnWater ) {
-                   if ( *m ) { // already checked
-                       if ( state == OnLand && *m == 66 ) {    // tansporter?
-                           DebugLevel0Fn( "->Water\n" );
+               if (state != OnWater) {
+                   if (*m) {           // already checked
+                       if (state == OnLand && *m == 66) {      // tansporter?
+                           DebugLevel0Fn("->Water\n");
                            *m = 6;
                            points[wp].X = x;   // push the point
                            points[wp].Y = y;
                            points[wp].State = OnWater;
-                           if ( ++wp >= size ) {       // round about
+                           if (++wp >= size) { // round about
                                wp = 0;
                            }
                        }
                        continue;
                    }
-                  // Check targets on tile?
-                  // FIXME: the move code didn't likes a shore building as
-                  //          target
-                   if ( EnemyOnMapTile( unit, x, y ) ) {
-                       DebugLevel0Fn( "Target found %d,%d-%d\n" _C_ x _C_ y 
_C_ state );
+                   // Check targets on tile?
+                   // FIXME: the move code didn't likes a shore building as
+                   //          target
+                   if (EnemyOnMapTile(unit, x, y)) {
+                       DebugLevel0Fn("Target found %d,%d-%d\n" _C_ x _C_ y _C_ 
state);
                        *dx = x;
                        *dy = y;
                        *ds = state;
-                       free( points );
+                       free(points);
                        return 1;
                    }
 
-                   if ( CanMoveToMask( x, y, mask ) ) {        // reachable
+                   if (CanMoveToMask(x, y, mask)) {    // reachable
 
                        *m = 1;
                        points[wp].X = x;       // push the point
                        points[wp].Y = y;
                        points[wp].State = state;
-                       if ( ++wp >= size ) {   // round about
+                       if (++wp >= size) {     // round about
                            wp = 0;
                        }
-                   } else {    // unreachable
+                   } else {            // unreachable
                        *m = 99;
                    }
-               } else {        // On water
-                   if ( *m ) { // already checked 
-                       if ( *m == 66 ) {       // tansporter?
+               } else {                // On water
+                   if (*m) {           // already checked 
+                       if (*m == 66) { // tansporter?
                            *m = 6;
                            points[wp].X = x;   // push the point
                            points[wp].Y = y;
                            points[wp].State = OnWater;
-                           if ( ++wp >= size ) {       // round about
+                           if (++wp >= size) { // round about
                                wp = 0;
                            }
                        }
                        continue;
                    }
-                   if ( CanMoveToMask( x, y, mask ) ) {        // reachable
-                       DebugLevel0Fn( "->Land\n" );
+                   if (CanMoveToMask(x, y, mask)) {    // reachable
+                       DebugLevel0Fn("->Land\n");
                        *m = 1;
                        points[wp].X = x;       // push the point
                        points[wp].Y = y;
                        points[wp].State = OnIsle;
-                       if ( ++wp >= size ) {   // round about
+                       if (++wp >= size) {     // round about
                            wp = 0;
                        }
-                   } else {    // unreachable
+                   } else {            // unreachable
                        *m = 99;
                    }
                }
            }
 
-           if ( ++rp >= size ) {       // round about
+           if (++rp >= size) {         // round about
                rp = 0;
            }
        }
 
-       //
-       //      Continue with next frame.
-       //
-       if ( rp == wp ) {       // unreachable, no more points available
+       //
+       //      Continue with next frame.
+       //
+       if (rp == wp) {                 // unreachable, no more points available
            break;
        }
        ep = wp;
     }
-    free( points );
+    free(points);
     return 0;
 }
 
@@ -369,16 +364,14 @@
 **
 **     @return         True if wall found.
 */
-global int AiFindWall( AiForce * force )
+global int AiFindWall(AiForce * force)
 {
     static const int xoffset[] = { 0, -1, +1, 0, -1, +1, -1, +1 };
     static const int yoffset[] = { -1, 0, 0, +1, -1, -1, +1, +1 };
-    struct
-    {
+    struct {
        unsigned short X;
        unsigned short Y;
-    }
-    *points;
+    }     *points;
     int size;
     int x;
     int y;
@@ -397,14 +390,14 @@
     AiUnit *aiunit;
     Unit *unit;
 
-   // Find a unit to use.  Best choice is a land unit with range 1.
-   // Next best choice is any land unit.  Otherwise just use the first.
+    // Find a unit to use.  Best choice is a land unit with range 1.
+    // Next best choice is any land unit.  Otherwise just use the first.
     aiunit = force->Units;
     unit = aiunit->Unit;
-    while ( aiunit ) {
-       if ( aiunit->Unit->Type->UnitType == UnitTypeLand ) {
+    while (aiunit) {
+       if (aiunit->Unit->Type->UnitType == UnitTypeLand) {
            unit = aiunit->Unit;
-           if ( aiunit->Unit->Type->Missile.Missile->Range == 1 ) {
+           if (aiunit->Unit->Type->Missile.Missile->Range == 1) {
                break;
            }
        }
@@ -414,7 +407,7 @@
     x = unit->X;
     y = unit->Y;
     size = TheMap.Width * TheMap.Height / 4;
-    points = malloc( size * sizeof ( *points ) );
+    points = malloc(size * sizeof (*points));
 
     destx = -1;
     desty = -1;
@@ -426,69 +419,69 @@
     points[0].X = x;
     points[0].Y = y;
     rp = 0;
-    matrix[x + y * w] = 1;     // mark start point
-    ep = wp = 1;               // start with one point
+    matrix[x + y * w] = 1;             // mark start point
+    ep = wp = 1;                       // start with one point
 
-    mask = UnitMovementMask( unit );
+    mask = UnitMovementMask(unit);
 
-   //
-   //  Pop a point from stack, push all neighbors which could be entered.
-   //
-    for ( ; destx == -1; ) {
-       while ( rp != ep && destx == -1 ) {
+    //
+    //  Pop a point from stack, push all neighbors which could be entered.
+    //
+    for (; destx == -1;) {
+       while (rp != ep && destx == -1) {
            rx = points[rp].X;
            ry = points[rp].Y;
-           for ( i = 0; i < 8; ++i ) { // mark all neighbors
+           for (i = 0; i < 8; ++i) {   // mark all neighbors
                x = rx + xoffset[i];
                y = ry + yoffset[i];
                m = matrix + x + y * w;
-               if ( *m ) {
+               if (*m) {
                    continue;
                }
-              // 
-              //      Check for a wall
-              //
-               if ( WallOnMap( x, y ) ) {
-                   DebugLevel0Fn( "Wall found %d,%d\n" _C_ x _C_ y );
+               // 
+               //      Check for a wall
+               //
+               if (WallOnMap(x, y)) {
+                   DebugLevel0Fn("Wall found %d,%d\n" _C_ x _C_ y);
                    destx = x;
                    desty = y;
                    break;
                }
 
-               if ( CanMoveToMask( x, y, mask ) ) {    // reachable
+               if (CanMoveToMask(x, y, mask)) {        // reachable
                    *m = 1;
                    points[wp].X = x;   // push the point
                    points[wp].Y = y;
-                   if ( ++wp >= size ) {       // round about
+                   if (++wp >= size) { // round about
                        wp = 0;
                    }
-               } else {        // unreachable
+               } else {                // unreachable
                    *m = 99;
                }
            }
-           if ( ++rp >= size ) {       // round about
+           if (++rp >= size) {         // round about
                rp = 0;
            }
        }
 
-       //
-       //      Continue with next frame.
-       //
-       if ( rp == wp ) {       // unreachable, no more points available
+       //
+       //      Continue with next frame.
+       //
+       if (rp == wp) {                 // unreachable, no more points available
            break;
        }
        ep = wp;
     }
-    free( points );
+    free(points);
 
-    if ( destx != -1 ) {
+    if (destx != -1) {
        force->State = 0;
        aiunit = force->Units;
-       while ( aiunit ) {
-           if ( aiunit->Unit->Type->CanAttack ) {
-               CommandAttack( aiunit->Unit, destx, desty, NULL, FlushCommands 
);
+       while (aiunit) {
+           if (aiunit->Unit->Type->CanAttack) {
+               CommandAttack(aiunit->Unit, destx, desty, NULL, FlushCommands);
            } else {
-               CommandMove( aiunit->Unit, destx, desty, FlushCommands );
+               CommandMove(aiunit->Unit, destx, desty, FlushCommands);
            }
            aiunit = aiunit->Next;
        }
@@ -509,7 +502,7 @@
 **     @todo   Perfect planning.
 **             Only works for water transporter!
 */
-global int AiPlanAttack( AiForce * force )
+global int AiPlanAttack(AiForce * force)
 {
     char *watermatrix;
     const AiUnit *aiunit;
@@ -519,81 +512,81 @@
     int state;
     Unit *transporter;
 
-    DebugLevel0Fn( "Planning for force #%d of player #%d\n"
-                  _C_ force - AiPlayer->Force _C_ AiPlayer->Player->Player );
+    DebugLevel0Fn("Planning for force #%d of player #%d\n"
+       _C_ force - AiPlayer->Force _C_ AiPlayer->Player->Player);
 
     watermatrix = CreateMatrix();
 
-   //
-   //  Transporter must be already assigned to the force.
-   //  NOTE: finding free transportes was too much work for me.
-   //
+    //
+    //  Transporter must be already assigned to the force.
+    //  NOTE: finding free transportes was too much work for me.
+    //
     aiunit = force->Units;
     state = 1;
-    while ( aiunit ) {
-       if ( aiunit->Unit->Type->Transporter ) {
-           DebugLevel0Fn( "Transporter #%d\n" _C_ UnitNumber( aiunit->Unit ) );
-           AiMarkWaterTransporter( aiunit->Unit, watermatrix );
+    while (aiunit) {
+       if (aiunit->Unit->Type->Transporter) {
+           DebugLevel0Fn("Transporter #%d\n" _C_ UnitNumber(aiunit->Unit));
+           AiMarkWaterTransporter(aiunit->Unit, watermatrix);
            state = 0;
        }
        aiunit = aiunit->Next;
     }
 
-   //
-   //  No transport that belongs to the force.
-   //
+    //
+    //  No transport that belongs to the force.
+    //
     transporter = NULL;
-    if ( state ) {
-       for ( i = 0; i < AiPlayer->Player->TotalNumUnits; ++i ) {
+    if (state) {
+       for (i = 0; i < AiPlayer->Player->TotalNumUnits; ++i) {
            Unit *unit;
 
            unit = AiPlayer->Player->Units[i];
-           if ( unit->Type->Transporter && UnitIdle( unit ) ) {
-               DebugLevel0Fn( "Assign any transporter\n" );
-               AiMarkWaterTransporter( unit, watermatrix );
-              // FIXME: can be the wrong transporter.
+           if (unit->Type->Transporter && UnitIdle(unit)) {
+               DebugLevel0Fn("Assign any transporter\n");
+               AiMarkWaterTransporter(unit, watermatrix);
+               // FIXME: can be the wrong transporter.
                transporter = unit;
                state = 0;
            }
        }
     }
 
-    if ( state ) {             // Absolute no transporter
-       DebugLevel0Fn( "No transporter available\n" );
-       // FIXME: should tell the resource manager we need a transporter!
+    if (state) {                       // Absolute no transporter
+       DebugLevel0Fn("No transporter available\n");
+       // FIXME: should tell the resource manager we need a transporter!
        return 0;
     }
-   //
-   //  Find a land unit of the force.
-   //          FIXME: if force is split over different places -> broken
-   //
+    //
+    //  Find a land unit of the force.
+    //          FIXME: if force is split over different places -> broken
+    //
     aiunit = force->Units;
-    while ( aiunit ) {
-       if ( aiunit->Unit->Type->UnitType == UnitTypeLand ) {
-           DebugLevel0Fn( "Landunit %d\n" _C_ UnitNumber( aiunit->Unit ) );
+    while (aiunit) {
+       if (aiunit->Unit->Type->UnitType == UnitTypeLand) {
+           DebugLevel0Fn("Landunit %d\n" _C_ UnitNumber(aiunit->Unit));
            break;
        }
        aiunit = aiunit->Next;
     }
 
-    if ( !aiunit ) {
-       DebugLevel0Fn( "No land unit in force\n" );
+    if (!aiunit) {
+       DebugLevel0Fn("No land unit in force\n");
        return 0;
     }
 
-    if ( AiFindTarget( aiunit->Unit, watermatrix, &x, &y, &state ) ) {
+    if (AiFindTarget(aiunit->Unit, watermatrix, &x, &y, &state)) {
        AiUnit *aiunit;
 
-       if ( transporter ) {
-           aiunit = malloc( sizeof ( *aiunit ) );
+       if (transporter) {
+           aiunit = malloc(sizeof (*aiunit));
            aiunit->Next = force->Units;
            force->Units = aiunit;
            aiunit->Unit = transporter;
-           RefsDebugCheck( transporter->Destroyed || !transporter->Refs );
+           RefsDebugCheck(transporter->Destroyed || !transporter->Refs);
            ++transporter->Refs;
        }
 
-       DebugLevel0Fn( "Can attack\n" );
+       DebugLevel0Fn("Can attack\n");
        force->GoalX = x;
        force->GoalY = y;
        force->MustTransport = state == 2;
Index: stratagus/src/ai/ai_resource.c
diff -u stratagus/src/ai/ai_resource.c:1.72 stratagus/src/ai/ai_resource.c:1.73
--- stratagus/src/ai/ai_resource.c:1.72 Thu Oct 23 14:38:34 2003
+++ stratagus/src/ai/ai_resource.c      Sun Oct 26 10:34:58 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//      $Id: ai_resource.c,v 1.72 2003/10/23 18:38:34 n0body Exp $
+//      $Id: ai_resource.c,v 1.73 2003/10/26 15:34:58 pludov Exp $
 
 //@{
 
@@ -46,7 +46,7 @@
 #include "ai_local.h"
 #include "actions.h"
 
-local int AiMakeUnit( UnitType * type );
+local int AiMakeUnit(UnitType * type);
 
 /*----------------------------------------------------------------------------
 --     Variables
@@ -65,7 +65,7 @@
 **
 **     @return         A bit field of the missing costs.
 */
-local int AiCheckCosts( const int *costs )
+local int AiCheckCosts(const int *costs)
 {
     int i;
     int j;
@@ -79,20 +79,20 @@
     const int *building_costs;
 
 
-   // FIXME: the used costs shouldn't be calculated here
+    // FIXME: the used costs shouldn't be calculated here
     used = AiPlayer->Used;
-    for ( j = 1; j < MaxCosts; ++j ) {
+    for (j = 1; j < MaxCosts; ++j) {
        used[j] = 0;
     }
 
     nunits = AiPlayer->Player->TotalNumUnits;
     units = AiPlayer->Player->Units;
-    for ( i = 0; i < nunits; ++i ) {
-       for ( k = 0; k < units[i]->OrderCount; ++k ) {
-           if ( units[i]->Orders[k].Action == UnitActionBuild ) {
+    for (i = 0; i < nunits; ++i) {
+       for (k = 0; k < units[i]->OrderCount; ++k) {
+           if (units[i]->Orders[k].Action == UnitActionBuild) {
                building_costs =
                    
units[i]->Orders[k].Type->Stats[AiPlayer->Player->Player].Costs;
-               for ( j = 1; j < MaxCosts; ++j ) {
+               for (j = 1; j < MaxCosts; ++j) {
                    used[j] += building_costs[j];
                }
            }
@@ -103,8 +103,8 @@
     err = 0;
     resources = AiPlayer->Player->Resources;
     reserve = AiPlayer->Reserve;
-    for ( i = 1; i < MaxCosts; ++i ) {
-       if ( resources[i] - used[i] < costs[i] - reserve[i] ) {
+    for (i = 1; i < MaxCosts; ++i) {
+       if (resources[i] - used[i] < costs[i] - reserve[i]) {
            err |= 1 << i;
        }
     }
@@ -124,40 +124,40 @@
 **     @todo   The number of food currently trained can be stored global
 **             for faster use.
 */
-local int AiCheckFood( const PlayerAi * pai, const UnitType * type )
+local int AiCheckFood(const PlayerAi * pai, const UnitType * type)
 {
     int remaining;
     const AiBuildQueue *queue;
 
-    DebugLevel3Fn( " for player %d\n" _C_ pai->Player->Player );
-   //
-   //  Count food supplies under construction.
-   //
+    DebugLevel3Fn(" for player %d\n" _C_ pai->Player->Player);
+    //
+    //  Count food supplies under construction.
+    //
     remaining = 0;
-    for ( queue = pai->UnitTypeBuilded; queue; queue = queue->Next ) {
-       if ( queue->Type->Supply ) {
-           DebugLevel3Fn( "Builded %d remain %d\n" _C_ queue->Made _C_ 
remaining );
+    for (queue = pai->UnitTypeBuilded; queue; queue = queue->Next) {
+       if (queue->Type->Supply) {
+           DebugLevel3Fn("Builded %d remain %d\n" _C_ queue->Made _C_ 
remaining);
            remaining += queue->Made * queue->Type->Supply;
        }
     }
-    DebugLevel3Fn( "Remain %d" _C_ remaining );
-   //
-   //  We are already out of food.
-   //
+    DebugLevel3Fn("Remain %d" _C_ remaining);
+    //
+    //  We are already out of food.
+    //
     remaining += pai->Player->Food - pai->Player->NumFoodUnits - type->Demand;
-    DebugLevel3Fn( "-Demand %d\n" _C_ remaining );
-    if ( remaining < 0 ) {
-       DebugLevel3Fn( " player %d needs more food\n" _C_ pai->Player->Player );
+    DebugLevel3Fn("-Demand %d\n" _C_ remaining);
+    if (remaining < 0) {
+       DebugLevel3Fn(" player %d needs more food\n" _C_ pai->Player->Player);
        return 0;
     }
-   //
-   //  Count what we train.
-   //
-    for ( queue = pai->UnitTypeBuilded; queue; queue = queue->Next ) {
-       if ( !queue->Type->Building ) {
-           DebugLevel3Fn( "Trained %d remain %d\n" _C_ queue->Made _C_ 
remaining );
-           if ( ( remaining -= queue->Made * queue->Type->Demand ) < 0 ) {
-               DebugLevel3Fn( " player %d needs more food\n" _C_ 
pai->Player->Player );
+    //
+    //  Count what we train.
+    //
+    for (queue = pai->UnitTypeBuilded; queue; queue = queue->Next) {
+       if (!queue->Type->Building) {
+           DebugLevel3Fn("Trained %d remain %d\n" _C_ queue->Made _C_ 
remaining);
+           if ((remaining -= queue->Made * queue->Type->Demand) < 0) {
+               DebugLevel3Fn(" player %d needs more food\n" _C_ 
pai->Player->Player);
                return 0;
            }
        }
@@ -174,9 +174,9 @@
 **
 **     @return         A bit field of the missing costs.
 */
-local int AiCheckUnitTypeCosts( const UnitType * type )
+local int AiCheckUnitTypeCosts(const UnitType * type)
 {
-    return AiCheckCosts( type->Stats[AiPlayer->Player->Player].Costs );
+    return AiCheckCosts(type->Stats[AiPlayer->Player->Player].Costs);
 }
 
 /**
@@ -187,7 +187,7 @@
 **
 **     @return         Number of enemy units.
 */
-global int EnemyUnitsInDistance( const Unit * unit, unsigned range )
+global int EnemyUnitsInDistance(const Unit * unit, unsigned range)
 {
     const Unit *dest;
     const UnitType *type;
@@ -199,41 +199,41 @@
     int e;
     const Player *player;
 
-    DebugLevel3Fn( "(%d)%s\n" _C_ UnitNumber( unit ) _C_ unit->Type->Ident );
+    DebugLevel3Fn("(%d)%s\n" _C_ UnitNumber(unit) _C_ unit->Type->Ident);
 
-   //
-   //  Select all units in range.
-   //
+    //
+    //  Select all units in range.
+    //
     x = unit->X;
     y = unit->Y;
-    n = SelectUnits( x - range, y - range, x + range + 1, y + range + 1, table 
);
+    n = SelectUnits(x - range, y - range, x + range + 1, y + range + 1, table);
 
     player = unit->Player;
     type = unit->Type;
 
-   //
-   //  Find the enemy units which can attack
-   //
-    for ( e = i = 0; i < n; ++i ) {
+    //
+    //  Find the enemy units which can attack
+    //
+    for (e = i = 0; i < n; ++i) {
        dest = table[i];
-       //
-       //      unusable unit
-       //
-       // FIXME: did SelectUnits already filter this.
-       if ( dest->Removed || dest->Invisible || !unit->HP
-            || !( dest->Visible & ( 1 << player->Player ) )
-            || dest->Orders[0].Action == UnitActionDie ) {
-           DebugLevel0Fn( "NO\n" );
+       //
+       //      unusable unit
+       //
+       // FIXME: did SelectUnits already filter this.
+       if (dest->Removed || dest->Invisible || !unit->HP
+           || !(dest->Visible & (1 << player->Player))
+           || dest->Orders[0].Action == UnitActionDie) {
+           DebugLevel0Fn("NO\n");
            continue;
        }
 
-       if ( !IsEnemy( player, dest ) ) {       // a friend or neutral
+       if (!IsEnemy(player, dest)) {   // a friend or neutral
            continue;
        }
-       //
-       //      Unit can attack back?
-       //
-       if ( CanTarget( dest->Type, type ) ) {
+       //
+       //      Unit can attack back?
+       //
+       if (CanTarget(dest->Type, type)) {
            ++e;
        }
     }
@@ -250,7 +250,7 @@
 **
 **     @note   We must check if the dependencies are fulfilled.
 */
-local int AiBuildBuilding( const UnitType * type, UnitType * building )
+local int AiBuildBuilding(const UnitType * type, UnitType * building)
 {
     Unit *table[UnitMax];
     Unit *unit;
@@ -260,42 +260,43 @@
     int x;
     int y;
 
-    DebugLevel3Fn( "%s can made %s\n" _C_ type->Ident _C_ building->Ident );
+    DebugLevel3Fn("%s can made %s\n" _C_ type->Ident _C_ building->Ident);
 
-    IfDebug( unit = NoUnitP; );
-   //
-   //  Remove all workers on the way building something
-   //
-    nunits = FindPlayerUnitsByType( AiPlayer->Player, type, table );
-    for ( num = i = 0; i < nunits; i++ ) {
+    IfDebug(unit = NoUnitP;
+       );
+    //
+    //  Remove all workers on the way building something
+    //
+    nunits = FindPlayerUnitsByType(AiPlayer->Player, type, table);
+    for (num = i = 0; i < nunits; i++) {
        unit = table[i];
-       for ( x = 0; x < unit->OrderCount; x++ ) {
-           if ( unit->Orders[x].Action == UnitActionBuild
-                || unit->Orders[x].Action == UnitActionRepair ) {
+       for (x = 0; x < unit->OrderCount; x++) {
+           if (unit->Orders[x].Action == UnitActionBuild
+               || unit->Orders[x].Action == UnitActionRepair) {
                break;
            }
        }
-       if ( x == unit->OrderCount ) {
+       if (x == unit->OrderCount) {
            table[num++] = unit;
        }
     }
 
-    for ( i = 0; i < num; ++i ) {
+    for (i = 0; i < num; ++i) {
 
        unit = table[i];
-       DebugLevel3Fn( "Have an unit to build %d :)\n" _C_ UnitNumber( unit ) );
+       DebugLevel3Fn("Have an unit to build %d :)\n" _C_ UnitNumber(unit));
 
-       //
-       //  Find place on that could be build.
-       //
-       if ( !AiFindBuildingPlace( unit, building, &x, &y ) ) {
+       //
+       //  Find place on that could be build.
+       //
+       if (!AiFindBuildingPlace(unit, building, &x, &y)) {
            continue;
        }
 
-       DebugLevel3Fn( "Have a building place %d,%d for %s:)\n" _C_ x _C_ y _C_ 
building->
-                      Name );
+       DebugLevel3Fn("Have a building place %d,%d for %s:)\n" _C_ x _C_ y _C_ 
building->
+           Name);
 
-       CommandBuildBuilding( unit, x, y, building, FlushCommands );
+       CommandBuildBuilding(unit, x, y, building, FlushCommands);
 
        return 1;
     }
@@ -306,7 +307,7 @@
 /**
 **     Build new units to reduce the food shortage.
 */
-local void AiRequestFarms( void )
+local void AiRequestFarms(void)
 {
     int i;
     int n;
@@ -315,36 +316,36 @@
     AiBuildQueue *queue;
     int counter[UnitTypeMax];
 
-   //
-   //  Count the already made build requests.
-   //
-    memset( counter, 0, sizeof ( counter ) );
-    for ( queue = AiPlayer->UnitTypeBuilded; queue; queue = queue->Next ) {
+    //
+    //  Count the already made build requests.
+    //
+    memset(counter, 0, sizeof (counter));
+    for (queue = AiPlayer->UnitTypeBuilded; queue; queue = queue->Next) {
        counter[queue->Type->Type] += queue->Want;
     }
 
-   //
-   //  Check if we can build this?
-   //
+    //
+    //  Check if we can build this?
+    //
     n = AiHelpers.UnitLimit[0]->Count;
-    for ( i = 0; i < n; ++i ) {
+    for (i = 0; i < n; ++i) {
        type = AiHelpers.UnitLimit[0]->Table[i];
-       if ( counter[type->Type] ) {    // Already ordered.
+       if (counter[type->Type]) {      // Already ordered.
            return;
        }
 
-       DebugLevel3Fn( "Must build: %s\n" _C_ type->Ident );
-       //
-       //      Check if resources available.
-       //
-       if ( ( c = AiCheckUnitTypeCosts( type ) ) ) {
-           DebugLevel3( "- no resources\n" );
+       DebugLevel3Fn("Must build: %s\n" _C_ type->Ident);
+       //
+       //      Check if resources available.
+       //
+       if ((c = AiCheckUnitTypeCosts(type))) {
+           DebugLevel3("- no resources\n");
            AiPlayer->NeededMask |= c;
            return;
        } else {
-           DebugLevel3( "- enough resources\n" );
-           if ( AiMakeUnit( type ) ) {
-               queue = malloc( sizeof ( *AiPlayer->UnitTypeBuilded ) );
+           DebugLevel3("- enough resources\n");
+           if (AiMakeUnit(type)) {
+               queue = malloc(sizeof (*AiPlayer->UnitTypeBuilded));
                queue->Next = AiPlayer->UnitTypeBuilded;
                queue->Type = type;
                queue->Want = 1;
@@ -364,7 +365,7 @@
 **
 **     @note   We must check if the dependencies are fulfilled.
 */
-local int AiTrainUnit( const UnitType * type, UnitType * what )
+local int AiTrainUnit(const UnitType * type, UnitType * what)
 {
     Unit *table[UnitMax];
     Unit *unit;
@@ -372,26 +373,27 @@
     int i;
     int num;
 
-    DebugLevel3Fn( "%s can made %s\n" _C_ type->Ident _C_ what->Ident );
+    DebugLevel3Fn("%s can made %s\n" _C_ type->Ident _C_ what->Ident);
 
-    IfDebug( unit = NoUnitP; );
-   //
-   //  Remove all units already doing something.
-   //
-    nunits = FindPlayerUnitsByType( AiPlayer->Player, type, table );
-    for ( num = i = 0; i < nunits; i++ ) {
+    IfDebug(unit = NoUnitP;
+       );
+    //
+    //  Remove all units already doing something.
+    //
+    nunits = FindPlayerUnitsByType(AiPlayer->Player, type, table);
+    for (num = i = 0; i < nunits; i++) {
        unit = table[i];
-       if ( UnitIdle( unit ) ) {
+       if (UnitIdle(unit)) {
            table[num++] = unit;
        }
     }
 
-    for ( i = 0; i < num; ++i ) {
+    for (i = 0; i < num; ++i) {
 
        unit = table[i];
-       DebugLevel3Fn( "Have an unit to train %d :)\n" _C_ UnitNumber( unit ) );
+       DebugLevel3Fn("Have an unit to train %d :)\n" _C_ UnitNumber(unit));
 
-       CommandTrainUnit( unit, what, FlushCommands );
+       CommandTrainUnit(unit, what, FlushCommands);
 
        return 1;
     }
@@ -404,7 +406,7 @@
 **
 **     @param type the unittype we wan't to build
 */
-global int AiCountUnitBuilders( UnitType * type )
+global int AiCountUnitBuilders(UnitType * type)
 {
     int result;
     int i;
@@ -413,37 +415,37 @@
     AiUnitTypeTable *const *tablep;
     const AiUnitTypeTable *table;
 
-    if ( !UnitIdAllowed( AiPlayer->Player, type->Type ) ) {
-       DebugLevel0Fn( "Can't build `%s' now\n" _C_ type->Ident );
+    if (!UnitIdAllowed(AiPlayer->Player, type->Type)) {
+       DebugLevel0Fn("Can't build `%s' now\n" _C_ type->Ident);
        return 0;
     }
-   //
-   //  Check if we have a place for building or an unit to build.
-   //
-    if ( type->Building ) {
+    //
+    //  Check if we have a place for building or an unit to build.
+    //
+    if (type->Building) {
        n = AiHelpers.BuildCount;
        tablep = AiHelpers.Build;
     } else {
        n = AiHelpers.TrainCount;
        tablep = AiHelpers.Train;
     }
-    if ( type->Type > n ) {    // Oops not known.
-       DebugLevel0Fn( "Nothing known about `%s'\n" _C_ type->Ident );
+    if (type->Type > n) {              // Oops not known.
+       DebugLevel0Fn("Nothing known about `%s'\n" _C_ type->Ident);
        return 0;
     }
     table = tablep[type->Type];
-    if ( !table ) {            // Oops not known.
-       DebugLevel0Fn( "Nothing known about `%s'\n" _C_ type->Ident );
+    if (!table) {                      // Oops not known.
+       DebugLevel0Fn("Nothing known about `%s'\n" _C_ type->Ident);
        return 0;
     }
     n = table->Count;
 
     unit_count = AiPlayer->Player->UnitTypesCount;
     result = 0;
-    for ( i = 0; i < n; ++i ) {
-       //
-       //      The type for builder/trainer is available
-       //
+    for (i = 0; i < n; ++i) {
+       //
+       //      The type for builder/trainer is available
+       //
        result += unit_count[table->Table[i]->Type];
     }
     return result;
@@ -457,7 +459,7 @@
 **
 **     @note   We must check if the dependencies are fulfilled.
 */
-local int AiMakeUnit( UnitType * type )
+local int AiMakeUnit(UnitType * type)
 {
     int i;
     int n;
@@ -465,42 +467,42 @@
     AiUnitTypeTable *const *tablep;
     const AiUnitTypeTable *table;
 
-    DebugLevel3Fn( ":%s\n" _C_ type->Name );
+    DebugLevel3Fn(":%s\n" _C_ type->Name);
 
-   //
-   //  Check if we have a place for building or an unit to build.
-   //
-    if ( type->Building ) {
+    //
+    //  Check if we have a place for building or an unit to build.
+    //
+    if (type->Building) {
        n = AiHelpers.BuildCount;
        tablep = AiHelpers.Build;
     } else {
        n = AiHelpers.TrainCount;
        tablep = AiHelpers.Train;
     }
-    if ( type->Type > n ) {    // Oops not known.
-       DebugLevel0Fn( "Nothing known about `%s'\n" _C_ type->Ident );
+    if (type->Type > n) {              // Oops not known.
+       DebugLevel0Fn("Nothing known about `%s'\n" _C_ type->Ident);
        return 0;
     }
     table = tablep[type->Type];
-    if ( !table ) {            // Oops not known.
-       DebugLevel0Fn( "Nothing known about `%s'\n" _C_ type->Ident );
+    if (!table) {                      // Oops not known.
+       DebugLevel0Fn("Nothing known about `%s'\n" _C_ type->Ident);
        return 0;
     }
     n = table->Count;
 
     unit_count = AiPlayer->Player->UnitTypesCount;
-    for ( i = 0; i < n; ++i ) {
-       //
-       //      The type for builder/trainer is available
-       //
-       if ( unit_count[table->Table[i]->Type] ) {
-           DebugLevel3( "Found a builder for a %s.\n" _C_ type->ident );
-           if ( type->Building ) {
-               if ( AiBuildBuilding( table->Table[i], type ) ) {
+    for (i = 0; i < n; ++i) {
+       //
+       //      The type for builder/trainer is available
+       //
+       if (unit_count[table->Table[i]->Type]) {
+           DebugLevel3("Found a builder for a %s.\n" _C_ type->ident);
+           if (type->Building) {
+               if (AiBuildBuilding(table->Table[i], type)) {
                    return 1;
                }
            } else {
-               if ( AiTrainUnit( table->Table[i], type ) ) {
+               if (AiTrainUnit(table->Table[i], type)) {
                    return 1;
                }
            }
@@ -519,7 +521,7 @@
 **
 **     @note   We must check if the dependencies are fulfilled.
 */
-local int AiResearchUpgrade( const UnitType * type, Upgrade * what )
+local int AiResearchUpgrade(const UnitType * type, Upgrade * what)
 {
     Unit *table[UnitMax];
     Unit *unit;
@@ -527,26 +529,27 @@
     int i;
     int num;
 
-    DebugLevel3Fn( "%s can research %s\n" _C_ type->Ident _C_ what->Ident );
+    DebugLevel3Fn("%s can research %s\n" _C_ type->Ident _C_ what->Ident);
 
-    IfDebug( unit = NoUnitP; );
-   //
-   //  Remove all units already doing something.
-   //
-    nunits = FindPlayerUnitsByType( AiPlayer->Player, type, table );
-    for ( num = i = 0; i < nunits; i++ ) {
+    IfDebug(unit = NoUnitP;
+       );
+    //
+    //  Remove all units already doing something.
+    //
+    nunits = FindPlayerUnitsByType(AiPlayer->Player, type, table);
+    for (num = i = 0; i < nunits; i++) {
        unit = table[i];
-       if ( UnitIdle( unit ) ) {
+       if (UnitIdle(unit)) {
            table[num++] = unit;
        }
     }
 
-    for ( i = 0; i < num; ++i ) {
+    for (i = 0; i < num; ++i) {
 
        unit = table[i];
-       DebugLevel3Fn( "Have an unit to research %d :)\n" _C_ UnitNumber( unit 
) );
+       DebugLevel3Fn("Have an unit to research %d :)\n" _C_ UnitNumber(unit));
 
-       CommandResearch( unit, what, FlushCommands );
+       CommandResearch(unit, what, FlushCommands);
 
        return 1;
     }
@@ -557,7 +560,7 @@
 /**
 **     Check if the research can be done.
 */
-global void AiAddResearchRequest( Upgrade * upgrade )
+global void AiAddResearchRequest(Upgrade * upgrade)
 {
     int i;
     int n;
@@ -565,37 +568,37 @@
     AiUnitTypeTable *const *tablep;
     const AiUnitTypeTable *table;
 
-   //
-   //  Check if resources are available.
-   //
-    if ( ( i = AiCheckCosts( upgrade->Costs ) ) ) {
+    //
+    //  Check if resources are available.
+    //
+    if ((i = AiCheckCosts(upgrade->Costs))) {
        AiPlayer->NeededMask |= i;
        return;
     }
-   //
-   //  Check if we have a place for the upgrade to research
-   //
+    //
+    //  Check if we have a place for the upgrade to research
+    //
     n = AiHelpers.ResearchCount;
     tablep = AiHelpers.Research;
 
-    if ( upgrade - Upgrades > n ) {    // Oops not known.
-       DebugLevel0Fn( "Nothing known about `%s'\n" _C_ upgrade->Ident );
+    if (upgrade - Upgrades > n) {      // Oops not known.
+       DebugLevel0Fn("Nothing known about `%s'\n" _C_ upgrade->Ident);
        return;
     }
     table = tablep[upgrade - Upgrades];
-    if ( !table ) {            // Oops not known.
-       DebugLevel0Fn( "Nothing known about `%s'\n" _C_ upgrade->Ident );
+    if (!table) {                      // Oops not known.
+       DebugLevel0Fn("Nothing known about `%s'\n" _C_ upgrade->Ident);
        return;
     }
     n = table->Count;
 
     unit_count = AiPlayer->Player->UnitTypesCount;
-    for ( i = 0; i < n; ++i ) {
-       //
-       //      The type is available
-       //
-       if ( unit_count[table->Table[i]->Type] ) {
-           if ( AiResearchUpgrade( table->Table[i], upgrade ) ) {
+    for (i = 0; i < n; ++i) {
+       //
+       //      The type is available
+       //
+       if (unit_count[table->Table[i]->Type]) {
+           if (AiResearchUpgrade(table->Table[i], upgrade)) {
                return;
            }
        }
@@ -613,7 +616,7 @@
 **
 **     @note   We must check if the dependencies are fulfilled.
 */
-local int AiUpgradeTo( const UnitType * type, UnitType * what )
+local int AiUpgradeTo(const UnitType * type, UnitType * what)
 {
     Unit *table[UnitMax];
     Unit *unit;
@@ -621,26 +624,27 @@
     int i;
     int num;
 
-    DebugLevel3Fn( "%s can upgrade-to %s\n" _C_ type->Ident _C_ what->Ident );
+    DebugLevel3Fn("%s can upgrade-to %s\n" _C_ type->Ident _C_ what->Ident);
 
-    IfDebug( unit = NoUnitP; );
-   //
-   //  Remove all units already doing something.
-   //
-    nunits = FindPlayerUnitsByType( AiPlayer->Player, type, table );
-    for ( num = i = 0; i < nunits; i++ ) {
+    IfDebug(unit = NoUnitP;
+       );
+    //
+    //  Remove all units already doing something.
+    //
+    nunits = FindPlayerUnitsByType(AiPlayer->Player, type, table);
+    for (num = i = 0; i < nunits; i++) {
        unit = table[i];
-       if ( UnitIdle( unit ) ) {
+       if (UnitIdle(unit)) {
            table[num++] = unit;
        }
     }
 
-    for ( i = 0; i < num; ++i ) {
+    for (i = 0; i < num; ++i) {
 
        unit = table[i];
-       DebugLevel3Fn( "Have an unit to upgrade-to %d :)\n" _C_ UnitNumber( 
unit ) );
+       DebugLevel3Fn("Have an unit to upgrade-to %d :)\n" _C_ 
UnitNumber(unit));
 
-       CommandUpgradeTo( unit, what, FlushCommands );
+       CommandUpgradeTo(unit, what, FlushCommands);
 
        return 1;
     }
@@ -651,7 +655,7 @@
 /**
 **     Check if the upgrade-to can be done.
 */
-global void AiAddUpgradeToRequest( UnitType * type )
+global void AiAddUpgradeToRequest(UnitType * type)
 {
     int i;
     int n;
@@ -659,37 +663,37 @@
     AiUnitTypeTable *const *tablep;
     const AiUnitTypeTable *table;
 
-   //
-   //  Check if resources are available.
-   //
-    if ( ( i = AiCheckUnitTypeCosts( type ) ) ) {
+    //
+    //  Check if resources are available.
+    //
+    if ((i = AiCheckUnitTypeCosts(type))) {
        AiPlayer->NeededMask |= i;
        return;
     }
-   //
-   //  Check if we have a place for the upgrade to.
-   //
+    //
+    //  Check if we have a place for the upgrade to.
+    //
     n = AiHelpers.UpgradeCount;
     tablep = AiHelpers.Upgrade;
 
-    if ( type->Type > n ) {    // Oops not known.
-       DebugLevel0Fn( "Nothing known about `%s'\n" _C_ type->Ident );
+    if (type->Type > n) {              // Oops not known.
+       DebugLevel0Fn("Nothing known about `%s'\n" _C_ type->Ident);
        return;
     }
     table = tablep[type->Type];
-    if ( !table ) {            // Oops not known.
-       DebugLevel0Fn( "Nothing known about `%s'\n" _C_ type->Ident );
+    if (!table) {                      // Oops not known.
+       DebugLevel0Fn("Nothing known about `%s'\n" _C_ type->Ident);
        return;
     }
     n = table->Count;
 
     unit_count = AiPlayer->Player->UnitTypesCount;
-    for ( i = 0; i < n; ++i ) {
-       //
-       //      The type is available
-       //
-       if ( unit_count[table->Table[i]->Type] ) {
-           if ( AiUpgradeTo( table->Table[i], type ) ) {
+    for (i = 0; i < n; ++i) {
+       //
+       //      The type is available
+       //
+       if (unit_count[table->Table[i]->Type]) {
+           if (AiUpgradeTo(table->Table[i], type)) {
                return;
            }
        }
@@ -701,70 +705,70 @@
 /**
 **     Check what must be builded / trained.
 */
-local void AiCheckingWork( void )
+local void AiCheckingWork(void)
 {
     int c;
     UnitType *type;
     AiBuildQueue *queue;
 
-    DebugLevel3Fn( "%d:%d %d %d\n" _C_ AiPlayer->Player->Player _C_
-                  AiPlayer->Player->Resources[1] _C_
-                  AiPlayer->Player->Resources[2] _C_ 
AiPlayer->Player->Resources[3] );
-
-   // Food has the highest priority
-    if ( AiPlayer->NeedFood ) {
-       DebugLevel3Fn( "player %d needs food.\n" _C_ AiPlayer->Player->Player );
-       if ( !( AiPlayer->UnitTypeBuilded && 
AiPlayer->UnitTypeBuilded->Type->Supply ) ) {
+    DebugLevel3Fn("%d:%d %d %d\n" _C_ AiPlayer->Player->Player _C_
+       AiPlayer->Player->Resources[1] _C_
+       AiPlayer->Player->Resources[2] _C_ AiPlayer->Player->Resources[3]);
+
+    // Food has the highest priority
+    if (AiPlayer->NeedFood) {
+       DebugLevel3Fn("player %d needs food.\n" _C_ AiPlayer->Player->Player);
+       if (!(AiPlayer->UnitTypeBuilded && 
AiPlayer->UnitTypeBuilded->Type->Supply)) {
            AiPlayer->NeedFood = 0;
            AiRequestFarms();
        }
     }
-   //
-   //  Look to the build requests, what can be done.
-   //
-    for ( queue = AiPlayer->UnitTypeBuilded; queue; queue = queue->Next ) {
-       if ( queue->Want > queue->Made ) {
+    //
+    //  Look to the build requests, what can be done.
+    //
+    for (queue = AiPlayer->UnitTypeBuilded; queue; queue = queue->Next) {
+       if (queue->Want > queue->Made) {
            type = queue->Type;
-           DebugLevel3Fn( "Must build: %s\n" _C_ type->Ident );
+           DebugLevel3Fn("Must build: %s\n" _C_ type->Ident);
 
-          //
-          //  FIXME: must check if requirements are fulfilled.
-          //          Buildings can be destructed.
-
-          //
-          //  Check limits, AI should be broken if reached.
-          //
-           if ( !PlayerCheckLimits( AiPlayer->Player, type ) ) {
-               DebugLevel2Fn( "Unit limits reached\n" );
+           //
+           //  FIXME: must check if requirements are fulfilled.
+           //          Buildings can be destructed.
+
+           //
+           //  Check limits, AI should be broken if reached.
+           //
+           if (!PlayerCheckLimits(AiPlayer->Player, type)) {
+               DebugLevel2Fn("Unit limits reached\n");
                continue;
            }
-          //
-          //  Check if we have enough food.
-          //
-           if ( !type->Building ) {
-              // Count future
-               if ( !AiCheckFood( AiPlayer, type ) ) {
+           //
+           //  Check if we have enough food.
+           //
+           if (!type->Building) {
+               // Count future
+               if (!AiCheckFood(AiPlayer, type)) {
                    AiPlayer->NeedFood = 1;
                    AiRequestFarms();
                }
-              // Current limit
-               if ( !PlayerCheckFood( AiPlayer->Player, type ) ) {
+               // Current limit
+               if (!PlayerCheckFood(AiPlayer->Player, type)) {
                    continue;
                }
            }
-          //
-          //  Check if resources available.
-          //
-           if ( ( c = AiCheckUnitTypeCosts( type ) ) ) {
-               DebugLevel3( "- no resources\n" );
+           //
+           //  Check if resources available.
+           //
+           if ((c = AiCheckUnitTypeCosts(type))) {
+               DebugLevel3("- no resources\n");
                AiPlayer->NeededMask |= c;
-              //
-              //      NOTE: we can continue and build things with lesser
-              //              resource or other resource need!
+               //
+               //      NOTE: we can continue and build things with lesser
+               //              resource or other resource need!
                continue;
            } else {
-               DebugLevel3( "- enough resources\n" );
-               if ( AiMakeUnit( type ) ) {
+               DebugLevel3("- enough resources\n");
+               if (AiMakeUnit(type)) {
                    ++queue->Made;
                }
            }
@@ -784,36 +788,36 @@
 **
 **     @return 1 if the worker was assigned, 0 otherwise.
 */
-local int AiAssignHarvester( Unit * unit, int resource )
+local int AiAssignHarvester(Unit * unit, int resource)
 {
     ResourceInfo *resinfo;
-   //  These will hold the coordinates of the forest.
+    //  These will hold the coordinates of the forest.
     int forestx;
     int foresty;
-   //  This will hold the resulting gather destination.
+    //  This will hold the resulting gather destination.
     Unit *dest;
 
     resinfo = unit->Type->ResInfo[resource];
-    DebugCheck( !resinfo );
-    if ( resinfo->TerrainHarvester ) {
-       //
-       //      Code for terrain harvesters. Search for piece of terrain to 
mine.
-       //
-       if ( FindTerrainType( UnitMovementMask( unit ), MapFieldForest, 0, 1000,
-                             unit->Player, unit->X, unit->Y, &forestx, 
&foresty ) ) {
-           CommandResourceLoc( unit, forestx, foresty, FlushCommands );
+    DebugCheck(!resinfo);
+    if (resinfo->TerrainHarvester) {
+       //
+       //      Code for terrain harvesters. Search for piece of terrain to 
mine.
+       //
+       if (FindTerrainType(UnitMovementMask(unit), MapFieldForest, 0, 1000,
+               unit->Player, unit->X, unit->Y, &forestx, &foresty)) {
+           CommandResourceLoc(unit, forestx, foresty, FlushCommands);
            return 1;
        }
     } else {
-       //
-       //      Find a resource to ravest from.
-       //
-       if ( ( dest = FindResource( unit, unit->X, unit->Y, 1000, resource ) ) 
) {
-           CommandResource( unit, dest, FlushCommands );
+       //
+       //      Find a resource to ravest from.
+       //
+       if ((dest = FindResource(unit, unit->X, unit->Y, 1000, resource))) {
+           CommandResource(unit, dest, FlushCommands);
            return 1;
        }
     }
-   //  Failed.
+    //  Failed.
     return 0;
 }
 
@@ -823,7 +827,7 @@
 **     If we have a shortage of a resource, let many workers collecting this.
 **     If no shortage, split workers to all resources.
 */
-local void AiCollectResources( void )
+local void AiCollectResources(void)
 {
     Unit *units_with_resource[UnitMax][MaxCosts];      // Worker with resource
     int num_units_with_resource[MaxCosts];
@@ -831,7 +835,7 @@
     int num_units_assigned[MaxCosts];
     Unit *units_unassigned[UnitMax][MaxCosts]; // Unassigned workers
     int num_units_unassigned[MaxCosts];
-    int total;                 // Total of workers
+    int total;                         // Total of workers
     int c;
     int i;
     int n;
@@ -841,16 +845,16 @@
     int percent[MaxCosts];
     int percent_total;
 
-   //
-   //  Collect statistics about the current assignment
-   //
+    //
+    //  Collect statistics about the current assignment
+    //
     percent_total = 100;
-    for ( c = 0; c < MaxCosts; c++ ) {
+    for (c = 0; c < MaxCosts; c++) {
        num_units_with_resource[c] = 0;
        num_units_assigned[c] = 0;
        num_units_unassigned[c] = 0;
        percent[c] = AiPlayer->Collect[c];
-       if ( ( AiPlayer->NeededMask & ( 1 << c ) ) ) {  // Double percent if 
needed
+       if ((AiPlayer->NeededMask & (1 << c))) {        // Double percent if 
needed
            percent_total += percent[c];
            percent[c] <<= 1;
        }
@@ -858,88 +862,89 @@
 
     n = AiPlayer->Player->TotalNumUnits;
     units = AiPlayer->Player->Units;
-    for ( i = 0; i < n; i++ ) {
+    for (i = 0; i < n; i++) {
        unit = units[i];
-       if ( ( !unit->Type->Harvester ) || ( unit->Removed ) ) {
+       if ((!unit->Type->Harvester) || (unit->Removed)) {
            continue;
        }
 
        c = unit->CurrentResource;
-       //
-       //      See if it's assigned already
-       //
-       if ( unit->Orders[0].Action == UnitActionResource && c ) {
+       //
+       //      See if it's assigned already
+       //
+       if (unit->Orders[0].Action == UnitActionResource && c) {
            units_assigned[num_units_assigned[c]++][c] = unit;
            continue;
        }
-       //
-       //      Ignore busy units.
-       //      
-       if ( !UnitIdle( unit ) ) {
+       //
+       //      Ignore busy units.
+       //      
+       if (!UnitIdle(unit)) {
            continue;
        }
-       //
-       //      Send workers with resources back home.
-       //
-       if ( unit->Value && c ) {
+       //
+       //      Send workers with resources back home.
+       //
+       if (unit->Value && c) {
            units_with_resource[num_units_with_resource[c]++][c] = unit;
-           CommandReturnGoods( unit, 0, FlushCommands );
+           CommandReturnGoods(unit, 0, FlushCommands);
            continue;
        }
-       //
-       //      Look what the unit can do
-       //
-       for ( c = 0; c < MaxCosts; ++c ) {
-           if ( unit->Type->ResInfo[c] ) {
+       //
+       //      Look what the unit can do
+       //
+       for (c = 0; c < MaxCosts; ++c) {
+           if (unit->Type->ResInfo[c]) {
                units_unassigned[num_units_unassigned[c]++][c] = unit;
            }
        }
     }
 
     total = 0;
-    for ( c = 0; c < MaxCosts; ++c ) {
+    for (c = 0; c < MaxCosts; ++c) {
        total += num_units_assigned[c] + num_units_with_resource[c];
-       DebugLevel3Fn( "Assigned %d = %d\n" _C_ c _C_ num_units_assigned[c] );
-       DebugLevel3Fn( "Resource %d = %d\n" _C_ c _C_ 
num_units_with_resource[c] );
+       DebugLevel3Fn("Assigned %d = %d\n" _C_ c _C_ num_units_assigned[c]);
+       DebugLevel3Fn("Resource %d = %d\n" _C_ c _C_ 
num_units_with_resource[c]);
     }
 #ifdef DEBUG
-    DebugLevel3Fn( "Unassigned %d of total %d\n" _C_ num_units_unassigned[c] 
_C_ total );
-    if ( AiPlayer->Player == ThisPlayer ) {
-       DebugLevel3Fn( "Percent Assignment:" );
-       for ( c = 0; c < MaxCosts; ++c ) {
-           if ( percent[c] ) {
-               DebugLevel3( " %s:%d%%" _C_ DefaultResourceNames[c] _C_ 
percent[c] );
+    DebugLevel3Fn("Unassigned %d of total %d\n" _C_ num_units_unassigned[c] 
_C_ total);
+    if (AiPlayer->Player == ThisPlayer) {
+       DebugLevel3Fn("Percent Assignment:");
+       for (c = 0; c < MaxCosts; ++c) {
+           if (percent[c]) {
+               DebugLevel3(" %s:%d%%" _C_ DefaultResourceNames[c] _C_ 
percent[c]);
            }
        }
-       DebugLevel3( "\n" );
+       DebugLevel3("\n");
     }
 #endif
 
-   //
-   //  Reassign free workers
-   //
-    for ( c = 0; c < MaxCosts; ++c ) {
-       if ( num_units_unassigned[c] == 0 ) {
-           if ( percent[c] == 0 ) {
+    //
+    //  Reassign free workers
+    //
+    for (c = 0; c < MaxCosts; ++c) {
+       if (num_units_unassigned[c] == 0) {
+           if (percent[c] == 0) {
                continue;
            }
-           for ( i = 0; i < MaxCosts; ++i ) {
-               if ( i == c ) {
+           for (i = 0; i < MaxCosts; ++i) {
+               if (i == c) {
                    continue;
                }
-              //  FIXME: Shouldn't this turn into a while? currently max one 
worker is transfered.
-               if ( ( percent[i] < percent[c] &&
-                      ( ( num_units_assigned[c] + num_units_with_resource[c] -
-                          1 ) * percent_total > total * percent[c]
-                        || num_units_assigned[c] + num_units_with_resource[c] 
== 0 ) )
-                    || ( num_units_assigned[i] + num_units_with_resource[i] -
-                         1 ) * percent_total > total * percent[i] ) {
-                  //  We take workers from resource i and move them to 
resource c
+               //  FIXME: Shouldn't this turn into a while? currently max one 
worker is transfered.
+               if ((percent[i] < percent[c] &&
+                       ((num_units_assigned[c] + num_units_with_resource[c] -
+                               1) * percent_total > total * percent[c]
+                           || num_units_assigned[c] + 
num_units_with_resource[c] == 0))
+                   || (num_units_assigned[i] + num_units_with_resource[i] -
+                       1) * percent_total > total * percent[i]) {
+                   //  We take workers from resource i and move them to 
resource c
                    int j;
-                   for ( j = num_units_assigned[i] - 1; j >= 0; --j ) {
+                   for (j = num_units_assigned[i] - 1; j >= 0; --j) {
                        unit = units_assigned[j][i];
-                       if ( unit && unit->SubAction < 50 ) {
-                           units_assigned[j][i] = 
units_assigned[--num_units_assigned[i]][i];
+                       if (unit && unit->SubAction < 50) {
+                           units_assigned[j][i] =
+                               units_assigned[--num_units_assigned[i]][i];
                            --total;
                            units_unassigned[num_units_unassigned[c]++][c] = 
unit;
                            break;
@@ -950,59 +955,60 @@
        }
     }
 
-   //
-   //  Now assign the free workers.
-   //
-    for ( n = 0; n < MaxCosts; ++n ) {
-       for ( i = 0; i < num_units_unassigned[n]; i++ ) {
+    //
+    //  Now assign the free workers.
+    //
+    for (n = 0; n < MaxCosts; ++n) {
+       for (i = 0; i < num_units_unassigned[n]; i++) {
            int t;
            int max;
 
-          //
-          //  Loop through all of the workers.
-          //
+           //
+           //  Loop through all of the workers.
+           //
            unit = units_unassigned[i][n];
 
-          //
-          //  Here we determine what to assign the worker to first. 
-          //
-           for ( max = o = c = 0; c < MaxCosts; ++c ) {
-               DebugLevel3Fn( "%d, %d, %d\n" _C_
-                              ( num_units_assigned[c] +
-                                num_units_with_resource[c] ) *
-                              percent_total _C_ percent[c] _C_ total * 
percent[c] );
-               t = ( num_units_assigned[c] + num_units_with_resource[c] ) * 
percent_total;
-               if ( t < total * percent[c] ) {
-                   if ( total * percent[c] - t > max ) {
+           //
+           //  Here we determine what to assign the worker to first. 
+           //
+           for (max = o = c = 0; c < MaxCosts; ++c) {
+               DebugLevel3Fn("%d, %d, %d\n" _C_
+                   (num_units_assigned[c] +
+                       num_units_with_resource[c]) *
+                   percent_total _C_ percent[c] _C_ total * percent[c]);
+               t = (num_units_assigned[c] + num_units_with_resource[c]) * 
percent_total;
+               if (t < total * percent[c]) {
+                   if (total * percent[c] - t > max) {
                        max = total * percent[c] - t;
                        o = c;
                    }
                }
            }
 
-          //
-          //  Look what the unit can do
-          //
-           for ( t = 0; t < MaxCosts; ++t ) {
-              //
-              //  Now we have to assign it to resource c
-              //  
-               c = ( t + o ) % MaxCosts;
-               if ( !unit->Type->ResInfo[c] ) {
-                   continue;   //        Alas, we can't mine c
+           //
+           //  Look what the unit can do
+           //
+           for (t = 0; t < MaxCosts; ++t) {
+               //
+               //  Now we have to assign it to resource c
+               //  
+               c = (t + o) % MaxCosts;
+               if (!unit->Type->ResInfo[c]) {
+                   continue;           //        Alas, we can't mine c
                }
-              //
-              //  Look if it is a worker for this resource
-              //
-               if ( AiAssignHarvester( unit, c ) ) {
+               //
+               //  Look if it is a worker for this resource
+               //
+               if (AiAssignHarvester(unit, c)) {
                    int n1, n2;
-                   DebugLevel3Fn( "Assigned %d to %s\n" _C_ unit->
-                                  Slot _C_ DefaultResourceNames[c] );
+                   DebugLevel3Fn("Assigned %d to %s\n" _C_ unit->
+                       Slot _C_ DefaultResourceNames[c]);
                    units_assigned[num_units_assigned[c]++][c] = unit;
-                   units_unassigned[i][c] = 
units_unassigned[--num_units_unassigned[c]][c];
-                   for ( n1 = 0; n1 < MaxCosts; ++n1 ) {
-                       for ( n2 = 0; n2 < num_units_unassigned[n1]; ++n2 ) {
-                           if ( units_unassigned[n2][n1] == unit ) {
+                   units_unassigned[i][c] =
+                       units_unassigned[--num_units_unassigned[c]][c];
+                   for (n1 = 0; n1 < MaxCosts; ++n1) {
+                       for (n2 = 0; n2 < num_units_unassigned[n1]; ++n2) {
+                           if (units_unassigned[n2][n1] == unit) {
                                units_unassigned[n2][n1] =
                                    
units_unassigned[--num_units_unassigned[n1]][n1];
                                break;
@@ -1010,7 +1016,7 @@
                        }
                    }
                    ++total;
-                  //  We assigned this worker to something already.
+                   //  We assigned this worker to something already.
                    break;
                }
            }
@@ -1029,7 +1035,7 @@
 **     @param building Building to be repaired.
 **     @return         True if can repair, false if can't repair..
 */
-local int AiRepairBuilding( const UnitType * type, Unit * building )
+local int AiRepairBuilding(const UnitType * type, Unit * building)
 {
     Unit *table[UnitMax];
     Unit *unit;
@@ -1045,55 +1051,56 @@
     int k;
     int num;
 
-    DebugLevel3Fn( "%s can repair %s\n" _C_ type->Ident _C_ 
building->Type->Ident );
+    DebugLevel3Fn("%s can repair %s\n" _C_ type->Ident _C_ 
building->Type->Ident);
 
-    IfDebug( unit = NoUnitP; );
-   //
-   //  Remove all workers not mining. on the way building something
-   //  FIXME: It is not clever to use workers with gold
-   //  Idea: Antonis: Put the rest of the workers in a table in case
-   //  miners can't reach but others can. This will be useful if AI becomes
-   //  more flexible (e.g.: transports workers to an island)
-   //  FIXME: too hardcoded, not nice, needs improvement.
-   //  FIXME: too many workers repair the same building!
-
-   // Selection of mining workers.
-    nunits = FindPlayerUnitsByType( AiPlayer->Player, type, table );
-    for ( num = i = 0; i < nunits; i++ ) {
+    IfDebug(unit = NoUnitP;
+       );
+    //
+    //  Remove all workers not mining. on the way building something
+    //  FIXME: It is not clever to use workers with gold
+    //  Idea: Antonis: Put the rest of the workers in a table in case
+    //  miners can't reach but others can. This will be useful if AI becomes
+    //  more flexible (e.g.: transports workers to an island)
+    //  FIXME: too hardcoded, not nice, needs improvement.
+    //  FIXME: too many workers repair the same building!
+
+    // Selection of mining workers.
+    nunits = FindPlayerUnitsByType(AiPlayer->Player, type, table);
+    for (num = i = 0; i < nunits; i++) {
        unit = table[i];
-       if ( unit->Type->RepairRange &&
-            ( unit->Orders[0].Action == UnitActionResource ||
-              unit->Orders[0].Action == UnitActionStill ) && unit->OrderCount 
== 1 ) {
+       if (unit->Type->RepairRange &&
+           (unit->Orders[0].Action == UnitActionResource ||
+               unit->Orders[0].Action == UnitActionStill) && unit->OrderCount 
== 1) {
            table[num++] = unit;
        }
     }
 
-   // Sort by distance loops -Antonis-
-    for ( i = 0; i < num; ++i ) {
+    // Sort by distance loops -Antonis-
+    for (i = 0; i < num; ++i) {
        unit = table[i];
-       //      FIXME: Probably calculated from top left corner of building
-       if ( ( rX = unit->X - building->X ) < 0 ) {
+       //      FIXME: Probably calculated from top left corner of building
+       if ((rX = unit->X - building->X) < 0) {
            rX = -rX;
        }
-       if ( ( rY = unit->Y - building->Y ) < 0 ) {
+       if ((rY = unit->Y - building->Y) < 0) {
            rY = -rY;
        }
-       if ( rX < rY ) {
+       if (rX < rY) {
            distance[i] = rX;
        } else {
            distance[i] = rY;
        }
     }
-    for ( i = 0; i < num; ++i ) {
+    for (i = 0; i < num; ++i) {
        r_temp = distance[i];
        index_temp = i;
-       for ( j = i; j < num; ++j ) {
-           if ( distance[j] < r_temp ) {
+       for (j = i; j < num; ++j) {
+           if (distance[j] < r_temp) {
                r_temp = distance[j];
                index_temp = j;
            }
        }
-       if ( index_temp > i ) {
+       if (index_temp > i) {
            unit_temp = table[index_temp];
            table[index_temp] = table[i];
            distance[index_temp] = distance[i];
@@ -1102,24 +1109,24 @@
        }
     }
 
-   // Check if building is reachable and try next trio of workers
+    // Check if building is reachable and try next trio of workers
 
-    if ( ( j = AiPlayer->TriedRepairWorkers[UnitNumber( building )] ) > num ) {
-       j = AiPlayer->TriedRepairWorkers[UnitNumber( building )] = 0;
+    if ((j = AiPlayer->TriedRepairWorkers[UnitNumber(building)]) > num) {
+       j = AiPlayer->TriedRepairWorkers[UnitNumber(building)] = 0;
     }
 
-    for ( k = i = j; i < num && i < j + 3; ++i ) {
+    for (k = i = j; i < num && i < j + 3; ++i) {
 
        unit = table[i];
-       DebugLevel2Fn( "Have an unit to repair %d :)\n" _C_ UnitNumber( unit ) 
);
+       DebugLevel2Fn("Have an unit to repair %d :)\n" _C_ UnitNumber(unit));
 
-       if ( UnitReachable( unit, building, unit->Type->RepairRange ) ) {
-           CommandRepair( unit, 0, 0, building, FlushCommands );
+       if (UnitReachable(unit, building, unit->Type->RepairRange)) {
+           CommandRepair(unit, 0, 0, building, FlushCommands);
            return 1;
        }
        k = i;
     }
-    AiPlayer->TriedRepairWorkers[UnitNumber( building )] = k + 1;
+    AiPlayer->TriedRepairWorkers[UnitNumber(building)] = k + 1;
     return 0;
 }
 
@@ -1129,7 +1136,7 @@
 **     @param unit     Unit that must be repaired.
 **     @return         True if made, false if can't be made.
 */
-local int AiRepairUnit( Unit * unit )
+local int AiRepairUnit(Unit * unit)
 {
     int i;
     int n;
@@ -1141,24 +1148,24 @@
     n = AiHelpers.RepairCount;
     tablep = AiHelpers.Repair;
     type = unit->Type;
-    if ( type->Type > n ) {    // Oops not known.
-       DebugLevel0Fn( "Nothing known about `%s'\n" _C_ type->Ident );
+    if (type->Type > n) {              // Oops not known.
+       DebugLevel0Fn("Nothing known about `%s'\n" _C_ type->Ident);
        return 0;
     }
     table = tablep[type->Type];
-    if ( !table ) {            // Oops not known.
-       DebugLevel0Fn( "Nothing known about `%s'\n" _C_ type->Ident );
+    if (!table) {                      // Oops not known.
+       DebugLevel0Fn("Nothing known about `%s'\n" _C_ type->Ident);
        return 0;
     }
 
     n = table->Count;
     unit_count = AiPlayer->Player->UnitTypesCount;
-    for ( i = 0; i < n; ++i ) {
-       //
-       //      The type is available
-       //
-       if ( unit_count[table->Table[i]->Type] ) {
-           if ( AiRepairBuilding( table->Table[i], unit ) ) {
+    for (i = 0; i < n; ++i) {
+       //
+       //      The type is available
+       //
+       if (unit_count[table->Table[i]->Type]) {
+           if (AiRepairBuilding(table->Table[i], unit)) {
                return 1;
            }
        }
@@ -1170,7 +1177,7 @@
 /**
 **     Look through the units, if an unit must be repaired.
 */
-local void AiCheckRepair( void )
+local void AiCheckRepair(void)
 {
     int i, j, k;
     int n;
@@ -1179,50 +1186,50 @@
 
     n = AiPlayer->Player->TotalNumUnits;
     k = 0;
-   // Selector for next unit
-    for ( i = n; ( i > 0 ); --i ) {
+    // Selector for next unit
+    for (i = n; (i > 0); --i) {
        unit = AiPlayer->Player->Units[i];
-       if ( unit ) {
-           if ( UnitNumber( unit ) == AiPlayer->LastRepairBuilding ) {
+       if (unit) {
+           if (UnitNumber(unit) == AiPlayer->LastRepairBuilding) {
                k = i + 1;
            }
        }
     }
 
-    for ( i = k; i < n; ++i ) {
+    for (i = k; i < n; ++i) {
        unit = AiPlayer->Player->Units[i];
        repair_flag = 1;
-       // Unit damaged?
-       if ( unit->Type->Building
-            && unit->Orders[0].Action != UnitActionBuilded
-            && unit->Orders[0].Action != UnitActionUpgradeTo
-            && unit->HP < unit->Stats->HitPoints ) {
-
-           DebugLevel3Fn( "Have building to repair %d(%s)\n" _C_
-                          UnitNumber( unit ) _C_ unit->Type->Ident );
-
-          //
-          //  FIXME: Repair only buildings under control
-          //
-           if ( EnemyUnitsInDistance( unit, unit->Stats->SightRange ) ) {
+       // Unit damaged?
+       if (unit->Type->Building
+           && unit->Orders[0].Action != UnitActionBuilded
+           && unit->Orders[0].Action != UnitActionUpgradeTo
+           && unit->HP < unit->Stats->HitPoints) {
+
+           DebugLevel3Fn("Have building to repair %d(%s)\n" _C_
+               UnitNumber(unit) _C_ unit->Type->Ident);
+
+           //
+           //  FIXME: Repair only buildings under control
+           //
+           if (EnemyUnitsInDistance(unit, unit->Stats->SightRange)) {
                continue;
            }
-          //
-          //  Must check, if there are enough resources
-          //
-           for ( j = 1; j < MaxCosts; ++j ) {
-               if ( unit->Stats->Costs[j]
-                    && AiPlayer->Player->Resources[j] < 99 ) {
+           //
+           //  Must check, if there are enough resources
+           //
+           for (j = 1; j < MaxCosts; ++j) {
+               if (unit->Stats->Costs[j]
+                   && AiPlayer->Player->Resources[j] < 99) {
                    repair_flag = 0;
                }
            }
 
-          //
-          //  Find a free worker, who can build this building can repair it?
-          //
-           if ( repair_flag ) {
-               AiRepairUnit( unit );
-               AiPlayer->LastRepairBuilding = UnitNumber( unit );
+           //
+           //  Find a free worker, who can build this building can repair it?
+           //
+           if (repair_flag) {
+               AiRepairUnit(unit);
+               AiPlayer->LastRepairBuilding = UnitNumber(unit);
                return;
            }
        }
@@ -1238,48 +1245,48 @@
 **
 **     @todo FIXME: should store the end of list and not search it.
 */
-global void AiAddUnitTypeRequest( UnitType * type, int count )
+global void AiAddUnitTypeRequest(UnitType * type, int count)
 {
     AiBuildQueue **queue;
 
-    DebugLevel3Fn( "%s %d\n" _C_ type->Ident _C_ count );
+    DebugLevel3Fn("%s %d\n" _C_ type->Ident _C_ count);
 
-   //
-   //  Find end of the list.
-   //
-    for ( queue = &AiPlayer->UnitTypeBuilded; *queue; queue = &( *queue 
)->Next ) {
+    //
+    //  Find end of the list.
+    //
+    for (queue = &AiPlayer->UnitTypeBuilded; *queue; queue = &(*queue)->Next) {
     }
 
-    *queue = malloc( sizeof ( *AiPlayer->UnitTypeBuilded ) );
-    ( *queue )->Next = NULL;
-    ( *queue )->Type = type;
-    ( *queue )->Want = count;
-    ( *queue )->Made = 0;
+    *queue = malloc(sizeof (*AiPlayer->UnitTypeBuilded));
+    (*queue)->Next = NULL;
+    (*queue)->Type = type;
+    (*queue)->Want = count;
+    (*queue)->Made = 0;
 }
 
 /**
 **     Entry point of resource manager, periodically called.
 */
-global void AiResourceManager( void )
+global void AiResourceManager(void)
 {
-   //
-   //  Check if something needs to be build / trained.
-   //
+    //
+    //  Check if something needs to be build / trained.
+    //
     AiCheckingWork();
-   //
-   //  Look if we can build a farm in advance.
-   //
-    if ( !AiPlayer->NeedFood && AiPlayer->Player->NumFoodUnits == 
AiPlayer->Player->Food ) {
-       DebugLevel3Fn( "Farm in advance request\n" );
+    //
+    //  Look if we can build a farm in advance.
+    //
+    if (!AiPlayer->NeedFood && AiPlayer->Player->NumFoodUnits == 
AiPlayer->Player->Food) {
+       DebugLevel3Fn("Farm in advance request\n");
        AiRequestFarms();
     }
-   //
-   //  Collect resources.
-   //
+    //
+    //  Collect resources.
+    //
     AiCollectResources();
-   //
-   //  Check repair.
-   //
+    //
+    //  Check repair.
+    //
     AiCheckRepair();
 
     AiPlayer->NeededMask = 0;
Index: stratagus/src/ai/ai_rules.c
diff -u stratagus/src/ai/ai_rules.c:1.2 stratagus/src/ai/ai_rules.c:1.3
--- stratagus/src/ai/ai_rules.c:1.2     Fri Oct 24 02:28:54 2003
+++ stratagus/src/ai/ai_rules.c Sun Oct 26 10:34:59 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//      $Id: ai_rules.c,v 1.2 2003/10/24 06:28:54 mr-russ Exp $
+//      $Id: ai_rules.c,v 1.3 2003/10/26 15:34:59 pludov Exp $
 
 //@{
 
@@ -201,11 +201,11 @@
 // These are indead constant...  
 static int ScoreBase = 0;
 static int RessourceBase = 3;
-static int ForceBase = 3 + ( RESSOURCE_COUNT * 2 );
+static int ForceBase = 3 + (RESSOURCE_COUNT * 2);
 // Global number of (non computed) game state gauge...
-static int BasicGaugeNb = 3 + ( RESSOURCE_COUNT * 2 ) + ( FORCE_COUNT * 6 );
+static int BasicGaugeNb = 3 + (RESSOURCE_COUNT * 2) + (FORCE_COUNT * 6);
 
-static int GaugeValues[3 + ( RESSOURCE_COUNT * 2 ) + ( FORCE_COUNT * 6 )];
+static int GaugeValues[3 + (RESSOURCE_COUNT * 2) + (FORCE_COUNT * 6)];
 
 static Player *currentPlayer;
 
@@ -216,11 +216,11 @@
 static const char *str_location[2] = { "hotspot", "map" };
 static const char *str_ressources[RESSOURCE_COUNT] = { "gold", "wood", "oil" };
 static const char *str_forces[FORCE_COUNT] = {
-   // Fire to  ( water / ground / air )
+    // Fire to  ( water / ground / air )
     "sea-fire", "ground-fire", "air-fire", "detectors",
-   // Force of units on water, groud, air
+    // Force of units on water, groud, air
     "sea-force", "ground-force", "air-force",
-   // Value ( point of values )
+    // Value ( point of values )
     "sea-value", "ground-value", "air-value", "invisibles"
 };
 
@@ -229,33 +229,33 @@
 --     Functions
 ----------------------------------------------------------------------------*/
 
-local int ForceGauge( int Force, int location, int camp )
+local int ForceGauge(int Force, int location, int camp)
 {
     return ForceBase + Force * 6 + location * 3 + camp;
 }
 
-local void AiGetGaugeName( int gauge, char *buffer, int bufferSize )
+local void AiGetGaugeName(int gauge, char *buffer, int bufferSize)
 {
     int camp;
     int ressource;
     int location;
     int force;
 
-    if ( gauge < RessourceBase ) {
+    if (gauge < RessourceBase) {
        gauge -= ScoreBase;
        camp = gauge;
-       snprintf( buffer, bufferSize, "%s-score", str_camp[camp] );
+       snprintf(buffer, bufferSize, "%s-score", str_camp[camp]);
        return;
     }
-    if ( gauge < ForceBase ) {
+    if (gauge < ForceBase) {
        gauge -= RessourceBase;
        ressource = gauge / 2;
        location = gauge % 2;
-       snprintf( buffer, bufferSize, "%s-%s", str_ressources[ressource],
-                 str_location[location] );
+       snprintf(buffer, bufferSize, "%s-%s", str_ressources[ressource],
+           str_location[location]);
        return;
     }
-   // Force...
+    // Force...
     gauge -= ForceBase;
 
     force = gauge / 6;
@@ -264,8 +264,8 @@
     location = gauge / 3;
     camp = gauge % 3;
 
-    snprintf( buffer, bufferSize, "%s-%s-%s", str_camp[camp], 
str_location[location],
-             str_forces[force] );
+    snprintf(buffer, bufferSize, "%s-%s-%s", str_camp[camp], 
str_location[location],
+       str_forces[force]);
 }
 
 /**
@@ -275,14 +275,14 @@
 **     @param y        Y map position of unit
 **     @return         1 if it is in the hotspot, 0 otherwisee
 **/
-local int AiCheckOnHotSpot( int x, int y )
+local int AiCheckOnHotSpot(int x, int y)
 {
     int dst;
-    if ( ( AiScript->HotSpot_X < 0 ) || ( AiScript->HotSpot_Y < 0 )
-        || ( AiScript->HotSpot_Ray <= 0 ) ) {
+    if ((AiScript->HotSpot_X < 0) || (AiScript->HotSpot_Y < 0)
+       || (AiScript->HotSpot_Ray <= 0)) {
        return 0;
     }
-    dst = abs( x - AiScript->HotSpot_X ) + abs( y - AiScript->HotSpot_Y );
+    dst = abs(x - AiScript->HotSpot_X) + abs(y - AiScript->HotSpot_Y);
     return dst < AiScript->HotSpot_Ray;
 
 }
@@ -293,38 +293,39 @@
 **     @param p        the player
 **     @return         FOR_SELF,FOR_ALLIED,FOR_ENEMY,FOR_NEUTRAL  
 **/
-local int AiGetPlayerCamp( Player * p )
+local int AiGetPlayerCamp(Player * p)
 {
     int id;
-    if ( !p ) {
+    if (!p) {
        return FOR_NEUTRAL;
     }
 
-    if ( p == currentPlayer ) {
+    if (p == currentPlayer) {
        return FOR_SELF;
     }
 
     id = p->Player;
-    if ( currentPlayer->Enemy & ( 1 << id ) ) {
+    if (currentPlayer->Enemy & (1 << id)) {
        return FOR_ENEMY;
     }
-    if ( currentPlayer->Allied & ( 1 << id ) ) {
+    if (currentPlayer->Allied & (1 << id)) {
        return FOR_ALLIED;
     }
     return FOR_NEUTRAL;
 }
 
-global int AiUnittypeForce( UnitType * unitType )
+global int AiUnittypeForce(UnitType * unitType)
 {
     int influence;
-   // Fixme : Ratio between stats are fixed
+    // Fixme : Ratio between stats are fixed
     influence = unitType->Stats[AiPlayer->Player->Player].AttackRange +
        unitType->Stats[AiPlayer->Player->Player].Armor +
        unitType->Stats[AiPlayer->Player->Player].BasicDamage +
        unitType->Stats[AiPlayer->Player->Player].PiercingDamage +
        unitType->Stats[AiPlayer->Player->Player].Speed / 3 +
-       unitType->Stats[AiPlayer->Player->Player].HitPoints / 5 + ( 
unitType->Magic ? 30 : 0 );
-    if ( influence == 0 ) {
+       unitType->Stats[AiPlayer->Player->Player].HitPoints / 5 +
+       (unitType->Magic ? 30 : 0);
+    if (influence == 0) {
        return 1;
     }
 
@@ -338,103 +339,110 @@
 **     @param y        Y map position of unit
 **     @param unit     actual unit ( used for gold mine amount, ... )
 **/
-local void AiDeclareUnitImpact( int x, int y, Unit * unit )
+local void AiDeclareUnitImpact(int x, int y, Unit * unit)
 {
-   // Unit camp
+    // Unit camp
     int camp;
-   // Unit type.
+    // Unit type.
     UnitType *unitType;
-   //int unittype_slot;
-   // Base gauge for the unittype
-   //int unittype_base;
+    //int unittype_slot;
+    // Base gauge for the unittype
+    //int unittype_base;
     int force;
     int onhotspot;
-   // Influence of this units on forces
+    // Influence of this units on forces
     int influence;
     int influences[FORCE_COUNT];
 
-   // Find unittype of unit
+    // Find unittype of unit
     unitType = unit->Type;
 
-   // Find unit's camp.
-    camp = AiGetPlayerCamp( unit->Player );
+    // Find unit's camp.
+    camp = AiGetPlayerCamp(unit->Player);
 
-   // Updates unit counts...   
-   //unittype_slot=unitType->Type;
+    // Updates unit counts...   
+    //unittype_slot=unitType->Type;
 
-    onhotspot = AiCheckOnHotSpot( x, y );
-   //unittype_base=UnitTypeBase+6*unittype_slot;
+    onhotspot = AiCheckOnHotSpot(x, y);
+    //unittype_base=UnitTypeBase+6*unittype_slot;
 
-    if ( camp != FOR_NEUTRAL ) {
+    if (camp != FOR_NEUTRAL) {
 
-       // For force, take AI Priority
-       if ( !unitType->CanAttack ) {
+       // For force, take AI Priority
+       if (!unitType->CanAttack) {
            influence = 0;
        } else {
-          // Hard...
+           // Hard...
            influence = unit->Stats->AttackRange +
                unit->Stats->Armor +
                unit->Stats->BasicDamage +
                unit->Stats->PiercingDamage +
                unit->Stats->Speed / 3 +
-               unit->Stats->HitPoints / 5 + ( unitType->Magic ? 30 : 0 );
+               unit->Stats->HitPoints / 5 + (unitType->Magic ? 30 : 0);
        }
 
-       if ( influence <= 1 ) {
+       if (influence <= 1) {
            influence = 1;
        }
 
-       influences[WATER_FORCE] = ( unitType->CanTarget & CanTargetSea ? 
influence : 0 );
-       influences[GROUND_FORCE] = ( unitType->CanTarget & CanTargetLand ? 
influence : 0 );
-       influences[AIR_FORCE] = ( unitType->CanTarget & CanTargetAir ? 
influence : 0 );
-       influences[DETECTOR_FORCE] = ( unitType->DetectCloak ? 1 : 0 );
-
-       influences[WATER_UNITS_FORCE] = ( unitType->UnitType == UnitTypeNaval ? 
influence : 0 );
-       influences[GROUND_UNITS_FORCE] = ( unitType->UnitType == UnitTypeLand ? 
influence : 0 );
-       influences[AIR_UNITS_FORCE] = ( unitType->UnitType == UnitTypeFly ? 
influence : 0 );
+       influences[WATER_FORCE] = (unitType->CanTarget & CanTargetSea ? 
influence : 0);
+       influences[GROUND_FORCE] = (unitType->CanTarget & CanTargetLand ? 
influence : 0);
+       influences[AIR_FORCE] = (unitType->CanTarget & CanTargetAir ? influence 
: 0);
+       influences[DETECTOR_FORCE] = (unitType->DetectCloak ? 1 : 0);
+
+       influences[WATER_UNITS_FORCE] =
+           (unitType->UnitType == UnitTypeNaval ? influence : 0);
+       influences[GROUND_UNITS_FORCE] =
+           (unitType->UnitType == UnitTypeLand ? influence : 0);
+       influences[AIR_UNITS_FORCE] =
+           (unitType->UnitType == UnitTypeFly ? influence : 0);
 
-       // For unit value, take Points...
+       // For unit value, take Points...
        influence = unitType->Points;
-       if ( influence <= 0 ) {
+       if (influence <= 0) {
            influence = 1;
        }
 
-       influences[WATER_UNITS_VALUE] = ( unitType->UnitType == UnitTypeNaval ? 
influence : 0 );
-       influences[GROUND_UNITS_VALUE] = ( unitType->UnitType == UnitTypeLand ? 
influence : 0 );
-       influences[AIR_UNITS_VALUE] = ( unitType->UnitType == UnitTypeFly ? 
influence : 0 );
-       influences[INVISIBLE_UNITS_VALUE] = ( unitType->PermanentCloak ? 1 : 0 
);
-
-       // Check if the unit has influence on force gauges
-       for ( force = 0; force < FORCE_COUNT; force++ ) {
-           if ( ( influence = influences[force] ) ) {
-               if ( onhotspot ) {
-                   GaugeValues[ForceBase + force * 6 + HOTSPOT_AREA + camp] += 
influence;
+       influences[WATER_UNITS_VALUE] =
+           (unitType->UnitType == UnitTypeNaval ? influence : 0);
+       influences[GROUND_UNITS_VALUE] =
+           (unitType->UnitType == UnitTypeLand ? influence : 0);
+       influences[AIR_UNITS_VALUE] =
+           (unitType->UnitType == UnitTypeFly ? influence : 0);
+       influences[INVISIBLE_UNITS_VALUE] = (unitType->PermanentCloak ? 1 : 0);
+
+       // Check if the unit has influence on force gauges
+       for (force = 0; force < FORCE_COUNT; force++) {
+           if ((influence = influences[force])) {
+               if (onhotspot) {
+                   GaugeValues[ForceBase + force * 6 + HOTSPOT_AREA + camp] +=
+                       influence;
                }
                GaugeValues[ForceBase + force * 6 + GLOBAL_AREA + camp] += 
influence;
            }
        }
     }
-   // Update ressources counts
-   // TODO : ressource not correctly computed ( but still unused... )
+    // Update ressources counts
+    // TODO : ressource not correctly computed ( but still unused... )
 }
 
-global void AiDebugGauges()
+global void AiDebugGauges(void)
 {
     int gauge;
     int *values;
     char buffer[256];
     values = AiScript->gauges;
 
-    if ( !values ) {
+    if (!values) {
        return;
     }
 
-    for ( gauge = 0; gauge < GAUGE_NB; gauge++ ) {
-       AiGetGaugeName( gauge, buffer, 256 );
-       DebugLevel3Fn( "%32s:%4d" _C_ buffer _C_ values[gauge] );
+    for (gauge = 0; gauge < GAUGE_NB; gauge++) {
+       AiGetGaugeName(gauge, buffer, 256);
+       DebugLevel3Fn("%32s:%4d" _C_ buffer _C_ values[gauge]);
     }
-    DebugLevel3Fn( "\n" );
-    fflush( stdout );
+    DebugLevel3Fn("\n");
+    fflush(stdout);
 }
 
 /**
@@ -445,7 +453,7 @@
 **             - the landpath needed to go there on ground
 **             - ...
 **/
-global void AiComputeCurrentScriptGauges()
+global void AiComputeCurrentScriptGauges(void)
 {
     int unit_id;
     int camp;
@@ -458,40 +466,40 @@
     HotSpotY = AiScript->HotSpot_Y;
     HotSpotRay = AiScript->HotSpot_Ray;
 
-   // Clear gauges
-    memset( GaugeValues, 0, sizeof ( int ) * GAUGE_NB );
+    // Clear gauges
+    memset(GaugeValues, 0, sizeof (int) * GAUGE_NB);
 
-    for ( player_id = 0; player_id < NumPlayers; player_id++ ) {
-       camp = AiGetPlayerCamp( Players + player_id );
-       if ( camp != FOR_NEUTRAL ) {
+    for (player_id = 0; player_id < NumPlayers; player_id++) {
+       camp = AiGetPlayerCamp(Players + player_id);
+       if (camp != FOR_NEUTRAL) {
            GaugeValues[camp] += Players[player_id].Score;
        }
     }
 
-   // Iterates Units...
-    for ( unit_id = 0; unit_id < NumUnits; unit_id++ ) {
+    // Iterates Units...
+    for (unit_id = 0; unit_id < NumUnits; unit_id++) {
        unit = Units[unit_id];
 
-       if ( ( unit )->Orders[0].Action == UnitActionDie ) {
+       if ((unit)->Orders[0].Action == UnitActionDie) {
            continue;
        }
-       if ( ( unit->X == -1 ) || ( unit->Y == -1 ) ) {
+       if ((unit->X == -1) || (unit->Y == -1)) {
            continue;
        }
 
-       AiDeclareUnitImpact( unit->X, unit->Y, unit );
-       // TODO : add onboard units, but only for value ( no fire power )
+       AiDeclareUnitImpact(unit->X, unit->Y, unit);
+       // TODO : add onboard units, but only for value ( no fire power )
 
     }
 
-   // debugGauge(GaugeValues);
+    // debugGauge(GaugeValues);
 
-   // If necessary, allocate space for values
-    if ( !AiScript->gauges ) {
-       AiScript->gauges = ( int * ) malloc( sizeof ( int ) * BasicGaugeNb );
+    // If necessary, allocate space for values
+    if (!AiScript->gauges) {
+       AiScript->gauges = (int *) malloc(sizeof (int) * BasicGaugeNb);
     }
-   // Copy gauges 
-    memcpy( AiScript->gauges, GaugeValues, sizeof ( int ) * BasicGaugeNb );
+    // Copy gauges 
+    memcpy(AiScript->gauges, GaugeValues, sizeof (int) * BasicGaugeNb);
 }
 
 /**
@@ -500,9 +508,9 @@
 **     @param gauge    the gauge
 **     @return its value
 */
-global int AiGetGaugeValue( int gauge )
+global int AiGetGaugeValue(int gauge)
 {
-    if ( !AiScript->gauges ) {
+    if (!AiScript->gauges) {
        return 0;
     }
     return AiScript->gauges[gauge];
@@ -514,7 +522,7 @@
 **     @param symbol   the gauge's scheme identifier
 **     @return         the gauge id, or -1 if not found
 */
-global int AiFindGaugeId( SCM symbol )
+global int AiFindGaugeId(SCM symbol)
 {
     int gauge;
     char buffer[256];
@@ -535,11 +543,11 @@
     return -1;
 }
 
-local int AiFindUnusedScript()
+local int AiFindUnusedScript(void)
 {
     int i;
-    for ( i = 1; i < AI_MAX_RUNNING_SCRIPTS; i++ ) {
-       if ( gh_null_p( AiPlayer->Scripts[i].Script ) ) {
+    for (i = 1; i < AI_MAX_RUNNING_SCRIPTS; i++) {
+       if (gh_null_p(AiPlayer->Scripts[i].Script)) {
            return i;
        }
     }
@@ -555,17 +563,17 @@
 **     @return                 -1 if running script now is not possible, 
 **                             else a value indicating how long/costly it 
would be to become 100% OK
 */
-local int AiEvaluateScript( SCM script )
+local int AiEvaluateScript(SCM script)
 {
     SCM get_need_lambda, rslt, willeval;
-    get_need_lambda = gh_cadr( gh_car( script ) );
+    get_need_lambda = gh_cadr(gh_car(script));
     willeval =
-       cons( get_need_lambda,
-             cons( cons( gh_symbol2scm( "quote" ), cons( script, NIL ) ), NIL 
) );
+       cons(get_need_lambda,
+       cons(cons(gh_symbol2scm("quote"), cons(script, NIL)), NIL));
 
-    rslt = gh_eval( willeval, NIL );
+    rslt = gh_eval(willeval, NIL);
 
-    return gh_scm2int( rslt );
+    return gh_scm2int(rslt);
 }
 
 /**
@@ -575,7 +583,7 @@
 **     @param total    want cost to build the entire force (1), or only for 
missing units ?
 **     @return         the cost, or -1 if impossible
 */
-global int AiEvaluateForceCost( int force, int total )
+global int AiEvaluateForceCost(int force, int total)
 {
     int want, i;
 
@@ -589,72 +597,72 @@
     AiUnitType *unittype;
 
 
-    AiForceCountUnits( force, count );
-   // We have everything ready
-    if ( !total ) {
-       if ( !AiForceSubstractWant( force, count ) ) {
-           DebugLevel3Fn( "Force ready, no cost\n" );
+    AiForceCountUnits(force, count);
+    // We have everything ready
+    if (!total) {
+       if (!AiForceSubstractWant(force, count)) {
+           DebugLevel3Fn("Force ready, no cost\n");
            return 0;
        }
     }
 
-    for ( i = 0; i < MaxCosts; i++ ) {
+    for (i = 0; i < MaxCosts; i++) {
        globalCosts[i] = 0;
     }
     globalTime = 0;
 
-   // For each "want" unittype, evaluate a cost, based on the number of units.
+    // For each "want" unittype, evaluate a cost, based on the number of units.
     unittype = AiPlayer->Force[force].UnitTypes;
-    while ( unittype ) {
-       want = ( -count[unittype->Type->Type] );
+    while (unittype) {
+       want = (-count[unittype->Type->Type]);
 
-       // Don't count full unittypes...        
-       if ( want > 0 ) {
-           if ( !CheckDependByIdent( AiPlayer->Player, unittype->Type->Ident ) 
) {
+       // Don't count full unittypes...        
+       if (want > 0) {
+           if (!CheckDependByIdent(AiPlayer->Player, unittype->Type->Ident)) {
                return -1;
            }
-          // Find number of units which can build this            
-           builders = AiCountUnitBuilders( unittype->Type );
+           // Find number of units which can build this            
+           builders = AiCountUnitBuilders(unittype->Type);
 
-          // No way to build this, return -1
-           if ( !builders ) {
+           // No way to build this, return -1
+           if (!builders) {
                return -1;
            }
-          // FIXME : all costs count the same there
-          // ( sum all costs ... )
+           // FIXME : all costs count the same there
+           // ( sum all costs ... )
 
-           for ( i = 0; i < MaxCosts; i++ ) {
+           for (i = 0; i < MaxCosts; i++) {
                globalCosts[i] += want * unittype->Type->_Costs[i];
            }
 
-          // FIXME : buildtime is assumed to be proportionnal to hitpoints 
+           // FIXME : buildtime is assumed to be proportionnal to hitpoints 
 
-          // Time to build the first
+           // Time to build the first
            globalTime += unittype->Type->_HitPoints;
-          // Time to build the nexts
-           globalTime += ( unittype->Type->_HitPoints * want ) / builders;
+           // Time to build the nexts
+           globalTime += (unittype->Type->_HitPoints * want) / builders;
        }
        unittype = unittype->Next;
     }
-   // Count the ressource proportionnaly to player ressource 
+    // Count the ressource proportionnaly to player ressource 
     cost = 0;
 
-   // Each ressource count as percentage of available...
-    for ( i = 0; i < MaxCosts; i++ ) {
-       if ( globalCosts[i] ) {
+    // Each ressource count as percentage of available...
+    for (i = 0; i < MaxCosts; i++) {
+       if (globalCosts[i]) {
            own = AiPlayer->Player->Resources[i];
-          // FIXME : minimum 400 is hardcoded ...
-           if ( own < 400 ) {
+           // FIXME : minimum 400 is hardcoded ...
+           if (own < 400) {
                own = 400;
            }
-          // FIXME : are overflow possible here ?
-           cost += ( 100 * globalCosts[i] + 100 * own ) / own;
+           // FIXME : are overflow possible here ?
+           cost += (100 * globalCosts[i] + 100 * own) / own;
        }
     }
 
 
-   // FIXME : 20 / 1 ratio between buildtime and cost is hardcoded         
-   // Here globalTime is ~ the sum of all HitPoints...
+    // FIXME : 20 / 1 ratio between buildtime and cost is hardcoded         
+    // Here globalTime is ~ the sum of all HitPoints...
     cost += globalTime / 20;
 
     return cost;
@@ -665,21 +673,21 @@
 **     Update the dst_force, so that it requires at least what "force" 
requires 
 **
 */
-local void AiUpdateForce( int dst_force, int force )
+local void AiUpdateForce(int dst_force, int force)
 {
     int i;
     int unitcount[UnitTypeMax + 1];
     AiUnitType *aitype;
 
-    memset( unitcount, 0, ( UnitTypeMax + 1 ) * sizeof ( int ) );
-    AiForceSubstractWant( force, unitcount );
-    for ( i = 0; i <= UnitTypeMax; i++ ) {
-       unitcount[i] = ( -unitcount[i] );
+    memset(unitcount, 0, (UnitTypeMax + 1) * sizeof (int));
+    AiForceSubstractWant(force, unitcount);
+    for (i = 0; i <= UnitTypeMax; i++) {
+       unitcount[i] = (-unitcount[i]);
     }
 
     aitype = AiPlayer->Force[dst_force].UnitTypes;
-    while ( aitype ) {
-       if ( unitcount[aitype->Type->Type] > aitype->Want ) {
+    while (aitype) {
+       if (unitcount[aitype->Type->Type] > aitype->Want) {
            aitype->Want = unitcount[aitype->Type->Type];
            unitcount[aitype->Type->Type] = 0;
        } else {
@@ -688,13 +696,13 @@
        aitype = aitype->Next;
     }
 
-    for ( i = 0; i <= UnitTypeMax; i++ ) {
-       if ( unitcount[i] > 0 ) {
-           aitype = ( AiUnitType * ) malloc( sizeof ( AiUnitType ) );
+    for (i = 0; i <= UnitTypeMax; i++) {
+       if (unitcount[i] > 0) {
+           aitype = (AiUnitType *) malloc(sizeof (AiUnitType));
            aitype->Want = unitcount[i];
            aitype->Type = UnitTypes[i];
 
-          // Insert into force.
+           // Insert into force.
            aitype->Next = AiPlayer->Force[dst_force].UnitTypes;
            AiPlayer->Force[dst_force].UnitTypes = aitype;
        }
@@ -706,37 +714,37 @@
 ** 
 ** Return the best value. 
 */
-local int AiFindBestScript( int defend, AiScriptAction * 
*foundBestScriptAction )
+local int AiFindBestScript(int defend, AiScriptAction * *foundBestScriptAction)
 {
     AiScriptAction *aiScriptAction, *bestScriptAction;
     int bestValue, curValue;
     int i;
 
-   // Find the best to do !
+    // Find the best to do !
     bestScriptAction = 0;
     bestValue = -1;
 
-    for ( i = 0; i < AiScriptActionNum; i++ ) {
+    for (i = 0; i < AiScriptActionNum; i++) {
        aiScriptAction = AiScriptActions + i;
 
-       if ( ( defend && ( aiScriptAction->Defensive ) )
-            || ( ( !defend ) && ( aiScriptAction->Offensive ) ) ) {
-           curValue = AiEvaluateScript( aiScriptAction->Action );
-           DebugLevel3Fn( "evaluate script " );
+       if ((defend && (aiScriptAction->Defensive))
+           || ((!defend) && (aiScriptAction->Offensive))) {
+           curValue = AiEvaluateScript(aiScriptAction->Action);
+           DebugLevel3Fn("evaluate script ");
 #if 0
-           gh_display( gh_car( gh_car( aiScriptAction->Action ) ) );
+           gh_display(gh_car(gh_car(aiScriptAction->Action)));
 #endif
-           DebugLevel3Fn( " => %d\n" _C_ curValue );
-           if ( ( curValue != -1 ) && ( ( !bestScriptAction ) || ( curValue <= 
bestValue ) ) ) {
+           DebugLevel3Fn(" => %d\n" _C_ curValue);
+           if ((curValue != -1) && ((!bestScriptAction) || (curValue <= 
bestValue))) {
                bestScriptAction = aiScriptAction;
                bestValue = curValue;
            }
-          // TODO : move to force 1 if attacking !!!!
-           AiEraseForce( AiScript->ownForce );
+           // TODO : move to force 1 if attacking !!!!
+           AiEraseForce(AiScript->ownForce);
        }
     }
 
-    ( *foundBestScriptAction ) = bestScriptAction;
+    (*foundBestScriptAction) = bestScriptAction;
     return bestValue;
 }
 
@@ -749,31 +757,31 @@
 **     @param HotSpot_Ray      Size of the hotspot
 **     @param defend           Is this a defense script ?      
 */
-local int AiPrepareScript( int HotSpot_X, int HotSpot_Y, int HotSpot_Ray, int 
defend )
+local int AiPrepareScript(int HotSpot_X, int HotSpot_Y, int HotSpot_Ray, int 
defend)
 {
     int scriptid;
 
     scriptid = AiFindUnusedScript();
 
-   // FIXME : scriptid>0    
-    if ( scriptid == -1 ) {
-       // FIXME : should we kill a running script there ?
-       //              ( maybe any attack script )
-       //              ( then a close "defend" script )
-       DebugLevel3Fn( "no free defend script available...\n" );
+    // FIXME : scriptid>0    
+    if (scriptid == -1) {
+       // FIXME : should we kill a running script there ?
+       //              ( maybe any attack script )
+       //              ( then a close "defend" script )
+       DebugLevel3Fn("no free defend script available...\n");
        return 0;
     }
-   // Need to set AiScript, to make AiEvaluateScript work
+    // Need to set AiScript, to make AiEvaluateScript work
     AiScript = AiPlayer->Scripts + scriptid;
     AiScript->HotSpot_X = HotSpot_X;
     AiScript->HotSpot_Y = HotSpot_Y;
 
     AiScript->HotSpot_Ray = HotSpot_Ray;
-    AiEraseForce( AiScript->ownForce );
+    AiEraseForce(AiScript->ownForce);
     AiPlayer->Force[AiScript->ownForce].Role =
-       ( defend ? AiForceRoleDefend : AiForceRoleAttack );
+       (defend ? AiForceRoleDefend : AiForceRoleAttack);
     AiPlayer->Force[AiScript->ownForce].PopulateMode =
-       ( defend ? AiForcePopulateAny : AiForcePopulateFromAttack );
+       (defend ? AiForcePopulateAny : AiForcePopulateFromAttack);
     AiPlayer->Force[AiScript->ownForce].UnitsReusable = 0;
     AiPlayer->Force[AiScript->ownForce].HelpMode = AiForceHelpForce;
 
@@ -782,59 +790,59 @@
     return scriptid;
 }
 
-local void AiStartScript( AiScriptAction * script, char *ident )
+local void AiStartScript(AiScriptAction * script, char *ident)
 {
     SCM code;
 
-   // Compute force requirements.
-    AiEvaluateScript( script->Action );
-   // TODO : move from force 0 to force script->ownForce    
-   // TODO : give some feedback on force 0 !
+    // Compute force requirements.
+    AiEvaluateScript(script->Action);
+    // TODO : move from force 0 to force script->ownForce    
+    // TODO : give some feedback on force 0 !
 
-   // Launch the code.
-    code = gh_eval( gh_cadr( gh_cdr( gh_car( script->Action ) ) ), NIL );
+    // Launch the code.
+    code = gh_eval(gh_cadr(gh_cdr(gh_car(script->Action))), NIL);
     AiScript->Script = code;
     AiScript->SleepCycles = 0;
-    snprintf( AiScript->ident, 10, "%s", ident );
+    snprintf(AiScript->ident, 10, "%s", ident);
 }
 
 
-global void AiFindDefendScript( int attackX, int attackY )
+global void AiFindDefendScript(int attackX, int attackY)
 {
     int bestValue;
     AiScriptAction *bestScriptAction;
 
-    if ( !AiPrepareScript( attackX, attackY, 12, 1 ) ) {
+    if (!AiPrepareScript(attackX, attackY, 12, 1)) {
        return;
     }
-    DebugLevel3Fn( "find defend script\n" );
-    bestValue = AiFindBestScript( 1, &bestScriptAction );
+    DebugLevel3Fn("find defend script\n");
+    bestValue = AiFindBestScript(1, &bestScriptAction);
 
-    if ( !bestScriptAction ) {
-       // Nothing available, ouch !
-       AiUpdateForce( 0, AiScript->ownForce );
-       AiEraseForce( AiScript->ownForce );
-       DebugLevel3Fn( "no correct defense action script available...\n" );
+    if (!bestScriptAction) {
+       // Nothing available, ouch !
+       AiUpdateForce(0, AiScript->ownForce);
+       AiEraseForce(AiScript->ownForce);
+       DebugLevel3Fn("no correct defense action script available...\n");
        return;
     }
-    DebugLevel3Fn( "launch script with value %d\n" _C_ bestValue );
-    AiStartScript( bestScriptAction, "defend" );
+    DebugLevel3Fn("launch script with value %d\n" _C_ bestValue);
+    AiStartScript(bestScriptAction, "defend");
 }
 
-local Unit *RandomPlayerUnit( Player * player )
+local Unit *RandomPlayerUnit(Player * player)
 {
     int try;
     int unitId;
     Unit *unit;
-    if ( !player->TotalNumUnits ) {
+    if (!player->TotalNumUnits) {
        return NoUnitP;
     }
 
-    for ( try = 0; try < 10; try++ ) {
+    for (try = 0; try < 10; try++) {
        unitId = SyncRand() % player->TotalNumUnits;
        unit = player->Units[unitId];
-       // FIXME : is this unit targettable ?   
-       if ( ( !unit->Removed ) && ( !( ( unit )->Orders[0].Action == 
UnitActionDie ) ) ) {
+       // FIXME : is this unit targettable ?   
+       if ((!unit->Removed) && (!((unit)->Orders[0].Action == UnitActionDie))) 
{
            return unit;
        }
     }
@@ -842,7 +850,7 @@
 
 }
 
-local Unit *RandomEnemyUnit()
+local Unit *RandomEnemyUnit(void)
 {
     int try;
     int player;
@@ -850,27 +858,27 @@
     int enemyPlayerCount;
     Unit *unit;
 
-   // find enemies
+    // find enemies
     enemyPlayerCount = 0;
-    for ( player = 0; player < NumPlayers; player++ ) {
-       if ( ( AiPlayer->Player->Enemy & ( 1 << player ) )
-            && ( AiPlayer->Player->TotalNumUnits ) ) {
+    for (player = 0; player < NumPlayers; player++) {
+       if ((AiPlayer->Player->Enemy & (1 << player))
+           && (AiPlayer->Player->TotalNumUnits)) {
            enemyPlayers[enemyPlayerCount] = player;
            enemyPlayerCount++;
        }
     }
 
-    if ( !enemyPlayerCount ) {
+    if (!enemyPlayerCount) {
        return NoUnitP;
     }
 
-    for ( try = 0; try < 10; try++ ) {
-       // find one enemy
+    for (try = 0; try < 10; try++) {
+       // find one enemy
        player = enemyPlayers[SyncRand() % enemyPlayerCount];
 
-       unit = RandomPlayerUnit( Players + player );
+       unit = RandomPlayerUnit(Players + player);
 
-       if ( unit != NoUnitP ) {
+       if (unit != NoUnitP) {
            return unit;
        }
     }
@@ -878,16 +886,16 @@
     return NoUnitP;
 }
 
-local void AiRemoveFirstAiPlayerEvaluation()
+local void AiRemoveFirstAiPlayerEvaluation(void)
 {
     AiActionEvaluation *actionEvaluation = AiPlayer->FirstEvaluation;
 
     AiPlayer->FirstEvaluation = actionEvaluation->Next;
-    free( actionEvaluation );
+    free(actionEvaluation);
     AiPlayer->EvaluationCount--;
 }
 
-global void AiPeriodicAttack()
+global void AiPeriodicAttack(void)
 {
     AiScriptAction *bestScriptAction;
     AiActionEvaluation *actionEvaluation;
@@ -897,95 +905,96 @@
     int bestValue, bestHotSpot;
     int leftCost, totalCost;
 
-   // Find a random enemy unit.
+    // Find a random enemy unit.
     enemy = RandomEnemyUnit();
-    if ( enemy == NoUnitP ) {
-       DebugLevel3Fn( "No enemy unit found for attack, giving up !\n" );
+    if (enemy == NoUnitP) {
+       DebugLevel3Fn("No enemy unit found for attack, giving up !\n");
        return;
     }
-   // Find a unit as start point.
-   // own=RandomPlayerUnit(AiPlayer->Player);
-   // Need to set AiScript, to make AiEvaluateScript work
-    if ( !AiPrepareScript( enemy->X, enemy->Y, 16, 0 ) ) {
+    // Find a unit as start point.
+    // own=RandomPlayerUnit(AiPlayer->Player);
+    // Need to set AiScript, to make AiEvaluateScript work
+    if (!AiPrepareScript(enemy->X, enemy->Y, 16, 0)) {
        return;
     }
-    DebugLevel3Fn( "random attack\n" );
+    DebugLevel3Fn("random attack\n");
 
-    bestScriptValue = AiFindBestScript( 0, &bestScriptAction );
-    if ( bestScriptValue == -1 ) {
-       DebugLevel3Fn( "No usable attack script, giving up !\n" );
+    bestScriptValue = AiFindBestScript(0, &bestScriptAction);
+    if (bestScriptValue == -1) {
+       DebugLevel3Fn("No usable attack script, giving up !\n");
        return;
     }
-   // Add a new ActionEvaluation at the end of the queue
-    actionEvaluation = ( AiActionEvaluation * ) malloc( sizeof ( 
AiActionEvaluation ) );
+    // Add a new ActionEvaluation at the end of the queue
+    actionEvaluation = (AiActionEvaluation *) malloc(sizeof 
(AiActionEvaluation));
     actionEvaluation->aiScriptAction = bestScriptAction;
     actionEvaluation->hotSpotX = enemy->X;
     actionEvaluation->hotSpotY = enemy->Y;
     actionEvaluation->value = bestScriptValue;
     actionEvaluation->hotSpotValue =
-       AiGetGaugeValue( ForceGauge( WATER_UNITS_VALUE, HOTSPOT_AREA, FOR_ENEMY 
) )
-       + AiGetGaugeValue( ForceGauge( GROUND_UNITS_VALUE, HOTSPOT_AREA, 
FOR_ENEMY ) )
-       + AiGetGaugeValue( ForceGauge( AIR_UNITS_VALUE, HOTSPOT_AREA, FOR_ENEMY 
) );
-    DebugLevel3Fn( "new action at %d %d, hotspotValue=%d, cost=%d\n" _C_
-                  enemy->X _C_ enemy->Y _C_
-                  actionEvaluation->hotSpotValue _C_ actionEvaluation->value );
+       AiGetGaugeValue(ForceGauge(WATER_UNITS_VALUE, HOTSPOT_AREA, FOR_ENEMY))
+       + AiGetGaugeValue(ForceGauge(GROUND_UNITS_VALUE, HOTSPOT_AREA, 
FOR_ENEMY))
+       + AiGetGaugeValue(ForceGauge(AIR_UNITS_VALUE, HOTSPOT_AREA, FOR_ENEMY));
+    DebugLevel3Fn("new action at %d %d, hotspotValue=%d, cost=%d\n" _C_
+       enemy->X _C_ enemy->Y _C_
+       actionEvaluation->hotSpotValue _C_ actionEvaluation->value);
 
-   // Insert the evaluation result at the end...
+    // Insert the evaluation result at the end...
     AiPlayer->EvaluationCount++;
     actionEvaluation->Next = 0;
-    if ( AiPlayer->LastEvaluation ) {
+    if (AiPlayer->LastEvaluation) {
        AiPlayer->LastEvaluation->Next = actionEvaluation;
     } else {
        AiPlayer->FirstEvaluation = actionEvaluation;
     }
     AiPlayer->LastEvaluation = actionEvaluation;
 
-   // Don't keep more than AI_MEMORY_SIZE ( remove old ones )  
-    while ( AiPlayer->EvaluationCount > AI_MEMORY_SIZE ) {
+    // Don't keep more than AI_MEMORY_SIZE ( remove old ones )  
+    while (AiPlayer->EvaluationCount > AI_MEMORY_SIZE) {
        AiRemoveFirstAiPlayerEvaluation();
     }
 
-   // Iterate all actionEvalution. If one of them is better than all others, 
go !
+    // Iterate all actionEvalution. If one of them is better than all others, 
go !
     bestActionEvaluation = 0;
     bestValue = -1;
     bestHotSpot = 0;
 
     actionEvaluation = AiPlayer->FirstEvaluation;
-    while ( actionEvaluation ) {
-       if ( ( ( bestValue == -1 ) || ( actionEvaluation->value <= bestValue ) )
-            && ( actionEvaluation->hotSpotValue >= bestHotSpot ) ) {
+    while (actionEvaluation) {
+       if (((bestValue == -1) || (actionEvaluation->value <= bestValue))
+           && (actionEvaluation->hotSpotValue >= bestHotSpot)) {
            bestActionEvaluation = actionEvaluation;
        }
 
-       if ( ( bestValue == -1 ) || ( actionEvaluation->value <= bestValue ) ) {
+       if ((bestValue == -1) || (actionEvaluation->value <= bestValue)) {
            bestValue = actionEvaluation->value;
        }
-       if ( actionEvaluation->hotSpotValue >= bestHotSpot ) {
+       if (actionEvaluation->hotSpotValue >= bestHotSpot) {
            bestHotSpot = actionEvaluation->hotSpotValue;
        }
        actionEvaluation = actionEvaluation->Next;
     }
 
-    if ( ( bestActionEvaluation ) ) {
-       DebugLevel3Fn( "has a best script, value=%d, hotspot=%d\n" _C_ 
bestValue _C_
-                      bestHotSpot );
-       // => lance si la force est à 80-90%... 
-       AiPrepareScript( bestActionEvaluation->hotSpotX, 
bestActionEvaluation->hotSpotY, 16, 0 );
-
-       AiEvaluateScript( bestActionEvaluation->aiScriptAction->Action );
-
-       leftCost = AiEvaluateForceCost( AiScript->ownForce, 0 );
-       totalCost = AiEvaluateForceCost( AiScript->ownForce, 1 );
-
-       if ( leftCost <= ( ( 8 * totalCost ) / 10 ) ) {
-           DebugLevel3Fn( "Attack script !...\n" );
-           AiStartScript( bestActionEvaluation->aiScriptAction, "attack" );
+    if ((bestActionEvaluation)) {
+       DebugLevel3Fn("has a best script, value=%d, hotspot=%d\n" _C_ bestValue 
_C_
+           bestHotSpot);
+       // => lance si la force est à 80-90%... 
+       AiPrepareScript(bestActionEvaluation->hotSpotX, 
bestActionEvaluation->hotSpotY,
+           16, 0);
+
+       AiEvaluateScript(bestActionEvaluation->aiScriptAction->Action);
+
+       leftCost = AiEvaluateForceCost(AiScript->ownForce, 0);
+       totalCost = AiEvaluateForceCost(AiScript->ownForce, 1);
+
+       if (leftCost <= ((8 * totalCost) / 10)) {
+           DebugLevel3Fn("Attack script !...\n");
+           AiStartScript(bestActionEvaluation->aiScriptAction, "attack");
        } else {
-           DebugLevel3Fn( "Not ready for attack script, wait...\n" );
+           DebugLevel3Fn("Not ready for attack script, wait...\n");
 
-          //AiForceTransfert(AiScript->ownForce,0);
-           AiUpdateForce( 1, AiScript->ownForce );
-           AiEraseForce( AiScript->ownForce );
+           //AiForceTransfert(AiScript->ownForce,0);
+           AiUpdateForce(1, AiScript->ownForce);
+           AiEraseForce(AiScript->ownForce);
        }
     }
 }
Index: stratagus/src/ai/ccl_ai.c
diff -u stratagus/src/ai/ccl_ai.c:1.71 stratagus/src/ai/ccl_ai.c:1.72
--- stratagus/src/ai/ccl_ai.c:1.71      Fri Oct 24 01:22:29 2003
+++ stratagus/src/ai/ccl_ai.c   Sun Oct 26 10:34:59 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//      $Id: ccl_ai.c,v 1.71 2003/10/24 05:22:29 mr-russ Exp $
+//      $Id: ccl_ai.c,v 1.72 2003/10/26 15:34:59 pludov Exp $
 
 //@{
 
@@ -53,310 +53,235 @@
 --     Forwards
 ----------------------------------------------------------------------------*/
 /// Handle saving/loading a reference to an AiType.
-local void IOAiTypePtr( SCM from, void *binaryform, void *para );
+local void IOAiTypePtr(SCM from, void *binaryform, void *para);
 /// Handle saving/loading a reference to an AiScriptAction.
-local void IOAiScriptActionPtr( SCM scmfrom, void *binaryform, void *para );
+local void IOAiScriptActionPtr(SCM scmfrom, void *binaryform, void *para);
 /// Handle saving/loading an array of int for ressources.
-local void IORessourceArray( SCM scmfrom, void *binaryform, void *para );
+local void IORessourceArray(SCM scmfrom, void *binaryform, void *para);
 /// Handle saving/loading a ressource mask
-local void IORessourceMask( SCM scmfrom, void *binaryform, void *para );
+local void IORessourceMask(SCM scmfrom, void *binaryform, void *para);
 
 /*----------------------------------------------------------------------------
 --     Constants
 ----------------------------------------------------------------------------*/
 
 /// Description of the AiActionEvaluation structure 
-static CclStructDef AiActionEvaluationStructDef = {
+static IOStructDef AiActionEvaluationStructDef = {
     "AiActionEvaluation",
-    sizeof ( AiActionEvaluation ),
+    sizeof (AiActionEvaluation),
     -1,
     {
-     {"`next", NULL, &( ( AiActionEvaluation * ) 0 )->Next, NULL}
-     ,
-     {"ai-script-action", &IOAiScriptActionPtr,
-      &( ( AiActionEvaluation * ) 0 )->aiScriptAction, NULL}
-     ,
-     {"hotspot-x", &IOInt, &( ( AiActionEvaluation * ) 0 )->hotSpotX, NULL}
-     ,
-     {"hotspot-y", &IOInt, &( ( AiActionEvaluation * ) 0 )->hotSpotY, NULL}
-     ,
-     {"hotspot-value", &IOInt, &( ( AiActionEvaluation * ) 0 )->hotSpotValue, 
NULL}
-     ,
-     {"value", &IOInt, &( ( AiActionEvaluation * ) 0 )->value, NULL}
-     ,
-     {0, 0, 0, 0}
-     }
+       {"`next",               NULL,           &((AiActionEvaluation *) 
0)->Next,      NULL},
+       {"ai-script-action",    &IOAiScriptActionPtr,&((AiActionEvaluation *) 
0)->aiScriptAction,NULL},
+       {"hotspot-x",           &IOInt,         &((AiActionEvaluation *) 
0)->hotSpotX,  NULL},
+       {"hotspot-y",           &IOInt,         &((AiActionEvaluation *) 
0)->hotSpotY,  NULL},
+       {"hotspot-value",       &IOInt,         &((AiActionEvaluation *) 
0)->hotSpotValue,NULL},
+       {"value",               &IOInt,         &((AiActionEvaluation *) 
0)->value,     NULL},
+       {0, 0, 0, 0}
+    }
 };
 
 /// Description of the AiRunningScript structure
-static CclStructDef AiRunningScriptStructDef = {
+static IOStructDef AiRunningScriptStructDef = {
     "AiRunningScript",
-    sizeof ( AiRunningScript ),
+    sizeof (AiRunningScript),
     AI_MAX_RUNNING_SCRIPTS,
     {
-     {"script", &IOCcl, &( ( AiRunningScript * ) 0 )->Script, NULL}
-     ,
-     {"sleep-cycles", &IOInt, &( ( AiRunningScript * ) 0 )->SleepCycles, NULL}
-     ,
-     {"ident", &IOStrBuffer, &( ( AiRunningScript * ) 0 )->ident, ( void * ) 
10},
-     {"hotspot-x", &IOInt, &( ( AiRunningScript * ) 0 )->HotSpot_X, NULL},
-     {"hotspot-y", &IOInt, &( ( AiRunningScript * ) 0 )->HotSpot_Y, NULL},
-     {"hotspot-ray", &IOInt, &( ( AiRunningScript * ) 0 )->HotSpot_Ray, NULL},
-     {"own-force", &IOInt, &( ( AiRunningScript * ) 0 )->ownForce, NULL},
-     {"gauges", &IOIntArrayPtr, &( ( AiRunningScript * ) 0 )->gauges, ( void * 
) GAUGE_NB},
-     {0, 0, 0, 0}
-     }
+       {"script",              &IOCcl,         &((AiRunningScript *) 
0)->Script,       NULL},
+       {"sleep-cycles",        &IOInt,         &((AiRunningScript *) 
0)->SleepCycles,  NULL},
+       {"ident",               &IOStrBuffer,   &((AiRunningScript *) 
0)->ident,        (void *) 10},
+       {"hotspot-x",           &IOInt,         &((AiRunningScript *) 
0)->HotSpot_X,    NULL},
+       {"hotspot-y",           &IOInt,         &((AiRunningScript *) 
0)->HotSpot_Y,    NULL},
+       {"hotspot-ray",         &IOInt,         &((AiRunningScript *) 
0)->HotSpot_Ray,  NULL},
+       {"own-force",           &IOInt,         &((AiRunningScript *) 
0)->ownForce,     NULL},
+       {"gauges",              &IOIntArrayPtr, &((AiRunningScript *) 
0)->gauges,       (void *) GAUGE_NB},
+       {0, 0, 0, 0}
+    }
 };
 
 /// Description of the role flags
-static CclFlagDef AiRoleFlag[] = {
+static IOFlagDef AiRoleFlag[] = {
     {"attack", AiForceRoleAttack}, {"defend", AiForceRoleDefend}, {0, 0}
 };
 
 /// Description of the populate flags
-static CclFlagDef AiPopulateFlag[] = {
+static IOFlagDef AiPopulateFlag[] = {
     {"dont-populate", AiForceDontPopulate}, {"from-scratch", 
AiForcePopulateFromScratch},
     {"from-attack", AiForcePopulateFromAttack}, {"any", AiForcePopulateAny}, 
{0, 0}
 };
 
 /// Description of the help flags
-static CclFlagDef AiHelpFlag[] = {
+static IOFlagDef AiHelpFlag[] = {
     {"no-help", AiForceDontHelp}, {"force-help", AiForceHelpForce},
     {"full-help", AiForceHelpFull}, {0, 0}
 };
 
 /// Description of the AiUnitType structure
-static CclStructDef AiUnitTypeStructDef = {
+static IOStructDef AiUnitTypeStructDef = {
     "AiUnitType",
-    sizeof ( AiUnitType ),
+    sizeof (AiUnitType),
     -1,
     {
-     {"'next", 0, &( ( AiUnitType * ) 0 )->Next, 0}
-     ,
-     {"type", &IOUnitTypePtr, &( ( AiUnitType * ) 0 )->Type, 0}
-     ,
-     {"want", &IOInt, &( ( AiUnitType * ) 0 )->Want, 0}
-     ,
-     {0, 0, 0, 0}
-     }
+       {"'next",               0,              &((AiUnitType *) 0)->Next,      
        0},
+       {"type",                &IOUnitTypePtr, &((AiUnitType *) 0)->Type,      
        0},
+       {"want",                &IOInt,         &((AiUnitType *) 0)->Want,      
        0},
+       {0, 0, 0, 0}
+    }
 };
 
 /// Description of the AiUnit structure
-static CclStructDef AiUnitStructDef = {
+static IOStructDef AiUnitStructDef = {
     "AiUnit",
-    sizeof ( AiUnit ),
+    sizeof (AiUnit),
     -1,
     {
-     {"'next", NULL, &( ( AiUnit * ) 0 )->Next, 0}
-     ,
-     {"unit", &IOUnitPtr, &( ( AiUnit * ) 0 )->Unit, 0}
-     ,
-     {0, 0, 0, 0}
-     }
+       {"'next",               NULL,           &((AiUnit *) 0)->Next,          
        0},
+       {"unit",                &IOUnitPtr,     &((AiUnit *) 0)->Unit,          
        0},
+       {0, 0, 0, 0}
+    }
 };
 
 /// Description of the AiForce structure
-static CclStructDef AiForceStructDef = {
+static IOStructDef AiForceStructDef = {
     "AiForce",
-    sizeof ( AiForce ),
+    sizeof (AiForce),
     AI_MAX_FORCES,
     {
-     {"completed", &IOCharBool, &( ( AiForce * ) 0 )->Completed, 0}
-     ,
-     {"attacking", &IOCharBool, &( ( AiForce * ) 0 )->Attacking, 0}
-     ,
-     {"role", &IOCharFlag, &( ( AiForce * ) 0 )->Role, &AiRoleFlag}
-     ,
-     {"populate-mode", &IOCharFlag, &( ( AiForce * ) 0 )->PopulateMode, 
&AiPopulateFlag}
-     ,
-     {"units-reusable", &IOCharBool, &( ( AiForce * ) 0 )->UnitsReusable, 0}
-     ,
-     {"help-mode", &IOCharFlag, &( ( AiForce * ) 0 )->HelpMode, &AiHelpFlag}
-     ,
-
-     {"unit-wants", &IOLinkedList, &( ( AiForce * ) 0 )->UnitTypes, 
&AiUnitTypeStructDef}
-     ,
-     {"unit-presents", &IOLinkedList, &( ( AiForce * ) 0 )->Units, 
&AiUnitStructDef}
-     ,
-
-     {"attack-state", &IOInt, &( ( AiForce * ) 0 )->State, 0}
-     ,
-     {"attack-goal-x", &IOInt, &( ( AiForce * ) 0 )->GoalX, 0}
-     ,
-     {"attack-goal-y", &IOInt, &( ( AiForce * ) 0 )->GoalY, 0}
-     ,
-     {"must-transport", &IOBool, &( ( AiForce * ) 0 )->MustTransport, 0}
-     ,
-     {0, 0, 0, 0}
-     }
+       {"completed",           &IOCharBool,    &((AiForce *) 0)->Completed,    
        0},
+       {"attacking",           &IOCharBool,    &((AiForce *) 0)->Attacking,    
        0},
+       {"role",                &IOCharFlag,    &((AiForce *) 0)->Role,         
        &AiRoleFlag},
+       {"populate-mode",       &IOCharFlag,    &((AiForce *) 0)->PopulateMode, 
        &AiPopulateFlag},
+       {"units-reusable",      &IOCharBool,    &((AiForce *) 
0)->UnitsReusable,        0},
+       {"help-mode",           &IOCharFlag,    &((AiForce *) 0)->HelpMode,     
        &AiHelpFlag},
+       {"unit-wants",          &IOLinkedList,  &((AiForce *) 0)->UnitTypes,    
        &AiUnitTypeStructDef},
+       {"unit-presents",       &IOLinkedList,  &((AiForce *) 0)->Units,        
        &AiUnitStructDef},
+       {"attack-state",        &IOInt,         &((AiForce *) 0)->State,        
        0},
+       {"attack-goal-x",       &IOInt,         &((AiForce *) 0)->GoalX,        
        0},
+       {"attack-goal-y",       &IOInt,         &((AiForce *) 0)->GoalY,        
        0},
+       {"must-transport",      &IOBool,        &((AiForce *) 
0)->MustTransport,        0},
+       {0, 0, 0, 0}
+    }
 };
 
 /// Description of the AiBuildQueue structure/linked list
-static CclStructDef AiBuildQueueStructDef = {
+static IOStructDef AiBuildQueueStructDef = {
     "AiBuildQueue",
-    sizeof ( AiBuildQueue ),
+    sizeof (AiBuildQueue),
     -1,
     {
-     {"`next", 0, &( ( AiBuildQueue * ) 0 )->Next, 0}
-     ,
-     {"want", &IOInt, &( ( AiBuildQueue * ) 0 )->Want, 0}
-     ,
-     {"made", &IOInt, &( ( AiBuildQueue * ) 0 )->Made, 0}
-     ,
-     {"type", &IOUnitTypePtr, &( ( AiBuildQueue * ) 0 )->Type, 0}
-     ,
-     {0, 0, 0, 0}
-     }
+       {"`next",               0,              &((AiBuildQueue *) 0)->Next,    
        0},
+       {"want",                &IOInt,         &((AiBuildQueue *) 0)->Want,    
        0},
+       {"made",                &IOInt,         &((AiBuildQueue *) 0)->Made,    
        0},
+       {"type",                &IOUnitTypePtr, &((AiBuildQueue *) 0)->Type,    
        0},
+       {0, 0, 0, 0}
+    }
 };
 
 /// Description of the AiUnitTypeTable table in PlayerAi
-static CclStructDef AiUnitTypeTableStructDef = {
+static IOStructDef AiUnitTypeTableStructDef = {
     "AiUnitTypeTable",
-    sizeof ( AiUnitTypeTable ),
+    sizeof (AiUnitTypeTable),
     -1,
     {
-     {"unittype", IOUnitTypePtr, &( ( AiUnitTypeTable * ) 0 )->Table, 0}
-     ,
-     {"count", IOInt, &( ( AiUnitTypeTable * ) 0 )->Count, 0}
-     ,
-     {0, 0, 0, 0}
-     }
+       {"unittype",            &IOUnitTypePtr, &((AiUnitTypeTable *) 
0)->Table,        0},
+       {"count",               &IOInt,         &((AiUnitTypeTable *) 
0)->Count,        0},
+       {0, 0, 0, 0}
+    }
 };
 
 
 /// Description of the UnitTypeRequests table in PlayerAi
-static CclStructDef UnitTypeRequestsTableDef = {
+static IOStructDef UnitTypeRequestsTableDef = {
     "UnitTypeRequests",
-    sizeof ( AiUnitTypeTable ),
+    sizeof (AiUnitTypeTable),
     -1,
     {
-     {"`ptr", 0, &( ( PlayerAi * ) 0 )->UnitTypeRequests, 0}
-     ,
-     {"`count", 0, &( ( PlayerAi * ) 0 )->UnitTypeRequestsCount, 0}
-     ,
-     {"`items", &IOStruct, 0, &AiUnitTypeTableStructDef}
-     ,
-     {0, 0, 0, 0}
-     }
+       {"`ptr",                0,              &((PlayerAi *) 
0)->UnitTypeRequests,    0},
+       {"`count",              0,              &((PlayerAi *) 
0)->UnitTypeRequestsCount,0},
+       {"`items",              &IOStruct,      0,                              
        &AiUnitTypeTableStructDef},
+       {0, 0, 0, 0}
+    }
 };
 
 /// Description of the UpgradeToRequests table in PlayerAi
-static CclStructDef UpgradeToRequestsTableDef = {
+static IOStructDef UpgradeToRequestsTableDef = {
     "UpgradeToRequests",
-    sizeof ( UnitType * ),
+    sizeof (UnitType *),
     -1,
     {
-     {"`ptr", 0, &( ( PlayerAi * ) 0 )->UpgradeToRequests, 0}
-     ,
-     {"`count", 0, &( ( PlayerAi * ) 0 )->UpgradeToRequestsCount, 0}
-     ,
-     {"`items", &IOUnitTypePtr, 0, 0}
-     ,
-     {0, 0, 0, 0}
-     }
+       {"`ptr",                0,              &((PlayerAi *) 
0)->UpgradeToRequests,   0},
+       {"`count",              0,              &((PlayerAi *) 
0)->UpgradeToRequestsCount,0},
+       {"`items",              &IOUnitTypePtr, 0,                              
        0},
+       {0, 0, 0, 0}
+    }
 };
 
 /// Description of the ResearchRequests table in PlayerAi
-static CclStructDef ResearchRequestsTableDef = {
+static IOStructDef ResearchRequestsTableDef = {
     "ResearchRequests",
-    sizeof ( Upgrade * ),
+    sizeof (Upgrade *),
     -1,
     {
-     {"`ptr", 0, &( ( PlayerAi * ) 0 )->ResearchRequests, 0}
-     ,
-     {"`count", 0, &( ( PlayerAi * ) 0 )->ResearchRequestsCount, 0}
-     ,
-     {"`items", &IOUpgradePtr, 0, 0}
-     ,
-     {0, 0, 0, 0}
-     }
+       {"`ptr",                0,              &((PlayerAi *) 
0)->ResearchRequests,    0},
+       {"`count",              0,              &((PlayerAi *) 
0)->ResearchRequestsCount,0},
+       {"`items",              &IOUpgradePtr,  0,                              
        0},
+       {0, 0, 0, 0}
+    }
 };
 
 /// Description of the PlayerAi structure
-static CclStructDef PlayerAiStructDef = {
+static IOStructDef PlayerAiStructDef = {
     "PlayerAi",
-    sizeof ( PlayerAi ),
+    sizeof (PlayerAi),
     -1,
     {
-     {"player", &IOPlayerPtr, &( ( PlayerAi * ) 0 )->Player, 0}
-     ,
-     {"ai-type", &IOAiTypePtr, &( ( PlayerAi * ) 0 )->AiType, 0}
-     ,
-     {"scripts", &IOStructArray, &( ( PlayerAi * ) 0 )->Scripts, 
&AiRunningScriptStructDef}
-     ,
-     {"past-evaluations", &IOLinkedList, &( ( PlayerAi * ) 0 
)->FirstEvaluation,
-      &AiActionEvaluationStructDef}
-     ,
-     {"debug", &IOBool, &( ( PlayerAi * ) 0 )->ScriptDebug, 0}
-     ,
-     {"auto-attack", &IOBool, &( ( PlayerAi * ) 0 )->AutoAttack, 0}
-     ,
-     {"forces", &IOStructArray, &( ( PlayerAi * ) 0 )->Force, 
&AiForceStructDef}
-     ,
-
-     {"reserve", &IORessourceArray, &( ( PlayerAi * ) 0 )->Reserve, 0}
-     ,
-     {"used", &IORessourceArray, &( ( PlayerAi * ) 0 )->Used, 0}
-     ,
-     {"needed", &IORessourceArray, &( ( PlayerAi * ) 0 )->Needed, 0}
-     ,
-     {"collect", &IORessourceArray, &( ( PlayerAi * ) 0 )->Collect, 0}
-     ,
-     {"neededmask", &IORessourceMask, &( ( PlayerAi * ) 0 )->Reserve, 0}
-     ,
-     {"need-food", &IOBool, &( ( PlayerAi * ) 0 )->NeedFood, 0}
-     ,
-
-     {"unit-type-requests", &IOTable, 0, &UnitTypeRequestsTableDef}
-     ,
-     {"upgrade-to-requests", &IOTable, 0, &UpgradeToRequestsTableDef}
-     ,
-     {"research-requests", &IOTable, 0, &ResearchRequestsTableDef}
-     ,
-
-     {"unit-type-builded", &IOLinkedList, &( ( PlayerAi * ) 0 
)->UnitTypeBuilded,
-      &AiBuildQueueStructDef}
-     ,
-
-     {"last-repair-building", &IOInt, &( ( PlayerAi * ) 0 
)->LastRepairBuilding, 0}
-     ,
-     {"tried-repair-worker", &IOIntArray, &( ( PlayerAi * ) 0 
)->TriedRepairWorkers,
-      ( void * ) UnitMax},
-     {0, 0, 0, 0}
-     }
+       {"player",              &IOPlayerPtr,   &((PlayerAi *) 0)->Player,      
        0},
+       {"ai-type",             &IOAiTypePtr,   &((PlayerAi *) 0)->AiType,      
        0},
+       {"scripts",             &IOStructArray, &((PlayerAi *) 0)->Scripts,     
        &AiRunningScriptStructDef},
+       {"past-evaluations",    &IOLinkedList,  &((PlayerAi *) 
0)->FirstEvaluation,     &AiActionEvaluationStructDef},
+       {"debug",               &IOBool,        &((PlayerAi *) 0)->ScriptDebug, 
        0},
+       {"auto-attack",         &IOBool,        &((PlayerAi *) 0)->AutoAttack,  
        0},
+       {"forces",              &IOStructArray, &((PlayerAi *) 0)->Force,       
        &AiForceStructDef},
+       {"reserve",             &IORessourceArray,&((PlayerAi *) 0)->Reserve,   
        0},
+       {"used",                &IORessourceArray,&((PlayerAi *) 0)->Used,      
        0},
+       {"needed",              &IORessourceArray,&((PlayerAi *) 0)->Needed,    
        0},
+       {"collect",             &IORessourceArray,&((PlayerAi *) 0)->Collect,   
        0},
+       {"neededmask",          &IORessourceMask,&((PlayerAi *) 0)->Reserve,    
        0},
+       {"need-food",           &IOBool,        &((PlayerAi *) 0)->NeedFood,    
        0},
+       {"unit-type-requests",  &IOTable,       0,                              
        &UnitTypeRequestsTableDef},
+       {"upgrade-to-requests", &IOTable,       0,                              
        &UpgradeToRequestsTableDef},
+       {"research-requests",   &IOTable,       0,                              
        &ResearchRequestsTableDef},
+       {"unit-type-builded",   &IOLinkedList,  &((PlayerAi *) 
0)->UnitTypeBuilded,     &AiBuildQueueStructDef},
+       {"last-repair-building",&IOInt,         &((PlayerAi *) 
0)->LastRepairBuilding,  0},
+       {"tried-repair-worker", &IOIntArray,    &((PlayerAi *) 
0)->TriedRepairWorkers,  (void*)UnitMax},
+       {0, 0, 0, 0}
+    }
 };
 
 /// Description of the PlayerAi structure
-static CclStructDef AiTypeStructDef = {
+static IOStructDef AiTypeStructDef = {
     "AiType",
-    sizeof ( AiType ),
+    sizeof (AiType),
     -1,
     {
-     {"name", &IOString, &( ( AiType * ) 0 )->Name, 0}
-     ,
-     {"race", &IOString, &( ( AiType * ) 0 )->Race, 0}
-     ,
-     {"class", &IOString, &( ( AiType * ) 0 )->Class, 0}
-     ,
-     {"script", &IOCcl, &( ( AiType * ) 0 )->Script, 0}
-     ,
-     {0, 0, 0, 0}
-     }
+       {"name",                &IOString,      &((AiType *) 0)->Name,          
        0},
+       {"race",                &IOString,      &((AiType *) 0)->Race,          
        0},
+       {"class",               &IOString,      &((AiType *) 0)->Class,         
        0},
+       {"script",              &IOCcl,         &((AiType *) 0)->Script,        
        0},
+       {0, 0, 0, 0}
+    }
 };
 
-static CclStructDef AiScriptActionStructDef = {
+static IOStructDef AiScriptActionStructDef = {
     "AiScriptAction",
-    sizeof ( AiScriptAction ),
+    sizeof (AiScriptAction),
     -1,
     {
-     {"action", &IOCcl, &( ( AiScriptAction * ) 0 )->Action, 0}
-     ,
-     {"defensive", &IOBool, &( ( AiScriptAction * ) 0 )->Defensive, 0}
-     ,
-     {"offensive", &IOBool, &( ( AiScriptAction * ) 0 )->Offensive, 0}
-     ,
-     {0, 0, 0, 0}
-     }
+       {"action",              &IOCcl,         &((AiScriptAction *) 
0)->Action,        0},
+       {"defensive",           &IOBool,        &((AiScriptAction *) 
0)->Defensive,     0},
+       {"offensive",           &IOBool,        &((AiScriptAction *) 
0)->Offensive,     0},
+       {0, 0, 0, 0}
+    }
 };
 
 
@@ -372,32 +297,32 @@
 **     @param  binaryform      Pointer to the unit'ref ( AiType ** )
 **     @param  para            unused
 */
-local void IOAiTypePtr( SCM from, void *binaryform, void *para )
+local void IOAiTypePtr(SCM from, void *binaryform, void *para)
 {
     char buffer[512];
     char *str;
     AiType *cur;
 
-    if ( IOHandleNullPtr( from, binaryform ) ) {
+    if (IOHandleNullPtr(from, binaryform)) {
        return;
     }
-    if ( IOLoadingMode ) {
-       str = gh_scm2newstr( from, 0 );
+    if (IOLoadingMode) {
+       str = gh_scm2newstr(from, 0);
        cur = AiTypes;
-       while ( cur ) {
-           snprintf( buffer, 512, "%s-%s-%s", cur->Name, cur->Race, cur->Class 
);
-           if ( !strcmp( str, buffer ) ) {
-               *( ( AiType ** ) binaryform ) = cur;
+       while (cur) {
+           snprintf(buffer, 512, "%s-%s-%s", cur->Name, cur->Race, cur->Class);
+           if (!strcmp(str, buffer)) {
+               *((AiType **) binaryform) = cur;
                return;
            }
            cur = cur->Next;
        }
-       errl( "unknown aitype ", from );
+       errl("unknown aitype ", from);
     } else {
-       cur = *( ( AiType ** ) binaryform );
+       cur = *((AiType **) binaryform);
 
-       snprintf( buffer, 512, "%s-%s-%s", cur->Name, cur->Race, cur->Class );
-       CLprintf( IOOutFile, " \"%s\"", buffer );
+       snprintf(buffer, 512, "%s-%s-%s", cur->Name, cur->Race, cur->Class);
+       CLprintf(IOOutFile, " \"%s\"", buffer);
     }
 }
 
@@ -410,57 +335,57 @@
 **     @param  binaryform      Pointer to the unit'ref ( AiScriptAction ** )
 **     @param  para            unused
 */
-local void IOAiScriptActionPtr( SCM scmfrom, void *binaryform, void *para )
+local void IOAiScriptActionPtr(SCM scmfrom, void *binaryform, void *para)
 {
     int slot;
     AiScriptAction *a;
-    if ( IOHandleNullPtr( scmfrom, binaryform ) ) {
+    if (IOHandleNullPtr(scmfrom, binaryform)) {
        return;
     }
-    if ( IOLoadingMode ) {
-       slot = gh_scm2int( scmfrom );
-       *( ( AiScriptAction ** ) binaryform ) = AiScriptActions + slot;
+    if (IOLoadingMode) {
+       slot = gh_scm2int(scmfrom);
+       *((AiScriptAction **) binaryform) = AiScriptActions + slot;
     } else {
-       a = *( ( AiScriptAction ** ) binaryform );
-       CLprintf( IOOutFile, " %d", a - AiScriptActions );
+       a = *((AiScriptAction **) binaryform);
+       CLprintf(IOOutFile, " %d", a - AiScriptActions);
     }
 }
 
 /// Handle loading an array of int for each ressource ( int[MAX_COSTS] )
-local void IORessourceArray( SCM scmfrom, void *binaryform, void *para )
+local void IORessourceArray(SCM scmfrom, void *binaryform, void *para)
 {
-    IOIntArray( scmfrom, binaryform, ( void * ) MaxCosts );
+    IOIntArray(scmfrom, binaryform, (void *) MaxCosts);
 }
 
 /// Handle loading a mask for each ressource ( int[MAX_COSTS] )
-local void IORessourceMask( SCM scmfrom, void *binaryform, void *para )
+local void IORessourceMask(SCM scmfrom, void *binaryform, void *para)
 {
     int tmp[MaxCosts];
     int mask;
     int i;
 
-    if ( IOLoadingMode ) {
-       IOIntArray( scmfrom, tmp, ( void * ) MaxCosts );
+    if (IOLoadingMode) {
+       IOIntArray(scmfrom, tmp, (void *) MaxCosts);
 
        mask = 0;
-       for ( i = 0; i < MaxCosts; i++ ) {
-           if ( tmp[i] ) {
-               mask |= ( 1 << i );
+       for (i = 0; i < MaxCosts; i++) {
+           if (tmp[i]) {
+               mask |= (1 << i);
            }
        }
 
-       *( int * ) binaryform = mask;
+       *(int *) binaryform = mask;
     } else {
-       mask = *( int * ) binaryform;
-       for ( i = 0; i < MaxCosts; i++ ) {
-           if ( mask & ( 1 << i ) ) {
+       mask = *(int *) binaryform;
+       for (i = 0; i < MaxCosts; i++) {
+           if (mask & (1 << i)) {
                tmp[i] = 1;
            } else {
                tmp[i] = 0;
            }
        }
 
-       IOIntArray( scmfrom, tmp, ( void * ) MaxCosts );
+       IOIntArray(scmfrom, tmp, (void *) MaxCosts);
     }
 }
 
@@ -472,39 +397,39 @@
 **     @param  binaryform      Pointer to the PlayerAi'ref ( PlayerAi ** )
 **     @param  para            unused
 */
-global void IOPlayerAiFullPtr( SCM form, void *binaryform, void *para )
+global void IOPlayerAiFullPtr(SCM form, void *binaryform, void *para)
 {
     AiActionEvaluation *aa;
-    PlayerAi **playerAi = ( PlayerAi ** ) binaryform;
+    PlayerAi **playerAi = (PlayerAi **) binaryform;
 
-    IOStructPtr( form, binaryform, &PlayerAiStructDef );
-    if ( IOLoadingMode && ( *playerAi ) ) {
-       // Finalize the playerAi struct !
-       // => last evaluation, evaluation count
-       aa = ( *playerAi )->FirstEvaluation;
-       while ( aa ) {
-           ( *playerAi )->LastEvaluation = aa;
-           ( *playerAi )->EvaluationCount++;
+    IOStructPtr(form, binaryform, &PlayerAiStructDef);
+    if (IOLoadingMode && (*playerAi)) {
+       // Finalize the playerAi struct !
+       // => last evaluation, evaluation count
+       aa = (*playerAi)->FirstEvaluation;
+       while (aa) {
+           (*playerAi)->LastEvaluation = aa;
+           (*playerAi)->EvaluationCount++;
            aa = aa->Next;
        }
     }
 }
 
-global void IOAiTypeFullPtr( SCM form, void *binaryform, void *para )
+global void IOAiTypeFullPtr(SCM form, void *binaryform, void *para)
 {
-    AiType **aiType = ( AiType ** ) binaryform;
-    IOStructPtr( form, binaryform, &AiTypeStructDef );
-    if ( IOLoadingMode && ( *aiType ) ) {
-       // Append the ai_type...
-       ( *aiType )->Next = AiTypes;
-       AiTypes = ( *aiType );
+    AiType **aiType = (AiType **) binaryform;
+    IOStructPtr(form, binaryform, &AiTypeStructDef);
+    if (IOLoadingMode && (*aiType)) {
+       // Append the ai_type...
+       (*aiType)->Next = AiTypes;
+       AiTypes = (*aiType);
     }
 }
 
-global void IOAiScriptActionFull( SCM form, void *binaryform, void *para )
+global void IOAiScriptActionFull(SCM form, void *binaryform, void *para)
 {
-   /*AiScriptAction * asa = (AiScriptAction*) binaryform; */
-    IOStruct( form, binaryform, &AiScriptActionStructDef );
+    /*AiScriptAction * asa = (AiScriptAction*) binaryform; */
+    IOStruct(form, binaryform, &AiScriptActionStructDef);
 }
 
 
@@ -512,34 +437,34 @@
 
 #ifdef INCOMPLETE_SIOD
 
-local SCM CclQuotient( SCM a, SCM b )
+local SCM CclQuotient(SCM a, SCM b)
 {
     int va, vb;
-    va = gh_scm2int( a );
-    vb = gh_scm2int( b );
-    if ( vb == 0 ) {
-       errl( "CclQuotient division by zero", b );
+    va = gh_scm2int(a);
+    vb = gh_scm2int(b);
+    if (vb == 0) {
+       errl("CclQuotient division by zero", b);
     }
-    return gh_int2scm( va / vb );
+    return gh_int2scm(va / vb);
 }
 
-local SCM CclOutput( SCM x )
+local SCM CclOutput(SCM x)
 {
-    if ( gh_null_p( x ) ) {
-       printf( " '()" );
+    if (gh_null_p(x)) {
+       printf(" '()");
        return SCM_BOOL_T;
     }
-    if ( gh_list_p( x ) ) {
-       printf( " (" );
-       while ( !gh_null_p( x ) ) {
-           CclOutput( gh_car( x ) );
-           x = gh_cdr( x );
+    if (gh_list_p(x)) {
+       printf(" (");
+       while (!gh_null_p(x)) {
+           CclOutput(gh_car(x));
+           x = gh_cdr(x);
        }
-       printf( " )" );
+       printf(" )");
        return SCM_BOOL_T;
     }
-    printf( " " );
-    gh_display( x );
+    printf(" ");
+    gh_display(x);
     return x;
 }
 
@@ -555,18 +480,18 @@
 **     @param table    Pointer to table with elements.
 **     @param n        Index to insert new into table
 */
-local void AiHelperSetupTable( int *count, AiUnitTypeTable *** table, int n )
+local void AiHelperSetupTable(int *count, AiUnitTypeTable *** table, int n)
 {
     int i;
 
     ++n;
-    if ( n > ( i = *count ) ) {
-       if ( *table ) {
-           *table = realloc( *table, n * sizeof ( AiUnitTypeTable * ) );
-           memset( ( *table ) + i, 0, ( n - i ) * sizeof ( AiUnitTypeTable * ) 
);
+    if (n > (i = *count)) {
+       if (*table) {
+           *table = realloc(*table, n * sizeof (AiUnitTypeTable *));
+           memset((*table) + i, 0, (n - i) * sizeof (AiUnitTypeTable *));
        } else {
-           *table = malloc( n * sizeof ( AiUnitTypeTable * ) );
-           memset( *table, 0, n * sizeof ( AiUnitTypeTable * ) );
+           *table = malloc(n * sizeof (AiUnitTypeTable *));
+           memset(*table, 0, n * sizeof (AiUnitTypeTable *));
        }
        *count = n;
     }
@@ -578,35 +503,35 @@
 **     @param tablep   Pointer to table with elements.
 **     @param base     Base type to insert into table.
 */
-local void AiHelperInsert( AiUnitTypeTable ** tablep, UnitType * base )
+local void AiHelperInsert(AiUnitTypeTable ** tablep, UnitType * base)
 {
     int i;
     int n;
     AiUnitTypeTable *table;
 
-   //
-   //  New unit-type
-   //
-    if ( !( table = *tablep ) ) {
-       table = *tablep = malloc( sizeof ( AiUnitTypeTable ) );
+    //
+    //  New unit-type
+    //
+    if (!(table = *tablep)) {
+       table = *tablep = malloc(sizeof (AiUnitTypeTable));
        table->Count = 1;
        table->Table[0] = base;
        return;
     }
-   //
-   //  Look if already known.
-   //
+    //
+    //  Look if already known.
+    //
     n = table->Count;
-    for ( i = 0; i < n; ++i ) {
-       if ( table->Table[i] == base ) {
+    for (i = 0; i < n; ++i) {
+       if (table->Table[i] == base) {
            return;
        }
     }
 
-   //
-   //  Append new base unit-type to units.
-   //
-    table = *tablep = realloc( table, sizeof ( AiUnitTypeTable ) + sizeof ( 
UnitType * ) * n );
+    //
+    //  Append new base unit-type to units.
+    //
+    table = *tablep = realloc(table, sizeof (AiUnitTypeTable) + sizeof 
(UnitType *) * n);
     table->Count = n + 1;
     table->Table[n] = base;
 }
@@ -615,7 +540,7 @@
 /**
 **     Print AI helper table.
 */
-local void PrintAiHelperTable( void )
+local void PrintAiHelperTable(void)
 {
 }
 #endif
@@ -627,7 +552,7 @@
 **
 **     @todo   FIXME: the first unit could be a list see ../doc/ccl/ai.html
 */
-local SCM CclDefineAiHelper( SCM list )
+local SCM CclDefineAiHelper(SCM list)
 {
     SCM sub_list;
     SCM value;
@@ -638,117 +563,126 @@
     Upgrade *upgrade;
     int cost;
 
-    IfDebug( type = NULL; upgrade = NULL; cost = 0; ); // keep the compiler 
happy
-    while ( !gh_null_p( list ) ) {
-       sub_list = gh_car( list );
-       list = gh_cdr( list );
-
-       //
-       //      Type build,train,research/upgrade.
-       //
-       value = gh_car( sub_list );
-       sub_list = gh_cdr( sub_list );
-       if ( gh_eq_p( value, gh_symbol2scm( "build" ) ) ) {
+    IfDebug(type = NULL;
+       upgrade = NULL;
+       cost = 0;
+       );                              // keep the compiler happy
+    while (!gh_null_p(list)) {
+       sub_list = gh_car(list);
+       list = gh_cdr(list);
+
+       //
+       //      Type build,train,research/upgrade.
+       //
+       value = gh_car(sub_list);
+       sub_list = gh_cdr(sub_list);
+       if (gh_eq_p(value, gh_symbol2scm("build"))) {
            what = 0;
-       } else if ( gh_eq_p( value, gh_symbol2scm( "train" ) ) ) {
+       } else if (gh_eq_p(value, gh_symbol2scm("train"))) {
            what = 1;
-       } else if ( gh_eq_p( value, gh_symbol2scm( "upgrade" ) ) ) {
+       } else if (gh_eq_p(value, gh_symbol2scm("upgrade"))) {
            what = 2;
-       } else if ( gh_eq_p( value, gh_symbol2scm( "research" ) ) ) {
+       } else if (gh_eq_p(value, gh_symbol2scm("research"))) {
            what = 3;
-       } else if ( gh_eq_p( value, gh_symbol2scm( "unit-limit" ) ) ) {
+       } else if (gh_eq_p(value, gh_symbol2scm("unit-limit"))) {
            what = 4;
-       } else if ( gh_eq_p( value, gh_symbol2scm( "unit-equiv" ) ) ) {
+       } else if (gh_eq_p(value, gh_symbol2scm("unit-equiv"))) {
            what = 5;
-       } else if ( gh_eq_p( value, gh_symbol2scm( "repair" ) ) ) {
+       } else if (gh_eq_p(value, gh_symbol2scm("repair"))) {
            what = 6;
        } else {
-           fprintf( stderr, "unknown tag\n" );
+           fprintf(stderr, "unknown tag\n");
            continue;
        }
 
-       //
-       //      Get the base unit type, which could handle the action.
-       //
-       value = gh_car( sub_list );
-       sub_list = gh_cdr( sub_list );
-
-       // FIXME: support value as list!
-       str = gh_scm2newstr( value, NULL );
-       base = UnitTypeByIdent( str );
-       if ( !base ) {
-           fprintf( stderr, "unknown unittype %s\n", str );
-           free( str );
+       //
+       //      Get the base unit type, which could handle the action.
+       //
+       value = gh_car(sub_list);
+       sub_list = gh_cdr(sub_list);
+
+       // FIXME: support value as list!
+       str = gh_scm2newstr(value, NULL);
+       base = UnitTypeByIdent(str);
+       if (!base) {
+           fprintf(stderr, "unknown unittype %s\n", str);
+           free(str);
            continue;
        }
-       DebugLevel3Fn( "%s\n" _C_ base->Name );
-       free( str );
+       DebugLevel3Fn("%s\n" _C_ base->Name);
+       free(str);
 
-       //
-       //      Get the unit types, which could be produced
-       //
-       while ( !gh_null_p( sub_list ) ) {
-           value = gh_car( sub_list );
-           sub_list = gh_cdr( sub_list );
-           str = gh_scm2newstr( value, NULL );
-           if ( what == 3 ) {
-               upgrade = UpgradeByIdent( str );
-               if ( !upgrade ) {
-                   fprintf( stderr, "unknown upgrade %s\n", str );
-                   free( str );
+       //
+       //      Get the unit types, which could be produced
+       //
+       while (!gh_null_p(sub_list)) {
+           value = gh_car(sub_list);
+           sub_list = gh_cdr(sub_list);
+           str = gh_scm2newstr(value, NULL);
+           if (what == 3) {
+               upgrade = UpgradeByIdent(str);
+               if (!upgrade) {
+                   fprintf(stderr, "unknown upgrade %s\n", str);
+                   free(str);
                    continue;
                }
-               DebugLevel3Fn( "> %s\n" _C_ upgrade->Ident );
-           } else if ( what == 4 ) {
-               if ( !strcmp( "food", str ) ) {
+               DebugLevel3Fn("> %s\n" _C_ upgrade->Ident);
+           } else if (what == 4) {
+               if (!strcmp("food", str)) {
                    cost = 0;
                } else {
-                   fprintf( stderr, "unknown limit %s\n", str );
-                   free( str );
+                   fprintf(stderr, "unknown limit %s\n", str);
+                   free(str);
                    continue;
                }
-               DebugLevel3Fn( "> %s\n" _C_ str );
+               DebugLevel3Fn("> %s\n" _C_ str);
            } else {
-               type = UnitTypeByIdent( str );
-               if ( !type ) {
-                   fprintf( stderr, "unknown unittype %s\n", str );
-                   free( str );
+               type = UnitTypeByIdent(str);
+               if (!type) {
+                   fprintf(stderr, "unknown unittype %s\n", str);
+                   free(str);
                    continue;
                }
-               DebugLevel3Fn( "> %s\n" _C_ type->Name );
+               DebugLevel3Fn("> %s\n" _C_ type->Name);
            }
-           free( str );
+           free(str);
 
-           switch ( what ) {
-           case 0:             // build
-               AiHelperSetupTable( &AiHelpers.BuildCount, &AiHelpers.Build, 
type->Type );
-               AiHelperInsert( AiHelpers.Build + type->Type, base );
-               break;
-           case 1:             // train
-               AiHelperSetupTable( &AiHelpers.TrainCount, &AiHelpers.Train, 
type->Type );
-               AiHelperInsert( AiHelpers.Train + type->Type, base );
-               break;
-           case 2:             // upgrade
-               AiHelperSetupTable( &AiHelpers.UpgradeCount, 
&AiHelpers.Upgrade, type->Type );
-               AiHelperInsert( AiHelpers.Upgrade + type->Type, base );
-               break;
-           case 3:             // research
-               AiHelperSetupTable( &AiHelpers.ResearchCount, 
&AiHelpers.Research,
-                                   upgrade - Upgrades );
-               AiHelperInsert( AiHelpers.Research + ( upgrade - Upgrades ), 
base );
-               break;
-           case 4:             // unit-limit
-               AiHelperSetupTable( &AiHelpers.UnitLimitCount, 
&AiHelpers.UnitLimit, cost );
-               AiHelperInsert( AiHelpers.UnitLimit + cost, base );
-               break;
-           case 5:             // equivalence
-               AiHelperSetupTable( &AiHelpers.EquivCount, &AiHelpers.Equiv, 
base->Type );
-               AiHelperInsert( AiHelpers.Equiv + base->Type, type );
-               break;
-           case 6:             // repair
-               AiHelperSetupTable( &AiHelpers.RepairCount, &AiHelpers.Repair, 
type->Type );
-               AiHelperInsert( AiHelpers.Repair + type->Type, base );
-               break;
+           switch (what) {
+               case 0:         // build
+                   AiHelperSetupTable(&AiHelpers.BuildCount, &AiHelpers.Build,
+                       type->Type);
+                   AiHelperInsert(AiHelpers.Build + type->Type, base);
+                   break;
+               case 1:         // train
+                   AiHelperSetupTable(&AiHelpers.TrainCount, &AiHelpers.Train,
+                       type->Type);
+                   AiHelperInsert(AiHelpers.Train + type->Type, base);
+                   break;
+               case 2:         // upgrade
+                   AiHelperSetupTable(&AiHelpers.UpgradeCount, 
&AiHelpers.Upgrade,
+                       type->Type);
+                   AiHelperInsert(AiHelpers.Upgrade + type->Type, base);
+                   break;
+               case 3:         // research
+                   AiHelperSetupTable(&AiHelpers.ResearchCount, 
&AiHelpers.Research,
+                       upgrade - Upgrades);
+                   AiHelperInsert(AiHelpers.Research + (upgrade - Upgrades), 
base);
+                   break;
+               case 4:         // unit-limit
+                   AiHelperSetupTable(&AiHelpers.UnitLimitCount, 
&AiHelpers.UnitLimit,
+                       cost);
+                   AiHelperInsert(AiHelpers.UnitLimit + cost, base);
+                   break;
+               case 5:         // equivalence
+                   AiHelperSetupTable(&AiHelpers.EquivCount, &AiHelpers.Equiv,
+                       base->Type);
+                   AiHelperInsert(AiHelpers.Equiv + base->Type, type);
+                   break;
+               case 6:         // repair
+                   AiHelperSetupTable(&AiHelpers.RepairCount, 
&AiHelpers.Repair,
+                       type->Type);
+                   AiHelperInsert(AiHelpers.Repair + type->Type, base);
+                   break;
            }
        }
     }
@@ -756,26 +690,26 @@
     return list;
 }
 
-local SCM CclDefineAiAction( SCM type, SCM definition )
+local SCM CclDefineAiAction(SCM type, SCM definition)
 {
     AiScriptAction *aiScriptAction;
 
     aiScriptAction = AiScriptActions + AiScriptActionNum;
     AiScriptActionNum++;
 
-    memset( aiScriptAction, 0, sizeof ( AiScriptAction ) );
+    memset(aiScriptAction, 0, sizeof (AiScriptAction));
 
     aiScriptAction->Action = definition;
-    CclGcProtect( aiScriptAction->Action );
+    CclGcProtect(aiScriptAction->Action);
 
-    while ( !gh_null_p( type ) ) {
-       if ( gh_eq_p( gh_car( type ), gh_symbol2scm( "defense" ) ) ) {
+    while (!gh_null_p(type)) {
+       if (gh_eq_p(gh_car(type), gh_symbol2scm("defense"))) {
            aiScriptAction->Defensive = 1;
        }
-       if ( gh_eq_p( gh_car( type ), gh_symbol2scm( "attack" ) ) ) {
+       if (gh_eq_p(gh_car(type), gh_symbol2scm("attack"))) {
            aiScriptAction->Offensive = 1;
        }
-       type = gh_cdr( type );
+       type = gh_cdr(type);
     }
 
     return SCM_UNSPECIFIED;
@@ -784,7 +718,7 @@
 /**
 **     Define an AI engine.
 */
-local SCM CclDefineAi( SCM list )
+local SCM CclDefineAi(SCM list)
 {
     SCM value;
     char *str;
@@ -793,59 +727,60 @@
     const AiType *ait;
 #endif
 
-    aitype = malloc( sizeof ( AiType ) );
+    aitype = malloc(sizeof (AiType));
     aitype->Next = AiTypes;
     AiTypes = aitype;
 
-   //
-   //  AI Name
-   //
-    value = gh_car( list );
-    list = gh_cdr( list );
-    str = gh_scm2newstr( value, NULL );
-    DebugLevel3Fn( "%s\n" _C_ str );
+    //
+    //  AI Name
+    //
+    value = gh_car(list);
+    list = gh_cdr(list);
+    str = gh_scm2newstr(value, NULL);
+    DebugLevel3Fn("%s\n" _C_ str);
     aitype->Name = str;
 
 #ifdef DEBUG
-    for ( ait = AiTypes->Next; ait; ait = ait->Next ) {
-       if ( !strcmp( aitype->Name, ait->Name ) ) {
-           DebugLevel0Fn( "Warning two or more AI's with the same name '%s'\n" 
_C_ ait->Name );
+    for (ait = AiTypes->Next; ait; ait = ait->Next) {
+       if (!strcmp(aitype->Name, ait->Name)) {
+           DebugLevel0Fn("Warning two or more AI's with the same name '%s'\n" 
_C_ ait->
+               Name);
        }
     }
 #endif
 
-   //
-   //  AI Race
-   //
-    value = gh_car( list );
-    list = gh_cdr( list );
-    str = gh_scm2newstr( value, NULL );
-    DebugLevel3Fn( "%s\n" _C_ str );
-    if ( *str != '*' ) {
+    //
+    //  AI Race
+    //
+    value = gh_car(list);
+    list = gh_cdr(list);
+    str = gh_scm2newstr(value, NULL);
+    DebugLevel3Fn("%s\n" _C_ str);
+    if (*str != '*') {
        aitype->Race = str;
     } else {
        aitype->Race = NULL;
-       free( str );
+       free(str);
     }
 
-   //
-   //  AI Class
-   //
-    value = gh_car( list );
-    list = gh_cdr( list );
-    str = gh_scm2newstr( value, NULL );
-    DebugLevel3Fn( "%s\n" _C_ str );
+    //
+    //  AI Class
+    //
+    value = gh_car(list);
+    list = gh_cdr(list);
+    str = gh_scm2newstr(value, NULL);
+    DebugLevel3Fn("%s\n" _C_ str);
     aitype->Class = str;
 
-   //
-   //  AI Script
-   //
-    value = gh_car( list );
-    list = gh_cdr( list );
+    //
+    //  AI Script
+    //
+    value = gh_car(list);
+    list = gh_cdr(list);
     aitype->Script = value;
 
-   // Protect the scheme script against GC garbage-collect.
-    CclGcProtect( value );
+    // Protect the scheme script against GC garbage-collect.
+    CclGcProtect(value);
 
     return list;
 }
@@ -855,7 +790,7 @@
 ----------------------------------------------------------------------------*/
 
     /// Get unit-type.
-extern UnitType *CclGetUnitType( SCM ptr );
+extern UnitType *CclGetUnitType(SCM ptr);
 
 /**
 **     Append unit-type to request table.
@@ -863,17 +798,16 @@
 **     @param type     Unit-type to be appended.
 **     @param count    How many unit-types to build.
 */
-local void InsertUnitTypeRequests( UnitType * type, int count )
+local void InsertUnitTypeRequests(UnitType * type, int count)
 {
     int n;
 
-    if ( AiPlayer->UnitTypeRequests ) {
+    if (AiPlayer->UnitTypeRequests) {
        n = AiPlayer->UnitTypeRequestsCount;
-       AiPlayer->UnitTypeRequests = realloc( AiPlayer->UnitTypeRequests,
-                                             ( n +
-                                               1 ) * sizeof ( 
*AiPlayer->UnitTypeRequests ) );
+       AiPlayer->UnitTypeRequests = realloc(AiPlayer->UnitTypeRequests,
+           (n + 1) * sizeof (*AiPlayer->UnitTypeRequests));
     } else {
-       AiPlayer->UnitTypeRequests = malloc( sizeof ( 
*AiPlayer->UnitTypeRequests ) );
+       AiPlayer->UnitTypeRequests = malloc(sizeof 
(*AiPlayer->UnitTypeRequests));
        n = 0;
     }
     AiPlayer->UnitTypeRequests[n].Table[0] = type;
@@ -886,14 +820,14 @@
 **
 **     @param type     Unit-type to be found.
 */
-local AiUnitTypeTable *FindInUnitTypeRequests( const UnitType * type )
+local AiUnitTypeTable *FindInUnitTypeRequests(const UnitType * type)
 {
     int i;
     int n;
 
     n = AiPlayer->UnitTypeRequestsCount;
-    for ( i = 0; i < n; ++i ) {
-       if ( AiPlayer->UnitTypeRequests[i].Table[0] == type ) {
+    for (i = 0; i < n; ++i) {
+       if (AiPlayer->UnitTypeRequests[i].Table[0] == type) {
            return &AiPlayer->UnitTypeRequests[i];
        }
     }
@@ -905,14 +839,14 @@
 **
 **     @param type     Unit-type to be found.
 */
-local int FindInUpgradeToRequests( const UnitType * type )
+local int FindInUpgradeToRequests(const UnitType * type)
 {
     int i;
     int n;
 
     n = AiPlayer->UnitTypeRequestsCount;
-    for ( i = 0; i < n; ++i ) {
-       if ( AiPlayer->UpgradeToRequests[i] == type ) {
+    for (i = 0; i < n; ++i) {
+       if (AiPlayer->UpgradeToRequests[i] == type) {
            return 1;
        }
     }
@@ -924,18 +858,16 @@
 **
 **     @param type     Unit-type to be appended.
 */
-local void InsertUpgradeToRequests( UnitType * type )
+local void InsertUpgradeToRequests(UnitType * type)
 {
     int n;
 
-    if ( AiPlayer->UpgradeToRequests ) {
+    if (AiPlayer->UpgradeToRequests) {
        n = AiPlayer->UpgradeToRequestsCount;
-       AiPlayer->UpgradeToRequests = realloc( AiPlayer->UpgradeToRequests,
-                                              ( n +
-                                                1 ) *
-                                              sizeof ( 
*AiPlayer->UpgradeToRequests ) );
+       AiPlayer->UpgradeToRequests = realloc(AiPlayer->UpgradeToRequests,
+           (n + 1) * sizeof (*AiPlayer->UpgradeToRequests));
     } else {
-       AiPlayer->UpgradeToRequests = malloc( sizeof ( 
*AiPlayer->UpgradeToRequests ) );
+       AiPlayer->UpgradeToRequests = malloc(sizeof 
(*AiPlayer->UpgradeToRequests));
        n = 0;
     }
     AiPlayer->UpgradeToRequests[n] = type;
@@ -947,17 +879,16 @@
 **
 **     @param upgrade  Upgrade to be appended.
 */
-local void InsertResearchRequests( Upgrade * upgrade )
+local void InsertResearchRequests(Upgrade * upgrade)
 {
     int n;
 
-    if ( AiPlayer->ResearchRequests ) {
+    if (AiPlayer->ResearchRequests) {
        n = AiPlayer->ResearchRequestsCount;
-       AiPlayer->ResearchRequests = realloc( AiPlayer->ResearchRequests,
-                                             ( n +
-                                               1 ) * sizeof ( 
*AiPlayer->ResearchRequests ) );
+       AiPlayer->ResearchRequests = realloc(AiPlayer->ResearchRequests,
+           (n + 1) * sizeof (*AiPlayer->ResearchRequests));
     } else {
-       AiPlayer->ResearchRequests = malloc( sizeof ( 
*AiPlayer->ResearchRequests ) );
+       AiPlayer->ResearchRequests = malloc(sizeof 
(*AiPlayer->ResearchRequests));
        n = 0;
     }
     AiPlayer->ResearchRequests[n] = upgrade;
@@ -969,17 +900,17 @@
 /**
 **     Get the race of the current AI player.
 */
-local SCM CclAiGetRace( void )
+local SCM CclAiGetRace(void)
 {
-    return gh_symbol2scm( AiPlayer->Player->RaceName );
+    return gh_symbol2scm(AiPlayer->Player->RaceName);
 }
 
 /**
 **     Get the number of cycles to sleep.
 */
-local SCM CclAiGetSleepCycles( void )
+local SCM CclAiGetSleepCycles(void)
 {
-    return gh_int2scm( AiSleepCycles );
+    return gh_int2scm(AiSleepCycles);
 }
 
 //----------------------------------------------------------------------------
@@ -987,9 +918,9 @@
 /**
 **     Set debuging flag of AI script.
 */
-local SCM CclAiDebug( SCM flag )
+local SCM CclAiDebug(SCM flag)
 {
-    if ( gh_eq_p( flag, SCM_BOOL_F ) ) {
+    if (gh_eq_p(flag, SCM_BOOL_F)) {
        AiPlayer->ScriptDebug = 0;
     } else {
        AiPlayer->ScriptDebug = 1;
@@ -1002,9 +933,9 @@
 **
 **     @param value    Unit-type as string/symbol/object.
 */
-local SCM CclAiNeed( SCM value )
+local SCM CclAiNeed(SCM value)
 {
-    InsertUnitTypeRequests( CclGetUnitType( value ), 1 );
+    InsertUnitTypeRequests(CclGetUnitType(value), 1);
 
     return SCM_BOOL_F;
 }
@@ -1017,17 +948,17 @@
 **
 **     @todo FIXME:    count==0 should remove the request.
 */
-local SCM CclAiSet( SCM value, SCM count )
+local SCM CclAiSet(SCM value, SCM count)
 {
     AiUnitTypeTable *autt;
     UnitType *type;
 
-    type = CclGetUnitType( value );
-    if ( ( autt = FindInUnitTypeRequests( type ) ) ) {
-       autt->Count = gh_scm2int( count );
-       // FIXME: 0 should remove it.
+    type = CclGetUnitType(value);
+    if ((autt = FindInUnitTypeRequests(type))) {
+       autt->Count = gh_scm2int(count);
+       // FIXME: 0 should remove it.
     } else {
-       InsertUnitTypeRequests( type, gh_scm2int( count ) );
+       InsertUnitTypeRequests(type, gh_scm2int(count));
     }
 
     return SCM_BOOL_F;
@@ -1038,7 +969,7 @@
 **
 **     @param value    Unit-type as string/symbol/object.
 */
-local SCM CclAiWait( SCM value )
+local SCM CclAiWait(SCM value)
 {
     const AiUnitTypeTable *autt;
     const UnitType *type;
@@ -1046,48 +977,48 @@
     int j;
     int n;
 
-    type = CclGetUnitType( value );
+    type = CclGetUnitType(value);
     unit_types_count = AiPlayer->Player->UnitTypesCount;
-    if ( !( autt = FindInUnitTypeRequests( type ) ) ) {
-       //
-       //      Look if we have this unit-type.
-       //
-       if ( unit_types_count[type->Type] ) {
+    if (!(autt = FindInUnitTypeRequests(type))) {
+       //
+       //      Look if we have this unit-type.
+       //
+       if (unit_types_count[type->Type]) {
            return SCM_BOOL_F;
        }
-       //
-       //      Look if we have equivalent unit-types.
-       //
-       if ( type->Type < AiHelpers.EquivCount && AiHelpers.Equiv[type->Type] ) 
{
-           DebugLevel3Fn( "Equivalence for %s\n" _C_ type->Ident );
-           for ( j = 0; j < AiHelpers.Equiv[type->Type]->Count; ++j ) {
-               if ( 
unit_types_count[AiHelpers.Equiv[type->Type]->Table[j]->Type] ) {
+       //
+       //      Look if we have equivalent unit-types.
+       //
+       if (type->Type < AiHelpers.EquivCount && AiHelpers.Equiv[type->Type]) {
+           DebugLevel3Fn("Equivalence for %s\n" _C_ type->Ident);
+           for (j = 0; j < AiHelpers.Equiv[type->Type]->Count; ++j) {
+               if 
(unit_types_count[AiHelpers.Equiv[type->Type]->Table[j]->Type]) {
                    return SCM_BOOL_F;
                }
            }
        }
-       //
-       //      Look if we have an upgrade-to request.
-       //
-       if ( FindInUpgradeToRequests( type ) ) {
+       //
+       //      Look if we have an upgrade-to request.
+       //
+       if (FindInUpgradeToRequests(type)) {
            return SCM_BOOL_T;
        }
-       DebugLevel0Fn( "Broken? waiting on %s which wasn't requested.\n" _C_ 
type->Ident );
+       DebugLevel0Fn("Broken? waiting on %s which wasn't requested.\n" _C_ 
type->Ident);
        return SCM_BOOL_F;
     }
-   //
-   //  Add equivalent units
-   //
+    //
+    //  Add equivalent units
+    //
     n = unit_types_count[type->Type];
-    if ( type->Type < AiHelpers.EquivCount && AiHelpers.Equiv[type->Type] ) {
-       for ( j = 0; j < AiHelpers.Equiv[type->Type]->Count; ++j ) {
+    if (type->Type < AiHelpers.EquivCount && AiHelpers.Equiv[type->Type]) {
+       for (j = 0; j < AiHelpers.Equiv[type->Type]->Count; ++j) {
            n += unit_types_count[AiHelpers.Equiv[type->Type]->Table[j]->Type];
        }
     }
-   // units available?
-    DebugLevel3Fn( "%d,%d\n" _C_ n _C_ autt->Count );
+    // units available?
+    DebugLevel3Fn("%d,%d\n" _C_ n _C_ autt->Count);
 
-    if ( n >= autt->Count ) {
+    if (n >= autt->Count) {
        return SCM_BOOL_F;
     }
 
@@ -1100,7 +1031,7 @@
 */
 local SCM CclAiOwnForce(void)
 {
-    return gh_int2scm( AiScript->ownForce );
+    return gh_int2scm(AiScript->ownForce);
 }
 
 /**
@@ -1108,15 +1039,15 @@
 **
 **     @param s_force  Force to free.
 */
-local SCM CclAiClearForce( SCM s_force )
+local SCM CclAiClearForce(SCM s_force)
 {
     int force;
 /*    AiUnitType * aiut,*next;
     AiUnit *aiu,*next_u;
 */
-    force = gh_scm2int( s_force );
-    if ( force < 0 || force >= AI_MAX_FORCES ) {
-       errl( "Force out of range", s_force );
+    force = gh_scm2int(s_force);
+    if (force < 0 || force >= AI_MAX_FORCES) {
+       errl("Force out of range", s_force);
     }
 /*
     aiut=AiPlayer->Force[force].UnitTypes;
@@ -1137,29 +1068,29 @@
     
     AiAssignFreeUnitsToForce();
     */
-    AiEraseForce( force );
+    AiEraseForce(force);
     return SCM_BOOL_F;
 
 }
 
-local SCM CclAiGetForce( SCM list )
+local SCM CclAiGetForce(SCM list)
 {
     int force;
     SCM rslt;
     AiUnitType *aiut;
 
-    force = gh_scm2int( list );
-    if ( force < 0 || force >= AI_MAX_FORCES ) {
-       errl( "Force out of range", list );
+    force = gh_scm2int(list);
+    if (force < 0 || force >= AI_MAX_FORCES) {
+       errl("Force out of range", list);
     }
     rslt = SCM_UNSPECIFIED;
     aiut = AiPlayer->Force[force].UnitTypes;
-    while ( aiut ) {
+    while (aiut) {
        rslt =
-           cons( gh_symbol2scm( aiut->Type->Ident ), cons( gh_int2scm( 
aiut->Want ), rslt ) );
+           cons(gh_symbol2scm(aiut->Type->Ident), cons(gh_int2scm(aiut->Want), 
rslt));
        aiut = aiut->Next;
     }
-    CclOutput( rslt );
+    CclOutput(rslt);
     return rslt;
 }
 
@@ -1168,23 +1099,23 @@
 **
 **
 */
-local SCM CclAiForceEmpty( SCM list )
+local SCM CclAiForceEmpty(SCM list)
 {
     int force;
 
-    force = gh_scm2int( list );
-    if ( force < 0 || force >= AI_MAX_FORCES ) {
-       errl( "Force out of range", list );
+    force = gh_scm2int(list);
+    if (force < 0 || force >= AI_MAX_FORCES) {
+       errl("Force out of range", list);
     }
 
-    if ( AiPlayer->Force[force].Units ) {
+    if (AiPlayer->Force[force].Units) {
        return SCM_BOOL_F;
     } else {
        return SCM_BOOL_T;
     }
 }
 
-local SCM CclAiAdHocForce( SCM requirement, SCM scm_unittypes )
+local SCM CclAiAdHocForce(SCM requirement, SCM scm_unittypes)
 {
     int want[3];
     int *unittypes;
@@ -1194,59 +1125,59 @@
     int i;
     int rslt;
 
-    for ( i = 0; i < 3; i++ ) {
-       want[i] = gh_scm2int( gh_car( requirement ) );
-       requirement = gh_cdr( requirement );
+    for (i = 0; i < 3; i++) {
+       want[i] = gh_scm2int(gh_car(requirement));
+       requirement = gh_cdr(requirement);
     }
 
-    unittypecount = gh_length( scm_unittypes );
-    if ( unittypecount ) {
-       unittypes = ( int * ) malloc( sizeof ( int ) * unittypecount );
+    unittypecount = gh_length(scm_unittypes);
+    if (unittypecount) {
+       unittypes = (int *) malloc(sizeof (int) * unittypecount);
 
-       for ( i = 0; i < unittypecount; i++ ) {
+       for (i = 0; i < unittypecount; i++) {
 
-           str = gh_scm2newstr( gh_car( scm_unittypes ), NULL );
-           scm_unittypes = gh_cdr( scm_unittypes );
+           str = gh_scm2newstr(gh_car(scm_unittypes), NULL);
+           scm_unittypes = gh_cdr(scm_unittypes);
 
 
-           unittype = UnitTypeByIdent( str );
-           if ( !unittype ) {
-               fprintf( stderr, "unknown unittype %s\n", str );
-               free( str );
+           unittype = UnitTypeByIdent(str);
+           if (!unittype) {
+               fprintf(stderr, "unknown unittype %s\n", str);
+               free(str);
                i--;
                unittypecount--;
                continue;
 
            }
-           free( str );
+           free(str);
 
            unittypes[i] = unittype->Type;
        }
     } else {
        unittypes = 0;
     }
-    rslt = AiCreateSpecificForce( want, unittypes, unittypecount );
-    if ( unittypes ) {
-       free( unittypes );
+    rslt = AiCreateSpecificForce(want, unittypes, unittypecount);
+    if (unittypes) {
+       free(unittypes);
     }
 
-    if ( rslt != -1 ) {
+    if (rslt != -1) {
        return SCM_BOOL_T;
     } else {
        return SCM_BOOL_F;
     }
 }
 
-local SCM CclAiForceActive( SCM list )
+local SCM CclAiForceActive(SCM list)
 {
     int force;
 
-    force = gh_scm2int( list );
-    if ( force < 0 || force >= AI_MAX_FORCES ) {
-       errl( "Force out of range", list );
+    force = gh_scm2int(list);
+    if (force < 0 || force >= AI_MAX_FORCES) {
+       errl("Force out of range", list);
     }
 
-    if ( AiPlayer->Force[force].Attacking ) {
+    if (AiPlayer->Force[force].Attacking) {
        return SCM_BOOL_T;
     } else {
        return SCM_BOOL_F;
@@ -1259,7 +1190,7 @@
 **
 **     @param list     Pairs of unit-types and counts.
 */
-local SCM CclAiForce( SCM list )
+local SCM CclAiForce(SCM list)
 {
     AiUnitType **prev;
     AiUnitType *aiut;
@@ -1267,46 +1198,47 @@
     int count;
     int force;
 
-    force = gh_scm2int( gh_car( list ) );
-    if ( force < 0 || force >= AI_MAX_FORCES ) {
-       errl( "Force out of range", gh_car( list ) );
-    }
-    list = gh_cdr( list );
-
-    while ( !gh_null_p( list ) ) {
-       type = CclGetUnitType( gh_car( list ) );
-       list = gh_cdr( list );
-       count = gh_scm2int( gh_car( list ) );
-       list = gh_cdr( list );
+    force = gh_scm2int(gh_car(list));
+    if (force < 0 || force >= AI_MAX_FORCES) {
+       errl("Force out of range", gh_car(list));
+    }
+    list = gh_cdr(list);
+
+    while (!gh_null_p(list)) {
+       type = CclGetUnitType(gh_car(list));
+       list = gh_cdr(list);
+       count = gh_scm2int(gh_car(list));
+       list = gh_cdr(list);
 
-       if ( !type ) {          // bulletproof
+       if (!type) {                    // bulletproof
            continue;
        }
-       if ( !count ) {         // Don't care
+       if (!count) {                   // Don't care
            continue;
        }
-       //
-       //      Look if already in force.
-       //
-       for ( prev = &AiPlayer->Force[force].UnitTypes; ( aiut = *prev ); prev 
= &aiut->Next ) {
-           if ( aiut->Type == type ) { // found
-               if ( aiut->Want < count ) {
+       //
+       //      Look if already in force.
+       //
+       for (prev = &AiPlayer->Force[force].UnitTypes; (aiut = *prev);
+           prev = &aiut->Next) {
+           if (aiut->Type == type) {   // found
+               if (aiut->Want < count) {
                    aiut->Want = count;
                }
 
-               if ( !aiut->Want ) {
+               if (!aiut->Want) {
                    *prev = aiut->Next;
-                   free( aiut );
+                   free(aiut);
                }
                break;
            }
        }
 
-       //
-       //      New type append it.
-       //
-       if ( !aiut ) {
-           *prev = aiut = malloc( sizeof ( *aiut ) );
+       //
+       //      New type append it.
+       //
+       if (!aiut) {
+           *prev = aiut = malloc(sizeof (*aiut));
            aiut->Next = NULL;
            aiut->Want = count;
            aiut->Type = type;
@@ -1318,13 +1250,13 @@
     return SCM_BOOL_F;
 }
 
-local SCM CclAiForceTransfert( SCM sourceForce, SCM destForce )
+local SCM CclAiForceTransfert(SCM sourceForce, SCM destForce)
 {
     int src, dst;
 
-    src = gh_scm2int( sourceForce );
-    dst = gh_scm2int( destForce );
-    AiForceTransfert( src, dst );
+    src = gh_scm2int(sourceForce);
+    dst = gh_scm2int(destForce);
+    AiForceTransfert(src, dst);
     return SCM_BOOL_F;
 }
 
@@ -1334,12 +1266,12 @@
 **
 **     @param destForce        the force to complete
 */
-local SCM CclAiForceComplete( SCM destForce )
+local SCM CclAiForceComplete(SCM destForce)
 {
     int dst;
 
-    dst = gh_scm2int( destForce );
-    AiForceComplete( dst );
+    dst = gh_scm2int(destForce);
+    AiForceComplete(dst);
     return SCM_BOOL_F;
 }
 
@@ -1349,20 +1281,20 @@
 **     @param value    Force number.
 **     @param flag     Which role of the force.
 */
-local SCM CclAiForceRole( SCM value, SCM flag )
+local SCM CclAiForceRole(SCM value, SCM flag)
 {
     int force;
 
-    force = gh_scm2int( value );
-    if ( force < 0 || force >= AI_MAX_FORCES ) {
-       errl( "Force out of range", value );
+    force = gh_scm2int(value);
+    if (force < 0 || force >= AI_MAX_FORCES) {
+       errl("Force out of range", value);
     }
-    if ( gh_eq_p( flag, gh_symbol2scm( "attack" ) ) ) {
+    if (gh_eq_p(flag, gh_symbol2scm("attack"))) {
        AiPlayer->Force[force].Role = AiForceRoleAttack;
-    } else if ( gh_eq_p( flag, gh_symbol2scm( "defend" ) ) ) {
+    } else if (gh_eq_p(flag, gh_symbol2scm("defend"))) {
        AiPlayer->Force[force].Role = AiForceRoleDefend;
     } else {
-       errl( "Unknown force role", flag );
+       errl("Unknown force role", flag);
     }
 
     return SCM_BOOL_F;
@@ -1375,16 +1307,16 @@
 **     @param  value   the force
 **     @return         true if the force is defending, false otherwise
 */
-local SCM CclAiIsForceDefending( SCM value )
+local SCM CclAiIsForceDefending(SCM value)
 {
     int force;
 
-    force = gh_scm2int( value );
-    if ( force < 0 || force >= AI_MAX_FORCES ) {
-       errl( "Force out of range", value );
+    force = gh_scm2int(value);
+    if (force < 0 || force >= AI_MAX_FORCES) {
+       errl("Force out of range", value);
     }
 
-    if ( AiPlayer->Force[force].Role == AiForceRoleDefend ) {
+    if (AiPlayer->Force[force].Role == AiForceRoleDefend) {
        return SCM_BOOL_T;
     }
     return SCM_BOOL_F;
@@ -1398,100 +1330,100 @@
 **     @param way      air, ground or sea
 **     @return         true if the hotspot is reachable
 */
-local SCM CclAiCanReachHotSpot( SCM way )
+local SCM CclAiCanReachHotSpot(SCM way)
 {
     int wayid, i;
     int x, y, w, h;
     Unit *unit;
 
 
-    if ( ( AiScript->HotSpot_X == -1 ) || ( AiScript->HotSpot_Y == -1 )
-        || ( AiScript->HotSpot_Ray <= 0 ) ) {
+    if ((AiScript->HotSpot_X == -1) || (AiScript->HotSpot_Y == -1)
+       || (AiScript->HotSpot_Ray <= 0)) {
        return SCM_BOOL_T;
     }
 
     wayid = -1;
-   // Air is always accessible...
-    if ( gh_eq_p( way, gh_symbol2scm( "air" ) ) ) {
+    // Air is always accessible...
+    if (gh_eq_p(way, gh_symbol2scm("air"))) {
        wayid = 0;
     }
-    if ( gh_eq_p( way, gh_symbol2scm( "ground" ) ) ) {
+    if (gh_eq_p(way, gh_symbol2scm("ground"))) {
        wayid = 1;
     }
-    if ( gh_eq_p( way, gh_symbol2scm( "sea" ) ) ) {
+    if (gh_eq_p(way, gh_symbol2scm("sea"))) {
        wayid = 2;
     }
 
-    if ( wayid == -1 ) {
-       errl( "Unknown way ", way );
+    if (wayid == -1) {
+       errl("Unknown way ", way);
     }
-   // Calculate a rectangle...
-   // FIXME : Why 2 ?
+    // Calculate a rectangle...
+    // FIXME : Why 2 ?
     x = AiScript->HotSpot_X - 2;
     y = AiScript->HotSpot_Y - 2;
     w = 5;
     h = 5;
 
-   // clip it
-    if ( x < 0 ) {
+    // clip it
+    if (x < 0) {
        w += x;
        x = 0;
     }
-    if ( y < 0 ) {
+    if (y < 0) {
        h += y;
        y = 0;
     }
-    if ( x + w >= TheMap.Width ) {
+    if (x + w >= TheMap.Width) {
        w = TheMap.Width - x;
     }
 
-    if ( y + h >= TheMap.Height ) {
+    if (y + h >= TheMap.Height) {
        h = TheMap.Height - y;
     }
-   // Dummy check...
-    if ( ( w <= 0 ) || ( h <= 0 ) ) {
+    // Dummy check...
+    if ((w <= 0) || (h <= 0)) {
        return SCM_BOOL_F;
     }
-   // Air is no problem...
-    if ( wayid == 0 ) {
+    // Air is no problem...
+    if (wayid == 0) {
        return SCM_BOOL_T;
     }
-   // Find a unit which can move, check if it can access the hotspot.
-    for ( i = 0; i < AiPlayer->Player->TotalNumUnits; i++ ) {
+    // Find a unit which can move, check if it can access the hotspot.
+    for (i = 0; i < AiPlayer->Player->TotalNumUnits; i++) {
        unit = AiPlayer->Player->Units[i];
 
-       if ( unit->Orders[0].Action == UnitActionDie ) {
+       if (unit->Orders[0].Action == UnitActionDie) {
            continue;
        }
 
-       if ( unit->Removed ) {
+       if (unit->Removed) {
            continue;
        }
 
-       if ( ( unit->X == -1 ) || ( unit->Y == -1 ) ) {
+       if ((unit->X == -1) || (unit->Y == -1)) {
            continue;
        }
 
-       if ( unit->Type->Building ) {
+       if (unit->Type->Building) {
            continue;
        }
 
-       if ( ( wayid == 1 ) && ( unit->Type->UnitType != UnitTypeLand ) ) {
+       if ((wayid == 1) && (unit->Type->UnitType != UnitTypeLand)) {
            continue;
        }
 
-       if ( ( wayid == 2 ) && ( unit->Type->UnitType != UnitTypeNaval ) ) {
+       if ((wayid == 2) && (unit->Type->UnitType != UnitTypeNaval)) {
            continue;
        }
-       // Ok, unit is a possible test
-       if ( PlaceReachable( unit, x, y, w, h, 2 ) ) {
+       // Ok, unit is a possible test
+       if (PlaceReachable(unit, x, y, w, h, 2)) {
            return SCM_BOOL_T;
        }
        return SCM_BOOL_F;
     }
 
-   // Fall back : no unit at all ? Use the starting point...
-    DebugLevel3Fn( "CclAiCanReach failled to use a test unit...\n" );
+    // Fall back : no unit at all ? Use the starting point...
+    DebugLevel3Fn("CclAiCanReach failled to use a test unit...\n");
     return SCM_BOOL_T;
 }
 
@@ -1502,15 +1434,15 @@
 **     @param value    Force number.
 **     @return         #t if ready, #f otherwise.
 */
-local SCM CclAiCheckForce( SCM value )
+local SCM CclAiCheckForce(SCM value)
 {
     int force;
 
-    force = gh_scm2int( value );
-    if ( force < 0 || force >= AI_MAX_FORCES ) {
-       errl( "Force out of range", value );
+    force = gh_scm2int(value);
+    if (force < 0 || force >= AI_MAX_FORCES) {
+       errl("Force out of range", value);
     }
-    if ( AiPlayer->Force[force].Completed ) {
+    if (AiPlayer->Force[force].Completed) {
        return SCM_BOOL_T;
     }
     return SCM_BOOL_F;
@@ -1523,9 +1455,9 @@
 **
 ** @return -1 if it is not possible ( upgrade missing )
 */
-local SCM CclAiEvaluateForceCost( SCM s_force )
+local SCM CclAiEvaluateForceCost(SCM s_force)
 {
-    return gh_int2scm( AiEvaluateForceCost( gh_scm2int( s_force ), 0 ) );
+    return gh_int2scm(AiEvaluateForceCost(gh_scm2int(s_force), 0));
 }
 
 // Just hang...
@@ -1539,22 +1471,22 @@
 **
 **     @param value    Force number.
 */
-local SCM CclAiWaitForce( SCM value )
+local SCM CclAiWaitForce(SCM value)
 {
     int force;
 
-    force = gh_scm2int( value );
-    if ( force < 0 || force >= AI_MAX_FORCES ) {
-       errl( "Force out of range", value );
+    force = gh_scm2int(value);
+    if (force < 0 || force >= AI_MAX_FORCES) {
+       errl("Force out of range", value);
     }
-    if ( AiPlayer->Force[force].Completed ) {
+    if (AiPlayer->Force[force].Completed) {
        return SCM_BOOL_F;
     }
-    DebugLevel3Fn( "Wait force %d\n" _C_ force );
+    DebugLevel3Fn("Wait force %d\n" _C_ force);
 #if 0
-   // Debuging
+    // Debuging
     AiCleanForces();
-    DebugCheck( AiPlayer->Force[force].Completed );
+    DebugCheck(AiPlayer->Force[force].Completed);
 #endif
 
     return SCM_BOOL_T;
@@ -1565,16 +1497,16 @@
 **
 **     @param value    Force number.
 */
-local SCM CclAiAttackWithForce( SCM value )
+local SCM CclAiAttackWithForce(SCM value)
 {
     int force;
 
-    force = gh_scm2int( value );
-    if ( force < 0 || force >= AI_MAX_FORCES ) {
-       errl( "Force out of range", value );
+    force = gh_scm2int(value);
+    if (force < 0 || force >= AI_MAX_FORCES) {
+       errl("Force out of range", value);
     }
 
-    AiAttackWithForce( force );
+    AiAttackWithForce(force);
 
     return SCM_BOOL_F;
 }
@@ -1584,16 +1516,16 @@
 **
 **     @param value    Force number.
 */
-local SCM CclAiHotSpotAttackWithForce( SCM value )
+local SCM CclAiHotSpotAttackWithForce(SCM value)
 {
     int force;
 
-    force = gh_scm2int( value );
-    if ( force < 0 || force >= AI_MAX_FORCES ) {
-       errl( "Force out of range", value );
+    force = gh_scm2int(value);
+    if (force < 0 || force >= AI_MAX_FORCES) {
+       errl("Force out of range", value);
     }
 
-    AiAttackWithForceAt( force, AiScript->HotSpot_X, AiScript->HotSpot_Y );
+    AiAttackWithForceAt(force, AiScript->HotSpot_X, AiScript->HotSpot_Y);
 
     return SCM_BOOL_F;
 }
@@ -1602,30 +1534,30 @@
 **
 **
 */
-local SCM CclAiGroupForce( SCM value )
+local SCM CclAiGroupForce(SCM value)
 {
     int force;
 
-    force = gh_scm2int( value );
-    if ( force < 0 || force >= AI_MAX_FORCES ) {
-       errl( "Force out of range", value );
+    force = gh_scm2int(value);
+    if (force < 0 || force >= AI_MAX_FORCES) {
+       errl("Force out of range", value);
     }
 
-    AiGroupForceNear( force, AiScript->HotSpot_X, AiScript->HotSpot_Y );
+    AiGroupForceNear(force, AiScript->HotSpot_X, AiScript->HotSpot_Y);
 
     return SCM_BOOL_F;
 }
 
-local SCM CclAiForceHome( SCM value )
+local SCM CclAiForceHome(SCM value)
 {
     int force;
 
-    force = gh_scm2int( value );
-    if ( force < 0 || force >= AI_MAX_FORCES ) {
-       errl( "Force out of range", value );
+    force = gh_scm2int(value);
+    if (force < 0 || force >= AI_MAX_FORCES) {
+       errl("Force out of range", value);
     }
 
-    AiSendForceHome( force );
+    AiSendForceHome(force);
 
     return SCM_BOOL_F;
 }
@@ -1636,20 +1568,20 @@
 **     @param s_force  Force number.
 **     @param s_wait   Maximum number of cycles to delay.
 */
-local SCM CclAiTimedWaitForce( SCM s_force, SCM s_wait )
+local SCM CclAiTimedWaitForce(SCM s_force, SCM s_wait)
 {
     SCM result;
-   // return true after n call or when force is ready
-    if ( AiScript->SleepCycles ) {
-       if ( AiScript->SleepCycles < GameCycle ) {
+    // return true after n call or when force is ready
+    if (AiScript->SleepCycles) {
+       if (AiScript->SleepCycles < GameCycle) {
            AiScript->SleepCycles = 0;
            return SCM_BOOL_F;
        }
     } else {
-       AiScript->SleepCycles = GameCycle + gh_scm2int( s_wait );
+       AiScript->SleepCycles = GameCycle + gh_scm2int(s_wait);
     }
-    result = CclAiWaitForce( s_force );
-    if ( result == SCM_BOOL_F ) {
+    result = CclAiWaitForce(s_force);
+    if (result == SCM_BOOL_F) {
        AiScript->SleepCycles = 0;
     }
     return result;
@@ -1660,18 +1592,18 @@
 **
 **     @param value    Number of cycles to delay.
 */
-local SCM CclAiSleep( SCM value )
+local SCM CclAiSleep(SCM value)
 {
     int i;
 
-    DebugLevel3Fn( "%lu %d\n" _C_ GameCycle _C_ AiPlayer->SleepCycles );
-    if ( AiScript->SleepCycles ) {
-       if ( AiScript->SleepCycles < GameCycle ) {
+    DebugLevel3Fn("%lu %d\n" _C_ GameCycle _C_ AiPlayer->SleepCycles);
+    if (AiScript->SleepCycles) {
+       if (AiScript->SleepCycles < GameCycle) {
            AiScript->SleepCycles = 0;
            return SCM_BOOL_F;
        }
     } else {
-       i = gh_scm2int( value );
+       i = gh_scm2int(value);
        AiScript->SleepCycles = GameCycle + i;
     }
 
@@ -1683,20 +1615,20 @@
 **
 **     @param value    Upgrade as string/symbol/object.
 */
-local SCM CclAiResearch( SCM value )
+local SCM CclAiResearch(SCM value)
 {
     const char *str;
     Upgrade *upgrade;
 
-   // Be kind allow also strings or symbols
-    if ( ( str = try_get_c_string( value ) ) ) {
-       upgrade = UpgradeByIdent( str );
+    // Be kind allow also strings or symbols
+    if ((str = try_get_c_string(value))) {
+       upgrade = UpgradeByIdent(str);
     } else {
-       errl( "Upgrade needed", value );
+       errl("Upgrade needed", value);
        return SCM_BOOL_F;
     }
 
-    InsertResearchRequests( upgrade );
+    InsertResearchRequests(upgrade);
 
     return SCM_BOOL_F;
 }
@@ -1706,17 +1638,17 @@
 **
 **     @param value    Unit-type as string/symbol/object.
 */
-local SCM CclAiUpgradeTo( SCM value )
+local SCM CclAiUpgradeTo(SCM value)
 {
     UnitType *type;
 
-    type = CclGetUnitType( value );
-    InsertUpgradeToRequests( type );
+    type = CclGetUnitType(value);
+    InsertUpgradeToRequests(type);
 
     return SCM_BOOL_F;
 }
 
-local SCM CclAiSetHotSpotRay( SCM value )
+local SCM CclAiSetHotSpotRay(SCM value)
 {
     return SCM_BOOL_F;
 }
@@ -1733,42 +1665,42 @@
     return SCM_BOOL_F;
 }
 
-local SCM CclAiGetGauge( SCM value )
+local SCM CclAiGetGauge(SCM value)
 {
     int gauge;
-    if ( gh_exact_p( value ) ) {
-       gauge = gh_scm2int( value );
+    if (gh_exact_p(value)) {
+       gauge = gh_scm2int(value);
     } else {
-       gauge = AiFindGaugeId( value );
-       if ( gauge == -1 ) {
-           errl( "invalid gauge name", value );
+       gauge = AiFindGaugeId(value);
+       if (gauge == -1) {
+           errl("invalid gauge name", value);
        }
     }
-    return gh_int2scm( AiGetGaugeValue( gauge ) );
+    return gh_int2scm(AiGetGaugeValue(gauge));
 }
 
-local SCM CclGetUnitTypeForce( SCM value )
+local SCM CclGetUnitTypeForce(SCM value)
 {
     UnitType *unitType;
 
-    unitType = CclGetUnitType( value );
+    unitType = CclGetUnitType(value);
 
-    return gh_int2scm( AiUnittypeForce( unitType ) );
+    return gh_int2scm(AiUnittypeForce(unitType));
 }
 
 /**
 **     Simple restart the AI.
 */
-local SCM CclAiRestart( void )
+local SCM CclAiRestart(void)
 {
     int i;
     AiPlayer->Scripts[0].Script = AiPlayer->AiType->Script;
     AiPlayer->Scripts[0].SleepCycles = 0;
-    snprintf( AiPlayer->Scripts[0].ident, 10, "Main AI" );
-    for ( i = 1; i < AI_MAX_RUNNING_SCRIPTS; i++ ) {
+    snprintf(AiPlayer->Scripts[0].ident, 10, "Main AI");
+    for (i = 1; i < AI_MAX_RUNNING_SCRIPTS; i++) {
        AiPlayer->Scripts[i].Script = NIL;
        AiPlayer->Scripts[i].SleepCycles = 0;
-       snprintf( AiPlayer->Scripts[i].ident, 10, "Empty" );
+       snprintf(AiPlayer->Scripts[i].ident, 10, "Empty");
     }
     return SCM_BOOL_T;
 }
@@ -1782,21 +1714,21 @@
 **     @param hotSpotY         position of the hotspot (Y)
 **     @param hotSpotRay       ray of the hotspot
 */
-global void AiRunScript( int script, SCM list, int hotSpotX, int hotSpotY, int 
hotSpotRay )
+global void AiRunScript(int script, SCM list, int hotSpotX, int hotSpotY, int 
hotSpotRay)
 {
     AiPlayer->Scripts[script].Script = list;
     AiPlayer->Scripts[script].SleepCycles = 0;
-    snprintf( AiPlayer->Scripts[script].ident, 10, "AiRunScript" );
+    snprintf(AiPlayer->Scripts[script].ident, 10, "AiRunScript");
     AiPlayer->Scripts[script].HotSpot_X = hotSpotX;
     AiPlayer->Scripts[script].HotSpot_Y = hotSpotY;
     AiPlayer->Scripts[script].HotSpot_Ray = hotSpotRay;
-   // TODO : Compute gauges here ?    
+    // TODO : Compute gauges here ?    
 }
 
 /**
 **     Change the current script
 */
-local SCM CclAiSwitchTo( SCM value )
+local SCM CclAiSwitchTo(SCM value)
 {
     AiScript->Script = value;
     AiScript->SleepCycles = 0;
@@ -1806,16 +1738,16 @@
 /**
 **     Execute new main script
 */
-local SCM CclAiScript( SCM value )
+local SCM CclAiScript(SCM value)
 {
     int i;
     AiPlayer->Scripts[0].Script = value;
     AiPlayer->Scripts[0].SleepCycles = 0;
-    snprintf( AiPlayer->Scripts[0].ident, 10, "MainScript" );
-    for ( i = 1; i < AI_MAX_RUNNING_SCRIPTS; i++ ) {
+    snprintf(AiPlayer->Scripts[0].ident, 10, "MainScript");
+    for (i = 1; i < AI_MAX_RUNNING_SCRIPTS; i++) {
        AiPlayer->Scripts[i].Script = NIL;
        AiPlayer->Scripts[i].SleepCycles = 0;
-       snprintf( AiPlayer->Scripts[i].ident, 10, "Empty" );
+       snprintf(AiPlayer->Scripts[i].ident, 10, "Empty");
     }
     return SCM_BOOL_T;
 }
@@ -1825,9 +1757,9 @@
 **
 **     @return         Player number of the AI.
 */
-local SCM CclAiPlayer( void )
+local SCM CclAiPlayer(void)
 {
-    return gh_int2scm( AiPlayer->Player->Player );
+    return gh_int2scm(AiPlayer->Player->Player);
 }
 
 /**
@@ -1836,17 +1768,17 @@
 **     @param vec      Resources vector
 **     @return         Old resource vector
 */
-local SCM CclAiSetReserve( SCM vec )
+local SCM CclAiSetReserve(SCM vec)
 {
     int i;
     SCM old;
 
-    old = cons_array( gh_int2scm( MaxCosts ), 0 );
-    for ( i = 0; i < MaxCosts; ++i ) {
-       aset1( old, gh_int2scm( i ), gh_int2scm( AiPlayer->Reserve[i] ) );
+    old = cons_array(gh_int2scm(MaxCosts), 0);
+    for (i = 0; i < MaxCosts; ++i) {
+       aset1(old, gh_int2scm(i), gh_int2scm(AiPlayer->Reserve[i]));
     }
-    for ( i = 0; i < MaxCosts; ++i ) {
-       AiPlayer->Reserve[i] = gh_scm2int( gh_vector_ref( vec, gh_int2scm( i ) 
) );
+    for (i = 0; i < MaxCosts; ++i) {
+       AiPlayer->Reserve[i] = gh_scm2int(gh_vector_ref(vec, gh_int2scm(i)));
     }
     return old;
 }
@@ -1857,17 +1789,17 @@
 **     @param vec      Resources vector
 **     @return         Old resource vector
 */
-local SCM CclAiSetCollect( SCM vec )
+local SCM CclAiSetCollect(SCM vec)
 {
     int i;
     SCM old;
 
-    old = cons_array( gh_int2scm( MaxCosts ), 0 );
-    for ( i = 0; i < MaxCosts; ++i ) {
-       aset1( old, gh_int2scm( i ), gh_int2scm( AiPlayer->Collect[i] ) );
+    old = cons_array(gh_int2scm(MaxCosts), 0);
+    for (i = 0; i < MaxCosts; ++i) {
+       aset1(old, gh_int2scm(i), gh_int2scm(AiPlayer->Collect[i]));
     }
-    for ( i = 0; i < MaxCosts; ++i ) {
-       AiPlayer->Collect[i] = gh_scm2int( gh_vector_ref( vec, gh_int2scm( i ) 
) );
+    for (i = 0; i < MaxCosts; ++i) {
+       AiPlayer->Collect[i] = gh_scm2int(gh_vector_ref(vec, gh_int2scm(i)));
     }
     return old;
 }
@@ -1878,78 +1810,78 @@
 **     @param val      new value of the autoattack flag
 **     @return         SCM_BOOL_F
 */
-local SCM CclAiSetAutoAttack( SCM val )
+local SCM CclAiSetAutoAttack(SCM val)
 {
-    AiPlayer->AutoAttack = gh_scm2bool( val );
+    AiPlayer->AutoAttack = gh_scm2bool(val);
     return SCM_BOOL_F;
 }
 
 /**
 **     Dump some AI debug informations.
 */
-local SCM CclAiDump( void )
+local SCM CclAiDump(void)
 {
     int i;
     int n;
     const AiUnitType *aut;
     const AiBuildQueue *queue;
 
-   //
-   //  Script
-   //
-    printf( "------\n" );
-    for ( i = 0; i < MaxCosts; ++i ) {
-       printf( "%s(%4d) ", DefaultResourceNames[i], 
AiPlayer->Player->Resources[i] );
-    }
-    printf( "\n" );
-    printf( "%d:", AiPlayer->Player->Player );
-    for ( i = 0; i < AI_MAX_RUNNING_SCRIPTS; ++i ) {
-       gh_display( gh_car( AiPlayer->Scripts[i].Script ) );
+    //
+    //  Script
+    //
+    printf("------\n");
+    for (i = 0; i < MaxCosts; ++i) {
+       printf("%s(%4d) ", DefaultResourceNames[i], 
AiPlayer->Player->Resources[i]);
+    }
+    printf("\n");
+    printf("%d:", AiPlayer->Player->Player);
+    for (i = 0; i < AI_MAX_RUNNING_SCRIPTS; ++i) {
+       gh_display(gh_car(AiPlayer->Scripts[i].Script));
     }
     gh_newline();
 
-   //
-   //  Requests
-   //
+    //
+    //  Requests
+    //
     n = AiPlayer->UnitTypeRequestsCount;
-    printf( "UnitTypeRequests(%d):\n", n );
-    for ( i = 0; i < n; ++i ) {
-       printf( "%s ", AiPlayer->UnitTypeRequests[i].Table[0]->Ident );
+    printf("UnitTypeRequests(%d):\n", n);
+    for (i = 0; i < n; ++i) {
+       printf("%s ", AiPlayer->UnitTypeRequests[i].Table[0]->Ident);
     }
-    printf( "\n" );
+    printf("\n");
     n = AiPlayer->UpgradeToRequestsCount;
-    printf( "UpgradeToRequests(%d):\n", n );
-    for ( i = 0; i < n; ++i ) {
-       printf( "%s ", AiPlayer->UpgradeToRequests[i]->Ident );
+    printf("UpgradeToRequests(%d):\n", n);
+    for (i = 0; i < n; ++i) {
+       printf("%s ", AiPlayer->UpgradeToRequests[i]->Ident);
     }
-    printf( "\n" );
+    printf("\n");
     n = AiPlayer->ResearchRequestsCount;
-    printf( "ResearchRequests(%d):\n", n );
-    for ( i = 0; i < n; ++i ) {
-       printf( "%s ", AiPlayer->ResearchRequests[i]->Ident );
-    }
-    printf( "\n" );
-
-   //
-   //  Building queue
-   //
-    printf( "Building queue:\n" );
-    for ( queue = AiPlayer->UnitTypeBuilded; queue; queue = queue->Next ) {
-       printf( "%s(%d/%d) ", queue->Type->Ident, queue->Made, queue->Want );
-    }
-    printf( "\n" );
-
-   //
-   //  PrintForce
-   //
-    for ( i = 0; i < AI_MAX_FORCES; ++i ) {
-       printf( "Force(%d%s%s):\n", i,
-               AiPlayer->Force[i].Completed ? ",complete" : ",recruit",
-               AiPlayer->Force[i].Attacking ? ",attack" : "" );
-       for ( aut = AiPlayer->Force[i].UnitTypes; aut; aut = aut->Next ) {
-           printf( "%s(%d) ", aut->Type->Ident, aut->Want );
+    printf("ResearchRequests(%d):\n", n);
+    for (i = 0; i < n; ++i) {
+       printf("%s ", AiPlayer->ResearchRequests[i]->Ident);
+    }
+    printf("\n");
+
+    //
+    //  Building queue
+    //
+    printf("Building queue:\n");
+    for (queue = AiPlayer->UnitTypeBuilded; queue; queue = queue->Next) {
+       printf("%s(%d/%d) ", queue->Type->Ident, queue->Made, queue->Want);
+    }
+    printf("\n");
+
+    //
+    //  PrintForce
+    //
+    for (i = 0; i < AI_MAX_FORCES; ++i) {
+       printf("Force(%d%s%s):\n", i,
+           AiPlayer->Force[i].Completed ? ",complete" : ",recruit",
+           AiPlayer->Force[i].Attacking ? ",attack" : "");
+       for (aut = AiPlayer->Force[i].UnitTypes; aut; aut = aut->Next) {
+           printf("%s(%d) ", aut->Type->Ident, aut->Want);
        }
-       printf( "\n" );
+       printf("\n");
     }
 
     return SCM_BOOL_F;
@@ -1960,25 +1892,25 @@
 **
 **     @param list     List of all names.
 */
-local SCM CclDefineAiWcNames( SCM list )
+local SCM CclDefineAiWcNames(SCM list)
 {
     int i;
     char **cp;
 
-    if ( ( cp = AiTypeWcNames ) ) {    // Free all old names
-       while ( *cp ) {
-           free( *cp++ );
-       }
-       free( AiTypeWcNames );
-    }
-   //
-   //  Get new table.
-   //
-    i = gh_length( list );
-    AiTypeWcNames = cp = malloc( ( i + 1 ) * sizeof ( char * ) );
-    while ( i-- ) {
-       *cp++ = gh_scm2newstr( gh_car( list ), NULL );
-       list = gh_cdr( list );
+    if ((cp = AiTypeWcNames)) {                // Free all old names
+       while (*cp) {
+           free(*cp++);
+       }
+       free(AiTypeWcNames);
+    }
+    //
+    //  Get new table.
+    //
+    i = gh_length(list);
+    AiTypeWcNames = cp = malloc((i + 1) * sizeof (char *));
+    while (i--) {
+       *cp++ = gh_scm2newstr(gh_car(list), NULL);
+       list = gh_cdr(list);
     }
     *cp = NULL;
 
@@ -1992,16 +1924,16 @@
 **
 **     @return         The number of the resource in DEFAULT_NAMES
 */
-local int DefaultResourceNumber( const char *type )
+local int DefaultResourceNumber(const char *type)
 {
     int i;
-    for ( i = 0; i < MaxCosts; ++i ) {
-       if ( !strcmp( DefaultResourceNames[i], type ) ) {
+    for (i = 0; i < MaxCosts; ++i) {
+       if (!strcmp(DefaultResourceNames[i], type)) {
            return i;
        }
     }
-   // Resource not found, should never happen
-    DebugCheck( 1 );
+    // Resource not found, should never happen
+    DebugCheck(1);
     return -1;
 }
 
@@ -2021,316 +1953,316 @@
 **                             
 **     @param list     List of the AI Player.
 */
-local SCM CclDefineAiPlayer( SCM list )
+local SCM CclDefineAiPlayer(SCM list)
 {
-   //SCM value;
-   //SCM sublist;
+    //SCM value;
+    //SCM sublist;
     int i;
-   //char* str;
+    //char* str;
     PlayerAi *ai;
 
     IOLoadingMode = 1;
 
-    IOPlayerAiFullPtr( gh_car( list ), &ai, 0 );
+    IOPlayerAiFullPtr(gh_car(list), &ai, 0);
 
     i = ai->Player->Player;
-    DebugCheck( i < 0 || i > PlayerMax );
+    DebugCheck(i < 0 || i > PlayerMax);
     Players[i].Ai = ai;
 
 #if 0
-    i = gh_scm2int( gh_car( list ) );
-    list = gh_cdr( list );
+    i = gh_scm2int(gh_car(list));
+    list = gh_cdr(list);
 
-    DebugCheck( i < 0 || i > PlayerMax );
-    DebugLevel0Fn( "%p %d\n" _C_ Players[i].Ai _C_ Players[i].AiEnabled );
-   // FIXME: loose this:
-   // DebugCheck( Players[i].Ai || !Players[i].AiEnabled );
+    DebugCheck(i < 0 || i > PlayerMax);
+    DebugLevel0Fn("%p %d\n" _C_ Players[i].Ai _C_ Players[i].AiEnabled);
+    // FIXME: loose this:
+    // DebugCheck( Players[i].Ai || !Players[i].AiEnabled );
 
-    ai = Players[i].Ai = calloc( 1, sizeof ( PlayerAi ) );
+    ai = Players[i].Ai = calloc(1, sizeof (PlayerAi));
     ai->Player = &Players[i];
 
-    snprintf( AiPlayer->Scripts[0].ident, 10, "Empty" );
-    for ( i = 1; i < AI_MAX_RUNNING_SCRIPTS; i++ ) {
+    snprintf(AiPlayer->Scripts[0].ident, 10, "Empty");
+    for (i = 1; i < AI_MAX_RUNNING_SCRIPTS; i++) {
        ai->Scripts[i].Script = NIL;
        ai->Scripts[i].SleepCycles = 0;
-       snprintf( AiPlayer->Scripts[i].ident, 10, "Empty" );
+       snprintf(AiPlayer->Scripts[i].ident, 10, "Empty");
     }
 
-   //
-   //  Parse the list: (still everything could be changed!)
-   //
-    while ( !gh_null_p( list ) ) {
+    //
+    //  Parse the list: (still everything could be changed!)
+    //
+    while (!gh_null_p(list)) {
 
-       value = gh_car( list );
-       list = gh_cdr( list );
+       value = gh_car(list);
+       list = gh_cdr(list);
 
-       if ( gh_eq_p( value, gh_symbol2scm( "ai-type" ) ) ) {
+       if (gh_eq_p(value, gh_symbol2scm("ai-type"))) {
            AiType *ait;
 
-           str = gh_scm2newstr( gh_car( list ), NULL );
-           for ( ait = AiTypes; ait; ait = ait->Next ) {
-               if ( !strcmp( ait->Name, str ) ) {
+           str = gh_scm2newstr(gh_car(list), NULL);
+           for (ait = AiTypes; ait; ait = ait->Next) {
+               if (!strcmp(ait->Name, str)) {
                    break;
                }
            }
-           free( str );
-           if ( !ait ) {
-               errl( "ai-type not found", gh_car( list ) );
+           free(str);
+           if (!ait) {
+               errl("ai-type not found", gh_car(list));
            }
            ai->AiType = ait;
            ai->Scripts[0].Script = ait->Script;
-           list = gh_cdr( list );
-       } else if ( gh_eq_p( value, gh_symbol2scm( "script" ) ) ) {
-           sublist = gh_car( list );
-           value = gh_car( sublist );
-           sublist = gh_cdr( sublist );
-           if ( gh_eq_p( value, gh_symbol2scm( "aitypes" ) ) ) {
-               i = gh_scm2int( gh_car( sublist ) );
-               while ( i-- ) {
-                   ai->Scripts[0].Script = gh_cdr( ai->Scripts[0].Script );
+           list = gh_cdr(list);
+       } else if (gh_eq_p(value, gh_symbol2scm("script"))) {
+           sublist = gh_car(list);
+           value = gh_car(sublist);
+           sublist = gh_cdr(sublist);
+           if (gh_eq_p(value, gh_symbol2scm("aitypes"))) {
+               i = gh_scm2int(gh_car(sublist));
+               while (i--) {
+                   ai->Scripts[0].Script = gh_cdr(ai->Scripts[0].Script);
                }
            } else {
-               DebugLevel0Fn( "FIXME: not written\n" );
+               DebugLevel0Fn("FIXME: not written\n");
            }
-           list = gh_cdr( list );
-       } else if ( gh_eq_p( value, gh_symbol2scm( "script-debug" ) ) ) {
-           ai->ScriptDebug = gh_scm2bool( gh_car( list ) );
-           list = gh_cdr( list );
-       } else if ( gh_eq_p( value, gh_symbol2scm( "sleep-cycles" ) ) ) {
-           ai->Scripts[0].SleepCycles = gh_scm2int( gh_car( list ) );
-           list = gh_cdr( list );
-       } else if ( gh_eq_p( value, gh_symbol2scm( "force" ) ) ) {
-           sublist = gh_car( list );
-           value = gh_car( sublist );
-           sublist = gh_cdr( sublist );
-           i = gh_scm2int( value );
-           while ( !gh_null_p( sublist ) ) {
-               value = gh_car( sublist );
-               sublist = gh_cdr( sublist );
-               if ( gh_eq_p( value, gh_symbol2scm( "complete" ) ) ) {
+           list = gh_cdr(list);
+       } else if (gh_eq_p(value, gh_symbol2scm("script-debug"))) {
+           ai->ScriptDebug = gh_scm2bool(gh_car(list));
+           list = gh_cdr(list);
+       } else if (gh_eq_p(value, gh_symbol2scm("sleep-cycles"))) {
+           ai->Scripts[0].SleepCycles = gh_scm2int(gh_car(list));
+           list = gh_cdr(list);
+       } else if (gh_eq_p(value, gh_symbol2scm("force"))) {
+           sublist = gh_car(list);
+           value = gh_car(sublist);
+           sublist = gh_cdr(sublist);
+           i = gh_scm2int(value);
+           while (!gh_null_p(sublist)) {
+               value = gh_car(sublist);
+               sublist = gh_cdr(sublist);
+               if (gh_eq_p(value, gh_symbol2scm("complete"))) {
                    ai->Force[i].Completed = 1;
-               } else if ( gh_eq_p( value, gh_symbol2scm( "recruit" ) ) ) {
+               } else if (gh_eq_p(value, gh_symbol2scm("recruit"))) {
                    ai->Force[i].Completed = 0;
-               } else if ( gh_eq_p( value, gh_symbol2scm( "attack" ) ) ) {
+               } else if (gh_eq_p(value, gh_symbol2scm("attack"))) {
                    ai->Force[i].Attacking = 1;
-               } else if ( gh_eq_p( value, gh_symbol2scm( "role" ) ) ) {
-                   if ( gh_eq_p( gh_car( sublist ), gh_symbol2scm( "attack" ) 
) ) {
+               } else if (gh_eq_p(value, gh_symbol2scm("role"))) {
+                   if (gh_eq_p(gh_car(sublist), gh_symbol2scm("attack"))) {
                        ai->Force[i].Role = AiForceRoleAttack;
-                   } else if ( gh_eq_p( gh_car( sublist ), gh_symbol2scm( 
"defend" ) ) ) {
+                   } else if (gh_eq_p(gh_car(sublist), 
gh_symbol2scm("defend"))) {
                        ai->Force[i].Role = AiForceRoleDefend;
                    }
-                   sublist = gh_cdr( sublist );
-               } else if ( gh_eq_p( value, gh_symbol2scm( "types" ) ) ) {
+                   sublist = gh_cdr(sublist);
+               } else if (gh_eq_p(value, gh_symbol2scm("types"))) {
                    AiUnitType **queue;
                    SCM subsublist;
-                   subsublist = gh_car( sublist );
+                   subsublist = gh_car(sublist);
                    queue = &ai->Force[i].UnitTypes;
-                   while ( !gh_null_p( subsublist ) ) {
+                   while (!gh_null_p(subsublist)) {
                        int num;
                        char *ident;
-                       value = gh_car( subsublist );
-                       subsublist = gh_cdr( subsublist );
-                       num = gh_scm2int( value );
-                       value = gh_car( subsublist );
-                       subsublist = gh_cdr( subsublist );
-                       ident = get_c_string( value );
-                       *queue = malloc( sizeof ( AiUnitType ) );
-                       ( *queue )->Next = NULL;
-                       ( *queue )->Want = num;
-                       ( *queue )->Type = UnitTypeByIdent( ident );
-                       queue = &( *queue )->Next;
+                       value = gh_car(subsublist);
+                       subsublist = gh_cdr(subsublist);
+                       num = gh_scm2int(value);
+                       value = gh_car(subsublist);
+                       subsublist = gh_cdr(subsublist);
+                       ident = get_c_string(value);
+                       *queue = malloc(sizeof (AiUnitType));
+                       (*queue)->Next = NULL;
+                       (*queue)->Want = num;
+                       (*queue)->Type = UnitTypeByIdent(ident);
+                       queue = &(*queue)->Next;
                    }
-                   sublist = gh_cdr( sublist );
-               } else if ( gh_eq_p( value, gh_symbol2scm( "units" ) ) ) {
+                   sublist = gh_cdr(sublist);
+               } else if (gh_eq_p(value, gh_symbol2scm("units"))) {
                    AiUnit **queue;
                    SCM subsublist;
-                   subsublist = gh_car( sublist );
+                   subsublist = gh_car(sublist);
                    queue = &ai->Force[i].Units;
-                   while ( !gh_null_p( subsublist ) ) {
+                   while (!gh_null_p(subsublist)) {
                        int num;
                        char *ident;
-                       value = gh_car( subsublist );
-                       subsublist = gh_cdr( subsublist );
-                       num = gh_scm2int( value );
-                       value = gh_car( subsublist );
-                       subsublist = gh_cdr( subsublist );
-                       ident = get_c_string( value );
-                       *queue = malloc( sizeof ( AiUnit ) );
-                       ( *queue )->Next = NULL;
-                       ( *queue )->Unit = UnitSlots[num];
-                       queue = &( *queue )->Next;
+                       value = gh_car(subsublist);
+                       subsublist = gh_cdr(subsublist);
+                       num = gh_scm2int(value);
+                       value = gh_car(subsublist);
+                       subsublist = gh_cdr(subsublist);
+                       ident = get_c_string(value);
+                       *queue = malloc(sizeof (AiUnit));
+                       (*queue)->Next = NULL;
+                       (*queue)->Unit = UnitSlots[num];
+                       queue = &(*queue)->Next;
                    }
                }
            }
-           list = gh_cdr( list );
-       } else if ( gh_eq_p( value, gh_symbol2scm( "reserve" ) ) ) {
-           sublist = gh_car( list );
-           while ( !gh_null_p( sublist ) ) {
+           list = gh_cdr(list);
+       } else if (gh_eq_p(value, gh_symbol2scm("reserve"))) {
+           sublist = gh_car(list);
+           while (!gh_null_p(sublist)) {
                char *type;
                int num;
-               value = gh_car( sublist );
-               sublist = gh_cdr( sublist );
-               type = get_c_string( value );
-               value = gh_car( sublist );
-               sublist = gh_cdr( sublist );
-               num = gh_scm2int( value );
-               ai->Reserve[DefaultResourceNumber( type )] = num;
-           }
-           list = gh_cdr( list );
-       } else if ( gh_eq_p( value, gh_symbol2scm( "used" ) ) ) {
-           sublist = gh_car( list );
-           while ( !gh_null_p( sublist ) ) {
+               value = gh_car(sublist);
+               sublist = gh_cdr(sublist);
+               type = get_c_string(value);
+               value = gh_car(sublist);
+               sublist = gh_cdr(sublist);
+               num = gh_scm2int(value);
+               ai->Reserve[DefaultResourceNumber(type)] = num;
+           }
+           list = gh_cdr(list);
+       } else if (gh_eq_p(value, gh_symbol2scm("used"))) {
+           sublist = gh_car(list);
+           while (!gh_null_p(sublist)) {
                char *type;
                int num;
-               value = gh_car( sublist );
-               sublist = gh_cdr( sublist );
-               type = get_c_string( value );
-               value = gh_car( sublist );
-               sublist = gh_cdr( sublist );
-               num = gh_scm2int( value );
-               ai->Used[DefaultResourceNumber( type )] = num;
-           }
-           list = gh_cdr( list );
-       } else if ( gh_eq_p( value, gh_symbol2scm( "needed" ) ) ) {
-           sublist = gh_car( list );
-           while ( !gh_null_p( sublist ) ) {
+               value = gh_car(sublist);
+               sublist = gh_cdr(sublist);
+               type = get_c_string(value);
+               value = gh_car(sublist);
+               sublist = gh_cdr(sublist);
+               num = gh_scm2int(value);
+               ai->Used[DefaultResourceNumber(type)] = num;
+           }
+           list = gh_cdr(list);
+       } else if (gh_eq_p(value, gh_symbol2scm("needed"))) {
+           sublist = gh_car(list);
+           while (!gh_null_p(sublist)) {
                char *type;
                int num;
-               value = gh_car( sublist );
-               sublist = gh_cdr( sublist );
-               type = get_c_string( value );
-               value = gh_car( sublist );
-               sublist = gh_cdr( sublist );
-               num = gh_scm2int( value );
-               ai->Needed[DefaultResourceNumber( type )] = num;
-           }
-           list = gh_cdr( list );
-       } else if ( gh_eq_p( value, gh_symbol2scm( "collect" ) ) ) {
-           sublist = gh_car( list );
-           while ( !gh_null_p( sublist ) ) {
+               value = gh_car(sublist);
+               sublist = gh_cdr(sublist);
+               type = get_c_string(value);
+               value = gh_car(sublist);
+               sublist = gh_cdr(sublist);
+               num = gh_scm2int(value);
+               ai->Needed[DefaultResourceNumber(type)] = num;
+           }
+           list = gh_cdr(list);
+       } else if (gh_eq_p(value, gh_symbol2scm("collect"))) {
+           sublist = gh_car(list);
+           while (!gh_null_p(sublist)) {
                char *type;
                int num;
-               value = gh_car( sublist );
-               sublist = gh_cdr( sublist );
-               type = get_c_string( value );
-               value = gh_car( sublist );
-               sublist = gh_cdr( sublist );
-               num = gh_scm2int( value );
-               ai->Collect[DefaultResourceNumber( type )] = num;
-           }
-           list = gh_cdr( list );
-       } else if ( gh_eq_p( value, gh_symbol2scm( "need-mask" ) ) ) {
-           sublist = gh_car( list );
-           while ( !gh_null_p( sublist ) ) {
+               value = gh_car(sublist);
+               sublist = gh_cdr(sublist);
+               type = get_c_string(value);
+               value = gh_car(sublist);
+               sublist = gh_cdr(sublist);
+               num = gh_scm2int(value);
+               ai->Collect[DefaultResourceNumber(type)] = num;
+           }
+           list = gh_cdr(list);
+       } else if (gh_eq_p(value, gh_symbol2scm("need-mask"))) {
+           sublist = gh_car(list);
+           while (!gh_null_p(sublist)) {
                char *type;
-               value = gh_car( sublist );
-               sublist = gh_cdr( sublist );
-               type = get_c_string( value );
-               ai->NeededMask |= ( 1 << DefaultResourceNumber( type ) );
+               value = gh_car(sublist);
+               sublist = gh_cdr(sublist);
+               type = get_c_string(value);
+               ai->NeededMask |= (1 << DefaultResourceNumber(type));
            }
-           list = gh_cdr( list );
-       } else if ( gh_eq_p( value, gh_symbol2scm( "need-food" ) ) ) {
+           list = gh_cdr(list);
+       } else if (gh_eq_p(value, gh_symbol2scm("need-food"))) {
            ai->NeedFood = 1;
-       } else if ( gh_eq_p( value, gh_symbol2scm( "unit-type" ) ) ) {
-           sublist = gh_car( list );
+       } else if (gh_eq_p(value, gh_symbol2scm("unit-type"))) {
+           sublist = gh_car(list);
            i = 0;
-           if ( gh_length( sublist ) ) {
+           if (gh_length(sublist)) {
                ai->UnitTypeRequests =
-                   malloc( gh_length( sublist ) / 2 * sizeof ( AiUnitTypeTable 
) );
+                   malloc(gh_length(sublist) / 2 * sizeof (AiUnitTypeTable));
            }
-           while ( !gh_null_p( sublist ) ) {
+           while (!gh_null_p(sublist)) {
                char *ident;
                int count;
-               value = gh_car( sublist );
-               sublist = gh_cdr( sublist );
-               ident = get_c_string( value );
-               value = gh_car( sublist );
-               sublist = gh_cdr( sublist );
-               count = gh_scm2int( value );
-               ai->UnitTypeRequests[i].Table[0] = UnitTypeByIdent( ident );
+               value = gh_car(sublist);
+               sublist = gh_cdr(sublist);
+               ident = get_c_string(value);
+               value = gh_car(sublist);
+               sublist = gh_cdr(sublist);
+               count = gh_scm2int(value);
+               ai->UnitTypeRequests[i].Table[0] = UnitTypeByIdent(ident);
                ai->UnitTypeRequests[i].Count = count;
                ++i;
            }
            ai->UnitTypeRequestsCount = i;
-           list = gh_cdr( list );
-       } else if ( gh_eq_p( value, gh_symbol2scm( "upgrade" ) ) ) {
-           sublist = gh_car( list );
+           list = gh_cdr(list);
+       } else if (gh_eq_p(value, gh_symbol2scm("upgrade"))) {
+           sublist = gh_car(list);
            i = 0;
-           if ( gh_length( sublist ) ) {
-               ai->UpgradeToRequests = malloc( gh_length( sublist ) * sizeof ( 
UnitType * ) );
+           if (gh_length(sublist)) {
+               ai->UpgradeToRequests = malloc(gh_length(sublist) * sizeof 
(UnitType *));
            }
-           while ( !gh_null_p( sublist ) ) {
+           while (!gh_null_p(sublist)) {
                char *ident;
-               value = gh_car( sublist );
-               sublist = gh_cdr( sublist );
-               ident = get_c_string( value );
-               ai->UpgradeToRequests[i] = UnitTypeByIdent( ident );
+               value = gh_car(sublist);
+               sublist = gh_cdr(sublist);
+               ident = get_c_string(value);
+               ai->UpgradeToRequests[i] = UnitTypeByIdent(ident);
                ++i;
            }
            ai->UpgradeToRequestsCount = i;
-           list = gh_cdr( list );
-       } else if ( gh_eq_p( value, gh_symbol2scm( "research" ) ) ) {
-           sublist = gh_car( list );
+           list = gh_cdr(list);
+       } else if (gh_eq_p(value, gh_symbol2scm("research"))) {
+           sublist = gh_car(list);
            i = 0;
-           if ( gh_length( sublist ) ) {
-               ai->ResearchRequests = malloc( gh_length( sublist ) * sizeof ( 
Upgrade * ) );
+           if (gh_length(sublist)) {
+               ai->ResearchRequests = malloc(gh_length(sublist) * sizeof 
(Upgrade *));
            }
-           while ( !gh_null_p( sublist ) ) {
+           while (!gh_null_p(sublist)) {
                char *ident;
-               value = gh_car( sublist );
-               sublist = gh_cdr( sublist );
-               ident = get_c_string( value );
-               ai->ResearchRequests[i] = UpgradeByIdent( ident );
+               value = gh_car(sublist);
+               sublist = gh_cdr(sublist);
+               ident = get_c_string(value);
+               ai->ResearchRequests[i] = UpgradeByIdent(ident);
                ++i;
            }
            ai->ResearchRequestsCount = i;
-           list = gh_cdr( list );
-       } else if ( gh_eq_p( value, gh_symbol2scm( "building" ) ) ) {
+           list = gh_cdr(list);
+       } else if (gh_eq_p(value, gh_symbol2scm("building"))) {
            AiBuildQueue **queue;
-           sublist = gh_car( list );
+           sublist = gh_car(list);
            queue = &ai->UnitTypeBuilded;
-           while ( !gh_null_p( sublist ) ) {
+           while (!gh_null_p(sublist)) {
                char *ident;
                int made;
                int want;
-               value = gh_car( sublist );
-               sublist = gh_cdr( sublist );
-               ident = get_c_string( value );
-               value = gh_car( sublist );
-               sublist = gh_cdr( sublist );
-               made = gh_scm2int( value );
-               value = gh_car( sublist );
-               sublist = gh_cdr( sublist );
-               want = gh_scm2int( value );
-               *queue = malloc( sizeof ( AiBuildQueue ) );
-               ( *queue )->Next = NULL;
-               ( *queue )->Type = UnitTypeByIdent( ident );
-               ( *queue )->Want = want;
-               ( *queue )->Made = made;
-               queue = &( *queue )->Next;
-           }
-           list = gh_cdr( list );
-       } else if ( gh_eq_p( value, gh_symbol2scm( "repair-building" ) ) ) {
-           ai->LastRepairBuilding = gh_scm2int( gh_car( list ) );
-           list = gh_cdr( list );
-       } else if ( gh_eq_p( value, gh_symbol2scm( "repair-workers" ) ) ) {
-           sublist = gh_car( list );
-           while ( !gh_null_p( sublist ) ) {
+               value = gh_car(sublist);
+               sublist = gh_cdr(sublist);
+               ident = get_c_string(value);
+               value = gh_car(sublist);
+               sublist = gh_cdr(sublist);
+               made = gh_scm2int(value);
+               value = gh_car(sublist);
+               sublist = gh_cdr(sublist);
+               want = gh_scm2int(value);
+               *queue = malloc(sizeof (AiBuildQueue));
+               (*queue)->Next = NULL;
+               (*queue)->Type = UnitTypeByIdent(ident);
+               (*queue)->Want = want;
+               (*queue)->Made = made;
+               queue = &(*queue)->Next;
+           }
+           list = gh_cdr(list);
+       } else if (gh_eq_p(value, gh_symbol2scm("repair-building"))) {
+           ai->LastRepairBuilding = gh_scm2int(gh_car(list));
+           list = gh_cdr(list);
+       } else if (gh_eq_p(value, gh_symbol2scm("repair-workers"))) {
+           sublist = gh_car(list);
+           while (!gh_null_p(sublist)) {
                int num;
                int workers;
-               value = gh_car( sublist );
-               sublist = gh_cdr( sublist );
-               num = gh_scm2int( value );
-               value = gh_car( sublist );
-               sublist = gh_cdr( sublist );
-               workers = gh_scm2int( value );
+               value = gh_car(sublist);
+               sublist = gh_cdr(sublist);
+               num = gh_scm2int(value);
+               value = gh_car(sublist);
+               sublist = gh_cdr(sublist);
+               workers = gh_scm2int(value);
                ai->TriedRepairWorkers[num] = workers;
                ++i;
            }
-           list = gh_cdr( list );
+           list = gh_cdr(list);
        } else {
-          // FIXME: this leaves a half initialized ai player
-           errl( "Unsupported tag", value );
+           // FIXME: this leaves a half initialized ai player
+           errl("Unsupported tag", value);
        }
     }
 #endif
@@ -2340,81 +2272,81 @@
 /**
 **     Register CCL features for unit-type.
 */
-global void AiCclRegister( void )
+global void AiCclRegister(void)
 {
-   // FIXME: Need to save memory here.
-   // Loading all into memory isn't necessary.
+    // FIXME: Need to save memory here.
+    // Loading all into memory isn't necessary.
 
-    gh_new_procedureN( "define-ai-helper", CclDefineAiHelper );
-    gh_new_procedureN( "define-ai", CclDefineAi );
+    gh_new_procedureN("define-ai-helper", CclDefineAiHelper);
+    gh_new_procedureN("define-ai", CclDefineAi);
 
 #ifdef INCOMPLETE_SIOD
-    gh_new_procedure2_0( "quotient", CclQuotient );
-    gh_new_procedure1_0( "output", CclOutput );
+    gh_new_procedure2_0("quotient", CclQuotient);
+    gh_new_procedure1_0("output", CclOutput);
 #endif
-    gh_new_procedure2_0( "define-ai-action", CclDefineAiAction );
+    gh_new_procedure2_0("define-ai-action", CclDefineAiAction);
 
-    gh_new_procedure0_0( "ai:get-race", CclAiGetRace );
-    gh_new_procedure0_0( "ai:get-sleep-cycles", CclAiGetSleepCycles );
+    gh_new_procedure0_0("ai:get-race", CclAiGetRace);
+    gh_new_procedure0_0("ai:get-sleep-cycles", CclAiGetSleepCycles);
 
-    gh_new_procedure1_0( "ai:debug", CclAiDebug );
-    gh_new_procedure1_0( "ai:need", CclAiNeed );
-    gh_new_procedure2_0( "ai:set", CclAiSet );
-    gh_new_procedure1_0( "ai:wait", CclAiWait );
+    gh_new_procedure1_0("ai:debug", CclAiDebug);
+    gh_new_procedure1_0("ai:need", CclAiNeed);
+    gh_new_procedure2_0("ai:set", CclAiSet);
+    gh_new_procedure1_0("ai:wait", CclAiWait);
 
-    gh_new_procedure0_0( "ai:own-force", CclAiOwnForce );
+    gh_new_procedure0_0("ai:own-force", CclAiOwnForce);
 
-    gh_new_procedure1_0( "ai:get-force", CclAiGetForce );
+    gh_new_procedure1_0("ai:get-force", CclAiGetForce);
 
 
-    gh_new_procedureN( "ai:force", CclAiForce );
+    gh_new_procedureN("ai:force", CclAiForce);
 
-    gh_new_procedure2_0( "ai:adhoc-force", CclAiAdHocForce );
+    gh_new_procedure2_0("ai:adhoc-force", CclAiAdHocForce);
 
-    gh_new_procedure1_0( "ai:force-empty", CclAiForceEmpty );
-    gh_new_procedure1_0( "ai:force-active", CclAiForceActive );
-    gh_new_procedure1_0( "ai:force-list", CclAiForce );
-    gh_new_procedure2_0( "ai:force-transfer", CclAiForceTransfert );
-    gh_new_procedure1_0( "ai:force-complete", CclAiForceComplete );
-    gh_new_procedure2_0( "ai:force-role", CclAiForceRole );
-    gh_new_procedure1_0( "ai:is-force-defending", CclAiIsForceDefending );
-    gh_new_procedure1_0( "ai:check-force", CclAiCheckForce );
-    gh_new_procedure1_0( "ai:group-force", CclAiGroupForce );
-    gh_new_procedure1_0( "ai:wait-force", CclAiWaitForce );
-    gh_new_procedure1_0( "ai:clear-force", CclAiClearForce );
-    gh_new_procedure1_0( "ai:evaluate-force-cost", CclAiEvaluateForceCost );
+    gh_new_procedure1_0("ai:force-empty", CclAiForceEmpty);
+    gh_new_procedure1_0("ai:force-active", CclAiForceActive);
+    gh_new_procedure1_0("ai:force-list", CclAiForce);
+    gh_new_procedure2_0("ai:force-transfer", CclAiForceTransfert);
+    gh_new_procedure1_0("ai:force-complete", CclAiForceComplete);
+    gh_new_procedure2_0("ai:force-role", CclAiForceRole);
+    gh_new_procedure1_0("ai:is-force-defending", CclAiIsForceDefending);
+    gh_new_procedure1_0("ai:check-force", CclAiCheckForce);
+    gh_new_procedure1_0("ai:group-force", CclAiGroupForce);
+    gh_new_procedure1_0("ai:wait-force", CclAiWaitForce);
+    gh_new_procedure1_0("ai:clear-force", CclAiClearForce);
+    gh_new_procedure1_0("ai:evaluate-force-cost", CclAiEvaluateForceCost);
 
-    gh_new_procedure1_0( "ai:can-reach-hotspot", CclAiCanReachHotSpot );
+    gh_new_procedure1_0("ai:can-reach-hotspot", CclAiCanReachHotSpot);
 
-    gh_new_procedure1_0( "ai:set-hotspot-ray", CclAiSetHotSpotRay );
-    gh_new_procedure0_0( "ai:compute-gauges", CclAiComputeGauges );
-    gh_new_procedure0_0( "ai:debug-gauges", CclAiDebugGauges );
-    gh_new_procedure1_0( "ai:get-gauge", CclAiGetGauge );
-    gh_new_procedure1_0( "ai:get-unittype-force", CclGetUnitTypeForce );
+    gh_new_procedure1_0("ai:set-hotspot-ray", CclAiSetHotSpotRay);
+    gh_new_procedure0_0("ai:compute-gauges", CclAiComputeGauges);
+    gh_new_procedure0_0("ai:debug-gauges", CclAiDebugGauges);
+    gh_new_procedure1_0("ai:get-gauge", CclAiGetGauge);
+    gh_new_procedure1_0("ai:get-unittype-force", CclGetUnitTypeForce);
 
-    gh_new_procedure0_0( "ai:idle", CclAiIdle );
-    gh_new_procedure2_0( "ai:timed-wait-force", CclAiTimedWaitForce );
-    gh_new_procedure1_0( "ai:attack-with-force", CclAiAttackWithForce );
-    gh_new_procedure1_0( "ai:hotspot-attack-with-force", 
CclAiHotSpotAttackWithForce );
-    gh_new_procedure1_0( "ai:force-go-home", CclAiForceHome );
-    gh_new_procedure1_0( "ai:sleep", CclAiSleep );
-    gh_new_procedure1_0( "ai:research", CclAiResearch );
-    gh_new_procedure1_0( "ai:upgrade-to", CclAiUpgradeTo );
-    gh_new_procedure1_0( "ai:script", CclAiScript );
-    gh_new_procedure1_0( "ai:goto", CclAiSwitchTo );
+    gh_new_procedure0_0("ai:idle", CclAiIdle);
+    gh_new_procedure2_0("ai:timed-wait-force", CclAiTimedWaitForce);
+    gh_new_procedure1_0("ai:attack-with-force", CclAiAttackWithForce);
+    gh_new_procedure1_0("ai:hotspot-attack-with-force", 
CclAiHotSpotAttackWithForce);
+    gh_new_procedure1_0("ai:force-go-home", CclAiForceHome);
+    gh_new_procedure1_0("ai:sleep", CclAiSleep);
+    gh_new_procedure1_0("ai:research", CclAiResearch);
+    gh_new_procedure1_0("ai:upgrade-to", CclAiUpgradeTo);
+    gh_new_procedure1_0("ai:script", CclAiScript);
+    gh_new_procedure1_0("ai:goto", CclAiSwitchTo);
 
-    gh_new_procedure0_0( "ai:restart", CclAiRestart );
+    gh_new_procedure0_0("ai:restart", CclAiRestart);
 
-    gh_new_procedure0_0( "ai:player", CclAiPlayer );
-    gh_new_procedure1_0( "ai:set-reserve!", CclAiSetReserve );
-    gh_new_procedure1_0( "ai:set-collect!", CclAiSetCollect );
-    gh_new_procedure1_0( "ai:set-auto-attack", CclAiSetAutoAttack );
+    gh_new_procedure0_0("ai:player", CclAiPlayer);
+    gh_new_procedure1_0("ai:set-reserve!", CclAiSetReserve);
+    gh_new_procedure1_0("ai:set-collect!", CclAiSetCollect);
+    gh_new_procedure1_0("ai:set-auto-attack", CclAiSetAutoAttack);
 
-    gh_new_procedure0_0( "ai:dump", CclAiDump );
+    gh_new_procedure0_0("ai:dump", CclAiDump);
 
-    gh_new_procedureN( "define-ai-wc-names", CclDefineAiWcNames );
+    gh_new_procedureN("define-ai-wc-names", CclDefineAiWcNames);
 
-    gh_new_procedureN( "define-ai-player", CclDefineAiPlayer );
+    gh_new_procedureN("define-ai-player", CclDefineAiPlayer);
 }
 
 
Index: stratagus/src/ai/new_ai.c
diff -u stratagus/src/ai/new_ai.c:1.77 stratagus/src/ai/new_ai.c:1.78
--- stratagus/src/ai/new_ai.c:1.77      Fri Oct 24 08:29:09 2003
+++ stratagus/src/ai/new_ai.c   Sun Oct 26 10:34:59 2003
@@ -26,12 +26,12 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//      $Id: new_ai.c,v 1.77 2003/10/24 12:29:09 n0body Exp $
+//      $Id: new_ai.c,v 1.78 2003/10/26 15:34:59 pludov Exp $
 
 
 //@{
 
-#define noTIMEIT               /// Enable CPU use debugging
+#define noTIMEIT                       /// Enable CPU use debugging
 
 //----------------------------------------------------------------------------
 //      Documentation
@@ -154,16 +154,16 @@
 --     Variables
 ----------------------------------------------------------------------------*/
 
-global int AiSleepCycles;      /// Ai sleeps # cycles
-global int AiTimeFactor = 100; /// Adjust the AI build times
-global int AiCostFactor = 100; /// Adjust the AI costs
+global int AiSleepCycles;              /// Ai sleeps # cycles
+global int AiTimeFactor = 100;         /// Adjust the AI build times
+global int AiCostFactor = 100;         /// Adjust the AI costs
 
-global AiType *AiTypes;                /// List of all AI types.
-global AiHelper AiHelpers;     /// AI helper variables
+global AiType *AiTypes;                        /// List of all AI types.
+global AiHelper AiHelpers;             /// AI helper variables
 global int AiScriptActionNum = 0;      /// number of action script ( FIXME : 
initialized only once )
 global AiScriptAction AiScriptActions[MaxAiScriptActions];     /// definitions 
of action scripts
 
-global PlayerAi *AiPlayer;     /// Current AI player
+global PlayerAi *AiPlayer;             /// Current AI player
 global AiRunningScript *AiScript;      /// Current AI script
 /**
 **     W*rCr*ft number to internal ai-type name.
@@ -174,53 +174,53 @@
 --     Lowlevel functions
 ----------------------------------------------------------------------------*/
 
-local void debugForces()
+local void debugForces(void)
 {
     const AiUnit *aiunit;
     const AiUnitType *aiunittype;
     int force, i;
     int count[UnitTypeMax];
 
-    DebugLevel3Fn( " ! : completed    A/D : attacking/defending\n" );
-    for ( force = 0; force < AI_MAX_FORCES; force++ ) {
-       DebugLevel3Fn( "force %5d %c%c :" _C_
-                      force _C_
-                      ( AiPlayer->Force[force].Role == AiForceRoleAttack ? 'A' 
: 'D' ) _C_
-                      ( AiPlayer->Force[force].Completed ? '!' : ' ' ) );
+    DebugLevel3Fn(" ! : completed    A/D : attacking/defending\n");
+    for (force = 0; force < AI_MAX_FORCES; force++) {
+       DebugLevel3Fn("force %5d %c%c :" _C_
+           force _C_
+           (AiPlayer->Force[force].Role == AiForceRoleAttack ? 'A' : 'D') _C_
+           (AiPlayer->Force[force].Completed ? '!' : ' '));
 
-       for ( i = 0; i < UnitTypeMax; i++ ) {
+       for (i = 0; i < UnitTypeMax; i++) {
            count[i] = 0;
        }
 
        aiunit = AiPlayer->Force[force].Units;
 
-       while ( aiunit ) {
+       while (aiunit) {
            count[aiunit->Unit->Type->Type]++;
            aiunit = aiunit->Next;
        }
 
        aiunittype = AiPlayer->Force[force].UnitTypes;
-       while ( aiunittype ) {
-           DebugLevel3Fn( " %s(%d/%d)" _C_ aiunittype->Type->
-                          Ident _C_ count[aiunittype->Type->Type] _C_ 
aiunittype->Want );
+       while (aiunittype) {
+           DebugLevel3Fn(" %s(%d/%d)" _C_ aiunittype->Type->
+               Ident _C_ count[aiunittype->Type->Type] _C_ aiunittype->Want);
            count[aiunittype->Type->Type] = 0;
            aiunittype = aiunittype->Next;
        }
 
-       for ( i = 0; i < UnitTypeMax; i++ ) {
-           if ( count[i] ) {
-               DebugLevel3Fn( " %s(%d/0)" _C_ UnitTypes[i]->Ident _C_ count[i] 
);
+       for (i = 0; i < UnitTypeMax; i++) {
+           if (count[i]) {
+               DebugLevel3Fn(" %s(%d/0)" _C_ UnitTypes[i]->Ident _C_ count[i]);
            }
        }
 
-       DebugLevel3Fn( "\n" );
+       DebugLevel3Fn("\n");
     }
 }
 
 /**
 **     Execute the AI Script.
 */
-local void AiExecuteScripts( void )
+local void AiExecuteScripts(void)
 {
     int i;
     PlayerAi *pai;
@@ -228,21 +228,21 @@
 
     pai = AiPlayer;
     debugForces();
-    for ( i = 0; i < AI_MAX_RUNNING_SCRIPTS; i++ ) {
+    for (i = 0; i < AI_MAX_RUNNING_SCRIPTS; i++) {
        AiScript = pai->Scripts + i;
-       if ( !gh_null_p( AiScript->Script ) ) {
-          /*
-             if( pai->ScriptDebug ) {         // display executed command
-             DebugLevel3Fn("%d.%d (%12s) @ %3d.%3d :" _C_ pai->Player->Player 
_C_ i _C_ AiScript->ident _C_ AiScript->HotSpot_X _C_ AiScript->HotSpot_Y);
-             gh_display(AiScript->Script);
-             gh_newline();
-             } */
-           value = gh_eval( gh_car( AiScript->Script ), NIL );
-           if ( !gh_eq_p( value, SCM_BOOL_T ) ) {
-               AiScript->Script = gh_cdr( AiScript->Script );
+       if (!gh_null_p(AiScript->Script)) {
+           /*
+              if( pai->ScriptDebug ) {         // display executed command
+              DebugLevel3Fn("%d.%d (%12s) @ %3d.%3d :" _C_ pai->Player->Player 
_C_ i _C_ AiScript->ident _C_ AiScript->HotSpot_X _C_ AiScript->HotSpot_Y);
+              gh_display(AiScript->Script);
+              gh_newline();
+              } */
+           value = gh_eval(gh_car(AiScript->Script), NIL);
+           if (!gh_eq_p(value, SCM_BOOL_T)) {
+               AiScript->Script = gh_cdr(AiScript->Script);
            }
-           if ( ( gh_null_p( AiScript->Script ) ) && ( AiScript->ownForce ) ) {
-               AiEraseForce( AiScript->ownForce );
+           if ((gh_null_p(AiScript->Script)) && (AiScript->ownForce)) {
+               AiEraseForce(AiScript->ownForce);
            }
        }
     }
@@ -251,7 +251,7 @@
 /**
 **     Check if everything is fine, send new requests to resource manager.
 */
-local void AiCheckUnits( void )
+local void AiCheckUnits(void)
 {
     int counter[UnitTypeMax];
     const AiBuildQueue *queue;
@@ -263,89 +263,91 @@
     int x;
     int e;
 
-    memset( counter, 0, sizeof ( counter ) );
+    memset(counter, 0, sizeof (counter));
 
-   //
-   //  Count the already made build requests.
-   //
-    for ( queue = AiPlayer->UnitTypeBuilded; queue; queue = queue->Next ) {
+    //
+    //  Count the already made build requests.
+    //
+    for (queue = AiPlayer->UnitTypeBuilded; queue; queue = queue->Next) {
        counter[queue->Type->Type] += queue->Want;
-       DebugLevel3Fn( "Already in build queue: %s %d/%d\n" _C_
-                      queue->Type->Ident _C_ queue->Made _C_ queue->Want );
+       DebugLevel3Fn("Already in build queue: %s %d/%d\n" _C_
+           queue->Type->Ident _C_ queue->Made _C_ queue->Want);
     }
 
-   //
-   //  Remove non active units.
-   //
+    //
+    //  Remove non active units.
+    //
     n = AiPlayer->Player->TotalNumUnits;
-    for ( i = 0; i < n; ++i ) {
-       if ( !AiPlayer->Player->Units[i]->Active ) {
+    for (i = 0; i < n; ++i) {
+       if (!AiPlayer->Player->Units[i]->Active) {
            counter[AiPlayer->Player->Units[i]->Type->Type]--;
-           DebugLevel3Fn( "Removing non active unit: %s\n" _C_
-                          AiPlayer->Player->Units[i]->Type->Ident );
+           DebugLevel3Fn("Removing non active unit: %s\n" _C_
+               AiPlayer->Player->Units[i]->Type->Ident);
        }
     }
     unit_types_count = AiPlayer->Player->UnitTypesCount;
 
-   //
-   //  Look if some unit-types are missing.
-   //
+    //
+    //  Look if some unit-types are missing.
+    //
     n = AiPlayer->UnitTypeRequestsCount;
-    for ( i = 0; i < n; ++i ) {
+    for (i = 0; i < n; ++i) {
        t = AiPlayer->UnitTypeRequests[i].Table[0]->Type;
        x = AiPlayer->UnitTypeRequests[i].Count;
 
-       //
-       //      Add equivalent units
-       //
+       //
+       //      Add equivalent units
+       //
        e = unit_types_count[t];
-       if ( t < AiHelpers.EquivCount && AiHelpers.Equiv[t] ) {
-           DebugLevel3Fn( "Equivalence for %s\n" _C_
-                          AiPlayer->UnitTypeRequests[i].Table[0]->Ident );
-           for ( j = 0; j < AiHelpers.Equiv[t]->Count; ++j ) {
+       if (t < AiHelpers.EquivCount && AiHelpers.Equiv[t]) {
+           DebugLevel3Fn("Equivalence for %s\n" _C_
+               AiPlayer->UnitTypeRequests[i].Table[0]->Ident);
+           for (j = 0; j < AiHelpers.Equiv[t]->Count; ++j) {
                e += unit_types_count[AiHelpers.Equiv[t]->Table[j]->Type];
            }
        }
 
-       if ( x > e + counter[t] ) {     // Request it.
-           DebugLevel3Fn( "Need %s *%d\n" _C_
-                          AiPlayer->UnitTypeRequests[i].Table[0]->Ident _C_ x 
);
-           AiAddUnitTypeRequest( AiPlayer->UnitTypeRequests[i].Table[0], x - e 
- counter[t] );
+       if (x > e + counter[t]) {       // Request it.
+           DebugLevel3Fn("Need %s *%d\n" _C_
+               AiPlayer->UnitTypeRequests[i].Table[0]->Ident _C_ x);
+           AiAddUnitTypeRequest(AiPlayer->UnitTypeRequests[i].Table[0],
+               x - e - counter[t]);
            counter[t] += x - e - counter[t];
        }
        counter[t] -= x;
     }
 
-   //
-   // Magically complete all forces
-   //
-    for ( i = 0; i < AI_MAX_FORCES; ++i ) {
-       if ( ( !AiPlayer->Force[i].Completed ) &&
-            ( ( AiPlayer->Force[i].PopulateMode == AiForcePopulateFromAttack ) 
||
-              ( AiPlayer->Force[i].PopulateMode == AiForcePopulateAny ) ) ) {
-
-          // This force should be completed from other forces.
-           AiForceComplete( i );
+    //
+    // Magically complete all forces
+    //
+    for (i = 0; i < AI_MAX_FORCES; ++i) {
+       if ((!AiPlayer->Force[i].Completed) &&
+           ((AiPlayer->Force[i].PopulateMode == AiForcePopulateFromAttack) ||
+               (AiPlayer->Force[i].PopulateMode == AiForcePopulateAny))) {
+
+           // This force should be completed from other forces.
+           AiForceComplete(i);
        }
     }
 
-   //
-   // create missing units
-   //
-    for ( i = 0; i < AI_MAX_FORCES; ++i ) {
+    //
+    // create missing units
+    //
+    for (i = 0; i < AI_MAX_FORCES; ++i) {
        const AiUnitType *aiut;
 
-       // Create units only for AiForceCreateFromScratch forces
-       if ( AiPlayer->Force[i].PopulateMode != AiForcePopulateFromScratch ) {
+       // Create units only for AiForceCreateFromScratch forces
+       if (AiPlayer->Force[i].PopulateMode != AiForcePopulateFromScratch) {
            continue;
        }
 
-       for ( aiut = AiPlayer->Force[i].UnitTypes; aiut; aiut = aiut->Next ) {
+       for (aiut = AiPlayer->Force[i].UnitTypes; aiut; aiut = aiut->Next) {
            t = aiut->Type->Type;
            x = aiut->Want;
-           if ( x > unit_types_count[t] + counter[t] ) {       // Request it.
-               DebugLevel2Fn( "Force %d need %s * %d\n" _C_ i _C_ 
aiut->Type->Ident _C_ x );
-               AiAddUnitTypeRequest( aiut->Type, x - unit_types_count[t] - 
counter[t] );
+           if (x > unit_types_count[t] + counter[t]) { // Request it.
+               DebugLevel2Fn("Force %d need %s * %d\n" _C_ i _C_ aiut->Type->
+                   Ident _C_ x);
+               AiAddUnitTypeRequest(aiut->Type, x - unit_types_count[t] - 
counter[t]);
                counter[t] += x - unit_types_count[t] - counter[t];
                AiPlayer->Force[i].Completed = 0;
            }
@@ -353,44 +355,45 @@
        }
     }
 
-   //
-   //  Look if some upgrade-to are missing.
-   //
+    //
+    //  Look if some upgrade-to are missing.
+    //
     n = AiPlayer->UpgradeToRequestsCount;
-    for ( i = 0; i < n; ++i ) {
+    for (i = 0; i < n; ++i) {
        t = AiPlayer->UpgradeToRequests[i]->Type;
        x = 1;
 
-       //
-       //      Add equivalent units
-       //
+       //
+       //      Add equivalent units
+       //
        e = unit_types_count[t];
-       if ( t < AiHelpers.EquivCount && AiHelpers.Equiv[t] ) {
-           DebugLevel3Fn( "Equivalence for %s\n" _C_ 
AiPlayer->UpgradeToRequests[i]->Ident );
-           for ( j = 0; j < AiHelpers.Equiv[t]->Count; ++j ) {
+       if (t < AiHelpers.EquivCount && AiHelpers.Equiv[t]) {
+           DebugLevel3Fn("Equivalence for %s\n" _C_ 
AiPlayer->UpgradeToRequests[i]->
+               Ident);
+           for (j = 0; j < AiHelpers.Equiv[t]->Count; ++j) {
                e += unit_types_count[AiHelpers.Equiv[t]->Table[j]->Type];
            }
        }
 
-       if ( x > e + counter[t] ) {     // Request it.
-           AiAddUpgradeToRequest( AiPlayer->UpgradeToRequests[i] );
+       if (x > e + counter[t]) {       // Request it.
+           AiAddUpgradeToRequest(AiPlayer->UpgradeToRequests[i]);
            counter[t] += x - e - counter[t];
        }
        counter[t] -= x;
     }
 
-   //
-   //  Look if some researches are missing.
-   //
+    //
+    //  Look if some researches are missing.
+    //
     n = AiPlayer->ResearchRequestsCount;
-    for ( i = 0; i < n; ++i ) {
-       DebugLevel3Fn( "%s - %c\n" _C_
-                      AiPlayer->ResearchRequests[i]->Ident _C_
-                      UpgradeIdAllowed( AiPlayer->Player,
-                                        AiPlayer->ResearchRequests[i] - 
Upgrades ) );
-       if ( UpgradeIdAllowed( AiPlayer->Player,
-                              AiPlayer->ResearchRequests[i] - Upgrades ) == 
'A' ) {
-           AiAddResearchRequest( AiPlayer->ResearchRequests[i] );
+    for (i = 0; i < n; ++i) {
+       DebugLevel3Fn("%s - %c\n" _C_
+           AiPlayer->ResearchRequests[i]->Ident _C_
+           UpgradeIdAllowed(AiPlayer->Player,
+               AiPlayer->ResearchRequests[i] - Upgrades));
+       if (UpgradeIdAllowed(AiPlayer->Player,
+               AiPlayer->ResearchRequests[i] - Upgrades) == 'A') {
+           AiAddResearchRequest(AiPlayer->ResearchRequests[i]);
        }
     }
 }
@@ -404,25 +407,25 @@
 **
 **     @param file     Output file.
 */
-local void SaveAiTypesWcName( CLFile * file )
+local void SaveAiTypesWcName(CLFile * file)
 {
     char **cp;
     int i;
 
-   //
-   //  Dump table wc2 race numbers -> internal symbol.
-   //
-    if ( ( cp = AiTypeWcNames ) ) {
-       CLprintf( file, "(define-ai-wc-names" );
+    //
+    //  Dump table wc2 race numbers -> internal symbol.
+    //
+    if ((cp = AiTypeWcNames)) {
+       CLprintf(file, "(define-ai-wc-names");
 
        i = 90;
-       while ( *cp ) {
-           if ( i + strlen( *cp ) > 79 ) {
-               i = CLprintf( file, "\n " );
+       while (*cp) {
+           if (i + strlen(*cp) > 79) {
+               i = CLprintf(file, "\n ");
            }
-           i += CLprintf( file, " '%s", *cp++ );
+           i += CLprintf(file, " '%s", *cp++);
        }
-       CLprintf( file, ")\n\n" );
+       CLprintf(file, ")\n\n");
     }
 }
 
@@ -435,42 +438,42 @@
 **     @param n        Number of elements in table
 **     @param table    unit-type table.
 */
-local void SaveAiHelperTable( CLFile * file, const char *name, int upgrade, 
int n,
-                             AiUnitTypeTable * const *table )
+local void SaveAiHelperTable(CLFile * file, const char *name, int upgrade, int 
n,
+    AiUnitTypeTable * const *table)
 {
     int t;
     int i;
     int j;
     int f;
 
-    for ( t = 0; t < ( upgrade ? UpgradeMax : NumUnitTypes ); ++t ) {
-       // Look if that unit-type can build something
-       for ( f = i = 0; i < n; ++i ) {
-           if ( table[i] ) {
-               for ( j = 0; j < table[i]->Count; ++j ) {
-                   if ( table[i]->Table[j]->Type == t ) {
-                       if ( !f ) {
-                           CLprintf( file, "\n  (list '%s '%s\n    ", name,
-                                     UnitTypes[t]->Ident );
+    for (t = 0; t < (upgrade ? UpgradeMax : NumUnitTypes); ++t) {
+       // Look if that unit-type can build something
+       for (f = i = 0; i < n; ++i) {
+           if (table[i]) {
+               for (j = 0; j < table[i]->Count; ++j) {
+                   if (table[i]->Table[j]->Type == t) {
+                       if (!f) {
+                           CLprintf(file, "\n  (list '%s '%s\n    ", name,
+                               UnitTypes[t]->Ident);
                            f = 4;
                        }
-                       if ( upgrade ) {
-                           if ( f + strlen( Upgrades[i].Ident ) > 78 ) {
-                               f = CLprintf( file, "\n    " );
+                       if (upgrade) {
+                           if (f + strlen(Upgrades[i].Ident) > 78) {
+                               f = CLprintf(file, "\n    ");
                            }
-                           f += CLprintf( file, "'%s ", Upgrades[i].Ident );
+                           f += CLprintf(file, "'%s ", Upgrades[i].Ident);
                        } else {
-                           if ( f + strlen( UnitTypes[i]->Ident ) > 78 ) {
-                               f = CLprintf( file, "\n    " );
+                           if (f + strlen(UnitTypes[i]->Ident) > 78) {
+                               f = CLprintf(file, "\n    ");
                            }
-                           f += CLprintf( file, "'%s ", UnitTypes[i]->Ident );
+                           f += CLprintf(file, "'%s ", UnitTypes[i]->Ident);
                        }
                    }
                }
            }
        }
-       if ( f ) {
-           CLprintf( file, ")" );
+       if (f) {
+           CLprintf(file, ")");
        }
     }
 }
@@ -483,24 +486,24 @@
 **     @param n        Number of elements in table
 **     @param table    unit-type table.
 */
-local void SaveAiEquivTable( CLFile * file, const char *name, int n,
-                            AiUnitTypeTable * const *table )
+local void SaveAiEquivTable(CLFile * file, const char *name, int n,
+    AiUnitTypeTable * const *table)
 {
     int i;
     int j;
     int f;
 
-    for ( i = 0; i < n; ++i ) {
-       if ( table[i] ) {
-           CLprintf( file, "\n  (list '%s '%s\n    ", name, 
UnitTypes[i]->Ident );
+    for (i = 0; i < n; ++i) {
+       if (table[i]) {
+           CLprintf(file, "\n  (list '%s '%s\n    ", name, 
UnitTypes[i]->Ident);
            f = 4;
-           for ( j = 0; j < table[i]->Count; ++j ) {
-               if ( f + strlen( table[i]->Table[j]->Ident ) > 78 ) {
-                   f = CLprintf( file, "\n    " );
+           for (j = 0; j < table[i]->Count; ++j) {
+               if (f + strlen(table[i]->Table[j]->Ident) > 78) {
+                   f = CLprintf(file, "\n    ");
                }
-               f += CLprintf( file, "'%s ", table[i]->Table[j]->Ident );
+               f += CLprintf(file, "'%s ", table[i]->Table[j]->Ident);
            }
-           CLprintf( file, ")" );
+           CLprintf(file, ")");
        }
     }
 }
@@ -513,35 +516,35 @@
 **     @param n        Number of elements in table
 **     @param table    unit-type table.
 */
-local void SaveAiCostTable( CLFile * file, const char *name, int n,
-                           AiUnitTypeTable * const *table )
+local void SaveAiCostTable(CLFile * file, const char *name, int n,
+    AiUnitTypeTable * const *table)
 {
     int t;
     int i;
     int j;
     int f;
 
-    for ( t = 0; t < NumUnitTypes; ++t ) {
-       // Look if that unit-type can build something
-       for ( f = i = 0; i < n; ++i ) {
-           if ( table[i] ) {
-               for ( j = 0; j < table[i]->Count; ++j ) {
-                   if ( table[i]->Table[j]->Type == t ) {
-                       if ( !f ) {
-                           CLprintf( file, "\n  (list '%s '%s\n    ", name,
-                                     UnitTypes[t]->Ident );
+    for (t = 0; t < NumUnitTypes; ++t) {
+       // Look if that unit-type can build something
+       for (f = i = 0; i < n; ++i) {
+           if (table[i]) {
+               for (j = 0; j < table[i]->Count; ++j) {
+                   if (table[i]->Table[j]->Type == t) {
+                       if (!f) {
+                           CLprintf(file, "\n  (list '%s '%s\n    ", name,
+                               UnitTypes[t]->Ident);
                            f = 4;
                        }
-                       if ( f + strlen( DefaultResourceNames[i] ) > 78 ) {
-                           f = CLprintf( file, "\n    " );
+                       if (f + strlen(DefaultResourceNames[i]) > 78) {
+                           f = CLprintf(file, "\n    ");
                        }
-                       f += CLprintf( file, "'%s ", DefaultResourceNames[i] );
+                       f += CLprintf(file, "'%s ", DefaultResourceNames[i]);
                    }
                }
            }
        }
-       if ( f ) {
-           CLprintf( file, ")" );
+       if (f) {
+           CLprintf(file, ")");
        }
     }
 }
@@ -554,35 +557,35 @@
 **     @param n        Number of elements in table
 **     @param table    unit-type table.
 */
-local void SaveAiUnitLimitTable( CLFile * file, const char *name, int n,
-                                AiUnitTypeTable * const *table )
+local void SaveAiUnitLimitTable(CLFile * file, const char *name, int n,
+    AiUnitTypeTable * const *table)
 {
     int t;
     int i;
     int j;
     int f;
 
-    for ( t = 0; t < NumUnitTypes; ++t ) {
-       // Look if that unit-type can build something
-       for ( f = i = 0; i < n; ++i ) {
-           if ( table[i] ) {
-               for ( j = 0; j < table[i]->Count; ++j ) {
-                   if ( table[i]->Table[j]->Type == t ) {
-                       if ( !f ) {
-                           CLprintf( file, "\n  (list '%s '%s\n    ", name,
-                                     UnitTypes[t]->Ident );
+    for (t = 0; t < NumUnitTypes; ++t) {
+       // Look if that unit-type can build something
+       for (f = i = 0; i < n; ++i) {
+           if (table[i]) {
+               for (j = 0; j < table[i]->Count; ++j) {
+                   if (table[i]->Table[j]->Type == t) {
+                       if (!f) {
+                           CLprintf(file, "\n  (list '%s '%s\n    ", name,
+                               UnitTypes[t]->Ident);
                            f = 4;
                        }
-                       if ( f + strlen( "food" ) > 78 ) {
-                           f = CLprintf( file, "\n    " );
+                       if (f + strlen("food") > 78) {
+                           f = CLprintf(file, "\n    ");
                        }
-                       f += CLprintf( file, "'%s ", "food" );
+                       f += CLprintf(file, "'%s ", "food");
                    }
                }
            }
        }
-       if ( f ) {
-           CLprintf( file, ")" );
+       if (f) {
+           CLprintf(file, ")");
        }
     }
 }
@@ -592,45 +595,46 @@
 **
 **     @param file     Output file.
 */
-local void SaveAiHelper( CLFile * file )
+local void SaveAiHelper(CLFile * file)
 {
-    CLprintf( file, "(define-ai-helper" );
-   //
-   //  Save build table
-   //
-    SaveAiHelperTable( file, "build", 0, AiHelpers.BuildCount, AiHelpers.Build 
);
-
-   //
-   //  Save train table
-   //
-    SaveAiHelperTable( file, "train", 0, AiHelpers.TrainCount, AiHelpers.Train 
);
-
-   //
-   //  Save upgrade table
-   //
-    SaveAiHelperTable( file, "upgrade", 0, AiHelpers.UpgradeCount, 
AiHelpers.Upgrade );
-
-   //
-   //  Save research table
-   //
-    SaveAiHelperTable( file, "research", 1, AiHelpers.ResearchCount, 
AiHelpers.Research );
-
-   //
-   //  Save repair table
-   //
-    SaveAiHelperTable( file, "repair", 0, AiHelpers.RepairCount, 
AiHelpers.Repair );
-
-   //
-   //  Save limits table
-   //
-    SaveAiUnitLimitTable( file, "unit-limit", AiHelpers.UnitLimitCount, 
AiHelpers.UnitLimit );
-
-   //
-   //  Save equivalence table
-   //
-    SaveAiEquivTable( file, "unit-equiv", AiHelpers.EquivCount, 
AiHelpers.Equiv );
+    CLprintf(file, "(define-ai-helper");
+    //
+    //  Save build table
+    //
+    SaveAiHelperTable(file, "build", 0, AiHelpers.BuildCount, AiHelpers.Build);
+
+    //
+    //  Save train table
+    //
+    SaveAiHelperTable(file, "train", 0, AiHelpers.TrainCount, AiHelpers.Train);
+
+    //
+    //  Save upgrade table
+    //
+    SaveAiHelperTable(file, "upgrade", 0, AiHelpers.UpgradeCount, 
AiHelpers.Upgrade);
+
+    //
+    //  Save research table
+    //
+    SaveAiHelperTable(file, "research", 1, AiHelpers.ResearchCount, 
AiHelpers.Research);
+
+    //
+    //  Save repair table
+    //
+    SaveAiHelperTable(file, "repair", 0, AiHelpers.RepairCount, 
AiHelpers.Repair);
+
+    //
+    //  Save limits table
+    //
+    SaveAiUnitLimitTable(file, "unit-limit", AiHelpers.UnitLimitCount,
+       AiHelpers.UnitLimit);
+
+    //
+    //  Save equivalence table
+    //
+    SaveAiEquivTable(file, "unit-equiv", AiHelpers.EquivCount, 
AiHelpers.Equiv);
 
-    CLprintf( file, " )\n\n" );
+    CLprintf(file, " )\n\n");
 }
 
 /**
@@ -638,21 +642,21 @@
 **
 **     @param file     Output file
 */
-local void SaveAiScriptActions( CLFile * file )
+local void SaveAiScriptActions(CLFile * file)
 {
     AiScriptAction *aiScriptAction;
     int i;
 
-   // FIXME : should import the built-in lambda as well ( really needed ? )
-    for ( i = 0; i < AiScriptActionNum; i++ ) {
+    // FIXME : should import the built-in lambda as well ( really needed ? )
+    for (i = 0; i < AiScriptActionNum; i++) {
        aiScriptAction = AiScriptActions + i;
 
-       CLprintf( file, "(define-ai-action '(%s%s)\n  '",
-                 ( aiScriptAction->Defensive ? " defense " : "" ),
-                 ( aiScriptAction->Offensive ? " attack " : "" ) );
+       CLprintf(file, "(define-ai-action '(%s%s)\n  '",
+           (aiScriptAction->Defensive ? " defense " : ""),
+           (aiScriptAction->Offensive ? " attack " : ""));
 
-       lprin1CL( aiScriptAction->Action, file );
-       CLprintf( file, "\n)\n" );
+       lprin1CL(aiScriptAction->Action, file);
+       CLprintf(file, "\n)\n");
     }
 }
 
@@ -662,26 +666,26 @@
 **     @param file     Output file.
 **     @param aitype   AI type to save.
 */
-local void SaveAiType( CLFile * file, const AiType * aitype )
+local void SaveAiType(CLFile * file, const AiType * aitype)
 {
     SCM list;
 
-    if ( aitype->Next ) {
-       SaveAiType( file, aitype->Next );
+    if (aitype->Next) {
+       SaveAiType(file, aitype->Next);
     }
-    DebugLevel3Fn( "%s,%s,%s\n" _C_ aitype->Name _C_ aitype->Race _C_ 
aitype->Class );
-    CLprintf( file, "(define-ai \"%s\" '%s '%s\n",
-             aitype->Name, aitype->Race ? aitype->Race : "*", aitype->Class );
+    DebugLevel3Fn("%s,%s,%s\n" _C_ aitype->Name _C_ aitype->Race _C_ 
aitype->Class);
+    CLprintf(file, "(define-ai \"%s\" '%s '%s\n",
+       aitype->Name, aitype->Race ? aitype->Race : "*", aitype->Class);
 
-    CLprintf( file, "  '(" );
-   //  Print the script a little formated
+    CLprintf(file, "  '(");
+    //  Print the script a little formated
     list = aitype->Script;
-    while ( !gh_null_p( list ) ) {
-       CLprintf( file, "\n    " );
-       //lprin1CL(gh_car(list),file);
-       list = gh_cdr( list );
+    while (!gh_null_p(list)) {
+       CLprintf(file, "\n    ");
+       //lprin1CL(gh_car(list),file);
+       list = gh_cdr(list);
     }
-    CLprintf( file, " ))\n\n" );
+    CLprintf(file, " ))\n\n");
 }
 
 /**
@@ -689,12 +693,12 @@
 **
 **     @param file     Output file.
 */
-local void SaveAiTypes( CLFile * file )
+local void SaveAiTypes(CLFile * file)
 {
-    SaveAiType( file, AiTypes );
+    SaveAiType(file, AiTypes);
 
-   // FIXME: Must save references to other scripts - scheme functions
-   // Perhaps we should dump the complete scheme state
+    // FIXME: Must save references to other scripts - scheme functions
+    // Perhaps we should dump the complete scheme state
 }
 
 /**
@@ -704,7 +708,7 @@
 **     @param plynr    Player number.
 **     @param ai       Player AI.
 */
-local void SaveAiPlayer(CLFile* file, unsigned plynr, const PlayerAi * ai)
+local void SaveAiPlayer(CLFile * file, unsigned plynr, const PlayerAi * ai)
 {
     IOOutFile = file;
     IOLoadingMode = 0;
@@ -720,13 +724,13 @@
 **
 **     @param file     Output file.
 */
-local void SaveAiPlayers( CLFile * file )
+local void SaveAiPlayers(CLFile * file)
 {
     unsigned p;
 
-    for ( p = 0; p < PlayerMax; ++p ) {
-       if ( Players[p].Ai ) {
-           SaveAiPlayer( file, p, Players[p].Ai );
+    for (p = 0; p < PlayerMax; ++p) {
+       if (Players[p].Ai) {
+           SaveAiPlayer(file, p, Players[p].Ai);
        }
     }
 }
@@ -736,19 +740,19 @@
 **
 **     @param file     Output file.
 */
-global void SaveAi( CLFile * file )
+global void SaveAi(CLFile * file)
 {
-    CLprintf( file, "\n;;; -----------------------------------------\n" );
-    CLprintf( file,
-             ";;; MODULE: AI $Id: new_ai.c,v 1.77 2003/10/24 12:29:09 n0body 
Exp $\n\n" );
-
-    SaveAiTypesWcName( file );
-    SaveAiHelper( file );
-    SaveAiTypes( file );
-    SaveAiScriptActions( file );
-    SaveAiPlayers( file );
+    CLprintf(file, "\n;;; -----------------------------------------\n");
+    CLprintf(file,
+       ";;; MODULE: AI $Id: new_ai.c,v 1.78 2003/10/26 15:34:59 pludov Exp 
$\n\n");
+
+    SaveAiTypesWcName(file);
+    SaveAiHelper(file);
+    SaveAiTypes(file);
+    SaveAiScriptActions(file);
+    SaveAiPlayers(file);
 
-    DebugLevel0Fn( "FIXME: Saving AI isn't supported\n" );
+    DebugLevel0Fn("FIXME: Saving AI isn't supported\n");
 }
 
 /**
@@ -756,24 +760,24 @@
 **
 **      @param player   The player structure pointer.
 */
-global void AiInit( Player * player )
+global void AiInit(Player * player)
 {
     int i;
     PlayerAi *pai;
     AiType *ait;
     char *ainame;
 
-    DebugLevel0Fn( "%d - %s -" _C_ player->Player _C_ player->Name );
+    DebugLevel0Fn("%d - %s -" _C_ player->Player _C_ player->Name);
 
-    pai = calloc( 1, sizeof ( PlayerAi ) );
-    if ( !pai ) {
-       fprintf( stderr, "Out of memory.\n" );
-       exit( 0 );
+    pai = calloc(1, sizeof (PlayerAi));
+    if (!pai) {
+       fprintf(stderr, "Out of memory.\n");
+       exit(0);
     }
     pai->Player = player;
     ait = AiTypes;
 
-    for ( i = 0; i < AI_MAX_RUNNING_SCRIPTS; i++ ) {
+    for (i = 0; i < AI_MAX_RUNNING_SCRIPTS; i++) {
        pai->Scripts[i].ownForce = AI_GENERIC_FORCES + i;
        pai->Scripts[i].HotSpot_X = -1;
        pai->Scripts[i].HotSpot_Y = -1;
@@ -781,17 +785,17 @@
        pai->Scripts[i].gauges = 0;
        pai->Scripts[i].SleepCycles = 0;
        pai->Scripts[i].Script = NIL;
-       snprintf( pai->Scripts[i].ident, 10, "Empty" );
+       snprintf(pai->Scripts[i].ident, 10, "Empty");
     }
 
-   // Set autoattack to 1 as default
+    // Set autoattack to 1 as default
     pai->AutoAttack = 1;
 
-    for ( i = 0; i < AI_GENERIC_FORCES; i++ ) {
-       // First force defend, others are attacking...
-       pai->Force[i].Role = ( i ? AiForceRoleAttack : AiForceRoleDefend );
+    for (i = 0; i < AI_GENERIC_FORCES; i++) {
+       // First force defend, others are attacking...
+       pai->Force[i].Role = (i ? AiForceRoleAttack : AiForceRoleDefend);
 
-       // Theses forces should be built from scratch
+       // Theses forces should be built from scratch
        pai->Force[i].PopulateMode = AiForcePopulateFromScratch;
        pai->Force[i].UnitsReusable = 1;
        pai->Force[i].HelpMode = AiForceHelpFull;
@@ -799,52 +803,52 @@
 
 
     ainame = AiTypeWcNames[player->AiNum];
-    DebugLevel0( " looking for class %s\n" _C_ ainame );
+    DebugLevel0(" looking for class %s\n" _C_ ainame);
 
-   //
-   //  Search correct AI type.
-   //
-    if ( !ait ) {
+    //
+    //  Search correct AI type.
+    //
+    if (!ait) {
        DebugLevel0Fn
-           ( "AI: Got no scripts at all! You need at least one dummy fallback 
script.\n" );
-       DebugLevel0Fn( "AI: Look at the (define-ai) documentation.\n" );
-       exit( 0 );
+           ("AI: Got no scripts at all! You need at least one dummy fallback 
script.\n");
+       DebugLevel0Fn("AI: Look at the (define-ai) documentation.\n");
+       exit(0);
     }
-    for ( ;; ) {
-       if ( ait->Race && strcmp( ait->Race, player->RaceName ) ) {
+    for (;;) {
+       if (ait->Race && strcmp(ait->Race, player->RaceName)) {
            ait = ait->Next;
-           if ( !ait && ainame ) {
+           if (!ait && ainame) {
                ainame = NULL;
                ait = AiTypes;
            }
-           if ( !ait ) {
+           if (!ait) {
                break;
            }
            continue;
        }
-       if ( ainame && strcmp( ainame, ait->Class ) ) {
+       if (ainame && strcmp(ainame, ait->Class)) {
            ait = ait->Next;
-           if ( !ait && ainame ) {
+           if (!ait && ainame) {
                ainame = NULL;
                ait = AiTypes;
            }
-           if ( !ait ) {
+           if (!ait) {
                break;
            }
            continue;
        }
        break;
     }
-    if ( !ait ) {
-       DebugLevel0Fn( "AI: Found no matching ai scripts at all!\n" );
-       exit( 0 );
-    }
-    if ( !ainame ) {
-       DebugLevel0Fn( "AI: not found!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n" 
);
-       DebugLevel0Fn( "AI: Using fallback:\n" );
+    if (!ait) {
+       DebugLevel0Fn("AI: Found no matching ai scripts at all!\n");
+       exit(0);
+    }
+    if (!ainame) {
+       DebugLevel0Fn("AI: not found!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");
+       DebugLevel0Fn("AI: Using fallback:\n");
     }
-    DebugLevel0Fn( "AI: %s:%s with %s:%s\n" _C_ player->RaceName _C_ ait->Race
-                  _C_ ainame _C_ ait->Class );
+    DebugLevel0Fn("AI: %s:%s with %s:%s\n" _C_ player->RaceName _C_ ait->Race
+       _C_ ainame _C_ ait->Class);
 
     pai->AiType = ait;
     pai->Scripts[0].Script = ait->Script;
@@ -863,7 +867,7 @@
 /**
 **     Cleanup the AI.
 */
-global void CleanAi( void )
+global void CleanAi(void)
 {
     int i;
     int p;
@@ -873,116 +877,116 @@
     AiBuildQueue *queue;
     char **cp;
 
-    for ( p = 0; p < PlayerMax; ++p ) {
-       if ( ( pai = Players[p].Ai ) ) {
-          //
-          //  Free forces
-          //
-           for ( i = 0; i < AI_MAX_FORCES; ++i ) {
+    for (p = 0; p < PlayerMax; ++p) {
+       if ((pai = Players[p].Ai)) {
+           //
+           //  Free forces
+           //
+           for (i = 0; i < AI_MAX_FORCES; ++i) {
                AiUnitType *aut;
                AiUnit *aiunit;
 
-               for ( aut = pai->Force[i].UnitTypes; aut; aut = temp ) {
+               for (aut = pai->Force[i].UnitTypes; aut; aut = temp) {
                    temp = aut->Next;
-                   free( aut );
+                   free(aut);
                }
-               for ( aiunit = pai->Force[i].Units; aiunit; aiunit = temp ) {
+               for (aiunit = pai->Force[i].Units; aiunit; aiunit = temp) {
                    temp = aiunit->Next;
-                   free( aiunit );
+                   free(aiunit);
                }
            }
-          //
-          //  Free UnitTypeRequests
-          //
-           free( pai->UnitTypeRequests );
-          //
-          //  Free UpgradeToRequests
-          //
-           free( pai->UpgradeToRequests );
-          //
-          //  Free ResearchRequests
-          //
-           free( pai->ResearchRequests );
-          //
-          //  Free UnitTypeBuilded
-          //
-           for ( queue = pai->UnitTypeBuilded; queue; queue = temp ) {
+           //
+           //  Free UnitTypeRequests
+           //
+           free(pai->UnitTypeRequests);
+           //
+           //  Free UpgradeToRequests
+           //
+           free(pai->UpgradeToRequests);
+           //
+           //  Free ResearchRequests
+           //
+           free(pai->ResearchRequests);
+           //
+           //  Free UnitTypeBuilded
+           //
+           for (queue = pai->UnitTypeBuilded; queue; queue = temp) {
                temp = queue->Next;
-               free( queue );
+               free(queue);
            }
 
-           free( pai );
+           free(pai);
            Players[p].Ai = NULL;
        }
     }
 
-   //
-   //  Free AiTypes.
-   //
-    for ( aitype = AiTypes; aitype; aitype = temp ) {
-       DebugLevel3Fn( "%s,%s,%s\n" _C_ aitype->Name _C_ aitype->Race _C_ 
aitype->Class );
-       free( aitype->Name );
-       free( aitype->Race );
-       free( aitype->Class );
+    //
+    //  Free AiTypes.
+    //
+    for (aitype = AiTypes; aitype; aitype = temp) {
+       DebugLevel3Fn("%s,%s,%s\n" _C_ aitype->Name _C_ aitype->Race _C_ 
aitype->Class);
+       free(aitype->Name);
+       free(aitype->Race);
+       free(aitype->Class);
 
-       // ai-type->Script freed by ccl
+       // ai-type->Script freed by ccl
 
        temp = aitype->Next;
-       free( aitype );
+       free(aitype);
     }
     AiTypes = NULL;
 
-   //
-   //  Free AiHelpers.
-   //
-    for ( i = 0; i < AiHelpers.TrainCount; ++i ) {
-       free( AiHelpers.Train[i] );
+    //
+    //  Free AiHelpers.
+    //
+    for (i = 0; i < AiHelpers.TrainCount; ++i) {
+       free(AiHelpers.Train[i]);
     }
-    free( AiHelpers.Train );
+    free(AiHelpers.Train);
 
-    for ( i = 0; i < AiHelpers.BuildCount; ++i ) {
-       free( AiHelpers.Build[i] );
+    for (i = 0; i < AiHelpers.BuildCount; ++i) {
+       free(AiHelpers.Build[i]);
     }
-    free( AiHelpers.Build );
+    free(AiHelpers.Build);
 
-    for ( i = 0; i < AiHelpers.UpgradeCount; ++i ) {
-       free( AiHelpers.Upgrade[i] );
+    for (i = 0; i < AiHelpers.UpgradeCount; ++i) {
+       free(AiHelpers.Upgrade[i]);
     }
-    free( AiHelpers.Upgrade );
+    free(AiHelpers.Upgrade);
 
-    for ( i = 0; i < AiHelpers.ResearchCount; ++i ) {
-       free( AiHelpers.Research[i] );
+    for (i = 0; i < AiHelpers.ResearchCount; ++i) {
+       free(AiHelpers.Research[i]);
     }
-    free( AiHelpers.Research );
+    free(AiHelpers.Research);
 
-    for ( i = 0; i < AiHelpers.RepairCount; ++i ) {
-       free( AiHelpers.Repair[i] );
+    for (i = 0; i < AiHelpers.RepairCount; ++i) {
+       free(AiHelpers.Repair[i]);
     }
-    free( AiHelpers.Repair );
+    free(AiHelpers.Repair);
 
-    for ( i = 0; i < AiHelpers.UnitLimitCount; ++i ) {
-       free( AiHelpers.UnitLimit[i] );
+    for (i = 0; i < AiHelpers.UnitLimitCount; ++i) {
+       free(AiHelpers.UnitLimit[i]);
     }
-    free( AiHelpers.UnitLimit );
+    free(AiHelpers.UnitLimit);
 
-    for ( i = 0; i < AiHelpers.EquivCount; ++i ) {
-       free( AiHelpers.Equiv[i] );
+    for (i = 0; i < AiHelpers.EquivCount; ++i) {
+       free(AiHelpers.Equiv[i]);
     }
-    free( AiHelpers.Equiv );
+    free(AiHelpers.Equiv);
 
-    memset( &AiHelpers, 0, sizeof ( AiHelpers ) );
+    memset(&AiHelpers, 0, sizeof (AiHelpers));
 
-   //
-   //  Mapping original AI numbers in puds to our internal strings
-   //
-    if ( ( cp = AiTypeWcNames ) ) {    // Free all old names
-       while ( *cp ) {
-           free( *cp++ );
+    //
+    //  Mapping original AI numbers in puds to our internal strings
+    //
+    if ((cp = AiTypeWcNames)) {                // Free all old names
+       while (*cp) {
+           free(*cp++);
        }
-       free( AiTypeWcNames );
+       free(AiTypeWcNames);
        AiTypeWcNames = NULL;
     }
-   // TODO : AiScriptActions are not freed
+    // TODO : AiScriptActions are not freed
     AiScriptActionNum = 0;
 }
 
@@ -997,21 +1001,21 @@
 **     @param type     Unit-type which is now available.
 **     @return         True, if unit-type was found in list.
 */
-local int AiRemoveFromBuilded2( PlayerAi * pai, const UnitType * type )
+local int AiRemoveFromBuilded2(PlayerAi * pai, const UnitType * type)
 {
     AiBuildQueue **queue;
     AiBuildQueue *next;
 
-   //
-   //  Search the unit-type order.
-   //
-    for ( queue = &pai->UnitTypeBuilded; ( next = *queue ); queue = 
&next->Next ) {
-       DebugCheck( !next->Want );
-       if ( type == next->Type && next->Made ) {
+    //
+    //  Search the unit-type order.
+    //
+    for (queue = &pai->UnitTypeBuilded; (next = *queue); queue = &next->Next) {
+       DebugCheck(!next->Want);
+       if (type == next->Type && next->Made) {
            --next->Made;
-           if ( !--next->Want ) {
+           if (!--next->Want) {
                *queue = next->Next;
-               free( next );
+               free(next);
            }
            return 1;
        }
@@ -1025,30 +1029,31 @@
 **     @param pai      Computer AI player.
 **     @param type     Unit-type which is now available.
 */
-local void AiRemoveFromBuilded( PlayerAi * pai, const UnitType * type )
+local void AiRemoveFromBuilded(PlayerAi * pai, const UnitType * type)
 {
     int i;
 
-    if ( AiRemoveFromBuilded2( pai, type ) ) {
+    if (AiRemoveFromBuilded2(pai, type)) {
        return;
     }
-   //
-   //  This could happen if an upgrade is ready, look for equivalent units.
-   //
-    if ( type->Type < AiHelpers.EquivCount && AiHelpers.Equiv[type->Type] ) {
-       DebugLevel2Fn( "Equivalence for %s\n" _C_ type->Ident );
-       for ( i = 0; i < AiHelpers.Equiv[type->Type]->Count; ++i ) {
-           if ( AiRemoveFromBuilded2( pai, 
AiHelpers.Equiv[type->Type]->Table[i] ) ) {
+    //
+    //  This could happen if an upgrade is ready, look for equivalent units.
+    //
+    if (type->Type < AiHelpers.EquivCount && AiHelpers.Equiv[type->Type]) {
+       DebugLevel2Fn("Equivalence for %s\n" _C_ type->Ident);
+       for (i = 0; i < AiHelpers.Equiv[type->Type]->Count; ++i) {
+           if (AiRemoveFromBuilded2(pai, 
AiHelpers.Equiv[type->Type]->Table[i])) {
                return;
            }
        }
     }
 
-    if (pai->Player==ThisPlayer) {
-       DebugLevel0Fn("My guess is that you built something under ai me. 
naughty boy!\n");
+    if (pai->Player == ThisPlayer) {
+       DebugLevel0Fn
+           ("My guess is that you built something under ai me. naughty 
boy!\n");
        return;
     }
-    DebugCheck( 1 );
+    DebugCheck(1);
 }
 
 /**
@@ -1058,15 +1063,15 @@
 **     @param type     Unit-type which is now available.
 **     @return         True if the unit-type could be reduced.
 */
-local int AiReduceMadeInBuilded2( const PlayerAi * pai, const UnitType * type )
+local int AiReduceMadeInBuilded2(const PlayerAi * pai, const UnitType * type)
 {
     AiBuildQueue *queue;
 
-   //
-   //  Search the unit-type order.
-   //
-    for ( queue = pai->UnitTypeBuilded; queue; queue = queue->Next ) {
-       if ( type == queue->Type && queue->Made ) {
+    //
+    //  Search the unit-type order.
+    //
+    for (queue = pai->UnitTypeBuilded; queue; queue = queue->Next) {
+       if (type == queue->Type && queue->Made) {
            queue->Made--;
            return 1;
        }
@@ -1080,26 +1085,26 @@
 **     @param pai      Computer AI player.
 **     @param type     Unit-type which is now available.
 */
-local void AiReduceMadeInBuilded( const PlayerAi * pai, const UnitType * type )
+local void AiReduceMadeInBuilded(const PlayerAi * pai, const UnitType * type)
 {
     int i;
 
-    if ( AiReduceMadeInBuilded2( pai, type ) ) {
+    if (AiReduceMadeInBuilded2(pai, type)) {
        return;
     }
-   //
-   //  This could happen if an upgrade is ready, look for equivalent units.
-   //
-    if ( type->Type < AiHelpers.EquivCount && AiHelpers.Equiv[type->Type] ) {
-       DebugLevel2Fn( "Equivalence for %s\n" _C_ type->Ident );
-       for ( i = 0; i < AiHelpers.Equiv[type->Type]->Count; ++i ) {
-           if ( AiReduceMadeInBuilded2( pai, 
AiHelpers.Equiv[type->Type]->Table[i] ) ) {
+    //
+    //  This could happen if an upgrade is ready, look for equivalent units.
+    //
+    if (type->Type < AiHelpers.EquivCount && AiHelpers.Equiv[type->Type]) {
+       DebugLevel2Fn("Equivalence for %s\n" _C_ type->Ident);
+       for (i = 0; i < AiHelpers.Equiv[type->Type]->Count; ++i) {
+           if (AiReduceMadeInBuilded2(pai, 
AiHelpers.Equiv[type->Type]->Table[i])) {
                return;
            }
        }
     }
 
-    DebugCheck( 1 );
+    DebugCheck(1);
 }
 
 /*----------------------------------------------------------------------------
@@ -1112,42 +1117,42 @@
 **     @param attacker Pointer to attacker unit.
 **     @param defender Pointer to unit that is being attacked.
 */
-global void AiHelpMe( const Unit * attacker, Unit * defender )
+global void AiHelpMe(const Unit * attacker, Unit * defender)
 {
     PlayerAi *pai;
     AiUnit *aiunit;
     int force;
 
-    DebugLevel0Fn( "%d: %d(%s) attacked at %d,%d\n" _C_
-                  defender->Player->Player _C_ UnitNumber( defender ) _C_
-                  defender->Type->Ident _C_ defender->X _C_ defender->Y );
-
-   //
-   //  Don't send help to scouts (zeppelin,eye of vision).
-   //
-    if ( !defender->Type->CanAttack && defender->Type->UnitType == UnitTypeFly 
) {
+    DebugLevel0Fn("%d: %d(%s) attacked at %d,%d\n" _C_
+       defender->Player->Player _C_ UnitNumber(defender) _C_
+       defender->Type->Ident _C_ defender->X _C_ defender->Y);
+
+    //
+    //  Don't send help to scouts (zeppelin,eye of vision).
+    //
+    if (!defender->Type->CanAttack && defender->Type->UnitType == UnitTypeFly) 
{
        return;
     }
 
     AiPlayer = pai = defender->Player->Ai;
 
-   //
-   //  If unit belongs to an attack/defend force, don't defend it.
-   //
-    for ( force = 1; force < AI_MAX_FORCES; ++force ) {
+    //
+    //  If unit belongs to an attack/defend force, don't defend it.
+    //
+    for (force = 1; force < AI_MAX_FORCES; ++force) {
        aiunit = pai->Force[force].Units;
 
-       while ( aiunit ) {
-           if ( defender == aiunit->Unit ) {
-               AiForceHelpMe( force, attacker, defender );
+       while (aiunit) {
+           if (defender == aiunit->Unit) {
+               AiForceHelpMe(force, attacker, defender);
                return;
            }
            aiunit = aiunit->Next;
        }
     }
 
-   // Unit can't be found in forces, consider it's in force 0
-    AiForceHelpMe( 0, attacker, defender );
+    // Unit can't be found in forces, consider it's in force 0
+    AiForceHelpMe(0, attacker, defender);
 }
 
 /**
@@ -1155,36 +1160,36 @@
 **
 **     @param unit     Pointer to unit.
 */
-global void AiUnitKilled( Unit * unit )
+global void AiUnitKilled(Unit * unit)
 {
-    DebugLevel1Fn( "%d: %d(%s) killed\n" _C_
-                  unit->Player->Player _C_ UnitNumber( unit ) _C_ 
unit->Type->Ident );
+    DebugLevel1Fn("%d: %d(%s) killed\n" _C_
+       unit->Player->Player _C_ UnitNumber(unit) _C_ unit->Type->Ident);
 
-    DebugCheck( unit->Player->Type == PlayerPerson );
+    DebugCheck(unit->Player->Type == PlayerPerson);
 
-   // FIXME: must handle all orders...
+    // FIXME: must handle all orders...
 
-    switch ( unit->Orders[0].Action ) {
-    case UnitActionStill:
-    case UnitActionAttack:
-    case UnitActionMove:
-       break;
-    case UnitActionBuilded:
-       DebugLevel1Fn( "%d: %d(%s) killed, under construction!\n" _C_
-                      unit->Player->Player _C_ UnitNumber( unit ) _C_ 
unit->Type->Ident );
-       AiReduceMadeInBuilded( unit->Player->Ai, unit->Type );
-       break;
-    case UnitActionBuild:
-       DebugLevel1Fn( "%d: %d(%s) killed, with order %s!\n" _C_
-                      unit->Player->Player _C_ UnitNumber( unit ) _C_
-                      unit->Type->Ident _C_ unit->Orders[0].Type->Ident );
-       AiReduceMadeInBuilded( unit->Player->Ai, unit->Orders[0].Type );
-       break;
-    default:
-       DebugLevel1Fn( "FIXME: %d: %d(%s) killed, with order %d!\n" _C_
-                      unit->Player->Player _C_ UnitNumber( unit ) _C_
-                      unit->Type->Ident _C_ unit->Orders[0].Action );
-       break;
+    switch (unit->Orders[0].Action) {
+       case UnitActionStill:
+       case UnitActionAttack:
+       case UnitActionMove:
+           break;
+       case UnitActionBuilded:
+           DebugLevel1Fn("%d: %d(%s) killed, under construction!\n" _C_
+               unit->Player->Player _C_ UnitNumber(unit) _C_ 
unit->Type->Ident);
+           AiReduceMadeInBuilded(unit->Player->Ai, unit->Type);
+           break;
+       case UnitActionBuild:
+           DebugLevel1Fn("%d: %d(%s) killed, with order %s!\n" _C_
+               unit->Player->Player _C_ UnitNumber(unit) _C_
+               unit->Type->Ident _C_ unit->Orders[0].Type->Ident);
+           AiReduceMadeInBuilded(unit->Player->Ai, unit->Orders[0].Type);
+           break;
+       default:
+           DebugLevel1Fn("FIXME: %d: %d(%s) killed, with order %d!\n" _C_
+               unit->Player->Player _C_ UnitNumber(unit) _C_
+               unit->Type->Ident _C_ unit->Orders[0].Action);
+           break;
     }
 }
 
@@ -1194,20 +1199,20 @@
 **     @param unit     Pointer to unit that builds the building.
 **     @param what     Pointer to unit building that was built.
 */
-global void AiWorkComplete( Unit * unit, Unit * what )
+global void AiWorkComplete(Unit * unit, Unit * what)
 {
-    if ( unit ) {
-       DebugLevel1Fn( "%d: %d(%s) build %s at %d,%d completed\n" _C_
-                      what->Player->Player _C_ UnitNumber( unit ) _C_ 
unit->Type->Ident _C_
-                      what->Type->Ident _C_ unit->X _C_ unit->Y );
+    if (unit) {
+       DebugLevel1Fn("%d: %d(%s) build %s at %d,%d completed\n" _C_
+           what->Player->Player _C_ UnitNumber(unit) _C_ unit->Type->Ident _C_
+           what->Type->Ident _C_ unit->X _C_ unit->Y);
     } else {
-       DebugLevel1Fn( "%d: building %s at %d,%d completed\n" _C_
-                      what->Player->Player _C_ what->Type->Ident _C_ what->X 
_C_ what->Y );
+       DebugLevel1Fn("%d: building %s at %d,%d completed\n" _C_
+           what->Player->Player _C_ what->Type->Ident _C_ what->X _C_ what->Y);
     }
 
-    DebugCheck( what->Player->Type == PlayerPerson );
+    DebugCheck(what->Player->Type == PlayerPerson);
 
-    AiRemoveFromBuilded( what->Player->Ai, what->Type );
+    AiRemoveFromBuilded(what->Player->Ai, what->Type);
 }
 
 /**
@@ -1216,15 +1221,15 @@
 **     @param unit     Pointer to unit what builds the building.
 **     @param what     Pointer to unit-type.
 */
-global void AiCanNotBuild( Unit * unit, const UnitType * what )
+global void AiCanNotBuild(Unit * unit, const UnitType * what)
 {
-    DebugLevel0Fn( "%d: %d(%s) Can't build %s at %d,%d\n" _C_
-                  unit->Player->Player _C_ UnitNumber( unit ) _C_ 
unit->Type->Ident
-                  _C_ what->Ident _C_ unit->X _C_ unit->Y );
+    DebugLevel0Fn("%d: %d(%s) Can't build %s at %d,%d\n" _C_
+       unit->Player->Player _C_ UnitNumber(unit) _C_ unit->Type->Ident
+       _C_ what->Ident _C_ unit->X _C_ unit->Y);
 
-    DebugCheck( unit->Player->Type == PlayerPerson );
+    DebugCheck(unit->Player->Type == PlayerPerson);
 
-    AiReduceMadeInBuilded( unit->Player->Ai, what );
+    AiReduceMadeInBuilded(unit->Player->Ai, what);
 }
 
 /**
@@ -1233,15 +1238,15 @@
 **     @param unit     Pointer to unit what builds the building.
 **     @param what     Pointer to unit-type.
 */
-global void AiCanNotReach( Unit * unit, const UnitType * what )
+global void AiCanNotReach(Unit * unit, const UnitType * what)
 {
-    DebugLevel3Fn( "%d: %d(%s) Can't reach %s at %d,%d\n" _C_
-                  unit->Player->Player _C_ UnitNumber( unit ) _C_ 
unit->Type->Ident _C_
-                  what->Ident _C_ unit->X _C_ unit->Y );
+    DebugLevel3Fn("%d: %d(%s) Can't reach %s at %d,%d\n" _C_
+       unit->Player->Player _C_ UnitNumber(unit) _C_ unit->Type->Ident _C_
+       what->Ident _C_ unit->X _C_ unit->Y);
 
-    DebugCheck( unit->Player->Type == PlayerPerson );
+    DebugCheck(unit->Player->Type == PlayerPerson);
 
-    AiReduceMadeInBuilded( unit->Player->Ai, what );
+    AiReduceMadeInBuilded(unit->Player->Ai, what);
 }
 
 /**
@@ -1250,15 +1255,15 @@
 **     @param unit     Point to unit.
 **      @param what     Pointer to unit-type.
 */
-global void AiNeedMoreFarms( Unit * unit, const UnitType * what __attribute__ 
( ( unused ) ) )
+global void AiNeedMoreFarms(Unit * unit, const UnitType * what __attribute__ 
((unused)))
 {
-    DebugLevel3Fn( "%d: %d(%s) need more farms %s at %d,%d\n" _C_
-                  unit->Player->Player _C_ UnitNumber( unit ) _C_ 
unit->Type->Ident _C_
-                  what->Ident _C_ unit->X _C_ unit->Y );
+    DebugLevel3Fn("%d: %d(%s) need more farms %s at %d,%d\n" _C_
+       unit->Player->Player _C_ UnitNumber(unit) _C_ unit->Type->Ident _C_
+       what->Ident _C_ unit->X _C_ unit->Y);
 
-    DebugCheck( unit->Player->Type == PlayerPerson );
+    DebugCheck(unit->Player->Type == PlayerPerson);
 
-    ( ( PlayerAi * ) unit->Player->Ai )->NeedFood = 1;
+    ((PlayerAi *) unit->Player->Ai)->NeedFood = 1;
 }
 
 /**
@@ -1267,19 +1272,19 @@
 **     @param unit     Pointer to unit making.
 **     @param what     Pointer to new ready trained unit.
 */
-global void AiTrainingComplete( Unit * unit, Unit * what )
+global void AiTrainingComplete(Unit * unit, Unit * what)
 {
-    DebugLevel1Fn( "%d: %d(%s) training %s at %d,%d completed\n" _C_
-                  unit->Player->Player _C_ UnitNumber( unit ) _C_ 
unit->Type->Ident _C_
-                  what->Type->Ident _C_ unit->X _C_ unit->Y );
+    DebugLevel1Fn("%d: %d(%s) training %s at %d,%d completed\n" _C_
+       unit->Player->Player _C_ UnitNumber(unit) _C_ unit->Type->Ident _C_
+       what->Type->Ident _C_ unit->X _C_ unit->Y);
 
-    DebugCheck( unit->Player->Type == PlayerPerson );
+    DebugCheck(unit->Player->Type == PlayerPerson);
 
-    AiRemoveFromBuilded( unit->Player->Ai, what->Type );
+    AiRemoveFromBuilded(unit->Player->Ai, what->Type);
 
     AiPlayer = unit->Player->Ai;
     AiCleanForces();
-    AiAssignToForce( what );
+    AiAssignToForce(what);
 }
 
 /**
@@ -1288,14 +1293,14 @@
 **     @param unit     Pointer to unit working.
 **     @param what     Pointer to the new unit-type.
 */
-global void AiUpgradeToComplete( Unit * unit __attribute__ ( ( unused ) ),
-                                const UnitType * what __attribute__ ( ( unused 
) ) )
+global void AiUpgradeToComplete(Unit * unit __attribute__ ((unused)),
+    const UnitType * what __attribute__ ((unused)))
 {
-    DebugLevel1Fn( "%d: %d(%s) upgrade-to %s at %d,%d completed\n" _C_
-                  unit->Player->Player _C_ UnitNumber( unit ) _C_ 
unit->Type->Ident _C_
-                  what->Ident _C_ unit->X _C_ unit->Y );
+    DebugLevel1Fn("%d: %d(%s) upgrade-to %s at %d,%d completed\n" _C_
+       unit->Player->Player _C_ UnitNumber(unit) _C_ unit->Type->Ident _C_
+       what->Ident _C_ unit->X _C_ unit->Y);
 
-    DebugCheck( unit->Player->Type == PlayerPerson );
+    DebugCheck(unit->Player->Type == PlayerPerson);
 }
 
 /**
@@ -1304,16 +1309,16 @@
 **     @param unit     Pointer to unit working.
 **     @param what     Pointer to the new upgrade.
 */
-global void AiResearchComplete( Unit * unit __attribute__ ( ( unused ) ),
-                               const Upgrade * what __attribute__ ( ( unused ) 
) )
+global void AiResearchComplete(Unit * unit __attribute__ ((unused)),
+    const Upgrade * what __attribute__ ((unused)))
 {
-    DebugLevel1Fn( "%d: %d(%s) research %s at %d,%d completed\n" _C_
-                  unit->Player->Player _C_ UnitNumber( unit ) _C_ 
unit->Type->Ident _C_
-                  what->Ident _C_ unit->X _C_ unit->Y );
+    DebugLevel1Fn("%d: %d(%s) research %s at %d,%d completed\n" _C_
+       unit->Player->Player _C_ UnitNumber(unit) _C_ unit->Type->Ident _C_
+       what->Ident _C_ unit->X _C_ unit->Y);
 
-    DebugCheck( unit->Player->Type == PlayerPerson );
+    DebugCheck(unit->Player->Type == PlayerPerson);
 
-   // FIXME: upgrading knights -> paladins, must rebuild lists!
+    // FIXME: upgrading knights -> paladins, must rebuild lists!
 }
 
 /**
@@ -1321,7 +1326,7 @@
 **
 **     @param player   The player structure pointer.
 */
-global void AiEachCycle( Player * player __attribute__ ( ( unused ) ) )
+global void AiEachCycle(Player * player __attribute__ ((unused)))
 {
 }
 
@@ -1330,7 +1335,7 @@
 **
 **     @param player   The player structure pointer.
 */
-global void AiEachSecond( Player * player )
+global void AiEachSecond(Player * player)
 {
 #ifdef TIMEIT
     u_int64_t sv = rdtsc();
@@ -1339,41 +1344,41 @@
     long sx;
 #endif
 
-    DebugLevel3Fn( "%d:\n" _C_ player->Player );
+    DebugLevel3Fn("%d:\n" _C_ player->Player);
 
     AiPlayer = player->Ai;
-    IfDebug( if ( !AiPlayer ) return; );       // For debug only!
+    IfDebug(if (!AiPlayer) return;);   // For debug only!
 
-   //
-   //  Advance script
-   //
+    //
+    //  Advance script
+    //
     AiExecuteScripts();
 
-   //
-   //  Look if everything is fine.
-   //
+    //
+    //  Look if everything is fine.
+    //
     AiCheckUnits();
-   //
-   //  Handle the resource manager.
-   //
+    //
+    //  Handle the resource manager.
+    //
     AiResourceManager();
-   //
-   //  Handle the force manager.
-   //
+    //
+    //  Handle the force manager.
+    //
     AiForceManager();
-   //
-   //  Check for magic actions.
-   //
+    //
+    //  Check for magic actions.
+    //
     AiCheckMagic();
 
-    if ( AiPlayer->AutoAttack ) {
+    if (AiPlayer->AutoAttack) {
        AiPeriodicAttack();
     }
 #ifdef TIMEIT
     ev = rdtsc();
-    sx = ( ev - sv );
-    mv = ( mv + sx ) / 2;
-    DebugLevel1Fn( "%ld %ld\n" _C_ sx / 1000 _C_ mv / 1000 );
+    sx = (ev - sv);
+    mv = (mv + sx) / 2;
+    DebugLevel1Fn("%ld %ld\n" _C_ sx / 1000 _C_ mv / 1000);
 #endif
 }
 
Index: stratagus/src/clone/ccl_helpers.c
diff -u stratagus/src/clone/ccl_helpers.c:1.4 
stratagus/src/clone/ccl_helpers.c:1.5
--- stratagus/src/clone/ccl_helpers.c:1.4       Fri Oct 24 02:28:54 2003
+++ stratagus/src/clone/ccl_helpers.c   Sun Oct 26 10:34:59 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//      $Id: ccl_helpers.c,v 1.4 2003/10/24 06:28:54 mr-russ Exp $
+//      $Id: ccl_helpers.c,v 1.5 2003/10/26 15:34:59 pludov Exp $
 
 //@{
 
@@ -52,14 +52,17 @@
 global unsigned int IOTabLevel;
 global CLFile *IOOutFile;
 
-global void IOPrintTabs()
+/**
+**     Output tabs when saving a ccl value
+*/
+global void IOPrintTabs(void)
 {
     unsigned int tableft;
     unsigned int cur;
     char buffer[256];
     tableft = IOTabLevel;
     while (tableft) {
-       cur = (tableft >= sizeof(buffer) ? sizeof(buffer) - 1 : tableft);
+       cur = (tableft >= sizeof (buffer) ? sizeof (buffer) - 1 : tableft);
 
        memset(buffer, 9, cur);
        buffer[cur] = 0;
@@ -70,22 +73,27 @@
     }
 }
 
-local void saveData(CclFieldDef * defs, void *data)
+/**
+**     Save a structure.
+**
+**     @param defs     the structure definition
+**     @param data     pointer to the structure
+*/
+local void saveData(IOFieldDef * defs, void *data)
 {
     unsigned int i;
     while (defs->name) {
        if (defs->convertfunc) {
            IOPrintTabs();
            for (i = 0; i < IOTabLevel; i++) {
-               DebugLevel3Fn( "\t" );
+               DebugLevel3Fn("\t");
            }
            DebugLevel3Fn("saving %s\n" _C_ defs->name);
            // name
            CLprintf(IOOutFile, "%s", defs->name);
            IOTabLevel++;
            // real output
-           (*defs->convertfunc)(SCM_UNSPECIFIED,
-               ((char*)data) + (int)defs->offset, defs->para);
+           (*defs->convertfunc) (SCM_UNSPECIFIED, ((char *) data) + (int) 
defs->offset, defs->para);
            IOTabLevel--;
            CLprintf(IOOutFile, "\n");
        }
@@ -93,11 +101,18 @@
     }
 }
 
-local void restoreData(CclFieldDef * defs, void *data, SCM desc)
+/**
+**     Load a structure.
+**
+**     @param defs     the structure definition
+**     @param data     pointer to the structure
+**     @param desc     SCM to parse
+*/
+local void restoreData(IOFieldDef * defs, void *data, SCM desc)
 {
     SCM ident;
     SCM value;
-    CclFieldDef *curdef;
+    IOFieldDef *curdef;
     while (!gh_null_p(desc)) {
        ident = gh_car(desc);
        desc = gh_cdr(desc);
@@ -105,7 +120,7 @@
        desc = gh_cdr(desc);
        for (curdef = defs; curdef->name; curdef++) {
            if (curdef->convertfunc && gh_eq_p(ident, 
gh_symbol2scm(curdef->name))) {
-               (*curdef->convertfunc)(value, ((char*)data) + 
(int)curdef->offset,
+               (*curdef->convertfunc) (value, ((char *) data) + (int) 
curdef->offset,
                    curdef->para);
                break;
            }
@@ -120,17 +135,17 @@
 /**
 **     Handle saving/loading of structure.
 **     binaryform points to the structure to load/save.
-**     para is used as a (CclStructDef*)
+**     para is used as a (IOStructDef*)
 **
 **     @param  scmform         When loading, the scm data to load
 **     @param  binaryform      Pointer to the structure to load/save
-**     @param  para            Pointer to a CclStructDef structure.
+**     @param  para            Pointer to a IOStructDef structure.
 */
 global void IOStruct(SCM scmform, void *binaryform, void *para)
 {
-    CclStructDef *structDef;
+    IOStructDef *structDef;
 
-    structDef = (CclStructDef*)para;
+    structDef = (IOStructDef *) para;
 
     if (IOLoadingMode) {
        restoreData(structDef->defs, binaryform, scmform);
@@ -151,23 +166,23 @@
 **
 **     @param  scmform         When loading, the scm data to load
 **     @param  binaryform      Pointer to the structure'reference to load/save 
( <structure-type> ** )
-**     @param  para            Pointer to a CclStructDef structure.
+**     @param  para            Pointer to a IOStructDef structure.
 */
 global void IOStructPtr(SCM scmform, void *binaryform, void *para)
 {
     void **structptr;
-    CclStructDef *def;
+    IOStructDef *def;
 
     if (IOHandleNullPtr(scmform, binaryform)) {
        return;
     }
 
-    def = (CclStructDef*)para;
+    def = (IOStructDef *) para;
 
-    structptr = (void**)binaryform;
+    structptr = (void **) binaryform;
 
     if (IOLoadingMode) {
-       (*structptr) = (void*)malloc(def->size);
+       (*structptr) = (void *) malloc(def->size);
        memset((*structptr), 0, def->size);
        IOStruct(scmform, (*structptr), para);
     } else {
@@ -177,26 +192,26 @@
 
 /**
 **     Handle saving/loading an array of structures.
-**     The array size is found in the array_size field of the CclStructDef 
structure. 
+**     The array size is found in the array_size field of the IOStructDef 
structure. 
 **     The array is NOT malloc'ed. 
 **
 **     @param  scmform         When loading, the scm data to load
 **     @param  binaryform      Pointer to the structure'reference to load/save 
( <structure-type> * )
-**     @param  para            Pointer to a CclStructDef structure, describing 
format of the structure.
+**     @param  para            Pointer to a IOStructDef structure, describing 
format of the structure.
 */
 global void IOStructArray(SCM from, void *binaryform, void *para)
 {
-    CclStructDef *def;
+    IOStructDef *def;
     int i;
 
-    def = (CclStructDef*) para;
+    def = (IOStructDef *) para;
 
     if (IOLoadingMode) {
        for (i = 0; i < def->array_size; ++i) {
            IOStruct(gh_car(from), binaryform, para);
 
            from = gh_cdr(from);
-           (char*)binaryform += def->size;
+           (char *) binaryform += def->size;
        }
     } else {
        CLprintf(IOOutFile, " (\n");
@@ -205,7 +220,7 @@
            IOPrintTabs();
            IOStruct(from, binaryform, para);
            CLprintf(IOOutFile, "\n");
-           (char*)binaryform += def->size;
+           (char *) binaryform += def->size;
        }
        --IOTabLevel;
        IOPrintTabs();
@@ -216,23 +231,23 @@
 /**
 **     Handle saving/loading a linked list of structure.
 **     The binaryform is a pointer to the "first" field.
-**     The third parameter is a pointer to a CclStructDef, describing list 
elements.
+**     The third parameter is a pointer to a IOStructDef, describing list 
elements.
 **
 **     defs[0] must contain the reference to the next field on the loaded 
structure.  
 **
 **     @param  scmform         When loading, the scm data to load
 **     @param  binaryform      Pointer to the "first"'ref ( <any-structure>** )
-**     @param  para            Pointer to the CclStructDef
+**     @param  para            Pointer to the IOStructDef
 */
 global void IOLinkedList(SCM scmfrom, void *binaryform, void *para)
 {
     SCM item;
-    CclStructDef *itemDef;
+    IOStructDef *itemDef;
     void **current;
-    itemDef = (CclStructDef*)para;
+    itemDef = (IOStructDef *) para;
 
     if (IOLoadingMode) {
-       current = (void**)binaryform;
+       current = (void **) binaryform;
        while (!gh_null_p(scmfrom)) {
            item = gh_car(scmfrom);
            scmfrom = gh_cdr(scmfrom);
@@ -240,21 +255,22 @@
            // Just to be safe... 
            if (!gh_null_p(item)) {
                IOStructPtr(item, current, itemDef);
-               current = (void**)(((char*)(*current)) + 
(int)itemDef->defs->offset);
+               current =
+                   (void **) (((char *) (*current)) + (int) 
itemDef->defs->offset);
            }
        }
     } else {
-       current = ((void**)binaryform);
+       current = ((void **) binaryform);
 
        CLprintf(IOOutFile, " (\n");
        ++IOTabLevel;
-       while (*((void**)current)) {
+       while (*((void **) current)) {
            IOPrintTabs();
            IOStructPtr(gh_car(scmfrom), current, itemDef);
            CLprintf(IOOutFile, "\n");
 
            // Get the next...
-           current = (void**)(((char*)(*current)) + 
(int)itemDef->defs->offset);
+           current = (void **) (((char *) (*current)) + (int) 
itemDef->defs->offset);
        }
        --IOTabLevel;
        IOPrintTabs();
@@ -266,8 +282,8 @@
 /**
 **     Handle saving/loading a table of structure.
 **     The table is composed of two thing : a pointer to data and a counter. 
-**     The third parameter is a pointer to a CclStructDef, describing the table
-**     fields of the CclStructDef are :
+**     The third parameter is a pointer to a IOStructDef, describing the table
+**     fields of the IOStructDef are :
 **             size            indicate the size of one element of the table.
 **             defs[0]:        describe the data field ( should be 
<any-structure>** ) 
 **             defs[1]:        describe the counter field ( should be int )
@@ -275,39 +291,38 @@
 **     
 **     @param  scmform         When loading, the scm data to load
 **     @param  binaryform      Pointer to the "first"'ref ( <any-structure>** )
-**     @param  para            Pointer to the CclStructDef
+**     @param  para            Pointer to the IOStructDef
 */
 global void IOTable(SCM scmfrom, void *binaryform, void *para)
 {
-    CclStructDef *def;
+    IOStructDef *def;
     int count;
     void *org;
 
-    def = (CclStructDef*)para;
+    def = (IOStructDef *) para;
     if (IOLoadingMode) {
        count = 0;
        org = 0;
        while (!gh_null_p(scmfrom)) {
            ++count;
            org = realloc(org, def->size * count);
-           (*def->defs[2].convertfunc)(gh_car(scmfrom),
-               (void*)((char*)org + (def->size * (count - 1))),
-               def->defs[2].para);
+           (*def->defs[2].convertfunc) (gh_car(scmfrom),
+               (void *) ((char *) org + (def->size * (count - 1))), 
def->defs[2].para);
            scmfrom = gh_cdr(scmfrom);
        }
-       *((void**)((char*)binaryform + (int)def->defs[0].offset)) = org;
-       *((int*)((char*)binaryform + (int)def->defs[1].offset)) = count;
+       *((void **) ((char *) binaryform + (int) def->defs[0].offset)) = org;
+       *((int *) ((char *) binaryform + (int) def->defs[1].offset)) = count;
     } else {
        CLprintf(IOOutFile, " (\n");
        ++IOTabLevel;
-       count = *((int*)((char*)binaryform + (int)def->defs[1].offset));
-       org = *((void**)((char*)binaryform + (int)def->defs[0].offset));
+       count = *((int *) ((char *) binaryform + (int) def->defs[1].offset));
+       org = *((void **) ((char *) binaryform + (int) def->defs[0].offset));
 
        while (count) {
            IOPrintTabs();
-           (*def->defs[2].convertfunc)(scmfrom, org, def->defs[2].para);
+           (*def->defs[2].convertfunc) (scmfrom, org, def->defs[2].para);
            CLprintf(IOOutFile, "\n");
-           org = (void*)((char*)org + def->size);
+           org = (void *) ((char *) org + def->size);
            --count;
        }
        --IOTabLevel;
@@ -328,9 +343,9 @@
 global void IOInt(SCM scmfrom, void *binaryform, void *para)
 {
     if (IOLoadingMode) {
-       (*((int*)binaryform)) = gh_scm2long(scmfrom);
+       (*((int *) binaryform)) = gh_scm2long(scmfrom);
     } else {
-       CLprintf(IOOutFile, " %d", (*((int*)binaryform)));
+       CLprintf(IOOutFile, " %d", (*((int *) binaryform)));
     }
 }
 
@@ -349,9 +364,9 @@
        return;
     }
     if (IOLoadingMode) {
-       (*((char**)binaryform)) = gh_scm2newstr(scmfrom, 0);
-    } else {                   // FIXME : (pludov) better string support
-       CLprintf(IOOutFile, " \"%s\"", (*((char**)binaryform)));
+       (*((char **) binaryform)) = gh_scm2newstr(scmfrom, 0);
+    } else {                           // FIXME : (pludov) better string 
support
+       CLprintf(IOOutFile, " \"%s\"", (*((char **) binaryform)));
     }
 }
 
@@ -367,9 +382,9 @@
 global void IOBool(SCM scmfrom, void *binaryform, void *para)
 {
     if (IOLoadingMode) {
-       (*((int*)binaryform)) = gh_null_p(scmfrom) ? 0 : 1;
+       (*((int *) binaryform)) = gh_null_p(scmfrom) ? 0 : 1;
     } else {
-       CLprintf(IOOutFile, " %s", (*((int*)binaryform) ? "#t" : "#f"));
+       CLprintf(IOOutFile, " %s", (*((int *) binaryform) ? "#t" : "#f"));
     }
 }
 
@@ -385,9 +400,9 @@
 global void IOCharBool(SCM scmfrom, void *binaryform, void *para)
 {
     if (IOLoadingMode) {
-       (*((char*)binaryform)) = (gh_null_p(scmfrom) ? 0 : 1);
+       (*((char *) binaryform)) = (gh_null_p(scmfrom) ? 0 : 1);
     } else {
-       CLprintf(IOOutFile, " %s", (*((char*)binaryform) ? "#t" : "#f"));
+       CLprintf(IOOutFile, " %s", (*((char *) binaryform) ? "#t" : "#f"));
     }
 }
 
@@ -402,7 +417,7 @@
 global void IOCcl(SCM scmfrom, void *binaryform, void *para)
 {
     SCM *ptr;
-    ptr = (SCM*)binaryform;
+    ptr = (SCM *) binaryform;
     if (IOLoadingMode) {
        *ptr = scmfrom;
        CclGcProtect(*ptr);
@@ -414,25 +429,25 @@
 
 /**
 **     Handle saving/loading a flag stored on a char
-**     Flag are defined as an array of CclFlagDef, terminated by {0,0}
+**     Flag are defined as an array of IOFlagDef, terminated by {0,0}
 **
 **     @param  scmform         When loading, the scm data to load
 **     @param  binaryform      Pointer to the scm value to load/save ( char* )
-**     @param  para            Array of CclFlagDef, describing possible values 
( CclFlagDef * ) 
+**     @param  para            Array of IOFlagDef, describing possible values 
( IOFlagDef * ) 
 */
 global void IOCharFlag(SCM scmfrom, void *binaryform, void *para)
 {
-    CclFlagDef *flags;
+    IOFlagDef *flags;
 
     flags = para;
 
     if (IOLoadingMode) {
        if (gh_exact_p(scmfrom)) {
-           (*((char*)binaryform)) = gh_scm2int(scmfrom);
+           (*((char *) binaryform)) = gh_scm2int(scmfrom);
        }
        while (flags->ident) {
            if (gh_eq_p(scmfrom, gh_symbol2scm(flags->ident))) {
-               (*((char*)binaryform)) = flags->value;
+               (*((char *) binaryform)) = flags->value;
                return;
            }
            ++flags;
@@ -440,14 +455,14 @@
        errl("invalid flag", scmfrom);
     } else {
        while (flags->ident) {
-           if (flags->value == (*((char*)binaryform))) {
+           if (flags->value == (*((char *) binaryform))) {
                CLprintf(IOOutFile, " %s", flags->ident);
                return;
            }
            ++flags;
        }
        CLprintf(IOOutFile, "\n;; WARNING : no flag defined for value %d\n",
-           (*((char*)binaryform)));
+           (*((char *) binaryform)));
        CLprintf(IOOutFile, ";; defined flags are : ");
        flags = para;
        while (flags->ident) {
@@ -455,7 +470,7 @@
            ++flags;
        }
        IOPrintTabs();
-       CLprintf(IOOutFile, "%d", (*((char*)binaryform)));
+       CLprintf(IOOutFile, "%d", (*((char *) binaryform)));
     }
 }
 
@@ -472,8 +487,8 @@
     char *buffer;
     char *str;
 
-    size = (int)para;
-    buffer = (char*)binaryform;
+    size = (int) para;
+    buffer = (char *) binaryform;
     if (IOLoadingMode) {
        str = gh_scm2newstr(scmfrom, NULL);
        strncpy(buffer, str, size);
@@ -497,11 +512,11 @@
 {
     if (IOLoadingMode) {
        if (gh_null_p(scmfrom)) {
-           *((void**)binaryform) = 0;
+           *((void **) binaryform) = 0;
            return 1;
        }
     } else {
-       if (!*((void**)binaryform)) {
+       if (!*((void **) binaryform)) {
            CLprintf(IOOutFile, " ()");
            return 1;
        }
@@ -527,11 +542,11 @@
        return;
     }
 
-    size = (int)para;
-    array = (int**)binaryform;
+    size = (int) para;
+    array = (int **) binaryform;
 
     if (IOLoadingMode) {
-       (*array) = (int*)malloc(sizeof(int) * size);
+       (*array) = (int *) malloc(sizeof (int) * size);
        for (i = 0; i < size; ++i) {
            (*array)[i] = gh_scm2int(gh_car(scmfrom));
            scmfrom = gh_cdr(scmfrom);
@@ -540,7 +555,7 @@
        i = 0;
        CLprintf(IOOutFile, " (");
        while (i < size) {
-           CLprintf(IOOutFile, " %d", ( *array )[i]);
+           CLprintf(IOOutFile, " %d", (*array)[i]);
            ++i;
        }
        CLprintf(IOOutFile, " )");
@@ -559,12 +574,12 @@
 {
     int i;
     int size;
-    
-    size = (int)para;
+
+    size = (int) para;
 
     if (IOLoadingMode) {
        for (i = 0; i < size; ++i) {
-           ((int*)binaryform)[i] = gh_scm2int(gh_car(scmfrom));
+           ((int *) binaryform)[i] = gh_scm2int(gh_car(scmfrom));
            scmfrom = gh_cdr(scmfrom);
        }
     } else {
@@ -576,8 +591,8 @@
        }
 
        for (i = 0; i < size; ++i) {
-           CLprintf(IOOutFile, " %d", ((int*)binaryform)[i]);
-           if (i > 0  &&  !( i & 15 )) {
+           CLprintf(IOOutFile, " %d", ((int *) binaryform)[i]);
+           if (i > 0 && !(i & 15)) {
                CLprintf(IOOutFile, "\n");
                IOPrintTabs();
            }
@@ -609,7 +624,7 @@
        return;
     }
 
-    unittype = (UnitType**)binaryform;
+    unittype = (UnitType **) binaryform;
     if (IOLoadingMode) {
        str = gh_scm2newstr(scmfrom, NULL);
        (*unittype) = UnitTypeByIdent(str);
@@ -636,7 +651,7 @@
        return;
     }
 
-    upgrade = (Upgrade**)binaryform;
+    upgrade = (Upgrade **) binaryform;
     if (IOLoadingMode) {
        str = gh_scm2newstr(scmfrom, NULL);
        (*upgrade) = UpgradeByIdent(str);
@@ -658,16 +673,16 @@
 global void IOUnitPtr(SCM scmfrom, void *binaryform, void *para)
 {
     int slot;
-    
+
     if (IOHandleNullPtr(scmfrom, binaryform)) {
        return;
     }
     if (IOLoadingMode) {
        slot = gh_scm2int(scmfrom);
-       *((Unit**)binaryform) = UnitSlots[slot];
+       *((Unit **) binaryform) = UnitSlots[slot];
        // FIXME: (pludov) increment unit usage count!
     } else {
-       CLprintf(IOOutFile, " %d", (*((Unit**)binaryform))->Slot);
+       CLprintf(IOOutFile, " %d", (*((Unit **) binaryform))->Slot);
     }
 }
 
@@ -682,17 +697,17 @@
 global void IOPlayerPtr(SCM scmfrom, void *binaryform, void *para)
 {
     int playerid;
-    
+
     if (IOHandleNullPtr(scmfrom, binaryform)) {
        return;
     }
     if (IOLoadingMode) {
        // Load a player from scm
        playerid = gh_scm2int(scmfrom);
-       *((Player**)binaryform) = Players + playerid;
+       *((Player **) binaryform) = Players + playerid;
     } else {
        // Save a player to scm
-       playerid = (*((Player**)binaryform))->Player;
+       playerid = (*((Player **) binaryform))->Player;
        CLprintf(IOOutFile, " %d", playerid);
     }
 }
Index: stratagus/src/include/ccl_helpers.h
diff -u stratagus/src/include/ccl_helpers.h:1.2 
stratagus/src/include/ccl_helpers.h:1.3
--- stratagus/src/include/ccl_helpers.h:1.2     Thu Oct 23 19:31:28 2003
+++ stratagus/src/include/ccl_helpers.h Sun Oct 26 10:34:59 2003
@@ -8,7 +8,7 @@
 //                        T H E   W A R   B E G I N S
 //         Stratagus - A free fantasy real time strategy game engine
 //
-/address@hidden ccl.h          -       The clone configuration language 
headerfile. */
+/address@hidden ccl_helpers.h          -       The clone configuration 
language headerfile. */
 //
 //      (c) Copyright 2003 by Ludovic Pollet
 //
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//      $Id: ccl_helpers.h,v 1.2 2003/10/23 23:31:28 mr-russ Exp $
+//      $Id: ccl_helpers.h,v 1.3 2003/10/26 15:34:59 pludov Exp $
 
 #ifndef __CCL_HELPERS__
 #define __CCL_HELPERS__
@@ -34,41 +34,110 @@
 
 //@{
 
+/*----------------------------------------------------------------------------
+--     Documentation
+----------------------------------------------------------------------------*/
+
+/**
+**
+**     This Module is a translator to and from scheme.
+**
+**     It builds a nice looking scheme list from a structure and it's 
description
+**     It can also load a structure from this list and the description
+**
+**     The IOLoadingMode variable control wether IO functions will load or 
save datas.
+**     Theses IO functions all take the same parameters :
+**             A list : The ccl list to translate into data (unused when 
saving)
+**             A pointer : points to the structure to load, 
+**                         or to a (structure*), when loading a ptr
+**             A parameter which is used differently by the functions
+**
+**     Example:
+**     1 To load or save a unit ptr
+**
+**     void load_dummy_struct(void)
+**     {
+**             Unit* u;
+**             IOLoadingMode=1;
+**             IOUnitPtr(list, (void*)&u, 0);
+**     }
+**
+**
+**     2 To load/save a full struct
+**
+**     If the struct is :
+**
+**     typedef struct _my_struct_{
+**             UnitType*       unit;
+**             int             count;
+**     } MyStruct;
+**
+**     These describe the structure :
+**
+**     IOStructDef MyStructDef = {
+**             "MyStruct",             // Name
+**             sizeof(MyStruct),       // Size
+**             -1,                     // Array size
+**             {
+**                 { "unit", IOUnitPtr, &((MyStruct *) 0)->Unit,       0 },
+**                 { "count",IOInt,     &((MyStruct *) 0)->Count,      0 },
+**                 { 0,0,0,0 }
+**              }
+**
+**     Then :
+**     IOStructPtr(list,(void*)&myglobalstructptr,(void*)&MyStructDef);
+**     This code will load or save the myglobalstructptr, depending on 
IOLoadingMode value
+**
+**     There are more facility available ( for handling arrays,linked list,... 
).
+**     Have a look at the differents IOxxx functions for details
+*/
 
 /*----------------------------------------------------------------------------
 --     Structures
 ----------------------------------------------------------------------------*/
 
-// FIXME: (mr-russ) document
-
-typedef struct _ccl_flag_def_
-{
-    char*      ident;
-    int                value;
-} CclFlagDef;
-
-typedef struct _ccl_field_def_
-{
-    char*      name;
-    void       (*convertfunc)(SCM scmfrom, void *binaryform, void *para);
-    void*      offset;
-    void*      para;
-} CclFieldDef;
-
-typedef struct _IOStruct_def_
-{
-    char*      name;
-    int                size;
-    int                array_size;
-    CclFieldDef        defs[];
-} CclStructDef;
+/**
+**     Definition of flags. 
+**     Each flag map an int value to a SCM symbol
+*/
+typedef struct _io_flag_def_ {
+    char*              ident;          /// Flag name
+    int                        value;          /// Flag value
+} IOFlagDef;
+
+/**
+**     The IOFieldDef structure define each field in a structure
+**     The name of the field is used to identify the field in Scheme LIST.
+**
+**     The fonction receive as parameter (binaryform), a void pointer to the 
field
+*/
+typedef struct _io_field_def_ {
+    char*              name;           /// Name of the field ( used as ccl 
ident )
+    void                (*convertfunc) (SCM scmfrom, void* binaryform, void* 
para);
+                                       /// Function to load/save the field
+    void*              offset;         /// Offset of the field in the structure
+    void*              para;           /// Parameter passed to the field
+} IOFieldDef;
+
+/**
+**     The IOStructDef define a full structure, for loading & saving.
+**     It is meant to be used with the IOStruct or IOStruct parameter,
+**     to load or save a structure (depending on IOLoadingMode value)
+**
+*/
+typedef struct _io_struct_def_ {
+    char*              name;           /// Name of the structure (debugging 
only)
+    int                 size;          /// Size of the structure (for malloc)
+    int                 array_size;    /// Number of element when in an array
+    IOFieldDef         defs[];         /// Definition of fields, terminated by 
a null field
+} IOStructDef;
 
 /*----------------------------------------------------------------------------
 --     Variables
 ----------------------------------------------------------------------------*/
-extern int IOLoadingMode;
-extern unsigned int IOTabLevel;
-extern CLFile* IOOutFile;
+extern int          IOLoadingMode;     /// IOxxx functions do load (1) or save 
(0) struct 
+extern unsigned int IOTabLevel;                /// When saving to ccl, current 
indentation level
+extern CLFile      *IOOutFile;         /// When saving to ccl, output file
 
 /*----------------------------------------------------------------------------
 --     Functions
@@ -77,52 +146,44 @@
     /// Print "IOTabLevel" tabs on the ccl output
 extern void IOPrintTabs();
     /// Handle saving/loading of structure
-extern void IOStruct(SCM scmform, void *binaryform, void *para);
+extern void IOStruct(SCM scmform, void* binaryform, void* para);
     /// Handle saving/loading a pointer to a structure.
-extern void IOStructPtr(SCM scmform, void *binaryform, void *para);
+extern void IOStructPtr(SCM scmform, void* binaryform, void* para);
     /// Handle loading a fixed size array of structure.
-extern void IOStructArray( SCM from, void *binaryform, void *para);
+extern void IOStructArray(SCM from, void* binaryform, void* para);
     /// Handle saving/loading linked list.
-extern void IOLinkedList(SCM scmfrom, void *binaryform, void *para);
+extern void IOLinkedList(SCM scmfrom, void* binaryform, void* para);
     /// Handle saving/loading tables.
-extern void IOTable(SCM scmfrom, void *binaryform, void *para);
+extern void IOTable(SCM scmfrom, void* binaryform, void* para);
     /// Handle the case of saving/loading pointers which are null
-extern int IOHandleNullPtr(SCM scmfrom, void *binaryform);
+extern int IOHandleNullPtr(SCM scmfrom, void* binaryform);
     /// Handle saving/loading of int
-extern void IOInt(SCM scmform, void *binaryform, void *para);
+extern void IOInt(SCM scmform, void* binaryform, void* para);
     /// Handle saving/loading of bool stored as int 
-extern void IOBool(SCM scmfrom, void *binaryform, void *para);
+extern void IOBool(SCM scmfrom, void* binaryform, void* para);
     /// Handle saving/loading of bool stored as char
-extern void IOCharBool(SCM scmfrom, void *binaryform, void *para);
+extern void IOCharBool(SCM scmfrom, void* binaryform, void* para);
     /// Handle saving/loading of string
-extern void IOString(SCM scmfrom, void *binaryform, void *para);
+extern void IOString(SCM scmfrom, void* binaryform, void* para);
     /// Handle saving/loading of SCM
-extern void IOCcl(SCM scmfrom, void *binaryform, void *para);
+extern void IOCcl(SCM scmfrom, void* binaryform, void* para);
     /// Handle saving/loading of flag stored in char
-extern void IOCharFlag(SCM scmfrom, void *binaryform, void *para);
+extern void IOCharFlag(SCM scmfrom, void* binaryform, void* para);
     /// Handle saving/loading a fixed length string
-extern void IOStrBuffer(SCM scmfrom, void *binaryform, void *para);
+extern void IOStrBuffer(SCM scmfrom, void* binaryform, void* para);
     /// Handle saving/loading a dynamic array of int
-extern void IOIntArrayPtr(SCM scmfrom, void *binaryform, void *para);
+extern void IOIntArrayPtr(SCM scmfrom, void* binaryform, void* para);
     /// Handle saving/loading an already allocated array of int
-extern void IOIntArray(SCM scmfrom, void *binaryform, void *para);
-
+extern void IOIntArray(SCM scmfrom, void* binaryform, void* para);
     /// Handle saving/loading an unittype pointer (UnitType*)
-extern void IOUnitTypePtr(SCM scmfrom, void *binaryform, void *para);
+extern void IOUnitTypePtr(SCM scmfrom, void* binaryform, void* para);
     /// Handle saving/loading a reference to an unit (Unit*)
-extern void IOUnitPtr(SCM scmfrom, void *binaryform, void *para);
+extern void IOUnitPtr(SCM scmfrom, void* binaryform, void* para);
     /// Handle saving/loading a reference to an upgrade (Upgrade*)
-extern void IOUpgradePtr(SCM scmfrom, void *binaryform, void *para);
+extern void IOUpgradePtr(SCM scmfrom, void* binaryform, void* para);
     /// Handle saving/loading a reference to a player (Player*)
-extern void IOPlayerPtr(SCM scmfrom, void *binaryform, void *para);
-
+extern void IOPlayerPtr(SCM scmfrom, void* binaryform, void* para);
 
-#if 0
-    /// Handle saving/loading a reference to an aitype. (AiType*)
-extern void IOAiTypePtr(SCM from,void * binaryform,void * para);
-    /// Handle saving/loading a reference to an AiScriptAction. 
(AiScriptAction**)
-extern void IOAiScriptActionPtr(SCM scmfrom,void * binaryform,void * para);
-#endif
 //@}
 
-#endif                         // !__CCL_H__
+#endif         // !__CCL_H__




reply via email to

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