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, either version 3 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 {$INCLUDE ../shared/a_modes.inc}
17 {.$DEFINE GWEP_HITSCAN_TRACE_BITMAP_CHECKER}
23 g_textures
, g_basic
, e_graphics
, g_phys
, BinEditor
, xprofiler
;
45 Animation
: TAnimation
;
50 procedure positionChanged (); //WARNING! call this after monster position was changed, or coldet will not work right!
55 Shots
: array of TShot
= nil;
56 LastShotID
: Integer = 0;
58 procedure g_Weapon_LoadData();
59 procedure g_Weapon_FreeData();
60 procedure g_Weapon_Init();
61 procedure g_Weapon_Free();
62 function g_Weapon_Hit(obj
: PObj
; d
: Integer; SpawnerUID
: Word; t
: Byte; HitCorpses
: Boolean = True): Byte;
63 function g_Weapon_HitUID(UID
: Word; d
: Integer; SpawnerUID
: Word; t
: Byte): Boolean;
64 function g_Weapon_CreateShot(I
: Integer; ShotType
: Byte; Spawner
, TargetUID
: Word; X
, Y
, XV
, YV
: Integer): LongWord;
66 procedure g_Weapon_gun(const x
, y
, xd
, yd
, v
, dmg
: Integer; SpawnerUID
: Word; CheckTrigger
: Boolean);
67 procedure g_Weapon_punch(x
, y
: Integer; d
, SpawnerUID
: Word);
68 function g_Weapon_chainsaw(x
, y
: Integer; d
, SpawnerUID
: Word): Integer;
69 procedure g_Weapon_rocket(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1; Silent
: Boolean = False);
70 procedure g_Weapon_revf(x
, y
, xd
, yd
: Integer; SpawnerUID
, TargetUID
: Word; WID
: Integer = -1; Silent
: Boolean = False);
71 procedure g_Weapon_flame(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1; Silent
: Boolean = False);
72 procedure g_Weapon_plasma(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1; Silent
: Boolean = False);
73 procedure g_Weapon_ball1(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1; Silent
: Boolean = False);
74 procedure g_Weapon_ball2(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1; Silent
: Boolean = False);
75 procedure g_Weapon_ball7(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1; Silent
: Boolean = False);
76 procedure g_Weapon_aplasma(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1; Silent
: Boolean = False);
77 procedure g_Weapon_manfire(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1; Silent
: Boolean = False);
78 procedure g_Weapon_bfgshot(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1; Silent
: Boolean = False);
79 procedure g_Weapon_bfghit(x
, y
: Integer);
80 procedure g_Weapon_pistol(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; Silent
: Boolean = False);
81 procedure g_Weapon_mgun(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; Silent
: Boolean = False);
82 procedure g_Weapon_shotgun(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; Silent
: Boolean = False);
83 procedure g_Weapon_dshotgun(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; Silent
: Boolean = False);
85 function g_Weapon_Explode(X
, Y
: Integer; rad
: Integer; SpawnerUID
: Word): Boolean;
86 procedure g_Weapon_BFG9000(X
, Y
: Integer; SpawnerUID
: Word);
87 procedure g_Weapon_Update();
88 procedure g_Weapon_Draw();
89 function g_Weapon_Danger(UID
: Word; X
, Y
: Integer; Width
, Height
: Word; Time
: Byte): Boolean;
90 procedure g_Weapon_DestroyShot(I
: Integer; X
, Y
: Integer; Loud
: Boolean = True);
92 procedure g_Weapon_SaveState(var Mem
: TBinMemoryWriter
);
93 procedure g_Weapon_LoadState(var Mem
: TBinMemoryReader
);
95 procedure g_Weapon_AddDynLights();
104 WEAPON_ROCKETLAUNCHER
= 6;
107 WEAPON_SUPERPULEMET
= 9;
108 WEAPON_FLAMETHROWER
= 10;
109 WEAPON_ZOMBY_PISTOL
= 20;
110 WEAPON_IMP_FIRE
= 21;
111 WEAPON_BSP_FIRE
= 22;
112 WEAPON_CACO_FIRE
= 23;
113 WEAPON_BARON_FIRE
= 24;
114 WEAPON_MANCUB_FIRE
= 25;
115 WEAPON_SKEL_FIRE
= 26;
117 WP_FIRST
= WEAPON_KASTET
;
118 WP_LAST
= WEAPON_FLAMETHROWER
;
122 gwep_debug_fast_trace
: Boolean = true;
128 Math
, g_map
, g_player
, g_gfx
, g_sound
, g_main
, g_panel
,
129 g_console
, SysUtils
, g_options
, g_game
,
130 g_triggers
, MAPDEF
, e_log
, g_monsters
, g_saveload
,
131 g_language
, g_netmsg
,
132 z_aabbtree
, binheap
, hashtable
;
142 SHOT_ROCKETLAUNCHER_WIDTH
= 14;
143 SHOT_ROCKETLAUNCHER_HEIGHT
= 14;
145 SHOT_SKELFIRE_WIDTH
= 14;
146 SHOT_SKELFIRE_HEIGHT
= 14;
148 SHOT_PLASMA_WIDTH
= 16;
149 SHOT_PLASMA_HEIGHT
= 16;
152 SHOT_BFG_HEIGHT
= 32;
153 SHOT_BFG_DAMAGE
= 100;
154 SHOT_BFG_RADIUS
= 256;
156 SHOT_FLAME_WIDTH
= 4;
157 SHOT_FLAME_HEIGHT
= 4;
158 SHOT_FLAME_LIFETIME
= 180;
160 SHOT_SIGNATURE
= $544F4853; // 'SHOT'
163 PHitTime
= ^THitTime
;
167 plridx
: Integer; // if mon=nil
170 // indicies in `wgunHitTime` array
171 TBinaryHeapHitTimes
= specialize TBinaryHeapBase
<Integer>;
174 WaterMap
: array of array of DWORD
= nil;
175 wgunMonHash
: THashIntInt
= nil;
176 wgunHitHeap
: TBinaryHeapHitTimes
= nil;
177 wgunHitTime
: array of THitTime
= nil;
178 wgunHitTimeUsed
: Integer = 0;
181 function hitTimeCompare (a
, b
: Integer): Boolean;
183 if (wgunHitTime
[a
].time
< wgunHitTime
[b
].time
) then begin result
:= true; exit
; end;
184 if (wgunHitTime
[a
].time
> wgunHitTime
[b
].time
) then begin result
:= false; exit
; end;
185 if (wgunHitTime
[a
].mon
<> nil) then
188 if (wgunHitTime
[b
].mon
= nil) then begin result
:= false; exit
; end; // players first
189 result
:= (wgunHitTime
[a
].mon
.UID
< wgunHitTime
[b
].mon
.UID
); // why not?
194 if (wgunHitTime
[b
].mon
<> nil) then begin result
:= true; exit
; end; // players first
195 result
:= (wgunHitTime
[a
].plridx
< wgunHitTime
[b
].plridx
); // why not?
200 procedure appendHitTimeMon (time
: Single; mon
: TMonster
);
202 if (wgunHitTimeUsed
= Length(wgunHitTime
)) then SetLength(wgunHitTime
, wgunHitTimeUsed
+128);
203 wgunHitTime
[wgunHitTimeUsed
].time
:= time
;
204 wgunHitTime
[wgunHitTimeUsed
].mon
:= mon
;
205 wgunHitTime
[wgunHitTimeUsed
].plridx
:= -1;
206 wgunHitHeap
.insert(wgunHitTimeUsed
);
207 Inc(wgunHitTimeUsed
);
211 procedure appendHitTimePlr (time
: Single; plridx
: Integer);
213 if (wgunHitTimeUsed
= Length(wgunHitTime
)) then SetLength(wgunHitTime
, wgunHitTimeUsed
+128);
214 wgunHitTime
[wgunHitTimeUsed
].time
:= time
;
215 wgunHitTime
[wgunHitTimeUsed
].mon
:= nil;
216 wgunHitTime
[wgunHitTimeUsed
].plridx
:= plridx
;
217 wgunHitHeap
.insert(wgunHitTimeUsed
);
218 Inc(wgunHitTimeUsed
);
222 function FindShot(): DWORD
;
227 for i
:= 0 to High(Shots
) do
228 if Shots
[i
].ShotType
= 0 then
231 LastShotID
:= Result
;
237 SetLength(Shots
, 128);
242 Result
:= High(Shots
) + 1;
243 SetLength(Shots
, Length(Shots
) + 128);
245 LastShotID
:= Result
;
248 procedure CreateWaterMap();
250 WaterArray
: Array of TWaterPanel
;
257 SetLength(WaterArray
, Length(gWater
));
259 for a
:= 0 to High(gWater
) do
261 WaterArray
[a
].X
:= gWater
[a
].X
;
262 WaterArray
[a
].Y
:= gWater
[a
].Y
;
263 WaterArray
[a
].Width
:= gWater
[a
].Width
;
264 WaterArray
[a
].Height
:= gWater
[a
].Height
;
265 WaterArray
[a
].Active
:= True;
268 g_Game_SetLoadingText(_lc
[I_LOAD_WATER_MAP
], High(WaterArray
), False);
270 for a
:= 0 to High(WaterArray
) do
271 if WaterArray
[a
].Active
then
273 WaterArray
[a
].Active
:= False;
274 m
:= Length(WaterMap
);
275 SetLength(WaterMap
, m
+1);
276 SetLength(WaterMap
[m
], 1);
283 for b
:= 0 to High(WaterArray
) do
284 if WaterArray
[b
].Active
then
285 for c
:= 0 to High(WaterMap
[m
]) do
286 if g_CollideAround(WaterArray
[b
].X
,
289 WaterArray
[b
].Height
,
290 WaterArray
[WaterMap
[m
][c
]].X
,
291 WaterArray
[WaterMap
[m
][c
]].Y
,
292 WaterArray
[WaterMap
[m
][c
]].Width
,
293 WaterArray
[WaterMap
[m
][c
]].Height
) then
295 WaterArray
[b
].Active
:= False;
296 SetLength(WaterMap
[m
],
297 Length(WaterMap
[m
])+1);
298 WaterMap
[m
][High(WaterMap
[m
])] := b
;
304 g_Game_StepLoading();
312 chkTrap_pl
: array [0..256] of Integer;
313 chkTrap_mn
: array [0..65535] of TMonster
;
315 procedure CheckTrap(ID
: DWORD
; dm
: Integer; t
: Byte);
317 //a, b, c, d, i1, i2: Integer;
318 //chkTrap_pl, chkTrap_mn: WArray;
319 plaCount
: Integer = 0;
320 mnaCount
: Integer = 0;
324 function monsWaterCheck (mon: TMonster): Boolean;
326 result := false; // don't stop
327 if mon.Live and mon.Collide(gWater[WaterMap[a][c]]) and (not InWArray(monidx, chkTrap_mn)) and (i2 < 1023) then //FIXME
330 chkTrap_mn[i2] := monidx;
335 function monsWaterCheck (mon
: TMonster
): Boolean;
337 result
:= false; // don't stop
338 if (mon
.trapCheckFrameId
<> frameId
) then
340 mon
.trapCheckFrameId
:= frameId
;
341 chkTrap_mn
[mnaCount
] := mon
;
347 a
, b
, c
, d
, f
: Integer;
350 if (gWater
= nil) or (WaterMap
= nil) then Exit
;
352 frameId
:= g_Mons_getNewTrapFrameId();
357 //SetLength(chkTrap_pl, 1024);
358 //SetLength(chkTrap_mn, 1024);
359 //for d := 0 to 1023 do chkTrap_pl[d] := $FFFF;
360 //for d := 0 to 1023 do chkTrap_mn[d] := $FFFF;
362 for a
:= 0 to High(WaterMap
) do
364 for b
:= 0 to High(WaterMap
[a
]) do
366 pan
:= gWater
[WaterMap
[a
][b
]];
367 if not g_Obj_Collide(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, @Shots
[ID
].Obj
) then continue
;
369 for c
:= 0 to High(WaterMap
[a
]) do
371 pan
:= gWater
[WaterMap
[a
][c
]];
372 for d
:= 0 to High(gPlayers
) do
374 if (gPlayers
[d
] <> nil) and (gPlayers
[d
].Live
) then
376 if gPlayers
[d
].Collide(pan
) then
379 while (f
< plaCount
) and (chkTrap_pl
[f
] <> d
) do Inc(f
);
380 if (f
= plaCount
) then
382 chkTrap_pl
[plaCount
] := d
;
384 if (plaCount
= Length(chkTrap_pl
)) then break
;
390 //g_Mons_ForEach(monsWaterCheck);
391 g_Mons_ForEachAliveAt(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, monsWaterCheck
);
394 for f
:= 0 to plaCount
-1 do gPlayers
[chkTrap_pl
[f
]].Damage(dm
, Shots
[ID
].SpawnerUID
, 0, 0, t
);
395 for f
:= 0 to mnaCount
-1 do chkTrap_mn
[f
].Damage(dm
, 0, 0, Shots
[ID
].SpawnerUID
, t
);
403 function HitMonster(m
: TMonster
; d
: Integer; vx
, vy
: Integer; SpawnerUID
: Word; t
: Byte): Boolean;
410 tt
:= g_GetUIDType(SpawnerUID
);
411 if tt
= UID_MONSTER
then
413 mon
:= g_Monsters_ByUID(SpawnerUID
);
415 mt
:= g_Monsters_ByUID(SpawnerUID
).MonsterType
422 if m
= nil then Exit
;
423 if m
.UID
= SpawnerUID
then
425 // Ñàì ñåáÿ ìîæåò ðàíèòü òîëüêî ðàêåòîé è òîêîì:
426 if (t
<> HIT_ROCKET
) and (t
<> HIT_ELECTRO
) then
428 // Êèáåð äåìîí è áî÷êà âîîáùå íå ìîãóò ñåáÿ ðàíèòü:
429 if (m
.MonsterType
= MONSTER_CYBER
) or
430 (m
.MonsterType
= MONSTER_BARREL
) then
437 if tt
= UID_MONSTER
then
439 // Lost_Soul íå ìîæåò ðàíèòü Pain_Elemental'à:
440 if (mt
= MONSTER_SOUL
) and (m
.MonsterType
= MONSTER_PAIN
) then
443 // Îáà ìîíñòðà îäíîãî âèäà:
444 if mt
= m
.MonsterType
then
446 MONSTER_IMP
, MONSTER_DEMON
, MONSTER_BARON
, MONSTER_KNIGHT
, MONSTER_CACO
,
447 MONSTER_SOUL
, MONSTER_MANCUB
, MONSTER_SKEL
, MONSTER_FISH
:
448 Exit
; // Ýòè íå áüþò ñâîèõ
452 if g_Game_IsServer
then
454 if (t
<> HIT_FLAME
) or (m
.FFireTime
= 0) or (vx
<> 0) or (vy
<> 0) then
455 Result
:= m
.Damage(d
, vx
, vy
, SpawnerUID
, t
)
458 if t
= HIT_FLAME
then
459 m
.CatchFire(SpawnerUID
);
466 function HitPlayer (p
: TPlayer
; d
: Integer; vx
, vy
: Integer; SpawnerUID
: Word; t
: Byte): Boolean;
470 // Ñàì ñåáÿ ìîæåò ðàíèòü òîëüêî ðàêåòîé è òîêîì
471 if (p
.UID
= SpawnerUID
) and (t
<> HIT_ROCKET
) and (t
<> HIT_ELECTRO
) then exit
;
473 if g_Game_IsServer
then
475 if (t
<> HIT_FLAME
) or (p
.FFireTime
= 0) or (vx
<> 0) or (vy
<> 0) then p
.Damage(d
, SpawnerUID
, vx
, vy
, t
);
476 if (t
= HIT_FLAME
) then p
.CatchFire(SpawnerUID
);
483 procedure g_Weapon_BFG9000(X
, Y
: Integer; SpawnerUID
: Word);
485 function monsCheck (mon
: TMonster
): Boolean;
487 result
:= false; // don't stop
488 if (mon
.Live
) and (mon
.UID
<> SpawnerUID
) then
492 if (g_PatchLength(X
, Y
, Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2),
493 Obj
.Y
+Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2)) <= SHOT_BFG_RADIUS
) and
494 g_TraceVector(X
, Y
, Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2),
495 Obj
.Y
+Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2)) then
497 if HitMonster(mon
, 50, 0, 0, SpawnerUID
, HIT_SOME
) then mon
.BFGHit();
509 //g_Sound_PlayEx('SOUND_WEAPON_EXPLODEBFG', 255);
513 if gAdvCorpses
and (h
<> -1) then
515 if (gCorpses
[i
] <> nil) and (gCorpses
[i
].State
<> CORPSE_STATE_REMOVEME
) then
517 if (g_PatchLength(X
, Y
, Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2),
518 Obj
.Y
+Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2)) <= SHOT_BFG_RADIUS
) and
519 g_TraceVector(X
, Y
, Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2),
520 Obj
.Y
+Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2)) then
523 g_Weapon_BFGHit(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2),
524 Obj
.Y
+Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2));
528 pl
:= g_Player_Get(SpawnerUID
);
536 if (gPlayers
[i
] <> nil) and (gPlayers
[i
].Live
) and (gPlayers
[i
].UID
<> SpawnerUID
) then
538 if (g_PatchLength(X
, Y
, GameX
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
539 GameY
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)) <= SHOT_BFG_RADIUS
) and
540 g_TraceVector(X
, Y
, GameX
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
541 GameY
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)) then
543 if (st
= TEAM_NONE
) or (st
<> gPlayers
[i
].Team
) then
544 b
:= HitPlayer(gPlayers
[i
], 50, 0, 0, SpawnerUID
, HIT_SOME
)
546 b
:= HitPlayer(gPlayers
[i
], 25, 0, 0, SpawnerUID
, HIT_SOME
);
548 gPlayers
[i
].BFGHit();
552 g_Mons_ForEachAlive(monsCheck
);
555 function g_Weapon_CreateShot(I
: Integer; ShotType
: Byte; Spawner
, TargetUID
: Word; X
, Y
, XV
, YV
: Integer): LongWord;
557 find_id
, FramesID
: DWORD
;
560 find_id
:= FindShot()
564 if Integer(find_id
) >= High(Shots
) then
565 SetLength(Shots
, find_id
+ 64)
569 WEAPON_ROCKETLAUNCHER
:
571 with Shots
[find_id
] do
575 Obj
.Rect
.Width
:= SHOT_ROCKETLAUNCHER_WIDTH
;
576 Obj
.Rect
.Height
:= SHOT_ROCKETLAUNCHER_HEIGHT
;
580 ShotType
:= WEAPON_ROCKETLAUNCHER
;
581 g_Texture_Get('TEXTURE_WEAPON_ROCKET', TextureID
);
587 with Shots
[find_id
] do
591 Obj
.Rect
.Width
:= SHOT_PLASMA_WIDTH
;
592 Obj
.Rect
.Height
:= SHOT_PLASMA_HEIGHT
;
595 ShotType
:= WEAPON_PLASMA
;
596 g_Frames_Get(FramesID
, 'FRAMES_WEAPON_PLASMA');
597 Animation
:= TAnimation
.Create(FramesID
, True, 5);
603 with Shots
[find_id
] do
607 Obj
.Rect
.Width
:= SHOT_BFG_WIDTH
;
608 Obj
.Rect
.Height
:= SHOT_BFG_HEIGHT
;
611 ShotType
:= WEAPON_BFG
;
612 g_Frames_Get(FramesID
, 'FRAMES_WEAPON_BFG');
613 Animation
:= TAnimation
.Create(FramesID
, True, 6);
619 with Shots
[find_id
] do
623 Obj
.Rect
.Width
:= SHOT_FLAME_WIDTH
;
624 Obj
.Rect
.Height
:= SHOT_FLAME_HEIGHT
;
627 ShotType
:= WEAPON_FLAMETHROWER
;
630 g_Frames_Get(TextureID
, 'FRAMES_FLAME');
636 with Shots
[find_id
] do
640 Obj
.Rect
.Width
:= 16;
641 Obj
.Rect
.Height
:= 16;
644 ShotType
:= WEAPON_IMP_FIRE
;
645 g_Frames_Get(FramesID
, 'FRAMES_WEAPON_IMPFIRE');
646 Animation
:= TAnimation
.Create(FramesID
, True, 4);
652 with Shots
[find_id
] do
656 Obj
.Rect
.Width
:= 16;
657 Obj
.Rect
.Height
:= 16;
660 ShotType
:= WEAPON_CACO_FIRE
;
661 g_Frames_Get(FramesID
, 'FRAMES_WEAPON_CACOFIRE');
662 Animation
:= TAnimation
.Create(FramesID
, True, 4);
668 with Shots
[find_id
] do
672 Obj
.Rect
.Width
:= 32;
673 Obj
.Rect
.Height
:= 32;
676 ShotType
:= WEAPON_MANCUB_FIRE
;
677 g_Frames_Get(FramesID
, 'FRAMES_WEAPON_MANCUBFIRE');
678 Animation
:= TAnimation
.Create(FramesID
, True, 4);
684 with Shots
[find_id
] do
688 Obj
.Rect
.Width
:= 32;
689 Obj
.Rect
.Height
:= 16;
692 ShotType
:= WEAPON_BARON_FIRE
;
693 g_Frames_Get(FramesID
, 'FRAMES_WEAPON_BARONFIRE');
694 Animation
:= TAnimation
.Create(FramesID
, True, 4);
700 with Shots
[find_id
] do
704 Obj
.Rect
.Width
:= 16;
705 Obj
.Rect
.Height
:= 16;
708 ShotType
:= WEAPON_BSP_FIRE
;
709 g_Frames_Get(FramesID
, 'FRAMES_WEAPON_BSPFIRE');
710 Animation
:= TAnimation
.Create(FramesID
, True, 4);
716 with Shots
[find_id
] do
720 Obj
.Rect
.Width
:= SHOT_SKELFIRE_WIDTH
;
721 Obj
.Rect
.Height
:= SHOT_SKELFIRE_HEIGHT
;
724 ShotType
:= WEAPON_SKEL_FIRE
;
726 g_Frames_Get(FramesID
, 'FRAMES_WEAPON_SKELFIRE');
727 Animation
:= TAnimation
.Create(FramesID
, True, 5);
732 Shots
[find_id
].Obj
.X
:= X
;
733 Shots
[find_id
].Obj
.Y
:= Y
;
734 Shots
[find_id
].Obj
.Vel
.X
:= XV
;
735 Shots
[find_id
].Obj
.Vel
.Y
:= YV
;
736 Shots
[find_id
].Obj
.Accel
.X
:= 0;
737 Shots
[find_id
].Obj
.Accel
.Y
:= 0;
738 Shots
[find_id
].SpawnerUID
:= Spawner
;
739 if (ShotType
= WEAPON_FLAMETHROWER
) and (XV
= 0) and (YV
= 0) then
740 Shots
[find_id
].Stopped
:= 255
742 Shots
[find_id
].Stopped
:= 0;
746 procedure throw(i
, x
, y
, xd
, yd
, s
: Integer);
753 a
:= Max(Abs(xd
), Abs(yd
));
759 Shots
[i
].Obj
.Vel
.X
:= (xd
*s
) div a
;
760 Shots
[i
].Obj
.Vel
.Y
:= (yd
*s
) div a
;
761 Shots
[i
].Obj
.Accel
.X
:= 0;
762 Shots
[i
].Obj
.Accel
.Y
:= 0;
763 Shots
[i
].Stopped
:= 0;
764 if Shots
[i
].ShotType
in [WEAPON_ROCKETLAUNCHER
, WEAPON_BFG
] then
765 Shots
[i
].Timeout
:= 900 // ~25 sec
768 if Shots
[i
].ShotType
= WEAPON_FLAMETHROWER
then
769 Shots
[i
].Timeout
:= SHOT_FLAME_LIFETIME
771 Shots
[i
].Timeout
:= 550; // ~15 sec
775 function g_Weapon_Hit(obj
: PObj
; d
: Integer; SpawnerUID
: Word; t
: Byte; HitCorpses
: Boolean = True): Byte;
779 function PlayerHit(Team
: Byte = 0): Boolean;
790 if (gPlayers
[i
] <> nil) and gPlayers
[i
].Live
and g_Obj_Collide(obj
, @gPlayers
[i
].Obj
) then
793 if (Team
> 0) and (g_GetUIDType(SpawnerUID
) = UID_PLAYER
) then
795 p
:= g_Player_Get(SpawnerUID
);
797 ChkTeam
:= (p
.Team
= gPlayers
[i
].Team
) xor (Team
= 2);
800 if HitPlayer(gPlayers
[i
], d
, obj
^.Vel
.X
, obj
^.Vel
.Y
, SpawnerUID
, t
) then
802 if t
<> HIT_FLAME
then
803 gPlayers
[i
].Push((obj
^.Vel
.X
+obj
^.Accel
.X
)*IfThen(t
= HIT_BFG
, 8, 1) div 4,
804 (obj
^.Vel
.Y
+obj
^.Accel
.Y
)*IfThen(t
= HIT_BFG
, 8, 1) div 4);
806 g_Game_DelayEvent(DE_BFGHIT
, 1000, SpawnerUID
);
814 function monsCheckHit (monidx: Integer; mon: TMonster): Boolean;
816 result := false; // don't stop
817 if mon.Live and g_Obj_Collide(obj, @mon.Obj) then
819 if HitMonster(mon, d, obj^.Vel.X, obj^.Vel.Y, SpawnerUID, t) then
821 if (t <> HIT_FLAME) then
823 mon.Push((obj^.Vel.X+obj^.Accel.X)*IfThen(t = HIT_BFG, 8, 1) div 4,
824 (obj^.Vel.Y+obj^.Accel.Y)*IfThen(t = HIT_BFG, 8, 1) div 4);
832 function monsCheckHit (mon
: TMonster
): Boolean;
834 result
:= false; // don't stop
835 if HitMonster(mon
, d
, obj
.Vel
.X
, obj
.Vel
.Y
, SpawnerUID
, t
) then
837 if (t
<> HIT_FLAME
) then
839 mon
.Push((obj
.Vel
.X
+obj
.Accel
.X
)*IfThen(t
= HIT_BFG
, 8, 1) div 4,
840 (obj
.Vel
.Y
+obj
.Accel
.Y
)*IfThen(t
= HIT_BFG
, 8, 1) div 4);
846 function MonsterHit(): Boolean;
848 //result := g_Mons_ForEach(monsCheckHit);
849 //FIXME: accelerate this!
850 result
:= g_Mons_ForEachAliveAt(obj
.X
+obj
.Rect
.X
, obj
.Y
+obj
.Rect
.Y
, obj
.Rect
.Width
, obj
.Rect
.Height
, monsCheckHit
);
860 if gAdvCorpses
and (h
<> -1) then
862 if (gCorpses
[i
] <> nil) and (gCorpses
[i
].State
<> CORPSE_STATE_REMOVEME
) and
863 g_Obj_Collide(obj
, @gCorpses
[i
].Obj
) then
866 gCorpses
[i
].Damage(d
, (obj
^.Vel
.X
+obj
^.Accel
.X
) div 4,
867 (obj
^.Vel
.Y
+obj
^.Accel
.Y
) div 4);
872 case gGameSettings
.GameMode
of
876 // Ñíà÷àëà áü¸ì ìîíñòðîâ, åñëè åñòü, ïîòîì ïûòàåìñÿ áèòü èãðîêîâ
893 // Ñíà÷àëà áü¸ì èãðîêîâ, åñëè åñòü, ïîòîì ïûòàåìñÿ áèòü ìîíñòðîâ
910 // Ñíà÷àëà áü¸ì èãðîêîâ êîìàíäû ñîïåðíèêà
924 // È â êîíöå ñâîèõ èãðîêîâ
935 function g_Weapon_HitUID(UID
: Word; d
: Integer; SpawnerUID
: Word; t
: Byte): Boolean;
939 case g_GetUIDType(UID
) of
940 UID_PLAYER
: Result
:= HitPlayer(g_Player_Get(UID
), d
, 0, 0, SpawnerUID
, t
);
941 UID_MONSTER
: Result
:= HitMonster(g_Monsters_ByUID(UID
), d
, 0, 0, SpawnerUID
, t
);
946 function g_Weapon_Explode(X
, Y
: Integer; rad
: Integer; SpawnerUID
: Word): Boolean;
948 r
: Integer; // squared radius
950 function monsExCheck (mon
: TMonster
): Boolean;
954 result
:= false; // don't stop
956 dx
:= mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-X
;
957 dy
:= mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2)-Y
;
959 if dx
> 1000 then dx
:= 1000;
960 if dy
> 1000 then dy
:= 1000;
962 if (dx
*dx
+dy
*dy
< r
) then
964 //m := PointToRect(X, Y, Obj.X+Obj.Rect.X, Obj.Y+Obj.Rect.Y, Obj.Rect.Width, Obj.Rect.Height);
965 //e_WriteLog(Format('explo monster #%d: x=%d; y=%d; rad=%d; dx=%d; dy=%d', [monidx, X, Y, rad, dx, dy]), MSG_NOTIFY);
967 mm
:= Max(abs(dx
), abs(dy
));
968 if mm
= 0 then mm
:= 1;
972 HitMonster(mon
, ((mon
.Obj
.Rect
.Width
div 4)*10*(rad
-mm
)) div rad
, 0, 0, SpawnerUID
, HIT_ROCKET
);
975 mon
.Push((dx
*7) div mm
, (dy
*7) div mm
);
981 i
, h
, dx
, dy
, m
, mm
: Integer;
986 g_Triggers_PressC(X
, Y
, rad
, SpawnerUID
, ACTIVATE_SHOT
);
994 if (gPlayers
[i
] <> nil) and gPlayers
[i
].Live
then
997 dx
:= Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)-X
;
998 dy
:= Obj
.Y
+Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2)-Y
;
1000 if dx
> 1000 then dx
:= 1000;
1001 if dy
> 1000 then dy
:= 1000;
1003 if dx
*dx
+dy
*dy
< r
then
1005 //m := PointToRect(X, Y, GameX+PLAYER_RECT.X, GameY+PLAYER_RECT.Y,
1006 // PLAYER_RECT.Width, PLAYER_RECT.Height);
1008 mm
:= Max(abs(dx
), abs(dy
));
1009 if mm
= 0 then mm
:= 1;
1011 HitPlayer(gPlayers
[i
], (100*(rad
-mm
)) div rad
, (dx
*10) div mm
, (dy
*10) div mm
, SpawnerUID
, HIT_ROCKET
);
1012 gPlayers
[i
].Push((dx
*7) div mm
, (dy
*7) div mm
);
1016 //g_Mons_ForEach(monsExCheck);
1017 g_Mons_ForEachAt(X
-(rad
+32), Y
-(rad
+32), (rad
+32)*2, (rad
+32)*2, monsExCheck
);
1019 h
:= High(gCorpses
);
1021 if gAdvCorpses
and (h
<> -1) then
1023 if (gCorpses
[i
] <> nil) and (gCorpses
[i
].State
<> CORPSE_STATE_REMOVEME
) then
1026 dx
:= Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)-X
;
1027 dy
:= Obj
.Y
+Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2)-Y
;
1029 if dx
> 1000 then dx
:= 1000;
1030 if dy
> 1000 then dy
:= 1000;
1032 if dx
*dx
+dy
*dy
< r
then
1034 m
:= PointToRect(X
, Y
, Obj
.X
+Obj
.Rect
.X
, Obj
.Y
+Obj
.Rect
.Y
,
1035 Obj
.Rect
.Width
, Obj
.Rect
.Height
);
1037 mm
:= Max(abs(dx
), abs(dy
));
1038 if mm
= 0 then mm
:= 1;
1040 Damage(Round(100*(rad
-m
)/rad
), (dx
*10) div mm
, (dy
*10) div mm
);
1046 if gAdvGibs
and (h
<> -1) then
1048 if gGibs
[i
].Live
then
1051 dx
:= Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)-X
;
1052 dy
:= Obj
.Y
+Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2)-Y
;
1054 if dx
> 1000 then dx
:= 1000;
1055 if dy
> 1000 then dy
:= 1000;
1057 if dx
*dx
+dy
*dy
< r
then
1059 m
:= PointToRect(X
, Y
, Obj
.X
+Obj
.Rect
.X
, Obj
.Y
+Obj
.Rect
.Y
,
1060 Obj
.Rect
.Width
, Obj
.Rect
.Height
);
1061 _angle
:= GetAngle(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2),
1062 Obj
.Y
+Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2), X
, Y
);
1064 g_Obj_PushA(@Obj
, Round(15*(rad
-m
)/rad
), _angle
);
1065 positionChanged(); // this updates spatial accelerators
1070 procedure g_Weapon_Init();
1075 procedure g_Weapon_Free();
1079 if Shots
<> nil then
1081 for i
:= 0 to High(Shots
) do
1082 if Shots
[i
].ShotType
<> 0 then
1083 Shots
[i
].Animation
.Free();
1091 procedure g_Weapon_LoadData();
1093 e_WriteLog('Loading weapons data...', MSG_NOTIFY
);
1095 g_Sound_CreateWADEx('SOUND_WEAPON_HITPUNCH', GameWAD
+':SOUNDS\HITPUNCH');
1096 g_Sound_CreateWADEx('SOUND_WEAPON_MISSPUNCH', GameWAD
+':SOUNDS\MISSPUNCH');
1097 g_Sound_CreateWADEx('SOUND_WEAPON_HITBERSERK', GameWAD
+':SOUNDS\HITBERSERK');
1098 g_Sound_CreateWADEx('SOUND_WEAPON_MISSBERSERK', GameWAD
+':SOUNDS\MISSBERSERK');
1099 g_Sound_CreateWADEx('SOUND_WEAPON_SELECTSAW', GameWAD
+':SOUNDS\SELECTSAW');
1100 g_Sound_CreateWADEx('SOUND_WEAPON_IDLESAW', GameWAD
+':SOUNDS\IDLESAW');
1101 g_Sound_CreateWADEx('SOUND_WEAPON_HITSAW', GameWAD
+':SOUNDS\HITSAW');
1102 g_Sound_CreateWADEx('SOUND_WEAPON_FIRESHOTGUN2', GameWAD
+':SOUNDS\FIRESHOTGUN2');
1103 g_Sound_CreateWADEx('SOUND_WEAPON_FIRESHOTGUN', GameWAD
+':SOUNDS\FIRESHOTGUN');
1104 g_Sound_CreateWADEx('SOUND_WEAPON_FIRESAW', GameWAD
+':SOUNDS\FIRESAW');
1105 g_Sound_CreateWADEx('SOUND_WEAPON_FIREROCKET', GameWAD
+':SOUNDS\FIREROCKET');
1106 g_Sound_CreateWADEx('SOUND_WEAPON_FIREPLASMA', GameWAD
+':SOUNDS\FIREPLASMA');
1107 g_Sound_CreateWADEx('SOUND_WEAPON_FIREPISTOL', GameWAD
+':SOUNDS\FIREPISTOL');
1108 g_Sound_CreateWADEx('SOUND_WEAPON_FIRECGUN', GameWAD
+':SOUNDS\FIRECGUN');
1109 g_Sound_CreateWADEx('SOUND_WEAPON_FIREBFG', GameWAD
+':SOUNDS\FIREBFG');
1110 g_Sound_CreateWADEx('SOUND_FIRE', GameWAD
+':SOUNDS\FIRE');
1111 g_Sound_CreateWADEx('SOUND_WEAPON_STARTFIREBFG', GameWAD
+':SOUNDS\STARTFIREBFG');
1112 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEROCKET', GameWAD
+':SOUNDS\EXPLODEROCKET');
1113 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEBFG', GameWAD
+':SOUNDS\EXPLODEBFG');
1114 g_Sound_CreateWADEx('SOUND_WEAPON_BFGWATER', GameWAD
+':SOUNDS\BFGWATER');
1115 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEPLASMA', GameWAD
+':SOUNDS\EXPLODEPLASMA');
1116 g_Sound_CreateWADEx('SOUND_WEAPON_PLASMAWATER', GameWAD
+':SOUNDS\PLASMAWATER');
1117 g_Sound_CreateWADEx('SOUND_WEAPON_FIREBALL', GameWAD
+':SOUNDS\FIREBALL');
1118 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEBALL', GameWAD
+':SOUNDS\EXPLODEBALL');
1119 g_Sound_CreateWADEx('SOUND_WEAPON_FIREREV', GameWAD
+':SOUNDS\FIREREV');
1120 g_Sound_CreateWADEx('SOUND_PLAYER_JETFLY', GameWAD
+':SOUNDS\WORKJETPACK');
1121 g_Sound_CreateWADEx('SOUND_PLAYER_JETON', GameWAD
+':SOUNDS\STARTJETPACK');
1122 g_Sound_CreateWADEx('SOUND_PLAYER_JETOFF', GameWAD
+':SOUNDS\STOPJETPACK');
1123 g_Sound_CreateWADEx('SOUND_PLAYER_CASING1', GameWAD
+':SOUNDS\CASING1');
1124 g_Sound_CreateWADEx('SOUND_PLAYER_CASING2', GameWAD
+':SOUNDS\CASING2');
1125 g_Sound_CreateWADEx('SOUND_PLAYER_SHELL1', GameWAD
+':SOUNDS\SHELL1');
1126 g_Sound_CreateWADEx('SOUND_PLAYER_SHELL2', GameWAD
+':SOUNDS\SHELL2');
1128 g_Texture_CreateWADEx('TEXTURE_WEAPON_ROCKET', GameWAD
+':TEXTURES\BROCKET');
1129 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_SKELFIRE', GameWAD
+':TEXTURES\BSKELFIRE', 64, 16, 2);
1130 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_BFG', GameWAD
+':TEXTURES\BBFG', 64, 64, 2);
1131 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_PLASMA', GameWAD
+':TEXTURES\BPLASMA', 16, 16, 2);
1132 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_IMPFIRE', GameWAD
+':TEXTURES\BIMPFIRE', 16, 16, 2);
1133 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_BSPFIRE', GameWAD
+':TEXTURES\BBSPFIRE', 16, 16, 2);
1134 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_CACOFIRE', GameWAD
+':TEXTURES\BCACOFIRE', 16, 16, 2);
1135 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_BARONFIRE', GameWAD
+':TEXTURES\BBARONFIRE', 64, 16, 2);
1136 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_MANCUBFIRE', GameWAD
+':TEXTURES\BMANCUBFIRE', 64, 32, 2);
1137 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_ROCKET', GameWAD
+':TEXTURES\EROCKET', 128, 128, 6);
1138 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_SKELFIRE', GameWAD
+':TEXTURES\ESKELFIRE', 64, 64, 3);
1139 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_BFG', GameWAD
+':TEXTURES\EBFG', 128, 128, 6);
1140 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_IMPFIRE', GameWAD
+':TEXTURES\EIMPFIRE', 64, 64, 3);
1141 g_Frames_CreateWAD(nil, 'FRAMES_BFGHIT', GameWAD
+':TEXTURES\BFGHIT', 64, 64, 4);
1142 g_Frames_CreateWAD(nil, 'FRAMES_FIRE', GameWAD
+':TEXTURES\FIRE', 64, 128, 8);
1143 g_Frames_CreateWAD(nil, 'FRAMES_FLAME', GameWAD
+':TEXTURES\FLAME', 32, 32, 11);
1144 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_PLASMA', GameWAD
+':TEXTURES\EPLASMA', 32, 32, 4, True);
1145 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_BSPFIRE', GameWAD
+':TEXTURES\EBSPFIRE', 32, 32, 5);
1146 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_CACOFIRE', GameWAD
+':TEXTURES\ECACOFIRE', 64, 64, 3);
1147 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_BARONFIRE', GameWAD
+':TEXTURES\EBARONFIRE', 64, 64, 3);
1148 g_Frames_CreateWAD(nil, 'FRAMES_SMOKE', GameWAD
+':TEXTURES\SMOKE', 32, 32, 10, False);
1150 g_Texture_CreateWADEx('TEXTURE_SHELL_BULLET', GameWAD
+':TEXTURES\EBULLET');
1151 g_Texture_CreateWADEx('TEXTURE_SHELL_SHELL', GameWAD
+':TEXTURES\ESHELL');
1153 wgunMonHash
:= hashNewIntInt();
1154 wgunHitHeap
:= TBinaryHeapHitTimes
.Create(hitTimeCompare
);
1157 procedure g_Weapon_FreeData();
1159 e_WriteLog('Releasing weapons data...', MSG_NOTIFY
);
1161 g_Sound_Delete('SOUND_WEAPON_HITPUNCH');
1162 g_Sound_Delete('SOUND_WEAPON_MISSPUNCH');
1163 g_Sound_Delete('SOUND_WEAPON_HITBERSERK');
1164 g_Sound_Delete('SOUND_WEAPON_MISSBERSERK');
1165 g_Sound_Delete('SOUND_WEAPON_SELECTSAW');
1166 g_Sound_Delete('SOUND_WEAPON_IDLESAW');
1167 g_Sound_Delete('SOUND_WEAPON_HITSAW');
1168 g_Sound_Delete('SOUND_WEAPON_FIRESHOTGUN2');
1169 g_Sound_Delete('SOUND_WEAPON_FIRESHOTGUN');
1170 g_Sound_Delete('SOUND_WEAPON_FIRESAW');
1171 g_Sound_Delete('SOUND_WEAPON_FIREROCKET');
1172 g_Sound_Delete('SOUND_WEAPON_FIREPLASMA');
1173 g_Sound_Delete('SOUND_WEAPON_FIREPISTOL');
1174 g_Sound_Delete('SOUND_WEAPON_FIRECGUN');
1175 g_Sound_Delete('SOUND_WEAPON_FIREBFG');
1176 g_Sound_Delete('SOUND_FIRE');
1177 g_Sound_Delete('SOUND_WEAPON_STARTFIREBFG');
1178 g_Sound_Delete('SOUND_WEAPON_EXPLODEROCKET');
1179 g_Sound_Delete('SOUND_WEAPON_EXPLODEBFG');
1180 g_Sound_Delete('SOUND_WEAPON_BFGWATER');
1181 g_Sound_Delete('SOUND_WEAPON_EXPLODEPLASMA');
1182 g_Sound_Delete('SOUND_WEAPON_PLASMAWATER');
1183 g_Sound_Delete('SOUND_WEAPON_FIREBALL');
1184 g_Sound_Delete('SOUND_WEAPON_EXPLODEBALL');
1185 g_Sound_Delete('SOUND_WEAPON_FIREREV');
1186 g_Sound_Delete('SOUND_PLAYER_JETFLY');
1187 g_Sound_Delete('SOUND_PLAYER_JETON');
1188 g_Sound_Delete('SOUND_PLAYER_JETOFF');
1189 g_Sound_Delete('SOUND_PLAYER_CASING1');
1190 g_Sound_Delete('SOUND_PLAYER_CASING2');
1191 g_Sound_Delete('SOUND_PLAYER_SHELL1');
1192 g_Sound_Delete('SOUND_PLAYER_SHELL2');
1194 g_Texture_Delete('TEXTURE_WEAPON_ROCKET');
1195 g_Frames_DeleteByName('FRAMES_WEAPON_BFG');
1196 g_Frames_DeleteByName('FRAMES_WEAPON_PLASMA');
1197 g_Frames_DeleteByName('FRAMES_WEAPON_IMPFIRE');
1198 g_Frames_DeleteByName('FRAMES_WEAPON_BSPFIRE');
1199 g_Frames_DeleteByName('FRAMES_WEAPON_CACOFIRE');
1200 g_Frames_DeleteByName('FRAMES_WEAPON_MANCUBFIRE');
1201 g_Frames_DeleteByName('FRAMES_EXPLODE_ROCKET');
1202 g_Frames_DeleteByName('FRAMES_EXPLODE_BFG');
1203 g_Frames_DeleteByName('FRAMES_EXPLODE_IMPFIRE');
1204 g_Frames_DeleteByName('FRAMES_BFGHIT');
1205 g_Frames_DeleteByName('FRAMES_FIRE');
1206 g_Frames_DeleteByName('FRAMES_EXPLODE_PLASMA');
1207 g_Frames_DeleteByName('FRAMES_EXPLODE_BSPFIRE');
1208 g_Frames_DeleteByName('FRAMES_EXPLODE_CACOFIRE');
1209 g_Frames_DeleteByName('FRAMES_SMOKE');
1210 g_Frames_DeleteByName('FRAMES_WEAPON_BARONFIRE');
1211 g_Frames_DeleteByName('FRAMES_EXPLODE_BARONFIRE');
1215 function GunHitPlayer (X
, Y
: Integer; vx
, vy
: Integer; dmg
: Integer; SpawnerUID
: Word; AllowPush
: Boolean): Boolean;
1220 for i
:= 0 to High(gPlayers
) do
1222 if (gPlayers
[i
] <> nil) and gPlayers
[i
].Live
and gPlayers
[i
].Collide(X
, Y
) then
1224 if HitPlayer(gPlayers
[i
], dmg
, vx
*10, vy
*10-3, SpawnerUID
, HIT_SOME
) then
1226 if AllowPush
then gPlayers
[i
].Push(vx
, vy
);
1234 function GunHit (X
, Y
: Integer; vx
, vy
: Integer; dmg
: Integer; SpawnerUID
: Word; AllowPush
: Boolean): Byte;
1236 function monsCheck (mon
: TMonster
): Boolean;
1238 result
:= false; // don't stop
1239 if HitMonster(mon
, dmg
, vx
*10, vy
*10-3, SpawnerUID
, HIT_SOME
) then
1241 if AllowPush
then mon
.Push(vx
, vy
);
1248 if GunHitPlayer(X
, Y
, vx
, vy
, dmg
, SpawnerUID
, AllowPush
) then result
:= 1
1249 else if g_Mons_ForEachAliveAt(X
, Y
, 1, 1, monsCheck
) then result
:= 2;
1253 procedure g_Weapon_gunOld(const x
, y
, xd
, yd
, v
, dmg
: Integer; SpawnerUID
: Word; CheckTrigger
: Boolean);
1264 t1
, _collide
: Boolean;
1266 {$IF DEFINED(D2F_DEBUG)}
1268 showTime
: Boolean = true;
1271 a
:= GetAngle(x
, y
, xd
, yd
)+180;
1273 SinCos(DegToRad(-a
), s
, c
);
1275 if Abs(s
) < 0.01 then s
:= 0;
1276 if Abs(c
) < 0.01 then c
:= 0;
1278 x2
:= x
+Round(c
*gMapInfo
.Width
);
1279 y2
:= y
+Round(s
*gMapInfo
.Width
);
1281 t1
:= gWalls
<> nil;
1283 w
:= gMapInfo
.Width
;
1284 h
:= gMapInfo
.Height
;
1291 if (xd
= 0) and (yd
= 0) then Exit
;
1293 if dx
> 0 then xi
:= 1 else if dx
< 0 then xi
:= -1 else xi
:= 0;
1294 if dy
> 0 then yi
:= 1 else if dy
< 0 then yi
:= -1 else yi
:= 0;
1299 if dx
> dy
then d
:= dx
else d
:= dy
;
1301 //blood vel, for Monster.Damage()
1302 //vx := (dx*10 div d)*xi;
1303 //vy := (dy*10 div d)*yi;
1305 {$IF DEFINED(D2F_DEBUG)}
1306 stt
:= curTimeMicro();
1329 if (yy
> h
) or (yy
< 0) then Break
;
1330 if (xx
> w
) or (xx
< 0) then Break
;
1333 if ByteBool(gCollideMap
[yy
, xx
] and MARK_BLOCKED
) then
1336 {$IF DEFINED(D2F_DEBUG)}
1337 stt
:= curTimeMicro()-stt
;
1338 e_WriteLog(Format('*** old trace time: %u microseconds', [LongWord(stt
)]), MSG_NOTIFY
);
1341 g_GFX_Spark(xx
-xi
, yy
-yi
, 2+Random(2), 180+a
, 0, 0);
1342 if g_Game_IsServer
and g_Game_IsNet
then
1343 MH_SEND_Effect(xx
-xi
, yy
-yi
, 180+a
, NET_GFX_SPARK
);
1346 if not _collide
then
1348 _collide
:= GunHit(xx
, yy
, xi
*v
, yi
*v
, dmg
, SpawnerUID
, v
<> 0) <> 0;
1351 if _collide
then Break
;
1354 {$IF DEFINED(D2F_DEBUG)}
1357 stt
:= curTimeMicro()-stt
;
1358 e_WriteLog(Format('*** old trace time: %u microseconds', [LongWord(stt
)]), MSG_NOTIFY
);
1362 if CheckTrigger
and g_Game_IsServer
then
1363 g_Triggers_PressL(X
, Y
, xx
-xi
, yy
-yi
, SpawnerUID
, ACTIVATE_SHOT
);
1368 procedure g_Weapon_gunComplicated (const x, y, xd, yd, v, dmg: Integer; SpawnerUID: Word; CheckTrigger: Boolean);
1376 function doPlayerHit (idx: Integer): Boolean;
1379 if (idx < 0) or (idx > High(gPlayers)) then exit;
1380 if (gPlayers[idx] = nil) or not gPlayers[idx].Live then exit;
1381 result := HitPlayer(gPlayers[idx], dmg, (xi*v)*10, (yi*v)*10-3, SpawnerUID, HIT_SOME);
1382 if result and (v <> 0) then gPlayers[idx].Push((xi*v), (yi*v));
1383 {$IF DEFINED(D2F_DEBUG)}
1384 //if result then e_WriteLog(Format(' PLAYER #%d HIT', [idx]), MSG_NOTIFY);
1388 function doMonsterHit (mon: TMonster): Boolean;
1391 if (mon = nil) then exit;
1392 result := HitMonster(mon, dmg, (xi*v)*10, (yi*v)*10-3, SpawnerUID, HIT_SOME);
1393 if result and (v <> 0) then mon.Push((xi*v), (yi*v));
1394 {$IF DEFINED(D2F_DEBUG)}
1395 //if result then e_WriteLog(Format(' MONSTER #%u HIT', [LongWord(mon.UID)]), MSG_NOTIFY);
1399 // get nearest player along hitray
1400 // return `true` if instant hit was detected
1401 function playerPossibleHit (): Boolean;
1408 for i := 0 to High(gPlayers) do
1410 if (gPlayers[i] <> nil) and gPlayers[i].Live then
1412 aabb := gPlayers[i].mapAABB;
1414 if aabb.contains(x, y) then
1416 if doPlayerHit(i) then begin result := true; exit; end;
1418 else if (aabb.intersects(hitray, @tmin)) then
1423 if doPlayerHit(i) then begin result := true; exit; end;
1427 appendHitTimePlr(tmin, i);
1434 function monsPossibleHitInstant (mon: TMonster): Boolean;
1438 result := false; // don't stop
1439 aabb := mon.mapAABB;
1440 if aabb.contains(x, y) then
1442 result := doMonsterHit(mon);
1446 function monsPossibleHit (mon: TMonster): Boolean;
1451 result := false; // don't stop
1452 if not wgunMonHash.put(Integer(mon.UID), 1) then
1454 // new monster; calculate hitpoint
1455 aabb := mon.mapAABB;
1456 if (aabb.intersects(hitray, @tmin)) then
1458 if (tmin < 0) then tmin := 1.0;
1459 appendHitTimeMon(tmin, mon);
1471 prevX, prevY: Integer;
1472 leftToNextMonsterQuery: Integer = 0;
1475 {$IF DEFINED(GWEP_HITSCAN_TRACE_BITMAP_CHECKER)}
1478 wallWasHit: Boolean = false;
1479 wallHitX: Integer = 0;
1480 wallHitY: Integer = 0;
1481 didHit: Boolean = false;
1484 mptHit: Integer = -1;
1485 {$IF DEFINED(D2F_DEBUG)}
1489 if not gwep_debug_fast_trace then
1491 g_Weapon_gunOld(x, y, xd, yd, v, dmg, SpawnerUID, CheckTrigger);
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;
1506 x2 := x+Round(c*gMapInfo.Width);
1507 y2 := y+Round(s*gMapInfo.Width);
1509 hitray := Ray2D.Create(x, y, x2, y2);
1511 e_WriteLog(Format('GUN TRACE: (%d,%d) to (%d,%d)', [x, y, x2, y2]), MSG_NOTIFY);
1513 {$IF DEFINED(GWEP_HITSCAN_TRACE_BITMAP_CHECKER)}
1514 t1 := (gWalls <> nil);
1515 w := gMapInfo.Width;
1516 h := gMapInfo.Height;
1522 if (xd = 0) and (yd = 0) then Exit;
1524 if dx > 0 then xi := 1 else if dx < 0 then xi := -1 else xi := 0;
1525 if dy > 0 then yi := 1 else if dy < 0 then yi := -1 else yi := 0;
1527 // check instant hits
1530 if (dx < 0) then Dec(xx);
1531 if (dy < 0) then Dec(yy);
1536 if playerPossibleHit() then exit; // instant hit
1537 if g_Mons_ForEachAliveAt(xx, yy, 3, 3, monsPossibleHitInstant) then exit; // instant hit
1539 if dx > dy then d := dx else d := dy;
1541 //blood vel, for Monster.Damage()
1542 //vx := (dx*10 div d)*xi;
1543 //vy := (dy*10 div d)*yi;
1545 {$IF DEFINED(D2F_DEBUG)}
1546 mptHit := g_Map_traceToNearestWall(x, y, x2, y2, @mptWX, @mptWY);
1547 e_WriteLog(Format('tree trace: (%d,%d)', [mptWX, mptWY]), MSG_NOTIFY);
1550 {$IF not DEFINED(GWEP_HITSCAN_TRACE_BITMAP_CHECKER)}
1551 wallWasHit := (mptHit >= 0);
1557 {$IF DEFINED(D2F_DEBUG)}
1558 stt := curTimeMicro();
1560 // find wall, collect monsters
1574 if (xe > d) then begin xe -= d; xx += xi; end;
1575 if (ye > d) then begin ye -= d; yy += yi; end;
1578 //if (yy > h) or (yy < 0) then break;
1579 //if (xx > w) or (xx < 0) then break;
1581 {$IF DEFINED(GWEP_HITSCAN_TRACE_BITMAP_CHECKER)}
1582 if t1 and (xx >= 0) and (yy >= 0) and (xx < w) and (yy < h) then
1584 if ByteBool(gCollideMap[yy, xx] and MARK_BLOCKED) then
1592 if (abs(prevX-wallHitX) < 2) and (abs(prevY-wallHitY) < 2) then t1 := true;
1595 if (leftToNextMonsterQuery <> 0) and not wallWasHit then
1597 Dec(leftToNextMonsterQuery);
1602 g_Mons_ForEachAliveAt(xx-HHGridSize div 2, yy-HHGridSize div 2, HHGridSize+HHGridSize div 2, HHGridSize+HHGridSize div 2, monsPossibleHit);
1603 leftToNextMonsterQuery := HHGridSize; // again
1604 {$IF DEFINED(GWEP_HITSCAN_TRACE_BITMAP_CHECKER)}
1605 if wallWasHit then break;
1612 if not wallWasHit then
1619 // here, we collected all monsters and players in `wgunHitHeap` and `wgunHitTime`
1620 // also, if `wallWasHit` is true, then `wallHitX` and `wallHitY` contains wall coords
1621 while (wgunHitHeap.count > 0) do
1623 // has some entities to check, do it
1624 i := wgunHitHeap.front;
1625 wgunHitHeap.popFront();
1626 hitray.atTime(wgunHitTime[i].time, xe, ye);
1627 // check if it is not behind the wall
1628 if ((xe-x)*(xe-x)+(ye-y)*(ye-y) < (wallHitX-x)*(wallHitX-x)+(wallHitY-y)*(wallHitY-y)) then
1630 if (wgunHitTime[i].mon <> nil) then
1632 didHit := doMonsterHit(wgunHitTime[i].mon);
1636 didHit := doPlayerHit(wgunHitTime[i].plridx);
1640 // need new coords for trigger
1643 wallWasHit := false; // no sparks
1652 {$IF DEFINED(GWEP_HITSCAN_TRACE_BITMAP_CHECKER)}
1653 if (mptHit < 0) then
1655 e_WriteLog('OOPS: tree trace failed, but pixel trace found the wall!', MSG_WARNING);
1656 raise Exception.Create('map tree trace fucked');
1660 {$IF DEFINED(D2F_DEBUG)}
1661 //e_WriteLog(Format(' trace: (%d,%d)', [wallHitX, wallHitY]), MSG_NOTIFY);
1667 {$IF DEFINED(D2F_DEBUG)}
1668 stt := curTimeMicro()-stt;
1669 e_WriteLog(Format('*** new trace time: %u microseconds', [LongWord(stt)]), MSG_NOTIFY);
1671 g_GFX_Spark(wallHitX, wallHitY, 2+Random(2), 180+a, 0, 0);
1672 if g_Game_IsServer and g_Game_IsNet then MH_SEND_Effect(wallHitX, wallHitY, 180+a, NET_GFX_SPARK);
1676 {$IF DEFINED(D2F_DEBUG)}
1677 stt := curTimeMicro()-stt;
1678 e_WriteLog(Format('*** new trace time: %u microseconds', [LongWord(stt)]), MSG_NOTIFY);
1682 if CheckTrigger and g_Game_IsServer then g_Triggers_PressL(X, Y, wallHitX, wallHitY, SpawnerUID, ACTIVATE_SHOT);
1687 procedure g_Weapon_gun (const x
, y
, xd
, yd
, v
, dmg
: Integer; SpawnerUID
: Word; CheckTrigger
: Boolean);
1691 wallDistSq
: Single = 1.0e100
;
1693 function doPlayerHit (idx
: Integer): Boolean;
1696 if (idx
< 0) or (idx
> High(gPlayers
)) then exit
;
1697 if (gPlayers
[idx
] = nil) or not gPlayers
[idx
].Live
then exit
;
1698 result
:= HitPlayer(gPlayers
[idx
], dmg
, (xi
*v
)*10, (yi
*v
)*10-3, SpawnerUID
, HIT_SOME
);
1699 if result
and (v
<> 0) then gPlayers
[idx
].Push((xi
*v
), (yi
*v
));
1700 {$IF DEFINED(D2F_DEBUG)}
1701 //if result then e_WriteLog(Format(' PLAYER #%d HIT', [idx]), MSG_NOTIFY);
1705 function doMonsterHit (mon
: TMonster
): Boolean;
1708 if (mon
= nil) then exit
;
1709 result
:= HitMonster(mon
, dmg
, (xi
*v
)*10, (yi
*v
)*10-3, SpawnerUID
, HIT_SOME
);
1710 if result
and (v
<> 0) then mon
.Push((xi
*v
), (yi
*v
));
1711 {$IF DEFINED(D2F_DEBUG)}
1712 //if result then e_WriteLog(Format(' MONSTER #%u HIT', [LongWord(mon.UID)]), MSG_NOTIFY);
1716 // collect players along hitray
1717 // return `true` if instant hit was detected
1718 function playerPossibleHit (): Boolean;
1725 for i
:= 0 to High(gPlayers
) do
1727 if (gPlayers
[i
] <> nil) and gPlayers
[i
].Live
then
1729 aabb
:= gPlayers
[i
].mapAABB
;
1731 if aabb
.contains(x
, y
) then
1733 if doPlayerHit(i
) then begin result
:= true; exit
; end;
1735 else if (aabb
.intersects(hitray
, @tmin
)) then
1738 if (tmin
<= 0.0) then
1740 if doPlayerHit(i
) then begin result
:= true; exit
; end;
1744 if (tmin
*tmin
< wallDistSq
) then appendHitTimePlr(tmin
, i
);
1751 function sqchecker (mon
: TMonster
; dist
: Single): Boolean;
1753 result
:= false; // don't stop
1754 if (dist
*dist
< wallDistSq
) then appendHitTimeMon(dist
, mon
);
1764 wallHitIdx
: Integer = -1;
1765 wallHitX
: Integer = 0;
1766 wallHitY
: Integer = 0;
1767 didHit
: Boolean = false;
1768 {$IF DEFINED(D2F_DEBUG)}
1772 if not gwep_debug_fast_trace
then
1774 g_Weapon_gunOld(x
, y
, xd
, yd
, v
, dmg
, SpawnerUID
, CheckTrigger
);
1778 wgunMonHash
.reset(); //FIXME: clear hash on level change
1779 wgunHitHeap
.clear();
1780 wgunHitTimeUsed
:= 0;
1782 a
:= GetAngle(x
, y
, xd
, yd
)+180;
1784 SinCos(DegToRad(-a
), s
, c
);
1786 if Abs(s
) < 0.01 then s
:= 0;
1787 if Abs(c
) < 0.01 then c
:= 0;
1789 x2
:= x
+Round(c
*gMapInfo
.Width
);
1790 y2
:= y
+Round(s
*gMapInfo
.Width
);
1795 if (xd
= 0) and (yd
= 0) then exit
;
1797 if dx
> 0 then xi
:= 1 else if dx
< 0 then xi
:= -1 else xi
:= 0;
1798 if dy
> 0 then yi
:= 1 else if dy
< 0 then yi
:= -1 else yi
:= 0;
1800 {$IF DEFINED(D2F_DEBUG)}
1801 e_WriteLog(Format('GUN TRACE: (%d,%d) to (%d,%d)', [x
, y
, x2
, y2
]), MSG_NOTIFY
);
1802 stt
:= curTimeMicro();
1805 wallHitIdx
:= g_Map_traceToNearestWall(x
, y
, x2
, y2
, @wallHitX
, @wallHitY
);
1806 if (wallHitIdx
>= 0) then
1810 wallDistSq
:= (wallHitX
-x
)*(wallHitX
-x
)+(wallHitY
-y
)*(wallHitY
-y
);
1818 hitray
:= Ray2D
.Create(x
, y
, x2
, y2
);
1820 if playerPossibleHit() then exit
; // instant hit
1823 g_Mons_alongLine(x
, y
, x2
, y2
, sqchecker
);
1825 // here, we collected all monsters and players in `wgunHitHeap` and `wgunHitTime`
1826 // also, if `wallWasHit` >= 0, then `wallHitX` and `wallHitY` contains spark coords
1827 while (wgunHitHeap
.count
> 0) do
1829 // has some entities to check, do it
1830 i
:= wgunHitHeap
.front
;
1831 wgunHitHeap
.popFront();
1832 hitray
.atTime(wgunHitTime
[i
].time
, xe
, ye
);
1833 // check if it is not behind the wall
1834 if (wgunHitTime
[i
].mon
<> nil) then
1836 didHit
:= doMonsterHit(wgunHitTime
[i
].mon
);
1840 didHit
:= doPlayerHit(wgunHitTime
[i
].plridx
);
1844 // need new coords for trigger
1847 wallHitIdx
:= -1; // no sparks
1853 if (wallHitIdx
>= 0) then
1855 {$IF DEFINED(D2F_DEBUG)}
1856 stt
:= curTimeMicro()-stt
;
1857 e_WriteLog(Format('*** new trace time: %u microseconds', [LongWord(stt
)]), MSG_NOTIFY
);
1859 g_GFX_Spark(wallHitX
, wallHitY
, 2+Random(2), 180+a
, 0, 0);
1860 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Effect(wallHitX
, wallHitY
, 180+a
, NET_GFX_SPARK
);
1864 {$IF DEFINED(D2F_DEBUG)}
1865 stt
:= curTimeMicro()-stt
;
1866 e_WriteLog(Format('*** new trace time: %u microseconds', [LongWord(stt
)]), MSG_NOTIFY
);
1870 if CheckTrigger
and g_Game_IsServer
then g_Triggers_PressL(X
, Y
, wallHitX
, wallHitY
, SpawnerUID
, ACTIVATE_SHOT
);
1874 procedure g_Weapon_punch(x
, y
: Integer; d
, SpawnerUID
: Word);
1882 obj
.rect
.Width
:= 39;
1883 obj
.rect
.Height
:= 52;
1889 if g_Weapon_Hit(@obj
, d
, SpawnerUID
, HIT_SOME
) <> 0 then
1890 g_Sound_PlayExAt('SOUND_WEAPON_HITPUNCH', x
, y
)
1892 g_Sound_PlayExAt('SOUND_WEAPON_MISSPUNCH', x
, y
);
1895 function g_Weapon_chainsaw(x
, y
: Integer; d
, SpawnerUID
: Word): Integer;
1903 obj
.rect
.Width
:= 32;
1904 obj
.rect
.Height
:= 52;
1910 Result
:= g_Weapon_Hit(@obj
, d
, SpawnerUID
, HIT_SOME
);
1913 procedure g_Weapon_rocket(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1;
1914 Silent
: Boolean = False);
1920 find_id
:= FindShot()
1924 if Integer(find_id
) >= High(Shots
) then
1925 SetLength(Shots
, find_id
+ 64)
1928 with Shots
[find_id
] do
1932 Obj
.Rect
.Width
:= SHOT_ROCKETLAUNCHER_WIDTH
;
1933 Obj
.Rect
.Height
:= SHOT_ROCKETLAUNCHER_HEIGHT
;
1935 dx
:= IfThen(xd
> x
, -Obj
.Rect
.Width
, 0);
1936 dy
:= -(Obj
.Rect
.Height
div 2);
1938 ShotType
:= WEAPON_ROCKETLAUNCHER
;
1939 throw(find_id
, x
+dx
, y
+dy
, xd
+dx
, yd
+dy
, 12);
1943 g_Texture_Get('TEXTURE_WEAPON_ROCKET', TextureID
);
1946 Shots
[find_id
].SpawnerUID
:= SpawnerUID
;
1949 g_Sound_PlayExAt('SOUND_WEAPON_FIREROCKET', x
, y
);
1952 procedure g_Weapon_revf(x
, y
, xd
, yd
: Integer; SpawnerUID
, TargetUID
: Word;
1953 WID
: Integer = -1; Silent
: Boolean = False);
1955 find_id
, FramesID
: DWORD
;
1959 find_id
:= FindShot()
1963 if Integer(find_id
) >= High(Shots
) then
1964 SetLength(Shots
, find_id
+ 64)
1967 with Shots
[find_id
] do
1971 Obj
.Rect
.Width
:= SHOT_SKELFIRE_WIDTH
;
1972 Obj
.Rect
.Height
:= SHOT_SKELFIRE_HEIGHT
;
1974 dx
:= -(Obj
.Rect
.Width
div 2);
1975 dy
:= -(Obj
.Rect
.Height
div 2);
1977 ShotType
:= WEAPON_SKEL_FIRE
;
1978 throw(find_id
, x
+dx
, y
+dy
, xd
+dx
, yd
+dy
, 12);
1981 target
:= TargetUID
;
1982 g_Frames_Get(FramesID
, 'FRAMES_WEAPON_SKELFIRE');
1983 Animation
:= TAnimation
.Create(FramesID
, True, 5);
1986 Shots
[find_id
].SpawnerUID
:= SpawnerUID
;
1989 g_Sound_PlayExAt('SOUND_WEAPON_FIREREV', x
, y
);
1992 procedure g_Weapon_plasma(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1;
1993 Silent
: Boolean = False);
1995 find_id
, FramesID
: DWORD
;
1999 find_id
:= FindShot()
2003 if Integer(find_id
) >= High(Shots
) then
2004 SetLength(Shots
, find_id
+ 64);
2007 with Shots
[find_id
] do
2011 Obj
.Rect
.Width
:= SHOT_PLASMA_WIDTH
;
2012 Obj
.Rect
.Height
:= SHOT_PLASMA_HEIGHT
;
2014 dx
:= IfThen(xd
>x
, -Obj
.Rect
.Width
, 0);
2015 dy
:= -(Obj
.Rect
.Height
div 2);
2017 ShotType
:= WEAPON_PLASMA
;
2018 throw(find_id
, x
+dx
, y
+dy
, xd
+dx
, yd
+dy
, 16);
2021 g_Frames_Get(FramesID
, 'FRAMES_WEAPON_PLASMA');
2022 Animation
:= TAnimation
.Create(FramesID
, True, 5);
2025 Shots
[find_id
].SpawnerUID
:= SpawnerUID
;
2028 g_Sound_PlayExAt('SOUND_WEAPON_FIREPLASMA', x
, y
);
2031 procedure g_Weapon_flame(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1;
2032 Silent
: Boolean = False);
2038 find_id
:= FindShot()
2042 if Integer(find_id
) >= High(Shots
) then
2043 SetLength(Shots
, find_id
+ 64);
2046 with Shots
[find_id
] do
2050 Obj
.Rect
.Width
:= SHOT_FLAME_WIDTH
;
2051 Obj
.Rect
.Height
:= SHOT_FLAME_HEIGHT
;
2053 dx
:= IfThen(xd
>x
, -Obj
.Rect
.Width
, 0);
2054 dy
:= -(Obj
.Rect
.Height
div 2);
2056 ShotType
:= WEAPON_FLAMETHROWER
;
2057 throw(find_id
, x
+dx
, y
+dy
, xd
+dx
, yd
+dy
, 16);
2062 g_Frames_Get(TextureID
, 'FRAMES_FLAME');
2065 Shots
[find_id
].SpawnerUID
:= SpawnerUID
;
2067 // if not Silent then
2068 // g_Sound_PlayExAt('SOUND_WEAPON_FIREPLASMA', x, y);
2071 procedure g_Weapon_ball1(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1;
2072 Silent
: Boolean = False);
2074 find_id
, FramesID
: DWORD
;
2078 find_id
:= FindShot()
2082 if Integer(find_id
) >= High(Shots
) then
2083 SetLength(Shots
, find_id
+ 64)
2086 with Shots
[find_id
] do
2090 Obj
.Rect
.Width
:= 16;
2091 Obj
.Rect
.Height
:= 16;
2093 dx
:= IfThen(xd
>x
, -Obj
.Rect
.Width
, 0);
2094 dy
:= -(Obj
.Rect
.Height
div 2);
2096 ShotType
:= WEAPON_IMP_FIRE
;
2097 throw(find_id
, x
+dx
, y
+dy
, xd
+dx
, yd
+dy
, 16);
2100 g_Frames_Get(FramesID
, 'FRAMES_WEAPON_IMPFIRE');
2101 Animation
:= TAnimation
.Create(FramesID
, True, 4);
2104 Shots
[find_id
].SpawnerUID
:= SpawnerUID
;
2107 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x
, y
);
2110 procedure g_Weapon_ball2(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1;
2111 Silent
: Boolean = False);
2113 find_id
, FramesID
: DWORD
;
2117 find_id
:= FindShot()
2121 if Integer(find_id
) >= High(Shots
) then
2122 SetLength(Shots
, find_id
+ 64)
2125 with Shots
[find_id
] do
2129 Obj
.Rect
.Width
:= 16;
2130 Obj
.Rect
.Height
:= 16;
2132 dx
:= IfThen(xd
>x
, -Obj
.Rect
.Width
, 0);
2133 dy
:= -(Obj
.Rect
.Height
div 2);
2135 ShotType
:= WEAPON_CACO_FIRE
;
2136 throw(find_id
, x
+dx
, y
+dy
, xd
+dx
, yd
+dy
, 16);
2139 g_Frames_Get(FramesID
, 'FRAMES_WEAPON_CACOFIRE');
2140 Animation
:= TAnimation
.Create(FramesID
, True, 4);
2143 Shots
[find_id
].SpawnerUID
:= SpawnerUID
;
2146 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x
, y
);
2149 procedure g_Weapon_ball7(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1;
2150 Silent
: Boolean = False);
2152 find_id
, FramesID
: DWORD
;
2156 find_id
:= FindShot()
2160 if Integer(find_id
) >= High(Shots
) then
2161 SetLength(Shots
, find_id
+ 64)
2164 with Shots
[find_id
] do
2168 Obj
.Rect
.Width
:= 32;
2169 Obj
.Rect
.Height
:= 16;
2171 dx
:= IfThen(xd
>x
, -Obj
.Rect
.Width
, 0);
2172 dy
:= -(Obj
.Rect
.Height
div 2);
2174 ShotType
:= WEAPON_BARON_FIRE
;
2175 throw(find_id
, x
+dx
, y
+dy
, xd
+dx
, yd
+dy
, 16);
2178 g_Frames_Get(FramesID
, 'FRAMES_WEAPON_BARONFIRE');
2179 Animation
:= TAnimation
.Create(FramesID
, True, 4);
2182 Shots
[find_id
].SpawnerUID
:= SpawnerUID
;
2185 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x
, y
);
2188 procedure g_Weapon_aplasma(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1;
2189 Silent
: Boolean = False);
2191 find_id
, FramesID
: DWORD
;
2195 find_id
:= FindShot()
2199 if Integer(find_id
) >= High(Shots
) then
2200 SetLength(Shots
, find_id
+ 64)
2203 with Shots
[find_id
] do
2207 Obj
.Rect
.Width
:= 16;
2208 Obj
.Rect
.Height
:= 16;
2210 dx
:= IfThen(xd
>x
, -Obj
.Rect
.Width
, 0);
2211 dy
:= -(Obj
.Rect
.Height
div 2);
2213 ShotType
:= WEAPON_BSP_FIRE
;
2214 throw(find_id
, x
+dx
, y
+dy
, xd
+dx
, yd
+dy
, 16);
2218 g_Frames_Get(FramesID
, 'FRAMES_WEAPON_BSPFIRE');
2219 Animation
:= TAnimation
.Create(FramesID
, True, 4);
2222 Shots
[find_id
].SpawnerUID
:= SpawnerUID
;
2225 g_Sound_PlayExAt('SOUND_WEAPON_FIREPLASMA', x
, y
);
2228 procedure g_Weapon_manfire(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1;
2229 Silent
: Boolean = False);
2231 find_id
, FramesID
: DWORD
;
2235 find_id
:= FindShot()
2239 if Integer(find_id
) >= High(Shots
) then
2240 SetLength(Shots
, find_id
+ 64)
2243 with Shots
[find_id
] do
2247 Obj
.Rect
.Width
:= 32;
2248 Obj
.Rect
.Height
:= 32;
2250 dx
:= IfThen(xd
>x
, -Obj
.Rect
.Width
, 0);
2251 dy
:= -(Obj
.Rect
.Height
div 2);
2253 ShotType
:= WEAPON_MANCUB_FIRE
;
2254 throw(find_id
, x
+dx
, y
+dy
, xd
+dx
, yd
+dy
, 16);
2258 g_Frames_Get(FramesID
, 'FRAMES_WEAPON_MANCUBFIRE');
2259 Animation
:= TAnimation
.Create(FramesID
, True, 4);
2262 Shots
[find_id
].SpawnerUID
:= SpawnerUID
;
2265 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x
, y
);
2268 procedure g_Weapon_bfgshot(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1;
2269 Silent
: Boolean = False);
2271 find_id
, FramesID
: DWORD
;
2275 find_id
:= FindShot()
2279 if Integer(find_id
) >= High(Shots
) then
2280 SetLength(Shots
, find_id
+ 64)
2283 with Shots
[find_id
] do
2287 Obj
.Rect
.Width
:= SHOT_BFG_WIDTH
;
2288 Obj
.Rect
.Height
:= SHOT_BFG_HEIGHT
;
2290 dx
:= IfThen(xd
>x
, -Obj
.Rect
.Width
, 0);
2291 dy
:= -(Obj
.Rect
.Height
div 2);
2293 ShotType
:= WEAPON_BFG
;
2294 throw(find_id
, x
+dx
, y
+dy
, xd
+dx
, yd
+dy
, 16);
2297 g_Frames_Get(FramesID
, 'FRAMES_WEAPON_BFG');
2298 Animation
:= TAnimation
.Create(FramesID
, True, 6);
2301 Shots
[find_id
].SpawnerUID
:= SpawnerUID
;
2304 g_Sound_PlayExAt('SOUND_WEAPON_FIREBFG', x
, y
);
2307 procedure g_Weapon_bfghit(x
, y
: Integer);
2312 if g_Frames_Get(ID
, 'FRAMES_BFGHIT') then
2314 Anim
:= TAnimation
.Create(ID
, False, 4);
2315 g_GFX_OnceAnim(x
-32, y
-32, Anim
);
2320 procedure g_Weapon_pistol(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word;
2321 Silent
: Boolean = False);
2324 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', x
, y
);
2326 g_Weapon_gun(x
, y
, xd
, yd
, 1, 3, SpawnerUID
, True);
2327 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
] then
2329 g_Weapon_gun(x
, y
+1, xd
, yd
+1, 1, 3, SpawnerUID
, False);
2330 g_Weapon_gun(x
, y
-1, xd
, yd
-1, 1, 2, SpawnerUID
, False);
2334 procedure g_Weapon_mgun(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word;
2335 Silent
: Boolean = False);
2338 if gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', x
, y
);
2340 g_Weapon_gun(x
, y
, xd
, yd
, 1, 3, SpawnerUID
, True);
2341 if (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) and
2342 (g_GetUIDType(SpawnerUID
) = UID_PLAYER
) then
2344 g_Weapon_gun(x
, y
+1, xd
, yd
+1, 1, 2, SpawnerUID
, False);
2345 g_Weapon_gun(x
, y
-1, xd
, yd
-1, 1, 2, SpawnerUID
, False);
2349 procedure g_Weapon_shotgun(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word;
2350 Silent
: Boolean = False);
2355 if gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', x
, y
);
2359 j
:= Random(17)-8; // -8 .. 8
2360 g_Weapon_gun(x
, y
+j
, xd
, yd
+j
, IfThen(i
mod 2 <> 0, 1, 0), 3, SpawnerUID
, i
=0);
2364 procedure g_Weapon_dshotgun(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word;
2365 Silent
: Boolean = False);
2370 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', x
, y
);
2372 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
] then a
:= 25 else a
:= 20;
2375 j
:= Random(41)-20; // -20 .. 20
2376 g_Weapon_gun(x
, y
+j
, xd
, yd
+j
, IfThen(i
mod 3 <> 0, 0, 1), 3, SpawnerUID
, i
=0);
2380 procedure g_Weapon_Update();
2382 i
, a
, h
, cx
, cy
, oldvx
, oldvy
, tf
: Integer;
2396 for i
:= 0 to High(Shots
) do
2398 if Shots
[i
].ShotType
= 0 then
2405 Timeout
:= Timeout
- 1;
2408 // Àêòèâèðîâàòü òðèããåðû ïî ïóòè (êðîìå óæå àêòèâèðîâàííûõ):
2409 if (Stopped
= 0) and g_Game_IsServer
then
2410 t
:= g_Triggers_PressR(Obj
.X
, Obj
.Y
, Obj
.Rect
.Width
, Obj
.Rect
.Height
,
2411 SpawnerUID
, ACTIVATE_SHOT
, triggers
)
2417 // Ïîïîëíÿåì ñïèñîê àêòèâèðîâàííûõ òðèããåðîâ:
2418 if triggers
= nil then
2425 if not InDWArray(t
[a
], triggers
) then
2427 SetLength(triggers
, Length(triggers
)+1);
2428 triggers
[High(triggers
)] := t
[a
];
2433 // Àíèìàöèÿ ñíàðÿäà:
2434 if Animation
<> nil then
2438 spl
:= (ShotType
<> WEAPON_PLASMA
) and
2439 (ShotType
<> WEAPON_BFG
) and
2440 (ShotType
<> WEAPON_BSP_FIRE
) and
2441 (ShotType
<> WEAPON_FLAMETHROWER
);
2445 st
:= g_Obj_Move(@Obj
, False, spl
);
2451 positionChanged(); // this updates spatial accelerators
2453 if WordBool(st
and MOVE_FALLOUT
) or (Obj
.X
< -1000) or
2454 (Obj
.X
> gMapInfo
.Width
+1000) or (Obj
.Y
< -1000) then
2456 // Íà êëèåíòå ñêîðåå âñåãî è òàê óæå âûïàë.
2462 cx
:= Obj
.X
+ (Obj
.Rect
.Width
div 2);
2463 cy
:= Obj
.Y
+ (Obj
.Rect
.Height
div 2);
2466 WEAPON_ROCKETLAUNCHER
, WEAPON_SKEL_FIRE
: // Ðàêåòû è ñíàðÿäû Ñêåëåòà
2468 // Âûëåòåëà èç âîäû:
2469 if WordBool(st
and MOVE_HITAIR
) then
2470 g_Obj_SetSpeed(@Obj
, 12);
2472 // Â âîäå øëåéô - ïóçûðè, â âîçäóõå øëåéô - äûì:
2473 if WordBool(st
and MOVE_INWATER
) then
2474 g_GFX_Bubbles(Obj
.X
+(Obj
.Rect
.Width
div 2),
2475 Obj
.Y
+(Obj
.Rect
.Height
div 2),
2476 1+Random(3), 16, 16)
2478 if g_Frames_Get(_id
, 'FRAMES_SMOKE') then
2480 Anim
:= TAnimation
.Create(_id
, False, 3);
2482 g_GFX_OnceAnim(Obj
.X
-14+Random(9),
2483 Obj
.Y
+(Obj
.Rect
.Height
div 2)-20+Random(9),
2484 Anim
, ONCEANIM_SMOKE
);
2488 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2489 if WordBool(st
and (MOVE_HITWALL
or MOVE_HITLAND
or MOVE_HITCEIL
)) or
2490 (g_Weapon_Hit(@Obj
, 10, SpawnerUID
, HIT_SOME
, False) <> 0) or
2496 g_Weapon_Explode(cx
, cy
, 60, SpawnerUID
);
2498 if ShotType
= WEAPON_SKEL_FIRE
then
2499 begin // Âçðûâ ñíàðÿäà Ñêåëåòà
2500 if g_Frames_Get(TextureID
, 'FRAMES_EXPLODE_SKELFIRE') then
2502 Anim
:= TAnimation
.Create(TextureID
, False, 8);
2503 Anim
.Blending
:= False;
2504 g_GFX_OnceAnim((Obj
.X
+32)-58, (Obj
.Y
+8)-36, Anim
);
2505 g_DynLightExplosion((Obj
.X
+32), (Obj
.Y
+8), 64, 1, 0, 0);
2510 begin // Âçðûâ Ðàêåòû
2511 if g_Frames_Get(TextureID
, 'FRAMES_EXPLODE_ROCKET') then
2513 Anim
:= TAnimation
.Create(TextureID
, False, 6);
2514 Anim
.Blending
:= False;
2515 g_GFX_OnceAnim(cx
-64, cy
-64, Anim
);
2516 g_DynLightExplosion(cx
, cy
, 64, 1, 0, 0);
2521 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', Obj
.X
, Obj
.Y
);
2526 if ShotType
= WEAPON_SKEL_FIRE
then
2527 begin // Ñàìîíàâîäêà ñíàðÿäà Ñêåëåòà:
2528 if GetPos(target
, @o
) then
2529 throw(i
, Obj
.X
, Obj
.Y
,
2530 o
.X
+o
.Rect
.X
+(o
.Rect
.Width
div 2)+o
.Vel
.X
+o
.Accel
.X
,
2531 o
.Y
+o
.Rect
.Y
+(o
.Rect
.Height
div 2)+o
.Vel
.Y
+o
.Accel
.Y
,
2536 WEAPON_PLASMA
, WEAPON_BSP_FIRE
: // Ïëàçìà, ïëàçìà Àðàõíàòðîíà
2538 // Ïîïàëà â âîäó - ýëåêòðîøîê ïî âîäå:
2539 if WordBool(st
and (MOVE_INWATER
or MOVE_HITWATER
)) then
2541 g_Sound_PlayExAt('SOUND_WEAPON_PLASMAWATER', Obj
.X
, Obj
.Y
);
2542 if g_Game_IsServer
then CheckTrap(i
, 10, HIT_ELECTRO
);
2548 if (ShotType
= WEAPON_PLASMA
) and
2549 (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) then
2554 if ShotType
= WEAPON_BSP_FIRE
then
2557 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2558 if WordBool(st
and (MOVE_HITWALL
or MOVE_HITLAND
or MOVE_HITCEIL
)) or
2559 (g_Weapon_Hit(@Obj
, a
, SpawnerUID
, HIT_SOME
, False) <> 0) or
2562 if ShotType
= WEAPON_PLASMA
then
2563 s
:= 'FRAMES_EXPLODE_PLASMA'
2565 s
:= 'FRAMES_EXPLODE_BSPFIRE';
2568 if g_Frames_Get(TextureID
, s
) then
2570 Anim
:= TAnimation
.Create(TextureID
, False, 3);
2571 Anim
.Blending
:= False;
2572 g_GFX_OnceAnim(cx
-16, cy
-16, Anim
);
2574 g_DynLightExplosion(cx
, cy
, 32, 0, 0.5, 0.5);
2577 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEPLASMA', Obj
.X
, Obj
.Y
);
2583 WEAPON_FLAMETHROWER
: // Îãíåìåò
2585 // Ñî âðåìåíåì óìèðàåò
2586 if (Timeout
< 1) then
2592 if WordBool(st
and (MOVE_HITWATER
or MOVE_INWATER
)) then
2594 if WordBool(st
and MOVE_HITWATER
) then
2596 if g_Frames_Get(_id
, 'FRAMES_SMOKE') then
2598 Anim
:= TAnimation
.Create(_id
, False, 3);
2602 g_GFX_OnceAnim(cx
-4+tcx
-(Anim
.Width
div 2),
2603 cy
-4+tcy
-(Anim
.Height
div 2),
2604 Anim
, ONCEANIM_SMOKE
);
2609 g_GFX_Bubbles(cx
, cy
, 1+Random(3), 16, 16);
2616 Obj
.Accel
.Y
:= Obj
.Accel
.Y
+ 1;
2617 // Ïîïàëè â ñòåíó èëè â âîäó:
2618 if WordBool(st
and (MOVE_HITWALL
or MOVE_HITLAND
or MOVE_HITCEIL
or MOVE_HITWATER
)) then
2624 if WordBool(st
and MOVE_HITWALL
) then
2625 Stopped
:= MOVE_HITWALL
2626 else if WordBool(st
and MOVE_HITLAND
) then
2627 Stopped
:= MOVE_HITLAND
2628 else if WordBool(st
and MOVE_HITCEIL
) then
2629 Stopped
:= MOVE_HITCEIL
;
2632 a
:= IfThen(Stopped
= 0, 3, 1);
2633 // Åñëè â êîãî-òî ïîïàëè
2634 if g_Weapon_Hit(@Obj
, a
, SpawnerUID
, HIT_FLAME
, False) <> 0 then
2636 // HIT_FLAME ñàì ïîäîææåò
2637 // Åñëè â ïîëåòå ïîïàëè, èñ÷åçàåì
2647 if (gTime
mod tf
= 0) then
2649 Anim
:= TAnimation
.Create(TextureID
, False, 2 + Random(2));
2652 MOVE_HITWALL
: begin tcx
:= cx
-4+Random(8); tcy
:= cy
-12+Random(24); end;
2653 MOVE_HITLAND
: begin tcx
:= cx
-12+Random(24); tcy
:= cy
-10+Random(8); end;
2654 MOVE_HITCEIL
: begin tcx
:= cx
-12+Random(24); tcy
:= cy
+6+Random(8); end;
2655 else begin tcx
:= cx
-4+Random(8); tcy
:= cy
-4+Random(8); end;
2657 g_GFX_OnceAnim(tcx
-(Anim
.Width
div 2), tcy
-(Anim
.Height
div 2), Anim
, ONCEANIM_SMOKE
);
2659 //g_DynLightExplosion(tcx, tcy, 1, 1, 0.8, 0.3);
2665 // Ïîïàëà â âîäó - ýëåêòðîøîê ïî âîäå:
2666 if WordBool(st
and (MOVE_INWATER
or MOVE_HITWATER
)) then
2668 g_Sound_PlayExAt('SOUND_WEAPON_BFGWATER', Obj
.X
, Obj
.Y
);
2669 if g_Game_IsServer
then CheckTrap(i
, 1000, HIT_ELECTRO
);
2674 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2675 if WordBool(st
and (MOVE_HITWALL
or MOVE_HITLAND
or MOVE_HITCEIL
)) or
2676 (g_Weapon_Hit(@Obj
, SHOT_BFG_DAMAGE
, SpawnerUID
, HIT_BFG
, False) <> 0) or
2680 if g_Game_IsServer
then g_Weapon_BFG9000(cx
, cy
, SpawnerUID
);
2683 if g_Frames_Get(TextureID
, 'FRAMES_EXPLODE_BFG') then
2685 Anim
:= TAnimation
.Create(TextureID
, False, 6);
2686 Anim
.Blending
:= False;
2687 g_GFX_OnceAnim(cx
-64, cy
-64, Anim
);
2689 g_DynLightExplosion(cx
, cy
, 96, 0, 1, 0);
2692 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', Obj
.X
, Obj
.Y
);
2698 WEAPON_IMP_FIRE
, WEAPON_CACO_FIRE
, WEAPON_BARON_FIRE
: // Âûñòðåëû Áåñà, Êàêîäåìîíà Ðûöàðÿ/Áàðîíà àäà
2701 if WordBool(st
and MOVE_HITAIR
) then
2702 g_Obj_SetSpeed(@Obj
, 16);
2705 if ShotType
= WEAPON_IMP_FIRE
then
2708 if ShotType
= WEAPON_CACO_FIRE
then
2713 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2714 if WordBool(st
and (MOVE_HITWALL
or MOVE_HITLAND
or MOVE_HITCEIL
)) or
2715 (g_Weapon_Hit(@Obj
, a
, SpawnerUID
, HIT_SOME
) <> 0) or
2718 if ShotType
= WEAPON_IMP_FIRE
then
2719 s
:= 'FRAMES_EXPLODE_IMPFIRE'
2721 if ShotType
= WEAPON_CACO_FIRE
then
2722 s
:= 'FRAMES_EXPLODE_CACOFIRE'
2724 s
:= 'FRAMES_EXPLODE_BARONFIRE';
2727 if g_Frames_Get(TextureID
, s
) then
2729 Anim
:= TAnimation
.Create(TextureID
, False, 6);
2730 Anim
.Blending
:= False;
2731 g_GFX_OnceAnim(cx
-32, cy
-32, Anim
);
2735 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj
.X
, Obj
.Y
);
2741 WEAPON_MANCUB_FIRE
: // Âûñòðåë Ìàíêóáóñà
2744 if WordBool(st
and MOVE_HITAIR
) then
2745 g_Obj_SetSpeed(@Obj
, 16);
2747 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2748 if WordBool(st
and (MOVE_HITWALL
or MOVE_HITLAND
or MOVE_HITCEIL
)) or
2749 (g_Weapon_Hit(@Obj
, 40, SpawnerUID
, HIT_SOME
, False) <> 0) or
2753 if g_Frames_Get(TextureID
, 'FRAMES_EXPLODE_ROCKET') then
2755 Anim
:= TAnimation
.Create(TextureID
, False, 6);
2756 Anim
.Blending
:= False;
2757 g_GFX_OnceAnim(cx
-64, cy
-64, Anim
);
2761 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj
.X
, Obj
.Y
);
2766 end; // case ShotType of...
2768 // Åñëè ñíàðÿäà óæå íåò, óäàëÿåì àíèìàöèþ:
2769 if (ShotType
= 0) then
2771 if gGameSettings
.GameType
= GT_SERVER
then
2772 MH_SEND_DeleteShot(i
, Obj
.X
, Obj
.Y
, Loud
);
2773 if Animation
<> nil then
2779 else if (ShotType
<> WEAPON_FLAMETHROWER
) and ((oldvx
<> Obj
.Vel
.X
) or (oldvy
<> Obj
.Vel
.Y
)) then
2780 if gGameSettings
.GameType
= GT_SERVER
then
2781 MH_SEND_UpdateShot(i
);
2786 procedure g_Weapon_Draw();
2795 for i
:= 0 to High(Shots
) do
2796 if Shots
[i
].ShotType
<> 0 then
2799 if (Shots
[i
].ShotType
= WEAPON_ROCKETLAUNCHER
) or
2800 (Shots
[i
].ShotType
= WEAPON_BARON_FIRE
) or
2801 (Shots
[i
].ShotType
= WEAPON_MANCUB_FIRE
) or
2802 (Shots
[i
].ShotType
= WEAPON_SKEL_FIRE
) then
2803 a
:= -GetAngle2(Obj
.Vel
.X
, Obj
.Vel
.Y
)
2807 p
.X
:= Obj
.Rect
.Width
div 2;
2808 p
.Y
:= Obj
.Rect
.Height
div 2;
2810 if Animation
<> nil then
2812 if (Shots
[i
].ShotType
= WEAPON_BARON_FIRE
) or
2813 (Shots
[i
].ShotType
= WEAPON_MANCUB_FIRE
) or
2814 (Shots
[i
].ShotType
= WEAPON_SKEL_FIRE
) then
2815 Animation
.DrawEx(Obj
.X
, Obj
.Y
, M_NONE
, p
, a
)
2817 Animation
.Draw(Obj
.X
, Obj
.Y
, M_NONE
);
2819 else if TextureID
<> 0 then
2821 if (Shots
[i
].ShotType
= WEAPON_ROCKETLAUNCHER
) then
2822 e_DrawAdv(TextureID
, Obj
.X
, Obj
.Y
, 0, True, False, a
, @p
, M_NONE
)
2823 else if (Shots
[i
].ShotType
<> WEAPON_FLAMETHROWER
) then
2824 e_Draw(TextureID
, Obj
.X
, Obj
.Y
, 0, True, False);
2827 if g_debug_Frames
then
2829 e_DrawQuad(Obj
.X
+Obj
.Rect
.X
,
2831 Obj
.X
+Obj
.Rect
.X
+Obj
.Rect
.Width
-1,
2832 Obj
.Y
+Obj
.Rect
.Y
+Obj
.Rect
.Height
-1,
2838 function g_Weapon_Danger(UID
: Word; X
, Y
: Integer; Width
, Height
: Word; Time
: Byte): Boolean;
2847 for a
:= 0 to High(Shots
) do
2848 if (Shots
[a
].ShotType
<> 0) and (Shots
[a
].SpawnerUID
<> UID
) then
2849 if ((Shots
[a
].Obj
.Vel
.Y
= 0) and (Shots
[a
].Obj
.Vel
.X
> 0) and (Shots
[a
].Obj
.X
< X
)) or
2850 (Shots
[a
].Obj
.Vel
.Y
= 0) and (Shots
[a
].Obj
.Vel
.X
< 0) and (Shots
[a
].Obj
.X
> X
) then
2851 if (Abs(X
-Shots
[a
].Obj
.X
) < Abs(Shots
[a
].Obj
.Vel
.X
*Time
)) and
2852 g_Collide(X
, Y
, Width
, Height
, X
, Shots
[a
].Obj
.Y
,
2853 Shots
[a
].Obj
.Rect
.Width
, Shots
[a
].Obj
.Rect
.Height
) and
2854 g_TraceVector(X
, Y
, Shots
[a
].Obj
.X
, Shots
[a
].Obj
.Y
) then
2861 procedure g_Weapon_SaveState(var Mem
: TBinMemoryWriter
);
2863 count
, i
, j
: Integer;
2866 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ ñíàðÿäîâ:
2868 if Shots
<> nil then
2869 for i
:= 0 to High(Shots
) do
2870 if Shots
[i
].ShotType
<> 0 then
2873 Mem
:= TBinMemoryWriter
.Create((count
+1) * 80);
2875 // Êîëè÷åñòâî ñíàðÿäîâ:
2876 Mem
.WriteInt(count
);
2881 for i
:= 0 to High(Shots
) do
2882 if Shots
[i
].ShotType
<> 0 then
2884 // Ñèãíàòóðà ñíàðÿäà:
2885 dw
:= SHOT_SIGNATURE
; // 'SHOT'
2888 Mem
.WriteByte(Shots
[i
].ShotType
);
2890 Mem
.WriteWord(Shots
[i
].Target
);
2892 Mem
.WriteWord(Shots
[i
].SpawnerUID
);
2893 // Ðàçìåð ïîëÿ Triggers:
2894 dw
:= Length(Shots
[i
].Triggers
);
2896 // Òðèããåðû, àêòèâèðîâàííûå âûñòðåëîì:
2897 for j
:= 0 to Integer(dw
)-1 do
2898 Mem
.WriteDWORD(Shots
[i
].Triggers
[j
]);
2900 Obj_SaveState(@Shots
[i
].Obj
, Mem
);
2901 // Êîñòûëèíà åáàíàÿ:
2902 Mem
.WriteByte(Shots
[i
].Stopped
);
2906 procedure g_Weapon_LoadState(var Mem
: TBinMemoryReader
);
2908 count
, i
, j
: Integer;
2914 // Êîëè÷åñòâî ñíàðÿäîâ:
2917 SetLength(Shots
, count
);
2922 for i
:= 0 to count
-1 do
2924 // Ñèãíàòóðà ñíàðÿäà:
2926 if dw
<> SHOT_SIGNATURE
then // 'SHOT'
2928 raise EBinSizeError
.Create('g_Weapons_LoadState: Wrong Shot Signature');
2931 Mem
.ReadByte(Shots
[i
].ShotType
);
2933 Mem
.ReadWord(Shots
[i
].Target
);
2935 Mem
.ReadWord(Shots
[i
].SpawnerUID
);
2936 // Ðàçìåð ïîëÿ Triggers:
2938 SetLength(Shots
[i
].Triggers
, dw
);
2939 // Òðèããåðû, àêòèâèðîâàííûå âûñòðåëîì:
2940 for j
:= 0 to Integer(dw
)-1 do
2941 Mem
.ReadDWORD(Shots
[i
].Triggers
[j
]);
2943 Obj_LoadState(@Shots
[i
].Obj
, Mem
);
2944 // Êîñòûëèíà åáàíàÿ:
2945 Mem
.ReadByte(Shots
[i
].Stopped
);
2947 // Óñòàíîâêà òåêñòóðû èëè àíèìàöèè:
2948 Shots
[i
].TextureID
:= DWORD(-1);
2949 Shots
[i
].Animation
:= nil;
2951 case Shots
[i
].ShotType
of
2952 WEAPON_ROCKETLAUNCHER
, WEAPON_SKEL_FIRE
:
2954 g_Texture_Get('TEXTURE_WEAPON_ROCKET', Shots
[i
].TextureID
);
2958 g_Frames_Get(dw
, 'FRAMES_WEAPON_PLASMA');
2959 Shots
[i
].Animation
:= TAnimation
.Create(dw
, True, 5);
2963 g_Frames_Get(dw
, 'FRAMES_WEAPON_BFG');
2964 Shots
[i
].Animation
:= TAnimation
.Create(dw
, True, 6);
2968 g_Frames_Get(dw
, 'FRAMES_WEAPON_IMPFIRE');
2969 Shots
[i
].Animation
:= TAnimation
.Create(dw
, True, 4);
2973 g_Frames_Get(dw
, 'FRAMES_WEAPON_BSPFIRE');
2974 Shots
[i
].Animation
:= TAnimation
.Create(dw
, True, 4);
2978 g_Frames_Get(dw
, 'FRAMES_WEAPON_CACOFIRE');
2979 Shots
[i
].Animation
:= TAnimation
.Create(dw
, True, 4);
2983 g_Frames_Get(dw
, 'FRAMES_WEAPON_BARONFIRE');
2984 Shots
[i
].Animation
:= TAnimation
.Create(dw
, True, 4);
2988 g_Frames_Get(dw
, 'FRAMES_WEAPON_MANCUBFIRE');
2989 Shots
[i
].Animation
:= TAnimation
.Create(dw
, True, 4);
2995 procedure g_Weapon_DestroyShot(I
: Integer; X
, Y
: Integer; Loud
: Boolean = True);
3003 if (I
> High(Shots
)) or (I
< 0) then Exit
;
3007 if ShotType
= 0 then Exit
;
3010 cx
:= Obj
.X
+ (Obj
.Rect
.Width
div 2);
3011 cy
:= Obj
.Y
+ (Obj
.Rect
.Height
div 2);
3014 WEAPON_ROCKETLAUNCHER
, WEAPON_SKEL_FIRE
: // Ðàêåòû è ñíàðÿäû Ñêåëåòà
3018 if ShotType
= WEAPON_SKEL_FIRE
then
3019 begin // Âçðûâ ñíàðÿäà Ñêåëåòà
3020 if g_Frames_Get(TextureID
, 'FRAMES_EXPLODE_SKELFIRE') then
3022 Anim
:= TAnimation
.Create(TextureID
, False, 8);
3023 Anim
.Blending
:= False;
3024 g_GFX_OnceAnim((Obj
.X
+32)-32, (Obj
.Y
+8)-32, Anim
);
3029 begin // Âçðûâ Ðàêåòû
3030 if g_Frames_Get(TextureID
, 'FRAMES_EXPLODE_ROCKET') then
3032 Anim
:= TAnimation
.Create(TextureID
, False, 6);
3033 Anim
.Blending
:= False;
3034 g_GFX_OnceAnim(cx
-64, cy
-64, Anim
);
3038 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', Obj
.X
, Obj
.Y
);
3042 WEAPON_PLASMA
, WEAPON_BSP_FIRE
: // Ïëàçìà, ïëàçìà Àðàõíàòðîíà
3044 if ShotType
= WEAPON_PLASMA
then
3045 s
:= 'FRAMES_EXPLODE_PLASMA'
3047 s
:= 'FRAMES_EXPLODE_BSPFIRE';
3049 if g_Frames_Get(TextureID
, s
) and loud
then
3051 Anim
:= TAnimation
.Create(TextureID
, False, 3);
3052 Anim
.Blending
:= False;
3053 g_GFX_OnceAnim(cx
-16, cy
-16, Anim
);
3056 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEPLASMA', Obj
.X
, Obj
.Y
);
3063 if g_Frames_Get(TextureID
, 'FRAMES_EXPLODE_BFG') and Loud
then
3065 Anim
:= TAnimation
.Create(TextureID
, False, 6);
3066 Anim
.Blending
:= False;
3067 g_GFX_OnceAnim(cx
-64, cy
-64, Anim
);
3070 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', Obj
.X
, Obj
.Y
);
3074 WEAPON_IMP_FIRE
, WEAPON_CACO_FIRE
, WEAPON_BARON_FIRE
: // Âûñòðåëû Áåñà, Êàêîäåìîíà Ðûöàðÿ/Áàðîíà àäà
3076 if ShotType
= WEAPON_IMP_FIRE
then
3077 s
:= 'FRAMES_EXPLODE_IMPFIRE'
3079 if ShotType
= WEAPON_CACO_FIRE
then
3080 s
:= 'FRAMES_EXPLODE_CACOFIRE'
3082 s
:= 'FRAMES_EXPLODE_BARONFIRE';
3084 if g_Frames_Get(TextureID
, s
) and Loud
then
3086 Anim
:= TAnimation
.Create(TextureID
, False, 6);
3087 Anim
.Blending
:= False;
3088 g_GFX_OnceAnim(cx
-32, cy
-32, Anim
);
3091 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj
.X
, Obj
.Y
);
3095 WEAPON_MANCUB_FIRE
: // Âûñòðåë Ìàíêóáóñà
3097 if g_Frames_Get(TextureID
, 'FRAMES_EXPLODE_ROCKET') and Loud
then
3099 Anim
:= TAnimation
.Create(TextureID
, False, 6);
3100 Anim
.Blending
:= False;
3101 g_GFX_OnceAnim(cx
-64, cy
-64, Anim
);
3104 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj
.X
, Obj
.Y
);
3107 end; // case ShotType of...
3115 procedure g_Weapon_AddDynLights();
3119 if Shots
= nil then Exit
;
3120 for i
:= 0 to High(Shots
) do
3122 if Shots
[i
].ShotType
= 0 then continue
;
3123 if (Shots
[i
].ShotType
= WEAPON_ROCKETLAUNCHER
) or
3124 (Shots
[i
].ShotType
= WEAPON_BARON_FIRE
) or
3125 (Shots
[i
].ShotType
= WEAPON_MANCUB_FIRE
) or
3126 (Shots
[i
].ShotType
= WEAPON_SKEL_FIRE
) or
3127 (Shots
[i
].ShotType
= WEAPON_IMP_FIRE
) or
3128 (Shots
[i
].ShotType
= WEAPON_CACO_FIRE
) or
3129 (Shots
[i
].ShotType
= WEAPON_MANCUB_FIRE
) or
3130 (Shots
[i
].ShotType
= WEAPON_BSP_FIRE
) or
3131 (Shots
[i
].ShotType
= WEAPON_PLASMA
) or
3132 (Shots
[i
].ShotType
= WEAPON_BFG
) or
3133 (Shots
[i
].ShotType
= WEAPON_FLAMETHROWER
) or
3136 if (Shots
[i
].ShotType
= WEAPON_PLASMA
) then
3137 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)
3138 else if (Shots
[i
].ShotType
= WEAPON_BFG
) then
3139 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)
3140 else if (Shots
[i
].ShotType
= WEAPON_FLAMETHROWER
) then
3141 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)
3143 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);
3149 procedure TShot
.positionChanged (); begin end;