source: tags/1.2.0/LocalPlayer/UnitStat.pas

Last change on this file was 209, checked in by chronos, 4 years ago
  • Modified: Code formatting.
File size: 23.7 KB
Line 
1{$INCLUDE Switches.inc}
2unit UnitStat;
3
4interface
5
6uses
7 Protocol, ClientTools, Term, ScreenTools, BaseWin,
8 LCLIntf, LCLType, SysUtils, Classes, Graphics, Controls, Forms,
9 ButtonB, ButtonC;
10
11type
12 TUnitStatDlg = class(TBufferedDrawDlg)
13 SwitchBtn: TButtonB;
14 CloseBtn: TButtonB;
15 ConscriptsBtn: TButtonB;
16 HelpBtn: TButtonC;
17 procedure FormShow(Sender: TObject);
18 procedure CloseBtnClick(Sender: TObject);
19 procedure FormCreate(Sender: TObject);
20 procedure ModelBoxChange(Sender: TObject);
21 procedure SwitchBtnClick(Sender: TObject);
22 procedure ConscriptsBtnClick(Sender: TObject);
23 procedure FormDestroy(Sender: TObject);
24 procedure FormClose(Sender: TObject; var Action: TCloseAction);
25 procedure HelpBtnClick(Sender: TObject);
26
27 public
28 procedure CheckAge;
29 procedure ShowNewContent_OwnModel(NewMode, mix: integer);
30 procedure ShowNewContent_OwnUnit(NewMode, uix: integer);
31 procedure ShowNewContent_EnemyUnit(NewMode, euix: integer);
32 procedure ShowNewContent_EnemyLoc(NewMode, Loc: integer);
33 procedure ShowNewContent_EnemyModel(NewMode, emix: integer);
34 procedure ShowNewContent_EnemyCity(NewMode, Loc: integer);
35
36 protected
37 mixShow, // for dkOwnModel
38 uixShow, euixShow, ecixShow, UnitLoc, AgePrepared: integer;
39 // for dkEnemyUnit, euixShow=-1 ->
40 mox: ^TModelInfo; // for dkEnemyModel
41 Kind: (dkOwnModel, dkOwnUnit, dkEnemyModel, dkEnemyUnit, dkEnemyCityDefense,
42 dkEnemyCity);
43 Back, Template: TBitmap;
44 procedure OffscreenPaint; override;
45 end;
46
47var
48 UnitStatDlg: TUnitStatDlg;
49
50implementation
51
52uses
53 Tribes, IsoEngine, Help, Directories;
54
55{$R *.lfm}
56
57const
58 xView = 71;
59 xTotal = 20;
60 StatDown = 112;
61 yImp = 133;
62
63 // window size
64 wCommon = 208;
65 hOwnModel = 293;
66 hEnemyModel = 236;
67 hEnemyUnit = 212;
68 hEnemyCityDefense = 320;
69 hEnemyCity = 166;
70 hMax = 320;
71
72procedure TUnitStatDlg.FormCreate(Sender: TObject);
73begin
74 inherited;
75 AgePrepared := -2;
76 TitleHeight := Screen.Height;
77 InitButtons();
78
79 Back := TBitmap.Create;
80 Back.PixelFormat := pf24bit;
81 Back.SetSize(5 * wCommon, hMax);
82 Back.Canvas.FillRect(0, 0, Back.Width,Back.Height);
83 Template := TBitmap.Create;
84 Template.PixelFormat := pf24bit;
85 LoadGraphicFile(Template, GetGraphicsDir + DirectorySeparator + 'Unit.png', gfNoGamma);
86end;
87
88procedure TUnitStatDlg.FormDestroy(Sender: TObject);
89begin
90 Template.Free;
91 Back.Free;
92end;
93
94procedure TUnitStatDlg.CheckAge;
95begin
96 if MainTextureAge <> AgePrepared then
97 begin
98 AgePrepared := MainTextureAge;
99 BitBltCanvas(Back.Canvas, 0, 0, wCommon, hOwnModel,
100 MainTexture.Image.Canvas, (wMainTexture - wCommon) div 2,
101 (hMainTexture - hOwnModel) div 2);
102 BitBltCanvas(Back.Canvas, wCommon, 0, wCommon, hEnemyModel,
103 MainTexture.Image.Canvas, (wMainTexture - wCommon) div 2,
104 (hMainTexture - hEnemyModel) div 2);
105 BitBltCanvas(Back.Canvas, 2 * wCommon, 0, wCommon, hEnemyUnit,
106 MainTexture.Image.Canvas, (wMainTexture - wCommon) div 2,
107 (hMainTexture - hEnemyUnit) div 2);
108 BitBltCanvas(Back.Canvas, 3 * wCommon, 0, wCommon, hEnemyCityDefense,
109 MainTexture.Image.Canvas, (wMainTexture - wCommon) div 2,
110 (hMainTexture - hEnemyCityDefense) div 2);
111 BitBltCanvas(Back.Canvas, 4 * wCommon, 0, wCommon, hEnemyCity,
112 MainTexture.Image.Canvas, (wMainTexture - wCommon) div 2,
113 (hMainTexture - hEnemyCity) div 2);
114 ImageOp_B(Back, Template, 0, 0, 0, 0, 5 * wCommon, hMax);
115 end
116end;
117
118procedure TUnitStatDlg.FormShow(Sender: TObject);
119var
120 owner, mix: integer;
121 IsSpecialUnit: boolean;
122begin
123 if Kind in [dkEnemyUnit, dkEnemyCityDefense, dkEnemyCity] then
124 begin
125 if MyMap[UnitLoc] and fUnit <> 0 then
126 begin // find model
127 if euixShow < 0 then
128 begin
129 euixShow := MyRO.nEnemyUn - 1;
130 while (euixShow >= 0) and (MyRO.EnemyUn[euixShow].Loc <> UnitLoc) do
131 dec(euixShow);
132 assert(euixShow >= 0);
133 end;
134 with MyRO.EnemyUn[euixShow] do
135 begin
136 mox := @MyRO.EnemyModel[emix];
137 if Tribe[owner].ModelPicture[mix].HGr = 0 then
138 InitEnemyModel(emix);
139 end
140 end
141 else
142 mox := nil;
143 if Kind in [dkEnemyCityDefense, dkEnemyCity] then
144 begin
145 ecixShow := MyRO.nEnemyCity - 1;
146 while (ecixShow >= 0) and (MyRO.EnemyCity[ecixShow].Loc <> UnitLoc) do
147 dec(ecixShow);
148 assert(ecixShow >= 0);
149 end
150 end;
151 case Kind of
152 dkOwnModel:
153 ClientHeight := hOwnModel;
154 dkOwnUnit:
155 ClientHeight := hEnemyUnit;
156 dkEnemyModel:
157 ClientHeight := hEnemyModel;
158 dkEnemyUnit:
159 ClientHeight := hEnemyUnit;
160 dkEnemyCityDefense:
161 ClientHeight := hEnemyCityDefense;
162 dkEnemyCity:
163 ClientHeight := hEnemyCity;
164 end;
165
166 if Kind in [dkOwnModel, dkEnemyModel] then
167 begin
168 Left := UserLeft;
169 Top := UserTop;
170 end
171 else
172 begin
173 Left := (Screen.Width - Width) div 2;
174 Top := (Screen.Height - Height) div 2;
175 end;
176
177 SwitchBtn.Visible := not supervising and (Kind = dkOwnModel);
178 ConscriptsBtn.Visible := not supervising and (Kind = dkOwnModel) and
179 (MyRO.Tech[adConscription] >= tsApplicable) and
180 (MyModel[mixShow].Domain = dGround) and (MyModel[mixShow].Kind < mkScout);
181 IsSpecialUnit := false;
182 if Kind in [dkEnemyCity, dkEnemyCityDefense] then
183 Caption := CityName(MyRO.EnemyCity[ecixShow].ID)
184 else
185 begin
186 case Kind of
187 dkOwnModel:
188 begin
189 owner := me;
190 mix := mixShow;
191 IsSpecialUnit := MyModel[mix].Kind >= $10;
192 end;
193 dkOwnUnit:
194 begin
195 owner := me;
196 mix := MyUn[uixShow].mix;
197 IsSpecialUnit := MyModel[mix].Kind >= $10;
198 end
199 else
200 begin
201 owner := mox.owner;
202 mix := mox.mix;
203 IsSpecialUnit := mox.Kind >= $10;
204 end;
205 end;
206 if MainScreen.mNames.Checked then
207 Caption := Tribe[owner].ModelName[mix]
208 else
209 Caption := Format(Tribe[owner].TPhrase('GENMODEL'), [mix])
210 end;
211 if IsSpecialUnit then
212 HelpBtn.Hint := Phrases.Lookup('CONTROLS', 6);
213 HelpBtn.Visible := IsSpecialUnit;
214 OffscreenPaint;
215end;
216
217procedure TUnitStatDlg.ShowNewContent_OwnModel(NewMode, mix: integer);
218begin
219 Kind := dkOwnModel;
220 mixShow := mix;
221 inherited ShowNewContent(NewMode);
222end;
223
224procedure TUnitStatDlg.ShowNewContent_OwnUnit(NewMode, uix: integer);
225begin
226 Kind := dkOwnUnit;
227 uixShow := uix;
228 inherited ShowNewContent(NewMode);
229end;
230
231procedure TUnitStatDlg.ShowNewContent_EnemyUnit(NewMode, euix: integer);
232begin
233 Kind := dkEnemyUnit;
234 euixShow := euix;
235 UnitLoc := MyRO.EnemyUn[euix].Loc;
236 inherited ShowNewContent(NewMode);
237end;
238
239procedure TUnitStatDlg.ShowNewContent_EnemyLoc(NewMode, Loc: integer);
240begin
241 Kind := dkEnemyUnit;
242 UnitLoc := Loc;
243 euixShow := -1;
244 inherited ShowNewContent(NewMode);
245end;
246
247procedure TUnitStatDlg.ShowNewContent_EnemyModel(NewMode, emix: integer);
248begin
249 Kind := dkEnemyModel;
250 mox := @MyRO.EnemyModel[emix];
251 inherited ShowNewContent(NewMode);
252end;
253
254procedure TUnitStatDlg.ShowNewContent_EnemyCity(NewMode, Loc: integer);
255begin
256 if MyMap[Loc] and fUnit <> 0 then
257 Kind := dkEnemyCityDefense
258 else
259 Kind := dkEnemyCity;
260 UnitLoc := Loc;
261 euixShow := -1;
262 inherited ShowNewContent(NewMode);
263end;
264
265procedure TUnitStatDlg.FormClose(Sender: TObject; var Action: TCloseAction);
266begin
267 if Kind in [dkOwnModel, dkEnemyModel] then
268 begin
269 UserLeft := Left;
270 UserTop := Top
271 end;
272 if OffscreenUser = self then
273 OffscreenUser := nil;
274end;
275
276procedure TUnitStatDlg.CloseBtnClick(Sender: TObject);
277begin
278 Close
279end;
280
281procedure TUnitStatDlg.OffscreenPaint;
282var
283 PPicture: ^TModelPicture;
284
285 function IsToCount(emix: integer): boolean;
286 var
287 PTestPicture: ^TModelPicture;
288 begin
289 if MainScreen.mNames.Checked then
290 begin
291 PTestPicture := @Tribe[MyRO.EnemyModel[emix].owner].ModelPicture
292 [MyRO.EnemyModel[emix].mix];
293 result := (PPicture.HGr = PTestPicture.HGr) and
294 (PPicture.pix = PTestPicture.pix) and
295 (ModelHash(mox^) = ModelHash(MyRO.EnemyModel[emix]))
296 end
297 else
298 result := (MyRO.EnemyModel[emix].owner = mox.owner) and
299 (MyRO.EnemyModel[emix].mix = mox.mix)
300 end;
301
302 procedure FeatureBar(dst: TBitmap; x, y: integer; const mi: TModelInfo;
303 const T: TTexture);
304 var
305 i, w, dx, num: integer;
306 s: string;
307 begin
308 DarkGradient(dst.Canvas, x - 6, y + 1, 180, 1);
309 with dst.Canvas do
310 if mi.Kind >= $10 then
311 begin
312 s := Phrases.Lookup('UNITSPECIAL');
313 Font.Color := $000000;
314 Textout(x - 1, y + 1, s);
315 Font.Color := $B0B0B0;
316 Textout(x - 2, y, s);
317 end
318 else
319 begin
320 Font.Color := $000000;
321 dx := 2;
322 for i := 3 to nFeature - 1 do
323 begin
324 num := 0;
325 case i of
326 mcSeaTrans:
327 if mi.Domain = dSea then
328 num := mi.TTrans;
329 mcCarrier:
330 if mi.Domain = dSea then
331 num := mi.ATrans_Fuel;
332 mcBombs:
333 num := mi.Bombs;
334 mcFuel:
335 if mi.Domain = dAir then
336 num := mi.ATrans_Fuel;
337 mcAirTrans:
338 if mi.Domain = dAir then
339 num := mi.TTrans;
340 mcFirstNonCap .. nFeature - 1:
341 if mi.Cap and (1 shl (i - mcFirstNonCap)) <> 0 then
342 num := 1
343 end;
344 if (num > 0) and
345 ((i <> mcSE) or (mi.Cap and (1 shl (mcNP - mcFirstNonCap)) = 0))
346 then
347 begin
348 if num > 1 then
349 begin
350 s := IntToStr(num);
351 w := TextWidth(s);
352 Brush.Color := $FFFFFF;
353 FillRect(Rect(x - 3 + dx, y + 2, x + w - 1 + dx, y + 16));
354 Brush.Style := bsClear;
355 Textout(x - 3 + dx + 1, y, s);
356 inc(dx, w + 1)
357 end;
358 Brush.Color := $C0C0C0;
359 FrameRect(Rect(x - 3 + dx, y + 2, x + 11 + dx, y + 16));
360 Brush.Style := bsClear;
361 Sprite(dst, HGrSystem, x - 1 + dx, y + 4, 10, 10,
362 66 + i mod 11 * 11, 137 + i div 11 * 11);
363 inc(dx, 15)
364 end;
365 end
366 end
367 end; { featurebar }
368
369 procedure NumberBarS(dst: TBitmap; x, y: integer; Cap, s: string;
370 const T: TTexture);
371 begin
372 DLine(dst.Canvas, x - 2, x + 170, y + 16, T.clBevelShade, T.clBevelLight);
373 LoweredTextOut(dst.Canvas, -1, T, x - 2, y, Cap);
374 RisedTextout(dst.Canvas, x + 170 - BiColorTextWidth(dst.Canvas, s), y, s);
375 end;
376
377var
378 i, j, x, y, cix, uix, emix, InProd, Available, Destroyed, Loc, Cnt, yView,
379 yTotal, yCaption: integer;
380 s: string;
381 ui: TUnitInfo;
382 mi: TModelInfo;
383begin
384 inherited;
385
386 case Kind of
387 dkOwnModel:
388 begin
389 BitBltCanvas(offscreen.Canvas, 0, 0, wCommon, hOwnModel,
390 Back.Canvas, 0, 0);
391 yView := 13;
392 yTotal := 92;
393 end;
394 dkEnemyModel:
395 begin
396 BitBltCanvas(offscreen.Canvas, 0, 0, wCommon, hEnemyModel,
397 Back.Canvas, wCommon, 0);
398 yView := 13;
399 yTotal := 92;
400 end;
401 dkEnemyUnit, dkOwnUnit:
402 begin
403 BitBltCanvas(offscreen.Canvas, 0, 0, wCommon, hEnemyUnit,
404 Back.Canvas, 2 * wCommon, 0);
405 yView := 13;
406 yTotal := 123;
407 end;
408 dkEnemyCityDefense:
409 begin
410 BitBltCanvas(offscreen.Canvas, 0, 0, wCommon, hEnemyCityDefense,
411 Back.Canvas, 3 * wCommon, 0);
412 yView := 171;
413 yTotal := 231;
414 end;
415 dkEnemyCity:
416 begin
417 BitBltCanvas(offscreen.Canvas, 0, 0, wCommon, hEnemyCity,
418 Back.Canvas, 4 * wCommon, 0);
419 end;
420 end;
421 MarkUsedOffscreen(ClientWidth, ClientHeight);
422 HelpBtn.Top := yTotal + 22;
423
424 if Kind in [dkEnemyCityDefense, dkEnemyCity] then
425 begin // show city defense facilities
426 Cnt := 0;
427 for i := 0 to 3 do
428 if MyRO.EnemyCity[ecixShow].Flags and (2 shl i) <> 0 then
429 inc(Cnt);
430 x := (wCommon - Cnt * xSizeSmall) div 2 - (Cnt - 1) * 2;
431 for i := 0 to 3 do
432 if MyRO.EnemyCity[ecixShow].Flags and (2 shl i) <> 0 then
433 begin
434 case i of
435 0:
436 j := imWalls;
437 1:
438 j := imCoastalFort;
439 2:
440 j := imMissileBat;
441 3:
442 j := imBunker
443 end;
444 Frame(offscreen.Canvas, x - 1, yImp - 1, x + xSizeSmall,
445 yImp + ySizeSmall, MainTexture.clBevelLight,
446 MainTexture.clBevelShade);
447 BitBltCanvas(offscreen.Canvas, x, yImp, xSizeSmall, ySizeSmall,
448 SmallImp.Canvas, j mod 7 * xSizeSmall,
449 (j + SystemIconLines * 7) div 7 * ySizeSmall);
450 inc(x, xSizeSmall + 4)
451 end;
452 end;
453
454 if Kind = dkEnemyModel then
455 begin
456 PPicture := @Tribe[mox.owner].ModelPicture[mox.mix];
457 Available := 0;
458 if G.Difficulty[me] = 0 then // supervisor -- count stacked units too
459 for Loc := 0 to G.lx * G.ly - 1 do
460 begin
461 if MyMap[Loc] and fUnit <> 0 then
462 begin
463 Server(sGetUnits, me, Loc, Cnt);
464 for uix := 0 to Cnt - 1 do
465 if IsToCount(MyRO.EnemyUn[MyRO.nEnemyUn + uix].emix) then
466 inc(Available);
467 end
468 end
469 else // no supervisor -- can only count stack top units
470 for uix := 0 to MyRO.nEnemyUn - 1 do
471 if (MyRO.EnemyUn[uix].Loc >= 0) and IsToCount(MyRO.EnemyUn[uix].emix)
472 then
473 inc(Available);
474 Destroyed := 0;
475 for emix := 0 to MyRO.nEnemyModel - 1 do
476 if IsToCount(emix) then
477 inc(Destroyed, MyRO.EnemyModel[emix].Lost);
478 end
479 else
480 begin
481 Available := 0;
482 for uix := 0 to MyRO.nUn - 1 do
483 if (MyUn[uix].Loc >= 0) and (MyUn[uix].mix = mixShow) then
484 inc(Available);
485 InProd := 0;
486 for cix := 0 to MyRO.nCity - 1 do
487 if (MyCity[cix].Loc >= 0) and
488 (MyCity[cix].Project and (cpImp + cpIndex) = mixShow) then
489 inc(InProd);
490 end;
491
492 offscreen.Canvas.Font.Assign(UniFont[ftSmall]);
493 if Kind in [dkEnemyCityDefense, dkEnemyCity] then
494 begin
495 NoMap.SetOutput(offscreen);
496 NoMap.PaintCity(ClientWidth div 2, 53, MyRO.EnemyCity[ecixShow], false);
497
498 s := Tribe[MyRO.EnemyCity[ecixShow].owner].TPhrase('UNITOWNER');
499 LoweredTextOut(offscreen.Canvas, -1, MainTexture,
500 (ClientWidth - BiColorTextWidth(offscreen.Canvas, s)) div 2, 105, s);
501 end;
502
503 if Kind <> dkEnemyCity then
504 begin // show unit stats
505 if Kind = dkOwnModel then
506 MakeModelInfo(me, mixShow, MyModel[mixShow], mi)
507 else if Kind = dkOwnUnit then
508 begin
509 MakeUnitInfo(me, MyUn[uixShow], ui);
510 MakeModelInfo(me, MyUn[uixShow].mix, MyModel[MyUn[uixShow].mix], mi)
511 end
512 else
513 begin
514 mi := mox^;
515 if Kind in [dkEnemyUnit, dkEnemyCityDefense] then
516 ui := MyRO.EnemyUn[euixShow]
517 end;
518
519 with Tribe[mi.owner].ModelPicture[mi.mix] do
520 begin
521 if Kind in [dkOwnUnit, dkEnemyUnit, dkEnemyCityDefense] then
522 with ui do
523 begin
524 { Frame(offscreen.canvas,xView-1,yView-1,xView+64,yView+48,
525 MainTexture.clBevelShade,MainTexture.clBevelLight);
526 RFrame(offscreen.canvas,xView-2,yView-2,xView+65,yView+49,
527 MainTexture.clBevelShade,MainTexture.clBevelLight); }
528 with offscreen.Canvas do
529 begin
530 Brush.Color := GrExt[HGrSystem].Data.Canvas.Pixels[98, 67];
531 offscreen.Canvas.FillRect(Rect(xView, yView, xView + 64,
532 yView + 16));
533 Brush.Style := bsClear;
534 end;
535
536 if MyMap[Loc] and fTerrain >= fForest then
537 begin
538 x := 1 + 2 * (xxt * 2 + 1);
539 y := 1 + yyt + 2 * (yyt * 3 + 1)
540 end
541 else
542 begin
543 x := integer(MyMap[Loc] and fTerrain) * (xxt * 2 + 1) + 1;
544 y := 1 + yyt
545 end;
546 for j := -1 to 1 do
547 for i := -1 to 1 do
548 if (i + j) and 1 = 0 then
549 begin
550 Sprite(Buffer, HGrTerrain, i * xxt, j * yyt, xxt * 2,
551 yyt * 2, x, y);
552 if MyMap[Loc] and (fTerrain or fSpecial) = fGrass or fSpecial1
553 then
554 Sprite(Buffer, HGrTerrain, i * xxt, j * yyt, xxt * 2, yyt * 2,
555 1 + 2 * (xxt * 2 + 1), 1 + yyt + 1 * (yyt * 3 + 1))
556 else if (MyMap[Loc] and fTerrain = fForest) and
557 IsJungle(Loc div G.lx) then
558 Sprite(Buffer, HGrTerrain, i * xxt, j * yyt, xxt * 2, yyt * 2,
559 1 + 7 * (xxt * 2 + 1), 1 + yyt + 19 * (yyt * 3 + 1))
560 else if MyMap[Loc] and fTerrain >= fForest then
561 Sprite(Buffer, HGrTerrain, i * xxt, j * yyt, xxt * 2, yyt * 2,
562 1 + 7 * (xxt * 2 + 1),
563 1 + yyt + 2 * integer(2 + MyMap[Loc] and fTerrain - fForest)
564 * (yyt * 3 + 1));
565 end;
566 BitBltCanvas(offscreen.Canvas, xView, yView + 16, 64, 32,
567 Buffer.Canvas, 1, 0);
568
569 // show unit, experience and health
570 Sprite(offscreen, HGr, xView, yView, 64, 48, pix mod 10 * 65 + 1,
571 pix div 10 * 49 + 1);
572 if Flags and unFortified <> 0 then
573 Sprite(offscreen, HGrStdUnits, xView, yView, xxu * 2, yyu * 2,
574 1 + 6 * (xxu * 2 + 1), 1);
575 FrameImage(offscreen.Canvas, GrExt[HGrSystem].Data, xView - 20,
576 yView + 5, 12, 14, 121 + Exp div ExpCost * 13, 28);
577 if Health < 100 then
578 begin
579 s := IntToStr(Health) + '%';
580 LightGradient(offscreen.Canvas, xView - 45, yView + 24, 38,
581 (ColorOfHealth(Health) and $FEFEFE shr 2) * 3);
582 RisedTextout(offscreen.Canvas, xView - 45 + 20 -
583 BiColorTextWidth(offscreen.Canvas, s) div 2, yView + 23, s);
584 end;
585
586 if Kind = dkEnemyUnit then
587 begin
588 s := Tribe[mox.owner].TPhrase('UNITOWNER');
589 LoweredTextOut(offscreen.Canvas, -1, MainTexture,
590 (ClientWidth - BiColorTextWidth(offscreen.Canvas, s)) div 2,
591 yView + 80, s);
592 end
593 end
594 else
595 begin
596 FrameImage(offscreen.Canvas, BigImp, xView + 4, yView, 56, 40, 0, 0);
597 Sprite(offscreen, HGr, xView, yView - 4, 64, 44, pix mod 10 * 65 + 1,
598 pix div 10 * 49 + 1);
599 end;
600
601 DarkGradient(offscreen.Canvas, xTotal - 6, yTotal + 1, 180, 2);
602 RisedTextout(offscreen.Canvas, xTotal - 2, yTotal,
603 Phrases.Lookup('UNITSTRENGTH'));
604 s := IntToStr(mi.Attack) + '/' + IntToStr(mi.Defense);
605 RisedTextout(offscreen.Canvas,
606 xTotal + 170 - BiColorTextWidth(offscreen.Canvas, s), yTotal, s);
607 FeatureBar(offscreen, xTotal, yTotal + 19, mi, MainTexture);
608 NumberBarS(offscreen, xTotal, yTotal + 38, Phrases.Lookup('UNITSPEED'),
609 MovementToString(mi.Speed), MainTexture);
610 LoweredTextOut(offscreen.Canvas, -1, MainTexture, xTotal - 2, yTotal + 57,
611 Phrases.Lookup('UNITCOST'));
612 DLine(offscreen.Canvas, xTotal - 2, xTotal + 170, yTotal + 57 + 16,
613 MainTexture.clBevelShade, MainTexture.clBevelLight);
614 if G.Difficulty[me] = 0 then
615 s := IntToStr(mi.cost)
616 else
617 s := IntToStr(mi.cost * BuildCostMod[G.Difficulty[me]] div 12);
618 RisedTextout(offscreen.Canvas,
619 xTotal + 159 - BiColorTextWidth(offscreen.Canvas, s), yTotal + 57, s);
620 Sprite(offscreen, HGrSystem, xTotal + 160, yTotal + 57 + 5, 10,
621 10, 88, 115);
622
623 if Kind = dkOwnModel then
624 begin
625 if MyModel[mixShow].IntroTurn > 0 then
626 begin
627 if MyModel[mixShow].Kind = mkEnemyDeveloped then
628 LoweredTextOut(offscreen.Canvas, -1, MainTexture, xTotal - 2,
629 (yTotal + StatDown - 19), Phrases.Lookup('UNITADOPT'))
630 else
631 LoweredTextOut(offscreen.Canvas, -1, MainTexture, xTotal - 2,
632 (yTotal + StatDown - 19), Phrases.Lookup('UNITINTRO'));
633 DLine(offscreen.Canvas, xTotal - 2, xTotal + 170,
634 (yTotal + StatDown - 19) + 16, MainTexture.clTextShade,
635 MainTexture.clTextLight);
636 s := TurnToString(MyModel[mixShow].IntroTurn);
637 RisedTextout(offscreen.Canvas,
638 xTotal + 170 - BiColorTextWidth(offscreen.Canvas, s),
639 (yTotal + StatDown - 19), s);
640 end;
641
642 NumberBar(offscreen, xTotal, yTotal + StatDown,
643 Phrases.Lookup('UNITBUILT'), MyModel[mixShow].Built, MainTexture);
644 if MyModel[mixShow].Lost > 0 then
645 NumberBar(offscreen, xTotal, yTotal + StatDown + 19,
646 Phrases.Lookup('UNITLOST'), MyModel[mixShow].Lost, MainTexture);
647 if InProd > 0 then
648 NumberBar(offscreen, xTotal, yTotal + StatDown + 57,
649 Phrases.Lookup('UNITINPROD'), InProd, MainTexture);
650 if Available > 0 then
651 NumberBar(offscreen, xTotal, yTotal + StatDown + 38,
652 Phrases.Lookup('UNITAVAILABLE'), Available, MainTexture);
653
654 if MyModel[mixShow].Status and msObsolete <> 0 then
655 begin
656 SwitchBtn.ButtonIndex := 12;
657 SwitchBtn.Hint := Phrases.Lookup('BTN_OBSOLETE');
658 end
659 else
660 begin
661 SwitchBtn.ButtonIndex := 11;
662 SwitchBtn.Hint := Phrases.Lookup('BTN_NONOBSOLETE');
663 end;
664 if MyModel[mixShow].Status and msAllowConscripts = 0 then
665 begin
666 ConscriptsBtn.ButtonIndex := 30;
667 ConscriptsBtn.Hint := Phrases.Lookup('BTN_NOCONSCRIPTS');
668 end
669 else
670 begin
671 ConscriptsBtn.ButtonIndex := 29;
672 ConscriptsBtn.Hint := Phrases.Lookup('BTN_ALLOWCONSCRIPTS');
673 end
674 end
675 else if Kind = dkEnemyModel then
676 begin
677 if Destroyed > 0 then
678 NumberBar(offscreen, xTotal, yTotal + StatDown - 19,
679 Phrases.Lookup('UNITDESTROYED'), Destroyed, MainTexture);
680 if Available > 0 then
681 NumberBar(offscreen, xTotal, yTotal + StatDown,
682 Phrases.Lookup('UNITKNOWN'), Available, MainTexture);
683 end
684 end;
685 end;
686
687 offscreen.Canvas.Font.Assign(UniFont[ftNormal]);
688 case Kind of
689 dkOwnModel, dkEnemyModel:
690 yCaption := yView + 46;
691 dkEnemyUnit, dkOwnUnit:
692 yCaption := yView + 54;
693 dkEnemyCityDefense, dkEnemyCity:
694 yCaption := 79;
695 end;
696 RisedTextout(offscreen.Canvas,
697 (ClientWidth - BiColorTextWidth(offscreen.Canvas, Caption)) div 2,
698 yCaption, Caption);
699end; { OffscreenPaint }
700
701procedure TUnitStatDlg.ModelBoxChange(Sender: TObject);
702begin
703 SmartUpdateContent
704end;
705
706procedure TUnitStatDlg.SwitchBtnClick(Sender: TObject);
707begin
708 MyModel[mixShow].Status := MyModel[mixShow].Status xor msObsolete;
709 if MyModel[mixShow].Status and msObsolete <> 0 then
710 begin
711 SwitchBtn.ButtonIndex := 12;
712 SwitchBtn.Hint := Phrases.Lookup('BTN_OBSOLETE');
713 end
714 else
715 begin
716 SwitchBtn.ButtonIndex := 11;
717 SwitchBtn.Hint := Phrases.Lookup('BTN_NONOBSOLETE');
718 end
719end;
720
721procedure TUnitStatDlg.ConscriptsBtnClick(Sender: TObject);
722begin
723 MyModel[mixShow].Status := MyModel[mixShow].Status xor msAllowConscripts;
724 if MyModel[mixShow].Status and msAllowConscripts = 0 then
725 begin
726 ConscriptsBtn.ButtonIndex := 30;
727 ConscriptsBtn.Hint := Phrases.Lookup('BTN_NOCONSCRIPTS');
728 end
729 else
730 begin
731 ConscriptsBtn.ButtonIndex := 29;
732 ConscriptsBtn.Hint := Phrases.Lookup('BTN_ALLOWCONSCRIPTS');
733 end
734end;
735
736procedure TUnitStatDlg.HelpBtnClick(Sender: TObject);
737begin
738 HelpDlg.ShowNewContent(wmPersistent, hkModel, 0)
739end;
740
741end.
Note: See TracBrowser for help on using the repository browser.