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