-
Notifications
You must be signed in to change notification settings - Fork 1
/
_w_GAME.pas
1910 lines (1758 loc) · 50.3 KB
/
_w_GAME.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
{$IFDEF FULLGAME}
procedure eff_Respawn(aplayer:PTPlayer);
begin
with aplayer^ do
begin
cl_eff_add(x,y,0,1,eid_spawn);
Sound_PlaySource(snd_spawn,nil,nil,x,y);
end;
end;
procedure eff_Shoot(aplayer:PTPlayer);
begin
with aplayer^ do Sound_PlaySource(snd_gun[gun_curr],@vx,@vy,0,0);
end;
procedure eff_Death(aplayer:PTPlayer);
begin
with aplayer^ do
begin
if(pnum=cl_playeri)
then Sound_PlaySource(snd_death ,@vx,@vy,0,0)
else
if(gids_death)
then Sound_PlaySource(snd_meat ,@vx,@vy,0,0)
else Sound_PlaySource(snd_skinD[team],@vx,@vy,0,0);
if(gids_death)
then cl_dead_add(vx,vy,255 )
else cl_dead_add(vx,vy,team);
end;
end;
procedure player_ClientVars(aplayer:PTPlayer);
begin
with aplayer^ do
if(pnum<>cl_playeri)then
begin
if(state<=ps_dead)or(menu_locmatch)or(not player_smooth)then
begin
vx :=x;
vy :=y;
vdir:=dir;
end
else
begin
vx :=(x+vx)/2;
vy :=(y+vy)/2;
if(state=ps_attk)
then vdir:=dir
else vdir:=dir_turn(dir,vdir,dir_diff(dir,vdir)/2);
end;
if(state>ps_dead)then
if(hits<>hits_sound)then
begin
if(hits<hits_sound)then Sound_PlaySource(snd_skinP[team],@vx,@vy,0,0);
hits_sound:=hits;
end;
end;
end;
procedure player_ClientDeathEff(aplayer:PTPlayer);
begin
with aplayer^ do
begin
if(hits>0)then hits:=0;
if(hits>-128)then
begin
hits-=6;
dir -=2;
vdir-=2;
end;
end;
end;
procedure client_ChatCommand(message:shortstring);
begin
if(menu_locmatch)
then room_log_add(sv_clroom,log_chat,message)
else net_SendChat(message);
end;
{$ELSE}
procedure player_xybuffer(aplayer:PTPlayer);
begin
with aplayer^ do
begin
ibuffer+=1;
if(ibuffer>MaxXYBuffer)then ibuffer:=0;
xbuffer[ibuffer]:=x;
ybuffer[ibuffer]:=y;
end;
end;
{$ENDIF}
procedure player_State(aplayer:PTPlayer;nstate:byte;log:boolean);
var pstr,
str2: shortstring;
{$IFDEF FULLGAME}
eff: boolean;
std: integer;
{$ENDIF}
begin
pstr:='';
str2:='';
with aplayer^ do
with room^ do
begin
{$IFDEF FULLGAME}
std:=nstate-state;
eff:=(-2<std);
{$ENDIF}
if(nstate>state)then
while(nstate<>state)do
begin
case state of
ps_none: begin
cur_clients+=1;
if(bot)then
begin
bot_curt[team]+=1;
bot_cur +=1;
end;
pstr:=str_pconnected;
if(not bot)then
str2:='('+c2ip(ip)+') ';
end;
ps_spec: begin
cur_players+=1;
pstr:=str_pjoined;
end;
ps_dead: begin
gun_rld :=0;
pause_gun:=fr_fpsh1;
{$IFDEF FULLGAME}
if(eff)then eff_Respawn(aplayer);
tesla_eff:=0;
{$ENDIF}
end;
end;
state+=1;
end;
if(nstate<state)then
while(nstate<>state)do
begin
case state of
ps_spec: begin
cur_clients-=1;
if(bot)then
begin
bot_curt[team]-=1;
bot_cur -=1;
end;
if(ttl>=MaxPlayerTTL)
then pstr:=str_ptimeout
else pstr:=str_pdconnected;
end;
ps_dead: begin
frags:=0;
cur_players-=1;
pstr:=str_pleave;
end;
ps_walk: begin
{$IFDEF FULLGAME}
if(eff)then eff_death(aplayer);
if(pnum=cl_playeri)then cl_buffer_xy_clear;
{$ENDIF}
death_time:=g_deathtime;
end;
end;
state-=1;
end;
if(log)and(length(pstr)>0)then room_log_add(room,log_common,name+str2+pstr);
end;
end;
function room_CollisionXY(aroom:PTRoom;x,y:single):byte;
var gx,
gy:integer;
c :char;
begin
gx:=trunc(x);
gy:=trunc(y);
if(0<gx)and(gx<map_mlw)and(0<gy)and(gy<map_mlw)then
begin
room_CollisionXY:=0;
c:=aroom^.rgrid[gx,gy];
if(c in mgr_dwalls)then room_CollisionXY:=1;
if(c in mgr_bwalls)then room_CollisionXY:=2;
if(c=mgr_wih )then room_CollisionXY:=3;
end
else room_CollisionXY:=4;
end;
function BWallHit(aroom:PTRoom;psx,psy,bsx,bsy:single):byte;
begin
BWallHit:=room_CollisionXY(aroom,bsx,bsy);
if(BWallHit<2)then
if(abs(trunc(psx)-trunc(bsx))=1)
and(abs(trunc(bsy)-trunc(psy))=1)then BWallHit:=max2(room_CollisionXY(aroom,bsx,psy),room_CollisionXY(aroom,psx,bsy));
end;
function collision_line(aroom:PTRoom;x0,y0,x1,y1:single):boolean;
var px,py,sx,sy,d:single;
begin
collision_line:=false;
if(x0=x1)and(y0=y1)then exit;
d:=point_dist(x0,y0,x1,y1)*2;
sx:=(x1-x0)/d;
sy:=(y1-y0)/d;
while true do
begin
px:=x0;
py:=y0;
x0:=x0+sx;
y0:=y0+sy;
d -=1;
if(d<=0)then break;
if(BWallHit(aroom,px,py,x0,y0)>1)then
begin
collision_line:=true;
break;
end;
end;
end;
procedure SetNewXY(aroom:PTRoom;cx,cy:psingle;nx,ny,width:single;m:byte);
procedure SetMapBorder(cs:psingle);
begin
if(cs^<map_pl)then cs^:=map_pl;
if(cs^>map_pb)then cs^:=map_pb;
end;
begin
if(room_CollisionXY(aroom,nx-width,cy^-width)<m)
and(room_CollisionXY(aroom,nx-width,cy^+width)<m)
and(room_CollisionXY(aroom,nx+width,cy^+width)<m)
and(room_CollisionXY(aroom,nx+width,cy^-width)<m)then cx^:=nx;
if(room_CollisionXY(aroom,cx^-width,ny-width)<m)
and(room_CollisionXY(aroom,cx^-width,ny+width)<m)
and(room_CollisionXY(aroom,cx^+width,ny+width)<m)
and(room_CollisionXY(aroom,cx^+width,ny-width)<m)then cy^:=ny;
SetMapBorder(cx);
SetMapBorder(cy);
end;
procedure player_Move(aroom:PTRoom;cur_x,cur_y:psingle;dir,width:single;spec:boolean);
var new_x,new_y,d:single;
begin
if(aroom^.time_scorepause>0)then exit;
d:=dir*DegToRad;
new_x:=cur_x^+Player_max_speed[spec]*cos(d);
new_y:=cur_y^+Player_max_speed[spec]*sin(d);
if(spec)
then SetNewXY(aroom,cur_x,cur_y,new_x,new_y,0 ,4)
else SetNewXY(aroom,cur_x,cur_y,new_x,new_y,width,1);
end;
procedure player_MoveToSpawn(aplayer:PTPlayer);
var s:integer;
begin
with aplayer^ do
with room^ do
if(r_spawn_n>0)then
begin
s:=random(r_spawn_n);
with r_spawn_l[s] do
begin
x :=spx;
y :=spy;
dir :=spdir;
{$IFDEF FULLGAME}
vx :=x;
vy :=y;
vdir:=dir;
{$ENDIF}
end;
end;
end;
function player_Respawn(aplayer:PTPlayer;forse:boolean):boolean;
begin
player_Respawn:=false;
with aplayer^ do
if(pause_resp=0)or(forse)then
with room^ do
if(time_scorepause=0)then
begin
player_MoveToSpawn(aplayer);
FillChar(ammo,SizeOf(ammo),0);
armor :=0;
gun_rld:=0;
player_State(aplayer,ps_walk,true);
if(Room_CheckFlag(room,sv_g_instagib))then
begin
hits :=1;
ammo[ammo_rifle] :=1;
gun_inv :=gun_bit[4];
gun_curr:=4;
end
else
begin
if(Room_CheckFlag(room,sv_g_itemrespawn))
then ammo[ammo_bullet]:=20
else ammo[ammo_bullet]:=60;
hits :=Player_max_hits;
gun_inv :=gun_bit[0]+gun_bit[1];
gun_curr:=1;
{ammo[ammo_flame ]:=250;
ammo[ammo_rocket]:=250;
ammo[ammo_tesla ]:=250;
gun_inv+=gun_bit[5]+gun_bit[6]+gun_bit[7]; }
end;
gun_next :=gun_curr;
pause_resp :=fr_fpsh1;
player_Respawn:=true;
bot_enemy :=0;
end;
end;
function player_Damage(aplayer:PTPlayer;damage:integer):boolean;
var dmg_armor,
dmg_hits :integer;
begin
player_Damage:=false;
with aplayer^ do
if(room^.time_scorepause=0)then
begin
dmg_hits :=damage div 3;
dmg_armor:=damage-dmg_hits;
armor-=dmg_armor;
if(armor<0)then
begin
dmg_hits+=abs(armor);
armor:=0;
end;
hits-=dmg_hits;
if(hits<=0)then
begin
gids_death :=(hits<=gibs_hits);
player_State(aplayer,ps_dead,true);
hits :=0;
player_Damage:=true;
pause_resp :=fr_fpsx1;
end;
end;
end;
procedure player_Reset(aplayer:PTPlayer);
begin
with aplayer^ do
if(state>ps_spec)then
begin
//player_Respawn(aplayer,true);
player_Damage(aplayer,1000);
death_time:=pause_resp;
frags :=0;
end;
end;
procedure player_SpecJoin(aplayer:PTPlayer);
begin
with aplayer^ do
with room^ do
if(time_scorepause<=0)and(state>ps_none)and(pause_spec=0)then
if(state=ps_spec)then
begin
if(cur_players<max_players)then
if(player_Respawn(aplayer,false))then
begin
frags:=0;
pause_spec:={$IFDEF FULLGAME}2{$ELSE}fr_fpsx1{$ENDIF};
end;
end
else
begin
frags:=0;
player_State(aplayer,ps_spec,true);
pause_spec:={$IFDEF FULLGAME}2{$ELSE}fr_fpsx1{$ENDIF};
end;
end;
procedure SetPHS(phs:PTPlayerHitSet;p:byte);
var byt,
bit:integer;
begin
if(p<=MaxPlayers)then
begin
byt:=p div 8;
bit:=p mod 8;
SetBBit(@phs^[byt],bit,true);
end;
end;
function CheckPHS(phs:PTPlayerHitSet;p:byte;byt,bit:pbyte):boolean;
begin
CheckPHS:=false;
if(p<=MaxPlayers)and(phs<>nil)then
begin
byt^:=p div 8;
bit^:=p mod 8;
CheckPHS:=GetBBit(@phs^[byt^],bit^);
end;
end;
function player_FindInPoint(tar_x,tar_y:single;aroomi:integer;phs:PTPlayerHitSet{$IFNDEF FULLGAME};stepback:word{$ENDIF}):PTPlayer;
var p,
byt,
bit:byte;
_stx,
_sty:single;
{$IFNDEF FULLGAME}
i,b :byte;
{$ENDIF}
begin
player_FindInPoint:=nil;
{$IFNDEF FULLGAME}
if(stepback>MaxXYBuffer)then stepback:=MaxXYBuffer;
{$ENDIF}
for p:=0 to MaxPlayers do
with g_players[p] do
if(roomi=aroomi)and(state>ps_dead)then
if(not CheckPHS(phs,p,@byt,@bit))then
begin
{$IFNDEF FULLGAME}
if(stepback=0)then
begin
_stx:=x;
_sty:=y;
end
else
begin
b:=ibuffer;
for i:=1 to stepback do
if(b=0)
then b:=MaxXYBuffer
else b-=1;
_stx:=xbuffer[b];
_sty:=ybuffer[b];
end;
{$ELSE}
_stx:=x;
_sty:=y;
{$ENDIF}
if(abs(tar_x-_stx)<Player_BWidth)
and(abs(tar_y-_sty)<Player_BWidth)then
begin
player_FindInPoint:=@g_players[p];
if(phs<>nil)then SetBBit(@phs^[byt],bit,true);
break;
end;
end;
end;
function player_IncFrags(aplayer:PTPlayer;TeamPlay,TeamKill:boolean):boolean;
begin
player_IncFrags:=false;
with aplayer^ do
begin
if(TeamPlay)and(TeamKill)
then frags-=1
else
begin
frags+=1;
{$IFDEF FULLGAME}
spec_LastFrager:=pnum;
{$ENDIF}
end;
with room^ do
begin
if(TeamPlay)and(TeamKill)
then team_frags[team]-=1
else team_frags[team]+=1;
if(g_fraglimit>0)then
if(frags>=g_fraglimit)
or((TeamPlay)and(team_frags[team]>=g_fraglimit))then
begin
room_log_add(room,log_endgame,str_fraglimithit);
Room_Score(room);
player_IncFrags:=true;
end;
end;
end;
end;
procedure player_BulletShot(aplayer:PTPlayer{$IFDEF FULLGAME};fakeshoot:boolean{$ENDIF});
const init_dstep = 0.25;
var d,sx,sy,
dstep,
max_dist,
psx,psy,
bsx,bsy :single;
damage,
dispersion :integer;
teams,
rail :boolean;
wall_hit
{$IFDEF FULLGAME}
,bstep
{$ENDIF} :byte;
tpl :PTPlayer;
phs :TPlayerHitSet;
begin
with aplayer^ do
begin
max_dist :=gun_dist[gun_curr];
dispersion:=gun_disp[gun_curr];
damage :=gun_dmg [gun_curr];
rail :=gun_curr=4;
teams :=Room_CheckFlag(room,sv_g_teams);
bsx := x;
bsy := y;
dstep:= init_dstep;
{$IFDEF FULLGAME}
bstep:= 2;
{$ENDIF}
FillChar(phs,SizeOf(phs),0);
SetPHS(@phs,pnum);
if(dispersion>1)
then d :=(dir-random(dispersion)+random(dispersion))*degtorad
else d := dir*degtorad;
sx:=cos(d)*dstep;
sy:=sin(d)*dstep;
while true do
begin
psx :=bsx;
psy :=bsy;
bsx +=sx;
bsy +=sy;
max_dist-=dstep;
wall_hit:=BWallHit(room,psx,psy,bsx,bsy);
{$IFDEF FULLGAME}
if(bstep>0)then
if(wall_hit>1)or(max_dist<=0)then
begin
bsx -=sx;
bsy -=sy;
max_dist +=bstep;
sx /=2;
sy /=2;
max_dist /=2;
bstep-=1;
continue;
end;
case wall_hit of
0,1: ;
2: begin
cl_eff_add(bsx-sx,bsy-sy,0,1,eid_puff);
break;
end;
else break; // wall with sky texture
end;
{$ELSE}
if(wall_hit> 1)then break;
{$ENDIF}
if(max_dist<=0)then break;
{$IFDEF FULLGAME}
tpl:=player_FindInPoint(bsx,bsy,roomi,@phs);
{$ELSE}
if(antilag)
then tpl:=player_FindInPoint(bsx,bsy,roomi,@phs,round(ping/fr_RateTicks))
else tpl:=player_FindInPoint(bsx,bsy,roomi,@phs,0);
{$ENDIF}
if(tpl<>nil)then
begin
{$IFDEF FULLGAME}
cl_eff_add(bsx,bsy,0,1,eid_blood);
if(not fakeshoot)then
{$ENDIF}
if(not teams)or(Room_CheckFlag(room,sv_g_teamdamage))or(team<>tpl^.team)then
if(player_Damage(tpl,damage))then
begin
room_log_add(room,log_common,name+' > '+gun_name[gun_curr]+' > '+tpl^.name);
if(player_IncFrags(aplayer,teams,team=tpl^.team))then exit;
end;
if(rail=false)then break;
end;
end;
end;
end;
procedure player_MissileShot(aplayer:PTPlayer{$IFDEF FULLGAME};fakeshot:boolean{$ENDIF});
var mi : word;
rdir : single;
begin
with aplayer^ do
begin
{$IFDEF FULLGAME}
if(fakeshot)then exit;
{$ENDIF}
case gun_btype[gun_curr] of
gpt_fire,
gpt_rocket: with room^ do
begin
if(r_missile_n>=MaxMissiles)then exit;
if(r_missile_n>0)then
begin
mi:=0;
while(mi<r_missile_n)do
begin
with r_missile_l[mi] do
if(mtype=0)then break;
mi+=1;
end;
if(mi=r_missile_n)then
begin
r_missile_n+=1;
setlength(r_missile_l,r_missile_n);
end;
end
else
begin
r_missile_n+=1;
setlength(r_missile_l,r_missile_n);
mi:=0;
end;
with r_missile_l[mi] do
begin
mx :=x;
my :=y;
mdir :=dir_360(dir);
mgun :=gun_curr;
mtype :=gun_btype[gun_curr];
mmaxdist:=gun_dist [gun_curr];
mdamage :=gun_dmg [gun_curr];
mplayer :=aplayer^.pnum;
case mtype of
gpt_fire : begin
mspeed :=gpt_fire_speed;
msplashr:=gpt_fire_splashr;
{$IFDEF FULLGAME}
mspriteScale:=0.1;
{$ENDIF}
end;
gpt_rocket: begin
mspeed :=gpt_rocket_speed;
msplashr:=gpt_rocket_splashr;
end;
end;
if(gun_disp[gun_curr]>1)
then rdir :=(dir-random(gun_disp[gun_curr])+random(gun_disp[gun_curr]))*DEGTORAD
else rdir := dir*DEGTORAD;
mvx :=cos(rdir)*mspeed;
mvy :=sin(rdir)*mspeed;
end;
end;
end;
end;
end;
function missile_Proc(aroom:PTRoom;amissile:PTMissile):boolean;
var pmx,
pmy,
ds : single;
pl : byte;
damage : integer;
teams : boolean;
attacker: PTPlayer;
function CheckCollision:boolean;
var p:byte;
begin
CheckCollision:=true;
with amissile^ do
begin
if(BWallHit(aroom,pmx,pmy,mx,my)>1)then
begin
mx-=mvx;
my-=mvy;
exit;
end;
for p:=0 to MaxPlayers do
with g_players[p] do
if(room=aroom)and(state>ps_dead)and(p<>mplayer)then
if (abs(mx-x)<=Player_BWidth)
and(abs(my-y)<=Player_BWidth)
then exit;
end;
CheckCollision:=false;
end;
begin
missile_Proc:=false;
with amissile^ do
if(mtype>0)then
begin
if(mdamage<=0)then
begin
missile_Proc:=true;
exit;
end;
pmx:=mx;
pmy:=my;
mx+=mvx;
my+=mvy;
mmaxdist-=mspeed;
if(CheckCollision)or(mmaxdist<=0)then
begin
attacker:=@g_players[mplayer];
with attacker^ do teams:=Room_CheckFlag(room,sv_g_teams);
missile_Proc:=true;
for pl:=0 to MaxPlayers do
with g_players[pl] do
if(room=aroom)and(state>ps_dead)then
begin
if(msplashr>0)then
begin
ds:=point_dist(mx,my,x,y)-Player_BWidth;
if(ds>msplashr)then continue;
if(collision_line(room,mx,my,x,y))then continue;
if(ds<0)then ds:=0;
damage:=round(mdamage*(1-(ds/msplashr)));
end
else
begin
if(pl=mplayer)then continue;
if(abs(mx-x)>Player_BWidth)
or(abs(my-y)>Player_BWidth)
then continue;
damage:=mdamage;
end;
if(damage<=0)then continue;
if(not teams)
or(Room_CheckFlag(room,sv_g_teamdamage))
or(team<>attacker^.team)
or(pl=mplayer)then
if(player_Damage(@g_players[pl],damage))then
begin
if(mgun<=WeaponsN)then
begin
if(pl=mplayer)
then room_log_add(room,log_common,attacker^.name+str_fsplit+str_suicide+str_fsplit+gun_name[mgun])
else room_log_add(room,log_common,attacker^.name+str_fsplit+gun_name[mgun]+str_fsplit+name);
end
else
if(pl=mplayer)
then room_log_add(room,log_common,attacker^.name+str_fsplit+str_suicide)
else room_log_add(room,log_common,attacker^.name+str_fsplit+name );
if(player_IncFrags(attacker,teams or(pl=mplayer),team=attacker^.team))or(msplashr=0)then exit;
end;
end;
end;
end;
end;
procedure player_TeslaShot(aplayer:PTPlayer{$IFDEF FULLGAME};fakeshot:boolean{$ENDIF});
var
pl : byte;
ax,ay,
bx,by,
tdir,
dist,
fov : single;
damage : integer;
teams : boolean;
{$IFNDEF FULLGAME}
b,i : byte;
stepback: word;
{$ENDIF}
begin
with aplayer^ do
begin
fov :=gun_disp[gun_curr];
dist :=gun_dist[gun_curr];
damage :=gun_dmg [gun_curr];
ax :=x;
ay :=y;
tdir :=dir;
teams :=Room_CheckFlag(room,sv_g_teams);
{$IFNDEF FULLGAME}
stepback:=round(ping/fr_RateTicks);
{$ENDIF}
end;
for pl:=0 to MaxPlayers do
with g_players[pl] do
if(room=aplayer^.room)and(state>ps_dead)and(pl<>aplayer^.pnum)then
begin
{$IFNDEF FULLGAME}
if(aplayer^.antilag)and(stepback>0)then
begin
b:=ibuffer;
for i:=1 to stepback do
if(b=0)
then b:=MaxXYBuffer
else b-=1;
bx:=xbuffer[b];
by:=ybuffer[b];
end
else
begin
bx:=x;
by:=y;
end;
{$ELSE}
bx:=x;
by:=y;
{$ENDIF}
if(point_dist(ax,ay,bx,by)>dist)then continue;
if(abs(dir_diff(point_dir(ax,ay,bx,by),tdir))>fov)then continue;
if(collision_line(room,ax,ay,bx,by))then continue;
if(not teams)
or(Room_CheckFlag(room,sv_g_teamdamage))
or(team<>aplayer^.team)then
begin
{$IFDEF FULLGAME}
tesla_eff:=tesla_eff_time;
if(fakeshot)then continue;
{$ENDIF}
if(player_Damage(@g_players[pl],damage))then
begin
room_log_add(room,log_common,aplayer^.name+str_fsplit+gun_name[aplayer^.gun_curr]+str_fsplit+name);
if(player_IncFrags(aplayer,teams,team=aplayer^.team))then continue;
end;
end;
end;
end;
procedure player_Shot(aplayer:PTPlayer{$IFDEF FULLGAME};fakeshot:boolean{$ENDIF});
begin
with aplayer^ do
if(gun_rld=0)and(state>ps_dead)then
with room^ do
begin
gun_rld:=gun_reload[gun_curr];
case gun_btype[gun_curr] of
gpt_bullet : player_BulletShot (aplayer{$IFDEF FULLGAME},fakeshot{$ENDIF});
gpt_fire,
gpt_rocket : player_MissileShot(aplayer{$IFDEF FULLGAME},fakeshot{$ENDIF});
gpt_tesla : player_TeslaShot (aplayer{$IFDEF FULLGAME},fakeshot{$ENDIF});
end;
{$IFDEF FULLGAME}
eff_Shoot(aplayer);
{$ENDIF}
end;
end;
function player_Attack(aplayer:PTPlayer{$IFDEF FULLGAME};fakeshot:boolean{$ENDIF}):boolean;
begin
player_Attack:=false;
with aplayer^ do
if(gun_rld=0)and(state>ps_dead)and(pause_gun=0)then
with room^ do
if(time_scorepause<=0)then
begin
if(Room_CheckFlag(room,sv_g_instagib)=false)then
begin
if(ammo[gun_ammot[gun_curr]]<gun_ammog[gun_curr])then
begin
player_Attack:=true;
exit;
end;
{$IFDEF FULLGAME}
if(not fakeshot)then
{$ENDIF}
ammo[gun_ammot[gun_curr]]-=gun_ammog[gun_curr];
end;
player_Shot(aplayer{$IFDEF FULLGAME},fakeshot{$ENDIF});
end;
end;
procedure player_WeaponSwitch(aplayer:PTPlayer);
begin
with aplayer^ do
if(gun_next>WeaponsN)
then gun_next:=gun_curr
else
if(gun_next<>gun_curr)then
if((gun_inv and gun_bit[gun_next])=0)
then gun_next:=gun_curr
else
if(gun_rld=0)then gun_curr:=gun_next;
end;
{$INCLUDE _w_BOTZ.pas}
function player_ItemPickup(aplayer:PTPlayer;i:word;c:integer):boolean;
var w:byte;
function item_Proc(ap,cp:pinteger;mp,c:integer):boolean;
var np:integer;
begin
item_Proc:=false;
np:=ap^*c;
if(np>0)and(cp^<mp)then
begin
cp^:=min2(cp^+np,mp);
item_Proc:=true;
end;
end;
begin
player_ItemPickup:=false;
with aplayer^ do
with room^ do
with r_item_l[i] do
begin
for w:=0 to AmmoTypesN do
if item_Proc(@iammo[w],@ammo[w],Player_max_ammo[w],c)then player_ItemPickup:=true;
if item_Proc(@ihealth ,@hits ,Player_max_hits ,1)then player_ItemPickup:=true;
if item_Proc(@iarmor ,@armor ,Player_max_armor ,1)then player_ItemPickup:=true;
end;
end;
function Inv2BestGunN(inv:byte):byte;
var b:byte;
begin
Inv2BestGunN:=255;
for b:=7 downto 0 do
if(inv and (1 shl b))>0 then
begin
Inv2BestGunN:=b;
break;
end;
end;
procedure player_Items(aplayer:PTPlayer);
var i:word;
w:byte;
m:integer;
begin
with aplayer^ do
with room^ do
if(r_item_n>0)then
for i:=0 to r_item_n-1 do
with r_item_l[i] do
if(irespt=0)then
if(abs(ix-x)<Player_IWidth)
and(abs(iy-y)<Player_IWidth)then
begin
if(not Room_CheckFlag(room,sv_g_itemrespawn))
then m:=4
else
if(Room_CheckFlag(room,sv_g_weaponstay))and(iweapon>0)
then m:=2
else m:=1;
if(iweapon>0)then
begin
w:=gun_inv or iweapon;
if(w<>gun_inv)then
begin
gun_inv:=w;
if(wswitch)then gun_next:=Inv2BestGunN(iweapon);
if(Room_CheckFlag(room,sv_g_itemrespawn))and(not Room_CheckFlag(room,sv_g_weaponstay))
then irespt:=irespm
else
begin
player_ItemPickup(aplayer,i,m);
continue;
end;
end
else