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