📄 cityscreen.pas
字号:
if (Kind=mkSettler)
{and (MyRO.Wonder[woFreeSettlers].EffectiveOwner<>me)}
or (MyUn[i].Flags and unConscripts<>0) then
for j:=0 to SettlerFood[cGov]-1 do
Sprite(offscreen,HGrSystem,x+38+11*j,ySupp+51,10,10,66,115);
mov0:=Speed;
if (Domain=dSea) and (MyRO.Wonder[woMagellan].EffectiveOwner=me) then
inc(mov0,200);
if (MyRO.Wonder[woLiberty].EffectiveOwner<>me)
or (MyMap[MyUn[i].Loc] and fCity=0) or (MyUn[i].Movement<mov0) then
begin
if (FreeSupp>0) and (Kind<>mkSpecial_TownGuard) then
begin
Sprite(offscreen,HGrSystem,x+16,ySupp+51,10,10,132,126);
dec(FreeSupp);
end
else Sprite(offscreen,HGrSystem,x+16,ySupp+51,10,10,88,115);
if Flags and mdDoubleSupport<>0 then
begin // double support unit
dec(FreeSupp);
if FreeSupp>=0 then
Sprite(offscreen,HGrSystem,x+5,ySupp+51,10,10,132,126)
else Sprite(offscreen,HGrSystem,x+5,ySupp+51,10,10,88,115);
end
end;
// deployed?
TestDeployed:=false;
if Flags and mdCivil=0 then
begin
TerrOwner:=MyMap[MyUn[i].Loc] shr 27;
case cGov of
gRepublic: TestDeployed:= (TerrOwner<>me) and (TerrOwner<nPl);
gDemocracy, gLybertarianism: TestDeployed:= TerrOwner<>me;
end;
end;
if TestDeployed then
Sprite(offscreen,HGrSystem,x+27,ySupp+51,10,10,110,126)
end // unit visible in display
else if Flags and mdDoubleSupport<>0 then dec(FreeSupp,2)
else dec(FreeSupp);
inc(Cnt);
end;
end;
with offscreen.Canvas do
begin
{display project now}
if c.Project and cpImp=0 then
with Tribe[cOwner].ModelPicture[c.Project and cpIndex] do
begin
FrameImage(offscreen.canvas,bigimp,xView+9,yView+5,xSizeBig,ySizeBig,0,0,
(cix>=0) and (ClientMode<scContact));
Sprite(offscreen,HGr,xView+5,yView+1,64,44,
pix mod 10 *65+1,pix div 10*49+1);
end
else if (cix<0) or (c.Status and 7=0) then
begin // no city type autobuild
if ProdHint then Paintiix:=c.Project0 and cpIndex
else Paintiix:=c.Project and cpIndex;
FrameImage(Offscreen.Canvas,BigImp,xView+9,yView+5,xSizeBig,ySizeBig,
Paintiix mod 7 *xSizeBig, (Paintiix+SystemIconLines*7) div 7 *ySizeBig,
(cix>=0) and (ClientMode<scContact));
end
else
begin
FrameImage(offscreen.canvas,bigimp,xView+9,yView+5,xSizeBig,ySizeBig,56,0,
(cix>=0) and (ClientMode<scContact));
Dump(offscreen,HGrSystem,xView+19,yView+15,36,20,1+(c.Status and 7-1)*37,316); // city type autobuild
end;
{display messages now}
line:=0;
for i:=0 to nCityEventPriority-1 do
CheckMessage(CityEventPriority[i]);
end;
{RFrame(offscreen.Canvas,CloseBtn.Left-1-SideFrame,CloseBtn.Top-1-WideFrame,
CloseBtn.Left+CloseBtn.Width-SideFrame,CloseBtn.Top+CloseBtn.Height-WideFrame,
InnerCityTex.clBevelShade,InnerCityTex.clBevelLight);}
SupportBtn.Visible:=(cix>=0) and (MyRO.Turn>0);
if SupportBtn.Visible then
RFrame(offscreen.Canvas,SupportBtn.Left-(SideFrame+1),SupportBtn.Top-(WideFrame+1),
SupportBtn.Left+SupportBtn.Width-SideFrame,SupportBtn.Top+SupportBtn.Height-WideFrame,
InnerCityTex.clBevelShade,InnerCityTex.clBevelLight);
BuiltBtn.Visible:=(cix>=0) and (MyRO.Turn>0);
if BuiltBtn.Visible then
RFrame(offscreen.Canvas,BuiltBtn.Left-(SideFrame+1),BuiltBtn.Top-(WideFrame+1),
BuiltBtn.Left+BuiltBtn.Width-SideFrame,BuiltBtn.Top+BuiltBtn.Height-WideFrame,
InnerCityTex.clBevelShade,InnerCityTex.clBevelLight);
if cix>=0 then
begin
i:=Server(sBuyCityProject-sExecute,me,cix,nil^);
BuyBtn.Visible:= (MyRO.Turn>0) and (i<>eInvalid) and (i<>eOutOfControl)
end
else BuyBtn.Visible:=false;
if BuyBtn.Visible then
RFrame(offscreen.Canvas,BuyBtn.Left-(SideFrame+1),BuyBtn.Top-(WideFrame+1),
BuyBtn.Left+BuyBtn.Width-SideFrame,BuyBtn.Top+BuyBtn.Height-WideFrame,
OuterCityTex.clBevelShade,OuterCityTex.clBevelLight);
MarkUsedOffscreen(InnerWidth,InnerHeight);
end;{OffscreenPaint}
procedure TCityDlg.OffscreenUpdate;
begin
OffscreenPaint;
SmartInvalidate;
if CityListDlg.Visible then
begin
Update;
CityListDlg.OffscreenPaint;
CityListDlg.SmartInvalidate;
CityListDlg.Update
end;
end;
procedure TCityDlg.FormShow(Sender: TObject);
var
CityInfo: TCityInfo;
GetCityData: TGetCityData;
begin
BlinkTime:=-1;
if cix>=0 then
begin {own city}
c:=MyCity[cix];
cOwner:=me;
cGov:=MyRO.Government;
Server(sGetCityAreaInfo,me,cix,CityAreaInfo);
CityAge:=Age;
OuterCityTex:=OuterTex;
InnerCityTex:=InnerTex;
end
else {enemy city}
begin
Mode:=mImp;
CityInfo.Loc:=cLoc;
GetCityInfo(CityInfo.Loc,cix,CityInfo);
cix:=-1; {don't use EnemyCity}
Server(sGetCity,me,cLoc,GetCityData);
c:=GetCityData.c;
cOwner:=GetCityData.Owner;
cGov:=MyRO.EnemyReport[cOwner].Government;
Happened:=c.Flags;
Server(sGetEnemyCityAreaInfo,me,cLoc,CityAreaInfo);
if c.Project and cpImp=0 then
begin
emix:=MyRO.nEnemyModel-1;
while (emix>0) and ((MyRO.EnemyModel[emix].Owner<>cOwner)
or (integer(MyRO.EnemyModel[emix].mix)<>c.Project and cpIndex)) do dec(emix);
if Tribe[cOwner].ModelPicture[c.Project and cpIndex].HGr=0 then
InitEnemyModel(MyRO.EnemyModel[emix],true);
end;
CityAge:=GetAge(cOwner);
Tribe[cOwner].InitAgeTextures(OuterCityTex,InnerCityTex,CityAge);
end;
Tex:=OuterCityTex;
Caption:=CityName(c.ID);
SupportBtn.Down:=(Mode=mSupp);
BuiltBtn.Down:=(Mode=mImp);
InitDisplay;
EventSoundEnabled:=true;
OffscreenPaint;
EventSoundEnabled:=false;
Timer1.Enabled:=true;
end;
procedure TCityDlg.FormMouseDown(Sender:TObject;
Button:TMouseButton;Shift:TShiftState;x,y:integer);
var
i,qx,qy,dx,dy,fix,NewTiles,Loc1,iix,SellResult: integer;
Rebuild: boolean;
begin
if cix<0 then exit;
x:=x-SideFrame; y:=y-WideFrame;
if (ssLeft in Shift) then
if (ClientMode<scContact)
and (x>=xView) and (y>=yView) and (x<xView+73) and (y<yView+50) then
begin
if ProdHint then
begin
ProdHint:=false;
OffscreenPaint;
SmartInvalidate
end;
ChooseProject;
end
else if (Mode=mImp) and (x>=xImp) and (y>=yImp+8) and (y<yImp+48) then
begin
i:=(x-xImp) div ImpPitch;
if (i>=0) and (i<nDisplay) and (x-xImp-i*ImpPitch<56) and (imix[i]>=0) then
if ssShift in Shift then
HelpDlg.ShowPage(hkImp,imix[i])
else if (ClientMode<scContact) then with MessgExDlg do
begin
iix:=imix[i];
BigIcon:=iix;
if Imp[iix].Kind=ikWonder then
begin
MessgText:=Format(Phrases.Lookup('DISPOSEWONDER'),
[Phrases.Lookup('IMPROVEMENTS',iix)]);
Kind:=mkOk;
ShowModal;
end
else
begin
SellResult:=Server(sSellCityImprovement-sExecute,me,cix,iix);
if SellResult<rExecuted then
begin
if SellResult=eOnlyOnce then
MessgText:=Phrases.Lookup('NOSELLAGAIN')
else MessgText:=Phrases.Lookup('OUTOFCONTROL');
MessgText:=Format(MessgText,[Phrases.Lookup('IMPROVEMENTS',iix)]);
Kind:=mkOk;
ShowModal;
end
else
begin
if Server(sRebuildCityImprovement-sExecute,me,cix,iix)<rExecuted then
begin // no rebuild possible, ask for sell only
MessgText:=Format(Phrases.Lookup('SELL'),
[Phrases.Lookup('IMPROVEMENTS',iix)]);
Kind:=mkYesNo;
ShowModal;
if ModalResult=mrOK then Rebuild:=false
else iix:=-1
end
else
begin
MessgText:=Format(Phrases.Lookup('DISPOSE'),
[Phrases.Lookup('IMPROVEMENTS',iix)]);
Kind:=mkRebuildSell;
ShowModal;
if ModalResult<>mrCancel then Rebuild:= ModalResult=mrOK
else iix:=-1
end;
if iix>=0 then
begin
if Rebuild then
begin
Play('REBUILD');
Server(sRebuildCityImprovement,me,cix,iix);
end
else
begin
Play('SELL');
Server(sSellCityImprovement,me,cix,iix);
end;
OffscreenUpdate;
end
end
end
end
end
else if (Mode=mSupp) and (x>=xSupp) and (y>=ySupp+2) and (y<ySupp+61) then
begin
i:=(x-xSupp) div 64;
if (i>=0) and (i<nDisplay) and (imix[i]>=0) then
begin
CloseAction:=None;
Close;
MainScreen.CityClosed(imix[i]);
end
end
else if (ClientMode<scContact)
and (x>=xArea) and (x<xArea+8*33) and (y>=yArea) and (y<yArea+8*16) then
begin
qx:=((x-xArea)*32+(y-yArea)*66-16*66) div(32*66);
qy:=((y-yArea)*66+(2000*33*32-16*66)-(x-xArea)*32) div(32*66);
dx:=qx-qy+996;
dy:=qx+qy-1002;
if (dx>=-3) and (dx<=3) and (dy>=-3) and (dy<=3) and (dx*dx*dy*dy<81)
and ((dx<>0) or (dy<>0)) then
if ssShift in Shift then
begin // terrain help
Loc1:=dLoc(c.Loc,dx,dy);
if (Loc1>=0) and (Loc1<G.lx*G.ly) then
HelpDlg.ShowPage(hkTer,
MyMap[Loc1] and fTerrain + (MyMap[Loc1] shr 5 and 3)*12);
end
else
begin // toggle exploitation
fix:=(dy+3) shl 2+(dx+3) shr 1;
NewTiles:=MyCity[cix].Tiles xor (1 shl fix);
if Server(sSetCityTiles,me,cix,NewTiles)>=rExecuted then
OffscreenUpdate;
end
end
end;{FormMouseDown}
procedure TCityDlg.ChooseProject;
var
NewProject: integer;
begin
SelectDlg.Caption:=Phrases.Lookup('TITLE_PROJECT');
SelectDlg.Kind:=kProject;
SelectDlg.cix:=cix;
SelectDlg.ShowModal;
if SelectDlg.result<>-1 then
begin
if SelectDlg.result and cpType<>0 then
begin
MyCity[cix].Status:=MyCity[cix].Status and not 7
or (1+SelectDlg.result and cpIndex);
AutoBuild(cix, MyData.ImpOrder[SelectDlg.result and cpIndex]);
end
else
begin
MyCity[cix].Status:=MyCity[cix].Status and not 7;
if (MyCity[cix].Prod0>0) and (SelectDlg.result=cpImp+imTrGoods) then
begin
Server(sSellCityProject,me,cix,nil^);
Play('SELL');
end;
NewProject:=SelectDlg.result;
if (NewProject and cpImp=0)
and ((MyCity[cix].Size<4) and (MyModel[NewProject and cpIndex].Kind=mkSettler)
or (MyCity[cix].Size<3) and ((MyModel[NewProject and cpIndex].Kind=mkSlaves)
or (NewProject and cpConscripts<>0))) then
if SimpleQuery(mkYesNo,Phrases.Lookup('EMIGRATE'),'')<>mrOK then
NewProject:=NewProject or cpDisbandCity;
Server(sSetCityProject,me,cix,NewProject);
end;
OffscreenUpdate;
end;
end;
procedure TCityDlg.BuyClick(Sender:TObject);
var
NextProd,Cost:integer;
begin
if (cix<0) or (ClientMode>=scContact) then exit;
with MyCity[cix],MessgExDlg do
begin
Cost:=Report.ProdCost;
NextProd:=Report.ProdRep-Report.Support;
if NextProd<0 then NextProd:=0;
Cost:=4*(Cost-Prod-NextProd);
if (Cost<=0) and (Report.Working-Report.Happy<=Size div 2) {no disorder} then
begin MessgText:=Phrases.Lookup('READY'); Kind:=mkOK; end
else if Cost>MyRO.Money then
begin
MessgText:=Format(Phrases.Lookup('NOMONEY'),[Cost,MyRO.Money]);
Kind:=mkOK;
end
else begin MessgText:=Format(Phrases.Lookup('BUY'),[Cost]); Kind:=mkYesNo; end;
ShowModal;
if (Kind=mkYesNo) and (ModalResult=mrOK) then
begin
Server(sBuyCityProject,me,cix,nil^);
OffscreenUpdate;
end
end
end;
procedure TCityDlg.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Timer1.Enabled:=false;
ProdHint:=false;
if CloseAction>None then
MainScreen.CityClosed(-1,CloseAction=RestoreAutoTurn);
inherited;
end;
procedure TCityDlg.ShowNow;
begin
if Visible then begin FormShow(nil); Invalidate end else Show
end;
procedure TCityDlg.Timer1Timer(Sender: TObject);
begin
if ProdHint then
begin
BlinkTime:=(BlinkTime+1) mod 12;
if BlinkTime=0 then with Canvas do
begin
Brush.Color:=$000000;
FillRect(Rect(xView+SideFrame+9,yView+WideFrame+5,
xView+SideFrame+1+72-8,yView+WideFrame+5+40));
Brush.Style:=bsClear;
end
else if BlinkTime=6 then
BitBlt(Canvas.Handle,xView+SideFrame+9,yView+WideFrame+5,
xSizeBig,ySizeBig,BigImp.Canvas.Handle,
c.Project0 and cpIndex mod 7 *xSizeBig,
(c.Project0 and cpIndex+SystemIconLines*7) div 7 *ySizeBig,SRCCOPY);
end
end;
procedure TCityDlg.SupportBtnClick(Sender: TObject);
begin
Mode:=mSupp;
BuiltBtn.Down:=false;
InitDisplay;
OffscreenPaint;
SmartInvalidate
end;
procedure TCityDlg.BuiltBtnClick(Sender: TObject);
begin
Mode:=mImp;
SupportBtn.Down:=false;
InitDisplay;
OffscreenPaint;
SmartInvalidate
end;
procedure TCityDlg.FormPaint(Sender: TObject);
begin
inherited;
BtnFrame(Canvas,CloseBtn.BoundsRect,OuterCityTex);
end;
function Prio(iix: integer): integer;
begin
case Imp[iix].Kind of
ikWonder: result:=iix+10000;
ikNatLocal, ikNatGlobal: result:=iix+20000;
else case iix of
imTownHall, imCourt: result:=iix+30000;
imAqueduct, imSewer: result:=iix+40000;
imTemple, imTheater, imCathedral: result:=iix+50000;
else result:=iix+90000;
end;
end;
end;
var
i,j,k: integer;
initialization
for i:=0 to nImp-1 do ImpSorted[i]:=i;
for i:=0 to nImp-2 do for j:=i+1 to nImp-1 do
if Prio(ImpSorted[i])>Prio(ImpSorted[j]) then
begin k:=ImpSorted[i]; ImpSorted[i]:=ImpSorted[j]; ImpSorted[j]:=k end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -