1 (* Copyright (C) Doom 2D: Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, version 3 of the License ONLY.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 {$INCLUDE ../shared/a_modes.inc}
16 {.$DEFINE GWEP_HITSCAN_TRACE_BITMAP_CHECKER}
22 SysUtils
, Classes
, mempool
,
23 g_basic
, g_phys
, xprofiler
;
37 procedure positionChanged (); //WARNING! call this after monster position was changed, or coldet will not work right!
42 Shots
: array of TShot
= nil;
43 LastShotID
: Integer = 0;
45 procedure g_Weapon_LoadData();
46 procedure g_Weapon_FreeData();
47 procedure g_Weapon_Init();
48 procedure g_Weapon_Free();
49 function g_Weapon_Hit(obj
: PObj
; d
: Integer; SpawnerUID
: Word; t
: Byte; HitCorpses
: Boolean = True): Byte;
50 function g_Weapon_HitUID(UID
: Word; d
: Integer; SpawnerUID
: Word; t
: Byte): Boolean;
51 function g_Weapon_CreateShot(I
: Integer; ShotType
: Byte; Spawner
, TargetUID
: Word; X
, Y
, XV
, YV
: Integer): LongWord;
53 procedure g_Weapon_gun(const x
, y
, xd
, yd
, v
, indmg
: Integer; SpawnerUID
: Word; CheckTrigger
: Boolean);
54 procedure g_Weapon_punch(x
, y
: Integer; d
, SpawnerUID
: Word);
55 function g_Weapon_chainsaw(x
, y
: Integer; d
, SpawnerUID
: Word): Integer;
56 procedure g_Weapon_rocket(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1; Silent
: Boolean = False; compat
: Boolean = true);
57 procedure g_Weapon_revf(x
, y
, xd
, yd
: Integer; SpawnerUID
, TargetUID
: Word; WID
: Integer = -1; Silent
: Boolean = False);
58 procedure g_Weapon_flame(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1; Silent
: Boolean = False; compat
: Boolean = true);
59 procedure g_Weapon_plasma(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1; Silent
: Boolean = False; compat
: Boolean = true);
60 procedure g_Weapon_ball1(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1; Silent
: Boolean = False; compat
: Boolean = true);
61 procedure g_Weapon_ball2(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1; Silent
: Boolean = False; compat
: Boolean = true);
62 procedure g_Weapon_ball7(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1; Silent
: Boolean = False; compat
: Boolean = true);
63 procedure g_Weapon_aplasma(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1; Silent
: Boolean = False; compat
: Boolean = true);
64 procedure g_Weapon_manfire(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1; Silent
: Boolean = False; compat
: Boolean = true);
65 procedure g_Weapon_bfgshot(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1; Silent
: Boolean = False; compat
: Boolean = true);
66 procedure g_Weapon_bfghit(x
, y
: Integer);
67 procedure g_Weapon_pistol(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; Silent
: Boolean = False);
68 procedure g_Weapon_mgun(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; Silent
: Boolean = False);
69 procedure g_Weapon_shotgun(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; Silent
: Boolean = False);
70 procedure g_Weapon_dshotgun(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; Silent
: Boolean = False);
72 function g_Weapon_Explode(X
, Y
: Integer; rad
: Integer; SpawnerUID
: Word): Boolean;
73 procedure g_Weapon_BFG9000(X
, Y
: Integer; SpawnerUID
: Word);
74 procedure g_Weapon_PreUpdate();
75 procedure g_Weapon_Update();
76 function g_Weapon_Danger(UID
: Word; X
, Y
: Integer; Width
, Height
: Word; Time
: Byte): Boolean;
77 procedure g_Weapon_DestroyShot(I
: Integer; X
, Y
: Integer; Loud
: Boolean = True);
79 procedure g_Weapon_SaveState (st
: TStream
);
80 procedure g_Weapon_LoadState (st
: TStream
);
82 procedure g_Weapon_AddDynLights();
91 WEAPON_ROCKETLAUNCHER
= 6;
94 WEAPON_SUPERPULEMET
= 9;
95 WEAPON_FLAMETHROWER
= 10;
96 WEAPON_ZOMBY_PISTOL
= 20;
99 WEAPON_CACO_FIRE
= 23;
100 WEAPON_BARON_FIRE
= 24;
101 WEAPON_MANCUB_FIRE
= 25;
102 WEAPON_SKEL_FIRE
= 26;
103 WEAPON_LAST
= WEAPON_SKEL_FIRE
;
105 WP_FIRST
= WEAPON_KASTET
;
106 WP_LAST
= WEAPON_FLAMETHROWER
;
109 gwep_debug_fast_trace
: Boolean = true;
121 {$IFDEF ENABLE_CORPSES}
124 Math
, g_map
, g_player
, g_sound
, g_panel
,
125 g_console
, g_options
, g_game
,
126 g_triggers
, MAPDEF
, e_log
, g_monsters
, g_saveload
,
127 g_language
, g_netmsg
, g_grid
, g_window
,
128 geom
, binheap
, hashtable
, utils
, xstreams
139 SHOT_ROCKETLAUNCHER_WIDTH
= 14;
140 SHOT_ROCKETLAUNCHER_HEIGHT
= 14;
142 SHOT_SKELFIRE_WIDTH
= 14;
143 SHOT_SKELFIRE_HEIGHT
= 14;
145 SHOT_PLASMA_WIDTH
= 16;
146 SHOT_PLASMA_HEIGHT
= 16;
149 SHOT_BFG_HEIGHT
= 32;
150 SHOT_BFG_DAMAGE
= 100;
151 SHOT_BFG_RADIUS
= 256;
153 SHOT_FLAME_WIDTH
= 4;
154 SHOT_FLAME_HEIGHT
= 4;
155 SHOT_FLAME_LIFETIME
= 180;
157 SHOT_SIGNATURE
= $544F4853; // 'SHOT'
160 PHitTime
= ^THitTime
;
164 plridx
: Integer; // if mon=nil
168 TBinHeapKeyHitTime
= class
170 class function less (const a
, b
: Integer): Boolean; inline;
173 // indicies in `wgunHitTime` array
174 TBinaryHeapHitTimes
= specialize TBinaryHeapBase
<Integer, TBinHeapKeyHitTime
>;
177 WaterMap
: array of array of DWORD
= nil;
178 //wgunMonHash: THashIntInt = nil;
179 wgunHitHeap
: TBinaryHeapHitTimes
= nil;
180 wgunHitTime
: array of THitTime
= nil;
181 wgunHitTimeUsed
: Integer = 0;
184 class function TBinHeapKeyHitTime
.less (const a
, b
: Integer): Boolean;
188 hta
:= @wgunHitTime
[a
];
189 htb
:= @wgunHitTime
[b
];
190 if (hta
.distSq
<> htb
.distSq
) then begin result
:= (hta
.distSq
< htb
.distSq
); exit
; end;
191 if (hta
.mon
<> nil) then
194 if (htb
.mon
= nil) then begin result
:= false; exit
; end; // players first
195 result
:= (hta
.mon
.UID
< htb
.mon
.UID
); // why not?
200 if (htb
.mon
<> nil) then begin result
:= true; exit
; end; // players first
201 result
:= (hta
.plridx
< htb
.plridx
); // why not?
206 procedure appendHitTimeMon (adistSq
: Integer; amon
: TMonster
; ax
, ay
: Integer);
208 if (wgunHitTimeUsed
= Length(wgunHitTime
)) then SetLength(wgunHitTime
, wgunHitTimeUsed
+128);
209 with wgunHitTime
[wgunHitTimeUsed
] do
217 wgunHitHeap
.insert(wgunHitTimeUsed
);
218 Inc(wgunHitTimeUsed
);
222 procedure appendHitTimePlr (adistSq
: Integer; aplridx
: Integer; ax
, ay
: Integer);
224 if (wgunHitTimeUsed
= Length(wgunHitTime
)) then SetLength(wgunHitTime
, wgunHitTimeUsed
+128);
225 with wgunHitTime
[wgunHitTimeUsed
] do
233 wgunHitHeap
.insert(wgunHitTimeUsed
);
234 Inc(wgunHitTimeUsed
);
238 function FindShot(): DWORD
;
243 for i
:= 0 to High(Shots
) do
244 if Shots
[i
].ShotType
= 0 then
247 LastShotID
:= Result
;
253 SetLength(Shots
, 128);
258 Result
:= High(Shots
) + 1;
259 SetLength(Shots
, Length(Shots
) + 128);
261 LastShotID
:= Result
;
264 procedure CreateWaterMap();
266 WaterArray
: Array of TWaterPanel
;
273 SetLength(WaterArray
, Length(gWater
));
275 for a
:= 0 to High(gWater
) do
277 WaterArray
[a
].X
:= gWater
[a
].X
;
278 WaterArray
[a
].Y
:= gWater
[a
].Y
;
279 WaterArray
[a
].Width
:= gWater
[a
].Width
;
280 WaterArray
[a
].Height
:= gWater
[a
].Height
;
281 WaterArray
[a
].Active
:= True;
284 g_Game_SetLoadingText(_lc
[I_LOAD_WATER_MAP
], High(WaterArray
), False);
286 for a
:= 0 to High(WaterArray
) do
287 if WaterArray
[a
].Active
then
289 WaterArray
[a
].Active
:= False;
290 m
:= Length(WaterMap
);
291 SetLength(WaterMap
, m
+1);
292 SetLength(WaterMap
[m
], 1);
299 for b
:= 0 to High(WaterArray
) do
300 if WaterArray
[b
].Active
then
301 for c
:= 0 to High(WaterMap
[m
]) do
302 if g_CollideAround(WaterArray
[b
].X
,
305 WaterArray
[b
].Height
,
306 WaterArray
[WaterMap
[m
][c
]].X
,
307 WaterArray
[WaterMap
[m
][c
]].Y
,
308 WaterArray
[WaterMap
[m
][c
]].Width
,
309 WaterArray
[WaterMap
[m
][c
]].Height
) then
311 WaterArray
[b
].Active
:= False;
312 SetLength(WaterMap
[m
],
313 Length(WaterMap
[m
])+1);
314 WaterMap
[m
][High(WaterMap
[m
])] := b
;
320 g_Game_StepLoading();
328 chkTrap_pl
: array [0..256] of Integer;
329 chkTrap_mn
: array [0..65535] of TMonster
;
331 procedure CheckTrap(ID
: DWORD
; dm
: Integer; t
: Byte);
333 //a, b, c, d, i1, i2: Integer;
334 //chkTrap_pl, chkTrap_mn: WArray;
335 plaCount
: Integer = 0;
336 mnaCount
: Integer = 0;
340 function monsWaterCheck (mon: TMonster): Boolean;
342 result := false; // don't stop
343 if mon.alive and mon.Collide(gWater[WaterMap[a][c]]) and (not InWArray(monidx, chkTrap_mn)) and (i2 < 1023) then //FIXME
346 chkTrap_mn[i2] := monidx;
351 function monsWaterCheck (mon
: TMonster
): Boolean;
353 result
:= false; // don't stop
354 if (mon
.trapCheckFrameId
<> frameId
) then
356 mon
.trapCheckFrameId
:= frameId
;
357 chkTrap_mn
[mnaCount
] := mon
;
363 a
, b
, c
, d
, f
: Integer;
366 if (gWater
= nil) or (WaterMap
= nil) then Exit
;
368 frameId
:= g_Mons_getNewTrapFrameId();
373 //SetLength(chkTrap_pl, 1024);
374 //SetLength(chkTrap_mn, 1024);
375 //for d := 0 to 1023 do chkTrap_pl[d] := $FFFF;
376 //for d := 0 to 1023 do chkTrap_mn[d] := $FFFF;
378 for a
:= 0 to High(WaterMap
) do
380 for b
:= 0 to High(WaterMap
[a
]) do
382 pan
:= gWater
[WaterMap
[a
][b
]];
383 if not g_Obj_Collide(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, @Shots
[ID
].Obj
) then continue
;
385 for c
:= 0 to High(WaterMap
[a
]) do
387 pan
:= gWater
[WaterMap
[a
][c
]];
388 for d
:= 0 to High(gPlayers
) do
390 if (gPlayers
[d
] <> nil) and (gPlayers
[d
].alive
) then
392 if gPlayers
[d
].Collide(pan
) then
395 while (f
< plaCount
) and (chkTrap_pl
[f
] <> d
) do Inc(f
);
396 if (f
= plaCount
) then
398 chkTrap_pl
[plaCount
] := d
;
400 if (plaCount
= Length(chkTrap_pl
)) then break
;
406 //g_Mons_ForEach(monsWaterCheck);
407 g_Mons_ForEachAliveAt(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, monsWaterCheck
);
410 for f
:= 0 to plaCount
-1 do gPlayers
[chkTrap_pl
[f
]].Damage(dm
, Shots
[ID
].SpawnerUID
, 0, 0, t
);
411 for f
:= 0 to mnaCount
-1 do chkTrap_mn
[f
].Damage(dm
, 0, 0, Shots
[ID
].SpawnerUID
, t
);
419 function HitMonster(m
: TMonster
; d
: Integer; vx
, vy
: Integer; SpawnerUID
: Word; t
: Byte): Boolean;
426 tt
:= g_GetUIDType(SpawnerUID
);
427 if tt
= UID_MONSTER
then
429 mon
:= g_Monsters_ByUID(SpawnerUID
);
431 mt
:= g_Monsters_ByUID(SpawnerUID
).MonsterType
438 if m
= nil then Exit
;
439 if m
.UID
= SpawnerUID
then
441 // Ñàì ñåáÿ ìîæåò ðàíèòü òîëüêî ðàêåòîé è òîêîì:
442 if (t
<> HIT_ROCKET
) and (t
<> HIT_ELECTRO
) then
444 // Êèáåð äåìîí è áî÷êà âîîáùå íå ìîãóò ñåáÿ ðàíèòü:
445 if (m
.MonsterType
= MONSTER_CYBER
) or
446 (m
.MonsterType
= MONSTER_BARREL
) then
453 if tt
= UID_MONSTER
then
455 // Lost_Soul íå ìîæåò ðàíèòü Pain_Elemental'à:
456 if (mt
= MONSTER_SOUL
) and (m
.MonsterType
= MONSTER_PAIN
) then
459 // Îáà ìîíñòðà îäíîãî âèäà:
460 if mt
= m
.MonsterType
then
462 MONSTER_IMP
, MONSTER_DEMON
, MONSTER_BARON
, MONSTER_KNIGHT
, MONSTER_CACO
,
463 MONSTER_SOUL
, MONSTER_MANCUB
, MONSTER_SKEL
, MONSTER_FISH
:
464 Exit
; // Ýòè íå áüþò ñâîèõ
468 if g_Game_IsServer
then
470 if (t
<> HIT_FLAME
) or (m
.FFireTime
= 0) or (vx
<> 0) or (vy
<> 0) then
471 Result
:= m
.Damage(d
, vx
, vy
, SpawnerUID
, t
)
473 Result
:= (gLMSRespawn
= LMS_RESPAWN_NONE
); // don't hit monsters when it's warmup time
474 if t
= HIT_FLAME
then
475 m
.CatchFire(SpawnerUID
);
478 Result
:= (gLMSRespawn
= LMS_RESPAWN_NONE
); // don't hit monsters when it's warmup time
482 function HitPlayer (p
: TPlayer
; d
: Integer; vx
, vy
: Integer; SpawnerUID
: Word; t
: Byte): Boolean;
486 // Ñàì ñåáÿ ìîæåò ðàíèòü òîëüêî ðàêåòîé è òîêîì
487 if (p
.UID
= SpawnerUID
) and (t
<> HIT_ROCKET
) and (t
<> HIT_ELECTRO
) then exit
;
489 if g_Game_IsServer
then
491 if (t
<> HIT_FLAME
) or (p
.FFireTime
= 0) or (vx
<> 0) or (vy
<> 0) then p
.Damage(d
, SpawnerUID
, vx
, vy
, t
);
492 if (t
= HIT_FLAME
) then p
.CatchFire(SpawnerUID
);
499 procedure g_Weapon_BFG9000(X
, Y
: Integer; SpawnerUID
: Word);
501 function monsCheck (mon
: TMonster
): Boolean;
503 result
:= false; // don't stop
504 if (mon
.alive
) and (mon
.UID
<> SpawnerUID
) then
508 if (g_PatchLength(X
, Y
, Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2),
509 Obj
.Y
+Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2)) <= SHOT_BFG_RADIUS
) and
510 g_TraceVector(X
, Y
, Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2),
511 Obj
.Y
+Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2)) then
513 if HitMonster(mon
, 50, 0, 0, SpawnerUID
, HIT_SOME
) then mon
.BFGHit();
525 //g_Sound_PlayEx('SOUND_WEAPON_EXPLODEBFG', 255);
527 {$IFDEF ENABLE_CORPSES}
529 if gAdvCorpses
and (h
<> -1) then
533 if (gCorpses
[i
] <> nil) and (gCorpses
[i
].State
<> CORPSE_STATE_REMOVEME
) then
537 if (g_PatchLength(X
, Y
, Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2),
538 Obj
.Y
+Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2)) <= SHOT_BFG_RADIUS
) and
539 g_TraceVector(X
, Y
, Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2),
540 Obj
.Y
+Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2)) then
542 Damage(50, SpawnerUID
, 0, 0);
543 g_Weapon_BFGHit(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2), Obj
.Y
+Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2));
552 pl
:= g_Player_Get(SpawnerUID
);
560 if (gPlayers
[i
] <> nil) and (gPlayers
[i
].alive
) and (gPlayers
[i
].UID
<> SpawnerUID
) then
562 if (g_PatchLength(X
, Y
, GameX
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
563 GameY
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)) <= SHOT_BFG_RADIUS
) and
564 g_TraceVector(X
, Y
, GameX
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
565 GameY
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)) then
567 if (st
= TEAM_NONE
) or (st
<> gPlayers
[i
].Team
) then
568 b
:= HitPlayer(gPlayers
[i
], 50, 0, 0, SpawnerUID
, HIT_SOME
)
570 b
:= HitPlayer(gPlayers
[i
], 25, 0, 0, SpawnerUID
, HIT_SOME
);
572 gPlayers
[i
].BFGHit();
576 g_Mons_ForEachAlive(monsCheck
);
579 function g_Weapon_CreateShot(I
: Integer; ShotType
: Byte; Spawner
, TargetUID
: Word; X
, Y
, XV
, YV
: Integer): LongWord;
584 find_id
:= FindShot()
588 if Integer(find_id
) >= High(Shots
) then
589 SetLength(Shots
, find_id
+ 64)
592 shots
[find_id
].time
:= gTime
;
595 WEAPON_ROCKETLAUNCHER
:
597 with Shots
[find_id
] do
601 Obj
.Rect
.Width
:= SHOT_ROCKETLAUNCHER_WIDTH
;
602 Obj
.Rect
.Height
:= SHOT_ROCKETLAUNCHER_HEIGHT
;
605 ShotType
:= WEAPON_ROCKETLAUNCHER
;
611 with Shots
[find_id
] do
615 Obj
.Rect
.Width
:= SHOT_PLASMA_WIDTH
;
616 Obj
.Rect
.Height
:= SHOT_PLASMA_HEIGHT
;
619 ShotType
:= WEAPON_PLASMA
;
625 with Shots
[find_id
] do
629 Obj
.Rect
.Width
:= SHOT_BFG_WIDTH
;
630 Obj
.Rect
.Height
:= SHOT_BFG_HEIGHT
;
633 ShotType
:= WEAPON_BFG
;
639 with Shots
[find_id
] do
643 Obj
.Rect
.Width
:= SHOT_FLAME_WIDTH
;
644 Obj
.Rect
.Height
:= SHOT_FLAME_HEIGHT
;
647 ShotType
:= WEAPON_FLAMETHROWER
;
653 with Shots
[find_id
] do
657 Obj
.Rect
.Width
:= 16;
658 Obj
.Rect
.Height
:= 16;
661 ShotType
:= WEAPON_IMP_FIRE
;
667 with Shots
[find_id
] do
671 Obj
.Rect
.Width
:= 16;
672 Obj
.Rect
.Height
:= 16;
675 ShotType
:= WEAPON_CACO_FIRE
;
681 with Shots
[find_id
] do
685 Obj
.Rect
.Width
:= 32;
686 Obj
.Rect
.Height
:= 32;
689 ShotType
:= WEAPON_MANCUB_FIRE
;
695 with Shots
[find_id
] do
699 Obj
.Rect
.Width
:= 16;
700 Obj
.Rect
.Height
:= 16;
703 ShotType
:= WEAPON_BARON_FIRE
;
709 with Shots
[find_id
] do
713 Obj
.Rect
.Width
:= 16;
714 Obj
.Rect
.Height
:= 16;
717 ShotType
:= WEAPON_BSP_FIRE
;
723 with Shots
[find_id
] do
727 Obj
.Rect
.Width
:= SHOT_SKELFIRE_WIDTH
;
728 Obj
.Rect
.Height
:= SHOT_SKELFIRE_HEIGHT
;
731 ShotType
:= WEAPON_SKEL_FIRE
;
737 Shots
[find_id
].Obj
.oldX
:= X
;
738 Shots
[find_id
].Obj
.oldY
:= Y
;
739 Shots
[find_id
].Obj
.X
:= X
;
740 Shots
[find_id
].Obj
.Y
:= Y
;
741 Shots
[find_id
].Obj
.Vel
.X
:= XV
;
742 Shots
[find_id
].Obj
.Vel
.Y
:= YV
;
743 Shots
[find_id
].Obj
.Accel
.X
:= 0;
744 Shots
[find_id
].Obj
.Accel
.Y
:= 0;
745 Shots
[find_id
].SpawnerUID
:= Spawner
;
746 if (ShotType
= WEAPON_FLAMETHROWER
) and (XV
= 0) and (YV
= 0) then
747 Shots
[find_id
].Stopped
:= 255
749 Shots
[find_id
].Stopped
:= 0;
753 procedure throw(i
, x
, y
, xd
, yd
, s
: Integer);
760 a
:= Max(Abs(xd
), Abs(yd
));
764 Shots
[i
].Obj
.oldX
:= x
;
765 Shots
[i
].Obj
.oldY
:= y
;
768 Shots
[i
].Obj
.Vel
.X
:= (xd
*s
) div a
;
769 Shots
[i
].Obj
.Vel
.Y
:= (yd
*s
) div a
;
770 Shots
[i
].Obj
.Accel
.X
:= 0;
771 Shots
[i
].Obj
.Accel
.Y
:= 0;
772 Shots
[i
].Stopped
:= 0;
773 if Shots
[i
].ShotType
in [WEAPON_ROCKETLAUNCHER
, WEAPON_BFG
] then
774 Shots
[i
].Timeout
:= 900 // ~25 sec
777 if Shots
[i
].ShotType
= WEAPON_FLAMETHROWER
then
778 Shots
[i
].Timeout
:= SHOT_FLAME_LIFETIME
780 Shots
[i
].Timeout
:= 550; // ~15 sec
784 function g_Weapon_Hit(obj
: PObj
; d
: Integer; SpawnerUID
: Word; t
: Byte; HitCorpses
: Boolean = True): Byte;
785 {$IFDEF ENABLE_CORPSES}
790 function PlayerHit(Team
: Byte = 0): Boolean;
801 if (gPlayers
[i
] <> nil) and gPlayers
[i
].alive
and g_Obj_Collide(obj
, @gPlayers
[i
].Obj
) then
804 if (Team
> 0) and (g_GetUIDType(SpawnerUID
) = UID_PLAYER
) then
806 p
:= g_Player_Get(SpawnerUID
);
808 ChkTeam
:= (p
.Team
= gPlayers
[i
].Team
) xor (Team
= 2);
811 if HitPlayer(gPlayers
[i
], d
, obj
^.Vel
.X
, obj
^.Vel
.Y
, SpawnerUID
, t
) then
813 if t
<> HIT_FLAME
then
814 gPlayers
[i
].Push((obj
^.Vel
.X
+obj
^.Accel
.X
)*IfThen(t
= HIT_BFG
, 8, 1) div 4,
815 (obj
^.Vel
.Y
+obj
^.Accel
.Y
)*IfThen(t
= HIT_BFG
, 8, 1) div 4);
817 g_Game_DelayEvent(DE_BFGHIT
, 1000, SpawnerUID
);
825 function monsCheckHit (monidx: Integer; mon: TMonster): Boolean;
827 result := false; // don't stop
828 if mon.alive and g_Obj_Collide(obj, @mon.Obj) then
830 if HitMonster(mon, d, obj^.Vel.X, obj^.Vel.Y, SpawnerUID, t) then
832 if (t <> HIT_FLAME) then
834 mon.Push((obj^.Vel.X+obj^.Accel.X)*IfThen(t = HIT_BFG, 8, 1) div 4,
835 (obj^.Vel.Y+obj^.Accel.Y)*IfThen(t = HIT_BFG, 8, 1) div 4);
843 function monsCheckHit (mon
: TMonster
): Boolean;
845 result
:= false; // don't stop
846 if HitMonster(mon
, d
, obj
.Vel
.X
, obj
.Vel
.Y
, SpawnerUID
, t
) then
848 if (t
<> HIT_FLAME
) then
850 mon
.Push((obj
.Vel
.X
+obj
.Accel
.X
)*IfThen(t
= HIT_BFG
, 8, 1) div 4,
851 (obj
.Vel
.Y
+obj
.Accel
.Y
)*IfThen(t
= HIT_BFG
, 8, 1) div 4);
857 function MonsterHit(): Boolean;
859 //result := g_Mons_ForEach(monsCheckHit);
860 //FIXME: accelerate this!
861 result
:= g_Mons_ForEachAliveAt(obj
.X
+obj
.Rect
.X
, obj
.Y
+obj
.Rect
.Y
, obj
.Rect
.Width
, obj
.Rect
.Height
, monsCheckHit
);
867 {$IFDEF ENABLE_CORPSES}
871 if gAdvCorpses
and (h
<> -1) then
875 if (gCorpses
[i
] <> nil) and (gCorpses
[i
].State
<> CORPSE_STATE_REMOVEME
) and
876 g_Obj_Collide(obj
, @gCorpses
[i
].Obj
) then
879 gCorpses
[i
].Damage(d
, SpawnerUID
, (obj
^.Vel
.X
+obj
^.Accel
.X
) div 4,
880 (obj
^.Vel
.Y
+obj
^.Accel
.Y
) div 4);
888 case gGameSettings
.GameMode
of
892 // Ñíà÷àëà áü¸ì ìîíñòðîâ, åñëè åñòü, ïîòîì ïûòàåìñÿ áèòü èãðîêîâ
899 // È â êîíöå èãðîêîâ, íî òîëüêî åñëè ïîëîæåíî
900 // (èëè ñíàðÿä îò ìîíñòðà, èëè friendlyfire, èëè friendly_hit_projectile)
901 if (g_GetUIDType(SpawnerUID
) <> UID_PLAYER
) or
902 LongBool(gGameSettings
.Options
and (GAME_OPTION_TEAMDAMAGE
or GAME_OPTION_TEAMHITPROJECTILE
)) then
915 // Ñíà÷àëà áü¸ì èãðîêîâ, åñëè åñòü, ïîòîì ïûòàåìñÿ áèòü ìîíñòðîâ
932 // Ñíà÷àëà áü¸ì èãðîêîâ êîìàíäû ñîïåðíèêà
946 // È â êîíöå ñâîèõ èãðîêîâ, íî òîëüêî åñëè ïîëîæåíî
947 // (èëè friendlyfire, èëè friendly_hit_projectile)
948 if LongBool(gGameSettings
.Options
and (GAME_OPTION_TEAMDAMAGE
or GAME_OPTION_TEAMHITPROJECTILE
)) then
961 function g_Weapon_HitUID(UID
: Word; d
: Integer; SpawnerUID
: Word; t
: Byte): Boolean;
965 case g_GetUIDType(UID
) of
966 UID_PLAYER
: Result
:= HitPlayer(g_Player_Get(UID
), d
, 0, 0, SpawnerUID
, t
);
967 UID_MONSTER
: Result
:= HitMonster(g_Monsters_ByUID(UID
), d
, 0, 0, SpawnerUID
, t
);
972 function g_Weapon_Explode(X
, Y
: Integer; rad
: Integer; SpawnerUID
: Word): Boolean;
974 r
: Integer; // squared radius
976 function monsExCheck (mon
: TMonster
): Boolean;
980 result
:= false; // don't stop
982 dx
:= mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-X
;
983 dy
:= mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2)-Y
;
985 if dx
> 1000 then dx
:= 1000;
986 if dy
> 1000 then dy
:= 1000;
988 if (dx
*dx
+dy
*dy
< r
) then
990 //m := PointToRect(X, Y, Obj.X+Obj.Rect.X, Obj.Y+Obj.Rect.Y, Obj.Rect.Width, Obj.Rect.Height);
991 //e_WriteLog(Format('explo monster #%d: x=%d; y=%d; rad=%d; dx=%d; dy=%d', [monidx, X, Y, rad, dx, dy]), MSG_NOTIFY);
993 mm
:= Max(abs(dx
), abs(dy
));
994 if mm
= 0 then mm
:= 1;
998 HitMonster(mon
, ((mon
.Obj
.Rect
.Width
div 4)*10*(rad
-mm
)) div rad
, 0, 0, SpawnerUID
, HIT_ROCKET
);
1001 mon
.Push((dx
*7) div mm
, (dy
*7) div mm
);
1006 var i
, h
, dx
, dy
, mm
: Integer;
1007 {$IFDEF ENABLE_GIBS}
1008 var _angle
: SmallInt;
1010 {$IF DEFINED(ENABLE_GIBS) OR DEFINED(ENABLE_CORPSES)}
1016 g_Triggers_PressC(X
, Y
, rad
, SpawnerUID
, ACTIVATE_SHOT
);
1020 h
:= High(gPlayers
);
1024 if (gPlayers
[i
] <> nil) and gPlayers
[i
].alive
then
1027 dx
:= Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)-X
;
1028 dy
:= Obj
.Y
+Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2)-Y
;
1030 if dx
> 1000 then dx
:= 1000;
1031 if dy
> 1000 then dy
:= 1000;
1033 if dx
*dx
+dy
*dy
< r
then
1035 //m := PointToRect(X, Y, GameX+PLAYER_RECT.X, GameY+PLAYER_RECT.Y,
1036 // PLAYER_RECT.Width, PLAYER_RECT.Height);
1038 mm
:= Max(abs(dx
), abs(dy
));
1039 if mm
= 0 then mm
:= 1;
1041 HitPlayer(gPlayers
[i
], (100*(rad
-mm
)) div rad
, (dx
*10) div mm
, (dy
*10) div mm
, SpawnerUID
, HIT_ROCKET
);
1042 gPlayers
[i
].Push((dx
*7) div mm
, (dy
*7) div mm
);
1046 //g_Mons_ForEach(monsExCheck);
1047 g_Mons_ForEachAt(X
-(rad
+32), Y
-(rad
+32), (rad
+32)*2, (rad
+32)*2, monsExCheck
);
1049 {$IFDEF ENABLE_CORPSES}
1050 h
:= High(gCorpses
);
1051 if gAdvCorpses
and (h
<> -1) then
1055 if (gCorpses
[i
] <> nil) and (gCorpses
[i
].State
<> CORPSE_STATE_REMOVEME
) then
1059 dx
:= Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)-X
;
1060 dy
:= Obj
.Y
+Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2)-Y
;
1061 if dx
> 1000 then dx
:= 1000;
1062 if dy
> 1000 then dy
:= 1000;
1063 if dx
*dx
+dy
*dy
< r
then
1065 m
:= PointToRect(X
, Y
, Obj
.X
+Obj
.Rect
.X
, Obj
.Y
+Obj
.Rect
.Y
, Obj
.Rect
.Width
, Obj
.Rect
.Height
);
1066 mm
:= Max(abs(dx
), abs(dy
));
1069 Damage(Round(100*(rad
-m
)/rad
), SpawnerUID
, (dx
*10) div mm
, (dy
*10) div mm
);
1077 {$IFDEF ENABLE_GIBS}
1079 if gAdvGibs
and (h
<> -1) then
1081 if gGibs
[i
].alive
then
1084 dx
:= Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)-X
;
1085 dy
:= Obj
.Y
+Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2)-Y
;
1086 if dx
> 1000 then dx
:= 1000;
1087 if dy
> 1000 then dy
:= 1000;
1088 if dx
*dx
+dy
*dy
< r
then
1090 m
:= PointToRect(X
, Y
, Obj
.X
+Obj
.Rect
.X
, Obj
.Y
+Obj
.Rect
.Y
,
1091 Obj
.Rect
.Width
, Obj
.Rect
.Height
);
1092 _angle
:= GetAngle(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2),
1093 Obj
.Y
+Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2), X
, Y
);
1094 g_Obj_PushA(@Obj
, Round(15*(rad
-m
)/rad
), _angle
);
1095 positionChanged(); // this updates spatial accelerators
1101 procedure g_Weapon_Init();
1106 procedure g_Weapon_Free();
1112 procedure g_Weapon_LoadData();
1114 e_WriteLog('Loading weapons data...', TMsgType
.Notify
);
1115 g_Game_SetLoadingText(_lc
[I_LOAD_WEAPONS_DATA
], 0, False);
1117 g_Sound_CreateWADEx('SOUND_WEAPON_HITPUNCH', GameWAD
+':SOUNDS\HITPUNCH');
1118 g_Sound_CreateWADEx('SOUND_WEAPON_MISSPUNCH', GameWAD
+':SOUNDS\MISSPUNCH');
1119 g_Sound_CreateWADEx('SOUND_WEAPON_HITBERSERK', GameWAD
+':SOUNDS\HITBERSERK');
1120 g_Sound_CreateWADEx('SOUND_WEAPON_MISSBERSERK', GameWAD
+':SOUNDS\MISSBERSERK');
1121 g_Sound_CreateWADEx('SOUND_WEAPON_SELECTSAW', GameWAD
+':SOUNDS\SELECTSAW');
1122 g_Sound_CreateWADEx('SOUND_WEAPON_IDLESAW', GameWAD
+':SOUNDS\IDLESAW');
1123 g_Sound_CreateWADEx('SOUND_WEAPON_HITSAW', GameWAD
+':SOUNDS\HITSAW');
1124 g_Sound_CreateWADEx('SOUND_WEAPON_FIRESHOTGUN2', GameWAD
+':SOUNDS\FIRESHOTGUN2');
1125 g_Sound_CreateWADEx('SOUND_WEAPON_FIRESHOTGUN', GameWAD
+':SOUNDS\FIRESHOTGUN');
1126 g_Sound_CreateWADEx('SOUND_WEAPON_FIRESAW', GameWAD
+':SOUNDS\FIRESAW');
1127 g_Sound_CreateWADEx('SOUND_WEAPON_FIREROCKET', GameWAD
+':SOUNDS\FIREROCKET');
1128 g_Sound_CreateWADEx('SOUND_WEAPON_FIREPLASMA', GameWAD
+':SOUNDS\FIREPLASMA');
1129 g_Sound_CreateWADEx('SOUND_WEAPON_FIREPISTOL', GameWAD
+':SOUNDS\FIREPISTOL');
1130 g_Sound_CreateWADEx('SOUND_WEAPON_FIRECGUN', GameWAD
+':SOUNDS\FIRECGUN');
1131 g_Sound_CreateWADEx('SOUND_WEAPON_FIREBFG', GameWAD
+':SOUNDS\FIREBFG');
1132 g_Sound_CreateWADEx('SOUND_FIRE', GameWAD
+':SOUNDS\FIRE');
1133 g_Sound_CreateWADEx('SOUND_IGNITE', GameWAD
+':SOUNDS\IGNITE');
1134 g_Sound_CreateWADEx('SOUND_WEAPON_STARTFIREBFG', GameWAD
+':SOUNDS\STARTFIREBFG');
1135 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEROCKET', GameWAD
+':SOUNDS\EXPLODEROCKET');
1136 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEBFG', GameWAD
+':SOUNDS\EXPLODEBFG');
1137 g_Sound_CreateWADEx('SOUND_WEAPON_BFGWATER', GameWAD
+':SOUNDS\BFGWATER');
1138 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEPLASMA', GameWAD
+':SOUNDS\EXPLODEPLASMA');
1139 g_Sound_CreateWADEx('SOUND_WEAPON_PLASMAWATER', GameWAD
+':SOUNDS\PLASMAWATER');
1140 g_Sound_CreateWADEx('SOUND_WEAPON_FIREBALL', GameWAD
+':SOUNDS\FIREBALL');
1141 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEBALL', GameWAD
+':SOUNDS\EXPLODEBALL');
1142 g_Sound_CreateWADEx('SOUND_WEAPON_FIREREV', GameWAD
+':SOUNDS\FIREREV');
1143 g_Sound_CreateWADEx('SOUND_WEAPON_FLAMEON', GameWAD
+':SOUNDS\STARTFLM');
1144 g_Sound_CreateWADEx('SOUND_WEAPON_FLAMEOFF', GameWAD
+':SOUNDS\STOPFLM');
1145 g_Sound_CreateWADEx('SOUND_WEAPON_FLAMEWORK', GameWAD
+':SOUNDS\WORKFLM');
1146 g_Sound_CreateWADEx('SOUND_PLAYER_JETFLY', GameWAD
+':SOUNDS\WORKJETPACK');
1147 g_Sound_CreateWADEx('SOUND_PLAYER_JETON', GameWAD
+':SOUNDS\STARTJETPACK');
1148 g_Sound_CreateWADEx('SOUND_PLAYER_JETOFF', GameWAD
+':SOUNDS\STOPJETPACK');
1149 g_Sound_CreateWADEx('SOUND_PLAYER_CASING1', GameWAD
+':SOUNDS\CASING1');
1150 g_Sound_CreateWADEx('SOUND_PLAYER_CASING2', GameWAD
+':SOUNDS\CASING2');
1151 g_Sound_CreateWADEx('SOUND_PLAYER_SHELL1', GameWAD
+':SOUNDS\SHELL1');
1152 g_Sound_CreateWADEx('SOUND_PLAYER_SHELL2', GameWAD
+':SOUNDS\SHELL2');
1154 //wgunMonHash := hashNewIntInt();
1155 wgunHitHeap
:= TBinaryHeapHitTimes
.Create();
1158 procedure g_Weapon_FreeData();
1160 e_WriteLog('Releasing weapons data...', TMsgType
.Notify
);
1162 g_Sound_Delete('SOUND_WEAPON_HITPUNCH');
1163 g_Sound_Delete('SOUND_WEAPON_MISSPUNCH');
1164 g_Sound_Delete('SOUND_WEAPON_HITBERSERK');
1165 g_Sound_Delete('SOUND_WEAPON_MISSBERSERK');
1166 g_Sound_Delete('SOUND_WEAPON_SELECTSAW');
1167 g_Sound_Delete('SOUND_WEAPON_IDLESAW');
1168 g_Sound_Delete('SOUND_WEAPON_HITSAW');
1169 g_Sound_Delete('SOUND_WEAPON_FIRESHOTGUN2');
1170 g_Sound_Delete('SOUND_WEAPON_FIRESHOTGUN');
1171 g_Sound_Delete('SOUND_WEAPON_FIRESAW');
1172 g_Sound_Delete('SOUND_WEAPON_FIREROCKET');
1173 g_Sound_Delete('SOUND_WEAPON_FIREPLASMA');
1174 g_Sound_Delete('SOUND_WEAPON_FIREPISTOL');
1175 g_Sound_Delete('SOUND_WEAPON_FIRECGUN');
1176 g_Sound_Delete('SOUND_WEAPON_FIREBFG');
1177 g_Sound_Delete('SOUND_FIRE');
1178 g_Sound_Delete('SOUND_IGNITE');
1179 g_Sound_Delete('SOUND_WEAPON_STARTFIREBFG');
1180 g_Sound_Delete('SOUND_WEAPON_EXPLODEROCKET');
1181 g_Sound_Delete('SOUND_WEAPON_EXPLODEBFG');
1182 g_Sound_Delete('SOUND_WEAPON_BFGWATER');
1183 g_Sound_Delete('SOUND_WEAPON_EXPLODEPLASMA');
1184 g_Sound_Delete('SOUND_WEAPON_PLASMAWATER');
1185 g_Sound_Delete('SOUND_WEAPON_FIREBALL');
1186 g_Sound_Delete('SOUND_WEAPON_EXPLODEBALL');
1187 g_Sound_Delete('SOUND_WEAPON_FIREREV');
1188 g_Sound_Delete('SOUND_WEAPON_FLAMEON');
1189 g_Sound_Delete('SOUND_WEAPON_FLAMEOFF');
1190 g_Sound_Delete('SOUND_WEAPON_FLAMEWORK');
1191 g_Sound_Delete('SOUND_PLAYER_JETFLY');
1192 g_Sound_Delete('SOUND_PLAYER_JETON');
1193 g_Sound_Delete('SOUND_PLAYER_JETOFF');
1194 g_Sound_Delete('SOUND_PLAYER_CASING1');
1195 g_Sound_Delete('SOUND_PLAYER_CASING2');
1196 g_Sound_Delete('SOUND_PLAYER_SHELL1');
1197 g_Sound_Delete('SOUND_PLAYER_SHELL2');
1201 function GunHitPlayer (X
, Y
: Integer; vx
, vy
: Integer; dmg
: Integer; SpawnerUID
: Word; AllowPush
: Boolean): Boolean;
1206 for i
:= 0 to High(gPlayers
) do
1208 if (gPlayers
[i
] <> nil) and gPlayers
[i
].alive
and gPlayers
[i
].Collide(X
, Y
) then
1210 if HitPlayer(gPlayers
[i
], dmg
, vx
*10, vy
*10-3, SpawnerUID
, HIT_SOME
) then
1212 if AllowPush
then gPlayers
[i
].Push(vx
, vy
);
1220 function GunHit (X
, Y
: Integer; vx
, vy
: Integer; dmg
: Integer; SpawnerUID
: Word; AllowPush
: Boolean): Byte;
1222 function monsCheck (mon
: TMonster
): Boolean;
1224 result
:= false; // don't stop
1225 if HitMonster(mon
, dmg
, vx
*10, vy
*10-3, SpawnerUID
, HIT_SOME
) then
1227 if AllowPush
then mon
.Push(vx
, vy
);
1234 if GunHitPlayer(X
, Y
, vx
, vy
, dmg
, SpawnerUID
, AllowPush
) then result
:= 1
1235 else if g_Mons_ForEachAliveAt(X
, Y
, 1, 1, monsCheck
) then result
:= 2;
1240 procedure g_Weapon_gunOld(const x, y, xd, yd, v, dmg: Integer; SpawnerUID: Word; CheckTrigger: Boolean);
1251 t1, _collide: Boolean;
1253 {$IF DEFINED(D2F_DEBUG)}
1255 showTime: Boolean = true;
1258 a := GetAngle(x, y, xd, yd)+180;
1260 SinCos(DegToRad(-a), s, c);
1262 if Abs(s) < 0.01 then s := 0;
1263 if Abs(c) < 0.01 then c := 0;
1265 x2 := x+Round(c*gMapInfo.Width);
1266 y2 := y+Round(s*gMapInfo.Width);
1268 t1 := gWalls <> nil;
1270 w := gMapInfo.Width;
1271 h := gMapInfo.Height;
1278 if (xd = 0) and (yd = 0) then Exit;
1280 if dx > 0 then xi := 1 else if dx < 0 then xi := -1 else xi := 0;
1281 if dy > 0 then yi := 1 else if dy < 0 then yi := -1 else yi := 0;
1286 if dx > dy then d := dx else d := dy;
1288 //blood vel, for Monster.Damage()
1289 //vx := (dx*10 div d)*xi;
1290 //vy := (dy*10 div d)*yi;
1292 {$IF DEFINED(D2F_DEBUG)}
1293 stt := getTimeMicro();
1316 if (yy > h) or (yy < 0) then Break;
1317 if (xx > w) or (xx < 0) then Break;
1320 if ByteBool(gCollideMap[yy, xx] and MARK_BLOCKED) then
1323 {$IF DEFINED(D2F_DEBUG)}
1324 stt := getTimeMicro()-stt;
1325 e_WriteLog(Format('*** old trace time: %u microseconds', [LongWord(stt)]), MSG_NOTIFY);
1328 g_GFX_Spark(xx-xi, yy-yi, 2+Random(2), 180+a, 0, 0);
1329 if g_Game_IsServer and g_Game_IsNet then
1330 MH_SEND_Effect(xx-xi, yy-yi, 180+a, NET_GFX_SPARK);
1333 if not _collide then
1335 _collide := GunHit(xx, yy, xi*v, yi*v, dmg, SpawnerUID, v <> 0) <> 0;
1338 if _collide then Break;
1341 {$IF DEFINED(D2F_DEBUG)}
1344 stt := getTimeMicro()-stt;
1345 e_WriteLog(Format('*** old trace time: %u microseconds', [LongWord(stt)]), MSG_NOTIFY);
1349 if CheckTrigger and g_Game_IsServer then
1350 g_Triggers_PressL(X, Y, xx-xi, yy-yi, SpawnerUID, ACTIVATE_SHOT);
1356 procedure g_Weapon_gun (const x
, y
, xd
, yd
, v
, indmg
: Integer; SpawnerUID
: Word; CheckTrigger
: Boolean);
1361 wallDistSq
: Integer = $3fffffff;
1362 spawnerPlr
: TPlayer
= nil;
1365 function doPlayerHit (idx
: Integer; hx
, hy
: Integer): Boolean;
1368 if (idx
< 0) or (idx
> High(gPlayers
)) then exit
;
1369 if (gPlayers
[idx
] = nil) or not gPlayers
[idx
].alive
then exit
;
1370 if (spawnerPlr
<> nil) then
1372 if ((gGameSettings
.Options
and (GAME_OPTION_TEAMHITTRACE
or GAME_OPTION_TEAMDAMAGE
)) = 0) and
1373 (spawnerPlr
.Team
<> TEAM_NONE
) and (spawnerPlr
.Team
= gPlayers
[idx
].Team
) then
1375 if (spawnerPlr
<> gPlayers
[idx
]) and ((gGameSettings
.Options
and GAME_OPTION_TEAMABSORBDAMAGE
) = 0) then
1376 dmg
:= Max(1, dmg
div 2);
1380 result
:= HitPlayer(gPlayers
[idx
], dmg
, (xi
*v
)*10, (yi
*v
)*10-3, SpawnerUID
, HIT_SOME
);
1381 if result
and (v
<> 0) then gPlayers
[idx
].Push((xi
*v
), (yi
*v
));
1382 {$IF DEFINED(D2F_DEBUG)}
1383 //if result then e_WriteLog(Format(' PLAYER #%d HIT', [idx]), MSG_NOTIFY);
1387 function doMonsterHit (mon
: TMonster
; hx
, hy
: Integer): Boolean;
1390 if (mon
= nil) then exit
;
1391 result
:= HitMonster(mon
, dmg
, (xi
*v
)*10, (yi
*v
)*10-3, SpawnerUID
, HIT_SOME
);
1392 if result
and (v
<> 0) then mon
.Push((xi
*v
), (yi
*v
));
1393 {$IF DEFINED(D2F_DEBUG)}
1394 //if result then e_WriteLog(Format(' MONSTER #%u HIT', [LongWord(mon.UID)]), MSG_NOTIFY);
1398 // collect players along hitray
1399 // return `true` if instant hit was detected
1400 function playerPossibleHit (): Boolean;
1403 px
, py
, pw
, ph
: Integer;
1409 for i
:= 0 to High(gPlayers
) do
1412 if (plr
<> nil) and plr
.alive
then
1414 plr
.getMapBox(px
, py
, pw
, ph
);
1415 if lineAABBIntersects(x
, y
, x2
, y2
, px
, py
, pw
, ph
, inx
, iny
) then
1417 distSq
:= distanceSq(x
, y
, inx
, iny
);
1418 if (distSq
= 0) then
1421 if doPlayerHit(i
, x
, y
) then begin result
:= true; exit
; end;
1423 else if (distSq
< wallDistSq
) then
1425 appendHitTimePlr(distSq
, i
, inx
, iny
);
1432 procedure sqchecker (mon
: TMonster
);
1434 mx
, my
, mw
, mh
: Integer;
1438 mon
.getMapBox(mx
, my
, mw
, mh
);
1439 if lineAABBIntersects(x0
, y0
, x2
, y2
, mx
, my
, mw
, mh
, inx
, iny
) then
1441 distSq
:= distanceSq(x0
, y0
, inx
, iny
);
1442 if (distSq
< wallDistSq
) then appendHitTimeMon(distSq
, mon
, inx
, iny
);
1452 wallHitFlag
: Boolean = false;
1453 wallHitX
: Integer = 0;
1454 wallHitY
: Integer = 0;
1455 didHit
: Boolean = false;
1456 {$IF DEFINED(D2F_DEBUG)}
1460 it
: TMonsterGrid
.Iter
;
1463 if not gwep_debug_fast_trace then
1465 g_Weapon_gunOld(x, y, xd, yd, v, dmg, SpawnerUID, CheckTrigger);
1470 if (xd
= 0) and (yd
= 0) then exit
;
1472 if (g_GetUIDType(SpawnerUID
) = UID_PLAYER
) then
1473 spawnerPlr
:= g_Player_Get(SpawnerUID
);
1477 //wgunMonHash.reset(); //FIXME: clear hash on level change
1478 wgunHitHeap
.clear();
1479 wgunHitTimeUsed
:= 0;
1481 a
:= GetAngle(x
, y
, xd
, yd
)+180;
1483 SinCos(DegToRad(-a
), s
, c
);
1485 if Abs(s
) < 0.01 then s
:= 0;
1486 if Abs(c
) < 0.01 then c
:= 0;
1490 x2
:= x
+Round(c
*gMapInfo
.Width
);
1491 y2
:= y
+Round(s
*gMapInfo
.Width
);
1496 if (dx
> 0) then xi
:= 1 else if (dx
< 0) then xi
:= -1 else xi
:= 0;
1497 if (dy
> 0) then yi
:= 1 else if (dy
< 0) then yi
:= -1 else yi
:= 0;
1499 {$IF DEFINED(D2F_DEBUG)}
1500 e_WriteLog(Format('GUN TRACE: (%d,%d) to (%d,%d)', [x
, y
, x2
, y2
]), TMsgType
.Notify
);
1501 stt
:= getTimeMicro();
1504 wallHitFlag
:= (g_Map_traceToNearestWall(x
, y
, x2
, y2
, @wallHitX
, @wallHitY
) <> nil);
1509 wallDistSq
:= distanceSq(x
, y
, wallHitX
, wallHitY
);
1517 if playerPossibleHit() then exit
; // instant hit
1520 //g_Mons_AlongLine(x, y, x2, y2, sqchecker);
1522 it
:= monsGrid
.forEachAlongLine(x
, y
, x2
, y2
, -1);
1523 for mit
in it
do sqchecker(mit
^);
1526 // here, we collected all monsters and players in `wgunHitHeap` and `wgunHitTime`
1527 // also, if `wallWasHit` is `true`, then `wallHitX` and `wallHitY` contains spark coords
1528 while (wgunHitHeap
.count
> 0) do
1530 // has some entities to check, do it
1531 i
:= wgunHitHeap
.front
;
1532 wgunHitHeap
.popFront();
1534 xe
:= wgunHitTime
[i
].x
;
1535 ye
:= wgunHitTime
[i
].y
;
1536 // check if it is not behind the wall
1537 if (wgunHitTime
[i
].mon
<> nil) then
1539 didHit
:= doMonsterHit(wgunHitTime
[i
].mon
, xe
, ye
);
1543 didHit
:= doPlayerHit(wgunHitTime
[i
].plridx
, xe
, ye
);
1547 // need new coords for trigger
1550 wallHitFlag
:= false; // no sparks
1558 {$IF DEFINED(D2F_DEBUG)}
1559 stt
:= getTimeMicro()-stt
;
1560 e_WriteLog(Format('*** new trace time: %u microseconds', [LongWord(stt
)]), TMsgType
.Notify
);
1563 g_GFX_Spark(wallHitX
, wallHitY
, 2+Random(2), 180+a
, 0, 0);
1565 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Effect(wallHitX
, wallHitY
, 180+a
, NET_GFX_SPARK
);
1569 {$IF DEFINED(D2F_DEBUG)}
1570 stt
:= getTimeMicro()-stt
;
1571 e_WriteLog(Format('*** new trace time: %u microseconds', [LongWord(stt
)]), TMsgType
.Notify
);
1575 if CheckTrigger
and g_Game_IsServer
then g_Triggers_PressL(X
, Y
, wallHitX
, wallHitY
, SpawnerUID
, ACTIVATE_SHOT
);
1579 procedure g_Weapon_punch(x
, y
: Integer; d
, SpawnerUID
: Word);
1587 obj
.rect
.Width
:= 39;
1588 obj
.rect
.Height
:= 52;
1594 if g_Weapon_Hit(@obj
, d
, SpawnerUID
, HIT_SOME
) <> 0 then
1595 g_Sound_PlayExAt('SOUND_WEAPON_HITPUNCH', x
, y
)
1597 g_Sound_PlayExAt('SOUND_WEAPON_MISSPUNCH', x
, y
);
1600 function g_Weapon_chainsaw(x
, y
: Integer; d
, SpawnerUID
: Word): Integer;
1608 obj
.rect
.Width
:= 32;
1609 obj
.rect
.Height
:= 52;
1615 Result
:= g_Weapon_Hit(@obj
, d
, SpawnerUID
, HIT_SOME
);
1618 procedure g_Weapon_rocket(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1;
1619 Silent
: Boolean = False; compat
: Boolean = true);
1625 find_id
:= FindShot()
1629 if Integer(find_id
) >= High(Shots
) then
1630 SetLength(Shots
, find_id
+ 64)
1633 with Shots
[find_id
] do
1637 Obj
.Rect
.Width
:= SHOT_ROCKETLAUNCHER_WIDTH
;
1638 Obj
.Rect
.Height
:= SHOT_ROCKETLAUNCHER_HEIGHT
;
1641 dx
:= IfThen(xd
> x
, -Obj
.Rect
.Width
, 0)
1643 dx
:= -(Obj
.Rect
.Width
div 2);
1644 dy
:= -(Obj
.Rect
.Height
div 2);
1646 ShotType
:= WEAPON_ROCKETLAUNCHER
;
1647 throw(find_id
, x
+dx
, y
+dy
, xd
+dx
, yd
+dy
, 12);
1653 Shots
[find_id
].SpawnerUID
:= SpawnerUID
;
1656 g_Sound_PlayExAt('SOUND_WEAPON_FIREROCKET', x
, y
);
1659 procedure g_Weapon_revf(x
, y
, xd
, yd
: Integer; SpawnerUID
, TargetUID
: Word;
1660 WID
: Integer = -1; Silent
: Boolean = False);
1666 find_id
:= FindShot()
1670 if Integer(find_id
) >= High(Shots
) then
1671 SetLength(Shots
, find_id
+ 64)
1674 with Shots
[find_id
] do
1678 Obj
.Rect
.Width
:= SHOT_SKELFIRE_WIDTH
;
1679 Obj
.Rect
.Height
:= SHOT_SKELFIRE_HEIGHT
;
1681 dx
:= -(Obj
.Rect
.Width
div 2);
1682 dy
:= -(Obj
.Rect
.Height
div 2);
1684 ShotType
:= WEAPON_SKEL_FIRE
;
1685 throw(find_id
, x
+dx
, y
+dy
, xd
+dx
, yd
+dy
, 12);
1688 target
:= TargetUID
;
1692 Shots
[find_id
].SpawnerUID
:= SpawnerUID
;
1695 g_Sound_PlayExAt('SOUND_WEAPON_FIREREV', x
, y
);
1698 procedure g_Weapon_plasma(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1;
1699 Silent
: Boolean = False; compat
: Boolean = true);
1705 find_id
:= FindShot()
1709 if Integer(find_id
) >= High(Shots
) then
1710 SetLength(Shots
, find_id
+ 64);
1713 with Shots
[find_id
] do
1717 Obj
.Rect
.Width
:= SHOT_PLASMA_WIDTH
;
1718 Obj
.Rect
.Height
:= SHOT_PLASMA_HEIGHT
;
1721 dx
:= IfThen(xd
> x
, -Obj
.Rect
.Width
, 0)
1723 dx
:= -(Obj
.Rect
.Width
div 2);
1724 dy
:= -(Obj
.Rect
.Height
div 2);
1726 ShotType
:= WEAPON_PLASMA
;
1727 throw(find_id
, x
+dx
, y
+dy
, xd
+dx
, yd
+dy
, 16);
1733 Shots
[find_id
].SpawnerUID
:= SpawnerUID
;
1736 g_Sound_PlayExAt('SOUND_WEAPON_FIREPLASMA', x
, y
);
1739 procedure g_Weapon_flame(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1;
1740 Silent
: Boolean = False; compat
: Boolean = true);
1746 find_id
:= FindShot()
1750 if Integer(find_id
) >= High(Shots
) then
1751 SetLength(Shots
, find_id
+ 64);
1754 with Shots
[find_id
] do
1758 Obj
.Rect
.Width
:= SHOT_FLAME_WIDTH
;
1759 Obj
.Rect
.Height
:= SHOT_FLAME_HEIGHT
;
1762 dx
:= IfThen(xd
> x
, -Obj
.Rect
.Width
, 0)
1764 dx
:= -(Obj
.Rect
.Width
div 2);
1765 dy
:= -(Obj
.Rect
.Height
div 2);
1767 ShotType
:= WEAPON_FLAMETHROWER
;
1768 throw(find_id
, x
+dx
, y
+dy
, xd
+dx
, yd
+dy
, 16);
1774 Shots
[find_id
].SpawnerUID
:= SpawnerUID
;
1776 // if not Silent then
1777 // g_Sound_PlayExAt('SOUND_WEAPON_FIREPLASMA', x, y);
1780 procedure g_Weapon_ball1(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1;
1781 Silent
: Boolean = False; compat
: Boolean = true);
1787 find_id
:= FindShot()
1791 if Integer(find_id
) >= High(Shots
) then
1792 SetLength(Shots
, find_id
+ 64)
1795 with Shots
[find_id
] do
1799 Obj
.Rect
.Width
:= 16;
1800 Obj
.Rect
.Height
:= 16;
1803 dx
:= IfThen(xd
> x
, -Obj
.Rect
.Width
, 0)
1805 dx
:= -(Obj
.Rect
.Width
div 2);
1806 dy
:= -(Obj
.Rect
.Height
div 2);
1808 ShotType
:= WEAPON_IMP_FIRE
;
1809 throw(find_id
, x
+dx
, y
+dy
, xd
+dx
, yd
+dy
, 16);
1815 Shots
[find_id
].SpawnerUID
:= SpawnerUID
;
1818 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x
, y
);
1821 procedure g_Weapon_ball2(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1;
1822 Silent
: Boolean = False; compat
: Boolean = true);
1828 find_id
:= FindShot()
1832 if Integer(find_id
) >= High(Shots
) then
1833 SetLength(Shots
, find_id
+ 64)
1836 with Shots
[find_id
] do
1840 Obj
.Rect
.Width
:= 16;
1841 Obj
.Rect
.Height
:= 16;
1844 dx
:= IfThen(xd
> x
, -Obj
.Rect
.Width
, 0)
1846 dx
:= -(Obj
.Rect
.Width
div 2);
1847 dy
:= -(Obj
.Rect
.Height
div 2);
1849 ShotType
:= WEAPON_CACO_FIRE
;
1850 throw(find_id
, x
+dx
, y
+dy
, xd
+dx
, yd
+dy
, 16);
1856 Shots
[find_id
].SpawnerUID
:= SpawnerUID
;
1859 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x
, y
);
1862 procedure g_Weapon_ball7(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1;
1863 Silent
: Boolean = False; compat
: Boolean = true);
1869 find_id
:= FindShot()
1873 if Integer(find_id
) >= High(Shots
) then
1874 SetLength(Shots
, find_id
+ 64)
1877 with Shots
[find_id
] do
1881 Obj
.Rect
.Width
:= 32;
1882 Obj
.Rect
.Height
:= 16;
1885 dx
:= IfThen(xd
> x
, -Obj
.Rect
.Width
, 0)
1887 dx
:= -(Obj
.Rect
.Width
div 2);
1888 dy
:= -(Obj
.Rect
.Height
div 2);
1890 ShotType
:= WEAPON_BARON_FIRE
;
1891 throw(find_id
, x
+dx
, y
+dy
, xd
+dx
, yd
+dy
, 16);
1897 Shots
[find_id
].SpawnerUID
:= SpawnerUID
;
1900 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x
, y
);
1903 procedure g_Weapon_aplasma(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1;
1904 Silent
: Boolean = False; compat
: Boolean = true);
1910 find_id
:= FindShot()
1914 if Integer(find_id
) >= High(Shots
) then
1915 SetLength(Shots
, find_id
+ 64)
1918 with Shots
[find_id
] do
1922 Obj
.Rect
.Width
:= 16;
1923 Obj
.Rect
.Height
:= 16;
1926 dx
:= IfThen(xd
> x
, -Obj
.Rect
.Width
, 0)
1928 dx
:= -(Obj
.Rect
.Width
div 2);
1929 dy
:= -(Obj
.Rect
.Height
div 2);
1931 ShotType
:= WEAPON_BSP_FIRE
;
1932 throw(find_id
, x
+dx
, y
+dy
, xd
+dx
, yd
+dy
, 16);
1938 Shots
[find_id
].SpawnerUID
:= SpawnerUID
;
1941 g_Sound_PlayExAt('SOUND_WEAPON_FIREPLASMA', x
, y
);
1944 procedure g_Weapon_manfire(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1;
1945 Silent
: Boolean = False; compat
: Boolean = true);
1951 find_id
:= FindShot()
1955 if Integer(find_id
) >= High(Shots
) then
1956 SetLength(Shots
, find_id
+ 64)
1959 with Shots
[find_id
] do
1963 Obj
.Rect
.Width
:= 32;
1964 Obj
.Rect
.Height
:= 32;
1967 dx
:= IfThen(xd
> x
, -Obj
.Rect
.Width
, 0)
1969 dx
:= -(Obj
.Rect
.Width
div 2);
1970 dy
:= -(Obj
.Rect
.Height
div 2);
1972 ShotType
:= WEAPON_MANCUB_FIRE
;
1973 throw(find_id
, x
+dx
, y
+dy
, xd
+dx
, yd
+dy
, 16);
1979 Shots
[find_id
].SpawnerUID
:= SpawnerUID
;
1982 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x
, y
);
1985 procedure g_Weapon_bfgshot(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1;
1986 Silent
: Boolean = False; compat
: Boolean = true);
1992 find_id
:= FindShot()
1996 if Integer(find_id
) >= High(Shots
) then
1997 SetLength(Shots
, find_id
+ 64)
2000 with Shots
[find_id
] do
2004 Obj
.Rect
.Width
:= SHOT_BFG_WIDTH
;
2005 Obj
.Rect
.Height
:= SHOT_BFG_HEIGHT
;
2008 dx
:= IfThen(xd
> x
, -Obj
.Rect
.Width
, 0)
2010 dx
:= -(Obj
.Rect
.Width
div 2);
2011 dy
:= -(Obj
.Rect
.Height
div 2);
2013 ShotType
:= WEAPON_BFG
;
2014 throw(find_id
, x
+dx
, y
+dy
, xd
+dx
, yd
+dy
, 16);
2020 Shots
[find_id
].SpawnerUID
:= SpawnerUID
;
2023 g_Sound_PlayExAt('SOUND_WEAPON_FIREBFG', x
, y
);
2026 procedure g_Weapon_bfghit(x
, y
: Integer);
2029 g_GFX_QueueEffect(R_GFX_BFG_HIT
, x
- 32, y
- 32);
2033 procedure g_Weapon_pistol(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word;
2034 Silent
: Boolean = False);
2037 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', x
, y
);
2039 g_Weapon_gun(x
, y
, xd
, yd
, 1, 3, SpawnerUID
, True);
2040 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
] then
2042 if ABS(x
-xd
) >= ABS(y
-yd
) then
2044 g_Weapon_gun(x
, y
+1, xd
, yd
+1, 1, 3, SpawnerUID
, False);
2045 g_Weapon_gun(x
, y
-1, xd
, yd
-1, 1, 2, SpawnerUID
, False);
2049 g_Weapon_gun(x
+1, y
, xd
+1, yd
, 1, 3, SpawnerUID
, False);
2050 g_Weapon_gun(x
-1, y
, xd
-1, yd
, 1, 2, SpawnerUID
, False);
2055 procedure g_Weapon_mgun(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word;
2056 Silent
: Boolean = False);
2059 if gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', x
, y
);
2061 g_Weapon_gun(x
, y
, xd
, yd
, 1, 3, SpawnerUID
, True);
2062 if (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) and
2063 (g_GetUIDType(SpawnerUID
) = UID_PLAYER
) then
2065 if ABS(x
-xd
) >= ABS(y
-yd
) then
2067 g_Weapon_gun(x
, y
+1, xd
, yd
+1, 1, 2, SpawnerUID
, False);
2068 g_Weapon_gun(x
, y
-1, xd
, yd
-1, 1, 2, SpawnerUID
, False);
2072 g_Weapon_gun(x
+1, y
, xd
+1, yd
, 1, 2, SpawnerUID
, False);
2073 g_Weapon_gun(x
-1, y
, xd
-1, yd
, 1, 2, SpawnerUID
, False);
2078 procedure g_Weapon_shotgun(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word;
2079 Silent
: Boolean = False);
2084 if gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', x
, y
);
2089 if ABS(x
-xd
) >= ABS(y
-yd
) then j
:= Random(17) - 8 else k
:= Random(17) - 8; // -8 .. 8
2090 g_Weapon_gun(x
+k
, y
+j
, xd
+k
, yd
+j
, IfThen(i
mod 2 <> 0, 1, 0), 3, SpawnerUID
, i
=0);
2094 procedure g_Weapon_dshotgun(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word;
2095 Silent
: Boolean = False);
2097 a
, i
, j
, k
: Integer;
2100 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', x
, y
);
2102 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
] then a
:= 25 else a
:= 20;
2106 if ABS(x
-xd
) >= ABS(y
-yd
) then j
:= Random(41) - 20 else k
:= Random(41) - 20; // -20 .. 20
2107 g_Weapon_gun(x
+k
, y
+j
, xd
+k
, yd
+j
, IfThen(i
mod 3 <> 0, 0, 1), 3, SpawnerUID
, i
=0);
2111 procedure g_Weapon_PreUpdate();
2115 if Shots
= nil then Exit
;
2116 for i
:= 0 to High(Shots
) do
2117 if Shots
[i
].ShotType
<> 0 then
2119 Shots
[i
].Obj
.oldX
:= Shots
[i
].Obj
.X
;
2120 Shots
[i
].Obj
.oldY
:= Shots
[i
].Obj
.Y
;
2124 procedure g_Weapon_Update();
2126 i
, a
, h
, cx
, cy
, oldvx
, oldvy
, tf
: Integer;
2133 var tcx
, tcy
: Integer;
2139 for i
:= 0 to High(Shots
) do
2141 if Shots
[i
].ShotType
= 0 then
2148 Timeout
:= Timeout
- 1;
2151 // Àêòèâèðîâàòü òðèããåðû ïî ïóòè (êðîìå óæå àêòèâèðîâàííûõ):
2152 if (Stopped
= 0) and g_Game_IsServer
then
2153 t
:= g_Triggers_PressR(Obj
.X
, Obj
.Y
, Obj
.Rect
.Width
, Obj
.Rect
.Height
,
2154 SpawnerUID
, ACTIVATE_SHOT
, triggers
)
2160 // Ïîïîëíÿåì ñïèñîê àêòèâèðîâàííûõ òðèããåðîâ:
2161 if triggers
= nil then
2168 if not InDWArray(t
[a
], triggers
) then
2170 SetLength(triggers
, Length(triggers
)+1);
2171 triggers
[High(triggers
)] := t
[a
];
2177 spl
:= (ShotType
<> WEAPON_PLASMA
) and
2178 (ShotType
<> WEAPON_BFG
) and
2179 (ShotType
<> WEAPON_BSP_FIRE
) and
2180 (ShotType
<> WEAPON_FLAMETHROWER
);
2184 st
:= g_Obj_Move_Projectile(@Obj
, False, spl
);
2190 positionChanged(); // this updates spatial accelerators
2192 if WordBool(st
and MOVE_FALLOUT
) or (Obj
.X
< -1000) or
2193 (Obj
.X
> gMapInfo
.Width
+1000) or (Obj
.Y
< -1000) then
2195 // Íà êëèåíòå ñêîðåå âñåãî è òàê óæå âûïàë.
2201 cx
:= Obj
.X
+ (Obj
.Rect
.Width
div 2);
2202 cy
:= Obj
.Y
+ (Obj
.Rect
.Height
div 2);
2205 WEAPON_ROCKETLAUNCHER
, WEAPON_SKEL_FIRE
: // Ðàêåòû è ñíàðÿäû Ñêåëåòà
2207 // Âûëåòåëà èç âîäû:
2208 if WordBool(st
and MOVE_HITAIR
) then
2209 g_Obj_SetSpeed(@Obj
, 12);
2211 // Â âîäå øëåéô - ïóçûðè, â âîçäóõå øëåéô - äûì:
2212 if WordBool(st
and MOVE_INWATER
) then
2215 g_GFX_Bubbles(cx
, cy
, 1+Random(3), 16, 16);
2218 then g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', cx
, cy
)
2219 else g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', cx
, cy
);
2224 g_GFX_QueueEffect(R_GFX_SMOKE_TRANS
, Obj
.X
-14+Random(9), cy
-20+Random(9));
2228 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2229 if WordBool(st
and (MOVE_HITWALL
or MOVE_HITLAND
or MOVE_HITCEIL
)) or
2230 (g_Weapon_Hit(@Obj
, 10, SpawnerUID
, HIT_SOME
, False) <> 0) or
2236 g_Weapon_Explode(cx
, cy
, 60, SpawnerUID
);
2238 if ShotType
= WEAPON_SKEL_FIRE
then
2239 begin // Âçðûâ ñíàðÿäà Ñêåëåòà
2241 g_GFX_QueueEffect(R_GFX_EXPLODE_SKELFIRE
, Obj
.X
+ 32 - 58, Obj
.Y
+ 8 - 36);
2242 g_DynLightExplosion((Obj
.X
+32), (Obj
.Y
+8), 64, 1, 0, 0);
2246 begin // Âçðûâ Ðàêåòû
2248 g_GFX_QueueEffect(R_GFX_EXPLODE_ROCKET
, cx
- 64, cy
- 64);
2249 g_DynLightExplosion(cx
, cy
, 64, 1, 0, 0);
2253 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', Obj
.X
, Obj
.Y
);
2258 if ShotType
= WEAPON_SKEL_FIRE
then
2259 begin // Ñàìîíàâîäêà ñíàðÿäà Ñêåëåòà:
2260 if GetPos(target
, @o
) then
2261 throw(i
, Obj
.X
, Obj
.Y
,
2262 o
.X
+o
.Rect
.X
+(o
.Rect
.Width
div 2)+o
.Vel
.X
+o
.Accel
.X
,
2263 o
.Y
+o
.Rect
.Y
+(o
.Rect
.Height
div 2)+o
.Vel
.Y
+o
.Accel
.Y
,
2268 WEAPON_PLASMA
, WEAPON_BSP_FIRE
: // Ïëàçìà, ïëàçìà Àðàõíàòðîíà
2270 // Ïîïàëà â âîäó - ýëåêòðîøîê ïî âîäå:
2271 if WordBool(st
and (MOVE_INWATER
or MOVE_HITWATER
)) then
2273 g_Sound_PlayExAt('SOUND_WEAPON_PLASMAWATER', Obj
.X
, Obj
.Y
);
2274 if g_Game_IsServer
then CheckTrap(i
, 10, HIT_ELECTRO
);
2280 if (ShotType
= WEAPON_PLASMA
) and
2281 (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) then
2286 if ShotType
= WEAPON_BSP_FIRE
then
2289 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2290 if WordBool(st
and (MOVE_HITWALL
or MOVE_HITLAND
or MOVE_HITCEIL
)) or
2291 (g_Weapon_Hit(@Obj
, a
, SpawnerUID
, HIT_SOME
, False) <> 0) or
2295 if ShotType
= WEAPON_PLASMA
then
2296 g_GFX_QueueEffect(R_GFX_EXPLODE_PLASMA
, cx
- 16, cy
- 16)
2298 g_GFX_QueueEffect(R_GFX_EXPLODE_BSPFIRE
, cx
- 16, cy
- 16);
2299 g_DynLightExplosion(cx
, cy
, 32, 0, 0.5, 0.5);
2301 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEPLASMA', Obj
.X
, Obj
.Y
);
2306 WEAPON_FLAMETHROWER
: // Îãíåìåò
2308 // Ñî âðåìåíåì óìèðàåò
2309 if (Timeout
< 1) then
2315 if WordBool(st
and (MOVE_HITWATER
or MOVE_INWATER
)) then
2317 if WordBool(st
and MOVE_HITWATER
) then
2322 g_GFX_QueueEffect(R_GFX_SMOKE
, cx
-4+tcx
-(R_GFX_SMOKE_WIDTH
div 2), cy
-4+tcy
-(R_GFX_SMOKE_HEIGHT
div 2));
2328 g_GFX_Bubbles(cx
, cy
, 1+Random(3), 16, 16);
2331 then g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', cx
, cy
)
2332 else g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', cx
, cy
);
2340 Obj
.Accel
.Y
:= Obj
.Accel
.Y
+ 1;
2341 // Ïîïàëè â ñòåíó èëè â âîäó:
2342 if WordBool(st
and (MOVE_HITWALL
or MOVE_HITLAND
or MOVE_HITCEIL
or MOVE_HITWATER
)) then
2348 if WordBool(st
and MOVE_HITWALL
) then
2349 Stopped
:= MOVE_HITWALL
2350 else if WordBool(st
and MOVE_HITLAND
) then
2351 Stopped
:= MOVE_HITLAND
2352 else if WordBool(st
and MOVE_HITCEIL
) then
2353 Stopped
:= MOVE_HITCEIL
;
2356 a
:= IfThen(Stopped
= 0, 10, 1);
2357 // Åñëè â êîãî-òî ïîïàëè
2358 if g_Weapon_Hit(@Obj
, a
, SpawnerUID
, HIT_FLAME
, False) <> 0 then
2360 // HIT_FLAME ñàì ïîäîææåò
2361 // Åñëè â ïîëåòå ïîïàëè, èñ÷åçàåì
2371 if (gTime
mod LongWord(tf
) = 0) then
2375 MOVE_HITWALL
: begin tcx
:= cx
-4+Random(8); tcy
:= cy
-12+Random(24); end;
2376 MOVE_HITLAND
: begin tcx
:= cx
-12+Random(24); tcy
:= cy
-10+Random(8); end;
2377 MOVE_HITCEIL
: begin tcx
:= cx
-12+Random(24); tcy
:= cy
+6+Random(8); end;
2378 else begin tcx
:= cx
-4+Random(8); tcy
:= cy
-4+Random(8); end;
2380 g_GFX_QueueEffect(R_GFX_FLAME_RAND
, tcx
- (R_GFX_FLAME_WIDTH
div 2), tcy
- (R_GFX_FLAME_HEIGHT
div 2));
2381 //g_DynLightExplosion(tcx, tcy, 1, 1, 0.8, 0.3);
2388 // Ïîïàëà â âîäó - ýëåêòðîøîê ïî âîäå:
2389 if WordBool(st
and (MOVE_INWATER
or MOVE_HITWATER
)) then
2391 g_Sound_PlayExAt('SOUND_WEAPON_BFGWATER', Obj
.X
, Obj
.Y
);
2392 if g_Game_IsServer
then CheckTrap(i
, 1000, HIT_ELECTRO
);
2397 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2398 if WordBool(st
and (MOVE_HITWALL
or MOVE_HITLAND
or MOVE_HITCEIL
)) or
2399 (g_Weapon_Hit(@Obj
, SHOT_BFG_DAMAGE
, SpawnerUID
, HIT_BFG
, False) <> 0) or
2403 if g_Game_IsServer
then g_Weapon_BFG9000(cx
, cy
, SpawnerUID
);
2405 g_GFX_QueueEffect(R_GFX_EXPLODE_BFG
, cx
- 64, cy
- 64);
2406 g_DynLightExplosion(cx
, cy
, 96, 0, 1, 0);
2408 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', Obj
.X
, Obj
.Y
);
2413 WEAPON_IMP_FIRE
, WEAPON_CACO_FIRE
, WEAPON_BARON_FIRE
: // Âûñòðåëû Áåñà, Êàêîäåìîíà Ðûöàðÿ/Áàðîíà àäà
2416 if WordBool(st
and MOVE_HITAIR
) then
2417 g_Obj_SetSpeed(@Obj
, 16);
2420 if ShotType
= WEAPON_IMP_FIRE
then
2423 if ShotType
= WEAPON_CACO_FIRE
then
2428 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2429 if WordBool(st
and (MOVE_HITWALL
or MOVE_HITLAND
or MOVE_HITCEIL
)) or
2430 (g_Weapon_Hit(@Obj
, a
, SpawnerUID
, HIT_SOME
) <> 0) or
2435 WEAPON_IMP_FIRE
: g_GFX_QueueEffect(R_GFX_EXPLODE_IMPFIRE
, cx
- 32, cy
- 32);
2436 WEAPON_CACO_FIRE
: g_GFX_QueueEffect(R_GFX_EXPLODE_CACOFIRE
, cx
- 32, cy
- 32);
2437 WEAPON_BARON_FIRE
: g_GFX_QueueEffect(R_GFX_EXPLODE_BARONFIRE
, cx
- 32, cy
- 32);
2440 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj
.X
, Obj
.Y
);
2445 WEAPON_MANCUB_FIRE
: // Âûñòðåë Ìàíêóáóñà
2448 if WordBool(st
and MOVE_HITAIR
) then
2449 g_Obj_SetSpeed(@Obj
, 16);
2451 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2452 if WordBool(st
and (MOVE_HITWALL
or MOVE_HITLAND
or MOVE_HITCEIL
)) or
2453 (g_Weapon_Hit(@Obj
, 40, SpawnerUID
, HIT_SOME
, False) <> 0) or
2458 g_GFX_QueueEffect(R_GFX_EXPLODE_ROCKET
, cx
- 64, cy
- 64);
2460 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj
.X
, Obj
.Y
);
2464 end; // case ShotType of...
2466 // Åñëè ñíàðÿäà óæå íåò, óäàëÿåì àíèìàöèþ:
2467 if (ShotType
= 0) then
2469 if gGameSettings
.GameType
= GT_SERVER
then
2470 MH_SEND_DeleteShot(i
, Obj
.X
, Obj
.Y
, Loud
);
2473 else if (ShotType
<> WEAPON_FLAMETHROWER
) and ((oldvx
<> Obj
.Vel
.X
) or (oldvy
<> Obj
.Vel
.Y
)) then
2474 if gGameSettings
.GameType
= GT_SERVER
then
2475 MH_SEND_UpdateShot(i
);
2480 function g_Weapon_Danger(UID
: Word; X
, Y
: Integer; Width
, Height
: Word; Time
: Byte): Boolean;
2489 for a
:= 0 to High(Shots
) do
2490 if (Shots
[a
].ShotType
<> 0) and (Shots
[a
].SpawnerUID
<> UID
) then
2491 if ((Shots
[a
].Obj
.Vel
.Y
= 0) and (Shots
[a
].Obj
.Vel
.X
> 0) and (Shots
[a
].Obj
.X
< X
)) or
2492 (Shots
[a
].Obj
.Vel
.Y
= 0) and (Shots
[a
].Obj
.Vel
.X
< 0) and (Shots
[a
].Obj
.X
> X
) then
2493 if (Abs(X
-Shots
[a
].Obj
.X
) < Abs(Shots
[a
].Obj
.Vel
.X
*Time
)) and
2494 g_Collide(X
, Y
, Width
, Height
, X
, Shots
[a
].Obj
.Y
,
2495 Shots
[a
].Obj
.Rect
.Width
, Shots
[a
].Obj
.Rect
.Height
) and
2496 g_TraceVector(X
, Y
, Shots
[a
].Obj
.X
, Shots
[a
].Obj
.Y
) then
2503 procedure g_Weapon_SaveState (st
: TStream
);
2505 count
, i
, j
: Integer;
2507 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ ñíàðÿäîâ
2509 for i
:= 0 to High(Shots
) do if (Shots
[i
].ShotType
<> 0) then Inc(count
);
2511 // Êîëè÷åñòâî ñíàðÿäîâ
2512 utils
.WriteInt(st
, count
);
2514 if (count
= 0) then exit
;
2516 for i
:= 0 to High(Shots
) do
2518 if Shots
[i
].ShotType
<> 0 then
2520 // Ñèãíàòóðà ñíàðÿäà
2521 utils
.writeSign(st
, 'SHOT');
2522 utils
.writeInt(st
, Byte(0)); // version
2524 utils
.writeInt(st
, Byte(Shots
[i
].ShotType
));
2526 utils
.writeInt(st
, Word(Shots
[i
].Target
));
2528 utils
.writeInt(st
, Word(Shots
[i
].SpawnerUID
));
2529 // Ðàçìåð ïîëÿ Triggers
2530 utils
.writeInt(st
, Integer(Length(Shots
[i
].Triggers
)));
2531 // Òðèããåðû, àêòèâèðîâàííûå âûñòðåëîì
2532 for j
:= 0 to Length(Shots
[i
].Triggers
)-1 do utils
.writeInt(st
, LongWord(Shots
[i
].Triggers
[j
]));
2534 Obj_SaveState(st
, @Shots
[i
].Obj
);
2536 utils
.writeInt(st
, Byte(Shots
[i
].Stopped
));
2541 procedure g_Weapon_LoadState (st
: TStream
);
2543 count
, tc
, i
, j
: Integer;
2545 if (st
= nil) then exit
;
2547 // Êîëè÷åñòâî ñíàðÿäîâ
2548 count
:= utils
.readLongInt(st
);
2549 if (count
< 0) or (count
> 1024*1024) then raise XStreamError
.Create('invalid shots counter');
2551 SetLength(Shots
, count
);
2553 if (count
= 0) then exit
;
2555 for i
:= 0 to count
-1 do
2557 // Ñèãíàòóðà ñíàðÿäà
2558 if not utils
.checkSign(st
, 'SHOT') then raise XStreamError
.Create('invalid shot signature');
2559 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid shot version');
2561 Shots
[i
].ShotType
:= utils
.readByte(st
);
2563 Shots
[i
].Target
:= utils
.readWord(st
);
2565 Shots
[i
].SpawnerUID
:= utils
.readWord(st
);
2566 // Ðàçìåð ïîëÿ Triggers
2567 tc
:= utils
.readLongInt(st
);
2568 if (tc
< 0) or (tc
> 1024*1024) then raise XStreamError
.Create('invalid shot triggers counter');
2569 SetLength(Shots
[i
].Triggers
, tc
);
2570 // Òðèããåðû, àêòèâèðîâàííûå âûñòðåëîì
2571 for j
:= 0 to tc
-1 do Shots
[i
].Triggers
[j
] := utils
.readLongWord(st
);
2573 Obj_LoadState(@Shots
[i
].Obj
, st
);
2575 Shots
[i
].Stopped
:= utils
.readByte(st
);
2577 Shots
[i
].time
:= gTime
; // TODO save time?
2581 procedure g_Weapon_DestroyShot(I
: Integer; X
, Y
: Integer; Loud
: Boolean = True);
2583 var cx
, cy
: Integer;
2588 if (I
> High(Shots
)) or (I
< 0) then Exit
;
2592 if ShotType
= 0 then Exit
;
2596 cx
:= Obj
.X
+ (Obj
.Rect
.Width
div 2);
2597 cy
:= Obj
.Y
+ (Obj
.Rect
.Height
div 2);
2601 WEAPON_ROCKETLAUNCHER
, WEAPON_SKEL_FIRE
: // Ðàêåòû è ñíàðÿäû Ñêåëåòà
2606 if ShotType
= WEAPON_SKEL_FIRE
then
2607 g_GFX_QueueEffect(R_GFX_EXPLODE_SKELFIRE
, (Obj
.X
+ 32) - 32, (Obj
.Y
+ 8) - 32)
2609 g_GFX_QueueEffect(R_GFX_EXPLODE_ROCKET
, cx
- 64, cy
- 64);
2611 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', Obj
.X
, Obj
.Y
);
2615 WEAPON_PLASMA
, WEAPON_BSP_FIRE
: // Ïëàçìà, ïëàçìà Àðàõíàòðîíà
2620 if ShotType
= WEAPON_PLASMA
then
2621 g_GFX_QueueEffect(R_GFX_EXPLODE_PLASMA
, cx
- 16, cy
- 16)
2623 g_GFX_QueueEffect(R_GFX_EXPLODE_BSPFIRE
, cx
- 16, cy
- 16);
2625 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEPLASMA', Obj
.X
, Obj
.Y
);
2632 g_GFX_QueueEffect(R_GFX_EXPLODE_BFG
, cx
- 64, cy
- 64);
2634 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', Obj
.X
, Obj
.Y
);
2637 WEAPON_IMP_FIRE
, WEAPON_CACO_FIRE
, WEAPON_BARON_FIRE
: // Âûñòðåëû Áåñà, Êàêîäåìîíà Ðûöàðÿ/Áàðîíà àäà
2643 WEAPON_IMP_FIRE
: g_GFX_QueueEffect(R_GFX_EXPLODE_IMPFIRE
, cx
- 32, cy
- 32);
2644 WEAPON_CACO_FIRE
: g_GFX_QueueEffect(R_GFX_EXPLODE_CACOFIRE
, cx
- 32, cy
- 32);
2645 WEAPON_BARON_FIRE
: g_GFX_QueueEffect(R_GFX_EXPLODE_BARONFIRE
, cx
- 32, cy
- 32);
2648 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj
.X
, Obj
.Y
);
2652 WEAPON_MANCUB_FIRE
: // Âûñòðåë Ìàíêóáóñà
2655 g_GFX_QueueEffect(R_GFX_EXPLODE_ROCKET
, cx
- 64, cy
- 64);
2657 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj
.X
, Obj
.Y
);
2659 end; // case ShotType of...
2666 procedure g_Weapon_AddDynLights();
2670 if Shots
= nil then Exit
;
2671 for i
:= 0 to High(Shots
) do
2673 if Shots
[i
].ShotType
= 0 then continue
;
2674 if (Shots
[i
].ShotType
= WEAPON_ROCKETLAUNCHER
) or
2675 (Shots
[i
].ShotType
= WEAPON_BARON_FIRE
) or
2676 (Shots
[i
].ShotType
= WEAPON_MANCUB_FIRE
) or
2677 (Shots
[i
].ShotType
= WEAPON_SKEL_FIRE
) or
2678 (Shots
[i
].ShotType
= WEAPON_IMP_FIRE
) or
2679 (Shots
[i
].ShotType
= WEAPON_CACO_FIRE
) or
2680 (Shots
[i
].ShotType
= WEAPON_MANCUB_FIRE
) or
2681 (Shots
[i
].ShotType
= WEAPON_BSP_FIRE
) or
2682 (Shots
[i
].ShotType
= WEAPON_PLASMA
) or
2683 (Shots
[i
].ShotType
= WEAPON_BFG
) or
2684 (Shots
[i
].ShotType
= WEAPON_FLAMETHROWER
) or
2687 if (Shots
[i
].ShotType
= WEAPON_PLASMA
) then
2688 g_AddDynLight(Shots
[i
].Obj
.X
+(Shots
[i
].Obj
.Rect
.Width
div 2), Shots
[i
].Obj
.Y
+(Shots
[i
].Obj
.Rect
.Height
div 2), 128, 0, 0.3, 1, 0.4)
2689 else if (Shots
[i
].ShotType
= WEAPON_BFG
) then
2690 g_AddDynLight(Shots
[i
].Obj
.X
+(Shots
[i
].Obj
.Rect
.Width
div 2), Shots
[i
].Obj
.Y
+(Shots
[i
].Obj
.Rect
.Height
div 2), 128, 0, 1, 0, 0.5)
2691 else if (Shots
[i
].ShotType
= WEAPON_FLAMETHROWER
) then
2692 g_AddDynLight(Shots
[i
].Obj
.X
+(Shots
[i
].Obj
.Rect
.Width
div 2), Shots
[i
].Obj
.Y
+(Shots
[i
].Obj
.Rect
.Height
div 2), 42, 1, 0.8, 0, 0.4)
2694 g_AddDynLight(Shots
[i
].Obj
.X
+(Shots
[i
].Obj
.Rect
.Width
div 2), Shots
[i
].Obj
.Y
+(Shots
[i
].Obj
.Rect
.Height
div 2), 128, 1, 0, 0, 0.4);
2700 procedure TShot
.positionChanged (); begin end;