(svn r28004) -Update from Eints:
[openttd.git] / src / saveload / cargomonitor_sl.cpp
blob98ad95f090f6b781d78719420acff9383872c896
1 /* $Id$ */
3 /*
4 * This file is part of OpenTTD.
5 * 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.
6 * 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.
7 * 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/>.
8 */
10 /** @file cargomonitor_sl.cpp Code handling saving and loading of Cargo monitoring. */
12 #include "../stdafx.h"
13 #include "../cargomonitor.h"
15 #include "saveload.h"
17 #include "../safeguards.h"
19 /** Temporary storage of cargo monitoring data for loading or saving it. */
20 struct TempStorage {
21 CargoMonitorID number;
22 uint32 amount;
25 /** Description of the #TempStorage structure for the purpose of load and save. */
26 static const SaveLoad _cargomonitor_pair_desc[] = {
27 SLE_VAR(TempStorage, number, SLE_UINT32),
28 SLE_VAR(TempStorage, amount, SLE_UINT32),
29 SLE_END()
32 /** Save the #_cargo_deliveries monitoring map. */
33 static void SaveDelivery()
35 TempStorage storage;
37 int i = 0;
38 CargoMonitorMap::const_iterator iter = _cargo_deliveries.begin();
39 while (iter != _cargo_deliveries.end()) {
40 storage.number = iter->first;
41 storage.amount = iter->second;
43 SlSetArrayIndex(i);
44 SlObject(&storage, _cargomonitor_pair_desc);
46 i++;
47 iter++;
51 /** Load the #_cargo_deliveries monitoring map. */
52 static void LoadDelivery()
54 TempStorage storage;
56 ClearCargoDeliveryMonitoring();
57 for (;;) {
58 if (SlIterateArray() < 0) break;
59 SlObject(&storage, _cargomonitor_pair_desc);
61 std::pair<CargoMonitorID, uint32> p(storage.number, storage.amount);
62 _cargo_deliveries.insert(p);
67 /** Save the #_cargo_pickups monitoring map. */
68 static void SavePickup()
70 TempStorage storage;
72 int i = 0;
73 CargoMonitorMap::const_iterator iter = _cargo_pickups.begin();
74 while (iter != _cargo_pickups.end()) {
75 storage.number = iter->first;
76 storage.amount = iter->second;
78 SlSetArrayIndex(i);
79 SlObject(&storage, _cargomonitor_pair_desc);
81 i++;
82 iter++;
86 /** Load the #_cargo_pickups monitoring map. */
87 static void LoadPickup()
89 TempStorage storage;
91 ClearCargoPickupMonitoring();
92 for (;;) {
93 if (SlIterateArray() < 0) break;
94 SlObject(&storage, _cargomonitor_pair_desc);
96 std::pair<CargoMonitorID, uint32> p(storage.number, storage.amount);
97 _cargo_pickups.insert(p);
101 /** Chunk definition of the cargomonitoring maps. */
102 extern const ChunkHandler _cargomonitor_chunk_handlers[] = {
103 { 'CMDL', SaveDelivery, LoadDelivery, NULL, NULL, CH_ARRAY},
104 { 'CMPU', SavePickup, LoadPickup, NULL, NULL, CH_ARRAY | CH_LAST},