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