# cargomonitor_sl.cpp

Go to the documentation of this file.

    00001 /* $Id$ */
    00002
    00003 /*
    00004  * This file is part of OpenTTD.
    00005  * 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.
    00006  * 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.
    00007  * 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/>.
    00008  */
    00009
    00012 #include "../stdafx.h"
    00013 #include "../cargomonitor.h"
    00014
    00015 #include "saveload.h"
    00016
    00018 struct TempStorage {
    00019   CargoMonitorID number;
    00020   uint32 amount;
    00021 };
    00022
    00024 static const SaveLoad _cargomonitor_pair_desc[] = {
    00025   SLE_VAR(TempStorage, number, SLE_UINT32),
    00026   SLE_VAR(TempStorage, amount, SLE_UINT32),
    00027   SLE_END()
    00028 };
    00029
    00031 static void SaveDelivery()
    00032 {
    00033   TempStorage storage;
    00034
    00035   int i = 0;
    00036   CargoMonitorMap::const_iterator iter = _cargo_deliveries.begin();
    00037   while (iter != _cargo_deliveries.end()) {
    00038     storage.number = iter->first;
    00039     storage.amount = iter->second;
    00040
    00041     SlSetArrayIndex(i);
    00042     SlObject(&storage, _cargomonitor_pair_desc);
    00043
    00044     i++;
    00045     iter++;
    00046   }
    00047 }
    00048
    00050 static void LoadDelivery()
    00051 {
    00052   TempStorage storage;
    00053
    00054   ClearCargoDeliveryMonitoring();
    00055   for (;;) {
    00056     if (SlIterateArray() < 0) break;
    00057     SlObject(&storage, _cargomonitor_pair_desc);
    00058
    00059     std::pair<CargoMonitorID, uint32> p(storage.number, storage.amount);
    00060     _cargo_deliveries.insert(p);
    00061   }
    00062 }
    00063
    00064
    00066 static void SavePickup()
    00067 {
    00068   TempStorage storage;
    00069
    00070   int i = 0;
    00071   CargoMonitorMap::const_iterator iter = _cargo_pickups.begin();
    00072   while (iter != _cargo_pickups.end()) {
    00073     storage.number = iter->first;
    00074     storage.amount = iter->second;
    00075
    00076     SlSetArrayIndex(i);
    00077     SlObject(&storage, _cargomonitor_pair_desc);
    00078
    00079     i++;
    00080     iter++;
    00081   }
    00082 }
    00083
    00085 static void LoadPickup()
    00086 {
    00087   TempStorage storage;
    00088
    00089   ClearCargoPickupMonitoring();
    00090   for (;;) {
    00091     if (SlIterateArray() < 0) break;
    00092     SlObject(&storage, _cargomonitor_pair_desc);
    00093
    00094     std::pair<CargoMonitorID, uint32> p(storage.number, storage.amount);
    00095     _cargo_pickups.insert(p);
    00096   }
    00097 }
    00098
    00100 extern const ChunkHandler _cargomonitor_chunk_handlers[] = {
    00101   { 'CMDL', SaveDelivery, LoadDelivery, NULL, NULL, CH_ARRAY},
    00102   { 'CMPU', SavePickup,   LoadPickup,   NULL, NULL, CH_ARRAY | CH_LAST},
    00103 };