1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543
|
{$INCLUDE Switches.inc}
unit NatStat;
interface
uses
Protocol, ClientTools, Term, ScreenTools, BaseWin, LCLIntf, LCLType, SysUtils,
Classes, Graphics, Controls, Forms, ButtonB, ButtonC, Menus, EOTButton;
type
PEnemyReport = ^TEnemyReport;
TNatStatDlg = class(TBufferedDrawDlg)
ToggleBtn: TButtonB;
CloseBtn: TButtonB;
Popup: TPopupMenu;
ScrollUpBtn: TButtonC2;
ScrollDownBtn: TButtonC2;
ContactBtn: TEOTButton;
TellAIBtn: TButtonC2;
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure CloseBtnClick(Sender: TObject);
procedure DialogBtnClick(Sender: TObject);
procedure ToggleBtnClick(Sender: TObject);
procedure PlayerClick(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: word; Shift: TShiftState);
procedure FormDestroy(Sender: TObject);
procedure ScrollUpBtnClick(Sender: TObject);
procedure ScrollDownBtnClick(Sender: TObject);
procedure TellAIBtnClick(Sender: TObject);
public
procedure CheckAge;
procedure ShowNewContent(NewMode: TWindowMode; p: integer = -1);
procedure EcoChange;
protected
procedure OffscreenPaint; override;
private
pView, AgePrepared, LinesDown: integer;
SelfReport, CurrentReport: PEnemyReport;
ShowContact, ContactEnabled: boolean;
Back, Template: TBitmap;
ReportText: TStringList;
procedure GenerateReportText;
end;
var
NatStatDlg: TNatStatDlg;
implementation
{$R *.lfm}
uses
Messg, Tribes, Directories;
const
xIcon = 326;
yIcon = 49;
xAttrib = 96;
yAttrib = 40;
xRelation = 16;
yRelation = 110;
PaperShade = 3;
ReportLines = 12;
LineSpacing = 22;
xReport = 24;
yReport = 165;
wReport = 352;
hReport = ReportLines * LineSpacing;
procedure TNatStatDlg.FormCreate(Sender: TObject);
begin
inherited;
AgePrepared := -2;
GetMem(SelfReport, SizeOf(TEnemyReport) - 2 * (INFIN + 1));
ReportText := TStringList.Create;
InitButtons;
ContactBtn.Template := Templates.Data;
HelpContext := 'DIPLOMACY';
ToggleBtn.Hint := Phrases.Lookup('BTN_SELECT');
ContactBtn.Hint := Phrases.Lookup('BTN_DIALOG');
Back := TBitmap.Create;
Back.PixelFormat := pf24bit;
Back.SetSize(Width, Height);
Back.Canvas.FillRect(0, 0, Back.Width, Back.Height);
Template := TBitmap.Create;
Template.PixelFormat := pf24bit;
LoadGraphicFile(Template, GetGraphicsDir + DirectorySeparator + 'Nation.png',
[gfNoGamma]);
end;
procedure TNatStatDlg.FormDestroy(Sender: TObject);
begin
FreeAndNil(ReportText);
FreeMem(SelfReport);
FreeAndNil(Template);
FreeAndNil(Back);
end;
procedure TNatStatDlg.CheckAge;
begin
if MainTexture.Age <> AgePrepared then begin
AgePrepared := MainTexture.Age;
BitBltCanvas(Back.Canvas, 0, 0, ClientWidth, ClientHeight,
MainTexture.Image.Canvas, (MainTexture.Width - ClientWidth) div 2,
(MainTexture.Height - ClientHeight) div 2);
ImageOp_B(Back, Template, 0, 0, 0, 0, ClientWidth, ClientHeight);
end;
end;
procedure TNatStatDlg.FormShow(Sender: TObject);
begin
if pView = me then
begin
SelfReport.TurnOfCivilReport := MyRO.Turn;
SelfReport.TurnOfMilReport := MyRO.Turn;
move(MyRO.Treaty, SelfReport.Treaty, SizeOf(SelfReport.Treaty));
SelfReport.Government := MyRO.Government;
SelfReport.Money := MyRO.Money;
CurrentReport := pointer(SelfReport);
end
else
CurrentReport := pointer(MyRO.EnemyReport[pView]);
if CurrentReport.TurnOfCivilReport >= 0 then
GenerateReportText;
ShowContact := (pView <> me) and (not supervising or (me <> 0));
ContactEnabled := ShowContact and not supervising and
(1 shl pView and MyRO.Alive <> 0);
ContactBtn.Visible := ContactEnabled and (MyRO.Happened and phGameEnd = 0) and
(ClientMode < scContact);
ScrollUpBtn.Visible := (CurrentReport.TurnOfCivilReport >= 0) and
(ReportText.Count > ReportLines);
ScrollDownBtn.Visible := (CurrentReport.TurnOfCivilReport >= 0) and
(ReportText.Count > ReportLines);
if soTellAI in OptionChecked then
TellAIBtn.ButtonIndex := 3
else
TellAIBtn.ButtonIndex := 2;
Caption := Tribe[pView].TPhrase('TITLE_NATION');
LinesDown := 0;
OffscreenPaint;
end;
procedure TNatStatDlg.ShowNewContent(NewMode: TWindowMode; p: integer);
begin
if p < 0 then
if ClientMode >= scContact then
pView := DipMem[me].pContact
else
begin
pView := 0;
while (pView < nPl) and ((MyRO.Treaty[pView] < trNone) or
(1 shl pView and MyRO.Alive = 0)) do
inc(pView);
if pView >= nPl then
pView := me;
end
else
pView := p;
inherited ShowNewContent(NewMode);
end;
procedure TNatStatDlg.PlayerClick(Sender: TObject);
begin
ShowNewContent(FWindowMode, TComponent(Sender).Tag);
end;
procedure TNatStatDlg.GenerateReportText;
var
List: ^TChart;
function StatText(no: integer): string;
var
i: integer;
begin
result := '';
if (CurrentReport.TurnOfCivilReport >= 0) and
(Server(sGetChart + no shl 4, me, pView, List^) >= rExecuted) then
begin
i := List[CurrentReport.TurnOfCivilReport];
case no of
stPop:
result := Format(Phrases.Lookup('FRSTATPOP'), [i]);
stTerritory:
result := Format(Phrases.Lookup('FRSTATTER'), [i]);
stScience:
result := Format(Phrases.Lookup('FRSTATTECH'), [i div nAdv]);
stExplore:
result := Format(Phrases.Lookup('FRSTATEXP'),
[i * 100 div (G.lx * G.ly)]);
end;
end
end;
var
p1, Treaty: integer;
s: string;
HasContact, ExtinctPart: boolean;
begin
GetMem(List, 4 * (MyRO.Turn + 2));
ReportText.Clear;
ReportText.Add('');
if (MyRO.Turn - CurrentReport.TurnOfCivilReport > 1) and
(1 shl pView and MyRO.Alive <> 0) then
begin
s := Format(Phrases.Lookup('FROLDCIVILREP'),
[TurnToString(CurrentReport.TurnOfCivilReport)]);
ReportText.Add('C' + s);
ReportText.Add('');
end;
if (1 shl pView and MyRO.Alive <> 0) then
begin
ReportText.Add('M' + Format(Phrases.Lookup('FRTREASURY'),
[CurrentReport.Money]));
ReportText.Add('P' + StatText(stPop));
ReportText.Add('T' + StatText(stTerritory));
end;
ReportText.Add('S' + StatText(stScience));
ReportText.Add('E' + StatText(stExplore));
HasContact := false;
for p1 := 0 to nPl - 1 do
if (p1 <> me) and (CurrentReport.Treaty[p1] > trNoContact) then
HasContact := true;
if HasContact then
begin
ReportText.Add('');
ReportText.Add(' ' + Phrases.Lookup('FRRELATIONS'));
for ExtinctPart := false to true do
for Treaty := trAlliance downto trNone do
for p1 := 0 to nPl - 1 do
if (p1 <> me) and (CurrentReport.Treaty[p1] = Treaty) and
((1 shl p1 and MyRO.Alive = 0) = ExtinctPart) then
begin
s := Tribe[p1].TString(Phrases.Lookup('HAVETREATY', Treaty));
if ExtinctPart then
s := '(' + s + ')';
ReportText.Add(char(48 + Treaty) + s);
end;
end;
ReportText.Add('');
FreeMem(List);
end;
procedure TNatStatDlg.OffscreenPaint;
var
i, y: integer;
s: string;
ps: pchar;
Extinct: boolean;
begin
inherited;
Extinct := 1 shl pView and MyRO.Alive = 0;
BitBltCanvas(offscreen.Canvas, 0, 0, ClientWidth, ClientHeight,
Back.Canvas, 0, 0);
offscreen.Canvas.Font.Assign(UniFont[ftCaption]);
RisedTextout(offscreen.Canvas,
40 { (ClientWidth-BiColorTextWidth(offscreen.canvas,caption)) div 2 } ,
7, Caption);
offscreen.Canvas.Font.Assign(UniFont[ftNormal]);
with offscreen do
begin
// show leader picture
Tribe[pView].InitAge(GetAge(pView));
if Assigned(Tribe[pView].faceHGr) then
begin
Dump(offscreen, Tribe[pView].faceHGr, 18, yIcon - 4, 64, 48,
1 + Tribe[pView].facepix mod 10 * 65,
1 + Tribe[pView].facepix div 10 * 49);
frame(offscreen.Canvas, 18 - 1, yIcon - 4 - 1, 18 + 64, yIcon - 4 + 48,
$000000, $000000);
end;
if (pView = me) or not Extinct then
LoweredTextOut(Canvas, -1, MainTexture, xAttrib, yAttrib,
Phrases.Lookup('GOVERNMENT', CurrentReport.Government) +
Phrases.Lookup('FRAND'));
if pView = me then
begin
LoweredTextOut(Canvas, -1, MainTexture, xAttrib, yAttrib + 19,
Phrases.Lookup('CREDIBILITY', RoughCredibility(MyRO.Credibility)));
LoweredTextOut(Canvas, -1, MainTexture, xAttrib, yAttrib + 38,
Format(Phrases.Lookup('FRCREDIBILITY'), [MyRO.Credibility]));
end
else
begin
if Extinct then
begin
LoweredTextOut(Canvas, -1, MainTexture, xAttrib, yAttrib + 9,
Phrases.Lookup('FREXTINCT'));
LoweredTextOut(Canvas, -1, MainTexture, xAttrib, yAttrib + 28,
TurnToString(CurrentReport.TurnOfCivilReport));
end
else
begin
LoweredTextOut(Canvas, -1, MainTexture, xAttrib, yAttrib + 19,
Phrases.Lookup('CREDIBILITY',
RoughCredibility(CurrentReport.Credibility)));
LoweredTextOut(Canvas, -1, MainTexture, xAttrib, yAttrib + 38,
Format(Phrases.Lookup('FRCREDIBILITY'), [CurrentReport.Credibility]));
end;
if MyRO.Treaty[pView] = trNoContact then
begin
s := Phrases.Lookup('FRNOCONTACT');
LoweredTextOut(Canvas, -1, MainTexture,
(ClientWidth - BiColorTextWidth(Canvas, s)) div 2, yRelation + 9, s);
end
else if ShowContact then
begin
LoweredTextOut(Canvas, -1, MainTexture, xRelation, yRelation,
Phrases.Lookup('FRTREATY'));
LoweredTextOut(Canvas, -1, MainTexture, ClientWidth div 2, yRelation,
Phrases.Lookup('TREATY', MyRO.Treaty[pView]));
if CurrentReport.TurnOfContact < 0 then
LoweredTextOut(Canvas, -1, MainTexture, ClientWidth div 2,
yRelation + 19, Phrases.Lookup('FRNOVISIT'))
else
begin
LoweredTextOut(Canvas, -1, MainTexture, xRelation, yRelation + 19,
Phrases.Lookup('FRLASTCONTACT'));
if CurrentReport.TurnOfContact >= 0 then
LoweredTextOut(Canvas, -1, MainTexture, ClientWidth div 2,
yRelation + 19, TurnToString(CurrentReport.TurnOfContact));
end;
end;
if Extinct then
FrameImage(Canvas, BigImp, xIcon, yIcon, xSizeBig, ySizeBig, 0, 200)
{ else if CurrentReport.Government=gAnarchy then
FrameImage(canvas,BigImp,xIcon,yIcon,xSizeBig,ySizeBig,112,400,
ContactEnabled and (MyRO.Happened and phGameEnd=0) and (ClientMode<scContact))
else
FrameImage(canvas,BigImp,xIcon,yIcon,xSizeBig,ySizeBig,
56*(CurrentReport.Government-1),40,
ContactEnabled and (MyRO.Happened and phGameEnd=0) and (ClientMode<scContact)) };
end;
if CurrentReport.TurnOfCivilReport >= 0 then
begin // print state report
FillSeamless(Canvas, xReport, yReport, wReport, hReport, 0, 0, Paper);
with Canvas do
begin
Brush.Color := MainTexture.ColorBevelShade;
FillRect(Rect(xReport + wReport, yReport + PaperShade,
xReport + wReport + PaperShade, yReport + hReport + PaperShade));
FillRect(Rect(xReport + PaperShade, yReport + hReport,
xReport + wReport + PaperShade, yReport + hReport + PaperShade));
Brush.Style := bsClear;
end;
y := 0;
for i := 0 to ReportText.Count - 1 do
begin
if (i >= LinesDown) and (i < LinesDown + ReportLines) then
begin
s := ReportText[i];
if s <> '' then
begin
// LineType:=s[1];
delete(s, 1, 1);
BiColorTextOut(Canvas, Colors.Canvas.Pixels[clkMisc, cliPaperText],
$7F007F, xReport + 8, yReport + LineSpacing * y, s);
end;
inc(y);
end;
end;
end
else
begin
s := Phrases.Lookup('FRNOCIVILREP');
RisedTextout(Canvas, (ClientWidth - BiColorTextWidth(Canvas, s)) div 2,
yReport + hReport div 2 - 10, s);
end;
if soTellAI in OptionChecked then begin
Server(sGetAIInfo, me, pView, ps);
LoweredTextOut(Canvas, -1, MainTexture, 48, 445, ps);
end else
LoweredTextOut(Canvas, -2, MainTexture, 48, 445,
Phrases2.Lookup('MENU_TELLAI'));
end;
ContactBtn.SetBack(offscreen.Canvas, ContactBtn.Left, ContactBtn.Top);
MarkUsedOffscreen(ClientWidth, ClientHeight);
end;
procedure TNatStatDlg.CloseBtnClick(Sender: TObject);
begin
Close;
end;
procedure TNatStatDlg.DialogBtnClick(Sender: TObject);
var
ContactResult: integer;
begin
ContactResult := MainScreen.DipCall(scContact + pView shl 4);
if ContactResult < rExecuted then
begin
if ContactResult = eColdWar then
SoundMessage(Phrases.Lookup('FRCOLDWAR'), 'MSG_DEFAULT')
else if MyRO.Government = gAnarchy then
SoundMessage(Tribe[me].TPhrase('FRMYANARCHY'), 'MSG_DEFAULT')
else if ContactResult = eAnarchy then
if MyRO.Treaty[pView] >= trPeace then
begin
if MainScreen.ContactRefused(pView, 'FRANARCHY') then
SmartUpdateContent;
end
else
SoundMessage(Tribe[pView].TPhrase('FRANARCHY'), 'MSG_DEFAULT');
end
else
Close;
end;
procedure TNatStatDlg.ToggleBtnClick(Sender: TObject);
var
p1, StartCount: integer;
m: TMenuItem;
ExtinctPart: boolean;
begin
EmptyMenu(Popup.Items);
// own nation
if G.Difficulty[me] <> 0 then
begin
m := TMenuItem.Create(Popup);
m.RadioItem := true;
m.Caption := Tribe[me].TPhrase('TITLE_NATION');
m.Tag := me;
m.OnClick := PlayerClick;
if me = pView then
m.Checked := true;
Popup.Items.Add(m);
end;
// foreign nations
for ExtinctPart := false to true do
begin
StartCount := Popup.Items.Count;
for p1 := 0 to nPl - 1 do
if ExtinctPart and (G.Difficulty[p1] > 0) and
(1 shl p1 and MyRO.Alive = 0) or not ExtinctPart and
(1 shl p1 and MyRO.Alive <> 0) and (MyRO.Treaty[p1] >= trNone) then
begin
m := TMenuItem.Create(Popup);
m.RadioItem := true;
m.Caption := Tribe[p1].TPhrase('TITLE_NATION');
if ExtinctPart then
m.Caption := '(' + m.Caption + ')';
m.Tag := p1;
m.OnClick := PlayerClick;
if p1 = pView then
m.Checked := true;
Popup.Items.Add(m);
end;
if (StartCount > 0) and (Popup.Items.Count > StartCount) then
begin // seperator
m := TMenuItem.Create(Popup);
m.Caption := '-';
Popup.Items.Insert(StartCount, m);
end;
end;
Popup.Popup(Left + ToggleBtn.Left, Top + ToggleBtn.Top + ToggleBtn.Height);
end;
procedure TNatStatDlg.FormKeyDown(Sender: TObject; var Key: word;
Shift: TShiftState);
var
i: integer;
begin
if Key = VK_F9 then // my key
begin // toggle nation
i := 0;
repeat
pView := (pView + 1) mod nPl;
inc(i);
until (i >= nPl) or (1 shl pView and MyRO.Alive <> 0) and
(MyRO.Treaty[pView] >= trNone);
if i >= nPl then
pView := me;
Tag := pView;
PlayerClick(self); // no, this is not nice
end
else
inherited;
end;
procedure TNatStatDlg.EcoChange;
begin
if Visible and (pView = me) then
begin
SelfReport.Government := MyRO.Government;
SelfReport.Money := MyRO.Money;
SmartUpdateContent;
end;
end;
procedure TNatStatDlg.ScrollUpBtnClick(Sender: TObject);
begin
if LinesDown > 0 then
begin
dec(LinesDown);
SmartUpdateContent;
end;
end;
procedure TNatStatDlg.ScrollDownBtnClick(Sender: TObject);
begin
if LinesDown + ReportLines < ReportText.Count then
begin
inc(LinesDown);
SmartUpdateContent;
end;
end;
procedure TNatStatDlg.TellAIBtnClick(Sender: TObject);
begin
if soTellAI in OptionChecked then OptionChecked := OptionChecked - [soTellAI]
else OptionChecked := OptionChecked + [soTellAI];
if soTellAI in OptionChecked then
TellAIBtn.ButtonIndex := 3
else
TellAIBtn.ButtonIndex := 2;
SmartUpdateContent;
end;
end.
|