| 1 |
// ____ _ __ |
| 2 |
// / __ )____ _____ | | / /___ ___________ |
| 3 |
// / __ / __ \/ ___/ | | /| / / __ `/ ___/ ___/ |
| 4 |
// / /_/ / /_/ (__ ) | |/ |/ / /_/ / / (__ ) |
| 5 |
// /_____/\____/____/ |__/|__/\__,_/_/ /____/ |
| 6 |
// |
| 7 |
// A futuristic real-time strategy game. |
| 8 |
// This file is part of Bos Wars. |
| 9 |
// |
| 10 |
/**@name map_save.cpp - Saving the map. */ |
| 11 |
// |
| 12 |
// (c) Copyright 2001-2007 by Lutz Sammer and Jimmy Salmon |
| 13 |
// |
| 14 |
// This program is free software; you can redistribute it and/or modify |
| 15 |
// it under the terms of the GNU General Public License as published by |
| 16 |
// the Free Software Foundation; only version 2 of the License. |
| 17 |
// |
| 18 |
// This program is distributed in the hope that it will be useful, |
| 19 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 21 |
// GNU General Public License for more details. |
| 22 |
// |
| 23 |
// You should have received a copy of the GNU General Public License |
| 24 |
// along with this program; if not, write to the Free Software |
| 25 |
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
| 26 |
// 02111-1307, USA. |
| 27 |
// |
| 28 |
|
| 29 |
//@{ |
| 30 |
|
| 31 |
/*---------------------------------------------------------------------------- |
| 32 |
-- Includes |
| 33 |
----------------------------------------------------------------------------*/ |
| 34 |
|
| 35 |
#include "stratagus.h" |
| 36 |
#include "map.h" |
| 37 |
#include "patch_manager.h" |
| 38 |
#include "iolib.h" |
| 39 |
#include "version.h" |
| 40 |
|
| 41 |
/*---------------------------------------------------------------------------- |
| 42 |
-- Variables |
| 43 |
----------------------------------------------------------------------------*/ |
| 44 |
|
| 45 |
/*---------------------------------------------------------------------------- |
| 46 |
-- Functions |
| 47 |
----------------------------------------------------------------------------*/ |
| 48 |
|
| 49 |
/** |
| 50 |
** Save the complete map. |
| 51 |
** |
| 52 |
** @param file Output file. |
| 53 |
*/ |
| 54 |
void CMap::Save(CFile *file) const |
| 55 |
{ |
| 56 |
file->printf("\n--- -----------------------------------------\n"); |
| 57 |
file->printf("--- MODULE: map\n\n"); |
| 58 |
|
| 59 |
file->printf("StratagusMap(\n"); |
| 60 |
|
| 61 |
file->printf(" \"version\", \"" StratagusFormatString "\",\n", |
| 62 |
StratagusFormatArgs(StratagusVersion)); |
| 63 |
file->printf(" \"description\", \"%s\",\n", this->Info.Description.c_str()); |
| 64 |
|
| 65 |
file->printf(" \"the-map\", {\n"); |
| 66 |
|
| 67 |
file->printf(" \"size\", {%d, %d},\n", this->Info.MapWidth, this->Info.MapHeight); |
| 68 |
file->printf(" \"%s\",\n", this->NoFogOfWar ? "no-fog-of-war" : "fog-of-war"); |
| 69 |
file->printf(" \"filename\", \"%s\",\n", this->Info.Filename.c_str()); |
| 70 |
|
| 71 |
file->printf(" \"map-fields\", {\n"); |
| 72 |
for (int h = 0; h < this->Info.MapHeight; ++h) { |
| 73 |
file->printf(" -- %d\n", h); |
| 74 |
for (int w = 0; w < this->Info.MapWidth; ++w) { |
| 75 |
CMapField* mf; |
| 76 |
|
| 77 |
mf = this->Field(w, h); |
| 78 |
file->printf(" {"); |
| 79 |
for (int i = 0; i < PlayerMax; ++i) { |
| 80 |
if (mf->Visible[i] == 1) { |
| 81 |
file->printf(" \"explored\", %d,", i); |
| 82 |
} |
| 83 |
} |
| 84 |
if (mf->Flags & MapFieldLandAllowed) { |
| 85 |
file->printf(" \"land\","); |
| 86 |
} |
| 87 |
if (mf->Flags & MapFieldCoastAllowed) { |
| 88 |
file->printf(" \"coast\","); |
| 89 |
} |
| 90 |
if (mf->Flags & MapFieldShallowWater) { |
| 91 |
file->printf(" \"pond\","); |
| 92 |
} |
| 93 |
if (mf->Flags & MapFieldDeepWater) { |
| 94 |
file->printf(" \"water\","); |
| 95 |
} |
| 96 |
if (mf->Flags & MapFieldNoBuilding) { |
| 97 |
file->printf(" \"mud\","); |
| 98 |
} |
| 99 |
if (mf->Flags & MapFieldUnpassable) { |
| 100 |
file->printf(" \"block\","); |
| 101 |
} |
| 102 |
#if 1 |
| 103 |
// Not Required for save |
| 104 |
// These are required for now, UnitType::FieldFlags is 0 until |
| 105 |
// UpdateStats is called which is after the game is loaded |
| 106 |
if (mf->Flags & MapFieldLandUnit) { |
| 107 |
file->printf(" \"ground\","); |
| 108 |
} |
| 109 |
if (mf->Flags & MapFieldAirUnit) { |
| 110 |
file->printf(" \"air\","); |
| 111 |
} |
| 112 |
if (mf->Flags & MapFieldSeaUnit) { |
| 113 |
file->printf(" \"sea\","); |
| 114 |
} |
| 115 |
if (mf->Flags & MapFieldBuilding) { |
| 116 |
file->printf(" \"building\","); |
| 117 |
} |
| 118 |
#endif |
| 119 |
if (w & 1) { |
| 120 |
file->printf("},\n"); |
| 121 |
} else { |
| 122 |
file->printf("}, "); |
| 123 |
} |
| 124 |
} |
| 125 |
} |
| 126 |
file->printf("}})\n"); |
| 127 |
} |
| 128 |
|
| 129 |
//@} |