rnd-20100317-1-src
[rocksndiamonds.git] / src / game_sp / init.c
1
2 #include "main_sp.h"
3 #include "global.h"
4
5
6 Bitmap *screenBitmap;
7
8 struct EngineSnapshotInfo_SP engine_snapshot_sp;
9
10 void sp_open_all()
11 {
12   Form_Load();
13
14   screenBitmap = CreateBitmap(MAX_BUF_XSIZE * TILEX, MAX_BUF_YSIZE * TILEY,
15                               DEFAULT_DEPTH);
16 }
17
18 void sp_close_all()
19 {
20 }
21
22 unsigned int InitEngineRandom_SP(long seed)
23 {
24   if (seed == NEW_RANDOMIZE)
25   {
26     subRandomize();
27
28     seed = (long)RandomSeed;
29   }
30
31   RandomSeed = (short)seed;
32
33   return (unsigned int) seed;
34 }
35
36
37 /* ------------------------------------------------------------------------- */
38 /* Supaplex game engine snapshot handling functions                          */
39 /* ------------------------------------------------------------------------- */
40
41 void SaveEngineSnapshotValues_SP()
42 {
43   int i;
44
45   engine_snapshot_sp.game_sp = game_sp;
46
47   /* these arrays have playfield-size dependent variable size */
48
49   for (i = 0; i < FieldWidth * FieldHeight + HeaderSize; i++)
50     engine_snapshot_sp.PlayField16[i] = PlayField16[i];
51   for (i = 0; i < FieldWidth * FieldHeight + HeaderSize; i++)
52     engine_snapshot_sp.PlayField8[i] = PlayField8[i];
53   for (i = 0; i < FieldWidth * FieldHeight + HeaderSize; i++)
54     engine_snapshot_sp.DisPlayField[i] = DisPlayField[i];
55
56   for (i = 0; i < FieldWidth * (FieldHeight - 2); i++)
57     engine_snapshot_sp.AnimationPosTable[i] = AnimationPosTable[i];
58   for (i = 0; i < FieldWidth * (FieldHeight - 2); i++)
59     engine_snapshot_sp.AnimationSubTable[i] = AnimationSubTable[i];
60   for (i = 0; i < FieldWidth * FieldHeight + HeaderSize; i++)
61     engine_snapshot_sp.TerminalState[i] = TerminalState[i];
62
63   /* store special data into engine snapshot buffers */
64
65   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(FieldWidth));
66   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(FieldHeight));
67   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(FieldMax));
68   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(LevelMax));
69   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(FileMax));
70
71   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(TimerVar));
72   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(RandomSeed));
73
74   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(TerminalMaxCycles));
75
76   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(mScrollX));
77   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(mScrollY));
78   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(mScrollX_last));
79   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(mScrollY_last));
80
81   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(ScreenScrollXPos));
82   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(ScreenScrollYPos));
83   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(DisplayMinX));
84   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(DisplayMinY));
85   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(DisplayMaxX));
86   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(DisplayMaxY));
87
88   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(InfotronsNeeded));
89   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(KillMurphyFlag));
90   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(MurphyMoveCounter));
91   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(MurphyExplodePos));
92   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(SplitMoveFlag));
93   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(RedDiskReleaseMurphyPos));
94   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(MurphyPosIndex));
95   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(MurphyXPos));
96   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(MurphyYPos));
97   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(MurphyScreenXPos));
98   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(MurphyScreenYPos));
99   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(MurphyVarFaceLeft));
100   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(RedDiskCount));
101   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(RedDiskReleaseFlag));
102   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(MovingPictureSequencePhase));
103   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(RedDiskReleasePhase));
104   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(ScratchGravity));
105   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(GravityFlag));
106   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(SnikSnaksElectronsFrozen));
107   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(YellowDisksExploded));
108   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(YawnSleepCounter));
109
110   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(LeadOutCounter));
111
112   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(GfxElementLast));
113   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(GfxGraphicLast));
114   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(GfxGraphic));
115   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(GfxFrame));
116
117   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(ScrollMinX));
118   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(ScrollMinY));
119   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(ScrollMaxX));
120   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(ScrollMaxY));
121   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(ScrollX));
122   SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(ScrollY));
123
124   SaveEngineSnapshotBuffer(&PlayField16[-game_sp.preceding_buffer_size],
125                            game_sp.preceding_buffer_size * sizeof(int));
126 }
127
128 void LoadEngineSnapshotValues_SP()
129 {
130   int i;
131
132   /* stored engine snapshot buffers already restored at this point */
133
134   game_sp = engine_snapshot_sp.game_sp;
135
136   /* these arrays have playfield-size dependent variable size */
137
138   for (i = 0; i < FieldWidth * FieldHeight + HeaderSize; i++)
139     PlayField16[i] = engine_snapshot_sp.PlayField16[i];
140   for (i = 0; i < FieldWidth * FieldHeight + HeaderSize; i++)
141     PlayField8[i] = engine_snapshot_sp.PlayField8[i];
142   for (i = 0; i < FieldWidth * FieldHeight + HeaderSize; i++)
143     DisPlayField[i] = engine_snapshot_sp.DisPlayField[i];
144
145   for (i = 0; i < FieldWidth * (FieldHeight - 2); i++)
146     AnimationPosTable[i] = engine_snapshot_sp.AnimationPosTable[i];
147   for (i = 0; i < FieldWidth * (FieldHeight - 2); i++)
148     AnimationSubTable[i] = engine_snapshot_sp.AnimationSubTable[i];
149   for (i = 0; i < FieldWidth * FieldHeight + HeaderSize; i++)
150     TerminalState[i] = engine_snapshot_sp.TerminalState[i];
151
152   RedrawPlayfield_SP(TRUE);
153 }