DEADSOFTWARE

no more public `gMonsters`
[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 unit g_weapons;
19 interface
21 uses
22 g_textures, g_basic, e_graphics, g_phys, BinEditor;
24 const
25 HIT_SOME = 0;
26 HIT_ROCKET = 1;
27 HIT_BFG = 2;
28 HIT_TRAP = 3;
29 HIT_FALL = 4;
30 HIT_WATER = 5;
31 HIT_ACID = 6;
32 HIT_ELECTRO = 7;
33 HIT_FLAME = 8;
34 HIT_SELF = 9;
35 HIT_DISCON = 10;
37 type
38 TShot = record
39 ShotType: Byte;
40 Target: Word;
41 SpawnerUID: Word;
42 Triggers: DWArray;
43 Obj: TObj;
44 Animation: TAnimation;
45 TextureID: DWORD;
46 Timeout: DWORD;
47 Stopped: Byte;
49 procedure positionChanged (); //WARNING! call this after monster position was changed, or coldet will not work right!
50 end;
53 var
54 Shots: array of TShot = nil;
55 LastShotID: Integer = 0;
57 procedure g_Weapon_LoadData();
58 procedure g_Weapon_FreeData();
59 procedure g_Weapon_Init();
60 procedure g_Weapon_Free();
61 function g_Weapon_Hit(obj: PObj; d: Integer; SpawnerUID: Word; t: Byte; HitCorpses: Boolean = True): Byte;
62 function g_Weapon_HitUID(UID: Word; d: Integer; SpawnerUID: Word; t: Byte): Boolean;
63 function g_Weapon_CreateShot(I: Integer; ShotType: Byte; Spawner, TargetUID: Word; X, Y, XV, YV: Integer): LongWord;
65 procedure g_Weapon_gun(x, y, xd, yd, v, dmg: Integer; SpawnerUID: Word; CheckTrigger: Boolean);
66 procedure g_Weapon_punch(x, y: Integer; d, SpawnerUID: Word);
67 function g_Weapon_chainsaw(x, y: Integer; d, SpawnerUID: Word): Integer;
68 procedure g_Weapon_rocket(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1; Silent: Boolean = False);
69 procedure g_Weapon_revf(x, y, xd, yd: Integer; SpawnerUID, TargetUID: Word; WID: Integer = -1; Silent: Boolean = False);
70 procedure g_Weapon_flame(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1; Silent: Boolean = False);
71 procedure g_Weapon_plasma(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1; Silent: Boolean = False);
72 procedure g_Weapon_ball1(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1; Silent: Boolean = False);
73 procedure g_Weapon_ball2(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1; Silent: Boolean = False);
74 procedure g_Weapon_ball7(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1; Silent: Boolean = False);
75 procedure g_Weapon_aplasma(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1; Silent: Boolean = False);
76 procedure g_Weapon_manfire(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1; Silent: Boolean = False);
77 procedure g_Weapon_bfgshot(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1; Silent: Boolean = False);
78 procedure g_Weapon_bfghit(x, y: Integer);
79 procedure g_Weapon_pistol(x, y, xd, yd: Integer; SpawnerUID: Word; Silent: Boolean = False);
80 procedure g_Weapon_mgun(x, y, xd, yd: Integer; SpawnerUID: Word; Silent: Boolean = False);
81 procedure g_Weapon_shotgun(x, y, xd, yd: Integer; SpawnerUID: Word; Silent: Boolean = False);
82 procedure g_Weapon_dshotgun(x, y, xd, yd: Integer; SpawnerUID: Word; Silent: Boolean = False);
84 function g_Weapon_Explode(X, Y: Integer; rad: Integer; SpawnerUID: Word): Boolean;
85 procedure g_Weapon_BFG9000(X, Y: Integer; SpawnerUID: Word);
86 procedure g_Weapon_Update();
87 procedure g_Weapon_Draw();
88 function g_Weapon_Danger(UID: Word; X, Y: Integer; Width, Height: Word; Time: Byte): Boolean;
89 procedure g_Weapon_DestroyShot(I: Integer; X, Y: Integer; Loud: Boolean = True);
91 procedure g_Weapon_SaveState(var Mem: TBinMemoryWriter);
92 procedure g_Weapon_LoadState(var Mem: TBinMemoryReader);
94 procedure g_Weapon_AddDynLights();
96 const
97 WEAPON_KASTET = 0;
98 WEAPON_SAW = 1;
99 WEAPON_PISTOL = 2;
100 WEAPON_SHOTGUN1 = 3;
101 WEAPON_SHOTGUN2 = 4;
102 WEAPON_CHAINGUN = 5;
103 WEAPON_ROCKETLAUNCHER = 6;
104 WEAPON_PLASMA = 7;
105 WEAPON_BFG = 8;
106 WEAPON_SUPERPULEMET = 9;
107 WEAPON_FLAMETHROWER = 10;
108 WEAPON_ZOMBY_PISTOL = 20;
109 WEAPON_IMP_FIRE = 21;
110 WEAPON_BSP_FIRE = 22;
111 WEAPON_CACO_FIRE = 23;
112 WEAPON_BARON_FIRE = 24;
113 WEAPON_MANCUB_FIRE = 25;
114 WEAPON_SKEL_FIRE = 26;
116 WP_FIRST = WEAPON_KASTET;
117 WP_LAST = WEAPON_FLAMETHROWER;
119 implementation
121 uses
122 Math, g_map, g_player, g_gfx, g_sound, g_main,
123 g_console, SysUtils, g_options, g_game,
124 g_triggers, MAPDEF, e_log, g_monsters, g_saveload,
125 g_language, g_netmsg;
127 type
128 TWaterPanel = record
129 X, Y: Integer;
130 Width, Height: Word;
131 Active: Boolean;
132 end;
134 const
135 SHOT_ROCKETLAUNCHER_WIDTH = 14;
136 SHOT_ROCKETLAUNCHER_HEIGHT = 14;
138 SHOT_SKELFIRE_WIDTH = 14;
139 SHOT_SKELFIRE_HEIGHT = 14;
141 SHOT_PLASMA_WIDTH = 16;
142 SHOT_PLASMA_HEIGHT = 16;
144 SHOT_BFG_WIDTH = 32;
145 SHOT_BFG_HEIGHT = 32;
146 SHOT_BFG_DAMAGE = 100;
147 SHOT_BFG_RADIUS = 256;
149 SHOT_FLAME_WIDTH = 4;
150 SHOT_FLAME_HEIGHT = 4;
151 SHOT_FLAME_LIFETIME = 180;
153 SHOT_SIGNATURE = $544F4853; // 'SHOT'
155 var
156 WaterMap: array of array of DWORD = nil;
158 function FindShot(): DWORD;
159 var
160 i: Integer;
161 begin
162 if Shots <> nil then
163 for i := 0 to High(Shots) do
164 if Shots[i].ShotType = 0 then
165 begin
166 Result := i;
167 LastShotID := Result;
168 Exit;
169 end;
171 if Shots = nil then
172 begin
173 SetLength(Shots, 128);
174 Result := 0;
175 end
176 else
177 begin
178 Result := High(Shots) + 1;
179 SetLength(Shots, Length(Shots) + 128);
180 end;
181 LastShotID := Result;
182 end;
184 procedure CreateWaterMap();
185 var
186 WaterArray: Array of TWaterPanel;
187 a, b, c, m: Integer;
188 ok: Boolean;
189 begin
190 if gWater = nil then
191 Exit;
193 SetLength(WaterArray, Length(gWater));
195 for a := 0 to High(gWater) do
196 begin
197 WaterArray[a].X := gWater[a].X;
198 WaterArray[a].Y := gWater[a].Y;
199 WaterArray[a].Width := gWater[a].Width;
200 WaterArray[a].Height := gWater[a].Height;
201 WaterArray[a].Active := True;
202 end;
204 g_Game_SetLoadingText(_lc[I_LOAD_WATER_MAP], High(WaterArray), False);
206 for a := 0 to High(WaterArray) do
207 if WaterArray[a].Active then
208 begin
209 WaterArray[a].Active := False;
210 m := Length(WaterMap);
211 SetLength(WaterMap, m+1);
212 SetLength(WaterMap[m], 1);
213 WaterMap[m][0] := a;
214 ok := True;
216 while ok do
217 begin
218 ok := False;
219 for b := 0 to High(WaterArray) do
220 if WaterArray[b].Active then
221 for c := 0 to High(WaterMap[m]) do
222 if g_CollideAround(WaterArray[b].X,
223 WaterArray[b].Y,
224 WaterArray[b].Width,
225 WaterArray[b].Height,
226 WaterArray[WaterMap[m][c]].X,
227 WaterArray[WaterMap[m][c]].Y,
228 WaterArray[WaterMap[m][c]].Width,
229 WaterArray[WaterMap[m][c]].Height) then
230 begin
231 WaterArray[b].Active := False;
232 SetLength(WaterMap[m],
233 Length(WaterMap[m])+1);
234 WaterMap[m][High(WaterMap[m])] := b;
235 ok := True;
236 Break;
237 end;
238 end;
240 g_Game_StepLoading();
241 end;
243 WaterArray := nil;
244 end;
246 procedure CheckTrap(ID: DWORD; dm: Integer; t: Byte);
248 var
249 a, b, c, d, i1, i2: Integer;
250 pl, mn: WArray;
252 function monsWaterCheck (monidx: Integer; mon: TMonster): Boolean;
253 begin
254 result := false; // don't stop
255 if mon.Live and mon.Collide(gWater[WaterMap[a][c]]) and (not InWArray(monidx, mn)) and (i2 < 1023) then //FIXME
256 begin
257 i2 += 1;
258 mn[i2] := monidx;
259 end;
260 end;
262 begin
263 if (gWater = nil) or (WaterMap = nil) then Exit;
265 i1 := -1;
266 i2 := -1;
268 SetLength(pl, 1024);
269 SetLength(mn, 1024);
270 for d := 0 to 1023 do pl[d] := $FFFF;
271 for d := 0 to 1023 do mn[d] := $FFFF;
273 for a := 0 to High(WaterMap) do
274 for b := 0 to High(WaterMap[a]) do
275 begin
276 if not g_Obj_Collide(gWater[WaterMap[a][b]].X, gWater[WaterMap[a][b]].Y,
277 gWater[WaterMap[a][b]].Width, gWater[WaterMap[a][b]].Height,
278 @Shots[ID].Obj) then Continue;
280 for c := 0 to High(WaterMap[a]) do
281 begin
282 if gPlayers <> nil then
283 begin
284 for d := 0 to High(gPlayers) do
285 if (gPlayers[d] <> nil) and (gPlayers[d].Live) then
286 if gPlayers[d].Collide(gWater[WaterMap[a][c]]) then
287 if not InWArray(d, pl) then
288 if i1 < 1023 then
289 begin
290 i1 := i1+1;
291 pl[i1] := d;
292 end;
293 end;
295 g_Mons_ForEach(monsWaterCheck);
296 end;
298 if i1 <> -1 then
299 for d := 0 to i1 do
300 gPlayers[pl[d]].Damage(dm, Shots[ID].SpawnerUID, 0, 0, t);
302 if i2 <> -1 then
303 for d := 0 to i2 do
304 g_Mons_ByIdx(mn[d]).Damage(dm, 0, 0, Shots[ID].SpawnerUID, t);
305 end;
307 pl := nil;
308 mn := nil;
309 end;
311 function HitMonster(m: TMonster; d: Integer; vx, vy: Integer; SpawnerUID: Word; t: Byte): Boolean;
312 var
313 tt, mt: Byte;
314 mon: TMonster;
315 begin
316 Result := False;
318 tt := g_GetUIDType(SpawnerUID);
319 if tt = UID_MONSTER then
320 begin
321 mon := g_Monsters_Get(SpawnerUID);
322 if mon <> nil then
323 mt := g_Monsters_Get(SpawnerUID).MonsterType
324 else
325 mt := 0;
326 end
327 else
328 mt := 0;
330 if m = nil then Exit;
331 if m.UID = SpawnerUID then
332 begin
333 // Ñàì ñåáÿ ìîæåò ðàíèòü òîëüêî ðàêåòîé è òîêîì:
334 if (t <> HIT_ROCKET) and (t <> HIT_ELECTRO) then
335 Exit;
336 // Êèáåð äåìîí è áî÷êà âîîáùå íå ìîãóò ñåáÿ ðàíèòü:
337 if (m.MonsterType = MONSTER_CYBER) or
338 (m.MonsterType = MONSTER_BARREL) then
339 begin
340 Result := True;
341 Exit;
342 end;
343 end;
345 if tt = UID_MONSTER then
346 begin
347 // Lost_Soul íå ìîæåò ðàíèòü Pain_Elemental'à:
348 if (mt = MONSTER_SOUL) and (m.MonsterType = MONSTER_PAIN) then
349 Exit;
351 // Îáà ìîíñòðà îäíîãî âèäà:
352 if mt = m.MonsterType then
353 case mt of
354 MONSTER_IMP, MONSTER_DEMON, MONSTER_BARON, MONSTER_KNIGHT, MONSTER_CACO,
355 MONSTER_SOUL, MONSTER_MANCUB, MONSTER_SKEL, MONSTER_FISH:
356 Exit; // Ýòè íå áüþò ñâîèõ
357 end;
358 end;
360 if g_Game_IsServer then
361 begin
362 if (t <> HIT_FLAME) or (m.FFireTime = 0) or (vx <> 0) or (vy <> 0) then
363 Result := m.Damage(d, vx, vy, SpawnerUID, t)
364 else
365 Result := True;
366 if t = HIT_FLAME then
367 m.CatchFire(SpawnerUID);
368 end
369 else
370 Result := True;
371 end;
373 function HitPlayer(p: TPlayer; d: Integer; vx, vy: Integer; SpawnerUID: Word; t: Byte): Boolean;
374 begin
375 Result := False;
377 // Ñàì ñåáÿ ìîæåò ðàíèòü òîëüêî ðàêåòîé è òîêîì:
378 if (p.UID = SpawnerUID) and (t <> HIT_ROCKET) and (t <> HIT_ELECTRO) then
379 Exit;
381 if g_Game_IsServer then
382 begin
383 if (t <> HIT_FLAME) or (p.FFireTime = 0) or (vx <> 0) or (vy <> 0) then
384 p.Damage(d, SpawnerUID, vx, vy, t);
385 if (t = HIT_FLAME) then
386 p.CatchFire(SpawnerUID);
387 end;
389 Result := True;
390 end;
392 function GunHit(X, Y: Integer; vx, vy: Integer; dmg: Integer;
393 SpawnerUID: Word; AllowPush: Boolean): Byte;
395 function monsCheck (monidx: Integer; mon: TMonster): Boolean;
396 begin
397 result := false; // don't stop
398 if (mon <> nil) and mon.Live and mon.Collide(X, Y) then
399 begin
400 if HitMonster(mon, dmg, vx*10, vy*10-3, SpawnerUID, HIT_SOME) then
401 begin
402 if AllowPush then mon.Push(vx, vy);
403 result := true;
404 end;
405 end;
406 end;
408 var
409 i, h: Integer;
410 begin
411 Result := 0;
413 h := High(gPlayers);
415 if h <> -1 then
416 for i := 0 to h do
417 if (gPlayers[i] <> nil) and gPlayers[i].Live and gPlayers[i].Collide(X, Y) then
418 if HitPlayer(gPlayers[i], dmg, vx*10, vy*10-3, SpawnerUID, HIT_SOME) then
419 begin
420 if AllowPush then gPlayers[i].Push(vx, vy);
421 Result := 1;
422 end;
424 if Result <> 0 then Exit;
426 if g_Mons_ForEach(monsCheck) then result := 2;
427 end;
429 procedure g_Weapon_BFG9000(X, Y: Integer; SpawnerUID: Word);
431 function monsCheck (monidx: Integer; mon: TMonster): Boolean;
432 begin
433 result := false; // don't stop
434 if (mon <> nil) and (mon.Live) and (mon.UID <> SpawnerUID) then
435 begin
436 with mon do
437 begin
438 if (g_PatchLength(X, Y, Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2),
439 Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)) <= SHOT_BFG_RADIUS) and
440 g_TraceVector(X, Y, Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2),
441 Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)) then
442 begin
443 if HitMonster(mon, 50, 0, 0, SpawnerUID, HIT_SOME) then mon.BFGHit();
444 end;
445 end;
446 end;
447 end;
449 var
450 i, h: Integer;
451 st: Byte;
452 pl: TPlayer;
453 b: Boolean;
454 begin
455 //g_Sound_PlayEx('SOUND_WEAPON_EXPLODEBFG', 255);
457 h := High(gCorpses);
459 if gAdvCorpses and (h <> -1) then
460 for i := 0 to h do
461 if (gCorpses[i] <> nil) and (gCorpses[i].State <> CORPSE_STATE_REMOVEME) then
462 with gCorpses[i] do
463 if (g_PatchLength(X, Y, Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2),
464 Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)) <= SHOT_BFG_RADIUS) and
465 g_TraceVector(X, Y, Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2),
466 Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)) then
467 begin
468 Damage(50, 0, 0);
469 g_Weapon_BFGHit(Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2),
470 Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2));
471 end;
473 st := TEAM_NONE;
474 pl := g_Player_Get(SpawnerUID);
475 if pl <> nil then
476 st := pl.Team;
478 h := High(gPlayers);
480 if h <> -1 then
481 for i := 0 to h do
482 if (gPlayers[i] <> nil) and (gPlayers[i].Live) and (gPlayers[i].UID <> SpawnerUID) then
483 with gPlayers[i] do
484 if (g_PatchLength(X, Y, GameX+PLAYER_RECT.X+(PLAYER_RECT.Width div 2),
485 GameY+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)) <= SHOT_BFG_RADIUS) and
486 g_TraceVector(X, Y, GameX+PLAYER_RECT.X+(PLAYER_RECT.Width div 2),
487 GameY+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)) then
488 begin
489 if (st = TEAM_NONE) or (st <> gPlayers[i].Team) then
490 b := HitPlayer(gPlayers[i], 50, 0, 0, SpawnerUID, HIT_SOME)
491 else
492 b := HitPlayer(gPlayers[i], 25, 0, 0, SpawnerUID, HIT_SOME);
493 if b then
494 gPlayers[i].BFGHit();
495 end;
497 g_Mons_ForEach(monsCheck);
498 end;
500 function g_Weapon_CreateShot(I: Integer; ShotType: Byte; Spawner, TargetUID: Word; X, Y, XV, YV: Integer): LongWord;
501 var
502 find_id, FramesID: DWORD;
503 begin
504 if I < 0 then
505 find_id := FindShot()
506 else
507 begin
508 find_id := I;
509 if Integer(find_id) >= High(Shots) then
510 SetLength(Shots, find_id + 64)
511 end;
513 case ShotType of
514 WEAPON_ROCKETLAUNCHER:
515 begin
516 with Shots[find_id] do
517 begin
518 g_Obj_Init(@Obj);
520 Obj.Rect.Width := SHOT_ROCKETLAUNCHER_WIDTH;
521 Obj.Rect.Height := SHOT_ROCKETLAUNCHER_HEIGHT;
523 Animation := nil;
524 Triggers := nil;
525 ShotType := WEAPON_ROCKETLAUNCHER;
526 g_Texture_Get('TEXTURE_WEAPON_ROCKET', TextureID);
527 end;
528 end;
530 WEAPON_PLASMA:
531 begin
532 with Shots[find_id] do
533 begin
534 g_Obj_Init(@Obj);
536 Obj.Rect.Width := SHOT_PLASMA_WIDTH;
537 Obj.Rect.Height := SHOT_PLASMA_HEIGHT;
539 Triggers := nil;
540 ShotType := WEAPON_PLASMA;
541 g_Frames_Get(FramesID, 'FRAMES_WEAPON_PLASMA');
542 Animation := TAnimation.Create(FramesID, True, 5);
543 end;
544 end;
546 WEAPON_BFG:
547 begin
548 with Shots[find_id] do
549 begin
550 g_Obj_Init(@Obj);
552 Obj.Rect.Width := SHOT_BFG_WIDTH;
553 Obj.Rect.Height := SHOT_BFG_HEIGHT;
555 Triggers := nil;
556 ShotType := WEAPON_BFG;
557 g_Frames_Get(FramesID, 'FRAMES_WEAPON_BFG');
558 Animation := TAnimation.Create(FramesID, True, 6);
559 end;
560 end;
562 WEAPON_FLAMETHROWER:
563 begin
564 with Shots[find_id] do
565 begin
566 g_Obj_Init(@Obj);
568 Obj.Rect.Width := SHOT_FLAME_WIDTH;
569 Obj.Rect.Height := SHOT_FLAME_HEIGHT;
571 Triggers := nil;
572 ShotType := WEAPON_FLAMETHROWER;
573 Animation := nil;
574 TextureID := 0;
575 g_Frames_Get(TextureID, 'FRAMES_FLAME');
576 end;
577 end;
579 WEAPON_IMP_FIRE:
580 begin
581 with Shots[find_id] do
582 begin
583 g_Obj_Init(@Obj);
585 Obj.Rect.Width := 16;
586 Obj.Rect.Height := 16;
588 Triggers := nil;
589 ShotType := WEAPON_IMP_FIRE;
590 g_Frames_Get(FramesID, 'FRAMES_WEAPON_IMPFIRE');
591 Animation := TAnimation.Create(FramesID, True, 4);
592 end;
593 end;
595 WEAPON_CACO_FIRE:
596 begin
597 with Shots[find_id] do
598 begin
599 g_Obj_Init(@Obj);
601 Obj.Rect.Width := 16;
602 Obj.Rect.Height := 16;
604 Triggers := nil;
605 ShotType := WEAPON_CACO_FIRE;
606 g_Frames_Get(FramesID, 'FRAMES_WEAPON_CACOFIRE');
607 Animation := TAnimation.Create(FramesID, True, 4);
608 end;
609 end;
611 WEAPON_MANCUB_FIRE:
612 begin
613 with Shots[find_id] do
614 begin
615 g_Obj_Init(@Obj);
617 Obj.Rect.Width := 32;
618 Obj.Rect.Height := 32;
620 Triggers := nil;
621 ShotType := WEAPON_MANCUB_FIRE;
622 g_Frames_Get(FramesID, 'FRAMES_WEAPON_MANCUBFIRE');
623 Animation := TAnimation.Create(FramesID, True, 4);
624 end;
625 end;
627 WEAPON_BARON_FIRE:
628 begin
629 with Shots[find_id] do
630 begin
631 g_Obj_Init(@Obj);
633 Obj.Rect.Width := 32;
634 Obj.Rect.Height := 16;
636 Triggers := nil;
637 ShotType := WEAPON_BARON_FIRE;
638 g_Frames_Get(FramesID, 'FRAMES_WEAPON_BARONFIRE');
639 Animation := TAnimation.Create(FramesID, True, 4);
640 end;
641 end;
643 WEAPON_BSP_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_BSP_FIRE;
654 g_Frames_Get(FramesID, 'FRAMES_WEAPON_BSPFIRE');
655 Animation := TAnimation.Create(FramesID, True, 4);
656 end;
657 end;
659 WEAPON_SKEL_FIRE:
660 begin
661 with Shots[find_id] do
662 begin
663 g_Obj_Init(@Obj);
665 Obj.Rect.Width := SHOT_SKELFIRE_WIDTH;
666 Obj.Rect.Height := SHOT_SKELFIRE_HEIGHT;
668 Triggers := nil;
669 ShotType := WEAPON_SKEL_FIRE;
670 target := TargetUID;
671 g_Frames_Get(FramesID, 'FRAMES_WEAPON_SKELFIRE');
672 Animation := TAnimation.Create(FramesID, True, 5);
673 end;
674 end;
675 end;
677 Shots[find_id].Obj.X := X;
678 Shots[find_id].Obj.Y := Y;
679 Shots[find_id].Obj.Vel.X := XV;
680 Shots[find_id].Obj.Vel.Y := YV;
681 Shots[find_id].Obj.Accel.X := 0;
682 Shots[find_id].Obj.Accel.Y := 0;
683 Shots[find_id].SpawnerUID := Spawner;
684 if (ShotType = WEAPON_FLAMETHROWER) and (XV = 0) and (YV = 0) then
685 Shots[find_id].Stopped := 255
686 else
687 Shots[find_id].Stopped := 0;
688 Result := find_id;
689 end;
691 procedure throw(i, x, y, xd, yd, s: Integer);
692 var
693 a: Integer;
694 begin
695 yd := yd - y;
696 xd := xd - x;
698 a := Max(Abs(xd), Abs(yd));
699 if a = 0 then
700 a := 1;
702 Shots[i].Obj.X := x;
703 Shots[i].Obj.Y := y;
704 Shots[i].Obj.Vel.X := (xd*s) div a;
705 Shots[i].Obj.Vel.Y := (yd*s) div a;
706 Shots[i].Obj.Accel.X := 0;
707 Shots[i].Obj.Accel.Y := 0;
708 Shots[i].Stopped := 0;
709 if Shots[i].ShotType in [WEAPON_ROCKETLAUNCHER, WEAPON_BFG] then
710 Shots[i].Timeout := 900 // ~25 sec
711 else
712 begin
713 if Shots[i].ShotType = WEAPON_FLAMETHROWER then
714 Shots[i].Timeout := SHOT_FLAME_LIFETIME
715 else
716 Shots[i].Timeout := 550; // ~15 sec
717 end;
718 end;
720 function g_Weapon_Hit(obj: PObj; d: Integer; SpawnerUID: Word; t: Byte; HitCorpses: Boolean = True): Byte;
721 var
722 i, h: Integer;
724 function PlayerHit(Team: Byte = 0): Boolean;
725 var
726 i: Integer;
727 ChkTeam: Boolean;
728 p: TPlayer;
729 begin
730 Result := False;
731 h := High(gPlayers);
733 if h <> -1 then
734 for i := 0 to h do
735 if (gPlayers[i] <> nil) and gPlayers[i].Live and g_Obj_Collide(obj, @gPlayers[i].Obj) then
736 begin
737 ChkTeam := True;
738 if (Team > 0) and (g_GetUIDType(SpawnerUID) = UID_PLAYER) then
739 begin
740 p := g_Player_Get(SpawnerUID);
741 if p <> nil then
742 ChkTeam := (p.Team = gPlayers[i].Team) xor (Team = 2);
743 end;
744 if ChkTeam then
745 if HitPlayer(gPlayers[i], d, obj^.Vel.X, obj^.Vel.Y, SpawnerUID, t) then
746 begin
747 if t <> HIT_FLAME then
748 gPlayers[i].Push((obj^.Vel.X+obj^.Accel.X)*IfThen(t = HIT_BFG, 8, 1) div 4,
749 (obj^.Vel.Y+obj^.Accel.Y)*IfThen(t = HIT_BFG, 8, 1) div 4);
750 if t = HIT_BFG then
751 g_Game_DelayEvent(DE_BFGHIT, 1000, SpawnerUID);
752 Result := True;
753 break;
754 end;
755 end;
756 end;
758 function monsCheckHit (monidx: Integer; mon: TMonster): Boolean;
759 begin
760 result := false; // don't stop
761 if (mon <> nil) and mon.Live and g_Obj_Collide(obj, @mon.Obj) then
762 begin
763 if HitMonster(mon, d, obj^.Vel.X, obj^.Vel.Y, SpawnerUID, t) then
764 begin
765 if (t <> HIT_FLAME) then
766 begin
767 mon.Push((obj^.Vel.X+obj^.Accel.X)*IfThen(t = HIT_BFG, 8, 1) div 4,
768 (obj^.Vel.Y+obj^.Accel.Y)*IfThen(t = HIT_BFG, 8, 1) div 4);
769 end;
770 result := True;
771 end;
772 end;
773 end;
775 function MonsterHit(): Boolean;
776 begin
777 result := g_Mons_ForEach(monsCheckHit);
778 end;
780 begin
781 Result := 0;
783 if HitCorpses then
784 begin
785 h := High(gCorpses);
787 if gAdvCorpses and (h <> -1) then
788 for i := 0 to h do
789 if (gCorpses[i] <> nil) and (gCorpses[i].State <> CORPSE_STATE_REMOVEME) and
790 g_Obj_Collide(obj, @gCorpses[i].Obj) then
791 begin
792 // Ðàñïèëèâàåì òðóï:
793 gCorpses[i].Damage(d, (obj^.Vel.X+obj^.Accel.X) div 4,
794 (obj^.Vel.Y+obj^.Accel.Y) div 4);
795 Result := 1;
796 end;
797 end;
799 case gGameSettings.GameMode of
800 // Êàìïàíèÿ:
801 GM_COOP, GM_SINGLE:
802 begin
803 // Ñíà÷àëà áü¸ì ìîíñòðîâ, åñëè åñòü, ïîòîì ïûòàåìñÿ áèòü èãðîêîâ
804 if MonsterHit() then
805 begin
806 Result := 2;
807 Exit;
808 end;
810 if PlayerHit() then
811 begin
812 Result := 1;
813 Exit;
814 end;
815 end;
817 // Äåçìàò÷:
818 GM_DM:
819 begin
820 // Ñíà÷àëà áü¸ì èãðîêîâ, åñëè åñòü, ïîòîì ïûòàåìñÿ áèòü ìîíñòðîâ
821 if PlayerHit() then
822 begin
823 Result := 1;
824 Exit;
825 end;
827 if MonsterHit() then
828 begin
829 Result := 2;
830 Exit;
831 end;
832 end;
834 // Êîìàíäíûå:
835 GM_TDM, GM_CTF:
836 begin
837 // Ñíà÷àëà áü¸ì èãðîêîâ êîìàíäû ñîïåðíèêà
838 if PlayerHit(2) then
839 begin
840 Result := 1;
841 Exit;
842 end;
844 // Ïîòîì ìîíñòðîâ
845 if MonsterHit() then
846 begin
847 Result := 2;
848 Exit;
849 end;
851 // È â êîíöå ñâîèõ èãðîêîâ
852 if PlayerHit(1) then
853 begin
854 Result := 1;
855 Exit;
856 end;
857 end;
859 end;
860 end;
862 function g_Weapon_HitUID(UID: Word; d: Integer; SpawnerUID: Word; t: Byte): Boolean;
863 begin
864 Result := False;
866 case g_GetUIDType(UID) of
867 UID_PLAYER: Result := HitPlayer(g_Player_Get(UID), d, 0, 0, SpawnerUID, t);
868 UID_MONSTER: Result := HitMonster(g_Monsters_Get(UID), d, 0, 0, SpawnerUID, t);
869 else Exit;
870 end;
871 end;
873 function g_Weapon_Explode(X, Y: Integer; rad: Integer; SpawnerUID: Word): Boolean;
874 var
875 r: Integer;
877 function monsExCheck (monidx: Integer; mon: TMonster): Boolean;
878 var
879 dx, dy, mm: Integer;
880 begin
881 result := false; // don't stop
882 if mon <> nil then
883 begin
884 with mon do
885 begin
886 dx := Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2)-X;
887 dy := Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)-Y;
889 if dx > 1000 then dx := 1000;
890 if dy > 1000 then dy := 1000;
892 if (dx*dx+dy*dy < r) then
893 begin
894 //m := PointToRect(X, Y, Obj.X+Obj.Rect.X, Obj.Y+Obj.Rect.Y, Obj.Rect.Width, Obj.Rect.Height);
896 mm := Max(abs(dx), abs(dy));
897 if mm = 0 then mm := 1;
899 if mon.Live then
900 HitMonster(mon, ((mon.Obj.Rect.Width div 4)*10*(rad-mm)) div rad,
901 0, 0, SpawnerUID, HIT_ROCKET);
903 mon.Push((dx*7) div mm, (dy*7) div mm);
904 end;
905 end;
906 end;
907 end;
909 var
910 i, h, dx, dy, m, mm: Integer;
911 _angle: SmallInt;
913 begin
914 Result := False;
916 g_Triggers_PressC(X, Y, rad, SpawnerUID, ACTIVATE_SHOT);
918 r := rad*rad;
920 h := High(gPlayers);
922 if h <> -1 then
923 for i := 0 to h do
924 if (gPlayers[i] <> nil) and gPlayers[i].Live then
925 with gPlayers[i] do
926 begin
927 dx := Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2)-X;
928 dy := Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)-Y;
930 if dx > 1000 then dx := 1000;
931 if dy > 1000 then dy := 1000;
933 if dx*dx+dy*dy < r then
934 begin
935 //m := PointToRect(X, Y, GameX+PLAYER_RECT.X, GameY+PLAYER_RECT.Y,
936 // PLAYER_RECT.Width, PLAYER_RECT.Height);
938 mm := Max(abs(dx), abs(dy));
939 if mm = 0 then mm := 1;
941 HitPlayer(gPlayers[i], (100*(rad-mm)) div rad, (dx*10) div mm, (dy*10) div mm, SpawnerUID, HIT_ROCKET);
942 gPlayers[i].Push((dx*7) div mm, (dy*7) div mm);
943 end;
944 end;
946 g_Mons_ForEach(monsExCheck);
949 h := High(gCorpses);
951 if gAdvCorpses and (h <> -1) then
952 for i := 0 to h do
953 if (gCorpses[i] <> nil) and (gCorpses[i].State <> CORPSE_STATE_REMOVEME) then
954 with gCorpses[i] do
955 begin
956 dx := Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2)-X;
957 dy := Obj.Y+Obj.Rect.Y+(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,
965 Obj.Rect.Width, Obj.Rect.Height);
967 mm := Max(abs(dx), abs(dy));
968 if mm = 0 then mm := 1;
970 Damage(Round(100*(rad-m)/rad), (dx*10) div mm, (dy*10) div mm);
971 end;
972 end;
974 h := High(gGibs);
976 if gAdvGibs and (h <> -1) then
977 for i := 0 to h do
978 if gGibs[i].Live then
979 with gGibs[i] do
980 begin
981 dx := Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2)-X;
982 dy := Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)-Y;
984 if dx > 1000 then dx := 1000;
985 if dy > 1000 then dy := 1000;
987 if dx*dx+dy*dy < r then
988 begin
989 m := PointToRect(X, Y, Obj.X+Obj.Rect.X, Obj.Y+Obj.Rect.Y,
990 Obj.Rect.Width, Obj.Rect.Height);
991 _angle := GetAngle(Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2),
992 Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2), X, Y);
994 g_Obj_PushA(@Obj, Round(15*(rad-m)/rad), _angle);
995 positionChanged(); // this updates spatial accelerators
996 end;
997 end;
998 end;
1000 procedure g_Weapon_Init();
1001 begin
1002 CreateWaterMap();
1003 end;
1005 procedure g_Weapon_Free();
1006 var
1007 i: Integer;
1008 begin
1009 if Shots <> nil then
1010 begin
1011 for i := 0 to High(Shots) do
1012 if Shots[i].ShotType <> 0 then
1013 Shots[i].Animation.Free();
1015 Shots := nil;
1016 end;
1018 WaterMap := nil;
1019 end;
1021 procedure g_Weapon_LoadData();
1022 begin
1023 e_WriteLog('Loading weapons data...', MSG_NOTIFY);
1025 g_Sound_CreateWADEx('SOUND_WEAPON_HITPUNCH', GameWAD+':SOUNDS\HITPUNCH');
1026 g_Sound_CreateWADEx('SOUND_WEAPON_MISSPUNCH', GameWAD+':SOUNDS\MISSPUNCH');
1027 g_Sound_CreateWADEx('SOUND_WEAPON_HITBERSERK', GameWAD+':SOUNDS\HITBERSERK');
1028 g_Sound_CreateWADEx('SOUND_WEAPON_MISSBERSERK', GameWAD+':SOUNDS\MISSBERSERK');
1029 g_Sound_CreateWADEx('SOUND_WEAPON_SELECTSAW', GameWAD+':SOUNDS\SELECTSAW');
1030 g_Sound_CreateWADEx('SOUND_WEAPON_IDLESAW', GameWAD+':SOUNDS\IDLESAW');
1031 g_Sound_CreateWADEx('SOUND_WEAPON_HITSAW', GameWAD+':SOUNDS\HITSAW');
1032 g_Sound_CreateWADEx('SOUND_WEAPON_FIRESHOTGUN2', GameWAD+':SOUNDS\FIRESHOTGUN2');
1033 g_Sound_CreateWADEx('SOUND_WEAPON_FIRESHOTGUN', GameWAD+':SOUNDS\FIRESHOTGUN');
1034 g_Sound_CreateWADEx('SOUND_WEAPON_FIRESAW', GameWAD+':SOUNDS\FIRESAW');
1035 g_Sound_CreateWADEx('SOUND_WEAPON_FIREROCKET', GameWAD+':SOUNDS\FIREROCKET');
1036 g_Sound_CreateWADEx('SOUND_WEAPON_FIREPLASMA', GameWAD+':SOUNDS\FIREPLASMA');
1037 g_Sound_CreateWADEx('SOUND_WEAPON_FIREPISTOL', GameWAD+':SOUNDS\FIREPISTOL');
1038 g_Sound_CreateWADEx('SOUND_WEAPON_FIRECGUN', GameWAD+':SOUNDS\FIRECGUN');
1039 g_Sound_CreateWADEx('SOUND_WEAPON_FIREBFG', GameWAD+':SOUNDS\FIREBFG');
1040 g_Sound_CreateWADEx('SOUND_FIRE', GameWAD+':SOUNDS\FIRE');
1041 g_Sound_CreateWADEx('SOUND_WEAPON_STARTFIREBFG', GameWAD+':SOUNDS\STARTFIREBFG');
1042 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEROCKET', GameWAD+':SOUNDS\EXPLODEROCKET');
1043 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEBFG', GameWAD+':SOUNDS\EXPLODEBFG');
1044 g_Sound_CreateWADEx('SOUND_WEAPON_BFGWATER', GameWAD+':SOUNDS\BFGWATER');
1045 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEPLASMA', GameWAD+':SOUNDS\EXPLODEPLASMA');
1046 g_Sound_CreateWADEx('SOUND_WEAPON_PLASMAWATER', GameWAD+':SOUNDS\PLASMAWATER');
1047 g_Sound_CreateWADEx('SOUND_WEAPON_FIREBALL', GameWAD+':SOUNDS\FIREBALL');
1048 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEBALL', GameWAD+':SOUNDS\EXPLODEBALL');
1049 g_Sound_CreateWADEx('SOUND_WEAPON_FIREREV', GameWAD+':SOUNDS\FIREREV');
1050 g_Sound_CreateWADEx('SOUND_PLAYER_JETFLY', GameWAD+':SOUNDS\WORKJETPACK');
1051 g_Sound_CreateWADEx('SOUND_PLAYER_JETON', GameWAD+':SOUNDS\STARTJETPACK');
1052 g_Sound_CreateWADEx('SOUND_PLAYER_JETOFF', GameWAD+':SOUNDS\STOPJETPACK');
1053 g_Sound_CreateWADEx('SOUND_PLAYER_CASING1', GameWAD+':SOUNDS\CASING1');
1054 g_Sound_CreateWADEx('SOUND_PLAYER_CASING2', GameWAD+':SOUNDS\CASING2');
1055 g_Sound_CreateWADEx('SOUND_PLAYER_SHELL1', GameWAD+':SOUNDS\SHELL1');
1056 g_Sound_CreateWADEx('SOUND_PLAYER_SHELL2', GameWAD+':SOUNDS\SHELL2');
1058 g_Texture_CreateWADEx('TEXTURE_WEAPON_ROCKET', GameWAD+':TEXTURES\BROCKET');
1059 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_SKELFIRE', GameWAD+':TEXTURES\BSKELFIRE', 64, 16, 2);
1060 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_BFG', GameWAD+':TEXTURES\BBFG', 64, 64, 2);
1061 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_PLASMA', GameWAD+':TEXTURES\BPLASMA', 16, 16, 2);
1062 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_IMPFIRE', GameWAD+':TEXTURES\BIMPFIRE', 16, 16, 2);
1063 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_BSPFIRE', GameWAD+':TEXTURES\BBSPFIRE', 16, 16, 2);
1064 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_CACOFIRE', GameWAD+':TEXTURES\BCACOFIRE', 16, 16, 2);
1065 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_BARONFIRE', GameWAD+':TEXTURES\BBARONFIRE', 64, 16, 2);
1066 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_MANCUBFIRE', GameWAD+':TEXTURES\BMANCUBFIRE', 64, 32, 2);
1067 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_ROCKET', GameWAD+':TEXTURES\EROCKET', 128, 128, 6);
1068 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_SKELFIRE', GameWAD+':TEXTURES\ESKELFIRE', 64, 64, 3);
1069 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_BFG', GameWAD+':TEXTURES\EBFG', 128, 128, 6);
1070 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_IMPFIRE', GameWAD+':TEXTURES\EIMPFIRE', 64, 64, 3);
1071 g_Frames_CreateWAD(nil, 'FRAMES_BFGHIT', GameWAD+':TEXTURES\BFGHIT', 64, 64, 4);
1072 g_Frames_CreateWAD(nil, 'FRAMES_FIRE', GameWAD+':TEXTURES\FIRE', 64, 128, 8);
1073 g_Frames_CreateWAD(nil, 'FRAMES_FLAME', GameWAD+':TEXTURES\FLAME', 32, 32, 11);
1074 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_PLASMA', GameWAD+':TEXTURES\EPLASMA', 32, 32, 4, True);
1075 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_BSPFIRE', GameWAD+':TEXTURES\EBSPFIRE', 32, 32, 5);
1076 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_CACOFIRE', GameWAD+':TEXTURES\ECACOFIRE', 64, 64, 3);
1077 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_BARONFIRE', GameWAD+':TEXTURES\EBARONFIRE', 64, 64, 3);
1078 g_Frames_CreateWAD(nil, 'FRAMES_SMOKE', GameWAD+':TEXTURES\SMOKE', 32, 32, 10, False);
1080 g_Texture_CreateWADEx('TEXTURE_SHELL_BULLET', GameWAD+':TEXTURES\EBULLET');
1081 g_Texture_CreateWADEx('TEXTURE_SHELL_SHELL', GameWAD+':TEXTURES\ESHELL');
1082 end;
1084 procedure g_Weapon_FreeData();
1085 begin
1086 e_WriteLog('Releasing weapons data...', MSG_NOTIFY);
1088 g_Sound_Delete('SOUND_WEAPON_HITPUNCH');
1089 g_Sound_Delete('SOUND_WEAPON_MISSPUNCH');
1090 g_Sound_Delete('SOUND_WEAPON_HITBERSERK');
1091 g_Sound_Delete('SOUND_WEAPON_MISSBERSERK');
1092 g_Sound_Delete('SOUND_WEAPON_SELECTSAW');
1093 g_Sound_Delete('SOUND_WEAPON_IDLESAW');
1094 g_Sound_Delete('SOUND_WEAPON_HITSAW');
1095 g_Sound_Delete('SOUND_WEAPON_FIRESHOTGUN2');
1096 g_Sound_Delete('SOUND_WEAPON_FIRESHOTGUN');
1097 g_Sound_Delete('SOUND_WEAPON_FIRESAW');
1098 g_Sound_Delete('SOUND_WEAPON_FIREROCKET');
1099 g_Sound_Delete('SOUND_WEAPON_FIREPLASMA');
1100 g_Sound_Delete('SOUND_WEAPON_FIREPISTOL');
1101 g_Sound_Delete('SOUND_WEAPON_FIRECGUN');
1102 g_Sound_Delete('SOUND_WEAPON_FIREBFG');
1103 g_Sound_Delete('SOUND_FIRE');
1104 g_Sound_Delete('SOUND_WEAPON_STARTFIREBFG');
1105 g_Sound_Delete('SOUND_WEAPON_EXPLODEROCKET');
1106 g_Sound_Delete('SOUND_WEAPON_EXPLODEBFG');
1107 g_Sound_Delete('SOUND_WEAPON_BFGWATER');
1108 g_Sound_Delete('SOUND_WEAPON_EXPLODEPLASMA');
1109 g_Sound_Delete('SOUND_WEAPON_PLASMAWATER');
1110 g_Sound_Delete('SOUND_WEAPON_FIREBALL');
1111 g_Sound_Delete('SOUND_WEAPON_EXPLODEBALL');
1112 g_Sound_Delete('SOUND_WEAPON_FIREREV');
1113 g_Sound_Delete('SOUND_PLAYER_JETFLY');
1114 g_Sound_Delete('SOUND_PLAYER_JETON');
1115 g_Sound_Delete('SOUND_PLAYER_JETOFF');
1116 g_Sound_Delete('SOUND_PLAYER_CASING1');
1117 g_Sound_Delete('SOUND_PLAYER_CASING2');
1118 g_Sound_Delete('SOUND_PLAYER_SHELL1');
1119 g_Sound_Delete('SOUND_PLAYER_SHELL2');
1121 g_Texture_Delete('TEXTURE_WEAPON_ROCKET');
1122 g_Frames_DeleteByName('FRAMES_WEAPON_BFG');
1123 g_Frames_DeleteByName('FRAMES_WEAPON_PLASMA');
1124 g_Frames_DeleteByName('FRAMES_WEAPON_IMPFIRE');
1125 g_Frames_DeleteByName('FRAMES_WEAPON_BSPFIRE');
1126 g_Frames_DeleteByName('FRAMES_WEAPON_CACOFIRE');
1127 g_Frames_DeleteByName('FRAMES_WEAPON_MANCUBFIRE');
1128 g_Frames_DeleteByName('FRAMES_EXPLODE_ROCKET');
1129 g_Frames_DeleteByName('FRAMES_EXPLODE_BFG');
1130 g_Frames_DeleteByName('FRAMES_EXPLODE_IMPFIRE');
1131 g_Frames_DeleteByName('FRAMES_BFGHIT');
1132 g_Frames_DeleteByName('FRAMES_FIRE');
1133 g_Frames_DeleteByName('FRAMES_EXPLODE_PLASMA');
1134 g_Frames_DeleteByName('FRAMES_EXPLODE_BSPFIRE');
1135 g_Frames_DeleteByName('FRAMES_EXPLODE_CACOFIRE');
1136 g_Frames_DeleteByName('FRAMES_SMOKE');
1137 g_Frames_DeleteByName('FRAMES_WEAPON_BARONFIRE');
1138 g_Frames_DeleteByName('FRAMES_EXPLODE_BARONFIRE');
1139 end;
1141 procedure g_Weapon_gun(x, y, xd, yd, v, dmg: Integer; SpawnerUID: Word; CheckTrigger: Boolean);
1142 var
1143 a: Integer;
1144 x2, y2: Integer;
1145 dx, dy: Integer;
1146 xe, ye: Integer;
1147 xi, yi: Integer;
1148 s, c: Extended;
1149 //vx, vy: Integer;
1150 xx, yy, d: Integer;
1152 i: Integer;
1153 t1, _collide: Boolean;
1154 w, h: Word;
1155 begin
1156 a := GetAngle(x, y, xd, yd)+180;
1158 SinCos(DegToRad(-a), s, c);
1160 if Abs(s) < 0.01 then s := 0;
1161 if Abs(c) < 0.01 then c := 0;
1163 x2 := x+Round(c*gMapInfo.Width);
1164 y2 := y+Round(s*gMapInfo.Width);
1166 t1 := gWalls <> nil;
1167 _collide := False;
1168 w := gMapInfo.Width;
1169 h := gMapInfo.Height;
1171 xe := 0;
1172 ye := 0;
1173 dx := x2-x;
1174 dy := y2-y;
1176 if (xd = 0) and (yd = 0) then Exit;
1178 if dx > 0 then xi := 1 else if dx < 0 then xi := -1 else xi := 0;
1179 if dy > 0 then yi := 1 else if dy < 0 then yi := -1 else yi := 0;
1181 dx := Abs(dx);
1182 dy := Abs(dy);
1184 if dx > dy then d := dx else d := dy;
1186 //blood vel, for Monster.Damage()
1187 //vx := (dx*10 div d)*xi;
1188 //vy := (dy*10 div d)*yi;
1190 xx := x;
1191 yy := y;
1193 for i := 1 to d do
1194 begin
1195 xe := xe+dx;
1196 ye := ye+dy;
1198 if xe > d then
1199 begin
1200 xe := xe-d;
1201 xx := xx+xi;
1202 end;
1204 if ye > d then
1205 begin
1206 ye := ye-d;
1207 yy := yy+yi;
1208 end;
1210 if (yy > h) or (yy < 0) then Break;
1211 if (xx > w) or (xx < 0) then Break;
1213 if t1 then
1214 if ByteBool(gCollideMap[yy, xx] and MARK_BLOCKED) then
1215 begin
1216 _collide := True;
1217 g_GFX_Spark(xx-xi, yy-yi, 2+Random(2), 180+a, 0, 0);
1218 if g_Game_IsServer and g_Game_IsNet then
1219 MH_SEND_Effect(xx-xi, yy-yi, 180+a, NET_GFX_SPARK);
1220 end;
1222 if not _collide then
1223 _collide := GunHit(xx, yy, xi*v, yi*v, dmg, SpawnerUID, v <> 0) <> 0;
1225 if _collide then
1226 Break;
1227 end;
1229 if CheckTrigger and g_Game_IsServer then
1230 g_Triggers_PressL(X, Y, xx-xi, yy-yi, SpawnerUID, ACTIVATE_SHOT);
1231 end;
1233 procedure g_Weapon_punch(x, y: Integer; d, SpawnerUID: Word);
1234 var
1235 obj: TObj;
1236 begin
1237 obj.X := X;
1238 obj.Y := Y;
1239 obj.rect.X := 0;
1240 obj.rect.Y := 0;
1241 obj.rect.Width := 39;
1242 obj.rect.Height := 52;
1243 obj.Vel.X := 0;
1244 obj.Vel.Y := 0;
1245 obj.Accel.X := 0;
1246 obj.Accel.Y := 0;
1248 if g_Weapon_Hit(@obj, d, SpawnerUID, HIT_SOME) <> 0 then
1249 g_Sound_PlayExAt('SOUND_WEAPON_HITPUNCH', x, y)
1250 else
1251 g_Sound_PlayExAt('SOUND_WEAPON_MISSPUNCH', x, y);
1252 end;
1254 function g_Weapon_chainsaw(x, y: Integer; d, SpawnerUID: Word): Integer;
1255 var
1256 obj: TObj;
1257 begin
1258 obj.X := X;
1259 obj.Y := Y;
1260 obj.rect.X := 0;
1261 obj.rect.Y := 0;
1262 obj.rect.Width := 32;
1263 obj.rect.Height := 52;
1264 obj.Vel.X := 0;
1265 obj.Vel.Y := 0;
1266 obj.Accel.X := 0;
1267 obj.Accel.Y := 0;
1269 Result := g_Weapon_Hit(@obj, d, SpawnerUID, HIT_SOME);
1270 end;
1272 procedure g_Weapon_rocket(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1273 Silent: Boolean = False);
1274 var
1275 find_id: DWORD;
1276 dx, dy: Integer;
1277 begin
1278 if WID < 0 then
1279 find_id := FindShot()
1280 else
1281 begin
1282 find_id := WID;
1283 if Integer(find_id) >= High(Shots) then
1284 SetLength(Shots, find_id + 64)
1285 end;
1287 with Shots[find_id] do
1288 begin
1289 g_Obj_Init(@Obj);
1291 Obj.Rect.Width := SHOT_ROCKETLAUNCHER_WIDTH;
1292 Obj.Rect.Height := SHOT_ROCKETLAUNCHER_HEIGHT;
1294 dx := IfThen(xd > x, -Obj.Rect.Width, 0);
1295 dy := -(Obj.Rect.Height div 2);
1297 ShotType := WEAPON_ROCKETLAUNCHER;
1298 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 12);
1300 Animation := nil;
1301 triggers := nil;
1302 g_Texture_Get('TEXTURE_WEAPON_ROCKET', TextureID);
1303 end;
1305 Shots[find_id].SpawnerUID := SpawnerUID;
1307 if not Silent then
1308 g_Sound_PlayExAt('SOUND_WEAPON_FIREROCKET', x, y);
1309 end;
1311 procedure g_Weapon_revf(x, y, xd, yd: Integer; SpawnerUID, TargetUID: Word;
1312 WID: Integer = -1; Silent: Boolean = False);
1313 var
1314 find_id, FramesID: DWORD;
1315 dx, dy: Integer;
1316 begin
1317 if WID < 0 then
1318 find_id := FindShot()
1319 else
1320 begin
1321 find_id := WID;
1322 if Integer(find_id) >= High(Shots) then
1323 SetLength(Shots, find_id + 64)
1324 end;
1326 with Shots[find_id] do
1327 begin
1328 g_Obj_Init(@Obj);
1330 Obj.Rect.Width := SHOT_SKELFIRE_WIDTH;
1331 Obj.Rect.Height := SHOT_SKELFIRE_HEIGHT;
1333 dx := -(Obj.Rect.Width div 2);
1334 dy := -(Obj.Rect.Height div 2);
1336 ShotType := WEAPON_SKEL_FIRE;
1337 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 12);
1339 triggers := nil;
1340 target := TargetUID;
1341 g_Frames_Get(FramesID, 'FRAMES_WEAPON_SKELFIRE');
1342 Animation := TAnimation.Create(FramesID, True, 5);
1343 end;
1345 Shots[find_id].SpawnerUID := SpawnerUID;
1347 if not Silent then
1348 g_Sound_PlayExAt('SOUND_WEAPON_FIREREV', x, y);
1349 end;
1351 procedure g_Weapon_plasma(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1352 Silent: Boolean = False);
1353 var
1354 find_id, FramesID: DWORD;
1355 dx, dy: Integer;
1356 begin
1357 if WID < 0 then
1358 find_id := FindShot()
1359 else
1360 begin
1361 find_id := WID;
1362 if Integer(find_id) >= High(Shots) then
1363 SetLength(Shots, find_id + 64);
1364 end;
1366 with Shots[find_id] do
1367 begin
1368 g_Obj_Init(@Obj);
1370 Obj.Rect.Width := SHOT_PLASMA_WIDTH;
1371 Obj.Rect.Height := SHOT_PLASMA_HEIGHT;
1373 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1374 dy := -(Obj.Rect.Height div 2);
1376 ShotType := WEAPON_PLASMA;
1377 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1379 triggers := nil;
1380 g_Frames_Get(FramesID, 'FRAMES_WEAPON_PLASMA');
1381 Animation := TAnimation.Create(FramesID, True, 5);
1382 end;
1384 Shots[find_id].SpawnerUID := SpawnerUID;
1386 if not Silent then
1387 g_Sound_PlayExAt('SOUND_WEAPON_FIREPLASMA', x, y);
1388 end;
1390 procedure g_Weapon_flame(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1391 Silent: Boolean = False);
1392 var
1393 find_id: DWORD;
1394 dx, dy: Integer;
1395 begin
1396 if WID < 0 then
1397 find_id := FindShot()
1398 else
1399 begin
1400 find_id := WID;
1401 if Integer(find_id) >= High(Shots) then
1402 SetLength(Shots, find_id + 64);
1403 end;
1405 with Shots[find_id] do
1406 begin
1407 g_Obj_Init(@Obj);
1409 Obj.Rect.Width := SHOT_FLAME_WIDTH;
1410 Obj.Rect.Height := SHOT_FLAME_HEIGHT;
1412 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1413 dy := -(Obj.Rect.Height div 2);
1415 ShotType := WEAPON_FLAMETHROWER;
1416 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1418 triggers := nil;
1419 Animation := nil;
1420 TextureID := 0;
1421 g_Frames_Get(TextureID, 'FRAMES_FLAME');
1422 end;
1424 Shots[find_id].SpawnerUID := SpawnerUID;
1426 // if not Silent then
1427 // g_Sound_PlayExAt('SOUND_WEAPON_FIREPLASMA', x, y);
1428 end;
1430 procedure g_Weapon_ball1(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1431 Silent: Boolean = False);
1432 var
1433 find_id, FramesID: DWORD;
1434 dx, dy: Integer;
1435 begin
1436 if WID < 0 then
1437 find_id := FindShot()
1438 else
1439 begin
1440 find_id := WID;
1441 if Integer(find_id) >= High(Shots) then
1442 SetLength(Shots, find_id + 64)
1443 end;
1445 with Shots[find_id] do
1446 begin
1447 g_Obj_Init(@Obj);
1449 Obj.Rect.Width := 16;
1450 Obj.Rect.Height := 16;
1452 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1453 dy := -(Obj.Rect.Height div 2);
1455 ShotType := WEAPON_IMP_FIRE;
1456 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1458 triggers := nil;
1459 g_Frames_Get(FramesID, 'FRAMES_WEAPON_IMPFIRE');
1460 Animation := TAnimation.Create(FramesID, True, 4);
1461 end;
1463 Shots[find_id].SpawnerUID := SpawnerUID;
1465 if not Silent then
1466 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x, y);
1467 end;
1469 procedure g_Weapon_ball2(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1470 Silent: Boolean = False);
1471 var
1472 find_id, FramesID: DWORD;
1473 dx, dy: Integer;
1474 begin
1475 if WID < 0 then
1476 find_id := FindShot()
1477 else
1478 begin
1479 find_id := WID;
1480 if Integer(find_id) >= High(Shots) then
1481 SetLength(Shots, find_id + 64)
1482 end;
1484 with Shots[find_id] do
1485 begin
1486 g_Obj_Init(@Obj);
1488 Obj.Rect.Width := 16;
1489 Obj.Rect.Height := 16;
1491 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1492 dy := -(Obj.Rect.Height div 2);
1494 ShotType := WEAPON_CACO_FIRE;
1495 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1497 triggers := nil;
1498 g_Frames_Get(FramesID, 'FRAMES_WEAPON_CACOFIRE');
1499 Animation := TAnimation.Create(FramesID, True, 4);
1500 end;
1502 Shots[find_id].SpawnerUID := SpawnerUID;
1504 if not Silent then
1505 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x, y);
1506 end;
1508 procedure g_Weapon_ball7(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1509 Silent: Boolean = False);
1510 var
1511 find_id, FramesID: DWORD;
1512 dx, dy: Integer;
1513 begin
1514 if WID < 0 then
1515 find_id := FindShot()
1516 else
1517 begin
1518 find_id := WID;
1519 if Integer(find_id) >= High(Shots) then
1520 SetLength(Shots, find_id + 64)
1521 end;
1523 with Shots[find_id] do
1524 begin
1525 g_Obj_Init(@Obj);
1527 Obj.Rect.Width := 32;
1528 Obj.Rect.Height := 16;
1530 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1531 dy := -(Obj.Rect.Height div 2);
1533 ShotType := WEAPON_BARON_FIRE;
1534 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1536 triggers := nil;
1537 g_Frames_Get(FramesID, 'FRAMES_WEAPON_BARONFIRE');
1538 Animation := TAnimation.Create(FramesID, True, 4);
1539 end;
1541 Shots[find_id].SpawnerUID := SpawnerUID;
1543 if not Silent then
1544 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x, y);
1545 end;
1547 procedure g_Weapon_aplasma(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1548 Silent: Boolean = False);
1549 var
1550 find_id, FramesID: DWORD;
1551 dx, dy: Integer;
1552 begin
1553 if WID < 0 then
1554 find_id := FindShot()
1555 else
1556 begin
1557 find_id := WID;
1558 if Integer(find_id) >= High(Shots) then
1559 SetLength(Shots, find_id + 64)
1560 end;
1562 with Shots[find_id] do
1563 begin
1564 g_Obj_Init(@Obj);
1566 Obj.Rect.Width := 16;
1567 Obj.Rect.Height := 16;
1569 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1570 dy := -(Obj.Rect.Height div 2);
1572 ShotType := WEAPON_BSP_FIRE;
1573 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1575 triggers := nil;
1577 g_Frames_Get(FramesID, 'FRAMES_WEAPON_BSPFIRE');
1578 Animation := TAnimation.Create(FramesID, True, 4);
1579 end;
1581 Shots[find_id].SpawnerUID := SpawnerUID;
1583 if not Silent then
1584 g_Sound_PlayExAt('SOUND_WEAPON_FIREPLASMA', x, y);
1585 end;
1587 procedure g_Weapon_manfire(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1588 Silent: Boolean = False);
1589 var
1590 find_id, FramesID: DWORD;
1591 dx, dy: Integer;
1592 begin
1593 if WID < 0 then
1594 find_id := FindShot()
1595 else
1596 begin
1597 find_id := WID;
1598 if Integer(find_id) >= High(Shots) then
1599 SetLength(Shots, find_id + 64)
1600 end;
1602 with Shots[find_id] do
1603 begin
1604 g_Obj_Init(@Obj);
1606 Obj.Rect.Width := 32;
1607 Obj.Rect.Height := 32;
1609 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1610 dy := -(Obj.Rect.Height div 2);
1612 ShotType := WEAPON_MANCUB_FIRE;
1613 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1615 triggers := nil;
1617 g_Frames_Get(FramesID, 'FRAMES_WEAPON_MANCUBFIRE');
1618 Animation := TAnimation.Create(FramesID, True, 4);
1619 end;
1621 Shots[find_id].SpawnerUID := SpawnerUID;
1623 if not Silent then
1624 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x, y);
1625 end;
1627 procedure g_Weapon_bfgshot(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1628 Silent: Boolean = False);
1629 var
1630 find_id, FramesID: DWORD;
1631 dx, dy: Integer;
1632 begin
1633 if WID < 0 then
1634 find_id := FindShot()
1635 else
1636 begin
1637 find_id := WID;
1638 if Integer(find_id) >= High(Shots) then
1639 SetLength(Shots, find_id + 64)
1640 end;
1642 with Shots[find_id] do
1643 begin
1644 g_Obj_Init(@Obj);
1646 Obj.Rect.Width := SHOT_BFG_WIDTH;
1647 Obj.Rect.Height := SHOT_BFG_HEIGHT;
1649 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1650 dy := -(Obj.Rect.Height div 2);
1652 ShotType := WEAPON_BFG;
1653 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1655 triggers := nil;
1656 g_Frames_Get(FramesID, 'FRAMES_WEAPON_BFG');
1657 Animation := TAnimation.Create(FramesID, True, 6);
1658 end;
1660 Shots[find_id].SpawnerUID := SpawnerUID;
1662 if not Silent then
1663 g_Sound_PlayExAt('SOUND_WEAPON_FIREBFG', x, y);
1664 end;
1666 procedure g_Weapon_bfghit(x, y: Integer);
1667 var
1668 ID: DWORD;
1669 Anim: TAnimation;
1670 begin
1671 if g_Frames_Get(ID, 'FRAMES_BFGHIT') then
1672 begin
1673 Anim := TAnimation.Create(ID, False, 4);
1674 g_GFX_OnceAnim(x-32, y-32, Anim);
1675 Anim.Free();
1676 end;
1677 end;
1679 procedure g_Weapon_pistol(x, y, xd, yd: Integer; SpawnerUID: Word;
1680 Silent: Boolean = False);
1681 begin
1682 if not Silent then
1683 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', x, y);
1685 g_Weapon_gun(x, y, xd, yd, 1, 3, SpawnerUID, True);
1686 if gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF] then
1687 begin
1688 g_Weapon_gun(x, y+1, xd, yd+1, 1, 3, SpawnerUID, False);
1689 g_Weapon_gun(x, y-1, xd, yd-1, 1, 2, SpawnerUID, False);
1690 end;
1691 end;
1693 procedure g_Weapon_mgun(x, y, xd, yd: Integer; SpawnerUID: Word;
1694 Silent: Boolean = False);
1695 begin
1696 if not Silent then
1697 if gSoundEffectsDF then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', x, y);
1699 g_Weapon_gun(x, y, xd, yd, 1, 3, SpawnerUID, True);
1700 if (gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF]) and
1701 (g_GetUIDType(SpawnerUID) = UID_PLAYER) then
1702 begin
1703 g_Weapon_gun(x, y+1, xd, yd+1, 1, 2, SpawnerUID, False);
1704 g_Weapon_gun(x, y-1, xd, yd-1, 1, 2, SpawnerUID, False);
1705 end;
1706 end;
1708 procedure g_Weapon_shotgun(x, y, xd, yd: Integer; SpawnerUID: Word;
1709 Silent: Boolean = False);
1710 var
1711 i, j: Integer;
1712 begin
1713 if not Silent then
1714 if gSoundEffectsDF then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', x, y);
1716 for i := 0 to 9 do
1717 begin
1718 j := Random(17)-8; // -8 .. 8
1719 g_Weapon_gun(x, y+j, xd, yd+j, IfThen(i mod 2 <> 0, 1, 0), 3, SpawnerUID, i=0);
1720 end;
1721 end;
1723 procedure g_Weapon_dshotgun(x, y, xd, yd: Integer; SpawnerUID: Word;
1724 Silent: Boolean = False);
1725 var
1726 a, i, j: Integer;
1727 begin
1728 if not Silent then
1729 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', x, y);
1731 if gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF] then a := 25 else a := 20;
1732 for i := 0 to a do
1733 begin
1734 j := Random(41)-20; // -20 .. 20
1735 g_Weapon_gun(x, y+j, xd, yd+j, IfThen(i mod 3 <> 0, 0, 1), 3, SpawnerUID, i=0);
1736 end;
1737 end;
1739 procedure g_Weapon_Update();
1740 var
1741 i, a, h, cx, cy, oldvx, oldvy, tf: Integer;
1742 _id: DWORD;
1743 Anim: TAnimation;
1744 t: DWArray;
1745 st: Word;
1746 s: String;
1747 o: TObj;
1748 spl: Boolean;
1749 Loud: Boolean;
1750 tcx, tcy: Integer;
1751 begin
1752 if Shots = nil then
1753 Exit;
1755 for i := 0 to High(Shots) do
1756 begin
1757 if Shots[i].ShotType = 0 then
1758 Continue;
1760 Loud := True;
1762 with Shots[i] do
1763 begin
1764 Timeout := Timeout - 1;
1765 oldvx := Obj.Vel.X;
1766 oldvy := Obj.Vel.Y;
1767 // Àêòèâèðîâàòü òðèããåðû ïî ïóòè (êðîìå óæå àêòèâèðîâàííûõ):
1768 if (Stopped = 0) and g_Game_IsServer then
1769 t := g_Triggers_PressR(Obj.X, Obj.Y, Obj.Rect.Width, Obj.Rect.Height,
1770 SpawnerUID, ACTIVATE_SHOT, triggers)
1771 else
1772 t := nil;
1774 if t <> nil then
1775 begin
1776 // Ïîïîëíÿåì ñïèñîê àêòèâèðîâàííûõ òðèããåðîâ:
1777 if triggers = nil then
1778 triggers := t
1779 else
1780 begin
1781 h := High(t);
1783 for a := 0 to h do
1784 if not InDWArray(t[a], triggers) then
1785 begin
1786 SetLength(triggers, Length(triggers)+1);
1787 triggers[High(triggers)] := t[a];
1788 end;
1789 end;
1790 end;
1792 // Àíèìàöèÿ ñíàðÿäà:
1793 if Animation <> nil then
1794 Animation.Update();
1796 // Äâèæåíèå:
1797 spl := (ShotType <> WEAPON_PLASMA) and
1798 (ShotType <> WEAPON_BFG) and
1799 (ShotType <> WEAPON_BSP_FIRE) and
1800 (ShotType <> WEAPON_FLAMETHROWER);
1802 if Stopped = 0 then
1803 begin
1804 st := g_Obj_Move(@Obj, False, spl);
1805 end
1806 else
1807 begin
1808 st := 0;
1809 end;
1810 positionChanged(); // this updates spatial accelerators
1812 if WordBool(st and MOVE_FALLOUT) or (Obj.X < -1000) or
1813 (Obj.X > gMapInfo.Width+1000) or (Obj.Y < -1000) then
1814 begin
1815 // Íà êëèåíòå ñêîðåå âñåãî è òàê óæå âûïàë.
1816 ShotType := 0;
1817 Animation.Free();
1818 Continue;
1819 end;
1821 cx := Obj.X + (Obj.Rect.Width div 2);
1822 cy := Obj.Y + (Obj.Rect.Height div 2);
1824 case ShotType of
1825 WEAPON_ROCKETLAUNCHER, WEAPON_SKEL_FIRE: // Ðàêåòû è ñíàðÿäû Ñêåëåòà
1826 begin
1827 // Âûëåòåëà èç âîäû:
1828 if WordBool(st and MOVE_HITAIR) then
1829 g_Obj_SetSpeed(@Obj, 12);
1831 // Â âîäå øëåéô - ïóçûðè, â âîçäóõå øëåéô - äûì:
1832 if WordBool(st and MOVE_INWATER) then
1833 g_GFX_Bubbles(Obj.X+(Obj.Rect.Width div 2),
1834 Obj.Y+(Obj.Rect.Height div 2),
1835 1+Random(3), 16, 16)
1836 else
1837 if g_Frames_Get(_id, 'FRAMES_SMOKE') then
1838 begin
1839 Anim := TAnimation.Create(_id, False, 3);
1840 Anim.Alpha := 150;
1841 g_GFX_OnceAnim(Obj.X-14+Random(9),
1842 Obj.Y+(Obj.Rect.Height div 2)-20+Random(9),
1843 Anim, ONCEANIM_SMOKE);
1844 Anim.Free();
1845 end;
1847 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
1848 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL)) or
1849 (g_Weapon_Hit(@Obj, 10, SpawnerUID, HIT_SOME, False) <> 0) or
1850 (Timeout < 1) then
1851 begin
1852 Obj.Vel.X := 0;
1853 Obj.Vel.Y := 0;
1855 g_Weapon_Explode(cx, cy, 60, SpawnerUID);
1857 if ShotType = WEAPON_SKEL_FIRE then
1858 begin // Âçðûâ ñíàðÿäà Ñêåëåòà
1859 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_SKELFIRE') then
1860 begin
1861 Anim := TAnimation.Create(TextureID, False, 8);
1862 Anim.Blending := False;
1863 g_GFX_OnceAnim((Obj.X+32)-58, (Obj.Y+8)-36, Anim);
1864 g_DynLightExplosion((Obj.X+32), (Obj.Y+8), 64, 1, 0, 0);
1865 Anim.Free();
1866 end;
1867 end
1868 else
1869 begin // Âçðûâ Ðàêåòû
1870 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_ROCKET') then
1871 begin
1872 Anim := TAnimation.Create(TextureID, False, 6);
1873 Anim.Blending := False;
1874 g_GFX_OnceAnim(cx-64, cy-64, Anim);
1875 g_DynLightExplosion(cx, cy, 64, 1, 0, 0);
1876 Anim.Free();
1877 end;
1878 end;
1880 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', Obj.X, Obj.Y);
1882 ShotType := 0;
1883 end;
1885 if ShotType = WEAPON_SKEL_FIRE then
1886 begin // Ñàìîíàâîäêà ñíàðÿäà Ñêåëåòà:
1887 if GetPos(target, @o) then
1888 throw(i, Obj.X, Obj.Y,
1889 o.X+o.Rect.X+(o.Rect.Width div 2)+o.Vel.X+o.Accel.X,
1890 o.Y+o.Rect.Y+(o.Rect.Height div 2)+o.Vel.Y+o.Accel.Y,
1891 12);
1892 end;
1893 end;
1895 WEAPON_PLASMA, WEAPON_BSP_FIRE: // Ïëàçìà, ïëàçìà Àðàõíàòðîíà
1896 begin
1897 // Ïîïàëà â âîäó - ýëåêòðîøîê ïî âîäå:
1898 if WordBool(st and (MOVE_INWATER or MOVE_HITWATER)) then
1899 begin
1900 g_Sound_PlayExAt('SOUND_WEAPON_PLASMAWATER', Obj.X, Obj.Y);
1901 if g_Game_IsServer then CheckTrap(i, 10, HIT_ELECTRO);
1902 ShotType := 0;
1903 Continue;
1904 end;
1906 // Âåëè÷èíà óðîíà:
1907 if (ShotType = WEAPON_PLASMA) and
1908 (gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF]) then
1909 a := 10
1910 else
1911 a := 5;
1913 if ShotType = WEAPON_BSP_FIRE then
1914 a := 10;
1916 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
1917 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL)) or
1918 (g_Weapon_Hit(@Obj, a, SpawnerUID, HIT_SOME, False) <> 0) or
1919 (Timeout < 1) then
1920 begin
1921 if ShotType = WEAPON_PLASMA then
1922 s := 'FRAMES_EXPLODE_PLASMA'
1923 else
1924 s := 'FRAMES_EXPLODE_BSPFIRE';
1926 // Âçðûâ Ïëàçìû:
1927 if g_Frames_Get(TextureID, s) then
1928 begin
1929 Anim := TAnimation.Create(TextureID, False, 3);
1930 Anim.Blending := False;
1931 g_GFX_OnceAnim(cx-16, cy-16, Anim);
1932 Anim.Free();
1933 g_DynLightExplosion(cx, cy, 32, 0, 0.5, 0.5);
1934 end;
1936 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEPLASMA', Obj.X, Obj.Y);
1938 ShotType := 0;
1939 end;
1940 end;
1942 WEAPON_FLAMETHROWER: // Îãíåìåò
1943 begin
1944 // Ñî âðåìåíåì óìèðàåò
1945 if (Timeout < 1) then
1946 begin
1947 ShotType := 0;
1948 Continue;
1949 end;
1950 // Ïîä âîäîé òîæå
1951 if WordBool(st and (MOVE_HITWATER or MOVE_INWATER)) then
1952 begin
1953 if WordBool(st and MOVE_HITWATER) then
1954 begin
1955 if g_Frames_Get(_id, 'FRAMES_SMOKE') then
1956 begin
1957 Anim := TAnimation.Create(_id, False, 3);
1958 Anim.Alpha := 0;
1959 tcx := Random(8);
1960 tcy := Random(8);
1961 g_GFX_OnceAnim(cx-4+tcx-(Anim.Width div 2),
1962 cy-4+tcy-(Anim.Height div 2),
1963 Anim, ONCEANIM_SMOKE);
1964 Anim.Free();
1965 end;
1966 end
1967 else
1968 g_GFX_Bubbles(cx, cy, 1+Random(3), 16, 16);
1969 ShotType := 0;
1970 Continue;
1971 end;
1973 // Ãðàâèòàöèÿ
1974 if Stopped = 0 then
1975 Obj.Accel.Y := Obj.Accel.Y + 1;
1976 // Ïîïàëè â ñòåíó èëè â âîäó:
1977 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL or MOVE_HITWATER)) then
1978 begin
1979 // Ïðèëèïàåì:
1980 Obj.Vel.X := 0;
1981 Obj.Vel.Y := 0;
1982 Obj.Accel.Y := 0;
1983 if WordBool(st and MOVE_HITWALL) then
1984 Stopped := MOVE_HITWALL
1985 else if WordBool(st and MOVE_HITLAND) then
1986 Stopped := MOVE_HITLAND
1987 else if WordBool(st and MOVE_HITCEIL) then
1988 Stopped := MOVE_HITCEIL;
1989 end;
1991 a := IfThen(Stopped = 0, 3, 1);
1992 // Åñëè â êîãî-òî ïîïàëè
1993 if g_Weapon_Hit(@Obj, a, SpawnerUID, HIT_FLAME, False) <> 0 then
1994 begin
1995 // HIT_FLAME ñàì ïîäîææåò
1996 // Åñëè â ïîëåòå ïîïàëè, èñ÷åçàåì
1997 if Stopped = 0 then
1998 ShotType := 0;
1999 end;
2001 if Stopped = 0 then
2002 tf := 2
2003 else
2004 tf := 3;
2006 if (gTime mod tf = 0) then
2007 begin
2008 Anim := TAnimation.Create(TextureID, False, 2 + Random(2));
2009 Anim.Alpha := 0;
2010 case Stopped of
2011 MOVE_HITWALL: begin tcx := cx-4+Random(8); tcy := cy-12+Random(24); end;
2012 MOVE_HITLAND: begin tcx := cx-12+Random(24); tcy := cy-10+Random(8); end;
2013 MOVE_HITCEIL: begin tcx := cx-12+Random(24); tcy := cy+6+Random(8); end;
2014 else begin tcx := cx-4+Random(8); tcy := cy-4+Random(8); end;
2015 end;
2016 g_GFX_OnceAnim(tcx-(Anim.Width div 2), tcy-(Anim.Height div 2), Anim, ONCEANIM_SMOKE);
2017 Anim.Free();
2018 //g_DynLightExplosion(tcx, tcy, 1, 1, 0.8, 0.3);
2019 end;
2020 end;
2022 WEAPON_BFG: // BFG
2023 begin
2024 // Ïîïàëà â âîäó - ýëåêòðîøîê ïî âîäå:
2025 if WordBool(st and (MOVE_INWATER or MOVE_HITWATER)) then
2026 begin
2027 g_Sound_PlayExAt('SOUND_WEAPON_BFGWATER', Obj.X, Obj.Y);
2028 if g_Game_IsServer then CheckTrap(i, 1000, HIT_ELECTRO);
2029 ShotType := 0;
2030 Continue;
2031 end;
2033 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2034 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL)) or
2035 (g_Weapon_Hit(@Obj, SHOT_BFG_DAMAGE, SpawnerUID, HIT_BFG, False) <> 0) or
2036 (Timeout < 1) then
2037 begin
2038 // Ëó÷è BFG:
2039 if g_Game_IsServer then g_Weapon_BFG9000(cx, cy, SpawnerUID);
2041 // Âçðûâ BFG:
2042 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_BFG') then
2043 begin
2044 Anim := TAnimation.Create(TextureID, False, 6);
2045 Anim.Blending := False;
2046 g_GFX_OnceAnim(cx-64, cy-64, Anim);
2047 Anim.Free();
2048 g_DynLightExplosion(cx, cy, 96, 0, 1, 0);
2049 end;
2051 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', Obj.X, Obj.Y);
2053 ShotType := 0;
2054 end;
2055 end;
2057 WEAPON_IMP_FIRE, WEAPON_CACO_FIRE, WEAPON_BARON_FIRE: // Âûñòðåëû Áåñà, Êàêîäåìîíà Ðûöàðÿ/Áàðîíà àäà
2058 begin
2059 // Âûëåòåë èç âîäû:
2060 if WordBool(st and MOVE_HITAIR) then
2061 g_Obj_SetSpeed(@Obj, 16);
2063 // Âåëè÷èíà óðîíà:
2064 if ShotType = WEAPON_IMP_FIRE then
2065 a := 5
2066 else
2067 if ShotType = WEAPON_CACO_FIRE then
2068 a := 20
2069 else
2070 a := 40;
2072 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2073 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL)) or
2074 (g_Weapon_Hit(@Obj, a, SpawnerUID, HIT_SOME) <> 0) or
2075 (Timeout < 1) then
2076 begin
2077 if ShotType = WEAPON_IMP_FIRE then
2078 s := 'FRAMES_EXPLODE_IMPFIRE'
2079 else
2080 if ShotType = WEAPON_CACO_FIRE then
2081 s := 'FRAMES_EXPLODE_CACOFIRE'
2082 else
2083 s := 'FRAMES_EXPLODE_BARONFIRE';
2085 // Âçðûâ:
2086 if g_Frames_Get(TextureID, s) then
2087 begin
2088 Anim := TAnimation.Create(TextureID, False, 6);
2089 Anim.Blending := False;
2090 g_GFX_OnceAnim(cx-32, cy-32, Anim);
2091 Anim.Free();
2092 end;
2094 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj.X, Obj.Y);
2096 ShotType := 0;
2097 end;
2098 end;
2100 WEAPON_MANCUB_FIRE: // Âûñòðåë Ìàíêóáóñà
2101 begin
2102 // Âûëåòåë èç âîäû:
2103 if WordBool(st and MOVE_HITAIR) then
2104 g_Obj_SetSpeed(@Obj, 16);
2106 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2107 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL)) or
2108 (g_Weapon_Hit(@Obj, 40, SpawnerUID, HIT_SOME, False) <> 0) or
2109 (Timeout < 1) then
2110 begin
2111 // Âçðûâ:
2112 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_ROCKET') then
2113 begin
2114 Anim := TAnimation.Create(TextureID, False, 6);
2115 Anim.Blending := False;
2116 g_GFX_OnceAnim(cx-64, cy-64, Anim);
2117 Anim.Free();
2118 end;
2120 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj.X, Obj.Y);
2122 ShotType := 0;
2123 end;
2124 end;
2125 end; // case ShotType of...
2127 // Åñëè ñíàðÿäà óæå íåò, óäàëÿåì àíèìàöèþ:
2128 if (ShotType = 0) then
2129 begin
2130 if gGameSettings.GameType = GT_SERVER then
2131 MH_SEND_DeleteShot(i, Obj.X, Obj.Y, Loud);
2132 if Animation <> nil then
2133 begin
2134 Animation.Free();
2135 Animation := nil;
2136 end;
2137 end
2138 else if (ShotType <> WEAPON_FLAMETHROWER) and ((oldvx <> Obj.Vel.X) or (oldvy <> Obj.Vel.Y)) then
2139 if gGameSettings.GameType = GT_SERVER then
2140 MH_SEND_UpdateShot(i);
2141 end;
2142 end;
2143 end;
2145 procedure g_Weapon_Draw();
2146 var
2147 i: Integer;
2148 a: SmallInt;
2149 p: TPoint;
2150 begin
2151 if Shots = nil then
2152 Exit;
2154 for i := 0 to High(Shots) do
2155 if Shots[i].ShotType <> 0 then
2156 with Shots[i] do
2157 begin
2158 if (Shots[i].ShotType = WEAPON_ROCKETLAUNCHER) or
2159 (Shots[i].ShotType = WEAPON_BARON_FIRE) or
2160 (Shots[i].ShotType = WEAPON_MANCUB_FIRE) or
2161 (Shots[i].ShotType = WEAPON_SKEL_FIRE) then
2162 a := -GetAngle2(Obj.Vel.X, Obj.Vel.Y)
2163 else
2164 a := 0;
2166 p.X := Obj.Rect.Width div 2;
2167 p.Y := Obj.Rect.Height div 2;
2169 if Animation <> nil then
2170 begin
2171 if (Shots[i].ShotType = WEAPON_BARON_FIRE) or
2172 (Shots[i].ShotType = WEAPON_MANCUB_FIRE) or
2173 (Shots[i].ShotType = WEAPON_SKEL_FIRE) then
2174 Animation.DrawEx(Obj.X, Obj.Y, M_NONE, p, a)
2175 else
2176 Animation.Draw(Obj.X, Obj.Y, M_NONE);
2177 end
2178 else if TextureID <> 0 then
2179 begin
2180 if (Shots[i].ShotType = WEAPON_ROCKETLAUNCHER) then
2181 e_DrawAdv(TextureID, Obj.X, Obj.Y, 0, True, False, a, @p, M_NONE)
2182 else if (Shots[i].ShotType <> WEAPON_FLAMETHROWER) then
2183 e_Draw(TextureID, Obj.X, Obj.Y, 0, True, False);
2184 end;
2186 if g_debug_Frames then
2187 begin
2188 e_DrawQuad(Obj.X+Obj.Rect.X,
2189 Obj.Y+Obj.Rect.Y,
2190 Obj.X+Obj.Rect.X+Obj.Rect.Width-1,
2191 Obj.Y+Obj.Rect.Y+Obj.Rect.Height-1,
2192 0, 255, 0);
2193 end;
2194 end;
2195 end;
2197 function g_Weapon_Danger(UID: Word; X, Y: Integer; Width, Height: Word; Time: Byte): Boolean;
2198 var
2199 a: Integer;
2200 begin
2201 Result := False;
2203 if Shots = nil then
2204 Exit;
2206 for a := 0 to High(Shots) do
2207 if (Shots[a].ShotType <> 0) and (Shots[a].SpawnerUID <> UID) then
2208 if ((Shots[a].Obj.Vel.Y = 0) and (Shots[a].Obj.Vel.X > 0) and (Shots[a].Obj.X < X)) or
2209 (Shots[a].Obj.Vel.Y = 0) and (Shots[a].Obj.Vel.X < 0) and (Shots[a].Obj.X > X) then
2210 if (Abs(X-Shots[a].Obj.X) < Abs(Shots[a].Obj.Vel.X*Time)) and
2211 g_Collide(X, Y, Width, Height, X, Shots[a].Obj.Y,
2212 Shots[a].Obj.Rect.Width, Shots[a].Obj.Rect.Height) and
2213 g_TraceVector(X, Y, Shots[a].Obj.X, Shots[a].Obj.Y) then
2214 begin
2215 Result := True;
2216 Exit;
2217 end;
2218 end;
2220 procedure g_Weapon_SaveState(var Mem: TBinMemoryWriter);
2221 var
2222 count, i, j: Integer;
2223 dw: DWORD;
2224 begin
2225 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ ñíàðÿäîâ:
2226 count := 0;
2227 if Shots <> nil then
2228 for i := 0 to High(Shots) do
2229 if Shots[i].ShotType <> 0 then
2230 count := count + 1;
2232 Mem := TBinMemoryWriter.Create((count+1) * 80);
2234 // Êîëè÷åñòâî ñíàðÿäîâ:
2235 Mem.WriteInt(count);
2237 if count = 0 then
2238 Exit;
2240 for i := 0 to High(Shots) do
2241 if Shots[i].ShotType <> 0 then
2242 begin
2243 // Ñèãíàòóðà ñíàðÿäà:
2244 dw := SHOT_SIGNATURE; // 'SHOT'
2245 Mem.WriteDWORD(dw);
2246 // Òèï ñíàðÿäà:
2247 Mem.WriteByte(Shots[i].ShotType);
2248 // Öåëü:
2249 Mem.WriteWord(Shots[i].Target);
2250 // UID ñòðåëÿâøåãî:
2251 Mem.WriteWord(Shots[i].SpawnerUID);
2252 // Ðàçìåð ïîëÿ Triggers:
2253 dw := Length(Shots[i].Triggers);
2254 Mem.WriteDWORD(dw);
2255 // Òðèããåðû, àêòèâèðîâàííûå âûñòðåëîì:
2256 for j := 0 to Integer(dw)-1 do
2257 Mem.WriteDWORD(Shots[i].Triggers[j]);
2258 // Îáúåêò ñíàðÿäà:
2259 Obj_SaveState(@Shots[i].Obj, Mem);
2260 // Êîñòûëèíà åáàíàÿ:
2261 Mem.WriteByte(Shots[i].Stopped);
2262 end;
2263 end;
2265 procedure g_Weapon_LoadState(var Mem: TBinMemoryReader);
2266 var
2267 count, i, j: Integer;
2268 dw: DWORD;
2269 begin
2270 if Mem = nil then
2271 Exit;
2273 // Êîëè÷åñòâî ñíàðÿäîâ:
2274 Mem.ReadInt(count);
2276 SetLength(Shots, count);
2278 if count = 0 then
2279 Exit;
2281 for i := 0 to count-1 do
2282 begin
2283 // Ñèãíàòóðà ñíàðÿäà:
2284 Mem.ReadDWORD(dw);
2285 if dw <> SHOT_SIGNATURE then // 'SHOT'
2286 begin
2287 raise EBinSizeError.Create('g_Weapons_LoadState: Wrong Shot Signature');
2288 end;
2289 // Òèï ñíàðÿäà:
2290 Mem.ReadByte(Shots[i].ShotType);
2291 // Öåëü:
2292 Mem.ReadWord(Shots[i].Target);
2293 // UID ñòðåëÿâøåãî:
2294 Mem.ReadWord(Shots[i].SpawnerUID);
2295 // Ðàçìåð ïîëÿ Triggers:
2296 Mem.ReadDWORD(dw);
2297 SetLength(Shots[i].Triggers, dw);
2298 // Òðèããåðû, àêòèâèðîâàííûå âûñòðåëîì:
2299 for j := 0 to Integer(dw)-1 do
2300 Mem.ReadDWORD(Shots[i].Triggers[j]);
2301 // Îáúåêò ïðåäìåòà:
2302 Obj_LoadState(@Shots[i].Obj, Mem);
2303 // Êîñòûëèíà åáàíàÿ:
2304 Mem.ReadByte(Shots[i].Stopped);
2306 // Óñòàíîâêà òåêñòóðû èëè àíèìàöèè:
2307 Shots[i].TextureID := DWORD(-1);
2308 Shots[i].Animation := nil;
2310 case Shots[i].ShotType of
2311 WEAPON_ROCKETLAUNCHER, WEAPON_SKEL_FIRE:
2312 begin
2313 g_Texture_Get('TEXTURE_WEAPON_ROCKET', Shots[i].TextureID);
2314 end;
2315 WEAPON_PLASMA:
2316 begin
2317 g_Frames_Get(dw, 'FRAMES_WEAPON_PLASMA');
2318 Shots[i].Animation := TAnimation.Create(dw, True, 5);
2319 end;
2320 WEAPON_BFG:
2321 begin
2322 g_Frames_Get(dw, 'FRAMES_WEAPON_BFG');
2323 Shots[i].Animation := TAnimation.Create(dw, True, 6);
2324 end;
2325 WEAPON_IMP_FIRE:
2326 begin
2327 g_Frames_Get(dw, 'FRAMES_WEAPON_IMPFIRE');
2328 Shots[i].Animation := TAnimation.Create(dw, True, 4);
2329 end;
2330 WEAPON_BSP_FIRE:
2331 begin
2332 g_Frames_Get(dw, 'FRAMES_WEAPON_BSPFIRE');
2333 Shots[i].Animation := TAnimation.Create(dw, True, 4);
2334 end;
2335 WEAPON_CACO_FIRE:
2336 begin
2337 g_Frames_Get(dw, 'FRAMES_WEAPON_CACOFIRE');
2338 Shots[i].Animation := TAnimation.Create(dw, True, 4);
2339 end;
2340 WEAPON_BARON_FIRE:
2341 begin
2342 g_Frames_Get(dw, 'FRAMES_WEAPON_BARONFIRE');
2343 Shots[i].Animation := TAnimation.Create(dw, True, 4);
2344 end;
2345 WEAPON_MANCUB_FIRE:
2346 begin
2347 g_Frames_Get(dw, 'FRAMES_WEAPON_MANCUBFIRE');
2348 Shots[i].Animation := TAnimation.Create(dw, True, 4);
2349 end;
2350 end;
2351 end;
2352 end;
2354 procedure g_Weapon_DestroyShot(I: Integer; X, Y: Integer; Loud: Boolean = True);
2355 var
2356 cx, cy: Integer;
2357 Anim: TAnimation;
2358 s: string;
2359 begin
2360 if Shots = nil then
2361 Exit;
2362 if (I > High(Shots)) or (I < 0) then Exit;
2364 with Shots[I] do
2365 begin
2366 if ShotType = 0 then Exit;
2367 Obj.X := X;
2368 Obj.Y := Y;
2369 cx := Obj.X + (Obj.Rect.Width div 2);
2370 cy := Obj.Y + (Obj.Rect.Height div 2);
2372 case ShotType of
2373 WEAPON_ROCKETLAUNCHER, WEAPON_SKEL_FIRE: // Ðàêåòû è ñíàðÿäû Ñêåëåòà
2374 begin
2375 if Loud then
2376 begin
2377 if ShotType = WEAPON_SKEL_FIRE then
2378 begin // Âçðûâ ñíàðÿäà Ñêåëåòà
2379 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_SKELFIRE') then
2380 begin
2381 Anim := TAnimation.Create(TextureID, False, 8);
2382 Anim.Blending := False;
2383 g_GFX_OnceAnim((Obj.X+32)-32, (Obj.Y+8)-32, Anim);
2384 Anim.Free();
2385 end;
2386 end
2387 else
2388 begin // Âçðûâ Ðàêåòû
2389 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_ROCKET') then
2390 begin
2391 Anim := TAnimation.Create(TextureID, False, 6);
2392 Anim.Blending := False;
2393 g_GFX_OnceAnim(cx-64, cy-64, Anim);
2394 Anim.Free();
2395 end;
2396 end;
2397 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', Obj.X, Obj.Y);
2398 end;
2399 end;
2401 WEAPON_PLASMA, WEAPON_BSP_FIRE: // Ïëàçìà, ïëàçìà Àðàõíàòðîíà
2402 begin
2403 if ShotType = WEAPON_PLASMA then
2404 s := 'FRAMES_EXPLODE_PLASMA'
2405 else
2406 s := 'FRAMES_EXPLODE_BSPFIRE';
2408 if g_Frames_Get(TextureID, s) and loud then
2409 begin
2410 Anim := TAnimation.Create(TextureID, False, 3);
2411 Anim.Blending := False;
2412 g_GFX_OnceAnim(cx-16, cy-16, Anim);
2413 Anim.Free();
2415 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEPLASMA', Obj.X, Obj.Y);
2416 end;
2417 end;
2419 WEAPON_BFG: // BFG
2420 begin
2421 // Âçðûâ BFG:
2422 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_BFG') and Loud then
2423 begin
2424 Anim := TAnimation.Create(TextureID, False, 6);
2425 Anim.Blending := False;
2426 g_GFX_OnceAnim(cx-64, cy-64, Anim);
2427 Anim.Free();
2429 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', Obj.X, Obj.Y);
2430 end;
2431 end;
2433 WEAPON_IMP_FIRE, WEAPON_CACO_FIRE, WEAPON_BARON_FIRE: // Âûñòðåëû Áåñà, Êàêîäåìîíà Ðûöàðÿ/Áàðîíà àäà
2434 begin
2435 if ShotType = WEAPON_IMP_FIRE then
2436 s := 'FRAMES_EXPLODE_IMPFIRE'
2437 else
2438 if ShotType = WEAPON_CACO_FIRE then
2439 s := 'FRAMES_EXPLODE_CACOFIRE'
2440 else
2441 s := 'FRAMES_EXPLODE_BARONFIRE';
2443 if g_Frames_Get(TextureID, s) and Loud then
2444 begin
2445 Anim := TAnimation.Create(TextureID, False, 6);
2446 Anim.Blending := False;
2447 g_GFX_OnceAnim(cx-32, cy-32, Anim);
2448 Anim.Free();
2450 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj.X, Obj.Y);
2451 end;
2452 end;
2454 WEAPON_MANCUB_FIRE: // Âûñòðåë Ìàíêóáóñà
2455 begin
2456 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_ROCKET') and Loud then
2457 begin
2458 Anim := TAnimation.Create(TextureID, False, 6);
2459 Anim.Blending := False;
2460 g_GFX_OnceAnim(cx-64, cy-64, Anim);
2461 Anim.Free();
2463 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj.X, Obj.Y);
2464 end;
2465 end;
2466 end; // case ShotType of...
2468 ShotType := 0;
2469 Animation.Free();
2470 end;
2471 end;
2474 procedure g_Weapon_AddDynLights();
2475 var
2476 i: Integer;
2477 begin
2478 if Shots = nil then Exit;
2479 for i := 0 to High(Shots) do
2480 begin
2481 if Shots[i].ShotType = 0 then continue;
2482 if (Shots[i].ShotType = WEAPON_ROCKETLAUNCHER) or
2483 (Shots[i].ShotType = WEAPON_BARON_FIRE) or
2484 (Shots[i].ShotType = WEAPON_MANCUB_FIRE) or
2485 (Shots[i].ShotType = WEAPON_SKEL_FIRE) or
2486 (Shots[i].ShotType = WEAPON_IMP_FIRE) or
2487 (Shots[i].ShotType = WEAPON_CACO_FIRE) or
2488 (Shots[i].ShotType = WEAPON_MANCUB_FIRE) or
2489 (Shots[i].ShotType = WEAPON_BSP_FIRE) or
2490 (Shots[i].ShotType = WEAPON_PLASMA) or
2491 (Shots[i].ShotType = WEAPON_BFG) or
2492 (Shots[i].ShotType = WEAPON_FLAMETHROWER) or
2493 false then
2494 begin
2495 if (Shots[i].ShotType = WEAPON_PLASMA) then
2496 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)
2497 else if (Shots[i].ShotType = WEAPON_BFG) then
2498 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)
2499 else if (Shots[i].ShotType = WEAPON_FLAMETHROWER) then
2500 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)
2501 else
2502 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);
2503 end;
2504 end;
2505 end;
2508 procedure TShot.positionChanged (); begin end;
2511 end.