1 (* Copyright (C) Doom 2D: Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, version 3 of the License ONLY.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 {$INCLUDE ../shared/a_modes.inc}
16 {.$DEFINE GWEP_HITSCAN_TRACE_BITMAP_CHECKER}
22 SysUtils
, Classes
, mempool
,
23 g_textures
, g_basic
, g_phys
, xprofiler
;
33 Animation
: TAnimationState
;
37 procedure positionChanged (); //WARNING! call this after monster position was changed, or coldet will not work right!
42 Shots
: array of TShot
= nil;
43 LastShotID
: Integer = 0;
45 procedure g_Weapon_LoadData();
46 procedure g_Weapon_FreeData();
47 procedure g_Weapon_Init();
48 procedure g_Weapon_Free();
49 function g_Weapon_Hit(obj
: PObj
; d
: Integer; SpawnerUID
: Word; t
: Byte; HitCorpses
: Boolean = True): Byte;
50 function g_Weapon_HitUID(UID
: Word; d
: Integer; SpawnerUID
: Word; t
: Byte): Boolean;
51 function g_Weapon_CreateShot(I
: Integer; ShotType
: Byte; Spawner
, TargetUID
: Word; X
, Y
, XV
, YV
: Integer): LongWord;
53 procedure g_Weapon_gun(const x
, y
, xd
, yd
, v
, indmg
: Integer; SpawnerUID
: Word; CheckTrigger
: Boolean);
54 procedure g_Weapon_punch(x
, y
: Integer; d
, SpawnerUID
: Word);
55 function g_Weapon_chainsaw(x
, y
: Integer; d
, SpawnerUID
: Word): Integer;
56 procedure g_Weapon_rocket(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1; Silent
: Boolean = False; compat
: Boolean = true);
57 procedure g_Weapon_revf(x
, y
, xd
, yd
: Integer; SpawnerUID
, TargetUID
: Word; WID
: Integer = -1; Silent
: Boolean = False);
58 procedure g_Weapon_flame(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1; Silent
: Boolean = False; compat
: Boolean = true);
59 procedure g_Weapon_plasma(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1; Silent
: Boolean = False; compat
: Boolean = true);
60 procedure g_Weapon_ball1(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1; Silent
: Boolean = False; compat
: Boolean = true);
61 procedure g_Weapon_ball2(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1; Silent
: Boolean = False; compat
: Boolean = true);
62 procedure g_Weapon_ball7(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1; Silent
: Boolean = False; compat
: Boolean = true);
63 procedure g_Weapon_aplasma(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1; Silent
: Boolean = False; compat
: Boolean = true);
64 procedure g_Weapon_manfire(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1; Silent
: Boolean = False; compat
: Boolean = true);
65 procedure g_Weapon_bfgshot(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1; Silent
: Boolean = False; compat
: Boolean = true);
66 procedure g_Weapon_bfghit(x
, y
: Integer);
67 procedure g_Weapon_pistol(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; Silent
: Boolean = False);
68 procedure g_Weapon_mgun(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; Silent
: Boolean = False);
69 procedure g_Weapon_shotgun(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; Silent
: Boolean = False);
70 procedure g_Weapon_dshotgun(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; Silent
: Boolean = False);
72 function g_Weapon_Explode(X
, Y
: Integer; rad
: Integer; SpawnerUID
: Word): Boolean;
73 procedure g_Weapon_BFG9000(X
, Y
: Integer; SpawnerUID
: Word);
74 procedure g_Weapon_PreUpdate();
75 procedure g_Weapon_Update();
76 function g_Weapon_Danger(UID
: Word; X
, Y
: Integer; Width
, Height
: Word; Time
: Byte): Boolean;
77 procedure g_Weapon_DestroyShot(I
: Integer; X
, Y
: Integer; Loud
: Boolean = True);
79 procedure g_Weapon_SaveState (st
: TStream
);
80 procedure g_Weapon_LoadState (st
: TStream
);
82 procedure g_Weapon_AddDynLights();
91 WEAPON_ROCKETLAUNCHER
= 6;
94 WEAPON_SUPERPULEMET
= 9;
95 WEAPON_FLAMETHROWER
= 10;
96 WEAPON_ZOMBY_PISTOL
= 20;
99 WEAPON_CACO_FIRE
= 23;
100 WEAPON_BARON_FIRE
= 24;
101 WEAPON_MANCUB_FIRE
= 25;
102 WEAPON_SKEL_FIRE
= 26;
104 WP_FIRST
= WEAPON_KASTET
;
105 WP_LAST
= WEAPON_FLAMETHROWER
;
108 gwep_debug_fast_trace
: Boolean = true;
120 Math
, g_map
, g_player
, g_sound
, g_panel
,
121 g_console
, g_options
, g_game
,
122 g_triggers
, MAPDEF
, e_log
, g_monsters
, g_saveload
,
123 g_language
, g_netmsg
, g_grid
,
124 geom
, binheap
, hashtable
, utils
, xstreams
135 SHOT_ROCKETLAUNCHER_WIDTH
= 14;
136 SHOT_ROCKETLAUNCHER_HEIGHT
= 14;
138 SHOT_SKELFIRE_WIDTH
= 14;
139 SHOT_SKELFIRE_HEIGHT
= 14;
141 SHOT_PLASMA_WIDTH
= 16;
142 SHOT_PLASMA_HEIGHT
= 16;
145 SHOT_BFG_HEIGHT
= 32;
146 SHOT_BFG_DAMAGE
= 100;
147 SHOT_BFG_RADIUS
= 256;
149 SHOT_FLAME_WIDTH
= 4;
150 SHOT_FLAME_HEIGHT
= 4;
151 SHOT_FLAME_LIFETIME
= 180;
153 SHOT_SIGNATURE
= $544F4853; // 'SHOT'
156 PHitTime
= ^THitTime
;
160 plridx
: Integer; // if mon=nil
164 TBinHeapKeyHitTime
= class
166 class function less (const a
, b
: Integer): Boolean; inline;
169 // indicies in `wgunHitTime` array
170 TBinaryHeapHitTimes
= specialize TBinaryHeapBase
<Integer, TBinHeapKeyHitTime
>;
173 WaterMap
: array of array of DWORD
= nil;
174 //wgunMonHash: THashIntInt = nil;
175 wgunHitHeap
: TBinaryHeapHitTimes
= nil;
176 wgunHitTime
: array of THitTime
= nil;
177 wgunHitTimeUsed
: Integer = 0;
180 class function TBinHeapKeyHitTime
.less (const a
, b
: Integer): Boolean;
184 hta
:= @wgunHitTime
[a
];
185 htb
:= @wgunHitTime
[b
];
186 if (hta
.distSq
<> htb
.distSq
) then begin result
:= (hta
.distSq
< htb
.distSq
); exit
; end;
187 if (hta
.mon
<> nil) then
190 if (htb
.mon
= nil) then begin result
:= false; exit
; end; // players first
191 result
:= (hta
.mon
.UID
< htb
.mon
.UID
); // why not?
196 if (htb
.mon
<> nil) then begin result
:= true; exit
; end; // players first
197 result
:= (hta
.plridx
< htb
.plridx
); // why not?
202 procedure appendHitTimeMon (adistSq
: Integer; amon
: TMonster
; ax
, ay
: Integer);
204 if (wgunHitTimeUsed
= Length(wgunHitTime
)) then SetLength(wgunHitTime
, wgunHitTimeUsed
+128);
205 with wgunHitTime
[wgunHitTimeUsed
] do
213 wgunHitHeap
.insert(wgunHitTimeUsed
);
214 Inc(wgunHitTimeUsed
);
218 procedure appendHitTimePlr (adistSq
: Integer; aplridx
: Integer; ax
, ay
: Integer);
220 if (wgunHitTimeUsed
= Length(wgunHitTime
)) then SetLength(wgunHitTime
, wgunHitTimeUsed
+128);
221 with wgunHitTime
[wgunHitTimeUsed
] do
229 wgunHitHeap
.insert(wgunHitTimeUsed
);
230 Inc(wgunHitTimeUsed
);
234 function FindShot(): DWORD
;
239 for i
:= 0 to High(Shots
) do
240 if Shots
[i
].ShotType
= 0 then
243 LastShotID
:= Result
;
249 SetLength(Shots
, 128);
254 Result
:= High(Shots
) + 1;
255 SetLength(Shots
, Length(Shots
) + 128);
257 LastShotID
:= Result
;
260 procedure CreateWaterMap();
262 WaterArray
: Array of TWaterPanel
;
269 SetLength(WaterArray
, Length(gWater
));
271 for a
:= 0 to High(gWater
) do
273 WaterArray
[a
].X
:= gWater
[a
].X
;
274 WaterArray
[a
].Y
:= gWater
[a
].Y
;
275 WaterArray
[a
].Width
:= gWater
[a
].Width
;
276 WaterArray
[a
].Height
:= gWater
[a
].Height
;
277 WaterArray
[a
].Active
:= True;
280 g_Game_SetLoadingText(_lc
[I_LOAD_WATER_MAP
], High(WaterArray
), False);
282 for a
:= 0 to High(WaterArray
) do
283 if WaterArray
[a
].Active
then
285 WaterArray
[a
].Active
:= False;
286 m
:= Length(WaterMap
);
287 SetLength(WaterMap
, m
+1);
288 SetLength(WaterMap
[m
], 1);
295 for b
:= 0 to High(WaterArray
) do
296 if WaterArray
[b
].Active
then
297 for c
:= 0 to High(WaterMap
[m
]) do
298 if g_CollideAround(WaterArray
[b
].X
,
301 WaterArray
[b
].Height
,
302 WaterArray
[WaterMap
[m
][c
]].X
,
303 WaterArray
[WaterMap
[m
][c
]].Y
,
304 WaterArray
[WaterMap
[m
][c
]].Width
,
305 WaterArray
[WaterMap
[m
][c
]].Height
) then
307 WaterArray
[b
].Active
:= False;
308 SetLength(WaterMap
[m
],
309 Length(WaterMap
[m
])+1);
310 WaterMap
[m
][High(WaterMap
[m
])] := b
;
316 g_Game_StepLoading();
324 chkTrap_pl
: array [0..256] of Integer;
325 chkTrap_mn
: array [0..65535] of TMonster
;
327 procedure CheckTrap(ID
: DWORD
; dm
: Integer; t
: Byte);
329 //a, b, c, d, i1, i2: Integer;
330 //chkTrap_pl, chkTrap_mn: WArray;
331 plaCount
: Integer = 0;
332 mnaCount
: Integer = 0;
336 function monsWaterCheck (mon: TMonster): Boolean;
338 result := false; // don't stop
339 if mon.alive and mon.Collide(gWater[WaterMap[a][c]]) and (not InWArray(monidx, chkTrap_mn)) and (i2 < 1023) then //FIXME
342 chkTrap_mn[i2] := monidx;
347 function monsWaterCheck (mon
: TMonster
): Boolean;
349 result
:= false; // don't stop
350 if (mon
.trapCheckFrameId
<> frameId
) then
352 mon
.trapCheckFrameId
:= frameId
;
353 chkTrap_mn
[mnaCount
] := mon
;
359 a
, b
, c
, d
, f
: Integer;
362 if (gWater
= nil) or (WaterMap
= nil) then Exit
;
364 frameId
:= g_Mons_getNewTrapFrameId();
369 //SetLength(chkTrap_pl, 1024);
370 //SetLength(chkTrap_mn, 1024);
371 //for d := 0 to 1023 do chkTrap_pl[d] := $FFFF;
372 //for d := 0 to 1023 do chkTrap_mn[d] := $FFFF;
374 for a
:= 0 to High(WaterMap
) do
376 for b
:= 0 to High(WaterMap
[a
]) do
378 pan
:= gWater
[WaterMap
[a
][b
]];
379 if not g_Obj_Collide(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, @Shots
[ID
].Obj
) then continue
;
381 for c
:= 0 to High(WaterMap
[a
]) do
383 pan
:= gWater
[WaterMap
[a
][c
]];
384 for d
:= 0 to High(gPlayers
) do
386 if (gPlayers
[d
] <> nil) and (gPlayers
[d
].alive
) then
388 if gPlayers
[d
].Collide(pan
) then
391 while (f
< plaCount
) and (chkTrap_pl
[f
] <> d
) do Inc(f
);
392 if (f
= plaCount
) then
394 chkTrap_pl
[plaCount
] := d
;
396 if (plaCount
= Length(chkTrap_pl
)) then break
;
402 //g_Mons_ForEach(monsWaterCheck);
403 g_Mons_ForEachAliveAt(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, monsWaterCheck
);
406 for f
:= 0 to plaCount
-1 do gPlayers
[chkTrap_pl
[f
]].Damage(dm
, Shots
[ID
].SpawnerUID
, 0, 0, t
);
407 for f
:= 0 to mnaCount
-1 do chkTrap_mn
[f
].Damage(dm
, 0, 0, Shots
[ID
].SpawnerUID
, t
);
415 function HitMonster(m
: TMonster
; d
: Integer; vx
, vy
: Integer; SpawnerUID
: Word; t
: Byte): Boolean;
422 tt
:= g_GetUIDType(SpawnerUID
);
423 if tt
= UID_MONSTER
then
425 mon
:= g_Monsters_ByUID(SpawnerUID
);
427 mt
:= g_Monsters_ByUID(SpawnerUID
).MonsterType
434 if m
= nil then Exit
;
435 if m
.UID
= SpawnerUID
then
437 // Ñàì ñåáÿ ìîæåò ðàíèòü òîëüêî ðàêåòîé è òîêîì:
438 if (t
<> HIT_ROCKET
) and (t
<> HIT_ELECTRO
) then
440 // Êèáåð äåìîí è áî÷êà âîîáùå íå ìîãóò ñåáÿ ðàíèòü:
441 if (m
.MonsterType
= MONSTER_CYBER
) or
442 (m
.MonsterType
= MONSTER_BARREL
) then
449 if tt
= UID_MONSTER
then
451 // Lost_Soul íå ìîæåò ðàíèòü Pain_Elemental'à:
452 if (mt
= MONSTER_SOUL
) and (m
.MonsterType
= MONSTER_PAIN
) then
455 // Îáà ìîíñòðà îäíîãî âèäà:
456 if mt
= m
.MonsterType
then
458 MONSTER_IMP
, MONSTER_DEMON
, MONSTER_BARON
, MONSTER_KNIGHT
, MONSTER_CACO
,
459 MONSTER_SOUL
, MONSTER_MANCUB
, MONSTER_SKEL
, MONSTER_FISH
:
460 Exit
; // Ýòè íå áüþò ñâîèõ
464 if g_Game_IsServer
then
466 if (t
<> HIT_FLAME
) or (m
.FFireTime
= 0) or (vx
<> 0) or (vy
<> 0) then
467 Result
:= m
.Damage(d
, vx
, vy
, SpawnerUID
, t
)
469 Result
:= (gLMSRespawn
= LMS_RESPAWN_NONE
); // don't hit monsters when it's warmup time
470 if t
= HIT_FLAME
then
471 m
.CatchFire(SpawnerUID
);
474 Result
:= (gLMSRespawn
= LMS_RESPAWN_NONE
); // don't hit monsters when it's warmup time
478 function HitPlayer (p
: TPlayer
; d
: Integer; vx
, vy
: Integer; SpawnerUID
: Word; t
: Byte): Boolean;
482 // Ñàì ñåáÿ ìîæåò ðàíèòü òîëüêî ðàêåòîé è òîêîì
483 if (p
.UID
= SpawnerUID
) and (t
<> HIT_ROCKET
) and (t
<> HIT_ELECTRO
) then exit
;
485 if g_Game_IsServer
then
487 if (t
<> HIT_FLAME
) or (p
.FFireTime
= 0) or (vx
<> 0) or (vy
<> 0) then p
.Damage(d
, SpawnerUID
, vx
, vy
, t
);
488 if (t
= HIT_FLAME
) then p
.CatchFire(SpawnerUID
);
495 procedure g_Weapon_BFG9000(X
, Y
: Integer; SpawnerUID
: Word);
497 function monsCheck (mon
: TMonster
): Boolean;
499 result
:= false; // don't stop
500 if (mon
.alive
) and (mon
.UID
<> SpawnerUID
) then
504 if (g_PatchLength(X
, Y
, Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2),
505 Obj
.Y
+Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2)) <= SHOT_BFG_RADIUS
) and
506 g_TraceVector(X
, Y
, Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2),
507 Obj
.Y
+Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2)) then
509 if HitMonster(mon
, 50, 0, 0, SpawnerUID
, HIT_SOME
) then mon
.BFGHit();
521 //g_Sound_PlayEx('SOUND_WEAPON_EXPLODEBFG', 255);
525 if gAdvCorpses
and (h
<> -1) then
527 if (gCorpses
[i
] <> nil) and (gCorpses
[i
].State
<> CORPSE_STATE_REMOVEME
) then
529 if (g_PatchLength(X
, Y
, Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2),
530 Obj
.Y
+Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2)) <= SHOT_BFG_RADIUS
) and
531 g_TraceVector(X
, Y
, Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2),
532 Obj
.Y
+Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2)) then
534 Damage(50, SpawnerUID
, 0, 0);
535 g_Weapon_BFGHit(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2),
536 Obj
.Y
+Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2));
540 pl
:= g_Player_Get(SpawnerUID
);
548 if (gPlayers
[i
] <> nil) and (gPlayers
[i
].alive
) and (gPlayers
[i
].UID
<> SpawnerUID
) then
550 if (g_PatchLength(X
, Y
, GameX
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
551 GameY
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)) <= SHOT_BFG_RADIUS
) and
552 g_TraceVector(X
, Y
, GameX
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
553 GameY
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)) then
555 if (st
= TEAM_NONE
) or (st
<> gPlayers
[i
].Team
) then
556 b
:= HitPlayer(gPlayers
[i
], 50, 0, 0, SpawnerUID
, HIT_SOME
)
558 b
:= HitPlayer(gPlayers
[i
], 25, 0, 0, SpawnerUID
, HIT_SOME
);
560 gPlayers
[i
].BFGHit();
564 g_Mons_ForEachAlive(monsCheck
);
567 function g_Weapon_CreateShot(I
: Integer; ShotType
: Byte; Spawner
, TargetUID
: Word; X
, Y
, XV
, YV
: Integer): LongWord;
572 find_id
:= FindShot()
576 if Integer(find_id
) >= High(Shots
) then
577 SetLength(Shots
, find_id
+ 64)
581 WEAPON_ROCKETLAUNCHER
:
583 with Shots
[find_id
] do
587 Obj
.Rect
.Width
:= SHOT_ROCKETLAUNCHER_WIDTH
;
588 Obj
.Rect
.Height
:= SHOT_ROCKETLAUNCHER_HEIGHT
;
592 ShotType
:= WEAPON_ROCKETLAUNCHER
;
598 with Shots
[find_id
] do
602 Obj
.Rect
.Width
:= SHOT_PLASMA_WIDTH
;
603 Obj
.Rect
.Height
:= SHOT_PLASMA_HEIGHT
;
606 ShotType
:= WEAPON_PLASMA
;
607 Animation
:= TAnimationState
.Create(True, 5, 2); // !!! put values into table
613 with Shots
[find_id
] do
617 Obj
.Rect
.Width
:= SHOT_BFG_WIDTH
;
618 Obj
.Rect
.Height
:= SHOT_BFG_HEIGHT
;
621 ShotType
:= WEAPON_BFG
;
622 Animation
:= TAnimationState
.Create(True, 6, 2); // !!! put values into table
628 with Shots
[find_id
] do
632 Obj
.Rect
.Width
:= SHOT_FLAME_WIDTH
;
633 Obj
.Rect
.Height
:= SHOT_FLAME_HEIGHT
;
636 ShotType
:= WEAPON_FLAMETHROWER
;
637 // Animation := TAnimationState.Create(True, 6, 0); // drawed as gfx
643 with Shots
[find_id
] do
647 Obj
.Rect
.Width
:= 16;
648 Obj
.Rect
.Height
:= 16;
651 ShotType
:= WEAPON_IMP_FIRE
;
652 Animation
:= TAnimationState
.Create(True, 4, 2); // !!! put values into table
658 with Shots
[find_id
] do
662 Obj
.Rect
.Width
:= 16;
663 Obj
.Rect
.Height
:= 16;
666 ShotType
:= WEAPON_CACO_FIRE
;
667 Animation
:= TAnimationState
.Create(True, 4, 2); // !!! put values into table
673 with Shots
[find_id
] do
677 Obj
.Rect
.Width
:= 32;
678 Obj
.Rect
.Height
:= 32;
681 ShotType
:= WEAPON_MANCUB_FIRE
;
682 Animation
:= TAnimationState
.Create(True, 4, 2); // !!! put values into table
688 with Shots
[find_id
] do
692 Obj
.Rect
.Width
:= 16;
693 Obj
.Rect
.Height
:= 16;
696 ShotType
:= WEAPON_BARON_FIRE
;
697 Animation
:= TAnimationState
.Create(True, 4, 2); // !!! put values into table
703 with Shots
[find_id
] do
707 Obj
.Rect
.Width
:= 16;
708 Obj
.Rect
.Height
:= 16;
711 ShotType
:= WEAPON_BSP_FIRE
;
712 Animation
:= TAnimationState
.Create(True, 4, 2); // !!! put values into table
718 with Shots
[find_id
] do
722 Obj
.Rect
.Width
:= SHOT_SKELFIRE_WIDTH
;
723 Obj
.Rect
.Height
:= SHOT_SKELFIRE_HEIGHT
;
726 ShotType
:= WEAPON_SKEL_FIRE
;
728 Animation
:= TAnimationState
.Create(True, 5, 2); // !!! put values into table
733 Shots
[find_id
].Obj
.oldX
:= X
;
734 Shots
[find_id
].Obj
.oldY
:= Y
;
735 Shots
[find_id
].Obj
.X
:= X
;
736 Shots
[find_id
].Obj
.Y
:= Y
;
737 Shots
[find_id
].Obj
.Vel
.X
:= XV
;
738 Shots
[find_id
].Obj
.Vel
.Y
:= YV
;
739 Shots
[find_id
].Obj
.Accel
.X
:= 0;
740 Shots
[find_id
].Obj
.Accel
.Y
:= 0;
741 Shots
[find_id
].SpawnerUID
:= Spawner
;
742 if (ShotType
= WEAPON_FLAMETHROWER
) and (XV
= 0) and (YV
= 0) then
743 Shots
[find_id
].Stopped
:= 255
745 Shots
[find_id
].Stopped
:= 0;
749 procedure throw(i
, x
, y
, xd
, yd
, s
: Integer);
756 a
:= Max(Abs(xd
), Abs(yd
));
760 Shots
[i
].Obj
.oldX
:= x
;
761 Shots
[i
].Obj
.oldY
:= y
;
764 Shots
[i
].Obj
.Vel
.X
:= (xd
*s
) div a
;
765 Shots
[i
].Obj
.Vel
.Y
:= (yd
*s
) div a
;
766 Shots
[i
].Obj
.Accel
.X
:= 0;
767 Shots
[i
].Obj
.Accel
.Y
:= 0;
768 Shots
[i
].Stopped
:= 0;
769 if Shots
[i
].ShotType
in [WEAPON_ROCKETLAUNCHER
, WEAPON_BFG
] then
770 Shots
[i
].Timeout
:= 900 // ~25 sec
773 if Shots
[i
].ShotType
= WEAPON_FLAMETHROWER
then
774 Shots
[i
].Timeout
:= SHOT_FLAME_LIFETIME
776 Shots
[i
].Timeout
:= 550; // ~15 sec
780 function g_Weapon_Hit(obj
: PObj
; d
: Integer; SpawnerUID
: Word; t
: Byte; HitCorpses
: Boolean = True): Byte;
784 function PlayerHit(Team
: Byte = 0): Boolean;
795 if (gPlayers
[i
] <> nil) and gPlayers
[i
].alive
and g_Obj_Collide(obj
, @gPlayers
[i
].Obj
) then
798 if (Team
> 0) and (g_GetUIDType(SpawnerUID
) = UID_PLAYER
) then
800 p
:= g_Player_Get(SpawnerUID
);
802 ChkTeam
:= (p
.Team
= gPlayers
[i
].Team
) xor (Team
= 2);
805 if HitPlayer(gPlayers
[i
], d
, obj
^.Vel
.X
, obj
^.Vel
.Y
, SpawnerUID
, t
) then
807 if t
<> HIT_FLAME
then
808 gPlayers
[i
].Push((obj
^.Vel
.X
+obj
^.Accel
.X
)*IfThen(t
= HIT_BFG
, 8, 1) div 4,
809 (obj
^.Vel
.Y
+obj
^.Accel
.Y
)*IfThen(t
= HIT_BFG
, 8, 1) div 4);
811 g_Game_DelayEvent(DE_BFGHIT
, 1000, SpawnerUID
);
819 function monsCheckHit (monidx: Integer; mon: TMonster): Boolean;
821 result := false; // don't stop
822 if mon.alive and g_Obj_Collide(obj, @mon.Obj) then
824 if HitMonster(mon, d, obj^.Vel.X, obj^.Vel.Y, SpawnerUID, t) then
826 if (t <> HIT_FLAME) then
828 mon.Push((obj^.Vel.X+obj^.Accel.X)*IfThen(t = HIT_BFG, 8, 1) div 4,
829 (obj^.Vel.Y+obj^.Accel.Y)*IfThen(t = HIT_BFG, 8, 1) div 4);
837 function monsCheckHit (mon
: TMonster
): Boolean;
839 result
:= false; // don't stop
840 if HitMonster(mon
, d
, obj
.Vel
.X
, obj
.Vel
.Y
, SpawnerUID
, t
) then
842 if (t
<> HIT_FLAME
) then
844 mon
.Push((obj
.Vel
.X
+obj
.Accel
.X
)*IfThen(t
= HIT_BFG
, 8, 1) div 4,
845 (obj
.Vel
.Y
+obj
.Accel
.Y
)*IfThen(t
= HIT_BFG
, 8, 1) div 4);
851 function MonsterHit(): Boolean;
853 //result := g_Mons_ForEach(monsCheckHit);
854 //FIXME: accelerate this!
855 result
:= g_Mons_ForEachAliveAt(obj
.X
+obj
.Rect
.X
, obj
.Y
+obj
.Rect
.Y
, obj
.Rect
.Width
, obj
.Rect
.Height
, monsCheckHit
);
865 if gAdvCorpses
and (h
<> -1) then
867 if (gCorpses
[i
] <> nil) and (gCorpses
[i
].State
<> CORPSE_STATE_REMOVEME
) and
868 g_Obj_Collide(obj
, @gCorpses
[i
].Obj
) then
871 gCorpses
[i
].Damage(d
, SpawnerUID
, (obj
^.Vel
.X
+obj
^.Accel
.X
) div 4,
872 (obj
^.Vel
.Y
+obj
^.Accel
.Y
) div 4);
877 case gGameSettings
.GameMode
of
881 // Ñíà÷àëà áü¸ì ìîíñòðîâ, åñëè åñòü, ïîòîì ïûòàåìñÿ áèòü èãðîêîâ
888 // È â êîíöå èãðîêîâ, íî òîëüêî åñëè ïîëîæåíî
889 // (èëè ñíàðÿä îò ìîíñòðà, èëè friendlyfire, èëè friendly_hit_projectile)
890 if (g_GetUIDType(SpawnerUID
) <> UID_PLAYER
) or
891 LongBool(gGameSettings
.Options
and (GAME_OPTION_TEAMDAMAGE
or GAME_OPTION_TEAMHITPROJECTILE
)) then
904 // Ñíà÷àëà áü¸ì èãðîêîâ, åñëè åñòü, ïîòîì ïûòàåìñÿ áèòü ìîíñòðîâ
921 // Ñíà÷àëà áü¸ì èãðîêîâ êîìàíäû ñîïåðíèêà
935 // È â êîíöå ñâîèõ èãðîêîâ, íî òîëüêî åñëè ïîëîæåíî
936 // (èëè friendlyfire, èëè friendly_hit_projectile)
937 if LongBool(gGameSettings
.Options
and (GAME_OPTION_TEAMDAMAGE
or GAME_OPTION_TEAMHITPROJECTILE
)) then
950 function g_Weapon_HitUID(UID
: Word; d
: Integer; SpawnerUID
: Word; t
: Byte): Boolean;
954 case g_GetUIDType(UID
) of
955 UID_PLAYER
: Result
:= HitPlayer(g_Player_Get(UID
), d
, 0, 0, SpawnerUID
, t
);
956 UID_MONSTER
: Result
:= HitMonster(g_Monsters_ByUID(UID
), d
, 0, 0, SpawnerUID
, t
);
961 function g_Weapon_Explode(X
, Y
: Integer; rad
: Integer; SpawnerUID
: Word): Boolean;
963 r
: Integer; // squared radius
965 function monsExCheck (mon
: TMonster
): Boolean;
969 result
:= false; // don't stop
971 dx
:= mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-X
;
972 dy
:= mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2)-Y
;
974 if dx
> 1000 then dx
:= 1000;
975 if dy
> 1000 then dy
:= 1000;
977 if (dx
*dx
+dy
*dy
< r
) then
979 //m := PointToRect(X, Y, Obj.X+Obj.Rect.X, Obj.Y+Obj.Rect.Y, Obj.Rect.Width, Obj.Rect.Height);
980 //e_WriteLog(Format('explo monster #%d: x=%d; y=%d; rad=%d; dx=%d; dy=%d', [monidx, X, Y, rad, dx, dy]), MSG_NOTIFY);
982 mm
:= Max(abs(dx
), abs(dy
));
983 if mm
= 0 then mm
:= 1;
987 HitMonster(mon
, ((mon
.Obj
.Rect
.Width
div 4)*10*(rad
-mm
)) div rad
, 0, 0, SpawnerUID
, HIT_ROCKET
);
990 mon
.Push((dx
*7) div mm
, (dy
*7) div mm
);
995 var i
, h
, dx
, dy
, m
, mm
: Integer;
997 var _angle
: SmallInt;
1002 g_Triggers_PressC(X
, Y
, rad
, SpawnerUID
, ACTIVATE_SHOT
);
1006 h
:= High(gPlayers
);
1010 if (gPlayers
[i
] <> nil) and gPlayers
[i
].alive
then
1013 dx
:= Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)-X
;
1014 dy
:= Obj
.Y
+Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2)-Y
;
1016 if dx
> 1000 then dx
:= 1000;
1017 if dy
> 1000 then dy
:= 1000;
1019 if dx
*dx
+dy
*dy
< r
then
1021 //m := PointToRect(X, Y, GameX+PLAYER_RECT.X, GameY+PLAYER_RECT.Y,
1022 // PLAYER_RECT.Width, PLAYER_RECT.Height);
1024 mm
:= Max(abs(dx
), abs(dy
));
1025 if mm
= 0 then mm
:= 1;
1027 HitPlayer(gPlayers
[i
], (100*(rad
-mm
)) div rad
, (dx
*10) div mm
, (dy
*10) div mm
, SpawnerUID
, HIT_ROCKET
);
1028 gPlayers
[i
].Push((dx
*7) div mm
, (dy
*7) div mm
);
1032 //g_Mons_ForEach(monsExCheck);
1033 g_Mons_ForEachAt(X
-(rad
+32), Y
-(rad
+32), (rad
+32)*2, (rad
+32)*2, monsExCheck
);
1035 h
:= High(gCorpses
);
1037 if gAdvCorpses
and (h
<> -1) then
1039 if (gCorpses
[i
] <> nil) and (gCorpses
[i
].State
<> CORPSE_STATE_REMOVEME
) then
1042 dx
:= Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)-X
;
1043 dy
:= Obj
.Y
+Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2)-Y
;
1045 if dx
> 1000 then dx
:= 1000;
1046 if dy
> 1000 then dy
:= 1000;
1048 if dx
*dx
+dy
*dy
< r
then
1050 m
:= PointToRect(X
, Y
, Obj
.X
+Obj
.Rect
.X
, Obj
.Y
+Obj
.Rect
.Y
,
1051 Obj
.Rect
.Width
, Obj
.Rect
.Height
);
1053 mm
:= Max(abs(dx
), abs(dy
));
1054 if mm
= 0 then mm
:= 1;
1056 Damage(Round(100*(rad
-m
)/rad
), SpawnerUID
, (dx
*10) div mm
, (dy
*10) div mm
);
1060 {$IFDEF ENABLE_GIBS}
1062 if gAdvGibs
and (h
<> -1) then
1064 if gGibs
[i
].alive
then
1067 dx
:= Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)-X
;
1068 dy
:= Obj
.Y
+Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2)-Y
;
1069 if dx
> 1000 then dx
:= 1000;
1070 if dy
> 1000 then dy
:= 1000;
1071 if dx
*dx
+dy
*dy
< r
then
1073 m
:= PointToRect(X
, Y
, Obj
.X
+Obj
.Rect
.X
, Obj
.Y
+Obj
.Rect
.Y
,
1074 Obj
.Rect
.Width
, Obj
.Rect
.Height
);
1075 _angle
:= GetAngle(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2),
1076 Obj
.Y
+Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2), X
, Y
);
1077 g_Obj_PushA(@Obj
, Round(15*(rad
-m
)/rad
), _angle
);
1078 positionChanged(); // this updates spatial accelerators
1084 procedure g_Weapon_Init();
1089 procedure g_Weapon_Free();
1093 if Shots
<> nil then
1095 for i
:= 0 to High(Shots
) do
1096 if Shots
[i
].ShotType
<> 0 then
1097 Shots
[i
].Animation
.Free();
1105 procedure g_Weapon_LoadData();
1107 e_WriteLog('Loading weapons data...', TMsgType
.Notify
);
1109 g_Sound_CreateWADEx('SOUND_WEAPON_HITPUNCH', GameWAD
+':SOUNDS\HITPUNCH');
1110 g_Sound_CreateWADEx('SOUND_WEAPON_MISSPUNCH', GameWAD
+':SOUNDS\MISSPUNCH');
1111 g_Sound_CreateWADEx('SOUND_WEAPON_HITBERSERK', GameWAD
+':SOUNDS\HITBERSERK');
1112 g_Sound_CreateWADEx('SOUND_WEAPON_MISSBERSERK', GameWAD
+':SOUNDS\MISSBERSERK');
1113 g_Sound_CreateWADEx('SOUND_WEAPON_SELECTSAW', GameWAD
+':SOUNDS\SELECTSAW');
1114 g_Sound_CreateWADEx('SOUND_WEAPON_IDLESAW', GameWAD
+':SOUNDS\IDLESAW');
1115 g_Sound_CreateWADEx('SOUND_WEAPON_HITSAW', GameWAD
+':SOUNDS\HITSAW');
1116 g_Sound_CreateWADEx('SOUND_WEAPON_FIRESHOTGUN2', GameWAD
+':SOUNDS\FIRESHOTGUN2');
1117 g_Sound_CreateWADEx('SOUND_WEAPON_FIRESHOTGUN', GameWAD
+':SOUNDS\FIRESHOTGUN');
1118 g_Sound_CreateWADEx('SOUND_WEAPON_FIRESAW', GameWAD
+':SOUNDS\FIRESAW');
1119 g_Sound_CreateWADEx('SOUND_WEAPON_FIREROCKET', GameWAD
+':SOUNDS\FIREROCKET');
1120 g_Sound_CreateWADEx('SOUND_WEAPON_FIREPLASMA', GameWAD
+':SOUNDS\FIREPLASMA');
1121 g_Sound_CreateWADEx('SOUND_WEAPON_FIREPISTOL', GameWAD
+':SOUNDS\FIREPISTOL');
1122 g_Sound_CreateWADEx('SOUND_WEAPON_FIRECGUN', GameWAD
+':SOUNDS\FIRECGUN');
1123 g_Sound_CreateWADEx('SOUND_WEAPON_FIREBFG', GameWAD
+':SOUNDS\FIREBFG');
1124 g_Sound_CreateWADEx('SOUND_FIRE', GameWAD
+':SOUNDS\FIRE');
1125 g_Sound_CreateWADEx('SOUND_IGNITE', GameWAD
+':SOUNDS\IGNITE');
1126 g_Sound_CreateWADEx('SOUND_WEAPON_STARTFIREBFG', GameWAD
+':SOUNDS\STARTFIREBFG');
1127 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEROCKET', GameWAD
+':SOUNDS\EXPLODEROCKET');
1128 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEBFG', GameWAD
+':SOUNDS\EXPLODEBFG');
1129 g_Sound_CreateWADEx('SOUND_WEAPON_BFGWATER', GameWAD
+':SOUNDS\BFGWATER');
1130 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEPLASMA', GameWAD
+':SOUNDS\EXPLODEPLASMA');
1131 g_Sound_CreateWADEx('SOUND_WEAPON_PLASMAWATER', GameWAD
+':SOUNDS\PLASMAWATER');
1132 g_Sound_CreateWADEx('SOUND_WEAPON_FIREBALL', GameWAD
+':SOUNDS\FIREBALL');
1133 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEBALL', GameWAD
+':SOUNDS\EXPLODEBALL');
1134 g_Sound_CreateWADEx('SOUND_WEAPON_FIREREV', GameWAD
+':SOUNDS\FIREREV');
1135 g_Sound_CreateWADEx('SOUND_WEAPON_FLAMEON', GameWAD
+':SOUNDS\STARTFLM');
1136 g_Sound_CreateWADEx('SOUND_WEAPON_FLAMEOFF', GameWAD
+':SOUNDS\STOPFLM');
1137 g_Sound_CreateWADEx('SOUND_WEAPON_FLAMEWORK', GameWAD
+':SOUNDS\WORKFLM');
1138 g_Sound_CreateWADEx('SOUND_PLAYER_JETFLY', GameWAD
+':SOUNDS\WORKJETPACK');
1139 g_Sound_CreateWADEx('SOUND_PLAYER_JETON', GameWAD
+':SOUNDS\STARTJETPACK');
1140 g_Sound_CreateWADEx('SOUND_PLAYER_JETOFF', GameWAD
+':SOUNDS\STOPJETPACK');
1141 g_Sound_CreateWADEx('SOUND_PLAYER_CASING1', GameWAD
+':SOUNDS\CASING1');
1142 g_Sound_CreateWADEx('SOUND_PLAYER_CASING2', GameWAD
+':SOUNDS\CASING2');
1143 g_Sound_CreateWADEx('SOUND_PLAYER_SHELL1', GameWAD
+':SOUNDS\SHELL1');
1144 g_Sound_CreateWADEx('SOUND_PLAYER_SHELL2', GameWAD
+':SOUNDS\SHELL2');
1146 //wgunMonHash := hashNewIntInt();
1147 wgunHitHeap
:= TBinaryHeapHitTimes
.Create();
1150 procedure g_Weapon_FreeData();
1152 e_WriteLog('Releasing weapons data...', TMsgType
.Notify
);
1154 g_Sound_Delete('SOUND_WEAPON_HITPUNCH');
1155 g_Sound_Delete('SOUND_WEAPON_MISSPUNCH');
1156 g_Sound_Delete('SOUND_WEAPON_HITBERSERK');
1157 g_Sound_Delete('SOUND_WEAPON_MISSBERSERK');
1158 g_Sound_Delete('SOUND_WEAPON_SELECTSAW');
1159 g_Sound_Delete('SOUND_WEAPON_IDLESAW');
1160 g_Sound_Delete('SOUND_WEAPON_HITSAW');
1161 g_Sound_Delete('SOUND_WEAPON_FIRESHOTGUN2');
1162 g_Sound_Delete('SOUND_WEAPON_FIRESHOTGUN');
1163 g_Sound_Delete('SOUND_WEAPON_FIRESAW');
1164 g_Sound_Delete('SOUND_WEAPON_FIREROCKET');
1165 g_Sound_Delete('SOUND_WEAPON_FIREPLASMA');
1166 g_Sound_Delete('SOUND_WEAPON_FIREPISTOL');
1167 g_Sound_Delete('SOUND_WEAPON_FIRECGUN');
1168 g_Sound_Delete('SOUND_WEAPON_FIREBFG');
1169 g_Sound_Delete('SOUND_FIRE');
1170 g_Sound_Delete('SOUND_IGNITE');
1171 g_Sound_Delete('SOUND_WEAPON_STARTFIREBFG');
1172 g_Sound_Delete('SOUND_WEAPON_EXPLODEROCKET');
1173 g_Sound_Delete('SOUND_WEAPON_EXPLODEBFG');
1174 g_Sound_Delete('SOUND_WEAPON_BFGWATER');
1175 g_Sound_Delete('SOUND_WEAPON_EXPLODEPLASMA');
1176 g_Sound_Delete('SOUND_WEAPON_PLASMAWATER');
1177 g_Sound_Delete('SOUND_WEAPON_FIREBALL');
1178 g_Sound_Delete('SOUND_WEAPON_EXPLODEBALL');
1179 g_Sound_Delete('SOUND_WEAPON_FIREREV');
1180 g_Sound_Delete('SOUND_WEAPON_FLAMEON');
1181 g_Sound_Delete('SOUND_WEAPON_FLAMEOFF');
1182 g_Sound_Delete('SOUND_WEAPON_FLAMEWORK');
1183 g_Sound_Delete('SOUND_PLAYER_JETFLY');
1184 g_Sound_Delete('SOUND_PLAYER_JETON');
1185 g_Sound_Delete('SOUND_PLAYER_JETOFF');
1186 g_Sound_Delete('SOUND_PLAYER_CASING1');
1187 g_Sound_Delete('SOUND_PLAYER_CASING2');
1188 g_Sound_Delete('SOUND_PLAYER_SHELL1');
1189 g_Sound_Delete('SOUND_PLAYER_SHELL2');
1193 function GunHitPlayer (X
, Y
: Integer; vx
, vy
: Integer; dmg
: Integer; SpawnerUID
: Word; AllowPush
: Boolean): Boolean;
1198 for i
:= 0 to High(gPlayers
) do
1200 if (gPlayers
[i
] <> nil) and gPlayers
[i
].alive
and gPlayers
[i
].Collide(X
, Y
) then
1202 if HitPlayer(gPlayers
[i
], dmg
, vx
*10, vy
*10-3, SpawnerUID
, HIT_SOME
) then
1204 if AllowPush
then gPlayers
[i
].Push(vx
, vy
);
1212 function GunHit (X
, Y
: Integer; vx
, vy
: Integer; dmg
: Integer; SpawnerUID
: Word; AllowPush
: Boolean): Byte;
1214 function monsCheck (mon
: TMonster
): Boolean;
1216 result
:= false; // don't stop
1217 if HitMonster(mon
, dmg
, vx
*10, vy
*10-3, SpawnerUID
, HIT_SOME
) then
1219 if AllowPush
then mon
.Push(vx
, vy
);
1226 if GunHitPlayer(X
, Y
, vx
, vy
, dmg
, SpawnerUID
, AllowPush
) then result
:= 1
1227 else if g_Mons_ForEachAliveAt(X
, Y
, 1, 1, monsCheck
) then result
:= 2;
1232 procedure g_Weapon_gunOld(const x, y, xd, yd, v, dmg: Integer; SpawnerUID: Word; CheckTrigger: Boolean);
1243 t1, _collide: Boolean;
1245 {$IF DEFINED(D2F_DEBUG)}
1247 showTime: Boolean = true;
1250 a := GetAngle(x, y, xd, yd)+180;
1252 SinCos(DegToRad(-a), s, c);
1254 if Abs(s) < 0.01 then s := 0;
1255 if Abs(c) < 0.01 then c := 0;
1257 x2 := x+Round(c*gMapInfo.Width);
1258 y2 := y+Round(s*gMapInfo.Width);
1260 t1 := gWalls <> nil;
1262 w := gMapInfo.Width;
1263 h := gMapInfo.Height;
1270 if (xd = 0) and (yd = 0) then Exit;
1272 if dx > 0 then xi := 1 else if dx < 0 then xi := -1 else xi := 0;
1273 if dy > 0 then yi := 1 else if dy < 0 then yi := -1 else yi := 0;
1278 if dx > dy then d := dx else d := dy;
1280 //blood vel, for Monster.Damage()
1281 //vx := (dx*10 div d)*xi;
1282 //vy := (dy*10 div d)*yi;
1284 {$IF DEFINED(D2F_DEBUG)}
1285 stt := getTimeMicro();
1308 if (yy > h) or (yy < 0) then Break;
1309 if (xx > w) or (xx < 0) then Break;
1312 if ByteBool(gCollideMap[yy, xx] and MARK_BLOCKED) then
1315 {$IF DEFINED(D2F_DEBUG)}
1316 stt := getTimeMicro()-stt;
1317 e_WriteLog(Format('*** old trace time: %u microseconds', [LongWord(stt)]), MSG_NOTIFY);
1320 g_GFX_Spark(xx-xi, yy-yi, 2+Random(2), 180+a, 0, 0);
1321 if g_Game_IsServer and g_Game_IsNet then
1322 MH_SEND_Effect(xx-xi, yy-yi, 180+a, NET_GFX_SPARK);
1325 if not _collide then
1327 _collide := GunHit(xx, yy, xi*v, yi*v, dmg, SpawnerUID, v <> 0) <> 0;
1330 if _collide then Break;
1333 {$IF DEFINED(D2F_DEBUG)}
1336 stt := getTimeMicro()-stt;
1337 e_WriteLog(Format('*** old trace time: %u microseconds', [LongWord(stt)]), MSG_NOTIFY);
1341 if CheckTrigger and g_Game_IsServer then
1342 g_Triggers_PressL(X, Y, xx-xi, yy-yi, SpawnerUID, ACTIVATE_SHOT);
1348 procedure g_Weapon_gun (const x
, y
, xd
, yd
, v
, indmg
: Integer; SpawnerUID
: Word; CheckTrigger
: Boolean);
1353 wallDistSq
: Integer = $3fffffff;
1354 spawnerPlr
: TPlayer
= nil;
1357 function doPlayerHit (idx
: Integer; hx
, hy
: Integer): Boolean;
1360 if (idx
< 0) or (idx
> High(gPlayers
)) then exit
;
1361 if (gPlayers
[idx
] = nil) or not gPlayers
[idx
].alive
then exit
;
1362 if (spawnerPlr
<> nil) then
1364 if ((gGameSettings
.Options
and (GAME_OPTION_TEAMHITTRACE
or GAME_OPTION_TEAMDAMAGE
)) = 0) and
1365 (spawnerPlr
.Team
<> TEAM_NONE
) and (spawnerPlr
.Team
= gPlayers
[idx
].Team
) then
1367 if (spawnerPlr
<> gPlayers
[idx
]) and ((gGameSettings
.Options
and GAME_OPTION_TEAMABSORBDAMAGE
) = 0) then
1368 dmg
:= Max(1, dmg
div 2);
1372 result
:= HitPlayer(gPlayers
[idx
], dmg
, (xi
*v
)*10, (yi
*v
)*10-3, SpawnerUID
, HIT_SOME
);
1373 if result
and (v
<> 0) then gPlayers
[idx
].Push((xi
*v
), (yi
*v
));
1374 {$IF DEFINED(D2F_DEBUG)}
1375 //if result then e_WriteLog(Format(' PLAYER #%d HIT', [idx]), MSG_NOTIFY);
1379 function doMonsterHit (mon
: TMonster
; hx
, hy
: Integer): Boolean;
1382 if (mon
= nil) then exit
;
1383 result
:= HitMonster(mon
, dmg
, (xi
*v
)*10, (yi
*v
)*10-3, SpawnerUID
, HIT_SOME
);
1384 if result
and (v
<> 0) then mon
.Push((xi
*v
), (yi
*v
));
1385 {$IF DEFINED(D2F_DEBUG)}
1386 //if result then e_WriteLog(Format(' MONSTER #%u HIT', [LongWord(mon.UID)]), MSG_NOTIFY);
1390 // collect players along hitray
1391 // return `true` if instant hit was detected
1392 function playerPossibleHit (): Boolean;
1395 px
, py
, pw
, ph
: Integer;
1401 for i
:= 0 to High(gPlayers
) do
1404 if (plr
<> nil) and plr
.alive
then
1406 plr
.getMapBox(px
, py
, pw
, ph
);
1407 if lineAABBIntersects(x
, y
, x2
, y2
, px
, py
, pw
, ph
, inx
, iny
) then
1409 distSq
:= distanceSq(x
, y
, inx
, iny
);
1410 if (distSq
= 0) then
1413 if doPlayerHit(i
, x
, y
) then begin result
:= true; exit
; end;
1415 else if (distSq
< wallDistSq
) then
1417 appendHitTimePlr(distSq
, i
, inx
, iny
);
1424 procedure sqchecker (mon
: TMonster
);
1426 mx
, my
, mw
, mh
: Integer;
1430 mon
.getMapBox(mx
, my
, mw
, mh
);
1431 if lineAABBIntersects(x0
, y0
, x2
, y2
, mx
, my
, mw
, mh
, inx
, iny
) then
1433 distSq
:= distanceSq(x0
, y0
, inx
, iny
);
1434 if (distSq
< wallDistSq
) then appendHitTimeMon(distSq
, mon
, inx
, iny
);
1444 wallHitFlag
: Boolean = false;
1445 wallHitX
: Integer = 0;
1446 wallHitY
: Integer = 0;
1447 didHit
: Boolean = false;
1448 {$IF DEFINED(D2F_DEBUG)}
1452 it
: TMonsterGrid
.Iter
;
1455 if not gwep_debug_fast_trace then
1457 g_Weapon_gunOld(x, y, xd, yd, v, dmg, SpawnerUID, CheckTrigger);
1462 if (xd
= 0) and (yd
= 0) then exit
;
1464 if (g_GetUIDType(SpawnerUID
) = UID_PLAYER
) then
1465 spawnerPlr
:= g_Player_Get(SpawnerUID
);
1469 //wgunMonHash.reset(); //FIXME: clear hash on level change
1470 wgunHitHeap
.clear();
1471 wgunHitTimeUsed
:= 0;
1473 a
:= GetAngle(x
, y
, xd
, yd
)+180;
1475 SinCos(DegToRad(-a
), s
, c
);
1477 if Abs(s
) < 0.01 then s
:= 0;
1478 if Abs(c
) < 0.01 then c
:= 0;
1482 x2
:= x
+Round(c
*gMapInfo
.Width
);
1483 y2
:= y
+Round(s
*gMapInfo
.Width
);
1488 if (dx
> 0) then xi
:= 1 else if (dx
< 0) then xi
:= -1 else xi
:= 0;
1489 if (dy
> 0) then yi
:= 1 else if (dy
< 0) then yi
:= -1 else yi
:= 0;
1491 {$IF DEFINED(D2F_DEBUG)}
1492 e_WriteLog(Format('GUN TRACE: (%d,%d) to (%d,%d)', [x
, y
, x2
, y2
]), TMsgType
.Notify
);
1493 stt
:= getTimeMicro();
1496 wallHitFlag
:= (g_Map_traceToNearestWall(x
, y
, x2
, y2
, @wallHitX
, @wallHitY
) <> nil);
1501 wallDistSq
:= distanceSq(x
, y
, wallHitX
, wallHitY
);
1509 if playerPossibleHit() then exit
; // instant hit
1512 //g_Mons_AlongLine(x, y, x2, y2, sqchecker);
1514 it
:= monsGrid
.forEachAlongLine(x
, y
, x2
, y2
, -1);
1515 for mit
in it
do sqchecker(mit
^);
1518 // here, we collected all monsters and players in `wgunHitHeap` and `wgunHitTime`
1519 // also, if `wallWasHit` is `true`, then `wallHitX` and `wallHitY` contains spark coords
1520 while (wgunHitHeap
.count
> 0) do
1522 // has some entities to check, do it
1523 i
:= wgunHitHeap
.front
;
1524 wgunHitHeap
.popFront();
1526 xe
:= wgunHitTime
[i
].x
;
1527 ye
:= wgunHitTime
[i
].y
;
1528 // check if it is not behind the wall
1529 if (wgunHitTime
[i
].mon
<> nil) then
1531 didHit
:= doMonsterHit(wgunHitTime
[i
].mon
, xe
, ye
);
1535 didHit
:= doPlayerHit(wgunHitTime
[i
].plridx
, xe
, ye
);
1539 // need new coords for trigger
1542 wallHitFlag
:= false; // no sparks
1550 {$IF DEFINED(D2F_DEBUG)}
1551 stt
:= getTimeMicro()-stt
;
1552 e_WriteLog(Format('*** new trace time: %u microseconds', [LongWord(stt
)]), TMsgType
.Notify
);
1555 g_GFX_Spark(wallHitX
, wallHitY
, 2+Random(2), 180+a
, 0, 0);
1557 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Effect(wallHitX
, wallHitY
, 180+a
, NET_GFX_SPARK
);
1561 {$IF DEFINED(D2F_DEBUG)}
1562 stt
:= getTimeMicro()-stt
;
1563 e_WriteLog(Format('*** new trace time: %u microseconds', [LongWord(stt
)]), TMsgType
.Notify
);
1567 if CheckTrigger
and g_Game_IsServer
then g_Triggers_PressL(X
, Y
, wallHitX
, wallHitY
, SpawnerUID
, ACTIVATE_SHOT
);
1571 procedure g_Weapon_punch(x
, y
: Integer; d
, SpawnerUID
: Word);
1579 obj
.rect
.Width
:= 39;
1580 obj
.rect
.Height
:= 52;
1586 if g_Weapon_Hit(@obj
, d
, SpawnerUID
, HIT_SOME
) <> 0 then
1587 g_Sound_PlayExAt('SOUND_WEAPON_HITPUNCH', x
, y
)
1589 g_Sound_PlayExAt('SOUND_WEAPON_MISSPUNCH', x
, y
);
1592 function g_Weapon_chainsaw(x
, y
: Integer; d
, SpawnerUID
: Word): Integer;
1600 obj
.rect
.Width
:= 32;
1601 obj
.rect
.Height
:= 52;
1607 Result
:= g_Weapon_Hit(@obj
, d
, SpawnerUID
, HIT_SOME
);
1610 procedure g_Weapon_rocket(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1;
1611 Silent
: Boolean = False; compat
: Boolean = true);
1617 find_id
:= FindShot()
1621 if Integer(find_id
) >= High(Shots
) then
1622 SetLength(Shots
, find_id
+ 64)
1625 with Shots
[find_id
] do
1629 Obj
.Rect
.Width
:= SHOT_ROCKETLAUNCHER_WIDTH
;
1630 Obj
.Rect
.Height
:= SHOT_ROCKETLAUNCHER_HEIGHT
;
1633 dx
:= IfThen(xd
> x
, -Obj
.Rect
.Width
, 0)
1635 dx
:= -(Obj
.Rect
.Width
div 2);
1636 dy
:= -(Obj
.Rect
.Height
div 2);
1638 ShotType
:= WEAPON_ROCKETLAUNCHER
;
1639 throw(find_id
, x
+dx
, y
+dy
, xd
+dx
, yd
+dy
, 12);
1645 Shots
[find_id
].SpawnerUID
:= SpawnerUID
;
1648 g_Sound_PlayExAt('SOUND_WEAPON_FIREROCKET', x
, y
);
1651 procedure g_Weapon_revf(x
, y
, xd
, yd
: Integer; SpawnerUID
, TargetUID
: Word;
1652 WID
: Integer = -1; Silent
: Boolean = False);
1658 find_id
:= FindShot()
1662 if Integer(find_id
) >= High(Shots
) then
1663 SetLength(Shots
, find_id
+ 64)
1666 with Shots
[find_id
] do
1670 Obj
.Rect
.Width
:= SHOT_SKELFIRE_WIDTH
;
1671 Obj
.Rect
.Height
:= SHOT_SKELFIRE_HEIGHT
;
1673 dx
:= -(Obj
.Rect
.Width
div 2);
1674 dy
:= -(Obj
.Rect
.Height
div 2);
1676 ShotType
:= WEAPON_SKEL_FIRE
;
1677 throw(find_id
, x
+dx
, y
+dy
, xd
+dx
, yd
+dy
, 12);
1680 target
:= TargetUID
;
1681 Animation
:= TAnimationState
.Create(True, 5, 2); // !!! put values into table
1684 Shots
[find_id
].SpawnerUID
:= SpawnerUID
;
1687 g_Sound_PlayExAt('SOUND_WEAPON_FIREREV', x
, y
);
1690 procedure g_Weapon_plasma(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1;
1691 Silent
: Boolean = False; compat
: Boolean = true);
1697 find_id
:= FindShot()
1701 if Integer(find_id
) >= High(Shots
) then
1702 SetLength(Shots
, find_id
+ 64);
1705 with Shots
[find_id
] do
1709 Obj
.Rect
.Width
:= SHOT_PLASMA_WIDTH
;
1710 Obj
.Rect
.Height
:= SHOT_PLASMA_HEIGHT
;
1713 dx
:= IfThen(xd
> x
, -Obj
.Rect
.Width
, 0)
1715 dx
:= -(Obj
.Rect
.Width
div 2);
1716 dy
:= -(Obj
.Rect
.Height
div 2);
1718 ShotType
:= WEAPON_PLASMA
;
1719 throw(find_id
, x
+dx
, y
+dy
, xd
+dx
, yd
+dy
, 16);
1722 Animation
:= TAnimationState
.Create(True, 5, 2); // !!! put values into table
1725 Shots
[find_id
].SpawnerUID
:= SpawnerUID
;
1728 g_Sound_PlayExAt('SOUND_WEAPON_FIREPLASMA', x
, y
);
1731 procedure g_Weapon_flame(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1;
1732 Silent
: Boolean = False; compat
: Boolean = true);
1738 find_id
:= FindShot()
1742 if Integer(find_id
) >= High(Shots
) then
1743 SetLength(Shots
, find_id
+ 64);
1746 with Shots
[find_id
] do
1750 Obj
.Rect
.Width
:= SHOT_FLAME_WIDTH
;
1751 Obj
.Rect
.Height
:= SHOT_FLAME_HEIGHT
;
1754 dx
:= IfThen(xd
> x
, -Obj
.Rect
.Width
, 0)
1756 dx
:= -(Obj
.Rect
.Width
div 2);
1757 dy
:= -(Obj
.Rect
.Height
div 2);
1759 ShotType
:= WEAPON_FLAMETHROWER
;
1760 throw(find_id
, x
+dx
, y
+dy
, xd
+dx
, yd
+dy
, 16);
1766 Shots
[find_id
].SpawnerUID
:= SpawnerUID
;
1768 // if not Silent then
1769 // g_Sound_PlayExAt('SOUND_WEAPON_FIREPLASMA', x, y);
1772 procedure g_Weapon_ball1(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1;
1773 Silent
: Boolean = False; compat
: Boolean = true);
1779 find_id
:= FindShot()
1783 if Integer(find_id
) >= High(Shots
) then
1784 SetLength(Shots
, find_id
+ 64)
1787 with Shots
[find_id
] do
1791 Obj
.Rect
.Width
:= 16;
1792 Obj
.Rect
.Height
:= 16;
1795 dx
:= IfThen(xd
> x
, -Obj
.Rect
.Width
, 0)
1797 dx
:= -(Obj
.Rect
.Width
div 2);
1798 dy
:= -(Obj
.Rect
.Height
div 2);
1800 ShotType
:= WEAPON_IMP_FIRE
;
1801 throw(find_id
, x
+dx
, y
+dy
, xd
+dx
, yd
+dy
, 16);
1804 Animation
:= TAnimationState
.Create(True, 4, 2); // !!! put values into table
1807 Shots
[find_id
].SpawnerUID
:= SpawnerUID
;
1810 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x
, y
);
1813 procedure g_Weapon_ball2(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1;
1814 Silent
: Boolean = False; compat
: Boolean = true);
1820 find_id
:= FindShot()
1824 if Integer(find_id
) >= High(Shots
) then
1825 SetLength(Shots
, find_id
+ 64)
1828 with Shots
[find_id
] do
1832 Obj
.Rect
.Width
:= 16;
1833 Obj
.Rect
.Height
:= 16;
1836 dx
:= IfThen(xd
> x
, -Obj
.Rect
.Width
, 0)
1838 dx
:= -(Obj
.Rect
.Width
div 2);
1839 dy
:= -(Obj
.Rect
.Height
div 2);
1841 ShotType
:= WEAPON_CACO_FIRE
;
1842 throw(find_id
, x
+dx
, y
+dy
, xd
+dx
, yd
+dy
, 16);
1845 Animation
:= TAnimationState
.Create(True, 4, 2); // !!! put values into table
1848 Shots
[find_id
].SpawnerUID
:= SpawnerUID
;
1851 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x
, y
);
1854 procedure g_Weapon_ball7(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1;
1855 Silent
: Boolean = False; compat
: Boolean = true);
1861 find_id
:= FindShot()
1865 if Integer(find_id
) >= High(Shots
) then
1866 SetLength(Shots
, find_id
+ 64)
1869 with Shots
[find_id
] do
1873 Obj
.Rect
.Width
:= 32;
1874 Obj
.Rect
.Height
:= 16;
1877 dx
:= IfThen(xd
> x
, -Obj
.Rect
.Width
, 0)
1879 dx
:= -(Obj
.Rect
.Width
div 2);
1880 dy
:= -(Obj
.Rect
.Height
div 2);
1882 ShotType
:= WEAPON_BARON_FIRE
;
1883 throw(find_id
, x
+dx
, y
+dy
, xd
+dx
, yd
+dy
, 16);
1886 Animation
:= TAnimationState
.Create(True, 4, 2); // !!! put values into table
1889 Shots
[find_id
].SpawnerUID
:= SpawnerUID
;
1892 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x
, y
);
1895 procedure g_Weapon_aplasma(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1;
1896 Silent
: Boolean = False; compat
: Boolean = true);
1902 find_id
:= FindShot()
1906 if Integer(find_id
) >= High(Shots
) then
1907 SetLength(Shots
, find_id
+ 64)
1910 with Shots
[find_id
] do
1914 Obj
.Rect
.Width
:= 16;
1915 Obj
.Rect
.Height
:= 16;
1918 dx
:= IfThen(xd
> x
, -Obj
.Rect
.Width
, 0)
1920 dx
:= -(Obj
.Rect
.Width
div 2);
1921 dy
:= -(Obj
.Rect
.Height
div 2);
1923 ShotType
:= WEAPON_BSP_FIRE
;
1924 throw(find_id
, x
+dx
, y
+dy
, xd
+dx
, yd
+dy
, 16);
1928 Animation
:= TAnimationState
.Create(True, 4, 2); // !!! put values into table
1931 Shots
[find_id
].SpawnerUID
:= SpawnerUID
;
1934 g_Sound_PlayExAt('SOUND_WEAPON_FIREPLASMA', x
, y
);
1937 procedure g_Weapon_manfire(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1;
1938 Silent
: Boolean = False; compat
: Boolean = true);
1944 find_id
:= FindShot()
1948 if Integer(find_id
) >= High(Shots
) then
1949 SetLength(Shots
, find_id
+ 64)
1952 with Shots
[find_id
] do
1956 Obj
.Rect
.Width
:= 32;
1957 Obj
.Rect
.Height
:= 32;
1960 dx
:= IfThen(xd
> x
, -Obj
.Rect
.Width
, 0)
1962 dx
:= -(Obj
.Rect
.Width
div 2);
1963 dy
:= -(Obj
.Rect
.Height
div 2);
1965 ShotType
:= WEAPON_MANCUB_FIRE
;
1966 throw(find_id
, x
+dx
, y
+dy
, xd
+dx
, yd
+dy
, 16);
1970 Animation
:= TAnimationState
.Create(True, 4, 2); // !!! put values into table
1973 Shots
[find_id
].SpawnerUID
:= SpawnerUID
;
1976 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x
, y
);
1979 procedure g_Weapon_bfgshot(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1;
1980 Silent
: Boolean = False; compat
: Boolean = true);
1986 find_id
:= FindShot()
1990 if Integer(find_id
) >= High(Shots
) then
1991 SetLength(Shots
, find_id
+ 64)
1994 with Shots
[find_id
] do
1998 Obj
.Rect
.Width
:= SHOT_BFG_WIDTH
;
1999 Obj
.Rect
.Height
:= SHOT_BFG_HEIGHT
;
2002 dx
:= IfThen(xd
> x
, -Obj
.Rect
.Width
, 0)
2004 dx
:= -(Obj
.Rect
.Width
div 2);
2005 dy
:= -(Obj
.Rect
.Height
div 2);
2007 ShotType
:= WEAPON_BFG
;
2008 throw(find_id
, x
+dx
, y
+dy
, xd
+dx
, yd
+dy
, 16);
2011 Animation
:= TAnimationState
.Create(True, 6, 2); // !!! put values into table
2014 Shots
[find_id
].SpawnerUID
:= SpawnerUID
;
2017 g_Sound_PlayExAt('SOUND_WEAPON_FIREBFG', x
, y
);
2020 procedure g_Weapon_bfghit(x
, y
: Integer);
2023 g_GFX_QueueEffect(R_GFX_BFG_HIT
, x
- 32, y
- 32);
2027 procedure g_Weapon_pistol(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word;
2028 Silent
: Boolean = False);
2031 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', x
, y
);
2033 g_Weapon_gun(x
, y
, xd
, yd
, 1, 3, SpawnerUID
, True);
2034 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
] then
2036 if ABS(x
-xd
) >= ABS(y
-yd
) then
2038 g_Weapon_gun(x
, y
+1, xd
, yd
+1, 1, 3, SpawnerUID
, False);
2039 g_Weapon_gun(x
, y
-1, xd
, yd
-1, 1, 2, SpawnerUID
, False);
2043 g_Weapon_gun(x
+1, y
, xd
+1, yd
, 1, 3, SpawnerUID
, False);
2044 g_Weapon_gun(x
-1, y
, xd
-1, yd
, 1, 2, SpawnerUID
, False);
2049 procedure g_Weapon_mgun(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word;
2050 Silent
: Boolean = False);
2053 if gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', x
, y
);
2055 g_Weapon_gun(x
, y
, xd
, yd
, 1, 3, SpawnerUID
, True);
2056 if (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) and
2057 (g_GetUIDType(SpawnerUID
) = UID_PLAYER
) then
2059 if ABS(x
-xd
) >= ABS(y
-yd
) then
2061 g_Weapon_gun(x
, y
+1, xd
, yd
+1, 1, 2, SpawnerUID
, False);
2062 g_Weapon_gun(x
, y
-1, xd
, yd
-1, 1, 2, SpawnerUID
, False);
2066 g_Weapon_gun(x
+1, y
, xd
+1, yd
, 1, 2, SpawnerUID
, False);
2067 g_Weapon_gun(x
-1, y
, xd
-1, yd
, 1, 2, SpawnerUID
, False);
2072 procedure g_Weapon_shotgun(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word;
2073 Silent
: Boolean = False);
2078 if gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', x
, y
);
2083 if ABS(x
-xd
) >= ABS(y
-yd
) then j
:= Random(17) - 8 else k
:= Random(17) - 8; // -8 .. 8
2084 g_Weapon_gun(x
+k
, y
+j
, xd
+k
, yd
+j
, IfThen(i
mod 2 <> 0, 1, 0), 3, SpawnerUID
, i
=0);
2088 procedure g_Weapon_dshotgun(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word;
2089 Silent
: Boolean = False);
2091 a
, i
, j
, k
: Integer;
2094 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', x
, y
);
2096 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
] then a
:= 25 else a
:= 20;
2100 if ABS(x
-xd
) >= ABS(y
-yd
) then j
:= Random(41) - 20 else k
:= Random(41) - 20; // -20 .. 20
2101 g_Weapon_gun(x
+k
, y
+j
, xd
+k
, yd
+j
, IfThen(i
mod 3 <> 0, 0, 1), 3, SpawnerUID
, i
=0);
2105 procedure g_Weapon_PreUpdate();
2109 if Shots
= nil then Exit
;
2110 for i
:= 0 to High(Shots
) do
2111 if Shots
[i
].ShotType
<> 0 then
2113 Shots
[i
].Obj
.oldX
:= Shots
[i
].Obj
.X
;
2114 Shots
[i
].Obj
.oldY
:= Shots
[i
].Obj
.Y
;
2118 procedure g_Weapon_Update();
2120 i
, a
, h
, cx
, cy
, oldvx
, oldvy
, tf
: Integer;
2127 var tcx
, tcy
: Integer;
2133 for i
:= 0 to High(Shots
) do
2135 if Shots
[i
].ShotType
= 0 then
2142 Timeout
:= Timeout
- 1;
2145 // Àêòèâèðîâàòü òðèããåðû ïî ïóòè (êðîìå óæå àêòèâèðîâàííûõ):
2146 if (Stopped
= 0) and g_Game_IsServer
then
2147 t
:= g_Triggers_PressR(Obj
.X
, Obj
.Y
, Obj
.Rect
.Width
, Obj
.Rect
.Height
,
2148 SpawnerUID
, ACTIVATE_SHOT
, triggers
)
2154 // Ïîïîëíÿåì ñïèñîê àêòèâèðîâàííûõ òðèããåðîâ:
2155 if triggers
= nil then
2162 if not InDWArray(t
[a
], triggers
) then
2164 SetLength(triggers
, Length(triggers
)+1);
2165 triggers
[High(triggers
)] := t
[a
];
2170 // Àíèìàöèÿ ñíàðÿäà:
2171 if Animation
<> nil then
2175 spl
:= (ShotType
<> WEAPON_PLASMA
) and
2176 (ShotType
<> WEAPON_BFG
) and
2177 (ShotType
<> WEAPON_BSP_FIRE
) and
2178 (ShotType
<> WEAPON_FLAMETHROWER
);
2182 st
:= g_Obj_Move_Projectile(@Obj
, False, spl
);
2188 positionChanged(); // this updates spatial accelerators
2190 if WordBool(st
and MOVE_FALLOUT
) or (Obj
.X
< -1000) or
2191 (Obj
.X
> gMapInfo
.Width
+1000) or (Obj
.Y
< -1000) then
2193 // Íà êëèåíòå ñêîðåå âñåãî è òàê óæå âûïàë.
2199 cx
:= Obj
.X
+ (Obj
.Rect
.Width
div 2);
2200 cy
:= Obj
.Y
+ (Obj
.Rect
.Height
div 2);
2203 WEAPON_ROCKETLAUNCHER
, WEAPON_SKEL_FIRE
: // Ðàêåòû è ñíàðÿäû Ñêåëåòà
2205 // Âûëåòåëà èç âîäû:
2206 if WordBool(st
and MOVE_HITAIR
) then
2207 g_Obj_SetSpeed(@Obj
, 12);
2209 // Â âîäå øëåéô - ïóçûðè, â âîçäóõå øëåéô - äûì:
2210 if WordBool(st
and MOVE_INWATER
) then
2213 g_GFX_Bubbles(cx
, cy
, 1+Random(3), 16, 16);
2216 then g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', cx
, cy
)
2217 else g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', cx
, cy
);
2222 g_GFX_QueueEffect(R_GFX_SMOKE_TRANS
, Obj
.X
-14+Random(9), cy
-20+Random(9));
2226 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2227 if WordBool(st
and (MOVE_HITWALL
or MOVE_HITLAND
or MOVE_HITCEIL
)) or
2228 (g_Weapon_Hit(@Obj
, 10, SpawnerUID
, HIT_SOME
, False) <> 0) or
2234 g_Weapon_Explode(cx
, cy
, 60, SpawnerUID
);
2236 if ShotType
= WEAPON_SKEL_FIRE
then
2237 begin // Âçðûâ ñíàðÿäà Ñêåëåòà
2239 g_GFX_QueueEffect(R_GFX_EXPLODE_SKELFIRE
, Obj
.X
+ 32 - 58, Obj
.Y
+ 8 - 36);
2240 g_DynLightExplosion((Obj
.X
+32), (Obj
.Y
+8), 64, 1, 0, 0);
2244 begin // Âçðûâ Ðàêåòû
2246 g_GFX_QueueEffect(R_GFX_EXPLODE_ROCKET
, cx
- 64, cy
- 64);
2247 g_DynLightExplosion(cx
, cy
, 64, 1, 0, 0);
2251 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', Obj
.X
, Obj
.Y
);
2256 if ShotType
= WEAPON_SKEL_FIRE
then
2257 begin // Ñàìîíàâîäêà ñíàðÿäà Ñêåëåòà:
2258 if GetPos(target
, @o
) then
2259 throw(i
, Obj
.X
, Obj
.Y
,
2260 o
.X
+o
.Rect
.X
+(o
.Rect
.Width
div 2)+o
.Vel
.X
+o
.Accel
.X
,
2261 o
.Y
+o
.Rect
.Y
+(o
.Rect
.Height
div 2)+o
.Vel
.Y
+o
.Accel
.Y
,
2266 WEAPON_PLASMA
, WEAPON_BSP_FIRE
: // Ïëàçìà, ïëàçìà Àðàõíàòðîíà
2268 // Ïîïàëà â âîäó - ýëåêòðîøîê ïî âîäå:
2269 if WordBool(st
and (MOVE_INWATER
or MOVE_HITWATER
)) then
2271 g_Sound_PlayExAt('SOUND_WEAPON_PLASMAWATER', Obj
.X
, Obj
.Y
);
2272 if g_Game_IsServer
then CheckTrap(i
, 10, HIT_ELECTRO
);
2278 if (ShotType
= WEAPON_PLASMA
) and
2279 (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) then
2284 if ShotType
= WEAPON_BSP_FIRE
then
2287 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2288 if WordBool(st
and (MOVE_HITWALL
or MOVE_HITLAND
or MOVE_HITCEIL
)) or
2289 (g_Weapon_Hit(@Obj
, a
, SpawnerUID
, HIT_SOME
, False) <> 0) or
2293 if ShotType
= WEAPON_PLASMA
then
2294 g_GFX_QueueEffect(R_GFX_EXPLODE_PLASMA
, cx
- 16, cy
- 16)
2296 g_GFX_QueueEffect(R_GFX_EXPLODE_BSPFIRE
, cx
- 16, cy
- 16);
2297 g_DynLightExplosion(cx
, cy
, 32, 0, 0.5, 0.5);
2299 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEPLASMA', Obj
.X
, Obj
.Y
);
2304 WEAPON_FLAMETHROWER
: // Îãíåìåò
2306 // Ñî âðåìåíåì óìèðàåò
2307 if (Timeout
< 1) then
2313 if WordBool(st
and (MOVE_HITWATER
or MOVE_INWATER
)) then
2315 if WordBool(st
and MOVE_HITWATER
) then
2320 g_GFX_QueueEffect(R_GFX_SMOKE
, cx
-4+tcx
-(R_GFX_SMOKE_WIDTH
div 2), cy
-4+tcy
-(R_GFX_SMOKE_HEIGHT
div 2));
2326 g_GFX_Bubbles(cx
, cy
, 1+Random(3), 16, 16);
2329 then g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', cx
, cy
)
2330 else g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', cx
, cy
);
2338 Obj
.Accel
.Y
:= Obj
.Accel
.Y
+ 1;
2339 // Ïîïàëè â ñòåíó èëè â âîäó:
2340 if WordBool(st
and (MOVE_HITWALL
or MOVE_HITLAND
or MOVE_HITCEIL
or MOVE_HITWATER
)) then
2346 if WordBool(st
and MOVE_HITWALL
) then
2347 Stopped
:= MOVE_HITWALL
2348 else if WordBool(st
and MOVE_HITLAND
) then
2349 Stopped
:= MOVE_HITLAND
2350 else if WordBool(st
and MOVE_HITCEIL
) then
2351 Stopped
:= MOVE_HITCEIL
;
2354 a
:= IfThen(Stopped
= 0, 10, 1);
2355 // Åñëè â êîãî-òî ïîïàëè
2356 if g_Weapon_Hit(@Obj
, a
, SpawnerUID
, HIT_FLAME
, False) <> 0 then
2358 // HIT_FLAME ñàì ïîäîææåò
2359 // Åñëè â ïîëåòå ïîïàëè, èñ÷åçàåì
2369 if (gTime
mod LongWord(tf
) = 0) then
2373 MOVE_HITWALL
: begin tcx
:= cx
-4+Random(8); tcy
:= cy
-12+Random(24); end;
2374 MOVE_HITLAND
: begin tcx
:= cx
-12+Random(24); tcy
:= cy
-10+Random(8); end;
2375 MOVE_HITCEIL
: begin tcx
:= cx
-12+Random(24); tcy
:= cy
+6+Random(8); end;
2376 else begin tcx
:= cx
-4+Random(8); tcy
:= cy
-4+Random(8); end;
2378 g_GFX_QueueEffect(R_GFX_FLAME_RAND
, tcx
- (R_GFX_FLAME_WIDTH
div 2), tcy
- (R_GFX_FLAME_HEIGHT
div 2));
2379 //g_DynLightExplosion(tcx, tcy, 1, 1, 0.8, 0.3);
2386 // Ïîïàëà â âîäó - ýëåêòðîøîê ïî âîäå:
2387 if WordBool(st
and (MOVE_INWATER
or MOVE_HITWATER
)) then
2389 g_Sound_PlayExAt('SOUND_WEAPON_BFGWATER', Obj
.X
, Obj
.Y
);
2390 if g_Game_IsServer
then CheckTrap(i
, 1000, HIT_ELECTRO
);
2395 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2396 if WordBool(st
and (MOVE_HITWALL
or MOVE_HITLAND
or MOVE_HITCEIL
)) or
2397 (g_Weapon_Hit(@Obj
, SHOT_BFG_DAMAGE
, SpawnerUID
, HIT_BFG
, False) <> 0) or
2401 if g_Game_IsServer
then g_Weapon_BFG9000(cx
, cy
, SpawnerUID
);
2403 g_GFX_QueueEffect(R_GFX_EXPLODE_BFG
, cx
- 64, cy
- 64);
2404 g_DynLightExplosion(cx
, cy
, 96, 0, 1, 0);
2406 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', Obj
.X
, Obj
.Y
);
2411 WEAPON_IMP_FIRE
, WEAPON_CACO_FIRE
, WEAPON_BARON_FIRE
: // Âûñòðåëû Áåñà, Êàêîäåìîíà Ðûöàðÿ/Áàðîíà àäà
2414 if WordBool(st
and MOVE_HITAIR
) then
2415 g_Obj_SetSpeed(@Obj
, 16);
2418 if ShotType
= WEAPON_IMP_FIRE
then
2421 if ShotType
= WEAPON_CACO_FIRE
then
2426 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2427 if WordBool(st
and (MOVE_HITWALL
or MOVE_HITLAND
or MOVE_HITCEIL
)) or
2428 (g_Weapon_Hit(@Obj
, a
, SpawnerUID
, HIT_SOME
) <> 0) or
2433 WEAPON_IMP_FIRE
: g_GFX_QueueEffect(R_GFX_EXPLODE_IMPFIRE
, cx
- 32, cy
- 32);
2434 WEAPON_CACO_FIRE
: g_GFX_QueueEffect(R_GFX_EXPLODE_CACOFIRE
, cx
- 32, cy
- 32);
2435 WEAPON_BARON_FIRE
: g_GFX_QueueEffect(R_GFX_EXPLODE_BARONFIRE
, cx
- 32, cy
- 32);
2438 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj
.X
, Obj
.Y
);
2443 WEAPON_MANCUB_FIRE
: // Âûñòðåë Ìàíêóáóñà
2446 if WordBool(st
and MOVE_HITAIR
) then
2447 g_Obj_SetSpeed(@Obj
, 16);
2449 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2450 if WordBool(st
and (MOVE_HITWALL
or MOVE_HITLAND
or MOVE_HITCEIL
)) or
2451 (g_Weapon_Hit(@Obj
, 40, SpawnerUID
, HIT_SOME
, False) <> 0) or
2456 g_GFX_QueueEffect(R_GFX_EXPLODE_ROCKET
, cx
- 64, cy
- 64);
2458 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj
.X
, Obj
.Y
);
2462 end; // case ShotType of...
2464 // Åñëè ñíàðÿäà óæå íåò, óäàëÿåì àíèìàöèþ:
2465 if (ShotType
= 0) then
2467 if gGameSettings
.GameType
= GT_SERVER
then
2468 MH_SEND_DeleteShot(i
, Obj
.X
, Obj
.Y
, Loud
);
2469 if Animation
<> nil then
2475 else if (ShotType
<> WEAPON_FLAMETHROWER
) and ((oldvx
<> Obj
.Vel
.X
) or (oldvy
<> Obj
.Vel
.Y
)) then
2476 if gGameSettings
.GameType
= GT_SERVER
then
2477 MH_SEND_UpdateShot(i
);
2482 function g_Weapon_Danger(UID
: Word; X
, Y
: Integer; Width
, Height
: Word; Time
: Byte): Boolean;
2491 for a
:= 0 to High(Shots
) do
2492 if (Shots
[a
].ShotType
<> 0) and (Shots
[a
].SpawnerUID
<> UID
) then
2493 if ((Shots
[a
].Obj
.Vel
.Y
= 0) and (Shots
[a
].Obj
.Vel
.X
> 0) and (Shots
[a
].Obj
.X
< X
)) or
2494 (Shots
[a
].Obj
.Vel
.Y
= 0) and (Shots
[a
].Obj
.Vel
.X
< 0) and (Shots
[a
].Obj
.X
> X
) then
2495 if (Abs(X
-Shots
[a
].Obj
.X
) < Abs(Shots
[a
].Obj
.Vel
.X
*Time
)) and
2496 g_Collide(X
, Y
, Width
, Height
, X
, Shots
[a
].Obj
.Y
,
2497 Shots
[a
].Obj
.Rect
.Width
, Shots
[a
].Obj
.Rect
.Height
) and
2498 g_TraceVector(X
, Y
, Shots
[a
].Obj
.X
, Shots
[a
].Obj
.Y
) then
2505 procedure g_Weapon_SaveState (st
: TStream
);
2507 count
, i
, j
: Integer;
2509 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ ñíàðÿäîâ
2511 for i
:= 0 to High(Shots
) do if (Shots
[i
].ShotType
<> 0) then Inc(count
);
2513 // Êîëè÷åñòâî ñíàðÿäîâ
2514 utils
.WriteInt(st
, count
);
2516 if (count
= 0) then exit
;
2518 for i
:= 0 to High(Shots
) do
2520 if Shots
[i
].ShotType
<> 0 then
2522 // Ñèãíàòóðà ñíàðÿäà
2523 utils
.writeSign(st
, 'SHOT');
2524 utils
.writeInt(st
, Byte(0)); // version
2526 utils
.writeInt(st
, Byte(Shots
[i
].ShotType
));
2528 utils
.writeInt(st
, Word(Shots
[i
].Target
));
2530 utils
.writeInt(st
, Word(Shots
[i
].SpawnerUID
));
2531 // Ðàçìåð ïîëÿ Triggers
2532 utils
.writeInt(st
, Integer(Length(Shots
[i
].Triggers
)));
2533 // Òðèããåðû, àêòèâèðîâàííûå âûñòðåëîì
2534 for j
:= 0 to Length(Shots
[i
].Triggers
)-1 do utils
.writeInt(st
, LongWord(Shots
[i
].Triggers
[j
]));
2536 Obj_SaveState(st
, @Shots
[i
].Obj
);
2538 utils
.writeInt(st
, Byte(Shots
[i
].Stopped
));
2543 procedure g_Weapon_LoadState (st
: TStream
);
2545 count
, tc
, i
, j
: Integer;
2547 if (st
= nil) then exit
;
2549 // Êîëè÷åñòâî ñíàðÿäîâ
2550 count
:= utils
.readLongInt(st
);
2551 if (count
< 0) or (count
> 1024*1024) then raise XStreamError
.Create('invalid shots counter');
2553 SetLength(Shots
, count
);
2555 if (count
= 0) then exit
;
2557 for i
:= 0 to count
-1 do
2559 // Ñèãíàòóðà ñíàðÿäà
2560 if not utils
.checkSign(st
, 'SHOT') then raise XStreamError
.Create('invalid shot signature');
2561 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid shot version');
2563 Shots
[i
].ShotType
:= utils
.readByte(st
);
2565 Shots
[i
].Target
:= utils
.readWord(st
);
2567 Shots
[i
].SpawnerUID
:= utils
.readWord(st
);
2568 // Ðàçìåð ïîëÿ Triggers
2569 tc
:= utils
.readLongInt(st
);
2570 if (tc
< 0) or (tc
> 1024*1024) then raise XStreamError
.Create('invalid shot triggers counter');
2571 SetLength(Shots
[i
].Triggers
, tc
);
2572 // Òðèããåðû, àêòèâèðîâàííûå âûñòðåëîì
2573 for j
:= 0 to tc
-1 do Shots
[i
].Triggers
[j
] := utils
.readLongWord(st
);
2575 Obj_LoadState(@Shots
[i
].Obj
, st
);
2577 Shots
[i
].Stopped
:= utils
.readByte(st
);
2579 // Óñòàíîâêà òåêñòóðû èëè àíèìàöèè
2580 Shots
[i
].Animation
:= nil;
2582 case Shots
[i
].ShotType
of
2583 WEAPON_ROCKETLAUNCHER
, WEAPON_SKEL_FIRE
:
2588 Shots
[i
].Animation
:= TAnimationState
.Create(True, 5, 2); // !!! put values into table
2592 Shots
[i
].Animation
:= TAnimationState
.Create(True, 6, 2); // !!! put values into table
2596 Shots
[i
].Animation
:= TAnimationState
.Create(True, 4, 2); // !!! put values into table
2600 Shots
[i
].Animation
:= TAnimationState
.Create(True, 4, 2); // !!! put values into table
2604 Shots
[i
].Animation
:= TAnimationState
.Create(True, 4, 2); // !!! put values into table
2608 Shots
[i
].Animation
:= TAnimationState
.Create(True, 4, 2); // !!! put values into table
2612 Shots
[i
].Animation
:= TAnimationState
.Create(True, 4, 2); // !!! put values into table
2618 procedure g_Weapon_DestroyShot(I
: Integer; X
, Y
: Integer; Loud
: Boolean = True);
2620 var cx
, cy
: Integer;
2625 if (I
> High(Shots
)) or (I
< 0) then Exit
;
2629 if ShotType
= 0 then Exit
;
2633 cx
:= Obj
.X
+ (Obj
.Rect
.Width
div 2);
2634 cy
:= Obj
.Y
+ (Obj
.Rect
.Height
div 2);
2638 WEAPON_ROCKETLAUNCHER
, WEAPON_SKEL_FIRE
: // Ðàêåòû è ñíàðÿäû Ñêåëåòà
2643 if ShotType
= WEAPON_SKEL_FIRE
then
2644 g_GFX_QueueEffect(R_GFX_EXPLODE_SKELFIRE
, (Obj
.X
+ 32) - 32, (Obj
.Y
+ 8) - 32)
2646 g_GFX_QueueEffect(R_GFX_EXPLODE_ROCKET
, cx
- 64, cy
- 64);
2648 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', Obj
.X
, Obj
.Y
);
2652 WEAPON_PLASMA
, WEAPON_BSP_FIRE
: // Ïëàçìà, ïëàçìà Àðàõíàòðîíà
2657 if ShotType
= WEAPON_PLASMA
then
2658 g_GFX_QueueEffect(R_GFX_EXPLODE_PLASMA
, cx
- 16, cy
- 16)
2660 g_GFX_QueueEffect(R_GFX_EXPLODE_BSPFIRE
, cx
- 16, cy
- 16);
2662 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEPLASMA', Obj
.X
, Obj
.Y
);
2669 g_GFX_QueueEffect(R_GFX_EXPLODE_BFG
, cx
- 64, cy
- 64);
2671 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', Obj
.X
, Obj
.Y
);
2674 WEAPON_IMP_FIRE
, WEAPON_CACO_FIRE
, WEAPON_BARON_FIRE
: // Âûñòðåëû Áåñà, Êàêîäåìîíà Ðûöàðÿ/Áàðîíà àäà
2680 WEAPON_IMP_FIRE
: g_GFX_QueueEffect(R_GFX_EXPLODE_IMPFIRE
, cx
- 32, cy
- 32);
2681 WEAPON_CACO_FIRE
: g_GFX_QueueEffect(R_GFX_EXPLODE_CACOFIRE
, cx
- 32, cy
- 32);
2682 WEAPON_BARON_FIRE
: g_GFX_QueueEffect(R_GFX_EXPLODE_BARONFIRE
, cx
- 32, cy
- 32);
2685 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj
.X
, Obj
.Y
);
2689 WEAPON_MANCUB_FIRE
: // Âûñòðåë Ìàíêóáóñà
2692 g_GFX_QueueEffect(R_GFX_EXPLODE_ROCKET
, cx
- 64, cy
- 64);
2694 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj
.X
, Obj
.Y
);
2696 end; // case ShotType of...
2704 procedure g_Weapon_AddDynLights();
2708 if Shots
= nil then Exit
;
2709 for i
:= 0 to High(Shots
) do
2711 if Shots
[i
].ShotType
= 0 then continue
;
2712 if (Shots
[i
].ShotType
= WEAPON_ROCKETLAUNCHER
) or
2713 (Shots
[i
].ShotType
= WEAPON_BARON_FIRE
) or
2714 (Shots
[i
].ShotType
= WEAPON_MANCUB_FIRE
) or
2715 (Shots
[i
].ShotType
= WEAPON_SKEL_FIRE
) or
2716 (Shots
[i
].ShotType
= WEAPON_IMP_FIRE
) or
2717 (Shots
[i
].ShotType
= WEAPON_CACO_FIRE
) or
2718 (Shots
[i
].ShotType
= WEAPON_MANCUB_FIRE
) or
2719 (Shots
[i
].ShotType
= WEAPON_BSP_FIRE
) or
2720 (Shots
[i
].ShotType
= WEAPON_PLASMA
) or
2721 (Shots
[i
].ShotType
= WEAPON_BFG
) or
2722 (Shots
[i
].ShotType
= WEAPON_FLAMETHROWER
) or
2725 if (Shots
[i
].ShotType
= WEAPON_PLASMA
) then
2726 g_AddDynLight(Shots
[i
].Obj
.X
+(Shots
[i
].Obj
.Rect
.Width
div 2), Shots
[i
].Obj
.Y
+(Shots
[i
].Obj
.Rect
.Height
div 2), 128, 0, 0.3, 1, 0.4)
2727 else if (Shots
[i
].ShotType
= WEAPON_BFG
) then
2728 g_AddDynLight(Shots
[i
].Obj
.X
+(Shots
[i
].Obj
.Rect
.Width
div 2), Shots
[i
].Obj
.Y
+(Shots
[i
].Obj
.Rect
.Height
div 2), 128, 0, 1, 0, 0.5)
2729 else if (Shots
[i
].ShotType
= WEAPON_FLAMETHROWER
) then
2730 g_AddDynLight(Shots
[i
].Obj
.X
+(Shots
[i
].Obj
.Rect
.Width
div 2), Shots
[i
].Obj
.Y
+(Shots
[i
].Obj
.Rect
.Height
div 2), 42, 1, 0.8, 0, 0.4)
2732 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);
2738 procedure TShot
.positionChanged (); begin end;