-
Notifications
You must be signed in to change notification settings - Fork 1
/
Map_Lib.pas
1781 lines (1551 loc) · 39.8 KB
/
Map_Lib.pas
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
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
unit Map_Lib;
//VERSION 1.0.1.9
//{$DEFINE DEBUG_LOG}
//{$DEFINE DEBUG2}
interface
//{$DEFINE NOSOUND}
uses
Windows, OpenGL, SysUtils,
Engine_Reg,
Func_Lib,
Type_Lib,
Graph_Lib,
Math_Lib,
MyEntries,
TFKEntries,
MapObj_Lib,
ItemObj_Lib,
ObjAnim_Lib,
ObjSound_Lib,
Constants_Lib,
HUD_Lib,
Weapon_Lib,
Real_Lib,
Stat_Lib,
Demo_Lib,
Scenario_Lib,
Particle_Lib,
Log_Lib,
Player_Lib,
Model_Lib,
LightMap_Lib,
TFKBot_Lib,
NET_Lib,
Phys_Lib;
type
TGameProps = record
sv_gravity : smallint;
fraglimit : WORD;
timelimit : WORD;
end;
type
TCamera = class
Pos : TPoint2f;
View : TPoint2f;
Target : TPlayer;
constructor Create;
procedure Update;
function NextPlayer: boolean;
function PrevPlayer: boolean;
end;
TTeamStat =
record
frags, captures, deaths: integer;
plcount: integer;
end;
TMap = class(TBotMap)
private
//èãðîâûå çâóêè
function Getdemoplay: boolean;
function Getdemorec: boolean;
public
BackGround : TTexData;
gp, lgp : TGameProps;
places: array of TPlayer;
teams: array [0..TEAM_RED] of TTeamStat;
session_number: word;//íîìåð èãðû - ñêîëüêî ðàç äåëàëè ðåñòàðò :)
warmup, not_warmup_game, no_bot_remove: boolean;
property Timelimit: word read gp.timelimit write gp.timelimit;
property Fraglimit: word read gp.fraglimit write gp.fraglimit;
property sv_gravity: smallint read gp.sv_gravity write gp.sv_gravity;
public
Camera : TCamera;
bg_pos : TPoint2f;
stopped, paused: boolean;
leader, exleader: TPlayer;
DefBrkTex: TBricksTexEntry;
scen_0: TTFKScenario;
fade_alpha : single; //0..1.0
fade_out: boolean;
flag_update: boolean;
constructor Create;
destructor Destroy; override;
procedure ClearAll;
procedure CheckDemo;
property demorec: boolean read Getdemorec;
property demoplay: boolean read Getdemoplay;
procedure AfterLoad; override;
procedure BeforeLoad; override;
procedure Restart;
procedure Ready;
procedure ResetGame;
procedure Update;
procedure Draw; // Ïîëíàÿ îòðèñîâêà
procedure SubDraw; // Ðèñóåì áåç èñïîëüçîâàíèÿ êàìåðû
procedure Draw_BackGround;
procedure Draw_Bricks(LMap: boolean; front: boolean); // Áðèêè + LightMap
procedure Draw_Players; // Èãðîêè
procedure Draw_Objects(Plane: TPlane); // Îáúåêòû
//èãðîâûå ïðîöåäóðû
procedure StopGame;
procedure UpdateMatch; // ïðîâåðêà íà êîíåö èãðû è.ò.ï.
function Playing: boolean;
procedure ActivateObjects;
function ActivateTarget(Target: WORD; net_: boolean = false): boolean;
function ActivatePoint(x, y: smallint; sender: TObject; damage: integer = 0): boolean;
procedure ActivateUse(x, y: smallint);
function Quad(UID: integer): integer;
procedure ConsoleShowStats;
procedure UpdateLog;
function TrixMap: boolean;
procedure BrkTexEnable(ID: word; mask: byte);
function SetPlayerModel(UID: integer; modelname: str32; isnet: boolean = true): boolean;
function SetPlayerName(UID: integer; name: str32; isnet: boolean = true): boolean;
procedure Say(UID: integer; saystr: string; isnet: boolean = true);
function IsLightMap: boolean;
function IsClientGame: boolean;
function NewScenario: boolean;
function StopScenario: boolean;
function PlayScenario(target: integer): boolean;
procedure ScenarioSay(UID: integer; saystr: string);
procedure ScenarioList;
procedure TeamJoin(uid, team: byte; net_:boolean=false);
function TeamAuto: byte;override;
procedure TeamCheck;
procedure phys_Update;
// SAVEGAME
procedure SaveGame(filename: string);
function LoadGame(filename, mapfile: string): integer;
function LoadGameFileName(filename: string): string;
end;
var
Map : TMap;
//äëÿ ëîãà
lastdx, lastdy: single;
// Ãëîáàëüíàÿ ïîçèöèÿ óùåé :)
sndPos : TPoint2f;
// Çâóê ïðè ÷àòå...
TalkSound : TSound;
// ïåðåêëþ÷åíèÿ îðóæèÿ
SwitchSound : TSound;
StartSound : TSound;
StopSound : TSound;
//Çâóê Ðåñïàóíà ;)
RespawnSound : TSound;
WarmupSound : TSound;
Warmup1Sound : TSound;
Warmup2Sound : TSound;
Warmup3Sound : TSound;
// âåðí¸ò áóôåð ñ äàííûìè êàðòû
function Map_GetBuffer(const FileName: string; var Size: integer): pointer;
function Map_IsEqMaps(const FileName1, FileName2: string): boolean;
implementation
uses
TFK, Menu_Lib, Bot_Lib, Mouse_Lib, MyMenu, Timing_Lib, NET_Server_Lib, NET_Client_Lib;
procedure Map_InitSound;
begin
StartSound := TSound.Create('sound\game\fight.wav', false, true);
StopSound := TSound.Create('sound\game\gameend.wav', false, true);
RespawnSound := TSound.Create('sound\respawn.wav', false);
TalkSound := TSound.Create('sound\game\talk.wav', false, true);
SwitchSound := TSound.Create('sound\weapons\change.wav', false);
WarmupSound := TSound.Create('sound\game\warmup.wav', false, true);
Warmup1Sound := TSound.Create('sound\game\warmup_1.wav', false, true);
Warmup2Sound := TSound.Create('sound\game\warmup_2.wav', false, true);
Warmup3Sound := TSound.Create('sound\game\warmup_3.wav', false, true);
end;
/////////////////////////
// TCamera
/////////////////////////
constructor TCamera.Create;
begin
Pos := Point2f(0, 0);
Target := nil;
SplitScreen := SPLIT_HORIZ;
end;
procedure TCamera.Update;
begin
with Map do
if (Target<>nil) and
(pl_index(Camera.Target)=-1) then Target:=nil;
if not cam_fixed then
if dis_view then
case SplitScreen of
SPLIT_NONE : View := Point2f(trunc(xglWidth div 2), trunc(xglHeight div 2));
SPLIT_VERT : View := Point2f(trunc(xglWidth div 4), trunc(xglHeight div 2));
SPLIT_HORIZ : View := Point2f(trunc(xglWidth div 2), trunc(xglHeight div 4));
end
else
case SplitScreen of
SPLIT_NONE : View := Point2f(320, 240);
SPLIT_VERT : View := Point2f(160, 240);
SPLIT_HORIZ : View := Point2f(320, 120);
end
else
if dis_view then
View := Point2f(trunc(xglWidth div 2), trunc(xglHeight div 2))
else
View := Point2f(320, 240);
if cam_fixed then
Pos := Point2f(Map.Width * 16, Map.Height * 8)
else
if Target <> nil then
if (cam_smooth = 0) or (splitscreen <> SPLIT_NONE) then
Pos := Target.Pos
else
begin
Pos.X := Pos.X + (Target.Pos.X - Pos.X)/cam_smooth;
Pos.Y := Pos.Y + (Target.Pos.Y - Pos.Y)/cam_smooth;
end
else
begin
if input_KeyDown(VK_LEFT) then Pos.X := Pos.X - cam_speed;
if input_KeyDown(VK_RIGHT) then Pos.X := Pos.X + cam_speed;
if input_KeyDown(VK_UP) then Pos.Y := Pos.Y - cam_speed;
if input_KeyDown(VK_DOWN) then Pos.Y := Pos.Y + cam_speed;
end;
// Çäåñü ýôôåêò Äîïïëåðà òîëüêî âñ¸ òîëüêî èñïîðòèò :)
// if Target.playertype = C_PLAYER_p1 then
// with Target.pstruct.dpos do
// snd_SetGlobalVelocity(Point3f(X * 10, Y * 10, 0));
// ×òîáû êàìåðà äâèãàëàñü ñèíõðîííî ñ ôîíîì :)
// Èç-çà äðîáíûõ ÷èñåë òû ìîã çàìå÷àòü ñäâèã ôîíà îòíîñèòåëüíî
// áðèêîâ è îáúåêòîâ íà êàðòå
// òåïåðü ä¸ðãàåòñÿ òîëüêî èãðîê =)))
// íî ÿ è ýòî èñïðàâèë, ñìîòðè Model.Draw
// XProger: Äà è ýòîãî íå áóäåò...
//Pos.X := trunc(Pos.X);
//Pos.Y := trunc(Pos.Y);
// XProger:
// Åñòü ïîçèöèÿ êàìåðû.
// Pos.X - View.X - left
// Pos.X + View.X - right
// Pos.Y - View.Y - top
// Pos.Y + View.Y - bottom
// Ïî ýòîìó "ðåêòó" îïðåäåëÿåòñÿ âèäèìîñòü îáúåêòà
// Íóæíî ëè åãî îòðèñîâûâàòü...
end;
function TCamera.NextPlayer: boolean;
var
i : integer;
begin
Result := false;
if Map.pl_find(-1, C_PLAYER_LOCAL) then Exit;
Result := true;
if Map.Players = 0 then
begin
Result := false;
Target := nil;
Exit;
end
else
if Target = nil then
begin
Target := Map.Player[0];
Exit;
end;
for i := 0 to Map.Players - 1 do
if Target = Map.player[i] then
begin
if i < Map.Players - 1 then
Target := Map.player[i + 1]
else
Target := nil;
Exit;
end;
end;
function TCamera.PrevPlayer: boolean;
var
i : integer;
begin
Result := false;
if Map.pl_find(-1, C_PLAYER_LOCAL) then Exit;
Result := true;
if Map.Players = 0 then
begin
Result := false;
Target := nil;
Exit;
end
else
if Target = nil then
begin
Target := Map.player[Map.Players - 1];
Exit;
end;
for i := Map.Players - 1 downto 0 do
if Target = Map.player[i] then
begin
if i > 0 then
Target := Map.Player[i - 1]
else
Target := nil;
Exit;
end;
end;
/////////////////////////
// TMap
/////////////////////////
function Map_GetBuffer(const FileName: string; var Size: integer): pointer;
var
Map : TCustomMap;
i : integer;
mh : TMapHeader1;
eh : TEntryHead;
begin
// Äàííàÿ ôóíêöèÿ ñîçäà¸ò áóôåð ñîäåðæèìîãî êàðòû
// áåç äèíàìè÷åñêîé ñåêöèè LightMap
// Ïðåäïîëîæèòåëüíîå íàçíà÷åíèå: ïåðåäà÷à êàðòû ïî ñåòè
Result := nil;
Size := 0;
Map := TCustomMap.Create;
with Map do
begin
if LoadFromFile(FileName) < 0 then
Exit; //Âàõ, íý ïàâýçëî, äà?
// Ïîäñ÷¸ò ðàçìåðà áóôåðà
inc(Size, SizeOf(head));
mh := head;
for i := 0 to EntriesCount - 1 do
with Entries[i] do
if Head.EntryClass <> 'LightMapV1' then
inc(Size, SizeOf(Head) + Head.size)
else mh.ECount:=mh.ECount-1;
// Ñîçäàíèå áóôåðà
GetMem(Result, Size);
Move(mh, Result^, SizeOf(mh));
inc(integer(Result), SizeOf(mh));
for i := 0 to EntriesCount - 1 do
with Entries[i] do
if Head.EntryClass <> 'LightMapV1' then
begin
eh := Head;
Move(eh, Result^, SizeOf(eh));
inc(integer(Result), SizeOf(eh));
Move(TSimpleEntry(entries[i]).buf[0], Result^, eh.size);
inc(integer(Result), eh.size);
end;
dec(integer(Result), Size);
Free;
end;
end;
function Map_IsEqMaps(const FileName1, FileName2: string): boolean;
var
buf1, buf2 : pointer;
size1, size2 : integer;
begin
Result := false;
buf1 := Map_GetBuffer(FileName1, size1);
buf2 := Map_GetBuffer(FileName2, size2);
if (buf1 = nil) or (buf2 = nil) then
Result := Utils_CRC32(4096, buf1, size1) = Utils_CRC32(4096, buf2, size2);
end;
procedure TMap.ClearAll;
begin
CheckDemo;
Clear;
ObjTex_BeginLoad;
ObjTex_EndLoad;
pl_clear;
botdll_Off;
NET_Create(false);
CallMainMenu;
end;
constructor TMap.Create;
begin
inherited Create;
Camera := TCamera.Create;
BackGround.Scale := true;
BackGround.Filter := true;
BackGround.Trans := false;
xglTex_Load(PChar('textures\background\' + bg), @BackGround);
DefbrkTex := TBricksTexEntry.Create;
DefbrkTex.LoadFromFile('textures\box.bmp');
Map_InitSound;
end;
destructor TMap.Destroy;
begin
ClearAll;
Mouse_Dispose;
xglTex_Free(@BackGround);
inherited;
end;
procedure TMap.Update;
var
i : integer;
begin
paused := console.Show and not net_game and not stopped;
if started and (stopped or paused) then
Exit;
if not fade_out then
begin
fade_alpha:=fade_alpha-r_fade_speed/1000;
if fade_alpha<0.0 then fade_alpha:=0.0;
end else
begin
fade_alpha:=fade_alpha+r_fade_speed/1000;
if fade_alpha>1.0 then fade_alpha:=1.0;
end;
//ÀÏÄÅÉÒÈÌ ÊËÀÂÈØÈ ÈÃÐÎÊÎÂ!
if not demoplay then
begin
Timing_Start('NFK Bot update');
for i := low(player) to high(player) do
if @DLL_SYSTEM_UpdatePlayer <> nil then
DLL_SYSTEM_UpdatePlayer(GetNFKPlayer(i));
Timing_End('NFK Bot update');
// Îáíîâëåíèå äëÿ áîòîâ
botdll_mainloop;
bot_update;
end;
//XProger: ÀÕÒÓÍÃ!!!
// ß òî÷íî íå çíàþ êàê ýòî ïîâëèÿåò íà ñåòåâóþ èãðó :)
// È âîáùå, íóæíî ÷àñòü îáíîâëåíèÿ ïåðâîãî èãðîêà ñíåñòè íàôèã
// åñëè ìû â ìåíþ èãðîâîì ñèäèì...
if not inMenu then
pl_update_input;
//ôèçè÷åñêîå ïåðåìåùåíèå èãðîêîâ
pl_update_physic;
//Îáíîâëåíèå... ÄÅÌÊÈ È ÑÖÅÍÀÐÈÅÂ ;)
Timing_Start('Demo update');
Demo.Update;
for i := 0 to EntriesCount - 1 do
if Entries[i] is TTFKScenario then
with TTFKScenario(Entries[i]) do
Update;
Timing_End('Demo update');
if started then
NET.Update_Next;
started := true;
if scen_0 <> nil then
scen_0.Update;
UpdateMatch;
NET.game_Prepare;
pl_update_kill;
if not flag_update then
pl_update_respawn;
flag_update:=false;
//ÎÒÑÛËÀÅÌ ÏÎËÎÆÅÍÈß/ÊËÀÂÈØÈ ÈÃÐÎÊÎÂ :)
WEAPONUPDATE;
for i := 0 to Obj.count-1 do
if Obj[i].fOwner = nil then
Obj[i].Update;
for i := 0 to Obj.count-1 do
if Obj[i].fOwner<>nil then
Obj[i].Update;
Optimize_update;
pl_update;
phys_update;
ActivateObjects;
RealObj_Update;
NET.game_send;
Particle_Update;
for i := 0 to Lights.Count - 1 do
Lights[i].Update;
if WP <> nil then
for i := 0 to WP.Count - 1 do
with WP.WP[i] do
blocked := block_s(X, Y);
Camera.Update;
{$IFDEF DEBUG_LOG}
UpdateLog;
{$ENDIF}
bg_pos.X := bg_pos.X + r_bg_speed_x/10;
bg_pos.Y := bg_pos.Y + r_bg_speed_y/10;
end;
procedure TMap.UpdateMatch;
var
i : integer;
function ComparePlayers(first, second: TPlayer): integer; //ïåðâûé êðó÷å âòîðîãî
begin
if first.team<second.team then Result:= 1
else if first.team>second.team then Result:= -1
else
if first.Stat.Frags < second.Stat.Frags then
Result := -1
else
if first.Stat.Frags = second.Stat.Frags then
Result := 0
else
Result := 1;
end;
procedure QSort(l, h: integer);
var
i, j: integer;
x, t: TPlayer;
begin
if l>=h then Exit;
i:=l;j:=h;x:=places[(l+h) div 2];
while (i<=j) do
if ComparePlayers(places[i], x)=1 then Inc(i)
else if ComparePlayers(places[j], x)=-1 then Dec(j)
else
begin
t:=places[i];places[i]:=places[j];places[j]:=t;
Inc(i);Dec(j);
end;
if l<j then QSort(l, j);
if i<h then QSort(i, h);
end;
begin
SetLength(places, pl_count);
teams[TEAM_BLUE].plcount:=0;
teams[TEAM_BLUE].frags:=0;
teams[TEAM_BLUE].deaths:=0;
teams[TEAM_RED].plcount:=0;
teams[TEAM_RED].frags:=0;
teams[TEAM_RED].deaths:=0;
for i:=0 to pl_count-1 do
begin
places[i]:=player[i];
if player[i].team>0 then
begin
Inc(teams[player[i].team].plcount);
Inc(teams[player[i].team].frags, player[i].stat.Frags);
Inc(teams[player[i].team].deaths, player[i].stat.deaths);
end;
end;
QSort(0, pl_count-1);
if not IsClientGame then
begin
if not warmup then
begin
timelimit := Constants_Lib.timelimit;
fraglimit := Constants_Lib.fraglimit;
if ((timelimit > 0) and
(HUD_GetTime >= timelimit*50*60)) or
((fraglimit > 0) and
(places<>nil) and
( (places[0].Stat^.frags>=fraglimit) or
(teams[TEAM_RED].frags>=fraglimit) or
(teams[TEAM_BLUE].frags>=fraglimit)
)) then
StopGame;
end else
if HUD_GetTime=0 then
begin
Ready;
Exit;
end;
end;
if (gametype = GT_SINGLE) then
begin
if pl_find(-1, C_PLAYER_LOCAL) then
begin
if (HUD_GetTime>50) and
pl_current.dead and
(pl_current.deadticker=49) then
StopGame;
end;
end;
if warmup then
with Camera.Pos do
begin
if HUD_GetTime = 150 then Warmup3Sound.Play(X, Y);
if HUD_GetTime = 100 then Warmup2Sound.Play(X, Y);
if HUD_GetTime = 50 then Warmup1Sound.Play(X, Y);
end;
end;
procedure TMap.StopGame;
var
i : integer;
begin
stopped := true;
Stat_Fix;
for i := low(Player) to high(Player) do
Player[i].Reset;
snd_StopAll(0);
Demo.Stop;
StopSound.Play(Camera.Pos.X, Camera.Pos.Y);
if NET.Type_=NT_SERVER then
net_server.game_stop;
end;
function TMap.Playing: boolean;
begin
Result := not stopped and not paused;
end;
procedure TMap.Draw;
begin
glPushMatrix; //çàïîìèíàåì òåêóùåå ñîñòîÿíèå
// Òðàíñôîðìèðóåì ìàòðèöó âèäà
with Camera do
glTranslatef(trunc(-Pos.X + View.X), trunc(-Pos.Y + View.Y), 0);
SubDraw;
glPopMatrix; //âîçâðàùàåì ñîñòîÿíèå ìàòðèöû íà ïðåæíåå
botdll_Draw;
//ïðîðèñîâêà fade in / out
if fade_alpha > 0 then
begin
xglTex_Disable;
xglAlphaBlend(1);
glColor4f(0, 0, 0, fade_alpha);
with Camera do
begin
glBegin(GL_QUADS);
glVertex2f(0, 0);
glVertex2f(2*View.X, 0);
glVertex2f(2*View.X, 2*View.Y);
glVertex2f(0, 2*View.Y);
glEnd;
end;
end;
end;
procedure TMap.SubDraw;
var
i, j: integer;
begin
if r_bg_draw then
Draw_Background;
// Çàäíèé ïëàí
Draw_Objects(pBack);
RealObj_Draw(pBack);
Particle_Draw(pBack);
Draw_Bricks(false, false);
// Ñðåäíèé ïëàí
Draw_Objects(pNone);
RealObj_Draw(pNone);
Particle_Draw(pNone);
Draw_Players;
//Front Bricks
Draw_Bricks(false, true);
// LightMap
Draw_Objects(pFront);
{ // XProger: òóò áûëè òùåòíûå ïîïûòêè ïðîãåðà ñäåëàòü
// äåéñòâèòåëüíî îñâåùàþùèå ñïðàéòû ñâåòà
// îòêàçàëñÿ ò.ê. 50 ôïñ äà è ãëþ÷èò íå ïî äåöêè
// áóäó èñêàòü äðóãîé ìåòîä :)
}
Draw_Bricks(true, false);
Particle_Draw(pFront);
RealObj_Draw(pFront);
// Áëèêè ñâåòà îò ëàìïî÷åê
for i := 0 to Map.Lights.Count - 1 do
Map.Lights[i].Draw;
xglTex_Disable;
glEnable(GL_BLEND);
glColor4f(1, 1, 1, 1);
xglAlphaBlend(1);
// Ðèñóåì ïðèöåëû
for i := Low(Player) to High(Player) do
Player[i].DrawCrosshair;
if d_waypoints and (WP <> nil) then
with WP do
begin
glPointSize(8);
glEnable(GL_POINT_SMOOTH);
glEnable(GL_LINE_SMOOTH);
xglAlphaBlend(1);
xglTex_Disable;
glColor3f(0.5, 0.5, 0.5);
glBegin(GL_LINES);
for i := 0 to Count - 1 do
for j := 0 to WP[i].Count - 1 do
with WP[i].Link[j] do
begin
glVertex2f(WP[i].X, WP[i].Y);
glVertex2f(WP[idx].X, WP[idx].Y);
end;
glEnd;
glDisable(GL_LINE_SMOOTH);
glColor3f(1, 1, 1);
glBegin(GL_POINTS);
for i := 0 to Count - 1 do
glVertex2f(WP[i].X, WP[i].Y);
glEnd;
if WayLen > 0 then
with self.WP do
begin
glColor3f(0, 0, 1);
glBegin(GL_POINTS);
for i := 0 to WayLen - 1 do
glVertex2f(WP[Way[i]].X, WP[Way[i]].Y);
glEnd;
end;
glDisable(GL_POINT_SMOOTH);
end;
end;
procedure TMap.Draw_Bricks(LMap: boolean; front: boolean);
var
minX, minY : integer;
maxX, maxY : integer;
procedure DrawBricks;
var
lx, ly, rx, ry : integer;
procedure DrawBrick;
begin
//ðèñóåì ïðÿìîóãîëüíèê
glTexCoord2f(0, 1); glVertex2f(lx, ly);
glTexCoord2f(1, 1); glVertex2f(rx, ly);
glTexCoord2f(1, 0); glVertex2f(rx, ry);
glTexCoord2f(0, 0); glVertex2f(lx, ry);
end;
var
x, y : integer;
ID : word; mask: byte;
begin
glColor4f(1, 1, 1, 1);
if not LMap then
begin
xglBegin(GL_QUADS); //Íà÷àòü îòðèñîâêó ÷åòûð¸õóãîëüíûêîâ :)
for y := minY to maxY do
begin
//âû÷èñëåíèå êîîðäèíàòû Y ïîëèãîíà
ly := y*16;
ry := ly + 16;
for x := minX to maxX do
begin
ID := Brk[x, y];
mask := Brk.Mask[x, y];
if (ID > 0) and (mask and MASK_CONTAINER = 0) then
begin
//âû÷èñëåíèå êîîðäèíàòû X ïîëèãîíà
lx := x*32;
rx := lx + 32;
//ðèñóåì
if (Brk.Mask[x, y] and MASK_FRONT > 0)= front then
begin
BrkTexEnable(ID, mask);
DrawBrick;
end;
end;
end;
end;
xglEnd;
end
else
if IsLightmap then
begin
xglAlphaBlend(3);
xglBegin(GL_QUADS);
for y := minY to maxY do
begin
ly := y*16;
ry := ly + 16;
for x := minX to maxX do
begin
lx := x*32;
rx := lx + 32;
//xglTex_Enable(DefBrkTex[Brk[x, y]]);
xglTex_Enable(LightMap.lMapTex[x, y]);
DrawBrick;
end;
end;
xglEnd;
xglAlphaBlend(1);
end;
xglTex_Disable;
end;
var
T, B, L, R : integer;
begin
with Camera do
if dis_view then
begin
minX := trunc(Pos.X) div 32 - (xglWidth + 63) div 64;
minY := trunc(Pos.Y) div 16 - (xglHeight + 31) div 32;
maxX := trunc(Pos.X) div 32 + (xglWidth + 63) div 64;
maxY := trunc(Pos.Y) div 16 + (xglHeight + 31) div 32;
end
else
begin
minX := trunc(Pos.X - View.X) div 32;
minY := trunc(Pos.Y - View.Y) div 16;
maxX := trunc(Pos.X + View.X) div 32;
maxY := trunc(Pos.Y + View.Y) div 16;
end;
L := minX - 1;
R := maxX + 1;
T := minY - 1;
B := maxY + 1;
if minX < 0 then minX := 0;
if minY < 0 then minY := 0;
if maxX > Width - 1 then maxX := Width - 1;
if maxY > Height - 1 then maxY := Height - 1;
//Ðèñóåì òîëüêî âèäèìûå áðèêè
DrawBricks;
// Çàêðàñêà ôîíà - íå îòíîñÿùåãîñÿ ê êàðòå
if IsLightMap and LMap then
begin
xglTex_Disable;
xglAlphaBlend(3);
glColor3ubv(@Fhead.EnvColor);
glBegin(GL_QUADS);
if L <= 0 then // ñëåâà
begin
glVertex2f(L*32, T*16);
glVertex2f(minX*32, T*16);
glVertex2f(minX*32, B*16);
glVertex2f(L*32, B*16);
end;
if T <= 0 then // ñâåðõó
begin
glVertex2f(minX*32, T*16);
glVertex2f(maxX*32+32, T*16);
glVertex2f(maxX*32+32, minY*16);
glVertex2f(minX*32, minY*16);
end;
if R > maxX + 1 then // ñïðàâà
begin
glVertex2f(R*32, T*16);
glVertex2f(maxX*32+32, T*16);
glVertex2f(maxX*32+32, B*16);
glVertex2f(R*32, B*16);
end;
if B > maxY + 1 then // ñâåðõó
begin
glVertex2f(minX*32, B*16);
glVertex2f(maxX*32+32, B*16);
glVertex2f(maxX*32+32, maxY*16+16);
glVertex2f(minX*32, maxY*16+16);
end;
glEnd;
xglAlphaBlend(1);
end;
end;
procedure TMap.Draw_Players;
var
i : integer;
begin
// Ðèñóåì âñåõ èãðîêîâ
for i := Low(Player) to High(Player) do
Player[i].Draw;
end;
procedure TMap.Draw_Objects(Plane: TPlane);
var
i : integer;
ViewRect : TRect;
begin
// Ðèñóåì îáúåêòû
// Ïðè îòðèñîâêå îáúåêòà íåîáõîäèìî ïðîâåðÿòü åãî ïîëîæåíèå
// (áëèæíèé èëè äàëüíèé)
// Òàêæå ïðîâåðÿåòñÿ ïîïàäàíèå åãî â Rect êàìåðû :)
with Camera do
ViewRect := Rect(trunc(Pos.X - View.X), trunc(Pos.Y - View.Y),
trunc(View.X * 2), trunc(View.Y * 2));
for i := 0 to Obj.Count-1 do
if Obj[i].Plane = Plane then
if RectIntersect(RectToMath(Obj[i].ObjRect), RectToMath(ViewRect)) then
try
Obj[i].Draw;
except
Log('Error: while draw ' + Obj[i].ClassName + ' + [' + IntToStr(i) + ']');
end;
end;
procedure TMap.AfterLoad;
begin
inherited;
block_BrkOptimize;
cam_fixed := (Width <= xglWidth div 32) and (Height <= xglHeight div 16);
if Demo = nil then
begin
Demo := TTFKDemo.Create;
SetEntriesSize(EntriesCount + 1);
Entries[EntriesCount - 1] := Demo;
GameCMDOn;
botdll_On;
end
else
begin
GameCMDOff;
botdll_Off;
Demo.playing := true;
end;
// Ñìåíà êàðòû
BotDLL_ChangeMap;