OpenTTD: src/saveload/cargomonitor_sl.cpp Source File

OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

cargomonitor_sl.cpp
Go to the documentation of this file.
1 /* $Id: cargomonitor_sl.cpp 26482 2014-04-23 20:13:33Z rubidium $ */
2
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 */
9
12 #include "../stdafx.h"
13 #include "../cargomonitor.h"
14
15 #include "saveload.h"
16
17 #include "../safeguards.h"
18
20 struct TempStorage {
21 CargoMonitorID number;
22 uint32 amount;
23 };
24
26 static const SaveLoad _cargomonitor_pair_desc[] = {
27 SLE_VAR(TempStorage, number, SLE_UINT32),
28 SLE_VAR(TempStorage, amount, SLE_UINT32),
29 SLE_END()
30 };
31
33 static void SaveDelivery()
34 {
35 TempStorage storage;
36
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;
42
43 SlSetArrayIndex(i);
44 SlObject(&storage, _cargomonitor_pair_desc);
45
46 i++;
47 iter++;
48 }
49 }
50
52 static void LoadDelivery()
53 {
54 TempStorage storage;
55
56 ClearCargoDeliveryMonitoring();
57 for (;;) {
58 if (SlIterateArray() < 0) break;
59 SlObject(&storage, _cargomonitor_pair_desc);
60
61 std::pair<CargoMonitorID, uint32> p(storage.number, storage.amount);
62 _cargo_deliveries.insert(p);
63 }
64 }
65
66
68 static void SavePickup()
69 {
70 TempStorage storage;
71
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;
77
78 SlSetArrayIndex(i);
79 SlObject(&storage, _cargomonitor_pair_desc);
80
81 i++;
82 iter++;
83 }
84 }
85
87 static void LoadPickup()
88 {
89 TempStorage storage;
90
91 ClearCargoPickupMonitoring();
92 for (;;) {
93 if (SlIterateArray() < 0) break;
94 SlObject(&storage, _cargomonitor_pair_desc);
95
96 std::pair<CargoMonitorID, uint32> p(storage.number, storage.amount);
97 _cargo_pickups.insert(p);
98 }
99 }
100
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},
105 };