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;
114 Math
, g_map
, g_player
, g_gfx
, g_sound
, g_panel
,
115 g_console
, g_options
, g_game
,
116 g_triggers
, MAPDEF
, e_log
, g_monsters
, g_saveload
,
117 g_language
, g_netmsg
, g_grid
,
118 geom
, binheap
, hashtable
, utils
, xstreams
;
128 SHOT_ROCKETLAUNCHER_WIDTH
= 14;
129 SHOT_ROCKETLAUNCHER_HEIGHT
= 14;
131 SHOT_SKELFIRE_WIDTH
= 14;
132 SHOT_SKELFIRE_HEIGHT
= 14;
134 SHOT_PLASMA_WIDTH
= 16;
135 SHOT_PLASMA_HEIGHT
= 16;
138 SHOT_BFG_HEIGHT
= 32;
139 SHOT_BFG_DAMAGE
= 100;
140 SHOT_BFG_RADIUS
= 256;
142 SHOT_FLAME_WIDTH
= 4;
143 SHOT_FLAME_HEIGHT
= 4;
144 SHOT_FLAME_LIFETIME
= 180;
146 SHOT_SIGNATURE
= $544F4853; // 'SHOT'
149 PHitTime
= ^THitTime
;
153 plridx
: Integer; // if mon=nil
157 TBinHeapKeyHitTime
= class
159 class function less (const a
, b
: Integer): Boolean; inline;
162 // indicies in `wgunHitTime` array
163 TBinaryHeapHitTimes
= specialize TBinaryHeapBase
<Integer, TBinHeapKeyHitTime
>;
166 WaterMap
: array of array of DWORD
= nil;
167 //wgunMonHash: THashIntInt = nil;
168 wgunHitHeap
: TBinaryHeapHitTimes
= nil;
169 wgunHitTime
: array of THitTime
= nil;
170 wgunHitTimeUsed
: Integer = 0;
173 class function TBinHeapKeyHitTime
.less (const a
, b
: Integer): Boolean;
177 hta
:= @wgunHitTime
[a
];
178 htb
:= @wgunHitTime
[b
];
179 if (hta
.distSq
<> htb
.distSq
) then begin result
:= (hta
.distSq
< htb
.distSq
); exit
; end;
180 if (hta
.mon
<> nil) then
183 if (htb
.mon
= nil) then begin result
:= false; exit
; end; // players first
184 result
:= (hta
.mon
.UID
< htb
.mon
.UID
); // why not?
189 if (htb
.mon
<> nil) then begin result
:= true; exit
; end; // players first
190 result
:= (hta
.plridx
< htb
.plridx
); // why not?
195 procedure appendHitTimeMon (adistSq
: Integer; amon
: TMonster
; ax
, ay
: Integer);
197 if (wgunHitTimeUsed
= Length(wgunHitTime
)) then SetLength(wgunHitTime
, wgunHitTimeUsed
+128);
198 with wgunHitTime
[wgunHitTimeUsed
] do
206 wgunHitHeap
.insert(wgunHitTimeUsed
);
207 Inc(wgunHitTimeUsed
);
211 procedure appendHitTimePlr (adistSq
: Integer; aplridx
: Integer; ax
, ay
: Integer);
213 if (wgunHitTimeUsed
= Length(wgunHitTime
)) then SetLength(wgunHitTime
, wgunHitTimeUsed
+128);
214 with wgunHitTime
[wgunHitTimeUsed
] do
222 wgunHitHeap
.insert(wgunHitTimeUsed
);
223 Inc(wgunHitTimeUsed
);
227 function FindShot(): DWORD
;
232 for i
:= 0 to High(Shots
) do
233 if Shots
[i
].ShotType
= 0 then
236 LastShotID
:= Result
;
242 SetLength(Shots
, 128);
247 Result
:= High(Shots
) + 1;
248 SetLength(Shots
, Length(Shots
) + 128);
250 LastShotID
:= Result
;
253 procedure CreateWaterMap();
255 WaterArray
: Array of TWaterPanel
;
262 SetLength(WaterArray
, Length(gWater
));
264 for a
:= 0 to High(gWater
) do
266 WaterArray
[a
].X
:= gWater
[a
].X
;
267 WaterArray
[a
].Y
:= gWater
[a
].Y
;
268 WaterArray
[a
].Width
:= gWater
[a
].Width
;
269 WaterArray
[a
].Height
:= gWater
[a
].Height
;
270 WaterArray
[a
].Active
:= True;
273 g_Game_SetLoadingText(_lc
[I_LOAD_WATER_MAP
], High(WaterArray
), False);
275 for a
:= 0 to High(WaterArray
) do
276 if WaterArray
[a
].Active
then
278 WaterArray
[a
].Active
:= False;
279 m
:= Length(WaterMap
);
280 SetLength(WaterMap
, m
+1);
281 SetLength(WaterMap
[m
], 1);
288 for b
:= 0 to High(WaterArray
) do
289 if WaterArray
[b
].Active
then
290 for c
:= 0 to High(WaterMap
[m
]) do
291 if g_CollideAround(WaterArray
[b
].X
,
294 WaterArray
[b
].Height
,
295 WaterArray
[WaterMap
[m
][c
]].X
,
296 WaterArray
[WaterMap
[m
][c
]].Y
,
297 WaterArray
[WaterMap
[m
][c
]].Width
,
298 WaterArray
[WaterMap
[m
][c
]].Height
) then
300 WaterArray
[b
].Active
:= False;
301 SetLength(WaterMap
[m
],
302 Length(WaterMap
[m
])+1);
303 WaterMap
[m
][High(WaterMap
[m
])] := b
;
309 g_Game_StepLoading();
317 chkTrap_pl
: array [0..256] of Integer;
318 chkTrap_mn
: array [0..65535] of TMonster
;
320 procedure CheckTrap(ID
: DWORD
; dm
: Integer; t
: Byte);
322 //a, b, c, d, i1, i2: Integer;
323 //chkTrap_pl, chkTrap_mn: WArray;
324 plaCount
: Integer = 0;
325 mnaCount
: Integer = 0;
329 function monsWaterCheck (mon: TMonster): Boolean;
331 result := false; // don't stop
332 if mon.alive and mon.Collide(gWater[WaterMap[a][c]]) and (not InWArray(monidx, chkTrap_mn)) and (i2 < 1023) then //FIXME
335 chkTrap_mn[i2] := monidx;
340 function monsWaterCheck (mon
: TMonster
): Boolean;
342 result
:= false; // don't stop
343 if (mon
.trapCheckFrameId
<> frameId
) then
345 mon
.trapCheckFrameId
:= frameId
;
346 chkTrap_mn
[mnaCount
] := mon
;
352 a
, b
, c
, d
, f
: Integer;
355 if (gWater
= nil) or (WaterMap
= nil) then Exit
;
357 frameId
:= g_Mons_getNewTrapFrameId();
362 //SetLength(chkTrap_pl, 1024);
363 //SetLength(chkTrap_mn, 1024);
364 //for d := 0 to 1023 do chkTrap_pl[d] := $FFFF;
365 //for d := 0 to 1023 do chkTrap_mn[d] := $FFFF;
367 for a
:= 0 to High(WaterMap
) do
369 for b
:= 0 to High(WaterMap
[a
]) do
371 pan
:= gWater
[WaterMap
[a
][b
]];
372 if not g_Obj_Collide(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, @Shots
[ID
].Obj
) then continue
;
374 for c
:= 0 to High(WaterMap
[a
]) do
376 pan
:= gWater
[WaterMap
[a
][c
]];
377 for d
:= 0 to High(gPlayers
) do
379 if (gPlayers
[d
] <> nil) and (gPlayers
[d
].alive
) then
381 if gPlayers
[d
].Collide(pan
) then
384 while (f
< plaCount
) and (chkTrap_pl
[f
] <> d
) do Inc(f
);
385 if (f
= plaCount
) then
387 chkTrap_pl
[plaCount
] := d
;
389 if (plaCount
= Length(chkTrap_pl
)) then break
;
395 //g_Mons_ForEach(monsWaterCheck);
396 g_Mons_ForEachAliveAt(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, monsWaterCheck
);
399 for f
:= 0 to plaCount
-1 do gPlayers
[chkTrap_pl
[f
]].Damage(dm
, Shots
[ID
].SpawnerUID
, 0, 0, t
);
400 for f
:= 0 to mnaCount
-1 do chkTrap_mn
[f
].Damage(dm
, 0, 0, Shots
[ID
].SpawnerUID
, t
);
408 function HitMonster(m
: TMonster
; d
: Integer; vx
, vy
: Integer; SpawnerUID
: Word; t
: Byte): Boolean;
415 tt
:= g_GetUIDType(SpawnerUID
);
416 if tt
= UID_MONSTER
then
418 mon
:= g_Monsters_ByUID(SpawnerUID
);
420 mt
:= g_Monsters_ByUID(SpawnerUID
).MonsterType
427 if m
= nil then Exit
;
428 if m
.UID
= SpawnerUID
then
430 // Ñàì ñåáÿ ìîæåò ðàíèòü òîëüêî ðàêåòîé è òîêîì:
431 if (t
<> HIT_ROCKET
) and (t
<> HIT_ELECTRO
) then
433 // Êèáåð äåìîí è áî÷êà âîîáùå íå ìîãóò ñåáÿ ðàíèòü:
434 if (m
.MonsterType
= MONSTER_CYBER
) or
435 (m
.MonsterType
= MONSTER_BARREL
) then
442 if tt
= UID_MONSTER
then
444 // Lost_Soul íå ìîæåò ðàíèòü Pain_Elemental'à:
445 if (mt
= MONSTER_SOUL
) and (m
.MonsterType
= MONSTER_PAIN
) then
448 // Îáà ìîíñòðà îäíîãî âèäà:
449 if mt
= m
.MonsterType
then
451 MONSTER_IMP
, MONSTER_DEMON
, MONSTER_BARON
, MONSTER_KNIGHT
, MONSTER_CACO
,
452 MONSTER_SOUL
, MONSTER_MANCUB
, MONSTER_SKEL
, MONSTER_FISH
:
453 Exit
; // Ýòè íå áüþò ñâîèõ
457 if g_Game_IsServer
then
459 if (t
<> HIT_FLAME
) or (m
.FFireTime
= 0) or (vx
<> 0) or (vy
<> 0) then
460 Result
:= m
.Damage(d
, vx
, vy
, SpawnerUID
, t
)
462 Result
:= (gLMSRespawn
= LMS_RESPAWN_NONE
); // don't hit monsters when it's warmup time
463 if t
= HIT_FLAME
then
464 m
.CatchFire(SpawnerUID
);
467 Result
:= (gLMSRespawn
= LMS_RESPAWN_NONE
); // don't hit monsters when it's warmup time
471 function HitPlayer (p
: TPlayer
; d
: Integer; vx
, vy
: Integer; SpawnerUID
: Word; t
: Byte): Boolean;
475 // Ñàì ñåáÿ ìîæåò ðàíèòü òîëüêî ðàêåòîé è òîêîì
476 if (p
.UID
= SpawnerUID
) and (t
<> HIT_ROCKET
) and (t
<> HIT_ELECTRO
) then exit
;
478 if g_Game_IsServer
then
480 if (t
<> HIT_FLAME
) or (p
.FFireTime
= 0) or (vx
<> 0) or (vy
<> 0) then p
.Damage(d
, SpawnerUID
, vx
, vy
, t
);
481 if (t
= HIT_FLAME
) then p
.CatchFire(SpawnerUID
);
488 procedure g_Weapon_BFG9000(X
, Y
: Integer; SpawnerUID
: Word);
490 function monsCheck (mon
: TMonster
): Boolean;
492 result
:= false; // don't stop
493 if (mon
.alive
) and (mon
.UID
<> SpawnerUID
) then
497 if (g_PatchLength(X
, Y
, Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2),
498 Obj
.Y
+Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2)) <= SHOT_BFG_RADIUS
) and
499 g_TraceVector(X
, Y
, Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2),
500 Obj
.Y
+Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2)) then
502 if HitMonster(mon
, 50, 0, 0, SpawnerUID
, HIT_SOME
) then mon
.BFGHit();
514 //g_Sound_PlayEx('SOUND_WEAPON_EXPLODEBFG', 255);
518 if gAdvCorpses
and (h
<> -1) then
520 if (gCorpses
[i
] <> nil) and (gCorpses
[i
].State
<> CORPSE_STATE_REMOVEME
) then
522 if (g_PatchLength(X
, Y
, Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2),
523 Obj
.Y
+Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2)) <= SHOT_BFG_RADIUS
) and
524 g_TraceVector(X
, Y
, Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2),
525 Obj
.Y
+Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2)) then
527 Damage(50, SpawnerUID
, 0, 0);
528 g_Weapon_BFGHit(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2),
529 Obj
.Y
+Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2));
533 pl
:= g_Player_Get(SpawnerUID
);
541 if (gPlayers
[i
] <> nil) and (gPlayers
[i
].alive
) and (gPlayers
[i
].UID
<> SpawnerUID
) then
543 if (g_PatchLength(X
, Y
, GameX
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
544 GameY
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)) <= SHOT_BFG_RADIUS
) and
545 g_TraceVector(X
, Y
, GameX
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
546 GameY
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)) then
548 if (st
= TEAM_NONE
) or (st
<> gPlayers
[i
].Team
) then
549 b
:= HitPlayer(gPlayers
[i
], 50, 0, 0, SpawnerUID
, HIT_SOME
)
551 b
:= HitPlayer(gPlayers
[i
], 25, 0, 0, SpawnerUID
, HIT_SOME
);
553 gPlayers
[i
].BFGHit();
557 g_Mons_ForEachAlive(monsCheck
);
560 function g_Weapon_CreateShot(I
: Integer; ShotType
: Byte; Spawner
, TargetUID
: Word; X
, Y
, XV
, YV
: Integer): LongWord;
565 find_id
:= FindShot()
569 if Integer(find_id
) >= High(Shots
) then
570 SetLength(Shots
, find_id
+ 64)
574 WEAPON_ROCKETLAUNCHER
:
576 with Shots
[find_id
] do
580 Obj
.Rect
.Width
:= SHOT_ROCKETLAUNCHER_WIDTH
;
581 Obj
.Rect
.Height
:= SHOT_ROCKETLAUNCHER_HEIGHT
;
585 ShotType
:= WEAPON_ROCKETLAUNCHER
;
591 with Shots
[find_id
] do
595 Obj
.Rect
.Width
:= SHOT_PLASMA_WIDTH
;
596 Obj
.Rect
.Height
:= SHOT_PLASMA_HEIGHT
;
599 ShotType
:= WEAPON_PLASMA
;
600 Animation
:= TAnimationState
.Create(True, 5, 2); // !!! put values into table
606 with Shots
[find_id
] do
610 Obj
.Rect
.Width
:= SHOT_BFG_WIDTH
;
611 Obj
.Rect
.Height
:= SHOT_BFG_HEIGHT
;
614 ShotType
:= WEAPON_BFG
;
615 Animation
:= TAnimationState
.Create(True, 6, 2); // !!! put values into table
621 with Shots
[find_id
] do
625 Obj
.Rect
.Width
:= SHOT_FLAME_WIDTH
;
626 Obj
.Rect
.Height
:= SHOT_FLAME_HEIGHT
;
629 ShotType
:= WEAPON_FLAMETHROWER
;
630 // Animation := TAnimationState.Create(True, 6, 0); // drawed as gfx
636 with Shots
[find_id
] do
640 Obj
.Rect
.Width
:= 16;
641 Obj
.Rect
.Height
:= 16;
644 ShotType
:= WEAPON_IMP_FIRE
;
645 Animation
:= TAnimationState
.Create(True, 4, 2); // !!! put values into table
651 with Shots
[find_id
] do
655 Obj
.Rect
.Width
:= 16;
656 Obj
.Rect
.Height
:= 16;
659 ShotType
:= WEAPON_CACO_FIRE
;
660 Animation
:= TAnimationState
.Create(True, 4, 2); // !!! put values into table
666 with Shots
[find_id
] do
670 Obj
.Rect
.Width
:= 32;
671 Obj
.Rect
.Height
:= 32;
674 ShotType
:= WEAPON_MANCUB_FIRE
;
675 Animation
:= TAnimationState
.Create(True, 4, 2); // !!! put values into table
681 with Shots
[find_id
] do
685 Obj
.Rect
.Width
:= 16;
686 Obj
.Rect
.Height
:= 16;
689 ShotType
:= WEAPON_BARON_FIRE
;
690 Animation
:= TAnimationState
.Create(True, 4, 2); // !!! put values into table
696 with Shots
[find_id
] do
700 Obj
.Rect
.Width
:= 16;
701 Obj
.Rect
.Height
:= 16;
704 ShotType
:= WEAPON_BSP_FIRE
;
705 Animation
:= TAnimationState
.Create(True, 4, 2); // !!! put values into table
711 with Shots
[find_id
] do
715 Obj
.Rect
.Width
:= SHOT_SKELFIRE_WIDTH
;
716 Obj
.Rect
.Height
:= SHOT_SKELFIRE_HEIGHT
;
719 ShotType
:= WEAPON_SKEL_FIRE
;
721 Animation
:= TAnimationState
.Create(True, 5, 2); // !!! put values into table
726 Shots
[find_id
].Obj
.oldX
:= X
;
727 Shots
[find_id
].Obj
.oldY
:= Y
;
728 Shots
[find_id
].Obj
.X
:= X
;
729 Shots
[find_id
].Obj
.Y
:= Y
;
730 Shots
[find_id
].Obj
.Vel
.X
:= XV
;
731 Shots
[find_id
].Obj
.Vel
.Y
:= YV
;
732 Shots
[find_id
].Obj
.Accel
.X
:= 0;
733 Shots
[find_id
].Obj
.Accel
.Y
:= 0;
734 Shots
[find_id
].SpawnerUID
:= Spawner
;
735 if (ShotType
= WEAPON_FLAMETHROWER
) and (XV
= 0) and (YV
= 0) then
736 Shots
[find_id
].Stopped
:= 255
738 Shots
[find_id
].Stopped
:= 0;
742 procedure throw(i
, x
, y
, xd
, yd
, s
: Integer);
749 a
:= Max(Abs(xd
), Abs(yd
));
753 Shots
[i
].Obj
.oldX
:= x
;
754 Shots
[i
].Obj
.oldY
:= y
;
757 Shots
[i
].Obj
.Vel
.X
:= (xd
*s
) div a
;
758 Shots
[i
].Obj
.Vel
.Y
:= (yd
*s
) div a
;
759 Shots
[i
].Obj
.Accel
.X
:= 0;
760 Shots
[i
].Obj
.Accel
.Y
:= 0;
761 Shots
[i
].Stopped
:= 0;
762 if Shots
[i
].ShotType
in [WEAPON_ROCKETLAUNCHER
, WEAPON_BFG
] then
763 Shots
[i
].Timeout
:= 900 // ~25 sec
766 if Shots
[i
].ShotType
= WEAPON_FLAMETHROWER
then
767 Shots
[i
].Timeout
:= SHOT_FLAME_LIFETIME
769 Shots
[i
].Timeout
:= 550; // ~15 sec
773 function g_Weapon_Hit(obj
: PObj
; d
: Integer; SpawnerUID
: Word; t
: Byte; HitCorpses
: Boolean = True): Byte;
777 function PlayerHit(Team
: Byte = 0): Boolean;
788 if (gPlayers
[i
] <> nil) and gPlayers
[i
].alive
and g_Obj_Collide(obj
, @gPlayers
[i
].Obj
) then
791 if (Team
> 0) and (g_GetUIDType(SpawnerUID
) = UID_PLAYER
) then
793 p
:= g_Player_Get(SpawnerUID
);
795 ChkTeam
:= (p
.Team
= gPlayers
[i
].Team
) xor (Team
= 2);
798 if HitPlayer(gPlayers
[i
], d
, obj
^.Vel
.X
, obj
^.Vel
.Y
, SpawnerUID
, t
) then
800 if t
<> HIT_FLAME
then
801 gPlayers
[i
].Push((obj
^.Vel
.X
+obj
^.Accel
.X
)*IfThen(t
= HIT_BFG
, 8, 1) div 4,
802 (obj
^.Vel
.Y
+obj
^.Accel
.Y
)*IfThen(t
= HIT_BFG
, 8, 1) div 4);
804 g_Game_DelayEvent(DE_BFGHIT
, 1000, SpawnerUID
);
812 function monsCheckHit (monidx: Integer; mon: TMonster): Boolean;
814 result := false; // don't stop
815 if mon.alive and g_Obj_Collide(obj, @mon.Obj) then
817 if HitMonster(mon, d, obj^.Vel.X, obj^.Vel.Y, SpawnerUID, t) then
819 if (t <> HIT_FLAME) then
821 mon.Push((obj^.Vel.X+obj^.Accel.X)*IfThen(t = HIT_BFG, 8, 1) div 4,
822 (obj^.Vel.Y+obj^.Accel.Y)*IfThen(t = HIT_BFG, 8, 1) div 4);
830 function monsCheckHit (mon
: TMonster
): Boolean;
832 result
:= false; // don't stop
833 if HitMonster(mon
, d
, obj
.Vel
.X
, obj
.Vel
.Y
, SpawnerUID
, t
) then
835 if (t
<> HIT_FLAME
) then
837 mon
.Push((obj
.Vel
.X
+obj
.Accel
.X
)*IfThen(t
= HIT_BFG
, 8, 1) div 4,
838 (obj
.Vel
.Y
+obj
.Accel
.Y
)*IfThen(t
= HIT_BFG
, 8, 1) div 4);
844 function MonsterHit(): Boolean;
846 //result := g_Mons_ForEach(monsCheckHit);
847 //FIXME: accelerate this!
848 result
:= g_Mons_ForEachAliveAt(obj
.X
+obj
.Rect
.X
, obj
.Y
+obj
.Rect
.Y
, obj
.Rect
.Width
, obj
.Rect
.Height
, monsCheckHit
);
858 if gAdvCorpses
and (h
<> -1) then
860 if (gCorpses
[i
] <> nil) and (gCorpses
[i
].State
<> CORPSE_STATE_REMOVEME
) and
861 g_Obj_Collide(obj
, @gCorpses
[i
].Obj
) then
864 gCorpses
[i
].Damage(d
, SpawnerUID
, (obj
^.Vel
.X
+obj
^.Accel
.X
) div 4,
865 (obj
^.Vel
.Y
+obj
^.Accel
.Y
) div 4);
870 case gGameSettings
.GameMode
of
874 // Ñíà÷àëà áü¸ì ìîíñòðîâ, åñëè åñòü, ïîòîì ïûòàåìñÿ áèòü èãðîêîâ
881 // È â êîíöå èãðîêîâ, íî òîëüêî åñëè ïîëîæåíî
882 // (èëè ñíàðÿä îò ìîíñòðà, èëè friendlyfire, èëè friendly_hit_projectile)
883 if (g_GetUIDType(SpawnerUID
) <> UID_PLAYER
) or
884 LongBool(gGameSettings
.Options
and (GAME_OPTION_TEAMDAMAGE
or GAME_OPTION_TEAMHITPROJECTILE
)) then
897 // Ñíà÷àëà áü¸ì èãðîêîâ, åñëè åñòü, ïîòîì ïûòàåìñÿ áèòü ìîíñòðîâ
914 // Ñíà÷àëà áü¸ì èãðîêîâ êîìàíäû ñîïåðíèêà
928 // È â êîíöå ñâîèõ èãðîêîâ, íî òîëüêî åñëè ïîëîæåíî
929 // (èëè friendlyfire, èëè friendly_hit_projectile)
930 if LongBool(gGameSettings
.Options
and (GAME_OPTION_TEAMDAMAGE
or GAME_OPTION_TEAMHITPROJECTILE
)) then
943 function g_Weapon_HitUID(UID
: Word; d
: Integer; SpawnerUID
: Word; t
: Byte): Boolean;
947 case g_GetUIDType(UID
) of
948 UID_PLAYER
: Result
:= HitPlayer(g_Player_Get(UID
), d
, 0, 0, SpawnerUID
, t
);
949 UID_MONSTER
: Result
:= HitMonster(g_Monsters_ByUID(UID
), d
, 0, 0, SpawnerUID
, t
);
954 function g_Weapon_Explode(X
, Y
: Integer; rad
: Integer; SpawnerUID
: Word): Boolean;
956 r
: Integer; // squared radius
958 function monsExCheck (mon
: TMonster
): Boolean;
962 result
:= false; // don't stop
964 dx
:= mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-X
;
965 dy
:= mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2)-Y
;
967 if dx
> 1000 then dx
:= 1000;
968 if dy
> 1000 then dy
:= 1000;
970 if (dx
*dx
+dy
*dy
< r
) then
972 //m := PointToRect(X, Y, Obj.X+Obj.Rect.X, Obj.Y+Obj.Rect.Y, Obj.Rect.Width, Obj.Rect.Height);
973 //e_WriteLog(Format('explo monster #%d: x=%d; y=%d; rad=%d; dx=%d; dy=%d', [monidx, X, Y, rad, dx, dy]), MSG_NOTIFY);
975 mm
:= Max(abs(dx
), abs(dy
));
976 if mm
= 0 then mm
:= 1;
980 HitMonster(mon
, ((mon
.Obj
.Rect
.Width
div 4)*10*(rad
-mm
)) div rad
, 0, 0, SpawnerUID
, HIT_ROCKET
);
983 mon
.Push((dx
*7) div mm
, (dy
*7) div mm
);
989 i
, h
, dx
, dy
, m
, mm
: Integer;
994 g_Triggers_PressC(X
, Y
, rad
, SpawnerUID
, ACTIVATE_SHOT
);
1002 if (gPlayers
[i
] <> nil) and gPlayers
[i
].alive
then
1005 dx
:= Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)-X
;
1006 dy
:= Obj
.Y
+Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2)-Y
;
1008 if dx
> 1000 then dx
:= 1000;
1009 if dy
> 1000 then dy
:= 1000;
1011 if dx
*dx
+dy
*dy
< r
then
1013 //m := PointToRect(X, Y, GameX+PLAYER_RECT.X, GameY+PLAYER_RECT.Y,
1014 // PLAYER_RECT.Width, PLAYER_RECT.Height);
1016 mm
:= Max(abs(dx
), abs(dy
));
1017 if mm
= 0 then mm
:= 1;
1019 HitPlayer(gPlayers
[i
], (100*(rad
-mm
)) div rad
, (dx
*10) div mm
, (dy
*10) div mm
, SpawnerUID
, HIT_ROCKET
);
1020 gPlayers
[i
].Push((dx
*7) div mm
, (dy
*7) div mm
);
1024 //g_Mons_ForEach(monsExCheck);
1025 g_Mons_ForEachAt(X
-(rad
+32), Y
-(rad
+32), (rad
+32)*2, (rad
+32)*2, monsExCheck
);
1027 h
:= High(gCorpses
);
1029 if gAdvCorpses
and (h
<> -1) then
1031 if (gCorpses
[i
] <> nil) and (gCorpses
[i
].State
<> CORPSE_STATE_REMOVEME
) then
1034 dx
:= Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)-X
;
1035 dy
:= Obj
.Y
+Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2)-Y
;
1037 if dx
> 1000 then dx
:= 1000;
1038 if dy
> 1000 then dy
:= 1000;
1040 if dx
*dx
+dy
*dy
< r
then
1042 m
:= PointToRect(X
, Y
, Obj
.X
+Obj
.Rect
.X
, Obj
.Y
+Obj
.Rect
.Y
,
1043 Obj
.Rect
.Width
, Obj
.Rect
.Height
);
1045 mm
:= Max(abs(dx
), abs(dy
));
1046 if mm
= 0 then mm
:= 1;
1048 Damage(Round(100*(rad
-m
)/rad
), SpawnerUID
, (dx
*10) div mm
, (dy
*10) div mm
);
1054 if gAdvGibs
and (h
<> -1) then
1056 if gGibs
[i
].alive
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
;
1062 if dx
> 1000 then dx
:= 1000;
1063 if dy
> 1000 then dy
:= 1000;
1065 if dx
*dx
+dy
*dy
< r
then
1067 m
:= PointToRect(X
, Y
, Obj
.X
+Obj
.Rect
.X
, Obj
.Y
+Obj
.Rect
.Y
,
1068 Obj
.Rect
.Width
, Obj
.Rect
.Height
);
1069 _angle
:= GetAngle(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2),
1070 Obj
.Y
+Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2), X
, Y
);
1072 g_Obj_PushA(@Obj
, Round(15*(rad
-m
)/rad
), _angle
);
1073 positionChanged(); // this updates spatial accelerators
1078 procedure g_Weapon_Init();
1083 procedure g_Weapon_Free();
1087 if Shots
<> nil then
1089 for i
:= 0 to High(Shots
) do
1090 if Shots
[i
].ShotType
<> 0 then
1091 Shots
[i
].Animation
.Free();
1099 procedure g_Weapon_LoadData();
1101 e_WriteLog('Loading weapons data...', TMsgType
.Notify
);
1103 g_Sound_CreateWADEx('SOUND_WEAPON_HITPUNCH', GameWAD
+':SOUNDS\HITPUNCH');
1104 g_Sound_CreateWADEx('SOUND_WEAPON_MISSPUNCH', GameWAD
+':SOUNDS\MISSPUNCH');
1105 g_Sound_CreateWADEx('SOUND_WEAPON_HITBERSERK', GameWAD
+':SOUNDS\HITBERSERK');
1106 g_Sound_CreateWADEx('SOUND_WEAPON_MISSBERSERK', GameWAD
+':SOUNDS\MISSBERSERK');
1107 g_Sound_CreateWADEx('SOUND_WEAPON_SELECTSAW', GameWAD
+':SOUNDS\SELECTSAW');
1108 g_Sound_CreateWADEx('SOUND_WEAPON_IDLESAW', GameWAD
+':SOUNDS\IDLESAW');
1109 g_Sound_CreateWADEx('SOUND_WEAPON_HITSAW', GameWAD
+':SOUNDS\HITSAW');
1110 g_Sound_CreateWADEx('SOUND_WEAPON_FIRESHOTGUN2', GameWAD
+':SOUNDS\FIRESHOTGUN2');
1111 g_Sound_CreateWADEx('SOUND_WEAPON_FIRESHOTGUN', GameWAD
+':SOUNDS\FIRESHOTGUN');
1112 g_Sound_CreateWADEx('SOUND_WEAPON_FIRESAW', GameWAD
+':SOUNDS\FIRESAW');
1113 g_Sound_CreateWADEx('SOUND_WEAPON_FIREROCKET', GameWAD
+':SOUNDS\FIREROCKET');
1114 g_Sound_CreateWADEx('SOUND_WEAPON_FIREPLASMA', GameWAD
+':SOUNDS\FIREPLASMA');
1115 g_Sound_CreateWADEx('SOUND_WEAPON_FIREPISTOL', GameWAD
+':SOUNDS\FIREPISTOL');
1116 g_Sound_CreateWADEx('SOUND_WEAPON_FIRECGUN', GameWAD
+':SOUNDS\FIRECGUN');
1117 g_Sound_CreateWADEx('SOUND_WEAPON_FIREBFG', GameWAD
+':SOUNDS\FIREBFG');
1118 g_Sound_CreateWADEx('SOUND_FIRE', GameWAD
+':SOUNDS\FIRE');
1119 g_Sound_CreateWADEx('SOUND_IGNITE', GameWAD
+':SOUNDS\IGNITE');
1120 g_Sound_CreateWADEx('SOUND_WEAPON_STARTFIREBFG', GameWAD
+':SOUNDS\STARTFIREBFG');
1121 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEROCKET', GameWAD
+':SOUNDS\EXPLODEROCKET');
1122 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEBFG', GameWAD
+':SOUNDS\EXPLODEBFG');
1123 g_Sound_CreateWADEx('SOUND_WEAPON_BFGWATER', GameWAD
+':SOUNDS\BFGWATER');
1124 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEPLASMA', GameWAD
+':SOUNDS\EXPLODEPLASMA');
1125 g_Sound_CreateWADEx('SOUND_WEAPON_PLASMAWATER', GameWAD
+':SOUNDS\PLASMAWATER');
1126 g_Sound_CreateWADEx('SOUND_WEAPON_FIREBALL', GameWAD
+':SOUNDS\FIREBALL');
1127 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEBALL', GameWAD
+':SOUNDS\EXPLODEBALL');
1128 g_Sound_CreateWADEx('SOUND_WEAPON_FIREREV', GameWAD
+':SOUNDS\FIREREV');
1129 g_Sound_CreateWADEx('SOUND_WEAPON_FLAMEON', GameWAD
+':SOUNDS\STARTFLM');
1130 g_Sound_CreateWADEx('SOUND_WEAPON_FLAMEOFF', GameWAD
+':SOUNDS\STOPFLM');
1131 g_Sound_CreateWADEx('SOUND_WEAPON_FLAMEWORK', GameWAD
+':SOUNDS\WORKFLM');
1132 g_Sound_CreateWADEx('SOUND_PLAYER_JETFLY', GameWAD
+':SOUNDS\WORKJETPACK');
1133 g_Sound_CreateWADEx('SOUND_PLAYER_JETON', GameWAD
+':SOUNDS\STARTJETPACK');
1134 g_Sound_CreateWADEx('SOUND_PLAYER_JETOFF', GameWAD
+':SOUNDS\STOPJETPACK');
1135 g_Sound_CreateWADEx('SOUND_PLAYER_CASING1', GameWAD
+':SOUNDS\CASING1');
1136 g_Sound_CreateWADEx('SOUND_PLAYER_CASING2', GameWAD
+':SOUNDS\CASING2');
1137 g_Sound_CreateWADEx('SOUND_PLAYER_SHELL1', GameWAD
+':SOUNDS\SHELL1');
1138 g_Sound_CreateWADEx('SOUND_PLAYER_SHELL2', GameWAD
+':SOUNDS\SHELL2');
1140 //wgunMonHash := hashNewIntInt();
1141 wgunHitHeap
:= TBinaryHeapHitTimes
.Create();
1144 procedure g_Weapon_FreeData();
1146 e_WriteLog('Releasing weapons data...', TMsgType
.Notify
);
1148 g_Sound_Delete('SOUND_WEAPON_HITPUNCH');
1149 g_Sound_Delete('SOUND_WEAPON_MISSPUNCH');
1150 g_Sound_Delete('SOUND_WEAPON_HITBERSERK');
1151 g_Sound_Delete('SOUND_WEAPON_MISSBERSERK');
1152 g_Sound_Delete('SOUND_WEAPON_SELECTSAW');
1153 g_Sound_Delete('SOUND_WEAPON_IDLESAW');
1154 g_Sound_Delete('SOUND_WEAPON_HITSAW');
1155 g_Sound_Delete('SOUND_WEAPON_FIRESHOTGUN2');
1156 g_Sound_Delete('SOUND_WEAPON_FIRESHOTGUN');
1157 g_Sound_Delete('SOUND_WEAPON_FIRESAW');
1158 g_Sound_Delete('SOUND_WEAPON_FIREROCKET');
1159 g_Sound_Delete('SOUND_WEAPON_FIREPLASMA');
1160 g_Sound_Delete('SOUND_WEAPON_FIREPISTOL');
1161 g_Sound_Delete('SOUND_WEAPON_FIRECGUN');
1162 g_Sound_Delete('SOUND_WEAPON_FIREBFG');
1163 g_Sound_Delete('SOUND_FIRE');
1164 g_Sound_Delete('SOUND_IGNITE');
1165 g_Sound_Delete('SOUND_WEAPON_STARTFIREBFG');
1166 g_Sound_Delete('SOUND_WEAPON_EXPLODEROCKET');
1167 g_Sound_Delete('SOUND_WEAPON_EXPLODEBFG');
1168 g_Sound_Delete('SOUND_WEAPON_BFGWATER');
1169 g_Sound_Delete('SOUND_WEAPON_EXPLODEPLASMA');
1170 g_Sound_Delete('SOUND_WEAPON_PLASMAWATER');
1171 g_Sound_Delete('SOUND_WEAPON_FIREBALL');
1172 g_Sound_Delete('SOUND_WEAPON_EXPLODEBALL');
1173 g_Sound_Delete('SOUND_WEAPON_FIREREV');
1174 g_Sound_Delete('SOUND_WEAPON_FLAMEON');
1175 g_Sound_Delete('SOUND_WEAPON_FLAMEOFF');
1176 g_Sound_Delete('SOUND_WEAPON_FLAMEWORK');
1177 g_Sound_Delete('SOUND_PLAYER_JETFLY');
1178 g_Sound_Delete('SOUND_PLAYER_JETON');
1179 g_Sound_Delete('SOUND_PLAYER_JETOFF');
1180 g_Sound_Delete('SOUND_PLAYER_CASING1');
1181 g_Sound_Delete('SOUND_PLAYER_CASING2');
1182 g_Sound_Delete('SOUND_PLAYER_SHELL1');
1183 g_Sound_Delete('SOUND_PLAYER_SHELL2');
1187 function GunHitPlayer (X
, Y
: Integer; vx
, vy
: Integer; dmg
: Integer; SpawnerUID
: Word; AllowPush
: Boolean): Boolean;
1192 for i
:= 0 to High(gPlayers
) do
1194 if (gPlayers
[i
] <> nil) and gPlayers
[i
].alive
and gPlayers
[i
].Collide(X
, Y
) then
1196 if HitPlayer(gPlayers
[i
], dmg
, vx
*10, vy
*10-3, SpawnerUID
, HIT_SOME
) then
1198 if AllowPush
then gPlayers
[i
].Push(vx
, vy
);
1206 function GunHit (X
, Y
: Integer; vx
, vy
: Integer; dmg
: Integer; SpawnerUID
: Word; AllowPush
: Boolean): Byte;
1208 function monsCheck (mon
: TMonster
): Boolean;
1210 result
:= false; // don't stop
1211 if HitMonster(mon
, dmg
, vx
*10, vy
*10-3, SpawnerUID
, HIT_SOME
) then
1213 if AllowPush
then mon
.Push(vx
, vy
);
1220 if GunHitPlayer(X
, Y
, vx
, vy
, dmg
, SpawnerUID
, AllowPush
) then result
:= 1
1221 else if g_Mons_ForEachAliveAt(X
, Y
, 1, 1, monsCheck
) then result
:= 2;
1226 procedure g_Weapon_gunOld(const x, y, xd, yd, v, dmg: Integer; SpawnerUID: Word; CheckTrigger: Boolean);
1237 t1, _collide: Boolean;
1239 {$IF DEFINED(D2F_DEBUG)}
1241 showTime: Boolean = true;
1244 a := GetAngle(x, y, xd, yd)+180;
1246 SinCos(DegToRad(-a), s, c);
1248 if Abs(s) < 0.01 then s := 0;
1249 if Abs(c) < 0.01 then c := 0;
1251 x2 := x+Round(c*gMapInfo.Width);
1252 y2 := y+Round(s*gMapInfo.Width);
1254 t1 := gWalls <> nil;
1256 w := gMapInfo.Width;
1257 h := gMapInfo.Height;
1264 if (xd = 0) and (yd = 0) then Exit;
1266 if dx > 0 then xi := 1 else if dx < 0 then xi := -1 else xi := 0;
1267 if dy > 0 then yi := 1 else if dy < 0 then yi := -1 else yi := 0;
1272 if dx > dy then d := dx else d := dy;
1274 //blood vel, for Monster.Damage()
1275 //vx := (dx*10 div d)*xi;
1276 //vy := (dy*10 div d)*yi;
1278 {$IF DEFINED(D2F_DEBUG)}
1279 stt := getTimeMicro();
1302 if (yy > h) or (yy < 0) then Break;
1303 if (xx > w) or (xx < 0) then Break;
1306 if ByteBool(gCollideMap[yy, xx] and MARK_BLOCKED) then
1309 {$IF DEFINED(D2F_DEBUG)}
1310 stt := getTimeMicro()-stt;
1311 e_WriteLog(Format('*** old trace time: %u microseconds', [LongWord(stt)]), MSG_NOTIFY);
1314 g_GFX_Spark(xx-xi, yy-yi, 2+Random(2), 180+a, 0, 0);
1315 if g_Game_IsServer and g_Game_IsNet then
1316 MH_SEND_Effect(xx-xi, yy-yi, 180+a, NET_GFX_SPARK);
1319 if not _collide then
1321 _collide := GunHit(xx, yy, xi*v, yi*v, dmg, SpawnerUID, v <> 0) <> 0;
1324 if _collide then Break;
1327 {$IF DEFINED(D2F_DEBUG)}
1330 stt := getTimeMicro()-stt;
1331 e_WriteLog(Format('*** old trace time: %u microseconds', [LongWord(stt)]), MSG_NOTIFY);
1335 if CheckTrigger and g_Game_IsServer then
1336 g_Triggers_PressL(X, Y, xx-xi, yy-yi, SpawnerUID, ACTIVATE_SHOT);
1342 procedure g_Weapon_gun (const x
, y
, xd
, yd
, v
, indmg
: Integer; SpawnerUID
: Word; CheckTrigger
: Boolean);
1347 wallDistSq
: Integer = $3fffffff;
1348 spawnerPlr
: TPlayer
= nil;
1351 function doPlayerHit (idx
: Integer; hx
, hy
: Integer): Boolean;
1354 if (idx
< 0) or (idx
> High(gPlayers
)) then exit
;
1355 if (gPlayers
[idx
] = nil) or not gPlayers
[idx
].alive
then exit
;
1356 if (spawnerPlr
<> nil) then
1358 if ((gGameSettings
.Options
and (GAME_OPTION_TEAMHITTRACE
or GAME_OPTION_TEAMDAMAGE
)) = 0) and
1359 (spawnerPlr
.Team
<> TEAM_NONE
) and (spawnerPlr
.Team
= gPlayers
[idx
].Team
) then
1361 if (spawnerPlr
<> gPlayers
[idx
]) and ((gGameSettings
.Options
and GAME_OPTION_TEAMABSORBDAMAGE
) = 0) then
1362 dmg
:= Max(1, dmg
div 2);
1366 result
:= HitPlayer(gPlayers
[idx
], dmg
, (xi
*v
)*10, (yi
*v
)*10-3, SpawnerUID
, HIT_SOME
);
1367 if result
and (v
<> 0) then gPlayers
[idx
].Push((xi
*v
), (yi
*v
));
1368 {$IF DEFINED(D2F_DEBUG)}
1369 //if result then e_WriteLog(Format(' PLAYER #%d HIT', [idx]), MSG_NOTIFY);
1373 function doMonsterHit (mon
: TMonster
; hx
, hy
: Integer): Boolean;
1376 if (mon
= nil) then exit
;
1377 result
:= HitMonster(mon
, dmg
, (xi
*v
)*10, (yi
*v
)*10-3, SpawnerUID
, HIT_SOME
);
1378 if result
and (v
<> 0) then mon
.Push((xi
*v
), (yi
*v
));
1379 {$IF DEFINED(D2F_DEBUG)}
1380 //if result then e_WriteLog(Format(' MONSTER #%u HIT', [LongWord(mon.UID)]), MSG_NOTIFY);
1384 // collect players along hitray
1385 // return `true` if instant hit was detected
1386 function playerPossibleHit (): Boolean;
1389 px
, py
, pw
, ph
: Integer;
1395 for i
:= 0 to High(gPlayers
) do
1398 if (plr
<> nil) and plr
.alive
then
1400 plr
.getMapBox(px
, py
, pw
, ph
);
1401 if lineAABBIntersects(x
, y
, x2
, y2
, px
, py
, pw
, ph
, inx
, iny
) then
1403 distSq
:= distanceSq(x
, y
, inx
, iny
);
1404 if (distSq
= 0) then
1407 if doPlayerHit(i
, x
, y
) then begin result
:= true; exit
; end;
1409 else if (distSq
< wallDistSq
) then
1411 appendHitTimePlr(distSq
, i
, inx
, iny
);
1418 procedure sqchecker (mon
: TMonster
);
1420 mx
, my
, mw
, mh
: Integer;
1424 mon
.getMapBox(mx
, my
, mw
, mh
);
1425 if lineAABBIntersects(x0
, y0
, x2
, y2
, mx
, my
, mw
, mh
, inx
, iny
) then
1427 distSq
:= distanceSq(x0
, y0
, inx
, iny
);
1428 if (distSq
< wallDistSq
) then appendHitTimeMon(distSq
, mon
, inx
, iny
);
1438 wallHitFlag
: Boolean = false;
1439 wallHitX
: Integer = 0;
1440 wallHitY
: Integer = 0;
1441 didHit
: Boolean = false;
1442 {$IF DEFINED(D2F_DEBUG)}
1446 it
: TMonsterGrid
.Iter
;
1449 if not gwep_debug_fast_trace then
1451 g_Weapon_gunOld(x, y, xd, yd, v, dmg, SpawnerUID, CheckTrigger);
1456 if (xd
= 0) and (yd
= 0) then exit
;
1458 if (g_GetUIDType(SpawnerUID
) = UID_PLAYER
) then
1459 spawnerPlr
:= g_Player_Get(SpawnerUID
);
1463 //wgunMonHash.reset(); //FIXME: clear hash on level change
1464 wgunHitHeap
.clear();
1465 wgunHitTimeUsed
:= 0;
1467 a
:= GetAngle(x
, y
, xd
, yd
)+180;
1469 SinCos(DegToRad(-a
), s
, c
);
1471 if Abs(s
) < 0.01 then s
:= 0;
1472 if Abs(c
) < 0.01 then c
:= 0;
1476 x2
:= x
+Round(c
*gMapInfo
.Width
);
1477 y2
:= y
+Round(s
*gMapInfo
.Width
);
1482 if (dx
> 0) then xi
:= 1 else if (dx
< 0) then xi
:= -1 else xi
:= 0;
1483 if (dy
> 0) then yi
:= 1 else if (dy
< 0) then yi
:= -1 else yi
:= 0;
1485 {$IF DEFINED(D2F_DEBUG)}
1486 e_WriteLog(Format('GUN TRACE: (%d,%d) to (%d,%d)', [x
, y
, x2
, y2
]), TMsgType
.Notify
);
1487 stt
:= getTimeMicro();
1490 wallHitFlag
:= (g_Map_traceToNearestWall(x
, y
, x2
, y2
, @wallHitX
, @wallHitY
) <> nil);
1495 wallDistSq
:= distanceSq(x
, y
, wallHitX
, wallHitY
);
1503 if playerPossibleHit() then exit
; // instant hit
1506 //g_Mons_AlongLine(x, y, x2, y2, sqchecker);
1508 it
:= monsGrid
.forEachAlongLine(x
, y
, x2
, y2
, -1);
1509 for mit
in it
do sqchecker(mit
^);
1512 // here, we collected all monsters and players in `wgunHitHeap` and `wgunHitTime`
1513 // also, if `wallWasHit` is `true`, then `wallHitX` and `wallHitY` contains spark coords
1514 while (wgunHitHeap
.count
> 0) do
1516 // has some entities to check, do it
1517 i
:= wgunHitHeap
.front
;
1518 wgunHitHeap
.popFront();
1520 xe
:= wgunHitTime
[i
].x
;
1521 ye
:= wgunHitTime
[i
].y
;
1522 // check if it is not behind the wall
1523 if (wgunHitTime
[i
].mon
<> nil) then
1525 didHit
:= doMonsterHit(wgunHitTime
[i
].mon
, xe
, ye
);
1529 didHit
:= doPlayerHit(wgunHitTime
[i
].plridx
, xe
, ye
);
1533 // need new coords for trigger
1536 wallHitFlag
:= false; // no sparks
1544 {$IF DEFINED(D2F_DEBUG)}
1545 stt
:= getTimeMicro()-stt
;
1546 e_WriteLog(Format('*** new trace time: %u microseconds', [LongWord(stt
)]), TMsgType
.Notify
);
1548 g_GFX_Spark(wallHitX
, wallHitY
, 2+Random(2), 180+a
, 0, 0);
1549 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Effect(wallHitX
, wallHitY
, 180+a
, NET_GFX_SPARK
);
1553 {$IF DEFINED(D2F_DEBUG)}
1554 stt
:= getTimeMicro()-stt
;
1555 e_WriteLog(Format('*** new trace time: %u microseconds', [LongWord(stt
)]), TMsgType
.Notify
);
1559 if CheckTrigger
and g_Game_IsServer
then g_Triggers_PressL(X
, Y
, wallHitX
, wallHitY
, SpawnerUID
, ACTIVATE_SHOT
);
1563 procedure g_Weapon_punch(x
, y
: Integer; d
, SpawnerUID
: Word);
1571 obj
.rect
.Width
:= 39;
1572 obj
.rect
.Height
:= 52;
1578 if g_Weapon_Hit(@obj
, d
, SpawnerUID
, HIT_SOME
) <> 0 then
1579 g_Sound_PlayExAt('SOUND_WEAPON_HITPUNCH', x
, y
)
1581 g_Sound_PlayExAt('SOUND_WEAPON_MISSPUNCH', x
, y
);
1584 function g_Weapon_chainsaw(x
, y
: Integer; d
, SpawnerUID
: Word): Integer;
1592 obj
.rect
.Width
:= 32;
1593 obj
.rect
.Height
:= 52;
1599 Result
:= g_Weapon_Hit(@obj
, d
, SpawnerUID
, HIT_SOME
);
1602 procedure g_Weapon_rocket(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1;
1603 Silent
: Boolean = False; compat
: Boolean = true);
1609 find_id
:= FindShot()
1613 if Integer(find_id
) >= High(Shots
) then
1614 SetLength(Shots
, find_id
+ 64)
1617 with Shots
[find_id
] do
1621 Obj
.Rect
.Width
:= SHOT_ROCKETLAUNCHER_WIDTH
;
1622 Obj
.Rect
.Height
:= SHOT_ROCKETLAUNCHER_HEIGHT
;
1625 dx
:= IfThen(xd
> x
, -Obj
.Rect
.Width
, 0)
1627 dx
:= -(Obj
.Rect
.Width
div 2);
1628 dy
:= -(Obj
.Rect
.Height
div 2);
1630 ShotType
:= WEAPON_ROCKETLAUNCHER
;
1631 throw(find_id
, x
+dx
, y
+dy
, xd
+dx
, yd
+dy
, 12);
1637 Shots
[find_id
].SpawnerUID
:= SpawnerUID
;
1640 g_Sound_PlayExAt('SOUND_WEAPON_FIREROCKET', x
, y
);
1643 procedure g_Weapon_revf(x
, y
, xd
, yd
: Integer; SpawnerUID
, TargetUID
: Word;
1644 WID
: Integer = -1; Silent
: Boolean = False);
1650 find_id
:= FindShot()
1654 if Integer(find_id
) >= High(Shots
) then
1655 SetLength(Shots
, find_id
+ 64)
1658 with Shots
[find_id
] do
1662 Obj
.Rect
.Width
:= SHOT_SKELFIRE_WIDTH
;
1663 Obj
.Rect
.Height
:= SHOT_SKELFIRE_HEIGHT
;
1665 dx
:= -(Obj
.Rect
.Width
div 2);
1666 dy
:= -(Obj
.Rect
.Height
div 2);
1668 ShotType
:= WEAPON_SKEL_FIRE
;
1669 throw(find_id
, x
+dx
, y
+dy
, xd
+dx
, yd
+dy
, 12);
1672 target
:= TargetUID
;
1673 Animation
:= TAnimationState
.Create(True, 5, 2); // !!! put values into table
1676 Shots
[find_id
].SpawnerUID
:= SpawnerUID
;
1679 g_Sound_PlayExAt('SOUND_WEAPON_FIREREV', x
, y
);
1682 procedure g_Weapon_plasma(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1;
1683 Silent
: Boolean = False; compat
: Boolean = true);
1689 find_id
:= FindShot()
1693 if Integer(find_id
) >= High(Shots
) then
1694 SetLength(Shots
, find_id
+ 64);
1697 with Shots
[find_id
] do
1701 Obj
.Rect
.Width
:= SHOT_PLASMA_WIDTH
;
1702 Obj
.Rect
.Height
:= SHOT_PLASMA_HEIGHT
;
1705 dx
:= IfThen(xd
> x
, -Obj
.Rect
.Width
, 0)
1707 dx
:= -(Obj
.Rect
.Width
div 2);
1708 dy
:= -(Obj
.Rect
.Height
div 2);
1710 ShotType
:= WEAPON_PLASMA
;
1711 throw(find_id
, x
+dx
, y
+dy
, xd
+dx
, yd
+dy
, 16);
1714 Animation
:= TAnimationState
.Create(True, 5, 2); // !!! put values into table
1717 Shots
[find_id
].SpawnerUID
:= SpawnerUID
;
1720 g_Sound_PlayExAt('SOUND_WEAPON_FIREPLASMA', x
, y
);
1723 procedure g_Weapon_flame(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1;
1724 Silent
: Boolean = False; compat
: Boolean = true);
1730 find_id
:= FindShot()
1734 if Integer(find_id
) >= High(Shots
) then
1735 SetLength(Shots
, find_id
+ 64);
1738 with Shots
[find_id
] do
1742 Obj
.Rect
.Width
:= SHOT_FLAME_WIDTH
;
1743 Obj
.Rect
.Height
:= SHOT_FLAME_HEIGHT
;
1746 dx
:= IfThen(xd
> x
, -Obj
.Rect
.Width
, 0)
1748 dx
:= -(Obj
.Rect
.Width
div 2);
1749 dy
:= -(Obj
.Rect
.Height
div 2);
1751 ShotType
:= WEAPON_FLAMETHROWER
;
1752 throw(find_id
, x
+dx
, y
+dy
, xd
+dx
, yd
+dy
, 16);
1758 Shots
[find_id
].SpawnerUID
:= SpawnerUID
;
1760 // if not Silent then
1761 // g_Sound_PlayExAt('SOUND_WEAPON_FIREPLASMA', x, y);
1764 procedure g_Weapon_ball1(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1;
1765 Silent
: Boolean = False; compat
: Boolean = true);
1771 find_id
:= FindShot()
1775 if Integer(find_id
) >= High(Shots
) then
1776 SetLength(Shots
, find_id
+ 64)
1779 with Shots
[find_id
] do
1783 Obj
.Rect
.Width
:= 16;
1784 Obj
.Rect
.Height
:= 16;
1787 dx
:= IfThen(xd
> x
, -Obj
.Rect
.Width
, 0)
1789 dx
:= -(Obj
.Rect
.Width
div 2);
1790 dy
:= -(Obj
.Rect
.Height
div 2);
1792 ShotType
:= WEAPON_IMP_FIRE
;
1793 throw(find_id
, x
+dx
, y
+dy
, xd
+dx
, yd
+dy
, 16);
1796 Animation
:= TAnimationState
.Create(True, 4, 2); // !!! put values into table
1799 Shots
[find_id
].SpawnerUID
:= SpawnerUID
;
1802 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x
, y
);
1805 procedure g_Weapon_ball2(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1;
1806 Silent
: Boolean = False; compat
: Boolean = true);
1812 find_id
:= FindShot()
1816 if Integer(find_id
) >= High(Shots
) then
1817 SetLength(Shots
, find_id
+ 64)
1820 with Shots
[find_id
] do
1824 Obj
.Rect
.Width
:= 16;
1825 Obj
.Rect
.Height
:= 16;
1828 dx
:= IfThen(xd
> x
, -Obj
.Rect
.Width
, 0)
1830 dx
:= -(Obj
.Rect
.Width
div 2);
1831 dy
:= -(Obj
.Rect
.Height
div 2);
1833 ShotType
:= WEAPON_CACO_FIRE
;
1834 throw(find_id
, x
+dx
, y
+dy
, xd
+dx
, yd
+dy
, 16);
1837 Animation
:= TAnimationState
.Create(True, 4, 2); // !!! put values into table
1840 Shots
[find_id
].SpawnerUID
:= SpawnerUID
;
1843 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x
, y
);
1846 procedure g_Weapon_ball7(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1;
1847 Silent
: Boolean = False; compat
: Boolean = true);
1853 find_id
:= FindShot()
1857 if Integer(find_id
) >= High(Shots
) then
1858 SetLength(Shots
, find_id
+ 64)
1861 with Shots
[find_id
] do
1865 Obj
.Rect
.Width
:= 32;
1866 Obj
.Rect
.Height
:= 16;
1869 dx
:= IfThen(xd
> x
, -Obj
.Rect
.Width
, 0)
1871 dx
:= -(Obj
.Rect
.Width
div 2);
1872 dy
:= -(Obj
.Rect
.Height
div 2);
1874 ShotType
:= WEAPON_BARON_FIRE
;
1875 throw(find_id
, x
+dx
, y
+dy
, xd
+dx
, yd
+dy
, 16);
1878 Animation
:= TAnimationState
.Create(True, 4, 2); // !!! put values into table
1881 Shots
[find_id
].SpawnerUID
:= SpawnerUID
;
1884 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x
, y
);
1887 procedure g_Weapon_aplasma(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1;
1888 Silent
: Boolean = False; compat
: Boolean = true);
1890 find_id
, FramesID
: DWORD
;
1894 find_id
:= FindShot()
1898 if Integer(find_id
) >= High(Shots
) then
1899 SetLength(Shots
, find_id
+ 64)
1902 with Shots
[find_id
] do
1906 Obj
.Rect
.Width
:= 16;
1907 Obj
.Rect
.Height
:= 16;
1910 dx
:= IfThen(xd
> x
, -Obj
.Rect
.Width
, 0)
1912 dx
:= -(Obj
.Rect
.Width
div 2);
1913 dy
:= -(Obj
.Rect
.Height
div 2);
1915 ShotType
:= WEAPON_BSP_FIRE
;
1916 throw(find_id
, x
+dx
, y
+dy
, xd
+dx
, yd
+dy
, 16);
1920 Animation
:= TAnimationState
.Create(True, 4, 2); // !!! put values into table
1923 Shots
[find_id
].SpawnerUID
:= SpawnerUID
;
1926 g_Sound_PlayExAt('SOUND_WEAPON_FIREPLASMA', x
, y
);
1929 procedure g_Weapon_manfire(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1;
1930 Silent
: Boolean = False; compat
: Boolean = true);
1936 find_id
:= FindShot()
1940 if Integer(find_id
) >= High(Shots
) then
1941 SetLength(Shots
, find_id
+ 64)
1944 with Shots
[find_id
] do
1948 Obj
.Rect
.Width
:= 32;
1949 Obj
.Rect
.Height
:= 32;
1952 dx
:= IfThen(xd
> x
, -Obj
.Rect
.Width
, 0)
1954 dx
:= -(Obj
.Rect
.Width
div 2);
1955 dy
:= -(Obj
.Rect
.Height
div 2);
1957 ShotType
:= WEAPON_MANCUB_FIRE
;
1958 throw(find_id
, x
+dx
, y
+dy
, xd
+dx
, yd
+dy
, 16);
1962 Animation
:= TAnimationState
.Create(True, 4, 2); // !!! put values into table
1965 Shots
[find_id
].SpawnerUID
:= SpawnerUID
;
1968 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x
, y
);
1971 procedure g_Weapon_bfgshot(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1;
1972 Silent
: Boolean = False; compat
: Boolean = true);
1978 find_id
:= FindShot()
1982 if Integer(find_id
) >= High(Shots
) then
1983 SetLength(Shots
, find_id
+ 64)
1986 with Shots
[find_id
] do
1990 Obj
.Rect
.Width
:= SHOT_BFG_WIDTH
;
1991 Obj
.Rect
.Height
:= SHOT_BFG_HEIGHT
;
1994 dx
:= IfThen(xd
> x
, -Obj
.Rect
.Width
, 0)
1996 dx
:= -(Obj
.Rect
.Width
div 2);
1997 dy
:= -(Obj
.Rect
.Height
div 2);
1999 ShotType
:= WEAPON_BFG
;
2000 throw(find_id
, x
+dx
, y
+dy
, xd
+dx
, yd
+dy
, 16);
2003 Animation
:= TAnimationState
.Create(True, 6, 2); // !!! put values into table
2006 Shots
[find_id
].SpawnerUID
:= SpawnerUID
;
2009 g_Sound_PlayExAt('SOUND_WEAPON_FIREBFG', x
, y
);
2012 procedure g_Weapon_bfghit(x
, y
: Integer);
2014 g_GFX_QueueEffect(R_GFX_BFG_HIT
, x
- 32, y
- 32);
2017 procedure g_Weapon_pistol(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word;
2018 Silent
: Boolean = False);
2021 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', x
, y
);
2023 g_Weapon_gun(x
, y
, xd
, yd
, 1, 3, SpawnerUID
, True);
2024 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
] then
2026 if ABS(x
-xd
) >= ABS(y
-yd
) then
2028 g_Weapon_gun(x
, y
+1, xd
, yd
+1, 1, 3, SpawnerUID
, False);
2029 g_Weapon_gun(x
, y
-1, xd
, yd
-1, 1, 2, SpawnerUID
, False);
2033 g_Weapon_gun(x
+1, y
, xd
+1, yd
, 1, 3, SpawnerUID
, False);
2034 g_Weapon_gun(x
-1, y
, xd
-1, yd
, 1, 2, SpawnerUID
, False);
2039 procedure g_Weapon_mgun(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word;
2040 Silent
: Boolean = False);
2043 if gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', x
, y
);
2045 g_Weapon_gun(x
, y
, xd
, yd
, 1, 3, SpawnerUID
, True);
2046 if (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) and
2047 (g_GetUIDType(SpawnerUID
) = UID_PLAYER
) then
2049 if ABS(x
-xd
) >= ABS(y
-yd
) then
2051 g_Weapon_gun(x
, y
+1, xd
, yd
+1, 1, 2, SpawnerUID
, False);
2052 g_Weapon_gun(x
, y
-1, xd
, yd
-1, 1, 2, SpawnerUID
, False);
2056 g_Weapon_gun(x
+1, y
, xd
+1, yd
, 1, 2, SpawnerUID
, False);
2057 g_Weapon_gun(x
-1, y
, xd
-1, yd
, 1, 2, SpawnerUID
, False);
2062 procedure g_Weapon_shotgun(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word;
2063 Silent
: Boolean = False);
2068 if gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', x
, y
);
2073 if ABS(x
-xd
) >= ABS(y
-yd
) then j
:= Random(17) - 8 else k
:= Random(17) - 8; // -8 .. 8
2074 g_Weapon_gun(x
+k
, y
+j
, xd
+k
, yd
+j
, IfThen(i
mod 2 <> 0, 1, 0), 3, SpawnerUID
, i
=0);
2078 procedure g_Weapon_dshotgun(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word;
2079 Silent
: Boolean = False);
2081 a
, i
, j
, k
: Integer;
2084 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', x
, y
);
2086 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
] then a
:= 25 else a
:= 20;
2090 if ABS(x
-xd
) >= ABS(y
-yd
) then j
:= Random(41) - 20 else k
:= Random(41) - 20; // -20 .. 20
2091 g_Weapon_gun(x
+k
, y
+j
, xd
+k
, yd
+j
, IfThen(i
mod 3 <> 0, 0, 1), 3, SpawnerUID
, i
=0);
2095 procedure g_Weapon_PreUpdate();
2099 if Shots
= nil then Exit
;
2100 for i
:= 0 to High(Shots
) do
2101 if Shots
[i
].ShotType
<> 0 then
2103 Shots
[i
].Obj
.oldX
:= Shots
[i
].Obj
.X
;
2104 Shots
[i
].Obj
.oldY
:= Shots
[i
].Obj
.Y
;
2108 procedure g_Weapon_Update();
2110 i
, a
, h
, cx
, cy
, oldvx
, oldvy
, tf
: Integer;
2121 for i
:= 0 to High(Shots
) do
2123 if Shots
[i
].ShotType
= 0 then
2130 Timeout
:= Timeout
- 1;
2133 // Àêòèâèðîâàòü òðèããåðû ïî ïóòè (êðîìå óæå àêòèâèðîâàííûõ):
2134 if (Stopped
= 0) and g_Game_IsServer
then
2135 t
:= g_Triggers_PressR(Obj
.X
, Obj
.Y
, Obj
.Rect
.Width
, Obj
.Rect
.Height
,
2136 SpawnerUID
, ACTIVATE_SHOT
, triggers
)
2142 // Ïîïîëíÿåì ñïèñîê àêòèâèðîâàííûõ òðèããåðîâ:
2143 if triggers
= nil then
2150 if not InDWArray(t
[a
], triggers
) then
2152 SetLength(triggers
, Length(triggers
)+1);
2153 triggers
[High(triggers
)] := t
[a
];
2158 // Àíèìàöèÿ ñíàðÿäà:
2159 if Animation
<> nil then
2163 spl
:= (ShotType
<> WEAPON_PLASMA
) and
2164 (ShotType
<> WEAPON_BFG
) and
2165 (ShotType
<> WEAPON_BSP_FIRE
) and
2166 (ShotType
<> WEAPON_FLAMETHROWER
);
2170 st
:= g_Obj_Move_Projectile(@Obj
, False, spl
);
2176 positionChanged(); // this updates spatial accelerators
2178 if WordBool(st
and MOVE_FALLOUT
) or (Obj
.X
< -1000) or
2179 (Obj
.X
> gMapInfo
.Width
+1000) or (Obj
.Y
< -1000) then
2181 // Íà êëèåíòå ñêîðåå âñåãî è òàê óæå âûïàë.
2187 cx
:= Obj
.X
+ (Obj
.Rect
.Width
div 2);
2188 cy
:= Obj
.Y
+ (Obj
.Rect
.Height
div 2);
2191 WEAPON_ROCKETLAUNCHER
, WEAPON_SKEL_FIRE
: // Ðàêåòû è ñíàðÿäû Ñêåëåòà
2193 // Âûëåòåëà èç âîäû:
2194 if WordBool(st
and MOVE_HITAIR
) then
2195 g_Obj_SetSpeed(@Obj
, 12);
2197 // Â âîäå øëåéô - ïóçûðè, â âîçäóõå øëåéô - äûì:
2198 if WordBool(st
and MOVE_INWATER
) then
2200 g_GFX_Bubbles(cx
, cy
, 1+Random(3), 16, 16);
2202 then g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', cx
, cy
)
2203 else g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', cx
, cy
);
2207 g_GFX_QueueEffect(R_GFX_SMOKE_TRANS
, Obj
.X
-14+Random(9), cy
-20+Random(9));
2210 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2211 if WordBool(st
and (MOVE_HITWALL
or MOVE_HITLAND
or MOVE_HITCEIL
)) or
2212 (g_Weapon_Hit(@Obj
, 10, SpawnerUID
, HIT_SOME
, False) <> 0) or
2218 g_Weapon_Explode(cx
, cy
, 60, SpawnerUID
);
2220 if ShotType
= WEAPON_SKEL_FIRE
then
2221 begin // Âçðûâ ñíàðÿäà Ñêåëåòà
2222 g_GFX_QueueEffect(R_GFX_EXPLODE_SKELFIRE
, Obj
.X
+ 32 - 58, Obj
.Y
+ 8 - 36);
2223 g_DynLightExplosion((Obj
.X
+32), (Obj
.Y
+8), 64, 1, 0, 0);
2226 begin // Âçðûâ Ðàêåòû
2227 g_GFX_QueueEffect(R_GFX_EXPLODE_ROCKET
, cx
- 64, cy
- 64);
2228 g_DynLightExplosion(cx
, cy
, 64, 1, 0, 0);
2231 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', Obj
.X
, Obj
.Y
);
2236 if ShotType
= WEAPON_SKEL_FIRE
then
2237 begin // Ñàìîíàâîäêà ñíàðÿäà Ñêåëåòà:
2238 if GetPos(target
, @o
) then
2239 throw(i
, Obj
.X
, Obj
.Y
,
2240 o
.X
+o
.Rect
.X
+(o
.Rect
.Width
div 2)+o
.Vel
.X
+o
.Accel
.X
,
2241 o
.Y
+o
.Rect
.Y
+(o
.Rect
.Height
div 2)+o
.Vel
.Y
+o
.Accel
.Y
,
2246 WEAPON_PLASMA
, WEAPON_BSP_FIRE
: // Ïëàçìà, ïëàçìà Àðàõíàòðîíà
2248 // Ïîïàëà â âîäó - ýëåêòðîøîê ïî âîäå:
2249 if WordBool(st
and (MOVE_INWATER
or MOVE_HITWATER
)) then
2251 g_Sound_PlayExAt('SOUND_WEAPON_PLASMAWATER', Obj
.X
, Obj
.Y
);
2252 if g_Game_IsServer
then CheckTrap(i
, 10, HIT_ELECTRO
);
2258 if (ShotType
= WEAPON_PLASMA
) and
2259 (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) then
2264 if ShotType
= WEAPON_BSP_FIRE
then
2267 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2268 if WordBool(st
and (MOVE_HITWALL
or MOVE_HITLAND
or MOVE_HITCEIL
)) or
2269 (g_Weapon_Hit(@Obj
, a
, SpawnerUID
, HIT_SOME
, False) <> 0) or
2272 if ShotType
= WEAPON_PLASMA
then
2273 g_GFX_QueueEffect(R_GFX_EXPLODE_PLASMA
, cx
- 16, cy
- 16)
2275 g_GFX_QueueEffect(R_GFX_EXPLODE_BSPFIRE
, cx
- 16, cy
- 16);
2276 g_DynLightExplosion(cx
, cy
, 32, 0, 0.5, 0.5);
2277 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEPLASMA', Obj
.X
, Obj
.Y
);
2282 WEAPON_FLAMETHROWER
: // Îãíåìåò
2284 // Ñî âðåìåíåì óìèðàåò
2285 if (Timeout
< 1) then
2291 if WordBool(st
and (MOVE_HITWATER
or MOVE_INWATER
)) then
2293 if WordBool(st
and MOVE_HITWATER
) then
2297 g_GFX_QueueEffect(R_GFX_SMOKE
, cx
-4+tcx
-(R_GFX_SMOKE_WIDTH
div 2), cy
-4+tcy
-(R_GFX_SMOKE_HEIGHT
div 2));
2301 g_GFX_Bubbles(cx
, cy
, 1+Random(3), 16, 16);
2303 then g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', cx
, cy
)
2304 else g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', cx
, cy
);
2312 Obj
.Accel
.Y
:= Obj
.Accel
.Y
+ 1;
2313 // Ïîïàëè â ñòåíó èëè â âîäó:
2314 if WordBool(st
and (MOVE_HITWALL
or MOVE_HITLAND
or MOVE_HITCEIL
or MOVE_HITWATER
)) then
2320 if WordBool(st
and MOVE_HITWALL
) then
2321 Stopped
:= MOVE_HITWALL
2322 else if WordBool(st
and MOVE_HITLAND
) then
2323 Stopped
:= MOVE_HITLAND
2324 else if WordBool(st
and MOVE_HITCEIL
) then
2325 Stopped
:= MOVE_HITCEIL
;
2328 a
:= IfThen(Stopped
= 0, 10, 1);
2329 // Åñëè â êîãî-òî ïîïàëè
2330 if g_Weapon_Hit(@Obj
, a
, SpawnerUID
, HIT_FLAME
, False) <> 0 then
2332 // HIT_FLAME ñàì ïîäîææåò
2333 // Åñëè â ïîëåòå ïîïàëè, èñ÷åçàåì
2343 if (gTime
mod LongWord(tf
) = 0) then
2346 MOVE_HITWALL
: begin tcx
:= cx
-4+Random(8); tcy
:= cy
-12+Random(24); end;
2347 MOVE_HITLAND
: begin tcx
:= cx
-12+Random(24); tcy
:= cy
-10+Random(8); end;
2348 MOVE_HITCEIL
: begin tcx
:= cx
-12+Random(24); tcy
:= cy
+6+Random(8); end;
2349 else begin tcx
:= cx
-4+Random(8); tcy
:= cy
-4+Random(8); end;
2351 g_GFX_QueueEffect(R_GFX_FLAME_RAND
, tcx
- (R_GFX_FLAME_WIDTH
div 2), tcy
- (R_GFX_FLAME_HEIGHT
div 2));
2352 //g_DynLightExplosion(tcx, tcy, 1, 1, 0.8, 0.3);
2358 // Ïîïàëà â âîäó - ýëåêòðîøîê ïî âîäå:
2359 if WordBool(st
and (MOVE_INWATER
or MOVE_HITWATER
)) then
2361 g_Sound_PlayExAt('SOUND_WEAPON_BFGWATER', Obj
.X
, Obj
.Y
);
2362 if g_Game_IsServer
then CheckTrap(i
, 1000, HIT_ELECTRO
);
2367 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2368 if WordBool(st
and (MOVE_HITWALL
or MOVE_HITLAND
or MOVE_HITCEIL
)) or
2369 (g_Weapon_Hit(@Obj
, SHOT_BFG_DAMAGE
, SpawnerUID
, HIT_BFG
, False) <> 0) or
2373 if g_Game_IsServer
then g_Weapon_BFG9000(cx
, cy
, SpawnerUID
);
2374 g_GFX_QueueEffect(R_GFX_EXPLODE_BFG
, cx
- 64, cy
- 64);
2375 g_DynLightExplosion(cx
, cy
, 96, 0, 1, 0);
2376 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', Obj
.X
, Obj
.Y
);
2381 WEAPON_IMP_FIRE
, WEAPON_CACO_FIRE
, WEAPON_BARON_FIRE
: // Âûñòðåëû Áåñà, Êàêîäåìîíà Ðûöàðÿ/Áàðîíà àäà
2384 if WordBool(st
and MOVE_HITAIR
) then
2385 g_Obj_SetSpeed(@Obj
, 16);
2388 if ShotType
= WEAPON_IMP_FIRE
then
2391 if ShotType
= WEAPON_CACO_FIRE
then
2396 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2397 if WordBool(st
and (MOVE_HITWALL
or MOVE_HITLAND
or MOVE_HITCEIL
)) or
2398 (g_Weapon_Hit(@Obj
, a
, SpawnerUID
, HIT_SOME
) <> 0) or
2402 WEAPON_IMP_FIRE
: g_GFX_QueueEffect(R_GFX_EXPLODE_IMPFIRE
, cx
- 32, cy
- 32);
2403 WEAPON_CACO_FIRE
: g_GFX_QueueEffect(R_GFX_EXPLODE_CACOFIRE
, cx
- 32, cy
- 32);
2404 WEAPON_BARON_FIRE
: g_GFX_QueueEffect(R_GFX_EXPLODE_BARONFIRE
, cx
- 32, cy
- 32);
2406 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj
.X
, Obj
.Y
);
2411 WEAPON_MANCUB_FIRE
: // Âûñòðåë Ìàíêóáóñà
2414 if WordBool(st
and MOVE_HITAIR
) then
2415 g_Obj_SetSpeed(@Obj
, 16);
2417 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2418 if WordBool(st
and (MOVE_HITWALL
or MOVE_HITLAND
or MOVE_HITCEIL
)) or
2419 (g_Weapon_Hit(@Obj
, 40, SpawnerUID
, HIT_SOME
, False) <> 0) or
2423 g_GFX_QueueEffect(R_GFX_EXPLODE_ROCKET
, cx
- 64, cy
- 64);
2424 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj
.X
, Obj
.Y
);
2428 end; // case ShotType of...
2430 // Åñëè ñíàðÿäà óæå íåò, óäàëÿåì àíèìàöèþ:
2431 if (ShotType
= 0) then
2433 if gGameSettings
.GameType
= GT_SERVER
then
2434 MH_SEND_DeleteShot(i
, Obj
.X
, Obj
.Y
, Loud
);
2435 if Animation
<> nil then
2441 else if (ShotType
<> WEAPON_FLAMETHROWER
) and ((oldvx
<> Obj
.Vel
.X
) or (oldvy
<> Obj
.Vel
.Y
)) then
2442 if gGameSettings
.GameType
= GT_SERVER
then
2443 MH_SEND_UpdateShot(i
);
2448 function g_Weapon_Danger(UID
: Word; X
, Y
: Integer; Width
, Height
: Word; Time
: Byte): Boolean;
2457 for a
:= 0 to High(Shots
) do
2458 if (Shots
[a
].ShotType
<> 0) and (Shots
[a
].SpawnerUID
<> UID
) then
2459 if ((Shots
[a
].Obj
.Vel
.Y
= 0) and (Shots
[a
].Obj
.Vel
.X
> 0) and (Shots
[a
].Obj
.X
< X
)) or
2460 (Shots
[a
].Obj
.Vel
.Y
= 0) and (Shots
[a
].Obj
.Vel
.X
< 0) and (Shots
[a
].Obj
.X
> X
) then
2461 if (Abs(X
-Shots
[a
].Obj
.X
) < Abs(Shots
[a
].Obj
.Vel
.X
*Time
)) and
2462 g_Collide(X
, Y
, Width
, Height
, X
, Shots
[a
].Obj
.Y
,
2463 Shots
[a
].Obj
.Rect
.Width
, Shots
[a
].Obj
.Rect
.Height
) and
2464 g_TraceVector(X
, Y
, Shots
[a
].Obj
.X
, Shots
[a
].Obj
.Y
) then
2471 procedure g_Weapon_SaveState (st
: TStream
);
2473 count
, i
, j
: Integer;
2475 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ ñíàðÿäîâ
2477 for i
:= 0 to High(Shots
) do if (Shots
[i
].ShotType
<> 0) then Inc(count
);
2479 // Êîëè÷åñòâî ñíàðÿäîâ
2480 utils
.WriteInt(st
, count
);
2482 if (count
= 0) then exit
;
2484 for i
:= 0 to High(Shots
) do
2486 if Shots
[i
].ShotType
<> 0 then
2488 // Ñèãíàòóðà ñíàðÿäà
2489 utils
.writeSign(st
, 'SHOT');
2490 utils
.writeInt(st
, Byte(0)); // version
2492 utils
.writeInt(st
, Byte(Shots
[i
].ShotType
));
2494 utils
.writeInt(st
, Word(Shots
[i
].Target
));
2496 utils
.writeInt(st
, Word(Shots
[i
].SpawnerUID
));
2497 // Ðàçìåð ïîëÿ Triggers
2498 utils
.writeInt(st
, Integer(Length(Shots
[i
].Triggers
)));
2499 // Òðèããåðû, àêòèâèðîâàííûå âûñòðåëîì
2500 for j
:= 0 to Length(Shots
[i
].Triggers
)-1 do utils
.writeInt(st
, LongWord(Shots
[i
].Triggers
[j
]));
2502 Obj_SaveState(st
, @Shots
[i
].Obj
);
2504 utils
.writeInt(st
, Byte(Shots
[i
].Stopped
));
2509 procedure g_Weapon_LoadState (st
: TStream
);
2511 count
, tc
, i
, j
: Integer;
2513 if (st
= nil) then exit
;
2515 // Êîëè÷åñòâî ñíàðÿäîâ
2516 count
:= utils
.readLongInt(st
);
2517 if (count
< 0) or (count
> 1024*1024) then raise XStreamError
.Create('invalid shots counter');
2519 SetLength(Shots
, count
);
2521 if (count
= 0) then exit
;
2523 for i
:= 0 to count
-1 do
2525 // Ñèãíàòóðà ñíàðÿäà
2526 if not utils
.checkSign(st
, 'SHOT') then raise XStreamError
.Create('invalid shot signature');
2527 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid shot version');
2529 Shots
[i
].ShotType
:= utils
.readByte(st
);
2531 Shots
[i
].Target
:= utils
.readWord(st
);
2533 Shots
[i
].SpawnerUID
:= utils
.readWord(st
);
2534 // Ðàçìåð ïîëÿ Triggers
2535 tc
:= utils
.readLongInt(st
);
2536 if (tc
< 0) or (tc
> 1024*1024) then raise XStreamError
.Create('invalid shot triggers counter');
2537 SetLength(Shots
[i
].Triggers
, tc
);
2538 // Òðèããåðû, àêòèâèðîâàííûå âûñòðåëîì
2539 for j
:= 0 to tc
-1 do Shots
[i
].Triggers
[j
] := utils
.readLongWord(st
);
2541 Obj_LoadState(@Shots
[i
].Obj
, st
);
2543 Shots
[i
].Stopped
:= utils
.readByte(st
);
2545 // Óñòàíîâêà òåêñòóðû èëè àíèìàöèè
2546 Shots
[i
].Animation
:= nil;
2548 case Shots
[i
].ShotType
of
2549 WEAPON_ROCKETLAUNCHER
, WEAPON_SKEL_FIRE
:
2554 Shots
[i
].Animation
:= TAnimationState
.Create(True, 5, 2); // !!! put values into table
2558 Shots
[i
].Animation
:= TAnimationState
.Create(True, 6, 2); // !!! put values into table
2562 Shots
[i
].Animation
:= TAnimationState
.Create(True, 4, 2); // !!! put values into table
2566 Shots
[i
].Animation
:= TAnimationState
.Create(True, 4, 2); // !!! put values into table
2570 Shots
[i
].Animation
:= TAnimationState
.Create(True, 4, 2); // !!! put values into table
2574 Shots
[i
].Animation
:= TAnimationState
.Create(True, 4, 2); // !!! put values into table
2578 Shots
[i
].Animation
:= TAnimationState
.Create(True, 4, 2); // !!! put values into table
2584 procedure g_Weapon_DestroyShot(I
: Integer; X
, Y
: Integer; Loud
: Boolean = True);
2585 var cx
, cy
: Integer;
2589 if (I
> High(Shots
)) or (I
< 0) then Exit
;
2593 if ShotType
= 0 then Exit
;
2596 cx
:= Obj
.X
+ (Obj
.Rect
.Width
div 2);
2597 cy
:= Obj
.Y
+ (Obj
.Rect
.Height
div 2);
2600 WEAPON_ROCKETLAUNCHER
, WEAPON_SKEL_FIRE
: // Ðàêåòû è ñíàðÿäû Ñêåëåòà
2604 if ShotType
= WEAPON_SKEL_FIRE
then
2605 g_GFX_QueueEffect(R_GFX_EXPLODE_SKELFIRE
, (Obj
.X
+ 32) - 32, (Obj
.Y
+ 8) - 32)
2607 g_GFX_QueueEffect(R_GFX_EXPLODE_ROCKET
, cx
- 64, cy
- 64);
2608 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', Obj
.X
, Obj
.Y
);
2612 WEAPON_PLASMA
, WEAPON_BSP_FIRE
: // Ïëàçìà, ïëàçìà Àðàõíàòðîíà
2616 if ShotType
= WEAPON_PLASMA
then
2617 g_GFX_QueueEffect(R_GFX_EXPLODE_PLASMA
, cx
- 16, cy
- 16)
2619 g_GFX_QueueEffect(R_GFX_EXPLODE_BSPFIRE
, cx
- 16, cy
- 16);
2620 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEPLASMA', Obj
.X
, Obj
.Y
);
2626 g_GFX_QueueEffect(R_GFX_EXPLODE_BFG
, cx
- 64, cy
- 64);
2627 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', Obj
.X
, Obj
.Y
);
2630 WEAPON_IMP_FIRE
, WEAPON_CACO_FIRE
, WEAPON_BARON_FIRE
: // Âûñòðåëû Áåñà, Êàêîäåìîíà Ðûöàðÿ/Áàðîíà àäà
2635 WEAPON_IMP_FIRE
: g_GFX_QueueEffect(R_GFX_EXPLODE_IMPFIRE
, cx
- 32, cy
- 32);
2636 WEAPON_CACO_FIRE
: g_GFX_QueueEffect(R_GFX_EXPLODE_CACOFIRE
, cx
- 32, cy
- 32);
2637 WEAPON_BARON_FIRE
: g_GFX_QueueEffect(R_GFX_EXPLODE_BARONFIRE
, cx
- 32, cy
- 32);
2639 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj
.X
, Obj
.Y
);
2643 WEAPON_MANCUB_FIRE
: // Âûñòðåë Ìàíêóáóñà
2645 g_GFX_QueueEffect(R_GFX_EXPLODE_ROCKET
, cx
- 64, cy
- 64);
2646 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj
.X
, Obj
.Y
);
2648 end; // case ShotType of...
2656 procedure g_Weapon_AddDynLights();
2660 if Shots
= nil then Exit
;
2661 for i
:= 0 to High(Shots
) do
2663 if Shots
[i
].ShotType
= 0 then continue
;
2664 if (Shots
[i
].ShotType
= WEAPON_ROCKETLAUNCHER
) or
2665 (Shots
[i
].ShotType
= WEAPON_BARON_FIRE
) or
2666 (Shots
[i
].ShotType
= WEAPON_MANCUB_FIRE
) or
2667 (Shots
[i
].ShotType
= WEAPON_SKEL_FIRE
) or
2668 (Shots
[i
].ShotType
= WEAPON_IMP_FIRE
) or
2669 (Shots
[i
].ShotType
= WEAPON_CACO_FIRE
) or
2670 (Shots
[i
].ShotType
= WEAPON_MANCUB_FIRE
) or
2671 (Shots
[i
].ShotType
= WEAPON_BSP_FIRE
) or
2672 (Shots
[i
].ShotType
= WEAPON_PLASMA
) or
2673 (Shots
[i
].ShotType
= WEAPON_BFG
) or
2674 (Shots
[i
].ShotType
= WEAPON_FLAMETHROWER
) or
2677 if (Shots
[i
].ShotType
= WEAPON_PLASMA
) then
2678 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)
2679 else if (Shots
[i
].ShotType
= WEAPON_BFG
) then
2680 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)
2681 else if (Shots
[i
].ShotType
= WEAPON_FLAMETHROWER
) then
2682 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)
2684 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);
2690 procedure TShot
.positionChanged (); begin end;