⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 isoengine.pas

📁 类似文明的游戏源代码。
💻 PAS
📖 第 1 页 / 共 3 页
字号:

procedure TIsoMap.Textout(x,y,Color: integer; const s: string);
begin
FOutput.Canvas.Font.Color:=Color;
if FBounds then
  FOutput.Canvas.TextRect(Rect(FLeft,FTop,FRight,FBottom), x, y, s)
else FOutput.Canvas.Textout(x,y,s);
end;

procedure TIsoMap.BitBlt(Src: TBitmap; x,y,Width,Height,xSrc,ySrc,Rop: integer);
begin
if FBounds then
  begin
  if x<FLeft then
    begin Width:=Width-(FLeft-x); xSrc:=xSrc+(FLeft-x); x:=FLeft end;
  if y<FTop then
    begin Height:=Height-(FTop-y); ySrc:=ySrc+(FTop-y); y:=FTop end;
  if x+Width>=FRight then Width:=FRight-x;
  if y+Height>=FBottom then Height:=FBottom-y;
  if (Width<=0) or (Height<=0) then exit
  end;
Windows.BitBlt(FOutput.Canvas.Handle,x,y,Width,Height,Src.Canvas.Handle,xSrc,
  ySrc,Rop);
end;

procedure TIsoMap.Sprite(HGr,xDst,yDst,Width,Height,xGr,yGr: integer);
begin
BitBlt(GrExt[HGr].Mask,xDst,yDst,Width,Height,xGr,yGr,SRCAND);
BitBlt(GrExt[HGr].Data,xDst,yDst,Width,Height,xGr,yGr,SRCPAINT);
end;

procedure TIsoMap.TSprite(xDst,yDst,grix: integer);
var
Width, Height, xSrc, ySrc: integer;
begin
Width:=TSpriteSize[grix].Right-TSpriteSize[grix].Left;
Height:=TSpriteSize[grix].Bottom-TSpriteSize[grix].Top;
xSrc:=1+grix mod 9 *65+TSpriteSize[grix].Left;
ySrc:=1+grix div 9 *33+TSpriteSize[grix].Top;
xDst:=xDst+TSpriteSize[grix].Left;
yDst:=yDst+TSpriteSize[grix].Top;
if grix in [83,92,101] then // connect to right
  inc(Width);
if grix in [87,96,105] then // connect to left
  begin dec(xSrc); dec(xDst); inc(Width); end;
if FBounds then
  begin
  if xDst<FLeft then
    begin Width:=Width-(FLeft-xDst); xSrc:=xSrc+(FLeft-xDst); xDst:=FLeft end;
  if yDst<FTop then
    begin Height:=Height-(FTop-yDst); ySrc:=ySrc+(FTop-yDst); yDst:=FTop end;
  if xDst+Width>=FRight then Width:=FRight-xDst;
  if yDst+Height>=FBottom then Height:=FBottom-yDst;
  if (Width<=0) or (Height<=0) then exit
  end;
Windows.BitBlt(OutDC,xDst,yDst,Width,Height,MaskDC,xSrc,ySrc,SRCAND);
Windows.BitBlt(OutDC,xDst,yDst,Width,Height,DataDC,xSrc,ySrc,SRCPAINT);
end;

procedure TIsoMap.PaintUnit(x,y:integer;const UnitInfo:TUnitInfo;Status:integer);
var
xsh,ysh,xGr,yGr,j,red,green,mixShow: integer;
begin
with UnitInfo do
  begin
  if Job=jCity then mixShow:=-1 // building site
  else mixShow:=mix;
  if Tribe[Owner].ModelPicture[mixShow].HGr=0 then
    InitEnemyModel(MyRO.EnemyModel[emix],true);
  xsh:=Tribe[Owner].ModelPicture[mixShow].xShield;
  ysh:=Tribe[Owner].ModelPicture[mixShow].yShield;
  if Status and usStay<>0 then j:=19
  else if Status and usRecover<>0 then j:=16
  else if Status and (usGoto or usEnhance)=usGoto or usEnhance then j:=18
  else if Status and usEnhance<>0 then j:=17
  else if Status and usGoto<>0 then j:=20
  else if Job=jCity then j:=jNone
  else j:=Job;
  if Flags and unMulti<>0 then
    Sprite(Tribe[Owner].symHGr,x+xsh-1+4,y+ysh-2,14,12,
      33+Tribe[Owner].sympix mod 10 *65,1+Tribe[Owner].sympix div 10 *49);
  Sprite(Tribe[Owner].symHGr,x+xsh-1,y+ysh-2,14,12,
    18+Tribe[Owner].sympix mod 10 *65,1+Tribe[Owner].sympix div 10 *49);
  green:=400*Health div 100; if green>200 then green:=200;
  red:=510*(100-Health) div 100; if red>255 then red:=255;
  FillRect(x+xsh,y+ysh+5,1+Health*11 div 100,3,green shl 8 + red);
  if j>0 then
    begin
    xGr:=121+j mod 7 *9; yGr:=1+j div 7 *9;
    BitBlt(GrExt[HGrSystem].Mask,x+xsh+3,y+ysh+9,8,8,xGr,yGr,SRCAND);
    Sprite(HGrSystem,x+xsh+2,y+ysh+8,8,8,xGr,yGr);
    end;
  with Tribe[Owner].ModelPicture[mixShow] do
    Sprite(HGr,x,y,64,48,pix mod 10 *65+1,pix div 10 *49+1);
  if Flags and unFortified<>0 then TSprite(x,y+16,12*9+7);
  end
end;{PaintUnit}

procedure TIsoMap.PaintCity(x,y:integer;const CityInfo:TCityInfo; accessory: boolean);
var
cHGr,cpix,xGr,LabelTextColor: integer;
cpic:TCityPicture;
s:string;
begin
if CityInfo.Size<5 then xGr:=0
else if CityInfo.Size<9 then xGr:=1
else if CityInfo.Size<13 then xGr:=2
else xGr:=3;

Tribe[CityInfo.Owner].InitAge(GetAge(CityInfo.Owner));
cHGr:=Tribe[CityInfo.Owner].cHGr;
cpix:=Tribe[CityInfo.Owner].cpix;
cpic:=Tribe[CityInfo.Owner].CityPicture[xGr];
if (ciWalled and CityInfo.Flags=0)
  or (GrExt[cHGr].Data.Canvas.Pixels[(xGr+4)*65,cpix*49+48]=$00FFFF) then
  Sprite(cHGr,x,y-16,64,48,xGr*65+1,1+cpix*49);
if ciWalled and CityInfo.Flags<>0 then
  Sprite(cHGr,x,y-16,64,48,(xGr+4)*65+1,1+cpix*49);
if not Accessory then exit;

if ciCapital and CityInfo.Flags<>0 then
  Sprite(Tribe[CityInfo.Owner].symHGr,x+cpic.xf,y-29+cpic.yf,13,14,
    1+Tribe[CityInfo.Owner].sympix mod 10 *65,
    1+Tribe[CityInfo.Owner].sympix div 10 *49); {capital -- paint flag}
s:=IntToStr(CityInfo.Size);
FillRect(x+cpic.xShield,y-16+cpic.yShield,FOutput.Canvas.TextWidth(s)+3,16,
  $000000);
if MyMap[CityInfo.Loc] and (fUnit or fObserved)=fObserved then
  // empty city
  LabelTextColor:=Tribe[CityInfo.Owner].Color
else
  begin
  FillRect(x+cpic.xShield+1,y-15+cpic.yShield,FOutput.Canvas.TextWidth(s)+1,
    14,Tribe[CityInfo.Owner].Color);
  LabelTextColor:=$000000;
  end;
Textout(x+2+cpic.xShield,y-17+cpic.yShield,LabelTextColor,s);
end;{PaintCity}

function PoleTile(Loc: integer): integer;
begin {virtual pole tile}
result:=fUNKNOWN;
if Loc<-2*G.lx then
else if Loc<-G.lx then
  begin
  if (MyMap[dLoc(Loc,0,2)] and fTerrain<>fUNKNOWN)
    and (MyMap[dLoc(Loc,-2,2)] and fTerrain<>fUNKNOWN)
    and (MyMap[dLoc(Loc,2,2)] and fTerrain<>fUNKNOWN) then result:=fArctic;
  if (MyMap[dLoc(Loc,0,2)] and fObserved<>0)
    and (MyMap[dLoc(Loc,-2,2)] and fObserved<>0)
    and (MyMap[dLoc(Loc,2,2)] and fObserved<>0) then result:=result or fObserved
  end
else if Loc<0 then
  begin
  if (MyMap[dLoc(Loc,-1,1)] and fTerrain<>fUNKNOWN)
    and (MyMap[dLoc(Loc,1,1)] and fTerrain<>fUNKNOWN) then result:=fArctic;
  if (MyMap[dLoc(Loc,-1,1)] and fObserved<>0)
    and (MyMap[dLoc(Loc,1,1)] and fObserved<>0) then result:=result or fObserved
  end
else if Loc<G.lx*(G.ly+1) then
  begin
  if (MyMap[dLoc(Loc,-1,-1)] and fTerrain<>fUNKNOWN)
    and (MyMap[dLoc(Loc,1,-1)] and fTerrain<>fUNKNOWN) then result:=fArctic;
  if (MyMap[dLoc(Loc,-1,-1)] and fObserved<>0)
    and (MyMap[dLoc(Loc,1,-1)] and fObserved<>0) then result:=result or fObserved
  end
else if Loc<G.lx*(G.ly+2) then
  begin
  if (MyMap[dLoc(Loc,0,-2)] and fTerrain<>fUNKNOWN)
    and (MyMap[dLoc(Loc,-2,-2)] and fTerrain<>fUNKNOWN)
    and (MyMap[dLoc(Loc,2,-2)] and fTerrain<>fUNKNOWN) then result:=fArctic;
  if (MyMap[dLoc(Loc,0,-2)] and fObserved<>0)
    and (MyMap[dLoc(Loc,-2,-2)] and fObserved<>0)
    and (MyMap[dLoc(Loc,2,-2)] and fObserved<>0) then result:=result or fObserved
  end
end;

const
Dirx: array[0..7] of integer=(1,2,1,0,-1,-2,-1,0);
Diry: array[0..7] of integer=(-1,0,1,2,1,0,-1,-2);

function TIsoMap.Connection4(Loc,Mask,Value:integer):integer;
begin
result:=0;
if dLoc(Loc,1,-1)>=0 then
  begin
  if MyMap[dLoc(Loc,1,-1)] and Mask=Cardinal(Value) then inc(result,1);
  if MyMap[dLoc(Loc,-1,-1)] and Mask=Cardinal(Value) then inc(result,8);
  end;
if dLoc(Loc,1,1)<G.lx*G.ly then
  begin
  if MyMap[dLoc(Loc,1,1)] and Mask=Cardinal(Value) then inc(result,2);
  if MyMap[dLoc(Loc,-1,1)] and Mask=Cardinal(Value) then inc(result,4);
  end
end;

function TIsoMap.Connection8(Loc,Mask:integer):integer;
var
Dir, ConnLoc: integer;
begin
result:=0;
for Dir:=0 to 7 do
  begin
  ConnLoc:=dLoc(Loc,Dirx[Dir],Diry[Dir]);
  if (ConnLoc>=0) and (ConnLoc<G.lx*G.ly) and (MyMap[ConnLoc] and Mask<>0) then
    inc(result,1 shl Dir);
  end
end;

function TIsoMap.OceanConnection(Loc: integer): integer;
var
Dir,ConnLoc: integer;
begin
result:=0;
for Dir:=0 to 7 do
  begin
  ConnLoc:=dLoc(Loc,Dirx[Dir],Diry[Dir]);
  if (ConnLoc<0) or (ConnLoc>=G.lx*G.ly)
    or ((MyMap[ConnLoc]-2) and fTerrain<13) then
    inc(result,1 shl Dir);
  end
end;

procedure TIsoMap.PaintShore(x,y,Loc:integer);
var
Conn,Tile:integer;
begin
if (y<=FTop-32) or (y>FBottom) or (x<=FLeft-64) or (x>FRight) then exit;
if (Loc<0) or (Loc>=G.lx*G.ly) then exit;
Tile:=MyMap[Loc];
if Tile and fTerrain>=fGrass then exit;
Conn:=OceanConnection(Loc);
if Conn=0 then exit;

BitBlt(GrExt[HGrTerrain].Data,x+16,y,32,16,
  (Conn shr 6 +Conn and 1 shl 2)*65+1,529+Tile and fTerrain *33,SRCPAINT);
BitBlt(GrExt[HGrTerrain].Data,x+32,y+8,32,16,
  (Conn and 7)*65+1+32,529+Tile and fTerrain *33+16,SRCPAINT);
BitBlt(GrExt[HGrTerrain].Data,x+16,y+16,32,16,
  (Conn shr 2 and 7)*65+1+32,529+Tile and fTerrain *33,SRCPAINT);
BitBlt(GrExt[HGrTerrain].Data,x,y+8,32,16,
  (Conn shr 4 and 7)*65+1,529+Tile and fTerrain *33+16,SRCPAINT);
Conn:=Connection4(Loc,fTerrain,fUNKNOWN); {dither to black}
if Conn and 1<>0 then
  BitBlt(GrExt[HGrTerrain].Mask,x+32,y,32,16,456+32,496,SRCAND);
if Conn and 2<>0 then
  BitBlt(GrExt[HGrTerrain].Mask,x+32,y+16,32,16,456+32,496+16,SRCAND);
if Conn and 4<>0 then
  BitBlt(GrExt[HGrTerrain].Mask,x,y+16,32,16,456,496+16,SRCAND);
if Conn and 8<>0 then
  BitBlt(GrExt[HGrTerrain].Mask,x,y,32,16,456,496,SRCAND);
end;

procedure TIsoMap.PaintTileExtraTerrain(x,y,Loc: integer);
var
yGr,Conn,Tile:integer;
begin
if (Loc<0) or (Loc>=G.lx*G.ly) or (y<=-32) or (y>FOutput.Height) or (x<=-64)
  or (x>FOutput.Width) then exit;
Tile:=MyMap[Loc];
if Tile and fTerrain in [fForest,fHills,fMountains] then
  begin
  yGr:=3+2*(Tile and fTerrain-fForest);
  Conn:=Connection4(Loc,fTerrain,Tile and fTerrain);
  TSprite(x,y,Conn mod 8+(yGr+Conn div 8)*9);
  end
end;

procedure TIsoMap.PaintTileObjects(x,y,Loc,CityLoc,CityOwner:integer);
type
TLine=array[0..9*65,0..2] of Byte;
var
p1,p2,uix,cix,dx,dy,Loc1,Dir,Conn,RRConn,Tile,Multi:integer;
CityInfo:TCityInfo;
UnitInfo:TUnitInfo;
Line: ^TLine;
fog,Border: boolean;

  procedure NameCity;
  var
  cix,xs: integer;
  BehindCityInfo:TCityInfo;
  s: string;
  begin
  BehindCityInfo.Loc:=Loc-2*G.lx;
  if ShowCityNames and (BehindCityInfo.Loc>=0) and (BehindCityInfo.Loc<G.lx*G.ly)
    and (MyMap[BehindCityInfo.Loc] and fCity<>0) then
    begin
    GetCityInfo(BehindCityInfo.Loc,cix,BehindCityInfo);
    {if Showuix and (cix>=0) then s:=IntToStr(cix)
    else} s:=CityName(BehindCityInfo.ID);
    xs:=x+32-FOutput.Canvas.TextWidth(s) div 2;
    Textout(xs+1,y-9,$000000,s);
    Textout(xs,y-10,$FFFFFF,s);
    end;
  end;

begin
if (y<=FTop-32) or (y>FBottom) or (x<=FLeft-64) or (x>FRight) then
  begin NameCity; exit; end;
if (Loc<0) or (Loc>=G.lx*G.ly) then Tile:=PoleTile(Loc)
else Tile:=MyMap[Loc];
if Tile and fTerrain=fUNKNOWN then
  begin NameCity; exit end;{square not discovered}

if ShowObjects then
  begin
  if (ClientMode<>cEditMap) and (Tile and fCity<>0) then
    GetCityInfo(Loc,cix,CityInfo);
  if Tile and fTerImp=tiFarm then TSprite(x,y,109) {farmland}
  else if Tile and fTerImp=tiIrrigation then TSprite(x,y,108); // irrigation
  end;
if Tile and fRiver<>0 then
  begin
  Conn:=Connection4(Loc,fRiver,fRiver) or Connection4(Loc,fTerrain,fShore)
    or Connection4(Loc,fTerrain,fUNKNOWN);
  TSprite(x,y,Conn mod 8+(13+Conn div 8)*9);
  end;

if Tile and fTerrain<fGrass then
  begin
  Conn:=Connection4(Loc,fRiver,fRiver);
  for Dir:=0 to 3 do if Conn and (1 shl Dir)<>0 then {river mouths}
    TSprite(x,y,15*9+Dir);
  Conn:=Connection8(Loc,fCanal);
  for Dir:=0 to 7 do if Conn and (1 shl Dir)<>0 then {canal mouths}
    TSprite(x,y,11*9+1+Dir);
  end;

if ShowObjects then
  begin
  if Tile and (fRR or fCity)<>0 then RRConn:=Connection8(Loc,fRR or fCity)
  else RRConn:=0;
  if Tile and (fRoad or fRR or fCity)<>0 then
    begin // paint road connections
    Conn:=Connection8(Loc,fRoad or fRR or fCity) and not RRConn;
    if (Conn=0) and (Tile and (fRR or fCity)=0) then TSprite(x,y,81)
    else if Conn>0 then
      for Dir:=0 to 7 do if (1 shl Dir) and Conn<>0 then TSprite(x,y,82+Dir);
    end;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -