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_textures
, g_basic
, g_phys
, xprofiler
;
33 Animation
: TAnimationState
;
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;
104 WP_FIRST
= WEAPON_KASTET
;
105 WP_LAST
= WEAPON_FLAMETHROWER
;
108 gwep_debug_fast_trace
: Boolean = true;
117 Math
, g_map
, g_player
, g_sound
, g_panel
,
118 g_console
, g_options
, g_game
,
119 g_triggers
, MAPDEF
, e_log
, g_monsters
, g_saveload
,
120 g_language
, g_netmsg
, g_grid
,
121 geom
, binheap
, hashtable
, utils
, xstreams
132 SHOT_ROCKETLAUNCHER_WIDTH
= 14;
133 SHOT_ROCKETLAUNCHER_HEIGHT
= 14;
135 SHOT_SKELFIRE_WIDTH
= 14;
136 SHOT_SKELFIRE_HEIGHT
= 14;
138 SHOT_PLASMA_WIDTH
= 16;
139 SHOT_PLASMA_HEIGHT
= 16;
142 SHOT_BFG_HEIGHT
= 32;
143 SHOT_BFG_DAMAGE
= 100;
144 SHOT_BFG_RADIUS
= 256;
146 SHOT_FLAME_WIDTH
= 4;
147 SHOT_FLAME_HEIGHT
= 4;
148 SHOT_FLAME_LIFETIME
= 180;
150 SHOT_SIGNATURE
= $544F4853; // 'SHOT'
153 PHitTime
= ^THitTime
;
157 plridx
: Integer; // if mon=nil
161 TBinHeapKeyHitTime
= class
163 class function less (const a
, b
: Integer): Boolean; inline;
166 // indicies in `wgunHitTime` array
167 TBinaryHeapHitTimes
= specialize TBinaryHeapBase
<Integer, TBinHeapKeyHitTime
>;
170 WaterMap
: array of array of DWORD
= nil;
171 //wgunMonHash: THashIntInt = nil;
172 wgunHitHeap
: TBinaryHeapHitTimes
= nil;
173 wgunHitTime
: array of THitTime
= nil;
174 wgunHitTimeUsed
: Integer = 0;
177 class function TBinHeapKeyHitTime
.less (const a
, b
: Integer): Boolean;
181 hta
:= @wgunHitTime
[a
];
182 htb
:= @wgunHitTime
[b
];
183 if (hta
.distSq
<> htb
.distSq
) then begin result
:= (hta
.distSq
< htb
.distSq
); exit
; end;
184 if (hta
.mon
<> nil) then
187 if (htb
.mon
= nil) then begin result
:= false; exit
; end; // players first
188 result
:= (hta
.mon
.UID
< htb
.mon
.UID
); // why not?
193 if (htb
.mon
<> nil) then begin result
:= true; exit
; end; // players first
194 result
:= (hta
.plridx
< htb
.plridx
); // why not?
199 procedure appendHitTimeMon (adistSq
: Integer; amon
: TMonster
; ax
, ay
: Integer);
201 if (wgunHitTimeUsed
= Length(wgunHitTime
)) then SetLength(wgunHitTime
, wgunHitTimeUsed
+128);
202 with wgunHitTime
[wgunHitTimeUsed
] do
210 wgunHitHeap
.insert(wgunHitTimeUsed
);
211 Inc(wgunHitTimeUsed
);
215 procedure appendHitTimePlr (adistSq
: Integer; aplridx
: Integer; ax
, ay
: Integer);
217 if (wgunHitTimeUsed
= Length(wgunHitTime
)) then SetLength(wgunHitTime
, wgunHitTimeUsed
+128);
218 with wgunHitTime
[wgunHitTimeUsed
] do
226 wgunHitHeap
.insert(wgunHitTimeUsed
);
227 Inc(wgunHitTimeUsed
);
231 function FindShot(): DWORD
;
236 for i
:= 0 to High(Shots
) do
237 if Shots
[i
].ShotType
= 0 then
240 LastShotID
:= Result
;
246 SetLength(Shots
, 128);
251 Result
:= High(Shots
) + 1;
252 SetLength(Shots
, Length(Shots
) + 128);
254 LastShotID
:= Result
;
257 procedure CreateWaterMap();
259 WaterArray
: Array of TWaterPanel
;
266 SetLength(WaterArray
, Length(gWater
));
268 for a
:= 0 to High(gWater
) do
270 WaterArray
[a
].X
:= gWater
[a
].X
;
271 WaterArray
[a
].Y
:= gWater
[a
].Y
;
272 WaterArray
[a
].Width
:= gWater
[a
].Width
;
273 WaterArray
[a
].Height
:= gWater
[a
].Height
;
274 WaterArray
[a
].Active
:= True;
277 g_Game_SetLoadingText(_lc
[I_LOAD_WATER_MAP
], High(WaterArray
), False);
279 for a
:= 0 to High(WaterArray
) do
280 if WaterArray
[a
].Active
then
282 WaterArray
[a
].Active
:= False;
283 m
:= Length(WaterMap
);
284 SetLength(WaterMap
, m
+1);
285 SetLength(WaterMap
[m
], 1);
292 for b
:= 0 to High(WaterArray
) do
293 if WaterArray
[b
].Active
then
294 for c
:= 0 to High(WaterMap
[m
]) do
295 if g_CollideAround(WaterArray
[b
].X
,
298 WaterArray
[b
].Height
,
299 WaterArray
[WaterMap
[m
][c
]].X
,
300 WaterArray
[WaterMap
[m
][c
]].Y
,
301 WaterArray
[WaterMap
[m
][c
]].Width
,
302 WaterArray
[WaterMap
[m
][c
]].Height
) then
304 WaterArray
[b
].Active
:= False;
305 SetLength(WaterMap
[m
],
306 Length(WaterMap
[m
])+1);
307 WaterMap
[m
][High(WaterMap
[m
])] := b
;
313 g_Game_StepLoading();
321 chkTrap_pl
: array [0..256] of Integer;
322 chkTrap_mn
: array [0..65535] of TMonster
;
324 procedure CheckTrap(ID
: DWORD
; dm
: Integer; t
: Byte);
326 //a, b, c, d, i1, i2: Integer;
327 //chkTrap_pl, chkTrap_mn: WArray;
328 plaCount
: Integer = 0;
329 mnaCount
: Integer = 0;
333 function monsWaterCheck (mon: TMonster): Boolean;
335 result := false; // don't stop
336 if mon.alive and mon.Collide(gWater[WaterMap[a][c]]) and (not InWArray(monidx, chkTrap_mn)) and (i2 < 1023) then //FIXME
339 chkTrap_mn[i2] := monidx;
344 function monsWaterCheck (mon
: TMonster
): Boolean;
346 result
:= false; // don't stop
347 if (mon
.trapCheckFrameId
<> frameId
) then
349 mon
.trapCheckFrameId
:= frameId
;
350 chkTrap_mn
[mnaCount
] := mon
;
356 a
, b
, c
, d
, f
: Integer;
359 if (gWater
= nil) or (WaterMap
= nil) then Exit
;
361 frameId
:= g_Mons_getNewTrapFrameId();
366 //SetLength(chkTrap_pl, 1024);
367 //SetLength(chkTrap_mn, 1024);
368 //for d := 0 to 1023 do chkTrap_pl[d] := $FFFF;
369 //for d := 0 to 1023 do chkTrap_mn[d] := $FFFF;
371 for a
:= 0 to High(WaterMap
) do
373 for b
:= 0 to High(WaterMap
[a
]) do
375 pan
:= gWater
[WaterMap
[a
][b
]];
376 if not g_Obj_Collide(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, @Shots
[ID
].Obj
) then continue
;
378 for c
:= 0 to High(WaterMap
[a
]) do
380 pan
:= gWater
[WaterMap
[a
][c
]];
381 for d
:= 0 to High(gPlayers
) do
383 if (gPlayers
[d
] <> nil) and (gPlayers
[d
].alive
) then
385 if gPlayers
[d
].Collide(pan
) then
388 while (f
< plaCount
) and (chkTrap_pl
[f
] <> d
) do Inc(f
);
389 if (f
= plaCount
) then
391 chkTrap_pl
[plaCount
] := d
;
393 if (plaCount
= Length(chkTrap_pl
)) then break
;
399 //g_Mons_ForEach(monsWaterCheck);
400 g_Mons_ForEachAliveAt(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, monsWaterCheck
);
403 for f
:= 0 to plaCount
-1 do gPlayers
[chkTrap_pl
[f
]].Damage(dm
, Shots
[ID
].SpawnerUID
, 0, 0, t
);
404 for f
:= 0 to mnaCount
-1 do chkTrap_mn
[f
].Damage(dm
, 0, 0, Shots
[ID
].SpawnerUID
, t
);
412 function HitMonster(m
: TMonster
; d
: Integer; vx
, vy
: Integer; SpawnerUID
: Word; t
: Byte): Boolean;
419 tt
:= g_GetUIDType(SpawnerUID
);
420 if tt
= UID_MONSTER
then
422 mon
:= g_Monsters_ByUID(SpawnerUID
);
424 mt
:= g_Monsters_ByUID(SpawnerUID
).MonsterType
431 if m
= nil then Exit
;
432 if m
.UID
= SpawnerUID
then
434 // Ñàì ñåáÿ ìîæåò ðàíèòü òîëüêî ðàêåòîé è òîêîì:
435 if (t
<> HIT_ROCKET
) and (t
<> HIT_ELECTRO
) then
437 // Êèáåð äåìîí è áî÷êà âîîáùå íå ìîãóò ñåáÿ ðàíèòü:
438 if (m
.MonsterType
= MONSTER_CYBER
) or
439 (m
.MonsterType
= MONSTER_BARREL
) then
446 if tt
= UID_MONSTER
then
448 // Lost_Soul íå ìîæåò ðàíèòü Pain_Elemental'à:
449 if (mt
= MONSTER_SOUL
) and (m
.MonsterType
= MONSTER_PAIN
) then
452 // Îáà ìîíñòðà îäíîãî âèäà:
453 if mt
= m
.MonsterType
then
455 MONSTER_IMP
, MONSTER_DEMON
, MONSTER_BARON
, MONSTER_KNIGHT
, MONSTER_CACO
,
456 MONSTER_SOUL
, MONSTER_MANCUB
, MONSTER_SKEL
, MONSTER_FISH
:
457 Exit
; // Ýòè íå áüþò ñâîèõ
461 if g_Game_IsServer
then
463 if (t
<> HIT_FLAME
) or (m
.FFireTime
= 0) or (vx
<> 0) or (vy
<> 0) then
464 Result
:= m
.Damage(d
, vx
, vy
, SpawnerUID
, t
)
466 Result
:= (gLMSRespawn
= LMS_RESPAWN_NONE
); // don't hit monsters when it's warmup time
467 if t
= HIT_FLAME
then
468 m
.CatchFire(SpawnerUID
);
471 Result
:= (gLMSRespawn
= LMS_RESPAWN_NONE
); // don't hit monsters when it's warmup time
475 function HitPlayer (p
: TPlayer
; d
: Integer; vx
, vy
: Integer; SpawnerUID
: Word; t
: Byte): Boolean;
479 // Ñàì ñåáÿ ìîæåò ðàíèòü òîëüêî ðàêåòîé è òîêîì
480 if (p
.UID
= SpawnerUID
) and (t
<> HIT_ROCKET
) and (t
<> HIT_ELECTRO
) then exit
;
482 if g_Game_IsServer
then
484 if (t
<> HIT_FLAME
) or (p
.FFireTime
= 0) or (vx
<> 0) or (vy
<> 0) then p
.Damage(d
, SpawnerUID
, vx
, vy
, t
);
485 if (t
= HIT_FLAME
) then p
.CatchFire(SpawnerUID
);
492 procedure g_Weapon_BFG9000(X
, Y
: Integer; SpawnerUID
: Word);
494 function monsCheck (mon
: TMonster
): Boolean;
496 result
:= false; // don't stop
497 if (mon
.alive
) and (mon
.UID
<> SpawnerUID
) then
501 if (g_PatchLength(X
, Y
, Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2),
502 Obj
.Y
+Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2)) <= SHOT_BFG_RADIUS
) and
503 g_TraceVector(X
, Y
, Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2),
504 Obj
.Y
+Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2)) then
506 if HitMonster(mon
, 50, 0, 0, SpawnerUID
, HIT_SOME
) then mon
.BFGHit();
518 //g_Sound_PlayEx('SOUND_WEAPON_EXPLODEBFG', 255);
522 if gAdvCorpses
and (h
<> -1) then
524 if (gCorpses
[i
] <> nil) and (gCorpses
[i
].State
<> CORPSE_STATE_REMOVEME
) then
526 if (g_PatchLength(X
, Y
, Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2),
527 Obj
.Y
+Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2)) <= SHOT_BFG_RADIUS
) and
528 g_TraceVector(X
, Y
, Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2),
529 Obj
.Y
+Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2)) then
531 Damage(50, SpawnerUID
, 0, 0);
532 g_Weapon_BFGHit(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2),
533 Obj
.Y
+Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2));
537 pl
:= g_Player_Get(SpawnerUID
);
545 if (gPlayers
[i
] <> nil) and (gPlayers
[i
].alive
) and (gPlayers
[i
].UID
<> SpawnerUID
) then
547 if (g_PatchLength(X
, Y
, GameX
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
548 GameY
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)) <= SHOT_BFG_RADIUS
) and
549 g_TraceVector(X
, Y
, GameX
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
550 GameY
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)) then
552 if (st
= TEAM_NONE
) or (st
<> gPlayers
[i
].Team
) then
553 b
:= HitPlayer(gPlayers
[i
], 50, 0, 0, SpawnerUID
, HIT_SOME
)
555 b
:= HitPlayer(gPlayers
[i
], 25, 0, 0, SpawnerUID
, HIT_SOME
);
557 gPlayers
[i
].BFGHit();
561 g_Mons_ForEachAlive(monsCheck
);
564 function g_Weapon_CreateShot(I
: Integer; ShotType
: Byte; Spawner
, TargetUID
: Word; X
, Y
, XV
, YV
: Integer): LongWord;
569 find_id
:= FindShot()
573 if Integer(find_id
) >= High(Shots
) then
574 SetLength(Shots
, find_id
+ 64)
578 WEAPON_ROCKETLAUNCHER
:
580 with Shots
[find_id
] do
584 Obj
.Rect
.Width
:= SHOT_ROCKETLAUNCHER_WIDTH
;
585 Obj
.Rect
.Height
:= SHOT_ROCKETLAUNCHER_HEIGHT
;
589 ShotType
:= WEAPON_ROCKETLAUNCHER
;
595 with Shots
[find_id
] do
599 Obj
.Rect
.Width
:= SHOT_PLASMA_WIDTH
;
600 Obj
.Rect
.Height
:= SHOT_PLASMA_HEIGHT
;
603 ShotType
:= WEAPON_PLASMA
;
604 Animation
:= TAnimationState
.Create(True, 5, 2); // !!! put values into table
610 with Shots
[find_id
] do
614 Obj
.Rect
.Width
:= SHOT_BFG_WIDTH
;
615 Obj
.Rect
.Height
:= SHOT_BFG_HEIGHT
;
618 ShotType
:= WEAPON_BFG
;
619 Animation
:= TAnimationState
.Create(True, 6, 2); // !!! put values into table
625 with Shots
[find_id
] do
629 Obj
.Rect
.Width
:= SHOT_FLAME_WIDTH
;
630 Obj
.Rect
.Height
:= SHOT_FLAME_HEIGHT
;
633 ShotType
:= WEAPON_FLAMETHROWER
;
634 // Animation := TAnimationState.Create(True, 6, 0); // drawed as gfx
640 with Shots
[find_id
] do
644 Obj
.Rect
.Width
:= 16;
645 Obj
.Rect
.Height
:= 16;
648 ShotType
:= WEAPON_IMP_FIRE
;
649 Animation
:= TAnimationState
.Create(True, 4, 2); // !!! put values into table
655 with Shots
[find_id
] do
659 Obj
.Rect
.Width
:= 16;
660 Obj
.Rect
.Height
:= 16;
663 ShotType
:= WEAPON_CACO_FIRE
;
664 Animation
:= TAnimationState
.Create(True, 4, 2); // !!! put values into table
670 with Shots
[find_id
] do
674 Obj
.Rect
.Width
:= 32;
675 Obj
.Rect
.Height
:= 32;
678 ShotType
:= WEAPON_MANCUB_FIRE
;
679 Animation
:= TAnimationState
.Create(True, 4, 2); // !!! put values into table
685 with Shots
[find_id
] do
689 Obj
.Rect
.Width
:= 16;
690 Obj
.Rect
.Height
:= 16;
693 ShotType
:= WEAPON_BARON_FIRE
;
694 Animation
:= TAnimationState
.Create(True, 4, 2); // !!! put values into table
700 with Shots
[find_id
] do
704 Obj
.Rect
.Width
:= 16;
705 Obj
.Rect
.Height
:= 16;
708 ShotType
:= WEAPON_BSP_FIRE
;
709 Animation
:= TAnimationState
.Create(True, 4, 2); // !!! put values into table
715 with Shots
[find_id
] do
719 Obj
.Rect
.Width
:= SHOT_SKELFIRE_WIDTH
;
720 Obj
.Rect
.Height
:= SHOT_SKELFIRE_HEIGHT
;
723 ShotType
:= WEAPON_SKEL_FIRE
;
725 Animation
:= TAnimationState
.Create(True, 5, 2); // !!! put values into table
730 Shots
[find_id
].Obj
.oldX
:= X
;
731 Shots
[find_id
].Obj
.oldY
:= Y
;
732 Shots
[find_id
].Obj
.X
:= X
;
733 Shots
[find_id
].Obj
.Y
:= Y
;
734 Shots
[find_id
].Obj
.Vel
.X
:= XV
;
735 Shots
[find_id
].Obj
.Vel
.Y
:= YV
;
736 Shots
[find_id
].Obj
.Accel
.X
:= 0;
737 Shots
[find_id
].Obj
.Accel
.Y
:= 0;
738 Shots
[find_id
].SpawnerUID
:= Spawner
;
739 if (ShotType
= WEAPON_FLAMETHROWER
) and (XV
= 0) and (YV
= 0) then
740 Shots
[find_id
].Stopped
:= 255
742 Shots
[find_id
].Stopped
:= 0;
746 procedure throw(i
, x
, y
, xd
, yd
, s
: Integer);
753 a
:= Max(Abs(xd
), Abs(yd
));
757 Shots
[i
].Obj
.oldX
:= x
;
758 Shots
[i
].Obj
.oldY
:= y
;
761 Shots
[i
].Obj
.Vel
.X
:= (xd
*s
) div a
;
762 Shots
[i
].Obj
.Vel
.Y
:= (yd
*s
) div a
;
763 Shots
[i
].Obj
.Accel
.X
:= 0;
764 Shots
[i
].Obj
.Accel
.Y
:= 0;
765 Shots
[i
].Stopped
:= 0;
766 if Shots
[i
].ShotType
in [WEAPON_ROCKETLAUNCHER
, WEAPON_BFG
] then
767 Shots
[i
].Timeout
:= 900 // ~25 sec
770 if Shots
[i
].ShotType
= WEAPON_FLAMETHROWER
then
771 Shots
[i
].Timeout
:= SHOT_FLAME_LIFETIME
773 Shots
[i
].Timeout
:= 550; // ~15 sec
777 function g_Weapon_Hit(obj
: PObj
; d
: Integer; SpawnerUID
: Word; t
: Byte; HitCorpses
: Boolean = True): Byte;
781 function PlayerHit(Team
: Byte = 0): Boolean;
792 if (gPlayers
[i
] <> nil) and gPlayers
[i
].alive
and g_Obj_Collide(obj
, @gPlayers
[i
].Obj
) then
795 if (Team
> 0) and (g_GetUIDType(SpawnerUID
) = UID_PLAYER
) then
797 p
:= g_Player_Get(SpawnerUID
);
799 ChkTeam
:= (p
.Team
= gPlayers
[i
].Team
) xor (Team
= 2);
802 if HitPlayer(gPlayers
[i
], d
, obj
^.Vel
.X
, obj
^.Vel
.Y
, SpawnerUID
, t
) then
804 if t
<> HIT_FLAME
then
805 gPlayers
[i
].Push((obj
^.Vel
.X
+obj
^.Accel
.X
)*IfThen(t
= HIT_BFG
, 8, 1) div 4,
806 (obj
^.Vel
.Y
+obj
^.Accel
.Y
)*IfThen(t
= HIT_BFG
, 8, 1) div 4);
808 g_Game_DelayEvent(DE_BFGHIT
, 1000, SpawnerUID
);
816 function monsCheckHit (monidx: Integer; mon: TMonster): Boolean;
818 result := false; // don't stop
819 if mon.alive and g_Obj_Collide(obj, @mon.Obj) then
821 if HitMonster(mon, d, obj^.Vel.X, obj^.Vel.Y, SpawnerUID, t) then
823 if (t <> HIT_FLAME) then
825 mon.Push((obj^.Vel.X+obj^.Accel.X)*IfThen(t = HIT_BFG, 8, 1) div 4,
826 (obj^.Vel.Y+obj^.Accel.Y)*IfThen(t = HIT_BFG, 8, 1) div 4);
834 function monsCheckHit (mon
: TMonster
): Boolean;
836 result
:= false; // don't stop
837 if HitMonster(mon
, d
, obj
.Vel
.X
, obj
.Vel
.Y
, SpawnerUID
, t
) then
839 if (t
<> HIT_FLAME
) then
841 mon
.Push((obj
.Vel
.X
+obj
.Accel
.X
)*IfThen(t
= HIT_BFG
, 8, 1) div 4,
842 (obj
.Vel
.Y
+obj
.Accel
.Y
)*IfThen(t
= HIT_BFG
, 8, 1) div 4);
848 function MonsterHit(): Boolean;
850 //result := g_Mons_ForEach(monsCheckHit);
851 //FIXME: accelerate this!
852 result
:= g_Mons_ForEachAliveAt(obj
.X
+obj
.Rect
.X
, obj
.Y
+obj
.Rect
.Y
, obj
.Rect
.Width
, obj
.Rect
.Height
, monsCheckHit
);
862 if gAdvCorpses
and (h
<> -1) then
864 if (gCorpses
[i
] <> nil) and (gCorpses
[i
].State
<> CORPSE_STATE_REMOVEME
) and
865 g_Obj_Collide(obj
, @gCorpses
[i
].Obj
) then
868 gCorpses
[i
].Damage(d
, SpawnerUID
, (obj
^.Vel
.X
+obj
^.Accel
.X
) div 4,
869 (obj
^.Vel
.Y
+obj
^.Accel
.Y
) div 4);
874 case gGameSettings
.GameMode
of
878 // Ñíà÷àëà áü¸ì ìîíñòðîâ, åñëè åñòü, ïîòîì ïûòàåìñÿ áèòü èãðîêîâ
885 // È â êîíöå èãðîêîâ, íî òîëüêî åñëè ïîëîæåíî
886 // (èëè ñíàðÿä îò ìîíñòðà, èëè friendlyfire, èëè friendly_hit_projectile)
887 if (g_GetUIDType(SpawnerUID
) <> UID_PLAYER
) or
888 LongBool(gGameSettings
.Options
and (GAME_OPTION_TEAMDAMAGE
or GAME_OPTION_TEAMHITPROJECTILE
)) then
901 // Ñíà÷àëà áü¸ì èãðîêîâ, åñëè åñòü, ïîòîì ïûòàåìñÿ áèòü ìîíñòðîâ
918 // Ñíà÷àëà áü¸ì èãðîêîâ êîìàíäû ñîïåðíèêà
932 // È â êîíöå ñâîèõ èãðîêîâ, íî òîëüêî åñëè ïîëîæåíî
933 // (èëè friendlyfire, èëè friendly_hit_projectile)
934 if LongBool(gGameSettings
.Options
and (GAME_OPTION_TEAMDAMAGE
or GAME_OPTION_TEAMHITPROJECTILE
)) then
947 function g_Weapon_HitUID(UID
: Word; d
: Integer; SpawnerUID
: Word; t
: Byte): Boolean;
951 case g_GetUIDType(UID
) of
952 UID_PLAYER
: Result
:= HitPlayer(g_Player_Get(UID
), d
, 0, 0, SpawnerUID
, t
);
953 UID_MONSTER
: Result
:= HitMonster(g_Monsters_ByUID(UID
), d
, 0, 0, SpawnerUID
, t
);
958 function g_Weapon_Explode(X
, Y
: Integer; rad
: Integer; SpawnerUID
: Word): Boolean;
960 r
: Integer; // squared radius
962 function monsExCheck (mon
: TMonster
): Boolean;
966 result
:= false; // don't stop
968 dx
:= mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-X
;
969 dy
:= mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2)-Y
;
971 if dx
> 1000 then dx
:= 1000;
972 if dy
> 1000 then dy
:= 1000;
974 if (dx
*dx
+dy
*dy
< r
) then
976 //m := PointToRect(X, Y, Obj.X+Obj.Rect.X, Obj.Y+Obj.Rect.Y, Obj.Rect.Width, Obj.Rect.Height);
977 //e_WriteLog(Format('explo monster #%d: x=%d; y=%d; rad=%d; dx=%d; dy=%d', [monidx, X, Y, rad, dx, dy]), MSG_NOTIFY);
979 mm
:= Max(abs(dx
), abs(dy
));
980 if mm
= 0 then mm
:= 1;
984 HitMonster(mon
, ((mon
.Obj
.Rect
.Width
div 4)*10*(rad
-mm
)) div rad
, 0, 0, SpawnerUID
, HIT_ROCKET
);
987 mon
.Push((dx
*7) div mm
, (dy
*7) div mm
);
993 i
, h
, dx
, dy
, m
, mm
: Integer;
998 g_Triggers_PressC(X
, Y
, rad
, SpawnerUID
, ACTIVATE_SHOT
);
1002 h
:= High(gPlayers
);
1006 if (gPlayers
[i
] <> nil) and gPlayers
[i
].alive
then
1009 dx
:= Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)-X
;
1010 dy
:= Obj
.Y
+Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2)-Y
;
1012 if dx
> 1000 then dx
:= 1000;
1013 if dy
> 1000 then dy
:= 1000;
1015 if dx
*dx
+dy
*dy
< r
then
1017 //m := PointToRect(X, Y, GameX+PLAYER_RECT.X, GameY+PLAYER_RECT.Y,
1018 // PLAYER_RECT.Width, PLAYER_RECT.Height);
1020 mm
:= Max(abs(dx
), abs(dy
));
1021 if mm
= 0 then mm
:= 1;
1023 HitPlayer(gPlayers
[i
], (100*(rad
-mm
)) div rad
, (dx
*10) div mm
, (dy
*10) div mm
, SpawnerUID
, HIT_ROCKET
);
1024 gPlayers
[i
].Push((dx
*7) div mm
, (dy
*7) div mm
);
1028 //g_Mons_ForEach(monsExCheck);
1029 g_Mons_ForEachAt(X
-(rad
+32), Y
-(rad
+32), (rad
+32)*2, (rad
+32)*2, monsExCheck
);
1031 h
:= High(gCorpses
);
1033 if gAdvCorpses
and (h
<> -1) then
1035 if (gCorpses
[i
] <> nil) and (gCorpses
[i
].State
<> CORPSE_STATE_REMOVEME
) then
1038 dx
:= Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)-X
;
1039 dy
:= Obj
.Y
+Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2)-Y
;
1041 if dx
> 1000 then dx
:= 1000;
1042 if dy
> 1000 then dy
:= 1000;
1044 if dx
*dx
+dy
*dy
< r
then
1046 m
:= PointToRect(X
, Y
, Obj
.X
+Obj
.Rect
.X
, Obj
.Y
+Obj
.Rect
.Y
,
1047 Obj
.Rect
.Width
, Obj
.Rect
.Height
);
1049 mm
:= Max(abs(dx
), abs(dy
));
1050 if mm
= 0 then mm
:= 1;
1052 Damage(Round(100*(rad
-m
)/rad
), SpawnerUID
, (dx
*10) div mm
, (dy
*10) div mm
);
1058 if gAdvGibs
and (h
<> -1) then
1060 if gGibs
[i
].alive
then
1063 dx
:= Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)-X
;
1064 dy
:= Obj
.Y
+Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2)-Y
;
1066 if dx
> 1000 then dx
:= 1000;
1067 if dy
> 1000 then dy
:= 1000;
1069 if dx
*dx
+dy
*dy
< r
then
1071 m
:= PointToRect(X
, Y
, Obj
.X
+Obj
.Rect
.X
, Obj
.Y
+Obj
.Rect
.Y
,
1072 Obj
.Rect
.Width
, Obj
.Rect
.Height
);
1073 _angle
:= GetAngle(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2),
1074 Obj
.Y
+Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2), X
, Y
);
1076 g_Obj_PushA(@Obj
, Round(15*(rad
-m
)/rad
), _angle
);
1077 positionChanged(); // this updates spatial accelerators
1082 procedure g_Weapon_Init();
1087 procedure g_Weapon_Free();
1091 if Shots
<> nil then
1093 for i
:= 0 to High(Shots
) do
1094 if Shots
[i
].ShotType
<> 0 then
1095 Shots
[i
].Animation
.Free();
1103 procedure g_Weapon_LoadData();
1105 e_WriteLog('Loading weapons data...', TMsgType
.Notify
);
1107 g_Sound_CreateWADEx('SOUND_WEAPON_HITPUNCH', GameWAD
+':SOUNDS\HITPUNCH');
1108 g_Sound_CreateWADEx('SOUND_WEAPON_MISSPUNCH', GameWAD
+':SOUNDS\MISSPUNCH');
1109 g_Sound_CreateWADEx('SOUND_WEAPON_HITBERSERK', GameWAD
+':SOUNDS\HITBERSERK');
1110 g_Sound_CreateWADEx('SOUND_WEAPON_MISSBERSERK', GameWAD
+':SOUNDS\MISSBERSERK');
1111 g_Sound_CreateWADEx('SOUND_WEAPON_SELECTSAW', GameWAD
+':SOUNDS\SELECTSAW');
1112 g_Sound_CreateWADEx('SOUND_WEAPON_IDLESAW', GameWAD
+':SOUNDS\IDLESAW');
1113 g_Sound_CreateWADEx('SOUND_WEAPON_HITSAW', GameWAD
+':SOUNDS\HITSAW');
1114 g_Sound_CreateWADEx('SOUND_WEAPON_FIRESHOTGUN2', GameWAD
+':SOUNDS\FIRESHOTGUN2');
1115 g_Sound_CreateWADEx('SOUND_WEAPON_FIRESHOTGUN', GameWAD
+':SOUNDS\FIRESHOTGUN');
1116 g_Sound_CreateWADEx('SOUND_WEAPON_FIRESAW', GameWAD
+':SOUNDS\FIRESAW');
1117 g_Sound_CreateWADEx('SOUND_WEAPON_FIREROCKET', GameWAD
+':SOUNDS\FIREROCKET');
1118 g_Sound_CreateWADEx('SOUND_WEAPON_FIREPLASMA', GameWAD
+':SOUNDS\FIREPLASMA');
1119 g_Sound_CreateWADEx('SOUND_WEAPON_FIREPISTOL', GameWAD
+':SOUNDS\FIREPISTOL');
1120 g_Sound_CreateWADEx('SOUND_WEAPON_FIRECGUN', GameWAD
+':SOUNDS\FIRECGUN');
1121 g_Sound_CreateWADEx('SOUND_WEAPON_FIREBFG', GameWAD
+':SOUNDS\FIREBFG');
1122 g_Sound_CreateWADEx('SOUND_FIRE', GameWAD
+':SOUNDS\FIRE');
1123 g_Sound_CreateWADEx('SOUND_IGNITE', GameWAD
+':SOUNDS\IGNITE');
1124 g_Sound_CreateWADEx('SOUND_WEAPON_STARTFIREBFG', GameWAD
+':SOUNDS\STARTFIREBFG');
1125 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEROCKET', GameWAD
+':SOUNDS\EXPLODEROCKET');
1126 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEBFG', GameWAD
+':SOUNDS\EXPLODEBFG');
1127 g_Sound_CreateWADEx('SOUND_WEAPON_BFGWATER', GameWAD
+':SOUNDS\BFGWATER');
1128 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEPLASMA', GameWAD
+':SOUNDS\EXPLODEPLASMA');
1129 g_Sound_CreateWADEx('SOUND_WEAPON_PLASMAWATER', GameWAD
+':SOUNDS\PLASMAWATER');
1130 g_Sound_CreateWADEx('SOUND_WEAPON_FIREBALL', GameWAD
+':SOUNDS\FIREBALL');
1131 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEBALL', GameWAD
+':SOUNDS\EXPLODEBALL');
1132 g_Sound_CreateWADEx('SOUND_WEAPON_FIREREV', GameWAD
+':SOUNDS\FIREREV');
1133 g_Sound_CreateWADEx('SOUND_WEAPON_FLAMEON', GameWAD
+':SOUNDS\STARTFLM');
1134 g_Sound_CreateWADEx('SOUND_WEAPON_FLAMEOFF', GameWAD
+':SOUNDS\STOPFLM');
1135 g_Sound_CreateWADEx('SOUND_WEAPON_FLAMEWORK', GameWAD
+':SOUNDS\WORKFLM');
1136 g_Sound_CreateWADEx('SOUND_PLAYER_JETFLY', GameWAD
+':SOUNDS\WORKJETPACK');
1137 g_Sound_CreateWADEx('SOUND_PLAYER_JETON', GameWAD
+':SOUNDS\STARTJETPACK');
1138 g_Sound_CreateWADEx('SOUND_PLAYER_JETOFF', GameWAD
+':SOUNDS\STOPJETPACK');
1139 g_Sound_CreateWADEx('SOUND_PLAYER_CASING1', GameWAD
+':SOUNDS\CASING1');
1140 g_Sound_CreateWADEx('SOUND_PLAYER_CASING2', GameWAD
+':SOUNDS\CASING2');
1141 g_Sound_CreateWADEx('SOUND_PLAYER_SHELL1', GameWAD
+':SOUNDS\SHELL1');
1142 g_Sound_CreateWADEx('SOUND_PLAYER_SHELL2', GameWAD
+':SOUNDS\SHELL2');
1144 //wgunMonHash := hashNewIntInt();
1145 wgunHitHeap
:= TBinaryHeapHitTimes
.Create();
1148 procedure g_Weapon_FreeData();
1150 e_WriteLog('Releasing weapons data...', TMsgType
.Notify
);
1152 g_Sound_Delete('SOUND_WEAPON_HITPUNCH');
1153 g_Sound_Delete('SOUND_WEAPON_MISSPUNCH');
1154 g_Sound_Delete('SOUND_WEAPON_HITBERSERK');
1155 g_Sound_Delete('SOUND_WEAPON_MISSBERSERK');
1156 g_Sound_Delete('SOUND_WEAPON_SELECTSAW');
1157 g_Sound_Delete('SOUND_WEAPON_IDLESAW');
1158 g_Sound_Delete('SOUND_WEAPON_HITSAW');
1159 g_Sound_Delete('SOUND_WEAPON_FIRESHOTGUN2');
1160 g_Sound_Delete('SOUND_WEAPON_FIRESHOTGUN');
1161 g_Sound_Delete('SOUND_WEAPON_FIRESAW');
1162 g_Sound_Delete('SOUND_WEAPON_FIREROCKET');
1163 g_Sound_Delete('SOUND_WEAPON_FIREPLASMA');
1164 g_Sound_Delete('SOUND_WEAPON_FIREPISTOL');
1165 g_Sound_Delete('SOUND_WEAPON_FIRECGUN');
1166 g_Sound_Delete('SOUND_WEAPON_FIREBFG');
1167 g_Sound_Delete('SOUND_FIRE');
1168 g_Sound_Delete('SOUND_IGNITE');
1169 g_Sound_Delete('SOUND_WEAPON_STARTFIREBFG');
1170 g_Sound_Delete('SOUND_WEAPON_EXPLODEROCKET');
1171 g_Sound_Delete('SOUND_WEAPON_EXPLODEBFG');
1172 g_Sound_Delete('SOUND_WEAPON_BFGWATER');
1173 g_Sound_Delete('SOUND_WEAPON_EXPLODEPLASMA');
1174 g_Sound_Delete('SOUND_WEAPON_PLASMAWATER');
1175 g_Sound_Delete('SOUND_WEAPON_FIREBALL');
1176 g_Sound_Delete('SOUND_WEAPON_EXPLODEBALL');
1177 g_Sound_Delete('SOUND_WEAPON_FIREREV');
1178 g_Sound_Delete('SOUND_WEAPON_FLAMEON');
1179 g_Sound_Delete('SOUND_WEAPON_FLAMEOFF');
1180 g_Sound_Delete('SOUND_WEAPON_FLAMEWORK');
1181 g_Sound_Delete('SOUND_PLAYER_JETFLY');
1182 g_Sound_Delete('SOUND_PLAYER_JETON');
1183 g_Sound_Delete('SOUND_PLAYER_JETOFF');
1184 g_Sound_Delete('SOUND_PLAYER_CASING1');
1185 g_Sound_Delete('SOUND_PLAYER_CASING2');
1186 g_Sound_Delete('SOUND_PLAYER_SHELL1');
1187 g_Sound_Delete('SOUND_PLAYER_SHELL2');
1191 function GunHitPlayer (X
, Y
: Integer; vx
, vy
: Integer; dmg
: Integer; SpawnerUID
: Word; AllowPush
: Boolean): Boolean;
1196 for i
:= 0 to High(gPlayers
) do
1198 if (gPlayers
[i
] <> nil) and gPlayers
[i
].alive
and gPlayers
[i
].Collide(X
, Y
) then
1200 if HitPlayer(gPlayers
[i
], dmg
, vx
*10, vy
*10-3, SpawnerUID
, HIT_SOME
) then
1202 if AllowPush
then gPlayers
[i
].Push(vx
, vy
);
1210 function GunHit (X
, Y
: Integer; vx
, vy
: Integer; dmg
: Integer; SpawnerUID
: Word; AllowPush
: Boolean): Byte;
1212 function monsCheck (mon
: TMonster
): Boolean;
1214 result
:= false; // don't stop
1215 if HitMonster(mon
, dmg
, vx
*10, vy
*10-3, SpawnerUID
, HIT_SOME
) then
1217 if AllowPush
then mon
.Push(vx
, vy
);
1224 if GunHitPlayer(X
, Y
, vx
, vy
, dmg
, SpawnerUID
, AllowPush
) then result
:= 1
1225 else if g_Mons_ForEachAliveAt(X
, Y
, 1, 1, monsCheck
) then result
:= 2;
1230 procedure g_Weapon_gunOld(const x, y, xd, yd, v, dmg: Integer; SpawnerUID: Word; CheckTrigger: Boolean);
1241 t1, _collide: Boolean;
1243 {$IF DEFINED(D2F_DEBUG)}
1245 showTime: Boolean = true;
1248 a := GetAngle(x, y, xd, yd)+180;
1250 SinCos(DegToRad(-a), s, c);
1252 if Abs(s) < 0.01 then s := 0;
1253 if Abs(c) < 0.01 then c := 0;
1255 x2 := x+Round(c*gMapInfo.Width);
1256 y2 := y+Round(s*gMapInfo.Width);
1258 t1 := gWalls <> nil;
1260 w := gMapInfo.Width;
1261 h := gMapInfo.Height;
1268 if (xd = 0) and (yd = 0) then Exit;
1270 if dx > 0 then xi := 1 else if dx < 0 then xi := -1 else xi := 0;
1271 if dy > 0 then yi := 1 else if dy < 0 then yi := -1 else yi := 0;
1276 if dx > dy then d := dx else d := dy;
1278 //blood vel, for Monster.Damage()
1279 //vx := (dx*10 div d)*xi;
1280 //vy := (dy*10 div d)*yi;
1282 {$IF DEFINED(D2F_DEBUG)}
1283 stt := getTimeMicro();
1306 if (yy > h) or (yy < 0) then Break;
1307 if (xx > w) or (xx < 0) then Break;
1310 if ByteBool(gCollideMap[yy, xx] and MARK_BLOCKED) then
1313 {$IF DEFINED(D2F_DEBUG)}
1314 stt := getTimeMicro()-stt;
1315 e_WriteLog(Format('*** old trace time: %u microseconds', [LongWord(stt)]), MSG_NOTIFY);
1318 g_GFX_Spark(xx-xi, yy-yi, 2+Random(2), 180+a, 0, 0);
1319 if g_Game_IsServer and g_Game_IsNet then
1320 MH_SEND_Effect(xx-xi, yy-yi, 180+a, NET_GFX_SPARK);
1323 if not _collide then
1325 _collide := GunHit(xx, yy, xi*v, yi*v, dmg, SpawnerUID, v <> 0) <> 0;
1328 if _collide then Break;
1331 {$IF DEFINED(D2F_DEBUG)}
1334 stt := getTimeMicro()-stt;
1335 e_WriteLog(Format('*** old trace time: %u microseconds', [LongWord(stt)]), MSG_NOTIFY);
1339 if CheckTrigger and g_Game_IsServer then
1340 g_Triggers_PressL(X, Y, xx-xi, yy-yi, SpawnerUID, ACTIVATE_SHOT);
1346 procedure g_Weapon_gun (const x
, y
, xd
, yd
, v
, indmg
: Integer; SpawnerUID
: Word; CheckTrigger
: Boolean);
1351 wallDistSq
: Integer = $3fffffff;
1352 spawnerPlr
: TPlayer
= nil;
1355 function doPlayerHit (idx
: Integer; hx
, hy
: Integer): Boolean;
1358 if (idx
< 0) or (idx
> High(gPlayers
)) then exit
;
1359 if (gPlayers
[idx
] = nil) or not gPlayers
[idx
].alive
then exit
;
1360 if (spawnerPlr
<> nil) then
1362 if ((gGameSettings
.Options
and (GAME_OPTION_TEAMHITTRACE
or GAME_OPTION_TEAMDAMAGE
)) = 0) and
1363 (spawnerPlr
.Team
<> TEAM_NONE
) and (spawnerPlr
.Team
= gPlayers
[idx
].Team
) then
1365 if (spawnerPlr
<> gPlayers
[idx
]) and ((gGameSettings
.Options
and GAME_OPTION_TEAMABSORBDAMAGE
) = 0) then
1366 dmg
:= Max(1, dmg
div 2);
1370 result
:= HitPlayer(gPlayers
[idx
], dmg
, (xi
*v
)*10, (yi
*v
)*10-3, SpawnerUID
, HIT_SOME
);
1371 if result
and (v
<> 0) then gPlayers
[idx
].Push((xi
*v
), (yi
*v
));
1372 {$IF DEFINED(D2F_DEBUG)}
1373 //if result then e_WriteLog(Format(' PLAYER #%d HIT', [idx]), MSG_NOTIFY);
1377 function doMonsterHit (mon
: TMonster
; hx
, hy
: Integer): Boolean;
1380 if (mon
= nil) then exit
;
1381 result
:= HitMonster(mon
, dmg
, (xi
*v
)*10, (yi
*v
)*10-3, SpawnerUID
, HIT_SOME
);
1382 if result
and (v
<> 0) then mon
.Push((xi
*v
), (yi
*v
));
1383 {$IF DEFINED(D2F_DEBUG)}
1384 //if result then e_WriteLog(Format(' MONSTER #%u HIT', [LongWord(mon.UID)]), MSG_NOTIFY);
1388 // collect players along hitray
1389 // return `true` if instant hit was detected
1390 function playerPossibleHit (): Boolean;
1393 px
, py
, pw
, ph
: Integer;
1399 for i
:= 0 to High(gPlayers
) do
1402 if (plr
<> nil) and plr
.alive
then
1404 plr
.getMapBox(px
, py
, pw
, ph
);
1405 if lineAABBIntersects(x
, y
, x2
, y2
, px
, py
, pw
, ph
, inx
, iny
) then
1407 distSq
:= distanceSq(x
, y
, inx
, iny
);
1408 if (distSq
= 0) then
1411 if doPlayerHit(i
, x
, y
) then begin result
:= true; exit
; end;
1413 else if (distSq
< wallDistSq
) then
1415 appendHitTimePlr(distSq
, i
, inx
, iny
);
1422 procedure sqchecker (mon
: TMonster
);
1424 mx
, my
, mw
, mh
: Integer;
1428 mon
.getMapBox(mx
, my
, mw
, mh
);
1429 if lineAABBIntersects(x0
, y0
, x2
, y2
, mx
, my
, mw
, mh
, inx
, iny
) then
1431 distSq
:= distanceSq(x0
, y0
, inx
, iny
);
1432 if (distSq
< wallDistSq
) then appendHitTimeMon(distSq
, mon
, inx
, iny
);
1442 wallHitFlag
: Boolean = false;
1443 wallHitX
: Integer = 0;
1444 wallHitY
: Integer = 0;
1445 didHit
: Boolean = false;
1446 {$IF DEFINED(D2F_DEBUG)}
1450 it
: TMonsterGrid
.Iter
;
1453 if not gwep_debug_fast_trace then
1455 g_Weapon_gunOld(x, y, xd, yd, v, dmg, SpawnerUID, CheckTrigger);
1460 if (xd
= 0) and (yd
= 0) then exit
;
1462 if (g_GetUIDType(SpawnerUID
) = UID_PLAYER
) then
1463 spawnerPlr
:= g_Player_Get(SpawnerUID
);
1467 //wgunMonHash.reset(); //FIXME: clear hash on level change
1468 wgunHitHeap
.clear();
1469 wgunHitTimeUsed
:= 0;
1471 a
:= GetAngle(x
, y
, xd
, yd
)+180;
1473 SinCos(DegToRad(-a
), s
, c
);
1475 if Abs(s
) < 0.01 then s
:= 0;
1476 if Abs(c
) < 0.01 then c
:= 0;
1480 x2
:= x
+Round(c
*gMapInfo
.Width
);
1481 y2
:= y
+Round(s
*gMapInfo
.Width
);
1486 if (dx
> 0) then xi
:= 1 else if (dx
< 0) then xi
:= -1 else xi
:= 0;
1487 if (dy
> 0) then yi
:= 1 else if (dy
< 0) then yi
:= -1 else yi
:= 0;
1489 {$IF DEFINED(D2F_DEBUG)}
1490 e_WriteLog(Format('GUN TRACE: (%d,%d) to (%d,%d)', [x
, y
, x2
, y2
]), TMsgType
.Notify
);
1491 stt
:= getTimeMicro();
1494 wallHitFlag
:= (g_Map_traceToNearestWall(x
, y
, x2
, y2
, @wallHitX
, @wallHitY
) <> nil);
1499 wallDistSq
:= distanceSq(x
, y
, wallHitX
, wallHitY
);
1507 if playerPossibleHit() then exit
; // instant hit
1510 //g_Mons_AlongLine(x, y, x2, y2, sqchecker);
1512 it
:= monsGrid
.forEachAlongLine(x
, y
, x2
, y2
, -1);
1513 for mit
in it
do sqchecker(mit
^);
1516 // here, we collected all monsters and players in `wgunHitHeap` and `wgunHitTime`
1517 // also, if `wallWasHit` is `true`, then `wallHitX` and `wallHitY` contains spark coords
1518 while (wgunHitHeap
.count
> 0) do
1520 // has some entities to check, do it
1521 i
:= wgunHitHeap
.front
;
1522 wgunHitHeap
.popFront();
1524 xe
:= wgunHitTime
[i
].x
;
1525 ye
:= wgunHitTime
[i
].y
;
1526 // check if it is not behind the wall
1527 if (wgunHitTime
[i
].mon
<> nil) then
1529 didHit
:= doMonsterHit(wgunHitTime
[i
].mon
, xe
, ye
);
1533 didHit
:= doPlayerHit(wgunHitTime
[i
].plridx
, xe
, ye
);
1537 // need new coords for trigger
1540 wallHitFlag
:= false; // no sparks
1548 {$IF DEFINED(D2F_DEBUG)}
1549 stt
:= getTimeMicro()-stt
;
1550 e_WriteLog(Format('*** new trace time: %u microseconds', [LongWord(stt
)]), TMsgType
.Notify
);
1553 g_GFX_Spark(wallHitX
, wallHitY
, 2+Random(2), 180+a
, 0, 0);
1555 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Effect(wallHitX
, wallHitY
, 180+a
, NET_GFX_SPARK
);
1559 {$IF DEFINED(D2F_DEBUG)}
1560 stt
:= getTimeMicro()-stt
;
1561 e_WriteLog(Format('*** new trace time: %u microseconds', [LongWord(stt
)]), TMsgType
.Notify
);
1565 if CheckTrigger
and g_Game_IsServer
then g_Triggers_PressL(X
, Y
, wallHitX
, wallHitY
, SpawnerUID
, ACTIVATE_SHOT
);
1569 procedure g_Weapon_punch(x
, y
: Integer; d
, SpawnerUID
: Word);
1577 obj
.rect
.Width
:= 39;
1578 obj
.rect
.Height
:= 52;
1584 if g_Weapon_Hit(@obj
, d
, SpawnerUID
, HIT_SOME
) <> 0 then
1585 g_Sound_PlayExAt('SOUND_WEAPON_HITPUNCH', x
, y
)
1587 g_Sound_PlayExAt('SOUND_WEAPON_MISSPUNCH', x
, y
);
1590 function g_Weapon_chainsaw(x
, y
: Integer; d
, SpawnerUID
: Word): Integer;
1598 obj
.rect
.Width
:= 32;
1599 obj
.rect
.Height
:= 52;
1605 Result
:= g_Weapon_Hit(@obj
, d
, SpawnerUID
, HIT_SOME
);
1608 procedure g_Weapon_rocket(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1;
1609 Silent
: Boolean = False; compat
: Boolean = true);
1615 find_id
:= FindShot()
1619 if Integer(find_id
) >= High(Shots
) then
1620 SetLength(Shots
, find_id
+ 64)
1623 with Shots
[find_id
] do
1627 Obj
.Rect
.Width
:= SHOT_ROCKETLAUNCHER_WIDTH
;
1628 Obj
.Rect
.Height
:= SHOT_ROCKETLAUNCHER_HEIGHT
;
1631 dx
:= IfThen(xd
> x
, -Obj
.Rect
.Width
, 0)
1633 dx
:= -(Obj
.Rect
.Width
div 2);
1634 dy
:= -(Obj
.Rect
.Height
div 2);
1636 ShotType
:= WEAPON_ROCKETLAUNCHER
;
1637 throw(find_id
, x
+dx
, y
+dy
, xd
+dx
, yd
+dy
, 12);
1643 Shots
[find_id
].SpawnerUID
:= SpawnerUID
;
1646 g_Sound_PlayExAt('SOUND_WEAPON_FIREROCKET', x
, y
);
1649 procedure g_Weapon_revf(x
, y
, xd
, yd
: Integer; SpawnerUID
, TargetUID
: Word;
1650 WID
: Integer = -1; Silent
: Boolean = False);
1656 find_id
:= FindShot()
1660 if Integer(find_id
) >= High(Shots
) then
1661 SetLength(Shots
, find_id
+ 64)
1664 with Shots
[find_id
] do
1668 Obj
.Rect
.Width
:= SHOT_SKELFIRE_WIDTH
;
1669 Obj
.Rect
.Height
:= SHOT_SKELFIRE_HEIGHT
;
1671 dx
:= -(Obj
.Rect
.Width
div 2);
1672 dy
:= -(Obj
.Rect
.Height
div 2);
1674 ShotType
:= WEAPON_SKEL_FIRE
;
1675 throw(find_id
, x
+dx
, y
+dy
, xd
+dx
, yd
+dy
, 12);
1678 target
:= TargetUID
;
1679 Animation
:= TAnimationState
.Create(True, 5, 2); // !!! put values into table
1682 Shots
[find_id
].SpawnerUID
:= SpawnerUID
;
1685 g_Sound_PlayExAt('SOUND_WEAPON_FIREREV', x
, y
);
1688 procedure g_Weapon_plasma(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1;
1689 Silent
: Boolean = False; compat
: Boolean = true);
1695 find_id
:= FindShot()
1699 if Integer(find_id
) >= High(Shots
) then
1700 SetLength(Shots
, find_id
+ 64);
1703 with Shots
[find_id
] do
1707 Obj
.Rect
.Width
:= SHOT_PLASMA_WIDTH
;
1708 Obj
.Rect
.Height
:= SHOT_PLASMA_HEIGHT
;
1711 dx
:= IfThen(xd
> x
, -Obj
.Rect
.Width
, 0)
1713 dx
:= -(Obj
.Rect
.Width
div 2);
1714 dy
:= -(Obj
.Rect
.Height
div 2);
1716 ShotType
:= WEAPON_PLASMA
;
1717 throw(find_id
, x
+dx
, y
+dy
, xd
+dx
, yd
+dy
, 16);
1720 Animation
:= TAnimationState
.Create(True, 5, 2); // !!! put values into table
1723 Shots
[find_id
].SpawnerUID
:= SpawnerUID
;
1726 g_Sound_PlayExAt('SOUND_WEAPON_FIREPLASMA', x
, y
);
1729 procedure g_Weapon_flame(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1;
1730 Silent
: Boolean = False; compat
: Boolean = true);
1736 find_id
:= FindShot()
1740 if Integer(find_id
) >= High(Shots
) then
1741 SetLength(Shots
, find_id
+ 64);
1744 with Shots
[find_id
] do
1748 Obj
.Rect
.Width
:= SHOT_FLAME_WIDTH
;
1749 Obj
.Rect
.Height
:= SHOT_FLAME_HEIGHT
;
1752 dx
:= IfThen(xd
> x
, -Obj
.Rect
.Width
, 0)
1754 dx
:= -(Obj
.Rect
.Width
div 2);
1755 dy
:= -(Obj
.Rect
.Height
div 2);
1757 ShotType
:= WEAPON_FLAMETHROWER
;
1758 throw(find_id
, x
+dx
, y
+dy
, xd
+dx
, yd
+dy
, 16);
1764 Shots
[find_id
].SpawnerUID
:= SpawnerUID
;
1766 // if not Silent then
1767 // g_Sound_PlayExAt('SOUND_WEAPON_FIREPLASMA', x, y);
1770 procedure g_Weapon_ball1(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1;
1771 Silent
: Boolean = False; compat
: Boolean = true);
1777 find_id
:= FindShot()
1781 if Integer(find_id
) >= High(Shots
) then
1782 SetLength(Shots
, find_id
+ 64)
1785 with Shots
[find_id
] do
1789 Obj
.Rect
.Width
:= 16;
1790 Obj
.Rect
.Height
:= 16;
1793 dx
:= IfThen(xd
> x
, -Obj
.Rect
.Width
, 0)
1795 dx
:= -(Obj
.Rect
.Width
div 2);
1796 dy
:= -(Obj
.Rect
.Height
div 2);
1798 ShotType
:= WEAPON_IMP_FIRE
;
1799 throw(find_id
, x
+dx
, y
+dy
, xd
+dx
, yd
+dy
, 16);
1802 Animation
:= TAnimationState
.Create(True, 4, 2); // !!! put values into table
1805 Shots
[find_id
].SpawnerUID
:= SpawnerUID
;
1808 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x
, y
);
1811 procedure g_Weapon_ball2(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1;
1812 Silent
: Boolean = False; compat
: Boolean = true);
1818 find_id
:= FindShot()
1822 if Integer(find_id
) >= High(Shots
) then
1823 SetLength(Shots
, find_id
+ 64)
1826 with Shots
[find_id
] do
1830 Obj
.Rect
.Width
:= 16;
1831 Obj
.Rect
.Height
:= 16;
1834 dx
:= IfThen(xd
> x
, -Obj
.Rect
.Width
, 0)
1836 dx
:= -(Obj
.Rect
.Width
div 2);
1837 dy
:= -(Obj
.Rect
.Height
div 2);
1839 ShotType
:= WEAPON_CACO_FIRE
;
1840 throw(find_id
, x
+dx
, y
+dy
, xd
+dx
, yd
+dy
, 16);
1843 Animation
:= TAnimationState
.Create(True, 4, 2); // !!! put values into table
1846 Shots
[find_id
].SpawnerUID
:= SpawnerUID
;
1849 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x
, y
);
1852 procedure g_Weapon_ball7(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1;
1853 Silent
: Boolean = False; compat
: Boolean = true);
1859 find_id
:= FindShot()
1863 if Integer(find_id
) >= High(Shots
) then
1864 SetLength(Shots
, find_id
+ 64)
1867 with Shots
[find_id
] do
1871 Obj
.Rect
.Width
:= 32;
1872 Obj
.Rect
.Height
:= 16;
1875 dx
:= IfThen(xd
> x
, -Obj
.Rect
.Width
, 0)
1877 dx
:= -(Obj
.Rect
.Width
div 2);
1878 dy
:= -(Obj
.Rect
.Height
div 2);
1880 ShotType
:= WEAPON_BARON_FIRE
;
1881 throw(find_id
, x
+dx
, y
+dy
, xd
+dx
, yd
+dy
, 16);
1884 Animation
:= TAnimationState
.Create(True, 4, 2); // !!! put values into table
1887 Shots
[find_id
].SpawnerUID
:= SpawnerUID
;
1890 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x
, y
);
1893 procedure g_Weapon_aplasma(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1;
1894 Silent
: Boolean = False; compat
: Boolean = true);
1900 find_id
:= FindShot()
1904 if Integer(find_id
) >= High(Shots
) then
1905 SetLength(Shots
, find_id
+ 64)
1908 with Shots
[find_id
] do
1912 Obj
.Rect
.Width
:= 16;
1913 Obj
.Rect
.Height
:= 16;
1916 dx
:= IfThen(xd
> x
, -Obj
.Rect
.Width
, 0)
1918 dx
:= -(Obj
.Rect
.Width
div 2);
1919 dy
:= -(Obj
.Rect
.Height
div 2);
1921 ShotType
:= WEAPON_BSP_FIRE
;
1922 throw(find_id
, x
+dx
, y
+dy
, xd
+dx
, yd
+dy
, 16);
1926 Animation
:= TAnimationState
.Create(True, 4, 2); // !!! put values into table
1929 Shots
[find_id
].SpawnerUID
:= SpawnerUID
;
1932 g_Sound_PlayExAt('SOUND_WEAPON_FIREPLASMA', x
, y
);
1935 procedure g_Weapon_manfire(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1;
1936 Silent
: Boolean = False; compat
: Boolean = true);
1942 find_id
:= FindShot()
1946 if Integer(find_id
) >= High(Shots
) then
1947 SetLength(Shots
, find_id
+ 64)
1950 with Shots
[find_id
] do
1954 Obj
.Rect
.Width
:= 32;
1955 Obj
.Rect
.Height
:= 32;
1958 dx
:= IfThen(xd
> x
, -Obj
.Rect
.Width
, 0)
1960 dx
:= -(Obj
.Rect
.Width
div 2);
1961 dy
:= -(Obj
.Rect
.Height
div 2);
1963 ShotType
:= WEAPON_MANCUB_FIRE
;
1964 throw(find_id
, x
+dx
, y
+dy
, xd
+dx
, yd
+dy
, 16);
1968 Animation
:= TAnimationState
.Create(True, 4, 2); // !!! put values into table
1971 Shots
[find_id
].SpawnerUID
:= SpawnerUID
;
1974 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x
, y
);
1977 procedure g_Weapon_bfgshot(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1;
1978 Silent
: Boolean = False; compat
: Boolean = true);
1984 find_id
:= FindShot()
1988 if Integer(find_id
) >= High(Shots
) then
1989 SetLength(Shots
, find_id
+ 64)
1992 with Shots
[find_id
] do
1996 Obj
.Rect
.Width
:= SHOT_BFG_WIDTH
;
1997 Obj
.Rect
.Height
:= SHOT_BFG_HEIGHT
;
2000 dx
:= IfThen(xd
> x
, -Obj
.Rect
.Width
, 0)
2002 dx
:= -(Obj
.Rect
.Width
div 2);
2003 dy
:= -(Obj
.Rect
.Height
div 2);
2005 ShotType
:= WEAPON_BFG
;
2006 throw(find_id
, x
+dx
, y
+dy
, xd
+dx
, yd
+dy
, 16);
2009 Animation
:= TAnimationState
.Create(True, 6, 2); // !!! put values into table
2012 Shots
[find_id
].SpawnerUID
:= SpawnerUID
;
2015 g_Sound_PlayExAt('SOUND_WEAPON_FIREBFG', x
, y
);
2018 procedure g_Weapon_bfghit(x
, y
: Integer);
2021 g_GFX_QueueEffect(R_GFX_BFG_HIT
, x
- 32, y
- 32);
2025 procedure g_Weapon_pistol(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word;
2026 Silent
: Boolean = False);
2029 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', x
, y
);
2031 g_Weapon_gun(x
, y
, xd
, yd
, 1, 3, SpawnerUID
, True);
2032 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
] then
2034 if ABS(x
-xd
) >= ABS(y
-yd
) then
2036 g_Weapon_gun(x
, y
+1, xd
, yd
+1, 1, 3, SpawnerUID
, False);
2037 g_Weapon_gun(x
, y
-1, xd
, yd
-1, 1, 2, SpawnerUID
, False);
2041 g_Weapon_gun(x
+1, y
, xd
+1, yd
, 1, 3, SpawnerUID
, False);
2042 g_Weapon_gun(x
-1, y
, xd
-1, yd
, 1, 2, SpawnerUID
, False);
2047 procedure g_Weapon_mgun(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word;
2048 Silent
: Boolean = False);
2051 if gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', x
, y
);
2053 g_Weapon_gun(x
, y
, xd
, yd
, 1, 3, SpawnerUID
, True);
2054 if (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) and
2055 (g_GetUIDType(SpawnerUID
) = UID_PLAYER
) then
2057 if ABS(x
-xd
) >= ABS(y
-yd
) then
2059 g_Weapon_gun(x
, y
+1, xd
, yd
+1, 1, 2, SpawnerUID
, False);
2060 g_Weapon_gun(x
, y
-1, xd
, yd
-1, 1, 2, SpawnerUID
, False);
2064 g_Weapon_gun(x
+1, y
, xd
+1, yd
, 1, 2, SpawnerUID
, False);
2065 g_Weapon_gun(x
-1, y
, xd
-1, yd
, 1, 2, SpawnerUID
, False);
2070 procedure g_Weapon_shotgun(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word;
2071 Silent
: Boolean = False);
2076 if gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', x
, y
);
2081 if ABS(x
-xd
) >= ABS(y
-yd
) then j
:= Random(17) - 8 else k
:= Random(17) - 8; // -8 .. 8
2082 g_Weapon_gun(x
+k
, y
+j
, xd
+k
, yd
+j
, IfThen(i
mod 2 <> 0, 1, 0), 3, SpawnerUID
, i
=0);
2086 procedure g_Weapon_dshotgun(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word;
2087 Silent
: Boolean = False);
2089 a
, i
, j
, k
: Integer;
2092 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', x
, y
);
2094 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
] then a
:= 25 else a
:= 20;
2098 if ABS(x
-xd
) >= ABS(y
-yd
) then j
:= Random(41) - 20 else k
:= Random(41) - 20; // -20 .. 20
2099 g_Weapon_gun(x
+k
, y
+j
, xd
+k
, yd
+j
, IfThen(i
mod 3 <> 0, 0, 1), 3, SpawnerUID
, i
=0);
2103 procedure g_Weapon_PreUpdate();
2107 if Shots
= nil then Exit
;
2108 for i
:= 0 to High(Shots
) do
2109 if Shots
[i
].ShotType
<> 0 then
2111 Shots
[i
].Obj
.oldX
:= Shots
[i
].Obj
.X
;
2112 Shots
[i
].Obj
.oldY
:= Shots
[i
].Obj
.Y
;
2116 procedure g_Weapon_Update();
2118 i
, a
, h
, cx
, cy
, oldvx
, oldvy
, tf
: Integer;
2125 var tcx
, tcy
: Integer;
2131 for i
:= 0 to High(Shots
) do
2133 if Shots
[i
].ShotType
= 0 then
2140 Timeout
:= Timeout
- 1;
2143 // Àêòèâèðîâàòü òðèããåðû ïî ïóòè (êðîìå óæå àêòèâèðîâàííûõ):
2144 if (Stopped
= 0) and g_Game_IsServer
then
2145 t
:= g_Triggers_PressR(Obj
.X
, Obj
.Y
, Obj
.Rect
.Width
, Obj
.Rect
.Height
,
2146 SpawnerUID
, ACTIVATE_SHOT
, triggers
)
2152 // Ïîïîëíÿåì ñïèñîê àêòèâèðîâàííûõ òðèããåðîâ:
2153 if triggers
= nil then
2160 if not InDWArray(t
[a
], triggers
) then
2162 SetLength(triggers
, Length(triggers
)+1);
2163 triggers
[High(triggers
)] := t
[a
];
2168 // Àíèìàöèÿ ñíàðÿäà:
2169 if Animation
<> nil then
2173 spl
:= (ShotType
<> WEAPON_PLASMA
) and
2174 (ShotType
<> WEAPON_BFG
) and
2175 (ShotType
<> WEAPON_BSP_FIRE
) and
2176 (ShotType
<> WEAPON_FLAMETHROWER
);
2180 st
:= g_Obj_Move_Projectile(@Obj
, False, spl
);
2186 positionChanged(); // this updates spatial accelerators
2188 if WordBool(st
and MOVE_FALLOUT
) or (Obj
.X
< -1000) or
2189 (Obj
.X
> gMapInfo
.Width
+1000) or (Obj
.Y
< -1000) then
2191 // Íà êëèåíòå ñêîðåå âñåãî è òàê óæå âûïàë.
2197 cx
:= Obj
.X
+ (Obj
.Rect
.Width
div 2);
2198 cy
:= Obj
.Y
+ (Obj
.Rect
.Height
div 2);
2201 WEAPON_ROCKETLAUNCHER
, WEAPON_SKEL_FIRE
: // Ðàêåòû è ñíàðÿäû Ñêåëåòà
2203 // Âûëåòåëà èç âîäû:
2204 if WordBool(st
and MOVE_HITAIR
) then
2205 g_Obj_SetSpeed(@Obj
, 12);
2207 // Â âîäå øëåéô - ïóçûðè, â âîçäóõå øëåéô - äûì:
2208 if WordBool(st
and MOVE_INWATER
) then
2211 g_GFX_Bubbles(cx
, cy
, 1+Random(3), 16, 16);
2214 then g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', cx
, cy
)
2215 else g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', cx
, cy
);
2220 g_GFX_QueueEffect(R_GFX_SMOKE_TRANS
, Obj
.X
-14+Random(9), cy
-20+Random(9));
2224 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2225 if WordBool(st
and (MOVE_HITWALL
or MOVE_HITLAND
or MOVE_HITCEIL
)) or
2226 (g_Weapon_Hit(@Obj
, 10, SpawnerUID
, HIT_SOME
, False) <> 0) or
2232 g_Weapon_Explode(cx
, cy
, 60, SpawnerUID
);
2234 if ShotType
= WEAPON_SKEL_FIRE
then
2235 begin // Âçðûâ ñíàðÿäà Ñêåëåòà
2237 g_GFX_QueueEffect(R_GFX_EXPLODE_SKELFIRE
, Obj
.X
+ 32 - 58, Obj
.Y
+ 8 - 36);
2238 g_DynLightExplosion((Obj
.X
+32), (Obj
.Y
+8), 64, 1, 0, 0);
2242 begin // Âçðûâ Ðàêåòû
2244 g_GFX_QueueEffect(R_GFX_EXPLODE_ROCKET
, cx
- 64, cy
- 64);
2245 g_DynLightExplosion(cx
, cy
, 64, 1, 0, 0);
2249 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', Obj
.X
, Obj
.Y
);
2254 if ShotType
= WEAPON_SKEL_FIRE
then
2255 begin // Ñàìîíàâîäêà ñíàðÿäà Ñêåëåòà:
2256 if GetPos(target
, @o
) then
2257 throw(i
, Obj
.X
, Obj
.Y
,
2258 o
.X
+o
.Rect
.X
+(o
.Rect
.Width
div 2)+o
.Vel
.X
+o
.Accel
.X
,
2259 o
.Y
+o
.Rect
.Y
+(o
.Rect
.Height
div 2)+o
.Vel
.Y
+o
.Accel
.Y
,
2264 WEAPON_PLASMA
, WEAPON_BSP_FIRE
: // Ïëàçìà, ïëàçìà Àðàõíàòðîíà
2266 // Ïîïàëà â âîäó - ýëåêòðîøîê ïî âîäå:
2267 if WordBool(st
and (MOVE_INWATER
or MOVE_HITWATER
)) then
2269 g_Sound_PlayExAt('SOUND_WEAPON_PLASMAWATER', Obj
.X
, Obj
.Y
);
2270 if g_Game_IsServer
then CheckTrap(i
, 10, HIT_ELECTRO
);
2276 if (ShotType
= WEAPON_PLASMA
) and
2277 (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) then
2282 if ShotType
= WEAPON_BSP_FIRE
then
2285 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2286 if WordBool(st
and (MOVE_HITWALL
or MOVE_HITLAND
or MOVE_HITCEIL
)) or
2287 (g_Weapon_Hit(@Obj
, a
, SpawnerUID
, HIT_SOME
, False) <> 0) or
2291 if ShotType
= WEAPON_PLASMA
then
2292 g_GFX_QueueEffect(R_GFX_EXPLODE_PLASMA
, cx
- 16, cy
- 16)
2294 g_GFX_QueueEffect(R_GFX_EXPLODE_BSPFIRE
, cx
- 16, cy
- 16);
2295 g_DynLightExplosion(cx
, cy
, 32, 0, 0.5, 0.5);
2297 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEPLASMA', Obj
.X
, Obj
.Y
);
2302 WEAPON_FLAMETHROWER
: // Îãíåìåò
2304 // Ñî âðåìåíåì óìèðàåò
2305 if (Timeout
< 1) then
2311 if WordBool(st
and (MOVE_HITWATER
or MOVE_INWATER
)) then
2313 if WordBool(st
and MOVE_HITWATER
) then
2318 g_GFX_QueueEffect(R_GFX_SMOKE
, cx
-4+tcx
-(R_GFX_SMOKE_WIDTH
div 2), cy
-4+tcy
-(R_GFX_SMOKE_HEIGHT
div 2));
2324 g_GFX_Bubbles(cx
, cy
, 1+Random(3), 16, 16);
2327 then g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', cx
, cy
)
2328 else g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', cx
, cy
);
2336 Obj
.Accel
.Y
:= Obj
.Accel
.Y
+ 1;
2337 // Ïîïàëè â ñòåíó èëè â âîäó:
2338 if WordBool(st
and (MOVE_HITWALL
or MOVE_HITLAND
or MOVE_HITCEIL
or MOVE_HITWATER
)) then
2344 if WordBool(st
and MOVE_HITWALL
) then
2345 Stopped
:= MOVE_HITWALL
2346 else if WordBool(st
and MOVE_HITLAND
) then
2347 Stopped
:= MOVE_HITLAND
2348 else if WordBool(st
and MOVE_HITCEIL
) then
2349 Stopped
:= MOVE_HITCEIL
;
2352 a
:= IfThen(Stopped
= 0, 10, 1);
2353 // Åñëè â êîãî-òî ïîïàëè
2354 if g_Weapon_Hit(@Obj
, a
, SpawnerUID
, HIT_FLAME
, False) <> 0 then
2356 // HIT_FLAME ñàì ïîäîææåò
2357 // Åñëè â ïîëåòå ïîïàëè, èñ÷åçàåì
2367 if (gTime
mod LongWord(tf
) = 0) then
2371 MOVE_HITWALL
: begin tcx
:= cx
-4+Random(8); tcy
:= cy
-12+Random(24); end;
2372 MOVE_HITLAND
: begin tcx
:= cx
-12+Random(24); tcy
:= cy
-10+Random(8); end;
2373 MOVE_HITCEIL
: begin tcx
:= cx
-12+Random(24); tcy
:= cy
+6+Random(8); end;
2374 else begin tcx
:= cx
-4+Random(8); tcy
:= cy
-4+Random(8); end;
2376 g_GFX_QueueEffect(R_GFX_FLAME_RAND
, tcx
- (R_GFX_FLAME_WIDTH
div 2), tcy
- (R_GFX_FLAME_HEIGHT
div 2));
2377 //g_DynLightExplosion(tcx, tcy, 1, 1, 0.8, 0.3);
2384 // Ïîïàëà â âîäó - ýëåêòðîøîê ïî âîäå:
2385 if WordBool(st
and (MOVE_INWATER
or MOVE_HITWATER
)) then
2387 g_Sound_PlayExAt('SOUND_WEAPON_BFGWATER', Obj
.X
, Obj
.Y
);
2388 if g_Game_IsServer
then CheckTrap(i
, 1000, HIT_ELECTRO
);
2393 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2394 if WordBool(st
and (MOVE_HITWALL
or MOVE_HITLAND
or MOVE_HITCEIL
)) or
2395 (g_Weapon_Hit(@Obj
, SHOT_BFG_DAMAGE
, SpawnerUID
, HIT_BFG
, False) <> 0) or
2399 if g_Game_IsServer
then g_Weapon_BFG9000(cx
, cy
, SpawnerUID
);
2401 g_GFX_QueueEffect(R_GFX_EXPLODE_BFG
, cx
- 64, cy
- 64);
2402 g_DynLightExplosion(cx
, cy
, 96, 0, 1, 0);
2404 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', Obj
.X
, Obj
.Y
);
2409 WEAPON_IMP_FIRE
, WEAPON_CACO_FIRE
, WEAPON_BARON_FIRE
: // Âûñòðåëû Áåñà, Êàêîäåìîíà Ðûöàðÿ/Áàðîíà àäà
2412 if WordBool(st
and MOVE_HITAIR
) then
2413 g_Obj_SetSpeed(@Obj
, 16);
2416 if ShotType
= WEAPON_IMP_FIRE
then
2419 if ShotType
= WEAPON_CACO_FIRE
then
2424 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2425 if WordBool(st
and (MOVE_HITWALL
or MOVE_HITLAND
or MOVE_HITCEIL
)) or
2426 (g_Weapon_Hit(@Obj
, a
, SpawnerUID
, HIT_SOME
) <> 0) or
2431 WEAPON_IMP_FIRE
: g_GFX_QueueEffect(R_GFX_EXPLODE_IMPFIRE
, cx
- 32, cy
- 32);
2432 WEAPON_CACO_FIRE
: g_GFX_QueueEffect(R_GFX_EXPLODE_CACOFIRE
, cx
- 32, cy
- 32);
2433 WEAPON_BARON_FIRE
: g_GFX_QueueEffect(R_GFX_EXPLODE_BARONFIRE
, cx
- 32, cy
- 32);
2436 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj
.X
, Obj
.Y
);
2441 WEAPON_MANCUB_FIRE
: // Âûñòðåë Ìàíêóáóñà
2444 if WordBool(st
and MOVE_HITAIR
) then
2445 g_Obj_SetSpeed(@Obj
, 16);
2447 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2448 if WordBool(st
and (MOVE_HITWALL
or MOVE_HITLAND
or MOVE_HITCEIL
)) or
2449 (g_Weapon_Hit(@Obj
, 40, SpawnerUID
, HIT_SOME
, False) <> 0) or
2454 g_GFX_QueueEffect(R_GFX_EXPLODE_ROCKET
, cx
- 64, cy
- 64);
2456 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj
.X
, Obj
.Y
);
2460 end; // case ShotType of...
2462 // Åñëè ñíàðÿäà óæå íåò, óäàëÿåì àíèìàöèþ:
2463 if (ShotType
= 0) then
2465 if gGameSettings
.GameType
= GT_SERVER
then
2466 MH_SEND_DeleteShot(i
, Obj
.X
, Obj
.Y
, Loud
);
2467 if Animation
<> nil then
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 // Óñòàíîâêà òåêñòóðû èëè àíèìàöèè
2578 Shots
[i
].Animation
:= nil;
2580 case Shots
[i
].ShotType
of
2581 WEAPON_ROCKETLAUNCHER
, WEAPON_SKEL_FIRE
:
2586 Shots
[i
].Animation
:= TAnimationState
.Create(True, 5, 2); // !!! put values into table
2590 Shots
[i
].Animation
:= TAnimationState
.Create(True, 6, 2); // !!! put values into table
2594 Shots
[i
].Animation
:= TAnimationState
.Create(True, 4, 2); // !!! put values into table
2598 Shots
[i
].Animation
:= TAnimationState
.Create(True, 4, 2); // !!! put values into table
2602 Shots
[i
].Animation
:= TAnimationState
.Create(True, 4, 2); // !!! put values into table
2606 Shots
[i
].Animation
:= TAnimationState
.Create(True, 4, 2); // !!! put values into table
2610 Shots
[i
].Animation
:= TAnimationState
.Create(True, 4, 2); // !!! put values into table
2616 procedure g_Weapon_DestroyShot(I
: Integer; X
, Y
: Integer; Loud
: Boolean = True);
2618 var cx
, cy
: Integer;
2623 if (I
> High(Shots
)) or (I
< 0) then Exit
;
2627 if ShotType
= 0 then Exit
;
2631 cx
:= Obj
.X
+ (Obj
.Rect
.Width
div 2);
2632 cy
:= Obj
.Y
+ (Obj
.Rect
.Height
div 2);
2636 WEAPON_ROCKETLAUNCHER
, WEAPON_SKEL_FIRE
: // Ðàêåòû è ñíàðÿäû Ñêåëåòà
2641 if ShotType
= WEAPON_SKEL_FIRE
then
2642 g_GFX_QueueEffect(R_GFX_EXPLODE_SKELFIRE
, (Obj
.X
+ 32) - 32, (Obj
.Y
+ 8) - 32)
2644 g_GFX_QueueEffect(R_GFX_EXPLODE_ROCKET
, cx
- 64, cy
- 64);
2646 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', Obj
.X
, Obj
.Y
);
2650 WEAPON_PLASMA
, WEAPON_BSP_FIRE
: // Ïëàçìà, ïëàçìà Àðàõíàòðîíà
2655 if ShotType
= WEAPON_PLASMA
then
2656 g_GFX_QueueEffect(R_GFX_EXPLODE_PLASMA
, cx
- 16, cy
- 16)
2658 g_GFX_QueueEffect(R_GFX_EXPLODE_BSPFIRE
, cx
- 16, cy
- 16);
2660 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEPLASMA', Obj
.X
, Obj
.Y
);
2667 g_GFX_QueueEffect(R_GFX_EXPLODE_BFG
, cx
- 64, cy
- 64);
2669 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', Obj
.X
, Obj
.Y
);
2672 WEAPON_IMP_FIRE
, WEAPON_CACO_FIRE
, WEAPON_BARON_FIRE
: // Âûñòðåëû Áåñà, Êàêîäåìîíà Ðûöàðÿ/Áàðîíà àäà
2678 WEAPON_IMP_FIRE
: g_GFX_QueueEffect(R_GFX_EXPLODE_IMPFIRE
, cx
- 32, cy
- 32);
2679 WEAPON_CACO_FIRE
: g_GFX_QueueEffect(R_GFX_EXPLODE_CACOFIRE
, cx
- 32, cy
- 32);
2680 WEAPON_BARON_FIRE
: g_GFX_QueueEffect(R_GFX_EXPLODE_BARONFIRE
, cx
- 32, cy
- 32);
2683 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj
.X
, Obj
.Y
);
2687 WEAPON_MANCUB_FIRE
: // Âûñòðåë Ìàíêóáóñà
2690 g_GFX_QueueEffect(R_GFX_EXPLODE_ROCKET
, cx
- 64, cy
- 64);
2692 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj
.X
, Obj
.Y
);
2694 end; // case ShotType of...
2702 procedure g_Weapon_AddDynLights();
2706 if Shots
= nil then Exit
;
2707 for i
:= 0 to High(Shots
) do
2709 if Shots
[i
].ShotType
= 0 then continue
;
2710 if (Shots
[i
].ShotType
= WEAPON_ROCKETLAUNCHER
) or
2711 (Shots
[i
].ShotType
= WEAPON_BARON_FIRE
) or
2712 (Shots
[i
].ShotType
= WEAPON_MANCUB_FIRE
) or
2713 (Shots
[i
].ShotType
= WEAPON_SKEL_FIRE
) or
2714 (Shots
[i
].ShotType
= WEAPON_IMP_FIRE
) or
2715 (Shots
[i
].ShotType
= WEAPON_CACO_FIRE
) or
2716 (Shots
[i
].ShotType
= WEAPON_MANCUB_FIRE
) or
2717 (Shots
[i
].ShotType
= WEAPON_BSP_FIRE
) or
2718 (Shots
[i
].ShotType
= WEAPON_PLASMA
) or
2719 (Shots
[i
].ShotType
= WEAPON_BFG
) or
2720 (Shots
[i
].ShotType
= WEAPON_FLAMETHROWER
) or
2723 if (Shots
[i
].ShotType
= WEAPON_PLASMA
) then
2724 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)
2725 else if (Shots
[i
].ShotType
= WEAPON_BFG
) then
2726 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)
2727 else if (Shots
[i
].ShotType
= WEAPON_FLAMETHROWER
) then
2728 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)
2730 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);
2736 procedure TShot
.positionChanged (); begin end;