DEADSOFTWARE

Add sounds for flamethrower
[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 SysUtils, Classes, mempool,
24 g_textures, g_basic, e_graphics, g_phys, xprofiler;
27 type
28 TShot = record
29 ShotType: Byte;
30 Target: Word;
31 SpawnerUID: Word;
32 Triggers: DWArray;
33 Obj: TObj;
34 Animation: TAnimation;
35 TextureID: DWORD;
36 Timeout: DWORD;
37 Stopped: Byte;
39 procedure positionChanged (); //WARNING! call this after monster position was changed, or coldet will not work right!
40 end;
43 var
44 Shots: array of TShot = nil;
45 LastShotID: Integer = 0;
47 procedure g_Weapon_LoadData();
48 procedure g_Weapon_FreeData();
49 procedure g_Weapon_Init();
50 procedure g_Weapon_Free();
51 function g_Weapon_Hit(obj: PObj; d: Integer; SpawnerUID: Word; t: Byte; HitCorpses: Boolean = True): Byte;
52 function g_Weapon_HitUID(UID: Word; d: Integer; SpawnerUID: Word; t: Byte): Boolean;
53 function g_Weapon_CreateShot(I: Integer; ShotType: Byte; Spawner, TargetUID: Word; X, Y, XV, YV: Integer): LongWord;
55 procedure g_Weapon_gun(const x, y, xd, yd, v, dmg: Integer; SpawnerUID: Word; CheckTrigger: Boolean);
56 procedure g_Weapon_punch(x, y: Integer; d, SpawnerUID: Word);
57 function g_Weapon_chainsaw(x, y: Integer; d, SpawnerUID: Word): Integer;
58 procedure g_Weapon_rocket(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1; Silent: Boolean = False);
59 procedure g_Weapon_revf(x, y, xd, yd: Integer; SpawnerUID, TargetUID: Word; WID: Integer = -1; Silent: Boolean = False);
60 procedure g_Weapon_flame(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1; Silent: Boolean = False);
61 procedure g_Weapon_plasma(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1; Silent: Boolean = False);
62 procedure g_Weapon_ball1(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1; Silent: Boolean = False);
63 procedure g_Weapon_ball2(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1; Silent: Boolean = False);
64 procedure g_Weapon_ball7(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1; Silent: Boolean = False);
65 procedure g_Weapon_aplasma(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1; Silent: Boolean = False);
66 procedure g_Weapon_manfire(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1; Silent: Boolean = False);
67 procedure g_Weapon_bfgshot(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1; Silent: Boolean = False);
68 procedure g_Weapon_bfghit(x, y: Integer);
69 procedure g_Weapon_pistol(x, y, xd, yd: Integer; SpawnerUID: Word; Silent: Boolean = False);
70 procedure g_Weapon_mgun(x, y, xd, yd: Integer; SpawnerUID: Word; Silent: Boolean = False);
71 procedure g_Weapon_shotgun(x, y, xd, yd: Integer; SpawnerUID: Word; Silent: Boolean = False);
72 procedure g_Weapon_dshotgun(x, y, xd, yd: Integer; SpawnerUID: Word; Silent: Boolean = False);
74 function g_Weapon_Explode(X, Y: Integer; rad: Integer; SpawnerUID: Word): Boolean;
75 procedure g_Weapon_BFG9000(X, Y: Integer; SpawnerUID: Word);
76 procedure g_Weapon_Update();
77 procedure g_Weapon_Draw();
78 function g_Weapon_Danger(UID: Word; X, Y: Integer; Width, Height: Word; Time: Byte): Boolean;
79 procedure g_Weapon_DestroyShot(I: Integer; X, Y: Integer; Loud: Boolean = True);
81 procedure g_Weapon_SaveState (st: TStream);
82 procedure g_Weapon_LoadState (st: TStream);
84 procedure g_Weapon_AddDynLights();
86 const
87 WEAPON_KASTET = 0;
88 WEAPON_SAW = 1;
89 WEAPON_PISTOL = 2;
90 WEAPON_SHOTGUN1 = 3;
91 WEAPON_SHOTGUN2 = 4;
92 WEAPON_CHAINGUN = 5;
93 WEAPON_ROCKETLAUNCHER = 6;
94 WEAPON_PLASMA = 7;
95 WEAPON_BFG = 8;
96 WEAPON_SUPERPULEMET = 9;
97 WEAPON_FLAMETHROWER = 10;
98 WEAPON_ZOMBY_PISTOL = 20;
99 WEAPON_IMP_FIRE = 21;
100 WEAPON_BSP_FIRE = 22;
101 WEAPON_CACO_FIRE = 23;
102 WEAPON_BARON_FIRE = 24;
103 WEAPON_MANCUB_FIRE = 25;
104 WEAPON_SKEL_FIRE = 26;
106 WP_FIRST = WEAPON_KASTET;
107 WP_LAST = WEAPON_FLAMETHROWER;
110 var
111 gwep_debug_fast_trace: Boolean = true;
114 implementation
116 uses
117 Math, g_map, g_player, g_gfx, g_sound, g_main, g_panel,
118 g_console, g_options, g_game,
119 g_triggers, MAPDEF, e_log, g_monsters, g_saveload,
120 g_language, g_netmsg, g_grid,
121 geom, binheap, hashtable, utils, xstreams;
123 type
124 TWaterPanel = record
125 X, Y: Integer;
126 Width, Height: Word;
127 Active: Boolean;
128 end;
130 const
131 SHOT_ROCKETLAUNCHER_WIDTH = 14;
132 SHOT_ROCKETLAUNCHER_HEIGHT = 14;
134 SHOT_SKELFIRE_WIDTH = 14;
135 SHOT_SKELFIRE_HEIGHT = 14;
137 SHOT_PLASMA_WIDTH = 16;
138 SHOT_PLASMA_HEIGHT = 16;
140 SHOT_BFG_WIDTH = 32;
141 SHOT_BFG_HEIGHT = 32;
142 SHOT_BFG_DAMAGE = 100;
143 SHOT_BFG_RADIUS = 256;
145 SHOT_FLAME_WIDTH = 4;
146 SHOT_FLAME_HEIGHT = 4;
147 SHOT_FLAME_LIFETIME = 180;
149 SHOT_SIGNATURE = $544F4853; // 'SHOT'
151 type
152 PHitTime = ^THitTime;
153 THitTime = record
154 distSq: Integer;
155 mon: TMonster;
156 plridx: Integer; // if mon=nil
157 x, y: Integer;
158 end;
160 TBinHeapKeyHitTime = class
161 public
162 class function less (const a, b: Integer): Boolean; inline;
163 end;
165 // indicies in `wgunHitTime` array
166 TBinaryHeapHitTimes = specialize TBinaryHeapBase<Integer, TBinHeapKeyHitTime>;
168 var
169 WaterMap: array of array of DWORD = nil;
170 //wgunMonHash: THashIntInt = nil;
171 wgunHitHeap: TBinaryHeapHitTimes = nil;
172 wgunHitTime: array of THitTime = nil;
173 wgunHitTimeUsed: Integer = 0;
176 class function TBinHeapKeyHitTime.less (const a, b: Integer): Boolean;
177 var
178 hta, htb: PHitTime;
179 begin
180 hta := @wgunHitTime[a];
181 htb := @wgunHitTime[b];
182 if (hta.distSq <> htb.distSq) then begin result := (hta.distSq < htb.distSq); exit; end;
183 if (hta.mon <> nil) then
184 begin
185 // a is monster
186 if (htb.mon = nil) then begin result := false; exit; end; // players first
187 result := (hta.mon.UID < htb.mon.UID); // why not?
188 end
189 else
190 begin
191 // a is player
192 if (htb.mon <> nil) then begin result := true; exit; end; // players first
193 result := (hta.plridx < htb.plridx); // why not?
194 end;
195 end;
198 procedure appendHitTimeMon (adistSq: Integer; amon: TMonster; ax, ay: Integer);
199 begin
200 if (wgunHitTimeUsed = Length(wgunHitTime)) then SetLength(wgunHitTime, wgunHitTimeUsed+128);
201 with wgunHitTime[wgunHitTimeUsed] do
202 begin
203 distSq := adistSq;
204 mon := amon;
205 plridx := -1;
206 x := ax;
207 y := ay;
208 end;
209 wgunHitHeap.insert(wgunHitTimeUsed);
210 Inc(wgunHitTimeUsed);
211 end;
214 procedure appendHitTimePlr (adistSq: Integer; aplridx: Integer; ax, ay: Integer);
215 begin
216 if (wgunHitTimeUsed = Length(wgunHitTime)) then SetLength(wgunHitTime, wgunHitTimeUsed+128);
217 with wgunHitTime[wgunHitTimeUsed] do
218 begin
219 distSq := adistSq;
220 mon := nil;
221 plridx := aplridx;
222 x := ax;
223 y := ay;
224 end;
225 wgunHitHeap.insert(wgunHitTimeUsed);
226 Inc(wgunHitTimeUsed);
227 end;
230 function FindShot(): DWORD;
231 var
232 i: Integer;
233 begin
234 if Shots <> nil then
235 for i := 0 to High(Shots) do
236 if Shots[i].ShotType = 0 then
237 begin
238 Result := i;
239 LastShotID := Result;
240 Exit;
241 end;
243 if Shots = nil then
244 begin
245 SetLength(Shots, 128);
246 Result := 0;
247 end
248 else
249 begin
250 Result := High(Shots) + 1;
251 SetLength(Shots, Length(Shots) + 128);
252 end;
253 LastShotID := Result;
254 end;
256 procedure CreateWaterMap();
257 var
258 WaterArray: Array of TWaterPanel;
259 a, b, c, m: Integer;
260 ok: Boolean;
261 begin
262 if gWater = nil then
263 Exit;
265 SetLength(WaterArray, Length(gWater));
267 for a := 0 to High(gWater) do
268 begin
269 WaterArray[a].X := gWater[a].X;
270 WaterArray[a].Y := gWater[a].Y;
271 WaterArray[a].Width := gWater[a].Width;
272 WaterArray[a].Height := gWater[a].Height;
273 WaterArray[a].Active := True;
274 end;
276 g_Game_SetLoadingText(_lc[I_LOAD_WATER_MAP], High(WaterArray), False);
278 for a := 0 to High(WaterArray) do
279 if WaterArray[a].Active then
280 begin
281 WaterArray[a].Active := False;
282 m := Length(WaterMap);
283 SetLength(WaterMap, m+1);
284 SetLength(WaterMap[m], 1);
285 WaterMap[m][0] := a;
286 ok := True;
288 while ok do
289 begin
290 ok := False;
291 for b := 0 to High(WaterArray) do
292 if WaterArray[b].Active then
293 for c := 0 to High(WaterMap[m]) do
294 if g_CollideAround(WaterArray[b].X,
295 WaterArray[b].Y,
296 WaterArray[b].Width,
297 WaterArray[b].Height,
298 WaterArray[WaterMap[m][c]].X,
299 WaterArray[WaterMap[m][c]].Y,
300 WaterArray[WaterMap[m][c]].Width,
301 WaterArray[WaterMap[m][c]].Height) then
302 begin
303 WaterArray[b].Active := False;
304 SetLength(WaterMap[m],
305 Length(WaterMap[m])+1);
306 WaterMap[m][High(WaterMap[m])] := b;
307 ok := True;
308 Break;
309 end;
310 end;
312 g_Game_StepLoading();
313 end;
315 WaterArray := nil;
316 end;
319 var
320 chkTrap_pl: array [0..256] of Integer;
321 chkTrap_mn: array [0..65535] of TMonster;
323 procedure CheckTrap(ID: DWORD; dm: Integer; t: Byte);
324 var
325 //a, b, c, d, i1, i2: Integer;
326 //chkTrap_pl, chkTrap_mn: WArray;
327 plaCount: Integer = 0;
328 mnaCount: Integer = 0;
329 frameId: DWord;
332 function monsWaterCheck (mon: TMonster): Boolean;
333 begin
334 result := false; // don't stop
335 if mon.alive and mon.Collide(gWater[WaterMap[a][c]]) and (not InWArray(monidx, chkTrap_mn)) and (i2 < 1023) then //FIXME
336 begin
337 i2 += 1;
338 chkTrap_mn[i2] := monidx;
339 end;
340 end;
343 function monsWaterCheck (mon: TMonster): Boolean;
344 begin
345 result := false; // don't stop
346 if (mon.trapCheckFrameId <> frameId) then
347 begin
348 mon.trapCheckFrameId := frameId;
349 chkTrap_mn[mnaCount] := mon;
350 Inc(mnaCount);
351 end;
352 end;
354 var
355 a, b, c, d, f: Integer;
356 pan: TPanel;
357 begin
358 if (gWater = nil) or (WaterMap = nil) then Exit;
360 frameId := g_Mons_getNewTrapFrameId();
362 //i1 := -1;
363 //i2 := -1;
365 //SetLength(chkTrap_pl, 1024);
366 //SetLength(chkTrap_mn, 1024);
367 //for d := 0 to 1023 do chkTrap_pl[d] := $FFFF;
368 //for d := 0 to 1023 do chkTrap_mn[d] := $FFFF;
370 for a := 0 to High(WaterMap) do
371 begin
372 for b := 0 to High(WaterMap[a]) do
373 begin
374 pan := gWater[WaterMap[a][b]];
375 if not g_Obj_Collide(pan.X, pan.Y, pan.Width, pan.Height, @Shots[ID].Obj) then continue;
377 for c := 0 to High(WaterMap[a]) do
378 begin
379 pan := gWater[WaterMap[a][c]];
380 for d := 0 to High(gPlayers) do
381 begin
382 if (gPlayers[d] <> nil) and (gPlayers[d].alive) then
383 begin
384 if gPlayers[d].Collide(pan) then
385 begin
386 f := 0;
387 while (f < plaCount) and (chkTrap_pl[f] <> d) do Inc(f);
388 if (f = plaCount) then
389 begin
390 chkTrap_pl[plaCount] := d;
391 Inc(plaCount);
392 if (plaCount = Length(chkTrap_pl)) then break;
393 end;
394 end;
395 end;
396 end;
398 //g_Mons_ForEach(monsWaterCheck);
399 g_Mons_ForEachAliveAt(pan.X, pan.Y, pan.Width, pan.Height, monsWaterCheck);
400 end;
402 for f := 0 to plaCount-1 do gPlayers[chkTrap_pl[f]].Damage(dm, Shots[ID].SpawnerUID, 0, 0, t);
403 for f := 0 to mnaCount-1 do chkTrap_mn[f].Damage(dm, 0, 0, Shots[ID].SpawnerUID, t);
404 end;
405 end;
407 //chkTrap_pl := nil;
408 //chkTrap_mn := nil;
409 end;
411 function HitMonster(m: TMonster; d: Integer; vx, vy: Integer; SpawnerUID: Word; t: Byte): Boolean;
412 var
413 tt, mt: Byte;
414 mon: TMonster;
415 begin
416 Result := False;
418 tt := g_GetUIDType(SpawnerUID);
419 if tt = UID_MONSTER then
420 begin
421 mon := g_Monsters_ByUID(SpawnerUID);
422 if mon <> nil then
423 mt := g_Monsters_ByUID(SpawnerUID).MonsterType
424 else
425 mt := 0;
426 end
427 else
428 mt := 0;
430 if m = nil then Exit;
431 if m.UID = SpawnerUID then
432 begin
433 // Ñàì ñåáÿ ìîæåò ðàíèòü òîëüêî ðàêåòîé è òîêîì:
434 if (t <> HIT_ROCKET) and (t <> HIT_ELECTRO) then
435 Exit;
436 // Êèáåð äåìîí è áî÷êà âîîáùå íå ìîãóò ñåáÿ ðàíèòü:
437 if (m.MonsterType = MONSTER_CYBER) or
438 (m.MonsterType = MONSTER_BARREL) then
439 begin
440 Result := True;
441 Exit;
442 end;
443 end;
445 if tt = UID_MONSTER then
446 begin
447 // Lost_Soul íå ìîæåò ðàíèòü Pain_Elemental'à:
448 if (mt = MONSTER_SOUL) and (m.MonsterType = MONSTER_PAIN) then
449 Exit;
451 // Îáà ìîíñòðà îäíîãî âèäà:
452 if mt = m.MonsterType then
453 case mt of
454 MONSTER_IMP, MONSTER_DEMON, MONSTER_BARON, MONSTER_KNIGHT, MONSTER_CACO,
455 MONSTER_SOUL, MONSTER_MANCUB, MONSTER_SKEL, MONSTER_FISH:
456 Exit; // Ýòè íå áüþò ñâîèõ
457 end;
458 end;
460 if g_Game_IsServer then
461 begin
462 if (t <> HIT_FLAME) or (m.FFireTime = 0) or (vx <> 0) or (vy <> 0) then
463 Result := m.Damage(d, vx, vy, SpawnerUID, t)
464 else
465 Result := True;
466 if t = HIT_FLAME then
467 m.CatchFire(SpawnerUID);
468 end
469 else
470 Result := True;
471 end;
474 function HitPlayer (p: TPlayer; d: Integer; vx, vy: Integer; SpawnerUID: Word; t: Byte): Boolean;
475 begin
476 result := False;
478 // Ñàì ñåáÿ ìîæåò ðàíèòü òîëüêî ðàêåòîé è òîêîì
479 if (p.UID = SpawnerUID) and (t <> HIT_ROCKET) and (t <> HIT_ELECTRO) then exit;
481 if g_Game_IsServer then
482 begin
483 if (t <> HIT_FLAME) or (p.FFireTime = 0) or (vx <> 0) or (vy <> 0) then p.Damage(d, SpawnerUID, vx, vy, t);
484 if (t = HIT_FLAME) then p.CatchFire(SpawnerUID);
485 end;
487 result := true;
488 end;
491 procedure g_Weapon_BFG9000(X, Y: Integer; SpawnerUID: Word);
493 function monsCheck (mon: TMonster): Boolean;
494 begin
495 result := false; // don't stop
496 if (mon.alive) and (mon.UID <> SpawnerUID) then
497 begin
498 with mon do
499 begin
500 if (g_PatchLength(X, Y, Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2),
501 Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)) <= SHOT_BFG_RADIUS) and
502 g_TraceVector(X, Y, Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2),
503 Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)) then
504 begin
505 if HitMonster(mon, 50, 0, 0, SpawnerUID, HIT_SOME) then mon.BFGHit();
506 end;
507 end;
508 end;
509 end;
511 var
512 i, h: Integer;
513 st: Byte;
514 pl: TPlayer;
515 b: Boolean;
516 begin
517 //g_Sound_PlayEx('SOUND_WEAPON_EXPLODEBFG', 255);
519 h := High(gCorpses);
521 if gAdvCorpses and (h <> -1) then
522 for i := 0 to h do
523 if (gCorpses[i] <> nil) and (gCorpses[i].State <> CORPSE_STATE_REMOVEME) then
524 with gCorpses[i] do
525 if (g_PatchLength(X, Y, Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2),
526 Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)) <= SHOT_BFG_RADIUS) and
527 g_TraceVector(X, Y, Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2),
528 Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)) then
529 begin
530 Damage(50, 0, 0);
531 g_Weapon_BFGHit(Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2),
532 Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2));
533 end;
535 st := TEAM_NONE;
536 pl := g_Player_Get(SpawnerUID);
537 if pl <> nil then
538 st := pl.Team;
540 h := High(gPlayers);
542 if h <> -1 then
543 for i := 0 to h do
544 if (gPlayers[i] <> nil) and (gPlayers[i].alive) and (gPlayers[i].UID <> SpawnerUID) then
545 with gPlayers[i] do
546 if (g_PatchLength(X, Y, GameX+PLAYER_RECT.X+(PLAYER_RECT.Width div 2),
547 GameY+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)) <= SHOT_BFG_RADIUS) and
548 g_TraceVector(X, Y, GameX+PLAYER_RECT.X+(PLAYER_RECT.Width div 2),
549 GameY+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)) then
550 begin
551 if (st = TEAM_NONE) or (st <> gPlayers[i].Team) then
552 b := HitPlayer(gPlayers[i], 50, 0, 0, SpawnerUID, HIT_SOME)
553 else
554 b := HitPlayer(gPlayers[i], 25, 0, 0, SpawnerUID, HIT_SOME);
555 if b then
556 gPlayers[i].BFGHit();
557 end;
559 //FIXME
560 g_Mons_ForEachAlive(monsCheck);
561 end;
563 function g_Weapon_CreateShot(I: Integer; ShotType: Byte; Spawner, TargetUID: Word; X, Y, XV, YV: Integer): LongWord;
564 var
565 find_id: DWord;
566 FramesID: DWORD = 0;
567 begin
568 if I < 0 then
569 find_id := FindShot()
570 else
571 begin
572 find_id := I;
573 if Integer(find_id) >= High(Shots) then
574 SetLength(Shots, find_id + 64)
575 end;
577 case ShotType of
578 WEAPON_ROCKETLAUNCHER:
579 begin
580 with Shots[find_id] do
581 begin
582 g_Obj_Init(@Obj);
584 Obj.Rect.Width := SHOT_ROCKETLAUNCHER_WIDTH;
585 Obj.Rect.Height := SHOT_ROCKETLAUNCHER_HEIGHT;
587 Animation := nil;
588 Triggers := nil;
589 ShotType := WEAPON_ROCKETLAUNCHER;
590 g_Texture_Get('TEXTURE_WEAPON_ROCKET', TextureID);
591 end;
592 end;
594 WEAPON_PLASMA:
595 begin
596 with Shots[find_id] do
597 begin
598 g_Obj_Init(@Obj);
600 Obj.Rect.Width := SHOT_PLASMA_WIDTH;
601 Obj.Rect.Height := SHOT_PLASMA_HEIGHT;
603 Triggers := nil;
604 ShotType := WEAPON_PLASMA;
605 g_Frames_Get(FramesID, 'FRAMES_WEAPON_PLASMA');
606 Animation := TAnimation.Create(FramesID, True, 5);
607 end;
608 end;
610 WEAPON_BFG:
611 begin
612 with Shots[find_id] do
613 begin
614 g_Obj_Init(@Obj);
616 Obj.Rect.Width := SHOT_BFG_WIDTH;
617 Obj.Rect.Height := SHOT_BFG_HEIGHT;
619 Triggers := nil;
620 ShotType := WEAPON_BFG;
621 g_Frames_Get(FramesID, 'FRAMES_WEAPON_BFG');
622 Animation := TAnimation.Create(FramesID, True, 6);
623 end;
624 end;
626 WEAPON_FLAMETHROWER:
627 begin
628 with Shots[find_id] do
629 begin
630 g_Obj_Init(@Obj);
632 Obj.Rect.Width := SHOT_FLAME_WIDTH;
633 Obj.Rect.Height := SHOT_FLAME_HEIGHT;
635 Triggers := nil;
636 ShotType := WEAPON_FLAMETHROWER;
637 Animation := nil;
638 TextureID := 0;
639 g_Frames_Get(TextureID, 'FRAMES_FLAME');
640 end;
641 end;
643 WEAPON_IMP_FIRE:
644 begin
645 with Shots[find_id] do
646 begin
647 g_Obj_Init(@Obj);
649 Obj.Rect.Width := 16;
650 Obj.Rect.Height := 16;
652 Triggers := nil;
653 ShotType := WEAPON_IMP_FIRE;
654 g_Frames_Get(FramesID, 'FRAMES_WEAPON_IMPFIRE');
655 Animation := TAnimation.Create(FramesID, True, 4);
656 end;
657 end;
659 WEAPON_CACO_FIRE:
660 begin
661 with Shots[find_id] do
662 begin
663 g_Obj_Init(@Obj);
665 Obj.Rect.Width := 16;
666 Obj.Rect.Height := 16;
668 Triggers := nil;
669 ShotType := WEAPON_CACO_FIRE;
670 g_Frames_Get(FramesID, 'FRAMES_WEAPON_CACOFIRE');
671 Animation := TAnimation.Create(FramesID, True, 4);
672 end;
673 end;
675 WEAPON_MANCUB_FIRE:
676 begin
677 with Shots[find_id] do
678 begin
679 g_Obj_Init(@Obj);
681 Obj.Rect.Width := 32;
682 Obj.Rect.Height := 32;
684 Triggers := nil;
685 ShotType := WEAPON_MANCUB_FIRE;
686 g_Frames_Get(FramesID, 'FRAMES_WEAPON_MANCUBFIRE');
687 Animation := TAnimation.Create(FramesID, True, 4);
688 end;
689 end;
691 WEAPON_BARON_FIRE:
692 begin
693 with Shots[find_id] do
694 begin
695 g_Obj_Init(@Obj);
697 Obj.Rect.Width := 32;
698 Obj.Rect.Height := 16;
700 Triggers := nil;
701 ShotType := WEAPON_BARON_FIRE;
702 g_Frames_Get(FramesID, 'FRAMES_WEAPON_BARONFIRE');
703 Animation := TAnimation.Create(FramesID, True, 4);
704 end;
705 end;
707 WEAPON_BSP_FIRE:
708 begin
709 with Shots[find_id] do
710 begin
711 g_Obj_Init(@Obj);
713 Obj.Rect.Width := 16;
714 Obj.Rect.Height := 16;
716 Triggers := nil;
717 ShotType := WEAPON_BSP_FIRE;
718 g_Frames_Get(FramesID, 'FRAMES_WEAPON_BSPFIRE');
719 Animation := TAnimation.Create(FramesID, True, 4);
720 end;
721 end;
723 WEAPON_SKEL_FIRE:
724 begin
725 with Shots[find_id] do
726 begin
727 g_Obj_Init(@Obj);
729 Obj.Rect.Width := SHOT_SKELFIRE_WIDTH;
730 Obj.Rect.Height := SHOT_SKELFIRE_HEIGHT;
732 Triggers := nil;
733 ShotType := WEAPON_SKEL_FIRE;
734 target := TargetUID;
735 g_Frames_Get(FramesID, 'FRAMES_WEAPON_SKELFIRE');
736 Animation := TAnimation.Create(FramesID, True, 5);
737 end;
738 end;
739 end;
741 Shots[find_id].Obj.X := X;
742 Shots[find_id].Obj.Y := Y;
743 Shots[find_id].Obj.Vel.X := XV;
744 Shots[find_id].Obj.Vel.Y := YV;
745 Shots[find_id].Obj.Accel.X := 0;
746 Shots[find_id].Obj.Accel.Y := 0;
747 Shots[find_id].SpawnerUID := Spawner;
748 if (ShotType = WEAPON_FLAMETHROWER) and (XV = 0) and (YV = 0) then
749 Shots[find_id].Stopped := 255
750 else
751 Shots[find_id].Stopped := 0;
752 Result := find_id;
753 end;
755 procedure throw(i, x, y, xd, yd, s: Integer);
756 var
757 a: Integer;
758 begin
759 yd := yd - y;
760 xd := xd - x;
762 a := Max(Abs(xd), Abs(yd));
763 if a = 0 then
764 a := 1;
766 Shots[i].Obj.X := x;
767 Shots[i].Obj.Y := y;
768 Shots[i].Obj.Vel.X := (xd*s) div a;
769 Shots[i].Obj.Vel.Y := (yd*s) div a;
770 Shots[i].Obj.Accel.X := 0;
771 Shots[i].Obj.Accel.Y := 0;
772 Shots[i].Stopped := 0;
773 if Shots[i].ShotType in [WEAPON_ROCKETLAUNCHER, WEAPON_BFG] then
774 Shots[i].Timeout := 900 // ~25 sec
775 else
776 begin
777 if Shots[i].ShotType = WEAPON_FLAMETHROWER then
778 Shots[i].Timeout := SHOT_FLAME_LIFETIME
779 else
780 Shots[i].Timeout := 550; // ~15 sec
781 end;
782 end;
784 function g_Weapon_Hit(obj: PObj; d: Integer; SpawnerUID: Word; t: Byte; HitCorpses: Boolean = True): Byte;
785 var
786 i, h: Integer;
788 function PlayerHit(Team: Byte = 0): Boolean;
789 var
790 i: Integer;
791 ChkTeam: Boolean;
792 p: TPlayer;
793 begin
794 Result := False;
795 h := High(gPlayers);
797 if h <> -1 then
798 for i := 0 to h do
799 if (gPlayers[i] <> nil) and gPlayers[i].alive and g_Obj_Collide(obj, @gPlayers[i].Obj) then
800 begin
801 ChkTeam := True;
802 if (Team > 0) and (g_GetUIDType(SpawnerUID) = UID_PLAYER) then
803 begin
804 p := g_Player_Get(SpawnerUID);
805 if p <> nil then
806 ChkTeam := (p.Team = gPlayers[i].Team) xor (Team = 2);
807 end;
808 if ChkTeam then
809 if HitPlayer(gPlayers[i], d, obj^.Vel.X, obj^.Vel.Y, SpawnerUID, t) then
810 begin
811 if t <> HIT_FLAME then
812 gPlayers[i].Push((obj^.Vel.X+obj^.Accel.X)*IfThen(t = HIT_BFG, 8, 1) div 4,
813 (obj^.Vel.Y+obj^.Accel.Y)*IfThen(t = HIT_BFG, 8, 1) div 4);
814 if t = HIT_BFG then
815 g_Game_DelayEvent(DE_BFGHIT, 1000, SpawnerUID);
816 Result := True;
817 break;
818 end;
819 end;
820 end;
823 function monsCheckHit (monidx: Integer; mon: TMonster): Boolean;
824 begin
825 result := false; // don't stop
826 if mon.alive and g_Obj_Collide(obj, @mon.Obj) then
827 begin
828 if HitMonster(mon, d, obj^.Vel.X, obj^.Vel.Y, SpawnerUID, t) then
829 begin
830 if (t <> HIT_FLAME) then
831 begin
832 mon.Push((obj^.Vel.X+obj^.Accel.X)*IfThen(t = HIT_BFG, 8, 1) div 4,
833 (obj^.Vel.Y+obj^.Accel.Y)*IfThen(t = HIT_BFG, 8, 1) div 4);
834 end;
835 result := True;
836 end;
837 end;
838 end;
841 function monsCheckHit (mon: TMonster): Boolean;
842 begin
843 result := false; // don't stop
844 if HitMonster(mon, d, obj.Vel.X, obj.Vel.Y, SpawnerUID, t) then
845 begin
846 if (t <> HIT_FLAME) then
847 begin
848 mon.Push((obj.Vel.X+obj.Accel.X)*IfThen(t = HIT_BFG, 8, 1) div 4,
849 (obj.Vel.Y+obj.Accel.Y)*IfThen(t = HIT_BFG, 8, 1) div 4);
850 end;
851 result := true;
852 end;
853 end;
855 function MonsterHit(): Boolean;
856 begin
857 //result := g_Mons_ForEach(monsCheckHit);
858 //FIXME: accelerate this!
859 result := g_Mons_ForEachAliveAt(obj.X+obj.Rect.X, obj.Y+obj.Rect.Y, obj.Rect.Width, obj.Rect.Height, monsCheckHit);
860 end;
862 begin
863 Result := 0;
865 if HitCorpses then
866 begin
867 h := High(gCorpses);
869 if gAdvCorpses and (h <> -1) then
870 for i := 0 to h do
871 if (gCorpses[i] <> nil) and (gCorpses[i].State <> CORPSE_STATE_REMOVEME) and
872 g_Obj_Collide(obj, @gCorpses[i].Obj) then
873 begin
874 // Ðàñïèëèâàåì òðóï:
875 gCorpses[i].Damage(d, (obj^.Vel.X+obj^.Accel.X) div 4,
876 (obj^.Vel.Y+obj^.Accel.Y) div 4);
877 Result := 1;
878 end;
879 end;
881 case gGameSettings.GameMode of
882 // Êàìïàíèÿ:
883 GM_COOP, GM_SINGLE:
884 begin
885 // Ñíà÷àëà áü¸ì ìîíñòðîâ, åñëè åñòü, ïîòîì ïûòàåìñÿ áèòü èãðîêîâ
886 if MonsterHit() then
887 begin
888 Result := 2;
889 Exit;
890 end;
892 if PlayerHit() then
893 begin
894 Result := 1;
895 Exit;
896 end;
897 end;
899 // Äåçìàò÷:
900 GM_DM:
901 begin
902 // Ñíà÷àëà áü¸ì èãðîêîâ, åñëè åñòü, ïîòîì ïûòàåìñÿ áèòü ìîíñòðîâ
903 if PlayerHit() then
904 begin
905 Result := 1;
906 Exit;
907 end;
909 if MonsterHit() then
910 begin
911 Result := 2;
912 Exit;
913 end;
914 end;
916 // Êîìàíäíûå:
917 GM_TDM, GM_CTF:
918 begin
919 // Ñíà÷àëà áü¸ì èãðîêîâ êîìàíäû ñîïåðíèêà
920 if PlayerHit(2) then
921 begin
922 Result := 1;
923 Exit;
924 end;
926 // Ïîòîì ìîíñòðîâ
927 if MonsterHit() then
928 begin
929 Result := 2;
930 Exit;
931 end;
933 // È â êîíöå ñâîèõ èãðîêîâ
934 if PlayerHit(1) then
935 begin
936 Result := 1;
937 Exit;
938 end;
939 end;
941 end;
942 end;
944 function g_Weapon_HitUID(UID: Word; d: Integer; SpawnerUID: Word; t: Byte): Boolean;
945 begin
946 Result := False;
948 case g_GetUIDType(UID) of
949 UID_PLAYER: Result := HitPlayer(g_Player_Get(UID), d, 0, 0, SpawnerUID, t);
950 UID_MONSTER: Result := HitMonster(g_Monsters_ByUID(UID), d, 0, 0, SpawnerUID, t);
951 else Exit;
952 end;
953 end;
955 function g_Weapon_Explode(X, Y: Integer; rad: Integer; SpawnerUID: Word): Boolean;
956 var
957 r: Integer; // squared radius
959 function monsExCheck (mon: TMonster): Boolean;
960 var
961 dx, dy, mm: Integer;
962 begin
963 result := false; // don't stop
964 begin
965 dx := mon.Obj.X+mon.Obj.Rect.X+(mon.Obj.Rect.Width div 2)-X;
966 dy := mon.Obj.Y+mon.Obj.Rect.Y+(mon.Obj.Rect.Height div 2)-Y;
968 if dx > 1000 then dx := 1000;
969 if dy > 1000 then dy := 1000;
971 if (dx*dx+dy*dy < r) then
972 begin
973 //m := PointToRect(X, Y, Obj.X+Obj.Rect.X, Obj.Y+Obj.Rect.Y, Obj.Rect.Width, Obj.Rect.Height);
974 //e_WriteLog(Format('explo monster #%d: x=%d; y=%d; rad=%d; dx=%d; dy=%d', [monidx, X, Y, rad, dx, dy]), MSG_NOTIFY);
976 mm := Max(abs(dx), abs(dy));
977 if mm = 0 then mm := 1;
979 if mon.alive then
980 begin
981 HitMonster(mon, ((mon.Obj.Rect.Width div 4)*10*(rad-mm)) div rad, 0, 0, SpawnerUID, HIT_ROCKET);
982 end;
984 mon.Push((dx*7) div mm, (dy*7) div mm);
985 end;
986 end;
987 end;
989 var
990 i, h, dx, dy, m, mm: Integer;
991 _angle: SmallInt;
992 begin
993 result := false;
995 g_Triggers_PressC(X, Y, rad, SpawnerUID, ACTIVATE_SHOT);
997 r := rad*rad;
999 h := High(gPlayers);
1001 if h <> -1 then
1002 for i := 0 to h do
1003 if (gPlayers[i] <> nil) and gPlayers[i].alive then
1004 with gPlayers[i] do
1005 begin
1006 dx := Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2)-X;
1007 dy := Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)-Y;
1009 if dx > 1000 then dx := 1000;
1010 if dy > 1000 then dy := 1000;
1012 if dx*dx+dy*dy < r then
1013 begin
1014 //m := PointToRect(X, Y, GameX+PLAYER_RECT.X, GameY+PLAYER_RECT.Y,
1015 // PLAYER_RECT.Width, PLAYER_RECT.Height);
1017 mm := Max(abs(dx), abs(dy));
1018 if mm = 0 then mm := 1;
1020 HitPlayer(gPlayers[i], (100*(rad-mm)) div rad, (dx*10) div mm, (dy*10) div mm, SpawnerUID, HIT_ROCKET);
1021 gPlayers[i].Push((dx*7) div mm, (dy*7) div mm);
1022 end;
1023 end;
1025 //g_Mons_ForEach(monsExCheck);
1026 g_Mons_ForEachAt(X-(rad+32), Y-(rad+32), (rad+32)*2, (rad+32)*2, monsExCheck);
1028 h := High(gCorpses);
1030 if gAdvCorpses and (h <> -1) then
1031 for i := 0 to h do
1032 if (gCorpses[i] <> nil) and (gCorpses[i].State <> CORPSE_STATE_REMOVEME) then
1033 with gCorpses[i] do
1034 begin
1035 dx := Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2)-X;
1036 dy := Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)-Y;
1038 if dx > 1000 then dx := 1000;
1039 if dy > 1000 then dy := 1000;
1041 if dx*dx+dy*dy < r then
1042 begin
1043 m := PointToRect(X, Y, Obj.X+Obj.Rect.X, Obj.Y+Obj.Rect.Y,
1044 Obj.Rect.Width, Obj.Rect.Height);
1046 mm := Max(abs(dx), abs(dy));
1047 if mm = 0 then mm := 1;
1049 Damage(Round(100*(rad-m)/rad), (dx*10) div mm, (dy*10) div mm);
1050 end;
1051 end;
1053 h := High(gGibs);
1055 if gAdvGibs and (h <> -1) then
1056 for i := 0 to h do
1057 if gGibs[i].alive then
1058 with gGibs[i] do
1059 begin
1060 dx := Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2)-X;
1061 dy := Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)-Y;
1063 if dx > 1000 then dx := 1000;
1064 if dy > 1000 then dy := 1000;
1066 if dx*dx+dy*dy < r then
1067 begin
1068 m := PointToRect(X, Y, Obj.X+Obj.Rect.X, Obj.Y+Obj.Rect.Y,
1069 Obj.Rect.Width, Obj.Rect.Height);
1070 _angle := GetAngle(Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2),
1071 Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2), X, Y);
1073 g_Obj_PushA(@Obj, Round(15*(rad-m)/rad), _angle);
1074 positionChanged(); // this updates spatial accelerators
1075 end;
1076 end;
1077 end;
1079 procedure g_Weapon_Init();
1080 begin
1081 CreateWaterMap();
1082 end;
1084 procedure g_Weapon_Free();
1085 var
1086 i: Integer;
1087 begin
1088 if Shots <> nil then
1089 begin
1090 for i := 0 to High(Shots) do
1091 if Shots[i].ShotType <> 0 then
1092 Shots[i].Animation.Free();
1094 Shots := nil;
1095 end;
1097 WaterMap := nil;
1098 end;
1100 procedure g_Weapon_LoadData();
1101 begin
1102 e_WriteLog('Loading weapons data...', TMsgType.Notify);
1104 g_Sound_CreateWADEx('SOUND_WEAPON_HITPUNCH', GameWAD+':SOUNDS\HITPUNCH');
1105 g_Sound_CreateWADEx('SOUND_WEAPON_MISSPUNCH', GameWAD+':SOUNDS\MISSPUNCH');
1106 g_Sound_CreateWADEx('SOUND_WEAPON_HITBERSERK', GameWAD+':SOUNDS\HITBERSERK');
1107 g_Sound_CreateWADEx('SOUND_WEAPON_MISSBERSERK', GameWAD+':SOUNDS\MISSBERSERK');
1108 g_Sound_CreateWADEx('SOUND_WEAPON_SELECTSAW', GameWAD+':SOUNDS\SELECTSAW');
1109 g_Sound_CreateWADEx('SOUND_WEAPON_IDLESAW', GameWAD+':SOUNDS\IDLESAW');
1110 g_Sound_CreateWADEx('SOUND_WEAPON_HITSAW', GameWAD+':SOUNDS\HITSAW');
1111 g_Sound_CreateWADEx('SOUND_WEAPON_FIRESHOTGUN2', GameWAD+':SOUNDS\FIRESHOTGUN2');
1112 g_Sound_CreateWADEx('SOUND_WEAPON_FIRESHOTGUN', GameWAD+':SOUNDS\FIRESHOTGUN');
1113 g_Sound_CreateWADEx('SOUND_WEAPON_FIRESAW', GameWAD+':SOUNDS\FIRESAW');
1114 g_Sound_CreateWADEx('SOUND_WEAPON_FIREROCKET', GameWAD+':SOUNDS\FIREROCKET');
1115 g_Sound_CreateWADEx('SOUND_WEAPON_FIREPLASMA', GameWAD+':SOUNDS\FIREPLASMA');
1116 g_Sound_CreateWADEx('SOUND_WEAPON_FIREPISTOL', GameWAD+':SOUNDS\FIREPISTOL');
1117 g_Sound_CreateWADEx('SOUND_WEAPON_FIRECGUN', GameWAD+':SOUNDS\FIRECGUN');
1118 g_Sound_CreateWADEx('SOUND_WEAPON_FIREBFG', GameWAD+':SOUNDS\FIREBFG');
1119 g_Sound_CreateWADEx('SOUND_FIRE', GameWAD+':SOUNDS\FIRE');
1120 g_Sound_CreateWADEx('SOUND_WEAPON_STARTFIREBFG', GameWAD+':SOUNDS\STARTFIREBFG');
1121 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEROCKET', GameWAD+':SOUNDS\EXPLODEROCKET');
1122 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEBFG', GameWAD+':SOUNDS\EXPLODEBFG');
1123 g_Sound_CreateWADEx('SOUND_WEAPON_BFGWATER', GameWAD+':SOUNDS\BFGWATER');
1124 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEPLASMA', GameWAD+':SOUNDS\EXPLODEPLASMA');
1125 g_Sound_CreateWADEx('SOUND_WEAPON_PLASMAWATER', GameWAD+':SOUNDS\PLASMAWATER');
1126 g_Sound_CreateWADEx('SOUND_WEAPON_FIREBALL', GameWAD+':SOUNDS\FIREBALL');
1127 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEBALL', GameWAD+':SOUNDS\EXPLODEBALL');
1128 g_Sound_CreateWADEx('SOUND_WEAPON_FIREREV', GameWAD+':SOUNDS\FIREREV');
1129 g_Sound_CreateWADEx('SOUND_WEAPON_FLAMEON', GameWAD+':SOUNDS\STARTFLM');
1130 g_Sound_CreateWADEx('SOUND_WEAPON_FLAMEOFF', GameWAD+':SOUNDS\STOPFLM');
1131 g_Sound_CreateWADEx('SOUND_WEAPON_FLAMEWORK', GameWAD+':SOUNDS\WORKFLM');
1132 g_Sound_CreateWADEx('SOUND_PLAYER_JETFLY', GameWAD+':SOUNDS\WORKJETPACK');
1133 g_Sound_CreateWADEx('SOUND_PLAYER_JETON', GameWAD+':SOUNDS\STARTJETPACK');
1134 g_Sound_CreateWADEx('SOUND_PLAYER_JETOFF', GameWAD+':SOUNDS\STOPJETPACK');
1135 g_Sound_CreateWADEx('SOUND_PLAYER_CASING1', GameWAD+':SOUNDS\CASING1');
1136 g_Sound_CreateWADEx('SOUND_PLAYER_CASING2', GameWAD+':SOUNDS\CASING2');
1137 g_Sound_CreateWADEx('SOUND_PLAYER_SHELL1', GameWAD+':SOUNDS\SHELL1');
1138 g_Sound_CreateWADEx('SOUND_PLAYER_SHELL2', GameWAD+':SOUNDS\SHELL2');
1140 g_Texture_CreateWADEx('TEXTURE_WEAPON_ROCKET', GameWAD+':TEXTURES\BROCKET');
1141 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_SKELFIRE', GameWAD+':TEXTURES\BSKELFIRE', 64, 16, 2);
1142 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_BFG', GameWAD+':TEXTURES\BBFG', 64, 64, 2);
1143 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_PLASMA', GameWAD+':TEXTURES\BPLASMA', 16, 16, 2);
1144 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_IMPFIRE', GameWAD+':TEXTURES\BIMPFIRE', 16, 16, 2);
1145 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_BSPFIRE', GameWAD+':TEXTURES\BBSPFIRE', 16, 16, 2);
1146 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_CACOFIRE', GameWAD+':TEXTURES\BCACOFIRE', 16, 16, 2);
1147 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_BARONFIRE', GameWAD+':TEXTURES\BBARONFIRE', 64, 16, 2);
1148 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_MANCUBFIRE', GameWAD+':TEXTURES\BMANCUBFIRE', 64, 32, 2);
1149 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_ROCKET', GameWAD+':TEXTURES\EROCKET', 128, 128, 6);
1150 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_SKELFIRE', GameWAD+':TEXTURES\ESKELFIRE', 64, 64, 3);
1151 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_BFG', GameWAD+':TEXTURES\EBFG', 128, 128, 6);
1152 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_IMPFIRE', GameWAD+':TEXTURES\EIMPFIRE', 64, 64, 3);
1153 g_Frames_CreateWAD(nil, 'FRAMES_BFGHIT', GameWAD+':TEXTURES\BFGHIT', 64, 64, 4);
1154 g_Frames_CreateWAD(nil, 'FRAMES_FIRE', GameWAD+':TEXTURES\FIRE', 64, 128, 8);
1155 g_Frames_CreateWAD(nil, 'FRAMES_FLAME', GameWAD+':TEXTURES\FLAME', 32, 32, 11);
1156 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_PLASMA', GameWAD+':TEXTURES\EPLASMA', 32, 32, 4, True);
1157 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_BSPFIRE', GameWAD+':TEXTURES\EBSPFIRE', 32, 32, 5);
1158 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_CACOFIRE', GameWAD+':TEXTURES\ECACOFIRE', 64, 64, 3);
1159 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_BARONFIRE', GameWAD+':TEXTURES\EBARONFIRE', 64, 64, 3);
1160 g_Frames_CreateWAD(nil, 'FRAMES_SMOKE', GameWAD+':TEXTURES\SMOKE', 32, 32, 10, False);
1162 g_Texture_CreateWADEx('TEXTURE_SHELL_BULLET', GameWAD+':TEXTURES\EBULLET');
1163 g_Texture_CreateWADEx('TEXTURE_SHELL_SHELL', GameWAD+':TEXTURES\ESHELL');
1165 //wgunMonHash := hashNewIntInt();
1166 wgunHitHeap := TBinaryHeapHitTimes.Create();
1167 end;
1169 procedure g_Weapon_FreeData();
1170 begin
1171 e_WriteLog('Releasing weapons data...', TMsgType.Notify);
1173 g_Sound_Delete('SOUND_WEAPON_HITPUNCH');
1174 g_Sound_Delete('SOUND_WEAPON_MISSPUNCH');
1175 g_Sound_Delete('SOUND_WEAPON_HITBERSERK');
1176 g_Sound_Delete('SOUND_WEAPON_MISSBERSERK');
1177 g_Sound_Delete('SOUND_WEAPON_SELECTSAW');
1178 g_Sound_Delete('SOUND_WEAPON_IDLESAW');
1179 g_Sound_Delete('SOUND_WEAPON_HITSAW');
1180 g_Sound_Delete('SOUND_WEAPON_FIRESHOTGUN2');
1181 g_Sound_Delete('SOUND_WEAPON_FIRESHOTGUN');
1182 g_Sound_Delete('SOUND_WEAPON_FIRESAW');
1183 g_Sound_Delete('SOUND_WEAPON_FIREROCKET');
1184 g_Sound_Delete('SOUND_WEAPON_FIREPLASMA');
1185 g_Sound_Delete('SOUND_WEAPON_FIREPISTOL');
1186 g_Sound_Delete('SOUND_WEAPON_FIRECGUN');
1187 g_Sound_Delete('SOUND_WEAPON_FIREBFG');
1188 g_Sound_Delete('SOUND_FIRE');
1189 g_Sound_Delete('SOUND_WEAPON_STARTFIREBFG');
1190 g_Sound_Delete('SOUND_WEAPON_EXPLODEROCKET');
1191 g_Sound_Delete('SOUND_WEAPON_EXPLODEBFG');
1192 g_Sound_Delete('SOUND_WEAPON_BFGWATER');
1193 g_Sound_Delete('SOUND_WEAPON_EXPLODEPLASMA');
1194 g_Sound_Delete('SOUND_WEAPON_PLASMAWATER');
1195 g_Sound_Delete('SOUND_WEAPON_FIREBALL');
1196 g_Sound_Delete('SOUND_WEAPON_EXPLODEBALL');
1197 g_Sound_Delete('SOUND_WEAPON_FIREREV');
1198 g_Sound_Delete('SOUND_WEAPON_FLAMEON');
1199 g_Sound_Delete('SOUND_WEAPON_FLAMEOFF');
1200 g_Sound_Delete('SOUND_WEAPON_FLAMEWORK');
1201 g_Sound_Delete('SOUND_PLAYER_JETFLY');
1202 g_Sound_Delete('SOUND_PLAYER_JETON');
1203 g_Sound_Delete('SOUND_PLAYER_JETOFF');
1204 g_Sound_Delete('SOUND_PLAYER_CASING1');
1205 g_Sound_Delete('SOUND_PLAYER_CASING2');
1206 g_Sound_Delete('SOUND_PLAYER_SHELL1');
1207 g_Sound_Delete('SOUND_PLAYER_SHELL2');
1209 g_Texture_Delete('TEXTURE_WEAPON_ROCKET');
1210 g_Frames_DeleteByName('FRAMES_WEAPON_BFG');
1211 g_Frames_DeleteByName('FRAMES_WEAPON_PLASMA');
1212 g_Frames_DeleteByName('FRAMES_WEAPON_IMPFIRE');
1213 g_Frames_DeleteByName('FRAMES_WEAPON_BSPFIRE');
1214 g_Frames_DeleteByName('FRAMES_WEAPON_CACOFIRE');
1215 g_Frames_DeleteByName('FRAMES_WEAPON_MANCUBFIRE');
1216 g_Frames_DeleteByName('FRAMES_EXPLODE_ROCKET');
1217 g_Frames_DeleteByName('FRAMES_EXPLODE_BFG');
1218 g_Frames_DeleteByName('FRAMES_EXPLODE_IMPFIRE');
1219 g_Frames_DeleteByName('FRAMES_BFGHIT');
1220 g_Frames_DeleteByName('FRAMES_FIRE');
1221 g_Frames_DeleteByName('FRAMES_EXPLODE_PLASMA');
1222 g_Frames_DeleteByName('FRAMES_EXPLODE_BSPFIRE');
1223 g_Frames_DeleteByName('FRAMES_EXPLODE_CACOFIRE');
1224 g_Frames_DeleteByName('FRAMES_SMOKE');
1225 g_Frames_DeleteByName('FRAMES_WEAPON_BARONFIRE');
1226 g_Frames_DeleteByName('FRAMES_EXPLODE_BARONFIRE');
1227 end;
1230 function GunHitPlayer (X, Y: Integer; vx, vy: Integer; dmg: Integer; SpawnerUID: Word; AllowPush: Boolean): Boolean;
1231 var
1232 i: Integer;
1233 begin
1234 result := false;
1235 for i := 0 to High(gPlayers) do
1236 begin
1237 if (gPlayers[i] <> nil) and gPlayers[i].alive and gPlayers[i].Collide(X, Y) then
1238 begin
1239 if HitPlayer(gPlayers[i], dmg, vx*10, vy*10-3, SpawnerUID, HIT_SOME) then
1240 begin
1241 if AllowPush then gPlayers[i].Push(vx, vy);
1242 result := true;
1243 end;
1244 end;
1245 end;
1246 end;
1249 function GunHit (X, Y: Integer; vx, vy: Integer; dmg: Integer; SpawnerUID: Word; AllowPush: Boolean): Byte;
1251 function monsCheck (mon: TMonster): Boolean;
1252 begin
1253 result := false; // don't stop
1254 if HitMonster(mon, dmg, vx*10, vy*10-3, SpawnerUID, HIT_SOME) then
1255 begin
1256 if AllowPush then mon.Push(vx, vy);
1257 result := true;
1258 end;
1259 end;
1261 begin
1262 result := 0;
1263 if GunHitPlayer(X, Y, vx, vy, dmg, SpawnerUID, AllowPush) then result := 1
1264 else if g_Mons_ForEachAliveAt(X, Y, 1, 1, monsCheck) then result := 2;
1265 end;
1268 (*
1269 procedure g_Weapon_gunOld(const x, y, xd, yd, v, dmg: Integer; SpawnerUID: Word; CheckTrigger: Boolean);
1270 var
1271 a: Integer;
1272 x2, y2: Integer;
1273 dx, dy: Integer;
1274 xe, ye: Integer;
1275 xi, yi: Integer;
1276 s, c: Extended;
1277 //vx, vy: Integer;
1278 xx, yy, d: Integer;
1279 i: Integer;
1280 t1, _collide: Boolean;
1281 w, h: Word;
1282 {$IF DEFINED(D2F_DEBUG)}
1283 stt: UInt64;
1284 showTime: Boolean = true;
1285 {$ENDIF}
1286 begin
1287 a := GetAngle(x, y, xd, yd)+180;
1289 SinCos(DegToRad(-a), s, c);
1291 if Abs(s) < 0.01 then s := 0;
1292 if Abs(c) < 0.01 then c := 0;
1294 x2 := x+Round(c*gMapInfo.Width);
1295 y2 := y+Round(s*gMapInfo.Width);
1297 t1 := gWalls <> nil;
1298 _collide := False;
1299 w := gMapInfo.Width;
1300 h := gMapInfo.Height;
1302 xe := 0;
1303 ye := 0;
1304 dx := x2-x;
1305 dy := y2-y;
1307 if (xd = 0) and (yd = 0) then Exit;
1309 if dx > 0 then xi := 1 else if dx < 0 then xi := -1 else xi := 0;
1310 if dy > 0 then yi := 1 else if dy < 0 then yi := -1 else yi := 0;
1312 dx := Abs(dx);
1313 dy := Abs(dy);
1315 if dx > dy then d := dx else d := dy;
1317 //blood vel, for Monster.Damage()
1318 //vx := (dx*10 div d)*xi;
1319 //vy := (dy*10 div d)*yi;
1321 {$IF DEFINED(D2F_DEBUG)}
1322 stt := getTimeMicro();
1323 {$ENDIF}
1325 xx := x;
1326 yy := y;
1328 for i := 1 to d do
1329 begin
1330 xe := xe+dx;
1331 ye := ye+dy;
1333 if xe > d then
1334 begin
1335 xe := xe-d;
1336 xx := xx+xi;
1337 end;
1339 if ye > d then
1340 begin
1341 ye := ye-d;
1342 yy := yy+yi;
1343 end;
1345 if (yy > h) or (yy < 0) then Break;
1346 if (xx > w) or (xx < 0) then Break;
1348 if t1 then
1349 if ByteBool(gCollideMap[yy, xx] and MARK_BLOCKED) then
1350 begin
1351 _collide := True;
1352 {$IF DEFINED(D2F_DEBUG)}
1353 stt := getTimeMicro()-stt;
1354 e_WriteLog(Format('*** old trace time: %u microseconds', [LongWord(stt)]), MSG_NOTIFY);
1355 showTime := false;
1356 {$ENDIF}
1357 g_GFX_Spark(xx-xi, yy-yi, 2+Random(2), 180+a, 0, 0);
1358 if g_Game_IsServer and g_Game_IsNet then
1359 MH_SEND_Effect(xx-xi, yy-yi, 180+a, NET_GFX_SPARK);
1360 end;
1362 if not _collide then
1363 begin
1364 _collide := GunHit(xx, yy, xi*v, yi*v, dmg, SpawnerUID, v <> 0) <> 0;
1365 end;
1367 if _collide then Break;
1368 end;
1370 {$IF DEFINED(D2F_DEBUG)}
1371 if showTime then
1372 begin
1373 stt := getTimeMicro()-stt;
1374 e_WriteLog(Format('*** old trace time: %u microseconds', [LongWord(stt)]), MSG_NOTIFY);
1375 end;
1376 {$ENDIF}
1378 if CheckTrigger and g_Game_IsServer then
1379 g_Triggers_PressL(X, Y, xx-xi, yy-yi, SpawnerUID, ACTIVATE_SHOT);
1380 end;
1381 *)
1384 //!!!FIXME!!!
1385 procedure g_Weapon_gun (const x, y, xd, yd, v, dmg: Integer; SpawnerUID: Word; CheckTrigger: Boolean);
1386 var
1387 x0, y0: Integer;
1388 x2, y2: Integer;
1389 xi, yi: Integer;
1390 wallDistSq: Integer = $3fffffff;
1392 function doPlayerHit (idx: Integer; hx, hy: Integer): Boolean;
1393 begin
1394 result := false;
1395 if (idx < 0) or (idx > High(gPlayers)) then exit;
1396 if (gPlayers[idx] = nil) or not gPlayers[idx].alive then exit;
1397 result := HitPlayer(gPlayers[idx], dmg, (xi*v)*10, (yi*v)*10-3, SpawnerUID, HIT_SOME);
1398 if result and (v <> 0) then gPlayers[idx].Push((xi*v), (yi*v));
1399 {$IF DEFINED(D2F_DEBUG)}
1400 //if result then e_WriteLog(Format(' PLAYER #%d HIT', [idx]), MSG_NOTIFY);
1401 {$ENDIF}
1402 end;
1404 function doMonsterHit (mon: TMonster; hx, hy: Integer): Boolean;
1405 begin
1406 result := false;
1407 if (mon = nil) then exit;
1408 result := HitMonster(mon, dmg, (xi*v)*10, (yi*v)*10-3, SpawnerUID, HIT_SOME);
1409 if result and (v <> 0) then mon.Push((xi*v), (yi*v));
1410 {$IF DEFINED(D2F_DEBUG)}
1411 //if result then e_WriteLog(Format(' MONSTER #%u HIT', [LongWord(mon.UID)]), MSG_NOTIFY);
1412 {$ENDIF}
1413 end;
1415 // collect players along hitray
1416 // return `true` if instant hit was detected
1417 function playerPossibleHit (): Boolean;
1418 var
1419 i: Integer;
1420 px, py, pw, ph: Integer;
1421 inx, iny: Integer;
1422 distSq: Integer;
1423 plr: TPlayer;
1424 begin
1425 result := false;
1426 for i := 0 to High(gPlayers) do
1427 begin
1428 plr := gPlayers[i];
1429 if (plr <> nil) and plr.alive then
1430 begin
1431 plr.getMapBox(px, py, pw, ph);
1432 if lineAABBIntersects(x, y, x2, y2, px, py, pw, ph, inx, iny) then
1433 begin
1434 distSq := distanceSq(x, y, inx, iny);
1435 if (distSq = 0) then
1436 begin
1437 // contains
1438 if doPlayerHit(i, x, y) then begin result := true; exit; end;
1439 end
1440 else if (distSq < wallDistSq) then
1441 begin
1442 appendHitTimePlr(distSq, i, inx, iny);
1443 end;
1444 end;
1445 end;
1446 end;
1447 end;
1449 procedure sqchecker (mon: TMonster);
1450 var
1451 mx, my, mw, mh: Integer;
1452 inx, iny: Integer;
1453 distSq: Integer;
1454 begin
1455 mon.getMapBox(mx, my, mw, mh);
1456 if lineAABBIntersects(x0, y0, x2, y2, mx, my, mw, mh, inx, iny) then
1457 begin
1458 distSq := distanceSq(x0, y0, inx, iny);
1459 if (distSq < wallDistSq) then appendHitTimeMon(distSq, mon, inx, iny);
1460 end;
1461 end;
1463 var
1464 a: Integer;
1465 dx, dy: Integer;
1466 xe, ye: Integer;
1467 s, c: Extended;
1468 i: Integer;
1469 wallHitFlag: Boolean = false;
1470 wallHitX: Integer = 0;
1471 wallHitY: Integer = 0;
1472 didHit: Boolean = false;
1473 {$IF DEFINED(D2F_DEBUG)}
1474 stt: UInt64;
1475 {$ENDIF}
1476 mit: PMonster;
1477 it: TMonsterGrid.Iter;
1478 begin
1479 (*
1480 if not gwep_debug_fast_trace then
1481 begin
1482 g_Weapon_gunOld(x, y, xd, yd, v, dmg, SpawnerUID, CheckTrigger);
1483 exit;
1484 end;
1485 *)
1487 if (xd = 0) and (yd = 0) then exit;
1489 //wgunMonHash.reset(); //FIXME: clear hash on level change
1490 wgunHitHeap.clear();
1491 wgunHitTimeUsed := 0;
1493 a := GetAngle(x, y, xd, yd)+180;
1495 SinCos(DegToRad(-a), s, c);
1497 if Abs(s) < 0.01 then s := 0;
1498 if Abs(c) < 0.01 then c := 0;
1500 x0 := x;
1501 y0 := y;
1502 x2 := x+Round(c*gMapInfo.Width);
1503 y2 := y+Round(s*gMapInfo.Width);
1505 dx := x2-x;
1506 dy := y2-y;
1508 if (dx > 0) then xi := 1 else if (dx < 0) then xi := -1 else xi := 0;
1509 if (dy > 0) then yi := 1 else if (dy < 0) then yi := -1 else yi := 0;
1511 {$IF DEFINED(D2F_DEBUG)}
1512 e_WriteLog(Format('GUN TRACE: (%d,%d) to (%d,%d)', [x, y, x2, y2]), TMsgType.Notify);
1513 stt := getTimeMicro();
1514 {$ENDIF}
1516 wallHitFlag := (g_Map_traceToNearestWall(x, y, x2, y2, @wallHitX, @wallHitY) <> nil);
1517 if wallHitFlag then
1518 begin
1519 x2 := wallHitX;
1520 y2 := wallHitY;
1521 wallDistSq := distanceSq(x, y, wallHitX, wallHitY);
1522 end
1523 else
1524 begin
1525 wallHitX := x2;
1526 wallHitY := y2;
1527 end;
1529 if playerPossibleHit() then exit; // instant hit
1531 // collect monsters
1532 //g_Mons_AlongLine(x, y, x2, y2, sqchecker);
1534 it := monsGrid.forEachAlongLine(x, y, x2, y2, -1);
1535 for mit in it do sqchecker(mit^);
1536 it.release();
1538 // here, we collected all monsters and players in `wgunHitHeap` and `wgunHitTime`
1539 // also, if `wallWasHit` is `true`, then `wallHitX` and `wallHitY` contains spark coords
1540 while (wgunHitHeap.count > 0) do
1541 begin
1542 // has some entities to check, do it
1543 i := wgunHitHeap.front;
1544 wgunHitHeap.popFront();
1545 // hitpoint
1546 xe := wgunHitTime[i].x;
1547 ye := wgunHitTime[i].y;
1548 // check if it is not behind the wall
1549 if (wgunHitTime[i].mon <> nil) then
1550 begin
1551 didHit := doMonsterHit(wgunHitTime[i].mon, xe, ye);
1552 end
1553 else
1554 begin
1555 didHit := doPlayerHit(wgunHitTime[i].plridx, xe, ye);
1556 end;
1557 if didHit then
1558 begin
1559 // need new coords for trigger
1560 wallHitX := xe;
1561 wallHitY := ye;
1562 wallHitFlag := false; // no sparks
1563 break;
1564 end;
1565 end;
1567 // need sparks?
1568 if wallHitFlag then
1569 begin
1570 {$IF DEFINED(D2F_DEBUG)}
1571 stt := getTimeMicro()-stt;
1572 e_WriteLog(Format('*** new trace time: %u microseconds', [LongWord(stt)]), TMsgType.Notify);
1573 {$ENDIF}
1574 g_GFX_Spark(wallHitX, wallHitY, 2+Random(2), 180+a, 0, 0);
1575 if g_Game_IsServer and g_Game_IsNet then MH_SEND_Effect(wallHitX, wallHitY, 180+a, NET_GFX_SPARK);
1576 end
1577 else
1578 begin
1579 {$IF DEFINED(D2F_DEBUG)}
1580 stt := getTimeMicro()-stt;
1581 e_WriteLog(Format('*** new trace time: %u microseconds', [LongWord(stt)]), TMsgType.Notify);
1582 {$ENDIF}
1583 end;
1585 if CheckTrigger and g_Game_IsServer then g_Triggers_PressL(X, Y, wallHitX, wallHitY, SpawnerUID, ACTIVATE_SHOT);
1586 end;
1589 procedure g_Weapon_punch(x, y: Integer; d, SpawnerUID: Word);
1590 var
1591 obj: TObj;
1592 begin
1593 obj.X := X;
1594 obj.Y := Y;
1595 obj.rect.X := 0;
1596 obj.rect.Y := 0;
1597 obj.rect.Width := 39;
1598 obj.rect.Height := 52;
1599 obj.Vel.X := 0;
1600 obj.Vel.Y := 0;
1601 obj.Accel.X := 0;
1602 obj.Accel.Y := 0;
1604 if g_Weapon_Hit(@obj, d, SpawnerUID, HIT_SOME) <> 0 then
1605 g_Sound_PlayExAt('SOUND_WEAPON_HITPUNCH', x, y)
1606 else
1607 g_Sound_PlayExAt('SOUND_WEAPON_MISSPUNCH', x, y);
1608 end;
1610 function g_Weapon_chainsaw(x, y: Integer; d, SpawnerUID: Word): Integer;
1611 var
1612 obj: TObj;
1613 begin
1614 obj.X := X;
1615 obj.Y := Y;
1616 obj.rect.X := 0;
1617 obj.rect.Y := 0;
1618 obj.rect.Width := 32;
1619 obj.rect.Height := 52;
1620 obj.Vel.X := 0;
1621 obj.Vel.Y := 0;
1622 obj.Accel.X := 0;
1623 obj.Accel.Y := 0;
1625 Result := g_Weapon_Hit(@obj, d, SpawnerUID, HIT_SOME);
1626 end;
1628 procedure g_Weapon_rocket(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1629 Silent: Boolean = False);
1630 var
1631 find_id: DWORD;
1632 dx, dy: Integer;
1633 begin
1634 if WID < 0 then
1635 find_id := FindShot()
1636 else
1637 begin
1638 find_id := WID;
1639 if Integer(find_id) >= High(Shots) then
1640 SetLength(Shots, find_id + 64)
1641 end;
1643 with Shots[find_id] do
1644 begin
1645 g_Obj_Init(@Obj);
1647 Obj.Rect.Width := SHOT_ROCKETLAUNCHER_WIDTH;
1648 Obj.Rect.Height := SHOT_ROCKETLAUNCHER_HEIGHT;
1650 dx := IfThen(xd > x, -Obj.Rect.Width, 0);
1651 dy := -(Obj.Rect.Height div 2);
1653 ShotType := WEAPON_ROCKETLAUNCHER;
1654 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 12);
1656 Animation := nil;
1657 triggers := nil;
1658 g_Texture_Get('TEXTURE_WEAPON_ROCKET', TextureID);
1659 end;
1661 Shots[find_id].SpawnerUID := SpawnerUID;
1663 if not Silent then
1664 g_Sound_PlayExAt('SOUND_WEAPON_FIREROCKET', x, y);
1665 end;
1667 procedure g_Weapon_revf(x, y, xd, yd: Integer; SpawnerUID, TargetUID: Word;
1668 WID: Integer = -1; Silent: Boolean = False);
1669 var
1670 find_id, FramesID: DWORD;
1671 dx, dy: Integer;
1672 begin
1673 if WID < 0 then
1674 find_id := FindShot()
1675 else
1676 begin
1677 find_id := WID;
1678 if Integer(find_id) >= High(Shots) then
1679 SetLength(Shots, find_id + 64)
1680 end;
1682 with Shots[find_id] do
1683 begin
1684 g_Obj_Init(@Obj);
1686 Obj.Rect.Width := SHOT_SKELFIRE_WIDTH;
1687 Obj.Rect.Height := SHOT_SKELFIRE_HEIGHT;
1689 dx := -(Obj.Rect.Width div 2);
1690 dy := -(Obj.Rect.Height div 2);
1692 ShotType := WEAPON_SKEL_FIRE;
1693 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 12);
1695 triggers := nil;
1696 target := TargetUID;
1697 g_Frames_Get(FramesID, 'FRAMES_WEAPON_SKELFIRE');
1698 Animation := TAnimation.Create(FramesID, True, 5);
1699 end;
1701 Shots[find_id].SpawnerUID := SpawnerUID;
1703 if not Silent then
1704 g_Sound_PlayExAt('SOUND_WEAPON_FIREREV', x, y);
1705 end;
1707 procedure g_Weapon_plasma(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1708 Silent: Boolean = False);
1709 var
1710 find_id, FramesID: DWORD;
1711 dx, dy: Integer;
1712 begin
1713 if WID < 0 then
1714 find_id := FindShot()
1715 else
1716 begin
1717 find_id := WID;
1718 if Integer(find_id) >= High(Shots) then
1719 SetLength(Shots, find_id + 64);
1720 end;
1722 with Shots[find_id] do
1723 begin
1724 g_Obj_Init(@Obj);
1726 Obj.Rect.Width := SHOT_PLASMA_WIDTH;
1727 Obj.Rect.Height := SHOT_PLASMA_HEIGHT;
1729 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1730 dy := -(Obj.Rect.Height div 2);
1732 ShotType := WEAPON_PLASMA;
1733 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1735 triggers := nil;
1736 g_Frames_Get(FramesID, 'FRAMES_WEAPON_PLASMA');
1737 Animation := TAnimation.Create(FramesID, True, 5);
1738 end;
1740 Shots[find_id].SpawnerUID := SpawnerUID;
1742 if not Silent then
1743 g_Sound_PlayExAt('SOUND_WEAPON_FIREPLASMA', x, y);
1744 end;
1746 procedure g_Weapon_flame(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1747 Silent: Boolean = False);
1748 var
1749 find_id: DWORD;
1750 dx, dy: Integer;
1751 begin
1752 if WID < 0 then
1753 find_id := FindShot()
1754 else
1755 begin
1756 find_id := WID;
1757 if Integer(find_id) >= High(Shots) then
1758 SetLength(Shots, find_id + 64);
1759 end;
1761 with Shots[find_id] do
1762 begin
1763 g_Obj_Init(@Obj);
1765 Obj.Rect.Width := SHOT_FLAME_WIDTH;
1766 Obj.Rect.Height := SHOT_FLAME_HEIGHT;
1768 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1769 dy := -(Obj.Rect.Height div 2);
1771 ShotType := WEAPON_FLAMETHROWER;
1772 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1774 triggers := nil;
1775 Animation := nil;
1776 TextureID := 0;
1777 g_Frames_Get(TextureID, 'FRAMES_FLAME');
1778 end;
1780 Shots[find_id].SpawnerUID := SpawnerUID;
1782 // if not Silent then
1783 // g_Sound_PlayExAt('SOUND_WEAPON_FIREPLASMA', x, y);
1784 end;
1786 procedure g_Weapon_ball1(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1787 Silent: Boolean = False);
1788 var
1789 find_id, FramesID: DWORD;
1790 dx, dy: Integer;
1791 begin
1792 if WID < 0 then
1793 find_id := FindShot()
1794 else
1795 begin
1796 find_id := WID;
1797 if Integer(find_id) >= High(Shots) then
1798 SetLength(Shots, find_id + 64)
1799 end;
1801 with Shots[find_id] do
1802 begin
1803 g_Obj_Init(@Obj);
1805 Obj.Rect.Width := 16;
1806 Obj.Rect.Height := 16;
1808 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1809 dy := -(Obj.Rect.Height div 2);
1811 ShotType := WEAPON_IMP_FIRE;
1812 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1814 triggers := nil;
1815 g_Frames_Get(FramesID, 'FRAMES_WEAPON_IMPFIRE');
1816 Animation := TAnimation.Create(FramesID, True, 4);
1817 end;
1819 Shots[find_id].SpawnerUID := SpawnerUID;
1821 if not Silent then
1822 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x, y);
1823 end;
1825 procedure g_Weapon_ball2(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1826 Silent: Boolean = False);
1827 var
1828 find_id, FramesID: DWORD;
1829 dx, dy: Integer;
1830 begin
1831 if WID < 0 then
1832 find_id := FindShot()
1833 else
1834 begin
1835 find_id := WID;
1836 if Integer(find_id) >= High(Shots) then
1837 SetLength(Shots, find_id + 64)
1838 end;
1840 with Shots[find_id] do
1841 begin
1842 g_Obj_Init(@Obj);
1844 Obj.Rect.Width := 16;
1845 Obj.Rect.Height := 16;
1847 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1848 dy := -(Obj.Rect.Height div 2);
1850 ShotType := WEAPON_CACO_FIRE;
1851 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1853 triggers := nil;
1854 g_Frames_Get(FramesID, 'FRAMES_WEAPON_CACOFIRE');
1855 Animation := TAnimation.Create(FramesID, True, 4);
1856 end;
1858 Shots[find_id].SpawnerUID := SpawnerUID;
1860 if not Silent then
1861 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x, y);
1862 end;
1864 procedure g_Weapon_ball7(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1865 Silent: Boolean = False);
1866 var
1867 find_id, FramesID: DWORD;
1868 dx, dy: Integer;
1869 begin
1870 if WID < 0 then
1871 find_id := FindShot()
1872 else
1873 begin
1874 find_id := WID;
1875 if Integer(find_id) >= High(Shots) then
1876 SetLength(Shots, find_id + 64)
1877 end;
1879 with Shots[find_id] do
1880 begin
1881 g_Obj_Init(@Obj);
1883 Obj.Rect.Width := 32;
1884 Obj.Rect.Height := 16;
1886 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1887 dy := -(Obj.Rect.Height div 2);
1889 ShotType := WEAPON_BARON_FIRE;
1890 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1892 triggers := nil;
1893 g_Frames_Get(FramesID, 'FRAMES_WEAPON_BARONFIRE');
1894 Animation := TAnimation.Create(FramesID, True, 4);
1895 end;
1897 Shots[find_id].SpawnerUID := SpawnerUID;
1899 if not Silent then
1900 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x, y);
1901 end;
1903 procedure g_Weapon_aplasma(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1904 Silent: Boolean = False);
1905 var
1906 find_id, FramesID: DWORD;
1907 dx, dy: Integer;
1908 begin
1909 if WID < 0 then
1910 find_id := FindShot()
1911 else
1912 begin
1913 find_id := WID;
1914 if Integer(find_id) >= High(Shots) then
1915 SetLength(Shots, find_id + 64)
1916 end;
1918 with Shots[find_id] do
1919 begin
1920 g_Obj_Init(@Obj);
1922 Obj.Rect.Width := 16;
1923 Obj.Rect.Height := 16;
1925 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1926 dy := -(Obj.Rect.Height div 2);
1928 ShotType := WEAPON_BSP_FIRE;
1929 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1931 triggers := nil;
1933 g_Frames_Get(FramesID, 'FRAMES_WEAPON_BSPFIRE');
1934 Animation := TAnimation.Create(FramesID, True, 4);
1935 end;
1937 Shots[find_id].SpawnerUID := SpawnerUID;
1939 if not Silent then
1940 g_Sound_PlayExAt('SOUND_WEAPON_FIREPLASMA', x, y);
1941 end;
1943 procedure g_Weapon_manfire(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1944 Silent: Boolean = False);
1945 var
1946 find_id, FramesID: DWORD;
1947 dx, dy: Integer;
1948 begin
1949 if WID < 0 then
1950 find_id := FindShot()
1951 else
1952 begin
1953 find_id := WID;
1954 if Integer(find_id) >= High(Shots) then
1955 SetLength(Shots, find_id + 64)
1956 end;
1958 with Shots[find_id] do
1959 begin
1960 g_Obj_Init(@Obj);
1962 Obj.Rect.Width := 32;
1963 Obj.Rect.Height := 32;
1965 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1966 dy := -(Obj.Rect.Height div 2);
1968 ShotType := WEAPON_MANCUB_FIRE;
1969 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1971 triggers := nil;
1973 g_Frames_Get(FramesID, 'FRAMES_WEAPON_MANCUBFIRE');
1974 Animation := TAnimation.Create(FramesID, True, 4);
1975 end;
1977 Shots[find_id].SpawnerUID := SpawnerUID;
1979 if not Silent then
1980 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x, y);
1981 end;
1983 procedure g_Weapon_bfgshot(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1984 Silent: Boolean = False);
1985 var
1986 find_id, FramesID: DWORD;
1987 dx, dy: Integer;
1988 begin
1989 if WID < 0 then
1990 find_id := FindShot()
1991 else
1992 begin
1993 find_id := WID;
1994 if Integer(find_id) >= High(Shots) then
1995 SetLength(Shots, find_id + 64)
1996 end;
1998 with Shots[find_id] do
1999 begin
2000 g_Obj_Init(@Obj);
2002 Obj.Rect.Width := SHOT_BFG_WIDTH;
2003 Obj.Rect.Height := SHOT_BFG_HEIGHT;
2005 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
2006 dy := -(Obj.Rect.Height div 2);
2008 ShotType := WEAPON_BFG;
2009 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
2011 triggers := nil;
2012 g_Frames_Get(FramesID, 'FRAMES_WEAPON_BFG');
2013 Animation := TAnimation.Create(FramesID, True, 6);
2014 end;
2016 Shots[find_id].SpawnerUID := SpawnerUID;
2018 if not Silent then
2019 g_Sound_PlayExAt('SOUND_WEAPON_FIREBFG', x, y);
2020 end;
2022 procedure g_Weapon_bfghit(x, y: Integer);
2023 var
2024 ID: DWORD;
2025 Anim: TAnimation;
2026 begin
2027 if g_Frames_Get(ID, 'FRAMES_BFGHIT') then
2028 begin
2029 Anim := TAnimation.Create(ID, False, 4);
2030 g_GFX_OnceAnim(x-32, y-32, Anim);
2031 Anim.Free();
2032 end;
2033 end;
2035 procedure g_Weapon_pistol(x, y, xd, yd: Integer; SpawnerUID: Word;
2036 Silent: Boolean = False);
2037 begin
2038 if not Silent then
2039 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', x, y);
2041 g_Weapon_gun(x, y, xd, yd, 1, 3, SpawnerUID, True);
2042 if gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF] then
2043 begin
2044 g_Weapon_gun(x, y+1, xd, yd+1, 1, 3, SpawnerUID, False);
2045 g_Weapon_gun(x, y-1, xd, yd-1, 1, 2, SpawnerUID, False);
2046 end;
2047 end;
2049 procedure g_Weapon_mgun(x, y, xd, yd: Integer; SpawnerUID: Word;
2050 Silent: Boolean = False);
2051 begin
2052 if not Silent then
2053 if gSoundEffectsDF then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', x, y);
2055 g_Weapon_gun(x, y, xd, yd, 1, 3, SpawnerUID, True);
2056 if (gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF]) and
2057 (g_GetUIDType(SpawnerUID) = UID_PLAYER) then
2058 begin
2059 g_Weapon_gun(x, y+1, xd, yd+1, 1, 2, SpawnerUID, False);
2060 g_Weapon_gun(x, y-1, xd, yd-1, 1, 2, SpawnerUID, False);
2061 end;
2062 end;
2064 procedure g_Weapon_shotgun(x, y, xd, yd: Integer; SpawnerUID: Word;
2065 Silent: Boolean = False);
2066 var
2067 i, j: Integer;
2068 begin
2069 if not Silent then
2070 if gSoundEffectsDF then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', x, y);
2072 for i := 0 to 9 do
2073 begin
2074 j := Random(17)-8; // -8 .. 8
2075 g_Weapon_gun(x, y+j, xd, yd+j, IfThen(i mod 2 <> 0, 1, 0), 3, SpawnerUID, i=0);
2076 end;
2077 end;
2079 procedure g_Weapon_dshotgun(x, y, xd, yd: Integer; SpawnerUID: Word;
2080 Silent: Boolean = False);
2081 var
2082 a, i, j: Integer;
2083 begin
2084 if not Silent then
2085 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', x, y);
2087 if gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF] then a := 25 else a := 20;
2088 for i := 0 to a do
2089 begin
2090 j := Random(41)-20; // -20 .. 20
2091 g_Weapon_gun(x, y+j, xd, yd+j, IfThen(i mod 3 <> 0, 0, 1), 3, SpawnerUID, i=0);
2092 end;
2093 end;
2095 procedure g_Weapon_Update();
2096 var
2097 i, a, h, cx, cy, oldvx, oldvy, tf: Integer;
2098 _id: DWORD;
2099 Anim: TAnimation;
2100 t: DWArray;
2101 st: Word;
2102 s: String;
2103 o: TObj;
2104 spl: Boolean;
2105 Loud: Boolean;
2106 tcx, tcy: Integer;
2107 begin
2108 if Shots = nil then
2109 Exit;
2111 for i := 0 to High(Shots) do
2112 begin
2113 if Shots[i].ShotType = 0 then
2114 Continue;
2116 Loud := True;
2118 with Shots[i] do
2119 begin
2120 Timeout := Timeout - 1;
2121 oldvx := Obj.Vel.X;
2122 oldvy := Obj.Vel.Y;
2123 // Àêòèâèðîâàòü òðèããåðû ïî ïóòè (êðîìå óæå àêòèâèðîâàííûõ):
2124 if (Stopped = 0) and g_Game_IsServer then
2125 t := g_Triggers_PressR(Obj.X, Obj.Y, Obj.Rect.Width, Obj.Rect.Height,
2126 SpawnerUID, ACTIVATE_SHOT, triggers)
2127 else
2128 t := nil;
2130 if t <> nil then
2131 begin
2132 // Ïîïîëíÿåì ñïèñîê àêòèâèðîâàííûõ òðèããåðîâ:
2133 if triggers = nil then
2134 triggers := t
2135 else
2136 begin
2137 h := High(t);
2139 for a := 0 to h do
2140 if not InDWArray(t[a], triggers) then
2141 begin
2142 SetLength(triggers, Length(triggers)+1);
2143 triggers[High(triggers)] := t[a];
2144 end;
2145 end;
2146 end;
2148 // Àíèìàöèÿ ñíàðÿäà:
2149 if Animation <> nil then
2150 Animation.Update();
2152 // Äâèæåíèå:
2153 spl := (ShotType <> WEAPON_PLASMA) and
2154 (ShotType <> WEAPON_BFG) and
2155 (ShotType <> WEAPON_BSP_FIRE) and
2156 (ShotType <> WEAPON_FLAMETHROWER);
2158 if Stopped = 0 then
2159 begin
2160 st := g_Obj_Move_Projectile(@Obj, False, spl);
2161 end
2162 else
2163 begin
2164 st := 0;
2165 end;
2166 positionChanged(); // this updates spatial accelerators
2168 if WordBool(st and MOVE_FALLOUT) or (Obj.X < -1000) or
2169 (Obj.X > gMapInfo.Width+1000) or (Obj.Y < -1000) then
2170 begin
2171 // Íà êëèåíòå ñêîðåå âñåãî è òàê óæå âûïàë.
2172 ShotType := 0;
2173 Animation.Free();
2174 Continue;
2175 end;
2177 cx := Obj.X + (Obj.Rect.Width div 2);
2178 cy := Obj.Y + (Obj.Rect.Height div 2);
2180 case ShotType of
2181 WEAPON_ROCKETLAUNCHER, WEAPON_SKEL_FIRE: // Ðàêåòû è ñíàðÿäû Ñêåëåòà
2182 begin
2183 // Âûëåòåëà èç âîäû:
2184 if WordBool(st and MOVE_HITAIR) then
2185 g_Obj_SetSpeed(@Obj, 12);
2187 // Â âîäå øëåéô - ïóçûðè, â âîçäóõå øëåéô - äûì:
2188 if WordBool(st and MOVE_INWATER) then
2189 g_GFX_Bubbles(Obj.X+(Obj.Rect.Width div 2),
2190 Obj.Y+(Obj.Rect.Height div 2),
2191 1+Random(3), 16, 16)
2192 else
2193 if g_Frames_Get(_id, 'FRAMES_SMOKE') then
2194 begin
2195 Anim := TAnimation.Create(_id, False, 3);
2196 Anim.Alpha := 150;
2197 g_GFX_OnceAnim(Obj.X-14+Random(9),
2198 Obj.Y+(Obj.Rect.Height div 2)-20+Random(9),
2199 Anim, ONCEANIM_SMOKE);
2200 Anim.Free();
2201 end;
2203 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2204 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL)) or
2205 (g_Weapon_Hit(@Obj, 10, SpawnerUID, HIT_SOME, False) <> 0) or
2206 (Timeout < 1) then
2207 begin
2208 Obj.Vel.X := 0;
2209 Obj.Vel.Y := 0;
2211 g_Weapon_Explode(cx, cy, 60, SpawnerUID);
2213 if ShotType = WEAPON_SKEL_FIRE then
2214 begin // Âçðûâ ñíàðÿäà Ñêåëåòà
2215 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_SKELFIRE') then
2216 begin
2217 Anim := TAnimation.Create(TextureID, False, 8);
2218 Anim.Blending := False;
2219 g_GFX_OnceAnim((Obj.X+32)-58, (Obj.Y+8)-36, Anim);
2220 g_DynLightExplosion((Obj.X+32), (Obj.Y+8), 64, 1, 0, 0);
2221 Anim.Free();
2222 end;
2223 end
2224 else
2225 begin // Âçðûâ Ðàêåòû
2226 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_ROCKET') then
2227 begin
2228 Anim := TAnimation.Create(TextureID, False, 6);
2229 Anim.Blending := False;
2230 g_GFX_OnceAnim(cx-64, cy-64, Anim);
2231 g_DynLightExplosion(cx, cy, 64, 1, 0, 0);
2232 Anim.Free();
2233 end;
2234 end;
2236 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', Obj.X, Obj.Y);
2238 ShotType := 0;
2239 end;
2241 if ShotType = WEAPON_SKEL_FIRE then
2242 begin // Ñàìîíàâîäêà ñíàðÿäà Ñêåëåòà:
2243 if GetPos(target, @o) then
2244 throw(i, Obj.X, Obj.Y,
2245 o.X+o.Rect.X+(o.Rect.Width div 2)+o.Vel.X+o.Accel.X,
2246 o.Y+o.Rect.Y+(o.Rect.Height div 2)+o.Vel.Y+o.Accel.Y,
2247 12);
2248 end;
2249 end;
2251 WEAPON_PLASMA, WEAPON_BSP_FIRE: // Ïëàçìà, ïëàçìà Àðàõíàòðîíà
2252 begin
2253 // Ïîïàëà â âîäó - ýëåêòðîøîê ïî âîäå:
2254 if WordBool(st and (MOVE_INWATER or MOVE_HITWATER)) then
2255 begin
2256 g_Sound_PlayExAt('SOUND_WEAPON_PLASMAWATER', Obj.X, Obj.Y);
2257 if g_Game_IsServer then CheckTrap(i, 10, HIT_ELECTRO);
2258 ShotType := 0;
2259 Continue;
2260 end;
2262 // Âåëè÷èíà óðîíà:
2263 if (ShotType = WEAPON_PLASMA) and
2264 (gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF]) then
2265 a := 10
2266 else
2267 a := 5;
2269 if ShotType = WEAPON_BSP_FIRE then
2270 a := 10;
2272 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2273 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL)) or
2274 (g_Weapon_Hit(@Obj, a, SpawnerUID, HIT_SOME, False) <> 0) or
2275 (Timeout < 1) then
2276 begin
2277 if ShotType = WEAPON_PLASMA then
2278 s := 'FRAMES_EXPLODE_PLASMA'
2279 else
2280 s := 'FRAMES_EXPLODE_BSPFIRE';
2282 // Âçðûâ Ïëàçìû:
2283 if g_Frames_Get(TextureID, s) then
2284 begin
2285 Anim := TAnimation.Create(TextureID, False, 3);
2286 Anim.Blending := False;
2287 g_GFX_OnceAnim(cx-16, cy-16, Anim);
2288 Anim.Free();
2289 g_DynLightExplosion(cx, cy, 32, 0, 0.5, 0.5);
2290 end;
2292 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEPLASMA', Obj.X, Obj.Y);
2294 ShotType := 0;
2295 end;
2296 end;
2298 WEAPON_FLAMETHROWER: // Îãíåìåò
2299 begin
2300 // Ñî âðåìåíåì óìèðàåò
2301 if (Timeout < 1) then
2302 begin
2303 ShotType := 0;
2304 Continue;
2305 end;
2306 // Ïîä âîäîé òîæå
2307 if WordBool(st and (MOVE_HITWATER or MOVE_INWATER)) then
2308 begin
2309 if WordBool(st and MOVE_HITWATER) then
2310 begin
2311 if g_Frames_Get(_id, 'FRAMES_SMOKE') then
2312 begin
2313 Anim := TAnimation.Create(_id, False, 3);
2314 Anim.Alpha := 0;
2315 tcx := Random(8);
2316 tcy := Random(8);
2317 g_GFX_OnceAnim(cx-4+tcx-(Anim.Width div 2),
2318 cy-4+tcy-(Anim.Height div 2),
2319 Anim, ONCEANIM_SMOKE);
2320 Anim.Free();
2321 end;
2322 end
2323 else
2324 g_GFX_Bubbles(cx, cy, 1+Random(3), 16, 16);
2325 ShotType := 0;
2326 Continue;
2327 end;
2329 // Ãðàâèòàöèÿ
2330 if Stopped = 0 then
2331 Obj.Accel.Y := Obj.Accel.Y + 1;
2332 // Ïîïàëè â ñòåíó èëè â âîäó:
2333 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL or MOVE_HITWATER)) then
2334 begin
2335 // Ïðèëèïàåì:
2336 Obj.Vel.X := 0;
2337 Obj.Vel.Y := 0;
2338 Obj.Accel.Y := 0;
2339 if WordBool(st and MOVE_HITWALL) then
2340 Stopped := MOVE_HITWALL
2341 else if WordBool(st and MOVE_HITLAND) then
2342 Stopped := MOVE_HITLAND
2343 else if WordBool(st and MOVE_HITCEIL) then
2344 Stopped := MOVE_HITCEIL;
2345 end;
2347 a := IfThen(Stopped = 0, 3, 1);
2348 // Åñëè â êîãî-òî ïîïàëè
2349 if g_Weapon_Hit(@Obj, a, SpawnerUID, HIT_FLAME, False) <> 0 then
2350 begin
2351 // HIT_FLAME ñàì ïîäîææåò
2352 // Åñëè â ïîëåòå ïîïàëè, èñ÷åçàåì
2353 if Stopped = 0 then
2354 ShotType := 0;
2355 end;
2357 if Stopped = 0 then
2358 tf := 2
2359 else
2360 tf := 3;
2362 if (gTime mod LongWord(tf) = 0) then
2363 begin
2364 Anim := TAnimation.Create(TextureID, False, 2 + Random(2));
2365 Anim.Alpha := 0;
2366 case Stopped of
2367 MOVE_HITWALL: begin tcx := cx-4+Random(8); tcy := cy-12+Random(24); end;
2368 MOVE_HITLAND: begin tcx := cx-12+Random(24); tcy := cy-10+Random(8); end;
2369 MOVE_HITCEIL: begin tcx := cx-12+Random(24); tcy := cy+6+Random(8); end;
2370 else begin tcx := cx-4+Random(8); tcy := cy-4+Random(8); end;
2371 end;
2372 g_GFX_OnceAnim(tcx-(Anim.Width div 2), tcy-(Anim.Height div 2), Anim, ONCEANIM_SMOKE);
2373 Anim.Free();
2374 //g_DynLightExplosion(tcx, tcy, 1, 1, 0.8, 0.3);
2375 end;
2376 end;
2378 WEAPON_BFG: // BFG
2379 begin
2380 // Ïîïàëà â âîäó - ýëåêòðîøîê ïî âîäå:
2381 if WordBool(st and (MOVE_INWATER or MOVE_HITWATER)) then
2382 begin
2383 g_Sound_PlayExAt('SOUND_WEAPON_BFGWATER', Obj.X, Obj.Y);
2384 if g_Game_IsServer then CheckTrap(i, 1000, HIT_ELECTRO);
2385 ShotType := 0;
2386 Continue;
2387 end;
2389 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2390 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL)) or
2391 (g_Weapon_Hit(@Obj, SHOT_BFG_DAMAGE, SpawnerUID, HIT_BFG, False) <> 0) or
2392 (Timeout < 1) then
2393 begin
2394 // Ëó÷è BFG:
2395 if g_Game_IsServer then g_Weapon_BFG9000(cx, cy, SpawnerUID);
2397 // Âçðûâ BFG:
2398 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_BFG') then
2399 begin
2400 Anim := TAnimation.Create(TextureID, False, 6);
2401 Anim.Blending := False;
2402 g_GFX_OnceAnim(cx-64, cy-64, Anim);
2403 Anim.Free();
2404 g_DynLightExplosion(cx, cy, 96, 0, 1, 0);
2405 end;
2407 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', Obj.X, Obj.Y);
2409 ShotType := 0;
2410 end;
2411 end;
2413 WEAPON_IMP_FIRE, WEAPON_CACO_FIRE, WEAPON_BARON_FIRE: // Âûñòðåëû Áåñà, Êàêîäåìîíà Ðûöàðÿ/Áàðîíà àäà
2414 begin
2415 // Âûëåòåë èç âîäû:
2416 if WordBool(st and MOVE_HITAIR) then
2417 g_Obj_SetSpeed(@Obj, 16);
2419 // Âåëè÷èíà óðîíà:
2420 if ShotType = WEAPON_IMP_FIRE then
2421 a := 5
2422 else
2423 if ShotType = WEAPON_CACO_FIRE then
2424 a := 20
2425 else
2426 a := 40;
2428 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2429 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL)) or
2430 (g_Weapon_Hit(@Obj, a, SpawnerUID, HIT_SOME) <> 0) or
2431 (Timeout < 1) then
2432 begin
2433 if ShotType = WEAPON_IMP_FIRE then
2434 s := 'FRAMES_EXPLODE_IMPFIRE'
2435 else
2436 if ShotType = WEAPON_CACO_FIRE then
2437 s := 'FRAMES_EXPLODE_CACOFIRE'
2438 else
2439 s := 'FRAMES_EXPLODE_BARONFIRE';
2441 // Âçðûâ:
2442 if g_Frames_Get(TextureID, s) then
2443 begin
2444 Anim := TAnimation.Create(TextureID, False, 6);
2445 Anim.Blending := False;
2446 g_GFX_OnceAnim(cx-32, cy-32, Anim);
2447 Anim.Free();
2448 end;
2450 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj.X, Obj.Y);
2452 ShotType := 0;
2453 end;
2454 end;
2456 WEAPON_MANCUB_FIRE: // Âûñòðåë Ìàíêóáóñà
2457 begin
2458 // Âûëåòåë èç âîäû:
2459 if WordBool(st and MOVE_HITAIR) then
2460 g_Obj_SetSpeed(@Obj, 16);
2462 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2463 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL)) or
2464 (g_Weapon_Hit(@Obj, 40, SpawnerUID, HIT_SOME, False) <> 0) or
2465 (Timeout < 1) then
2466 begin
2467 // Âçðûâ:
2468 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_ROCKET') then
2469 begin
2470 Anim := TAnimation.Create(TextureID, False, 6);
2471 Anim.Blending := False;
2472 g_GFX_OnceAnim(cx-64, cy-64, Anim);
2473 Anim.Free();
2474 end;
2476 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj.X, Obj.Y);
2478 ShotType := 0;
2479 end;
2480 end;
2481 end; // case ShotType of...
2483 // Åñëè ñíàðÿäà óæå íåò, óäàëÿåì àíèìàöèþ:
2484 if (ShotType = 0) then
2485 begin
2486 if gGameSettings.GameType = GT_SERVER then
2487 MH_SEND_DeleteShot(i, Obj.X, Obj.Y, Loud);
2488 if Animation <> nil then
2489 begin
2490 Animation.Free();
2491 Animation := nil;
2492 end;
2493 end
2494 else if (ShotType <> WEAPON_FLAMETHROWER) and ((oldvx <> Obj.Vel.X) or (oldvy <> Obj.Vel.Y)) then
2495 if gGameSettings.GameType = GT_SERVER then
2496 MH_SEND_UpdateShot(i);
2497 end;
2498 end;
2499 end;
2501 procedure g_Weapon_Draw();
2502 var
2503 i: Integer;
2504 a: SmallInt;
2505 p: TDFPoint;
2506 begin
2507 if Shots = nil then
2508 Exit;
2510 for i := 0 to High(Shots) do
2511 if Shots[i].ShotType <> 0 then
2512 with Shots[i] do
2513 begin
2514 if (Shots[i].ShotType = WEAPON_ROCKETLAUNCHER) or
2515 (Shots[i].ShotType = WEAPON_BARON_FIRE) or
2516 (Shots[i].ShotType = WEAPON_MANCUB_FIRE) or
2517 (Shots[i].ShotType = WEAPON_SKEL_FIRE) then
2518 a := -GetAngle2(Obj.Vel.X, Obj.Vel.Y)
2519 else
2520 a := 0;
2522 p.X := Obj.Rect.Width div 2;
2523 p.Y := Obj.Rect.Height div 2;
2525 if Animation <> nil then
2526 begin
2527 if (Shots[i].ShotType = WEAPON_BARON_FIRE) or
2528 (Shots[i].ShotType = WEAPON_MANCUB_FIRE) or
2529 (Shots[i].ShotType = WEAPON_SKEL_FIRE) then
2530 Animation.DrawEx(Obj.X, Obj.Y, TMirrorType.None, p, a)
2531 else
2532 Animation.Draw(Obj.X, Obj.Y, TMirrorType.None);
2533 end
2534 else if TextureID <> 0 then
2535 begin
2536 if (Shots[i].ShotType = WEAPON_ROCKETLAUNCHER) then
2537 e_DrawAdv(TextureID, Obj.X, Obj.Y, 0, True, False, a, @p, TMirrorType.None)
2538 else if (Shots[i].ShotType <> WEAPON_FLAMETHROWER) then
2539 e_Draw(TextureID, Obj.X, Obj.Y, 0, True, False);
2540 end;
2542 if g_debug_Frames then
2543 begin
2544 e_DrawQuad(Obj.X+Obj.Rect.X,
2545 Obj.Y+Obj.Rect.Y,
2546 Obj.X+Obj.Rect.X+Obj.Rect.Width-1,
2547 Obj.Y+Obj.Rect.Y+Obj.Rect.Height-1,
2548 0, 255, 0);
2549 end;
2550 end;
2551 end;
2553 function g_Weapon_Danger(UID: Word; X, Y: Integer; Width, Height: Word; Time: Byte): Boolean;
2554 var
2555 a: Integer;
2556 begin
2557 Result := False;
2559 if Shots = nil then
2560 Exit;
2562 for a := 0 to High(Shots) do
2563 if (Shots[a].ShotType <> 0) and (Shots[a].SpawnerUID <> UID) then
2564 if ((Shots[a].Obj.Vel.Y = 0) and (Shots[a].Obj.Vel.X > 0) and (Shots[a].Obj.X < X)) or
2565 (Shots[a].Obj.Vel.Y = 0) and (Shots[a].Obj.Vel.X < 0) and (Shots[a].Obj.X > X) then
2566 if (Abs(X-Shots[a].Obj.X) < Abs(Shots[a].Obj.Vel.X*Time)) and
2567 g_Collide(X, Y, Width, Height, X, Shots[a].Obj.Y,
2568 Shots[a].Obj.Rect.Width, Shots[a].Obj.Rect.Height) and
2569 g_TraceVector(X, Y, Shots[a].Obj.X, Shots[a].Obj.Y) then
2570 begin
2571 Result := True;
2572 Exit;
2573 end;
2574 end;
2576 procedure g_Weapon_SaveState (st: TStream);
2577 var
2578 count, i, j: Integer;
2579 begin
2580 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ ñíàðÿäîâ
2581 count := 0;
2582 for i := 0 to High(Shots) do if (Shots[i].ShotType <> 0) then Inc(count);
2584 // Êîëè÷åñòâî ñíàðÿäîâ
2585 utils.WriteInt(st, count);
2587 if (count = 0) then exit;
2589 for i := 0 to High(Shots) do
2590 begin
2591 if Shots[i].ShotType <> 0 then
2592 begin
2593 // Ñèãíàòóðà ñíàðÿäà
2594 utils.writeSign(st, 'SHOT');
2595 utils.writeInt(st, Byte(0)); // version
2596 // Òèï ñíàðÿäà
2597 utils.writeInt(st, Byte(Shots[i].ShotType));
2598 // Öåëü
2599 utils.writeInt(st, Word(Shots[i].Target));
2600 // UID ñòðåëÿâøåãî
2601 utils.writeInt(st, Word(Shots[i].SpawnerUID));
2602 // Ðàçìåð ïîëÿ Triggers
2603 utils.writeInt(st, Integer(Length(Shots[i].Triggers)));
2604 // Òðèããåðû, àêòèâèðîâàííûå âûñòðåëîì
2605 for j := 0 to Length(Shots[i].Triggers)-1 do utils.writeInt(st, LongWord(Shots[i].Triggers[j]));
2606 // Îáúåêò ñíàðÿäà
2607 Obj_SaveState(st, @Shots[i].Obj);
2608 // Êîñòûëèíà åáàíàÿ
2609 utils.writeInt(st, Byte(Shots[i].Stopped));
2610 end;
2611 end;
2612 end;
2614 procedure g_Weapon_LoadState (st: TStream);
2615 var
2616 count, tc, i, j: Integer;
2617 dw: LongWord;
2618 begin
2619 if (st = nil) then exit;
2621 // Êîëè÷åñòâî ñíàðÿäîâ
2622 count := utils.readLongInt(st);
2623 if (count < 0) or (count > 1024*1024) then raise XStreamError.Create('invalid shots counter');
2625 SetLength(Shots, count);
2627 if (count = 0) then exit;
2629 for i := 0 to count-1 do
2630 begin
2631 // Ñèãíàòóðà ñíàðÿäà
2632 if not utils.checkSign(st, 'SHOT') then raise XStreamError.Create('invalid shot signature');
2633 if (utils.readByte(st) <> 0) then raise XStreamError.Create('invalid shot version');
2634 // Òèï ñíàðÿäà:
2635 Shots[i].ShotType := utils.readByte(st);
2636 // Öåëü
2637 Shots[i].Target := utils.readWord(st);
2638 // UID ñòðåëÿâøåãî
2639 Shots[i].SpawnerUID := utils.readWord(st);
2640 // Ðàçìåð ïîëÿ Triggers
2641 tc := utils.readLongInt(st);
2642 if (tc < 0) or (tc > 1024*1024) then raise XStreamError.Create('invalid shot triggers counter');
2643 SetLength(Shots[i].Triggers, tc);
2644 // Òðèããåðû, àêòèâèðîâàííûå âûñòðåëîì
2645 for j := 0 to tc-1 do Shots[i].Triggers[j] := utils.readLongWord(st);
2646 // Îáúåêò ïðåäìåòà
2647 Obj_LoadState(@Shots[i].Obj, st);
2648 // Êîñòûëèíà åáàíàÿ
2649 Shots[i].Stopped := utils.readByte(st);
2651 // Óñòàíîâêà òåêñòóðû èëè àíèìàöèè
2652 Shots[i].TextureID := DWORD(-1);
2653 Shots[i].Animation := nil;
2655 case Shots[i].ShotType of
2656 WEAPON_ROCKETLAUNCHER, WEAPON_SKEL_FIRE:
2657 begin
2658 g_Texture_Get('TEXTURE_WEAPON_ROCKET', Shots[i].TextureID);
2659 end;
2660 WEAPON_PLASMA:
2661 begin
2662 g_Frames_Get(dw, 'FRAMES_WEAPON_PLASMA');
2663 Shots[i].Animation := TAnimation.Create(dw, True, 5);
2664 end;
2665 WEAPON_BFG:
2666 begin
2667 g_Frames_Get(dw, 'FRAMES_WEAPON_BFG');
2668 Shots[i].Animation := TAnimation.Create(dw, True, 6);
2669 end;
2670 WEAPON_IMP_FIRE:
2671 begin
2672 g_Frames_Get(dw, 'FRAMES_WEAPON_IMPFIRE');
2673 Shots[i].Animation := TAnimation.Create(dw, True, 4);
2674 end;
2675 WEAPON_BSP_FIRE:
2676 begin
2677 g_Frames_Get(dw, 'FRAMES_WEAPON_BSPFIRE');
2678 Shots[i].Animation := TAnimation.Create(dw, True, 4);
2679 end;
2680 WEAPON_CACO_FIRE:
2681 begin
2682 g_Frames_Get(dw, 'FRAMES_WEAPON_CACOFIRE');
2683 Shots[i].Animation := TAnimation.Create(dw, True, 4);
2684 end;
2685 WEAPON_BARON_FIRE:
2686 begin
2687 g_Frames_Get(dw, 'FRAMES_WEAPON_BARONFIRE');
2688 Shots[i].Animation := TAnimation.Create(dw, True, 4);
2689 end;
2690 WEAPON_MANCUB_FIRE:
2691 begin
2692 g_Frames_Get(dw, 'FRAMES_WEAPON_MANCUBFIRE');
2693 Shots[i].Animation := TAnimation.Create(dw, True, 4);
2694 end;
2695 end;
2696 end;
2697 end;
2699 procedure g_Weapon_DestroyShot(I: Integer; X, Y: Integer; Loud: Boolean = True);
2700 var
2701 cx, cy: Integer;
2702 Anim: TAnimation;
2703 s: string;
2704 begin
2705 if Shots = nil then
2706 Exit;
2707 if (I > High(Shots)) or (I < 0) then Exit;
2709 with Shots[I] do
2710 begin
2711 if ShotType = 0 then Exit;
2712 Obj.X := X;
2713 Obj.Y := Y;
2714 cx := Obj.X + (Obj.Rect.Width div 2);
2715 cy := Obj.Y + (Obj.Rect.Height div 2);
2717 case ShotType of
2718 WEAPON_ROCKETLAUNCHER, WEAPON_SKEL_FIRE: // Ðàêåòû è ñíàðÿäû Ñêåëåòà
2719 begin
2720 if Loud then
2721 begin
2722 if ShotType = WEAPON_SKEL_FIRE then
2723 begin // Âçðûâ ñíàðÿäà Ñêåëåòà
2724 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_SKELFIRE') then
2725 begin
2726 Anim := TAnimation.Create(TextureID, False, 8);
2727 Anim.Blending := False;
2728 g_GFX_OnceAnim((Obj.X+32)-32, (Obj.Y+8)-32, Anim);
2729 Anim.Free();
2730 end;
2731 end
2732 else
2733 begin // Âçðûâ Ðàêåòû
2734 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_ROCKET') then
2735 begin
2736 Anim := TAnimation.Create(TextureID, False, 6);
2737 Anim.Blending := False;
2738 g_GFX_OnceAnim(cx-64, cy-64, Anim);
2739 Anim.Free();
2740 end;
2741 end;
2742 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', Obj.X, Obj.Y);
2743 end;
2744 end;
2746 WEAPON_PLASMA, WEAPON_BSP_FIRE: // Ïëàçìà, ïëàçìà Àðàõíàòðîíà
2747 begin
2748 if ShotType = WEAPON_PLASMA then
2749 s := 'FRAMES_EXPLODE_PLASMA'
2750 else
2751 s := 'FRAMES_EXPLODE_BSPFIRE';
2753 if g_Frames_Get(TextureID, s) and loud then
2754 begin
2755 Anim := TAnimation.Create(TextureID, False, 3);
2756 Anim.Blending := False;
2757 g_GFX_OnceAnim(cx-16, cy-16, Anim);
2758 Anim.Free();
2760 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEPLASMA', Obj.X, Obj.Y);
2761 end;
2762 end;
2764 WEAPON_BFG: // BFG
2765 begin
2766 // Âçðûâ BFG:
2767 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_BFG') and Loud then
2768 begin
2769 Anim := TAnimation.Create(TextureID, False, 6);
2770 Anim.Blending := False;
2771 g_GFX_OnceAnim(cx-64, cy-64, Anim);
2772 Anim.Free();
2774 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', Obj.X, Obj.Y);
2775 end;
2776 end;
2778 WEAPON_IMP_FIRE, WEAPON_CACO_FIRE, WEAPON_BARON_FIRE: // Âûñòðåëû Áåñà, Êàêîäåìîíà Ðûöàðÿ/Áàðîíà àäà
2779 begin
2780 if ShotType = WEAPON_IMP_FIRE then
2781 s := 'FRAMES_EXPLODE_IMPFIRE'
2782 else
2783 if ShotType = WEAPON_CACO_FIRE then
2784 s := 'FRAMES_EXPLODE_CACOFIRE'
2785 else
2786 s := 'FRAMES_EXPLODE_BARONFIRE';
2788 if g_Frames_Get(TextureID, s) and Loud then
2789 begin
2790 Anim := TAnimation.Create(TextureID, False, 6);
2791 Anim.Blending := False;
2792 g_GFX_OnceAnim(cx-32, cy-32, Anim);
2793 Anim.Free();
2795 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj.X, Obj.Y);
2796 end;
2797 end;
2799 WEAPON_MANCUB_FIRE: // Âûñòðåë Ìàíêóáóñà
2800 begin
2801 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_ROCKET') and Loud then
2802 begin
2803 Anim := TAnimation.Create(TextureID, False, 6);
2804 Anim.Blending := False;
2805 g_GFX_OnceAnim(cx-64, cy-64, Anim);
2806 Anim.Free();
2808 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj.X, Obj.Y);
2809 end;
2810 end;
2811 end; // case ShotType of...
2813 ShotType := 0;
2814 Animation.Free();
2815 end;
2816 end;
2819 procedure g_Weapon_AddDynLights();
2820 var
2821 i: Integer;
2822 begin
2823 if Shots = nil then Exit;
2824 for i := 0 to High(Shots) do
2825 begin
2826 if Shots[i].ShotType = 0 then continue;
2827 if (Shots[i].ShotType = WEAPON_ROCKETLAUNCHER) or
2828 (Shots[i].ShotType = WEAPON_BARON_FIRE) or
2829 (Shots[i].ShotType = WEAPON_MANCUB_FIRE) or
2830 (Shots[i].ShotType = WEAPON_SKEL_FIRE) or
2831 (Shots[i].ShotType = WEAPON_IMP_FIRE) or
2832 (Shots[i].ShotType = WEAPON_CACO_FIRE) or
2833 (Shots[i].ShotType = WEAPON_MANCUB_FIRE) or
2834 (Shots[i].ShotType = WEAPON_BSP_FIRE) or
2835 (Shots[i].ShotType = WEAPON_PLASMA) or
2836 (Shots[i].ShotType = WEAPON_BFG) or
2837 (Shots[i].ShotType = WEAPON_FLAMETHROWER) or
2838 false then
2839 begin
2840 if (Shots[i].ShotType = WEAPON_PLASMA) then
2841 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)
2842 else if (Shots[i].ShotType = WEAPON_BFG) then
2843 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)
2844 else if (Shots[i].ShotType = WEAPON_FLAMETHROWER) then
2845 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)
2846 else
2847 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);
2848 end;
2849 end;
2850 end;
2853 procedure TShot.positionChanged (); begin end;
2856 end.