summaryrefslogtreecommitdiff
path: root/LoadBobs.c
blob: 84c8848f4367e2792b7e7972199cb376004f5408 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
#include <exec/types.h>
#include <exec/memory.h>
#include <proto/exec.h>
#include <proto/dos.h>
#include <graphics/gfx.h>
#include <string.h>

#include "Bobi.h"
#include "BobStructure.h"

extern struct MyBob		*BobTable[];
extern struct Screen	*mainscreen;

extern WORD	options,numbobs,actbobnum,firstanimbob,lastanimbob,animflags;
extern BYTE defaultorg;
extern WORD	mainpalette[];
extern char	idstring[],outputname[],sectionname[];
extern WORD	outputflags,mainx0,mainy0;
extern char	LabelGadgetSIBuff[];

extern BYTE	arexxflag;
extern char arexxfilename[];

static char BobPath[128];		/* Load / Save Bobs */
static char BobName[80];
static char InsertPath[128];	/* Insert Bobs */
static char InsertName[80];
static char OPath[128];			/* Load / Save Offsets */
static char OName[80];

char PicPath[128];				/* Benötigt von Picture.c */
char PicName[80];

/****************************************************************************
**	Konfigurations-File laden und auswerten
*/

void LoadConfigFile(char *name)
{
	char buf[500];
	register BPTR file;

	ClearMem(buf,sizeof(buf));

	if(file=Open(name,MODE_OLDFILE))
	{
		register char *sptr,*dptr;

		Read(file,buf,490);
		Close(file);

		sptr=buf;
		dptr=BobPath; while((*dptr=*sptr++)>' ') dptr++; *dptr='\0';
		dptr=PicPath; while((*dptr=*sptr++)>' ') dptr++; *dptr='\0';
		strcpy(InsertPath,BobPath);
	}
}

/****************************************************************************
**	Ein Bob aus file laden
*/

static struct MyBob *LoadOneBob(register BPTR file,register WORD version)
{
	register struct MyBob *bob;
	register long i;

	if(bob=AllocMem(sizeof(struct MyBob),MEMF_CLEAR))
	{
		Read(file,bob,sizeof(*bob));
		if(version<108)
		{
			char buf[66];
			Seek(file,-8,OFFSET_CURRENT);	/* Antiskip Collsion Coords */
			CopyMem(&bob->CollX0,buf,66);
			CopyMem(buf,&bob->PlanePick,66);
			bob->CollX0=bob->CollX1=bob->CollY0=bob->CollY1=0;
		}

		if(bob->Planes[0] = AllocMem(bob->PlaneSize*bob->Depth,0L))
		{
			for(i=1; i<bob->Depth; ++i)
				bob->Planes[i] = bob->Planes[0]+i*bob->PlaneSize;
			Read(file,bob->Planes[0],bob->PlaneSize*bob->Depth);

			bob->Mask = 0;	/* jaja! */
			return bob;
		}
		else
		{
			FreeMem(bob,sizeof(*bob));
			ShowMonoReq2("Not enough memory for bob planes!");
		}
	}
	else
	{
		ShowMonoReq2("Not enough memory for bob structure!");
	}
	return 0;
}

/****************************************************************************
**	Bobs laden
*/

void LoadBobsFunc()
{
	LockWindows();
	LoadBobs(arexxflag ? arexxfilename
		: FileRequest("Load Bobs from Disk", "LOAD", BobPath, BobName));
	UnLockWindows();
}


void LoadBobs(char *name)
{
	struct BobFileHeader bfh;
	register struct MyBob *bob;
	register BPTR file;
	register long i;
	char buf[64];

	LockWindows();

	if(name)
	{
		if(file=Open(name,MODE_OLDFILE))
		{
			Read(file,&bfh,sizeof(bfh));
			if(bfh.Magic == BF_MAGIC)
			{
				if((bfh.Version>=106) && (bfh.Version<=BF_VERSION))
				{
					if(bfh.Version < 110)
					{
						ShowMonoReq2("Warning:\nThis is an old Bobi file.\n"
								"MainOrg is not saved.");
					}

					if(bfh.Version < 109)
					{
						ShowMonoReq2("Warning:\nThis is a very old Bobi file.\n"
								"AnimKey bobs are not marked.");
					}

					if(bfh.Version < 108)
					{
						ShowMonoReq2("Warning:\nThis is a very very old Bobi file.\n"
								"Collision info is not set.");
					}

					if(bfh.Version < 107)
					{
						ShowMonoReq2("Warning:\nThis is a very very very old Bobi file!\n"
								"Bob/Sprite flags and Collision info\n"
								"may be wrong.");
						bfh.OutputFlags |= OF_GENERATEBOBS;
					}
					ClearAll();

					if(bfh.Version >= 110)
					{
						mainx0 = bfh.MainX0;
						mainy0 = bfh.MainY0;
					}

					if(bfh.Version >= 111)
					{
						defaultorg = bfh.DefaultOrg;
					}

					CopyMem(bfh.ColorTable,mainpalette,2*32);
					strcpy(outputname,bfh.OutputName);
					strcpy(sectionname,bfh.SectionName);
					SetGlobalOptions(bfh.GlobalOptions,defaultorg);
					outputflags = bfh.OutputFlags;
					strcpy(LabelGadgetSIBuff,bfh.DefaultLabel);
					firstanimbob = bfh.FirstAnimBob;
					lastanimbob  = bfh.LastAnimBob;
					SetAnimSpeed(bfh.AnimSpeed);
					SetAnimFlags(bfh.AnimFlags);

					numbobs = bfh.NumBobs;
					for(i=0; i<bfh.NumBobs; ++i)
					{
						if(bob=LoadOneBob(file,bfh.Version)) BobTable[i]=bob;
						else
						{
							numbobs = i;
							sprintf(buf,"%ld of %ld bobs loaded.",i,bfh.NumBobs);
							ShowMonoReq2(buf);
							break;
						}
					}
					RefreshBobNum();
				}
				else if(bfh.Version > BF_VERSION)
				{
					ShowMonoReq2("You need a newer Bobi version\nto handle this file!");
				}
				else ShowMonoReq2("This is a mangled or\ntoo old Bobi file!");
			}
			else
			{
				sprintf(buf,"This is not a %s file !",idstring);
				ShowMonoReq2(buf);
			}
			Close(file);
		}
		else ShowFileError(name);
	}
	UnLockWindows();
}

/****************************************************************************
**	Bobs aus File an aktueller Position einfügen
*/

void InsertBobsFunc()
{
	struct BobFileHeader bfh;
	register char *name;
	register struct MyBob *bob;
	register BPTR file;
	register long i;
	char buf[64];

	LockWindows();

	if(arexxflag)
		name = arexxfilename;
	else
		name = FileRequest("Insert Bobs from Disk", "INSERT", InsertPath, InsertName);

	if(name)
	{
		if(file=Open(name,MODE_OLDFILE))
		{
			Read(file,&bfh,sizeof(bfh));
			if(bfh.Magic == BF_MAGIC)
			{
				if((bfh.Version>=106) && (bfh.Version<=BF_VERSION))
				{
					for(i=0; i<bfh.NumBobs; ++i)
					{
						if(bob=LoadOneBob(file,bfh.Version))
						{
							InsertBob(bob,(WORD)(actbobnum+i));
						}
						else
						{
							sprintf(buf,"%ld of %ld bobs inserted.",i,bfh.NumBobs);
							ShowMonoReq2(buf);
							break;
						}
					}
					RefreshBobNum();
				}
				else if(bfh.Version > BF_VERSION)
				{
					ShowMonoReq2("You need a newer Bobi version\nto handle this file!");
				}
				else ShowMonoReq2("This is a mangled or\ntoo old Bobi file!");
			}
			else
			{
				sprintf(buf,"This is not a %s file !",idstring);
				ShowMonoReq2(buf);
			}
			Close(file);
		}
		else ShowFileError(name);
	}
	UnLockWindows();
}

/****************************************************************************
**	Bobs in eine Datei speichern
*/

void SaveBobsFunc()
{
	struct BobFileHeader bfh;
	register char *name;
	register BPTR file;
	register long i;

	ClearMem(&bfh,sizeof(bfh));
	LockWindows();

	if(arexxflag)
		name = arexxfilename;
	else
		name = FileRequest("Save Bobs to Disk", "SAVE", BobPath, BobName);

	if(name)
	{
		bfh.Magic         = BF_MAGIC;
		bfh.Version       = BF_VERSION;
		bfh.NumBobs       = numbobs;
		bfh.OutputFlags   = outputflags;
		bfh.FirstAnimBob  = firstanimbob;
		bfh.LastAnimBob   = lastanimbob;
		bfh.AnimSpeed     = GetAnimSpeed();
		bfh.AnimFlags     = animflags;
		bfh.DefaultOrg    = defaultorg;
		bfh.GlobalOptions = options;
		bfh.MainX0        = mainx0;
		bfh.MainY0        = mainy0;

		CopyMem(mainpalette,bfh.ColorTable,2*32);
		strcpy(bfh.OutputName,outputname);
		strcpy(bfh.SectionName,sectionname);
		strcpy(bfh.DefaultLabel,LabelGadgetSIBuff);

		if(file=OpenNewFileSafely(name))
		{
			Write(file,&bfh,sizeof(bfh));
			for(i=0; i<numbobs; ++i)
			{
				Write(file,BobTable[i],sizeof(struct MyBob));
				Write(file,BobTable[i]->Planes[0],BobTable[i]->PlaneSize*BobTable[i]->Depth);
			}
			Close(file);
		}
	}
	UnLockWindows();
}

/****************************************************************************
**	Eine Datei von der Disk löschen
*/

void DeleteFileFunc()
{
	register char *name;
	char buf[160];

	LockWindows();
	if (name = FileRequest("Delete File on Disk", "DELETE", BobPath, BobName))
	{
		sprintf(buf,"Do you really want to delete the\nfile '%s' ?",name);
		if(ShowRequest2(buf,"YEP!"))
		{
			if(DeleteFile(name))
			{
//				sprintf(buf,"%s%s.fd",BobPath,*BobPath?"/":"");
//				DeleteFile(buf);
			}
			else ShowFileError(name);
		}
	}
	UnLockWindows();
}

/****************************************************************************
**	Bob-Offset-Tabelle von Disk laden
*/

void LoadOffsetsFunc()
{
	register char *name;
	register BPTR file;
	register long i;

	LockWindows();
	OPath[0] = OName[0] = '\0';

	if(arexxflag)
		name = arexxfilename;
	else
		name = FileRequest("Load Bob Offsets from Disk", "LOAD", OPath, OName);

	if(name)
	{
		if(file=Open(name,MODE_OLDFILE))
		{
			for(i=0; i<numbobs; ++i)
			{
				Read(file,&BobTable[i]->X0,2);
				Read(file,&BobTable[i]->Y0,2);
			}
			Close(file);
		}
		else ShowFileError(name);
	}
	UnLockWindows();
}

/****************************************************************************
**	Bob-Offsets in Datei speichern
*/

void SaveOffsetsFunc()
{
	register char *name;
	register BPTR file;
	register long i;

	LockWindows();
	OPath[0] = OName[0] = '\0';

	if(arexxflag)
		name = arexxfilename;
	else
		name = FileRequest("Save Bob Offsets to Disk", "SAVE", OPath, OName);

	if(name)
	{
		if(file=OpenNewFileSafely(name))
		{
			for(i=0; i<numbobs; ++i)
			{
				Write(file,&BobTable[i]->X0,2);
				Write(file,&BobTable[i]->Y0,2);
//				sprintf(buf,"\t\tDC.W\t%ld,%ld\t; %s\n",
//					BobTable[i]->X0,BobTable[i]->Y0,BobTable[i]->SourceLabel);
//				Write(file,buf,strlen(buf));
			}
			Close(file);
		}
	}
	UnLockWindows();
}