stratagus-cvs
[Top][All Lists]
Advanced

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

[Stratagus-CVS] stratagus/src/map map_fog.c


From: Jimmy Salmon
Subject: [Stratagus-CVS] stratagus/src/map map_fog.c
Date: Thu, 02 Oct 2003 01:33:50 -0400

CVSROOT:        /cvsroot/stratagus
Module name:    stratagus
Branch:         
Changes by:     Jimmy Salmon <address@hidden>   03/10/02 01:33:50

Modified files:
        src/map        : map_fog.c 

Log message:
        Cleanup

Patches:
Index: stratagus/src/map/map_fog.c
diff -u stratagus/src/map/map_fog.c:1.106 stratagus/src/map/map_fog.c:1.107
--- stratagus/src/map/map_fog.c:1.106   Thu Sep 18 13:56:04 2003
+++ stratagus/src/map/map_fog.c Thu Oct  2 01:33:50 2003
@@ -27,7 +27,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: map_fog.c,v 1.106 2003/09/18 17:56:04 n0body Exp $
+//     $Id: map_fog.c,v 1.107 2003/10/02 05:33:50 jsalmon3 Exp $
 
 //@{
 
@@ -74,10 +74,10 @@
 **     @param x        Index passed to UNROLL2 incremented by 2.
 */
 #define UNROLL8(x)     \
-    UNROLL2((x)+0);    \
-    UNROLL2((x)+2);    \
-    UNROLL2((x)+4);    \
-    UNROLL2((x)+6)
+    UNROLL2((x) + 0);  \
+    UNROLL2((x) + 2);  \
+    UNROLL2((x) + 4);  \
+    UNROLL2((x) + 6)
 
 /**
 **     Do unroll 16x
@@ -85,8 +85,8 @@
 **     @param x        Index passed to UNROLL8 incremented by 8.
 */
 #define UNROLL16(x)    \
-    UNROLL8((x)+ 0);   \
-    UNROLL8((x)+ 8)
+    UNROLL8((x) + 0);  \
+    UNROLL8((x) + 8)
 
 /**
 **     Do unroll 32x
@@ -94,19 +94,19 @@
 **     @param x        Index passed to UNROLL8 incremented by 8.
 */
 #define UNROLL32(x)    \
-    UNROLL8((x)+ 0);   \
-    UNROLL8((x)+ 8);   \
-    UNROLL8((x)+16);   \
-    UNROLL8((x)+24)
+    UNROLL8((x) + 0);  \
+    UNROLL8((x) + 8);  \
+    UNROLL8((x) + 16); \
+    UNROLL8((x) + 24)
 
 /*----------------------------------------------------------------------------
 --     Variables
 ----------------------------------------------------------------------------*/
 
 global int OriginalFogOfWar;           /// Use original style fog of war
-global int FogOfWarContrast=50;                /// Contrast of fog of war
-global int FogOfWarBrightness=10;      /// Brightness of fog of war
-global int FogOfWarSaturation=40;      /// Saturation of fog of war
+global int FogOfWarContrast = 50;      /// Contrast of fog of war
+global int FogOfWarBrightness = 10;    /// Brightness of fog of war
+global int FogOfWarSaturation = 40;    /// Saturation of fog of war
 
 #define MapFieldCompletelyVisible   0x0001  /// Field completely visible
 #define MapFieldPartiallyVisible    0x0002  /// Field partially visible
@@ -118,22 +118,22 @@
      0,11,10, 2,  13, 6, 0, 3,  12, 0, 4, 1,  8, 9, 7, 0,
 };
 
-global unsigned char *VisionTable[3];
-global int *VisionLookup;
+global unsigned char* VisionTable[3];
+global int* VisionLookup;
 /**
 **     Draw unexplored area function pointer. (display and video mode independ)
 */
-local void (*VideoDrawUnexplored)(const GraphicData*,int,int);
+local void (*VideoDrawUnexplored)(const GraphicData*, int, int);
 
 /**
 **     Draw fog of war function pointer. (display and video mode independ)
 */
-local void (*VideoDrawFog)(const GraphicData*,int,int);
+local void (*VideoDrawFog)(const GraphicData*, int, int);
 
 /**
 **     Draw only fog of war function pointer. (display and video mode independ)
 */
-local void (*VideoDrawOnlyFog)(const GraphicData*,int x,int y);
+local void (*VideoDrawOnlyFog)(const GraphicData*, int x, int y);
 
 /**
 **     Precalculated fog of war alpha table.
@@ -154,7 +154,7 @@
 **
 **     @return         Number of units that can see this square.
 */
-local int LookupSight(const Player* player,int tx,int ty)
+local int LookupSight(const Player* player, int tx, int ty)
 {
     int i;
     int visiblecount;
@@ -163,18 +163,20 @@
     Unit* unit;
 
     visiblecount=0;
-    for( i=0; i<player->TotalNumUnits; ++i ) {
-       unit=player->Units[i];
-       range=unit->CurrentSightRange;
-       mapdistance=MapDistanceToUnit(tx,ty,unit);
-       if( mapdistance <= range) {
+    for (i = 0; i < player->TotalNumUnits; ++i) {
+       unit = player->Units[i];
+       range = unit->CurrentSightRange;
+       mapdistance = MapDistanceToUnit(tx,ty,unit);
+       if (mapdistance <= range) {
            ++visiblecount;
        }
-       if( (tx >= unit->X && tx < unit->X+unit->Type->TileWidth && mapdistance 
== range+1) ||
-           (ty >= unit->Y && ty < unit->Y+unit->Type->TileHeight && 
mapdistance == range+1)) {
+       if ((tx >= unit->X && tx < unit->X + unit->Type->TileWidth &&
+               mapdistance == range + 1) || (ty >= unit->Y &&
+               ty < unit->Y + unit->Type->TileHeight &&
+               mapdistance == range + 1)) {
            --visiblecount;
        }
-       if( visiblecount >= 255 ) {
+       if (visiblecount >= 255) {
            return 255;
        }
     }
@@ -190,23 +192,23 @@
 **
 **     @return         0 unexplored, 1 explored, >1 visible.
 */
-global int IsTileVisible(const Player* player,int x,int y)
+global int IsTileVisible(const Player* player, int x, int y)
 {
     int visiontype;
     int i;
 
-    if( TheMap.Fields[y*TheMap.Width+x].Visible[player->Player]>1 ) {
+    if (TheMap.Fields[y * TheMap.Width + x].Visible[player->Player]>1) {
        return 2;
     }
-    visiontype=TheMap.Fields[y*TheMap.Width+x].Visible[player->Player];
-    for( i=0; i<PlayerMax && visiontype < 2; i++ ) {
-       if( player->SharedVision&(1<<i) &&
-           (Players[i].SharedVision&(1<<player->Player)) ) {
-            if( visiontype<TheMap.Fields[y*TheMap.Width+x].Visible[i] ) {
-               visiontype=TheMap.Fields[y*TheMap.Width+x].Visible[i];
+    visiontype=TheMap.Fields[y * TheMap.Width + x].Visible[player->Player];
+    for (i = 0; i < PlayerMax && visiontype < 2; ++i) {
+       if (player->SharedVision & (1 << i) &&
+               (Players[i].SharedVision & (1 << player->Player))) {
+            if (visiontype < TheMap.Fields[y * TheMap.Width + x].Visible[i]) {
+               visiontype = TheMap.Fields[y * TheMap.Width + x].Visible[i];
            }
        }
-       if( visiontype>1 ) {
+       if (visiontype > 1) {
            return 2;
        }
     }
@@ -231,50 +233,51 @@
     Unit** corpses;
     int w;
     int h;
-    v=TheMap.Fields[x+y*TheMap.Width].Visible[player->Player];
+ 
+    v = TheMap.Fields[x + y * TheMap.Width].Visible[player->Player];
 
-    switch( v ) {
-    case 0:            // Unexplored
-    case 1:            // Unseen
-    // FIXME: mark for screen update
-       v=2;
-       if( player->Type == PlayerPerson ) {
-           corpses = &DestroyedBuildings;
-           while( *corpses ) {
-               unit = *corpses;
-               if( (unit->Visible & 1 << player->Player) ) {
-                   w = unit->Type->TileWidth;
-                   h = unit->Type->TileHeight;
-                   if( x >= unit->X && y >= unit->Y
-                       && x < unit->X+w && y < unit->Y+h ) {
+    switch (v) {
+       case 0:         // Unexplored
+       case 1:         // Unseen
+       // FIXME: mark for screen update
+           v = 2;
+           if (player->Type == PlayerPerson) {
+               corpses = &DestroyedBuildings;
+               while (*corpses) {
+                   unit = *corpses;
+                   if ((unit->Visible & 1 << player->Player)) {
+                       w = unit->Type->TileWidth;
+                       h = unit->Type->TileHeight;
+                       if (x >= unit->X && y >= unit->Y &&
+                               x < unit->X+w && y < unit->Y+h) {
                            unit->Visible &= ~(1 << player->Player);
                            UnitMarkSeen(unit);
+                       }
+                   }
+                   remove = unit;
+                   unit = unit->Next;
+                   corpses = &unit;
+                   if (remove->Visible == 0x0000 && !remove->Refs) {
+                       ReleaseUnit(remove);
                    }
-               }
-               remove = unit;
-               unit = unit->Next;
-               corpses=&(unit);
-               if( remove->Visible==0x0000 && !remove->Refs ) {
-                   ReleaseUnit(remove);
                }
            }
-        }
-       TheMap.Fields[x+y*TheMap.Width].Visible[player->Player]=v;
-       if( IsTileVisible(ThisPlayer,x,y) > 1) {
-           MapMarkSeenTile(x,y);
-           UnitsMarkSeen(x,y);
-       }
+           TheMap.Fields[x + y * TheMap.Width].Visible[player->Player] = v;
+           if (IsTileVisible(ThisPlayer, x, y) > 1) {
+               MapMarkSeenTile(x, y);
+               UnitsMarkSeen(x, y);
+           }
 
-       return;
-    case 255:          // Overflow
-       DebugLevel0Fn("Visible overflow (Player): %d\n" _C_ player->Player);
-       break;
-
-    default:           // seen -> seen
-       v++;
-       break;
+           return;
+       case 255:               // Overflow
+           DebugLevel0Fn("Visible overflow (Player): %d\n" _C_ player->Player);
+           break;
+
+       default:                // seen -> seen
+           ++v;
+           break;
     }
-    TheMap.Fields[x+y*TheMap.Width].Visible[player->Player]=v;
+    TheMap.Fields[x + y * TheMap.Width].Visible[player->Player] = v;
 }
 
 /**
@@ -284,33 +287,34 @@
 **     @param x        X tile to mark.
 **     @param y        Y tile to mark.
 */
-global void MapUnmarkTileSight(const Player* player,int x,int y)
+global void MapUnmarkTileSight(const Player* player, int x, int y)
 {
     unsigned char v;
-    v=TheMap.Fields[x+y*TheMap.Width].Visible[player->Player];
-    switch( v ) {
+
+    v = TheMap.Fields[x + y * TheMap.Width].Visible[player->Player];
+    switch (v) {
        case 255:
            // FIXME: (mr-russ) Lookupsight is broken :(
-           DebugCheck( 1 );
-           v = LookupSight(player,x,y);
-           DebugCheck( v < 254 );
+           DebugCheck(1);
+           v = LookupSight(player, x, y);
+           DebugCheck(v < 254);
            break;
        case 0:         // Unexplored
        case 1:
            // We are at minimum, don't do anything shouldn't happen.
-           DebugCheck( 1 );
+           DebugCheck(1);
            break;
        case 2:
            // Check visible Tile, then deduct...
-           if( IsTileVisible(ThisPlayer,x,y) > 1) {
-               MapMarkSeenTile(x,y);
-               UnitsMarkSeen(x,y);
+           if (IsTileVisible(ThisPlayer, x, y) > 1) {
+               MapMarkSeenTile(x, y);
+               UnitsMarkSeen(x, y);
            }
        default:                // seen -> seen
            v--;
            break;
     }
-    TheMap.Fields[x+y*TheMap.Width].Visible[player->Player]=v;
+    TheMap.Fields[x + y * TheMap.Width].Visible[player->Player] = v;
 }
 
 /**
@@ -320,17 +324,17 @@
 **     @param x        X tile to mark.
 **     @param y        Y tile to mark.
 */
-global void MapDetectUnitsOnTile(const Player* player,int x,int y)
+global void MapDetectUnitsOnTile(const Player* player, int x, int y)
 {
     Unit* table[UnitMax];
     int n;
     int i;
     int pm;
 
-    n=SelectUnitsOnTile(x,y,table);
-    pm=((1<<player->Player)|player->SharedVision);
-    for( i=0; i<n; ++i ) {
-       table[i]->Visible|=pm;
+    n = SelectUnitsOnTile(x, y, table);
+    pm = ((1 << player->Player) | player->SharedVision);
+    for (i = 0; i < n; ++i) {
+       table[i]->Visible |= pm;
     }
 }
 
@@ -345,7 +349,8 @@
 **     @param range    Radius to mark.
 **     @param marker   Function to mark or unmark sight
 */
-global void MapSight(const Player* player, int x, int y, int w, int h, int 
range, void (*marker)(const Player*,int,int))
+global void MapSight(const Player* player, int x, int y, int w, int h, int 
range,
+    void (*marker)(const Player*, int, int))
 {
     int mx;
     int my;
@@ -356,83 +361,83 @@
     int p;
 
     // Mark as seen
-    if( !range ) {                     // zero sight range is zero sight range
+    if (!range) {                      // zero sight range is zero sight range
        DebugLevel0Fn("Zero sight range\n");
        return;
     }
 
-    p=player->Player;
+    p = player->Player;
 
     // Mark Horizontal sight for unit
-    for(mx=x-range; mx < x+range+w; mx++) {
-        for(my=y; my < y+h; my++) {
-           if( mx >= 0 && mx < TheMap.Width ) {
-               marker(player,mx,my);
+    for (mx = x - range; mx < x + range + w; ++mx) {
+        for (my = y; my < y + h; ++my) {
+           if (mx >= 0 && mx < TheMap.Width) {
+               marker(player, mx, my);
            }
        }
     }
 
     // Mark vertical sight for unit (don't remark self) (above unit)
-    for(my=y-range; my < y; my++) {
-        for(mx=x; mx < x+w; mx++) {
-           if( my >= 0 && my < TheMap.Width ) {
-               marker(player,mx,my);
+    for (my = y - range; my < y; ++my) {
+        for (mx = x; mx < x + w; ++mx) {
+           if (my >= 0 && my < TheMap.Width) {
+               marker(player, mx, my);
            }
        }
     }
 
     // Mark vertical sight for unit (don't remark self) (below unit)
-    for(my=y+h; my < y+range+h; my++) {
-        for(mx=x; mx < x+w; mx++) {
-       if( my >= 0 && my < TheMap.Width ) {
-           marker(player,mx,my);
-       }
+    for (my = y + h; my < y + range + h; ++my) {
+       for (mx = x; mx < x + w; ++mx) {
+           if (my >= 0 && my < TheMap.Width) {
+               marker(player, mx, my);
+           }
        }
     }
 
     // Now the cross has been marked, need to use loop to mark in circle
-    steps=0;
-    while(VisionTable[0][steps] <= range) {
+    steps = 0;
+    while (VisionTable[0][steps] <= range) {
        // 0 - Top right Quadrant
-       cx[0] = x+w-1;
-       cy[0] = y-VisionTable[0][steps];
+       cx[0] = x + w - 1;
+       cy[0] = y - VisionTable[0][steps];
        // 1 - Top left Quadrant
        cx[1] = x;
-       cy[1] = y-VisionTable[0][steps];
+       cy[1] = y - VisionTable[0][steps];
        // 2 - Bottom Left Quadrant
        cx[2] = x;
-       cy[2] = y+VisionTable[0][steps]+h-1;
+       cy[2] = y + VisionTable[0][steps] + h - 1;
        // 3 - Bottom Right Quadrant
-       cx[3] = x+w-1;
-       cy[3] = y+VisionTable[0][steps]+h-1;
+       cx[3] = x + w - 1;
+       cy[3] = y + VisionTable[0][steps] + h - 1;
        // loop for steps
-       steps++;        // Increment past info pointer
-       while(VisionTable[1][steps] != 0 || VisionTable[2][steps] != 0 ) {
+       ++steps;        // Increment past info pointer
+       while (VisionTable[1][steps] != 0 || VisionTable[2][steps] != 0) {
            // Loop through for repeat cycle
-           cycle=0;
-           while( cycle++ < VisionTable[0][steps] ) {
-               cx[0]+=VisionTable[1][steps];
-               cy[0]+=VisionTable[2][steps];
-               cx[1]-=VisionTable[1][steps];
-               cy[1]+=VisionTable[2][steps];
-               cx[2]-=VisionTable[1][steps];
-               cy[2]-=VisionTable[2][steps];
-               cx[3]+=VisionTable[1][steps];
-               cy[3]-=VisionTable[2][steps];
-               if( cx[0] < TheMap.Width && cy[0] >= 0) {
-                   marker(player,cx[0],cy[0]);
+           cycle = 0;
+           while (cycle++ < VisionTable[0][steps]) {
+               cx[0] += VisionTable[1][steps];
+               cy[0] += VisionTable[2][steps];
+               cx[1] -= VisionTable[1][steps];
+               cy[1] += VisionTable[2][steps];
+               cx[2] -= VisionTable[1][steps];
+               cy[2] -= VisionTable[2][steps];
+               cx[3] += VisionTable[1][steps];
+               cy[3] -= VisionTable[2][steps];
+               if (cx[0] < TheMap.Width && cy[0] >= 0) {
+                   marker(player, cx[0], cy[0]);
                }
-               if( cx[1] >= 0 && cy[1] >= 0) {
-                   marker(player,cx[1],cy[1]);
+               if (cx[1] >= 0 && cy[1] >= 0) {
+                   marker(player, cx[1], cy[1]);
                }
-               if( cx[2] >= 0 && cy[2] < TheMap.Height ) {
-                   marker(player,cx[2],cy[2]);
+               if (cx[2] >= 0 && cy[2] < TheMap.Height) {
+                   marker(player, cx[2], cy[2]);
                }
-               if( cx[3] < TheMap.Width && cy[3] < TheMap.Height ) {
-                   marker(player,cx[3],cy[3]);
+               if (cx[3] < TheMap.Width && cy[3] < TheMap.Height) {
+                   marker(player, cx[3], cy[3]);
                }
            }
-           steps++;
+           ++steps;
        }
     }
 }
@@ -449,13 +454,13 @@
     //
     // Mark all explored fields as visible.
     //
-    if( TheMap.NoFogOfWar ) {
-       w=TheMap.Width;
-       for( y=0; y<TheMap.Height; y++ ) {
-           for( x=0; x<TheMap.Width; ++x ) {
-               if( IsMapFieldExplored(ThisPlayer,x,y) ) {
-                   MapMarkSeenTile( x,y );
-                   UnitsMarkSeen( x,y );
+    if (TheMap.NoFogOfWar) {
+       w = TheMap.Width;
+       for (y = 0; y < TheMap.Height; ++y) {
+           for (x = 0; x < TheMap.Width; ++x) {
+               if (IsMapFieldExplored(ThisPlayer, x, y)) {
+                   MapMarkSeenTile(x, y);
+                   UnitsMarkSeen(x, y);
                }
            }
        }
@@ -476,42 +481,42 @@
 **     @param x        X position into video memory.
 **     @param y        Y position into video memory.
 */
-global void VideoDraw8Fog16Solid(const GraphicData* data,int x,int y)
+global void VideoDraw8Fog16Solid(const GraphicData* data, int x, int y)
 {
     const unsigned char* sp;
     const unsigned char* gp;
     VMemType8* dp;
     int da;
 
-    sp=data;
-    gp=sp+TileSizeY*TileSizeX;
-    dp=VideoMemory8+x+y*VideoWidth;
-    da=VideoWidth;
+    sp = data;
+    gp = sp + TileSizeY * TileSizeX;
+    dp = VideoMemory8 + x + y * VideoWidth;
+    da = VideoWidth;
 
-    while( sp<gp ) {
+    while (sp < gp) {
 #undef UNROLL1
 #define UNROLL1(x)     \
        if(COLOR_FOG_P(sp[x])) {                \
-           dp[x]=((VMemType8*)TheMap.TileData->Pixels)[COLOR_FOG];     \
+           dp[x] = ((VMemType8*)TheMap.TileData->Pixels)[COLOR_FOG];   \
        }
 
 #undef UNROLL2
 #define UNROLL2(x)     \
-       UNROLL1(x+0);
+       UNROLL1(x + 0);
 
        UNROLL16(0);
 
-       sp+=TileSizeX;
-       dp+=da;
+       sp += TileSizeX;
+       dp += da;
 
 #undef UNROLL2
 #define UNROLL2(x)     \
-       UNROLL1(x+1);
+       UNROLL1(x + 1);
 
        UNROLL16(0);
 
-       sp+=TileSizeX;
-       dp+=da;
+       sp += TileSizeX;
+       dp += da;
     }
 }
 
@@ -525,27 +530,28 @@
 **     @param x        X position into video memory
 **     @param y        Y position into video memory
 */
-global void VideoDraw8OnlyFog16Solid(const GraphicData* data 
__attribute__((unused)),int x,int y)
+global void VideoDraw8OnlyFog16Solid(const GraphicData* data 
__attribute__((unused)),
+    int x, int y)
 {
     const VMemType8* gp;
     VMemType8* dp;
     int da;
 
-    dp=VideoMemory8+x+y*VideoWidth;
-    gp=dp+VideoWidth*TileSizeX;
-    da=VideoWidth;
-    while( dp<gp ) {
+    dp = VideoMemory8 + x + y * VideoWidth;
+    gp = dp + VideoWidth * TileSizeX;
+    da = VideoWidth;
+    while (dp < gp) {
 #undef UNROLL2
 #define UNROLL2(x)             \
-       dp[x+0]=((VMemType8*)TheMap.TileData->Pixels)[COLOR_FOG];
+       dp[x + 0] = ((VMemType8*)TheMap.TileData->Pixels)[COLOR_FOG];
        UNROLL16(0);
-       dp+=da;
+       dp += da;
 
 #undef UNROLL2
 #define UNROLL2(x)             \
-       dp[x+1]=((VMemType8*)TheMap.TileData->Pixels)[COLOR_FOG];
+       dp[x + 1] = ((VMemType8*)TheMap.TileData->Pixels)[COLOR_FOG];
        UNROLL16(0);
-       dp+=da;
+       dp += da;
     }
 }
 
@@ -556,37 +562,37 @@
 **     @param x        X position into video memory
 **     @param y        Y position into video memory
 */
-global void VideoDraw8Unexplored16Solid(const GraphicData* data,int x,int y)
+global void VideoDraw8Unexplored16Solid(const GraphicData* data, int x, int y)
 {
     const unsigned char* sp;
     const unsigned char* gp;
     VMemType8* dp;
     int da;
 
-    sp=data;
-    gp=sp+TileSizeY*TileSizeX;
-    dp=VideoMemory8+x+y*VideoWidth;
-    da=VideoWidth;
+    sp = data;
+    gp = sp + TileSizeY * TileSizeX;
+    dp = VideoMemory8 + x + y * VideoWidth;
+    da = VideoWidth;
 
-    while( sp<gp ) {
+    while (sp < gp) {
 #undef UNROLL1
 #define UNROLL1(x)     \
-       if(COLOR_FOG_P(sp[x]) ) {               \
-           dp[x]=((VMemType8*)TheMap.TileData->Pixels)[COLOR_FOG];     \
+       if(COLOR_FOG_P(sp[x])) {                \
+           dp[x] = ((VMemType8*)TheMap.TileData->Pixels)[COLOR_FOG];   \
        }
 
 #undef UNROLL2
 #define UNROLL2(x)     \
-       UNROLL1(x+0);   \
-       UNROLL1(x+1);
+       UNROLL1(x + 0); \
+       UNROLL1(x + 1);
 
        UNROLL16(0);
-       sp+=TileSizeX;
-       dp+=da;
+       sp += TileSizeX;
+       dp += da;
 
        UNROLL16(0);
-       sp+=TileSizeX;
-       dp+=da;
+       sp += TileSizeX;
+       dp += da;
 
     }
 }
@@ -598,42 +604,42 @@
 **     @param x        X position into video memory.
 **     @param y        Y position into video memory.
 */
-global void VideoDraw8Fog32Solid(const GraphicData* data,int x,int y)
+global void VideoDraw8Fog32Solid(const GraphicData* data, int x, int y)
 {
     const unsigned char* sp;
     const unsigned char* gp;
     VMemType8* dp;
     int da;
 
-    sp=data;
-    gp=sp+TileSizeY*TileSizeX;
-    dp=VideoMemory8+x+y*VideoWidth;
-    da=VideoWidth;
+    sp = data;
+    gp = sp + TileSizeY * TileSizeX;
+    dp = VideoMemory8 + x + y * VideoWidth;
+    da = VideoWidth;
 
-    while( sp<gp ) {
+    while (sp < gp) {
 #undef UNROLL1
 #define UNROLL1(x)     \
        if(COLOR_FOG_P(sp[x])) {                \
-           dp[x]=((VMemType8*)TheMap.TileData->Pixels)[COLOR_FOG];     \
+           dp[x] = ((VMemType8*)TheMap.TileData->Pixels)[COLOR_FOG];   \
        }
 
 #undef UNROLL2
 #define UNROLL2(x)     \
-       UNROLL1(x+0);
+       UNROLL1(x + 0);
 
        UNROLL32(0);
 
-       sp+=TileSizeX;
-       dp+=da;
+       sp += TileSizeX;
+       dp += da;
 
 #undef UNROLL2
 #define UNROLL2(x)     \
-       UNROLL1(x+1);
+       UNROLL1(x + 1);
 
        UNROLL32(0);
 
-       sp+=TileSizeX;
-       dp+=da;
+       sp += TileSizeX;
+       dp += da;
     }
 }
 
@@ -647,27 +653,28 @@
 **     @param x        X position into video memory
 **     @param y        Y position into video memory
 */
-global void VideoDraw8OnlyFog32Solid(const GraphicData* data 
__attribute__((unused)),int x,int y)
+global void VideoDraw8OnlyFog32Solid(const GraphicData* data 
__attribute__((unused)),
+    int x, int y)
 {
     const VMemType8* gp;
     VMemType8* dp;
     int da;
 
-    dp=VideoMemory8+x+y*VideoWidth;
-    gp=dp+VideoWidth*TileSizeX;
-    da=VideoWidth;
-    while( dp<gp ) {
+    dp = VideoMemory8 + x + y * VideoWidth;
+    gp = dp + VideoWidth * TileSizeX;
+    da = VideoWidth;
+    while (dp < gp) {
 #undef UNROLL2
 #define UNROLL2(x)             \
-       dp[x+0]=((VMemType8*)TheMap.TileData->Pixels)[COLOR_FOG];
+       dp[x + 0] = ((VMemType8*)TheMap.TileData->Pixels)[COLOR_FOG];
        UNROLL32(0);
-       dp+=da;
+       dp += da;
 
 #undef UNROLL2
 #define UNROLL2(x)             \
-       dp[x+1]=((VMemType8*)TheMap.TileData->Pixels)[COLOR_FOG];
+       dp[x + 1] = ((VMemType8*)TheMap.TileData->Pixels)[COLOR_FOG];
        UNROLL32(0);
-       dp+=da;
+       dp += da;
     }
 }
 
@@ -678,37 +685,37 @@
 **     @param x        X position into video memory
 **     @param y        Y position into video memory
 */
-global void VideoDraw8Unexplored32Solid(const GraphicData* data,int x,int y)
+global void VideoDraw8Unexplored32Solid(const GraphicData* data, int x, int y)
 {
     const unsigned char* sp;
     const unsigned char* gp;
     VMemType8* dp;
     int da;
 
-    sp=data;
-    gp=sp+TileSizeY*TileSizeX;
-    dp=VideoMemory8+x+y*VideoWidth;
-    da=VideoWidth;
+    sp = data;
+    gp = sp + TileSizeY * TileSizeX;
+    dp = VideoMemory8 + x + y * VideoWidth;
+    da = VideoWidth;
 
-    while( sp<gp ) {
+    while (sp < gp) {
 #undef UNROLL1
 #define UNROLL1(x)     \
-       if(COLOR_FOG_P(sp[x]) ) {               \
-           dp[x]=((VMemType8*)TheMap.TileData->Pixels)[COLOR_FOG];     \
+       if(COLOR_FOG_P(sp[x])) {                \
+           dp[x] = ((VMemType8*)TheMap.TileData->Pixels)[COLOR_FOG];   \
        }
 
 #undef UNROLL2
 #define UNROLL2(x)     \
-       UNROLL1(x+0);   \
-       UNROLL1(x+1);
+       UNROLL1(x + 0); \
+       UNROLL1(x + 1);
 
        UNROLL32(0);
-       sp+=TileSizeX;
-       dp+=da;
+       sp += TileSizeX;
+       dp += da;
 
        UNROLL32(0);
-       sp+=TileSizeX;
-       dp+=da;
+       sp += TileSizeX;
+       dp += da;
 
     }
 }
@@ -722,42 +729,42 @@
 **     @param x        X position into video memory.
 **     @param y        Y position into video memory.
 */
-global void VideoDraw16Fog16Solid(const GraphicData* data,int x,int y)
+global void VideoDraw16Fog16Solid(const GraphicData* data, int x, int y)
 {
     const unsigned char* sp;
     const unsigned char* gp;
     VMemType16* dp;
     int da;
 
-    sp=data;
-    gp=sp+TileSizeY*TileSizeX;
-    dp=VideoMemory16+x+y*VideoWidth;
-    da=VideoWidth;
+    sp = data;
+    gp = sp + TileSizeY * TileSizeX;
+    dp = VideoMemory16 + x + y * VideoWidth;
+    da = VideoWidth;
 
-    while( sp<gp ) {
+    while (sp < gp) {
 #undef UNROLL1
 #define UNROLL1(x)     \
        if(COLOR_FOG_P(sp[x])) {                \
-           dp[x]=((VMemType16*)TheMap.TileData->Pixels)[COLOR_FOG];    \
+           dp[x] = ((VMemType16*)TheMap.TileData->Pixels)[COLOR_FOG];  \
        }
 
 #undef UNROLL2
 #define UNROLL2(x)     \
-       UNROLL1(x+0);
+       UNROLL1(x + 0);
 
        UNROLL16(0);
 
-       sp+=TileSizeX;
-       dp+=da;
+       sp += TileSizeX;
+       dp += da;
 
 #undef UNROLL2
 #define UNROLL2(x)     \
-       UNROLL1(x+1);
+       UNROLL1(x + 1);
 
        UNROLL16(0);
 
-       sp+=TileSizeX;
-       dp+=da;
+       sp += TileSizeX;
+       dp += da;
     }
 }
 
@@ -771,27 +778,28 @@
 **     @param x        X position into video memory
 **     @param y        Y position into video memory
 */
-global void VideoDraw16OnlyFog16Solid(const GraphicData* data 
__attribute__((unused)),int x,int y)
+global void VideoDraw16OnlyFog16Solid(const GraphicData* data 
__attribute__((unused)),
+    int x, int y)
 {
     const VMemType16* gp;
     VMemType16* dp;
     int da;
 
-    dp=VideoMemory16+x+y*VideoWidth;
-    gp=dp+VideoWidth*TileSizeX;
-    da=VideoWidth;
-    while( dp<gp ) {
+    dp = VideoMemory16 + x + y * VideoWidth;
+    gp = dp + VideoWidth * TileSizeX;
+    da = VideoWidth;
+    while (dp < gp) {
 #undef UNROLL2
 #define UNROLL2(x)             \
-       dp[x+0]=((VMemType16*)TheMap.TileData->Pixels)[COLOR_FOG];
+       dp[x + 0] = ((VMemType16*)TheMap.TileData->Pixels)[COLOR_FOG];
        UNROLL16(0);
-       dp+=da;
+       dp += da;
 
 #undef UNROLL2
 #define UNROLL2(x)             \
-       dp[x+1]=((VMemType16*)TheMap.TileData->Pixels)[COLOR_FOG];
+       dp[x + 1] = ((VMemType16*)TheMap.TileData->Pixels)[COLOR_FOG];
        UNROLL16(0);
-       dp+=da;
+       dp += da;
     }
 }
 
@@ -802,37 +810,37 @@
 **     @param x        X position into video memory
 **     @param y        Y position into video memory
 */
-global void VideoDraw16Unexplored16Solid(const GraphicData* data,int x,int y)
+global void VideoDraw16Unexplored16Solid(const GraphicData* data, int x, int y)
 {
     const unsigned char* sp;
     const unsigned char* gp;
     VMemType16* dp;
     int da;
 
-    sp=data;
-    gp=sp+TileSizeY*TileSizeX;
-    dp=VideoMemory16+x+y*VideoWidth;
-    da=VideoWidth;
+    sp = data;
+    gp = sp + TileSizeY * TileSizeX;
+    dp = VideoMemory16 + x + y * VideoWidth;
+    da = VideoWidth;
 
-    while( sp<gp ) {
+    while (sp < gp) {
 #undef UNROLL1
 #define UNROLL1(x)     \
-       if(COLOR_FOG_P(sp[x]) ) {               \
-           dp[x]=((VMemType16*)TheMap.TileData->Pixels)[COLOR_FOG];    \
+       if(COLOR_FOG_P(sp[x])) {                \
+           dp[x] = ((VMemType16*)TheMap.TileData->Pixels)[COLOR_FOG];  \
        }
 
 #undef UNROLL2
 #define UNROLL2(x)     \
-       UNROLL1(x+0);   \
-       UNROLL1(x+1);
+       UNROLL1(x + 0); \
+       UNROLL1(x + 1);
 
        UNROLL16(0);
-       sp+=TileSizeX;
-       dp+=da;
+       sp += TileSizeX;
+       dp += da;
 
        UNROLL16(0);
-       sp+=TileSizeX;
-       dp+=da;
+       sp += TileSizeX;
+       dp += da;
     }
 }
 
@@ -843,42 +851,42 @@
 **     @param x        X position into video memory.
 **     @param y        Y position into video memory.
 */
-global void VideoDraw16Fog32Solid(const GraphicData* data,int x,int y)
+global void VideoDraw16Fog32Solid(const GraphicData* data, int x, int y)
 {
     const unsigned char* sp;
     const unsigned char* gp;
     VMemType16* dp;
     int da;
 
-    sp=data;
-    gp=sp+TileSizeY*TileSizeX;
-    dp=VideoMemory16+x+y*VideoWidth;
-    da=VideoWidth;
+    sp = data;
+    gp = sp + TileSizeY * TileSizeX;
+    dp = VideoMemory16 + x + y * VideoWidth;
+    da = VideoWidth;
 
-    while( sp<gp ) {
+    while (sp < gp) {
 #undef UNROLL1
 #define UNROLL1(x)     \
        if(COLOR_FOG_P(sp[x])) {                \
-           dp[x]=((VMemType16*)TheMap.TileData->Pixels)[COLOR_FOG];    \
+           dp[x] = ((VMemType16*)TheMap.TileData->Pixels)[COLOR_FOG];  \
        }
 
 #undef UNROLL2
 #define UNROLL2(x)     \
-       UNROLL1(x+0);
+       UNROLL1(x + 0);
 
        UNROLL32(0);
 
-       sp+=TileSizeX;
-       dp+=da;
+       sp += TileSizeX;
+       dp += da;
 
 #undef UNROLL2
 #define UNROLL2(x)     \
-       UNROLL1(x+1);
+       UNROLL1(x + 1);
 
        UNROLL32(0);
 
-       sp+=TileSizeX;
-       dp+=da;
+       sp += TileSizeX;
+       dp += da;
     }
 }
 
@@ -892,27 +900,28 @@
 **     @param x        X position into video memory
 **     @param y        Y position into video memory
 */
-global void VideoDraw16OnlyFog32Solid(const GraphicData* data 
__attribute__((unused)),int x,int y)
+global void VideoDraw16OnlyFog32Solid(const GraphicData* data 
__attribute__((unused)),
+    int x, int y)
 {
     const VMemType16* gp;
     VMemType16* dp;
     int da;
 
-    dp=VideoMemory16+x+y*VideoWidth;
-    gp=dp+VideoWidth*TileSizeX;
-    da=VideoWidth;
-    while( dp<gp ) {
+    dp = VideoMemory16 + x + y * VideoWidth;
+    gp = dp + VideoWidth * TileSizeX;
+    da = VideoWidth;
+    while (dp < gp) {
 #undef UNROLL2
 #define UNROLL2(x)             \
-       dp[x+0]=((VMemType16*)TheMap.TileData->Pixels)[COLOR_FOG];
+       dp[x + 0] = ((VMemType16*)TheMap.TileData->Pixels)[COLOR_FOG];
        UNROLL32(0);
-       dp+=da;
+       dp += da;
 
 #undef UNROLL2
 #define UNROLL2(x)             \
-       dp[x+1]=((VMemType16*)TheMap.TileData->Pixels)[COLOR_FOG];
+       dp[x + 1] = ((VMemType16*)TheMap.TileData->Pixels)[COLOR_FOG];
        UNROLL32(0);
-       dp+=da;
+       dp += da;
     }
 }
 
@@ -923,37 +932,37 @@
 **     @param x        X position into video memory
 **     @param y        Y position into video memory
 */
-global void VideoDraw16Unexplored32Solid(const GraphicData* data,int x,int y)
+global void VideoDraw16Unexplored32Solid(const GraphicData* data, int x, int y)
 {
     const unsigned char* sp;
     const unsigned char* gp;
     VMemType16* dp;
     int da;
 
-    sp=data;
-    gp=sp+TileSizeY*TileSizeX;
-    dp=VideoMemory16+x+y*VideoWidth;
-    da=VideoWidth;
+    sp = data;
+    gp = sp + TileSizeY * TileSizeX;
+    dp = VideoMemory16 + x + y * VideoWidth;
+    da = VideoWidth;
 
-    while( sp<gp ) {
+    while (sp < gp) {
 #undef UNROLL1
 #define UNROLL1(x)     \
-       if(COLOR_FOG_P(sp[x]) ) {               \
-           dp[x]=((VMemType16*)TheMap.TileData->Pixels)[COLOR_FOG];    \
+       if(COLOR_FOG_P(sp[x])) {                \
+           dp[x] = ((VMemType16*)TheMap.TileData->Pixels)[COLOR_FOG];  \
        }
 
 #undef UNROLL2
 #define UNROLL2(x)     \
-       UNROLL1(x+0);   \
-       UNROLL1(x+1);
+       UNROLL1(x + 0); \
+       UNROLL1(x + 1);
 
        UNROLL32(0);
-       sp+=TileSizeX;
-       dp+=da;
+       sp += TileSizeX;
+       dp += da;
 
        UNROLL32(0);
-       sp+=TileSizeX;
-       dp+=da;
+       sp += TileSizeX;
+       dp += da;
     }
 }
 
@@ -966,42 +975,42 @@
 **     @param x        X position into video memory.
 **     @param y        Y position into video memory.
 */
-global void VideoDraw24Fog16Solid(const GraphicData* data,int x,int y)
+global void VideoDraw24Fog16Solid(const GraphicData* data, int x, int y)
 {
     const unsigned char* sp;
     const unsigned char* gp;
     VMemType24* dp;
     int da;
 
-    sp=data;
-    gp=sp+TileSizeY*TileSizeX;
-    dp=VideoMemory24+x+y*VideoWidth;
-    da=VideoWidth;
+    sp = data;
+    gp = sp + TileSizeY * TileSizeX;
+    dp = VideoMemory24 + x + y * VideoWidth;
+    da = VideoWidth;
 
-    while( sp<gp ) {
+    while (sp < gp) {
 #undef UNROLL1
 #define UNROLL1(x)     \
        if(COLOR_FOG_P(sp[x])) {        \
-           dp[x]=((VMemType24*)TheMap.TileData->Pixels)[COLOR_FOG];    \
+           dp[x] = ((VMemType24*)TheMap.TileData->Pixels)[COLOR_FOG];  \
        }
 
 #undef UNROLL2
 #define UNROLL2(x)     \
-       UNROLL1(x+0);
+       UNROLL1(x + 0);
 
        UNROLL32(0);
 
-       sp+=TileSizeX;
-       dp+=da;
+       sp += TileSizeX;
+       dp += da;
 
 #undef UNROLL2
 #define UNROLL2(x)     \
-       UNROLL1(x+1);
+       UNROLL1(x + 1);
 
        UNROLL16(0);
 
-       sp+=TileSizeX;
-       dp+=da;
+       sp += TileSizeX;
+       dp += da;
     }
 }
 
@@ -1015,27 +1024,28 @@
 **     @param x        X position into video memory
 **     @param y        Y position into video memory
 */
-global void VideoDraw24OnlyFog16Solid(const GraphicData* data 
__attribute__((unused)),int x,int y)
+global void VideoDraw24OnlyFog16Solid(const GraphicData* data 
__attribute__((unused)),
+    int x, int y)
 {
     const VMemType24* gp;
     VMemType24* dp;
     int da;
 
-    dp=VideoMemory24+x+y*VideoWidth;
-    gp=dp+VideoWidth*TileSizeX;
-    da=VideoWidth;
-    while( dp<gp ) {
+    dp = VideoMemory24 + x + y * VideoWidth;
+    gp = dp + VideoWidth * TileSizeX;
+    da = VideoWidth;
+    while (dp < gp) {
 #undef UNROLL2
 #define UNROLL2(x)             \
-       dp[x+0]=((VMemType24*)TheMap.TileData->Pixels)[COLOR_FOG];
+       dp[x + 0] = ((VMemType24*)TheMap.TileData->Pixels)[COLOR_FOG];
        UNROLL16(0);
-       dp+=da;
+       dp += da;
 
 #undef UNROLL2
 #define UNROLL2(x)             \
-       dp[x+1]=((VMemType24*)TheMap.TileData->Pixels)[COLOR_FOG];
+       dp[x + 1] = ((VMemType24*)TheMap.TileData->Pixels)[COLOR_FOG];
        UNROLL16(0);
-       dp+=da;
+       dp += da;
     }
 }
 
@@ -1046,37 +1056,37 @@
 **     @param x        X position into video memory
 **     @param y        Y position into video memory
 */
-global void VideoDraw24Unexplored16Solid(const GraphicData* data,int x,int y)
+global void VideoDraw24Unexplored16Solid(const GraphicData* data, int x, int y)
 {
     const unsigned char* sp;
     const unsigned char* gp;
     VMemType24* dp;
     int da;
 
-    sp=data;
-    gp=sp+TileSizeY*TileSizeX;
-    dp=VideoMemory24+x+y*VideoWidth;
-    da=VideoWidth;
+    sp = data;
+    gp = sp + TileSizeY * TileSizeX;
+    dp = VideoMemory24 + x + y * VideoWidth;
+    da = VideoWidth;
 
-    while( sp<gp ) {
+    while (sp < gp) {
 #undef UNROLL1
 #define UNROLL1(x)     \
        if(COLOR_FOG_P(sp[x])) {                \
-           dp[x]=((VMemType24*)TheMap.TileData->Pixels)[COLOR_FOG];    \
+           dp[x] = ((VMemType24*)TheMap.TileData->Pixels)[COLOR_FOG];  \
        }
 
 #undef UNROLL2
 #define UNROLL2(x)     \
-       UNROLL1(x+0);   \
-       UNROLL1(x+1);
+       UNROLL1(x + 0); \
+       UNROLL1(x + 1);
 
        UNROLL16(0);
-       sp+=TileSizeX;
-       dp+=da;
+       sp += TileSizeX;
+       dp += da;
 
        UNROLL16(0);
-       sp+=TileSizeX;
-       dp+=da;
+       sp += TileSizeX;
+       dp += da;
     }
 }
 
@@ -1087,42 +1097,42 @@
 **     @param x        X position into video memory.
 **     @param y        Y position into video memory.
 */
-global void VideoDraw24Fog32Solid(const GraphicData* data,int x,int y)
+global void VideoDraw24Fog32Solid(const GraphicData* data, int x, int y)
 {
     const unsigned char* sp;
     const unsigned char* gp;
     VMemType24* dp;
     int da;
 
-    sp=data;
-    gp=sp+TileSizeY*TileSizeX;
-    dp=VideoMemory24+x+y*VideoWidth;
-    da=VideoWidth;
+    sp = data;
+    gp = sp + TileSizeY * TileSizeX;
+    dp = VideoMemory24 + x + y * VideoWidth;
+    da = VideoWidth;
 
-    while( sp<gp ) {
+    while (sp < gp) {
 #undef UNROLL1
 #define UNROLL1(x)     \
        if(COLOR_FOG_P(sp[x])) {        \
-           dp[x]=((VMemType24*)TheMap.TileData->Pixels)[COLOR_FOG];    \
+           dp[x] = ((VMemType24*)TheMap.TileData->Pixels)[COLOR_FOG];  \
        }
 
 #undef UNROLL2
 #define UNROLL2(x)     \
-       UNROLL1(x+0);
+       UNROLL1(x + 0);
 
        UNROLL32(0);
 
-       sp+=TileSizeX;
-       dp+=da;
+       sp += TileSizeX;
+       dp += da;
 
 #undef UNROLL2
 #define UNROLL2(x)     \
-       UNROLL1(x+1);
+       UNROLL1(x + 1);
 
        UNROLL32(0);
 
-       sp+=TileSizeX;
-       dp+=da;
+       sp += TileSizeX;
+       dp += da;
     }
 }
 
@@ -1136,27 +1146,28 @@
 **     @param x        X position into video memory
 **     @param y        Y position into video memory
 */
-global void VideoDraw24OnlyFog32Solid(const GraphicData* data 
__attribute__((unused)),int x,int y)
+global void VideoDraw24OnlyFog32Solid(const GraphicData* data 
__attribute__((unused)),
+    int x, int y)
 {
     const VMemType24* gp;
     VMemType24* dp;
     int da;
 
-    dp=VideoMemory24+x+y*VideoWidth;
-    gp=dp+VideoWidth*TileSizeX;
-    da=VideoWidth;
-    while( dp<gp ) {
+    dp = VideoMemory24 + x + y * VideoWidth;
+    gp = dp + VideoWidth * TileSizeX;
+    da = VideoWidth;
+    while (dp < gp) {
 #undef UNROLL2
 #define UNROLL2(x)             \
-       dp[x+0]=((VMemType24*)TheMap.TileData->Pixels)[COLOR_FOG];
+       dp[x + 0] = ((VMemType24*)TheMap.TileData->Pixels)[COLOR_FOG];
        UNROLL32(0);
-       dp+=da;
+       dp += da;
 
 #undef UNROLL2
 #define UNROLL2(x)             \
-       dp[x+1]=((VMemType24*)TheMap.TileData->Pixels)[COLOR_FOG];
+       dp[x + 1] = ((VMemType24*)TheMap.TileData->Pixels)[COLOR_FOG];
        UNROLL32(0);
-       dp+=da;
+       dp += da;
     }
 }
 
@@ -1167,37 +1178,37 @@
 **     @param x        X position into video memory
 **     @param y        Y position into video memory
 */
-global void VideoDraw24Unexplored32Solid(const GraphicData* data,int x,int y)
+global void VideoDraw24Unexplored32Solid(const GraphicData* data, int x, int y)
 {
     const unsigned char* sp;
     const unsigned char* gp;
     VMemType24* dp;
     int da;
 
-    sp=data;
-    gp=sp+TileSizeY*TileSizeX;
-    dp=VideoMemory24+x+y*VideoWidth;
-    da=VideoWidth;
+    sp = data;
+    gp = sp + TileSizeY * TileSizeX;
+    dp = VideoMemory24 + x + y * VideoWidth;
+    da = VideoWidth;
 
-    while( sp<gp ) {
+    while (sp < gp) {
 #undef UNROLL1
 #define UNROLL1(x)     \
        if(COLOR_FOG_P(sp[x])) {                \
-           dp[x]=((VMemType24*)TheMap.TileData->Pixels)[COLOR_FOG];    \
+           dp[x] = ((VMemType24*)TheMap.TileData->Pixels)[COLOR_FOG];  \
        }
 
 #undef UNROLL2
 #define UNROLL2(x)     \
-       UNROLL1(x+0);   \
-       UNROLL1(x+1);
+       UNROLL1(x + 0); \
+       UNROLL1(x + 1);
 
        UNROLL32(0);
-       sp+=TileSizeX;
-       dp+=da;
+       sp += TileSizeX;
+       dp += da;
 
        UNROLL32(0);
-       sp+=TileSizeX;
-       dp+=da;
+       sp += TileSizeX;
+       dp += da;
     }
 }
 
@@ -1210,42 +1221,42 @@
 **     @param x        X position into video memory.
 **     @param y        Y position into video memory.
 */
-global void VideoDraw32Fog16Solid(const GraphicData* data,int x,int y)
+global void VideoDraw32Fog16Solid(const GraphicData* data, int x, int y)
 {
     const unsigned char* sp;
     const unsigned char* gp;
     VMemType32* dp;
     int da;
 
-    sp=data;
-    gp=sp+TileSizeY*TileSizeX;
-    dp=VideoMemory32+x+y*VideoWidth;
-    da=VideoWidth;
+    sp = data;
+    gp = sp + TileSizeY * TileSizeX;
+    dp = VideoMemory32 + x + y * VideoWidth;
+    da = VideoWidth;
 
-    while( sp<gp ) {
+    while (sp < gp) {
 #undef UNROLL1
 #define UNROLL1(x)     \
        if(COLOR_FOG_P(sp[x])) {        \
-           dp[x]=((VMemType16*)TheMap.TileData->Pixels)[COLOR_FOG];    \
+           dp[x] = ((VMemType16*)TheMap.TileData->Pixels)[COLOR_FOG];  \
        }
 
 #undef UNROLL2
 #define UNROLL2(x)     \
-       UNROLL1(x+0);
+       UNROLL1(x + 0);
 
        UNROLL16(0);
 
-       sp+=TileSizeX;
-       dp+=da;
+       sp += TileSizeX;
+       dp += da;
 
 #undef UNROLL2
 #define UNROLL2(x)     \
-       UNROLL1(x+1);
+       UNROLL1(x + 1);
 
        UNROLL16(0);
 
-       sp+=TileSizeX;
-       dp+=da;
+       sp += TileSizeX;
+       dp += da;
     }
 }
 
@@ -1259,27 +1270,28 @@
 **     @param x        X position into video memory
 **     @param y        Y position into video memory
 */
-global void VideoDraw32OnlyFog16Solid(const GraphicData* data 
__attribute__((unused)),int x,int y)
+global void VideoDraw32OnlyFog16Solid(const GraphicData* data 
__attribute__((unused)),
+    int x, int y)
 {
     const VMemType32* gp;
     VMemType32* dp;
     int da;
 
-    dp=VideoMemory32+x+y*VideoWidth;
-    gp=dp+VideoWidth*TileSizeX;
-    da=VideoWidth;
-    while( dp<gp ) {
+    dp = VideoMemory32 + x + y * VideoWidth;
+    gp = dp + VideoWidth * TileSizeX;
+    da = VideoWidth;
+    while (dp < gp) {
 #undef UNROLL2
 #define UNROLL2(x)             \
-       dp[x+0]=((VMemType32*)TheMap.TileData->Pixels)[COLOR_FOG];
+       dp[x + 0] = ((VMemType32*)TheMap.TileData->Pixels)[COLOR_FOG];
        UNROLL16(0);
-       dp+=da;
+       dp += da;
 
 #undef UNROLL2
 #define UNROLL2(x)             \
-       dp[x+1]=((VMemType32*)TheMap.TileData->Pixels)[COLOR_FOG];
+       dp[x + 1] = ((VMemType32*)TheMap.TileData->Pixels)[COLOR_FOG];
        UNROLL16(0);
-       dp+=da;
+       dp += da;
     }
 }
 
@@ -1290,37 +1302,37 @@
 **     @param x        X position into video memory
 **     @param y        Y position into video memory
 */
-global void VideoDraw32Unexplored16Solid(const GraphicData* data,int x,int y)
+global void VideoDraw32Unexplored16Solid(const GraphicData* data, int x, int y)
 {
     const unsigned char* sp;
     const unsigned char* gp;
     VMemType32* dp;
     int da;
 
-    sp=data;
-    gp=sp+TileSizeY*TileSizeX;
-    dp=VideoMemory32+x+y*VideoWidth;
-    da=VideoWidth;
+    sp = data;
+    gp = sp + TileSizeY * TileSizeX;
+    dp = VideoMemory32 + x + y * VideoWidth;
+    da = VideoWidth;
 
-    while( sp<gp ) {
+    while (sp < gp) {
 #undef UNROLL1
 #define UNROLL1(x)     \
        if(COLOR_FOG_P(sp[x])) {                \
-           dp[x]=((VMemType32*)TheMap.TileData->Pixels)[COLOR_FOG];    \
+           dp[x] = ((VMemType32*)TheMap.TileData->Pixels)[COLOR_FOG];  \
        }
 
 #undef UNROLL2
 #define UNROLL2(x)     \
-       UNROLL1(x+0);   \
-       UNROLL1(x+1);
+       UNROLL1(x + 0); \
+       UNROLL1(x + 1);
 
        UNROLL16(0);
-       sp+=TileSizeX;
-       dp+=da;
+       sp += TileSizeX;
+       dp += da;
 
        UNROLL16(0);
-       sp+=TileSizeX;
-       dp+=da;
+       sp += TileSizeX;
+       dp += da;
     }
 }
 
@@ -1331,42 +1343,42 @@
 **     @param x        X position into video memory.
 **     @param y        Y position into video memory.
 */
-global void VideoDraw32Fog32Solid(const GraphicData* data,int x,int y)
+global void VideoDraw32Fog32Solid(const GraphicData* data, int x, int y)
 {
     const unsigned char* sp;
     const unsigned char* gp;
     VMemType32* dp;
     int da;
 
-    sp=data;
-    gp=sp+TileSizeY*TileSizeX;
-    dp=VideoMemory32+x+y*VideoWidth;
-    da=VideoWidth;
+    sp = data;
+    gp = sp + TileSizeY * TileSizeX;
+    dp = VideoMemory32 + x + y * VideoWidth;
+    da = VideoWidth;
 
-    while( sp<gp ) {
+    while (sp < gp) {
 #undef UNROLL1
 #define UNROLL1(x)     \
        if(COLOR_FOG_P(sp[x])) {        \
-           dp[x]=((VMemType16*)TheMap.TileData->Pixels)[COLOR_FOG];    \
+           dp[x] = ((VMemType16*)TheMap.TileData->Pixels)[COLOR_FOG];  \
        }
 
 #undef UNROLL2
 #define UNROLL2(x)     \
-       UNROLL1(x+0);
+       UNROLL1(x + 0);
 
        UNROLL32(0);
 
-       sp+=TileSizeX;
-       dp+=da;
+       sp += TileSizeX;
+       dp += da;
 
 #undef UNROLL2
 #define UNROLL2(x)     \
-       UNROLL1(x+1);
+       UNROLL1(x + 1);
 
        UNROLL32(0);
 
-       sp+=TileSizeX;
-       dp+=da;
+       sp += TileSizeX;
+       dp += da;
     }
 }
 
@@ -1380,27 +1392,28 @@
 **     @param x        X position into video memory
 **     @param y        Y position into video memory
 */
-global void VideoDraw32OnlyFog32Solid(const GraphicData* data 
__attribute__((unused)),int x,int y)
+global void VideoDraw32OnlyFog32Solid(const GraphicData* data 
__attribute__((unused)),
+    int x, int y)
 {
     const VMemType32* gp;
     VMemType32* dp;
     int da;
 
-    dp=VideoMemory32+x+y*VideoWidth;
-    gp=dp+VideoWidth*TileSizeX;
-    da=VideoWidth;
-    while( dp<gp ) {
+    dp = VideoMemory32 + x + y * VideoWidth;
+    gp = dp + VideoWidth * TileSizeX;
+    da = VideoWidth;
+    while (dp < gp) {
 #undef UNROLL2
 #define UNROLL2(x)             \
-       dp[x+0]=((VMemType32*)TheMap.TileData->Pixels)[COLOR_FOG];
+       dp[x + 0] = ((VMemType32*)TheMap.TileData->Pixels)[COLOR_FOG];
        UNROLL32(0);
-       dp+=da;
+       dp += da;
 
 #undef UNROLL2
 #define UNROLL2(x)             \
-       dp[x+1]=((VMemType32*)TheMap.TileData->Pixels)[COLOR_FOG];
+       dp[x + 1] = ((VMemType32*)TheMap.TileData->Pixels)[COLOR_FOG];
        UNROLL32(0);
-       dp+=da;
+       dp += da;
     }
 }
 
@@ -1411,37 +1424,37 @@
 **     @param x        X position into video memory
 **     @param y        Y position into video memory
 */
-global void VideoDraw32Unexplored32Solid(const GraphicData* data,int x,int y)
+global void VideoDraw32Unexplored32Solid(const GraphicData* data, int x, int y)
 {
     const unsigned char* sp;
     const unsigned char* gp;
     VMemType32* dp;
     int da;
 
-    sp=data;
-    gp=sp+TileSizeY*TileSizeX;
-    dp=VideoMemory32+x+y*VideoWidth;
-    da=VideoWidth;
+    sp = data;
+    gp = sp + TileSizeY * TileSizeX;
+    dp = VideoMemory32 + x + y * VideoWidth;
+    da = VideoWidth;
 
-    while( sp<gp ) {
+    while (sp < gp) {
 #undef UNROLL1
 #define UNROLL1(x)     \
        if(COLOR_FOG_P(sp[x])) {                \
-           dp[x]=((VMemType32*)TheMap.TileData->Pixels)[COLOR_FOG];    \
+           dp[x] = ((VMemType32*)TheMap.TileData->Pixels)[COLOR_FOG];  \
        }
 
 #undef UNROLL2
 #define UNROLL2(x)     \
-       UNROLL1(x+0);   \
-       UNROLL1(x+1);
+       UNROLL1(x + 0); \
+       UNROLL1(x + 1);
 
        UNROLL32(0);
-       sp+=TileSizeX;
-       dp+=da;
+       sp += TileSizeX;
+       dp += da;
 
        UNROLL32(0);
-       sp+=TileSizeX;
-       dp+=da;
+       sp += TileSizeX;
+       dp += da;
     }
 }
 
@@ -1455,7 +1468,7 @@
 #ifdef USE_OPENGL
 global void VideoDrawUnexploredSolidOpenGL(
     const GraphicData* data __attribute__((unused)),
-    int x __attribute__((unused)),int y __attribute__((unused)))
+    int x __attribute__((unused)), int y __attribute__((unused)))
 {
 }
 #endif
@@ -1475,7 +1488,7 @@
 **
 **     The random effect is commented out
 */
-global void VideoDraw8Fog16Alpha(const GraphicData* data,int x,int y)
+global void VideoDraw8Fog16Alpha(const GraphicData* data, int x, int y)
 {
     const unsigned char* sp;
     const unsigned char* gp;
@@ -1483,33 +1496,33 @@
     VMemType8 fog;
     int da;
 
-    sp=data;
-    gp=sp+TileSizeY*TileSizeX;
-    dp=VideoMemory8+x+y*VideoWidth;
-    da=VideoWidth;
-    fog=((VMemType8*)TheMap.TileData->Pixels)[COLOR_FOG];
+    sp = data;
+    gp = sp + TileSizeY * TileSizeX;
+    dp = VideoMemory8 + x + y * VideoWidth;
+    da = VideoWidth;
+    fog = ((VMemType8*)TheMap.TileData->Pixels)[COLOR_FOG];
 
-    while( sp<gp ) {
+    while (sp < gp) {
 #undef UNROLL1
 #define UNROLL1(x)     \
-       if( COLOR_FOG_P(sp[x]) ) {      \
+       if (COLOR_FOG_P(sp[x])) {       \
            if (dp[x] != fog) { \
-               dp[x]=((VMemType8*)FogOfWarAlphaTable)[dp[x]]; \
+               dp[x] = ((VMemType8*)FogOfWarAlphaTable)[dp[x]]; \
            } \
        } \
 
 #undef UNROLL2
 #define UNROLL2(x)     \
-       UNROLL1(x+0);   \
-       UNROLL1(x+1);   \
+       UNROLL1(x + 0); \
+       UNROLL1(x + 1); \
 
        UNROLL16(0);
-       sp+=TileSizeX;
-       dp+=da;
+       sp += TileSizeX;
+       dp += da;
 
        UNROLL16(0);
-       sp+=TileSizeX;
-       dp+=da;
+       sp += TileSizeX;
+       dp += da;
     }
 }
 
@@ -1525,35 +1538,36 @@
 **
 **     The random effect is commented out
 */
-global void VideoDraw8OnlyFog16Alpha(const GraphicData* data 
__attribute__((unused)),int x,int y)
+global void VideoDraw8OnlyFog16Alpha(const GraphicData* data 
__attribute__((unused)),
+    int x, int y)
 {
     const VMemType8* gp;
     VMemType8* dp;
     VMemType8 fog;
     int da;
 
-    dp=VideoMemory8+x+y*VideoWidth;
-    gp=dp+VideoWidth*TileSizeY;
-    da=VideoWidth;
-    fog=((VMemType8*)TheMap.TileData->Pixels)[COLOR_FOG];
+    dp = VideoMemory8 + x + y * VideoWidth;
+    gp = dp + VideoWidth * TileSizeY;
+    da = VideoWidth;
+    fog = ((VMemType8*)TheMap.TileData->Pixels)[COLOR_FOG];
 
-    while( dp<gp ) {
+    while (dp < gp) {
 #undef UNROLL1
 #define UNROLL1(x)     \
        if (dp[x] != fog) { \
-           dp[x]=((VMemType8*)FogOfWarAlphaTable)[dp[x]];      \
+           dp[x] = ((VMemType8*)FogOfWarAlphaTable)[dp[x]];    \
        } \
 
 #undef UNROLL2
 #define UNROLL2(x)     \
-       UNROLL1(x+0);   \
-       UNROLL1(x+1);   \
+       UNROLL1(x + 0); \
+       UNROLL1(x + 1); \
 
        UNROLL16(0);
-       dp+=da;
+       dp += da;
 
        UNROLL16(0);
-       dp+=da;
+       dp += da;
     }
 }
 
@@ -1566,7 +1580,7 @@
 **
 **     The random effect is commented out
 */
-global void VideoDraw8Fog32Alpha(const GraphicData* data,int x,int y)
+global void VideoDraw8Fog32Alpha(const GraphicData* data, int x, int y)
 {
     const unsigned char* sp;
     const unsigned char* gp;
@@ -1574,33 +1588,33 @@
     VMemType8 fog;
     int da;
 
-    sp=data;
-    gp=sp+TileSizeY*TileSizeX;
-    dp=VideoMemory8+x+y*VideoWidth;
-    da=VideoWidth;
-    fog=((VMemType8*)TheMap.TileData->Pixels)[COLOR_FOG];
+    sp = data;
+    gp = sp + TileSizeY * TileSizeX;
+    dp = VideoMemory8 + x + y * VideoWidth;
+    da = VideoWidth;
+    fog = ((VMemType8*)TheMap.TileData->Pixels)[COLOR_FOG];
 
-    while( sp<gp ) {
+    while (sp < gp) {
 #undef UNROLL1
 #define UNROLL1(x)     \
-       if( COLOR_FOG_P(sp[x]) ) {      \
+       if (COLOR_FOG_P(sp[x])) {       \
            if (dp[x] != fog) { \
-               dp[x]=((VMemType8*)FogOfWarAlphaTable)[dp[x]]; \
+               dp[x] = ((VMemType8*)FogOfWarAlphaTable)[dp[x]]; \
            } \
        } \
 
 #undef UNROLL2
 #define UNROLL2(x)     \
-       UNROLL1(x+0);   \
-       UNROLL1(x+1);   \
+       UNROLL1(x + 0); \
+       UNROLL1(x + 1); \
 
        UNROLL32(0);
-       sp+=TileSizeX;
-       dp+=da;
+       sp += TileSizeX;
+       dp += da;
 
        UNROLL32(0);
-       sp+=TileSizeX;
-       dp+=da;
+       sp += TileSizeX;
+       dp += da;
     }
 }
 
@@ -1616,35 +1630,36 @@
 **
 **     The random effect is commented out
 */
-global void VideoDraw8OnlyFog32Alpha(const GraphicData* data 
__attribute__((unused)),int x,int y)
+global void VideoDraw8OnlyFog32Alpha(const GraphicData* data 
__attribute__((unused)),
+    int x, int y)
 {
     const VMemType8* gp;
     VMemType8* dp;
     VMemType8 fog;
     int da;
 
-    dp=VideoMemory8+x+y*VideoWidth;
-    gp=dp+VideoWidth*TileSizeY;
-    da=VideoWidth;
-    fog=((VMemType8*)TheMap.TileData->Pixels)[COLOR_FOG];
+    dp = VideoMemory8 + x + y * VideoWidth;
+    gp = dp + VideoWidth * TileSizeY;
+    da = VideoWidth;
+    fog = ((VMemType8*)TheMap.TileData->Pixels)[COLOR_FOG];
 
-    while( dp<gp ) {
+    while (dp < gp) {
 #undef UNROLL1
 #define UNROLL1(x)     \
        if (dp[x] != fog) { \
-           dp[x]=((VMemType8*)FogOfWarAlphaTable)[dp[x]];      \
+           dp[x] = ((VMemType8*)FogOfWarAlphaTable)[dp[x]];    \
        } \
 
 #undef UNROLL2
 #define UNROLL2(x)     \
-       UNROLL1(x+0);   \
-       UNROLL1(x+1);   \
+       UNROLL1(x + 0); \
+       UNROLL1(x + 1); \
 
        UNROLL32(0);
-       dp+=da;
+       dp += da;
 
        UNROLL32(0);
-       dp+=da;
+       dp += da;
     }
 }
 
@@ -1659,7 +1674,7 @@
 **
 **     The random effect is commented out
 */
-global void VideoDraw16Fog16Alpha(const GraphicData* data,int x,int y)
+global void VideoDraw16Fog16Alpha(const GraphicData* data, int x, int y)
 {
     const unsigned char* sp;
     const unsigned char* gp;
@@ -1668,13 +1683,13 @@
     int da;
     //int o;
 
-    sp=data;
-    gp=sp+TileSizeY*TileSizeX;
-    dp=VideoMemory16+x+y*VideoWidth;
-    da=VideoWidth;
-    fog=((VMemType16*)TheMap.TileData->Pixels)[COLOR_FOG];
+    sp = data;
+    gp = sp + TileSizeY * TileSizeX;
+    dp = VideoMemory16 + x + y * VideoWidth;
+    da = VideoWidth;
+    fog = ((VMemType16*)TheMap.TileData->Pixels)[COLOR_FOG];
 
-    while( sp<gp ) {
+    while (sp < gp) {
        //static int a=1234567;
        //o=rand();
 
@@ -1682,20 +1697,20 @@
 #define UNROLL1(x)     \
        if (dp[x] != fog) { \
            /* o=a=a*(123456*4+1)+1; */ \
-           if( COLOR_FOG_P(sp[x]) ) {  \
-               dp[x]=((VMemType16*)FogOfWarAlphaTable)[dp[x]/*^((o>>20)&4)*/]; 
\
+           if (COLOR_FOG_P(sp[x])) {   \
+               dp[x] = 
((VMemType16*)FogOfWarAlphaTable)[dp[x]/*^((o>>20)&4)*/]; \
            } \
        } \
 
 #undef UNROLL2
 #define UNROLL2(x)     \
-       UNROLL1(x+0);   \
-       UNROLL1(x+1);   \
+       UNROLL1(x + 0); \
+       UNROLL1(x + 1); \
        //o=(o>>1)|((o&1)<<31);
 
        UNROLL16(0);
-       sp+=TileSizeX;
-       dp+=da;
+       sp += TileSizeX;
+       dp += da;
     }
 }
 
@@ -1711,7 +1726,8 @@
 **
 **     The random effect is commented out
 */
-global void VideoDraw16OnlyFog16Alpha(const GraphicData* data 
__attribute__((unused)),int x,int y)
+global void VideoDraw16OnlyFog16Alpha(const GraphicData* data 
__attribute__((unused)),
+    int x, int y)
 {
     const VMemType16* gp;
     VMemType16* dp;
@@ -1719,12 +1735,12 @@
     int da;
     //int o;
 
-    dp=VideoMemory16+x+y*VideoWidth;
-    gp=dp+VideoWidth*TileSizeY;
-    da=VideoWidth;
-    fog=((VMemType16*)TheMap.TileData->Pixels)[COLOR_FOG];
+    dp = VideoMemory16 + x + y * VideoWidth;
+    gp = dp + VideoWidth * TileSizeY;
+    da = VideoWidth;
+    fog = ((VMemType16*)TheMap.TileData->Pixels)[COLOR_FOG];
 
-    while( dp<gp ) {
+    while (dp < gp) {
        //static int a=1234567;
        //o=rand();
 
@@ -1732,17 +1748,17 @@
 #define UNROLL1(x)     \
        if (dp[x] != fog) { \
            /* o=a=a*(123456*4+1)+1; */ \
-           dp[x]=((VMemType16*)FogOfWarAlphaTable)[dp[x]/*^((o>>20)&4)*/]; \
+           dp[x] = ((VMemType16*)FogOfWarAlphaTable)[dp[x]/*^((o>>20)&4)*/]; \
        } \
 
 #undef UNROLL2
 #define UNROLL2(x)     \
-       UNROLL1(x+0);   \
-       UNROLL1(x+1);   \
+       UNROLL1(x + 0); \
+       UNROLL1(x + 1); \
        //o=(o>>1)|((o&1)<<31);
 
        UNROLL16(0);
-       dp+=da;
+       dp += da;
     }
 }
 
@@ -1755,7 +1771,7 @@
 **
 **     The random effect is commented out
 */
-global void VideoDraw16Fog32Alpha(const GraphicData* data,int x,int y)
+global void VideoDraw16Fog32Alpha(const GraphicData* data, int x, int y)
 {
     const unsigned char* sp;
     const unsigned char* gp;
@@ -1764,13 +1780,13 @@
     int da;
     //int o;
 
-    sp=data;
-    gp=sp+TileSizeY*TileSizeX;
-    dp=VideoMemory16+x+y*VideoWidth;
-    da=VideoWidth;
-    fog=((VMemType16*)TheMap.TileData->Pixels)[COLOR_FOG];
+    sp = data;
+    gp = sp + TileSizeY * TileSizeX;
+    dp = VideoMemory16 + x + y * VideoWidth;
+    da = VideoWidth;
+    fog = ((VMemType16*)TheMap.TileData->Pixels)[COLOR_FOG];
 
-    while( sp<gp ) {
+    while (sp < gp) {
        //static int a=1234567;
        //o=rand();
 
@@ -1778,20 +1794,20 @@
 #define UNROLL1(x)     \
        if (dp[x] != fog) { \
            /* o=a=a*(123456*4+1)+1; */ \
-           if( COLOR_FOG_P(sp[x]) ) {  \
-               dp[x]=((VMemType16*)FogOfWarAlphaTable)[dp[x]/*^((o>>20)&4)*/]; 
\
+           if (COLOR_FOG_P(sp[x])) {   \
+               dp[x] = 
((VMemType16*)FogOfWarAlphaTable)[dp[x]/*^((o>>20)&4)*/]; \
            } \
        } \
 
 #undef UNROLL2
 #define UNROLL2(x)     \
-       UNROLL1(x+0);   \
-       UNROLL1(x+1);   \
+       UNROLL1(x + 0); \
+       UNROLL1(x + 1); \
        //o=(o>>1)|((o&1)<<31);
 
        UNROLL32(0);
-       sp+=TileSizeX;
-       dp+=da;
+       sp += TileSizeX;
+       dp += da;
     }
 }
 
@@ -1807,7 +1823,8 @@
 **
 **     The random effect is commented out
 */
-global void VideoDraw16OnlyFog32Alpha(const GraphicData* data 
__attribute__((unused)),int x,int y)
+global void VideoDraw16OnlyFog32Alpha(const GraphicData* data 
__attribute__((unused)),
+    int x, int y)
 {
     const VMemType16* gp;
     VMemType16* dp;
@@ -1815,12 +1832,12 @@
     int da;
     //int o;
 
-    dp=VideoMemory16+x+y*VideoWidth;
-    gp=dp+VideoWidth*TileSizeY;
-    da=VideoWidth;
-    fog=((VMemType16*)TheMap.TileData->Pixels)[COLOR_FOG];
+    dp = VideoMemory16 + x + y * VideoWidth;
+    gp = dp + VideoWidth * TileSizeY;
+    da = VideoWidth;
+    fog = ((VMemType16*)TheMap.TileData->Pixels)[COLOR_FOG];
 
-    while( dp<gp ) {
+    while (dp < gp) {
        //static int a=1234567;
        //o=rand();
 
@@ -1828,17 +1845,17 @@
 #define UNROLL1(x)     \
        if (dp[x] != fog) { \
            /* o=a=a*(123456*4+1)+1; */ \
-           dp[x]=((VMemType16*)FogOfWarAlphaTable)[dp[x]/*^((o>>20)&4)*/]; \
+           dp[x] = ((VMemType16*)FogOfWarAlphaTable)[dp[x]/*^((o>>20)&4)*/]; \
        } \
 
 #undef UNROLL2
 #define UNROLL2(x)     \
-       UNROLL1(x+0);   \
-       UNROLL1(x+1);   \
+       UNROLL1(x + 0); \
+       UNROLL1(x + 1); \
        //o=(o>>1)|((o&1)<<31);
 
        UNROLL32(0);
-       dp+=da;
+       dp += da;
     }
 }
 
@@ -1851,44 +1868,46 @@
 **     @param x        X position into video memory
 **     @param y        Y position into video memory
 */
-global void VideoDraw24Fog16Alpha(const GraphicData* data,int x,int y)
+global void VideoDraw24Fog16Alpha(const GraphicData* data, int x, int y)
 {
     const unsigned char* sp;
     const unsigned char* gp;
     VMemType24* dp;
     VMemType24 fog;
     int da;
-    int r, g, b, v ;
+    int r;
+    int g;
+    int b;
+    int v ;
+
+    sp = data;
+    gp = sp + TileSizeY * TileSizeX;
+    dp = VideoMemory24 + x + y * VideoWidth;
+    da = VideoWidth;
+    fog = ((VMemType24*)TheMap.TileData->Pixels)[COLOR_FOG];
 
-    sp=data;
-    gp=sp+TileSizeY*TileSizeX;
-    dp=VideoMemory24+x+y*VideoWidth;
-    da=VideoWidth;
-    fog=((VMemType24*)TheMap.TileData->Pixels)[COLOR_FOG];
-
-    while( sp<gp ) {
+    while (sp < gp) {
 #undef FOG_SCALE
 #define FOG_SCALE(x) \
-           (((((x*3-v)*FogOfWarSaturation + v*100) \
-               *FogOfWarContrast) \
-               +FogOfWarBrightness*25600*3)/30000)
+           (((((x * 3 - v) * FogOfWarSaturation + v * 100) * FogOfWarContrast) 
+ \
+               FogOfWarBrightness * 25600 * 3) / 30000)
 
 #undef UNROLL1
 #define UNROLL1(x)      \
        if (COLOR_FOG_P(sp[x])) { \
            if (dp[x].a != fog.a || dp[x].b != fog.b || dp[x].c != fog.c) { \
-               r=dp[x].a & 0xff; \
-               g=dp[x].b & 0xff; \
-               b=dp[x].c & 0xff; \
-               v=r+g+b; \
+               r = dp[x].a & 0xff; \
+               g = dp[x].b & 0xff; \
+               b = dp[x].c & 0xff; \
+               v = r + g + b; \
 \
                r = FOG_SCALE(r); \
                g = FOG_SCALE(g); \
                b = FOG_SCALE(b); \
 \
-               r= r<0 ? 0 : r>255 ? 255 : r; \
-               g= g<0 ? 0 : g>255 ? 255 : g; \
-               b= b<0 ? 0 : b>255 ? 255 : b; \
+               r = r < 0 ? 0 : r > 255 ? 255 : r; \
+               g = g < 0 ? 0 : g > 255 ? 255 : g; \
+               b = b < 0 ? 0 : b > 255 ? 255 : b; \
                dp[x].a = r; \
                dp[x].b = g; \
                dp[x].c = b; \
@@ -1897,12 +1916,12 @@
 
 #undef UNROLL2
 #define UNROLL2(x)     \
-       UNROLL1(x+0);   \
-       UNROLL1(x+1);   \
+       UNROLL1(x + 0); \
+       UNROLL1(x + 1); \
 
        UNROLL16(0);
-       sp+=TileSizeX;
-       dp+=da;
+       sp += TileSizeX;
+       dp += da;
     }
 }
 
@@ -1916,42 +1935,45 @@
 **     @param x        X position into video memory
 **     @param y        Y position into video memory
 */
-global void VideoDraw24OnlyFog16Alpha(const GraphicData* data 
__attribute__((unused)),int x,int y)
+global void VideoDraw24OnlyFog16Alpha(const GraphicData* data 
__attribute__((unused)),
+    int x, int y)
 {
     const VMemType24* gp;
     VMemType24* dp;
     VMemType24 fog;
     int da;
-    int r, g, b, v;
-
-    dp=VideoMemory24+x+y*VideoWidth;
-    gp=dp+VideoWidth*TileSizeY;
-    da=VideoWidth;
-    fog=((VMemType24*)TheMap.TileData->Pixels)[COLOR_FOG];
+    int r;
+    int g;
+    int b;
+    int v;
+
+    dp = VideoMemory24 + x + y * VideoWidth;
+    gp = dp + VideoWidth * TileSizeY;
+    da = VideoWidth;
+    fog = ((VMemType24*)TheMap.TileData->Pixels)[COLOR_FOG];
 
-    while( dp<gp ) {
+    while (dp < gp) {
 
 #undef FOG_SCALE
 #define FOG_SCALE(x) \
-           (((((x*3-v)*FogOfWarSaturation + v*100) \
-               *FogOfWarContrast) \
-               +FogOfWarBrightness*25600*3)/30000)
+           (((((x * 3 - v) * FogOfWarSaturation + v * 100) * FogOfWarContrast) 
+ \
+               FogOfWarBrightness * 25600 * 3) / 30000)
 
 #undef UNROLL1
 #define UNROLL1(x)     \
        if (dp[x].a != fog.a || dp[x].b != fog.b || dp[x].c != fog.c) { \
-           r=dp[x].a & 0xff; \
-           g=dp[x].b & 0xff; \
-           b=dp[x].c & 0xff; \
-           v=r+g+b; \
+           r = dp[x].a & 0xff; \
+           g = dp[x].b & 0xff; \
+           b = dp[x].c & 0xff; \
+           v = r + g + b; \
 \
            r = FOG_SCALE(r); \
            g = FOG_SCALE(g); \
            b = FOG_SCALE(b); \
 \
-           r= r<0 ? 0 : r>255 ? 255 : r; \
-           g= g<0 ? 0 : g>255 ? 255 : g; \
-           b= b<0 ? 0 : b>255 ? 255 : b; \
+           r = r < 0 ? 0 : r > 255 ? 255 : r; \
+           g = g < 0 ? 0 : g > 255 ? 255 : g; \
+           b = b < 0 ? 0 : b > 255 ? 255 : b; \
            dp[x].a = r; \
            dp[x].b = g; \
            dp[x].c = b; \
@@ -1959,11 +1981,11 @@
 
 #undef UNROLL2
 #define UNROLL2(x)     \
-       UNROLL1(x+0);   \
-       UNROLL1(x+1);   \
+       UNROLL1(x + 0); \
+       UNROLL1(x + 1); \
 
        UNROLL16(0);
-       dp+=da;
+       dp += da;
     }
 }
 
@@ -1974,44 +1996,46 @@
 **     @param x        X position into video memory
 **     @param y        Y position into video memory
 */
-global void VideoDraw24Fog32Alpha(const GraphicData* data,int x,int y)
+global void VideoDraw24Fog32Alpha(const GraphicData* data, int x, int y)
 {
     const unsigned char* sp;
     const unsigned char* gp;
     VMemType24* dp;
     VMemType24 fog;
     int da;
-    int r, g, b, v ;
+    int r;
+    int g;
+    int b;
+    int v;
+
+    sp = data;
+    gp = sp + TileSizeY * TileSizeX;
+    dp = VideoMemory24 + x + y * VideoWidth;
+    da = VideoWidth;
+    fog = ((VMemType24*)TheMap.TileData->Pixels)[COLOR_FOG];
 
-    sp=data;
-    gp=sp+TileSizeY*TileSizeX;
-    dp=VideoMemory24+x+y*VideoWidth;
-    da=VideoWidth;
-    fog=((VMemType24*)TheMap.TileData->Pixels)[COLOR_FOG];
-
-    while( sp<gp ) {
+    while (sp < gp) {
 #undef FOG_SCALE
 #define FOG_SCALE(x) \
-           (((((x*3-v)*FogOfWarSaturation + v*100) \
-               *FogOfWarContrast) \
-               +FogOfWarBrightness*25600*3)/30000)
+           (((((x * 3 - v) * FogOfWarSaturation + v * 100) * FogOfWarContrast) 
+ \
+               FogOfWarBrightness * 25600 * 3) / 30000)
 
 #undef UNROLL1
 #define UNROLL1(x)      \
        if (COLOR_FOG_P(sp[x])) { \
            if (dp[x].a != fog.a || dp[x].b != fog.b || dp[x].c != fog.c) { \
-               r=dp[x].a & 0xff; \
-               g=dp[x].b & 0xff; \
-               b=dp[x].c & 0xff; \
-               v=r+g+b; \
+               r = dp[x].a & 0xff; \
+               g = dp[x].b & 0xff; \
+               b = dp[x].c & 0xff; \
+               v = r + g + b; \
 \
                r = FOG_SCALE(r); \
                g = FOG_SCALE(g); \
                b = FOG_SCALE(b); \
 \
-               r= r<0 ? 0 : r>255 ? 255 : r; \
-               g= g<0 ? 0 : g>255 ? 255 : g; \
-               b= b<0 ? 0 : b>255 ? 255 : b; \
+               r = r < 0 ? 0 : r > 255 ? 255 : r; \
+               g = g < 0 ? 0 : g > 255 ? 255 : g; \
+               b = b < 0 ? 0 : b > 255 ? 255 : b; \
                dp[x].a = r; \
                dp[x].b = g; \
                dp[x].c = b; \
@@ -2020,12 +2044,12 @@
 
 #undef UNROLL2
 #define UNROLL2(x)     \
-       UNROLL1(x+0);   \
-       UNROLL1(x+1);   \
+       UNROLL1(x + 0); \
+       UNROLL1(x + 1); \
 
        UNROLL32(0);
-       sp+=TileSizeX;
-       dp+=da;
+       sp += TileSizeX;
+       dp += da;
     }
 }
 
@@ -2039,42 +2063,45 @@
 **     @param x        X position into video memory
 **     @param y        Y position into video memory
 */
-global void VideoDraw24OnlyFog32Alpha(const GraphicData* data 
__attribute__((unused)),int x,int y)
+global void VideoDraw24OnlyFog32Alpha(const GraphicData* data 
__attribute__((unused)),
+    int x, int y)
 {
     const VMemType24* gp;
     VMemType24* dp;
     VMemType24 fog;
     int da;
-    int r, g, b, v;
-
-    dp=VideoMemory24+x+y*VideoWidth;
-    gp=dp+VideoWidth*TileSizeY;
-    da=VideoWidth;
-    fog=((VMemType24*)TheMap.TileData->Pixels)[COLOR_FOG];
+    int r;
+    int g;
+    int b;
+    int v;
+
+    dp = VideoMemory24 + x + y * VideoWidth;
+    gp = dp + VideoWidth * TileSizeY;
+    da = VideoWidth;
+    fog = ((VMemType24*)TheMap.TileData->Pixels)[COLOR_FOG];
 
-    while( dp<gp ) {
+    while (dp < gp) {
 
 #undef FOG_SCALE
 #define FOG_SCALE(x) \
-           (((((x*3-v)*FogOfWarSaturation + v*100) \
-               *FogOfWarContrast) \
-               +FogOfWarBrightness*25600*3)/30000)
+           (((((x * 3 - v) * FogOfWarSaturation + v * 100) * FogOfWarContrast) 
+ \
+               FogOfWarBrightness * 25600 * 3) / 30000)
 
 #undef UNROLL1
 #define UNROLL1(x)     \
        if (dp[x].a != fog.a || dp[x].b != fog.b || dp[x].c != fog.c) { \
-           r=dp[x].a & 0xff; \
-           g=dp[x].b & 0xff; \
-           b=dp[x].c & 0xff; \
-           v=r+g+b; \
+           r = dp[x].a & 0xff; \
+           g = dp[x].b & 0xff; \
+           b = dp[x].c & 0xff; \
+           v = r + g + b; \
 \
            r = FOG_SCALE(r); \
            g = FOG_SCALE(g); \
            b = FOG_SCALE(b); \
 \
-           r= r<0 ? 0 : r>255 ? 255 : r; \
-           g= g<0 ? 0 : g>255 ? 255 : g; \
-           b= b<0 ? 0 : b>255 ? 255 : b; \
+           r = r < 0 ? 0 : r > 255 ? 255 : r; \
+           g = g < 0 ? 0 : g > 255 ? 255 : g; \
+           b = b < 0 ? 0 : b > 255 ? 255 : b; \
            dp[x].a = r; \
            dp[x].b = g; \
            dp[x].c = b; \
@@ -2082,11 +2109,11 @@
 
 #undef UNROLL2
 #define UNROLL2(x)     \
-       UNROLL1(x+0);   \
-       UNROLL1(x+1);   \
+       UNROLL1(x + 0); \
+       UNROLL1(x + 1); \
 
        UNROLL32(0);
-       dp+=da;
+       dp += da;
     }
 }
 
@@ -2099,31 +2126,33 @@
 **     @param x        X position into video memory
 **     @param y        Y position into video memory
 */
-global void VideoDraw32Fog16Alpha(const GraphicData* data,int x,int y)
+global void VideoDraw32Fog16Alpha(const GraphicData* data, int x, int y)
 {
     const unsigned char* sp;
     const unsigned char* gp;
     VMemType32* dp;
     VMemType32 fog;
     int da;
-    int r, g, b, v ;
+    int r;
+    int g;
+    int b;
+    int v;
     VMemType32 i;
     VMemType32 lasti;
     VMemType32 lastrgb;
 
-    sp=data;
-    gp=sp+TileSizeY*TileSizeX;
-    dp=VideoMemory32+x+y*VideoWidth;
-    da=VideoWidth;
-    lastrgb=lasti=0;
-    fog=((VMemType32*)TheMap.TileData->Pixels)[COLOR_FOG];
+    sp = data;
+    gp = sp + TileSizeY * TileSizeX;
+    dp = VideoMemory32 + x + y * VideoWidth;
+    da = VideoWidth;
+    lastrgb = lasti = 0;
+    fog = ((VMemType32*)TheMap.TileData->Pixels)[COLOR_FOG];
 
-    while( sp<gp ) {
+    while (sp < gp) {
 #undef FOG_SCALE
 #define FOG_SCALE(x) \
-           (((((x*3-v)*FogOfWarSaturation + v*100) \
-               *FogOfWarContrast) \
-               +FogOfWarBrightness*25600*3)/30000)
+           (((((x * 3 - v) * FogOfWarSaturation + v * 100) * FogOfWarContrast) 
+ \
+               FogOfWarBrightness * 25600 * 3) / 30000)
 
 #undef UNROLL1
 #define UNROLL1(x)      \
@@ -2134,19 +2163,19 @@
                    dp[x] = lastrgb; \
                } else { \
                    lasti = i; \
-                   r=i       & 0xff; \
-                   g=(i>>8 ) & 0xff; \
-                   b=(i>>16) & 0xff; \
-                   v=r+g+b; \
+                   r = i         & 0xff; \
+                   g = (i >> 8 ) & 0xff; \
+                   b = (i >> 16) & 0xff; \
+                   v = r + g + b; \
  \
                    r = FOG_SCALE(r); \
                    g = FOG_SCALE(g); \
                    b = FOG_SCALE(b); \
  \
-                   r= r<0 ? 0 : r>255 ? 255 : r; \
-                   g= g<0 ? 0 : g>255 ? 255 : g; \
-                   b= b<0 ? 0 : b>255 ? 255 : b; \
-                   dp[x]= (r | (g << 8) | (b << 16)); \
+                   r = r < 0 ? 0 : r > 255 ? 255 : r; \
+                   g = g < 0 ? 0 : g > 255 ? 255 : g; \
+                   b = b < 0 ? 0 : b > 255 ? 255 : b; \
+                   dp[x] = (r | (g << 8) | (b << 16)); \
                    lastrgb = dp[x]; \
                } \
            } \
@@ -2154,12 +2183,12 @@
 
 #undef UNROLL2
 #define UNROLL2(x)     \
-       UNROLL1(x+0);   \
-       UNROLL1(x+1);   \
+       UNROLL1(x + 0); \
+       UNROLL1(x + 1); \
 
        UNROLL16(0);
-       sp+=TileSizeX;
-       dp+=da;
+       sp += TileSizeX;
+       dp += da;
     }
 }
 
@@ -2173,30 +2202,33 @@
 **     @param x        X position into video memory
 **     @param y        Y position into video memory
 */
-global void VideoDraw32OnlyFog16Alpha(const GraphicData* data 
__attribute__((unused)),int x,int y)
+global void VideoDraw32OnlyFog16Alpha(const GraphicData* data 
__attribute__((unused)),
+    int x, int y)
 {
     const VMemType32* gp;
     VMemType32* dp;
     VMemType32 fog;
     int da;
-    int r, g, b, v;
+    int r;
+    int g;
+    int b;
+    int v;
     VMemType32 i;
     VMemType32 lasti;
     VMemType32 lastrgb;
 
-    dp=VideoMemory32+x+y*VideoWidth;
-    gp=dp+VideoWidth*TileSizeY;
-    da=VideoWidth;
-    lastrgb=lasti=0;
-    fog=((VMemType32*)TheMap.TileData->Pixels)[COLOR_FOG];
+    dp = VideoMemory32 + x + y * VideoWidth;
+    gp = dp + VideoWidth * TileSizeY;
+    da = VideoWidth;
+    lastrgb = lasti = 0;
+    fog = ((VMemType32*)TheMap.TileData->Pixels)[COLOR_FOG];
 
-    while( dp<gp ) {
+    while (dp < gp) {
 
 #undef FOG_SCALE
 #define FOG_SCALE(x) \
-           (((((x*3-v)*FogOfWarSaturation + v*100) \
-               *FogOfWarContrast) \
-               +FogOfWarBrightness*25600*3)/30000)
+           (((((x * 3 - v) * FogOfWarSaturation + v * 100) * FogOfWarContrast) 
+ \
+               FogOfWarBrightness * 25600 * 3) / 30000)
 
 #undef UNROLL1
 #define UNROLL1(x)     \
@@ -2206,30 +2238,30 @@
                dp[x] = lastrgb; \
            } else { \
                lasti = i; \
-               r=i       & 0xff; \
-               g=(i>>8 ) & 0xff; \
-               b=(i>>16) & 0xff; \
-               v=r+g+b; \
+               r = i         & 0xff; \
+               g = (i >> 8 ) & 0xff; \
+               b = (i >> 16) & 0xff; \
+               v = r + g + b; \
  \
                r = FOG_SCALE(r); \
                g = FOG_SCALE(g); \
                b = FOG_SCALE(b); \
  \
-               r= r<0 ? 0 : r>255 ? 255 : r; \
-               g= g<0 ? 0 : g>255 ? 255 : g; \
-               b= b<0 ? 0 : b>255 ? 255 : b; \
-               dp[x]= r | (g << 8) | (b << 16); \
+               r = r < 0 ? 0 : r > 255 ? 255 : r; \
+               g = g < 0 ? 0 : g > 255 ? 255 : g; \
+               b = b < 0 ? 0 : b > 255 ? 255 : b; \
+               dp[x] = r | (g << 8) | (b << 16); \
                lastrgb = dp[x]; \
            } \
        } \
 
 #undef UNROLL2
 #define UNROLL2(x)     \
-       UNROLL1(x+0);   \
-       UNROLL1(x+1);   \
+       UNROLL1(x + 0); \
+       UNROLL1(x + 1); \
 
        UNROLL16(0);
-       dp+=da;
+       dp += da;
     }
 }
 
@@ -2240,31 +2272,33 @@
 **     @param x        X position into video memory
 **     @param y        Y position into video memory
 */
-global void VideoDraw32Fog32Alpha(const GraphicData* data,int x,int y)
+global void VideoDraw32Fog32Alpha(const GraphicData* data, int x, int y)
 {
     const unsigned char* sp;
     const unsigned char* gp;
     VMemType32* dp;
     VMemType32 fog;
     int da;
-    int r, g, b, v ;
+    int r;
+    int g;
+    int b;
+    int v;
     VMemType32 i;
     VMemType32 lasti;
     VMemType32 lastrgb;
 
-    sp=data;
-    gp=sp+TileSizeY*TileSizeX;
-    dp=VideoMemory32+x+y*VideoWidth;
-    da=VideoWidth;
-    lastrgb=lasti=0;
-    fog=((VMemType32*)TheMap.TileData->Pixels)[COLOR_FOG];
+    sp = data;
+    gp = sp + TileSizeY * TileSizeX;
+    dp = VideoMemory32 + x + y * VideoWidth;
+    da = VideoWidth;
+    lastrgb = lasti = 0;
+    fog = ((VMemType32*)TheMap.TileData->Pixels)[COLOR_FOG];
 
-    while( sp<gp ) {
+    while (sp < gp) {
 #undef FOG_SCALE
 #define FOG_SCALE(x) \
-           (((((x*3-v)*FogOfWarSaturation + v*100) \
-               *FogOfWarContrast) \
-               +FogOfWarBrightness*25600*3)/30000)
+           (((((x * 3 - v) * FogOfWarSaturation + v * 100) * FogOfWarContrast) 
+ \
+               FogOfWarBrightness * 25600 * 3) / 30000)
 
 #undef UNROLL1
 #define UNROLL1(x)      \
@@ -2275,19 +2309,19 @@
                    dp[x] = lastrgb; \
                } else { \
                    lasti = i; \
-                   r=i       & 0xff; \
-                   g=(i>>8 ) & 0xff; \
-                   b=(i>>16) & 0xff; \
-                   v=r+g+b; \
+                   r = i         & 0xff; \
+                   g = (i >> 8 ) & 0xff; \
+                   b = (i >> 16) & 0xff; \
+                   v = r + g + b; \
  \
                    r = FOG_SCALE(r); \
                    g = FOG_SCALE(g); \
                    b = FOG_SCALE(b); \
  \
-                   r= r<0 ? 0 : r>255 ? 255 : r; \
-                   g= g<0 ? 0 : g>255 ? 255 : g; \
-                   b= b<0 ? 0 : b>255 ? 255 : b; \
-                   dp[x]= (r | (g << 8) | (b << 16)); \
+                   r = r < 0 ? 0 : r > 255 ? 255 : r; \
+                   g = g < 0 ? 0 : g > 255 ? 255 : g; \
+                   b = b < 0 ? 0 : b > 255 ? 255 : b; \
+                   dp[x] = (r | (g << 8) | (b << 16)); \
                    lastrgb = dp[x]; \
                } \
            } \
@@ -2295,12 +2329,12 @@
 
 #undef UNROLL2
 #define UNROLL2(x)     \
-       UNROLL1(x+0);   \
-       UNROLL1(x+1);   \
+       UNROLL1(x + 0); \
+       UNROLL1(x + 1); \
 
        UNROLL32(0);
-       sp+=TileSizeX;
-       dp+=da;
+       sp += TileSizeX;
+       dp += da;
     }
 }
 
@@ -2314,30 +2348,33 @@
 **     @param x        X position into video memory
 **     @param y        Y position into video memory
 */
-global void VideoDraw32OnlyFog32Alpha(const GraphicData* data 
__attribute__((unused)),int x,int y)
+global void VideoDraw32OnlyFog32Alpha(const GraphicData* data 
__attribute__((unused)),
+    int x, int y)
 {
     const VMemType32* gp;
     VMemType32* dp;
     VMemType32 fog;
     int da;
-    int r, g, b, v;
+    int r;
+    int g;
+    int b;
+    int v;
     VMemType32 i;
     VMemType32 lasti;
     VMemType32 lastrgb;
 
-    dp=VideoMemory32+x+y*VideoWidth;
-    gp=dp+VideoWidth*TileSizeY;
-    da=VideoWidth;
-    lastrgb=lasti=0;
-    fog=((VMemType32*)TheMap.TileData->Pixels)[COLOR_FOG];
+    dp = VideoMemory32 + x + y * VideoWidth;
+    gp = dp + VideoWidth * TileSizeY;
+    da = VideoWidth;
+    lastrgb = lasti = 0;
+    fog = ((VMemType32*)TheMap.TileData->Pixels)[COLOR_FOG];
 
-    while( dp<gp ) {
+    while (dp < gp) {
 
 #undef FOG_SCALE
 #define FOG_SCALE(x) \
-           (((((x*3-v)*FogOfWarSaturation + v*100) \
-               *FogOfWarContrast) \
-               +FogOfWarBrightness*25600*3)/30000)
+           (((((x * 3 - v) * FogOfWarSaturation + v * 100) * FogOfWarContrast) 
+ \
+               FogOfWarBrightness*25600*3)/30000)
 
 #undef UNROLL1
 #define UNROLL1(x)     \
@@ -2347,30 +2384,30 @@
                dp[x] = lastrgb; \
            } else { \
                lasti = i; \
-               r=i       & 0xff; \
-               g=(i>>8 ) & 0xff; \
-               b=(i>>16) & 0xff; \
-               v=r+g+b; \
+               r = i         & 0xff; \
+               g = (i >> 8 ) & 0xff; \
+               b = (i >> 16) & 0xff; \
+               v = r + g + b; \
  \
                r = FOG_SCALE(r); \
                g = FOG_SCALE(g); \
                b = FOG_SCALE(b); \
  \
-               r= r<0 ? 0 : r>255 ? 255 : r; \
-               g= g<0 ? 0 : g>255 ? 255 : g; \
-               b= b<0 ? 0 : b>255 ? 255 : b; \
-               dp[x]= r | (g << 8) | (b << 16); \
+               r = r < 0 ? 0 : r > 255 ? 255 : r; \
+               g = g < 0 ? 0 : g > 255 ? 255 : g; \
+               b = b < 0 ? 0 : b > 255 ? 255 : b; \
+               dp[x] = r | (g << 8) | (b << 16); \
                lastrgb = dp[x]; \
            } \
        } \
 
 #undef UNROLL2
 #define UNROLL2(x)     \
-       UNROLL1(x+0);   \
-       UNROLL1(x+1);   \
+       UNROLL1(x + 0); \
+       UNROLL1(x + 1); \
 
        UNROLL32(0);
-       dp+=da;
+       dp += da;
     }
 }
 
@@ -2386,7 +2423,7 @@
 #ifdef USE_OPENGL
 global void VideoDrawFogAlphaOpenGL(
     const GraphicData* data __attribute__((unused)),
-    int x __attribute__((unused)),int y __attribute__((unused)))
+    int x __attribute__((unused)), int y __attribute__((unused)))
 {
 }
 #endif
@@ -2404,16 +2441,19 @@
 #ifdef USE_OPENGL
 global void VideoDrawOnlyFogAlphaOpenGL(
     const GraphicData* data __attribute__((unused)),
-    int x,int y)
+    int x, int y)
 {
-    GLint sx,ex,sy,ey;
+    GLint sx;
+    GLint ex;
+    GLint sy;
+    GLint ey;
     Graphic *g;
 
-    g=TheMap.TileData;
-    sx=x;
-    ex=sx+TileSizeX;
-    ey=VideoHeight-y;
-    sy=ey-TileSizeY;
+    g = TheMap.TileData;
+    sx = x;
+    ex = sx + TileSizeX;
+    ey = VideoHeight - y;
+    sy = ey - TileSizeY;
 
     glDisable(GL_TEXTURE_2D);
     glColor4f(0.0f, 0.0f, 0.0f, 0.5f);
@@ -2439,7 +2479,7 @@
 **     @param dx       X position into video memory.
 **     @param dy       Y position into video memory.
 */
-local void DrawFogOfWarTile(int sx,int sy,int dx,int dy)
+local void DrawFogOfWarTile(int sx, int sy, int dx, int dy)
 {
     int w;
     int tile;
@@ -2447,10 +2487,10 @@
     int x;
     int y;
 
-    w=TheMap.Width;
-    tile=tile2=0;
-    x=sx-sy;
-    y=sy/TheMap.Width;
+    w = TheMap.Width;
+    tile = tile2 = 0;
+    x = sx - sy;
+    y = sy / TheMap.Width;
 
     //
     // Which Tile to draw for fog
@@ -2460,99 +2500,99 @@
     // 4 * 5
     // 6 7 8
 
-    if( sy ) {
-       if( sx!=sy ) {
-           if( !IsMapFieldExplored(ThisPlayer,x-1,y-1) ) {
-               tile2|=2;
-               tile|=2;
-           } else if( !IsMapFieldVisible(ThisPlayer,x-1,y-1) ) {
-               tile|=2;
+    if (sy) {
+       if (sx != sy) {
+           if (!IsMapFieldExplored(ThisPlayer, x - 1, y - 1)) {
+               tile2 |= 2;
+               tile |= 2;
+           } else if (!IsMapFieldVisible(ThisPlayer, x - 1, y - 1)) {
+               tile |= 2;
            }
        }
-       if( !IsMapFieldExplored(ThisPlayer,x,y-1) ) {
-           tile2|=3;
-           tile|=3;
-       } else if( !IsMapFieldVisible(ThisPlayer,x,y-1) ) {
-           tile|=3;
-       }
-       if( sx!=sy+w-1 ) {
-           if( !IsMapFieldExplored(ThisPlayer,x+1,y-1) ) {
-               tile2|=1;
-               tile|=1;
-           } else if( !IsMapFieldVisible(ThisPlayer,x+1,y-1) ) {
-               tile|=1;
+       if (!IsMapFieldExplored(ThisPlayer, x, y - 1)) {
+           tile2 |= 3;
+           tile |= 3;
+       } else if (!IsMapFieldVisible(ThisPlayer, x, y - 1)) {
+           tile |= 3;
+       }
+       if (sx != sy + w - 1) {
+           if (!IsMapFieldExplored(ThisPlayer, x + 1, y - 1)) {
+               tile2 |= 1;
+               tile |= 1;
+           } else if (!IsMapFieldVisible(ThisPlayer, x + 1, y - 1)) {
+               tile |= 1;
            }
        }
     }
 
-    if( sx!=sy ) {
-       if( !IsMapFieldExplored(ThisPlayer,x-1,y) ) {
-           tile2|=10;
-           tile|=10;
-       } else if( !IsMapFieldVisible(ThisPlayer,x-1,y) ) {
-           tile|=10;
-       }
-    }
-    if( sx!=sy+w-1 ) {
-       if( !IsMapFieldExplored(ThisPlayer,x+1,y) ) {
-           tile2|=5;
-           tile|=5;
-       } else if( !IsMapFieldVisible(ThisPlayer,x+1,y) ) {
-           tile|=5;
+    if (sx != sy) {
+       if (!IsMapFieldExplored(ThisPlayer, x - 1, y)) {
+           tile2 |= 10;
+           tile |= 10;
+       } else if (!IsMapFieldVisible(ThisPlayer, x - 1, y)) {
+           tile |= 10;
+       }
+    }
+    if (sx != sy + w - 1) {
+       if (!IsMapFieldExplored(ThisPlayer, x + 1, y)) {
+           tile2 |= 5;
+           tile |= 5;
+       } else if (!IsMapFieldVisible(ThisPlayer, x + 1, y)) {
+           tile |= 5;
        }
     }
 
-    if( sy+w<TheMap.Height*w ) {
-       if( sx!=sy ) {
-           if( !IsMapFieldExplored(ThisPlayer,x-1,y+1) ) {
-               tile2|=8;
-               tile|=8;
-           } else if( !IsMapFieldVisible(ThisPlayer,x-1,y+1) ) {
-               tile|=8;
+    if (sy + w < TheMap.Height * w) {
+       if (sx != sy) {
+           if (!IsMapFieldExplored(ThisPlayer, x - 1, y + 1)) {
+               tile2 |= 8;
+               tile |= 8;
+           } else if (!IsMapFieldVisible(ThisPlayer, x - 1, y + 1)) {
+               tile |= 8;
            }
        }
-       if( !IsMapFieldExplored(ThisPlayer,x,y+1) ) {
-           tile2|=12;
-           tile|=12;
-       } else if( !IsMapFieldVisible(ThisPlayer,x,y+1) ) {
-           tile|=12;
-       }
-       if( sx!=sy+w-1 ) {
-           if( !IsMapFieldExplored(ThisPlayer,x+1,y+1) ) {
-               tile2|=4;
-               tile|=4;
-           } else if( !IsMapFieldVisible(ThisPlayer,x+1,y+1) ) {
-               tile|=4;
+       if (!IsMapFieldExplored(ThisPlayer, x, y + 1)) {
+           tile2 |= 12;
+           tile |= 12;
+       } else if (!IsMapFieldVisible(ThisPlayer, x, y + 1)) {
+           tile |= 12;
+       }
+       if (sx != sy + w - 1) {
+           if (!IsMapFieldExplored(ThisPlayer, x + 1, y + 1)) {
+               tile2 |= 4;
+               tile |= 4;
+           } else if (!IsMapFieldVisible(ThisPlayer, x + 1, y + 1)) {
+               tile |= 4;
            }
        }
     }
 
-    tile=FogTable[tile];
-    tile2=FogTable[tile2];
+    tile = FogTable[tile];
+    tile2 = FogTable[tile2];
 
-    if( ReplayRevealMap ) {
+    if (ReplayRevealMap) {
        tile2 = 0;
        tile = 0;
     }
 
-    if( tile2 ) {
-       VideoDrawUnexplored(TheMap.Tiles[tile2],dx,dy);
-       if( tile2==tile ) {             // no same fog over unexplored
-//         if( tile != 0xf ) {
-//             TheMap.Fields[sx].VisibleLastFrame|=MapFieldPartiallyVisible;
+    if (tile2) {
+       VideoDrawUnexplored(TheMap.Tiles[tile2], dx, dy);
+       if (tile2 == tile) {            // no same fog over unexplored
+//         if (tile != 0xf) {
+//             TheMap.Fields[sx].VisibleLastFrame |= MapFieldPartiallyVisible;
 //         }
-           tile=0;
+           tile = 0;
        }
     }
-    if( IsMapFieldVisible(ThisPlayer,x,y) || ReplayRevealMap ) {
-       if( tile ) {
-           VideoDrawFog(TheMap.Tiles[tile],dx,dy);
-//         TheMap.Fields[sx].VisibleLastFrame|=MapFieldPartiallyVisible;
+    if (IsMapFieldVisible(ThisPlayer, x, y) || ReplayRevealMap) {
+       if (tile) {
+           VideoDrawFog(TheMap.Tiles[tile], dx, dy);
+//         TheMap.Fields[sx].VisibleLastFrame |= MapFieldPartiallyVisible;
 //     } else {
-//         TheMap.Fields[sx].VisibleLastFrame|=MapFieldCompletelyVisible;
+//         TheMap.Fields[sx].VisibleLastFrame |= MapFieldCompletelyVisible;
        }
     } else {
-       VideoDrawOnlyFog(TheMap.Tiles[UNEXPLORED_TILE],dx,dy);
+       VideoDrawOnlyFog(TheMap.Tiles[UNEXPLORED_TILE], dx, dy);
     }   
 }
 
@@ -2569,7 +2609,7 @@
 **     @param x        Map viewpoint x position.
 **     @param y        Map viewpoint y position.
 */
-global void DrawMapFogOfWar(const Viewport* vp, int x,int y)
+global void DrawMapFogOfWar(const Viewport* vp, int x, int y)
 {
     int sx;
     int sy;
@@ -2584,101 +2624,100 @@
     int mx;
 
 #ifdef TIMEIT
-    u_int64_t sv=rdtsc();
+    u_int64_t sv = rdtsc();
     u_int64_t ev;
-    static long mv=9999999;
+    static long mv = 9999999;
 #endif
 
-    redraw_row=MustRedrawRow;          // flags must redraw or not
-    redraw_tile=MustRedrawTile;
+    redraw_row = MustRedrawRow;                // flags must redraw or not
+    redraw_tile = MustRedrawTile;
 
-    p=ThisPlayer->Player;
+    p = ThisPlayer->Player;
 
     ex = vp->EndX;
-    sy = y*TheMap.Width;
+    sy = y * TheMap.Width;
     dy = vp->Y;
     ey = vp->EndY;
 
-    while( dy<ey ) {
-       if( *redraw_row ) {             // row must be redrawn
+    while (dy < ey) {
+       if (*redraw_row) {              // row must be redrawn
 #if NEW_MAPDRAW > 1
            (*redraw_row)--;
 #else
-           *redraw_row=0;
+           *redraw_row = 0;
 #endif
-           sx=x+sy;
+           sx = x + sy;
            dx = vp->X;
-           while( dx<ex ) {
-               if( *redraw_tile ) {
+           while (dx < ex) {
+               if (*redraw_tile) {
 #if NEW_MAPDRAW > 1
                   (*redraw_tile)--;
 #else
-                  *redraw_tile=0;
-                   mx=(dx-vp->X)/TileSizeX + vp->MapX;
-                   my=(dy-vp->Y)/TileSizeY + vp->MapY;
-                   if( IsTileVisible(ThisPlayer,mx,my) || ReplayRevealMap ) {
-                       DrawFogOfWarTile(sx,sy,dx,dy);
+                  *redraw_tile = 0;
+                   mx = (dx - vp->X) / TileSizeX + vp->MapX;
+                   my = (dy - vp->Y) / TileSizeY + vp->MapY;
+                   if (IsTileVisible(ThisPlayer, mx, my) || ReplayRevealMap) {
+                       DrawFogOfWarTile(sx, sy, dx, dy);
                    } else {
 #ifdef USE_OPENGL
-                       MapDrawTile(UNEXPLORED_TILE,dx,dy);
+                       MapDrawTile(UNEXPLORED_TILE, dx, dy);
 #else
-                       VideoDrawTile(TheMap.Tiles[UNEXPLORED_TILE],dx,dy);
+                       VideoDrawTile(TheMap.Tiles[UNEXPLORED_TILE], dx, dy);
 #endif
                    }
 #endif
 
 // Used to debug NEW_FOW problems
 #if !defined(HIERARCHIC_PATHFINDER) && defined(DEBUG_FOG_OF_WAR)
-extern int VideoDrawText(int x,int y,unsigned font,const unsigned char* text);
+extern int VideoDrawText(int x, int y, unsigned font, const unsigned char* 
text);
 #define GameFont 1
-       {
-       char seen[7];
-       int x=(dx-vp->X)/TileSizeX + vp->MapX;
-       int y=(dy-vp->Y)/TileSizeY + vp->MapY;
+                   {
+                       char seen[7];
+                       int x = (dx - vp->X) / TileSizeX + vp->MapX;
+                       int y = (dy - vp->Y) / TileSizeY + vp->MapY;
 
 #if 1
-       //  Fog of War Vision
-       //  Really long and ugly, shared and own vision:
-       //  
sprintf(seen,"%d(%d)",TheMap.Fields[y*TheMap.Width+x].Visible[ThisPlayer->Player],IsMapFieldVisible(ThisPlayer,x,y));
-       //  Shorter version, but no shared vision:
-       
sprintf(seen,"%d",TheMap.Fields[y*TheMap.Width+x].Visible[ThisPlayer->Player]);
-//     if( TheMap.Fields[y*TheMap.Width+x].Visible[0] ) {
-           VideoDrawText(dx,dy, GameFont,seen);
-//     }
+                       //  Fog of War Vision
+                       //  Really long and ugly, shared and own vision:
+                       //  sprintf(seen,"%d(%d)",TheMap.Fields[y * 
TheMap.Width + x].Visible[ThisPlayer->Player],IsMapFieldVisible(ThisPlayer,x, 
y));
+                       //  Shorter version, but no shared vision:
+                       sprintf(seen,"%d",TheMap.Fields[y * TheMap.Width + 
x].Visible[ThisPlayer->Player]);
+//                     if (TheMap.Fields[y * TheMap.Width + x].Visible[0]) {
+                           VideoDrawText(dx, dy, GameFont,seen);
+//                     }
 #else
-       // Unit Distance Checks
-       if( Selected[1] && Selected[0] ) {
-           sprintf(seen,"%d",MapDistanceBetweenUnits(Selected[0],Selected[1]));
-           VideoDrawText(dx,dy, GameFont,seen);
-       } else if( Selected[0] ) {
-           sprintf(seen,"%d",MapDistanceToUnit(x,y,Selected[0]));
-           VideoDrawText(dx,dy, GameFont,seen);
-       }
+                       // Unit Distance Checks
+                       if (Selected[1] && Selected[0]) {
+                           sprintf(seen, "%d", 
MapDistanceBetweenUnits(Selected[0], Selected[1]));
+                           VideoDrawText(dx, dy, GameFont, seen);
+                       } else if (Selected[0]) {
+                           sprintf(seen, "%d", MapDistanceToUnit(x, 
y,Selected[0]));
+                           VideoDrawText(dx, dy, GameFont, seen);
+                       }
 #endif
-       }
+                   }
 #endif 
 #if defined(HIERARCHIC_PATHFINDER) && defined(DEBUG) && 0
                    {
                        char regidstr[8];
                        char groupstr[8];
                        int regid;
-extern int VideoDrawText(int x,int y,unsigned font,const unsigned char* text);
+extern int VideoDrawText(int x, int y, unsigned font, const unsigned char* 
text);
 #define GameFont 1
 
                        if (PfHierShowRegIds || PfHierShowGroupIds) {
-                           regid =
-                               MapFieldGetRegId (
-                                           (dx-vp->X)/TileSizeX + vp->MapX,
-                                           (dy-vp->Y)/TileSizeY + vp->MapY);
+                           regid = MapFieldGetRegId (
+                               (dx - vp->X) / TileSizeX + vp->MapX,
+                               (dy - vp->Y) / TileSizeY + vp->MapY);
                            if (regid) {
-                               Region *r = RegionSetFind (regid);
+                               Region* r = RegionSetFind(regid);
                                if (PfHierShowRegIds) {
-                                   snprintf (regidstr, 8, "%d", regid);
-                                   VideoDrawText (dx, dy, GameFont, regidstr);
+                                   snprintf(regidstr, 8, "%d", regid);
+                                   VideoDrawText(dx, dy, GameFont, regidstr);
                                }
                                if (PfHierShowGroupIds) {
-                                   snprintf (groupstr, 8, "%d", r->GroupId);
-                                   VideoDrawText (dx, dy+19, GameFont, 
groupstr);
+                                   snprintf(groupstr, 8, "%d", r->GroupId);
+                                   VideoDrawText(dx, dy + 19, GameFont, 
groupstr);
                                }
                            }
                        }
@@ -2687,24 +2726,24 @@
                }
                 ++redraw_tile;
                ++sx;
-               dx+=TileSizeX;
+               dx += TileSizeX;
            }
        } else {
            redraw_tile += vp->MapWidth;
        }
         ++redraw_row;
-       sy+=TheMap.Width;
-       dy+=TileSizeY;
+       sy += TheMap.Width;
+       dy += TileSizeY;
     }
 
 #ifdef TIMEIT
-    ev=rdtsc();
-    sx=(ev-sv);
-    if( sx<mv ) {
-       mv=sx;
+    ev = rdtsc();
+    sx = (ev - sv);
+    if (sx < mv) {
+       mv = sx;
     }
 
-    DebugLevel1("%ld %ld %3ld\n" _C_ (long)sx _C_ mv _C_ (sx*100)/mv);
+    DebugLevel1("%ld %ld %3ld\n" _C_ (long)sx _C_ mv _C_ (sx * 100) / mv);
 #endif
 }
 
@@ -2716,201 +2755,195 @@
 {
 
 #ifdef USE_OPENGL
-    VideoDrawFog=VideoDrawFogAlphaOpenGL;
-    VideoDrawOnlyFog=VideoDrawOnlyFogAlphaOpenGL;
-    VideoDrawUnexplored=VideoDrawUnexploredSolidOpenGL;
+    VideoDrawFog = VideoDrawFogAlphaOpenGL;
+    VideoDrawOnlyFog = VideoDrawOnlyFogAlphaOpenGL;
+    VideoDrawUnexplored = VideoDrawUnexploredSolidOpenGL;
 #else
-    if( !OriginalFogOfWar ) {
+    if (!OriginalFogOfWar) {
        int i;
        int n;
        int v;
-       int r,g,b;
-       int rmask,gmask,bmask;
-       int rshft,gshft,bshft;
-       int rloss,gloss,bloss;
+       int r, g, b;
+       int rmask, gmask, bmask;
+       int rshft, gshft, bshft;
+       int rloss, gloss, bloss;
 
 
-       switch( VideoDepth ) {
+       switch (VideoDepth) {
            case 8:
-               n=1<<(sizeof(VMemType8)*8);
-               if( !FogOfWarAlphaTable ) {
-                   FogOfWarAlphaTable=malloc(n*sizeof(VMemType8));
+               n = 1 << (sizeof(VMemType8) * 8);
+               if (!FogOfWarAlphaTable) {
+                   FogOfWarAlphaTable = malloc(n * sizeof(VMemType8));
                }
-               if ( lookup25trans8 ) { // if enabled, make use of it in 8bpp ;)
+               if (lookup25trans8) { // if enabled, make use of it in 8bpp ;)
                    unsigned int trans_color;
                    int j;
 
-                   trans_color=Pixels8[ColorBlack];
-                   trans_color<<=8;
+                   trans_color = Pixels8[ColorBlack];
+                   trans_color <<= 8;
 
                    //FIXME: determine which lookup table to use based on
                    //FIXME: FogOfWarSaturation,FogOfWarContrast and
                    //FIXME: FogOfWarBrightness
-                   for( j=0; j<n; ++j ) {
+                   for (j = 0; j < n; ++j) {
                        ((VMemType8*)FogOfWarAlphaTable)[j] =
-                           lookup50trans8[ trans_color | j ];
+                           lookup50trans8[trans_color | j];
                    }
                } else {
-                   for( i=0; i<n; ++i ) {
+                   for (i = 0; i < n; ++i) {
                        int j;
                        int l;
                        int d;
 
-                       r=GlobalPalette[i].r;
-                       g=GlobalPalette[i].g;
-                       b=GlobalPalette[i].b;
+                       r = GlobalPalette[i].r;
+                       g = GlobalPalette[i].g;
+                       b = GlobalPalette[i].b;
                        DebugLevel3("%d,%d,%d\n" _C_ r _C_ g _C_ b);
-                       v=r+g+b;
+                       v = r + g + b;
 
-                       r= ((((r*3-v)*FogOfWarSaturation + v*100)
-                           *FogOfWarContrast)
-                           +FogOfWarBrightness*25600*3)/30000;
-                       g= ((((g*3-v)*FogOfWarSaturation + v*100)
-                           *FogOfWarContrast)
-                           +FogOfWarBrightness*25600*3)/30000;
-                       b= ((((b*3-v)*FogOfWarSaturation + v*100)
-                           *FogOfWarContrast)
-                           +FogOfWarBrightness*25600*3)/30000;
+                       r = ((((r * 3 - v) * FogOfWarSaturation + v * 100) *
+                           FogOfWarContrast) + FogOfWarBrightness * 25600 * 3) 
/ 30000;
+                       g = ((((g * 3 - v) * FogOfWarSaturation + v * 100) *
+                           FogOfWarContrast) + FogOfWarBrightness * 25600 * 3) 
/ 30000;
+                       b = ((((b * 3 - v) * FogOfWarSaturation + v * 100) *
+                           FogOfWarContrast) + FogOfWarBrightness * 25600 * 3) 
/ 30000;
 
                        // Boundings
-                       r= r<0 ? 0 : r>255 ? 255 : r;
-                       g= g<0 ? 0 : g>255 ? 255 : g;
-                       b= b<0 ? 0 : b>255 ? 255 : b;
+                       r = r < 0 ? 0 : r > 255 ? 255 : r;
+                       g = g < 0 ? 0 : g > 255 ? 255 : g;
+                       b = b < 0 ? 0 : b > 255 ? 255 : b;
 
                        //
                        //      Find the best matching color
                        //
-                       l=i;
-                       d=256*3+256;
-                       for( j=0; j<256; ++j ) {
+                       l = i;
+                       d = 256 * 3 + 256;
+                       for (j = 0; j < 256; ++j) {
                            // simple color distance
-                           v=(abs(GlobalPalette[j].r-r)
-                               +abs(GlobalPalette[j].g-g)
-                               +abs(GlobalPalette[j].b-b))*3
+                           v = (abs(GlobalPalette[j].r - r) +
+                               abs(GlobalPalette[j].g - g) +
+                               abs(GlobalPalette[j].b - b)) * 3 +
                                // light
-                               +abs(GlobalPalette[j].r
-                                   +GlobalPalette[j].g
-                                   +GlobalPalette[j].b-(r+g+b))*1;
-                           if( v<d ) {
-                               d=v;
-                               l=j;
+                               abs(GlobalPalette[j].r +
+                                   GlobalPalette[j].g +
+                                   GlobalPalette[j].b - (r + g + b)) * 1;
+                           if (v < d) {
+                               d = v;
+                               l = j;
                            }
                        }
-                       DebugLevel3("%d,%d,%d -> %d,%d,%d\n" _C_ r _C_ g _C_ b
-                               _C_ GlobalPalette[l].r _C_ GlobalPalette[l].g
-                               _C_ GlobalPalette[l].b);
-                       ((VMemType8*)FogOfWarAlphaTable)[i]=l;
+                       DebugLevel3("%d,%d,%d -> %d,%d,%d\n" _C_ r _C_ g _C_ b 
_C_
+                           GlobalPalette[l].r _C_ GlobalPalette[l].g _C_
+                           GlobalPalette[l].b);
+                       ((VMemType8*)FogOfWarAlphaTable)[i] = l;
                    }
                }
 
-               if( TileSizeX==16 && TileSizeY==16 ) {
-                   VideoDrawFog=VideoDraw8Fog16Alpha;
-                   VideoDrawOnlyFog=VideoDraw8OnlyFog16Alpha;
-                   VideoDrawUnexplored=VideoDraw8Unexplored16Solid;
-               } else if( TileSizeX==32 && TileSizeY==32 ) {
-                   VideoDrawFog=VideoDraw8Fog32Alpha;
-                   VideoDrawOnlyFog=VideoDraw8OnlyFog32Alpha;
-                   VideoDrawUnexplored=VideoDraw8Unexplored32Solid;
+               if (TileSizeX == 16 && TileSizeY == 16) {
+                   VideoDrawFog = VideoDraw8Fog16Alpha;
+                   VideoDrawOnlyFog = VideoDraw8OnlyFog16Alpha;
+                   VideoDrawUnexplored = VideoDraw8Unexplored16Solid;
+               } else if (TileSizeX == 32 && TileSizeY == 32) {
+                   VideoDrawFog = VideoDraw8Fog32Alpha;
+                   VideoDrawOnlyFog = VideoDraw8OnlyFog32Alpha;
+                   VideoDrawUnexplored = VideoDraw8Unexplored32Solid;
                } else {
-                   printf("Tile size not supported: 
(%dx%d)\n",TileSizeX,TileSizeY);
+                   printf("Tile size not supported: (%dx%d)\n", TileSizeX, 
TileSizeY);
                    exit(1);
                }
                break;
 
            case 15:                    // 15 bpp 555 video depth
-               rshft=( 0);
-               gshft=( 5);
-               bshft=(10);
-               rmask=(0x1F<<rshft);
-               gmask=(0x1F<<gshft);
-               bmask=(0x1F<<bshft);
-               rloss=( 3);
-               gloss=( 3);
-               bloss=( 3);
+               rshft = ( 0);
+               gshft = ( 5);
+               bshft = (10);
+               rmask = (0x1F << rshft);
+               gmask = (0x1F << gshft);
+               bmask = (0x1F << bshft);
+               rloss = ( 3);
+               gloss = ( 3);
+               bloss = ( 3);
                goto build_table;
 
            case 16:                    // 16 bpp 565 video depth
-               rshft=( 0);
-               gshft=( 5);
-               bshft=(11);
-               rmask=(0x1F<<rshft);
-               gmask=(0x3F<<gshft);
-               bmask=(0x1F<<bshft);
-               rloss=( 3);
-               gloss=( 2);
-               bloss=( 3);
+               rshft = ( 0);
+               gshft = ( 5);
+               bshft = (11);
+               rmask = (0x1F << rshft);
+               gmask = (0x3F << gshft);
+               bmask = (0x1F << bshft);
+               rloss = ( 3);
+               gloss = ( 2);
+               bloss = ( 3);
 
 build_table:
-               n=1<<(sizeof(VMemType16)*8);
-               if( !FogOfWarAlphaTable ) {
-                   FogOfWarAlphaTable=malloc(n*sizeof(VMemType16));
+               n = 1 << (sizeof(VMemType16) * 8);
+               if (!FogOfWarAlphaTable) {
+                   FogOfWarAlphaTable = malloc(n * sizeof(VMemType16));
                }
-               for( i=0; i<n; ++i ) {
-                   r=(i&rmask)>>rshft<<rloss;
-                   g=(i&gmask)>>gshft<<gloss;
-                   b=(i&bmask)>>bshft<<bloss;
-                   v=r+g+b;
-
-                   r= ((((r*3-v)*FogOfWarSaturation + v*100)
-                       *FogOfWarContrast)
-                       +FogOfWarBrightness*25600*3)/30000;
-                   g= ((((g*3-v)*FogOfWarSaturation + v*100)
-                       *FogOfWarContrast)
-                       +FogOfWarBrightness*25600*3)/30000;
-                   b= ((((b*3-v)*FogOfWarSaturation + v*100)
-                       *FogOfWarContrast)
-                       +FogOfWarBrightness*25600*3)/30000;
+               for (i = 0; i < n; ++i) {
+                   r = (i & rmask) >> rshft << rloss;
+                   g = (i & gmask) >> gshft << gloss;
+                   b = (i & bmask) >> bshft << bloss;
+                   v = r + g + b;
+
+                   r = ((((r * 3 - v) * FogOfWarSaturation + v * 100) *
+                       FogOfWarContrast) + FogOfWarBrightness * 25600 * 3) / 
30000;
+                   g = ((((g * 3 - v) * FogOfWarSaturation + v * 100) *
+                       FogOfWarContrast) + FogOfWarBrightness * 25600 * 3) / 
30000;
+                   b = ((((b * 3 - v) * FogOfWarSaturation + v * 100) *
+                       FogOfWarContrast) + FogOfWarBrightness * 25600 * 3) / 
30000;
 
                    // Boundings
-                   r= r<0 ? 0 : r>255 ? 255 : r;
-                   g= g<0 ? 0 : g>255 ? 255 : g;
-                   b= b<0 ? 0 : b>255 ? 255 : b;
-                   ((VMemType16*)FogOfWarAlphaTable)[i]=((r>>rloss)<<rshft)
-                           |((g>>gloss)<<gshft)
-                           |((b>>bloss)<<bshft);
+                   r = r < 0 ? 0 : r > 255 ? 255 : r;
+                   g = g < 0 ? 0 : g > 255 ? 255 : g;
+                   b = b < 0 ? 0 : b > 255 ? 255 : b;
+                   ((VMemType16*)FogOfWarAlphaTable)[i] =
+                       ((r >> rloss) << rshft) | ((g >> gloss) << gshft) |
+                       ((b >> bloss) << bshft);
                }
-               if( TileSizeX==16 && TileSizeY==16 ) {
-                   VideoDrawFog=VideoDraw16Fog16Alpha;
-                   VideoDrawOnlyFog=VideoDraw16OnlyFog16Alpha;
-                   VideoDrawUnexplored=VideoDraw16Unexplored16Solid;
-               } else if( TileSizeX==32 && TileSizeY==32 ) {
-                   VideoDrawFog=VideoDraw16Fog32Alpha;
-                   VideoDrawOnlyFog=VideoDraw16OnlyFog32Alpha;
-                   VideoDrawUnexplored=VideoDraw16Unexplored32Solid;
+               if (TileSizeX == 16 && TileSizeY == 16) {
+                   VideoDrawFog = VideoDraw16Fog16Alpha;
+                   VideoDrawOnlyFog = VideoDraw16OnlyFog16Alpha;
+                   VideoDrawUnexplored = VideoDraw16Unexplored16Solid;
+               } else if (TileSizeX == 32 && TileSizeY == 32) {
+                   VideoDrawFog = VideoDraw16Fog32Alpha;
+                   VideoDrawOnlyFog = VideoDraw16OnlyFog32Alpha;
+                   VideoDrawUnexplored = VideoDraw16Unexplored32Solid;
                } else {
-                   printf("Tile size not supported: 
(%dx%d)\n",TileSizeX,TileSizeY);
+                   printf("Tile size not supported: (%dx%d)\n", TileSizeX, 
TileSizeY);
                    exit(1);
                }
                break;
 
            case 24:
-               if( VideoBpp==24 ) {
-                   if( TileSizeX==16 && TileSizeY==16 ) {
-                       VideoDrawFog=VideoDraw24Fog16Alpha;
-                       VideoDrawOnlyFog=VideoDraw24OnlyFog16Alpha;
-                       VideoDrawUnexplored=VideoDraw24Unexplored16Solid;
-                   } else if( TileSizeX==32 && TileSizeY==32 ) {
-                       VideoDrawFog=VideoDraw24Fog32Alpha;
-                       VideoDrawOnlyFog=VideoDraw24OnlyFog32Alpha;
-                       VideoDrawUnexplored=VideoDraw24Unexplored32Solid;
+               if (VideoBpp == 24) {
+                   if (TileSizeX == 16 && TileSizeY == 16) {
+                       VideoDrawFog = VideoDraw24Fog16Alpha;
+                       VideoDrawOnlyFog = VideoDraw24OnlyFog16Alpha;
+                       VideoDrawUnexplored = VideoDraw24Unexplored16Solid;
+                   } else if (TileSizeX == 32 && TileSizeY == 32) {
+                       VideoDrawFog = VideoDraw24Fog32Alpha;
+                       VideoDrawOnlyFog = VideoDraw24OnlyFog32Alpha;
+                       VideoDrawUnexplored = VideoDraw24Unexplored32Solid;
                    } else {
-                       printf("Tile size not supported: 
(%dx%d)\n",TileSizeX,TileSizeY);
+                       printf("Tile size not supported: (%dx%d)\n", TileSizeX, 
TileSizeY);
                        exit(1);
                    }
                    break;
                }
                // FALL THROUGH
            case 32:
-               if( TileSizeX==16 && TileSizeY==16 ) {
-                   VideoDrawFog=VideoDraw32Fog16Alpha;
-                   VideoDrawOnlyFog=VideoDraw32OnlyFog16Alpha;
-                   VideoDrawUnexplored=VideoDraw32Unexplored16Solid;
-               } else if( TileSizeX==32 && TileSizeY==32 ) {
-                   VideoDrawFog=VideoDraw32Fog32Alpha;
-                   VideoDrawOnlyFog=VideoDraw32OnlyFog32Alpha;
-                   VideoDrawUnexplored=VideoDraw32Unexplored32Solid;
+               if (TileSizeX == 16 && TileSizeY == 16) {
+                   VideoDrawFog = VideoDraw32Fog16Alpha;
+                   VideoDrawOnlyFog = VideoDraw32OnlyFog16Alpha;
+                   VideoDrawUnexplored = VideoDraw32Unexplored16Solid;
+               } else if (TileSizeX == 32 && TileSizeY == 32) {
+                   VideoDrawFog = VideoDraw32Fog32Alpha;
+                   VideoDrawOnlyFog = VideoDraw32OnlyFog32Alpha;
+                   VideoDrawUnexplored = VideoDraw32Unexplored32Solid;
                } else {
-                   printf("Tile size not supported: 
(%dx%d)\n",TileSizeX,TileSizeY);
+                   printf("Tile size not supported: (%dx%d)\n", TileSizeX, 
TileSizeY);
                    exit(1);
                }
                break;
@@ -2920,64 +2953,64 @@
                break;
        }
     } else {
-       if( TileSizeX==16 && TileSizeY==16 ) {
-           switch( VideoDepth ) {
+       if (TileSizeX == 16 && TileSizeY == 16) {
+           switch (VideoDepth) {
                case  8:                        //  8 bpp video depth
-                   VideoDrawFog=VideoDraw8Fog16Solid;
-                   VideoDrawOnlyFog=VideoDraw8OnlyFog16Solid;
-                   VideoDrawUnexplored=VideoDraw8Unexplored16Solid;
+                   VideoDrawFog = VideoDraw8Fog16Solid;
+                   VideoDrawOnlyFog = VideoDraw8OnlyFog16Solid;
+                   VideoDrawUnexplored = VideoDraw8Unexplored16Solid;
                    break;
 
                case 15:                        // 15 bpp video depth
                case 16:                        // 16 bpp video depth
-                   VideoDrawFog=VideoDraw16Fog16Solid;
-                   VideoDrawOnlyFog=VideoDraw16OnlyFog16Solid;
-                   VideoDrawUnexplored=VideoDraw16Unexplored16Solid;
+                   VideoDrawFog = VideoDraw16Fog16Solid;
+                   VideoDrawOnlyFog = VideoDraw16OnlyFog16Solid;
+                   VideoDrawUnexplored = VideoDraw16Unexplored16Solid;
                    break;
                case 24:                        // 24 bpp video depth
-                   if( VideoBpp==24 ) {
-                       VideoDrawFog=VideoDraw24Fog16Solid;
-                       VideoDrawOnlyFog=VideoDraw24OnlyFog16Solid;
-                       VideoDrawUnexplored=VideoDraw24Unexplored16Solid;
+                   if (VideoBpp == 24) {
+                       VideoDrawFog = VideoDraw24Fog16Solid;
+                       VideoDrawOnlyFog = VideoDraw24OnlyFog16Solid;
+                       VideoDrawUnexplored = VideoDraw24Unexplored16Solid;
                        break;
                    }
                    // FALL THROUGH
                case 32:                        // 32 bpp video depth
-                   VideoDrawFog=VideoDraw32Fog16Solid;
-                   VideoDrawOnlyFog=VideoDraw32OnlyFog16Solid;
-                   VideoDrawUnexplored=VideoDraw32Unexplored16Solid;
+                   VideoDrawFog = VideoDraw32Fog16Solid;
+                   VideoDrawOnlyFog = VideoDraw32OnlyFog16Solid;
+                   VideoDrawUnexplored = VideoDraw32Unexplored16Solid;
                    break;
 
                default:
                    DebugLevel0Fn("Depth unsupported %d\n" _C_ VideoDepth);
                    break;
            }
-       } else if( TileSizeX==32 && TileSizeY==32 ) {
-           switch( VideoDepth ) {
+       } else if (TileSizeX == 32 && TileSizeY == 32) {
+           switch (VideoDepth) {
                case  8:                        //  8 bpp video depth
-                   VideoDrawFog=VideoDraw8Fog32Solid;
-                   VideoDrawOnlyFog=VideoDraw8OnlyFog32Solid;
-                   VideoDrawUnexplored=VideoDraw8Unexplored32Solid;
+                   VideoDrawFog = VideoDraw8Fog32Solid;
+                   VideoDrawOnlyFog = VideoDraw8OnlyFog32Solid;
+                   VideoDrawUnexplored = VideoDraw8Unexplored32Solid;
                    break;
 
                case 15:                        // 15 bpp video depth
                case 16:                        // 16 bpp video depth
-                   VideoDrawFog=VideoDraw16Fog32Solid;
-                   VideoDrawOnlyFog=VideoDraw16OnlyFog32Solid;
-                   VideoDrawUnexplored=VideoDraw16Unexplored32Solid;
+                   VideoDrawFog = VideoDraw16Fog32Solid;
+                   VideoDrawOnlyFog = VideoDraw16OnlyFog32Solid;
+                   VideoDrawUnexplored = VideoDraw16Unexplored32Solid;
                    break;
                case 24:                        // 24 bpp video depth
-                   if( VideoBpp==24 ) {
-                       VideoDrawFog=VideoDraw24Fog32Solid;
-                       VideoDrawOnlyFog=VideoDraw24OnlyFog32Solid;
-                       VideoDrawUnexplored=VideoDraw24Unexplored32Solid;
+                   if (VideoBpp == 24) {
+                       VideoDrawFog = VideoDraw24Fog32Solid;
+                       VideoDrawOnlyFog = VideoDraw24OnlyFog32Solid;
+                       VideoDrawUnexplored = VideoDraw24Unexplored32Solid;
                        break;
                    }
                    // FALL THROUGH
                case 32:                        // 32 bpp video depth
-                   VideoDrawFog=VideoDraw32Fog32Solid;
-                   VideoDrawOnlyFog=VideoDraw32OnlyFog32Solid;
-                   VideoDrawUnexplored=VideoDraw32Unexplored32Solid;
+                   VideoDrawFog = VideoDraw32Fog32Solid;
+                   VideoDrawOnlyFog = VideoDraw32OnlyFog32Solid;
+                   VideoDrawUnexplored = VideoDraw32Unexplored32Solid;
                    break;
 
                default:
@@ -2985,7 +3018,7 @@
                    break;
            }
        } else {
-           printf("Tile size not supported: (%dx%d)\n",TileSizeX,TileSizeY);
+           printf("Tile size not supported: (%dx%d)\n", TileSizeX, TileSizeY);
            exit(1);
        }
     }
@@ -2997,9 +3030,9 @@
 */
 global void CleanMapFogOfWar(void)
 {
-    if( FogOfWarAlphaTable ) {
+    if (FogOfWarAlphaTable) {
        free(FogOfWarAlphaTable);
-       FogOfWarAlphaTable=NULL;
+       FogOfWarAlphaTable = NULL;
     }
 }
 
@@ -3008,7 +3041,7 @@
 */
 global void InitVisionTable(void)
 {
-    int *visionlist;
+    int* visionlist;
     int maxsize;
     int sizex;
     int sizey;
@@ -3022,136 +3055,131 @@
     int repeat;
 
     // Initialize Visiontable to large size, can't be more entries than tiles.
-    VisionTable[0]=malloc(MaxMapWidth*MaxMapWidth*sizeof(int));
-    VisionTable[1]=malloc(MaxMapWidth*MaxMapWidth*sizeof(int));
-    VisionTable[2]=malloc(MaxMapWidth*MaxMapWidth*sizeof(int));
+    VisionTable[0] = malloc(MaxMapWidth * MaxMapWidth * sizeof(int));
+    VisionTable[1] = malloc(MaxMapWidth * MaxMapWidth * sizeof(int));
+    VisionTable[2] = malloc(MaxMapWidth * MaxMapWidth * sizeof(int));
 
-    VisionLookup=malloc((MaxMapWidth+2)*sizeof(int));
+    VisionLookup = malloc((MaxMapWidth + 2) * sizeof(int));
 #ifndef SQUAREVISION
-    visionlist=malloc(MaxMapWidth*MaxMapWidth*sizeof(int));
+    visionlist = malloc(MaxMapWidth * MaxMapWidth * sizeof(int));
     //*2 as diagonal distance is longer
 
     maxsize = MaxMapWidth;
     maxsearchsize = MaxMapWidth;
     // Fill in table of map size
-    for(sizex=0; sizex < maxsize; sizex++) {
-       for(sizey=0; sizey < maxsize; sizey++) {
-           visionlist[sizey*maxsize+sizex]=isqrt(sizex*sizex+sizey*sizey);
+    for (sizex = 0; sizex < maxsize; ++sizex) {
+       for (sizey = 0; sizey < maxsize; ++sizey) {
+           visionlist[sizey * maxsize + sizex] = isqrt(sizex * sizex + sizey * 
sizey);
        }
     }
 
-    VisionLookup[0]=0;
-    i=1;
-    VisionTablePosition=0;
-    while( i < maxsearchsize ) {
+    VisionLookup[0] = 0;
+    i = 1;
+    VisionTablePosition = 0;
+    while (i < maxsearchsize) {
        // Set Lookup Table
-       VisionLookup[i]=VisionTablePosition;
+       VisionLookup[i] = VisionTablePosition;
        // Put in Null Marker
-       VisionTable[0][VisionTablePosition]=i;
-       VisionTable[1][VisionTablePosition]=0;
-       VisionTable[2][VisionTablePosition]=0;
-       VisionTablePosition++;
+       VisionTable[0][VisionTablePosition] = i;
+       VisionTable[1][VisionTablePosition] = 0;
+       VisionTable[2][VisionTablePosition] = 0;
+       ++VisionTablePosition;
 
 
-       // find i in left column
-       marker = maxsize*i;
+       // find i in left column
+       marker = maxsize * i;
        direction = 0;
-       right=0;
-       up=0;
+       right = 0;
+       up = 0;
 
        // If not on top row, continue
        do {
-           repeat=0;
+           repeat = 0;
            do {
                // search for repeating
                // Test Right
-               if( (repeat == 0 || direction==1) && visionlist[marker+1] == i 
) {
-                   right=1;
-                   up=0;
-                   repeat++;
-                   direction=1;
-                   marker++;
-               } else if ( (repeat == 0 || direction==2) && 
visionlist[marker-maxsize] == i ) {
-                   up=1;
-                   right=0;
-                   repeat++;
-                   direction=2;
-                   marker=marker-maxsize;
-               } else if ( (repeat == 0 || direction==3) && 
visionlist[marker+1-maxsize] == i
-                       &&  visionlist[marker-maxsize] != i && 
visionlist[marker+1] != i) {
-                   up=1;
-                   right=1;
-                   repeat++;
-                   direction=3;
-                   marker=marker+1-maxsize;
+               if ((repeat == 0 || direction == 1) && visionlist[marker + 1] 
== i) {
+                   right = 1;
+                   up = 0;
+                   ++repeat;
+                   direction = 1;
+                   ++marker;
+               } else if ((repeat == 0 || direction == 2) && visionlist[marker 
- maxsize] == i) {
+                   up = 1;
+                   right = 0;
+                   ++repeat;
+                   direction = 2;
+                   marker = marker - maxsize;
+               } else if ((repeat == 0 || direction == 3) && visionlist[marker 
+ 1 - maxsize] == i &&
+                       visionlist[marker - maxsize] != i && visionlist[marker 
+ 1] != i) {
+                   up = 1;
+                   right = 1;
+                   ++repeat;
+                   direction = 3;
+                   marker = marker + 1 - maxsize;
                } else {
-                   direction=0;
+                   direction = 0;
                    break;
                }
 
               // search rigth
                // search up - store as down.
                // search diagonal
-           }  while ( direction && marker > (maxsize*2));
-           if( right || up ) {
-               VisionTable[0][VisionTablePosition]=repeat;
-               VisionTable[1][VisionTablePosition]=right;
-               VisionTable[2][VisionTablePosition]=up;
-               VisionTablePosition++;
+           }  while (direction && marker > (maxsize * 2));
+           if (right || up) {
+               VisionTable[0][VisionTablePosition] = repeat;
+               VisionTable[1][VisionTablePosition] = right;
+               VisionTable[2][VisionTablePosition] = up;
+               ++VisionTablePosition;
            }
-       } while( marker > (maxsize*2) );
-       i++;
+       } while (marker > (maxsize * 2));
+       ++i;
     }
 
-
-
-
-
     free(visionlist);
 #else
     // Find maximum distance in corner of map.
     maxsize = MaxMapWidth;
-    maxsearchsize=isqrt(MaxMapWidth/2);
+    maxsearchsize = isqrt(MaxMapWidth / 2);
     // Mark 1, It's a special case
     // Only Horizontal is marked
-    VisionTable[0][0]=1;
-    VisionTable[1][0]=0;
-    VisionTable[2][0]=0;
-    VisionTable[0][1]=1;
-    VisionTable[1][1]=1;
-    VisionTable[2][1]=0;
+    VisionTable[0][0] = 1;
+    VisionTable[1][0] = 0;
+    VisionTable[2][0] = 0;
+    VisionTable[0][1] = 1;
+    VisionTable[1][1] = 1;
+    VisionTable[2][1] = 0;
 
     // Mark VisionLookup
-    VisionLookup[0]=0;
-    VisionLookup[1]=0;
-    i=2;
-    VisionTablePosition=1;
-    while( i <= maxsearchsize ) {
-       VisionTablePosition++;
-       VisionLookup[i]=VisionTablePosition;
+    VisionLookup[0] = 0;
+    VisionLookup[1] = 0;
+    i = 2;
+    VisionTablePosition = 1;
+    while (i <= maxsearchsize) {
+       ++VisionTablePosition;
+       VisionLookup[i] = VisionTablePosition;
        // Setup Vision Start
-        VisionTable[0][VisionTablePosition]=i;
-       VisionTable[1][VisionTablePosition]=0;
-       VisionTable[2][VisionTablePosition]=0;
+        VisionTable[0][VisionTablePosition] = i;
+       VisionTable[1][VisionTablePosition] = 0;
+       VisionTable[2][VisionTablePosition] = 0;
        // Do Horizontal
-       VisionTablePosition++;
-       VisionTable[0][VisionTablePosition]=i;
-       VisionTable[1][VisionTablePosition]=1;
-       VisionTable[2][VisionTablePosition]=0;
+       ++VisionTablePosition;
+       VisionTable[0][VisionTablePosition] = i;
+       VisionTable[1][VisionTablePosition] = 1;
+       VisionTable[2][VisionTablePosition] = 0;
        // Do Vertical
-       VisionTablePosition++;
-       VisionTable[0][VisionTablePosition]=i-1;
-       VisionTable[1][VisionTablePosition]=0;
-       VisionTable[2][VisionTablePosition]=1;
+       ++VisionTablePosition;
+       VisionTable[0][VisionTablePosition] = i - 1;
+       VisionTable[1][VisionTablePosition] = 0;
+       VisionTable[2][VisionTablePosition] = 1;
        i++;
     }
 
     // Update Size of VisionTable to what was used.
-    realloc(VisionTable[0],(VisionTablePosition+2)*sizeof(int));
-    realloc(VisionTable[1],(VisionTablePosition+2)*sizeof(int));
-    realloc(VisionTable[2],(VisionTablePosition+2)*sizeof(int));
+    realloc(VisionTable[0], (VisionTablePosition + 2) * sizeof(int));
+    realloc(VisionTable[1], (VisionTablePosition + 2) * sizeof(int));
+    realloc(VisionTable[2], (VisionTablePosition + 2) * sizeof(int));
 #endif
-
 }
 
 /**
@@ -3160,21 +3188,21 @@
 global void FreeVisionTable(void)
 {
    // Free Vision Data
-    if( VisionTable[0] ) {
+    if (VisionTable[0]) {
        free(VisionTable[0]);
-       VisionTable[0]=NULL;
+       VisionTable[0] = NULL;
     }
-    if( VisionTable[1] ) {
+    if (VisionTable[1]) {
        free(VisionTable[1]);
-       VisionTable[1]=NULL;
+       VisionTable[1] = NULL;
     }
-    if( VisionTable[2] ) {
+    if (VisionTable[2]) {
        free(VisionTable[2]);
-       VisionTable[2]=NULL;
+       VisionTable[2] = NULL;
     }
-    if( VisionLookup ) {
+    if (VisionLookup) {
        free(VisionLookup);
-       VisionLookup=NULL;
+       VisionLookup = NULL;
     }
 }
 //@}




reply via email to

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