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

📄 isoengine.pas

📁 类似文明的游戏源代码。
💻 PAS
📖 第 1 页 / 共 3 页
字号:
  // paint railroad connections
  if (Tile and fRR<>0) and (RRConn=0) then TSprite(x,y,90)
  else if RRConn>0 then
    for Dir:=0 to 7 do if (1 shl Dir) and RRConn<>0 then TSprite(x,y,91+Dir);
  if (Tile and fCanal<>0) or (Tile and fCity<>0) then
    begin // paint canal connections
    Conn:=Connection8(Loc,fCanal or fCity);
    if Tile and fCanal<>0 then Conn:=Conn or ($FF-OceanConnection(Loc));
    if Conn=0 then
      if Tile and fCanal<>0 then TSprite(x,y,99)
    else else for Dir:=0 to 7 do if (1 shl Dir) and Conn<>0 then
      TSprite(x,y,100+Dir);
    end;
  end;

// normal border
if (Loc>=0) and (Loc<G.lx*G.ly) and (Loc>=2*G.lx) then
  begin
  Border:=false;
  p1:=-1;
  for dy:=-2 to 0 do for dx:=-1 to 1 do if (dx+dy) and 1=0 then
    begin
    Loc1:=dLoc(Loc,dx,dy);
    if (Loc1>=0) and (Loc1<G.lx*G.ly) and (MyMap[Loc1] and fTerrain<>fUNKNOWN)
      and (MyMap[Loc1] and fTerrain>=fGrass)
      and (MyMap[Loc1] and MyMap[Loc] and fObserved<>0) then
      begin
      p2:=MyMap[Loc1] shr 27;
//      if p2=me then p2:=15;
      if p1<0 then p1:=p2
      else if p1<>p2 then Border:=true
      end;
    end;
  if Border then Sprite(HGrSystem,x+28,y-6,8,8,66,58);
  end;

// prominent border
if ShowBorder and (Loc>=0) and (Loc<G.lx*G.ly)
  and (Tile and fTerrain<>fUNKNOWN) then
  begin
  p1:=MyMap[Loc] shr 27;
  if (p1<nPl) and (ShowMyBorder or (p1<>me)) then
    begin
    if BordersOK and (1 shl p1)=0 then
      begin
      Windows.BitBlt(Borders.Canvas.Handle,0,p1*32,64,32,
        GrExt[HGrTerrain].Data.Canvas.Handle,521,529,SRCCOPY);
      for dy:=0 to 31 do
        begin
        Line:=Borders.ScanLine[p1*32+dy];
        for dx:=0 to 63 do if Line[dx,0]<>0 then
          begin
          Line[dx,0]:=Tribe[p1].Color shr 16 and $FF;
          Line[dx,1]:=Tribe[p1].Color shr 8 and $FF;
          Line[dx,2]:=Tribe[p1].Color and $FF;
          end
        end;
      BordersOK:=BordersOK or 1 shl p1;
      end;
    for dy:=0 to 1 do for dx:=0 to 1 do
      begin
      Loc1:=dLoc(Loc,dx*2-1,dy*2-1);
        begin
        if (Loc1<0) or (Loc1>=G.lx*G.ly) then p2:=nPl
        else if (MyMap[Loc1] and fTerrain=fUNKNOWN)
          or (MyRO.BorderHelper<>nil)
          and (MyRO.BorderHelper[Loc] and (1 shl (dy*2+dx))=0)
          and (MyRO.MapObservedLast[Loc1]<>MyRO.MapObservedLast[Loc]) then
          p2:=p1
        else p2:=MyMap[Loc1] shr 27;
        if p2<>p1 then
          begin
          BitBlt(GrExt[HGrTerrain].Mask,x+dx*32,y+dy*16,32,16,521+dx*32,529+dy*16,SRCAND);
          BitBlt(Borders,x+dx*32,y+dy*16,32,16,dx*32,p1*32+dy*16,SRCPAINT);
          end
        end;
      end
    end
  end;

if (Loc>=0) and (Loc<G.lx*G.ly) and (Tile and fSpecial<>0) then {special ressources}
  if Tile and fTerrain<fForest then
    TSprite(x,y,Tile and fTerrain+(Tile and fSpecial shr 5)*9)
  else TSprite(x,y,8+2*9+((Tile and fTerrain-fForest)*2+Tile and fSpecial shr 5)*9);

if ShowObjects then
  begin
  if Tile and fTerImp=tiMine then TSprite(x,y,2+9*12);
  if Tile and fTerImp=tiBase then TSprite(x,y,4+9*12);
  if (Tile and fTerImp=tiFort) and (Tile and fObserved=0) then TSprite(x,y,3+9*12);
  if Tile and fPoll<>0 then TSprite(x,y,6+9*12);
  end;
if Tile and fRare<>0 then TSprite(x,y,(12+Tile shr 25 and 3)*9+8);

if ClientMode=cEditMap then
  fog:= (Loc<0) or (Loc>=G.lx*G.ly)
else if CityLoc>=0 then
  fog:= (Loc<0) or (Loc>=G.lx*G.ly) or (Distance(Loc,CityLoc)>5)
else if ShowGrWall then fog:= Tile and fGrWall=0
else fog:=FoW and (Tile and fObserved=0);
if fog and ShowObjects then TSprite(x,y,6+9*15);

if ClientMode=cEditMap then
  begin
  if Tile and fPrefStartPos<>0 then TSprite(x,y,0+9*1)
  else if Tile and fStartPos<>0 then TSprite(x,y,0+9*2);
  end
else if ShowObjects then
  begin
{  if (CityLoc<0) and (UnFocus>=0) and (Loc=MyUn[UnFocus].Loc) then
    if BlinkOn then TSprite(x,y,8+9*0)
    else TSprite(x,y,8+9*1);}

  NameCity;
  if Tile and fCity<>0 then
    PaintCity(x,y,CityInfo,CityOwner<0);

  if (Tile and fUnit<>0) and (Loc<>AttLoc)
    and ((Loc<>DefLoc) or (DefHealth<>0))
    and ((CityOwner>=0) or (UnFocus<0) or BlinkON or (Loc<>MyUn[UnFocus].Loc))
    and ((Tile and (fCity or fOwned)<>fCity or fOwned)
      or BlinkON and (UnFocus>=0) and (Loc=MyUn[UnFocus].Loc)) then
    begin {unit}
    GetUnitInfo(Loc,uix,UnitInfo);
    if (Loc=DefLoc) and (DefHealth>=0) then
      UnitInfo.Health:=DefHealth;
    if UnitInfo.Owner<>CityOwner then
      if (UnFocus>=0) and (Loc=MyUn[UnFocus].Loc) then {active unit}
        begin
        Multi:=UnitInfo.Flags and unMulti;
        MakeUnitInfo(me,MyUn[UnFocus],UnitInfo);
        UnitInfo.Flags:=UnitInfo.Flags or Multi;
        PaintUnit(x,y-16,UnitInfo,MyUn[UnFocus].Status);
        end
      else if UnitInfo.Owner=me then
        begin
        PaintUnit(x,y-16,UnitInfo,MyUn[uix].Status);
  //      if Showuix then Textout(x+16,y+5,$80FF00,IntToStr(uix));
        end
      else PaintUnit(x,y-16,UnitInfo,0);
    end
  else if Tile and fHiddenUnit<>0 then TSprite(x,y,4+9*15)
  else if Tile and fStealthUnit<>0 then TSprite(x,y-16,5+9*15);
  end;

if ShowObjects and (Tile and fTerImp=tiFort) and (Tile and fObserved<>0) then
  TSprite(x,y,3+9*12);

if ShowLoc then Textout(x+16,y,$80FF00,IntToStr(Loc))
else if ShowDebug and (DebugMap<>nil)
  and (Loc>=0) and (Loc<G.lx*G.ly) and (DebugMap[Loc]<>0) then
  if DebugMap[Loc]=$FFFFFFFF then Textout(x+16,y,$80FF00,'FF')
  else Textout(x+16,y,$80FF00,IntToStr(DebugMap[Loc]))
end;{PaintTileObjects}

procedure TIsoMap.PaintGrid(x,y,nx,ny: integer);

  procedure ClippedLine(dx0,dy0: integer; mirror: boolean);
  var
  x0,x1,dxmin,dymin,dxmax,dymax,n: integer;
  begin
  with FOutput.Canvas do
    begin
    if FBounds then // clip!
      begin
      dxmin:=(FLeft-x) div 33;
      dymin:=(FTop-y) div 16;
      dxmax:=(FRight-x-1) div 33+1;
      dymax:=(FBottom-y-1) div 16+1;
      end
    else begin dxmin:=0; dymin:=0; dxmax:=nx+1; dymax:=ny+2; end;
    n:=dymax-dy0;
    if mirror then
      begin
      if dx0-dxmin<n then n:=dx0-dxmin;
      if dx0>dxmax then
        begin n:=n-(dx0-dxmax); dy0:=dy0+(dx0-dxmax); dx0:=dxmax end;
      if dy0<dymin then
        begin n:=n-(dymin-dy0); dx0:=dx0-(dymin-dy0); dy0:=dymin end;
      end
    else
      begin
      if dxmax-dx0<n then n:=dxmax-dx0;
      if dx0<dxmin then
        begin n:=n-(dxmin-dx0); dy0:=dy0+(dxmin-dx0); dx0:=dxmin end;
      if dy0<dymin then
        begin n:=n-(dymin-dy0); dx0:=dx0+(dymin-dy0); dy0:=dymin end;
      end;
    if n<=0 then exit;
    if mirror then begin x0:=x+dx0*33-1; x1:=x+(dx0-n)*33-1; end
    else begin x0:=x+dx0*33; x1:=x+(dx0+n)*33; end;
    moveto(x0,y+dy0*16);
    lineto(x1,y+(dy0+n)*16);
    end
  end;

var
i: integer;
begin
FOutput.Canvas.pen.color:=$000000; //$FF shl (8*random(3));
for i:=0 to nx div 2 do ClippedLine(i*2,0,false);
for i:=1 to (nx+1) div 2 do ClippedLine(i*2,0,true);
for i:=0 to ny div 2 do
  begin
  ClippedLine(0,2*i+2,false);
  ClippedLine(nx+1,2*i+1+nx and 1,true);
  end;
end;

procedure TIsoMap.Paint(x,y,Loc,nx,ny,CityLoc,CityOwner:integer);

  function IsShoreTile(Loc: integer):boolean;
  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);
  var
  Dir,ConnLoc: integer;
  begin
  result:=false;
  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
      result:=true
    end
  end;

var
dx,dy,ALoc,BLoc,ATer,BTer,Aix,bix:integer;
begin
Server(sGetDebugMap,me,0,DebugMap);
FoW:= MapOptionChecked and (1 shl moFoW + 1 shl moGreatWall)=1 shl moFoW;
ShowLoc:=MainScreen.mLocCodes.Checked;
ShowDebug:=MainScreen.mDebugMap.Checked;
ShowObjects:= (CityOwner>=0) or (MapOptionChecked and (1 shl moBareTerrain)=0);
ShowCityNames:= ShowObjects and (CityOwner<0) and (MapOptionChecked and (1 shl moCityNames)<>0);
ShowBorder:= (CityOwner>=0) or (MapOptionChecked and (1 shl moBorders)<>0);
ShowMyBorder:= (CityOwner<0) and (MapOptionChecked and (1 shl moBorders)<>0);
ShowGrWall:= (CityOwner<0) and (MapOptionChecked and (1 shl moGreatWall)<>0);
// Showuix:=MainScreen.mshowuix.checked;
with FOutput.Canvas do
  begin
  Brush.Color:=$000000;
  if FBounds then FillRect(Rect(FLeft,FTop,FRight,FBottom))
  else FillRect(Rect(x,y,x+nx*33+33,y+ny*16+32));
  Brush.Style:=bsClear;
  end;

for dy:=0 to ny+1 do for dx:=0 to nx do
  begin
  ALoc:=dLoc(Loc,dx-(dy+dx) and 1,dy-2);
  BLoc:=dLoc(Loc,dx-(dy+dx+1) and 1,dy-1);
  if (ALoc<0) or (ALoc>=G.lx*G.ly) then ATer:=PoleTile(ALoc) and fTerrain
  else ATer:=MyMap[ALoc] and fTerrain;
  if (BLoc<0) or (BLoc>=G.lx*G.ly) then BTer:=PoleTile(BLoc) and fTerrain
  else BTer:=MyMap[BLoc] and fTerrain;

  if (ATer<>fUNKNOWN) or (BTer<>fUNKNOWN) then
    if ((ATer<fGrass) or (ATer=fUNKNOWN)) and ((BTer<fGrass) or (BTer=fUNKNOWN)) then
      begin
      if ATer=fUNKNOWN then Aix:=0
      else if IsShoreTile(ALoc) then
        if ATer=fOcean then Aix:=-1
        else Aix:=1
      else Aix:=ATer+2;
      if BTer=fUNKNOWN then bix:=0
      else if IsShoreTile(BLoc) then
        if BTer=fOcean then bix:=-1
        else bix:=1
      else bix:=BTer+2;
      if (Aix>1) or (bix>1) then
        begin
        if aix=-1 then
          if bix=fOcean+2 then begin aix:=0; bix:=0 end
          else begin aix:=0; bix:=1 end
        else if bix=-1 then
          if aix=fOcean+2 then begin aix:=1; bix:=1 end
          else begin aix:=1; bix:=0 end;
        BitBlt(OceanPatch,x+dx*33,y+dy*16,33,16,
          Aix*66+(dx+dy+1) and 1 *33,bix*16,SRCCOPY)
        end
      end
    else
      begin
      if ATer=fUNKNOWN then Aix:=0
      else if ATer=fOcean then Aix:=-1
      else if ATer=fShore then Aix:=1
      else if ATer>=fForest then Aix:=8
      else Aix:=ATer;
      if BTer=fUNKNOWN then bix:=0
      else if BTer=fOcean then bix:=-1
      else if BTer=fShore then bix:=1
      else if BTer>=fForest then bix:=8
      else bix:=BTer;
      if Aix=-1 then BitBlt(GrExt[HGrTerrain].Data,x+dx*33,y+dy*16,33,16,
        390+(dx+dy+1) and 1 *33,1,SRCCOPY)
      else if bix=-1 then BitBlt(GrExt[HGrTerrain].Data,x+dx*33,y+dy*16,33,16,
        423-(dx+dy+1) and 1 *33,17,SRCCOPY)
      else BitBlt(LandPatch,x+dx*33,y+dy*16,33,16,
        Aix*66+(dx+dy+1) and 1 *33,bix*16,SRCCOPY)
      end
  end;

OutDC:=FOutput.Canvas.Handle;
DataDC:=GrExt[HGrTerrain].Data.Canvas.Handle;
MaskDC:=GrExt[HGrTerrain].Mask.Canvas.Handle;
for dy:=-2 to ny+1 do for dx:=-1 to nx do if (dx+dy) and 1=0 then
  PaintShore(x+1+33*dx,y+16+16*dy,dLoc(Loc,dx,dy));
for dy:=-2 to ny+1 do for dx:=-1 to nx do if (dx+dy) and 1=0 then
  PaintTileExtraTerrain(x+1+33*dx,y+16+16*dy,dLoc(Loc,dx,dy));
if (ClientMode=cEditMap) or (MapOptionChecked and (1 shl moGrid)<>0) then
  PaintGrid(x,y,nx,ny);
for dy:=-2 to ny+1 do for dx:=-2 to nx+1 do if (dx+dy) and 1=0 then
  PaintTileObjects(x+1+33*dx,y+16+16*dy,dLoc(Loc,dx,dy),CityLoc,CityOwner);

//frame(FOutput.Canvas,x+1,y+1,x+nx*33+33-2,y+ny*16+32-2,$FFFF,$FFFF);
end; {Paint}

procedure TIsoMap.AttackBegin(const ShowMove: TShowMove);
begin
AttLoc:=ShowMove.FromLoc;
DefLoc:=dLoc(AttLoc,ShowMove.dx,ShowMove.dy);
DefHealth:=-1;
end;

procedure TIsoMap.AttackEffect(const ShowMove: TShowMove);
begin
DefHealth:=ShowMove.EndHealthDef;
end;

procedure TIsoMap.AttackEnd;
begin
AttLoc:=-1;
DefLoc:=-1;
end;

end.

⌨️ 快捷键说明

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