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);
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);
59 procedure g_Weapon_plasma(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1; Silent
: Boolean = False);
60 procedure g_Weapon_ball1(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1; Silent
: Boolean = False);
61 procedure g_Weapon_ball2(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1; Silent
: Boolean = False);
62 procedure g_Weapon_ball7(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1; Silent
: Boolean = False);
63 procedure g_Weapon_aplasma(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1; Silent
: Boolean = False);
64 procedure g_Weapon_manfire(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1; Silent
: Boolean = False);
65 procedure g_Weapon_bfgshot(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1; Silent
: Boolean = False);
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
:= 32;
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);
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
;
1632 dx
:= IfThen(xd
> x
, -Obj
.Rect
.Width
, 0);
1633 dy
:= -(Obj
.Rect
.Height
div 2);
1635 ShotType
:= WEAPON_ROCKETLAUNCHER
;
1636 throw(find_id
, x
+dx
, y
+dy
, xd
+dx
, yd
+dy
, 12);
1642 Shots
[find_id
].SpawnerUID
:= SpawnerUID
;
1645 g_Sound_PlayExAt('SOUND_WEAPON_FIREROCKET', x
, y
);
1648 procedure g_Weapon_revf(x
, y
, xd
, yd
: Integer; SpawnerUID
, TargetUID
: Word;
1649 WID
: Integer = -1; Silent
: Boolean = False);
1655 find_id
:= FindShot()
1659 if Integer(find_id
) >= High(Shots
) then
1660 SetLength(Shots
, find_id
+ 64)
1663 with Shots
[find_id
] do
1667 Obj
.Rect
.Width
:= SHOT_SKELFIRE_WIDTH
;
1668 Obj
.Rect
.Height
:= SHOT_SKELFIRE_HEIGHT
;
1670 dx
:= -(Obj
.Rect
.Width
div 2);
1671 dy
:= -(Obj
.Rect
.Height
div 2);
1673 ShotType
:= WEAPON_SKEL_FIRE
;
1674 throw(find_id
, x
+dx
, y
+dy
, xd
+dx
, yd
+dy
, 12);
1677 target
:= TargetUID
;
1678 Animation
:= TAnimationState
.Create(True, 5, 2); // !!! put values into table
1681 Shots
[find_id
].SpawnerUID
:= SpawnerUID
;
1684 g_Sound_PlayExAt('SOUND_WEAPON_FIREREV', x
, y
);
1687 procedure g_Weapon_plasma(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1;
1688 Silent
: Boolean = False);
1694 find_id
:= FindShot()
1698 if Integer(find_id
) >= High(Shots
) then
1699 SetLength(Shots
, find_id
+ 64);
1702 with Shots
[find_id
] do
1706 Obj
.Rect
.Width
:= SHOT_PLASMA_WIDTH
;
1707 Obj
.Rect
.Height
:= SHOT_PLASMA_HEIGHT
;
1709 dx
:= IfThen(xd
>x
, -Obj
.Rect
.Width
, 0);
1710 dy
:= -(Obj
.Rect
.Height
div 2);
1712 ShotType
:= WEAPON_PLASMA
;
1713 throw(find_id
, x
+dx
, y
+dy
, xd
+dx
, yd
+dy
, 16);
1716 Animation
:= TAnimationState
.Create(True, 5, 2); // !!! put values into table
1719 Shots
[find_id
].SpawnerUID
:= SpawnerUID
;
1722 g_Sound_PlayExAt('SOUND_WEAPON_FIREPLASMA', x
, y
);
1725 procedure g_Weapon_flame(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1;
1726 Silent
: Boolean = False);
1732 find_id
:= FindShot()
1736 if Integer(find_id
) >= High(Shots
) then
1737 SetLength(Shots
, find_id
+ 64);
1740 with Shots
[find_id
] do
1744 Obj
.Rect
.Width
:= SHOT_FLAME_WIDTH
;
1745 Obj
.Rect
.Height
:= SHOT_FLAME_HEIGHT
;
1747 dx
:= IfThen(xd
>x
, -Obj
.Rect
.Width
, 0);
1748 dy
:= -(Obj
.Rect
.Height
div 2);
1750 ShotType
:= WEAPON_FLAMETHROWER
;
1751 throw(find_id
, x
+dx
, y
+dy
, xd
+dx
, yd
+dy
, 16);
1757 Shots
[find_id
].SpawnerUID
:= SpawnerUID
;
1759 // if not Silent then
1760 // g_Sound_PlayExAt('SOUND_WEAPON_FIREPLASMA', x, y);
1763 procedure g_Weapon_ball1(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1;
1764 Silent
: Boolean = False);
1770 find_id
:= FindShot()
1774 if Integer(find_id
) >= High(Shots
) then
1775 SetLength(Shots
, find_id
+ 64)
1778 with Shots
[find_id
] do
1782 Obj
.Rect
.Width
:= 16;
1783 Obj
.Rect
.Height
:= 16;
1785 dx
:= IfThen(xd
>x
, -Obj
.Rect
.Width
, 0);
1786 dy
:= -(Obj
.Rect
.Height
div 2);
1788 ShotType
:= WEAPON_IMP_FIRE
;
1789 throw(find_id
, x
+dx
, y
+dy
, xd
+dx
, yd
+dy
, 16);
1792 Animation
:= TAnimationState
.Create(True, 4, 2); // !!! put values into table
1795 Shots
[find_id
].SpawnerUID
:= SpawnerUID
;
1798 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x
, y
);
1801 procedure g_Weapon_ball2(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1;
1802 Silent
: Boolean = False);
1808 find_id
:= FindShot()
1812 if Integer(find_id
) >= High(Shots
) then
1813 SetLength(Shots
, find_id
+ 64)
1816 with Shots
[find_id
] do
1820 Obj
.Rect
.Width
:= 16;
1821 Obj
.Rect
.Height
:= 16;
1823 dx
:= IfThen(xd
>x
, -Obj
.Rect
.Width
, 0);
1824 dy
:= -(Obj
.Rect
.Height
div 2);
1826 ShotType
:= WEAPON_CACO_FIRE
;
1827 throw(find_id
, x
+dx
, y
+dy
, xd
+dx
, yd
+dy
, 16);
1830 Animation
:= TAnimationState
.Create(True, 4, 2); // !!! put values into table
1833 Shots
[find_id
].SpawnerUID
:= SpawnerUID
;
1836 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x
, y
);
1839 procedure g_Weapon_ball7(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1;
1840 Silent
: Boolean = False);
1846 find_id
:= FindShot()
1850 if Integer(find_id
) >= High(Shots
) then
1851 SetLength(Shots
, find_id
+ 64)
1854 with Shots
[find_id
] do
1858 Obj
.Rect
.Width
:= 32;
1859 Obj
.Rect
.Height
:= 16;
1861 dx
:= IfThen(xd
>x
, -Obj
.Rect
.Width
, 0);
1862 dy
:= -(Obj
.Rect
.Height
div 2);
1864 ShotType
:= WEAPON_BARON_FIRE
;
1865 throw(find_id
, x
+dx
, y
+dy
, xd
+dx
, yd
+dy
, 16);
1868 Animation
:= TAnimationState
.Create(True, 4, 2); // !!! put values into table
1871 Shots
[find_id
].SpawnerUID
:= SpawnerUID
;
1874 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x
, y
);
1877 procedure g_Weapon_aplasma(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1;
1878 Silent
: Boolean = False);
1884 find_id
:= FindShot()
1888 if Integer(find_id
) >= High(Shots
) then
1889 SetLength(Shots
, find_id
+ 64)
1892 with Shots
[find_id
] do
1896 Obj
.Rect
.Width
:= 16;
1897 Obj
.Rect
.Height
:= 16;
1899 dx
:= IfThen(xd
>x
, -Obj
.Rect
.Width
, 0);
1900 dy
:= -(Obj
.Rect
.Height
div 2);
1902 ShotType
:= WEAPON_BSP_FIRE
;
1903 throw(find_id
, x
+dx
, y
+dy
, xd
+dx
, yd
+dy
, 16);
1907 Animation
:= TAnimationState
.Create(True, 4, 2); // !!! put values into table
1910 Shots
[find_id
].SpawnerUID
:= SpawnerUID
;
1913 g_Sound_PlayExAt('SOUND_WEAPON_FIREPLASMA', x
, y
);
1916 procedure g_Weapon_manfire(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1;
1917 Silent
: Boolean = False);
1923 find_id
:= FindShot()
1927 if Integer(find_id
) >= High(Shots
) then
1928 SetLength(Shots
, find_id
+ 64)
1931 with Shots
[find_id
] do
1935 Obj
.Rect
.Width
:= 32;
1936 Obj
.Rect
.Height
:= 32;
1938 dx
:= IfThen(xd
>x
, -Obj
.Rect
.Width
, 0);
1939 dy
:= -(Obj
.Rect
.Height
div 2);
1941 ShotType
:= WEAPON_MANCUB_FIRE
;
1942 throw(find_id
, x
+dx
, y
+dy
, xd
+dx
, yd
+dy
, 16);
1946 Animation
:= TAnimationState
.Create(True, 4, 2); // !!! put values into table
1949 Shots
[find_id
].SpawnerUID
:= SpawnerUID
;
1952 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x
, y
);
1955 procedure g_Weapon_bfgshot(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word; WID
: Integer = -1;
1956 Silent
: Boolean = False);
1962 find_id
:= FindShot()
1966 if Integer(find_id
) >= High(Shots
) then
1967 SetLength(Shots
, find_id
+ 64)
1970 with Shots
[find_id
] do
1974 Obj
.Rect
.Width
:= SHOT_BFG_WIDTH
;
1975 Obj
.Rect
.Height
:= SHOT_BFG_HEIGHT
;
1977 dx
:= IfThen(xd
>x
, -Obj
.Rect
.Width
, 0);
1978 dy
:= -(Obj
.Rect
.Height
div 2);
1980 ShotType
:= WEAPON_BFG
;
1981 throw(find_id
, x
+dx
, y
+dy
, xd
+dx
, yd
+dy
, 16);
1984 Animation
:= TAnimationState
.Create(True, 6, 2); // !!! put values into table
1987 Shots
[find_id
].SpawnerUID
:= SpawnerUID
;
1990 g_Sound_PlayExAt('SOUND_WEAPON_FIREBFG', x
, y
);
1993 procedure g_Weapon_bfghit(x
, y
: Integer);
1996 g_GFX_QueueEffect(R_GFX_BFG_HIT
, x
- 32, y
- 32);
2000 procedure g_Weapon_pistol(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word;
2001 Silent
: Boolean = False);
2004 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', x
, y
);
2006 g_Weapon_gun(x
, y
, xd
, yd
, 1, 3, SpawnerUID
, True);
2007 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
] then
2009 g_Weapon_gun(x
, y
+1, xd
, yd
+1, 1, 3, SpawnerUID
, False);
2010 g_Weapon_gun(x
, y
-1, xd
, yd
-1, 1, 2, SpawnerUID
, False);
2014 procedure g_Weapon_mgun(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word;
2015 Silent
: Boolean = False);
2018 if gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', x
, y
);
2020 g_Weapon_gun(x
, y
, xd
, yd
, 1, 3, SpawnerUID
, True);
2021 if (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) and
2022 (g_GetUIDType(SpawnerUID
) = UID_PLAYER
) then
2024 g_Weapon_gun(x
, y
+1, xd
, yd
+1, 1, 2, SpawnerUID
, False);
2025 g_Weapon_gun(x
, y
-1, xd
, yd
-1, 1, 2, SpawnerUID
, False);
2029 procedure g_Weapon_shotgun(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word;
2030 Silent
: Boolean = False);
2035 if gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', x
, y
);
2039 j
:= Random(17)-8; // -8 .. 8
2040 g_Weapon_gun(x
, y
+j
, xd
, yd
+j
, IfThen(i
mod 2 <> 0, 1, 0), 3, SpawnerUID
, i
=0);
2044 procedure g_Weapon_dshotgun(x
, y
, xd
, yd
: Integer; SpawnerUID
: Word;
2045 Silent
: Boolean = False);
2050 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', x
, y
);
2052 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
] then a
:= 25 else a
:= 20;
2055 j
:= Random(41)-20; // -20 .. 20
2056 g_Weapon_gun(x
, y
+j
, xd
, yd
+j
, IfThen(i
mod 3 <> 0, 0, 1), 3, SpawnerUID
, i
=0);
2060 procedure g_Weapon_PreUpdate();
2064 if Shots
= nil then Exit
;
2065 for i
:= 0 to High(Shots
) do
2066 if Shots
[i
].ShotType
<> 0 then
2068 Shots
[i
].Obj
.oldX
:= Shots
[i
].Obj
.X
;
2069 Shots
[i
].Obj
.oldY
:= Shots
[i
].Obj
.Y
;
2073 procedure g_Weapon_Update();
2075 i
, a
, h
, cx
, cy
, oldvx
, oldvy
, tf
: Integer;
2082 var tcx
, tcy
: Integer;
2088 for i
:= 0 to High(Shots
) do
2090 if Shots
[i
].ShotType
= 0 then
2097 Timeout
:= Timeout
- 1;
2100 // Àêòèâèðîâàòü òðèããåðû ïî ïóòè (êðîìå óæå àêòèâèðîâàííûõ):
2101 if (Stopped
= 0) and g_Game_IsServer
then
2102 t
:= g_Triggers_PressR(Obj
.X
, Obj
.Y
, Obj
.Rect
.Width
, Obj
.Rect
.Height
,
2103 SpawnerUID
, ACTIVATE_SHOT
, triggers
)
2109 // Ïîïîëíÿåì ñïèñîê àêòèâèðîâàííûõ òðèããåðîâ:
2110 if triggers
= nil then
2117 if not InDWArray(t
[a
], triggers
) then
2119 SetLength(triggers
, Length(triggers
)+1);
2120 triggers
[High(triggers
)] := t
[a
];
2125 // Àíèìàöèÿ ñíàðÿäà:
2126 if Animation
<> nil then
2130 spl
:= (ShotType
<> WEAPON_PLASMA
) and
2131 (ShotType
<> WEAPON_BFG
) and
2132 (ShotType
<> WEAPON_BSP_FIRE
) and
2133 (ShotType
<> WEAPON_FLAMETHROWER
);
2137 st
:= g_Obj_Move_Projectile(@Obj
, False, spl
);
2143 positionChanged(); // this updates spatial accelerators
2145 if WordBool(st
and MOVE_FALLOUT
) or (Obj
.X
< -1000) or
2146 (Obj
.X
> gMapInfo
.Width
+1000) or (Obj
.Y
< -1000) then
2148 // Íà êëèåíòå ñêîðåå âñåãî è òàê óæå âûïàë.
2154 cx
:= Obj
.X
+ (Obj
.Rect
.Width
div 2);
2155 cy
:= Obj
.Y
+ (Obj
.Rect
.Height
div 2);
2158 WEAPON_ROCKETLAUNCHER
, WEAPON_SKEL_FIRE
: // Ðàêåòû è ñíàðÿäû Ñêåëåòà
2160 // Âûëåòåëà èç âîäû:
2161 if WordBool(st
and MOVE_HITAIR
) then
2162 g_Obj_SetSpeed(@Obj
, 12);
2165 // Â âîäå øëåéô - ïóçûðè, â âîçäóõå øëåéô - äûì:
2166 if WordBool(st
and MOVE_INWATER
) then
2168 g_GFX_Bubbles(Obj
.X
+ (Obj
.Rect
.Width
div 2), Obj
.Y
+ (Obj
.Rect
.Height
div 2), 1 + Random(3), 16, 16)
2172 g_GFX_QueueEffect(R_GFX_SMOKE_TRANS
, Obj
.X
-14+Random(9), Obj
.Y
+(Obj
.Rect
.Height
div 2)-20+Random(9));
2176 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2177 if WordBool(st
and (MOVE_HITWALL
or MOVE_HITLAND
or MOVE_HITCEIL
)) or
2178 (g_Weapon_Hit(@Obj
, 10, SpawnerUID
, HIT_SOME
, False) <> 0) or
2184 g_Weapon_Explode(cx
, cy
, 60, SpawnerUID
);
2186 if ShotType
= WEAPON_SKEL_FIRE
then
2187 begin // Âçðûâ ñíàðÿäà Ñêåëåòà
2189 g_GFX_QueueEffect(R_GFX_EXPLODE_SKELFIRE
, Obj
.X
+ 32 - 58, Obj
.Y
+ 8 - 36);
2190 g_DynLightExplosion((Obj
.X
+32), (Obj
.Y
+8), 64, 1, 0, 0);
2194 begin // Âçðûâ Ðàêåòû
2196 g_GFX_QueueEffect(R_GFX_EXPLODE_ROCKET
, cx
- 64, cy
- 64);
2197 g_DynLightExplosion(cx
, cy
, 64, 1, 0, 0);
2201 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', Obj
.X
, Obj
.Y
);
2206 if ShotType
= WEAPON_SKEL_FIRE
then
2207 begin // Ñàìîíàâîäêà ñíàðÿäà Ñêåëåòà:
2208 if GetPos(target
, @o
) then
2209 throw(i
, Obj
.X
, Obj
.Y
,
2210 o
.X
+o
.Rect
.X
+(o
.Rect
.Width
div 2)+o
.Vel
.X
+o
.Accel
.X
,
2211 o
.Y
+o
.Rect
.Y
+(o
.Rect
.Height
div 2)+o
.Vel
.Y
+o
.Accel
.Y
,
2216 WEAPON_PLASMA
, WEAPON_BSP_FIRE
: // Ïëàçìà, ïëàçìà Àðàõíàòðîíà
2218 // Ïîïàëà â âîäó - ýëåêòðîøîê ïî âîäå:
2219 if WordBool(st
and (MOVE_INWATER
or MOVE_HITWATER
)) then
2221 g_Sound_PlayExAt('SOUND_WEAPON_PLASMAWATER', Obj
.X
, Obj
.Y
);
2222 if g_Game_IsServer
then CheckTrap(i
, 10, HIT_ELECTRO
);
2228 if (ShotType
= WEAPON_PLASMA
) and
2229 (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) then
2234 if ShotType
= WEAPON_BSP_FIRE
then
2237 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2238 if WordBool(st
and (MOVE_HITWALL
or MOVE_HITLAND
or MOVE_HITCEIL
)) or
2239 (g_Weapon_Hit(@Obj
, a
, SpawnerUID
, HIT_SOME
, False) <> 0) or
2243 if ShotType
= WEAPON_PLASMA
then
2244 g_GFX_QueueEffect(R_GFX_EXPLODE_PLASMA
, cx
- 16, cy
- 16)
2246 g_GFX_QueueEffect(R_GFX_EXPLODE_BSPFIRE
, cx
- 16, cy
- 16);
2247 g_DynLightExplosion(cx
, cy
, 32, 0, 0.5, 0.5);
2249 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEPLASMA', Obj
.X
, Obj
.Y
);
2254 WEAPON_FLAMETHROWER
: // Îãíåìåò
2256 // Ñî âðåìåíåì óìèðàåò
2257 if (Timeout
< 1) then
2263 if WordBool(st
and (MOVE_HITWATER
or MOVE_INWATER
)) then
2266 if WordBool(st
and MOVE_HITWATER
) then
2270 g_GFX_QueueEffect(R_GFX_SMOKE
, cx
-4+tcx
-(R_GFX_SMOKE_WIDTH
div 2), cy
-4+tcy
-(R_GFX_SMOKE_HEIGHT
div 2));
2274 g_GFX_Bubbles(cx
, cy
, 1 + Random(3), 16, 16);
2283 Obj
.Accel
.Y
:= Obj
.Accel
.Y
+ 1;
2284 // Ïîïàëè â ñòåíó èëè â âîäó:
2285 if WordBool(st
and (MOVE_HITWALL
or MOVE_HITLAND
or MOVE_HITCEIL
or MOVE_HITWATER
)) then
2291 if WordBool(st
and MOVE_HITWALL
) then
2292 Stopped
:= MOVE_HITWALL
2293 else if WordBool(st
and MOVE_HITLAND
) then
2294 Stopped
:= MOVE_HITLAND
2295 else if WordBool(st
and MOVE_HITCEIL
) then
2296 Stopped
:= MOVE_HITCEIL
;
2299 a
:= IfThen(Stopped
= 0, 10, 1);
2300 // Åñëè â êîãî-òî ïîïàëè
2301 if g_Weapon_Hit(@Obj
, a
, SpawnerUID
, HIT_FLAME
, False) <> 0 then
2303 // HIT_FLAME ñàì ïîäîææåò
2304 // Åñëè â ïîëåòå ïîïàëè, èñ÷åçàåì
2314 if (gTime
mod LongWord(tf
) = 0) then
2318 MOVE_HITWALL
: begin tcx
:= cx
-4+Random(8); tcy
:= cy
-12+Random(24); end;
2319 MOVE_HITLAND
: begin tcx
:= cx
-12+Random(24); tcy
:= cy
-10+Random(8); end;
2320 MOVE_HITCEIL
: begin tcx
:= cx
-12+Random(24); tcy
:= cy
+6+Random(8); end;
2321 else begin tcx
:= cx
-4+Random(8); tcy
:= cy
-4+Random(8); end;
2323 g_GFX_QueueEffect(R_GFX_FLAME_RAND
, tcx
- (R_GFX_FLAME_WIDTH
div 2), tcy
- (R_GFX_FLAME_HEIGHT
div 2));
2324 //g_DynLightExplosion(tcx, tcy, 1, 1, 0.8, 0.3);
2331 // Ïîïàëà â âîäó - ýëåêòðîøîê ïî âîäå:
2332 if WordBool(st
and (MOVE_INWATER
or MOVE_HITWATER
)) then
2334 g_Sound_PlayExAt('SOUND_WEAPON_BFGWATER', Obj
.X
, Obj
.Y
);
2335 if g_Game_IsServer
then CheckTrap(i
, 1000, HIT_ELECTRO
);
2340 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2341 if WordBool(st
and (MOVE_HITWALL
or MOVE_HITLAND
or MOVE_HITCEIL
)) or
2342 (g_Weapon_Hit(@Obj
, SHOT_BFG_DAMAGE
, SpawnerUID
, HIT_BFG
, False) <> 0) or
2346 if g_Game_IsServer
then g_Weapon_BFG9000(cx
, cy
, SpawnerUID
);
2348 g_GFX_QueueEffect(R_GFX_EXPLODE_BFG
, cx
- 64, cy
- 64);
2349 g_DynLightExplosion(cx
, cy
, 96, 0, 1, 0);
2351 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', Obj
.X
, Obj
.Y
);
2356 WEAPON_IMP_FIRE
, WEAPON_CACO_FIRE
, WEAPON_BARON_FIRE
: // Âûñòðåëû Áåñà, Êàêîäåìîíà Ðûöàðÿ/Áàðîíà àäà
2359 if WordBool(st
and MOVE_HITAIR
) then
2360 g_Obj_SetSpeed(@Obj
, 16);
2363 if ShotType
= WEAPON_IMP_FIRE
then
2366 if ShotType
= WEAPON_CACO_FIRE
then
2371 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2372 if WordBool(st
and (MOVE_HITWALL
or MOVE_HITLAND
or MOVE_HITCEIL
)) or
2373 (g_Weapon_Hit(@Obj
, a
, SpawnerUID
, HIT_SOME
) <> 0) or
2378 WEAPON_IMP_FIRE
: g_GFX_QueueEffect(R_GFX_EXPLODE_IMPFIRE
, cx
- 32, cy
- 32);
2379 WEAPON_CACO_FIRE
: g_GFX_QueueEffect(R_GFX_EXPLODE_CACOFIRE
, cx
- 32, cy
- 32);
2380 WEAPON_BARON_FIRE
: g_GFX_QueueEffect(R_GFX_EXPLODE_BARONFIRE
, cx
- 32, cy
- 32);
2383 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj
.X
, Obj
.Y
);
2388 WEAPON_MANCUB_FIRE
: // Âûñòðåë Ìàíêóáóñà
2391 if WordBool(st
and MOVE_HITAIR
) then
2392 g_Obj_SetSpeed(@Obj
, 16);
2394 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2395 if WordBool(st
and (MOVE_HITWALL
or MOVE_HITLAND
or MOVE_HITCEIL
)) or
2396 (g_Weapon_Hit(@Obj
, 40, SpawnerUID
, HIT_SOME
, False) <> 0) or
2401 g_GFX_QueueEffect(R_GFX_EXPLODE_ROCKET
, cx
- 64, cy
- 64);
2403 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj
.X
, Obj
.Y
);
2407 end; // case ShotType of...
2409 // Åñëè ñíàðÿäà óæå íåò, óäàëÿåì àíèìàöèþ:
2410 if (ShotType
= 0) then
2412 if gGameSettings
.GameType
= GT_SERVER
then
2413 MH_SEND_DeleteShot(i
, Obj
.X
, Obj
.Y
, Loud
);
2414 if Animation
<> nil then
2420 else if (ShotType
<> WEAPON_FLAMETHROWER
) and ((oldvx
<> Obj
.Vel
.X
) or (oldvy
<> Obj
.Vel
.Y
)) then
2421 if gGameSettings
.GameType
= GT_SERVER
then
2422 MH_SEND_UpdateShot(i
);
2427 function g_Weapon_Danger(UID
: Word; X
, Y
: Integer; Width
, Height
: Word; Time
: Byte): Boolean;
2436 for a
:= 0 to High(Shots
) do
2437 if (Shots
[a
].ShotType
<> 0) and (Shots
[a
].SpawnerUID
<> UID
) then
2438 if ((Shots
[a
].Obj
.Vel
.Y
= 0) and (Shots
[a
].Obj
.Vel
.X
> 0) and (Shots
[a
].Obj
.X
< X
)) or
2439 (Shots
[a
].Obj
.Vel
.Y
= 0) and (Shots
[a
].Obj
.Vel
.X
< 0) and (Shots
[a
].Obj
.X
> X
) then
2440 if (Abs(X
-Shots
[a
].Obj
.X
) < Abs(Shots
[a
].Obj
.Vel
.X
*Time
)) and
2441 g_Collide(X
, Y
, Width
, Height
, X
, Shots
[a
].Obj
.Y
,
2442 Shots
[a
].Obj
.Rect
.Width
, Shots
[a
].Obj
.Rect
.Height
) and
2443 g_TraceVector(X
, Y
, Shots
[a
].Obj
.X
, Shots
[a
].Obj
.Y
) then
2450 procedure g_Weapon_SaveState (st
: TStream
);
2452 count
, i
, j
: Integer;
2454 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ ñíàðÿäîâ
2456 for i
:= 0 to High(Shots
) do if (Shots
[i
].ShotType
<> 0) then Inc(count
);
2458 // Êîëè÷åñòâî ñíàðÿäîâ
2459 utils
.WriteInt(st
, count
);
2461 if (count
= 0) then exit
;
2463 for i
:= 0 to High(Shots
) do
2465 if Shots
[i
].ShotType
<> 0 then
2467 // Ñèãíàòóðà ñíàðÿäà
2468 utils
.writeSign(st
, 'SHOT');
2469 utils
.writeInt(st
, Byte(0)); // version
2471 utils
.writeInt(st
, Byte(Shots
[i
].ShotType
));
2473 utils
.writeInt(st
, Word(Shots
[i
].Target
));
2475 utils
.writeInt(st
, Word(Shots
[i
].SpawnerUID
));
2476 // Ðàçìåð ïîëÿ Triggers
2477 utils
.writeInt(st
, Integer(Length(Shots
[i
].Triggers
)));
2478 // Òðèããåðû, àêòèâèðîâàííûå âûñòðåëîì
2479 for j
:= 0 to Length(Shots
[i
].Triggers
)-1 do utils
.writeInt(st
, LongWord(Shots
[i
].Triggers
[j
]));
2481 Obj_SaveState(st
, @Shots
[i
].Obj
);
2483 utils
.writeInt(st
, Byte(Shots
[i
].Stopped
));
2488 procedure g_Weapon_LoadState (st
: TStream
);
2490 count
, tc
, i
, j
: Integer;
2492 if (st
= nil) then exit
;
2494 // Êîëè÷åñòâî ñíàðÿäîâ
2495 count
:= utils
.readLongInt(st
);
2496 if (count
< 0) or (count
> 1024*1024) then raise XStreamError
.Create('invalid shots counter');
2498 SetLength(Shots
, count
);
2500 if (count
= 0) then exit
;
2502 for i
:= 0 to count
-1 do
2504 // Ñèãíàòóðà ñíàðÿäà
2505 if not utils
.checkSign(st
, 'SHOT') then raise XStreamError
.Create('invalid shot signature');
2506 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid shot version');
2508 Shots
[i
].ShotType
:= utils
.readByte(st
);
2510 Shots
[i
].Target
:= utils
.readWord(st
);
2512 Shots
[i
].SpawnerUID
:= utils
.readWord(st
);
2513 // Ðàçìåð ïîëÿ Triggers
2514 tc
:= utils
.readLongInt(st
);
2515 if (tc
< 0) or (tc
> 1024*1024) then raise XStreamError
.Create('invalid shot triggers counter');
2516 SetLength(Shots
[i
].Triggers
, tc
);
2517 // Òðèããåðû, àêòèâèðîâàííûå âûñòðåëîì
2518 for j
:= 0 to tc
-1 do Shots
[i
].Triggers
[j
] := utils
.readLongWord(st
);
2520 Obj_LoadState(@Shots
[i
].Obj
, st
);
2522 Shots
[i
].Stopped
:= utils
.readByte(st
);
2524 // Óñòàíîâêà òåêñòóðû èëè àíèìàöèè
2525 Shots
[i
].Animation
:= nil;
2527 case Shots
[i
].ShotType
of
2528 WEAPON_ROCKETLAUNCHER
, WEAPON_SKEL_FIRE
:
2533 Shots
[i
].Animation
:= TAnimationState
.Create(True, 5, 2); // !!! put values into table
2537 Shots
[i
].Animation
:= TAnimationState
.Create(True, 6, 2); // !!! put values into table
2541 Shots
[i
].Animation
:= TAnimationState
.Create(True, 4, 2); // !!! put values into table
2545 Shots
[i
].Animation
:= TAnimationState
.Create(True, 4, 2); // !!! put values into table
2549 Shots
[i
].Animation
:= TAnimationState
.Create(True, 4, 2); // !!! put values into table
2553 Shots
[i
].Animation
:= TAnimationState
.Create(True, 4, 2); // !!! put values into table
2557 Shots
[i
].Animation
:= TAnimationState
.Create(True, 4, 2); // !!! put values into table
2563 procedure g_Weapon_DestroyShot(I
: Integer; X
, Y
: Integer; Loud
: Boolean = True);
2565 var cx
, cy
: Integer;
2570 if (I
> High(Shots
)) or (I
< 0) then Exit
;
2574 if ShotType
= 0 then Exit
;
2578 cx
:= Obj
.X
+ (Obj
.Rect
.Width
div 2);
2579 cy
:= Obj
.Y
+ (Obj
.Rect
.Height
div 2);
2583 WEAPON_ROCKETLAUNCHER
, WEAPON_SKEL_FIRE
: // Ðàêåòû è ñíàðÿäû Ñêåëåòà
2588 if ShotType
= WEAPON_SKEL_FIRE
then
2589 g_GFX_QueueEffect(R_GFX_EXPLODE_SKELFIRE
, (Obj
.X
+ 32) - 32, (Obj
.Y
+ 8) - 32)
2591 g_GFX_QueueEffect(R_GFX_EXPLODE_ROCKET
, cx
- 64, cy
- 64);
2593 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', Obj
.X
, Obj
.Y
);
2597 WEAPON_PLASMA
, WEAPON_BSP_FIRE
: // Ïëàçìà, ïëàçìà Àðàõíàòðîíà
2602 if ShotType
= WEAPON_PLASMA
then
2603 g_GFX_QueueEffect(R_GFX_EXPLODE_PLASMA
, cx
- 16, cy
- 16)
2605 g_GFX_QueueEffect(R_GFX_EXPLODE_BSPFIRE
, cx
- 16, cy
- 16);
2607 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEPLASMA', Obj
.X
, Obj
.Y
);
2614 g_GFX_QueueEffect(R_GFX_EXPLODE_BFG
, cx
- 64, cy
- 64);
2616 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', Obj
.X
, Obj
.Y
);
2619 WEAPON_IMP_FIRE
, WEAPON_CACO_FIRE
, WEAPON_BARON_FIRE
: // Âûñòðåëû Áåñà, Êàêîäåìîíà Ðûöàðÿ/Áàðîíà àäà
2625 WEAPON_IMP_FIRE
: g_GFX_QueueEffect(R_GFX_EXPLODE_IMPFIRE
, cx
- 32, cy
- 32);
2626 WEAPON_CACO_FIRE
: g_GFX_QueueEffect(R_GFX_EXPLODE_CACOFIRE
, cx
- 32, cy
- 32);
2627 WEAPON_BARON_FIRE
: g_GFX_QueueEffect(R_GFX_EXPLODE_BARONFIRE
, cx
- 32, cy
- 32);
2630 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj
.X
, Obj
.Y
);
2634 WEAPON_MANCUB_FIRE
: // Âûñòðåë Ìàíêóáóñà
2637 g_GFX_QueueEffect(R_GFX_EXPLODE_ROCKET
, cx
- 64, cy
- 64);
2639 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj
.X
, Obj
.Y
);
2641 end; // case ShotType of...
2649 procedure g_Weapon_AddDynLights();
2653 if Shots
= nil then Exit
;
2654 for i
:= 0 to High(Shots
) do
2656 if Shots
[i
].ShotType
= 0 then continue
;
2657 if (Shots
[i
].ShotType
= WEAPON_ROCKETLAUNCHER
) or
2658 (Shots
[i
].ShotType
= WEAPON_BARON_FIRE
) or
2659 (Shots
[i
].ShotType
= WEAPON_MANCUB_FIRE
) or
2660 (Shots
[i
].ShotType
= WEAPON_SKEL_FIRE
) or
2661 (Shots
[i
].ShotType
= WEAPON_IMP_FIRE
) or
2662 (Shots
[i
].ShotType
= WEAPON_CACO_FIRE
) or
2663 (Shots
[i
].ShotType
= WEAPON_MANCUB_FIRE
) or
2664 (Shots
[i
].ShotType
= WEAPON_BSP_FIRE
) or
2665 (Shots
[i
].ShotType
= WEAPON_PLASMA
) or
2666 (Shots
[i
].ShotType
= WEAPON_BFG
) or
2667 (Shots
[i
].ShotType
= WEAPON_FLAMETHROWER
) or
2670 if (Shots
[i
].ShotType
= WEAPON_PLASMA
) then
2671 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)
2672 else if (Shots
[i
].ShotType
= WEAPON_BFG
) then
2673 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)
2674 else if (Shots
[i
].ShotType
= WEAPON_FLAMETHROWER
) then
2675 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)
2677 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);
2683 procedure TShot
.positionChanged (); begin end;