-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinc__r2world.pas
More file actions
2266 lines (1998 loc) · 106 KB
/
inc__r2world.pas
File metadata and controls
2266 lines (1998 loc) · 106 KB
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
{*******************************************************************************
NFK [R2]
World Library
Info:
This is up to store map data with all objects.
Contains:
procedure GetMapWeaponData;
function LOADMAPCRC32(filename:string):Cardinal;
procedure ADDDirContentMaps(StartDir: string; List:TStrings);
function LoadMapSearchSimple(filename:string):byte;
function CTF_ValidMap:boolean;
function DOM_ValidMap:boolean;
function MAPExists(filename:string; CRC32:cardinal) : boolean;
function LOADMAPSearch(filename:string;CRC32:cardinal) : byte;
procedure LOADMAP (Filename : string; inreal : boolean);
*******************************************************************************}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
function player_region_touch (x,y,x1,y1 : word; f : tplayer) : boolean;
begin
result := false;
if f = nil then exit;
if (f.x + 9 >= x*32) and (f.x-8 <= x1*32+32) then
if (f.y + 23 >= y * 16) and (f.y - 23 <= y1*16+16) then
result := true;
end;
//------------------------------------------------------------------------------
function object_region_touch (x,y,x1,y1 : word; f : tmonosprite) : boolean;
begin
result := false;
if f = nil then exit;
// HERE IS OPTIMIZA FOr gib. mayb
if (f.x + 3 >= x*32) and (f.x-3 <= x1*32+32) then
if (f.y + 3 >= y * 16) and (f.y - 3 <= y1*16+16) then
result := true;
end;
//------------------------------------------------------------------------------
// thiz procedure calls "Eat My Shit"
procedure MAPOBJ_think(i : word);
var
a,xx,yy,p,xxx,yyy : byte;
o,z : word;
rzlt : boolean;
str,str2 : string[255];
alpha : cardinal;
Msg: TMP_ObjChangeState;
Msg2: TMP_cl_ObjDestroy;
Msg3: TMP_TeleportPlayer;
Msg4: TMP_TrixArenaWin;
MsgSize: word;
begin
// if MATCH_GAMEEND Then exit;
// exit;
rzlt := false;
// ---------------------------------------
// addmessage('drawing '+inttostr(MapObjects[i].objtype));
if MapObjects[i].objtype = 1 then begin // teleporter
// addmessage('draw teleport #'+inttostr(i));
if inscreen(MapObjects[i].x*32,MapObjects[i].y*16,48) then
mainform.PowerGraph.RenderEffect(mainform.Images[30], MapObjects[i].x*32-16+GX, MapObjects[i].y*16-30+GY,0, effectSrcAlpha);
if MapObjects[i].wait < 15 then inc(MapObjects[i].wait) else MapObjects[i].wait := 0;
if inscreen(MapObjects[i].x*32,MapObjects[i].y*16,48) then
mainform.PowerGraph.RenderEffectCol(mainform.Images[31], MapObjects[i].x*32+6+GX, MapObjects[i].y*16-25+GY,$AAFFFFFF,MapObjects[i].wait div 4, effectSrcAlpha);
if MATCH_DDEMOPLAY then exit;
for a := 0 to SYS_MAXPLAYERS-1 do if players[a] <> nil then if (players[a].dead = 0) and (players[a].health > 0) and ((players[a].netobject=false)) then begin
xx := trunc(players[a].x) div 32;
yy := trunc(players[a].y+13) div 16;
if (xx = MapObjects[i].x) and (yy = MapObjects[i].y) then begin
players[a].x := MapObjects[i].lenght * 32 +16;
players[a].y := MapObjects[i].dir * 16 - 8;
//if players[a].inertiax > 1 then players[a].inertiax := players[a].inertiax / 2; // conn: keep inertia
RespawnFlash(xx*32,yy*16);
RespawnFlash(MapObjects[i].lenght * 32,MapObjects[i].dir * 16);
if ismultip>0 then begin
MsgSize := SizeOf(TMP_TeleportPlayer);
Msg3.Data := MMP_TELEPORTPLAYER;
Msg3.x1 := xx*32;
Msg3.y1 := yy*16;
Msg3.x2 := MapObjects[i].lenght * 32;
Msg3.y2 := MapObjects[i].dir * 16;
if ismultip=1 then
mainform.BNETSendData2All (Msg3, MsgSize, 0) else
mainform.BNETSendData2HOST (Msg3, MsgSize, 0);
end;
end;
end;
end;
// ---------------------------------------
if MapObjects[i].objtype = 2 then begin // BUTTON
// if gametic<=5 then exit;
if MapObjects[i].targetname = 0 then if MapObjects[i].nowanim > 0 then dec(MapObjects[i].nowanim,15);
if MapObjects[i].targetname = 1 then if MapObjects[i].nowanim < $ff then inc(MapObjects[i].nowanim,15);
alpha := MapObjects[i].nowanim;
if inscreen(MapObjects[i].x*32,MapObjects[i].y*16,48) then begin
mainform.PowerGraph.RenderEffectCol(mainform.Images[34], MapObjects[i].x*32+4+GX, MapObjects[i].y*16-4+GY,(($FF-Alpha ) shl 24) + $FFFFFF,6, effectSrcAlpha or EffectDiffuseAlpha);
mainform.PowerGraph.RenderEffectCol(mainform.Images[34], MapObjects[i].x*32+4+GX, MapObjects[i].y*16-4+GY,(Alpha shl 24) + $FFFFFF,7+MapObjects[i].orient, effectSrcAlpha or EffectDiffuseAlpha);
end;
if MATCH_DDEMOPLAY THEN EXIT;
if ismultip=2 then exit;
if MapObjects[i].targetname > 0 then begin
if MapObjects[i].lenght > 0 then dec(MapObjects[i].lenght) else begin
MapObjects[i].targetname := 0;
// send button off data to clients.
if ismultip=1 then begin
MsgSize := SizeOf(TMP_ObjChangeState);
Msg.Data := MMP_OBJCHANGESTATE;
Msg.objindex := i;
Msg.state := 0;
mainform.BNETSendData2All (Msg, MsgSize, 1);
end;
if MATCH_DRECORD then begin
// change obj state!
ddata.gametic := gametic;
ddata.gametime := gametime;
ddata.type0 := DDEMO_OBJCHANGESTATE;
DemoStream.Write( DData, Sizeof(DData));
DObjChangeState.objindex := i;
DObjChangeState.state := 0; // dizactive
DemoStream.Write( DObjChangeState, Sizeof(DObjChangeState));
end;
end;
end else
for z := 0 to SYS_MAXPLAYERS-1 do if players[z] <> nil then if players[z].dead = 0 then begin
xx := trunc(players[z].x) div 32;
for o := 0 to 2 do begin
case o of
0 : yy := trunc(players[z].y+23) div 16;
1 : yy := trunc(players[z].y-23) div 16;
2 : yy := trunc(players[z].y) div 16;
end;
if (xx = MapObjects[i].x) and (yy = MapObjects[i].y) then begin
MapObjects[i].targetname := 1; //0\1=normal\activated
MapObjects[i].lenght := MapObjects[i].wait; // time of gametic to wait.
// send button on data to clients.
if ismultip=1 then begin
MsgSize := SizeOf(TMP_ObjChangeState);
Msg.Data := MMP_OBJCHANGESTATE;
Msg.objindex := i;
Msg.state := 1;
mainform.BNETSendData2All (Msg, MsgSize, 1);
end;
if MATCH_DRECORD then begin
// change obj state!
ddata.gametic := gametic;
ddata.gametime := gametime;
ddata.type0 := DDEMO_OBJCHANGESTATE;
DemoStream.Write( DData, Sizeof(DData));
DObjChangeState.objindex := i;
DObjChangeState.state := 1; // active
DemoStream.Write( DObjChangeState, Sizeof(DObjChangeState));
end;
SND.play(SND_button,MapObjects[i].x*32,MapObjects[i].y*16);
//MapObjects[i].nowanim := 0;
for p := 0 to NUM_OBJECTS do
if (MapObjects[p].active = true) and (MapObjects[p].targetname = MapObjects[i].target) and ((MapObjects[p].objtype = 3) or (MapObjects[p].objtype = 6)) then ACTIVATEOBJ(p);
end;
end;
end;
end;
// ---------------------------------------
if (MATCH_DDEMOPLAY) or (ismultip=2) then // NOT REAL DOOOOORRRRRRR
if MapObjects[i].objtype = 3 then begin // simple ! door (!)
if MapObjects[i].nowanim > 0 then dec(MapObjects[i].nowanim) else MapObjects[i].nowanim := 0; // animate door
// !DOOR ANIMATION!
if (MapObjects[i].orient = 1) or (MapObjects[i].orient = 3) then begin //vertical anim
if MapObjects[i].target = 1 then a := MapObjects[i].nowanim;
if MapObjects[i].target = 0 then a := 6-MapObjects[i].nowanim;
if MapObjects[i].nowanim = 0 then if MapObjects[i].target = 0 then a := 11 else a:= 0;
end else
if (MapObjects[i].orient = 0) or (MapObjects[i].orient = 2) then begin //horz anim
if MapObjects[i].target = 1 then a := 6+MapObjects[i].nowanim;
if MapObjects[i].target = 0 then a := 12-MapObjects[i].nowanim;
if MapObjects[i].nowanim = 0 then if MapObjects[i].target = 0 then a := 11 else a:= 6;
end;
// end DOOR ANIM.
for o := 0 to MapObjects[i].lenght-1 do begin
if (MapObjects[i].orient = 0) or (MapObjects[i].orient = 2) then begin// horizon closed door
xxx := o;
yyy := 0;
end;
if (MapObjects[i].orient = 1) or (MapObjects[i].orient = 3) then begin// vert closed door
xxx := 0;
yyy := o;
end;
if inscreen(MapObjects[i].x*32+xxx*32,MapObjects[i].y*16+yyy*16,32) then
mainform.PowerGraph.RenderEffect(mainform.Images[21], MapObjects[i].x*32+xxx*32+GX, MapObjects[i].y*16+yyy*16+GY,73+a, effectSrcAlpha);
if MapObjects[i].target = 1 then AllBricks[MapObjects[i].x+xxx, MapObjects[i].y+yyy].block := true;
if MapObjects[i].target = 0 then if AllBricks[MapObjects[i].x+xxx, MapObjects[i].y+yyy].image < 54 then AllBricks[MapObjects[i].x+xxx, MapObjects[i].y+yyy].block := false;
end;
end;
// ---------------------------------------
if (MATCH_DDEMOPLAY=false) and (ismultip<2) then
if MapObjects[i].objtype = 3 then begin // door (!)
if MapObjects[i].dir > 0 then dec(MapObjects[i].dir) else MapObjects[i].dir := 0; // wait in toggled status
// addmessage(inttostr(MapObjects[i].dir));
if MapObjects[i].nowanim > 0 then dec(MapObjects[i].nowanim) else MapObjects[i].nowanim := 0; // animate door
// !DOOR ANIMATION!
if (MapObjects[i].orient = 1) or (MapObjects[i].orient = 3) then begin //vertical anim
if MapObjects[i].target = 1 then a := MapObjects[i].nowanim;
if MapObjects[i].target = 0 then a := 6-MapObjects[i].nowanim;
if MapObjects[i].nowanim = 0 then if MapObjects[i].target = 0 then a := 11 else a:= 0;
end else
if (MapObjects[i].orient = 0) or (MapObjects[i].orient = 2) then begin //horz_anim
if MapObjects[i].target = 1 then a := 6+MapObjects[i].nowanim;
if MapObjects[i].target = 0 then a := 12-MapObjects[i].nowanim;
if MapObjects[i].nowanim = 0 then if MapObjects[i].target = 0 then a := 11 else a:= 6;
end;
// end DOOR ANIM.
if (MapObjects[i].orient = 0) or (MapObjects[i].orient = 1) then
if (MapObjects[i].dir = 1) and (MapObjects[i].target = 0) then begin // so, CLOSE!
rzlt := false;
for o := 0 to SYS_MAXPLAYERS-1 do begin
if MapObjects[i].orient = 0 then rzlt := player_region_touch (MapObjects[i].x,MapObjects[i].y,MapObjects[i].x+MapObjects[i].lenght,MapObjects[i].y, players[o]);
if MapObjects[i].orient = 1 then rzlt := player_region_touch (MapObjects[i].x,MapObjects[i].y,MapObjects[i].x,MapObjects[i].y+MapObjects[i].lenght, players[o]);
if rzlt = true then break;
end;
if rzlt = true then begin
// shut up doortriggerz
for o := 0 to NUM_OBJECTS do if (MapObjects[o].active = true) and (MapObjects[i].targetname=MapObjects[o].target) and (MapObjects[o].objtype=9) then
begin
MapObjects[o].targetname := MapObjects[i].wait;
// addmessage('doortrigger time give|'+inttostr(MapObjects[i].targetname));
end;
MapObjects[i].target := 0;
if (MapObjects[i].special = 1) then
MapObjects[i].dir := 6 else MapObjects[i].dir := MapObjects[i].wait;
end else begin
MapObjects[i].target := 1; // ReMoVe ObJeCtS heRe.
for o := 0 to 1000 do if GameObjects[o].dead = 0 then begin
if MapObjects[i].orient = 0 then rzlt := object_region_touch(MapObjects[i].x,MapObjects[i].y-1,MapObjects[i].x+MapObjects[i].lenght+1,MapObjects[i].y, GameObjects[o]);
if MapObjects[i].orient = 1 then rzlt := object_region_touch(MapObjects[i].x,MapObjects[i].y-1,MapObjects[i].x,MapObjects[i].y+MapObjects[i].lenght+1, GameObjects[o]);
if rzlt = true then begin
if GameObjects[o].objname = 'corpse' then GameObjects[o].dead := 2;
end;
end;
for o := 0 to 1000 do if GameObjects[o].dead = 0 then begin
if MapObjects[i].orient = 0 then rzlt := object_region_touch(MapObjects[i].x,MapObjects[i].y,MapObjects[i].x+MapObjects[i].lenght,MapObjects[i].y, GameObjects[o]);
if MapObjects[i].orient = 1 then rzlt := object_region_touch(MapObjects[i].x,MapObjects[i].y,MapObjects[i].x,MapObjects[i].y+MapObjects[i].lenght, GameObjects[o]);
if rzlt = true then begin
if GameObjects[o].objname = 'corpse' then GameObjects[o].dead := 2;
if GameObjects[o].objname = 'blood' then GameObjects[o].dead := 2;
if GameObjects[o].objname = 'plasma' then GameObjects[o].dead := 2;
if GameObjects[o].objname = 'gib' then GameObjects[o].dead := 2;
if GameObjects[o].objname = 'rocket' then begin
GameObjects[o].dead := 1;
GameObjects[o].weapon := 0;
GameObjects[o].frame := 0;
end;
if GameObjects[o].objname = 'grenade' then begin
GameObjects[o].objname := 'rocket';
GameObjects[o].dead := 1;
GameObjects[o].weapon := 0;
GameObjects[o].frame := 0;
end;
// send explosion to client;
// if GameObjects[o].dead = 0 then
if (GameObjects[o].objname = 'weapon') or (GameObjects[o].objname = 'flag') then
GameObjects[o].health := 0; // weapon will kill himself
if (GameObjects[o].objname = 'grenade') or (GameObjects[o].objname = 'rocket') or (GameObjects[o].objname = 'plasma') then
if ismultip=1 then begin
MsgSize := SizeOf(TMP_cl_ObjDestroy);
Msg2.Data := MMP_CL_OBJDESTROY;
Msg2.killDXID := GameObjects[o].DXID;
// addmessage('sending killing packet: '+inttostr(GameObjects[o].DXID));
MSG2.index := 0;
Msg2.x := round(GameObjects[o].x);
Msg2.y := round(GameObjects[o].y);
mainform.BNETSendData2All (Msg2, MsgSize, 1);
end;
// & send explosion to client;
if GameObjects[o].dxid > 0 then
// if (GameObjects[o].objname = 'grenade') or (GameObjects[o].objname = 'rocket') or (GameObjects[o].objname = 'plasma') then
if MATCH_DRECORD then begin
DData.type0 := 5; // kill this object in demo
DData.gametic := gametic;
DData.gametime := gametime;
DDXIDKill.x := round(GameObjects[o].x);
DDXIDKill.y := round(GameObjects[o].y);
DDXIDKill.DXID := GameObjects[o].DXID;
DemoStream.Write( DData, Sizeof(DData));
DemoStream.Write( DDXIDKill, Sizeof(DDXIDKill));
end;
end;
end;
// send door data to clients.
if ismultip=1 then begin
MsgSize := SizeOf(TMP_ObjChangeState);
Msg.Data := MMP_OBJCHANGESTATE;
Msg.objindex := i;
Msg.state := 1;
mainform.BNETSendData2All (Msg, MsgSize, 1);
end;
if MATCH_DRECORD then begin
// change obj state!
ddata.gametic := gametic;
ddata.gametime := gametime;
ddata.type0 := DDEMO_OBJCHANGESTATE;
DemoStream.Write( DData, Sizeof(DData));
DObjChangeState.objindex := i;
DObjChangeState.state := 1; // closed
DemoStream.Write( DObjChangeState, Sizeof(DObjChangeState));
end;
if OPT_DOORSOUNDS then SND.play(SND_dr1_end,MapObjects[i].x*32,MapObjects[i].y*16);
MapObjects[i].nowanim := 6;
end;
end;
if (MapObjects[i].orient = 2) or (MapObjects[i].orient = 3) then
if (MapObjects[i].dir = 1) and (MapObjects[i].target = 1) then begin // so, OPEN!
MapObjects[i].target := 0;
if OPT_DOORSOUNDS then SND.play(SND_dr1_strt,MapObjects[i].x*32,MapObjects[i].y*16);
// send door data to clients.
if ismultip=1 then begin
MsgSize := SizeOf(TMP_ObjChangeState);
Msg.Data := MMP_OBJCHANGESTATE;
Msg.objindex := i;
Msg.state := 0;
mainform.BNETSendData2All (Msg, MsgSize, 1);
end;
if MATCH_DRECORD then begin
// change obj state!
ddata.gametic := gametic;
ddata.gametime := gametime;
ddata.type0 := DDEMO_OBJCHANGESTATE;
DemoStream.Write( DData, Sizeof(DData));
DObjChangeState.objindex := i;
DObjChangeState.state := 0; // open
DemoStream.Write( DObjChangeState, Sizeof(DObjChangeState));
end;
MapObjects[i].nowanim := 6;
end;
for o := 0 to MapObjects[i].lenght-1 do begin
if (MapObjects[i].orient = 0) or (MapObjects[i].orient = 2) then begin// horizon closed door
xxx := o;
yyy := 0;
end;
if (MapObjects[i].orient = 1) or (MapObjects[i].orient = 3) then begin// vert closed door
xxx := 0;
yyy := o;
end;
if inscreen(MapObjects[i].x*32+xxx*32,MapObjects[i].y*16+yyy*16,32) then
mainform.PowerGraph.RenderEffect(mainform.Images[21], MapObjects[i].x*32+xxx*32+GX, MapObjects[i].y*16+yyy*16+GY,73+a, effectSrcAlpha);
if MapObjects[i].target = 1 then AllBricks[MapObjects[i].x+xxx, MapObjects[i].y+yyy].block := true;
if MapObjects[i].target = 0 then if AllBricks[MapObjects[i].x+xxx, MapObjects[i].y+yyy].image < 54 then AllBricks[MapObjects[i].x+xxx, MapObjects[i].y+yyy].block := false;
end;
end;
// ---------------------------------------
if MapObjects[i].objtype = 4 then begin // trigger
if MATCH_DDEMOPLAY then exit;
if ismultip=2 then exit;
// if gametic<=5 then exit;
if MapObjects[i].targetname > 0 then dec(MapObjects[i].targetname);
if MapObjects[i].targetname > 0 then exit;
MapObjects[i].targetname := MapObjects[i].wait;
for o := 0 to SYS_MAXPLAYERS-1 do begin
if players[o] <> nil then if players[o].dead = 0 then
rzlt := player_region_touch (MapObjects[i].x,MapObjects[i].y,MapObjects[i].x+MapObjects[i].lenght-1,MapObjects[i].y+MapObjects[i].dir-1, players[o]);
if rzlt = true then break;
end;
if rzlt = true then begin
//shit
for p := 0 to NUM_OBJECTS do
if (MapObjects[p].active = true) and (MapObjects[p].targetname = MapObjects[i].target) and ((MapObjects[p].objtype = 3) or (MapObjects[p].objtype = 6)) then ACTIVATEOBJ(p);
end;
end;
// ---------------------------------------
if MapObjects[i].objtype = 5 then begin // area_push
if MapObjects[i].targetname > 0 then dec(MapObjects[i].targetname);
if MapObjects[i].targetname > 0 then exit;
// if gametic<=5 then exit;
MapObjects[i].targetname := MapObjects[i].wait;
if not MATCH_DDEMOPLAY then
for o := 0 to SYS_MAXPLAYERS-1 do begin
if players[o] <> nil then if (players[o].dead = 0) then begin
rzlt := player_region_touch (MapObjects[i].x,MapObjects[i].y,MapObjects[i].x+MapObjects[i].lenght-1,MapObjects[i].y+MapObjects[i].dir-1, players[o]);
if rzlt = true then begin
if (players[o].netobject=false) then begin
if MapObjects[i].orient = 0 then players[o].InertiaX := -MapObjects[i].special/10;
if MapObjects[i].orient = 1 then players[o].InertiaY := -MapObjects[i].special/10;
if MapObjects[i].orient = 2 then players[o].InertiaX := MapObjects[i].special/10;
if MapObjects[i].orient = 3 then players[o].InertiaY := MapObjects[i].special/10;
end;
if (rzlt = true) and (ismultip<=1) then begin
// if have target. fire it.
if MapObjects[i].target > 0 then for p := 0 to NUM_OBJECTS do
if (MapObjects[p].active = true) and (MapObjects[p].targetname = MapObjects[i].target) and ((MapObjects[p].objtype = 3) or (MapObjects[p].objtype = 6)) then ACTIVATEOBJ(p);
end;
end;
end;
end;
for o := 0 to 1000 do if (GameObjects[o].objname = 'gib')then
if object_region_touch (MapObjects[i].x,MapObjects[i].y,MapObjects[i].x+MapObjects[i].lenght-1,MapObjects[i].y+MapObjects[i].dir-1, GameObjects[o]) then
begin
if MapObjects[i].orient = 0 then GameObjects[o].InertiaX := -MapObjects[i].special/10;
if MapObjects[i].orient = 1 then GameObjects[o].InertiaY := -MapObjects[i].special/10;
if MapObjects[i].orient = 2 then GameObjects[o].InertiaX := MapObjects[i].special/10;
if MapObjects[i].orient = 3 then GameObjects[o].InertiaY := MapObjects[i].special/10;
end;
end;
// ---------------------------------------
if MapObjects[i].objtype = 6 then begin // area_pain
if MATCH_DDEMOPLAY then exit;
// if gametic<=5 then exit;
if ismultip=2 then exit;
//------------
if MapObjects[i].targetname = 0 then begin // JUST INSTANT PAIN!
if MapObjects[i].target > 0 then dec(MapObjects[i].target);
if MapObjects[i].target > 0 then exit;
MapObjects[i].target := MapObjects[i].nowanim;
for o := 0 to SYS_MAXPLAYERS-1 do begin
if players[o] <> nil then if players[o].dead = 0 then begin
rzlt := player_region_touch (MapObjects[i].x,MapObjects[i].y,MapObjects[i].x+MapObjects[i].special-1,MapObjects[i].y+MapObjects[i].orient-1, players[o]);
if rzlt = true then if players[o].health > 0 then begin
ApplyDamage(players[o],MapObjects[i].dir ,GameObjects[0],DIE_INPAIN);
SpawnBlood(players[o]);
end;
end;
end;
end;
//------------
if MapObjects[i].targetname > 0 then begin
if MapObjects[i].lenght > 0 then begin // waittime.
if MapObjects[i].target > 0 then begin // active. burn em burn em burn em.
dec(MapObjects[i].target);
if MapObjects[i].target=0 then begin // active wait time finished, so, do something,,,
MapObjects[i].target := MapObjects[i].nowanim; // MapObjects[i].wait itsa DMG INTERVAL.
for o := 0 to SYS_MAXPLAYERS-1 do begin
rzlt := player_region_touch (MapObjects[i].x,MapObjects[i].y,MapObjects[i].x+MapObjects[i].special-1,MapObjects[i].y+MapObjects[i].orient-1, players[o]);
if rzlt = true then if players[o].health > 0 then begin
ApplyDamage(players[o],MapObjects[i].dir ,GameObjects[0],DIE_INPAIN);
SpawnBlood(players[o]);
end;
end;
end;
end;
dec(MapObjects[i].lenght);
end;
end;
//------------
end;
// ---------------------------------------
if MapObjects[i].objtype = 7 then begin // area_trickarena_end;
if MATCH_GAMETYPE <> GAMETYPE_TRIXARENA then exit;
if ismultip > 1 then exit;
if MATCH_DDEMOPLAY then exit;
if MATCH_GAMEEND = true then exit;
for o := 0 to SYS_MAXPLAYERS-1 do begin
if players[o] <> nil then if players[o].dead = 0 then
rzlt := player_region_touch (MapObjects[i].x,MapObjects[i].y,MapObjects[i].x+MapObjects[i].special-1,MapObjects[i].y+MapObjects[i].orient-1, players[o]);
if rzlt = true then if players[o].health > 0 then begin
str := '';
if trunc(gametime / 60) < 10 then str := '0';
str := str + inttostr(trunc(gametime/60))+':';
if gametime - trunc(gametime / 60)*60 < 10 then str := str + '0';
str := str + inttostr(gametime - trunc(gametime / 60)*60);
if MATCH_STARTSIN = 0 then begin
addmessage(players[o].netname + ' ^7^nfinished the level. Time: '+str+'.'+inttostr(gametic));
if ismultip=1 then begin
MsgSize := SizeOf(TMP_TrixArenaWin);
Msg4.Data := MMP_MULTITRIX_WIN;
Msg4.DXID := players[o].DXID;
Msg4.gametic := gametic;
Msg4.gametime := gametime;
mainform.BNETSendData2All (Msg4, MsgSize, 1);
end;
IF MATCH_DRECORD then begin
ddata.gametic := gametic;
ddata.gametime := gametime;
ddata.type0 := DDEMO_TRIXARENAEND;
DemoStream.Write( DData, Sizeof(DData));
DTrixArenaEnd.DXID := players[o].dxid;
DemoStream.Write( DTrixArenaEnd, Sizeof(DTrixArenaEnd));
end;
GameEnd(END_JUSTEND);
if (OPT_TRIXMASTA) then begin
if fileexists(ROOTDIR+'\demos\temp.ndm') then begin
str2 := 'myrecords_'+map_filename+'_'+toValidFilename(str)+'_'+inttostr(gametic)+'s_';
for i := 0 to SYS_MAXPLAYERS-1 do begin if players[i] <> nil then
str2:= str2+toValidFilename(StripColorName(players[i].netname))+'.ndm';
break;
end;
Renamefile(ROOTDIR+'\demos\temp.ndm',ROOTDIR+'\demos\'+lowercase(str2));
addmessage('demo saved as "'+lowercase(str2)+'"');
end;
end;
end else begin
addmessage('Trix arena doesnt works in warmup.');
ApplyDamage(players[o],10,GameObjects[0],DIE_WRONGPLACE);
end;
break;
end;
end;
end;
// ---------------------------------------
if MapObjects[i].objtype = 8 then begin // area_teleport;
if MATCH_DDEMOPLAY then exit;
// if gametime<=1 then exit;
if MATCH_GAMEEND = true then exit;
for o := 0 to SYS_MAXPLAYERS-1 do begin
rzlt := player_region_touch (MapObjects[i].x,MapObjects[i].y,MapObjects[i].x+MapObjects[i].special-1,MapObjects[i].y+MapObjects[i].orient-1, players[o]);
if rzlt = true then if (players[o].dead = 0) and (players[o].health > 0) and (players[o].netobject=false) then begin
RespawnFlash(players[o].x-16, players[o].y);
players[o].x := MapObjects[i].dir * 32 +16;
players[o].y := MapObjects[i].wait * 16 - 8;
if players[o].inertiax > 1 then players[o].inertiax := players[o].inertiax / 2;
RespawnFlash(MapObjects[i].dir * 32,MapObjects[i].wait * 16);
MsgSize := SizeOf(TMP_TeleportPlayer);
Msg3.Data := MMP_TELEPORTPLAYER;
Msg3.x1 := round(players[o].x-16);
Msg3.y1 := round(players[o].y);
Msg3.x2 := MapObjects[i].dir * 32;
Msg3.y2 := MapObjects[i].wait * 16;
mainform.BNETSendData2All (Msg3, MsgSize, 0);
end;
end;
end;
// ---------------------------------------
if MapObjects[i].objtype = 9 then begin // doortrigger;
// nothing to do... so, we just sit here, and make our selves looks DUDE
if MapObjects[i].targetname > 0 then dec(MapObjects[i].targetname);
end;
end;
//------------------------------------------------------------------------------
procedure GetMapWeaponData;
var x,y : word;
begin
mapweapondata.machine := true;
mapweapondata.shotgun := false;
mapweapondata.grenade := false;
mapweapondata.rocket := false;
mapweapondata.shaft := false;
mapweapondata.rail := false;
mapweapondata.plasma := false;
mapweapondata.bfg := false;
if MATCH_GAMETYPE=GAMETYPE_RAILARENA then begin
mapweapondata.machine := false;
mapweapondata.rail := true;
exit;
end;
for x := 0 to BRICK_X-1 do
for y := 0 to BRICK_Y-1 do begin
if AllBricks[x,y].image = 1 then mapweapondata.shotgun := true;
if AllBricks[x,y].image = 2 then mapweapondata.grenade := true;
if AllBricks[x,y].image = 3 then mapweapondata.rocket := true;
if AllBricks[x,y].image = 4 then mapweapondata.shaft := true;
if AllBricks[x,y].image = 5 then mapweapondata.rail := true;
if AllBricks[x,y].image = 6 then mapweapondata.plasma := true;
if AllBricks[x,y].image = 7 then mapweapondata.bfg := true;
end;
end;
//------------------------------------------------------------------------------
function LOADMAPCRC32(filename:string):Cardinal;
var buffer : array[1..8192] of Char;
CRC : Cardinal;
Count : Cardinal;
F : File;
begin
if not fileexists(filename) then begin
addmessage('^1CRC32: Could not find map '+(filename));
exit;
end;
CRC := CRC32INIT;
{$I-}
AssignFile(F, filename);
FileMode := 0;
Reset(F,1);
{$I+}
if IOResult<>0 then begin
CloseFile(f);
addmessage('^1Cannot open file '+filename);
exit;
end;
repeat
BlockRead(F, Buffer, SizeOf( Buffer ), Count);
CRC := CalculateBufferCRC32( CRC, Buffer, Count );
until Eof(F);
CRC := CRC xor CRC32INIT;
result := CRC;
closefile(f);
end;
//------------------------------------------------------------------------------
procedure ADDDirContentMaps(StartDir: string; List:TStrings);
var
SearchRec : TSearchRec;
begin
if StartDir[Length(StartDir)] <> '\' then StartDir := StartDir + '\';
if FindFirst(startdir+'*.*', faAnyfile, SearchRec) = 0 then begin
if (SearchRec.Name <> '..') and (SearchRec.Name <> '.') then
if (SearchRec.Attr and faDirectory) <> faDirectory then
List.Add(copy( StartDir+SearchRec.Name,length(ROOTDIR+'\maps')+2,length(StartDir+SearchRec.Name)-length(ROOTDIR+'\maps')-1 )) else
ADDDirContentMaps(StartDir+searchrec.name, list);
while FindNext(SearchRec) = 0 do begin
if (SearchRec.Name <> '..') and (SearchRec.Name <> '.') then
if (SearchRec.Attr and faDirectory) <> faDirectory then
List.Add(copy( StartDir+SearchRec.Name,length(ROOTDIR+'\maps')+2,length(StartDir+SearchRec.Name)-length(ROOTDIR+'\maps')-1 )) else
ADDDirContentMaps(StartDir+searchrec.name,list);
end;
end;
FindClose(SearchRec);
end;
//------------------------------------------------------------------------------
{
Return Values:
LMS_OK
LMS_NOTFOUND
LMS_CRC32FAILED
}
// just scan for filename at the maps folder
function LoadMapSearchSimple(filename:string):byte;
var TempMapList:TStringList;
i : word;
begin
TempMapList := TStringList.create;
ADDDirContentMaps(ROOTDIR+'\maps', TempMapList);
if TempMapList.count = 0 then begin
TempMapList.free;
result := LMS_NOTFOUND;
exit;
end;
for i := 0 to TempMapList.Count-1 do begin
if extractfilename(lowercase(TempMapList[i])) = filename then begin
loadmapsearch_lastfile := TempMapList[i];
result := LMS_OK;
TempMapList.free;
exit;
end;
end;
result := LMS_NOTFOUND;
TempMapList.free;
end;
//------------------------------------------------------------------------------
function MAPExists(filename:string; CRC32:cardinal) : boolean;
var TempMapList:TStringList;
i : word;
found:boolean;
begin
if lowercase(extractfileext(filename))='' then filename := filename + '.mapa';
result := false;
TempMapList := TStringList.create;
ADDDirContentMaps(ROOTDIR+'\maps', TempMapList);
if TempMapList.count = 0 then begin
TempMapList.free;
result := false;
exit;
end;
found := false;
for i := 0 to TempMapList.Count-1 do
if extractfilename(lowercase(TempMapList[i])) = filename then begin
// if LOADMAPCRC32(ROOTDIR+'\maps\'+TempMapList[i]) = CRC32 then begin
result := true;
TempMapList.free;
exit;
end;
end;
//------------------------------------------------------------------------------
function LOADMAPSearch(filename:string;CRC32:cardinal) : byte;
var TempMapList:TStringList;
i : word;
found:boolean;
begin
TempMapList := TStringList.create;
ADDDirContentMaps(ROOTDIR+'\maps', TempMapList);
if TempMapList.count = 0 then begin
TempMapList.free;
result := LMS_NOTFOUND;
exit;
end;
found := false;
for i := 0 to TempMapList.Count-1 do begin
if extractfilename(lowercase(TempMapList[i])) = filename then begin
found := true;
if LOADMAPCRC32(ROOTDIR+'\maps\'+TempMapList[i]) = CRC32 then begin
loadmapsearch_lastfile := TempMapList[i];
result := LMS_OK;
TempMapList.free;
exit;
end;
end;
end;
if found then
result := LMS_CRC32FAILED
else result := LMS_NOTFOUND;
TempMapList.free;
end;
//------------------------------------------------------------------------------
function CTF_ValidMap:boolean;
var i,a,nr,nb:byte;
begin
nr := 0;
nb := 0;
for i := 0 to BRICK_X-1 do
for a := 0 to BRICK_Y-1 do begin
if (AllBricks[i,a].image = 40) then inc(nr);
if (AllBricks[i,a].image = 41) then inc(nb);
end;
if (nr=1) and (nb=1) then result:=true else result := false;
if (RESPAWNSRED_COUNT=0) or (RESPAWNSBLUE_COUNT=0) then result := false;
end;
//------------------------------------------------------------------------------
function DOM_ValidMap:boolean;
var i,a,nr:byte;
begin
nr := 0;
for i := 0 to BRICK_X-1 do
for a := 0 to BRICK_Y-1 do begin
if (AllBricks[i,a].image = CONTENT_DOMPOINT) then inc(nr);
end;
if (nr=3) then result:=true else result := false;
end;
//------------------------------------------------------------------------------
procedure LOADMAP (Filename : string; inreal : boolean);
Const BufSize = 3*4*4096;
Type TBuffer = array [1..BufSize] of Byte;
var F : File;
i,a,z : Integer;
Header : THeader;
tmp : TmapobjV2;
buf : array [0..$FE] of byte;
Entry:TMapEntry;
Buffer : TBuffer;
TotalSize, NumRead:longint;
CompressedPaletteStream : TMemoryStream;
ProgressCallback :TProgressEvent;
realEOF:boolean;
begin
//-------------------------------------------
//addmessage('loading map...');
fillchar(LocationsArray, sizeof(LocationsArray),0);
if not inreal then begin // DEMO MAP LOADING.
DemoStream.read( Header, Sizeof(Header));
if header.ID <> 'NDEM' then begin
// DemoStream.position := 0;
addmessage(filename +' is not NFK demo');
ShowCriticalError('Error loading demo',extractfilename(filename) +' is not NFK demo','or file corrupted.');
SND.play(SND_error,0,0);
Applyhcommand('disconnect');
exit;
end;
DDEMO_VERSION := header.Version;
if ((header.Version < 3) or (header.Version > 6)) then begin
addmessage('incorrect demo version ('+inttostr(header.version)+'). Only versions 3-6 supported.');
ShowCriticalError('Incorrect demo version','incorrect demo version ('+inttostr(header.version)+').','Only versions 3-6 supported.');
Applyhcommand('disconnect');
exit;
end;
MATCH_GAMETYPE := header.GAMETYPE;
BRICK_X := header.MapSizeX;
BRICK_Y := header.MapSizeY;
map_bg := header.BG;
if OPT_ALLOWMAPCHANGEBG then if header.BG > 0 then OPT_BG := header.BG;
if OPT_BG > 8 then OPT_BG := 8;
//brick field 19x29. erazing.
for i := 0 to BRICK_X-1 do
for z := 0 to BRICK_Y-1 do begin
AllBricks[i,z].image :=0;
AllBricks[i,z].block :=false;
AllBricks[i,z].respawntime := 0;
AllBricks[i,z].y :=0;
AllBricks[i,z].dir :=0;
AllBricks[i,z].scale := 255;
AllBricks[i,z].oy :=0;
AllBricks[i,z].respawnable := false;
end;
map_name := header.MapName;
map_author := header.Author;
RESPAWNS_COUNT := 0;
RESPAWNSRED_COUNT := 0;
RESPAWNSBLUE_COUNT := 0;
for a := 0 to header.MapSizeY - 1 do begin
DemoStream.read(buf,header.MapSizeX);
for z := 0 to header.MapSizeX - 1 do
AllBricks[z,a].image := buf[z];
end;
// prepare some of bricks.
for a := 0 to BRICK_X do
for z := 0 to BRICK_Y do begin
if (AllBricks[a,z].image >= 1) and (AllBricks[a,z].image <= 30) then begin // items
AllBricks[a,z].block := false;
AllBricks[a,z].respawnable := true;
AllBricks[a,z].respawntime := 0;
end;
if (AllBricks[a,z].image = 34) then begin // respawn point.
AllBricks[a,z].block := false;
AllBricks[a,z].respawnable := false;
AllBricks[a,z].respawntime := -1;
AllBricks[a,z].image := 0;
inc(RESPAWNS_COUNT);
end;
if (AllBricks[a,z].image >= 54) then begin // bricks
AllBricks[a,z].block := true;
AllBricks[a,z].respawnable := false;
AllBricks[a,z].respawntime := 0;
end;
if (AllBricks[a,z].image >= 31) and (AllBricks[a,z].image <= 39) then begin // misc
AllBricks[a,z].block := false;
AllBricks[a,z].respawnable := false;
AllBricks[a,z].respawntime := 0;
end;
if (AllBricks[a,z].image = 37) then begin // empty
AllBricks[a,z].block := true;
AllBricks[a,z].respawnable := false;
AllBricks[a,z].respawntime := 0;
end;
if (AllBricks[a,z].image >= 40) and (AllBricks[a,z].image <= 42) then
AllBricks[a,z].dir := 0;
end;
// ======== border block.
// fill border. ppì bugs protection.
for i := 0 to BRICK_X-1 do begin
AllBricks[i,0].block := true;
AllBricks[i,BRICK_Y-1].block := true;
if AllBricks[i,0].image = 37 then AllBricks[i,0].image := 0;
if AllBricks[i,BRICK_Y-1].image = 37 then AllBricks[i,BRICK_Y-1].image := 0;
end;
for i := 1 to BRICK_Y-2 do begin
AllBricks[0,i].block := true;
AllBricks[BRICK_X-1,i].block := true;
if AllBricks[0,i].image = 37 then AllBricks[0,i].image := 0;
if AllBricks[BRICK_X-1,i].image = 37 then AllBricks[BRICK_X-1,i].image := 0;
end;
GetMapWeaponData; // for stats.
OPT_SHOWSTATS := false;
GX := 0; GY := 0;
if (BRICK_X = 20) and (BRICK_Y = 30) then OPT_CAMERATYPE := 0 else OPT_CAMERATYPE := 1;
// reset special objects.
for i := 0 to 255 do MapObjects[i].active := false;
MSG_DISABLE := FALSE;
if header.numobj > 0 then begin
NUM_OBJECTS := header.numobj-1;
NUM_OBJECTS_0 := false;
end;
z := 0;
if not NUM_OBJECTS_0 then
for a := 0 to header.numobj-1 do begin
DemoStream.read(tmp,sizeof(tmp));
if tmp.objtype = 1 then begin
MapObjects[z].active := true;
MapObjects[z].x := tmp.x;
MapObjects[z].y := tmp.y;
MapObjects[z].lenght := tmp.lenght;
MapObjects[z].dir := tmp.dir;
MapObjects[z].objtype := 1;
inc(z);
end;
if tmp.objtype = 2 then begin
MapObjects[z].active := true;
MapObjects[z].objtype := 2;
MapObjects[z].x := tmp.x;
MapObjects[z].y := tmp.y;
MapObjects[z].target := tmp.target;
MapObjects[z].targetname := 0;
MapObjects[z].wait := tmp.wait;
MapObjects[z].orient := tmp.orient;
MapObjects[z].special := tmp.special;
MapObjects[z].nowanim := 0;
inc(z);
end;
if tmp.objtype = 3 then begin
MapObjects[z].active := true;
MapObjects[z].objtype := 3;
MapObjects[z].x := tmp.x;
MapObjects[z].y := tmp.y;
MapObjects[z].targetname := tmp.targetname;
if tmp.wait = 0 then tmp.wait := 100;
MapObjects[z].wait := tmp.wait;
MapObjects[z].lenght := tmp.lenght;
MapObjects[z].special := tmp.special;
MapObjects[z].dir := 1;
MapObjects[z].orient := tmp.orient;
if (MapObjects[z].orient = 1) or (MapObjects[z].orient = 0) then MapObjects[z].target := 1 else MapObjects[z].target := 0;
MapObjects[z].nowanim := 0;
inc(z);
end;
if tmp.objtype = 4 then begin
MapObjects[z].active := true;
MapObjects[z].objtype := 4;
MapObjects[z].x := tmp.x;
MapObjects[z].y := tmp.y;
MapObjects[z].target := tmp.target;
MapObjects[z].wait := tmp.wait;
MapObjects[z].lenght := tmp.lenght;
MapObjects[z].dir := tmp.dir;
inc(z);
end;
if tmp.objtype = 5 then begin
MapObjects[z].active := true;
MapObjects[z].objtype := 5;
MapObjects[z].x := tmp.x;