Subversion Repositories spacemission

Rev

Rev 28 | Rev 31 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 28 Rev 30
Line 145... Line 145...
145
  i, j: integer;
145
  i, j: integer;
146
  temp: string;
146
  temp: string;
147
  m: array[1..6] of tstrings;
147
  m: array[1..6] of tstrings;
148
  tmpX, tmpY, tmpLifes: integer;
148
  tmpX, tmpY, tmpLifes: integer;
149
  tmpEnemy: TEnemyType;
149
  tmpEnemy: TEnemyType;
-
 
150
  tmpRest: string;
150
begin
151
begin
151
  Clear;
152
  Clear;
152
 
153
 
153
  sl := TStringList.Create;
154
  sl := TStringList.Create;
154
  try
155
  try
155
    if EndsText('A1.lev', filename) then
156
    if EndsText('A1.lev', filename) then
156
    begin
157
    begin
157
      {$REGION 'Backwards compatibility level format 0.2 (split into 5-6 files)'}
158
      {$REGION 'Backwards compatibility level format 0.2 (split into 5-6 files; convert to 0.3)'}
158
      m[1] := TStringList.create;
159
      m[1] := TStringList.create;
159
      m[2] := TStringList.create;
160
      m[2] := TStringList.create;
160
      m[3] := TStringList.create;
161
      m[3] := TStringList.create;
161
      m[4] := TStringList.create;
162
      m[4] := TStringList.create;
162
      m[5] := TStringList.create;
163
      m[5] := TStringList.create;
Line 212... Line 213...
212
      sl.LoadFromFile(filename);
213
      sl.LoadFromFile(filename);
213
    end;
214
    end;
214
 
215
 
215
    if sl.Strings[0] = '; SpaceMission 0.3' then
216
    if sl.Strings[0] = '; SpaceMission 0.3' then
216
    begin
217
    begin
217
      {$REGION 'Backwards compatibility level format 0.3'}
218
      {$REGION 'Backwards compatibility level format 0.3 (convert to 0.4)'}
218
      sl.Strings[0] := '; SpaceMission 0.4';
219
      sl.Strings[0] := '; SpaceMission 0.4';
219
      sl.Insert(1, '; SAV-File');
220
      sl.Insert(1, '; LEV-File');
220
      {$ENDREGION}
221
      {$ENDREGION}
221
    end;
222
    end;
222
 
223
 
223
    if sl.Strings[0] = '; SpaceMission 0.4' then
224
    if (sl.Strings[0] = '; SpaceMission 0.4') and
-
 
225
       (sl.Strings[1] = '; LEV-File') then
224
    begin
226
    begin
225
      {$REGION 'Backwards compatibility level format 0.4'}
227
      {$REGION 'Backwards compatibility level format 0.4 (convert to 1.0)'}
226
      sl2 := TStringList.Create;
228
      sl2 := TStringList.Create;
227
      try
229
      try
228
        z := 0;
230
        z := 0;
229
        act := 0;
231
        act := 0;
230
        while z < sl.Count do
232
        while z < sl.Count do
Line 257... Line 259...
257
        FreeAndNil(sl2);
259
        FreeAndNil(sl2);
258
      end;
260
      end;
259
      {$ENDREGION}
261
      {$ENDREGION}
260
    end;
262
    end;
261
 
263
 
262
    if sl.Strings[0] = '; SpaceMission 1.0' then
264
    if (sl.Strings[0] = '; SpaceMission 1.0') and
-
 
265
       (sl.Strings[1] = '; LEV-File') then
263
    begin
266
    begin
264
      {$REGION 'Level format 1.0'}
267
      {$REGION 'Level format 1.0'}
265
      if sl.Strings[1]  <> '; LEV-File' then
-
 
266
      begin
-
 
267
        raise Exception.Create('Dies ist keine SpaceMission Level-Datei');
-
 
268
      end;
-
 
269
 
-
 
270
      LevelEditorLength := StrToInt(sl.Strings[2]);
268
      LevelEditorLength := StrToInt(sl.Strings[2]);
271
 
-
 
272
      curline := 3;
269
      curline := 3;
273
      while curline < sl.Count do
270
      while curline < sl.Count do
274
      begin
271
      begin
275
        tmpEnemy := TEnemyType(strtoint(sl.Strings[curline]));
272
        tmpEnemy := TEnemyType(strtoint(sl.Strings[curline]));
276
        Inc(curline);
273
        Inc(curline);
Line 282... Line 279...
282
        Inc(curline);
279
        Inc(curline);
283
        AddEnemy(tmpX, tmpY, tmpEnemy, tmpLifes);
280
        AddEnemy(tmpX, tmpY, tmpEnemy, tmpLifes);
284
      end;
281
      end;
285
      {$ENDREGION}
282
      {$ENDREGION}
286
    end
283
    end
-
 
284
    else if (sl.Strings[0] = '[SpaceMission Level, Format 1.2]') then
-
 
285
    begin
-
 
286
      {$REGION 'Level format 1.2'}
-
 
287
      LevelEditorLength := DefaultLevelLength;
-
 
288
      for curline := 1 to sl.Count-1 do
-
 
289
      begin
-
 
290
        // 1234567890123456789012345678901234567890
-
 
291
        // 123456 123456 123456 123456 123456 ; Kommentar
-
 
292
        if (sl.Strings[curline].Trim = '') or
-
 
293
           (Copy(sl.Strings[curline], 1, 1) = ';') then
-
 
294
          // Do nothing
-
 
295
        else if Copy(sl.Strings[curline], 1, 6).TrimRight = 'Width' then
-
 
296
        begin
-
 
297
          LevelEditorLength := StrToInt(TrimRight(Copy(sl.Strings[curline], 8, 6)))
-
 
298
        end
-
 
299
        else if Copy(sl.Strings[curline], 1, 6).TrimRight = 'Enemy' then
-
 
300
        begin
-
 
301
          tmpEnemy := TEnemyType(strtoint(TrimRight(Copy(sl.Strings[curline], 8, 6))));
-
 
302
          tmpX     := strtoint(TrimRight(Copy(sl.Strings[curline], 15, 6)));
-
 
303
          tmpY     := strtoint(TrimRight(Copy(sl.Strings[curline], 22, 6)));
-
 
304
          tmpLifes := strtoint(TrimRight(Copy(sl.Strings[curline], 29, 6)));
-
 
305
          tmpRest  := Copy(sl.Strings[curline], 36, Length(sl.Strings[curline])-36+1);
-
 
306
          if (Copy(tmpRest, 1, 1) <> ';') and (Trim(tmpRest) <> '') then
-
 
307
            raise Exception.CreateFmt('Zeile %d ist ungültig (Zusatzinfo am Ende)', [curline+1]);
-
 
308
          AddEnemy(tmpX, tmpY, tmpEnemy, tmpLifes);
-
 
309
        end
-
 
310
        else
-
 
311
        begin
-
 
312
          raise Exception.CreateFmt('Zeile %d ist ungültig (Unbekannter Zeilentyp)', [curline+1]);
-
 
313
        end;
-
 
314
      end;
-
 
315
      {$ENDREGION}
-
 
316
    end
287
    else
317
    else
288
    begin
318
    begin
289
      raise Exception.CreateFmt('Level-Format "%s" nicht unterstützt', [Copy(ergebnis, 3, Length(ergebnis)-2)]);
319
      raise Exception.Create('Level-Format nicht unterstützt oder Datei ist beschädigt');
290
    end;
320
    end;
291
  finally
321
  finally
292
    FreeAndNil(sl);
322
    FreeAndNil(sl);
293
  end;
323
  end;
294
  SortEnemies;
324
  SortEnemies; // Sortierung nach X-Koordinate ist sehr wichtig für das Spiel!
295
end;
325
end;
296
 
326
 
297
procedure TLevelData.Save(filename: string);
327
procedure TLevelData.Save(filename: string);
298
var
328
var
299
  sl: TStringList;
329
  sl: TStringList;
300
  i: integer;
330
  i: integer;
301
begin
331
begin
302
  sl := TStringList.Create;
332
  sl := TStringList.Create;
303
  try
333
  try
304
    sl.Add('; SpaceMission 1.0');
334
    sl.Add('[SpaceMission Level, Format 1.2]');
305
    sl.Add('; LEV-File');
335
    sl.Add(
-
 
336
      'Width'.PadRight(6, ' ')+
-
 
337
      ' '+
306
    sl.Add(IntToStr(LevelEditorLength));
338
      IntToStr(LevelEditorLength)+
-
 
339
      ' '
-
 
340
    );
307
    SortEnemies;
341
    SortEnemies;
308
    for i := 0 to Length(EnemyAdventTable)-1 do
342
    for i := 0 to Length(EnemyAdventTable)-1 do
309
    begin
343
    begin
-
 
344
      sl.Add(
-
 
345
        'Enemy'.PadRight(6, ' ')+
-
 
346
        ' '+
310
      sl.Add(IntToStr(Ord(EnemyAdventTable[i].enemyType)));
347
        IntToStr(Ord(EnemyAdventTable[i].enemyType)).PadRight(6, ' ')+
-
 
348
        ' '+
311
      sl.Add(IntToStr(EnemyAdventTable[i].x));
349
        IntToStr(EnemyAdventTable[i].x).PadRight(6, ' ')+
-
 
350
        ' '+
312
      sl.Add(IntToStr(EnemyAdventTable[i].y));
351
        IntToStr(EnemyAdventTable[i].y).PadRight(6, ' ')+
-
 
352
        ' '+
313
      sl.Add(IntToStr(EnemyAdventTable[i].lifes));
353
        IntToStr(EnemyAdventTable[i].lifes).PadRight(6, ' ')+
-
 
354
        ' '
-
 
355
      );
314
    end;
356
    end;
315
    sl.SaveToFile(filename);
357
    sl.SaveToFile(filename);
316
  finally
358
  finally
317
    FreeAndNil(sl);
359
    FreeAndNil(sl);
318
  end;
360
  end;