Maintain a circular buffer of recent commands, add to crashlog.
[openttd-joker.git] / src / saveload / plans_sl.cpp
blob3a8a84d6ffbcfb07e50a24a8550afaa669da74c6
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 plans_sl.cpp Code handling saving and loading of plans data. */
12 #include "../stdafx.h"
13 #include "../plans_base.h"
14 #include "../fios.h"
16 #include "saveload.h"
18 /** Description of a plan within the savegame. */
19 static const SaveLoad _plan_desc[] = {
20 SLE_VAR(Plan, owner, SLE_UINT8),
21 SLE_VAR(Plan, visible, SLE_BOOL),
22 SLE_VAR(Plan, visible_by_all, SLE_BOOL),
23 SLE_VAR(Plan, creation_date, SLE_INT32),
24 SLE_END()
27 /** Save all plans. */
28 static void Save_PLAN()
30 Plan *p;
31 FOR_ALL_PLANS(p) {
32 SlSetArrayIndex(p->index);
33 SlObject(p, _plan_desc);
37 /** Load all plans. */
38 static void Load_PLAN()
40 int index;
41 while ((index = SlIterateArray()) != -1) {
42 Plan *p = new (index)Plan();
43 SlObject(p, _plan_desc);
47 /** Save all plan lines. */
48 static void Save_PLANLINE()
50 Plan *p;
51 FOR_ALL_PLANS(p) {
52 for (size_t i = 0; i < p->lines.size(); i++) {
53 SlSetArrayIndex((uint)p->index << 16 | (uint)i);
54 PlanLine *pl = p->lines[i];
55 size_t plsz = pl->tiles.size();
56 SlSetLength(plsz * sizeof(TileIndex));
57 SlArray(&pl->tiles[0], plsz, SLE_UINT32);
62 /** Load all plan lines. */
63 static void Load_PLANLINE()
65 int index;
66 while ((index = SlIterateArray()) != -1) {
67 Plan *p = Plan::Get((uint)index >> 16);
68 uint line_index = index & 0xFFFF;
69 if (p->lines.size() <= line_index) p->lines.resize(line_index + 1);
70 PlanLine *pl = new PlanLine();
71 p->lines[line_index] = pl;
72 size_t plsz = SlGetFieldLength() / sizeof(TileIndex);
73 pl->tiles.resize(plsz);
74 SlArray(&pl->tiles[0], plsz, SLE_UINT32);
77 Plan *p;
78 FOR_ALL_PLANS(p) {
79 p->SetVisibility(false);
83 /** Chunk handlers related to plans. */
84 extern const ChunkHandler _plan_chunk_handlers[] = {
85 { 'PLAN', Save_PLAN, Load_PLAN, NULL, NULL, CH_ARRAY },
86 { 'PLLN', Save_PLANLINE, Load_PLANLINE, NULL, NULL, CH_ARRAY | CH_LAST },