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/>.
10 /** @file cargomonitor_sl.cpp Code handling saving and loading of Cargo monitoring. */
12 #include "../stdafx.h"
13 #include "../cargomonitor.h"
17 #include "../safeguards.h"
19 /** Temporary storage of cargo monitoring data for loading or saving it. */
21 CargoMonitorID number
;
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
),
32 /** Save the #_cargo_deliveries monitoring map. */
33 static void SaveDelivery()
38 CargoMonitorMap::const_iterator iter
= _cargo_deliveries
.begin();
39 while (iter
!= _cargo_deliveries
.end()) {
40 storage
.number
= iter
->first
;
41 storage
.amount
= iter
->second
;
44 SlObject(&storage
, _cargomonitor_pair_desc
);
51 /** Load the #_cargo_deliveries monitoring map. */
52 static void LoadDelivery()
56 ClearCargoDeliveryMonitoring();
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()
73 CargoMonitorMap::const_iterator iter
= _cargo_pickups
.begin();
74 while (iter
!= _cargo_pickups
.end()) {
75 storage
.number
= iter
->first
;
76 storage
.amount
= iter
->second
;
79 SlObject(&storage
, _cargomonitor_pair_desc
);
86 /** Load the #_cargo_pickups monitoring map. */
87 static void LoadPickup()
91 ClearCargoPickupMonitoring();
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
},