unit eq2mapedfn;

interface

uses windows, graphics;

// const
const
        clr_clst = $00ff00ff;
        clr_loc  = $000808d5;
        clr_MOB  = $00ff8300;
        clr_name = $00ff0000;
        clr_NPC  = $0000ff3b;
        clr_QST  = $0000fff6;
        clr_Zone = $00bbbbbb; // differ from original
        // mapzonerect definition
        mapother : array[0..33] of string = (
        'steppes','-1530,-1170,810,1720',
        'qey_catacomb01_','-46,-261,239,68',
        'antonica_1','765,-1220,2955,1330',
        'antonica_0','-585,-1135,1635,1445',
        'commonlands_1','-260,-1090,1645,1120',
        'commonlands_0','-1620,-1090,290,1120',
        'nektulos','-1117,-2680,1780,710',
        'orcishwastes','-781,-979,605,644',
        'enchanted_0', '-751,-1279,520,209',
        'feerrott_1','721,-309,2151,1315',
        'enchanted_1','-126,-1278,1144,205',
        'lavastorm', '-425,-730,944,841',
        'fprt_sewer02_', '-20,-200,290,164',
        'feerrott_0','-299,-309,1104,1314',
        'everfrost', '-877,-1853,884,218',
        'nektropos_castle_2', '0,0,0,0',
        'enchanted_mini01', '47,-1169,144,-1057');
        pathmap = 'images\maps\';
        pathico = 'eq2map\';
        tagUTF8BOM : array[0..2] of byte = ($EF, $BB, $BF);
                                
// functions
function splitstr(src : string; delimitor : char; var right : string):string;
procedure GCorrection(sbmp : Tbitmap; ga : extended);
function encodeXML(const val : string):string;
function decodeXML(const val : string):String;
function poschrev(subch : char; source : string):integer;
//procedure SortItems(itm : tjvSimpleXMLProps);

implementation

uses sysutils;

const
        specialname : array[1..5] of string = ('&amp;','&lt;','&gt;','&quot;','&apos;');
        specialchar : array[1..5] of char = ('&','<','>','"',#39);

var     gatable : array[0..255] of byte;

// split string with ','
function splitstr(src : string; delimitor : char; var right : string):string;
var
        ix : integer;
begin
        result := ''; right := '';
        ix := pos(delimitor,src);
        if ix > 0 then begin
                result := copy(src,1,ix-1);
                right := copy(src,ix+1,length(src)-ix);
        end else Result := src;
end;

// for gamma correction
procedure makegammatable( value : extended );
var
        i : byte;
        j : integer;
        exv : extended;
begin
        if value = 1 then begin
                for i:=0 to 255 do gatable[i]:=i;
        end else begin
                gatable[0]:=0;
                for i:=1 to 255 do begin
                        exv := 255 * exp(value * ln(i/255)) + 0.5;
                        j := round(exv);
                        if j>255 then j:=255;
                        gatable[i]:= byte(255 and j);
                end;
        end;
end;

procedure GCorrection(sbmp : Tbitmap; ga : extended);
var
        i, j : integer;
        sl : pbytearray;
begin
        makegammatable(ga);
        for j:=0 to sbmp.Height-1 do begin
        sl := sbmp.ScanLine[j];
        for i:=0 to (sbmp.Width-1)*4 do sl^[i] := gatable[sl^[i]];
        end;
end;

// ===
function decodeXML(const val : string):String;
var
        i : integer;
begin
        Result := val;
        for i:=1 to 5 do
        Result := StringReplace(Result,specialname[i],specialchar[i],[rfReplaceAll, rfIgnoreCase]);
end;

function encodeXML(const val : string):string;
var
        i : integer;
begin
        Result := val;
        for i:=1 to 5 do
        Result := StringReplace(Result,specialchar[i],specialname[i],[rfReplaceAll]);
end;

{procedure SortItems(itm : tjvSimpleXMLProps);
var
        i, j : integer;
        tmp : tStringList;
begin
        tmp := TStringList.Create;
        try
                GetTagptr(itm,'IconStyle',tmp);
                GetTagptr(itm,'IconType',tmp);
                GetTagptr(itm,'Location',tmp);
                GetTagptr(itm,'Name',tmp);
                GetTagptr(itm,'OnHoverIn',tmp);
                GetTagptr(itm,'pathfindlocation',tmp);
                GetTagptr(itm,'ScrollExtent',tmp);
                GetTagptr(itm,'Size',tmp);
                GetTagptr(itm,'Tooltip',tmp);
                GetTagptr(itm,'TreatAsButton',tmp);
                itm.Clear;
                j := tmp.Count shr 1;
                for i:=0 to pred(j) do itm.Add(tmp.Strings[i*2],tmp.Strings[i*2+1]);
        finally
                tmp.free;
        end;
end;}

function poschrev(subch : char; source : string):integer;
var
        i : integer;
begin
        result := 0;
        if length(source)>0 then
        for i:=length(source) downto 1 do
                if source[i]=subch then begin result :=i; break; end;
end;

end.
