-
Notifications
You must be signed in to change notification settings - Fork 1
/
Player_Lib.pas
2462 lines (2155 loc) · 59.4 KB
/
Player_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 Player_Lib;
//Ïðè äîáàâëåíèè íîâûõ ïàðàìåòðîâ êîòîðûå âëèÿþò íà ÈÃÐÎÂÎÉ ïðîöåññ èñïîëüçóåòå TPlayerStruct
//À â TPlayer ñòàâüòå property ñîîòâ. äàííîìó ñâîéñòâó ;)
{module version 1.0.3.6}
{$DEFINE NFKMODE}
interface
uses
Windows, OpenGL,
Engine_Reg,
Type_Lib,
Math_Lib,
Graph_Lib,
Func_Lib,
Constants_Lib,
Model_Lib,
Real_Lib,
Stat_Lib,
MapObj_Lib,
Binds_Lib,
Particle_Lib,
Phys_Lib,
Mouse_Lib,
NET_Lib,
NET_Client_Lib;
const
MAX_AIR = 40; //â 1/5 ñåêóíäû
WATER_DMG = 18; //ñêîëüêî æèçíåé îòíèìàåòñÿ
WATER_DMGWAIT = 50;
HASTE_SPEED = 1.0;
DEF_HEALTH = 125;
DEF_ARMOR = 0;
DEF_STARTAMMO = 50;
MIN_HEALTH = -30;
DEMO_HEALTH_TIMER = false;
var
Player_Jump5 : single = 1.0;
Player_Jump : single = 4.5;
Player_DJump : single = 6.0;
Player_DJump_time : integer = 20;
Player_run : single = 0.35;
Player_AmplitudeX : single = 1.0;
Player_AmplitudeY : single = 0.3;
Player_Omega : integer = 10;
Player_Extr : integer= 20;
Player_Jump_and_Crouch : single = 0.0;
Jump_plat2 : integer= 20;
player_h_top : integer = -18;
player_h_bottom : integer = 15;
player_Acceleration: single = 0.33;
player_weaponchange: integer = 15;
procedure phys_player_init;
type
TKeySet = set of 0..7; //ãëàâíîå çäåñü - ÐÀÇÌÅÐ!!! - 1 áàéò :)
TPlayerPhys = record
pos_x, pos_y : WORD;
dpos_x, dpos_y : ShortInt;
angle : WORD;
Keys : TKeySet;
crouch, onground : boolean;
omega, jump_stage: Byte;
weapon : Byte;
end;
TPlayerStruct = record
UID : Byte;
Pos : TPoint2f; //ïîçèöèÿ
dpos : TPoint2f; //ñêîðîñòü (ÁÛÂØÀß inertia) d- ýòî äèôôåðåíöèàë :)
crouch : boolean;
left : boolean;
dead, balloon: boolean;
fangle : SmallInt;
//ïåðåìåííûå îðóæèÿ è òèêåðû
HTicker : WORD;
SwitchTicker : WORD;
ReloadTicker : WORD;
lastrail : Byte;
lastfrag : Byte;
Has_wpn, Ammo : TWpnArray;
PowerUps : TPowerUpArray;
cur_weapon, cur_wpn, next_weapon: Byte;
//çäîðîâüå è áðîíÿ
Health: SmallInt;
Armor: SmallInt;
Name, ModelName : str32;
airticker: byte;
team : byte;
railcolor: TRGB;
railtype : byte;
reserved: array [0..2] of byte;
end;
(*** TPlayer ***)
TPlayer = class
private
//çäîðîâüå è áðîíÿ
procedure SetArmor(const Value: SmallInt);
procedure SetHealth(const Value: SmallInt);
function GetMY: integer;
function GetAngleChanged: boolean;
function GetKeysChanged: boolean;
function Get_byte_Health: byte;
procedure Set_byte_Health(const Value: byte);
function GetBalloon: boolean;
procedure SetBalloon(const Value: boolean);
procedure SetStruct(const Value: TPlayerStruct);
protected
//äâèæåíèå
can_jump, can_fly: boolean;
ph: TPhysRect;
deltablock : boolean;
maxspeedx: single;
jump_stage, jumpticker: byte;
jumping: boolean;
prevangle: word;
omega, lastextremum: byte;
function GetOmegaValue: single;
public
w_level: integer;
in_water: boolean;//èãðîê óïàë â âîäó - èëè íàîáîðîò âûáðàëñÿ...
onground, stayground: boolean; //ïåðâîå- òî ÷òî èãðîê íà ïëîùàäêå.
private
procedure CalcRect;
procedure CalcWaterLevel;
function CheckOnGround: boolean;
function CheckOnGround2: boolean; //PQR
public
procedure NetMove;
procedure NeoMove;
procedure DemoMove;
procedure FindGround(delta, deep: integer);
public
client: TClient;
current_ping: word;
lasthitid: word;
fireticker: byte;
netbuf: array [0..5] of TPlayerPhys;
net_recv: boolean;
net_moved: integer;
//ñåòåâûå ôóíêöèè
function IsNET: boolean;
function IsClient: boolean;
procedure Setpos(rec: TPlayerPhys); overload;
procedure Setpos(rec: TPlayerPhys; ticks: integer); overload;
procedure Getpos(var rec: TPlayerPhys);
public
function Get_word_pos_x: word;
function Get_word_pos_y: word;
procedure Set_word_pos_x(value: word);
procedure Set_word_pos_y(value: word);
function Get_short_dpos_x: shortint;
function Get_short_dpos_y: shortint;
procedure Set_short_dpos_x(value: shortint);
procedure Set_short_dpos_y(value: shortint);
property byte_Health: byte read Get_byte_Health write Set_byte_Health;
property word_pos_x: word read Get_word_pos_x write Set_word_pos_x;
property word_pos_y: word read Get_word_pos_y write Set_word_pos_y;
property short_dpos_x: shortint read Get_short_dpos_x write Set_short_dpos_x;
property short_dpos_y: shortint read Get_short_dpos_y write Set_short_dpos_y;
protected
//ñåêöèÿ äëÿ äåìîê
//ÄËß ÄÅÌÊÈ
lastwpn: byte;
lastkeys: TKeySet;
lastangle: smallint;
fstruct: TPlayerStruct;
fhited: boolean;
function GetKeys: TKeySet;
procedure SetKeys(value: TKeySet);
function GetMoved: boolean;
function GetWPNChanged: boolean;
public
fmoved: boolean;
fSquished: boolean;
property Moved: boolean read GetMoved write fmoved;
property WPNChanged: boolean read GetWPNChanged;
property AngleChanged: boolean read GetAngleChanged;
property KeysChanged: boolean read GetKeysChanged;
property pstruct: TPlayerStruct read fStruct write SetStruct;
property Keys: TKeySet read GetKeys write SetKeys;
property Squished: boolean read fSquished;
function HealthChanged: boolean;
public
//gauntlet
gauntlet: TParticle;
gauntletsnd: integer;//çâóê ãàóíòëåòà.
procedure GauntletON;
procedure GauntletOFF;
public
AI: TObject;
dead_mode: boolean;
public
Stat : PPlayerStat; //ÑÒÀÒÈÑÒÈÊÀ
Key : TKeyArray; //LKey - ñòàðûå êëàâèøè
UseMouse: boolean;
playertype, localtype: byte;
fRect: TRect; //ÐÅÊÒ ÈÃÐÎÊÀ - ÎÁÍÎÂËßÅÒÑß Â UPDATE!!!
quadtimer : integer; //Âðåìÿ ïðîèãðûâàíèÿ çâóêà!!!
regentimer : integer; //Òèêåð ðåãåíåðàöèè
hastetimer : integer; //õèõè, à ýòî ó íàñ ÄÛÌÎÊ :)
fly_snd : integer;
// äëÿ îòðèñîâêè íàãðàä
rewards_ticker : array [0..2] of integer;
//æä¸ò ëè èãðîê ðåñïàóíà
resp : boolean;
respindex : word;
//XProger: òåêóùèé êàäð àíèìàöèè ïóøêè, è âðåìÿ äî ñëåäóþùåãî (â òèêàõ)
weapon_frame, weapon_frame_wait : integer; //Neoff: ìîæåò ëó÷øå TObjTex.Update?
weapon_fire : boolean;
//Neoff: ØËÅÉÔ ØÀÔÒÀ!!! nil - çíà÷èò ñåé÷àñ íå ñòðåëÿåì
shaft : TShaftShot;
///////
Model : TModel; // òóò äîëæåì áûòü êîíÒåéòåð êàêîé-íèòü... òèïà TBaseModel
lasthit : integer; // Âðåìÿ äî õèò ñàóíäà
//òèêåð ÑÌÅÐÒÈ - ñêîëüêî èãðîê âûëÿåòñÿ áåç ñîçíàíèÿ...
deadticker: word;
//òèêåð ÆÈÇÍÈ - ñ êàêèõ ïîð èãðîê æèâ :)
liveticker: word;
fshot: boolean; //äîëæåí ëè èãðîê ñòðåëÿòü ïîñëå ýòîãî òèêà
//ïîñëåäíÿÿ ñìåíà îðóæèÿ...
lastwpnchange: byte;
//ïëàâíûé óãîë
sangle: single;
//òåêóùàÿ ïîçèöèÿ ñòðåëüáû
shotpos : TPoint2f;
//ÊÒÎ ÏÎÑËÅÄÍÈÉ ïîïàë â èãðîêà
hit_UID : integer;
hit_weapon : integer;
procedure SetLeft(Value: boolean);
//èäåíòèôèêàòîð
property UID : byte read fstruct.uid;
//êîìàíäà
property team: byte read fstruct.team write fstruct.team;
//ïîçèöèÿ
property Pos: TPoint2f read fstruct.Pos write fstruct.Pos;
//ñêîðîñòü
property dPos: TPoint2f read fstruct.dPos write fstruct.dPos;
//ïîâåðíóò íàëåâî?
property left: boolean read fstruct.left write SetLeft;
//ñìåðòü?
property dead: boolean read fstruct.dead write fstruct.dead;
//ñèäèò?
property Crouch : boolean read fstruct.Crouch write fstruct.Crouch;
//à òåïåðü îðóæèå
property Has_wpn: TWPNArray read fstruct.Has_wpn write fstruct.Has_wpn;
property Ammo: TWpnArray read fstruct.Ammo write fstruct.Ammo;
property PowerUps: TPowerUpArray read fstruct.powerups write fstruct.powerups;
property cur_weapon : byte read fstruct.cur_weapon write fstruct.cur_weapon;
property cur_wpn : byte read fstruct.cur_wpn write fstruct.cur_wpn;
property next_weapon: byte read fstruct.next_weapon write fstruct.next_weapon;
//òèêåð çäîðîâüÿ è áðîíè
property HTicker: word read fstruct.HTicker write fstruct.HTicker;
//òèêåð ñìåíû îðóæèÿ íà ñëåäóþùåå - down, ïî-óìîë÷àíèþ MAX!!!
property SwitchTicker: word read fstruct.SwitchTicker write fstruct.SwitchTicker;
//òèêåð ïåðåçàðÿäêè - down, ïî-óìîë÷àíèþ 0
property ReloadTicker: word read fstruct.ReloadTicker write fstruct.ReloadTicker;
//êîëè÷åñòâî ïîïàäàíèé èç ðåëüñû
property lastrail: byte read fstruct.lastrail write fstruct.lastrail;
//ñêîëüêî âðåìåíè íàçàä áûë âûáèò ôðàã. -1 = ôðàãà íå áûëî
property lastfrag: byte read fstruct.lastfrag write fstruct.lastfrag;
//ÇÄÀÐÎÂÜÅ!!F!
function GetHealth: smallint;
function GetArmor: smallint;
property Health : SmallInt read GetHealth write SetHealth;
property Armor : SmallInt read GetArmor write SetArmor;
function GetAngle: single;
procedure SetAngle(value: single);
function GetAbsAngle: single;
procedure SetAbsAngle(value: single);
property Angle: single read GetAngle write SetAngle;
property AbsAngle: single read GetAbsAngle write SetAbsAngle;
property fAngle: smallint read fstruct.fAngle write fstruct.fAngle;
property Name : str32 read fstruct.Name write fstruct.Name;
property ModelName : str32 read fstruct.ModelName write fstruct.ModelName;
property railcolor : TRGB read fstruct.railcolor write fstruct.railcolor;
property railtype : byte read fstruct.railtype write fstruct.railtype;
property balloon: boolean read GetBalloon write SetBalloon;
// rasprigka
property AirTicker: byte read fstruct.AirTicker write fstruct.AirTicker;
constructor Create(ptype: integer; uid: byte; team_: byte =0);
destructor Destroy; override;
procedure Restart;//ÐÅÑÒÀÐÒ ÏËÝÉÅÐÀ!!!
function LoadFromFile(const ModelName: string): boolean;
function GetCurPrevWeapon: word;//ÏÐÅÄÛÄÓÙÅÅ ïîñëå äàííîãî îðóæèå
function GetCurNextWeapon: word;//ÑËÅÄÓÞÙÈÅ îðóæèå
procedure SetWeapon(value: byte);
procedure MoveTo(x0, y0: word);
procedure MoveBy(dx0, dy0: smallint);
function TakeHealth(health_: word): boolean;
function TakeArmor(armor_: word): boolean;
function TakeWpn(wpnID, count: word; mode: byte): boolean;
function TakeAmmo(wpnID, count: word): boolean;
function TakePowerUp(itemID, count: word): boolean;
//ôóíêöèÿ áóäåò âûçûâàòüñÿ òîëüêî ÈÇ weapon_lib. ÍÅÏÎÑÐÅÄÑÒÂÅÍÍÛÉ ÂÛÇÎÂ
//ÒÎËÜÊÎ ÅÑËÈ ÓÐÎÍ ÏÐÈ×ÈÍÅÍ ÑÂÅÐÕÚÅÑÒÅÑÒÂÅÍÍÛÌ ÑÏÎÑÎÁÎÌ. - Neo...
//ÂÑÏÎÌÍÈË!!! ØÀÔÒ ÝÒÎ ÈÑÏÎËÜÇÓÅÒ!!!
function Hit(damage, playerUID: integer): integer;
function HitWater(damage, playerUID: integer): integer;
procedure Push0(sx, sy: single);
procedure Push(x0, y0, s: single);
procedure Push2(x0, y0, s: single);
procedure RotateX;
procedure RotateY;
//Õåõå, ïðîùàé èãðîê...
procedure Kill;
procedure SquishKill;
procedure Reset;
procedure PrevUpdate;
procedure Update; //îáíîâëåíèå
procedure UpdateMove;
procedure UpdateShot;
procedure UpdateTickers;
procedure Draw; //îòðèñîâêà
procedure DrawCrosshair;
property MY: integer read GetMY;
function Fly: boolean;
function Quad: integer;
public
end;
function IncMax(var x: single; dx, max: single): boolean;
function IncMin(var x: single; dx, min: single): boolean;
function GetShotY(crouch: boolean): integer;
implementation
uses
Map_Lib, TFK, ItemObj_Lib, ObjSound_Lib,
Weapon_Lib, TFKBot_Lib, Log_Lib, Menu_Lib, SysUtils_;
procedure phys_player_init;
var
i: byte;
begin
phys_register('player_deltaspeed', @player_jump5, VT_FLOAT);
phys_register('player_jump', @player_jump, VT_FLOAT);
phys_register('player_jump_and_crouch', @player_jump_and_crouch, VT_FLOAT);
phys_register('player_doublejump', @player_DJump, VT_FLOAT);
phys_register('player_doublejump_time', @player_DJump_time, VT_INTEGER);
phys_register('player_run', @player_run, VT_FLOAT);
phys_register('player_frequency', @player_extr, VT_INTEGER);
phys_register('player_speedjump_x', @Player_AmplitudeX, VT_FLOAT);
phys_register('player_speedjump_y', @Player_AmplitudeY, VT_FLOAT);
phys_register('player_h_bottom', @Player_h_bottom, VT_INTEGER);
phys_register('player_h_top', @Player_h_top, VT_INTEGER);
for i:=0 to WPN_Count-1 do
phys_register('reload_'+WPN_NAMES[i], @Reload_Wait[i], VT_WORD);
phys_register('player_acceleration', @Player_acceleration, VT_FLOAT);
phys_register('player_weaponchange', @Player_weaponchange, VT_INTEGER);
end;
function IncMax(var x: single; dx, max: single): boolean;
begin
Result := false;
if signf(x - max) < 0 then
begin
x := x + dx;
if signf(x - max)>0 then
x := max;
end;
end;
function IncMin(var x: single; dx, min: single): boolean;
begin
Result := false;
if signf(x - min) > 0 then
begin
x := x + dx;
if signf(x - min) < 0 then
x := min;
end;
end;
function GetShotY(crouch: boolean): integer;
const
stay = -8;
sit = 0;
begin
if crouch then
Result := sit
else
Result := stay;
end;
/////////////////////////
// TPlayer
/////////////////////////
{ TPlayer }
function TPlayer.Get_word_pos_x: WORD;
begin
with fstruct.Pos do
if X < 0 then
Result := 0
else
Result := round(X * C_ROUND);
end;
function TPlayer.Get_word_pos_y: WORD;
begin
with fstruct.Pos do
if Y < 0 then
Result := 0
else
Result := round(Y * C_ROUND);
end;
procedure TPlayer.Set_word_pos_x(value: WORD);
begin
fstruct.Pos.X := value/C_ROUND;
end;
procedure TPlayer.Set_word_pos_y(value: WORD);
begin
fstruct.Pos.Y := value/C_ROUND;
end;
// Ñëåäóþùèå 2 ôóíêöèè íåìíîãî ðàçãðóæàþò êîä...
function Short_Getdpos(x: single): ShortInt;
var
r: integer;
begin
r := round(x * S_ROUND);
if r > 64 then
r := r div 2 + 32
else
if r < -64 then
r := -(abs(r) div 2) - 32;
if r > 127 then r := 127;
if r < -128 then r := -128;
Result := r;
end;
function Short_Setdpos(value: ShortInt): single;
begin
if value > 64 then
Result := (value * 2 - 64)/S_ROUND
else
if value < -64 then
Result := (value * 2 + 64)/S_ROUND
else
Result := value/S_ROUND;
end;
function TPlayer.Get_short_dpos_x: shortint;
begin
Result := Short_Getdpos(fstruct.dpos.X);
end;
function TPlayer.Get_short_dpos_y: shortint;
begin
Result := Short_Getdpos(fstruct.dpos.Y);
end;
procedure TPlayer.Set_short_dpos_x(value: ShortInt);
begin
fstruct.dpos.X := Short_Setdpos(value);
end;
procedure TPlayer.Set_short_dpos_y(value: shortint);
begin
fstruct.dpos.Y := Short_Setdpos(value);
end;
function TPlayer.Get_byte_Health: byte;
begin
if fstruct.health<MIN_HEALTH then
Result:=0
else Result:=fstruct.health-MIN_HEALTH;
end;
procedure TPlayer.Set_byte_Health(const Value: byte);
begin
fstruct.health:=smallint(value)+MIN_HEALTH;
end;
procedure TPlayer.Getpos(var rec: TPlayerPhys);
begin
with fstruct do
begin
rec.pos_x := word_pos_x;
rec.pos_y := word_pos_y;
rec.dpos_x := short_dpos_x;
rec.dpos_y := short_dpos_y;
rec.angle := fangle;
rec.omega := omega;
if jump_stage<8 then
rec.jump_stage:=jump_stage
else rec.jump_stage:=7;
rec.keys := Keys;
if crouch then
rec.Keys := rec.Keys + [KEY_DOWN];
if (cur_weapon<>next_weapon) and not (cur_weapon in [WPN_SHAFT, WPN_GAUNTLET]) then
rec.Keys := rec.Keys - [KEY_FIRE];
rec.onground := onground;
rec.crouch := crouch;
rec.weapon := cur_weapon;
end;
end;
procedure TPlayer.Setpos(rec: TPlayerPhys);
begin
with fstruct do
begin
AbsAngle := rec.angle;
omega := rec.omega;
Keys := rec.Keys;
crouch := rec.crouch;
if (rec.pos_x<>0) or
(rec.pos_y<>0) or
(rec.dpos_x<>0) or
(rec.dpos_y<>0) then
begin
word_pos_x := rec.pos_x;
word_pos_y := rec.pos_y;
short_dpos_x := rec.dpos_x;
short_dpos_y := rec.dpos_y;
jump_stage:=rec.jump_stage;
SetWeapon(rec.weapon);
end;
end;
end;
procedure TPlayer.Setpos(rec: TPlayerPhys; ticks: integer);
var
j : integer;
dx, dy : single;
begin
SetPos(rec);
if rec.onground then
FindGround(3, 4);
GetPos(rec);
if ticks = 0 then
begin
SetPos(netbuf[0]);
// dx:=(pos.x-rec.pos_x/C_ROUND)*0.2;
// dy:=(pos.y-rec.pos_y/C_ROUND)*0.2;
dx := 0;
dy := 0;
SetPos(rec);
with fstruct.Pos do
begin
X := X + dx;
Y := Y + dy;
end;
GetPos(netbuf[0]);
Exit;
end;
netbuf[ticks] := rec;
if ticks > 0 then
begin
SetPos(netbuf[0]);
j := 0;
while j < ticks do
begin
NeoMove;
inc(j);
end;
dx := (rec.pos_x/C_ROUND - Pos.X)/ticks;
dy := (rec.pos_y/C_ROUND - pos.Y)/ticks;
SetPos(netbuf[0]);
j := 1;
while j < ticks do
begin
NeoMove;
with fstruct.Pos do
begin
X := X + dx;
Y := Y + dy;
end;
GetPos(netbuf[j]);
inc(j);
end;
end;
end;
//ôóíêöèè äëÿ äåìîê
function TPlayer.GetKeys: TKeySet;
var
b : byte;
begin
Result := [];
for b := 0 to 7 do
if Key[b].Down then
Result := Result + [b];
if not dead and (next_weapon <> cur_weapon) then
Result := Result - [KEY_FIRE];
end;
procedure TPlayer.SetKeys(value: TKeySet);
var
b : byte;
begin
for b := 0 to 7 do
Key[b].Down := b in value;
end;
function TPlayer.GetMoved: boolean;
begin
Result := fmoved;
fmoved := false;
end;
function TPlayer.GetWPNChanged: boolean;
begin
Result := lastwpn <> cur_weapon;
lastwpn := cur_weapon;
end;
function TPlayer.HealthChanged: boolean;
begin
Result := fhited;
fhited := false;
end;
function TPlayer.GetAngleChanged: boolean;
begin
Result := lastangle <> fangle;
lastangle := fangle;
end;
function TPlayer.GetKeysChanged: boolean;
begin
Result := ((KEY_LEFT in Keys) <> (KEY_LEFT in lastkeys)) or
((KEY_RIGHT in Keys) <> (KEY_RIGHT in lastkeys)) or
((KEY_UP in Keys) <> (KEY_UP in lastkeys)) or
((KEY_DOWN in Keys) <> (KEY_DOWN in lastkeys)) or
((KEY_BALLOON in Keys) <> (KEY_BALLOON in lastkeys));
lastkeys := Keys;
end;
//îáû÷íûå ôóíêöèè
constructor TPlayer.Create(ptype: integer; uid: byte; team_: byte);
begin
Self.playertype:=ptype;
if ptype=C_PLAYER_P1 then
begin
railcolor:=r_rail_color;
railtype:=r_rail_type;
end
else if ptype=C_PLAYER_P2 then
begin
railcolor:=r_p2_rail_color;
railtype:=r_p2_rail_type;
end
else
begin
railcolor:=r_enemy_rail_color;
railtype:=r_enemy_rail_type;
end;
fstruct.uid:=uid;
team:=team_;
if ptype and C_PLAYER_TFKBOT > 0 then
begin
// AI := TTFKBot.Create;
AI:=TAlienShaftBot.Create;
TTFKBot(AI).pl := Self;
end
else
AI := nil;
Model := TModel.Create;
lasthitid:=0;
current_ping:=0;
rewards_ticker[0] := 0;
rewards_ticker[1] := 0;
rewards_ticker[2] := 0;
end;
destructor TPlayer.Destroy;
begin
if shaft <> nil then
shaft.Kill;
gauntletOFF;
Model.Free;
end;
function TPlayer.LoadFromFile(const ModelName: string): boolean;
begin
// ÍÓ Î×ÅÍÜ êðèâàÿ çàãðóçêà...
//Neo: à ïî-ìîåìó íîðìàëüíàÿ. Êàê áû âñå â exception ïåðåäåëàòü...
// XProger: íåìíîãî ïîèçâðàùàëñÿ - äîëæíî ðàáîòàòü...
Result := Model.LoadFromFile(ModelName);
if Result then
fstruct.ModelName := ModelName
else
if not Model.LoadFromFile(fstruct.ModelName) then
begin
Model.LoadFromFile('sarge+default');
fstruct.ModelName := 'sarge+default';
end;
end;
//ÔÈÇÈÊÀ
procedure TPlayer.CalcRect;
begin
with ph do
if crouch then
fRect := Rect(trunc(pos.X - 8), trunc(pos.Y - 8), 16, 32)
else
fRect := Rect(trunc(pos.X - 9), trunc(pos.Y - 24), 18, 48);
end;
function TPlayer.CheckOnGround: boolean;
begin
with Map, ph do
onground := ( (block_Dot_Product(Pos.X - 9, pos.Y + 25, 0, -4, jump_plat2 div 4) = 2) or
(block_Dot_Product(Pos.X - 5, pos.Y + 25, 0, -4, jump_plat2 div 4) = 2) or
(block_Dot_Product(Pos.X + 5, pos.Y + 25, 0, -4, jump_plat2 div 4) = 2) or
(block_Dot_Product(Pos.X + 9, pos.Y + 25, 0, -4, jump_plat2 div 4) = 2) );
Result := onground;
end;
//PQR
function TPlayer.CheckOnGround2: boolean;
begin
with Map, ph do
onground := (block_Dot_Product(Pos.X - 9 + dPos.X, pos.Y + 25, 0, -4, jump_plat2 div 4) = 2) or
(block_Dot_Product(Pos.X - 5 + dPos.X, pos.Y + 25, 0, -4, jump_plat2 div 4) = 2) or
(block_Dot_Product(Pos.X + 5 + dPos.X, pos.Y + 25, 0, -4, jump_plat2 div 4) = 2) or
(block_Dot_Product(Pos.X + 9 + dPos.X, pos.Y + 25, 0, -4, jump_plat2 div 4) = 2);
Result := onground;
end;
procedure TPlayer.CalcWaterLevel;
begin
with Map, ph do
w_level := Byte(block_Water_s(Pos.X, Pos.Y + 18))+
Byte(block_Water_s(Pos.X, Pos.Y + 7)) +
Byte(block_Water_s(Pos.X, Pos.Y + 4)) +
Byte(block_Water_s(Pos.X, Pos.Y - 7)) +
Byte(block_Water_s(Pos.X, Pos.Y));
end;
procedure TPlayer.NetMove;
begin
if not net_recv then
NeoMove
else
begin
ph.dpos := dpos;
ph.pos := pos;
net_recv:= false;
CheckOnGround;
crouch := KEY[KEY_DOWN].Down and onground;
CalcRect;
end;
Move(netbuf[low(netbuf)], netbuf[low(netbuf)+1], sizeof(netbuf)-sizeof(Tplayerphys));
GetPos(netbuf[0]);
end;
procedure TPlayer.FindGround(delta, deep: integer);
var
i : integer;
begin
ph.pos := pos;
ph.dpos := dpos;
CheckOnGround;
for i := 1 to deep do
begin
if onground then
break;
ph.pos.Y := ph.pos.Y + delta;
CheckOnGround;
end;
if onground then
begin
with ph do
if crouch then
begin
x1 := -8; x2 := 8;
Vy1 := -8; Vy2 := 24;
Hy1 := -2; Hy2 := 15;
end
else
begin
x1 := -8; x2 := 8;
Vy1 := -24; Vy2 := 24;
Hy1 := player_h_top;
Hy2 := player_h_bottom;
end;
Map.phys_cliptest(ph);
pos := ph.pos;
dpos := ph.dpos;
end;
end;
procedure TPlayer.DemoMove;
function BrickOnHead: boolean;//head.
begin
with Map, ph do
Result:=(block_Dot_Product(Pos.X-8, pos.Y-26, 0, 2, 4) = 2) or
(block_Dot_Product(Pos.X-4, pos.Y-26, 0, 2, 4) = 2) or
(block_Dot_Product(Pos.X+4, pos.Y-26, 0, 2, 4) = 2) or
(block_Dot_Product(Pos.X+8, pos.Y-26, 0, 2, 4) = 2);
end;
function BrickOnHead2: boolean;//head.
begin
with Map, ph do
Result:=(block_Dot_Product(Pos.X-4, pos.Y-26, 0, 2, 4) = 2) or
(block_Dot_Product(Pos.X+4, pos.Y-26, 0, 2, 4) = 2);
end;
function BrickCrouchOnHead: boolean;
begin
with Map, ph do
Result:=(block_Dot_Product(Pos.X-8, pos.Y-22, 0, 2, 4) <> 1) or
(block_Dot_Product(Pos.X-4, pos.Y-22, 0, 2, 4) <> 1) or
(block_Dot_Product(Pos.X+4, pos.Y-22, 0, 2, 4) <> 1) or
(block_Dot_Product(Pos.X+8, pos.Y-22, 0, 2, 4) <> 1);
end;
function CheckJumping: boolean;
begin
can_jump := (CheckOnGround or CheckOnGround2) and
(not BrickCrouchOnHead and not BrickOnHead or deltablock and not crouch and
not BrickOnHead2);
Result := can_jump;
end;
begin
ph.pos := pos;
CalcWaterLevel;
CheckOnGround;
crouch := KEY[KEY_DOWN].Down and onground;
CalcRect;
CheckJumping;
//èìèòàöèÿ ïðûæêà íà äåìêå...
if can_jump and KEY[KEY_UP].Down and not phys_flag then
begin
jumping:=true;
if not brickonhead and
(jumpticker>=8) then
Model.Sound.Jump.Play(Pos.X, Pos.Y);
jumpticker:=0;
end;
end;
procedure TPlayer.NeoMove;
function BrickOnHead: boolean;//head.
begin
with Map, ph do
Result:=(block_Dot_Product(Pos.X-8, pos.Y-26, 0, 2, 4) = 2) or
(block_Dot_Product(Pos.X-4, pos.Y-26, 0, 2, 4) = 2) or
(block_Dot_Product(Pos.X+4, pos.Y-26, 0, 2, 4) = 2) or
(block_Dot_Product(Pos.X+8, pos.Y-26, 0, 2, 4) = 2);
end;
function BrickOnHead2: boolean;//head.
begin
with Map, ph do
Result:=(block_Dot_Product(Pos.X-4, pos.Y-26, 0, 2, 4) = 2) or
(block_Dot_Product(Pos.X+4, pos.Y-26, 0, 2, 4) = 2);
end;
function BrickCrouchOnHead: boolean;
begin
with Map, ph do
Result:=(block_Dot_Product(Pos.X-8, pos.Y-22, 0, 2, 4) <> 1) or
(block_Dot_Product(Pos.X-4, pos.Y-22, 0, 2, 4) <> 1) or
(block_Dot_Product(Pos.X+4, pos.Y-22, 0, 2, 4) <> 1) or
(block_Dot_Product(Pos.X+8, pos.Y-22, 0, 2, 4) <> 1);
end;
//ôóíêöèÿ ïðîâåðêè âîäû:
//íà ñêîëüêî èãðîê ïîãðóæ¸í:
//0 - âîîáùå íå ïîãðóæ¸í.
//1 - äî òðåòè
//2 - äî òð¸õ âîñüìûõ
//3 - äî ïîëîâèíû
//4 - äî äâóõ òðåòåé
//5 - áîëüøå
//WATER_LEVEL ïåðåíåñ¸í íåïîñðåäñòâåííî â êëàññ
var
lastpos: TPoint2f;
pp: TPhysicParams;
function CheckJumping: boolean;
begin
can_jump := (CheckOnGround or CheckOnGround2) and
(not BrickCrouchOnHead and not BrickOnHead or deltablock and not crouch and
not BrickOnHead2);
Result := can_jump;
end;
function CheckFly: boolean;
begin
// XProger: õûõûõû :)
can_fly := {not BrickCrouchOnHead and not BrickOnHead and} (fly or pp.flight);
Result := can_fly;
end;
begin
ph.dpos := dpos;
ph.pos := pos;
with fstruct, ph do
begin
CalcWaterLevel;
Map.phys_gravity(ph);
Map.phys_params(pos.x, pos.y, pp);
if dpos.x < pp.minspeed.X then dpos.X := pp.minspeed.X;
if dpos.x > pp.maxspeed.X then dpos.X := pp.maxspeed.X;
if dpos.y < pp.minspeed.Y then dpos.Y := pp.minspeed.Y;
if dpos.y > pp.maxspeed.Y then dpos.Y := pp.maxspeed.Y;
//ïðîäîëæàåì ñòîÿòü íà íîãàõ ;)
//åñëè èãðîê ðàíüøå ñòîÿë íà ïëîùàäêå íåïîäâèæíî, à ïëîùàäêà èçìåíèëà ñêîðîñòü, òî
//èãðîê äîëæåí òîæå ïîìåíÿòü ñêîðîñòü! òàêæå èä¸ò ñèíõðîíèçàöèÿ âåùåñòâåííîé ÷àñòè, ground_float.X,
//äëÿ áðèêîâ îíà ðàâíà 0.
if onground and stayground and not IsNET and not phys_flag then
begin
pos.X := int(pos.x) + ground_float.X;
if abs(frac(pos.X) - ground_float.X) < 0.5 then
pos.X := int(pos.x) + ground_float.X
else
if signf(frac(pos.X) - ground_float.X) > 0 then
pos.X := int(pos.x) + ground_float.X + 1
else
pos.X := int(pos.X) + ground_float.X - 1;
dpos.X := ground_dpos.X;
end;
lastpos := Pos;
Pos.X := Pos.X + dpos.X/phys_freq;