From fee897b0a72aa53b9c8493690c804469ca2c6e5b Mon Sep 17 00:00:00 2001 From: Joris Date: Thu, 6 Sep 2012 18:33:24 +0200 Subject: [PATCH] Add CMapField::Save. --- src/include/tile.h | 4 ++ src/map/map_save.cpp | 110 +++++++++++++++++++++++-------------------- 2 files changed, 62 insertions(+), 52 deletions(-) diff --git a/src/include/tile.h b/src/include/tile.h index ae1c62a0f..6262d7355 100644 --- a/src/include/tile.h +++ b/src/include/tile.h @@ -136,6 +136,7 @@ #include "unit_cache.h" #endif +class CFile; /*---------------------------------------------------------------------------- -- Map - field @@ -176,6 +177,9 @@ public: #endif {} + void Save(CFile &file) const; + +public: unsigned short Tile; /// graphic tile number unsigned short Flags; /// field flags unsigned char Cost; /// unit cost to move in this tile diff --git a/src/map/map_save.cpp b/src/map/map_save.cpp index 9977510e2..66e081799 100644 --- a/src/map/map_save.cpp +++ b/src/map/map_save.cpp @@ -47,6 +47,61 @@ -- Functions ----------------------------------------------------------------------------*/ +void CMapField::Save(CFile &file) const +{ + file.printf(" {%3d, %3d, %2d, %2d,", Tile, playerInfo.SeenTile, Value, Cost); + for (int i = 0; i != PlayerMax; ++i) { + if (playerInfo.Visible[i] == 1) { + file.printf(" \"explored\", %d,", i); + } + } + if (Flags & MapFieldHuman) { + file.printf(" \"human\","); + } + if (Flags & MapFieldLandAllowed) { + file.printf(" \"land\","); + } + if (Flags & MapFieldCoastAllowed) { + file.printf(" \"coast\","); + } + if (Flags & MapFieldWaterAllowed) { + file.printf(" \"water\","); + } + if (Flags & MapFieldNoBuilding) { + file.printf(" \"mud\","); + } + if (Flags & MapFieldUnpassable) { + file.printf(" \"block\","); + } + if (Flags & MapFieldWall) { + file.printf(" \"wall\","); + } + if (Flags & MapFieldRocks) { + file.printf(" \"rock\","); + } + if (Flags & MapFieldForest) { + file.printf(" \"wood\","); + } +#if 1 + // Not Required for save + // These are required for now, UnitType::FieldFlags is 0 until + // UpdateStats is called which is after the game is loaded + if (Flags & MapFieldLandUnit) { + file.printf(" \"ground\","); + } + if (Flags & MapFieldAirUnit) { + file.printf(" \"air\","); + } + if (Flags & MapFieldSeaUnit) { + file.printf(" \"sea\","); + } + if (Flags & MapFieldBuilding) { + file.printf(" \"building\","); + } +#endif + file.printf("}"); +} + /** ** Save the complete map. ** @@ -77,60 +132,11 @@ void CMap::Save(CFile &file) const for (int w = 0; w < this->Info.MapWidth; ++w) { const CMapField &mf = *this->Field(w, h); - file.printf(" {%3d, %3d, %2d, %2d,", mf.Tile, mf.playerInfo.SeenTile, mf.Value, mf.Cost); - for (int i = 0; i < PlayerMax; ++i) { - if (mf.playerInfo.Visible[i] == 1) { - file.printf(" \"explored\", %d,", i); - } - } - if (mf.Flags & MapFieldHuman) { - file.printf(" \"human\","); - } - if (mf.Flags & MapFieldLandAllowed) { - file.printf(" \"land\","); - } - if (mf.Flags & MapFieldCoastAllowed) { - file.printf(" \"coast\","); - } - if (mf.Flags & MapFieldWaterAllowed) { - file.printf(" \"water\","); - } - if (mf.Flags & MapFieldNoBuilding) { - file.printf(" \"mud\","); - } - if (mf.Flags & MapFieldUnpassable) { - file.printf(" \"block\","); - } - if (mf.Flags & MapFieldWall) { - file.printf(" \"wall\","); - } - if (mf.Flags & MapFieldRocks) { - file.printf(" \"rock\","); - } - if (mf.Flags & MapFieldForest) { - file.printf(" \"wood\","); - } -#if 1 - // Not Required for save - // These are required for now, UnitType::FieldFlags is 0 until - // UpdateStats is called which is after the game is loaded - if (mf.Flags & MapFieldLandUnit) { - file.printf(" \"ground\","); - } - if (mf.Flags & MapFieldAirUnit) { - file.printf(" \"air\","); - } - if (mf.Flags & MapFieldSeaUnit) { - file.printf(" \"sea\","); - } - if (mf.Flags & MapFieldBuilding) { - file.printf(" \"building\","); - } -#endif + mf.Save(file); if (w & 1) { - file.printf("},\n"); + file.printf(",\n"); } else { - file.printf("}, "); + file.printf(", "); } } }