DEADSOFTWARE

map ray tracer now using grid instead of tree
[d2df-sdl.git] / src / game / g_weapons.pas
1 (* Copyright (C) DooM 2D:Forever Developers
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *)
16 {$INCLUDE ../shared/a_modes.inc}
17 {.$DEFINE GWEP_HITSCAN_TRACE_BITMAP_CHECKER}
18 unit g_weapons;
20 interface
22 uses
23 g_textures, g_basic, e_graphics, g_phys, BinEditor, xprofiler;
25 const
26 HIT_SOME = 0;
27 HIT_ROCKET = 1;
28 HIT_BFG = 2;
29 HIT_TRAP = 3;
30 HIT_FALL = 4;
31 HIT_WATER = 5;
32 HIT_ACID = 6;
33 HIT_ELECTRO = 7;
34 HIT_FLAME = 8;
35 HIT_SELF = 9;
36 HIT_DISCON = 10;
38 type
39 TShot = record
40 ShotType: Byte;
41 Target: Word;
42 SpawnerUID: Word;
43 Triggers: DWArray;
44 Obj: TObj;
45 Animation: TAnimation;
46 TextureID: DWORD;
47 Timeout: DWORD;
48 Stopped: Byte;
50 procedure positionChanged (); //WARNING! call this after monster position was changed, or coldet will not work right!
51 end;
54 var
55 Shots: array of TShot = nil;
56 LastShotID: Integer = 0;
58 procedure g_Weapon_LoadData();
59 procedure g_Weapon_FreeData();
60 procedure g_Weapon_Init();
61 procedure g_Weapon_Free();
62 function g_Weapon_Hit(obj: PObj; d: Integer; SpawnerUID: Word; t: Byte; HitCorpses: Boolean = True): Byte;
63 function g_Weapon_HitUID(UID: Word; d: Integer; SpawnerUID: Word; t: Byte): Boolean;
64 function g_Weapon_CreateShot(I: Integer; ShotType: Byte; Spawner, TargetUID: Word; X, Y, XV, YV: Integer): LongWord;
66 procedure g_Weapon_gun(const x, y, xd, yd, v, dmg: Integer; SpawnerUID: Word; CheckTrigger: Boolean);
67 procedure g_Weapon_punch(x, y: Integer; d, SpawnerUID: Word);
68 function g_Weapon_chainsaw(x, y: Integer; d, SpawnerUID: Word): Integer;
69 procedure g_Weapon_rocket(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1; Silent: Boolean = False);
70 procedure g_Weapon_revf(x, y, xd, yd: Integer; SpawnerUID, TargetUID: Word; WID: Integer = -1; Silent: Boolean = False);
71 procedure g_Weapon_flame(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1; Silent: Boolean = False);
72 procedure g_Weapon_plasma(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1; Silent: Boolean = False);
73 procedure g_Weapon_ball1(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1; Silent: Boolean = False);
74 procedure g_Weapon_ball2(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1; Silent: Boolean = False);
75 procedure g_Weapon_ball7(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1; Silent: Boolean = False);
76 procedure g_Weapon_aplasma(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1; Silent: Boolean = False);
77 procedure g_Weapon_manfire(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1; Silent: Boolean = False);
78 procedure g_Weapon_bfgshot(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1; Silent: Boolean = False);
79 procedure g_Weapon_bfghit(x, y: Integer);
80 procedure g_Weapon_pistol(x, y, xd, yd: Integer; SpawnerUID: Word; Silent: Boolean = False);
81 procedure g_Weapon_mgun(x, y, xd, yd: Integer; SpawnerUID: Word; Silent: Boolean = False);
82 procedure g_Weapon_shotgun(x, y, xd, yd: Integer; SpawnerUID: Word; Silent: Boolean = False);
83 procedure g_Weapon_dshotgun(x, y, xd, yd: Integer; SpawnerUID: Word; Silent: Boolean = False);
85 function g_Weapon_Explode(X, Y: Integer; rad: Integer; SpawnerUID: Word): Boolean;
86 procedure g_Weapon_BFG9000(X, Y: Integer; SpawnerUID: Word);
87 procedure g_Weapon_Update();
88 procedure g_Weapon_Draw();
89 function g_Weapon_Danger(UID: Word; X, Y: Integer; Width, Height: Word; Time: Byte): Boolean;
90 procedure g_Weapon_DestroyShot(I: Integer; X, Y: Integer; Loud: Boolean = True);
92 procedure g_Weapon_SaveState(var Mem: TBinMemoryWriter);
93 procedure g_Weapon_LoadState(var Mem: TBinMemoryReader);
95 procedure g_Weapon_AddDynLights();
97 const
98 WEAPON_KASTET = 0;
99 WEAPON_SAW = 1;
100 WEAPON_PISTOL = 2;
101 WEAPON_SHOTGUN1 = 3;
102 WEAPON_SHOTGUN2 = 4;
103 WEAPON_CHAINGUN = 5;
104 WEAPON_ROCKETLAUNCHER = 6;
105 WEAPON_PLASMA = 7;
106 WEAPON_BFG = 8;
107 WEAPON_SUPERPULEMET = 9;
108 WEAPON_FLAMETHROWER = 10;
109 WEAPON_ZOMBY_PISTOL = 20;
110 WEAPON_IMP_FIRE = 21;
111 WEAPON_BSP_FIRE = 22;
112 WEAPON_CACO_FIRE = 23;
113 WEAPON_BARON_FIRE = 24;
114 WEAPON_MANCUB_FIRE = 25;
115 WEAPON_SKEL_FIRE = 26;
117 WP_FIRST = WEAPON_KASTET;
118 WP_LAST = WEAPON_FLAMETHROWER;
121 var
122 gwep_debug_fast_trace: Boolean = true;
125 implementation
127 uses
128 Math, g_map, g_player, g_gfx, g_sound, g_main, g_panel,
129 g_console, SysUtils, g_options, g_game,
130 g_triggers, MAPDEF, e_log, g_monsters, g_saveload,
131 g_language, g_netmsg,
132 z_aabbtree, binheap, hashtable;
134 type
135 TWaterPanel = record
136 X, Y: Integer;
137 Width, Height: Word;
138 Active: Boolean;
139 end;
141 const
142 SHOT_ROCKETLAUNCHER_WIDTH = 14;
143 SHOT_ROCKETLAUNCHER_HEIGHT = 14;
145 SHOT_SKELFIRE_WIDTH = 14;
146 SHOT_SKELFIRE_HEIGHT = 14;
148 SHOT_PLASMA_WIDTH = 16;
149 SHOT_PLASMA_HEIGHT = 16;
151 SHOT_BFG_WIDTH = 32;
152 SHOT_BFG_HEIGHT = 32;
153 SHOT_BFG_DAMAGE = 100;
154 SHOT_BFG_RADIUS = 256;
156 SHOT_FLAME_WIDTH = 4;
157 SHOT_FLAME_HEIGHT = 4;
158 SHOT_FLAME_LIFETIME = 180;
160 SHOT_SIGNATURE = $544F4853; // 'SHOT'
162 type
163 PHitTime = ^THitTime;
164 THitTime = record
165 time: Single;
166 mon: TMonster;
167 plridx: Integer; // if mon=nil
168 end;
170 // indicies in `wgunHitTime` array
171 TBinaryHeapHitTimes = specialize TBinaryHeapBase<Integer>;
173 var
174 WaterMap: array of array of DWORD = nil;
175 wgunMonHash: THashIntInt = nil;
176 wgunHitHeap: TBinaryHeapHitTimes = nil;
177 wgunHitTime: array of THitTime = nil;
178 wgunHitTimeUsed: Integer = 0;
181 function hitTimeCompare (a, b: Integer): Boolean;
182 begin
183 if (wgunHitTime[a].time < wgunHitTime[b].time) then begin result := true; exit; end;
184 if (wgunHitTime[a].time > wgunHitTime[b].time) then begin result := false; exit; end;
185 if (wgunHitTime[a].mon <> nil) then
186 begin
187 // a is monster
188 if (wgunHitTime[b].mon = nil) then begin result := false; exit; end; // players first
189 result := (wgunHitTime[a].mon.UID < wgunHitTime[b].mon.UID); // why not?
190 end
191 else
192 begin
193 // a is player
194 if (wgunHitTime[b].mon <> nil) then begin result := true; exit; end; // players first
195 result := (wgunHitTime[a].plridx < wgunHitTime[b].plridx); // why not?
196 end;
197 end;
200 procedure appendHitTimeMon (time: Single; mon: TMonster);
201 begin
202 if (wgunHitTimeUsed = Length(wgunHitTime)) then SetLength(wgunHitTime, wgunHitTimeUsed+128);
203 wgunHitTime[wgunHitTimeUsed].time := time;
204 wgunHitTime[wgunHitTimeUsed].mon := mon;
205 wgunHitTime[wgunHitTimeUsed].plridx := -1;
206 wgunHitHeap.insert(wgunHitTimeUsed);
207 Inc(wgunHitTimeUsed);
208 end;
211 procedure appendHitTimePlr (time: Single; plridx: Integer);
212 begin
213 if (wgunHitTimeUsed = Length(wgunHitTime)) then SetLength(wgunHitTime, wgunHitTimeUsed+128);
214 wgunHitTime[wgunHitTimeUsed].time := time;
215 wgunHitTime[wgunHitTimeUsed].mon := nil;
216 wgunHitTime[wgunHitTimeUsed].plridx := plridx;
217 wgunHitHeap.insert(wgunHitTimeUsed);
218 Inc(wgunHitTimeUsed);
219 end;
222 function FindShot(): DWORD;
223 var
224 i: Integer;
225 begin
226 if Shots <> nil then
227 for i := 0 to High(Shots) do
228 if Shots[i].ShotType = 0 then
229 begin
230 Result := i;
231 LastShotID := Result;
232 Exit;
233 end;
235 if Shots = nil then
236 begin
237 SetLength(Shots, 128);
238 Result := 0;
239 end
240 else
241 begin
242 Result := High(Shots) + 1;
243 SetLength(Shots, Length(Shots) + 128);
244 end;
245 LastShotID := Result;
246 end;
248 procedure CreateWaterMap();
249 var
250 WaterArray: Array of TWaterPanel;
251 a, b, c, m: Integer;
252 ok: Boolean;
253 begin
254 if gWater = nil then
255 Exit;
257 SetLength(WaterArray, Length(gWater));
259 for a := 0 to High(gWater) do
260 begin
261 WaterArray[a].X := gWater[a].X;
262 WaterArray[a].Y := gWater[a].Y;
263 WaterArray[a].Width := gWater[a].Width;
264 WaterArray[a].Height := gWater[a].Height;
265 WaterArray[a].Active := True;
266 end;
268 g_Game_SetLoadingText(_lc[I_LOAD_WATER_MAP], High(WaterArray), False);
270 for a := 0 to High(WaterArray) do
271 if WaterArray[a].Active then
272 begin
273 WaterArray[a].Active := False;
274 m := Length(WaterMap);
275 SetLength(WaterMap, m+1);
276 SetLength(WaterMap[m], 1);
277 WaterMap[m][0] := a;
278 ok := True;
280 while ok do
281 begin
282 ok := False;
283 for b := 0 to High(WaterArray) do
284 if WaterArray[b].Active then
285 for c := 0 to High(WaterMap[m]) do
286 if g_CollideAround(WaterArray[b].X,
287 WaterArray[b].Y,
288 WaterArray[b].Width,
289 WaterArray[b].Height,
290 WaterArray[WaterMap[m][c]].X,
291 WaterArray[WaterMap[m][c]].Y,
292 WaterArray[WaterMap[m][c]].Width,
293 WaterArray[WaterMap[m][c]].Height) then
294 begin
295 WaterArray[b].Active := False;
296 SetLength(WaterMap[m],
297 Length(WaterMap[m])+1);
298 WaterMap[m][High(WaterMap[m])] := b;
299 ok := True;
300 Break;
301 end;
302 end;
304 g_Game_StepLoading();
305 end;
307 WaterArray := nil;
308 end;
311 var
312 chkTrap_pl: array [0..256] of Integer;
313 chkTrap_mn: array [0..65535] of TMonster;
315 procedure CheckTrap(ID: DWORD; dm: Integer; t: Byte);
316 var
317 //a, b, c, d, i1, i2: Integer;
318 //chkTrap_pl, chkTrap_mn: WArray;
319 plaCount: Integer = 0;
320 mnaCount: Integer = 0;
321 frameId: DWord;
324 function monsWaterCheck (mon: TMonster): Boolean;
325 begin
326 result := false; // don't stop
327 if mon.Live and mon.Collide(gWater[WaterMap[a][c]]) and (not InWArray(monidx, chkTrap_mn)) and (i2 < 1023) then //FIXME
328 begin
329 i2 += 1;
330 chkTrap_mn[i2] := monidx;
331 end;
332 end;
335 function monsWaterCheck (mon: TMonster): Boolean;
336 begin
337 result := false; // don't stop
338 if (mon.trapCheckFrameId <> frameId) then
339 begin
340 mon.trapCheckFrameId := frameId;
341 chkTrap_mn[mnaCount] := mon;
342 Inc(mnaCount);
343 end;
344 end;
346 var
347 a, b, c, d, f: Integer;
348 pan: TPanel;
349 begin
350 if (gWater = nil) or (WaterMap = nil) then Exit;
352 frameId := g_Mons_getNewTrapFrameId();
354 //i1 := -1;
355 //i2 := -1;
357 //SetLength(chkTrap_pl, 1024);
358 //SetLength(chkTrap_mn, 1024);
359 //for d := 0 to 1023 do chkTrap_pl[d] := $FFFF;
360 //for d := 0 to 1023 do chkTrap_mn[d] := $FFFF;
362 for a := 0 to High(WaterMap) do
363 begin
364 for b := 0 to High(WaterMap[a]) do
365 begin
366 pan := gWater[WaterMap[a][b]];
367 if not g_Obj_Collide(pan.X, pan.Y, pan.Width, pan.Height, @Shots[ID].Obj) then continue;
369 for c := 0 to High(WaterMap[a]) do
370 begin
371 pan := gWater[WaterMap[a][c]];
372 for d := 0 to High(gPlayers) do
373 begin
374 if (gPlayers[d] <> nil) and (gPlayers[d].Live) then
375 begin
376 if gPlayers[d].Collide(pan) then
377 begin
378 f := 0;
379 while (f < plaCount) and (chkTrap_pl[f] <> d) do Inc(f);
380 if (f = plaCount) then
381 begin
382 chkTrap_pl[plaCount] := d;
383 Inc(plaCount);
384 if (plaCount = Length(chkTrap_pl)) then break;
385 end;
386 end;
387 end;
388 end;
390 //g_Mons_ForEach(monsWaterCheck);
391 g_Mons_ForEachAliveAt(pan.X, pan.Y, pan.Width, pan.Height, monsWaterCheck);
392 end;
394 for f := 0 to plaCount-1 do gPlayers[chkTrap_pl[f]].Damage(dm, Shots[ID].SpawnerUID, 0, 0, t);
395 for f := 0 to mnaCount-1 do chkTrap_mn[f].Damage(dm, 0, 0, Shots[ID].SpawnerUID, t);
396 end;
397 end;
399 //chkTrap_pl := nil;
400 //chkTrap_mn := nil;
401 end;
403 function HitMonster(m: TMonster; d: Integer; vx, vy: Integer; SpawnerUID: Word; t: Byte): Boolean;
404 var
405 tt, mt: Byte;
406 mon: TMonster;
407 begin
408 Result := False;
410 tt := g_GetUIDType(SpawnerUID);
411 if tt = UID_MONSTER then
412 begin
413 mon := g_Monsters_ByUID(SpawnerUID);
414 if mon <> nil then
415 mt := g_Monsters_ByUID(SpawnerUID).MonsterType
416 else
417 mt := 0;
418 end
419 else
420 mt := 0;
422 if m = nil then Exit;
423 if m.UID = SpawnerUID then
424 begin
425 // Ñàì ñåáÿ ìîæåò ðàíèòü òîëüêî ðàêåòîé è òîêîì:
426 if (t <> HIT_ROCKET) and (t <> HIT_ELECTRO) then
427 Exit;
428 // Êèáåð äåìîí è áî÷êà âîîáùå íå ìîãóò ñåáÿ ðàíèòü:
429 if (m.MonsterType = MONSTER_CYBER) or
430 (m.MonsterType = MONSTER_BARREL) then
431 begin
432 Result := True;
433 Exit;
434 end;
435 end;
437 if tt = UID_MONSTER then
438 begin
439 // Lost_Soul íå ìîæåò ðàíèòü Pain_Elemental'à:
440 if (mt = MONSTER_SOUL) and (m.MonsterType = MONSTER_PAIN) then
441 Exit;
443 // Îáà ìîíñòðà îäíîãî âèäà:
444 if mt = m.MonsterType then
445 case mt of
446 MONSTER_IMP, MONSTER_DEMON, MONSTER_BARON, MONSTER_KNIGHT, MONSTER_CACO,
447 MONSTER_SOUL, MONSTER_MANCUB, MONSTER_SKEL, MONSTER_FISH:
448 Exit; // Ýòè íå áüþò ñâîèõ
449 end;
450 end;
452 if g_Game_IsServer then
453 begin
454 if (t <> HIT_FLAME) or (m.FFireTime = 0) or (vx <> 0) or (vy <> 0) then
455 Result := m.Damage(d, vx, vy, SpawnerUID, t)
456 else
457 Result := True;
458 if t = HIT_FLAME then
459 m.CatchFire(SpawnerUID);
460 end
461 else
462 Result := True;
463 end;
466 function HitPlayer (p: TPlayer; d: Integer; vx, vy: Integer; SpawnerUID: Word; t: Byte): Boolean;
467 begin
468 result := False;
470 // Ñàì ñåáÿ ìîæåò ðàíèòü òîëüêî ðàêåòîé è òîêîì
471 if (p.UID = SpawnerUID) and (t <> HIT_ROCKET) and (t <> HIT_ELECTRO) then exit;
473 if g_Game_IsServer then
474 begin
475 if (t <> HIT_FLAME) or (p.FFireTime = 0) or (vx <> 0) or (vy <> 0) then p.Damage(d, SpawnerUID, vx, vy, t);
476 if (t = HIT_FLAME) then p.CatchFire(SpawnerUID);
477 end;
479 result := true;
480 end;
483 procedure g_Weapon_BFG9000(X, Y: Integer; SpawnerUID: Word);
485 function monsCheck (mon: TMonster): Boolean;
486 begin
487 result := false; // don't stop
488 if (mon.Live) and (mon.UID <> SpawnerUID) then
489 begin
490 with mon do
491 begin
492 if (g_PatchLength(X, Y, Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2),
493 Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)) <= SHOT_BFG_RADIUS) and
494 g_TraceVector(X, Y, Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2),
495 Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)) then
496 begin
497 if HitMonster(mon, 50, 0, 0, SpawnerUID, HIT_SOME) then mon.BFGHit();
498 end;
499 end;
500 end;
501 end;
503 var
504 i, h: Integer;
505 st: Byte;
506 pl: TPlayer;
507 b: Boolean;
508 begin
509 //g_Sound_PlayEx('SOUND_WEAPON_EXPLODEBFG', 255);
511 h := High(gCorpses);
513 if gAdvCorpses and (h <> -1) then
514 for i := 0 to h do
515 if (gCorpses[i] <> nil) and (gCorpses[i].State <> CORPSE_STATE_REMOVEME) then
516 with gCorpses[i] do
517 if (g_PatchLength(X, Y, Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2),
518 Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)) <= SHOT_BFG_RADIUS) and
519 g_TraceVector(X, Y, Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2),
520 Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)) then
521 begin
522 Damage(50, 0, 0);
523 g_Weapon_BFGHit(Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2),
524 Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2));
525 end;
527 st := TEAM_NONE;
528 pl := g_Player_Get(SpawnerUID);
529 if pl <> nil then
530 st := pl.Team;
532 h := High(gPlayers);
534 if h <> -1 then
535 for i := 0 to h do
536 if (gPlayers[i] <> nil) and (gPlayers[i].Live) and (gPlayers[i].UID <> SpawnerUID) then
537 with gPlayers[i] do
538 if (g_PatchLength(X, Y, GameX+PLAYER_RECT.X+(PLAYER_RECT.Width div 2),
539 GameY+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)) <= SHOT_BFG_RADIUS) and
540 g_TraceVector(X, Y, GameX+PLAYER_RECT.X+(PLAYER_RECT.Width div 2),
541 GameY+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)) then
542 begin
543 if (st = TEAM_NONE) or (st <> gPlayers[i].Team) then
544 b := HitPlayer(gPlayers[i], 50, 0, 0, SpawnerUID, HIT_SOME)
545 else
546 b := HitPlayer(gPlayers[i], 25, 0, 0, SpawnerUID, HIT_SOME);
547 if b then
548 gPlayers[i].BFGHit();
549 end;
551 //FIXME
552 g_Mons_ForEachAlive(monsCheck);
553 end;
555 function g_Weapon_CreateShot(I: Integer; ShotType: Byte; Spawner, TargetUID: Word; X, Y, XV, YV: Integer): LongWord;
556 var
557 find_id, FramesID: DWORD;
558 begin
559 if I < 0 then
560 find_id := FindShot()
561 else
562 begin
563 find_id := I;
564 if Integer(find_id) >= High(Shots) then
565 SetLength(Shots, find_id + 64)
566 end;
568 case ShotType of
569 WEAPON_ROCKETLAUNCHER:
570 begin
571 with Shots[find_id] do
572 begin
573 g_Obj_Init(@Obj);
575 Obj.Rect.Width := SHOT_ROCKETLAUNCHER_WIDTH;
576 Obj.Rect.Height := SHOT_ROCKETLAUNCHER_HEIGHT;
578 Animation := nil;
579 Triggers := nil;
580 ShotType := WEAPON_ROCKETLAUNCHER;
581 g_Texture_Get('TEXTURE_WEAPON_ROCKET', TextureID);
582 end;
583 end;
585 WEAPON_PLASMA:
586 begin
587 with Shots[find_id] do
588 begin
589 g_Obj_Init(@Obj);
591 Obj.Rect.Width := SHOT_PLASMA_WIDTH;
592 Obj.Rect.Height := SHOT_PLASMA_HEIGHT;
594 Triggers := nil;
595 ShotType := WEAPON_PLASMA;
596 g_Frames_Get(FramesID, 'FRAMES_WEAPON_PLASMA');
597 Animation := TAnimation.Create(FramesID, True, 5);
598 end;
599 end;
601 WEAPON_BFG:
602 begin
603 with Shots[find_id] do
604 begin
605 g_Obj_Init(@Obj);
607 Obj.Rect.Width := SHOT_BFG_WIDTH;
608 Obj.Rect.Height := SHOT_BFG_HEIGHT;
610 Triggers := nil;
611 ShotType := WEAPON_BFG;
612 g_Frames_Get(FramesID, 'FRAMES_WEAPON_BFG');
613 Animation := TAnimation.Create(FramesID, True, 6);
614 end;
615 end;
617 WEAPON_FLAMETHROWER:
618 begin
619 with Shots[find_id] do
620 begin
621 g_Obj_Init(@Obj);
623 Obj.Rect.Width := SHOT_FLAME_WIDTH;
624 Obj.Rect.Height := SHOT_FLAME_HEIGHT;
626 Triggers := nil;
627 ShotType := WEAPON_FLAMETHROWER;
628 Animation := nil;
629 TextureID := 0;
630 g_Frames_Get(TextureID, 'FRAMES_FLAME');
631 end;
632 end;
634 WEAPON_IMP_FIRE:
635 begin
636 with Shots[find_id] do
637 begin
638 g_Obj_Init(@Obj);
640 Obj.Rect.Width := 16;
641 Obj.Rect.Height := 16;
643 Triggers := nil;
644 ShotType := WEAPON_IMP_FIRE;
645 g_Frames_Get(FramesID, 'FRAMES_WEAPON_IMPFIRE');
646 Animation := TAnimation.Create(FramesID, True, 4);
647 end;
648 end;
650 WEAPON_CACO_FIRE:
651 begin
652 with Shots[find_id] do
653 begin
654 g_Obj_Init(@Obj);
656 Obj.Rect.Width := 16;
657 Obj.Rect.Height := 16;
659 Triggers := nil;
660 ShotType := WEAPON_CACO_FIRE;
661 g_Frames_Get(FramesID, 'FRAMES_WEAPON_CACOFIRE');
662 Animation := TAnimation.Create(FramesID, True, 4);
663 end;
664 end;
666 WEAPON_MANCUB_FIRE:
667 begin
668 with Shots[find_id] do
669 begin
670 g_Obj_Init(@Obj);
672 Obj.Rect.Width := 32;
673 Obj.Rect.Height := 32;
675 Triggers := nil;
676 ShotType := WEAPON_MANCUB_FIRE;
677 g_Frames_Get(FramesID, 'FRAMES_WEAPON_MANCUBFIRE');
678 Animation := TAnimation.Create(FramesID, True, 4);
679 end;
680 end;
682 WEAPON_BARON_FIRE:
683 begin
684 with Shots[find_id] do
685 begin
686 g_Obj_Init(@Obj);
688 Obj.Rect.Width := 32;
689 Obj.Rect.Height := 16;
691 Triggers := nil;
692 ShotType := WEAPON_BARON_FIRE;
693 g_Frames_Get(FramesID, 'FRAMES_WEAPON_BARONFIRE');
694 Animation := TAnimation.Create(FramesID, True, 4);
695 end;
696 end;
698 WEAPON_BSP_FIRE:
699 begin
700 with Shots[find_id] do
701 begin
702 g_Obj_Init(@Obj);
704 Obj.Rect.Width := 16;
705 Obj.Rect.Height := 16;
707 Triggers := nil;
708 ShotType := WEAPON_BSP_FIRE;
709 g_Frames_Get(FramesID, 'FRAMES_WEAPON_BSPFIRE');
710 Animation := TAnimation.Create(FramesID, True, 4);
711 end;
712 end;
714 WEAPON_SKEL_FIRE:
715 begin
716 with Shots[find_id] do
717 begin
718 g_Obj_Init(@Obj);
720 Obj.Rect.Width := SHOT_SKELFIRE_WIDTH;
721 Obj.Rect.Height := SHOT_SKELFIRE_HEIGHT;
723 Triggers := nil;
724 ShotType := WEAPON_SKEL_FIRE;
725 target := TargetUID;
726 g_Frames_Get(FramesID, 'FRAMES_WEAPON_SKELFIRE');
727 Animation := TAnimation.Create(FramesID, True, 5);
728 end;
729 end;
730 end;
732 Shots[find_id].Obj.X := X;
733 Shots[find_id].Obj.Y := Y;
734 Shots[find_id].Obj.Vel.X := XV;
735 Shots[find_id].Obj.Vel.Y := YV;
736 Shots[find_id].Obj.Accel.X := 0;
737 Shots[find_id].Obj.Accel.Y := 0;
738 Shots[find_id].SpawnerUID := Spawner;
739 if (ShotType = WEAPON_FLAMETHROWER) and (XV = 0) and (YV = 0) then
740 Shots[find_id].Stopped := 255
741 else
742 Shots[find_id].Stopped := 0;
743 Result := find_id;
744 end;
746 procedure throw(i, x, y, xd, yd, s: Integer);
747 var
748 a: Integer;
749 begin
750 yd := yd - y;
751 xd := xd - x;
753 a := Max(Abs(xd), Abs(yd));
754 if a = 0 then
755 a := 1;
757 Shots[i].Obj.X := x;
758 Shots[i].Obj.Y := y;
759 Shots[i].Obj.Vel.X := (xd*s) div a;
760 Shots[i].Obj.Vel.Y := (yd*s) div a;
761 Shots[i].Obj.Accel.X := 0;
762 Shots[i].Obj.Accel.Y := 0;
763 Shots[i].Stopped := 0;
764 if Shots[i].ShotType in [WEAPON_ROCKETLAUNCHER, WEAPON_BFG] then
765 Shots[i].Timeout := 900 // ~25 sec
766 else
767 begin
768 if Shots[i].ShotType = WEAPON_FLAMETHROWER then
769 Shots[i].Timeout := SHOT_FLAME_LIFETIME
770 else
771 Shots[i].Timeout := 550; // ~15 sec
772 end;
773 end;
775 function g_Weapon_Hit(obj: PObj; d: Integer; SpawnerUID: Word; t: Byte; HitCorpses: Boolean = True): Byte;
776 var
777 i, h: Integer;
779 function PlayerHit(Team: Byte = 0): Boolean;
780 var
781 i: Integer;
782 ChkTeam: Boolean;
783 p: TPlayer;
784 begin
785 Result := False;
786 h := High(gPlayers);
788 if h <> -1 then
789 for i := 0 to h do
790 if (gPlayers[i] <> nil) and gPlayers[i].Live and g_Obj_Collide(obj, @gPlayers[i].Obj) then
791 begin
792 ChkTeam := True;
793 if (Team > 0) and (g_GetUIDType(SpawnerUID) = UID_PLAYER) then
794 begin
795 p := g_Player_Get(SpawnerUID);
796 if p <> nil then
797 ChkTeam := (p.Team = gPlayers[i].Team) xor (Team = 2);
798 end;
799 if ChkTeam then
800 if HitPlayer(gPlayers[i], d, obj^.Vel.X, obj^.Vel.Y, SpawnerUID, t) then
801 begin
802 if t <> HIT_FLAME then
803 gPlayers[i].Push((obj^.Vel.X+obj^.Accel.X)*IfThen(t = HIT_BFG, 8, 1) div 4,
804 (obj^.Vel.Y+obj^.Accel.Y)*IfThen(t = HIT_BFG, 8, 1) div 4);
805 if t = HIT_BFG then
806 g_Game_DelayEvent(DE_BFGHIT, 1000, SpawnerUID);
807 Result := True;
808 break;
809 end;
810 end;
811 end;
814 function monsCheckHit (monidx: Integer; mon: TMonster): Boolean;
815 begin
816 result := false; // don't stop
817 if mon.Live and g_Obj_Collide(obj, @mon.Obj) then
818 begin
819 if HitMonster(mon, d, obj^.Vel.X, obj^.Vel.Y, SpawnerUID, t) then
820 begin
821 if (t <> HIT_FLAME) then
822 begin
823 mon.Push((obj^.Vel.X+obj^.Accel.X)*IfThen(t = HIT_BFG, 8, 1) div 4,
824 (obj^.Vel.Y+obj^.Accel.Y)*IfThen(t = HIT_BFG, 8, 1) div 4);
825 end;
826 result := True;
827 end;
828 end;
829 end;
832 function monsCheckHit (mon: TMonster): Boolean;
833 begin
834 result := false; // don't stop
835 if HitMonster(mon, d, obj.Vel.X, obj.Vel.Y, SpawnerUID, t) then
836 begin
837 if (t <> HIT_FLAME) then
838 begin
839 mon.Push((obj.Vel.X+obj.Accel.X)*IfThen(t = HIT_BFG, 8, 1) div 4,
840 (obj.Vel.Y+obj.Accel.Y)*IfThen(t = HIT_BFG, 8, 1) div 4);
841 end;
842 result := true;
843 end;
844 end;
846 function MonsterHit(): Boolean;
847 begin
848 //result := g_Mons_ForEach(monsCheckHit);
849 //FIXME: accelerate this!
850 result := g_Mons_ForEachAliveAt(obj.X+obj.Rect.X, obj.Y+obj.Rect.Y, obj.Rect.Width, obj.Rect.Height, monsCheckHit);
851 end;
853 begin
854 Result := 0;
856 if HitCorpses then
857 begin
858 h := High(gCorpses);
860 if gAdvCorpses and (h <> -1) then
861 for i := 0 to h do
862 if (gCorpses[i] <> nil) and (gCorpses[i].State <> CORPSE_STATE_REMOVEME) and
863 g_Obj_Collide(obj, @gCorpses[i].Obj) then
864 begin
865 // Ðàñïèëèâàåì òðóï:
866 gCorpses[i].Damage(d, (obj^.Vel.X+obj^.Accel.X) div 4,
867 (obj^.Vel.Y+obj^.Accel.Y) div 4);
868 Result := 1;
869 end;
870 end;
872 case gGameSettings.GameMode of
873 // Êàìïàíèÿ:
874 GM_COOP, GM_SINGLE:
875 begin
876 // Ñíà÷àëà áü¸ì ìîíñòðîâ, åñëè åñòü, ïîòîì ïûòàåìñÿ áèòü èãðîêîâ
877 if MonsterHit() then
878 begin
879 Result := 2;
880 Exit;
881 end;
883 if PlayerHit() then
884 begin
885 Result := 1;
886 Exit;
887 end;
888 end;
890 // Äåçìàò÷:
891 GM_DM:
892 begin
893 // Ñíà÷àëà áü¸ì èãðîêîâ, åñëè åñòü, ïîòîì ïûòàåìñÿ áèòü ìîíñòðîâ
894 if PlayerHit() then
895 begin
896 Result := 1;
897 Exit;
898 end;
900 if MonsterHit() then
901 begin
902 Result := 2;
903 Exit;
904 end;
905 end;
907 // Êîìàíäíûå:
908 GM_TDM, GM_CTF:
909 begin
910 // Ñíà÷àëà áü¸ì èãðîêîâ êîìàíäû ñîïåðíèêà
911 if PlayerHit(2) then
912 begin
913 Result := 1;
914 Exit;
915 end;
917 // Ïîòîì ìîíñòðîâ
918 if MonsterHit() then
919 begin
920 Result := 2;
921 Exit;
922 end;
924 // È â êîíöå ñâîèõ èãðîêîâ
925 if PlayerHit(1) then
926 begin
927 Result := 1;
928 Exit;
929 end;
930 end;
932 end;
933 end;
935 function g_Weapon_HitUID(UID: Word; d: Integer; SpawnerUID: Word; t: Byte): Boolean;
936 begin
937 Result := False;
939 case g_GetUIDType(UID) of
940 UID_PLAYER: Result := HitPlayer(g_Player_Get(UID), d, 0, 0, SpawnerUID, t);
941 UID_MONSTER: Result := HitMonster(g_Monsters_ByUID(UID), d, 0, 0, SpawnerUID, t);
942 else Exit;
943 end;
944 end;
946 function g_Weapon_Explode(X, Y: Integer; rad: Integer; SpawnerUID: Word): Boolean;
947 var
948 r: Integer; // squared radius
950 function monsExCheck (mon: TMonster): Boolean;
951 var
952 dx, dy, mm: Integer;
953 begin
954 result := false; // don't stop
955 begin
956 dx := mon.Obj.X+mon.Obj.Rect.X+(mon.Obj.Rect.Width div 2)-X;
957 dy := mon.Obj.Y+mon.Obj.Rect.Y+(mon.Obj.Rect.Height div 2)-Y;
959 if dx > 1000 then dx := 1000;
960 if dy > 1000 then dy := 1000;
962 if (dx*dx+dy*dy < r) then
963 begin
964 //m := PointToRect(X, Y, Obj.X+Obj.Rect.X, Obj.Y+Obj.Rect.Y, Obj.Rect.Width, Obj.Rect.Height);
965 //e_WriteLog(Format('explo monster #%d: x=%d; y=%d; rad=%d; dx=%d; dy=%d', [monidx, X, Y, rad, dx, dy]), MSG_NOTIFY);
967 mm := Max(abs(dx), abs(dy));
968 if mm = 0 then mm := 1;
970 if mon.Live then
971 begin
972 HitMonster(mon, ((mon.Obj.Rect.Width div 4)*10*(rad-mm)) div rad, 0, 0, SpawnerUID, HIT_ROCKET);
973 end;
975 mon.Push((dx*7) div mm, (dy*7) div mm);
976 end;
977 end;
978 end;
980 var
981 i, h, dx, dy, m, mm: Integer;
982 _angle: SmallInt;
983 begin
984 result := false;
986 g_Triggers_PressC(X, Y, rad, SpawnerUID, ACTIVATE_SHOT);
988 r := rad*rad;
990 h := High(gPlayers);
992 if h <> -1 then
993 for i := 0 to h do
994 if (gPlayers[i] <> nil) and gPlayers[i].Live then
995 with gPlayers[i] do
996 begin
997 dx := Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2)-X;
998 dy := Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)-Y;
1000 if dx > 1000 then dx := 1000;
1001 if dy > 1000 then dy := 1000;
1003 if dx*dx+dy*dy < r then
1004 begin
1005 //m := PointToRect(X, Y, GameX+PLAYER_RECT.X, GameY+PLAYER_RECT.Y,
1006 // PLAYER_RECT.Width, PLAYER_RECT.Height);
1008 mm := Max(abs(dx), abs(dy));
1009 if mm = 0 then mm := 1;
1011 HitPlayer(gPlayers[i], (100*(rad-mm)) div rad, (dx*10) div mm, (dy*10) div mm, SpawnerUID, HIT_ROCKET);
1012 gPlayers[i].Push((dx*7) div mm, (dy*7) div mm);
1013 end;
1014 end;
1016 //g_Mons_ForEach(monsExCheck);
1017 g_Mons_ForEachAt(X-(rad+32), Y-(rad+32), (rad+32)*2, (rad+32)*2, monsExCheck);
1019 h := High(gCorpses);
1021 if gAdvCorpses and (h <> -1) then
1022 for i := 0 to h do
1023 if (gCorpses[i] <> nil) and (gCorpses[i].State <> CORPSE_STATE_REMOVEME) then
1024 with gCorpses[i] do
1025 begin
1026 dx := Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2)-X;
1027 dy := Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)-Y;
1029 if dx > 1000 then dx := 1000;
1030 if dy > 1000 then dy := 1000;
1032 if dx*dx+dy*dy < r then
1033 begin
1034 m := PointToRect(X, Y, Obj.X+Obj.Rect.X, Obj.Y+Obj.Rect.Y,
1035 Obj.Rect.Width, Obj.Rect.Height);
1037 mm := Max(abs(dx), abs(dy));
1038 if mm = 0 then mm := 1;
1040 Damage(Round(100*(rad-m)/rad), (dx*10) div mm, (dy*10) div mm);
1041 end;
1042 end;
1044 h := High(gGibs);
1046 if gAdvGibs and (h <> -1) then
1047 for i := 0 to h do
1048 if gGibs[i].Live then
1049 with gGibs[i] do
1050 begin
1051 dx := Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2)-X;
1052 dy := Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)-Y;
1054 if dx > 1000 then dx := 1000;
1055 if dy > 1000 then dy := 1000;
1057 if dx*dx+dy*dy < r then
1058 begin
1059 m := PointToRect(X, Y, Obj.X+Obj.Rect.X, Obj.Y+Obj.Rect.Y,
1060 Obj.Rect.Width, Obj.Rect.Height);
1061 _angle := GetAngle(Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2),
1062 Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2), X, Y);
1064 g_Obj_PushA(@Obj, Round(15*(rad-m)/rad), _angle);
1065 positionChanged(); // this updates spatial accelerators
1066 end;
1067 end;
1068 end;
1070 procedure g_Weapon_Init();
1071 begin
1072 CreateWaterMap();
1073 end;
1075 procedure g_Weapon_Free();
1076 var
1077 i: Integer;
1078 begin
1079 if Shots <> nil then
1080 begin
1081 for i := 0 to High(Shots) do
1082 if Shots[i].ShotType <> 0 then
1083 Shots[i].Animation.Free();
1085 Shots := nil;
1086 end;
1088 WaterMap := nil;
1089 end;
1091 procedure g_Weapon_LoadData();
1092 begin
1093 e_WriteLog('Loading weapons data...', MSG_NOTIFY);
1095 g_Sound_CreateWADEx('SOUND_WEAPON_HITPUNCH', GameWAD+':SOUNDS\HITPUNCH');
1096 g_Sound_CreateWADEx('SOUND_WEAPON_MISSPUNCH', GameWAD+':SOUNDS\MISSPUNCH');
1097 g_Sound_CreateWADEx('SOUND_WEAPON_HITBERSERK', GameWAD+':SOUNDS\HITBERSERK');
1098 g_Sound_CreateWADEx('SOUND_WEAPON_MISSBERSERK', GameWAD+':SOUNDS\MISSBERSERK');
1099 g_Sound_CreateWADEx('SOUND_WEAPON_SELECTSAW', GameWAD+':SOUNDS\SELECTSAW');
1100 g_Sound_CreateWADEx('SOUND_WEAPON_IDLESAW', GameWAD+':SOUNDS\IDLESAW');
1101 g_Sound_CreateWADEx('SOUND_WEAPON_HITSAW', GameWAD+':SOUNDS\HITSAW');
1102 g_Sound_CreateWADEx('SOUND_WEAPON_FIRESHOTGUN2', GameWAD+':SOUNDS\FIRESHOTGUN2');
1103 g_Sound_CreateWADEx('SOUND_WEAPON_FIRESHOTGUN', GameWAD+':SOUNDS\FIRESHOTGUN');
1104 g_Sound_CreateWADEx('SOUND_WEAPON_FIRESAW', GameWAD+':SOUNDS\FIRESAW');
1105 g_Sound_CreateWADEx('SOUND_WEAPON_FIREROCKET', GameWAD+':SOUNDS\FIREROCKET');
1106 g_Sound_CreateWADEx('SOUND_WEAPON_FIREPLASMA', GameWAD+':SOUNDS\FIREPLASMA');
1107 g_Sound_CreateWADEx('SOUND_WEAPON_FIREPISTOL', GameWAD+':SOUNDS\FIREPISTOL');
1108 g_Sound_CreateWADEx('SOUND_WEAPON_FIRECGUN', GameWAD+':SOUNDS\FIRECGUN');
1109 g_Sound_CreateWADEx('SOUND_WEAPON_FIREBFG', GameWAD+':SOUNDS\FIREBFG');
1110 g_Sound_CreateWADEx('SOUND_FIRE', GameWAD+':SOUNDS\FIRE');
1111 g_Sound_CreateWADEx('SOUND_WEAPON_STARTFIREBFG', GameWAD+':SOUNDS\STARTFIREBFG');
1112 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEROCKET', GameWAD+':SOUNDS\EXPLODEROCKET');
1113 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEBFG', GameWAD+':SOUNDS\EXPLODEBFG');
1114 g_Sound_CreateWADEx('SOUND_WEAPON_BFGWATER', GameWAD+':SOUNDS\BFGWATER');
1115 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEPLASMA', GameWAD+':SOUNDS\EXPLODEPLASMA');
1116 g_Sound_CreateWADEx('SOUND_WEAPON_PLASMAWATER', GameWAD+':SOUNDS\PLASMAWATER');
1117 g_Sound_CreateWADEx('SOUND_WEAPON_FIREBALL', GameWAD+':SOUNDS\FIREBALL');
1118 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEBALL', GameWAD+':SOUNDS\EXPLODEBALL');
1119 g_Sound_CreateWADEx('SOUND_WEAPON_FIREREV', GameWAD+':SOUNDS\FIREREV');
1120 g_Sound_CreateWADEx('SOUND_PLAYER_JETFLY', GameWAD+':SOUNDS\WORKJETPACK');
1121 g_Sound_CreateWADEx('SOUND_PLAYER_JETON', GameWAD+':SOUNDS\STARTJETPACK');
1122 g_Sound_CreateWADEx('SOUND_PLAYER_JETOFF', GameWAD+':SOUNDS\STOPJETPACK');
1123 g_Sound_CreateWADEx('SOUND_PLAYER_CASING1', GameWAD+':SOUNDS\CASING1');
1124 g_Sound_CreateWADEx('SOUND_PLAYER_CASING2', GameWAD+':SOUNDS\CASING2');
1125 g_Sound_CreateWADEx('SOUND_PLAYER_SHELL1', GameWAD+':SOUNDS\SHELL1');
1126 g_Sound_CreateWADEx('SOUND_PLAYER_SHELL2', GameWAD+':SOUNDS\SHELL2');
1128 g_Texture_CreateWADEx('TEXTURE_WEAPON_ROCKET', GameWAD+':TEXTURES\BROCKET');
1129 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_SKELFIRE', GameWAD+':TEXTURES\BSKELFIRE', 64, 16, 2);
1130 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_BFG', GameWAD+':TEXTURES\BBFG', 64, 64, 2);
1131 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_PLASMA', GameWAD+':TEXTURES\BPLASMA', 16, 16, 2);
1132 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_IMPFIRE', GameWAD+':TEXTURES\BIMPFIRE', 16, 16, 2);
1133 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_BSPFIRE', GameWAD+':TEXTURES\BBSPFIRE', 16, 16, 2);
1134 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_CACOFIRE', GameWAD+':TEXTURES\BCACOFIRE', 16, 16, 2);
1135 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_BARONFIRE', GameWAD+':TEXTURES\BBARONFIRE', 64, 16, 2);
1136 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_MANCUBFIRE', GameWAD+':TEXTURES\BMANCUBFIRE', 64, 32, 2);
1137 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_ROCKET', GameWAD+':TEXTURES\EROCKET', 128, 128, 6);
1138 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_SKELFIRE', GameWAD+':TEXTURES\ESKELFIRE', 64, 64, 3);
1139 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_BFG', GameWAD+':TEXTURES\EBFG', 128, 128, 6);
1140 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_IMPFIRE', GameWAD+':TEXTURES\EIMPFIRE', 64, 64, 3);
1141 g_Frames_CreateWAD(nil, 'FRAMES_BFGHIT', GameWAD+':TEXTURES\BFGHIT', 64, 64, 4);
1142 g_Frames_CreateWAD(nil, 'FRAMES_FIRE', GameWAD+':TEXTURES\FIRE', 64, 128, 8);
1143 g_Frames_CreateWAD(nil, 'FRAMES_FLAME', GameWAD+':TEXTURES\FLAME', 32, 32, 11);
1144 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_PLASMA', GameWAD+':TEXTURES\EPLASMA', 32, 32, 4, True);
1145 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_BSPFIRE', GameWAD+':TEXTURES\EBSPFIRE', 32, 32, 5);
1146 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_CACOFIRE', GameWAD+':TEXTURES\ECACOFIRE', 64, 64, 3);
1147 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_BARONFIRE', GameWAD+':TEXTURES\EBARONFIRE', 64, 64, 3);
1148 g_Frames_CreateWAD(nil, 'FRAMES_SMOKE', GameWAD+':TEXTURES\SMOKE', 32, 32, 10, False);
1150 g_Texture_CreateWADEx('TEXTURE_SHELL_BULLET', GameWAD+':TEXTURES\EBULLET');
1151 g_Texture_CreateWADEx('TEXTURE_SHELL_SHELL', GameWAD+':TEXTURES\ESHELL');
1153 wgunMonHash := hashNewIntInt();
1154 wgunHitHeap := TBinaryHeapHitTimes.Create(hitTimeCompare);
1155 end;
1157 procedure g_Weapon_FreeData();
1158 begin
1159 e_WriteLog('Releasing weapons data...', MSG_NOTIFY);
1161 g_Sound_Delete('SOUND_WEAPON_HITPUNCH');
1162 g_Sound_Delete('SOUND_WEAPON_MISSPUNCH');
1163 g_Sound_Delete('SOUND_WEAPON_HITBERSERK');
1164 g_Sound_Delete('SOUND_WEAPON_MISSBERSERK');
1165 g_Sound_Delete('SOUND_WEAPON_SELECTSAW');
1166 g_Sound_Delete('SOUND_WEAPON_IDLESAW');
1167 g_Sound_Delete('SOUND_WEAPON_HITSAW');
1168 g_Sound_Delete('SOUND_WEAPON_FIRESHOTGUN2');
1169 g_Sound_Delete('SOUND_WEAPON_FIRESHOTGUN');
1170 g_Sound_Delete('SOUND_WEAPON_FIRESAW');
1171 g_Sound_Delete('SOUND_WEAPON_FIREROCKET');
1172 g_Sound_Delete('SOUND_WEAPON_FIREPLASMA');
1173 g_Sound_Delete('SOUND_WEAPON_FIREPISTOL');
1174 g_Sound_Delete('SOUND_WEAPON_FIRECGUN');
1175 g_Sound_Delete('SOUND_WEAPON_FIREBFG');
1176 g_Sound_Delete('SOUND_FIRE');
1177 g_Sound_Delete('SOUND_WEAPON_STARTFIREBFG');
1178 g_Sound_Delete('SOUND_WEAPON_EXPLODEROCKET');
1179 g_Sound_Delete('SOUND_WEAPON_EXPLODEBFG');
1180 g_Sound_Delete('SOUND_WEAPON_BFGWATER');
1181 g_Sound_Delete('SOUND_WEAPON_EXPLODEPLASMA');
1182 g_Sound_Delete('SOUND_WEAPON_PLASMAWATER');
1183 g_Sound_Delete('SOUND_WEAPON_FIREBALL');
1184 g_Sound_Delete('SOUND_WEAPON_EXPLODEBALL');
1185 g_Sound_Delete('SOUND_WEAPON_FIREREV');
1186 g_Sound_Delete('SOUND_PLAYER_JETFLY');
1187 g_Sound_Delete('SOUND_PLAYER_JETON');
1188 g_Sound_Delete('SOUND_PLAYER_JETOFF');
1189 g_Sound_Delete('SOUND_PLAYER_CASING1');
1190 g_Sound_Delete('SOUND_PLAYER_CASING2');
1191 g_Sound_Delete('SOUND_PLAYER_SHELL1');
1192 g_Sound_Delete('SOUND_PLAYER_SHELL2');
1194 g_Texture_Delete('TEXTURE_WEAPON_ROCKET');
1195 g_Frames_DeleteByName('FRAMES_WEAPON_BFG');
1196 g_Frames_DeleteByName('FRAMES_WEAPON_PLASMA');
1197 g_Frames_DeleteByName('FRAMES_WEAPON_IMPFIRE');
1198 g_Frames_DeleteByName('FRAMES_WEAPON_BSPFIRE');
1199 g_Frames_DeleteByName('FRAMES_WEAPON_CACOFIRE');
1200 g_Frames_DeleteByName('FRAMES_WEAPON_MANCUBFIRE');
1201 g_Frames_DeleteByName('FRAMES_EXPLODE_ROCKET');
1202 g_Frames_DeleteByName('FRAMES_EXPLODE_BFG');
1203 g_Frames_DeleteByName('FRAMES_EXPLODE_IMPFIRE');
1204 g_Frames_DeleteByName('FRAMES_BFGHIT');
1205 g_Frames_DeleteByName('FRAMES_FIRE');
1206 g_Frames_DeleteByName('FRAMES_EXPLODE_PLASMA');
1207 g_Frames_DeleteByName('FRAMES_EXPLODE_BSPFIRE');
1208 g_Frames_DeleteByName('FRAMES_EXPLODE_CACOFIRE');
1209 g_Frames_DeleteByName('FRAMES_SMOKE');
1210 g_Frames_DeleteByName('FRAMES_WEAPON_BARONFIRE');
1211 g_Frames_DeleteByName('FRAMES_EXPLODE_BARONFIRE');
1212 end;
1215 function GunHitPlayer (X, Y: Integer; vx, vy: Integer; dmg: Integer; SpawnerUID: Word; AllowPush: Boolean): Boolean;
1216 var
1217 i: Integer;
1218 begin
1219 result := false;
1220 for i := 0 to High(gPlayers) do
1221 begin
1222 if (gPlayers[i] <> nil) and gPlayers[i].Live and gPlayers[i].Collide(X, Y) then
1223 begin
1224 if HitPlayer(gPlayers[i], dmg, vx*10, vy*10-3, SpawnerUID, HIT_SOME) then
1225 begin
1226 if AllowPush then gPlayers[i].Push(vx, vy);
1227 result := true;
1228 end;
1229 end;
1230 end;
1231 end;
1234 function GunHit (X, Y: Integer; vx, vy: Integer; dmg: Integer; SpawnerUID: Word; AllowPush: Boolean): Byte;
1236 function monsCheck (mon: TMonster): Boolean;
1237 begin
1238 result := false; // don't stop
1239 if HitMonster(mon, dmg, vx*10, vy*10-3, SpawnerUID, HIT_SOME) then
1240 begin
1241 if AllowPush then mon.Push(vx, vy);
1242 result := true;
1243 end;
1244 end;
1246 begin
1247 result := 0;
1248 if GunHitPlayer(X, Y, vx, vy, dmg, SpawnerUID, AllowPush) then result := 1
1249 else if g_Mons_ForEachAliveAt(X, Y, 1, 1, monsCheck) then result := 2;
1250 end;
1253 (*
1254 procedure g_Weapon_gunOld(const x, y, xd, yd, v, dmg: Integer; SpawnerUID: Word; CheckTrigger: Boolean);
1255 var
1256 a: Integer;
1257 x2, y2: Integer;
1258 dx, dy: Integer;
1259 xe, ye: Integer;
1260 xi, yi: Integer;
1261 s, c: Extended;
1262 //vx, vy: Integer;
1263 xx, yy, d: Integer;
1264 i: Integer;
1265 t1, _collide: Boolean;
1266 w, h: Word;
1267 {$IF DEFINED(D2F_DEBUG)}
1268 stt: UInt64;
1269 showTime: Boolean = true;
1270 {$ENDIF}
1271 begin
1272 a := GetAngle(x, y, xd, yd)+180;
1274 SinCos(DegToRad(-a), s, c);
1276 if Abs(s) < 0.01 then s := 0;
1277 if Abs(c) < 0.01 then c := 0;
1279 x2 := x+Round(c*gMapInfo.Width);
1280 y2 := y+Round(s*gMapInfo.Width);
1282 t1 := gWalls <> nil;
1283 _collide := False;
1284 w := gMapInfo.Width;
1285 h := gMapInfo.Height;
1287 xe := 0;
1288 ye := 0;
1289 dx := x2-x;
1290 dy := y2-y;
1292 if (xd = 0) and (yd = 0) then Exit;
1294 if dx > 0 then xi := 1 else if dx < 0 then xi := -1 else xi := 0;
1295 if dy > 0 then yi := 1 else if dy < 0 then yi := -1 else yi := 0;
1297 dx := Abs(dx);
1298 dy := Abs(dy);
1300 if dx > dy then d := dx else d := dy;
1302 //blood vel, for Monster.Damage()
1303 //vx := (dx*10 div d)*xi;
1304 //vy := (dy*10 div d)*yi;
1306 {$IF DEFINED(D2F_DEBUG)}
1307 stt := curTimeMicro();
1308 {$ENDIF}
1310 xx := x;
1311 yy := y;
1313 for i := 1 to d do
1314 begin
1315 xe := xe+dx;
1316 ye := ye+dy;
1318 if xe > d then
1319 begin
1320 xe := xe-d;
1321 xx := xx+xi;
1322 end;
1324 if ye > d then
1325 begin
1326 ye := ye-d;
1327 yy := yy+yi;
1328 end;
1330 if (yy > h) or (yy < 0) then Break;
1331 if (xx > w) or (xx < 0) then Break;
1333 if t1 then
1334 if ByteBool(gCollideMap[yy, xx] and MARK_BLOCKED) then
1335 begin
1336 _collide := True;
1337 {$IF DEFINED(D2F_DEBUG)}
1338 stt := curTimeMicro()-stt;
1339 e_WriteLog(Format('*** old trace time: %u microseconds', [LongWord(stt)]), MSG_NOTIFY);
1340 showTime := false;
1341 {$ENDIF}
1342 g_GFX_Spark(xx-xi, yy-yi, 2+Random(2), 180+a, 0, 0);
1343 if g_Game_IsServer and g_Game_IsNet then
1344 MH_SEND_Effect(xx-xi, yy-yi, 180+a, NET_GFX_SPARK);
1345 end;
1347 if not _collide then
1348 begin
1349 _collide := GunHit(xx, yy, xi*v, yi*v, dmg, SpawnerUID, v <> 0) <> 0;
1350 end;
1352 if _collide then Break;
1353 end;
1355 {$IF DEFINED(D2F_DEBUG)}
1356 if showTime then
1357 begin
1358 stt := curTimeMicro()-stt;
1359 e_WriteLog(Format('*** old trace time: %u microseconds', [LongWord(stt)]), MSG_NOTIFY);
1360 end;
1361 {$ENDIF}
1363 if CheckTrigger and g_Game_IsServer then
1364 g_Triggers_PressL(X, Y, xx-xi, yy-yi, SpawnerUID, ACTIVATE_SHOT);
1365 end;
1366 *)
1369 (*
1370 procedure g_Weapon_gunComplicated (const x, y, xd, yd, v, dmg: Integer; SpawnerUID: Word; CheckTrigger: Boolean);
1371 const
1372 HHGridSize = 64;
1374 var
1375 hitray: Ray2D;
1376 xi, yi: Integer;
1378 function doPlayerHit (idx: Integer): Boolean;
1379 begin
1380 result := false;
1381 if (idx < 0) or (idx > High(gPlayers)) then exit;
1382 if (gPlayers[idx] = nil) or not gPlayers[idx].Live then exit;
1383 result := HitPlayer(gPlayers[idx], dmg, (xi*v)*10, (yi*v)*10-3, SpawnerUID, HIT_SOME);
1384 if result and (v <> 0) then gPlayers[idx].Push((xi*v), (yi*v));
1385 {$IF DEFINED(D2F_DEBUG)}
1386 //if result then e_WriteLog(Format(' PLAYER #%d HIT', [idx]), MSG_NOTIFY);
1387 {$ENDIF}
1388 end;
1390 function doMonsterHit (mon: TMonster): Boolean;
1391 begin
1392 result := false;
1393 if (mon = nil) then exit;
1394 result := HitMonster(mon, dmg, (xi*v)*10, (yi*v)*10-3, SpawnerUID, HIT_SOME);
1395 if result and (v <> 0) then mon.Push((xi*v), (yi*v));
1396 {$IF DEFINED(D2F_DEBUG)}
1397 //if result then e_WriteLog(Format(' MONSTER #%u HIT', [LongWord(mon.UID)]), MSG_NOTIFY);
1398 {$ENDIF}
1399 end;
1401 // get nearest player along hitray
1402 // return `true` if instant hit was detected
1403 function playerPossibleHit (): Boolean;
1404 var
1405 i: Integer;
1406 aabb: AABB2D;
1407 tmin: Single;
1408 begin
1409 result := false;
1410 for i := 0 to High(gPlayers) do
1411 begin
1412 if (gPlayers[i] <> nil) and gPlayers[i].Live then
1413 begin
1414 aabb := gPlayers[i].mapAABB;
1415 // inside?
1416 if aabb.contains(x, y) then
1417 begin
1418 if doPlayerHit(i) then begin result := true; exit; end;
1419 end
1420 else if (aabb.intersects(hitray, @tmin)) then
1421 begin
1422 // intersect
1423 if (tmin <= 0) then
1424 begin
1425 if doPlayerHit(i) then begin result := true; exit; end;
1426 end
1427 else
1428 begin
1429 appendHitTimePlr(tmin, i);
1430 end;
1431 end;
1432 end;
1433 end;
1434 end;
1436 function monsPossibleHitInstant (mon: TMonster): Boolean;
1437 var
1438 aabb: AABB2D;
1439 begin
1440 result := false; // don't stop
1441 aabb := mon.mapAABB;
1442 if aabb.contains(x, y) then
1443 begin
1444 result := doMonsterHit(mon);
1445 end;
1446 end;
1448 function monsPossibleHit (mon: TMonster): Boolean;
1449 var
1450 aabb: AABB2D;
1451 tmin: Single;
1452 begin
1453 result := false; // don't stop
1454 if not wgunMonHash.put(Integer(mon.UID), 1) then
1455 begin
1456 // new monster; calculate hitpoint
1457 aabb := mon.mapAABB;
1458 if (aabb.intersects(hitray, @tmin)) then
1459 begin
1460 if (tmin < 0) then tmin := 1.0;
1461 appendHitTimeMon(tmin, mon);
1462 end;
1463 end;
1464 end;
1466 var
1467 a: Integer;
1468 x2, y2: Integer;
1469 dx, dy: Integer;
1470 xe, ye: Integer;
1471 s, c: Extended;
1472 xx, yy, d: Integer;
1473 prevX, prevY: Integer;
1474 leftToNextMonsterQuery: Integer = 0;
1475 i: Integer;
1476 t1: Boolean;
1477 {$IF DEFINED(GWEP_HITSCAN_TRACE_BITMAP_CHECKER)}
1478 w, h: Word;
1479 {$ENDIF}
1480 wallWasHit: Boolean = false;
1481 wallHitX: Integer = 0;
1482 wallHitY: Integer = 0;
1483 didHit: Boolean = false;
1484 mptWX: Integer = 0;
1485 mptWY: Integer = 0;
1486 mptHit: Integer = -1;
1487 {$IF DEFINED(D2F_DEBUG)}
1488 stt: UInt64;
1489 {$ENDIF}
1490 begin
1491 if not gwep_debug_fast_trace then
1492 begin
1493 g_Weapon_gunOld(x, y, xd, yd, v, dmg, SpawnerUID, CheckTrigger);
1494 exit;
1495 end;
1497 wgunMonHash.reset(); //FIXME: clear hash on level change
1498 wgunHitHeap.clear();
1499 wgunHitTimeUsed := 0;
1501 a := GetAngle(x, y, xd, yd)+180;
1503 SinCos(DegToRad(-a), s, c);
1505 if Abs(s) < 0.01 then s := 0;
1506 if Abs(c) < 0.01 then c := 0;
1508 x2 := x+Round(c*gMapInfo.Width);
1509 y2 := y+Round(s*gMapInfo.Width);
1511 hitray := Ray2D.Create(x, y, x2, y2);
1513 e_WriteLog(Format('GUN TRACE: (%d,%d) to (%d,%d)', [x, y, x2, y2]), MSG_NOTIFY);
1515 {$IF DEFINED(GWEP_HITSCAN_TRACE_BITMAP_CHECKER)}
1516 t1 := (gWalls <> nil);
1517 w := gMapInfo.Width;
1518 h := gMapInfo.Height;
1519 {$ENDIF}
1521 dx := x2-x;
1522 dy := y2-y;
1524 if (xd = 0) and (yd = 0) then Exit;
1526 if dx > 0 then xi := 1 else if dx < 0 then xi := -1 else xi := 0;
1527 if dy > 0 then yi := 1 else if dy < 0 then yi := -1 else yi := 0;
1529 // check instant hits
1530 xx := x;
1531 yy := y;
1532 if (dx < 0) then Dec(xx);
1533 if (dy < 0) then Dec(yy);
1535 dx := Abs(dx);
1536 dy := Abs(dy);
1538 if playerPossibleHit() then exit; // instant hit
1539 if g_Mons_ForEachAliveAt(xx, yy, 3, 3, monsPossibleHitInstant) then exit; // instant hit
1541 if dx > dy then d := dx else d := dy;
1543 //blood vel, for Monster.Damage()
1544 //vx := (dx*10 div d)*xi;
1545 //vy := (dy*10 div d)*yi;
1547 {$IF DEFINED(D2F_DEBUG)}
1548 mptHit := g_Map_traceToNearestWall(x, y, x2, y2, @mptWX, @mptWY);
1549 e_WriteLog(Format('tree trace: (%d,%d)', [mptWX, mptWY]), MSG_NOTIFY);
1550 {$ENDIF}
1552 {$IF not DEFINED(GWEP_HITSCAN_TRACE_BITMAP_CHECKER)}
1553 wallWasHit := (mptHit >= 0);
1554 wallHitX := mptWX;
1555 wallHitY := mptWY;
1556 t1 := false;
1557 {$ENDIF}
1559 {$IF DEFINED(D2F_DEBUG)}
1560 stt := curTimeMicro();
1561 {$ENDIF}
1562 // find wall, collect monsters
1563 begin
1564 xe := 0;
1565 ye := 0;
1566 xx := x;
1567 yy := y;
1568 prevX := xx;
1569 prevY := yy;
1570 for i := 1 to d do
1571 begin
1572 prevX := xx;
1573 prevY := yy;
1574 xe += dx;
1575 ye += dy;
1576 if (xe > d) then begin xe -= d; xx += xi; end;
1577 if (ye > d) then begin ye -= d; yy += yi; end;
1579 // wtf?!
1580 //if (yy > h) or (yy < 0) then break;
1581 //if (xx > w) or (xx < 0) then break;
1583 {$IF DEFINED(GWEP_HITSCAN_TRACE_BITMAP_CHECKER)}
1584 if t1 and (xx >= 0) and (yy >= 0) and (xx < w) and (yy < h) then
1585 begin
1586 if ByteBool(gCollideMap[yy, xx] and MARK_BLOCKED) then
1587 begin
1588 wallWasHit := true;
1589 wallHitX := prevX;
1590 wallHitY := prevY;
1591 end;
1592 end;
1593 {$ELSE}
1594 if (abs(prevX-wallHitX) < 2) and (abs(prevY-wallHitY) < 2) then t1 := true;
1595 {$ENDIF}
1597 if (leftToNextMonsterQuery <> 0) and not wallWasHit then
1598 begin
1599 Dec(leftToNextMonsterQuery);
1600 end
1601 else
1602 begin
1603 // check monsters
1604 g_Mons_ForEachAliveAt(xx-HHGridSize div 2, yy-HHGridSize div 2, HHGridSize+HHGridSize div 2, HHGridSize+HHGridSize div 2, monsPossibleHit);
1605 leftToNextMonsterQuery := HHGridSize; // again
1606 {$IF DEFINED(GWEP_HITSCAN_TRACE_BITMAP_CHECKER)}
1607 if wallWasHit then break;
1608 {$ELSE}
1609 if t1 then break;
1610 {$ENDIF}
1611 end;
1612 end;
1614 if not wallWasHit then
1615 begin
1616 wallHitX := prevX;
1617 wallHitY := prevY;
1618 end;
1619 end;
1621 // here, we collected all monsters and players in `wgunHitHeap` and `wgunHitTime`
1622 // also, if `wallWasHit` is true, then `wallHitX` and `wallHitY` contains wall coords
1623 while (wgunHitHeap.count > 0) do
1624 begin
1625 // has some entities to check, do it
1626 i := wgunHitHeap.front;
1627 wgunHitHeap.popFront();
1628 hitray.atTime(wgunHitTime[i].time, xe, ye);
1629 // check if it is not behind the wall
1630 if ((xe-x)*(xe-x)+(ye-y)*(ye-y) < (wallHitX-x)*(wallHitX-x)+(wallHitY-y)*(wallHitY-y)) then
1631 begin
1632 if (wgunHitTime[i].mon <> nil) then
1633 begin
1634 didHit := doMonsterHit(wgunHitTime[i].mon);
1635 end
1636 else
1637 begin
1638 didHit := doPlayerHit(wgunHitTime[i].plridx);
1639 end;
1640 if didHit then
1641 begin
1642 // need new coords for trigger
1643 wallHitX := xe;
1644 wallHitY := ye;
1645 wallWasHit := false; // no sparks
1646 break;
1647 end;
1648 end;
1649 end;
1651 // need sparks?
1652 if wallWasHit then
1653 begin
1654 {$IF DEFINED(GWEP_HITSCAN_TRACE_BITMAP_CHECKER)}
1655 if (mptHit < 0) then
1656 begin
1657 e_WriteLog('OOPS: tree trace failed, but pixel trace found the wall!', MSG_WARNING);
1658 raise Exception.Create('map tree trace fucked');
1659 end
1660 else
1661 begin
1662 {$IF DEFINED(D2F_DEBUG)}
1663 //e_WriteLog(Format(' trace: (%d,%d)', [wallHitX, wallHitY]), MSG_NOTIFY);
1664 {$ENDIF}
1665 wallHitX := mptWX;
1666 wallHitY := mptWY;
1667 end;
1668 {$ENDIF}
1669 {$IF DEFINED(D2F_DEBUG)}
1670 stt := curTimeMicro()-stt;
1671 e_WriteLog(Format('*** new trace time: %u microseconds', [LongWord(stt)]), MSG_NOTIFY);
1672 {$ENDIF}
1673 g_GFX_Spark(wallHitX, wallHitY, 2+Random(2), 180+a, 0, 0);
1674 if g_Game_IsServer and g_Game_IsNet then MH_SEND_Effect(wallHitX, wallHitY, 180+a, NET_GFX_SPARK);
1675 end
1676 else
1677 begin
1678 {$IF DEFINED(D2F_DEBUG)}
1679 stt := curTimeMicro()-stt;
1680 e_WriteLog(Format('*** new trace time: %u microseconds', [LongWord(stt)]), MSG_NOTIFY);
1681 {$ENDIF}
1682 end;
1684 if CheckTrigger and g_Game_IsServer then g_Triggers_PressL(X, Y, wallHitX, wallHitY, SpawnerUID, ACTIVATE_SHOT);
1685 end;
1686 *)
1689 procedure g_Weapon_gun (const x, y, xd, yd, v, dmg: Integer; SpawnerUID: Word; CheckTrigger: Boolean);
1690 var
1691 hitray: Ray2D;
1692 xi, yi: Integer;
1693 wallDistSq: Single = 1.0e100;
1695 function doPlayerHit (idx: Integer): Boolean;
1696 begin
1697 result := false;
1698 if (idx < 0) or (idx > High(gPlayers)) then exit;
1699 if (gPlayers[idx] = nil) or not gPlayers[idx].Live then exit;
1700 result := HitPlayer(gPlayers[idx], dmg, (xi*v)*10, (yi*v)*10-3, SpawnerUID, HIT_SOME);
1701 if result and (v <> 0) then gPlayers[idx].Push((xi*v), (yi*v));
1702 {$IF DEFINED(D2F_DEBUG)}
1703 //if result then e_WriteLog(Format(' PLAYER #%d HIT', [idx]), MSG_NOTIFY);
1704 {$ENDIF}
1705 end;
1707 function doMonsterHit (mon: TMonster): Boolean;
1708 begin
1709 result := false;
1710 if (mon = nil) then exit;
1711 result := HitMonster(mon, dmg, (xi*v)*10, (yi*v)*10-3, SpawnerUID, HIT_SOME);
1712 if result and (v <> 0) then mon.Push((xi*v), (yi*v));
1713 {$IF DEFINED(D2F_DEBUG)}
1714 //if result then e_WriteLog(Format(' MONSTER #%u HIT', [LongWord(mon.UID)]), MSG_NOTIFY);
1715 {$ENDIF}
1716 end;
1718 // collect players along hitray
1719 // return `true` if instant hit was detected
1720 function playerPossibleHit (): Boolean;
1721 var
1722 i: Integer;
1723 aabb: AABB2D;
1724 tmin: Single;
1725 begin
1726 result := false;
1727 for i := 0 to High(gPlayers) do
1728 begin
1729 if (gPlayers[i] <> nil) and gPlayers[i].Live then
1730 begin
1731 aabb := gPlayers[i].mapAABB;
1732 // inside?
1733 if aabb.contains(x, y) then
1734 begin
1735 if doPlayerHit(i) then begin result := true; exit; end;
1736 end
1737 else if (aabb.intersects(hitray, @tmin)) then
1738 begin
1739 // intersect
1740 if (tmin <= 0.0) then
1741 begin
1742 if doPlayerHit(i) then begin result := true; exit; end;
1743 end
1744 else
1745 begin
1746 if (tmin*tmin < wallDistSq) then appendHitTimePlr(tmin, i);
1747 end;
1748 end;
1749 end;
1750 end;
1751 end;
1753 function sqchecker (mon: TMonster; dist: Single): Boolean;
1754 begin
1755 result := false; // don't stop
1756 if (dist*dist < wallDistSq) then appendHitTimeMon(dist, mon);
1757 end;
1759 var
1760 a: Integer;
1761 x2, y2: Integer;
1762 dx, dy: Integer;
1763 xe, ye: Integer;
1764 s, c: Extended;
1765 i: Integer;
1766 wallHitFlag: Boolean = false;
1767 wallHitX: Integer = 0;
1768 wallHitY: Integer = 0;
1769 didHit: Boolean = false;
1770 {$IF DEFINED(D2F_DEBUG)}
1771 stt: UInt64;
1772 {$ENDIF}
1773 begin
1774 (*
1775 if not gwep_debug_fast_trace then
1776 begin
1777 g_Weapon_gunOld(x, y, xd, yd, v, dmg, SpawnerUID, CheckTrigger);
1778 exit;
1779 end;
1780 *)
1782 wgunMonHash.reset(); //FIXME: clear hash on level change
1783 wgunHitHeap.clear();
1784 wgunHitTimeUsed := 0;
1786 a := GetAngle(x, y, xd, yd)+180;
1788 SinCos(DegToRad(-a), s, c);
1790 if Abs(s) < 0.01 then s := 0;
1791 if Abs(c) < 0.01 then c := 0;
1793 x2 := x+Round(c*gMapInfo.Width);
1794 y2 := y+Round(s*gMapInfo.Width);
1796 dx := x2-x;
1797 dy := y2-y;
1799 if (xd = 0) and (yd = 0) then exit;
1801 if dx > 0 then xi := 1 else if dx < 0 then xi := -1 else xi := 0;
1802 if dy > 0 then yi := 1 else if dy < 0 then yi := -1 else yi := 0;
1804 {$IF DEFINED(D2F_DEBUG)}
1805 e_WriteLog(Format('GUN TRACE: (%d,%d) to (%d,%d)', [x, y, x2, y2]), MSG_NOTIFY);
1806 stt := curTimeMicro();
1807 {$ENDIF}
1809 wallHitFlag := g_Map_traceToNearestWall(x, y, x2, y2, @wallHitX, @wallHitY);
1810 if wallHitFlag then
1811 begin
1812 x2 := wallHitX;
1813 y2 := wallHitY;
1814 wallDistSq := (wallHitX-x)*(wallHitX-x)+(wallHitY-y)*(wallHitY-y);
1815 end
1816 else
1817 begin
1818 wallHitX := x2;
1819 wallHitY := y2;
1820 end;
1822 hitray := Ray2D.Create(x, y, x2, y2);
1824 if playerPossibleHit() then exit; // instant hit
1826 // collect monsters
1827 g_Mons_alongLine(x, y, x2, y2, sqchecker);
1829 // here, we collected all monsters and players in `wgunHitHeap` and `wgunHitTime`
1830 // also, if `wallWasHit` >= 0, then `wallHitX` and `wallHitY` contains spark coords
1831 while (wgunHitHeap.count > 0) do
1832 begin
1833 // has some entities to check, do it
1834 i := wgunHitHeap.front;
1835 wgunHitHeap.popFront();
1836 hitray.atTime(wgunHitTime[i].time, xe, ye);
1837 // check if it is not behind the wall
1838 if (wgunHitTime[i].mon <> nil) then
1839 begin
1840 didHit := doMonsterHit(wgunHitTime[i].mon);
1841 end
1842 else
1843 begin
1844 didHit := doPlayerHit(wgunHitTime[i].plridx);
1845 end;
1846 if didHit then
1847 begin
1848 // need new coords for trigger
1849 wallHitX := xe;
1850 wallHitY := ye;
1851 wallHitFlag := false; // no sparks
1852 break;
1853 end;
1854 end;
1856 // need sparks?
1857 if wallHitFlag then
1858 begin
1859 {$IF DEFINED(D2F_DEBUG)}
1860 stt := curTimeMicro()-stt;
1861 e_WriteLog(Format('*** new trace time: %u microseconds', [LongWord(stt)]), MSG_NOTIFY);
1862 {$ENDIF}
1863 g_GFX_Spark(wallHitX, wallHitY, 2+Random(2), 180+a, 0, 0);
1864 if g_Game_IsServer and g_Game_IsNet then MH_SEND_Effect(wallHitX, wallHitY, 180+a, NET_GFX_SPARK);
1865 end
1866 else
1867 begin
1868 {$IF DEFINED(D2F_DEBUG)}
1869 stt := curTimeMicro()-stt;
1870 e_WriteLog(Format('*** new trace time: %u microseconds', [LongWord(stt)]), MSG_NOTIFY);
1871 {$ENDIF}
1872 end;
1874 if CheckTrigger and g_Game_IsServer then g_Triggers_PressL(X, Y, wallHitX, wallHitY, SpawnerUID, ACTIVATE_SHOT);
1875 end;
1878 procedure g_Weapon_punch(x, y: Integer; d, SpawnerUID: Word);
1879 var
1880 obj: TObj;
1881 begin
1882 obj.X := X;
1883 obj.Y := Y;
1884 obj.rect.X := 0;
1885 obj.rect.Y := 0;
1886 obj.rect.Width := 39;
1887 obj.rect.Height := 52;
1888 obj.Vel.X := 0;
1889 obj.Vel.Y := 0;
1890 obj.Accel.X := 0;
1891 obj.Accel.Y := 0;
1893 if g_Weapon_Hit(@obj, d, SpawnerUID, HIT_SOME) <> 0 then
1894 g_Sound_PlayExAt('SOUND_WEAPON_HITPUNCH', x, y)
1895 else
1896 g_Sound_PlayExAt('SOUND_WEAPON_MISSPUNCH', x, y);
1897 end;
1899 function g_Weapon_chainsaw(x, y: Integer; d, SpawnerUID: Word): Integer;
1900 var
1901 obj: TObj;
1902 begin
1903 obj.X := X;
1904 obj.Y := Y;
1905 obj.rect.X := 0;
1906 obj.rect.Y := 0;
1907 obj.rect.Width := 32;
1908 obj.rect.Height := 52;
1909 obj.Vel.X := 0;
1910 obj.Vel.Y := 0;
1911 obj.Accel.X := 0;
1912 obj.Accel.Y := 0;
1914 Result := g_Weapon_Hit(@obj, d, SpawnerUID, HIT_SOME);
1915 end;
1917 procedure g_Weapon_rocket(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1918 Silent: Boolean = False);
1919 var
1920 find_id: DWORD;
1921 dx, dy: Integer;
1922 begin
1923 if WID < 0 then
1924 find_id := FindShot()
1925 else
1926 begin
1927 find_id := WID;
1928 if Integer(find_id) >= High(Shots) then
1929 SetLength(Shots, find_id + 64)
1930 end;
1932 with Shots[find_id] do
1933 begin
1934 g_Obj_Init(@Obj);
1936 Obj.Rect.Width := SHOT_ROCKETLAUNCHER_WIDTH;
1937 Obj.Rect.Height := SHOT_ROCKETLAUNCHER_HEIGHT;
1939 dx := IfThen(xd > x, -Obj.Rect.Width, 0);
1940 dy := -(Obj.Rect.Height div 2);
1942 ShotType := WEAPON_ROCKETLAUNCHER;
1943 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 12);
1945 Animation := nil;
1946 triggers := nil;
1947 g_Texture_Get('TEXTURE_WEAPON_ROCKET', TextureID);
1948 end;
1950 Shots[find_id].SpawnerUID := SpawnerUID;
1952 if not Silent then
1953 g_Sound_PlayExAt('SOUND_WEAPON_FIREROCKET', x, y);
1954 end;
1956 procedure g_Weapon_revf(x, y, xd, yd: Integer; SpawnerUID, TargetUID: Word;
1957 WID: Integer = -1; Silent: Boolean = False);
1958 var
1959 find_id, FramesID: DWORD;
1960 dx, dy: Integer;
1961 begin
1962 if WID < 0 then
1963 find_id := FindShot()
1964 else
1965 begin
1966 find_id := WID;
1967 if Integer(find_id) >= High(Shots) then
1968 SetLength(Shots, find_id + 64)
1969 end;
1971 with Shots[find_id] do
1972 begin
1973 g_Obj_Init(@Obj);
1975 Obj.Rect.Width := SHOT_SKELFIRE_WIDTH;
1976 Obj.Rect.Height := SHOT_SKELFIRE_HEIGHT;
1978 dx := -(Obj.Rect.Width div 2);
1979 dy := -(Obj.Rect.Height div 2);
1981 ShotType := WEAPON_SKEL_FIRE;
1982 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 12);
1984 triggers := nil;
1985 target := TargetUID;
1986 g_Frames_Get(FramesID, 'FRAMES_WEAPON_SKELFIRE');
1987 Animation := TAnimation.Create(FramesID, True, 5);
1988 end;
1990 Shots[find_id].SpawnerUID := SpawnerUID;
1992 if not Silent then
1993 g_Sound_PlayExAt('SOUND_WEAPON_FIREREV', x, y);
1994 end;
1996 procedure g_Weapon_plasma(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1997 Silent: Boolean = False);
1998 var
1999 find_id, FramesID: DWORD;
2000 dx, dy: Integer;
2001 begin
2002 if WID < 0 then
2003 find_id := FindShot()
2004 else
2005 begin
2006 find_id := WID;
2007 if Integer(find_id) >= High(Shots) then
2008 SetLength(Shots, find_id + 64);
2009 end;
2011 with Shots[find_id] do
2012 begin
2013 g_Obj_Init(@Obj);
2015 Obj.Rect.Width := SHOT_PLASMA_WIDTH;
2016 Obj.Rect.Height := SHOT_PLASMA_HEIGHT;
2018 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
2019 dy := -(Obj.Rect.Height div 2);
2021 ShotType := WEAPON_PLASMA;
2022 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
2024 triggers := nil;
2025 g_Frames_Get(FramesID, 'FRAMES_WEAPON_PLASMA');
2026 Animation := TAnimation.Create(FramesID, True, 5);
2027 end;
2029 Shots[find_id].SpawnerUID := SpawnerUID;
2031 if not Silent then
2032 g_Sound_PlayExAt('SOUND_WEAPON_FIREPLASMA', x, y);
2033 end;
2035 procedure g_Weapon_flame(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
2036 Silent: Boolean = False);
2037 var
2038 find_id: DWORD;
2039 dx, dy: Integer;
2040 begin
2041 if WID < 0 then
2042 find_id := FindShot()
2043 else
2044 begin
2045 find_id := WID;
2046 if Integer(find_id) >= High(Shots) then
2047 SetLength(Shots, find_id + 64);
2048 end;
2050 with Shots[find_id] do
2051 begin
2052 g_Obj_Init(@Obj);
2054 Obj.Rect.Width := SHOT_FLAME_WIDTH;
2055 Obj.Rect.Height := SHOT_FLAME_HEIGHT;
2057 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
2058 dy := -(Obj.Rect.Height div 2);
2060 ShotType := WEAPON_FLAMETHROWER;
2061 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
2063 triggers := nil;
2064 Animation := nil;
2065 TextureID := 0;
2066 g_Frames_Get(TextureID, 'FRAMES_FLAME');
2067 end;
2069 Shots[find_id].SpawnerUID := SpawnerUID;
2071 // if not Silent then
2072 // g_Sound_PlayExAt('SOUND_WEAPON_FIREPLASMA', x, y);
2073 end;
2075 procedure g_Weapon_ball1(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
2076 Silent: Boolean = False);
2077 var
2078 find_id, FramesID: DWORD;
2079 dx, dy: Integer;
2080 begin
2081 if WID < 0 then
2082 find_id := FindShot()
2083 else
2084 begin
2085 find_id := WID;
2086 if Integer(find_id) >= High(Shots) then
2087 SetLength(Shots, find_id + 64)
2088 end;
2090 with Shots[find_id] do
2091 begin
2092 g_Obj_Init(@Obj);
2094 Obj.Rect.Width := 16;
2095 Obj.Rect.Height := 16;
2097 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
2098 dy := -(Obj.Rect.Height div 2);
2100 ShotType := WEAPON_IMP_FIRE;
2101 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
2103 triggers := nil;
2104 g_Frames_Get(FramesID, 'FRAMES_WEAPON_IMPFIRE');
2105 Animation := TAnimation.Create(FramesID, True, 4);
2106 end;
2108 Shots[find_id].SpawnerUID := SpawnerUID;
2110 if not Silent then
2111 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x, y);
2112 end;
2114 procedure g_Weapon_ball2(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
2115 Silent: Boolean = False);
2116 var
2117 find_id, FramesID: DWORD;
2118 dx, dy: Integer;
2119 begin
2120 if WID < 0 then
2121 find_id := FindShot()
2122 else
2123 begin
2124 find_id := WID;
2125 if Integer(find_id) >= High(Shots) then
2126 SetLength(Shots, find_id + 64)
2127 end;
2129 with Shots[find_id] do
2130 begin
2131 g_Obj_Init(@Obj);
2133 Obj.Rect.Width := 16;
2134 Obj.Rect.Height := 16;
2136 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
2137 dy := -(Obj.Rect.Height div 2);
2139 ShotType := WEAPON_CACO_FIRE;
2140 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
2142 triggers := nil;
2143 g_Frames_Get(FramesID, 'FRAMES_WEAPON_CACOFIRE');
2144 Animation := TAnimation.Create(FramesID, True, 4);
2145 end;
2147 Shots[find_id].SpawnerUID := SpawnerUID;
2149 if not Silent then
2150 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x, y);
2151 end;
2153 procedure g_Weapon_ball7(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
2154 Silent: Boolean = False);
2155 var
2156 find_id, FramesID: DWORD;
2157 dx, dy: Integer;
2158 begin
2159 if WID < 0 then
2160 find_id := FindShot()
2161 else
2162 begin
2163 find_id := WID;
2164 if Integer(find_id) >= High(Shots) then
2165 SetLength(Shots, find_id + 64)
2166 end;
2168 with Shots[find_id] do
2169 begin
2170 g_Obj_Init(@Obj);
2172 Obj.Rect.Width := 32;
2173 Obj.Rect.Height := 16;
2175 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
2176 dy := -(Obj.Rect.Height div 2);
2178 ShotType := WEAPON_BARON_FIRE;
2179 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
2181 triggers := nil;
2182 g_Frames_Get(FramesID, 'FRAMES_WEAPON_BARONFIRE');
2183 Animation := TAnimation.Create(FramesID, True, 4);
2184 end;
2186 Shots[find_id].SpawnerUID := SpawnerUID;
2188 if not Silent then
2189 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x, y);
2190 end;
2192 procedure g_Weapon_aplasma(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
2193 Silent: Boolean = False);
2194 var
2195 find_id, FramesID: DWORD;
2196 dx, dy: Integer;
2197 begin
2198 if WID < 0 then
2199 find_id := FindShot()
2200 else
2201 begin
2202 find_id := WID;
2203 if Integer(find_id) >= High(Shots) then
2204 SetLength(Shots, find_id + 64)
2205 end;
2207 with Shots[find_id] do
2208 begin
2209 g_Obj_Init(@Obj);
2211 Obj.Rect.Width := 16;
2212 Obj.Rect.Height := 16;
2214 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
2215 dy := -(Obj.Rect.Height div 2);
2217 ShotType := WEAPON_BSP_FIRE;
2218 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
2220 triggers := nil;
2222 g_Frames_Get(FramesID, 'FRAMES_WEAPON_BSPFIRE');
2223 Animation := TAnimation.Create(FramesID, True, 4);
2224 end;
2226 Shots[find_id].SpawnerUID := SpawnerUID;
2228 if not Silent then
2229 g_Sound_PlayExAt('SOUND_WEAPON_FIREPLASMA', x, y);
2230 end;
2232 procedure g_Weapon_manfire(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
2233 Silent: Boolean = False);
2234 var
2235 find_id, FramesID: DWORD;
2236 dx, dy: Integer;
2237 begin
2238 if WID < 0 then
2239 find_id := FindShot()
2240 else
2241 begin
2242 find_id := WID;
2243 if Integer(find_id) >= High(Shots) then
2244 SetLength(Shots, find_id + 64)
2245 end;
2247 with Shots[find_id] do
2248 begin
2249 g_Obj_Init(@Obj);
2251 Obj.Rect.Width := 32;
2252 Obj.Rect.Height := 32;
2254 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
2255 dy := -(Obj.Rect.Height div 2);
2257 ShotType := WEAPON_MANCUB_FIRE;
2258 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
2260 triggers := nil;
2262 g_Frames_Get(FramesID, 'FRAMES_WEAPON_MANCUBFIRE');
2263 Animation := TAnimation.Create(FramesID, True, 4);
2264 end;
2266 Shots[find_id].SpawnerUID := SpawnerUID;
2268 if not Silent then
2269 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x, y);
2270 end;
2272 procedure g_Weapon_bfgshot(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
2273 Silent: Boolean = False);
2274 var
2275 find_id, FramesID: DWORD;
2276 dx, dy: Integer;
2277 begin
2278 if WID < 0 then
2279 find_id := FindShot()
2280 else
2281 begin
2282 find_id := WID;
2283 if Integer(find_id) >= High(Shots) then
2284 SetLength(Shots, find_id + 64)
2285 end;
2287 with Shots[find_id] do
2288 begin
2289 g_Obj_Init(@Obj);
2291 Obj.Rect.Width := SHOT_BFG_WIDTH;
2292 Obj.Rect.Height := SHOT_BFG_HEIGHT;
2294 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
2295 dy := -(Obj.Rect.Height div 2);
2297 ShotType := WEAPON_BFG;
2298 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
2300 triggers := nil;
2301 g_Frames_Get(FramesID, 'FRAMES_WEAPON_BFG');
2302 Animation := TAnimation.Create(FramesID, True, 6);
2303 end;
2305 Shots[find_id].SpawnerUID := SpawnerUID;
2307 if not Silent then
2308 g_Sound_PlayExAt('SOUND_WEAPON_FIREBFG', x, y);
2309 end;
2311 procedure g_Weapon_bfghit(x, y: Integer);
2312 var
2313 ID: DWORD;
2314 Anim: TAnimation;
2315 begin
2316 if g_Frames_Get(ID, 'FRAMES_BFGHIT') then
2317 begin
2318 Anim := TAnimation.Create(ID, False, 4);
2319 g_GFX_OnceAnim(x-32, y-32, Anim);
2320 Anim.Free();
2321 end;
2322 end;
2324 procedure g_Weapon_pistol(x, y, xd, yd: Integer; SpawnerUID: Word;
2325 Silent: Boolean = False);
2326 begin
2327 if not Silent then
2328 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', x, y);
2330 g_Weapon_gun(x, y, xd, yd, 1, 3, SpawnerUID, True);
2331 if gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF] then
2332 begin
2333 g_Weapon_gun(x, y+1, xd, yd+1, 1, 3, SpawnerUID, False);
2334 g_Weapon_gun(x, y-1, xd, yd-1, 1, 2, SpawnerUID, False);
2335 end;
2336 end;
2338 procedure g_Weapon_mgun(x, y, xd, yd: Integer; SpawnerUID: Word;
2339 Silent: Boolean = False);
2340 begin
2341 if not Silent then
2342 if gSoundEffectsDF then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', x, y);
2344 g_Weapon_gun(x, y, xd, yd, 1, 3, SpawnerUID, True);
2345 if (gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF]) and
2346 (g_GetUIDType(SpawnerUID) = UID_PLAYER) then
2347 begin
2348 g_Weapon_gun(x, y+1, xd, yd+1, 1, 2, SpawnerUID, False);
2349 g_Weapon_gun(x, y-1, xd, yd-1, 1, 2, SpawnerUID, False);
2350 end;
2351 end;
2353 procedure g_Weapon_shotgun(x, y, xd, yd: Integer; SpawnerUID: Word;
2354 Silent: Boolean = False);
2355 var
2356 i, j: Integer;
2357 begin
2358 if not Silent then
2359 if gSoundEffectsDF then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', x, y);
2361 for i := 0 to 9 do
2362 begin
2363 j := Random(17)-8; // -8 .. 8
2364 g_Weapon_gun(x, y+j, xd, yd+j, IfThen(i mod 2 <> 0, 1, 0), 3, SpawnerUID, i=0);
2365 end;
2366 end;
2368 procedure g_Weapon_dshotgun(x, y, xd, yd: Integer; SpawnerUID: Word;
2369 Silent: Boolean = False);
2370 var
2371 a, i, j: Integer;
2372 begin
2373 if not Silent then
2374 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', x, y);
2376 if gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF] then a := 25 else a := 20;
2377 for i := 0 to a do
2378 begin
2379 j := Random(41)-20; // -20 .. 20
2380 g_Weapon_gun(x, y+j, xd, yd+j, IfThen(i mod 3 <> 0, 0, 1), 3, SpawnerUID, i=0);
2381 end;
2382 end;
2384 procedure g_Weapon_Update();
2385 var
2386 i, a, h, cx, cy, oldvx, oldvy, tf: Integer;
2387 _id: DWORD;
2388 Anim: TAnimation;
2389 t: DWArray;
2390 st: Word;
2391 s: String;
2392 o: TObj;
2393 spl: Boolean;
2394 Loud: Boolean;
2395 tcx, tcy: Integer;
2396 begin
2397 if Shots = nil then
2398 Exit;
2400 for i := 0 to High(Shots) do
2401 begin
2402 if Shots[i].ShotType = 0 then
2403 Continue;
2405 Loud := True;
2407 with Shots[i] do
2408 begin
2409 Timeout := Timeout - 1;
2410 oldvx := Obj.Vel.X;
2411 oldvy := Obj.Vel.Y;
2412 // Àêòèâèðîâàòü òðèããåðû ïî ïóòè (êðîìå óæå àêòèâèðîâàííûõ):
2413 if (Stopped = 0) and g_Game_IsServer then
2414 t := g_Triggers_PressR(Obj.X, Obj.Y, Obj.Rect.Width, Obj.Rect.Height,
2415 SpawnerUID, ACTIVATE_SHOT, triggers)
2416 else
2417 t := nil;
2419 if t <> nil then
2420 begin
2421 // Ïîïîëíÿåì ñïèñîê àêòèâèðîâàííûõ òðèããåðîâ:
2422 if triggers = nil then
2423 triggers := t
2424 else
2425 begin
2426 h := High(t);
2428 for a := 0 to h do
2429 if not InDWArray(t[a], triggers) then
2430 begin
2431 SetLength(triggers, Length(triggers)+1);
2432 triggers[High(triggers)] := t[a];
2433 end;
2434 end;
2435 end;
2437 // Àíèìàöèÿ ñíàðÿäà:
2438 if Animation <> nil then
2439 Animation.Update();
2441 // Äâèæåíèå:
2442 spl := (ShotType <> WEAPON_PLASMA) and
2443 (ShotType <> WEAPON_BFG) and
2444 (ShotType <> WEAPON_BSP_FIRE) and
2445 (ShotType <> WEAPON_FLAMETHROWER);
2447 if Stopped = 0 then
2448 begin
2449 st := g_Obj_Move(@Obj, False, spl);
2450 end
2451 else
2452 begin
2453 st := 0;
2454 end;
2455 positionChanged(); // this updates spatial accelerators
2457 if WordBool(st and MOVE_FALLOUT) or (Obj.X < -1000) or
2458 (Obj.X > gMapInfo.Width+1000) or (Obj.Y < -1000) then
2459 begin
2460 // Íà êëèåíòå ñêîðåå âñåãî è òàê óæå âûïàë.
2461 ShotType := 0;
2462 Animation.Free();
2463 Continue;
2464 end;
2466 cx := Obj.X + (Obj.Rect.Width div 2);
2467 cy := Obj.Y + (Obj.Rect.Height div 2);
2469 case ShotType of
2470 WEAPON_ROCKETLAUNCHER, WEAPON_SKEL_FIRE: // Ðàêåòû è ñíàðÿäû Ñêåëåòà
2471 begin
2472 // Âûëåòåëà èç âîäû:
2473 if WordBool(st and MOVE_HITAIR) then
2474 g_Obj_SetSpeed(@Obj, 12);
2476 // Â âîäå øëåéô - ïóçûðè, â âîçäóõå øëåéô - äûì:
2477 if WordBool(st and MOVE_INWATER) then
2478 g_GFX_Bubbles(Obj.X+(Obj.Rect.Width div 2),
2479 Obj.Y+(Obj.Rect.Height div 2),
2480 1+Random(3), 16, 16)
2481 else
2482 if g_Frames_Get(_id, 'FRAMES_SMOKE') then
2483 begin
2484 Anim := TAnimation.Create(_id, False, 3);
2485 Anim.Alpha := 150;
2486 g_GFX_OnceAnim(Obj.X-14+Random(9),
2487 Obj.Y+(Obj.Rect.Height div 2)-20+Random(9),
2488 Anim, ONCEANIM_SMOKE);
2489 Anim.Free();
2490 end;
2492 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2493 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL)) or
2494 (g_Weapon_Hit(@Obj, 10, SpawnerUID, HIT_SOME, False) <> 0) or
2495 (Timeout < 1) then
2496 begin
2497 Obj.Vel.X := 0;
2498 Obj.Vel.Y := 0;
2500 g_Weapon_Explode(cx, cy, 60, SpawnerUID);
2502 if ShotType = WEAPON_SKEL_FIRE then
2503 begin // Âçðûâ ñíàðÿäà Ñêåëåòà
2504 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_SKELFIRE') then
2505 begin
2506 Anim := TAnimation.Create(TextureID, False, 8);
2507 Anim.Blending := False;
2508 g_GFX_OnceAnim((Obj.X+32)-58, (Obj.Y+8)-36, Anim);
2509 g_DynLightExplosion((Obj.X+32), (Obj.Y+8), 64, 1, 0, 0);
2510 Anim.Free();
2511 end;
2512 end
2513 else
2514 begin // Âçðûâ Ðàêåòû
2515 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_ROCKET') then
2516 begin
2517 Anim := TAnimation.Create(TextureID, False, 6);
2518 Anim.Blending := False;
2519 g_GFX_OnceAnim(cx-64, cy-64, Anim);
2520 g_DynLightExplosion(cx, cy, 64, 1, 0, 0);
2521 Anim.Free();
2522 end;
2523 end;
2525 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', Obj.X, Obj.Y);
2527 ShotType := 0;
2528 end;
2530 if ShotType = WEAPON_SKEL_FIRE then
2531 begin // Ñàìîíàâîäêà ñíàðÿäà Ñêåëåòà:
2532 if GetPos(target, @o) then
2533 throw(i, Obj.X, Obj.Y,
2534 o.X+o.Rect.X+(o.Rect.Width div 2)+o.Vel.X+o.Accel.X,
2535 o.Y+o.Rect.Y+(o.Rect.Height div 2)+o.Vel.Y+o.Accel.Y,
2536 12);
2537 end;
2538 end;
2540 WEAPON_PLASMA, WEAPON_BSP_FIRE: // Ïëàçìà, ïëàçìà Àðàõíàòðîíà
2541 begin
2542 // Ïîïàëà â âîäó - ýëåêòðîøîê ïî âîäå:
2543 if WordBool(st and (MOVE_INWATER or MOVE_HITWATER)) then
2544 begin
2545 g_Sound_PlayExAt('SOUND_WEAPON_PLASMAWATER', Obj.X, Obj.Y);
2546 if g_Game_IsServer then CheckTrap(i, 10, HIT_ELECTRO);
2547 ShotType := 0;
2548 Continue;
2549 end;
2551 // Âåëè÷èíà óðîíà:
2552 if (ShotType = WEAPON_PLASMA) and
2553 (gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF]) then
2554 a := 10
2555 else
2556 a := 5;
2558 if ShotType = WEAPON_BSP_FIRE then
2559 a := 10;
2561 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2562 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL)) or
2563 (g_Weapon_Hit(@Obj, a, SpawnerUID, HIT_SOME, False) <> 0) or
2564 (Timeout < 1) then
2565 begin
2566 if ShotType = WEAPON_PLASMA then
2567 s := 'FRAMES_EXPLODE_PLASMA'
2568 else
2569 s := 'FRAMES_EXPLODE_BSPFIRE';
2571 // Âçðûâ Ïëàçìû:
2572 if g_Frames_Get(TextureID, s) then
2573 begin
2574 Anim := TAnimation.Create(TextureID, False, 3);
2575 Anim.Blending := False;
2576 g_GFX_OnceAnim(cx-16, cy-16, Anim);
2577 Anim.Free();
2578 g_DynLightExplosion(cx, cy, 32, 0, 0.5, 0.5);
2579 end;
2581 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEPLASMA', Obj.X, Obj.Y);
2583 ShotType := 0;
2584 end;
2585 end;
2587 WEAPON_FLAMETHROWER: // Îãíåìåò
2588 begin
2589 // Ñî âðåìåíåì óìèðàåò
2590 if (Timeout < 1) then
2591 begin
2592 ShotType := 0;
2593 Continue;
2594 end;
2595 // Ïîä âîäîé òîæå
2596 if WordBool(st and (MOVE_HITWATER or MOVE_INWATER)) then
2597 begin
2598 if WordBool(st and MOVE_HITWATER) then
2599 begin
2600 if g_Frames_Get(_id, 'FRAMES_SMOKE') then
2601 begin
2602 Anim := TAnimation.Create(_id, False, 3);
2603 Anim.Alpha := 0;
2604 tcx := Random(8);
2605 tcy := Random(8);
2606 g_GFX_OnceAnim(cx-4+tcx-(Anim.Width div 2),
2607 cy-4+tcy-(Anim.Height div 2),
2608 Anim, ONCEANIM_SMOKE);
2609 Anim.Free();
2610 end;
2611 end
2612 else
2613 g_GFX_Bubbles(cx, cy, 1+Random(3), 16, 16);
2614 ShotType := 0;
2615 Continue;
2616 end;
2618 // Ãðàâèòàöèÿ
2619 if Stopped = 0 then
2620 Obj.Accel.Y := Obj.Accel.Y + 1;
2621 // Ïîïàëè â ñòåíó èëè â âîäó:
2622 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL or MOVE_HITWATER)) then
2623 begin
2624 // Ïðèëèïàåì:
2625 Obj.Vel.X := 0;
2626 Obj.Vel.Y := 0;
2627 Obj.Accel.Y := 0;
2628 if WordBool(st and MOVE_HITWALL) then
2629 Stopped := MOVE_HITWALL
2630 else if WordBool(st and MOVE_HITLAND) then
2631 Stopped := MOVE_HITLAND
2632 else if WordBool(st and MOVE_HITCEIL) then
2633 Stopped := MOVE_HITCEIL;
2634 end;
2636 a := IfThen(Stopped = 0, 3, 1);
2637 // Åñëè â êîãî-òî ïîïàëè
2638 if g_Weapon_Hit(@Obj, a, SpawnerUID, HIT_FLAME, False) <> 0 then
2639 begin
2640 // HIT_FLAME ñàì ïîäîææåò
2641 // Åñëè â ïîëåòå ïîïàëè, èñ÷åçàåì
2642 if Stopped = 0 then
2643 ShotType := 0;
2644 end;
2646 if Stopped = 0 then
2647 tf := 2
2648 else
2649 tf := 3;
2651 if (gTime mod tf = 0) then
2652 begin
2653 Anim := TAnimation.Create(TextureID, False, 2 + Random(2));
2654 Anim.Alpha := 0;
2655 case Stopped of
2656 MOVE_HITWALL: begin tcx := cx-4+Random(8); tcy := cy-12+Random(24); end;
2657 MOVE_HITLAND: begin tcx := cx-12+Random(24); tcy := cy-10+Random(8); end;
2658 MOVE_HITCEIL: begin tcx := cx-12+Random(24); tcy := cy+6+Random(8); end;
2659 else begin tcx := cx-4+Random(8); tcy := cy-4+Random(8); end;
2660 end;
2661 g_GFX_OnceAnim(tcx-(Anim.Width div 2), tcy-(Anim.Height div 2), Anim, ONCEANIM_SMOKE);
2662 Anim.Free();
2663 //g_DynLightExplosion(tcx, tcy, 1, 1, 0.8, 0.3);
2664 end;
2665 end;
2667 WEAPON_BFG: // BFG
2668 begin
2669 // Ïîïàëà â âîäó - ýëåêòðîøîê ïî âîäå:
2670 if WordBool(st and (MOVE_INWATER or MOVE_HITWATER)) then
2671 begin
2672 g_Sound_PlayExAt('SOUND_WEAPON_BFGWATER', Obj.X, Obj.Y);
2673 if g_Game_IsServer then CheckTrap(i, 1000, HIT_ELECTRO);
2674 ShotType := 0;
2675 Continue;
2676 end;
2678 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2679 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL)) or
2680 (g_Weapon_Hit(@Obj, SHOT_BFG_DAMAGE, SpawnerUID, HIT_BFG, False) <> 0) or
2681 (Timeout < 1) then
2682 begin
2683 // Ëó÷è BFG:
2684 if g_Game_IsServer then g_Weapon_BFG9000(cx, cy, SpawnerUID);
2686 // Âçðûâ BFG:
2687 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_BFG') then
2688 begin
2689 Anim := TAnimation.Create(TextureID, False, 6);
2690 Anim.Blending := False;
2691 g_GFX_OnceAnim(cx-64, cy-64, Anim);
2692 Anim.Free();
2693 g_DynLightExplosion(cx, cy, 96, 0, 1, 0);
2694 end;
2696 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', Obj.X, Obj.Y);
2698 ShotType := 0;
2699 end;
2700 end;
2702 WEAPON_IMP_FIRE, WEAPON_CACO_FIRE, WEAPON_BARON_FIRE: // Âûñòðåëû Áåñà, Êàêîäåìîíà Ðûöàðÿ/Áàðîíà àäà
2703 begin
2704 // Âûëåòåë èç âîäû:
2705 if WordBool(st and MOVE_HITAIR) then
2706 g_Obj_SetSpeed(@Obj, 16);
2708 // Âåëè÷èíà óðîíà:
2709 if ShotType = WEAPON_IMP_FIRE then
2710 a := 5
2711 else
2712 if ShotType = WEAPON_CACO_FIRE then
2713 a := 20
2714 else
2715 a := 40;
2717 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2718 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL)) or
2719 (g_Weapon_Hit(@Obj, a, SpawnerUID, HIT_SOME) <> 0) or
2720 (Timeout < 1) then
2721 begin
2722 if ShotType = WEAPON_IMP_FIRE then
2723 s := 'FRAMES_EXPLODE_IMPFIRE'
2724 else
2725 if ShotType = WEAPON_CACO_FIRE then
2726 s := 'FRAMES_EXPLODE_CACOFIRE'
2727 else
2728 s := 'FRAMES_EXPLODE_BARONFIRE';
2730 // Âçðûâ:
2731 if g_Frames_Get(TextureID, s) then
2732 begin
2733 Anim := TAnimation.Create(TextureID, False, 6);
2734 Anim.Blending := False;
2735 g_GFX_OnceAnim(cx-32, cy-32, Anim);
2736 Anim.Free();
2737 end;
2739 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj.X, Obj.Y);
2741 ShotType := 0;
2742 end;
2743 end;
2745 WEAPON_MANCUB_FIRE: // Âûñòðåë Ìàíêóáóñà
2746 begin
2747 // Âûëåòåë èç âîäû:
2748 if WordBool(st and MOVE_HITAIR) then
2749 g_Obj_SetSpeed(@Obj, 16);
2751 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2752 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL)) or
2753 (g_Weapon_Hit(@Obj, 40, SpawnerUID, HIT_SOME, False) <> 0) or
2754 (Timeout < 1) then
2755 begin
2756 // Âçðûâ:
2757 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_ROCKET') then
2758 begin
2759 Anim := TAnimation.Create(TextureID, False, 6);
2760 Anim.Blending := False;
2761 g_GFX_OnceAnim(cx-64, cy-64, Anim);
2762 Anim.Free();
2763 end;
2765 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj.X, Obj.Y);
2767 ShotType := 0;
2768 end;
2769 end;
2770 end; // case ShotType of...
2772 // Åñëè ñíàðÿäà óæå íåò, óäàëÿåì àíèìàöèþ:
2773 if (ShotType = 0) then
2774 begin
2775 if gGameSettings.GameType = GT_SERVER then
2776 MH_SEND_DeleteShot(i, Obj.X, Obj.Y, Loud);
2777 if Animation <> nil then
2778 begin
2779 Animation.Free();
2780 Animation := nil;
2781 end;
2782 end
2783 else if (ShotType <> WEAPON_FLAMETHROWER) and ((oldvx <> Obj.Vel.X) or (oldvy <> Obj.Vel.Y)) then
2784 if gGameSettings.GameType = GT_SERVER then
2785 MH_SEND_UpdateShot(i);
2786 end;
2787 end;
2788 end;
2790 procedure g_Weapon_Draw();
2791 var
2792 i: Integer;
2793 a: SmallInt;
2794 p: TPoint;
2795 begin
2796 if Shots = nil then
2797 Exit;
2799 for i := 0 to High(Shots) do
2800 if Shots[i].ShotType <> 0 then
2801 with Shots[i] do
2802 begin
2803 if (Shots[i].ShotType = WEAPON_ROCKETLAUNCHER) or
2804 (Shots[i].ShotType = WEAPON_BARON_FIRE) or
2805 (Shots[i].ShotType = WEAPON_MANCUB_FIRE) or
2806 (Shots[i].ShotType = WEAPON_SKEL_FIRE) then
2807 a := -GetAngle2(Obj.Vel.X, Obj.Vel.Y)
2808 else
2809 a := 0;
2811 p.X := Obj.Rect.Width div 2;
2812 p.Y := Obj.Rect.Height div 2;
2814 if Animation <> nil then
2815 begin
2816 if (Shots[i].ShotType = WEAPON_BARON_FIRE) or
2817 (Shots[i].ShotType = WEAPON_MANCUB_FIRE) or
2818 (Shots[i].ShotType = WEAPON_SKEL_FIRE) then
2819 Animation.DrawEx(Obj.X, Obj.Y, M_NONE, p, a)
2820 else
2821 Animation.Draw(Obj.X, Obj.Y, M_NONE);
2822 end
2823 else if TextureID <> 0 then
2824 begin
2825 if (Shots[i].ShotType = WEAPON_ROCKETLAUNCHER) then
2826 e_DrawAdv(TextureID, Obj.X, Obj.Y, 0, True, False, a, @p, M_NONE)
2827 else if (Shots[i].ShotType <> WEAPON_FLAMETHROWER) then
2828 e_Draw(TextureID, Obj.X, Obj.Y, 0, True, False);
2829 end;
2831 if g_debug_Frames then
2832 begin
2833 e_DrawQuad(Obj.X+Obj.Rect.X,
2834 Obj.Y+Obj.Rect.Y,
2835 Obj.X+Obj.Rect.X+Obj.Rect.Width-1,
2836 Obj.Y+Obj.Rect.Y+Obj.Rect.Height-1,
2837 0, 255, 0);
2838 end;
2839 end;
2840 end;
2842 function g_Weapon_Danger(UID: Word; X, Y: Integer; Width, Height: Word; Time: Byte): Boolean;
2843 var
2844 a: Integer;
2845 begin
2846 Result := False;
2848 if Shots = nil then
2849 Exit;
2851 for a := 0 to High(Shots) do
2852 if (Shots[a].ShotType <> 0) and (Shots[a].SpawnerUID <> UID) then
2853 if ((Shots[a].Obj.Vel.Y = 0) and (Shots[a].Obj.Vel.X > 0) and (Shots[a].Obj.X < X)) or
2854 (Shots[a].Obj.Vel.Y = 0) and (Shots[a].Obj.Vel.X < 0) and (Shots[a].Obj.X > X) then
2855 if (Abs(X-Shots[a].Obj.X) < Abs(Shots[a].Obj.Vel.X*Time)) and
2856 g_Collide(X, Y, Width, Height, X, Shots[a].Obj.Y,
2857 Shots[a].Obj.Rect.Width, Shots[a].Obj.Rect.Height) and
2858 g_TraceVector(X, Y, Shots[a].Obj.X, Shots[a].Obj.Y) then
2859 begin
2860 Result := True;
2861 Exit;
2862 end;
2863 end;
2865 procedure g_Weapon_SaveState(var Mem: TBinMemoryWriter);
2866 var
2867 count, i, j: Integer;
2868 dw: DWORD;
2869 begin
2870 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ ñíàðÿäîâ:
2871 count := 0;
2872 if Shots <> nil then
2873 for i := 0 to High(Shots) do
2874 if Shots[i].ShotType <> 0 then
2875 count := count + 1;
2877 Mem := TBinMemoryWriter.Create((count+1) * 80);
2879 // Êîëè÷åñòâî ñíàðÿäîâ:
2880 Mem.WriteInt(count);
2882 if count = 0 then
2883 Exit;
2885 for i := 0 to High(Shots) do
2886 if Shots[i].ShotType <> 0 then
2887 begin
2888 // Ñèãíàòóðà ñíàðÿäà:
2889 dw := SHOT_SIGNATURE; // 'SHOT'
2890 Mem.WriteDWORD(dw);
2891 // Òèï ñíàðÿäà:
2892 Mem.WriteByte(Shots[i].ShotType);
2893 // Öåëü:
2894 Mem.WriteWord(Shots[i].Target);
2895 // UID ñòðåëÿâøåãî:
2896 Mem.WriteWord(Shots[i].SpawnerUID);
2897 // Ðàçìåð ïîëÿ Triggers:
2898 dw := Length(Shots[i].Triggers);
2899 Mem.WriteDWORD(dw);
2900 // Òðèããåðû, àêòèâèðîâàííûå âûñòðåëîì:
2901 for j := 0 to Integer(dw)-1 do
2902 Mem.WriteDWORD(Shots[i].Triggers[j]);
2903 // Îáúåêò ñíàðÿäà:
2904 Obj_SaveState(@Shots[i].Obj, Mem);
2905 // Êîñòûëèíà åáàíàÿ:
2906 Mem.WriteByte(Shots[i].Stopped);
2907 end;
2908 end;
2910 procedure g_Weapon_LoadState(var Mem: TBinMemoryReader);
2911 var
2912 count, i, j: Integer;
2913 dw: DWORD;
2914 begin
2915 if Mem = nil then
2916 Exit;
2918 // Êîëè÷åñòâî ñíàðÿäîâ:
2919 Mem.ReadInt(count);
2921 SetLength(Shots, count);
2923 if count = 0 then
2924 Exit;
2926 for i := 0 to count-1 do
2927 begin
2928 // Ñèãíàòóðà ñíàðÿäà:
2929 Mem.ReadDWORD(dw);
2930 if dw <> SHOT_SIGNATURE then // 'SHOT'
2931 begin
2932 raise EBinSizeError.Create('g_Weapons_LoadState: Wrong Shot Signature');
2933 end;
2934 // Òèï ñíàðÿäà:
2935 Mem.ReadByte(Shots[i].ShotType);
2936 // Öåëü:
2937 Mem.ReadWord(Shots[i].Target);
2938 // UID ñòðåëÿâøåãî:
2939 Mem.ReadWord(Shots[i].SpawnerUID);
2940 // Ðàçìåð ïîëÿ Triggers:
2941 Mem.ReadDWORD(dw);
2942 SetLength(Shots[i].Triggers, dw);
2943 // Òðèããåðû, àêòèâèðîâàííûå âûñòðåëîì:
2944 for j := 0 to Integer(dw)-1 do
2945 Mem.ReadDWORD(Shots[i].Triggers[j]);
2946 // Îáúåêò ïðåäìåòà:
2947 Obj_LoadState(@Shots[i].Obj, Mem);
2948 // Êîñòûëèíà åáàíàÿ:
2949 Mem.ReadByte(Shots[i].Stopped);
2951 // Óñòàíîâêà òåêñòóðû èëè àíèìàöèè:
2952 Shots[i].TextureID := DWORD(-1);
2953 Shots[i].Animation := nil;
2955 case Shots[i].ShotType of
2956 WEAPON_ROCKETLAUNCHER, WEAPON_SKEL_FIRE:
2957 begin
2958 g_Texture_Get('TEXTURE_WEAPON_ROCKET', Shots[i].TextureID);
2959 end;
2960 WEAPON_PLASMA:
2961 begin
2962 g_Frames_Get(dw, 'FRAMES_WEAPON_PLASMA');
2963 Shots[i].Animation := TAnimation.Create(dw, True, 5);
2964 end;
2965 WEAPON_BFG:
2966 begin
2967 g_Frames_Get(dw, 'FRAMES_WEAPON_BFG');
2968 Shots[i].Animation := TAnimation.Create(dw, True, 6);
2969 end;
2970 WEAPON_IMP_FIRE:
2971 begin
2972 g_Frames_Get(dw, 'FRAMES_WEAPON_IMPFIRE');
2973 Shots[i].Animation := TAnimation.Create(dw, True, 4);
2974 end;
2975 WEAPON_BSP_FIRE:
2976 begin
2977 g_Frames_Get(dw, 'FRAMES_WEAPON_BSPFIRE');
2978 Shots[i].Animation := TAnimation.Create(dw, True, 4);
2979 end;
2980 WEAPON_CACO_FIRE:
2981 begin
2982 g_Frames_Get(dw, 'FRAMES_WEAPON_CACOFIRE');
2983 Shots[i].Animation := TAnimation.Create(dw, True, 4);
2984 end;
2985 WEAPON_BARON_FIRE:
2986 begin
2987 g_Frames_Get(dw, 'FRAMES_WEAPON_BARONFIRE');
2988 Shots[i].Animation := TAnimation.Create(dw, True, 4);
2989 end;
2990 WEAPON_MANCUB_FIRE:
2991 begin
2992 g_Frames_Get(dw, 'FRAMES_WEAPON_MANCUBFIRE');
2993 Shots[i].Animation := TAnimation.Create(dw, True, 4);
2994 end;
2995 end;
2996 end;
2997 end;
2999 procedure g_Weapon_DestroyShot(I: Integer; X, Y: Integer; Loud: Boolean = True);
3000 var
3001 cx, cy: Integer;
3002 Anim: TAnimation;
3003 s: string;
3004 begin
3005 if Shots = nil then
3006 Exit;
3007 if (I > High(Shots)) or (I < 0) then Exit;
3009 with Shots[I] do
3010 begin
3011 if ShotType = 0 then Exit;
3012 Obj.X := X;
3013 Obj.Y := Y;
3014 cx := Obj.X + (Obj.Rect.Width div 2);
3015 cy := Obj.Y + (Obj.Rect.Height div 2);
3017 case ShotType of
3018 WEAPON_ROCKETLAUNCHER, WEAPON_SKEL_FIRE: // Ðàêåòû è ñíàðÿäû Ñêåëåòà
3019 begin
3020 if Loud then
3021 begin
3022 if ShotType = WEAPON_SKEL_FIRE then
3023 begin // Âçðûâ ñíàðÿäà Ñêåëåòà
3024 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_SKELFIRE') then
3025 begin
3026 Anim := TAnimation.Create(TextureID, False, 8);
3027 Anim.Blending := False;
3028 g_GFX_OnceAnim((Obj.X+32)-32, (Obj.Y+8)-32, Anim);
3029 Anim.Free();
3030 end;
3031 end
3032 else
3033 begin // Âçðûâ Ðàêåòû
3034 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_ROCKET') then
3035 begin
3036 Anim := TAnimation.Create(TextureID, False, 6);
3037 Anim.Blending := False;
3038 g_GFX_OnceAnim(cx-64, cy-64, Anim);
3039 Anim.Free();
3040 end;
3041 end;
3042 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', Obj.X, Obj.Y);
3043 end;
3044 end;
3046 WEAPON_PLASMA, WEAPON_BSP_FIRE: // Ïëàçìà, ïëàçìà Àðàõíàòðîíà
3047 begin
3048 if ShotType = WEAPON_PLASMA then
3049 s := 'FRAMES_EXPLODE_PLASMA'
3050 else
3051 s := 'FRAMES_EXPLODE_BSPFIRE';
3053 if g_Frames_Get(TextureID, s) and loud then
3054 begin
3055 Anim := TAnimation.Create(TextureID, False, 3);
3056 Anim.Blending := False;
3057 g_GFX_OnceAnim(cx-16, cy-16, Anim);
3058 Anim.Free();
3060 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEPLASMA', Obj.X, Obj.Y);
3061 end;
3062 end;
3064 WEAPON_BFG: // BFG
3065 begin
3066 // Âçðûâ BFG:
3067 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_BFG') and Loud then
3068 begin
3069 Anim := TAnimation.Create(TextureID, False, 6);
3070 Anim.Blending := False;
3071 g_GFX_OnceAnim(cx-64, cy-64, Anim);
3072 Anim.Free();
3074 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', Obj.X, Obj.Y);
3075 end;
3076 end;
3078 WEAPON_IMP_FIRE, WEAPON_CACO_FIRE, WEAPON_BARON_FIRE: // Âûñòðåëû Áåñà, Êàêîäåìîíà Ðûöàðÿ/Áàðîíà àäà
3079 begin
3080 if ShotType = WEAPON_IMP_FIRE then
3081 s := 'FRAMES_EXPLODE_IMPFIRE'
3082 else
3083 if ShotType = WEAPON_CACO_FIRE then
3084 s := 'FRAMES_EXPLODE_CACOFIRE'
3085 else
3086 s := 'FRAMES_EXPLODE_BARONFIRE';
3088 if g_Frames_Get(TextureID, s) and Loud then
3089 begin
3090 Anim := TAnimation.Create(TextureID, False, 6);
3091 Anim.Blending := False;
3092 g_GFX_OnceAnim(cx-32, cy-32, Anim);
3093 Anim.Free();
3095 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj.X, Obj.Y);
3096 end;
3097 end;
3099 WEAPON_MANCUB_FIRE: // Âûñòðåë Ìàíêóáóñà
3100 begin
3101 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_ROCKET') and Loud then
3102 begin
3103 Anim := TAnimation.Create(TextureID, False, 6);
3104 Anim.Blending := False;
3105 g_GFX_OnceAnim(cx-64, cy-64, Anim);
3106 Anim.Free();
3108 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj.X, Obj.Y);
3109 end;
3110 end;
3111 end; // case ShotType of...
3113 ShotType := 0;
3114 Animation.Free();
3115 end;
3116 end;
3119 procedure g_Weapon_AddDynLights();
3120 var
3121 i: Integer;
3122 begin
3123 if Shots = nil then Exit;
3124 for i := 0 to High(Shots) do
3125 begin
3126 if Shots[i].ShotType = 0 then continue;
3127 if (Shots[i].ShotType = WEAPON_ROCKETLAUNCHER) or
3128 (Shots[i].ShotType = WEAPON_BARON_FIRE) or
3129 (Shots[i].ShotType = WEAPON_MANCUB_FIRE) or
3130 (Shots[i].ShotType = WEAPON_SKEL_FIRE) or
3131 (Shots[i].ShotType = WEAPON_IMP_FIRE) or
3132 (Shots[i].ShotType = WEAPON_CACO_FIRE) or
3133 (Shots[i].ShotType = WEAPON_MANCUB_FIRE) or
3134 (Shots[i].ShotType = WEAPON_BSP_FIRE) or
3135 (Shots[i].ShotType = WEAPON_PLASMA) or
3136 (Shots[i].ShotType = WEAPON_BFG) or
3137 (Shots[i].ShotType = WEAPON_FLAMETHROWER) or
3138 false then
3139 begin
3140 if (Shots[i].ShotType = WEAPON_PLASMA) then
3141 g_AddDynLight(Shots[i].Obj.X+(Shots[i].Obj.Rect.Width div 2), Shots[i].Obj.Y+(Shots[i].Obj.Rect.Height div 2), 128, 0, 0.3, 1, 0.4)
3142 else if (Shots[i].ShotType = WEAPON_BFG) then
3143 g_AddDynLight(Shots[i].Obj.X+(Shots[i].Obj.Rect.Width div 2), Shots[i].Obj.Y+(Shots[i].Obj.Rect.Height div 2), 128, 0, 1, 0, 0.5)
3144 else if (Shots[i].ShotType = WEAPON_FLAMETHROWER) then
3145 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)
3146 else
3147 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);
3148 end;
3149 end;
3150 end;
3153 procedure TShot.positionChanged (); begin end;
3156 end.