OpenTTD
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 
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 
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 
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 
103  { 'CMDL', SaveDelivery, LoadDelivery, NULL, NULL, CH_ARRAY},
104  { 'CMPU', SavePickup, LoadPickup, NULL, NULL, CH_ARRAY | CH_LAST},
105 };
Temporary storage of cargo monitoring data for loading or saving it.
Functions/types related to saving and loading games.
static const SaveLoad _cargomonitor_pair_desc[]
Description of the TempStorage structure for the purpose of load and save.
CargoMonitorMap _cargo_deliveries
Map of monitored deliveries to the amount since last query/activation.
static void SavePickup()
Save the _cargo_pickups monitoring map.
void ClearCargoPickupMonitoring(CompanyID company)
Clear all pick-up cargo monitors.
static void SaveDelivery()
Save the _cargo_deliveries monitoring map.
int SlIterateArray()
Iterate through the elements of an array and read the whole thing.
Definition: saveload.cpp:828
void ClearCargoDeliveryMonitoring(CompanyID company)
Clear all delivery cargo monitors.
Handlers and description of chunk.
Definition: saveload.h:66
uint32 CargoMonitorID
Unique number for a company / cargo type / (town or industry).
Definition: cargomonitor.h:22
#define SLE_END()
End marker of a struct/class save or load.
Definition: saveload.h:353
CargoMonitorMap _cargo_pickups
Map of monitored pick-ups to the amount since last query/activation.
const ChunkHandler _cargomonitor_chunk_handlers[]
Chunk definition of the cargomonitoring maps.
static void LoadDelivery()
Load the _cargo_deliveries monitoring map.
void SlObject(void *object, const SaveLoad *sld)
Main SaveLoad function.
Definition: saveload.cpp:1612
SaveLoad type struct.
Definition: saveload.h:208
#define SLE_VAR(base, variable, type)
Storage of a variable in every version of a savegame.
Definition: saveload.h:296
static void LoadPickup()
Load the _cargo_pickups monitoring map.
Last chunk in this array.
Definition: saveload.h:104