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
, e_graphics
, g_phys
, xprofiler
;
33 Animation
: TAnimation
;
38 procedure positionChanged (); //WARNING! call this after monster position was changed, or coldet will not work right!
43 Shots
: array of TShot
= nil;
44 LastShotID
: Integer = 0;
46 procedure g_Weapon_LoadData();
47 procedure g_Weapon_FreeData();
48 procedure g_Weapon_Init();
49 procedure g_Weapon_Free();
50 function g_Weapon_Hit(obj
: PObj
; d
: Integer; SpawnerUID
: Word; t
: Byte; HitCorpses
: Boolean = True): Byte;
51 function g_Weapon_HitUID(UID
: Word; d
: Integer; SpawnerUID
: Word; t
: Byte): Boolean;
52 function g_Weapon_CreateShot(I
: Integer; ShotType
: Byte; Spawner
, TargetUID
: Word; X
, Y
, XV
, YV
: Integer): LongWord;
54 procedure g_Weapon_gun(const x
, y
, xd
, yd
, v
, dmg
: Integer; SpawnerUID
: Word; CheckTrigger
: Boolean);
55 procedure g_Weapon_punch(x
, y
: Integer; d
, SpawnerUID
: Word);
56 function g_Weapon_chainsaw(x
, y
: Integer; d
, SpawnerUID
: Word): Integer;
57 procedure g_Weapon_rocket(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1; Silent
: Boolean = False);
58 procedure g_Weapon_revf(x
, y
, xd
, yd
: Integer; SpawnerUID
, TargetUID
: Word; WID
: Integer = -1; Silent
: Boolean = False);
59 procedure g_Weapon_flame(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1; Silent
: Boolean = False);
60 procedure g_Weapon_plasma(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1; Silent
: Boolean = False);
61 procedure g_Weapon_ball1(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1; Silent
: Boolean = False);
62 procedure g_Weapon_ball2(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1; Silent
: Boolean = False);
63 procedure g_Weapon_ball7(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1; Silent
: Boolean = False);
64 procedure g_Weapon_aplasma(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1; Silent
: Boolean = False);
65 procedure g_Weapon_manfire(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1; Silent
: Boolean = False);
66 procedure g_Weapon_bfgshot(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1; Silent
: Boolean = False);
67 procedure g_Weapon_bfghit(x
, y
: Integer);
68 procedure g_Weapon_pistol(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; Silent
: Boolean = False);
69 procedure g_Weapon_mgun(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; Silent
: Boolean = False);
70 procedure g_Weapon_shotgun(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; Silent
: Boolean = False);
71 procedure g_Weapon_dshotgun(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; Silent
: Boolean = False);
73 function g_Weapon_Explode(X
, Y
: Integer; rad
: Integer; SpawnerUID
: Word): Boolean;
74 procedure g_Weapon_BFG9000(X
, Y
: Integer; SpawnerUID
: Word);
75 procedure g_Weapon_PreUpdate();
76 procedure g_Weapon_Update();
77 procedure g_Weapon_Draw();
78 function g_Weapon_Danger(UID
: Word; X
, Y
: Integer; Width
, Height
: Word; Time
: Byte): Boolean;
79 procedure g_Weapon_DestroyShot(I
: Integer; X
, Y
: Integer; Loud
: Boolean = True);
81 procedure g_Weapon_SaveState (st
: TStream
);
82 procedure g_Weapon_LoadState (st
: TStream
);
84 procedure g_Weapon_AddDynLights();
93 WEAPON_ROCKETLAUNCHER
= 6;
96 WEAPON_SUPERPULEMET
= 9;
97 WEAPON_FLAMETHROWER
= 10;
98 WEAPON_ZOMBY_PISTOL
= 20;
100 WEAPON_BSP_FIRE
= 22;
101 WEAPON_CACO_FIRE
= 23;
102 WEAPON_BARON_FIRE
= 24;
103 WEAPON_MANCUB_FIRE
= 25;
104 WEAPON_SKEL_FIRE
= 26;
106 WP_FIRST
= WEAPON_KASTET
;
107 WP_LAST
= WEAPON_FLAMETHROWER
;
111 gwep_debug_fast_trace
: Boolean = true;
117 Math
, g_map
, g_player
, g_gfx
, g_sound
, g_main
, 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
;
131 SHOT_ROCKETLAUNCHER_WIDTH
= 14;
132 SHOT_ROCKETLAUNCHER_HEIGHT
= 14;
134 SHOT_SKELFIRE_WIDTH
= 14;
135 SHOT_SKELFIRE_HEIGHT
= 14;
137 SHOT_PLASMA_WIDTH
= 16;
138 SHOT_PLASMA_HEIGHT
= 16;
141 SHOT_BFG_HEIGHT
= 32;
142 SHOT_BFG_DAMAGE
= 100;
143 SHOT_BFG_RADIUS
= 256;
145 SHOT_FLAME_WIDTH
= 4;
146 SHOT_FLAME_HEIGHT
= 4;
147 SHOT_FLAME_LIFETIME
= 180;
149 SHOT_SIGNATURE
= $544F4853; // 'SHOT'
152 PHitTime
= ^THitTime
;
156 plridx
: Integer; // if mon=nil
160 TBinHeapKeyHitTime
= class
162 class function less (const a
, b
: Integer): Boolean; inline;
165 // indicies in `wgunHitTime` array
166 TBinaryHeapHitTimes
= specialize TBinaryHeapBase
<Integer, TBinHeapKeyHitTime
>;
169 WaterMap
: array of array of DWORD
= nil;
170 //wgunMonHash: THashIntInt = nil;
171 wgunHitHeap
: TBinaryHeapHitTimes
= nil;
172 wgunHitTime
: array of THitTime
= nil;
173 wgunHitTimeUsed
: Integer = 0;
176 class function TBinHeapKeyHitTime
.less (const a
, b
: Integer): Boolean;
180 hta
:= @wgunHitTime
[a
];
181 htb
:= @wgunHitTime
[b
];
182 if (hta
.distSq
<> htb
.distSq
) then begin result
:= (hta
.distSq
< htb
.distSq
); exit
; end;
183 if (hta
.mon
<> nil) then
186 if (htb
.mon
= nil) then begin result
:= false; exit
; end; // players first
187 result
:= (hta
.mon
.UID
< htb
.mon
.UID
); // why not?
192 if (htb
.mon
<> nil) then begin result
:= true; exit
; end; // players first
193 result
:= (hta
.plridx
< htb
.plridx
); // why not?
198 procedure appendHitTimeMon (adistSq
: Integer; amon
: TMonster
; ax
, ay
: Integer);
200 if (wgunHitTimeUsed
= Length(wgunHitTime
)) then SetLength(wgunHitTime
, wgunHitTimeUsed
+128);
201 with wgunHitTime
[wgunHitTimeUsed
] do
209 wgunHitHeap
.insert(wgunHitTimeUsed
);
210 Inc(wgunHitTimeUsed
);
214 procedure appendHitTimePlr (adistSq
: Integer; aplridx
: Integer; ax
, ay
: Integer);
216 if (wgunHitTimeUsed
= Length(wgunHitTime
)) then SetLength(wgunHitTime
, wgunHitTimeUsed
+128);
217 with wgunHitTime
[wgunHitTimeUsed
] do
225 wgunHitHeap
.insert(wgunHitTimeUsed
);
226 Inc(wgunHitTimeUsed
);
230 function FindShot(): DWORD
;
235 for i
:= 0 to High(Shots
) do
236 if Shots
[i
].ShotType
= 0 then
239 LastShotID
:= Result
;
245 SetLength(Shots
, 128);
250 Result
:= High(Shots
) + 1;
251 SetLength(Shots
, Length(Shots
) + 128);
253 LastShotID
:= Result
;
256 procedure CreateWaterMap();
258 WaterArray
: Array of TWaterPanel
;
265 SetLength(WaterArray
, Length(gWater
));
267 for a
:= 0 to High(gWater
) do
269 WaterArray
[a
].X
:= gWater
[a
].X
;
270 WaterArray
[a
].Y
:= gWater
[a
].Y
;
271 WaterArray
[a
].Width
:= gWater
[a
].Width
;
272 WaterArray
[a
].Height
:= gWater
[a
].Height
;
273 WaterArray
[a
].Active
:= True;
276 g_Game_SetLoadingText(_lc
[I_LOAD_WATER_MAP
], High(WaterArray
), False);
278 for a
:= 0 to High(WaterArray
) do
279 if WaterArray
[a
].Active
then
281 WaterArray
[a
].Active
:= False;
282 m
:= Length(WaterMap
);
283 SetLength(WaterMap
, m
+1);
284 SetLength(WaterMap
[m
], 1);
291 for b
:= 0 to High(WaterArray
) do
292 if WaterArray
[b
].Active
then
293 for c
:= 0 to High(WaterMap
[m
]) do
294 if g_CollideAround(WaterArray
[b
].X
,
297 WaterArray
[b
].Height
,
298 WaterArray
[WaterMap
[m
][c
]].X
,
299 WaterArray
[WaterMap
[m
][c
]].Y
,
300 WaterArray
[WaterMap
[m
][c
]].Width
,
301 WaterArray
[WaterMap
[m
][c
]].Height
) then
303 WaterArray
[b
].Active
:= False;
304 SetLength(WaterMap
[m
],
305 Length(WaterMap
[m
])+1);
306 WaterMap
[m
][High(WaterMap
[m
])] := b
;
312 g_Game_StepLoading();
320 chkTrap_pl
: array [0..256] of Integer;
321 chkTrap_mn
: array [0..65535] of TMonster
;
323 procedure CheckTrap(ID
: DWORD
; dm
: Integer; t
: Byte);
325 //a, b, c, d, i1, i2: Integer;
326 //chkTrap_pl, chkTrap_mn: WArray;
327 plaCount
: Integer = 0;
328 mnaCount
: Integer = 0;
332 function monsWaterCheck (mon: TMonster): Boolean;
334 result := false; // don't stop
335 if mon.alive and mon.Collide(gWater[WaterMap[a][c]]) and (not InWArray(monidx, chkTrap_mn)) and (i2 < 1023) then //FIXME
338 chkTrap_mn[i2] := monidx;
343 function monsWaterCheck (mon
: TMonster
): Boolean;
345 result
:= false; // don't stop
346 if (mon
.trapCheckFrameId
<> frameId
) then
348 mon
.trapCheckFrameId
:= frameId
;
349 chkTrap_mn
[mnaCount
] := mon
;
355 a
, b
, c
, d
, f
: Integer;
358 if (gWater
= nil) or (WaterMap
= nil) then Exit
;
360 frameId
:= g_Mons_getNewTrapFrameId();
365 //SetLength(chkTrap_pl, 1024);
366 //SetLength(chkTrap_mn, 1024);
367 //for d := 0 to 1023 do chkTrap_pl[d] := $FFFF;
368 //for d := 0 to 1023 do chkTrap_mn[d] := $FFFF;
370 for a
:= 0 to High(WaterMap
) do
372 for b
:= 0 to High(WaterMap
[a
]) do
374 pan
:= gWater
[WaterMap
[a
][b
]];
375 if not g_Obj_Collide(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, @Shots
[ID
].Obj
) then continue
;
377 for c
:= 0 to High(WaterMap
[a
]) do
379 pan
:= gWater
[WaterMap
[a
][c
]];
380 for d
:= 0 to High(gPlayers
) do
382 if (gPlayers
[d
] <> nil) and (gPlayers
[d
].alive
) then
384 if gPlayers
[d
].Collide(pan
) then
387 while (f
< plaCount
) and (chkTrap_pl
[f
] <> d
) do Inc(f
);
388 if (f
= plaCount
) then
390 chkTrap_pl
[plaCount
] := d
;
392 if (plaCount
= Length(chkTrap_pl
)) then break
;
398 //g_Mons_ForEach(monsWaterCheck);
399 g_Mons_ForEachAliveAt(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, monsWaterCheck
);
402 for f
:= 0 to plaCount
-1 do gPlayers
[chkTrap_pl
[f
]].Damage(dm
, Shots
[ID
].SpawnerUID
, 0, 0, t
);
403 for f
:= 0 to mnaCount
-1 do chkTrap_mn
[f
].Damage(dm
, 0, 0, Shots
[ID
].SpawnerUID
, t
);
411 function HitMonster(m
: TMonster
; d
: Integer; vx
, vy
: Integer; SpawnerUID
: Word; t
: Byte): Boolean;
418 tt
:= g_GetUIDType(SpawnerUID
);
419 if tt
= UID_MONSTER
then
421 mon
:= g_Monsters_ByUID(SpawnerUID
);
423 mt
:= g_Monsters_ByUID(SpawnerUID
).MonsterType
430 if m
= nil then Exit
;
431 if m
.UID
= SpawnerUID
then
433 // Ñàì ñåáÿ ìîæåò ðàíèòü òîëüêî ðàêåòîé è òîêîì:
434 if (t
<> HIT_ROCKET
) and (t
<> HIT_ELECTRO
) then
436 // Êèáåð äåìîí è áî÷êà âîîáùå íå ìîãóò ñåáÿ ðàíèòü:
437 if (m
.MonsterType
= MONSTER_CYBER
) or
438 (m
.MonsterType
= MONSTER_BARREL
) then
445 if tt
= UID_MONSTER
then
447 // Lost_Soul íå ìîæåò ðàíèòü Pain_Elemental'à:
448 if (mt
= MONSTER_SOUL
) and (m
.MonsterType
= MONSTER_PAIN
) then
451 // Îáà ìîíñòðà îäíîãî âèäà:
452 if mt
= m
.MonsterType
then
454 MONSTER_IMP
, MONSTER_DEMON
, MONSTER_BARON
, MONSTER_KNIGHT
, MONSTER_CACO
,
455 MONSTER_SOUL
, MONSTER_MANCUB
, MONSTER_SKEL
, MONSTER_FISH
:
456 Exit
; // Ýòè íå áüþò ñâîèõ
460 if g_Game_IsServer
then
462 if (t
<> HIT_FLAME
) or (m
.FFireTime
= 0) or (vx
<> 0) or (vy
<> 0) then
463 Result
:= m
.Damage(d
, vx
, vy
, SpawnerUID
, t
)
465 Result
:= (gLMSRespawn
= LMS_RESPAWN_NONE
); // don't hit monsters when it's warmup time
466 if t
= HIT_FLAME
then
467 m
.CatchFire(SpawnerUID
);
470 Result
:= (gLMSRespawn
= LMS_RESPAWN_NONE
); // don't hit monsters when it's warmup time
474 function HitPlayer (p
: TPlayer
; d
: Integer; vx
, vy
: Integer; SpawnerUID
: Word; t
: Byte): Boolean;
478 // Ñàì ñåáÿ ìîæåò ðàíèòü òîëüêî ðàêåòîé è òîêîì
479 if (p
.UID
= SpawnerUID
) and (t
<> HIT_ROCKET
) and (t
<> HIT_ELECTRO
) then exit
;
481 if g_Game_IsServer
then
483 if (t
<> HIT_FLAME
) or (p
.FFireTime
= 0) or (vx
<> 0) or (vy
<> 0) then p
.Damage(d
, SpawnerUID
, vx
, vy
, t
);
484 if (t
= HIT_FLAME
) then p
.CatchFire(SpawnerUID
);
491 procedure g_Weapon_BFG9000(X
, Y
: Integer; SpawnerUID
: Word);
493 function monsCheck (mon
: TMonster
): Boolean;
495 result
:= false; // don't stop
496 if (mon
.alive
) and (mon
.UID
<> SpawnerUID
) then
500 if (g_PatchLength(X
, Y
, Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2),
501 Obj
.Y
+Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2)) <= SHOT_BFG_RADIUS
) and
502 g_TraceVector(X
, Y
, Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2),
503 Obj
.Y
+Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2)) then
505 if HitMonster(mon
, 50, 0, 0, SpawnerUID
, HIT_SOME
) then mon
.BFGHit();
517 //g_Sound_PlayEx('SOUND_WEAPON_EXPLODEBFG', 255);
521 if gAdvCorpses
and (h
<> -1) then
523 if (gCorpses
[i
] <> nil) and (gCorpses
[i
].State
<> CORPSE_STATE_REMOVEME
) then
525 if (g_PatchLength(X
, Y
, Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2),
526 Obj
.Y
+Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2)) <= SHOT_BFG_RADIUS
) and
527 g_TraceVector(X
, Y
, Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2),
528 Obj
.Y
+Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2)) then
530 Damage(50, SpawnerUID
, 0, 0);
531 g_Weapon_BFGHit(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2),
532 Obj
.Y
+Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2));
536 pl
:= g_Player_Get(SpawnerUID
);
544 if (gPlayers
[i
] <> nil) and (gPlayers
[i
].alive
) and (gPlayers
[i
].UID
<> SpawnerUID
) then
546 if (g_PatchLength(X
, Y
, GameX
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
547 GameY
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)) <= SHOT_BFG_RADIUS
) and
548 g_TraceVector(X
, Y
, GameX
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
549 GameY
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)) then
551 if (st
= TEAM_NONE
) or (st
<> gPlayers
[i
].Team
) then
552 b
:= HitPlayer(gPlayers
[i
], 50, 0, 0, SpawnerUID
, HIT_SOME
)
554 b
:= HitPlayer(gPlayers
[i
], 25, 0, 0, SpawnerUID
, HIT_SOME
);
556 gPlayers
[i
].BFGHit();
560 g_Mons_ForEachAlive(monsCheck
);
563 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
;
590 g_Texture_Get('TEXTURE_WEAPON_ROCKET', TextureID
);
596 with Shots
[find_id
] do
600 Obj
.Rect
.Width
:= SHOT_PLASMA_WIDTH
;
601 Obj
.Rect
.Height
:= SHOT_PLASMA_HEIGHT
;
604 ShotType
:= WEAPON_PLASMA
;
605 g_Frames_Get(FramesID
, 'FRAMES_WEAPON_PLASMA');
606 Animation
:= TAnimation
.Create(FramesID
, True, 5);
612 with Shots
[find_id
] do
616 Obj
.Rect
.Width
:= SHOT_BFG_WIDTH
;
617 Obj
.Rect
.Height
:= SHOT_BFG_HEIGHT
;
620 ShotType
:= WEAPON_BFG
;
621 g_Frames_Get(FramesID
, 'FRAMES_WEAPON_BFG');
622 Animation
:= TAnimation
.Create(FramesID
, True, 6);
628 with Shots
[find_id
] do
632 Obj
.Rect
.Width
:= SHOT_FLAME_WIDTH
;
633 Obj
.Rect
.Height
:= SHOT_FLAME_HEIGHT
;
636 ShotType
:= WEAPON_FLAMETHROWER
;
639 g_Frames_Get(TextureID
, 'FRAMES_FLAME');
645 with Shots
[find_id
] do
649 Obj
.Rect
.Width
:= 16;
650 Obj
.Rect
.Height
:= 16;
653 ShotType
:= WEAPON_IMP_FIRE
;
654 g_Frames_Get(FramesID
, 'FRAMES_WEAPON_IMPFIRE');
655 Animation
:= TAnimation
.Create(FramesID
, True, 4);
661 with Shots
[find_id
] do
665 Obj
.Rect
.Width
:= 16;
666 Obj
.Rect
.Height
:= 16;
669 ShotType
:= WEAPON_CACO_FIRE
;
670 g_Frames_Get(FramesID
, 'FRAMES_WEAPON_CACOFIRE');
671 Animation
:= TAnimation
.Create(FramesID
, True, 4);
677 with Shots
[find_id
] do
681 Obj
.Rect
.Width
:= 32;
682 Obj
.Rect
.Height
:= 32;
685 ShotType
:= WEAPON_MANCUB_FIRE
;
686 g_Frames_Get(FramesID
, 'FRAMES_WEAPON_MANCUBFIRE');
687 Animation
:= TAnimation
.Create(FramesID
, True, 4);
693 with Shots
[find_id
] do
697 Obj
.Rect
.Width
:= 32;
698 Obj
.Rect
.Height
:= 16;
701 ShotType
:= WEAPON_BARON_FIRE
;
702 g_Frames_Get(FramesID
, 'FRAMES_WEAPON_BARONFIRE');
703 Animation
:= TAnimation
.Create(FramesID
, True, 4);
709 with Shots
[find_id
] do
713 Obj
.Rect
.Width
:= 16;
714 Obj
.Rect
.Height
:= 16;
717 ShotType
:= WEAPON_BSP_FIRE
;
718 g_Frames_Get(FramesID
, 'FRAMES_WEAPON_BSPFIRE');
719 Animation
:= TAnimation
.Create(FramesID
, True, 4);
725 with Shots
[find_id
] do
729 Obj
.Rect
.Width
:= SHOT_SKELFIRE_WIDTH
;
730 Obj
.Rect
.Height
:= SHOT_SKELFIRE_HEIGHT
;
733 ShotType
:= WEAPON_SKEL_FIRE
;
735 g_Frames_Get(FramesID
, 'FRAMES_WEAPON_SKELFIRE');
736 Animation
:= TAnimation
.Create(FramesID
, True, 5);
741 Shots
[find_id
].Obj
.oldX
:= X
;
742 Shots
[find_id
].Obj
.oldY
:= Y
;
743 Shots
[find_id
].Obj
.X
:= X
;
744 Shots
[find_id
].Obj
.Y
:= Y
;
745 Shots
[find_id
].Obj
.Vel
.X
:= XV
;
746 Shots
[find_id
].Obj
.Vel
.Y
:= YV
;
747 Shots
[find_id
].Obj
.Accel
.X
:= 0;
748 Shots
[find_id
].Obj
.Accel
.Y
:= 0;
749 Shots
[find_id
].SpawnerUID
:= Spawner
;
750 if (ShotType
= WEAPON_FLAMETHROWER
) and (XV
= 0) and (YV
= 0) then
751 Shots
[find_id
].Stopped
:= 255
753 Shots
[find_id
].Stopped
:= 0;
757 procedure throw(i
, x
, y
, xd
, yd
, s
: Integer);
764 a
:= Max(Abs(xd
), Abs(yd
));
768 Shots
[i
].Obj
.oldX
:= x
;
769 Shots
[i
].Obj
.oldY
:= y
;
772 Shots
[i
].Obj
.Vel
.X
:= (xd
*s
) div a
;
773 Shots
[i
].Obj
.Vel
.Y
:= (yd
*s
) div a
;
774 Shots
[i
].Obj
.Accel
.X
:= 0;
775 Shots
[i
].Obj
.Accel
.Y
:= 0;
776 Shots
[i
].Stopped
:= 0;
777 if Shots
[i
].ShotType
in [WEAPON_ROCKETLAUNCHER
, WEAPON_BFG
] then
778 Shots
[i
].Timeout
:= 900 // ~25 sec
781 if Shots
[i
].ShotType
= WEAPON_FLAMETHROWER
then
782 Shots
[i
].Timeout
:= SHOT_FLAME_LIFETIME
784 Shots
[i
].Timeout
:= 550; // ~15 sec
788 function g_Weapon_Hit(obj
: PObj
; d
: Integer; SpawnerUID
: Word; t
: Byte; HitCorpses
: Boolean = True): Byte;
792 function PlayerHit(Team
: Byte = 0): Boolean;
803 if (gPlayers
[i
] <> nil) and gPlayers
[i
].alive
and g_Obj_Collide(obj
, @gPlayers
[i
].Obj
) then
806 if (Team
> 0) and (g_GetUIDType(SpawnerUID
) = UID_PLAYER
) then
808 p
:= g_Player_Get(SpawnerUID
);
810 ChkTeam
:= (p
.Team
= gPlayers
[i
].Team
) xor (Team
= 2);
813 if HitPlayer(gPlayers
[i
], d
, obj
^.Vel
.X
, obj
^.Vel
.Y
, SpawnerUID
, t
) then
815 if t
<> HIT_FLAME
then
816 gPlayers
[i
].Push((obj
^.Vel
.X
+obj
^.Accel
.X
)*IfThen(t
= HIT_BFG
, 8, 1) div 4,
817 (obj
^.Vel
.Y
+obj
^.Accel
.Y
)*IfThen(t
= HIT_BFG
, 8, 1) div 4);
819 g_Game_DelayEvent(DE_BFGHIT
, 1000, SpawnerUID
);
827 function monsCheckHit (monidx: Integer; mon: TMonster): Boolean;
829 result := false; // don't stop
830 if mon.alive and g_Obj_Collide(obj, @mon.Obj) then
832 if HitMonster(mon, d, obj^.Vel.X, obj^.Vel.Y, SpawnerUID, t) then
834 if (t <> HIT_FLAME) then
836 mon.Push((obj^.Vel.X+obj^.Accel.X)*IfThen(t = HIT_BFG, 8, 1) div 4,
837 (obj^.Vel.Y+obj^.Accel.Y)*IfThen(t = HIT_BFG, 8, 1) div 4);
845 function monsCheckHit (mon
: TMonster
): Boolean;
847 result
:= false; // don't stop
848 if HitMonster(mon
, d
, obj
.Vel
.X
, obj
.Vel
.Y
, SpawnerUID
, t
) then
850 if (t
<> HIT_FLAME
) then
852 mon
.Push((obj
.Vel
.X
+obj
.Accel
.X
)*IfThen(t
= HIT_BFG
, 8, 1) div 4,
853 (obj
.Vel
.Y
+obj
.Accel
.Y
)*IfThen(t
= HIT_BFG
, 8, 1) div 4);
859 function MonsterHit(): Boolean;
861 //result := g_Mons_ForEach(monsCheckHit);
862 //FIXME: accelerate this!
863 result
:= g_Mons_ForEachAliveAt(obj
.X
+obj
.Rect
.X
, obj
.Y
+obj
.Rect
.Y
, obj
.Rect
.Width
, obj
.Rect
.Height
, monsCheckHit
);
873 if gAdvCorpses
and (h
<> -1) then
875 if (gCorpses
[i
] <> nil) and (gCorpses
[i
].State
<> CORPSE_STATE_REMOVEME
) and
876 g_Obj_Collide(obj
, @gCorpses
[i
].Obj
) then
879 gCorpses
[i
].Damage(d
, SpawnerUID
, (obj
^.Vel
.X
+obj
^.Accel
.X
) div 4,
880 (obj
^.Vel
.Y
+obj
^.Accel
.Y
) div 4);
885 case gGameSettings
.GameMode
of
889 // Ñíà÷àëà áü¸ì ìîíñòðîâ, åñëè åñòü, ïîòîì ïûòàåìñÿ áèòü èãðîêîâ
906 // Ñíà÷àëà áü¸ì èãðîêîâ, åñëè åñòü, ïîòîì ïûòàåìñÿ áèòü ìîíñòðîâ
923 // Ñíà÷àëà áü¸ì èãðîêîâ êîìàíäû ñîïåðíèêà
937 // È â êîíöå ñâîèõ èãðîêîâ
948 function g_Weapon_HitUID(UID
: Word; d
: Integer; SpawnerUID
: Word; t
: Byte): Boolean;
952 case g_GetUIDType(UID
) of
953 UID_PLAYER
: Result
:= HitPlayer(g_Player_Get(UID
), d
, 0, 0, SpawnerUID
, t
);
954 UID_MONSTER
: Result
:= HitMonster(g_Monsters_ByUID(UID
), d
, 0, 0, SpawnerUID
, t
);
959 function g_Weapon_Explode(X
, Y
: Integer; rad
: Integer; SpawnerUID
: Word): Boolean;
961 r
: Integer; // squared radius
963 function monsExCheck (mon
: TMonster
): Boolean;
967 result
:= false; // don't stop
969 dx
:= mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-X
;
970 dy
:= mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2)-Y
;
972 if dx
> 1000 then dx
:= 1000;
973 if dy
> 1000 then dy
:= 1000;
975 if (dx
*dx
+dy
*dy
< r
) then
977 //m := PointToRect(X, Y, Obj.X+Obj.Rect.X, Obj.Y+Obj.Rect.Y, Obj.Rect.Width, Obj.Rect.Height);
978 //e_WriteLog(Format('explo monster #%d: x=%d; y=%d; rad=%d; dx=%d; dy=%d', [monidx, X, Y, rad, dx, dy]), MSG_NOTIFY);
980 mm
:= Max(abs(dx
), abs(dy
));
981 if mm
= 0 then mm
:= 1;
985 HitMonster(mon
, ((mon
.Obj
.Rect
.Width
div 4)*10*(rad
-mm
)) div rad
, 0, 0, SpawnerUID
, HIT_ROCKET
);
988 mon
.Push((dx
*7) div mm
, (dy
*7) div mm
);
994 i
, h
, dx
, dy
, m
, mm
: Integer;
999 g_Triggers_PressC(X
, Y
, rad
, SpawnerUID
, ACTIVATE_SHOT
);
1003 h
:= High(gPlayers
);
1007 if (gPlayers
[i
] <> nil) and gPlayers
[i
].alive
then
1010 dx
:= Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)-X
;
1011 dy
:= Obj
.Y
+Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2)-Y
;
1013 if dx
> 1000 then dx
:= 1000;
1014 if dy
> 1000 then dy
:= 1000;
1016 if dx
*dx
+dy
*dy
< r
then
1018 //m := PointToRect(X, Y, GameX+PLAYER_RECT.X, GameY+PLAYER_RECT.Y,
1019 // PLAYER_RECT.Width, PLAYER_RECT.Height);
1021 mm
:= Max(abs(dx
), abs(dy
));
1022 if mm
= 0 then mm
:= 1;
1024 HitPlayer(gPlayers
[i
], (100*(rad
-mm
)) div rad
, (dx
*10) div mm
, (dy
*10) div mm
, SpawnerUID
, HIT_ROCKET
);
1025 gPlayers
[i
].Push((dx
*7) div mm
, (dy
*7) div mm
);
1029 //g_Mons_ForEach(monsExCheck);
1030 g_Mons_ForEachAt(X
-(rad
+32), Y
-(rad
+32), (rad
+32)*2, (rad
+32)*2, monsExCheck
);
1032 h
:= High(gCorpses
);
1034 if gAdvCorpses
and (h
<> -1) then
1036 if (gCorpses
[i
] <> nil) and (gCorpses
[i
].State
<> CORPSE_STATE_REMOVEME
) then
1039 dx
:= Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)-X
;
1040 dy
:= Obj
.Y
+Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2)-Y
;
1042 if dx
> 1000 then dx
:= 1000;
1043 if dy
> 1000 then dy
:= 1000;
1045 if dx
*dx
+dy
*dy
< r
then
1047 m
:= PointToRect(X
, Y
, Obj
.X
+Obj
.Rect
.X
, Obj
.Y
+Obj
.Rect
.Y
,
1048 Obj
.Rect
.Width
, Obj
.Rect
.Height
);
1050 mm
:= Max(abs(dx
), abs(dy
));
1051 if mm
= 0 then mm
:= 1;
1053 Damage(Round(100*(rad
-m
)/rad
), SpawnerUID
, (dx
*10) div mm
, (dy
*10) div mm
);
1059 if gAdvGibs
and (h
<> -1) then
1061 if gGibs
[i
].alive
then
1064 dx
:= Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)-X
;
1065 dy
:= Obj
.Y
+Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2)-Y
;
1067 if dx
> 1000 then dx
:= 1000;
1068 if dy
> 1000 then dy
:= 1000;
1070 if dx
*dx
+dy
*dy
< r
then
1072 m
:= PointToRect(X
, Y
, Obj
.X
+Obj
.Rect
.X
, Obj
.Y
+Obj
.Rect
.Y
,
1073 Obj
.Rect
.Width
, Obj
.Rect
.Height
);
1074 _angle
:= GetAngle(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2),
1075 Obj
.Y
+Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2), X
, Y
);
1077 g_Obj_PushA(@Obj
, Round(15*(rad
-m
)/rad
), _angle
);
1078 positionChanged(); // this updates spatial accelerators
1083 procedure g_Weapon_Init();
1088 procedure g_Weapon_Free();
1092 if Shots
<> nil then
1094 for i
:= 0 to High(Shots
) do
1095 if Shots
[i
].ShotType
<> 0 then
1096 Shots
[i
].Animation
.Free();
1104 procedure g_Weapon_LoadData();
1106 e_WriteLog('Loading weapons data...', TMsgType
.Notify
);
1108 g_Sound_CreateWADEx('SOUND_WEAPON_HITPUNCH', GameWAD
+':SOUNDS\HITPUNCH');
1109 g_Sound_CreateWADEx('SOUND_WEAPON_MISSPUNCH', GameWAD
+':SOUNDS\MISSPUNCH');
1110 g_Sound_CreateWADEx('SOUND_WEAPON_HITBERSERK', GameWAD
+':SOUNDS\HITBERSERK');
1111 g_Sound_CreateWADEx('SOUND_WEAPON_MISSBERSERK', GameWAD
+':SOUNDS\MISSBERSERK');
1112 g_Sound_CreateWADEx('SOUND_WEAPON_SELECTSAW', GameWAD
+':SOUNDS\SELECTSAW');
1113 g_Sound_CreateWADEx('SOUND_WEAPON_IDLESAW', GameWAD
+':SOUNDS\IDLESAW');
1114 g_Sound_CreateWADEx('SOUND_WEAPON_HITSAW', GameWAD
+':SOUNDS\HITSAW');
1115 g_Sound_CreateWADEx('SOUND_WEAPON_FIRESHOTGUN2', GameWAD
+':SOUNDS\FIRESHOTGUN2');
1116 g_Sound_CreateWADEx('SOUND_WEAPON_FIRESHOTGUN', GameWAD
+':SOUNDS\FIRESHOTGUN');
1117 g_Sound_CreateWADEx('SOUND_WEAPON_FIRESAW', GameWAD
+':SOUNDS\FIRESAW');
1118 g_Sound_CreateWADEx('SOUND_WEAPON_FIREROCKET', GameWAD
+':SOUNDS\FIREROCKET');
1119 g_Sound_CreateWADEx('SOUND_WEAPON_FIREPLASMA', GameWAD
+':SOUNDS\FIREPLASMA');
1120 g_Sound_CreateWADEx('SOUND_WEAPON_FIREPISTOL', GameWAD
+':SOUNDS\FIREPISTOL');
1121 g_Sound_CreateWADEx('SOUND_WEAPON_FIRECGUN', GameWAD
+':SOUNDS\FIRECGUN');
1122 g_Sound_CreateWADEx('SOUND_WEAPON_FIREBFG', GameWAD
+':SOUNDS\FIREBFG');
1123 g_Sound_CreateWADEx('SOUND_FIRE', GameWAD
+':SOUNDS\FIRE');
1124 g_Sound_CreateWADEx('SOUND_IGNITE', GameWAD
+':SOUNDS\IGNITE');
1125 g_Sound_CreateWADEx('SOUND_WEAPON_STARTFIREBFG', GameWAD
+':SOUNDS\STARTFIREBFG');
1126 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEROCKET', GameWAD
+':SOUNDS\EXPLODEROCKET');
1127 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEBFG', GameWAD
+':SOUNDS\EXPLODEBFG');
1128 g_Sound_CreateWADEx('SOUND_WEAPON_BFGWATER', GameWAD
+':SOUNDS\BFGWATER');
1129 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEPLASMA', GameWAD
+':SOUNDS\EXPLODEPLASMA');
1130 g_Sound_CreateWADEx('SOUND_WEAPON_PLASMAWATER', GameWAD
+':SOUNDS\PLASMAWATER');
1131 g_Sound_CreateWADEx('SOUND_WEAPON_FIREBALL', GameWAD
+':SOUNDS\FIREBALL');
1132 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEBALL', GameWAD
+':SOUNDS\EXPLODEBALL');
1133 g_Sound_CreateWADEx('SOUND_WEAPON_FIREREV', GameWAD
+':SOUNDS\FIREREV');
1134 g_Sound_CreateWADEx('SOUND_WEAPON_FLAMEON', GameWAD
+':SOUNDS\STARTFLM');
1135 g_Sound_CreateWADEx('SOUND_WEAPON_FLAMEOFF', GameWAD
+':SOUNDS\STOPFLM');
1136 g_Sound_CreateWADEx('SOUND_WEAPON_FLAMEWORK', GameWAD
+':SOUNDS\WORKFLM');
1137 g_Sound_CreateWADEx('SOUND_PLAYER_JETFLY', GameWAD
+':SOUNDS\WORKJETPACK');
1138 g_Sound_CreateWADEx('SOUND_PLAYER_JETON', GameWAD
+':SOUNDS\STARTJETPACK');
1139 g_Sound_CreateWADEx('SOUND_PLAYER_JETOFF', GameWAD
+':SOUNDS\STOPJETPACK');
1140 g_Sound_CreateWADEx('SOUND_PLAYER_CASING1', GameWAD
+':SOUNDS\CASING1');
1141 g_Sound_CreateWADEx('SOUND_PLAYER_CASING2', GameWAD
+':SOUNDS\CASING2');
1142 g_Sound_CreateWADEx('SOUND_PLAYER_SHELL1', GameWAD
+':SOUNDS\SHELL1');
1143 g_Sound_CreateWADEx('SOUND_PLAYER_SHELL2', GameWAD
+':SOUNDS\SHELL2');
1145 g_Texture_CreateWADEx('TEXTURE_WEAPON_ROCKET', GameWAD
+':TEXTURES\BROCKET');
1146 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_SKELFIRE', GameWAD
+':TEXTURES\BSKELFIRE', 64, 16, 2);
1147 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_BFG', GameWAD
+':TEXTURES\BBFG', 64, 64, 2);
1148 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_PLASMA', GameWAD
+':TEXTURES\BPLASMA', 16, 16, 2);
1149 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_IMPFIRE', GameWAD
+':TEXTURES\BIMPFIRE', 16, 16, 2);
1150 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_BSPFIRE', GameWAD
+':TEXTURES\BBSPFIRE', 16, 16, 2);
1151 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_CACOFIRE', GameWAD
+':TEXTURES\BCACOFIRE', 16, 16, 2);
1152 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_BARONFIRE', GameWAD
+':TEXTURES\BBARONFIRE', 64, 16, 2);
1153 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_MANCUBFIRE', GameWAD
+':TEXTURES\BMANCUBFIRE', 64, 32, 2);
1154 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_ROCKET', GameWAD
+':TEXTURES\EROCKET', 128, 128, 6);
1155 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_SKELFIRE', GameWAD
+':TEXTURES\ESKELFIRE', 64, 64, 3);
1156 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_BFG', GameWAD
+':TEXTURES\EBFG', 128, 128, 6);
1157 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_IMPFIRE', GameWAD
+':TEXTURES\EIMPFIRE', 64, 64, 3);
1158 g_Frames_CreateWAD(nil, 'FRAMES_BFGHIT', GameWAD
+':TEXTURES\BFGHIT', 64, 64, 4);
1159 g_Frames_CreateWAD(nil, 'FRAMES_FIRE', GameWAD
+':TEXTURES\FIRE', 64, 128, 8);
1160 g_Frames_CreateWAD(nil, 'FRAMES_FLAME', GameWAD
+':TEXTURES\FLAME', 32, 32, 11);
1161 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_PLASMA', GameWAD
+':TEXTURES\EPLASMA', 32, 32, 4, True);
1162 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_BSPFIRE', GameWAD
+':TEXTURES\EBSPFIRE', 32, 32, 5);
1163 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_CACOFIRE', GameWAD
+':TEXTURES\ECACOFIRE', 64, 64, 3);
1164 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_BARONFIRE', GameWAD
+':TEXTURES\EBARONFIRE', 64, 64, 3);
1165 g_Frames_CreateWAD(nil, 'FRAMES_SMOKE', GameWAD
+':TEXTURES\SMOKE', 32, 32, 10, False);
1167 g_Texture_CreateWADEx('TEXTURE_SHELL_BULLET', GameWAD
+':TEXTURES\EBULLET');
1168 g_Texture_CreateWADEx('TEXTURE_SHELL_SHELL', GameWAD
+':TEXTURES\ESHELL');
1170 //wgunMonHash := hashNewIntInt();
1171 wgunHitHeap
:= TBinaryHeapHitTimes
.Create();
1174 procedure g_Weapon_FreeData();
1176 e_WriteLog('Releasing weapons data...', TMsgType
.Notify
);
1178 g_Sound_Delete('SOUND_WEAPON_HITPUNCH');
1179 g_Sound_Delete('SOUND_WEAPON_MISSPUNCH');
1180 g_Sound_Delete('SOUND_WEAPON_HITBERSERK');
1181 g_Sound_Delete('SOUND_WEAPON_MISSBERSERK');
1182 g_Sound_Delete('SOUND_WEAPON_SELECTSAW');
1183 g_Sound_Delete('SOUND_WEAPON_IDLESAW');
1184 g_Sound_Delete('SOUND_WEAPON_HITSAW');
1185 g_Sound_Delete('SOUND_WEAPON_FIRESHOTGUN2');
1186 g_Sound_Delete('SOUND_WEAPON_FIRESHOTGUN');
1187 g_Sound_Delete('SOUND_WEAPON_FIRESAW');
1188 g_Sound_Delete('SOUND_WEAPON_FIREROCKET');
1189 g_Sound_Delete('SOUND_WEAPON_FIREPLASMA');
1190 g_Sound_Delete('SOUND_WEAPON_FIREPISTOL');
1191 g_Sound_Delete('SOUND_WEAPON_FIRECGUN');
1192 g_Sound_Delete('SOUND_WEAPON_FIREBFG');
1193 g_Sound_Delete('SOUND_FIRE');
1194 g_Sound_Delete('SOUND_IGNITE');
1195 g_Sound_Delete('SOUND_WEAPON_STARTFIREBFG');
1196 g_Sound_Delete('SOUND_WEAPON_EXPLODEROCKET');
1197 g_Sound_Delete('SOUND_WEAPON_EXPLODEBFG');
1198 g_Sound_Delete('SOUND_WEAPON_BFGWATER');
1199 g_Sound_Delete('SOUND_WEAPON_EXPLODEPLASMA');
1200 g_Sound_Delete('SOUND_WEAPON_PLASMAWATER');
1201 g_Sound_Delete('SOUND_WEAPON_FIREBALL');
1202 g_Sound_Delete('SOUND_WEAPON_EXPLODEBALL');
1203 g_Sound_Delete('SOUND_WEAPON_FIREREV');
1204 g_Sound_Delete('SOUND_WEAPON_FLAMEON');
1205 g_Sound_Delete('SOUND_WEAPON_FLAMEOFF');
1206 g_Sound_Delete('SOUND_WEAPON_FLAMEWORK');
1207 g_Sound_Delete('SOUND_PLAYER_JETFLY');
1208 g_Sound_Delete('SOUND_PLAYER_JETON');
1209 g_Sound_Delete('SOUND_PLAYER_JETOFF');
1210 g_Sound_Delete('SOUND_PLAYER_CASING1');
1211 g_Sound_Delete('SOUND_PLAYER_CASING2');
1212 g_Sound_Delete('SOUND_PLAYER_SHELL1');
1213 g_Sound_Delete('SOUND_PLAYER_SHELL2');
1215 g_Texture_Delete('TEXTURE_WEAPON_ROCKET');
1216 g_Frames_DeleteByName('FRAMES_WEAPON_BFG');
1217 g_Frames_DeleteByName('FRAMES_WEAPON_PLASMA');
1218 g_Frames_DeleteByName('FRAMES_WEAPON_IMPFIRE');
1219 g_Frames_DeleteByName('FRAMES_WEAPON_BSPFIRE');
1220 g_Frames_DeleteByName('FRAMES_WEAPON_CACOFIRE');
1221 g_Frames_DeleteByName('FRAMES_WEAPON_MANCUBFIRE');
1222 g_Frames_DeleteByName('FRAMES_EXPLODE_ROCKET');
1223 g_Frames_DeleteByName('FRAMES_EXPLODE_BFG');
1224 g_Frames_DeleteByName('FRAMES_EXPLODE_IMPFIRE');
1225 g_Frames_DeleteByName('FRAMES_BFGHIT');
1226 g_Frames_DeleteByName('FRAMES_FIRE');
1227 g_Frames_DeleteByName('FRAMES_EXPLODE_PLASMA');
1228 g_Frames_DeleteByName('FRAMES_EXPLODE_BSPFIRE');
1229 g_Frames_DeleteByName('FRAMES_EXPLODE_CACOFIRE');
1230 g_Frames_DeleteByName('FRAMES_SMOKE');
1231 g_Frames_DeleteByName('FRAMES_WEAPON_BARONFIRE');
1232 g_Frames_DeleteByName('FRAMES_EXPLODE_BARONFIRE');
1236 function GunHitPlayer (X
, Y
: Integer; vx
, vy
: Integer; dmg
: Integer; SpawnerUID
: Word; AllowPush
: Boolean): Boolean;
1241 for i
:= 0 to High(gPlayers
) do
1243 if (gPlayers
[i
] <> nil) and gPlayers
[i
].alive
and gPlayers
[i
].Collide(X
, Y
) then
1245 if HitPlayer(gPlayers
[i
], dmg
, vx
*10, vy
*10-3, SpawnerUID
, HIT_SOME
) then
1247 if AllowPush
then gPlayers
[i
].Push(vx
, vy
);
1255 function GunHit (X
, Y
: Integer; vx
, vy
: Integer; dmg
: Integer; SpawnerUID
: Word; AllowPush
: Boolean): Byte;
1257 function monsCheck (mon
: TMonster
): Boolean;
1259 result
:= false; // don't stop
1260 if HitMonster(mon
, dmg
, vx
*10, vy
*10-3, SpawnerUID
, HIT_SOME
) then
1262 if AllowPush
then mon
.Push(vx
, vy
);
1269 if GunHitPlayer(X
, Y
, vx
, vy
, dmg
, SpawnerUID
, AllowPush
) then result
:= 1
1270 else if g_Mons_ForEachAliveAt(X
, Y
, 1, 1, monsCheck
) then result
:= 2;
1275 procedure g_Weapon_gunOld(const x, y, xd, yd, v, dmg: Integer; SpawnerUID: Word; CheckTrigger: Boolean);
1286 t1, _collide: Boolean;
1288 {$IF DEFINED(D2F_DEBUG)}
1290 showTime: Boolean = true;
1293 a := GetAngle(x, y, xd, yd)+180;
1295 SinCos(DegToRad(-a), s, c);
1297 if Abs(s) < 0.01 then s := 0;
1298 if Abs(c) < 0.01 then c := 0;
1300 x2 := x+Round(c*gMapInfo.Width);
1301 y2 := y+Round(s*gMapInfo.Width);
1303 t1 := gWalls <> nil;
1305 w := gMapInfo.Width;
1306 h := gMapInfo.Height;
1313 if (xd = 0) and (yd = 0) then Exit;
1315 if dx > 0 then xi := 1 else if dx < 0 then xi := -1 else xi := 0;
1316 if dy > 0 then yi := 1 else if dy < 0 then yi := -1 else yi := 0;
1321 if dx > dy then d := dx else d := dy;
1323 //blood vel, for Monster.Damage()
1324 //vx := (dx*10 div d)*xi;
1325 //vy := (dy*10 div d)*yi;
1327 {$IF DEFINED(D2F_DEBUG)}
1328 stt := getTimeMicro();
1351 if (yy > h) or (yy < 0) then Break;
1352 if (xx > w) or (xx < 0) then Break;
1355 if ByteBool(gCollideMap[yy, xx] and MARK_BLOCKED) then
1358 {$IF DEFINED(D2F_DEBUG)}
1359 stt := getTimeMicro()-stt;
1360 e_WriteLog(Format('*** old trace time: %u microseconds', [LongWord(stt)]), MSG_NOTIFY);
1363 g_GFX_Spark(xx-xi, yy-yi, 2+Random(2), 180+a, 0, 0);
1364 if g_Game_IsServer and g_Game_IsNet then
1365 MH_SEND_Effect(xx-xi, yy-yi, 180+a, NET_GFX_SPARK);
1368 if not _collide then
1370 _collide := GunHit(xx, yy, xi*v, yi*v, dmg, SpawnerUID, v <> 0) <> 0;
1373 if _collide then Break;
1376 {$IF DEFINED(D2F_DEBUG)}
1379 stt := getTimeMicro()-stt;
1380 e_WriteLog(Format('*** old trace time: %u microseconds', [LongWord(stt)]), MSG_NOTIFY);
1384 if CheckTrigger and g_Game_IsServer then
1385 g_Triggers_PressL(X, Y, xx-xi, yy-yi, SpawnerUID, ACTIVATE_SHOT);
1391 procedure g_Weapon_gun (const x
, y
, xd
, yd
, v
, dmg
: Integer; SpawnerUID
: Word; CheckTrigger
: Boolean);
1396 wallDistSq
: Integer = $3fffffff;
1398 function doPlayerHit (idx
: Integer; hx
, hy
: Integer): Boolean;
1401 if (idx
< 0) or (idx
> High(gPlayers
)) then exit
;
1402 if (gPlayers
[idx
] = nil) or not gPlayers
[idx
].alive
then exit
;
1403 result
:= HitPlayer(gPlayers
[idx
], dmg
, (xi
*v
)*10, (yi
*v
)*10-3, SpawnerUID
, HIT_SOME
);
1404 if result
and (v
<> 0) then gPlayers
[idx
].Push((xi
*v
), (yi
*v
));
1405 {$IF DEFINED(D2F_DEBUG)}
1406 //if result then e_WriteLog(Format(' PLAYER #%d HIT', [idx]), MSG_NOTIFY);
1410 function doMonsterHit (mon
: TMonster
; hx
, hy
: Integer): Boolean;
1413 if (mon
= nil) then exit
;
1414 result
:= HitMonster(mon
, dmg
, (xi
*v
)*10, (yi
*v
)*10-3, SpawnerUID
, HIT_SOME
);
1415 if result
and (v
<> 0) then mon
.Push((xi
*v
), (yi
*v
));
1416 {$IF DEFINED(D2F_DEBUG)}
1417 //if result then e_WriteLog(Format(' MONSTER #%u HIT', [LongWord(mon.UID)]), MSG_NOTIFY);
1421 // collect players along hitray
1422 // return `true` if instant hit was detected
1423 function playerPossibleHit (): Boolean;
1426 px
, py
, pw
, ph
: Integer;
1432 for i
:= 0 to High(gPlayers
) do
1435 if (plr
<> nil) and plr
.alive
then
1437 plr
.getMapBox(px
, py
, pw
, ph
);
1438 if lineAABBIntersects(x
, y
, x2
, y2
, px
, py
, pw
, ph
, inx
, iny
) then
1440 distSq
:= distanceSq(x
, y
, inx
, iny
);
1441 if (distSq
= 0) then
1444 if doPlayerHit(i
, x
, y
) then begin result
:= true; exit
; end;
1446 else if (distSq
< wallDistSq
) then
1448 appendHitTimePlr(distSq
, i
, inx
, iny
);
1455 procedure sqchecker (mon
: TMonster
);
1457 mx
, my
, mw
, mh
: Integer;
1461 mon
.getMapBox(mx
, my
, mw
, mh
);
1462 if lineAABBIntersects(x0
, y0
, x2
, y2
, mx
, my
, mw
, mh
, inx
, iny
) then
1464 distSq
:= distanceSq(x0
, y0
, inx
, iny
);
1465 if (distSq
< wallDistSq
) then appendHitTimeMon(distSq
, mon
, inx
, iny
);
1475 wallHitFlag
: Boolean = false;
1476 wallHitX
: Integer = 0;
1477 wallHitY
: Integer = 0;
1478 didHit
: Boolean = false;
1479 {$IF DEFINED(D2F_DEBUG)}
1483 it
: TMonsterGrid
.Iter
;
1486 if not gwep_debug_fast_trace then
1488 g_Weapon_gunOld(x, y, xd, yd, v, dmg, SpawnerUID, CheckTrigger);
1493 if (xd
= 0) and (yd
= 0) then exit
;
1495 //wgunMonHash.reset(); //FIXME: clear hash on level change
1496 wgunHitHeap
.clear();
1497 wgunHitTimeUsed
:= 0;
1499 a
:= GetAngle(x
, y
, xd
, yd
)+180;
1501 SinCos(DegToRad(-a
), s
, c
);
1503 if Abs(s
) < 0.01 then s
:= 0;
1504 if Abs(c
) < 0.01 then c
:= 0;
1508 x2
:= x
+Round(c
*gMapInfo
.Width
);
1509 y2
:= y
+Round(s
*gMapInfo
.Width
);
1514 if (dx
> 0) then xi
:= 1 else if (dx
< 0) then xi
:= -1 else xi
:= 0;
1515 if (dy
> 0) then yi
:= 1 else if (dy
< 0) then yi
:= -1 else yi
:= 0;
1517 {$IF DEFINED(D2F_DEBUG)}
1518 e_WriteLog(Format('GUN TRACE: (%d,%d) to (%d,%d)', [x
, y
, x2
, y2
]), TMsgType
.Notify
);
1519 stt
:= getTimeMicro();
1522 wallHitFlag
:= (g_Map_traceToNearestWall(x
, y
, x2
, y2
, @wallHitX
, @wallHitY
) <> nil);
1527 wallDistSq
:= distanceSq(x
, y
, wallHitX
, wallHitY
);
1535 if playerPossibleHit() then exit
; // instant hit
1538 //g_Mons_AlongLine(x, y, x2, y2, sqchecker);
1540 it
:= monsGrid
.forEachAlongLine(x
, y
, x2
, y2
, -1);
1541 for mit
in it
do sqchecker(mit
^);
1544 // here, we collected all monsters and players in `wgunHitHeap` and `wgunHitTime`
1545 // also, if `wallWasHit` is `true`, then `wallHitX` and `wallHitY` contains spark coords
1546 while (wgunHitHeap
.count
> 0) do
1548 // has some entities to check, do it
1549 i
:= wgunHitHeap
.front
;
1550 wgunHitHeap
.popFront();
1552 xe
:= wgunHitTime
[i
].x
;
1553 ye
:= wgunHitTime
[i
].y
;
1554 // check if it is not behind the wall
1555 if (wgunHitTime
[i
].mon
<> nil) then
1557 didHit
:= doMonsterHit(wgunHitTime
[i
].mon
, xe
, ye
);
1561 didHit
:= doPlayerHit(wgunHitTime
[i
].plridx
, xe
, ye
);
1565 // need new coords for trigger
1568 wallHitFlag
:= false; // no sparks
1576 {$IF DEFINED(D2F_DEBUG)}
1577 stt
:= getTimeMicro()-stt
;
1578 e_WriteLog(Format('*** new trace time: %u microseconds', [LongWord(stt
)]), TMsgType
.Notify
);
1580 g_GFX_Spark(wallHitX
, wallHitY
, 2+Random(2), 180+a
, 0, 0);
1581 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Effect(wallHitX
, wallHitY
, 180+a
, NET_GFX_SPARK
);
1585 {$IF DEFINED(D2F_DEBUG)}
1586 stt
:= getTimeMicro()-stt
;
1587 e_WriteLog(Format('*** new trace time: %u microseconds', [LongWord(stt
)]), TMsgType
.Notify
);
1591 if CheckTrigger
and g_Game_IsServer
then g_Triggers_PressL(X
, Y
, wallHitX
, wallHitY
, SpawnerUID
, ACTIVATE_SHOT
);
1595 procedure g_Weapon_punch(x
, y
: Integer; d
, SpawnerUID
: Word);
1603 obj
.rect
.Width
:= 39;
1604 obj
.rect
.Height
:= 52;
1610 if g_Weapon_Hit(@obj
, d
, SpawnerUID
, HIT_SOME
) <> 0 then
1611 g_Sound_PlayExAt('SOUND_WEAPON_HITPUNCH', x
, y
)
1613 g_Sound_PlayExAt('SOUND_WEAPON_MISSPUNCH', x
, y
);
1616 function g_Weapon_chainsaw(x
, y
: Integer; d
, SpawnerUID
: Word): Integer;
1624 obj
.rect
.Width
:= 32;
1625 obj
.rect
.Height
:= 52;
1631 Result
:= g_Weapon_Hit(@obj
, d
, SpawnerUID
, HIT_SOME
);
1634 procedure g_Weapon_rocket(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1;
1635 Silent
: Boolean = False);
1641 find_id
:= FindShot()
1645 if Integer(find_id
) >= High(Shots
) then
1646 SetLength(Shots
, find_id
+ 64)
1649 with Shots
[find_id
] do
1653 Obj
.Rect
.Width
:= SHOT_ROCKETLAUNCHER_WIDTH
;
1654 Obj
.Rect
.Height
:= SHOT_ROCKETLAUNCHER_HEIGHT
;
1656 dx
:= IfThen(xd
> x
, -Obj
.Rect
.Width
, 0);
1657 dy
:= -(Obj
.Rect
.Height
div 2);
1659 ShotType
:= WEAPON_ROCKETLAUNCHER
;
1660 throw(find_id
, x
+dx
, y
+dy
, xd
+dx
, yd
+dy
, 12);
1664 g_Texture_Get('TEXTURE_WEAPON_ROCKET', TextureID
);
1667 Shots
[find_id
].SpawnerUID
:= SpawnerUID
;
1670 g_Sound_PlayExAt('SOUND_WEAPON_FIREROCKET', x
, y
);
1673 procedure g_Weapon_revf(x
, y
, xd
, yd
: Integer; SpawnerUID
, TargetUID
: Word;
1674 WID
: Integer = -1; Silent
: Boolean = False);
1676 find_id
, FramesID
: DWORD
;
1680 find_id
:= FindShot()
1684 if Integer(find_id
) >= High(Shots
) then
1685 SetLength(Shots
, find_id
+ 64)
1688 with Shots
[find_id
] do
1692 Obj
.Rect
.Width
:= SHOT_SKELFIRE_WIDTH
;
1693 Obj
.Rect
.Height
:= SHOT_SKELFIRE_HEIGHT
;
1695 dx
:= -(Obj
.Rect
.Width
div 2);
1696 dy
:= -(Obj
.Rect
.Height
div 2);
1698 ShotType
:= WEAPON_SKEL_FIRE
;
1699 throw(find_id
, x
+dx
, y
+dy
, xd
+dx
, yd
+dy
, 12);
1702 target
:= TargetUID
;
1703 g_Frames_Get(FramesID
, 'FRAMES_WEAPON_SKELFIRE');
1704 Animation
:= TAnimation
.Create(FramesID
, True, 5);
1707 Shots
[find_id
].SpawnerUID
:= SpawnerUID
;
1710 g_Sound_PlayExAt('SOUND_WEAPON_FIREREV', x
, y
);
1713 procedure g_Weapon_plasma(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1;
1714 Silent
: Boolean = False);
1716 find_id
, FramesID
: DWORD
;
1720 find_id
:= FindShot()
1724 if Integer(find_id
) >= High(Shots
) then
1725 SetLength(Shots
, find_id
+ 64);
1728 with Shots
[find_id
] do
1732 Obj
.Rect
.Width
:= SHOT_PLASMA_WIDTH
;
1733 Obj
.Rect
.Height
:= SHOT_PLASMA_HEIGHT
;
1735 dx
:= IfThen(xd
>x
, -Obj
.Rect
.Width
, 0);
1736 dy
:= -(Obj
.Rect
.Height
div 2);
1738 ShotType
:= WEAPON_PLASMA
;
1739 throw(find_id
, x
+dx
, y
+dy
, xd
+dx
, yd
+dy
, 16);
1742 g_Frames_Get(FramesID
, 'FRAMES_WEAPON_PLASMA');
1743 Animation
:= TAnimation
.Create(FramesID
, True, 5);
1746 Shots
[find_id
].SpawnerUID
:= SpawnerUID
;
1749 g_Sound_PlayExAt('SOUND_WEAPON_FIREPLASMA', x
, y
);
1752 procedure g_Weapon_flame(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1;
1753 Silent
: Boolean = False);
1759 find_id
:= FindShot()
1763 if Integer(find_id
) >= High(Shots
) then
1764 SetLength(Shots
, find_id
+ 64);
1767 with Shots
[find_id
] do
1771 Obj
.Rect
.Width
:= SHOT_FLAME_WIDTH
;
1772 Obj
.Rect
.Height
:= SHOT_FLAME_HEIGHT
;
1774 dx
:= IfThen(xd
>x
, -Obj
.Rect
.Width
, 0);
1775 dy
:= -(Obj
.Rect
.Height
div 2);
1777 ShotType
:= WEAPON_FLAMETHROWER
;
1778 throw(find_id
, x
+dx
, y
+dy
, xd
+dx
, yd
+dy
, 16);
1783 g_Frames_Get(TextureID
, 'FRAMES_FLAME');
1786 Shots
[find_id
].SpawnerUID
:= SpawnerUID
;
1788 // if not Silent then
1789 // g_Sound_PlayExAt('SOUND_WEAPON_FIREPLASMA', x, y);
1792 procedure g_Weapon_ball1(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1;
1793 Silent
: Boolean = False);
1795 find_id
, FramesID
: DWORD
;
1799 find_id
:= FindShot()
1803 if Integer(find_id
) >= High(Shots
) then
1804 SetLength(Shots
, find_id
+ 64)
1807 with Shots
[find_id
] do
1811 Obj
.Rect
.Width
:= 16;
1812 Obj
.Rect
.Height
:= 16;
1814 dx
:= IfThen(xd
>x
, -Obj
.Rect
.Width
, 0);
1815 dy
:= -(Obj
.Rect
.Height
div 2);
1817 ShotType
:= WEAPON_IMP_FIRE
;
1818 throw(find_id
, x
+dx
, y
+dy
, xd
+dx
, yd
+dy
, 16);
1821 g_Frames_Get(FramesID
, 'FRAMES_WEAPON_IMPFIRE');
1822 Animation
:= TAnimation
.Create(FramesID
, True, 4);
1825 Shots
[find_id
].SpawnerUID
:= SpawnerUID
;
1828 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x
, y
);
1831 procedure g_Weapon_ball2(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1;
1832 Silent
: Boolean = False);
1834 find_id
, FramesID
: DWORD
;
1838 find_id
:= FindShot()
1842 if Integer(find_id
) >= High(Shots
) then
1843 SetLength(Shots
, find_id
+ 64)
1846 with Shots
[find_id
] do
1850 Obj
.Rect
.Width
:= 16;
1851 Obj
.Rect
.Height
:= 16;
1853 dx
:= IfThen(xd
>x
, -Obj
.Rect
.Width
, 0);
1854 dy
:= -(Obj
.Rect
.Height
div 2);
1856 ShotType
:= WEAPON_CACO_FIRE
;
1857 throw(find_id
, x
+dx
, y
+dy
, xd
+dx
, yd
+dy
, 16);
1860 g_Frames_Get(FramesID
, 'FRAMES_WEAPON_CACOFIRE');
1861 Animation
:= TAnimation
.Create(FramesID
, True, 4);
1864 Shots
[find_id
].SpawnerUID
:= SpawnerUID
;
1867 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x
, y
);
1870 procedure g_Weapon_ball7(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1;
1871 Silent
: Boolean = False);
1873 find_id
, FramesID
: DWORD
;
1877 find_id
:= FindShot()
1881 if Integer(find_id
) >= High(Shots
) then
1882 SetLength(Shots
, find_id
+ 64)
1885 with Shots
[find_id
] do
1889 Obj
.Rect
.Width
:= 32;
1890 Obj
.Rect
.Height
:= 16;
1892 dx
:= IfThen(xd
>x
, -Obj
.Rect
.Width
, 0);
1893 dy
:= -(Obj
.Rect
.Height
div 2);
1895 ShotType
:= WEAPON_BARON_FIRE
;
1896 throw(find_id
, x
+dx
, y
+dy
, xd
+dx
, yd
+dy
, 16);
1899 g_Frames_Get(FramesID
, 'FRAMES_WEAPON_BARONFIRE');
1900 Animation
:= TAnimation
.Create(FramesID
, True, 4);
1903 Shots
[find_id
].SpawnerUID
:= SpawnerUID
;
1906 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x
, y
);
1909 procedure g_Weapon_aplasma(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1;
1910 Silent
: Boolean = False);
1912 find_id
, FramesID
: DWORD
;
1916 find_id
:= FindShot()
1920 if Integer(find_id
) >= High(Shots
) then
1921 SetLength(Shots
, find_id
+ 64)
1924 with Shots
[find_id
] do
1928 Obj
.Rect
.Width
:= 16;
1929 Obj
.Rect
.Height
:= 16;
1931 dx
:= IfThen(xd
>x
, -Obj
.Rect
.Width
, 0);
1932 dy
:= -(Obj
.Rect
.Height
div 2);
1934 ShotType
:= WEAPON_BSP_FIRE
;
1935 throw(find_id
, x
+dx
, y
+dy
, xd
+dx
, yd
+dy
, 16);
1939 g_Frames_Get(FramesID
, 'FRAMES_WEAPON_BSPFIRE');
1940 Animation
:= TAnimation
.Create(FramesID
, True, 4);
1943 Shots
[find_id
].SpawnerUID
:= SpawnerUID
;
1946 g_Sound_PlayExAt('SOUND_WEAPON_FIREPLASMA', x
, y
);
1949 procedure g_Weapon_manfire(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1;
1950 Silent
: Boolean = False);
1952 find_id
, FramesID
: DWORD
;
1956 find_id
:= FindShot()
1960 if Integer(find_id
) >= High(Shots
) then
1961 SetLength(Shots
, find_id
+ 64)
1964 with Shots
[find_id
] do
1968 Obj
.Rect
.Width
:= 32;
1969 Obj
.Rect
.Height
:= 32;
1971 dx
:= IfThen(xd
>x
, -Obj
.Rect
.Width
, 0);
1972 dy
:= -(Obj
.Rect
.Height
div 2);
1974 ShotType
:= WEAPON_MANCUB_FIRE
;
1975 throw(find_id
, x
+dx
, y
+dy
, xd
+dx
, yd
+dy
, 16);
1979 g_Frames_Get(FramesID
, 'FRAMES_WEAPON_MANCUBFIRE');
1980 Animation
:= TAnimation
.Create(FramesID
, True, 4);
1983 Shots
[find_id
].SpawnerUID
:= SpawnerUID
;
1986 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x
, y
);
1989 procedure g_Weapon_bfgshot(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1;
1990 Silent
: Boolean = False);
1992 find_id
, FramesID
: DWORD
;
1996 find_id
:= FindShot()
2000 if Integer(find_id
) >= High(Shots
) then
2001 SetLength(Shots
, find_id
+ 64)
2004 with Shots
[find_id
] do
2008 Obj
.Rect
.Width
:= SHOT_BFG_WIDTH
;
2009 Obj
.Rect
.Height
:= SHOT_BFG_HEIGHT
;
2011 dx
:= IfThen(xd
>x
, -Obj
.Rect
.Width
, 0);
2012 dy
:= -(Obj
.Rect
.Height
div 2);
2014 ShotType
:= WEAPON_BFG
;
2015 throw(find_id
, x
+dx
, y
+dy
, xd
+dx
, yd
+dy
, 16);
2018 g_Frames_Get(FramesID
, 'FRAMES_WEAPON_BFG');
2019 Animation
:= TAnimation
.Create(FramesID
, True, 6);
2022 Shots
[find_id
].SpawnerUID
:= SpawnerUID
;
2025 g_Sound_PlayExAt('SOUND_WEAPON_FIREBFG', x
, y
);
2028 procedure g_Weapon_bfghit(x
, y
: Integer);
2033 if g_Frames_Get(ID
, 'FRAMES_BFGHIT') then
2035 Anim
:= TAnimation
.Create(ID
, False, 4);
2036 g_GFX_OnceAnim(x
-32, y
-32, Anim
);
2041 procedure g_Weapon_pistol(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word;
2042 Silent
: Boolean = False);
2045 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', x
, y
);
2047 g_Weapon_gun(x
, y
, xd
, yd
, 1, 3, SpawnerUID
, True);
2048 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
] then
2050 g_Weapon_gun(x
, y
+1, xd
, yd
+1, 1, 3, SpawnerUID
, False);
2051 g_Weapon_gun(x
, y
-1, xd
, yd
-1, 1, 2, SpawnerUID
, False);
2055 procedure g_Weapon_mgun(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word;
2056 Silent
: Boolean = False);
2059 if gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', x
, y
);
2061 g_Weapon_gun(x
, y
, xd
, yd
, 1, 3, SpawnerUID
, True);
2062 if (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) and
2063 (g_GetUIDType(SpawnerUID
) = UID_PLAYER
) then
2065 g_Weapon_gun(x
, y
+1, xd
, yd
+1, 1, 2, SpawnerUID
, False);
2066 g_Weapon_gun(x
, y
-1, xd
, yd
-1, 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
);
2080 j
:= Random(17)-8; // -8 .. 8
2081 g_Weapon_gun(x
, y
+j
, xd
, yd
+j
, IfThen(i
mod 2 <> 0, 1, 0), 3, SpawnerUID
, i
=0);
2085 procedure g_Weapon_dshotgun(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word;
2086 Silent
: Boolean = False);
2091 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', x
, y
);
2093 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
] then a
:= 25 else a
:= 20;
2096 j
:= Random(41)-20; // -20 .. 20
2097 g_Weapon_gun(x
, y
+j
, xd
, yd
+j
, IfThen(i
mod 3 <> 0, 0, 1), 3, SpawnerUID
, i
=0);
2101 procedure g_Weapon_PreUpdate();
2105 if Shots
= nil then Exit
;
2106 for i
:= 0 to High(Shots
) do
2107 if Shots
[i
].ShotType
<> 0 then
2109 Shots
[i
].Obj
.oldX
:= Shots
[i
].Obj
.X
;
2110 Shots
[i
].Obj
.oldY
:= Shots
[i
].Obj
.Y
;
2114 procedure g_Weapon_Update();
2116 i
, a
, h
, cx
, cy
, oldvx
, oldvy
, tf
: Integer;
2130 for i
:= 0 to High(Shots
) do
2132 if Shots
[i
].ShotType
= 0 then
2139 Timeout
:= Timeout
- 1;
2142 // Àêòèâèðîâàòü òðèããåðû ïî ïóòè (êðîìå óæå àêòèâèðîâàííûõ):
2143 if (Stopped
= 0) and g_Game_IsServer
then
2144 t
:= g_Triggers_PressR(Obj
.X
, Obj
.Y
, Obj
.Rect
.Width
, Obj
.Rect
.Height
,
2145 SpawnerUID
, ACTIVATE_SHOT
, triggers
)
2151 // Ïîïîëíÿåì ñïèñîê àêòèâèðîâàííûõ òðèããåðîâ:
2152 if triggers
= nil then
2159 if not InDWArray(t
[a
], triggers
) then
2161 SetLength(triggers
, Length(triggers
)+1);
2162 triggers
[High(triggers
)] := t
[a
];
2167 // Àíèìàöèÿ ñíàðÿäà:
2168 if Animation
<> nil then
2172 spl
:= (ShotType
<> WEAPON_PLASMA
) and
2173 (ShotType
<> WEAPON_BFG
) and
2174 (ShotType
<> WEAPON_BSP_FIRE
) and
2175 (ShotType
<> WEAPON_FLAMETHROWER
);
2179 st
:= g_Obj_Move_Projectile(@Obj
, False, spl
);
2185 positionChanged(); // this updates spatial accelerators
2187 if WordBool(st
and MOVE_FALLOUT
) or (Obj
.X
< -1000) or
2188 (Obj
.X
> gMapInfo
.Width
+1000) or (Obj
.Y
< -1000) then
2190 // Íà êëèåíòå ñêîðåå âñåãî è òàê óæå âûïàë.
2196 cx
:= Obj
.X
+ (Obj
.Rect
.Width
div 2);
2197 cy
:= Obj
.Y
+ (Obj
.Rect
.Height
div 2);
2200 WEAPON_ROCKETLAUNCHER
, WEAPON_SKEL_FIRE
: // Ðàêåòû è ñíàðÿäû Ñêåëåòà
2202 // Âûëåòåëà èç âîäû:
2203 if WordBool(st
and MOVE_HITAIR
) then
2204 g_Obj_SetSpeed(@Obj
, 12);
2206 // Â âîäå øëåéô - ïóçûðè, â âîçäóõå øëåéô - äûì:
2207 if WordBool(st
and MOVE_INWATER
) then
2208 g_GFX_Bubbles(Obj
.X
+(Obj
.Rect
.Width
div 2),
2209 Obj
.Y
+(Obj
.Rect
.Height
div 2),
2210 1+Random(3), 16, 16)
2212 if g_Frames_Get(_id
, 'FRAMES_SMOKE') then
2214 Anim
:= TAnimation
.Create(_id
, False, 3);
2216 g_GFX_OnceAnim(Obj
.X
-14+Random(9),
2217 Obj
.Y
+(Obj
.Rect
.Height
div 2)-20+Random(9),
2218 Anim
, ONCEANIM_SMOKE
);
2222 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2223 if WordBool(st
and (MOVE_HITWALL
or MOVE_HITLAND
or MOVE_HITCEIL
)) or
2224 (g_Weapon_Hit(@Obj
, 10, SpawnerUID
, HIT_SOME
, False) <> 0) or
2230 g_Weapon_Explode(cx
, cy
, 60, SpawnerUID
);
2232 if ShotType
= WEAPON_SKEL_FIRE
then
2233 begin // Âçðûâ ñíàðÿäà Ñêåëåòà
2234 if g_Frames_Get(TextureID
, 'FRAMES_EXPLODE_SKELFIRE') then
2236 Anim
:= TAnimation
.Create(TextureID
, False, 8);
2237 Anim
.Blending
:= False;
2238 g_GFX_OnceAnim((Obj
.X
+32)-58, (Obj
.Y
+8)-36, Anim
);
2239 g_DynLightExplosion((Obj
.X
+32), (Obj
.Y
+8), 64, 1, 0, 0);
2244 begin // Âçðûâ Ðàêåòû
2245 if g_Frames_Get(TextureID
, 'FRAMES_EXPLODE_ROCKET') then
2247 Anim
:= TAnimation
.Create(TextureID
, False, 6);
2248 Anim
.Blending
:= False;
2249 g_GFX_OnceAnim(cx
-64, cy
-64, Anim
);
2250 g_DynLightExplosion(cx
, cy
, 64, 1, 0, 0);
2255 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', Obj
.X
, Obj
.Y
);
2260 if ShotType
= WEAPON_SKEL_FIRE
then
2261 begin // Ñàìîíàâîäêà ñíàðÿäà Ñêåëåòà:
2262 if GetPos(target
, @o
) then
2263 throw(i
, Obj
.X
, Obj
.Y
,
2264 o
.X
+o
.Rect
.X
+(o
.Rect
.Width
div 2)+o
.Vel
.X
+o
.Accel
.X
,
2265 o
.Y
+o
.Rect
.Y
+(o
.Rect
.Height
div 2)+o
.Vel
.Y
+o
.Accel
.Y
,
2270 WEAPON_PLASMA
, WEAPON_BSP_FIRE
: // Ïëàçìà, ïëàçìà Àðàõíàòðîíà
2272 // Ïîïàëà â âîäó - ýëåêòðîøîê ïî âîäå:
2273 if WordBool(st
and (MOVE_INWATER
or MOVE_HITWATER
)) then
2275 g_Sound_PlayExAt('SOUND_WEAPON_PLASMAWATER', Obj
.X
, Obj
.Y
);
2276 if g_Game_IsServer
then CheckTrap(i
, 10, HIT_ELECTRO
);
2282 if (ShotType
= WEAPON_PLASMA
) and
2283 (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) then
2288 if ShotType
= WEAPON_BSP_FIRE
then
2291 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2292 if WordBool(st
and (MOVE_HITWALL
or MOVE_HITLAND
or MOVE_HITCEIL
)) or
2293 (g_Weapon_Hit(@Obj
, a
, SpawnerUID
, HIT_SOME
, False) <> 0) or
2296 if ShotType
= WEAPON_PLASMA
then
2297 s
:= 'FRAMES_EXPLODE_PLASMA'
2299 s
:= 'FRAMES_EXPLODE_BSPFIRE';
2302 if g_Frames_Get(TextureID
, s
) then
2304 Anim
:= TAnimation
.Create(TextureID
, False, 3);
2305 Anim
.Blending
:= False;
2306 g_GFX_OnceAnim(cx
-16, cy
-16, Anim
);
2308 g_DynLightExplosion(cx
, cy
, 32, 0, 0.5, 0.5);
2311 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEPLASMA', Obj
.X
, Obj
.Y
);
2317 WEAPON_FLAMETHROWER
: // Îãíåìåò
2319 // Ñî âðåìåíåì óìèðàåò
2320 if (Timeout
< 1) then
2326 if WordBool(st
and (MOVE_HITWATER
or MOVE_INWATER
)) then
2328 if WordBool(st
and MOVE_HITWATER
) then
2330 if g_Frames_Get(_id
, 'FRAMES_SMOKE') then
2332 Anim
:= TAnimation
.Create(_id
, False, 3);
2336 g_GFX_OnceAnim(cx
-4+tcx
-(Anim
.Width
div 2),
2337 cy
-4+tcy
-(Anim
.Height
div 2),
2338 Anim
, ONCEANIM_SMOKE
);
2343 g_GFX_Bubbles(cx
, cy
, 1+Random(3), 16, 16);
2350 Obj
.Accel
.Y
:= Obj
.Accel
.Y
+ 1;
2351 // Ïîïàëè â ñòåíó èëè â âîäó:
2352 if WordBool(st
and (MOVE_HITWALL
or MOVE_HITLAND
or MOVE_HITCEIL
or MOVE_HITWATER
)) then
2358 if WordBool(st
and MOVE_HITWALL
) then
2359 Stopped
:= MOVE_HITWALL
2360 else if WordBool(st
and MOVE_HITLAND
) then
2361 Stopped
:= MOVE_HITLAND
2362 else if WordBool(st
and MOVE_HITCEIL
) then
2363 Stopped
:= MOVE_HITCEIL
;
2366 a
:= IfThen(Stopped
= 0, 10, 1);
2367 // Åñëè â êîãî-òî ïîïàëè
2368 if g_Weapon_Hit(@Obj
, a
, SpawnerUID
, HIT_FLAME
, False) <> 0 then
2370 // HIT_FLAME ñàì ïîäîææåò
2371 // Åñëè â ïîëåòå ïîïàëè, èñ÷åçàåì
2381 if (gTime
mod LongWord(tf
) = 0) then
2383 Anim
:= TAnimation
.Create(TextureID
, False, 2 + Random(2));
2386 MOVE_HITWALL
: begin tcx
:= cx
-4+Random(8); tcy
:= cy
-12+Random(24); end;
2387 MOVE_HITLAND
: begin tcx
:= cx
-12+Random(24); tcy
:= cy
-10+Random(8); end;
2388 MOVE_HITCEIL
: begin tcx
:= cx
-12+Random(24); tcy
:= cy
+6+Random(8); end;
2389 else begin tcx
:= cx
-4+Random(8); tcy
:= cy
-4+Random(8); end;
2391 g_GFX_OnceAnim(tcx
-(Anim
.Width
div 2), tcy
-(Anim
.Height
div 2), Anim
, ONCEANIM_SMOKE
);
2393 //g_DynLightExplosion(tcx, tcy, 1, 1, 0.8, 0.3);
2399 // Ïîïàëà â âîäó - ýëåêòðîøîê ïî âîäå:
2400 if WordBool(st
and (MOVE_INWATER
or MOVE_HITWATER
)) then
2402 g_Sound_PlayExAt('SOUND_WEAPON_BFGWATER', Obj
.X
, Obj
.Y
);
2403 if g_Game_IsServer
then CheckTrap(i
, 1000, HIT_ELECTRO
);
2408 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2409 if WordBool(st
and (MOVE_HITWALL
or MOVE_HITLAND
or MOVE_HITCEIL
)) or
2410 (g_Weapon_Hit(@Obj
, SHOT_BFG_DAMAGE
, SpawnerUID
, HIT_BFG
, False) <> 0) or
2414 if g_Game_IsServer
then g_Weapon_BFG9000(cx
, cy
, SpawnerUID
);
2417 if g_Frames_Get(TextureID
, 'FRAMES_EXPLODE_BFG') then
2419 Anim
:= TAnimation
.Create(TextureID
, False, 6);
2420 Anim
.Blending
:= False;
2421 g_GFX_OnceAnim(cx
-64, cy
-64, Anim
);
2423 g_DynLightExplosion(cx
, cy
, 96, 0, 1, 0);
2426 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', Obj
.X
, Obj
.Y
);
2432 WEAPON_IMP_FIRE
, WEAPON_CACO_FIRE
, WEAPON_BARON_FIRE
: // Âûñòðåëû Áåñà, Êàêîäåìîíà Ðûöàðÿ/Áàðîíà àäà
2435 if WordBool(st
and MOVE_HITAIR
) then
2436 g_Obj_SetSpeed(@Obj
, 16);
2439 if ShotType
= WEAPON_IMP_FIRE
then
2442 if ShotType
= WEAPON_CACO_FIRE
then
2447 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2448 if WordBool(st
and (MOVE_HITWALL
or MOVE_HITLAND
or MOVE_HITCEIL
)) or
2449 (g_Weapon_Hit(@Obj
, a
, SpawnerUID
, HIT_SOME
) <> 0) or
2452 if ShotType
= WEAPON_IMP_FIRE
then
2453 s
:= 'FRAMES_EXPLODE_IMPFIRE'
2455 if ShotType
= WEAPON_CACO_FIRE
then
2456 s
:= 'FRAMES_EXPLODE_CACOFIRE'
2458 s
:= 'FRAMES_EXPLODE_BARONFIRE';
2461 if g_Frames_Get(TextureID
, s
) then
2463 Anim
:= TAnimation
.Create(TextureID
, False, 6);
2464 Anim
.Blending
:= False;
2465 g_GFX_OnceAnim(cx
-32, cy
-32, Anim
);
2469 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj
.X
, Obj
.Y
);
2475 WEAPON_MANCUB_FIRE
: // Âûñòðåë Ìàíêóáóñà
2478 if WordBool(st
and MOVE_HITAIR
) then
2479 g_Obj_SetSpeed(@Obj
, 16);
2481 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2482 if WordBool(st
and (MOVE_HITWALL
or MOVE_HITLAND
or MOVE_HITCEIL
)) or
2483 (g_Weapon_Hit(@Obj
, 40, SpawnerUID
, HIT_SOME
, False) <> 0) or
2487 if g_Frames_Get(TextureID
, 'FRAMES_EXPLODE_ROCKET') then
2489 Anim
:= TAnimation
.Create(TextureID
, False, 6);
2490 Anim
.Blending
:= False;
2491 g_GFX_OnceAnim(cx
-64, cy
-64, Anim
);
2495 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj
.X
, Obj
.Y
);
2500 end; // case ShotType of...
2502 // Åñëè ñíàðÿäà óæå íåò, óäàëÿåì àíèìàöèþ:
2503 if (ShotType
= 0) then
2505 if gGameSettings
.GameType
= GT_SERVER
then
2506 MH_SEND_DeleteShot(i
, Obj
.X
, Obj
.Y
, Loud
);
2507 if Animation
<> nil then
2513 else if (ShotType
<> WEAPON_FLAMETHROWER
) and ((oldvx
<> Obj
.Vel
.X
) or (oldvy
<> Obj
.Vel
.Y
)) then
2514 if gGameSettings
.GameType
= GT_SERVER
then
2515 MH_SEND_UpdateShot(i
);
2520 procedure g_Weapon_Draw();
2529 for i
:= 0 to High(Shots
) do
2530 if Shots
[i
].ShotType
<> 0 then
2533 if (Shots
[i
].ShotType
= WEAPON_ROCKETLAUNCHER
) or
2534 (Shots
[i
].ShotType
= WEAPON_BARON_FIRE
) or
2535 (Shots
[i
].ShotType
= WEAPON_MANCUB_FIRE
) or
2536 (Shots
[i
].ShotType
= WEAPON_SKEL_FIRE
) then
2537 a
:= -GetAngle2(Obj
.Vel
.X
, Obj
.Vel
.Y
)
2541 Obj
.lerp(gLerpFactor
, fX
, fY
);
2542 p
.X
:= Obj
.Rect
.Width
div 2;
2543 p
.Y
:= Obj
.Rect
.Height
div 2;
2545 if Animation
<> nil then
2547 if (Shots
[i
].ShotType
= WEAPON_BARON_FIRE
) or
2548 (Shots
[i
].ShotType
= WEAPON_MANCUB_FIRE
) or
2549 (Shots
[i
].ShotType
= WEAPON_SKEL_FIRE
) then
2550 Animation
.DrawEx(fX
, fY
, TMirrorType
.None
, p
, a
)
2552 Animation
.Draw(fX
, fY
, TMirrorType
.None
);
2554 else if TextureID
<> 0 then
2556 if (Shots
[i
].ShotType
= WEAPON_ROCKETLAUNCHER
) then
2557 e_DrawAdv(TextureID
, fX
, fY
, 0, True, False, a
, @p
, TMirrorType
.None
)
2558 else if (Shots
[i
].ShotType
<> WEAPON_FLAMETHROWER
) then
2559 e_Draw(TextureID
, fX
, fY
, 0, True, False);
2562 if g_debug_Frames
then
2564 e_DrawQuad(Obj
.X
+Obj
.Rect
.X
,
2566 Obj
.X
+Obj
.Rect
.X
+Obj
.Rect
.Width
-1,
2567 Obj
.Y
+Obj
.Rect
.Y
+Obj
.Rect
.Height
-1,
2573 function g_Weapon_Danger(UID
: Word; X
, Y
: Integer; Width
, Height
: Word; Time
: Byte): Boolean;
2582 for a
:= 0 to High(Shots
) do
2583 if (Shots
[a
].ShotType
<> 0) and (Shots
[a
].SpawnerUID
<> UID
) then
2584 if ((Shots
[a
].Obj
.Vel
.Y
= 0) and (Shots
[a
].Obj
.Vel
.X
> 0) and (Shots
[a
].Obj
.X
< X
)) or
2585 (Shots
[a
].Obj
.Vel
.Y
= 0) and (Shots
[a
].Obj
.Vel
.X
< 0) and (Shots
[a
].Obj
.X
> X
) then
2586 if (Abs(X
-Shots
[a
].Obj
.X
) < Abs(Shots
[a
].Obj
.Vel
.X
*Time
)) and
2587 g_Collide(X
, Y
, Width
, Height
, X
, Shots
[a
].Obj
.Y
,
2588 Shots
[a
].Obj
.Rect
.Width
, Shots
[a
].Obj
.Rect
.Height
) and
2589 g_TraceVector(X
, Y
, Shots
[a
].Obj
.X
, Shots
[a
].Obj
.Y
) then
2596 procedure g_Weapon_SaveState (st
: TStream
);
2598 count
, i
, j
: Integer;
2600 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ ñíàðÿäîâ
2602 for i
:= 0 to High(Shots
) do if (Shots
[i
].ShotType
<> 0) then Inc(count
);
2604 // Êîëè÷åñòâî ñíàðÿäîâ
2605 utils
.WriteInt(st
, count
);
2607 if (count
= 0) then exit
;
2609 for i
:= 0 to High(Shots
) do
2611 if Shots
[i
].ShotType
<> 0 then
2613 // Ñèãíàòóðà ñíàðÿäà
2614 utils
.writeSign(st
, 'SHOT');
2615 utils
.writeInt(st
, Byte(0)); // version
2617 utils
.writeInt(st
, Byte(Shots
[i
].ShotType
));
2619 utils
.writeInt(st
, Word(Shots
[i
].Target
));
2621 utils
.writeInt(st
, Word(Shots
[i
].SpawnerUID
));
2622 // Ðàçìåð ïîëÿ Triggers
2623 utils
.writeInt(st
, Integer(Length(Shots
[i
].Triggers
)));
2624 // Òðèããåðû, àêòèâèðîâàííûå âûñòðåëîì
2625 for j
:= 0 to Length(Shots
[i
].Triggers
)-1 do utils
.writeInt(st
, LongWord(Shots
[i
].Triggers
[j
]));
2627 Obj_SaveState(st
, @Shots
[i
].Obj
);
2629 utils
.writeInt(st
, Byte(Shots
[i
].Stopped
));
2634 procedure g_Weapon_LoadState (st
: TStream
);
2636 count
, tc
, i
, j
: Integer;
2639 if (st
= nil) then exit
;
2641 // Êîëè÷åñòâî ñíàðÿäîâ
2642 count
:= utils
.readLongInt(st
);
2643 if (count
< 0) or (count
> 1024*1024) then raise XStreamError
.Create('invalid shots counter');
2645 SetLength(Shots
, count
);
2647 if (count
= 0) then exit
;
2649 for i
:= 0 to count
-1 do
2651 // Ñèãíàòóðà ñíàðÿäà
2652 if not utils
.checkSign(st
, 'SHOT') then raise XStreamError
.Create('invalid shot signature');
2653 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid shot version');
2655 Shots
[i
].ShotType
:= utils
.readByte(st
);
2657 Shots
[i
].Target
:= utils
.readWord(st
);
2659 Shots
[i
].SpawnerUID
:= utils
.readWord(st
);
2660 // Ðàçìåð ïîëÿ Triggers
2661 tc
:= utils
.readLongInt(st
);
2662 if (tc
< 0) or (tc
> 1024*1024) then raise XStreamError
.Create('invalid shot triggers counter');
2663 SetLength(Shots
[i
].Triggers
, tc
);
2664 // Òðèããåðû, àêòèâèðîâàííûå âûñòðåëîì
2665 for j
:= 0 to tc
-1 do Shots
[i
].Triggers
[j
] := utils
.readLongWord(st
);
2667 Obj_LoadState(@Shots
[i
].Obj
, st
);
2669 Shots
[i
].Stopped
:= utils
.readByte(st
);
2671 // Óñòàíîâêà òåêñòóðû èëè àíèìàöèè
2672 Shots
[i
].TextureID
:= DWORD(-1);
2673 Shots
[i
].Animation
:= nil;
2675 case Shots
[i
].ShotType
of
2676 WEAPON_ROCKETLAUNCHER
, WEAPON_SKEL_FIRE
:
2678 g_Texture_Get('TEXTURE_WEAPON_ROCKET', Shots
[i
].TextureID
);
2682 g_Frames_Get(dw
, 'FRAMES_WEAPON_PLASMA');
2683 Shots
[i
].Animation
:= TAnimation
.Create(dw
, True, 5);
2687 g_Frames_Get(dw
, 'FRAMES_WEAPON_BFG');
2688 Shots
[i
].Animation
:= TAnimation
.Create(dw
, True, 6);
2692 g_Frames_Get(dw
, 'FRAMES_WEAPON_IMPFIRE');
2693 Shots
[i
].Animation
:= TAnimation
.Create(dw
, True, 4);
2697 g_Frames_Get(dw
, 'FRAMES_WEAPON_BSPFIRE');
2698 Shots
[i
].Animation
:= TAnimation
.Create(dw
, True, 4);
2702 g_Frames_Get(dw
, 'FRAMES_WEAPON_CACOFIRE');
2703 Shots
[i
].Animation
:= TAnimation
.Create(dw
, True, 4);
2707 g_Frames_Get(dw
, 'FRAMES_WEAPON_BARONFIRE');
2708 Shots
[i
].Animation
:= TAnimation
.Create(dw
, True, 4);
2712 g_Frames_Get(dw
, 'FRAMES_WEAPON_MANCUBFIRE');
2713 Shots
[i
].Animation
:= TAnimation
.Create(dw
, True, 4);
2719 procedure g_Weapon_DestroyShot(I
: Integer; X
, Y
: Integer; Loud
: Boolean = True);
2727 if (I
> High(Shots
)) or (I
< 0) then Exit
;
2731 if ShotType
= 0 then Exit
;
2734 cx
:= Obj
.X
+ (Obj
.Rect
.Width
div 2);
2735 cy
:= Obj
.Y
+ (Obj
.Rect
.Height
div 2);
2738 WEAPON_ROCKETLAUNCHER
, WEAPON_SKEL_FIRE
: // Ðàêåòû è ñíàðÿäû Ñêåëåòà
2742 if ShotType
= WEAPON_SKEL_FIRE
then
2743 begin // Âçðûâ ñíàðÿäà Ñêåëåòà
2744 if g_Frames_Get(TextureID
, 'FRAMES_EXPLODE_SKELFIRE') then
2746 Anim
:= TAnimation
.Create(TextureID
, False, 8);
2747 Anim
.Blending
:= False;
2748 g_GFX_OnceAnim((Obj
.X
+32)-32, (Obj
.Y
+8)-32, Anim
);
2753 begin // Âçðûâ Ðàêåòû
2754 if g_Frames_Get(TextureID
, 'FRAMES_EXPLODE_ROCKET') then
2756 Anim
:= TAnimation
.Create(TextureID
, False, 6);
2757 Anim
.Blending
:= False;
2758 g_GFX_OnceAnim(cx
-64, cy
-64, Anim
);
2762 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', Obj
.X
, Obj
.Y
);
2766 WEAPON_PLASMA
, WEAPON_BSP_FIRE
: // Ïëàçìà, ïëàçìà Àðàõíàòðîíà
2768 if ShotType
= WEAPON_PLASMA
then
2769 s
:= 'FRAMES_EXPLODE_PLASMA'
2771 s
:= 'FRAMES_EXPLODE_BSPFIRE';
2773 if g_Frames_Get(TextureID
, s
) and loud
then
2775 Anim
:= TAnimation
.Create(TextureID
, False, 3);
2776 Anim
.Blending
:= False;
2777 g_GFX_OnceAnim(cx
-16, cy
-16, Anim
);
2780 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEPLASMA', Obj
.X
, Obj
.Y
);
2787 if g_Frames_Get(TextureID
, 'FRAMES_EXPLODE_BFG') and Loud
then
2789 Anim
:= TAnimation
.Create(TextureID
, False, 6);
2790 Anim
.Blending
:= False;
2791 g_GFX_OnceAnim(cx
-64, cy
-64, Anim
);
2794 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', Obj
.X
, Obj
.Y
);
2798 WEAPON_IMP_FIRE
, WEAPON_CACO_FIRE
, WEAPON_BARON_FIRE
: // Âûñòðåëû Áåñà, Êàêîäåìîíà Ðûöàðÿ/Áàðîíà àäà
2800 if ShotType
= WEAPON_IMP_FIRE
then
2801 s
:= 'FRAMES_EXPLODE_IMPFIRE'
2803 if ShotType
= WEAPON_CACO_FIRE
then
2804 s
:= 'FRAMES_EXPLODE_CACOFIRE'
2806 s
:= 'FRAMES_EXPLODE_BARONFIRE';
2808 if g_Frames_Get(TextureID
, s
) and Loud
then
2810 Anim
:= TAnimation
.Create(TextureID
, False, 6);
2811 Anim
.Blending
:= False;
2812 g_GFX_OnceAnim(cx
-32, cy
-32, Anim
);
2815 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj
.X
, Obj
.Y
);
2819 WEAPON_MANCUB_FIRE
: // Âûñòðåë Ìàíêóáóñà
2821 if g_Frames_Get(TextureID
, 'FRAMES_EXPLODE_ROCKET') and Loud
then
2823 Anim
:= TAnimation
.Create(TextureID
, False, 6);
2824 Anim
.Blending
:= False;
2825 g_GFX_OnceAnim(cx
-64, cy
-64, Anim
);
2828 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj
.X
, Obj
.Y
);
2831 end; // case ShotType of...
2839 procedure g_Weapon_AddDynLights();
2843 if Shots
= nil then Exit
;
2844 for i
:= 0 to High(Shots
) do
2846 if Shots
[i
].ShotType
= 0 then continue
;
2847 if (Shots
[i
].ShotType
= WEAPON_ROCKETLAUNCHER
) or
2848 (Shots
[i
].ShotType
= WEAPON_BARON_FIRE
) or
2849 (Shots
[i
].ShotType
= WEAPON_MANCUB_FIRE
) or
2850 (Shots
[i
].ShotType
= WEAPON_SKEL_FIRE
) or
2851 (Shots
[i
].ShotType
= WEAPON_IMP_FIRE
) or
2852 (Shots
[i
].ShotType
= WEAPON_CACO_FIRE
) or
2853 (Shots
[i
].ShotType
= WEAPON_MANCUB_FIRE
) or
2854 (Shots
[i
].ShotType
= WEAPON_BSP_FIRE
) or
2855 (Shots
[i
].ShotType
= WEAPON_PLASMA
) or
2856 (Shots
[i
].ShotType
= WEAPON_BFG
) or
2857 (Shots
[i
].ShotType
= WEAPON_FLAMETHROWER
) or
2860 if (Shots
[i
].ShotType
= WEAPON_PLASMA
) then
2861 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)
2862 else if (Shots
[i
].ShotType
= WEAPON_BFG
) then
2863 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)
2864 else if (Shots
[i
].ShotType
= WEAPON_FLAMETHROWER
) then
2865 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)
2867 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);
2873 procedure TShot
.positionChanged (); begin end;