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