Changeset 590 for trunk/GameServer.pas
- Timestamp:
- Jul 24, 2024, 10:25:56 PM (4 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GameServer.pas
r589 r590 8 8 uses 9 9 Protocol, Database, DynLibs, Platform, DateUtils, LazFileUtils, Brain, Global, 10 Map, 10 11 {$IFDEF DPI}Graphics{$ELSE}Graphics{$ENDIF}; 11 12 … … 73 74 function LoadGame(const FileName: string; Turn: Integer; 74 75 MovieMode: Boolean): Boolean; 75 procedure EditMap(const Map: string; Newlx, Newly, NewLandMass: Integer);76 procedure EditMap(const AMapFileName: string; Newlx, Newly, NewLandMass: Integer); 76 77 procedure DirectHelp(Command: Integer); 77 78 function ToAutoSaveFileName(FileName: string): string; … … 80 81 procedure ChangeClient; 81 82 procedure NextPlayer; 82 function PreviewMap( lm: Integer): Pointer;83 function PreviewMap(ALandMass: Integer): Pointer; 83 84 84 85 … … 283 284 end; 284 285 285 function PreviewMap( lm: Integer): Pointer;286 function PreviewMap(ALandMass: Integer): Pointer; 286 287 begin 287 288 lx := lxmax; 288 289 ly := lymax; 289 290 MapSize := lx * ly; 290 LandMass := lm;291 LandMass := ALandMass; 291 292 DelphiRandSeed := PreviewRND; 292 293 if not PreviewElevation then … … 563 564 end; 564 565 565 procedure SaveMap(FileName: string);566 var567 I: Integer;568 MapFile: TFileStream;569 S: string[255];570 begin571 MapFile := TFileStream.Create(FileName, fmCreate or fmShareExclusive);572 try573 MapFile.Position := 0;574 S := 'cEvoMap'#0;575 MapFile.Write(S[1], 8); { file id }576 I := 0;577 MapFile.Write(I, 4); { format id }578 MapFile.Write(MaxTurn, 4);579 MapFile.Write(lx, 4);580 MapFile.Write(ly, 4);581 MapFile.Write(RealMap, MapSize * 4);582 finally583 FreeAndNil(MapFile);584 end;585 end;586 587 function LoadMap(FileName: string): Boolean;588 var589 I, Loc1: Integer;590 MapFile: TFileStream;591 S: string[255];592 begin593 Result := False;594 if not FileExists(FileName) then Exit;595 MapFile := TFileStream.Create(FileName, fmOpenRead or fmShareExclusive);596 try597 MapFile.Position := 0;598 MapFile.Read(S[1], 8); { file id }599 MapFile.Read(I, 4); { format id }600 if I = 0 then601 begin602 MapFile.Read(I, 4); // MaxTurn603 MapFile.Read(lx, 4);604 MapFile.Read(ly, 4);605 ly := ly and not 1;606 if lx > lxmax then607 lx := lxmax;608 if ly > lymax then609 ly := lymax;610 MapSize := lx * ly;611 MapFile.Read(RealMap, MapSize * 4);612 for Loc1 := 0 to MapSize - 1 do613 begin614 RealMap[Loc1] := RealMap[Loc1] and615 ($7F01FFFF or fPrefStartPos or fStartPos) or ($F shl 27);616 if RealMap[Loc1] and (fTerrain or fSpecial) = fSwamp or fSpecial2 then617 RealMap[Loc1] := RealMap[Loc1] and not (fTerrain or fSpecial) or618 (fSwamp or fSpecial1);619 if (RealMap[Loc1] and fDeadLands <> 0) and620 (RealMap[Loc1] and fTerrain <> fArctic) then621 RealMap[Loc1] := RealMap[Loc1] and not (fTerrain or fSpecial)622 or fDesert;623 end;624 Result := True;625 end;626 finally627 FreeAndNil(MapFile);628 end;629 end;630 631 566 procedure SaveGame(FileName: string; Auto: Boolean); 632 567 var … … 717 652 BrainUsed: Set of 0 .. 254; { used brains } 718 653 AIBrains: TBrains; 654 Map: TMap; 719 655 begin 720 656 for p1 := 0 to nPl - 1 do begin … … 865 801 else 866 802 begin // predefined map 867 if Mode = moPlaying then 868 LoadMap(MapFileName); // new game -- load map from file 803 if Mode = moPlaying then begin 804 Map := TMap.Create; 805 Map.LoadFromFile(MapFileName); // new game -- load map from file 806 MapSize := Map.MapSize; 807 lx := Map.Size.X; 808 ly := Map.Size.Y; 809 Move(Map.Tiles[0], RealMap, MapSize * 4); 810 FreeAndNil(Map); 811 end; 869 812 GetMem(MapField, MapSize * 4); 870 813 Move(RealMap, MapField^, MapSize * 4); … … 1419 1362 end; 1420 1363 1421 procedure EditMap(const Map: string; Newlx, Newly, NewLandMass: Integer);1364 procedure EditMap(const AMapFileName: string; Newlx, Newly, NewLandMass: Integer); 1422 1365 var 1423 1366 p1, Loc1: Integer; 1424 1367 Game: TNewGameData; 1368 Map: TMap; 1425 1369 begin 1426 1370 Notify(ntStartDone); 1427 1371 Notify(ntInitLocalHuman); 1428 MapFileName := Map;1372 MapFileName := AMapFileName; 1429 1373 lx := Newlx; 1430 1374 ly := Newly; … … 1438 1382 GAlive := 0; 1439 1383 GWatching := 1; 1440 if not LoadMap(MapFileName) then 1441 for Loc1 := 0 to MapSize - 1 do 1442 RealMap[Loc1] := fOcean or ($F shl 27); 1384 for Loc1 := 0 to MapSize - 1 do 1385 RealMap[Loc1] := fOcean or ($F shl 27); 1386 if FileExists(MapFileName) then begin 1387 Map := TMap.Create; 1388 Map.LoadFromFile(MapFileName); 1389 MapSize := Map.MapSize; 1390 lx := Map.Size.X; 1391 ly := Map.Size.Y; 1392 Move(Map.Tiles[0], RealMap, MapSize * 4); 1393 FreeAndNil(Map); 1394 end; 1443 1395 CL := nil; 1444 1396 InitMapEditor; … … 2720 2672 ShowNegoData: TShowNegoData; 2721 2673 Logged, Ok, HasShipChanged, AllHumansDead, OfferFullySupported: Boolean; 2674 Map: TMap; 2722 2675 begin 2723 2676 if Command = sTurn then … … 3295 3248 if Player = 0 then 3296 3249 begin 3297 if Command = sSaveMap then 3298 SaveMap(MapFileName); 3250 if Command = sSaveMap then begin 3251 Map := TMap.Create; 3252 Map.Size := Point(lx, ly); 3253 Map.MaxTurn := MaxTurn; 3254 Move(RealMap, Map.Tiles[0], MapSize * 4); 3255 Map.SaveToFile(MapFileName); 3256 FreeAndNil(Map); 3257 end; 3299 3258 Notify(ntBackOn); 3300 3259 BrainTerm.Client(cBreakGame, -1, nil^);
Note:
See TracChangeset
for help on using the changeset viewer.