* Added CentrED+ code (thanks to StaticZ for his awesome work!)

This commit is contained in:
2015-05-01 12:23:03 +02:00
parent 2e62fd570a
commit 34637d40ce
97 changed files with 22628 additions and 4243 deletions

View File

@@ -30,23 +30,49 @@ unit UArtProvider;
interface
uses
Graphics, UMulProvider, UMulBlock, UGenericIndex, UArt, UHue;
Classes, Graphics, UMulProvider, UMulBlock, UGenericIndex, UArt, UHue, types;
type
TArtProvider = class(TIndexedMulProvider)
constructor Create(OldFormat: Boolean; AData, AIndex: TStream; AReadOnly: Boolean = False); overload;
constructor Create(OldFormat: Boolean; AData, AIndex: string; AReadOnly: Boolean = False); overload;
protected
UseOldArtFormat: Boolean;
function GetData(AID: Integer; AIndex: TGenericIndex): TMulBlock; override;
function GetArtData(AID: Integer; AIndex: TGenericIndex; AColor: Word;
AHue: THue; APartialHue: Boolean): TArt;
public
function GetArt(AID: Integer; AColor: Word; AHue: THue; APartialHue: Boolean): TArt;
function GetFlatLand(AID: Integer): TArt;
function GetArtSize(AID: Integer): TSize;
end;
implementation
uses
Logging;
{ TArtProvider }
constructor TArtProvider.Create(OldFormat: Boolean; AData, AIndex: TStream; AReadOnly: Boolean = False);
begin
inherited Create(AData, AIndex, AReadOnly);
UseOldArtFormat := OldFormat;
if UseOldArtFormat
then Logger.Send([lcInfo], 'Using pre-Alpha ArtData Format')
else Logger.Send([lcInfo], 'Using common ArtData Format');
end;
constructor TArtProvider.Create(OldFormat: Boolean; AData, AIndex: string; AReadOnly: Boolean = False);
begin
inherited Create(AData, AIndex, AReadOnly);
UseOldArtFormat := OldFormat;
if UseOldArtFormat
then Logger.Send([lcInfo], 'Using pre-Alpha ArtData Format')
else Logger.Send([lcInfo], 'Using common ArtData Format');
end;
function TArtProvider.GetData(AID: Integer; AIndex: TGenericIndex): TMulBlock;
begin
Result := GetArtData(AID, AIndex, clBlack, nil, False);
@@ -60,14 +86,14 @@ begin
if AID < $4000 then
Result := TArt.Create(FData, AIndex, atLand, AColor, AHue, APartialHue)
else
Result := TArt.Create(FData, AIndex, atStatic, AColor, AHue, APartialHue);
Result := TArt.Create(FData, AIndex, atStatic, AColor, AHue, APartialHue, UseOldArtFormat);
end
else
begin
if AID < $4000 then
Result := TArt.Create(nil, nil, atLand, AColor, AHue, APartialHue)
else
Result := TArt.Create(nil, nil, atStatic, AColor, AHue, APartialHue);
Result := TArt.Create(nil, nil, atStatic, AColor, AHue, APartialHue, UseOldArtFormat);
end;
Result.ID := AID;
end;
@@ -91,11 +117,38 @@ var
begin
FIndex.Position := CalculateIndexOffset(AID);
genericIndex := TGenericIndex.Create(FIndex);
Result := TArt.Create(FData, genericIndex, atLandFlat);
Result := TArt.Create(FData, genericIndex, atLandFlat, UseOldArtFormat);
genericIndex.Free;
Result.OnChanged := @OnChanged;
Result.OnFinished := @OnFinished;
end;
function TArtProvider.GetArtSize(AID: Integer): TSize;
var
genericIndex: TGenericIndex;
//genericBlock: TMemoryStream;
value: SmallInt;
begin
if (AID < $4000)
then Result := Size(44, 44)
else begin
FIndex.Position := CalculateIndexOffset(AID);
genericIndex := TGenericIndex.Create(FIndex);
if (genericIndex.Lookup <> -1) and (genericIndex.Size > 0) then begin
FData.Position := genericIndex.Lookup + 4;
//genericBlock := TMemoryStream.Create;
//genericBlock.CopyFrom(FData, 8);
//genericBlock.Position := 4;
FData.Read(value, SizeOf(SmallInt)); Result.cx := value;
FData.Read(value, SizeOf(SmallInt)); Result.cy := value;
//if Assigned(genericBlock) then genericBlock.Free;
end else
Result := Size(0, 0);
genericIndex.Free;
end;
end;
end.

View File

@@ -30,23 +30,50 @@ unit UTexmapProvider;
interface
uses
UMulProvider, UMulBlock, UGenericIndex, UTexture;
Classes, UMulProvider, UMulBlock, UGenericIndex, UTexture;
type
TTexmapProvider = class(TIndexedMulProvider)
constructor Create(OldFormat: Boolean; AData, AIndex: TStream; AReadOnly: Boolean = False); overload;
constructor Create(OldFormat: Boolean; AData, AIndex: string; AReadOnly: Boolean = False); overload;
protected
UseOldArtFormat: Boolean;
function GetData(AID: Integer; AIndex: TGenericIndex): TMulBlock; override;
end;
implementation
uses
Logging;
{ TTexmapProvider }
constructor TTexmapProvider.Create(OldFormat: Boolean; AData, AIndex: TStream; AReadOnly: Boolean = False);
begin
inherited Create(AData, AIndex, AReadOnly);
UseOldArtFormat := OldFormat;
if UseOldArtFormat
then Logger.Send([lcInfo], 'Using textures in ArtData')
else Logger.Send([lcInfo], 'Using textures in TexMaps');
end;
constructor TTexmapProvider.Create(OldFormat: Boolean; AData, AIndex: string; AReadOnly: Boolean = False);
begin
inherited Create(AData, AIndex, AReadOnly);
UseOldArtFormat := OldFormat;
if UseOldArtFormat
then Logger.Send([lcInfo], 'Using textures in ArtData')
else Logger.Send([lcInfo], 'Using textures in TexMaps');
end;
function TTexmapProvider.GetData(AID: Integer; AIndex: TGenericIndex): TMulBlock;
begin
if (AIndex.Lookup > -1) and (AIndex.Size > 0) then
Result := TTexture.Create(FData, AIndex)
else
if (AIndex.Lookup > -1) and (AIndex.Size > 0) then begin
//Result := TTexture.Create(FData, AIndex)
if not UseOldArtFormat
then Result := TTexture.Create(FData, AIndex)
else Result := TOldTexture.Create(Cardinal(AID));
end else
Result := TTexture.Create(-1);
Result.ID := AID;
end;

View File

@@ -39,22 +39,27 @@ type
{ TTiledataProvider }
TTiledataProvider = class(TMulProvider)
constructor Create(AData: TStream; AReadOnly: Boolean = False); overload; override;
constructor Create(AData: string; AReadOnly: Boolean = False); overload; override;
constructor Create(OldFormat: Boolean; AData: TStream; AReadOnly: Boolean = False); overload;
constructor Create(OldFormat: Boolean; AData: string; AReadOnly: Boolean = False); overload;
destructor Destroy; override;
protected
FLandTiles: TLandTileDataArray;
FEmptyLandTile: TLandTileData;
FStaticTiles: TStaticTileDataArray;
FEmptyStaticTile: TStaticTileData;
FStaticCount: Cardinal;
UseOldTileDataFormat: Boolean;
procedure InitArray;
function CalculateOffset(AID: Integer): Integer; override;
function GetData(AID, AOffset: Integer): TMulBlock; override;
procedure SetData(AID, AOffset: Integer; ABlock: TMulBlock); override;
function GetTileData(AID: Integer): TTiledata;
function GetLandTileData(AID: Integer): TLandTileData;
function GetStaticTileData(AID: Integer): TStaticTileData;
public
function GetBlock(AID: Integer): TMulBlock; override;
property LandTiles: TLandTileDataArray read FLandTiles;
property StaticTiles: TStaticTileDataArray read FStaticTiles;
property LandTiles[AID: Integer]: TLandTileData read GetLandTileData;
property StaticTiles[AID: Integer]: TStaticTileData read GetStaticTileData;
property TileData[AID: Integer]: TTiledata read GetTileData; //all tiles, no cloning
property StaticCount: Cardinal read FStaticCount;
end;
@@ -68,18 +73,26 @@ uses
function TTiledataProvider.CalculateOffset(AID: Integer): Integer;
begin
Result := GetTileDataOffset(AID);
Result := GetTileDataOffset(AID, UseOldTileDataFormat);
end;
constructor TTiledataProvider.Create(AData: TStream; AReadOnly: Boolean = False);
constructor TTiledataProvider.Create(OldFormat: Boolean; AData: TStream; AReadOnly: Boolean = False);
begin
inherited;
inherited Create(AData, AReadOnly);
UseOldTileDataFormat := OldFormat; //(FData.Size <= 1644544);
if UseOldTileDataFormat
then Logger.Send([lcInfo], 'Using Old TileData Format')
else Logger.Send([lcInfo], 'Using New TileData Format');
InitArray;
end;
constructor TTiledataProvider.Create(AData: string; AReadOnly: Boolean = False);
constructor TTiledataProvider.Create(OldFormat: Boolean; AData: string; AReadOnly: Boolean = False);
begin
inherited;
inherited Create(AData, AReadOnly);
UseOldTileDataFormat := OldFormat; //(FData.Size <= 1644544);
if UseOldTileDataFormat
then Logger.Send([lcInfo], 'Using Old TileData Format')
else Logger.Send([lcInfo], 'Using New TileData Format');
InitArray;
end;
@@ -117,23 +130,60 @@ var
begin
FData.Position := 0;
Logger.Send([lcInfo], 'Loading $4000 LandTiledata Entries');
for i := $0 to $3FFF do
begin
if i mod 32 = 0 then
FData.Seek(4, soFromCurrent);
FLandTiles[i] := TLandTileData.Create(FData);
end;
if UseOldTileDataFormat
then for i := $0 to $3FFF do
begin
if i mod 32 = 0 then
FData.Seek(4, soFromCurrent);
FLandTiles[i] := TLandOldTileData.Create(FData);
end
else for i := $0 to $3FFF do
begin
if i mod 32 = 0 then
FData.Seek(4, soFromCurrent);
FLandTiles[i] := TLandTileData.Create(FData);
end;
FStaticCount := ((FData.Size - FData.Position) div StaticTileGroupSize) * 32;
if UseOldTileDataFormat
then FStaticCount := ((FData.Size - FData.Position) div StaticOldTileGroupSize) * 32
else FStaticCount := ((FData.Size - FData.Position) div StaticTileGroupSize) * 32;
Logger.Send([lcInfo], 'Loading $%x StaticTiledata Entries', [FStaticCount]);
SetLength(FStaticTiles, FStaticCount);
for i := 0 to FStaticCount - 1 do
begin
if i mod 32 = 0 then
FData.Seek(4, soFromCurrent);
FStaticTiles[i] := TStaticTileData.Create(FData);
end;
if UseOldTileDataFormat
then for i := 0 to FStaticCount - 1 do
begin
if i mod 32 = 0 then
FData.Seek(4, soFromCurrent);
FStaticTiles[i] := TStaticOldTileData.Create(FData);
end
else for i := 0 to FStaticCount - 1 do
begin
if i mod 32 = 0 then
FData.Seek(4, soFromCurrent);
FStaticTiles[i] := TStaticTileData.Create(FData);
end;
// empty
FEmptyLandTile := FLandTiles[0].Clone;
FEmptyLandTile.Flags := [];
FEmptyLandTile.TextureID := 0;
FEmptyStaticTile := FStaticTiles[0].Clone;
FEmptyStaticTile.Flags := [];
//FEmptyStaticTile.Flags2 := 0;
FEmptyStaticTile.TileName := '!! NOT EXISTING !!';
FEmptyStaticTile.Weight := 0;
FEmptyStaticTile.Quality := 0;
FEmptyStaticTile.Unknown1 := 0;
FEmptyStaticTile.Unknown2 := 0;
FEmptyStaticTile.Quantity := 0;
FEmptyStaticTile.AnimID := 0;
FEmptyStaticTile.Unknown3 := 0;
FEmptyStaticTile.Hue := 0;
FEmptyStaticTile.Unknown4 := 0;
FEmptyStaticTile.Height := 0;
end;
procedure TTiledataProvider.SetData(AID, AOffset: Integer;
@@ -145,11 +195,15 @@ begin
if AID < $4000 then
begin
FreeAndNil(FLandTiles[AID]);
FLandTiles[AID] := TLandTileData(ABlock.Clone);
if UseOldTileDataFormat
then FLandTiles[AID] := TLandOldTileData(ABlock.Clone)
else FLandTiles[AID] := TLandTileData(ABlock.Clone);
end else
begin
FreeAndNil(FStaticTiles[AID - $4000]);
FStaticTiles[AID - $4000] := TStaticTileData(ABlock.Clone);
if UseOldTileDataFormat
then FStaticTiles[AID - $4000] := TStaticOldTileData(ABlock.Clone)
else FStaticTiles[AID - $4000] := TStaticTileData(ABlock.Clone);
end;
if not FReadOnly then
@@ -164,7 +218,23 @@ begin
if AID < $4000 then
Result := FLandTiles[AID]
else
Result := FStaticTiles[AID - $4000];
Result := StaticTiles[AID - $4000];
end;
function TTiledataProvider.GetLandTileData(AID: Integer): TLandTileData;
begin
if (AID >= 0) and (AID < $4000) then
Result := FLandTiles[AID]
else
Result := FEmptyLandTile;
end;
function TTiledataProvider.GetStaticTileData(AID: Integer): TStaticTileData;
begin
if (AID >= 0) and (AID < FStaticCount) then
Result := FStaticTiles[AID]
else
Result := FEmptyStaticTile;
end;
end.