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