diff options
-rw-r--r-- | projects/openttd_vs100.vcxproj | 1 | ||||
-rw-r--r-- | projects/openttd_vs100.vcxproj.filters | 3 | ||||
-rw-r--r-- | projects/openttd_vs80.vcproj | 4 | ||||
-rw-r--r-- | projects/openttd_vs90.vcproj | 4 | ||||
-rw-r--r-- | source.list | 1 | ||||
-rw-r--r-- | src/economy.cpp | 2 | ||||
-rw-r--r-- | src/saveload/cargomonitor_sl.cpp | 103 | ||||
-rw-r--r-- | src/saveload/saveload.cpp | 2 |
8 files changed, 120 insertions, 0 deletions
diff --git a/projects/openttd_vs100.vcxproj b/projects/openttd_vs100.vcxproj index b1a2ad606..be141188b 100644 --- a/projects/openttd_vs100.vcxproj +++ b/projects/openttd_vs100.vcxproj @@ -790,6 +790,7 @@ <ClCompile Include="..\src\saveload\airport_sl.cpp" /> <ClCompile Include="..\src\saveload\animated_tile_sl.cpp" /> <ClCompile Include="..\src\saveload\autoreplace_sl.cpp" /> + <ClCompile Include="..\src\saveload\cargomonitor_sl.cpp" /> <ClCompile Include="..\src\saveload\cargopacket_sl.cpp" /> <ClCompile Include="..\src\saveload\cheat_sl.cpp" /> <ClCompile Include="..\src\saveload\company_sl.cpp" /> diff --git a/projects/openttd_vs100.vcxproj.filters b/projects/openttd_vs100.vcxproj.filters index c799129ec..d4d45663f 100644 --- a/projects/openttd_vs100.vcxproj.filters +++ b/projects/openttd_vs100.vcxproj.filters @@ -1599,6 +1599,9 @@ <ClCompile Include="..\src\saveload\autoreplace_sl.cpp"> <Filter>Save/Load handlers</Filter> </ClCompile> + <ClCompile Include="..\src\saveload\cargomonitor_sl.cpp"> + <Filter>Save/Load handlers</Filter> + </ClCompile> <ClCompile Include="..\src\saveload\cargopacket_sl.cpp"> <Filter>Save/Load handlers</Filter> </ClCompile> diff --git a/projects/openttd_vs80.vcproj b/projects/openttd_vs80.vcproj index 59917d8a3..b1418f265 100644 --- a/projects/openttd_vs80.vcproj +++ b/projects/openttd_vs80.vcproj @@ -2455,6 +2455,10 @@ > </File> <File + RelativePath=".\..\src\saveload\cargomonitor_sl.cpp" + > + </File> + <File RelativePath=".\..\src\saveload\cargopacket_sl.cpp" > </File> diff --git a/projects/openttd_vs90.vcproj b/projects/openttd_vs90.vcproj index 1dde4fa36..455a1dac0 100644 --- a/projects/openttd_vs90.vcproj +++ b/projects/openttd_vs90.vcproj @@ -2452,6 +2452,10 @@ > </File> <File + RelativePath=".\..\src\saveload\cargomonitor_sl.cpp" + > + </File> + <File RelativePath=".\..\src\saveload\cargopacket_sl.cpp" > </File> diff --git a/source.list b/source.list index 2ab418ed7..ec4794a07 100644 --- a/source.list +++ b/source.list @@ -548,6 +548,7 @@ saveload/ai_sl.cpp saveload/airport_sl.cpp saveload/animated_tile_sl.cpp saveload/autoreplace_sl.cpp +saveload/cargomonitor_sl.cpp saveload/cargopacket_sl.cpp saveload/cheat_sl.cpp saveload/company_sl.cpp diff --git a/src/economy.cpp b/src/economy.cpp index 1e140008a..e4eb25e23 100644 --- a/src/economy.cpp +++ b/src/economy.cpp @@ -863,6 +863,8 @@ void StartupEconomy() void InitializeEconomy() { _economy.inflation_prices = _economy.inflation_payment = 1 << 16; + ClearCargoPickupMonitoring(); + ClearCargoDeliveryMonitoring(); } /** diff --git a/src/saveload/cargomonitor_sl.cpp b/src/saveload/cargomonitor_sl.cpp new file mode 100644 index 000000000..2188470a2 --- /dev/null +++ b/src/saveload/cargomonitor_sl.cpp @@ -0,0 +1,103 @@ +/* $Id$ */ + +/* + * This file is part of OpenTTD. + * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. + * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>. + */ + +/** @file cargomonitor_sl.cpp Code handling saving and loading of Cargo monitoring. */ + +#include "../stdafx.h" +#include "../cargomonitor.h" + +#include "saveload.h" + +/** Temporary storage of cargo monitoring data for loading or saving it. */ +struct TempStorage { + CargoMonitorID number; + uint32 amount; +}; + +/** Description of the #TempStorage structure for the purpose of load and save. */ +static const SaveLoad _cargomonitor_pair_desc[] = { + SLE_VAR(TempStorage, number, SLE_UINT32), + SLE_VAR(TempStorage, amount, SLE_UINT32), + SLE_END() +}; + +/** Save the #_cargo_deliveries monitoring map. */ +static void SaveDelivery() +{ + TempStorage storage; + + int i = 0; + CargoMonitorMap::const_iterator iter = _cargo_deliveries.begin(); + while (iter != _cargo_deliveries.end()) { + storage.number = iter->first; + storage.amount = iter->second; + + SlSetArrayIndex(i); + SlObject(&storage, _cargomonitor_pair_desc); + + i++; + iter++; + } +} + +/** Load the #_cargo_deliveries monitoring map. */ +static void LoadDelivery() +{ + TempStorage storage; + + ClearCargoDeliveryMonitoring(); + for (;;) { + if (SlIterateArray() < 0) break; + SlObject(&storage, _cargomonitor_pair_desc); + + std::pair<CargoMonitorID, uint32> p(storage.number, storage.amount); + _cargo_deliveries.insert(p); + } +} + + +/** Save the #_cargo_pickups monitoring map. */ +static void SavePickup() +{ + TempStorage storage; + + int i = 0; + CargoMonitorMap::const_iterator iter = _cargo_pickups.begin(); + while (iter != _cargo_pickups.end()) { + storage.number = iter->first; + storage.amount = iter->second; + + SlSetArrayIndex(i); + SlObject(&storage, _cargomonitor_pair_desc); + + i++; + iter++; + } +} + +/** Load the #_cargo_pickups monitoring map. */ +static void LoadPickup() +{ + TempStorage storage; + + ClearCargoPickupMonitoring(); + for (;;) { + if (SlIterateArray() < 0) break; + SlObject(&storage, _cargomonitor_pair_desc); + + std::pair<CargoMonitorID, uint32> p(storage.number, storage.amount); + _cargo_pickups.insert(p); + } +} + +/** Chunk definition of the cargomonitoring maps. */ +extern const ChunkHandler _cargomonitor_chunk_handlers[] = { + { 'CMDL', SaveDelivery, LoadDelivery, NULL, NULL, CH_ARRAY}, + { 'CMPU', SavePickup, LoadPickup, NULL, NULL, CH_ARRAY | CH_LAST}, +}; diff --git a/src/saveload/saveload.cpp b/src/saveload/saveload.cpp index f9e569680..7cc1da4ed 100644 --- a/src/saveload/saveload.cpp +++ b/src/saveload/saveload.cpp @@ -409,6 +409,7 @@ extern const ChunkHandler _station_chunk_handlers[]; extern const ChunkHandler _industry_chunk_handlers[]; extern const ChunkHandler _economy_chunk_handlers[]; extern const ChunkHandler _subsidy_chunk_handlers[]; +extern const ChunkHandler _cargomonitor_chunk_handlers[]; extern const ChunkHandler _goal_chunk_handlers[]; extern const ChunkHandler _ai_chunk_handlers[]; extern const ChunkHandler _game_chunk_handlers[]; @@ -437,6 +438,7 @@ static const ChunkHandler * const _chunk_handlers[] = { _industry_chunk_handlers, _economy_chunk_handlers, _subsidy_chunk_handlers, + _cargomonitor_chunk_handlers, _goal_chunk_handlers, _engine_chunk_handlers, _town_chunk_handlers, |