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
: 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
, indmg
: 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; compat
: Boolean = true);
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; compat
: Boolean = true);
60 procedure g_Weapon_plasma(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1; Silent
: Boolean = False; compat
: Boolean = true);
61 procedure g_Weapon_ball1(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1; Silent
: Boolean = False; compat
: Boolean = true);
62 procedure g_Weapon_ball2(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1; Silent
: Boolean = False; compat
: Boolean = true);
63 procedure g_Weapon_ball7(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1; Silent
: Boolean = False; compat
: Boolean = true);
64 procedure g_Weapon_aplasma(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1; Silent
: Boolean = False; compat
: Boolean = true);
65 procedure g_Weapon_manfire(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1; Silent
: Boolean = False; compat
: Boolean = true);
66 procedure g_Weapon_bfgshot(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1; Silent
: Boolean = False; compat
: Boolean = true);
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 function g_Weapon_Danger(UID
: Word; X
, Y
: Integer; Width
, Height
: Word; Time
: Byte): Boolean;
78 procedure g_Weapon_DestroyShot(I
: Integer; X
, Y
: Integer; Loud
: Boolean = True);
80 procedure g_Weapon_SaveState (st
: TStream
);
81 procedure g_Weapon_LoadState (st
: TStream
);
83 procedure g_Weapon_AddDynLights();
92 WEAPON_ROCKETLAUNCHER
= 6;
95 WEAPON_SUPERPULEMET
= 9;
96 WEAPON_FLAMETHROWER
= 10;
97 WEAPON_ZOMBY_PISTOL
= 20;
100 WEAPON_CACO_FIRE
= 23;
101 WEAPON_BARON_FIRE
= 24;
102 WEAPON_MANCUB_FIRE
= 25;
103 WEAPON_SKEL_FIRE
= 26;
105 WP_FIRST
= WEAPON_KASTET
;
106 WP_LAST
= WEAPON_FLAMETHROWER
;
110 gwep_debug_fast_trace
: Boolean = true;
116 Math
, g_map
, g_player
, g_gfx
, g_sound
, g_panel
,
117 g_console
, g_options
, g_game
, r_textures
, r_animations
,
118 g_triggers
, MAPDEF
, e_log
, g_monsters
, g_saveload
,
119 g_language
, g_netmsg
, g_grid
,
120 geom
, binheap
, hashtable
, utils
, xstreams
;
130 SHOT_ROCKETLAUNCHER_WIDTH
= 14;
131 SHOT_ROCKETLAUNCHER_HEIGHT
= 14;
133 SHOT_SKELFIRE_WIDTH
= 14;
134 SHOT_SKELFIRE_HEIGHT
= 14;
136 SHOT_PLASMA_WIDTH
= 16;
137 SHOT_PLASMA_HEIGHT
= 16;
140 SHOT_BFG_HEIGHT
= 32;
141 SHOT_BFG_DAMAGE
= 100;
142 SHOT_BFG_RADIUS
= 256;
144 SHOT_FLAME_WIDTH
= 4;
145 SHOT_FLAME_HEIGHT
= 4;
146 SHOT_FLAME_LIFETIME
= 180;
148 SHOT_SIGNATURE
= $544F4853; // 'SHOT'
151 PHitTime
= ^THitTime
;
155 plridx
: Integer; // if mon=nil
159 TBinHeapKeyHitTime
= class
161 class function less (const a
, b
: Integer): Boolean; inline;
164 // indicies in `wgunHitTime` array
165 TBinaryHeapHitTimes
= specialize TBinaryHeapBase
<Integer, TBinHeapKeyHitTime
>;
168 WaterMap
: array of array of DWORD
= nil;
169 //wgunMonHash: THashIntInt = nil;
170 wgunHitHeap
: TBinaryHeapHitTimes
= nil;
171 wgunHitTime
: array of THitTime
= nil;
172 wgunHitTimeUsed
: Integer = 0;
175 class function TBinHeapKeyHitTime
.less (const a
, b
: Integer): Boolean;
179 hta
:= @wgunHitTime
[a
];
180 htb
:= @wgunHitTime
[b
];
181 if (hta
.distSq
<> htb
.distSq
) then begin result
:= (hta
.distSq
< htb
.distSq
); exit
; end;
182 if (hta
.mon
<> nil) then
185 if (htb
.mon
= nil) then begin result
:= false; exit
; end; // players first
186 result
:= (hta
.mon
.UID
< htb
.mon
.UID
); // why not?
191 if (htb
.mon
<> nil) then begin result
:= true; exit
; end; // players first
192 result
:= (hta
.plridx
< htb
.plridx
); // why not?
197 procedure appendHitTimeMon (adistSq
: Integer; amon
: TMonster
; ax
, ay
: Integer);
199 if (wgunHitTimeUsed
= Length(wgunHitTime
)) then SetLength(wgunHitTime
, wgunHitTimeUsed
+128);
200 with wgunHitTime
[wgunHitTimeUsed
] do
208 wgunHitHeap
.insert(wgunHitTimeUsed
);
209 Inc(wgunHitTimeUsed
);
213 procedure appendHitTimePlr (adistSq
: Integer; aplridx
: Integer; ax
, ay
: Integer);
215 if (wgunHitTimeUsed
= Length(wgunHitTime
)) then SetLength(wgunHitTime
, wgunHitTimeUsed
+128);
216 with wgunHitTime
[wgunHitTimeUsed
] do
224 wgunHitHeap
.insert(wgunHitTimeUsed
);
225 Inc(wgunHitTimeUsed
);
229 function FindShot(): DWORD
;
234 for i
:= 0 to High(Shots
) do
235 if Shots
[i
].ShotType
= 0 then
238 LastShotID
:= Result
;
244 SetLength(Shots
, 128);
249 Result
:= High(Shots
) + 1;
250 SetLength(Shots
, Length(Shots
) + 128);
252 LastShotID
:= Result
;
255 procedure CreateWaterMap();
257 WaterArray
: Array of TWaterPanel
;
264 SetLength(WaterArray
, Length(gWater
));
266 for a
:= 0 to High(gWater
) do
268 WaterArray
[a
].X
:= gWater
[a
].X
;
269 WaterArray
[a
].Y
:= gWater
[a
].Y
;
270 WaterArray
[a
].Width
:= gWater
[a
].Width
;
271 WaterArray
[a
].Height
:= gWater
[a
].Height
;
272 WaterArray
[a
].Active
:= True;
275 g_Game_SetLoadingText(_lc
[I_LOAD_WATER_MAP
], High(WaterArray
), False);
277 for a
:= 0 to High(WaterArray
) do
278 if WaterArray
[a
].Active
then
280 WaterArray
[a
].Active
:= False;
281 m
:= Length(WaterMap
);
282 SetLength(WaterMap
, m
+1);
283 SetLength(WaterMap
[m
], 1);
290 for b
:= 0 to High(WaterArray
) do
291 if WaterArray
[b
].Active
then
292 for c
:= 0 to High(WaterMap
[m
]) do
293 if g_CollideAround(WaterArray
[b
].X
,
296 WaterArray
[b
].Height
,
297 WaterArray
[WaterMap
[m
][c
]].X
,
298 WaterArray
[WaterMap
[m
][c
]].Y
,
299 WaterArray
[WaterMap
[m
][c
]].Width
,
300 WaterArray
[WaterMap
[m
][c
]].Height
) then
302 WaterArray
[b
].Active
:= False;
303 SetLength(WaterMap
[m
],
304 Length(WaterMap
[m
])+1);
305 WaterMap
[m
][High(WaterMap
[m
])] := b
;
311 g_Game_StepLoading();
319 chkTrap_pl
: array [0..256] of Integer;
320 chkTrap_mn
: array [0..65535] of TMonster
;
322 procedure CheckTrap(ID
: DWORD
; dm
: Integer; t
: Byte);
324 //a, b, c, d, i1, i2: Integer;
325 //chkTrap_pl, chkTrap_mn: WArray;
326 plaCount
: Integer = 0;
327 mnaCount
: Integer = 0;
331 function monsWaterCheck (mon: TMonster): Boolean;
333 result := false; // don't stop
334 if mon.alive and mon.Collide(gWater[WaterMap[a][c]]) and (not InWArray(monidx, chkTrap_mn)) and (i2 < 1023) then //FIXME
337 chkTrap_mn[i2] := monidx;
342 function monsWaterCheck (mon
: TMonster
): Boolean;
344 result
:= false; // don't stop
345 if (mon
.trapCheckFrameId
<> frameId
) then
347 mon
.trapCheckFrameId
:= frameId
;
348 chkTrap_mn
[mnaCount
] := mon
;
354 a
, b
, c
, d
, f
: Integer;
357 if (gWater
= nil) or (WaterMap
= nil) then Exit
;
359 frameId
:= g_Mons_getNewTrapFrameId();
364 //SetLength(chkTrap_pl, 1024);
365 //SetLength(chkTrap_mn, 1024);
366 //for d := 0 to 1023 do chkTrap_pl[d] := $FFFF;
367 //for d := 0 to 1023 do chkTrap_mn[d] := $FFFF;
369 for a
:= 0 to High(WaterMap
) do
371 for b
:= 0 to High(WaterMap
[a
]) do
373 pan
:= gWater
[WaterMap
[a
][b
]];
374 if not g_Obj_Collide(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, @Shots
[ID
].Obj
) then continue
;
376 for c
:= 0 to High(WaterMap
[a
]) do
378 pan
:= gWater
[WaterMap
[a
][c
]];
379 for d
:= 0 to High(gPlayers
) do
381 if (gPlayers
[d
] <> nil) and (gPlayers
[d
].alive
) then
383 if gPlayers
[d
].Collide(pan
) then
386 while (f
< plaCount
) and (chkTrap_pl
[f
] <> d
) do Inc(f
);
387 if (f
= plaCount
) then
389 chkTrap_pl
[plaCount
] := d
;
391 if (plaCount
= Length(chkTrap_pl
)) then break
;
397 //g_Mons_ForEach(monsWaterCheck);
398 g_Mons_ForEachAliveAt(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, monsWaterCheck
);
401 for f
:= 0 to plaCount
-1 do gPlayers
[chkTrap_pl
[f
]].Damage(dm
, Shots
[ID
].SpawnerUID
, 0, 0, t
);
402 for f
:= 0 to mnaCount
-1 do chkTrap_mn
[f
].Damage(dm
, 0, 0, Shots
[ID
].SpawnerUID
, t
);
410 function HitMonster(m
: TMonster
; d
: Integer; vx
, vy
: Integer; SpawnerUID
: Word; t
: Byte): Boolean;
417 tt
:= g_GetUIDType(SpawnerUID
);
418 if tt
= UID_MONSTER
then
420 mon
:= g_Monsters_ByUID(SpawnerUID
);
422 mt
:= g_Monsters_ByUID(SpawnerUID
).MonsterType
429 if m
= nil then Exit
;
430 if m
.UID
= SpawnerUID
then
432 // Ñàì ñåáÿ ìîæåò ðàíèòü òîëüêî ðàêåòîé è òîêîì:
433 if (t
<> HIT_ROCKET
) and (t
<> HIT_ELECTRO
) then
435 // Êèáåð äåìîí è áî÷êà âîîáùå íå ìîãóò ñåáÿ ðàíèòü:
436 if (m
.MonsterType
= MONSTER_CYBER
) or
437 (m
.MonsterType
= MONSTER_BARREL
) then
444 if tt
= UID_MONSTER
then
446 // Lost_Soul íå ìîæåò ðàíèòü Pain_Elemental'à:
447 if (mt
= MONSTER_SOUL
) and (m
.MonsterType
= MONSTER_PAIN
) then
450 // Îáà ìîíñòðà îäíîãî âèäà:
451 if mt
= m
.MonsterType
then
453 MONSTER_IMP
, MONSTER_DEMON
, MONSTER_BARON
, MONSTER_KNIGHT
, MONSTER_CACO
,
454 MONSTER_SOUL
, MONSTER_MANCUB
, MONSTER_SKEL
, MONSTER_FISH
:
455 Exit
; // Ýòè íå áüþò ñâîèõ
459 if g_Game_IsServer
then
461 if (t
<> HIT_FLAME
) or (m
.FFireTime
= 0) or (vx
<> 0) or (vy
<> 0) then
462 Result
:= m
.Damage(d
, vx
, vy
, SpawnerUID
, t
)
464 Result
:= (gLMSRespawn
= LMS_RESPAWN_NONE
); // don't hit monsters when it's warmup time
465 if t
= HIT_FLAME
then
466 m
.CatchFire(SpawnerUID
);
469 Result
:= (gLMSRespawn
= LMS_RESPAWN_NONE
); // don't hit monsters when it's warmup time
473 function HitPlayer (p
: TPlayer
; d
: Integer; vx
, vy
: Integer; SpawnerUID
: Word; t
: Byte): Boolean;
477 // Ñàì ñåáÿ ìîæåò ðàíèòü òîëüêî ðàêåòîé è òîêîì
478 if (p
.UID
= SpawnerUID
) and (t
<> HIT_ROCKET
) and (t
<> HIT_ELECTRO
) then exit
;
480 if g_Game_IsServer
then
482 if (t
<> HIT_FLAME
) or (p
.FFireTime
= 0) or (vx
<> 0) or (vy
<> 0) then p
.Damage(d
, SpawnerUID
, vx
, vy
, t
);
483 if (t
= HIT_FLAME
) then p
.CatchFire(SpawnerUID
);
490 procedure g_Weapon_BFG9000(X
, Y
: Integer; SpawnerUID
: Word);
492 function monsCheck (mon
: TMonster
): Boolean;
494 result
:= false; // don't stop
495 if (mon
.alive
) and (mon
.UID
<> SpawnerUID
) then
499 if (g_PatchLength(X
, Y
, Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2),
500 Obj
.Y
+Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2)) <= SHOT_BFG_RADIUS
) and
501 g_TraceVector(X
, Y
, Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2),
502 Obj
.Y
+Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2)) then
504 if HitMonster(mon
, 50, 0, 0, SpawnerUID
, HIT_SOME
) then mon
.BFGHit();
516 //g_Sound_PlayEx('SOUND_WEAPON_EXPLODEBFG', 255);
520 if gAdvCorpses
and (h
<> -1) then
522 if (gCorpses
[i
] <> nil) and (gCorpses
[i
].State
<> CORPSE_STATE_REMOVEME
) then
524 if (g_PatchLength(X
, Y
, Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2),
525 Obj
.Y
+Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2)) <= SHOT_BFG_RADIUS
) and
526 g_TraceVector(X
, Y
, Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2),
527 Obj
.Y
+Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2)) then
529 Damage(50, SpawnerUID
, 0, 0);
530 g_Weapon_BFGHit(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2),
531 Obj
.Y
+Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2));
535 pl
:= g_Player_Get(SpawnerUID
);
543 if (gPlayers
[i
] <> nil) and (gPlayers
[i
].alive
) and (gPlayers
[i
].UID
<> SpawnerUID
) then
545 if (g_PatchLength(X
, Y
, GameX
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
546 GameY
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)) <= SHOT_BFG_RADIUS
) and
547 g_TraceVector(X
, Y
, GameX
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
548 GameY
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)) then
550 if (st
= TEAM_NONE
) or (st
<> gPlayers
[i
].Team
) then
551 b
:= HitPlayer(gPlayers
[i
], 50, 0, 0, SpawnerUID
, HIT_SOME
)
553 b
:= HitPlayer(gPlayers
[i
], 25, 0, 0, SpawnerUID
, HIT_SOME
);
555 gPlayers
[i
].BFGHit();
559 g_Mons_ForEachAlive(monsCheck
);
562 function g_Weapon_CreateShot(I
: Integer; ShotType
: Byte; Spawner
, TargetUID
: Word; X
, Y
, XV
, YV
: Integer): LongWord;
568 find_id
:= FindShot()
572 if Integer(find_id
) >= High(Shots
) then
573 SetLength(Shots
, find_id
+ 64)
577 WEAPON_ROCKETLAUNCHER
:
579 with Shots
[find_id
] do
583 Obj
.Rect
.Width
:= SHOT_ROCKETLAUNCHER_WIDTH
;
584 Obj
.Rect
.Height
:= SHOT_ROCKETLAUNCHER_HEIGHT
;
588 ShotType
:= WEAPON_ROCKETLAUNCHER
;
589 g_Texture_Get('TEXTURE_WEAPON_ROCKET', TextureID
);
595 with Shots
[find_id
] do
599 Obj
.Rect
.Width
:= SHOT_PLASMA_WIDTH
;
600 Obj
.Rect
.Height
:= SHOT_PLASMA_HEIGHT
;
603 ShotType
:= WEAPON_PLASMA
;
604 g_Frames_Get(FramesID
, 'FRAMES_WEAPON_PLASMA');
605 Animation
:= TAnimation
.Create(FramesID
, True, 5);
611 with Shots
[find_id
] do
615 Obj
.Rect
.Width
:= SHOT_BFG_WIDTH
;
616 Obj
.Rect
.Height
:= SHOT_BFG_HEIGHT
;
619 ShotType
:= WEAPON_BFG
;
620 g_Frames_Get(FramesID
, 'FRAMES_WEAPON_BFG');
621 Animation
:= TAnimation
.Create(FramesID
, True, 6);
627 with Shots
[find_id
] do
631 Obj
.Rect
.Width
:= SHOT_FLAME_WIDTH
;
632 Obj
.Rect
.Height
:= SHOT_FLAME_HEIGHT
;
635 ShotType
:= WEAPON_FLAMETHROWER
;
638 g_Frames_Get(TextureID
, 'FRAMES_FLAME');
644 with Shots
[find_id
] do
648 Obj
.Rect
.Width
:= 16;
649 Obj
.Rect
.Height
:= 16;
652 ShotType
:= WEAPON_IMP_FIRE
;
653 g_Frames_Get(FramesID
, 'FRAMES_WEAPON_IMPFIRE');
654 Animation
:= TAnimation
.Create(FramesID
, True, 4);
660 with Shots
[find_id
] do
664 Obj
.Rect
.Width
:= 16;
665 Obj
.Rect
.Height
:= 16;
668 ShotType
:= WEAPON_CACO_FIRE
;
669 g_Frames_Get(FramesID
, 'FRAMES_WEAPON_CACOFIRE');
670 Animation
:= TAnimation
.Create(FramesID
, True, 4);
676 with Shots
[find_id
] do
680 Obj
.Rect
.Width
:= 32;
681 Obj
.Rect
.Height
:= 32;
684 ShotType
:= WEAPON_MANCUB_FIRE
;
685 g_Frames_Get(FramesID
, 'FRAMES_WEAPON_MANCUBFIRE');
686 Animation
:= TAnimation
.Create(FramesID
, True, 4);
692 with Shots
[find_id
] do
696 Obj
.Rect
.Width
:= 16;
697 Obj
.Rect
.Height
:= 16;
700 ShotType
:= WEAPON_BARON_FIRE
;
701 g_Frames_Get(FramesID
, 'FRAMES_WEAPON_BARONFIRE');
702 Animation
:= TAnimation
.Create(FramesID
, True, 4);
708 with Shots
[find_id
] do
712 Obj
.Rect
.Width
:= 16;
713 Obj
.Rect
.Height
:= 16;
716 ShotType
:= WEAPON_BSP_FIRE
;
717 g_Frames_Get(FramesID
, 'FRAMES_WEAPON_BSPFIRE');
718 Animation
:= TAnimation
.Create(FramesID
, True, 4);
724 with Shots
[find_id
] do
728 Obj
.Rect
.Width
:= SHOT_SKELFIRE_WIDTH
;
729 Obj
.Rect
.Height
:= SHOT_SKELFIRE_HEIGHT
;
732 ShotType
:= WEAPON_SKEL_FIRE
;
734 g_Frames_Get(FramesID
, 'FRAMES_WEAPON_SKELFIRE');
735 Animation
:= TAnimation
.Create(FramesID
, True, 5);
740 Shots
[find_id
].Obj
.oldX
:= X
;
741 Shots
[find_id
].Obj
.oldY
:= Y
;
742 Shots
[find_id
].Obj
.X
:= X
;
743 Shots
[find_id
].Obj
.Y
:= Y
;
744 Shots
[find_id
].Obj
.Vel
.X
:= XV
;
745 Shots
[find_id
].Obj
.Vel
.Y
:= YV
;
746 Shots
[find_id
].Obj
.Accel
.X
:= 0;
747 Shots
[find_id
].Obj
.Accel
.Y
:= 0;
748 Shots
[find_id
].SpawnerUID
:= Spawner
;
749 if (ShotType
= WEAPON_FLAMETHROWER
) and (XV
= 0) and (YV
= 0) then
750 Shots
[find_id
].Stopped
:= 255
752 Shots
[find_id
].Stopped
:= 0;
756 procedure throw(i
, x
, y
, xd
, yd
, s
: Integer);
763 a
:= Max(Abs(xd
), Abs(yd
));
767 Shots
[i
].Obj
.oldX
:= x
;
768 Shots
[i
].Obj
.oldY
:= y
;
771 Shots
[i
].Obj
.Vel
.X
:= (xd
*s
) div a
;
772 Shots
[i
].Obj
.Vel
.Y
:= (yd
*s
) div a
;
773 Shots
[i
].Obj
.Accel
.X
:= 0;
774 Shots
[i
].Obj
.Accel
.Y
:= 0;
775 Shots
[i
].Stopped
:= 0;
776 if Shots
[i
].ShotType
in [WEAPON_ROCKETLAUNCHER
, WEAPON_BFG
] then
777 Shots
[i
].Timeout
:= 900 // ~25 sec
780 if Shots
[i
].ShotType
= WEAPON_FLAMETHROWER
then
781 Shots
[i
].Timeout
:= SHOT_FLAME_LIFETIME
783 Shots
[i
].Timeout
:= 550; // ~15 sec
787 function g_Weapon_Hit(obj
: PObj
; d
: Integer; SpawnerUID
: Word; t
: Byte; HitCorpses
: Boolean = True): Byte;
791 function PlayerHit(Team
: Byte = 0): Boolean;
802 if (gPlayers
[i
] <> nil) and gPlayers
[i
].alive
and g_Obj_Collide(obj
, @gPlayers
[i
].Obj
) then
805 if (Team
> 0) and (g_GetUIDType(SpawnerUID
) = UID_PLAYER
) then
807 p
:= g_Player_Get(SpawnerUID
);
809 ChkTeam
:= (p
.Team
= gPlayers
[i
].Team
) xor (Team
= 2);
812 if HitPlayer(gPlayers
[i
], d
, obj
^.Vel
.X
, obj
^.Vel
.Y
, SpawnerUID
, t
) then
814 if t
<> HIT_FLAME
then
815 gPlayers
[i
].Push((obj
^.Vel
.X
+obj
^.Accel
.X
)*IfThen(t
= HIT_BFG
, 8, 1) div 4,
816 (obj
^.Vel
.Y
+obj
^.Accel
.Y
)*IfThen(t
= HIT_BFG
, 8, 1) div 4);
818 g_Game_DelayEvent(DE_BFGHIT
, 1000, SpawnerUID
);
826 function monsCheckHit (monidx: Integer; mon: TMonster): Boolean;
828 result := false; // don't stop
829 if mon.alive and g_Obj_Collide(obj, @mon.Obj) then
831 if HitMonster(mon, d, obj^.Vel.X, obj^.Vel.Y, SpawnerUID, t) then
833 if (t <> HIT_FLAME) then
835 mon.Push((obj^.Vel.X+obj^.Accel.X)*IfThen(t = HIT_BFG, 8, 1) div 4,
836 (obj^.Vel.Y+obj^.Accel.Y)*IfThen(t = HIT_BFG, 8, 1) div 4);
844 function monsCheckHit (mon
: TMonster
): Boolean;
846 result
:= false; // don't stop
847 if HitMonster(mon
, d
, obj
.Vel
.X
, obj
.Vel
.Y
, SpawnerUID
, t
) then
849 if (t
<> HIT_FLAME
) then
851 mon
.Push((obj
.Vel
.X
+obj
.Accel
.X
)*IfThen(t
= HIT_BFG
, 8, 1) div 4,
852 (obj
.Vel
.Y
+obj
.Accel
.Y
)*IfThen(t
= HIT_BFG
, 8, 1) div 4);
858 function MonsterHit(): Boolean;
860 //result := g_Mons_ForEach(monsCheckHit);
861 //FIXME: accelerate this!
862 result
:= g_Mons_ForEachAliveAt(obj
.X
+obj
.Rect
.X
, obj
.Y
+obj
.Rect
.Y
, obj
.Rect
.Width
, obj
.Rect
.Height
, monsCheckHit
);
872 if gAdvCorpses
and (h
<> -1) then
874 if (gCorpses
[i
] <> nil) and (gCorpses
[i
].State
<> CORPSE_STATE_REMOVEME
) and
875 g_Obj_Collide(obj
, @gCorpses
[i
].Obj
) then
878 gCorpses
[i
].Damage(d
, SpawnerUID
, (obj
^.Vel
.X
+obj
^.Accel
.X
) div 4,
879 (obj
^.Vel
.Y
+obj
^.Accel
.Y
) div 4);
884 case gGameSettings
.GameMode
of
888 // Ñíà÷àëà áü¸ì ìîíñòðîâ, åñëè åñòü, ïîòîì ïûòàåìñÿ áèòü èãðîêîâ
895 // È â êîíöå èãðîêîâ, íî òîëüêî åñëè ïîëîæåíî
896 // (èëè ñíàðÿä îò ìîíñòðà, èëè friendlyfire, èëè friendly_hit_projectile)
897 if (g_GetUIDType(SpawnerUID
) <> UID_PLAYER
) or
898 LongBool(gGameSettings
.Options
and (GAME_OPTION_TEAMDAMAGE
or GAME_OPTION_TEAMHITPROJECTILE
)) then
911 // Ñíà÷àëà áü¸ì èãðîêîâ, åñëè åñòü, ïîòîì ïûòàåìñÿ áèòü ìîíñòðîâ
928 // Ñíà÷àëà áü¸ì èãðîêîâ êîìàíäû ñîïåðíèêà
942 // È â êîíöå ñâîèõ èãðîêîâ, íî òîëüêî åñëè ïîëîæåíî
943 // (èëè friendlyfire, èëè friendly_hit_projectile)
944 if LongBool(gGameSettings
.Options
and (GAME_OPTION_TEAMDAMAGE
or GAME_OPTION_TEAMHITPROJECTILE
)) then
957 function g_Weapon_HitUID(UID
: Word; d
: Integer; SpawnerUID
: Word; t
: Byte): Boolean;
961 case g_GetUIDType(UID
) of
962 UID_PLAYER
: Result
:= HitPlayer(g_Player_Get(UID
), d
, 0, 0, SpawnerUID
, t
);
963 UID_MONSTER
: Result
:= HitMonster(g_Monsters_ByUID(UID
), d
, 0, 0, SpawnerUID
, t
);
968 function g_Weapon_Explode(X
, Y
: Integer; rad
: Integer; SpawnerUID
: Word): Boolean;
970 r
: Integer; // squared radius
972 function monsExCheck (mon
: TMonster
): Boolean;
976 result
:= false; // don't stop
978 dx
:= mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-X
;
979 dy
:= mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2)-Y
;
981 if dx
> 1000 then dx
:= 1000;
982 if dy
> 1000 then dy
:= 1000;
984 if (dx
*dx
+dy
*dy
< r
) then
986 //m := PointToRect(X, Y, Obj.X+Obj.Rect.X, Obj.Y+Obj.Rect.Y, Obj.Rect.Width, Obj.Rect.Height);
987 //e_WriteLog(Format('explo monster #%d: x=%d; y=%d; rad=%d; dx=%d; dy=%d', [monidx, X, Y, rad, dx, dy]), MSG_NOTIFY);
989 mm
:= Max(abs(dx
), abs(dy
));
990 if mm
= 0 then mm
:= 1;
994 HitMonster(mon
, ((mon
.Obj
.Rect
.Width
div 4)*10*(rad
-mm
)) div rad
, 0, 0, SpawnerUID
, HIT_ROCKET
);
997 mon
.Push((dx
*7) div mm
, (dy
*7) div mm
);
1003 i
, h
, dx
, dy
, m
, mm
: Integer;
1008 g_Triggers_PressC(X
, Y
, rad
, SpawnerUID
, ACTIVATE_SHOT
);
1012 h
:= High(gPlayers
);
1016 if (gPlayers
[i
] <> nil) and gPlayers
[i
].alive
then
1019 dx
:= Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)-X
;
1020 dy
:= Obj
.Y
+Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2)-Y
;
1022 if dx
> 1000 then dx
:= 1000;
1023 if dy
> 1000 then dy
:= 1000;
1025 if dx
*dx
+dy
*dy
< r
then
1027 //m := PointToRect(X, Y, GameX+PLAYER_RECT.X, GameY+PLAYER_RECT.Y,
1028 // PLAYER_RECT.Width, PLAYER_RECT.Height);
1030 mm
:= Max(abs(dx
), abs(dy
));
1031 if mm
= 0 then mm
:= 1;
1033 HitPlayer(gPlayers
[i
], (100*(rad
-mm
)) div rad
, (dx
*10) div mm
, (dy
*10) div mm
, SpawnerUID
, HIT_ROCKET
);
1034 gPlayers
[i
].Push((dx
*7) div mm
, (dy
*7) div mm
);
1038 //g_Mons_ForEach(monsExCheck);
1039 g_Mons_ForEachAt(X
-(rad
+32), Y
-(rad
+32), (rad
+32)*2, (rad
+32)*2, monsExCheck
);
1041 h
:= High(gCorpses
);
1043 if gAdvCorpses
and (h
<> -1) then
1045 if (gCorpses
[i
] <> nil) and (gCorpses
[i
].State
<> CORPSE_STATE_REMOVEME
) then
1048 dx
:= Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)-X
;
1049 dy
:= Obj
.Y
+Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2)-Y
;
1051 if dx
> 1000 then dx
:= 1000;
1052 if dy
> 1000 then dy
:= 1000;
1054 if dx
*dx
+dy
*dy
< r
then
1056 m
:= PointToRect(X
, Y
, Obj
.X
+Obj
.Rect
.X
, Obj
.Y
+Obj
.Rect
.Y
,
1057 Obj
.Rect
.Width
, Obj
.Rect
.Height
);
1059 mm
:= Max(abs(dx
), abs(dy
));
1060 if mm
= 0 then mm
:= 1;
1062 Damage(Round(100*(rad
-m
)/rad
), SpawnerUID
, (dx
*10) div mm
, (dy
*10) div mm
);
1068 if gAdvGibs
and (h
<> -1) then
1070 if gGibs
[i
].alive
then
1073 dx
:= Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)-X
;
1074 dy
:= Obj
.Y
+Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2)-Y
;
1076 if dx
> 1000 then dx
:= 1000;
1077 if dy
> 1000 then dy
:= 1000;
1079 if dx
*dx
+dy
*dy
< r
then
1081 m
:= PointToRect(X
, Y
, Obj
.X
+Obj
.Rect
.X
, Obj
.Y
+Obj
.Rect
.Y
,
1082 Obj
.Rect
.Width
, Obj
.Rect
.Height
);
1083 _angle
:= GetAngle(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2),
1084 Obj
.Y
+Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2), X
, Y
);
1086 g_Obj_PushA(@Obj
, Round(15*(rad
-m
)/rad
), _angle
);
1087 positionChanged(); // this updates spatial accelerators
1092 procedure g_Weapon_Init();
1097 procedure g_Weapon_Free();
1101 if Shots
<> nil then
1103 for i
:= 0 to High(Shots
) do
1104 if Shots
[i
].ShotType
<> 0 then
1105 Shots
[i
].Animation
.Free();
1113 procedure g_Weapon_LoadData();
1115 e_WriteLog('Loading weapons data...', TMsgType
.Notify
);
1117 g_Sound_CreateWADEx('SOUND_WEAPON_HITPUNCH', GameWAD
+':SOUNDS\HITPUNCH');
1118 g_Sound_CreateWADEx('SOUND_WEAPON_MISSPUNCH', GameWAD
+':SOUNDS\MISSPUNCH');
1119 g_Sound_CreateWADEx('SOUND_WEAPON_HITBERSERK', GameWAD
+':SOUNDS\HITBERSERK');
1120 g_Sound_CreateWADEx('SOUND_WEAPON_MISSBERSERK', GameWAD
+':SOUNDS\MISSBERSERK');
1121 g_Sound_CreateWADEx('SOUND_WEAPON_SELECTSAW', GameWAD
+':SOUNDS\SELECTSAW');
1122 g_Sound_CreateWADEx('SOUND_WEAPON_IDLESAW', GameWAD
+':SOUNDS\IDLESAW');
1123 g_Sound_CreateWADEx('SOUND_WEAPON_HITSAW', GameWAD
+':SOUNDS\HITSAW');
1124 g_Sound_CreateWADEx('SOUND_WEAPON_FIRESHOTGUN2', GameWAD
+':SOUNDS\FIRESHOTGUN2');
1125 g_Sound_CreateWADEx('SOUND_WEAPON_FIRESHOTGUN', GameWAD
+':SOUNDS\FIRESHOTGUN');
1126 g_Sound_CreateWADEx('SOUND_WEAPON_FIRESAW', GameWAD
+':SOUNDS\FIRESAW');
1127 g_Sound_CreateWADEx('SOUND_WEAPON_FIREROCKET', GameWAD
+':SOUNDS\FIREROCKET');
1128 g_Sound_CreateWADEx('SOUND_WEAPON_FIREPLASMA', GameWAD
+':SOUNDS\FIREPLASMA');
1129 g_Sound_CreateWADEx('SOUND_WEAPON_FIREPISTOL', GameWAD
+':SOUNDS\FIREPISTOL');
1130 g_Sound_CreateWADEx('SOUND_WEAPON_FIRECGUN', GameWAD
+':SOUNDS\FIRECGUN');
1131 g_Sound_CreateWADEx('SOUND_WEAPON_FIREBFG', GameWAD
+':SOUNDS\FIREBFG');
1132 g_Sound_CreateWADEx('SOUND_FIRE', GameWAD
+':SOUNDS\FIRE');
1133 g_Sound_CreateWADEx('SOUND_IGNITE', GameWAD
+':SOUNDS\IGNITE');
1134 g_Sound_CreateWADEx('SOUND_WEAPON_STARTFIREBFG', GameWAD
+':SOUNDS\STARTFIREBFG');
1135 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEROCKET', GameWAD
+':SOUNDS\EXPLODEROCKET');
1136 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEBFG', GameWAD
+':SOUNDS\EXPLODEBFG');
1137 g_Sound_CreateWADEx('SOUND_WEAPON_BFGWATER', GameWAD
+':SOUNDS\BFGWATER');
1138 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEPLASMA', GameWAD
+':SOUNDS\EXPLODEPLASMA');
1139 g_Sound_CreateWADEx('SOUND_WEAPON_PLASMAWATER', GameWAD
+':SOUNDS\PLASMAWATER');
1140 g_Sound_CreateWADEx('SOUND_WEAPON_FIREBALL', GameWAD
+':SOUNDS\FIREBALL');
1141 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEBALL', GameWAD
+':SOUNDS\EXPLODEBALL');
1142 g_Sound_CreateWADEx('SOUND_WEAPON_FIREREV', GameWAD
+':SOUNDS\FIREREV');
1143 g_Sound_CreateWADEx('SOUND_WEAPON_FLAMEON', GameWAD
+':SOUNDS\STARTFLM');
1144 g_Sound_CreateWADEx('SOUND_WEAPON_FLAMEOFF', GameWAD
+':SOUNDS\STOPFLM');
1145 g_Sound_CreateWADEx('SOUND_WEAPON_FLAMEWORK', GameWAD
+':SOUNDS\WORKFLM');
1146 g_Sound_CreateWADEx('SOUND_PLAYER_JETFLY', GameWAD
+':SOUNDS\WORKJETPACK');
1147 g_Sound_CreateWADEx('SOUND_PLAYER_JETON', GameWAD
+':SOUNDS\STARTJETPACK');
1148 g_Sound_CreateWADEx('SOUND_PLAYER_JETOFF', GameWAD
+':SOUNDS\STOPJETPACK');
1149 g_Sound_CreateWADEx('SOUND_PLAYER_CASING1', GameWAD
+':SOUNDS\CASING1');
1150 g_Sound_CreateWADEx('SOUND_PLAYER_CASING2', GameWAD
+':SOUNDS\CASING2');
1151 g_Sound_CreateWADEx('SOUND_PLAYER_SHELL1', GameWAD
+':SOUNDS\SHELL1');
1152 g_Sound_CreateWADEx('SOUND_PLAYER_SHELL2', GameWAD
+':SOUNDS\SHELL2');
1154 g_Texture_CreateWADEx('TEXTURE_WEAPON_ROCKET', GameWAD
+':TEXTURES\BROCKET');
1155 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_SKELFIRE', GameWAD
+':TEXTURES\BSKELFIRE', 64, 16, 2);
1156 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_BFG', GameWAD
+':TEXTURES\BBFG', 64, 64, 2);
1157 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_PLASMA', GameWAD
+':TEXTURES\BPLASMA', 16, 16, 2);
1158 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_IMPFIRE', GameWAD
+':TEXTURES\BIMPFIRE', 16, 16, 2);
1159 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_BSPFIRE', GameWAD
+':TEXTURES\BBSPFIRE', 16, 16, 2);
1160 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_CACOFIRE', GameWAD
+':TEXTURES\BCACOFIRE', 16, 16, 2);
1161 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_BARONFIRE', GameWAD
+':TEXTURES\BBARONFIRE', 64, 16, 2);
1162 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_MANCUBFIRE', GameWAD
+':TEXTURES\BMANCUBFIRE', 64, 32, 2);
1163 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_ROCKET', GameWAD
+':TEXTURES\EROCKET', 128, 128, 6);
1164 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_SKELFIRE', GameWAD
+':TEXTURES\ESKELFIRE', 64, 64, 3);
1165 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_BFG', GameWAD
+':TEXTURES\EBFG', 128, 128, 6);
1166 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_IMPFIRE', GameWAD
+':TEXTURES\EIMPFIRE', 64, 64, 3);
1167 g_Frames_CreateWAD(nil, 'FRAMES_BFGHIT', GameWAD
+':TEXTURES\BFGHIT', 64, 64, 4);
1168 g_Frames_CreateWAD(nil, 'FRAMES_FIRE', GameWAD
+':TEXTURES\FIRE', 64, 128, 8);
1169 g_Frames_CreateWAD(nil, 'FRAMES_FLAME', GameWAD
+':TEXTURES\FLAME', 32, 32, 11);
1170 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_PLASMA', GameWAD
+':TEXTURES\EPLASMA', 32, 32, 4, True);
1171 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_BSPFIRE', GameWAD
+':TEXTURES\EBSPFIRE', 32, 32, 5);
1172 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_CACOFIRE', GameWAD
+':TEXTURES\ECACOFIRE', 64, 64, 3);
1173 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_BARONFIRE', GameWAD
+':TEXTURES\EBARONFIRE', 64, 64, 3);
1174 g_Frames_CreateWAD(nil, 'FRAMES_SMOKE', GameWAD
+':TEXTURES\SMOKE', 32, 32, 10, False);
1176 g_Texture_CreateWADEx('TEXTURE_SHELL_BULLET', GameWAD
+':TEXTURES\EBULLET');
1177 g_Texture_CreateWADEx('TEXTURE_SHELL_SHELL', GameWAD
+':TEXTURES\ESHELL');
1179 //wgunMonHash := hashNewIntInt();
1180 wgunHitHeap
:= TBinaryHeapHitTimes
.Create();
1183 procedure g_Weapon_FreeData();
1185 e_WriteLog('Releasing weapons data...', TMsgType
.Notify
);
1187 g_Sound_Delete('SOUND_WEAPON_HITPUNCH');
1188 g_Sound_Delete('SOUND_WEAPON_MISSPUNCH');
1189 g_Sound_Delete('SOUND_WEAPON_HITBERSERK');
1190 g_Sound_Delete('SOUND_WEAPON_MISSBERSERK');
1191 g_Sound_Delete('SOUND_WEAPON_SELECTSAW');
1192 g_Sound_Delete('SOUND_WEAPON_IDLESAW');
1193 g_Sound_Delete('SOUND_WEAPON_HITSAW');
1194 g_Sound_Delete('SOUND_WEAPON_FIRESHOTGUN2');
1195 g_Sound_Delete('SOUND_WEAPON_FIRESHOTGUN');
1196 g_Sound_Delete('SOUND_WEAPON_FIRESAW');
1197 g_Sound_Delete('SOUND_WEAPON_FIREROCKET');
1198 g_Sound_Delete('SOUND_WEAPON_FIREPLASMA');
1199 g_Sound_Delete('SOUND_WEAPON_FIREPISTOL');
1200 g_Sound_Delete('SOUND_WEAPON_FIRECGUN');
1201 g_Sound_Delete('SOUND_WEAPON_FIREBFG');
1202 g_Sound_Delete('SOUND_FIRE');
1203 g_Sound_Delete('SOUND_IGNITE');
1204 g_Sound_Delete('SOUND_WEAPON_STARTFIREBFG');
1205 g_Sound_Delete('SOUND_WEAPON_EXPLODEROCKET');
1206 g_Sound_Delete('SOUND_WEAPON_EXPLODEBFG');
1207 g_Sound_Delete('SOUND_WEAPON_BFGWATER');
1208 g_Sound_Delete('SOUND_WEAPON_EXPLODEPLASMA');
1209 g_Sound_Delete('SOUND_WEAPON_PLASMAWATER');
1210 g_Sound_Delete('SOUND_WEAPON_FIREBALL');
1211 g_Sound_Delete('SOUND_WEAPON_EXPLODEBALL');
1212 g_Sound_Delete('SOUND_WEAPON_FIREREV');
1213 g_Sound_Delete('SOUND_WEAPON_FLAMEON');
1214 g_Sound_Delete('SOUND_WEAPON_FLAMEOFF');
1215 g_Sound_Delete('SOUND_WEAPON_FLAMEWORK');
1216 g_Sound_Delete('SOUND_PLAYER_JETFLY');
1217 g_Sound_Delete('SOUND_PLAYER_JETON');
1218 g_Sound_Delete('SOUND_PLAYER_JETOFF');
1219 g_Sound_Delete('SOUND_PLAYER_CASING1');
1220 g_Sound_Delete('SOUND_PLAYER_CASING2');
1221 g_Sound_Delete('SOUND_PLAYER_SHELL1');
1222 g_Sound_Delete('SOUND_PLAYER_SHELL2');
1224 g_Texture_Delete('TEXTURE_WEAPON_ROCKET');
1225 g_Frames_DeleteByName('FRAMES_WEAPON_BFG');
1226 g_Frames_DeleteByName('FRAMES_WEAPON_PLASMA');
1227 g_Frames_DeleteByName('FRAMES_WEAPON_IMPFIRE');
1228 g_Frames_DeleteByName('FRAMES_WEAPON_BSPFIRE');
1229 g_Frames_DeleteByName('FRAMES_WEAPON_CACOFIRE');
1230 g_Frames_DeleteByName('FRAMES_WEAPON_MANCUBFIRE');
1231 g_Frames_DeleteByName('FRAMES_EXPLODE_ROCKET');
1232 g_Frames_DeleteByName('FRAMES_EXPLODE_BFG');
1233 g_Frames_DeleteByName('FRAMES_EXPLODE_IMPFIRE');
1234 g_Frames_DeleteByName('FRAMES_BFGHIT');
1235 g_Frames_DeleteByName('FRAMES_FIRE');
1236 g_Frames_DeleteByName('FRAMES_EXPLODE_PLASMA');
1237 g_Frames_DeleteByName('FRAMES_EXPLODE_BSPFIRE');
1238 g_Frames_DeleteByName('FRAMES_EXPLODE_CACOFIRE');
1239 g_Frames_DeleteByName('FRAMES_SMOKE');
1240 g_Frames_DeleteByName('FRAMES_WEAPON_BARONFIRE');
1241 g_Frames_DeleteByName('FRAMES_EXPLODE_BARONFIRE');
1245 function GunHitPlayer (X
, Y
: Integer; vx
, vy
: Integer; dmg
: Integer; SpawnerUID
: Word; AllowPush
: Boolean): Boolean;
1250 for i
:= 0 to High(gPlayers
) do
1252 if (gPlayers
[i
] <> nil) and gPlayers
[i
].alive
and gPlayers
[i
].Collide(X
, Y
) then
1254 if HitPlayer(gPlayers
[i
], dmg
, vx
*10, vy
*10-3, SpawnerUID
, HIT_SOME
) then
1256 if AllowPush
then gPlayers
[i
].Push(vx
, vy
);
1264 function GunHit (X
, Y
: Integer; vx
, vy
: Integer; dmg
: Integer; SpawnerUID
: Word; AllowPush
: Boolean): Byte;
1266 function monsCheck (mon
: TMonster
): Boolean;
1268 result
:= false; // don't stop
1269 if HitMonster(mon
, dmg
, vx
*10, vy
*10-3, SpawnerUID
, HIT_SOME
) then
1271 if AllowPush
then mon
.Push(vx
, vy
);
1278 if GunHitPlayer(X
, Y
, vx
, vy
, dmg
, SpawnerUID
, AllowPush
) then result
:= 1
1279 else if g_Mons_ForEachAliveAt(X
, Y
, 1, 1, monsCheck
) then result
:= 2;
1284 procedure g_Weapon_gunOld(const x, y, xd, yd, v, dmg: Integer; SpawnerUID: Word; CheckTrigger: Boolean);
1295 t1, _collide: Boolean;
1297 {$IF DEFINED(D2F_DEBUG)}
1299 showTime: Boolean = true;
1302 a := GetAngle(x, y, xd, yd)+180;
1304 SinCos(DegToRad(-a), s, c);
1306 if Abs(s) < 0.01 then s := 0;
1307 if Abs(c) < 0.01 then c := 0;
1309 x2 := x+Round(c*gMapInfo.Width);
1310 y2 := y+Round(s*gMapInfo.Width);
1312 t1 := gWalls <> nil;
1314 w := gMapInfo.Width;
1315 h := gMapInfo.Height;
1322 if (xd = 0) and (yd = 0) then Exit;
1324 if dx > 0 then xi := 1 else if dx < 0 then xi := -1 else xi := 0;
1325 if dy > 0 then yi := 1 else if dy < 0 then yi := -1 else yi := 0;
1330 if dx > dy then d := dx else d := dy;
1332 //blood vel, for Monster.Damage()
1333 //vx := (dx*10 div d)*xi;
1334 //vy := (dy*10 div d)*yi;
1336 {$IF DEFINED(D2F_DEBUG)}
1337 stt := getTimeMicro();
1360 if (yy > h) or (yy < 0) then Break;
1361 if (xx > w) or (xx < 0) then Break;
1364 if ByteBool(gCollideMap[yy, xx] and MARK_BLOCKED) then
1367 {$IF DEFINED(D2F_DEBUG)}
1368 stt := getTimeMicro()-stt;
1369 e_WriteLog(Format('*** old trace time: %u microseconds', [LongWord(stt)]), MSG_NOTIFY);
1372 g_GFX_Spark(xx-xi, yy-yi, 2+Random(2), 180+a, 0, 0);
1373 if g_Game_IsServer and g_Game_IsNet then
1374 MH_SEND_Effect(xx-xi, yy-yi, 180+a, NET_GFX_SPARK);
1377 if not _collide then
1379 _collide := GunHit(xx, yy, xi*v, yi*v, dmg, SpawnerUID, v <> 0) <> 0;
1382 if _collide then Break;
1385 {$IF DEFINED(D2F_DEBUG)}
1388 stt := getTimeMicro()-stt;
1389 e_WriteLog(Format('*** old trace time: %u microseconds', [LongWord(stt)]), MSG_NOTIFY);
1393 if CheckTrigger and g_Game_IsServer then
1394 g_Triggers_PressL(X, Y, xx-xi, yy-yi, SpawnerUID, ACTIVATE_SHOT);
1400 procedure g_Weapon_gun (const x
, y
, xd
, yd
, v
, indmg
: Integer; SpawnerUID
: Word; CheckTrigger
: Boolean);
1405 wallDistSq
: Integer = $3fffffff;
1406 spawnerPlr
: TPlayer
= nil;
1409 function doPlayerHit (idx
: Integer; hx
, hy
: Integer): Boolean;
1412 if (idx
< 0) or (idx
> High(gPlayers
)) then exit
;
1413 if (gPlayers
[idx
] = nil) or not gPlayers
[idx
].alive
then exit
;
1414 if (spawnerPlr
<> nil) then
1416 if ((gGameSettings
.Options
and (GAME_OPTION_TEAMHITTRACE
or GAME_OPTION_TEAMDAMAGE
)) = 0) and
1417 (spawnerPlr
.Team
<> TEAM_NONE
) and (spawnerPlr
.Team
= gPlayers
[idx
].Team
) then
1419 if (spawnerPlr
<> gPlayers
[idx
]) and ((gGameSettings
.Options
and GAME_OPTION_TEAMABSORBDAMAGE
) = 0) then
1420 dmg
:= Max(1, dmg
div 2);
1424 result
:= HitPlayer(gPlayers
[idx
], dmg
, (xi
*v
)*10, (yi
*v
)*10-3, SpawnerUID
, HIT_SOME
);
1425 if result
and (v
<> 0) then gPlayers
[idx
].Push((xi
*v
), (yi
*v
));
1426 {$IF DEFINED(D2F_DEBUG)}
1427 //if result then e_WriteLog(Format(' PLAYER #%d HIT', [idx]), MSG_NOTIFY);
1431 function doMonsterHit (mon
: TMonster
; hx
, hy
: Integer): Boolean;
1434 if (mon
= nil) then exit
;
1435 result
:= HitMonster(mon
, dmg
, (xi
*v
)*10, (yi
*v
)*10-3, SpawnerUID
, HIT_SOME
);
1436 if result
and (v
<> 0) then mon
.Push((xi
*v
), (yi
*v
));
1437 {$IF DEFINED(D2F_DEBUG)}
1438 //if result then e_WriteLog(Format(' MONSTER #%u HIT', [LongWord(mon.UID)]), MSG_NOTIFY);
1442 // collect players along hitray
1443 // return `true` if instant hit was detected
1444 function playerPossibleHit (): Boolean;
1447 px
, py
, pw
, ph
: Integer;
1453 for i
:= 0 to High(gPlayers
) do
1456 if (plr
<> nil) and plr
.alive
then
1458 plr
.getMapBox(px
, py
, pw
, ph
);
1459 if lineAABBIntersects(x
, y
, x2
, y2
, px
, py
, pw
, ph
, inx
, iny
) then
1461 distSq
:= distanceSq(x
, y
, inx
, iny
);
1462 if (distSq
= 0) then
1465 if doPlayerHit(i
, x
, y
) then begin result
:= true; exit
; end;
1467 else if (distSq
< wallDistSq
) then
1469 appendHitTimePlr(distSq
, i
, inx
, iny
);
1476 procedure sqchecker (mon
: TMonster
);
1478 mx
, my
, mw
, mh
: Integer;
1482 mon
.getMapBox(mx
, my
, mw
, mh
);
1483 if lineAABBIntersects(x0
, y0
, x2
, y2
, mx
, my
, mw
, mh
, inx
, iny
) then
1485 distSq
:= distanceSq(x0
, y0
, inx
, iny
);
1486 if (distSq
< wallDistSq
) then appendHitTimeMon(distSq
, mon
, inx
, iny
);
1496 wallHitFlag
: Boolean = false;
1497 wallHitX
: Integer = 0;
1498 wallHitY
: Integer = 0;
1499 didHit
: Boolean = false;
1500 {$IF DEFINED(D2F_DEBUG)}
1504 it
: TMonsterGrid
.Iter
;
1507 if not gwep_debug_fast_trace then
1509 g_Weapon_gunOld(x, y, xd, yd, v, dmg, SpawnerUID, CheckTrigger);
1514 if (xd
= 0) and (yd
= 0) then exit
;
1516 if (g_GetUIDType(SpawnerUID
) = UID_PLAYER
) then
1517 spawnerPlr
:= g_Player_Get(SpawnerUID
);
1521 //wgunMonHash.reset(); //FIXME: clear hash on level change
1522 wgunHitHeap
.clear();
1523 wgunHitTimeUsed
:= 0;
1525 a
:= GetAngle(x
, y
, xd
, yd
)+180;
1527 SinCos(DegToRad(-a
), s
, c
);
1529 if Abs(s
) < 0.01 then s
:= 0;
1530 if Abs(c
) < 0.01 then c
:= 0;
1534 x2
:= x
+Round(c
*gMapInfo
.Width
);
1535 y2
:= y
+Round(s
*gMapInfo
.Width
);
1540 if (dx
> 0) then xi
:= 1 else if (dx
< 0) then xi
:= -1 else xi
:= 0;
1541 if (dy
> 0) then yi
:= 1 else if (dy
< 0) then yi
:= -1 else yi
:= 0;
1543 {$IF DEFINED(D2F_DEBUG)}
1544 e_WriteLog(Format('GUN TRACE: (%d,%d) to (%d,%d)', [x
, y
, x2
, y2
]), TMsgType
.Notify
);
1545 stt
:= getTimeMicro();
1548 wallHitFlag
:= (g_Map_traceToNearestWall(x
, y
, x2
, y2
, @wallHitX
, @wallHitY
) <> nil);
1553 wallDistSq
:= distanceSq(x
, y
, wallHitX
, wallHitY
);
1561 if playerPossibleHit() then exit
; // instant hit
1564 //g_Mons_AlongLine(x, y, x2, y2, sqchecker);
1566 it
:= monsGrid
.forEachAlongLine(x
, y
, x2
, y2
, -1);
1567 for mit
in it
do sqchecker(mit
^);
1570 // here, we collected all monsters and players in `wgunHitHeap` and `wgunHitTime`
1571 // also, if `wallWasHit` is `true`, then `wallHitX` and `wallHitY` contains spark coords
1572 while (wgunHitHeap
.count
> 0) do
1574 // has some entities to check, do it
1575 i
:= wgunHitHeap
.front
;
1576 wgunHitHeap
.popFront();
1578 xe
:= wgunHitTime
[i
].x
;
1579 ye
:= wgunHitTime
[i
].y
;
1580 // check if it is not behind the wall
1581 if (wgunHitTime
[i
].mon
<> nil) then
1583 didHit
:= doMonsterHit(wgunHitTime
[i
].mon
, xe
, ye
);
1587 didHit
:= doPlayerHit(wgunHitTime
[i
].plridx
, xe
, ye
);
1591 // need new coords for trigger
1594 wallHitFlag
:= false; // no sparks
1602 {$IF DEFINED(D2F_DEBUG)}
1603 stt
:= getTimeMicro()-stt
;
1604 e_WriteLog(Format('*** new trace time: %u microseconds', [LongWord(stt
)]), TMsgType
.Notify
);
1606 g_GFX_Spark(wallHitX
, wallHitY
, 2+Random(2), 180+a
, 0, 0);
1607 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Effect(wallHitX
, wallHitY
, 180+a
, NET_GFX_SPARK
);
1611 {$IF DEFINED(D2F_DEBUG)}
1612 stt
:= getTimeMicro()-stt
;
1613 e_WriteLog(Format('*** new trace time: %u microseconds', [LongWord(stt
)]), TMsgType
.Notify
);
1617 if CheckTrigger
and g_Game_IsServer
then g_Triggers_PressL(X
, Y
, wallHitX
, wallHitY
, SpawnerUID
, ACTIVATE_SHOT
);
1621 procedure g_Weapon_punch(x
, y
: Integer; d
, SpawnerUID
: Word);
1629 obj
.rect
.Width
:= 39;
1630 obj
.rect
.Height
:= 52;
1636 if g_Weapon_Hit(@obj
, d
, SpawnerUID
, HIT_SOME
) <> 0 then
1637 g_Sound_PlayExAt('SOUND_WEAPON_HITPUNCH', x
, y
)
1639 g_Sound_PlayExAt('SOUND_WEAPON_MISSPUNCH', x
, y
);
1642 function g_Weapon_chainsaw(x
, y
: Integer; d
, SpawnerUID
: Word): Integer;
1650 obj
.rect
.Width
:= 32;
1651 obj
.rect
.Height
:= 52;
1657 Result
:= g_Weapon_Hit(@obj
, d
, SpawnerUID
, HIT_SOME
);
1660 procedure g_Weapon_rocket(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1;
1661 Silent
: Boolean = False; compat
: Boolean = true);
1667 find_id
:= FindShot()
1671 if Integer(find_id
) >= High(Shots
) then
1672 SetLength(Shots
, find_id
+ 64)
1675 with Shots
[find_id
] do
1679 Obj
.Rect
.Width
:= SHOT_ROCKETLAUNCHER_WIDTH
;
1680 Obj
.Rect
.Height
:= SHOT_ROCKETLAUNCHER_HEIGHT
;
1683 dx
:= IfThen(xd
> x
, -Obj
.Rect
.Width
, 0)
1685 dx
:= -(Obj
.Rect
.Width
div 2);
1686 dy
:= -(Obj
.Rect
.Height
div 2);
1688 ShotType
:= WEAPON_ROCKETLAUNCHER
;
1689 throw(find_id
, x
+dx
, y
+dy
, xd
+dx
, yd
+dy
, 12);
1693 g_Texture_Get('TEXTURE_WEAPON_ROCKET', TextureID
);
1696 Shots
[find_id
].SpawnerUID
:= SpawnerUID
;
1699 g_Sound_PlayExAt('SOUND_WEAPON_FIREROCKET', x
, y
);
1702 procedure g_Weapon_revf(x
, y
, xd
, yd
: Integer; SpawnerUID
, TargetUID
: Word;
1703 WID
: Integer = -1; Silent
: Boolean = False);
1705 find_id
, FramesID
: DWORD
;
1709 find_id
:= FindShot()
1713 if Integer(find_id
) >= High(Shots
) then
1714 SetLength(Shots
, find_id
+ 64)
1717 with Shots
[find_id
] do
1721 Obj
.Rect
.Width
:= SHOT_SKELFIRE_WIDTH
;
1722 Obj
.Rect
.Height
:= SHOT_SKELFIRE_HEIGHT
;
1724 dx
:= -(Obj
.Rect
.Width
div 2);
1725 dy
:= -(Obj
.Rect
.Height
div 2);
1727 ShotType
:= WEAPON_SKEL_FIRE
;
1728 throw(find_id
, x
+dx
, y
+dy
, xd
+dx
, yd
+dy
, 12);
1731 target
:= TargetUID
;
1732 g_Frames_Get(FramesID
, 'FRAMES_WEAPON_SKELFIRE');
1733 Animation
:= TAnimation
.Create(FramesID
, True, 5);
1736 Shots
[find_id
].SpawnerUID
:= SpawnerUID
;
1739 g_Sound_PlayExAt('SOUND_WEAPON_FIREREV', x
, y
);
1742 procedure g_Weapon_plasma(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1;
1743 Silent
: Boolean = False; compat
: Boolean = true);
1745 find_id
, FramesID
: DWORD
;
1749 find_id
:= FindShot()
1753 if Integer(find_id
) >= High(Shots
) then
1754 SetLength(Shots
, find_id
+ 64);
1757 with Shots
[find_id
] do
1761 Obj
.Rect
.Width
:= SHOT_PLASMA_WIDTH
;
1762 Obj
.Rect
.Height
:= SHOT_PLASMA_HEIGHT
;
1765 dx
:= IfThen(xd
> x
, -Obj
.Rect
.Width
, 0)
1767 dx
:= -(Obj
.Rect
.Width
div 2);
1768 dy
:= -(Obj
.Rect
.Height
div 2);
1770 ShotType
:= WEAPON_PLASMA
;
1771 throw(find_id
, x
+dx
, y
+dy
, xd
+dx
, yd
+dy
, 16);
1774 g_Frames_Get(FramesID
, 'FRAMES_WEAPON_PLASMA');
1775 Animation
:= TAnimation
.Create(FramesID
, True, 5);
1778 Shots
[find_id
].SpawnerUID
:= SpawnerUID
;
1781 g_Sound_PlayExAt('SOUND_WEAPON_FIREPLASMA', x
, y
);
1784 procedure g_Weapon_flame(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1;
1785 Silent
: Boolean = False; compat
: Boolean = true);
1791 find_id
:= FindShot()
1795 if Integer(find_id
) >= High(Shots
) then
1796 SetLength(Shots
, find_id
+ 64);
1799 with Shots
[find_id
] do
1803 Obj
.Rect
.Width
:= SHOT_FLAME_WIDTH
;
1804 Obj
.Rect
.Height
:= SHOT_FLAME_HEIGHT
;
1807 dx
:= IfThen(xd
> x
, -Obj
.Rect
.Width
, 0)
1809 dx
:= -(Obj
.Rect
.Width
div 2);
1810 dy
:= -(Obj
.Rect
.Height
div 2);
1812 ShotType
:= WEAPON_FLAMETHROWER
;
1813 throw(find_id
, x
+dx
, y
+dy
, xd
+dx
, yd
+dy
, 16);
1818 g_Frames_Get(TextureID
, 'FRAMES_FLAME');
1821 Shots
[find_id
].SpawnerUID
:= SpawnerUID
;
1823 // if not Silent then
1824 // g_Sound_PlayExAt('SOUND_WEAPON_FIREPLASMA', x, y);
1827 procedure g_Weapon_ball1(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1;
1828 Silent
: Boolean = False; compat
: Boolean = true);
1830 find_id
, FramesID
: DWORD
;
1834 find_id
:= FindShot()
1838 if Integer(find_id
) >= High(Shots
) then
1839 SetLength(Shots
, find_id
+ 64)
1842 with Shots
[find_id
] do
1846 Obj
.Rect
.Width
:= 16;
1847 Obj
.Rect
.Height
:= 16;
1850 dx
:= IfThen(xd
> x
, -Obj
.Rect
.Width
, 0)
1852 dx
:= -(Obj
.Rect
.Width
div 2);
1853 dy
:= -(Obj
.Rect
.Height
div 2);
1855 ShotType
:= WEAPON_IMP_FIRE
;
1856 throw(find_id
, x
+dx
, y
+dy
, xd
+dx
, yd
+dy
, 16);
1859 g_Frames_Get(FramesID
, 'FRAMES_WEAPON_IMPFIRE');
1860 Animation
:= TAnimation
.Create(FramesID
, True, 4);
1863 Shots
[find_id
].SpawnerUID
:= SpawnerUID
;
1866 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x
, y
);
1869 procedure g_Weapon_ball2(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1;
1870 Silent
: Boolean = False; compat
: Boolean = true);
1872 find_id
, FramesID
: DWORD
;
1876 find_id
:= FindShot()
1880 if Integer(find_id
) >= High(Shots
) then
1881 SetLength(Shots
, find_id
+ 64)
1884 with Shots
[find_id
] do
1888 Obj
.Rect
.Width
:= 16;
1889 Obj
.Rect
.Height
:= 16;
1892 dx
:= IfThen(xd
> x
, -Obj
.Rect
.Width
, 0)
1894 dx
:= -(Obj
.Rect
.Width
div 2);
1895 dy
:= -(Obj
.Rect
.Height
div 2);
1897 ShotType
:= WEAPON_CACO_FIRE
;
1898 throw(find_id
, x
+dx
, y
+dy
, xd
+dx
, yd
+dy
, 16);
1901 g_Frames_Get(FramesID
, 'FRAMES_WEAPON_CACOFIRE');
1902 Animation
:= TAnimation
.Create(FramesID
, True, 4);
1905 Shots
[find_id
].SpawnerUID
:= SpawnerUID
;
1908 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x
, y
);
1911 procedure g_Weapon_ball7(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1;
1912 Silent
: Boolean = False; compat
: Boolean = true);
1914 find_id
, FramesID
: DWORD
;
1918 find_id
:= FindShot()
1922 if Integer(find_id
) >= High(Shots
) then
1923 SetLength(Shots
, find_id
+ 64)
1926 with Shots
[find_id
] do
1930 Obj
.Rect
.Width
:= 16;
1931 Obj
.Rect
.Height
:= 16;
1934 dx
:= IfThen(xd
> x
, -Obj
.Rect
.Width
, 0)
1936 dx
:= -(Obj
.Rect
.Width
div 2);
1937 dy
:= -(Obj
.Rect
.Height
div 2);
1939 ShotType
:= WEAPON_BARON_FIRE
;
1940 throw(find_id
, x
+dx
, y
+dy
, xd
+dx
, yd
+dy
, 16);
1943 g_Frames_Get(FramesID
, 'FRAMES_WEAPON_BARONFIRE');
1944 Animation
:= TAnimation
.Create(FramesID
, True, 4);
1947 Shots
[find_id
].SpawnerUID
:= SpawnerUID
;
1950 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x
, y
);
1953 procedure g_Weapon_aplasma(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1;
1954 Silent
: Boolean = False; compat
: Boolean = true);
1956 find_id
, FramesID
: DWORD
;
1960 find_id
:= FindShot()
1964 if Integer(find_id
) >= High(Shots
) then
1965 SetLength(Shots
, find_id
+ 64)
1968 with Shots
[find_id
] do
1972 Obj
.Rect
.Width
:= 16;
1973 Obj
.Rect
.Height
:= 16;
1976 dx
:= IfThen(xd
> x
, -Obj
.Rect
.Width
, 0)
1978 dx
:= -(Obj
.Rect
.Width
div 2);
1979 dy
:= -(Obj
.Rect
.Height
div 2);
1981 ShotType
:= WEAPON_BSP_FIRE
;
1982 throw(find_id
, x
+dx
, y
+dy
, xd
+dx
, yd
+dy
, 16);
1986 g_Frames_Get(FramesID
, 'FRAMES_WEAPON_BSPFIRE');
1987 Animation
:= TAnimation
.Create(FramesID
, True, 4);
1990 Shots
[find_id
].SpawnerUID
:= SpawnerUID
;
1993 g_Sound_PlayExAt('SOUND_WEAPON_FIREPLASMA', x
, y
);
1996 procedure g_Weapon_manfire(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1;
1997 Silent
: Boolean = False; compat
: Boolean = true);
1999 find_id
, FramesID
: DWORD
;
2003 find_id
:= FindShot()
2007 if Integer(find_id
) >= High(Shots
) then
2008 SetLength(Shots
, find_id
+ 64)
2011 with Shots
[find_id
] do
2015 Obj
.Rect
.Width
:= 32;
2016 Obj
.Rect
.Height
:= 32;
2019 dx
:= IfThen(xd
> x
, -Obj
.Rect
.Width
, 0)
2021 dx
:= -(Obj
.Rect
.Width
div 2);
2022 dy
:= -(Obj
.Rect
.Height
div 2);
2024 ShotType
:= WEAPON_MANCUB_FIRE
;
2025 throw(find_id
, x
+dx
, y
+dy
, xd
+dx
, yd
+dy
, 16);
2029 g_Frames_Get(FramesID
, 'FRAMES_WEAPON_MANCUBFIRE');
2030 Animation
:= TAnimation
.Create(FramesID
, True, 4);
2033 Shots
[find_id
].SpawnerUID
:= SpawnerUID
;
2036 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x
, y
);
2039 procedure g_Weapon_bfgshot(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1;
2040 Silent
: Boolean = False; compat
: Boolean = true);
2042 find_id
, FramesID
: DWORD
;
2046 find_id
:= FindShot()
2050 if Integer(find_id
) >= High(Shots
) then
2051 SetLength(Shots
, find_id
+ 64)
2054 with Shots
[find_id
] do
2058 Obj
.Rect
.Width
:= SHOT_BFG_WIDTH
;
2059 Obj
.Rect
.Height
:= SHOT_BFG_HEIGHT
;
2062 dx
:= IfThen(xd
> x
, -Obj
.Rect
.Width
, 0)
2064 dx
:= -(Obj
.Rect
.Width
div 2);
2065 dy
:= -(Obj
.Rect
.Height
div 2);
2067 ShotType
:= WEAPON_BFG
;
2068 throw(find_id
, x
+dx
, y
+dy
, xd
+dx
, yd
+dy
, 16);
2071 g_Frames_Get(FramesID
, 'FRAMES_WEAPON_BFG');
2072 Animation
:= TAnimation
.Create(FramesID
, True, 6);
2075 Shots
[find_id
].SpawnerUID
:= SpawnerUID
;
2078 g_Sound_PlayExAt('SOUND_WEAPON_FIREBFG', x
, y
);
2081 procedure g_Weapon_bfghit(x
, y
: Integer);
2086 if g_Frames_Get(ID
, 'FRAMES_BFGHIT') then
2088 Anim
:= TAnimation
.Create(ID
, False, 4);
2089 g_GFX_OnceAnim(x
-32, y
-32, Anim
);
2094 procedure g_Weapon_pistol(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word;
2095 Silent
: Boolean = False);
2098 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', x
, y
);
2100 g_Weapon_gun(x
, y
, xd
, yd
, 1, 3, SpawnerUID
, True);
2101 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
] then
2103 if ABS(x
-xd
) >= ABS(y
-yd
) then
2105 g_Weapon_gun(x
, y
+1, xd
, yd
+1, 1, 3, SpawnerUID
, False);
2106 g_Weapon_gun(x
, y
-1, xd
, yd
-1, 1, 2, SpawnerUID
, False);
2110 g_Weapon_gun(x
+1, y
, xd
+1, yd
, 1, 3, SpawnerUID
, False);
2111 g_Weapon_gun(x
-1, y
, xd
-1, yd
, 1, 2, SpawnerUID
, False);
2116 procedure g_Weapon_mgun(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word;
2117 Silent
: Boolean = False);
2120 if gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', x
, y
);
2122 g_Weapon_gun(x
, y
, xd
, yd
, 1, 3, SpawnerUID
, True);
2123 if (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) and
2124 (g_GetUIDType(SpawnerUID
) = UID_PLAYER
) then
2126 if ABS(x
-xd
) >= ABS(y
-yd
) then
2128 g_Weapon_gun(x
, y
+1, xd
, yd
+1, 1, 2, SpawnerUID
, False);
2129 g_Weapon_gun(x
, y
-1, xd
, yd
-1, 1, 2, SpawnerUID
, False);
2133 g_Weapon_gun(x
+1, y
, xd
+1, yd
, 1, 2, SpawnerUID
, False);
2134 g_Weapon_gun(x
-1, y
, xd
-1, yd
, 1, 2, SpawnerUID
, False);
2139 procedure g_Weapon_shotgun(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word;
2140 Silent
: Boolean = False);
2145 if gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', x
, y
);
2150 if ABS(x
-xd
) >= ABS(y
-yd
) then j
:= Random(17) - 8 else k
:= Random(17) - 8; // -8 .. 8
2151 g_Weapon_gun(x
+k
, y
+j
, xd
+k
, yd
+j
, IfThen(i
mod 2 <> 0, 1, 0), 3, SpawnerUID
, i
=0);
2155 procedure g_Weapon_dshotgun(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word;
2156 Silent
: Boolean = False);
2158 a
, i
, j
, k
: Integer;
2161 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', x
, y
);
2163 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
] then a
:= 25 else a
:= 20;
2167 if ABS(x
-xd
) >= ABS(y
-yd
) then j
:= Random(41) - 20 else k
:= Random(41) - 20; // -20 .. 20
2168 g_Weapon_gun(x
+k
, y
+j
, xd
+k
, yd
+j
, IfThen(i
mod 3 <> 0, 0, 1), 3, SpawnerUID
, i
=0);
2172 procedure g_Weapon_PreUpdate();
2176 if Shots
= nil then Exit
;
2177 for i
:= 0 to High(Shots
) do
2178 if Shots
[i
].ShotType
<> 0 then
2180 Shots
[i
].Obj
.oldX
:= Shots
[i
].Obj
.X
;
2181 Shots
[i
].Obj
.oldY
:= Shots
[i
].Obj
.Y
;
2185 procedure g_Weapon_Update();
2187 i
, a
, h
, cx
, cy
, oldvx
, oldvy
, tf
: Integer;
2201 for i
:= 0 to High(Shots
) do
2203 if Shots
[i
].ShotType
= 0 then
2210 Timeout
:= Timeout
- 1;
2213 // Àêòèâèðîâàòü òðèããåðû ïî ïóòè (êðîìå óæå àêòèâèðîâàííûõ):
2214 if (Stopped
= 0) and g_Game_IsServer
then
2215 t
:= g_Triggers_PressR(Obj
.X
, Obj
.Y
, Obj
.Rect
.Width
, Obj
.Rect
.Height
,
2216 SpawnerUID
, ACTIVATE_SHOT
, triggers
)
2222 // Ïîïîëíÿåì ñïèñîê àêòèâèðîâàííûõ òðèããåðîâ:
2223 if triggers
= nil then
2230 if not InDWArray(t
[a
], triggers
) then
2232 SetLength(triggers
, Length(triggers
)+1);
2233 triggers
[High(triggers
)] := t
[a
];
2238 // Àíèìàöèÿ ñíàðÿäà:
2239 if Animation
<> nil then
2243 spl
:= (ShotType
<> WEAPON_PLASMA
) and
2244 (ShotType
<> WEAPON_BFG
) and
2245 (ShotType
<> WEAPON_BSP_FIRE
) and
2246 (ShotType
<> WEAPON_FLAMETHROWER
);
2250 st
:= g_Obj_Move_Projectile(@Obj
, False, spl
);
2256 positionChanged(); // this updates spatial accelerators
2258 if WordBool(st
and MOVE_FALLOUT
) or (Obj
.X
< -1000) or
2259 (Obj
.X
> gMapInfo
.Width
+1000) or (Obj
.Y
< -1000) then
2261 // Íà êëèåíòå ñêîðåå âñåãî è òàê óæå âûïàë.
2267 cx
:= Obj
.X
+ (Obj
.Rect
.Width
div 2);
2268 cy
:= Obj
.Y
+ (Obj
.Rect
.Height
div 2);
2271 WEAPON_ROCKETLAUNCHER
, WEAPON_SKEL_FIRE
: // Ðàêåòû è ñíàðÿäû Ñêåëåòà
2273 // Âûëåòåëà èç âîäû:
2274 if WordBool(st
and MOVE_HITAIR
) then
2275 g_Obj_SetSpeed(@Obj
, 12);
2277 // Â âîäå øëåéô - ïóçûðè, â âîçäóõå øëåéô - äûì:
2278 if WordBool(st
and MOVE_INWATER
) then
2280 g_GFX_Bubbles(cx
, cy
, 1+Random(3), 16, 16);
2282 then g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', cx
, cy
)
2283 else g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', cx
, cy
);
2285 else if g_Frames_Get(_id
, 'FRAMES_SMOKE') then
2287 Anim
:= TAnimation
.Create(_id
, False, 3);
2289 g_GFX_OnceAnim(Obj
.X
-14+Random(9), cy
-20+Random(9),
2290 Anim
, ONCEANIM_SMOKE
);
2294 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2295 if WordBool(st
and (MOVE_HITWALL
or MOVE_HITLAND
or MOVE_HITCEIL
)) or
2296 (g_Weapon_Hit(@Obj
, 10, SpawnerUID
, HIT_SOME
, False) <> 0) or
2302 g_Weapon_Explode(cx
, cy
, 60, SpawnerUID
);
2304 if ShotType
= WEAPON_SKEL_FIRE
then
2305 begin // Âçðûâ ñíàðÿäà Ñêåëåòà
2306 if g_Frames_Get(TextureID
, 'FRAMES_EXPLODE_SKELFIRE') then
2308 Anim
:= TAnimation
.Create(TextureID
, False, 8);
2309 Anim
.Blending
:= False;
2310 g_GFX_OnceAnim((Obj
.X
+32)-58, (Obj
.Y
+8)-36, Anim
);
2311 g_DynLightExplosion((Obj
.X
+32), (Obj
.Y
+8), 64, 1, 0, 0);
2316 begin // Âçðûâ Ðàêåòû
2317 if g_Frames_Get(TextureID
, 'FRAMES_EXPLODE_ROCKET') then
2319 Anim
:= TAnimation
.Create(TextureID
, False, 6);
2320 Anim
.Blending
:= False;
2321 g_GFX_OnceAnim(cx
-64, cy
-64, Anim
);
2322 g_DynLightExplosion(cx
, cy
, 64, 1, 0, 0);
2327 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', Obj
.X
, Obj
.Y
);
2332 if ShotType
= WEAPON_SKEL_FIRE
then
2333 begin // Ñàìîíàâîäêà ñíàðÿäà Ñêåëåòà:
2334 if GetPos(target
, @o
) then
2335 throw(i
, Obj
.X
, Obj
.Y
,
2336 o
.X
+o
.Rect
.X
+(o
.Rect
.Width
div 2)+o
.Vel
.X
+o
.Accel
.X
,
2337 o
.Y
+o
.Rect
.Y
+(o
.Rect
.Height
div 2)+o
.Vel
.Y
+o
.Accel
.Y
,
2342 WEAPON_PLASMA
, WEAPON_BSP_FIRE
: // Ïëàçìà, ïëàçìà Àðàõíàòðîíà
2344 // Ïîïàëà â âîäó - ýëåêòðîøîê ïî âîäå:
2345 if WordBool(st
and (MOVE_INWATER
or MOVE_HITWATER
)) then
2347 g_Sound_PlayExAt('SOUND_WEAPON_PLASMAWATER', Obj
.X
, Obj
.Y
);
2348 if g_Game_IsServer
then CheckTrap(i
, 10, HIT_ELECTRO
);
2354 if (ShotType
= WEAPON_PLASMA
) and
2355 (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) then
2360 if ShotType
= WEAPON_BSP_FIRE
then
2363 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2364 if WordBool(st
and (MOVE_HITWALL
or MOVE_HITLAND
or MOVE_HITCEIL
)) or
2365 (g_Weapon_Hit(@Obj
, a
, SpawnerUID
, HIT_SOME
, False) <> 0) or
2368 if ShotType
= WEAPON_PLASMA
then
2369 s
:= 'FRAMES_EXPLODE_PLASMA'
2371 s
:= 'FRAMES_EXPLODE_BSPFIRE';
2374 if g_Frames_Get(TextureID
, s
) then
2376 Anim
:= TAnimation
.Create(TextureID
, False, 3);
2377 Anim
.Blending
:= False;
2378 g_GFX_OnceAnim(cx
-16, cy
-16, Anim
);
2380 g_DynLightExplosion(cx
, cy
, 32, 0, 0.5, 0.5);
2383 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEPLASMA', Obj
.X
, Obj
.Y
);
2389 WEAPON_FLAMETHROWER
: // Îãíåìåò
2391 // Ñî âðåìåíåì óìèðàåò
2392 if (Timeout
< 1) then
2398 if WordBool(st
and (MOVE_HITWATER
or MOVE_INWATER
)) then
2400 if WordBool(st
and MOVE_HITWATER
) then
2402 if g_Frames_Get(_id
, 'FRAMES_SMOKE') then
2404 Anim
:= TAnimation
.Create(_id
, False, 3);
2408 g_GFX_OnceAnim(cx
-4+tcx
-(Anim
.Width
div 2),
2409 cy
-4+tcy
-(Anim
.Height
div 2),
2410 Anim
, ONCEANIM_SMOKE
);
2416 g_GFX_Bubbles(cx
, cy
, 1+Random(3), 16, 16);
2418 then g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', cx
, cy
)
2419 else g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', cx
, cy
);
2427 Obj
.Accel
.Y
:= Obj
.Accel
.Y
+ 1;
2428 // Ïîïàëè â ñòåíó èëè â âîäó:
2429 if WordBool(st
and (MOVE_HITWALL
or MOVE_HITLAND
or MOVE_HITCEIL
or MOVE_HITWATER
)) then
2435 if WordBool(st
and MOVE_HITWALL
) then
2436 Stopped
:= MOVE_HITWALL
2437 else if WordBool(st
and MOVE_HITLAND
) then
2438 Stopped
:= MOVE_HITLAND
2439 else if WordBool(st
and MOVE_HITCEIL
) then
2440 Stopped
:= MOVE_HITCEIL
;
2443 a
:= IfThen(Stopped
= 0, 10, 1);
2444 // Åñëè â êîãî-òî ïîïàëè
2445 if g_Weapon_Hit(@Obj
, a
, SpawnerUID
, HIT_FLAME
, False) <> 0 then
2447 // HIT_FLAME ñàì ïîäîææåò
2448 // Åñëè â ïîëåòå ïîïàëè, èñ÷åçàåì
2458 if (gTime
mod LongWord(tf
) = 0) then
2460 Anim
:= TAnimation
.Create(TextureID
, False, 2 + Random(2));
2463 MOVE_HITWALL
: begin tcx
:= cx
-4+Random(8); tcy
:= cy
-12+Random(24); end;
2464 MOVE_HITLAND
: begin tcx
:= cx
-12+Random(24); tcy
:= cy
-10+Random(8); end;
2465 MOVE_HITCEIL
: begin tcx
:= cx
-12+Random(24); tcy
:= cy
+6+Random(8); end;
2466 else begin tcx
:= cx
-4+Random(8); tcy
:= cy
-4+Random(8); end;
2468 g_GFX_OnceAnim(tcx
-(Anim
.Width
div 2), tcy
-(Anim
.Height
div 2), Anim
, ONCEANIM_SMOKE
);
2470 //g_DynLightExplosion(tcx, tcy, 1, 1, 0.8, 0.3);
2476 // Ïîïàëà â âîäó - ýëåêòðîøîê ïî âîäå:
2477 if WordBool(st
and (MOVE_INWATER
or MOVE_HITWATER
)) then
2479 g_Sound_PlayExAt('SOUND_WEAPON_BFGWATER', Obj
.X
, Obj
.Y
);
2480 if g_Game_IsServer
then CheckTrap(i
, 1000, HIT_ELECTRO
);
2485 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2486 if WordBool(st
and (MOVE_HITWALL
or MOVE_HITLAND
or MOVE_HITCEIL
)) or
2487 (g_Weapon_Hit(@Obj
, SHOT_BFG_DAMAGE
, SpawnerUID
, HIT_BFG
, False) <> 0) or
2491 if g_Game_IsServer
then g_Weapon_BFG9000(cx
, cy
, SpawnerUID
);
2494 if g_Frames_Get(TextureID
, 'FRAMES_EXPLODE_BFG') then
2496 Anim
:= TAnimation
.Create(TextureID
, False, 6);
2497 Anim
.Blending
:= False;
2498 g_GFX_OnceAnim(cx
-64, cy
-64, Anim
);
2500 g_DynLightExplosion(cx
, cy
, 96, 0, 1, 0);
2503 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', Obj
.X
, Obj
.Y
);
2509 WEAPON_IMP_FIRE
, WEAPON_CACO_FIRE
, WEAPON_BARON_FIRE
: // Âûñòðåëû Áåñà, Êàêîäåìîíà Ðûöàðÿ/Áàðîíà àäà
2512 if WordBool(st
and MOVE_HITAIR
) then
2513 g_Obj_SetSpeed(@Obj
, 16);
2516 if ShotType
= WEAPON_IMP_FIRE
then
2519 if ShotType
= WEAPON_CACO_FIRE
then
2524 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2525 if WordBool(st
and (MOVE_HITWALL
or MOVE_HITLAND
or MOVE_HITCEIL
)) or
2526 (g_Weapon_Hit(@Obj
, a
, SpawnerUID
, HIT_SOME
) <> 0) or
2529 if ShotType
= WEAPON_IMP_FIRE
then
2530 s
:= 'FRAMES_EXPLODE_IMPFIRE'
2532 if ShotType
= WEAPON_CACO_FIRE
then
2533 s
:= 'FRAMES_EXPLODE_CACOFIRE'
2535 s
:= 'FRAMES_EXPLODE_BARONFIRE';
2538 if g_Frames_Get(TextureID
, s
) then
2540 Anim
:= TAnimation
.Create(TextureID
, False, 6);
2541 Anim
.Blending
:= False;
2542 g_GFX_OnceAnim(cx
-32, cy
-32, Anim
);
2546 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj
.X
, Obj
.Y
);
2552 WEAPON_MANCUB_FIRE
: // Âûñòðåë Ìàíêóáóñà
2555 if WordBool(st
and MOVE_HITAIR
) then
2556 g_Obj_SetSpeed(@Obj
, 16);
2558 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2559 if WordBool(st
and (MOVE_HITWALL
or MOVE_HITLAND
or MOVE_HITCEIL
)) or
2560 (g_Weapon_Hit(@Obj
, 40, SpawnerUID
, HIT_SOME
, False) <> 0) or
2564 if g_Frames_Get(TextureID
, 'FRAMES_EXPLODE_ROCKET') then
2566 Anim
:= TAnimation
.Create(TextureID
, False, 6);
2567 Anim
.Blending
:= False;
2568 g_GFX_OnceAnim(cx
-64, cy
-64, Anim
);
2572 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj
.X
, Obj
.Y
);
2577 end; // case ShotType of...
2579 // Åñëè ñíàðÿäà óæå íåò, óäàëÿåì àíèìàöèþ:
2580 if (ShotType
= 0) then
2582 if gGameSettings
.GameType
= GT_SERVER
then
2583 MH_SEND_DeleteShot(i
, Obj
.X
, Obj
.Y
, Loud
);
2584 if Animation
<> nil then
2590 else if (ShotType
<> WEAPON_FLAMETHROWER
) and ((oldvx
<> Obj
.Vel
.X
) or (oldvy
<> Obj
.Vel
.Y
)) then
2591 if gGameSettings
.GameType
= GT_SERVER
then
2592 MH_SEND_UpdateShot(i
);
2597 function g_Weapon_Danger(UID
: Word; X
, Y
: Integer; Width
, Height
: Word; Time
: Byte): Boolean;
2606 for a
:= 0 to High(Shots
) do
2607 if (Shots
[a
].ShotType
<> 0) and (Shots
[a
].SpawnerUID
<> UID
) then
2608 if ((Shots
[a
].Obj
.Vel
.Y
= 0) and (Shots
[a
].Obj
.Vel
.X
> 0) and (Shots
[a
].Obj
.X
< X
)) or
2609 (Shots
[a
].Obj
.Vel
.Y
= 0) and (Shots
[a
].Obj
.Vel
.X
< 0) and (Shots
[a
].Obj
.X
> X
) then
2610 if (Abs(X
-Shots
[a
].Obj
.X
) < Abs(Shots
[a
].Obj
.Vel
.X
*Time
)) and
2611 g_Collide(X
, Y
, Width
, Height
, X
, Shots
[a
].Obj
.Y
,
2612 Shots
[a
].Obj
.Rect
.Width
, Shots
[a
].Obj
.Rect
.Height
) and
2613 g_TraceVector(X
, Y
, Shots
[a
].Obj
.X
, Shots
[a
].Obj
.Y
) then
2620 procedure g_Weapon_SaveState (st
: TStream
);
2622 count
, i
, j
: Integer;
2624 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ ñíàðÿäîâ
2626 for i
:= 0 to High(Shots
) do if (Shots
[i
].ShotType
<> 0) then Inc(count
);
2628 // Êîëè÷åñòâî ñíàðÿäîâ
2629 utils
.WriteInt(st
, count
);
2631 if (count
= 0) then exit
;
2633 for i
:= 0 to High(Shots
) do
2635 if Shots
[i
].ShotType
<> 0 then
2637 // Ñèãíàòóðà ñíàðÿäà
2638 utils
.writeSign(st
, 'SHOT');
2639 utils
.writeInt(st
, Byte(0)); // version
2641 utils
.writeInt(st
, Byte(Shots
[i
].ShotType
));
2643 utils
.writeInt(st
, Word(Shots
[i
].Target
));
2645 utils
.writeInt(st
, Word(Shots
[i
].SpawnerUID
));
2646 // Ðàçìåð ïîëÿ Triggers
2647 utils
.writeInt(st
, Integer(Length(Shots
[i
].Triggers
)));
2648 // Òðèããåðû, àêòèâèðîâàííûå âûñòðåëîì
2649 for j
:= 0 to Length(Shots
[i
].Triggers
)-1 do utils
.writeInt(st
, LongWord(Shots
[i
].Triggers
[j
]));
2651 Obj_SaveState(st
, @Shots
[i
].Obj
);
2653 utils
.writeInt(st
, Byte(Shots
[i
].Stopped
));
2658 procedure g_Weapon_LoadState (st
: TStream
);
2660 count
, tc
, i
, j
: Integer;
2663 if (st
= nil) then exit
;
2665 // Êîëè÷åñòâî ñíàðÿäîâ
2666 count
:= utils
.readLongInt(st
);
2667 if (count
< 0) or (count
> 1024*1024) then raise XStreamError
.Create('invalid shots counter');
2669 SetLength(Shots
, count
);
2671 if (count
= 0) then exit
;
2673 for i
:= 0 to count
-1 do
2675 // Ñèãíàòóðà ñíàðÿäà
2676 if not utils
.checkSign(st
, 'SHOT') then raise XStreamError
.Create('invalid shot signature');
2677 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid shot version');
2679 Shots
[i
].ShotType
:= utils
.readByte(st
);
2681 Shots
[i
].Target
:= utils
.readWord(st
);
2683 Shots
[i
].SpawnerUID
:= utils
.readWord(st
);
2684 // Ðàçìåð ïîëÿ Triggers
2685 tc
:= utils
.readLongInt(st
);
2686 if (tc
< 0) or (tc
> 1024*1024) then raise XStreamError
.Create('invalid shot triggers counter');
2687 SetLength(Shots
[i
].Triggers
, tc
);
2688 // Òðèããåðû, àêòèâèðîâàííûå âûñòðåëîì
2689 for j
:= 0 to tc
-1 do Shots
[i
].Triggers
[j
] := utils
.readLongWord(st
);
2691 Obj_LoadState(@Shots
[i
].Obj
, st
);
2693 Shots
[i
].Stopped
:= utils
.readByte(st
);
2695 // Óñòàíîâêà òåêñòóðû èëè àíèìàöèè
2696 Shots
[i
].TextureID
:= DWORD(-1);
2697 Shots
[i
].Animation
:= nil;
2699 case Shots
[i
].ShotType
of
2700 WEAPON_ROCKETLAUNCHER
, WEAPON_SKEL_FIRE
:
2702 g_Texture_Get('TEXTURE_WEAPON_ROCKET', Shots
[i
].TextureID
);
2706 g_Frames_Get(dw
, 'FRAMES_WEAPON_PLASMA');
2707 Shots
[i
].Animation
:= TAnimation
.Create(dw
, True, 5);
2711 g_Frames_Get(dw
, 'FRAMES_WEAPON_BFG');
2712 Shots
[i
].Animation
:= TAnimation
.Create(dw
, True, 6);
2716 g_Frames_Get(dw
, 'FRAMES_WEAPON_IMPFIRE');
2717 Shots
[i
].Animation
:= TAnimation
.Create(dw
, True, 4);
2721 g_Frames_Get(dw
, 'FRAMES_WEAPON_BSPFIRE');
2722 Shots
[i
].Animation
:= TAnimation
.Create(dw
, True, 4);
2726 g_Frames_Get(dw
, 'FRAMES_WEAPON_CACOFIRE');
2727 Shots
[i
].Animation
:= TAnimation
.Create(dw
, True, 4);
2731 g_Frames_Get(dw
, 'FRAMES_WEAPON_BARONFIRE');
2732 Shots
[i
].Animation
:= TAnimation
.Create(dw
, True, 4);
2736 g_Frames_Get(dw
, 'FRAMES_WEAPON_MANCUBFIRE');
2737 Shots
[i
].Animation
:= TAnimation
.Create(dw
, True, 4);
2743 procedure g_Weapon_DestroyShot(I
: Integer; X
, Y
: Integer; Loud
: Boolean = True);
2751 if (I
> High(Shots
)) or (I
< 0) then Exit
;
2755 if ShotType
= 0 then Exit
;
2758 cx
:= Obj
.X
+ (Obj
.Rect
.Width
div 2);
2759 cy
:= Obj
.Y
+ (Obj
.Rect
.Height
div 2);
2762 WEAPON_ROCKETLAUNCHER
, WEAPON_SKEL_FIRE
: // Ðàêåòû è ñíàðÿäû Ñêåëåòà
2766 if ShotType
= WEAPON_SKEL_FIRE
then
2767 begin // Âçðûâ ñíàðÿäà Ñêåëåòà
2768 if g_Frames_Get(TextureID
, 'FRAMES_EXPLODE_SKELFIRE') then
2770 Anim
:= TAnimation
.Create(TextureID
, False, 8);
2771 Anim
.Blending
:= False;
2772 g_GFX_OnceAnim((Obj
.X
+32)-32, (Obj
.Y
+8)-32, Anim
);
2777 begin // Âçðûâ Ðàêåòû
2778 if g_Frames_Get(TextureID
, 'FRAMES_EXPLODE_ROCKET') then
2780 Anim
:= TAnimation
.Create(TextureID
, False, 6);
2781 Anim
.Blending
:= False;
2782 g_GFX_OnceAnim(cx
-64, cy
-64, Anim
);
2786 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', Obj
.X
, Obj
.Y
);
2790 WEAPON_PLASMA
, WEAPON_BSP_FIRE
: // Ïëàçìà, ïëàçìà Àðàõíàòðîíà
2792 if ShotType
= WEAPON_PLASMA
then
2793 s
:= 'FRAMES_EXPLODE_PLASMA'
2795 s
:= 'FRAMES_EXPLODE_BSPFIRE';
2797 if g_Frames_Get(TextureID
, s
) and loud
then
2799 Anim
:= TAnimation
.Create(TextureID
, False, 3);
2800 Anim
.Blending
:= False;
2801 g_GFX_OnceAnim(cx
-16, cy
-16, Anim
);
2804 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEPLASMA', Obj
.X
, Obj
.Y
);
2811 if g_Frames_Get(TextureID
, 'FRAMES_EXPLODE_BFG') and Loud
then
2813 Anim
:= TAnimation
.Create(TextureID
, False, 6);
2814 Anim
.Blending
:= False;
2815 g_GFX_OnceAnim(cx
-64, cy
-64, Anim
);
2818 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', Obj
.X
, Obj
.Y
);
2822 WEAPON_IMP_FIRE
, WEAPON_CACO_FIRE
, WEAPON_BARON_FIRE
: // Âûñòðåëû Áåñà, Êàêîäåìîíà Ðûöàðÿ/Áàðîíà àäà
2824 if ShotType
= WEAPON_IMP_FIRE
then
2825 s
:= 'FRAMES_EXPLODE_IMPFIRE'
2827 if ShotType
= WEAPON_CACO_FIRE
then
2828 s
:= 'FRAMES_EXPLODE_CACOFIRE'
2830 s
:= 'FRAMES_EXPLODE_BARONFIRE';
2832 if g_Frames_Get(TextureID
, s
) and Loud
then
2834 Anim
:= TAnimation
.Create(TextureID
, False, 6);
2835 Anim
.Blending
:= False;
2836 g_GFX_OnceAnim(cx
-32, cy
-32, Anim
);
2839 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj
.X
, Obj
.Y
);
2843 WEAPON_MANCUB_FIRE
: // Âûñòðåë Ìàíêóáóñà
2845 if g_Frames_Get(TextureID
, 'FRAMES_EXPLODE_ROCKET') and Loud
then
2847 Anim
:= TAnimation
.Create(TextureID
, False, 6);
2848 Anim
.Blending
:= False;
2849 g_GFX_OnceAnim(cx
-64, cy
-64, Anim
);
2852 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj
.X
, Obj
.Y
);
2855 end; // case ShotType of...
2863 procedure g_Weapon_AddDynLights();
2867 if Shots
= nil then Exit
;
2868 for i
:= 0 to High(Shots
) do
2870 if Shots
[i
].ShotType
= 0 then continue
;
2871 if (Shots
[i
].ShotType
= WEAPON_ROCKETLAUNCHER
) or
2872 (Shots
[i
].ShotType
= WEAPON_BARON_FIRE
) or
2873 (Shots
[i
].ShotType
= WEAPON_MANCUB_FIRE
) or
2874 (Shots
[i
].ShotType
= WEAPON_SKEL_FIRE
) or
2875 (Shots
[i
].ShotType
= WEAPON_IMP_FIRE
) or
2876 (Shots
[i
].ShotType
= WEAPON_CACO_FIRE
) or
2877 (Shots
[i
].ShotType
= WEAPON_MANCUB_FIRE
) or
2878 (Shots
[i
].ShotType
= WEAPON_BSP_FIRE
) or
2879 (Shots
[i
].ShotType
= WEAPON_PLASMA
) or
2880 (Shots
[i
].ShotType
= WEAPON_BFG
) or
2881 (Shots
[i
].ShotType
= WEAPON_FLAMETHROWER
) or
2884 if (Shots
[i
].ShotType
= WEAPON_PLASMA
) then
2885 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)
2886 else if (Shots
[i
].ShotType
= WEAPON_BFG
) then
2887 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)
2888 else if (Shots
[i
].ShotType
= WEAPON_FLAMETHROWER
) then
2889 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)
2891 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);
2897 procedure TShot
.positionChanged (); begin end;