- Timestamp:
- Mar 22, 2021, 9:53:40 PM (4 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Integrated.lpi
r317 r320 95 95 </Item2> 96 96 </RequiredPackages> 97 <Units Count="4 2">97 <Units Count="43"> 98 98 <Unit0> 99 99 <Filename Value="Integrated.lpr"/> … … 336 336 <IsPartOfProject Value="True"/> 337 337 </Unit41> 338 <Unit42> 339 <Filename Value="UMiniMap.pas"/> 340 <IsPartOfProject Value="True"/> 341 </Unit42> 338 342 </Units> 339 343 </ProjectOptions> -
trunk/Start.pas
r318 r320 7 7 GameServer, Messg, ButtonBase, ButtonA, ButtonC, ButtonB, Area, Types, 8 8 LCLIntf, LCLType, SysUtils, Classes, Graphics, Controls, Forms, StdCtrls, 9 Menus, Registry, DrawDlg, fgl, Protocol;9 Menus, Registry, DrawDlg, fgl, Protocol, UMiniMap; 10 10 11 11 type … … 34 34 TMainAction = (maConfig, maManual, maCredits, maAIDev, maWeb, maNone); 35 35 TMainActionSet = set of TMainAction; 36 37 TMapArray = array[0 .. lxmax * lymax - 1] of Byte;38 39 TMiniMode = (mmNone, mmPicture, mmMultiPlayer);40 41 { TMiniMap }42 43 TMiniMap = class44 const45 MaxWidthMapLogo = 96;46 MaxHeightMapLogo = 96;47 var48 Bitmap: TBitmap; { game world sample preview }49 Size: TPoint;50 Colors: array [0 .. 11, 0 .. 1] of TColor;51 Mode: TMiniMode;52 procedure LoadFromLogFile(FileName: string; var LastTurn: Integer);53 procedure LoadFromMapFile(FileName: string; var nMapLandTiles, nMapStartPositions: Integer);54 procedure PaintRandom(Brightness, StartLandMass, WorldSize: Integer);55 procedure PaintFile(SaveMap: TMapArray);56 constructor Create;57 destructor Destroy; override;58 end;59 36 60 37 { TStartDlg } … … 166 143 167 144 uses 168 Global, Directories, Direct, ScreenTools, Inp, Back, Settings , UPixelPointer;145 Global, Directories, Direct, ScreenTools, Inp, Back, Settings; 169 146 170 147 {$R *.lfm} … … 225 202 PlayerAutoDiff: array [1 .. 5] of integer = (1, 1, 2, 2, 3); 226 203 EnemyAutoDiff: array [1 .. 5] of integer = (4, 3, 2, 1, 1); 227 228 { TMiniMap }229 230 constructor TMiniMap.Create;231 var232 X, Y: Integer;233 begin234 Bitmap := TBitmap.Create;235 236 for X := 0 to 11 do237 for Y := 0 to 1 do238 Colors[x, y] := HGrSystem.Data.Canvas.Pixels[66 + x, 67 + y];239 end;240 241 destructor TMiniMap.Destroy;242 begin243 FreeAndNil(Bitmap);244 inherited;245 end;246 247 procedure TMiniMap.LoadFromLogFile(FileName: string; var LastTurn: Integer);248 var249 SaveMap: TMapArray;250 y: Integer;251 Dummy: Integer;252 FileLandMass: integer;253 LogFile: file;254 s: string[255];255 MapRow: array [0 .. lxmax - 1] of Cardinal;256 begin257 AssignFile(LogFile, FileName);258 try259 Reset(LogFile, 4);260 BlockRead(LogFile, s[1], 2); { file id }261 BlockRead(LogFile, Dummy, 1); { format id }262 if Dummy >= $000E01 then263 BlockRead(LogFile, Dummy, 1); { item stored since 0.14.1 }264 BlockRead(LogFile, Size.X, 1);265 BlockRead(LogFile, Size.Y, 1);266 BlockRead(LogFile, FileLandMass, 1);267 if FileLandMass = 0 then268 for y := 0 to Size.Y - 1 do269 BlockRead(LogFile, MapRow, Size.X);270 BlockRead(LogFile, Dummy, 1);271 BlockRead(LogFile, Dummy, 1);272 BlockRead(LogFile, LastTurn, 1);273 BlockRead(LogFile, SaveMap, 1);274 if SaveMap[0] = $80 then275 Mode := mmMultiPlayer276 else277 Mode := mmPicture;278 if Mode = mmPicture then279 BlockRead(LogFile, SaveMap[4], (Size.X * Size.Y - 1) div 4);280 CloseFile(LogFile);281 except282 CloseFile(LogFile);283 LastTurn := 0;284 Size := WorldSizes[DefaultWorldSize];285 Mode := mmNone;286 end;287 PaintFile(SaveMap);288 end;289 290 procedure TMiniMap.LoadFromMapFile(FileName: string; var nMapLandTiles, nMapStartPositions: Integer);291 var292 x, y, lxFile, lyFile: integer;293 MapFile: file;294 s: string[255];295 MapRow: array [0 .. lxmax - 1] of Cardinal;296 ImageFileName: string;297 begin298 ImageFileName := Copy(FileName, 1, Length(FileName) - Length(CevoMapExt)) + '.png';299 Mode := mmPicture;300 if LoadGraphicFile(Bitmap, ImageFileName, [gfNoError]) then301 begin302 if Bitmap.width div 2 > MaxWidthMapLogo then303 Bitmap.width := MaxWidthMapLogo * 2;304 if Bitmap.height > MaxHeightMapLogo then305 Bitmap.height := MaxHeightMapLogo;306 Size.X := Bitmap.width div 2;307 Size.Y := Bitmap.height;308 end309 else310 begin311 Mode := mmNone;312 Size.X := MaxWidthMapLogo;313 Size.Y := MaxHeightMapLogo;314 end;315 316 AssignFile(MapFile, FileName);317 try318 Reset(MapFile, 4);319 BlockRead(MapFile, s[1], 2); { file id }320 BlockRead(MapFile, x, 1); { format id }321 BlockRead(MapFile, x, 1); // MaxTurn322 BlockRead(MapFile, lxFile, 1);323 BlockRead(MapFile, lyFile, 1);324 nMapLandTiles := 0;325 nMapStartPositions := 0;326 for y := 0 to lyFile - 1 do begin327 BlockRead(MapFile, MapRow, lxFile);328 for x := 0 to lxFile - 1 do329 begin330 if (MapRow[x] and fTerrain) in [fGrass, fPrairie, fTundra, fSwamp,331 fForest, fHills] then332 inc(nMapLandTiles);333 if MapRow[x] and (fPrefStartPos or fStartPos) <> 0 then334 inc(nMapStartPositions);335 end336 end;337 if nMapStartPositions > nPl then338 nMapStartPositions := nPl;339 CloseFile(MapFile);340 except341 CloseFile(MapFile);342 end;343 end;344 345 procedure TMiniMap.PaintRandom(Brightness, StartLandMass, WorldSize: Integer);346 var347 i, x, y, xm, cm: Integer;348 MiniPixel: TPixelPointer;349 Map: ^TTileList;350 begin351 Map := PreviewMap(StartLandMass);352 Size := WorldSizes[WorldSize];353 354 Bitmap.PixelFormat := pf24bit;355 Bitmap.SetSize(Size.X * 2, Size.Y);356 Bitmap.BeginUpdate;357 MiniPixel := PixelPointer(Bitmap);358 for y := 0 to ScaleToNative(Size.Y) - 1 do begin359 for x := 0 to ScaleToNative(Size.X) - 1 do begin360 for i := 0 to 1 do begin361 xm := (x * 2 + i + y and 1) mod (ScaleToNative(Size.X) * 2);362 MiniPixel.SetX(xm);363 cm := Colors364 [Map[ScaleFromNative(x) * lxmax div Size.X + lxmax *365 ((ScaleFromNative(y) * (lymax - 1) + Size.Y div 2) div (Size.Y - 1))] and366 fTerrain, i];367 MiniPixel.Pixel^.B := ((cm shr 16) and $FF) * Brightness div 3;368 MiniPixel.Pixel^.G := ((cm shr 8) and $FF) * Brightness div 3;369 MiniPixel.Pixel^.R := ((cm shr 0) and $FF) * Brightness div 3;370 end;371 end;372 MiniPixel.NextLine;373 end;374 Bitmap.EndUpdate;375 end;376 377 procedure TMiniMap.PaintFile(SaveMap: TMapArray);378 var379 i, x, y, xm, cm, Tile, OwnColor, EnemyColor: integer;380 MiniPixel: TPixelPointer;381 PrevMiniPixel: TPixelPointer;382 begin383 OwnColor := HGrSystem.Data.Canvas.Pixels[95, 67];384 EnemyColor := HGrSystem.Data.Canvas.Pixels[96, 67];385 Bitmap.PixelFormat := pf24bit;386 Bitmap.SetSize(Size.X * 2, Size.Y);387 if Mode = mmPicture then begin388 Bitmap.BeginUpdate;389 MiniPixel := PixelPointer(Bitmap);390 PrevMiniPixel := PixelPointer(Bitmap, 0, -1);391 for y := 0 to ScaleToNative(Size.Y) - 1 do begin392 for x := 0 to ScaleToNative(Size.X) - 1 do begin393 for i := 0 to 1 do begin394 xm := (x * 2 + i + y and 1) mod (ScaleToNative(Size.X) * 2);395 MiniPixel.SetX(xm);396 Tile := SaveMap[ScaleFromNative(x) + Size.X * ScaleFromNative(y)];397 if Tile and fTerrain = fUNKNOWN then398 cm := $000000399 else if Tile and smCity <> 0 then400 begin401 if Tile and smOwned <> 0 then402 cm := OwnColor403 else404 cm := EnemyColor;405 if y > 0 then begin406 // 2x2 city dot covers two lines407 PrevMiniPixel.SetX(xm);408 PrevMiniPixel.Pixel^.B := cm shr 16;409 PrevMiniPixel.Pixel^.G:= cm shr 8 and $FF;410 PrevMiniPixel.Pixel^.R := cm and $FF;411 end;412 end413 else if (i = 0) and (Tile and smUnit <> 0) then414 if Tile and smOwned <> 0 then415 cm := OwnColor416 else cm := EnemyColor417 else418 cm := Colors[Tile and fTerrain, i];419 MiniPixel.Pixel^.B := (cm shr 16) and $ff;420 MiniPixel.Pixel^.G := (cm shr 8) and $ff;421 MiniPixel.Pixel^.R := (cm shr 0) and $ff;422 end;423 end;424 MiniPixel.NextLine;425 PrevMiniPixel.NextLine;426 end;427 Bitmap.EndUpdate;428 end;429 end;430 204 431 205 { TStartDlg } … … 1261 1035 pgStartRandom: begin 1262 1036 MiniMap.Mode := mmPicture; 1263 MiniMap.PaintRandom(3, StartLandMass, WorldSize );1037 MiniMap.PaintRandom(3, StartLandMass, WorldSizes[WorldSize]); 1264 1038 end; 1265 1039 pgNoLoad: begin … … 1269 1043 pgLoad: begin 1270 1044 MiniMap.LoadFromLogFile(GetSavedDir + DirectorySeparator + 1271 List.Items[List.ItemIndex] + CevoExt, LastTurn );1045 List.Items[List.ItemIndex] + CevoExt, LastTurn, WorldSizes[DefaultWorldSize]); 1272 1046 // BookDate:=DateToStr(FileDateToDateTime(FileAge(FileName))); 1273 1047 if not TurnValid then begin … … 1281 1055 MapFileName := ''; 1282 1056 MiniMap.Mode := mmPicture; 1283 MiniMap.PaintRandom(4, StartLandMass, WorldSize );1057 MiniMap.PaintRandom(4, StartLandMass, WorldSizes[WorldSize]); 1284 1058 end; 1285 1059 pgStartMap, pgEditMap:
Note:
See TracChangeset
for help on using the changeset viewer.