DEADSOFTWARE

some tree code for monsters
[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.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 function monsCheck (monidx: Integer; mon: TMonster): Boolean;
409 begin
410 result := false; // don't stop
411 if HitMonster(mon, dmg, vx*10, vy*10-3, SpawnerUID, HIT_SOME) then
412 begin
413 if AllowPush then mon.Push(vx, vy);
414 result := true;
415 end;
416 end;
418 var
419 i, h: Integer;
420 begin
421 Result := 0;
423 h := High(gPlayers);
425 if h <> -1 then
426 for i := 0 to h do
427 if (gPlayers[i] <> nil) and gPlayers[i].Live and gPlayers[i].Collide(X, Y) then
428 if HitPlayer(gPlayers[i], dmg, vx*10, vy*10-3, SpawnerUID, HIT_SOME) then
429 begin
430 if AllowPush then gPlayers[i].Push(vx, vy);
431 Result := 1;
432 end;
434 if Result <> 0 then Exit;
436 //if g_Mons_ForEach(monsCheck) then result := 2;
437 if g_Mons_ForEachAtAlive(X, Y, 1, 1, monsCheck) then result := 2;
438 end;
440 procedure g_Weapon_BFG9000(X, Y: Integer; SpawnerUID: Word);
442 function monsCheck (monidx: Integer; mon: TMonster): Boolean;
443 begin
444 result := false; // don't stop
445 if (mon <> nil) and (mon.Live) and (mon.UID <> SpawnerUID) then
446 begin
447 with mon do
448 begin
449 if (g_PatchLength(X, Y, Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2),
450 Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)) <= SHOT_BFG_RADIUS) and
451 g_TraceVector(X, Y, Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2),
452 Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)) then
453 begin
454 if HitMonster(mon, 50, 0, 0, SpawnerUID, HIT_SOME) then mon.BFGHit();
455 end;
456 end;
457 end;
458 end;
460 var
461 i, h: Integer;
462 st: Byte;
463 pl: TPlayer;
464 b: Boolean;
465 begin
466 //g_Sound_PlayEx('SOUND_WEAPON_EXPLODEBFG', 255);
468 h := High(gCorpses);
470 if gAdvCorpses and (h <> -1) then
471 for i := 0 to h do
472 if (gCorpses[i] <> nil) and (gCorpses[i].State <> CORPSE_STATE_REMOVEME) then
473 with gCorpses[i] do
474 if (g_PatchLength(X, Y, Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2),
475 Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)) <= SHOT_BFG_RADIUS) and
476 g_TraceVector(X, Y, Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2),
477 Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)) then
478 begin
479 Damage(50, 0, 0);
480 g_Weapon_BFGHit(Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2),
481 Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2));
482 end;
484 st := TEAM_NONE;
485 pl := g_Player_Get(SpawnerUID);
486 if pl <> nil then
487 st := pl.Team;
489 h := High(gPlayers);
491 if h <> -1 then
492 for i := 0 to h do
493 if (gPlayers[i] <> nil) and (gPlayers[i].Live) and (gPlayers[i].UID <> SpawnerUID) then
494 with gPlayers[i] do
495 if (g_PatchLength(X, Y, GameX+PLAYER_RECT.X+(PLAYER_RECT.Width div 2),
496 GameY+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)) <= SHOT_BFG_RADIUS) and
497 g_TraceVector(X, Y, GameX+PLAYER_RECT.X+(PLAYER_RECT.Width div 2),
498 GameY+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)) then
499 begin
500 if (st = TEAM_NONE) or (st <> gPlayers[i].Team) then
501 b := HitPlayer(gPlayers[i], 50, 0, 0, SpawnerUID, HIT_SOME)
502 else
503 b := HitPlayer(gPlayers[i], 25, 0, 0, SpawnerUID, HIT_SOME);
504 if b then
505 gPlayers[i].BFGHit();
506 end;
508 g_Mons_ForEach(monsCheck);
509 end;
511 function g_Weapon_CreateShot(I: Integer; ShotType: Byte; Spawner, TargetUID: Word; X, Y, XV, YV: Integer): LongWord;
512 var
513 find_id, FramesID: DWORD;
514 begin
515 if I < 0 then
516 find_id := FindShot()
517 else
518 begin
519 find_id := I;
520 if Integer(find_id) >= High(Shots) then
521 SetLength(Shots, find_id + 64)
522 end;
524 case ShotType of
525 WEAPON_ROCKETLAUNCHER:
526 begin
527 with Shots[find_id] do
528 begin
529 g_Obj_Init(@Obj);
531 Obj.Rect.Width := SHOT_ROCKETLAUNCHER_WIDTH;
532 Obj.Rect.Height := SHOT_ROCKETLAUNCHER_HEIGHT;
534 Animation := nil;
535 Triggers := nil;
536 ShotType := WEAPON_ROCKETLAUNCHER;
537 g_Texture_Get('TEXTURE_WEAPON_ROCKET', TextureID);
538 end;
539 end;
541 WEAPON_PLASMA:
542 begin
543 with Shots[find_id] do
544 begin
545 g_Obj_Init(@Obj);
547 Obj.Rect.Width := SHOT_PLASMA_WIDTH;
548 Obj.Rect.Height := SHOT_PLASMA_HEIGHT;
550 Triggers := nil;
551 ShotType := WEAPON_PLASMA;
552 g_Frames_Get(FramesID, 'FRAMES_WEAPON_PLASMA');
553 Animation := TAnimation.Create(FramesID, True, 5);
554 end;
555 end;
557 WEAPON_BFG:
558 begin
559 with Shots[find_id] do
560 begin
561 g_Obj_Init(@Obj);
563 Obj.Rect.Width := SHOT_BFG_WIDTH;
564 Obj.Rect.Height := SHOT_BFG_HEIGHT;
566 Triggers := nil;
567 ShotType := WEAPON_BFG;
568 g_Frames_Get(FramesID, 'FRAMES_WEAPON_BFG');
569 Animation := TAnimation.Create(FramesID, True, 6);
570 end;
571 end;
573 WEAPON_FLAMETHROWER:
574 begin
575 with Shots[find_id] do
576 begin
577 g_Obj_Init(@Obj);
579 Obj.Rect.Width := SHOT_FLAME_WIDTH;
580 Obj.Rect.Height := SHOT_FLAME_HEIGHT;
582 Triggers := nil;
583 ShotType := WEAPON_FLAMETHROWER;
584 Animation := nil;
585 TextureID := 0;
586 g_Frames_Get(TextureID, 'FRAMES_FLAME');
587 end;
588 end;
590 WEAPON_IMP_FIRE:
591 begin
592 with Shots[find_id] do
593 begin
594 g_Obj_Init(@Obj);
596 Obj.Rect.Width := 16;
597 Obj.Rect.Height := 16;
599 Triggers := nil;
600 ShotType := WEAPON_IMP_FIRE;
601 g_Frames_Get(FramesID, 'FRAMES_WEAPON_IMPFIRE');
602 Animation := TAnimation.Create(FramesID, True, 4);
603 end;
604 end;
606 WEAPON_CACO_FIRE:
607 begin
608 with Shots[find_id] do
609 begin
610 g_Obj_Init(@Obj);
612 Obj.Rect.Width := 16;
613 Obj.Rect.Height := 16;
615 Triggers := nil;
616 ShotType := WEAPON_CACO_FIRE;
617 g_Frames_Get(FramesID, 'FRAMES_WEAPON_CACOFIRE');
618 Animation := TAnimation.Create(FramesID, True, 4);
619 end;
620 end;
622 WEAPON_MANCUB_FIRE:
623 begin
624 with Shots[find_id] do
625 begin
626 g_Obj_Init(@Obj);
628 Obj.Rect.Width := 32;
629 Obj.Rect.Height := 32;
631 Triggers := nil;
632 ShotType := WEAPON_MANCUB_FIRE;
633 g_Frames_Get(FramesID, 'FRAMES_WEAPON_MANCUBFIRE');
634 Animation := TAnimation.Create(FramesID, True, 4);
635 end;
636 end;
638 WEAPON_BARON_FIRE:
639 begin
640 with Shots[find_id] do
641 begin
642 g_Obj_Init(@Obj);
644 Obj.Rect.Width := 32;
645 Obj.Rect.Height := 16;
647 Triggers := nil;
648 ShotType := WEAPON_BARON_FIRE;
649 g_Frames_Get(FramesID, 'FRAMES_WEAPON_BARONFIRE');
650 Animation := TAnimation.Create(FramesID, True, 4);
651 end;
652 end;
654 WEAPON_BSP_FIRE:
655 begin
656 with Shots[find_id] do
657 begin
658 g_Obj_Init(@Obj);
660 Obj.Rect.Width := 16;
661 Obj.Rect.Height := 16;
663 Triggers := nil;
664 ShotType := WEAPON_BSP_FIRE;
665 g_Frames_Get(FramesID, 'FRAMES_WEAPON_BSPFIRE');
666 Animation := TAnimation.Create(FramesID, True, 4);
667 end;
668 end;
670 WEAPON_SKEL_FIRE:
671 begin
672 with Shots[find_id] do
673 begin
674 g_Obj_Init(@Obj);
676 Obj.Rect.Width := SHOT_SKELFIRE_WIDTH;
677 Obj.Rect.Height := SHOT_SKELFIRE_HEIGHT;
679 Triggers := nil;
680 ShotType := WEAPON_SKEL_FIRE;
681 target := TargetUID;
682 g_Frames_Get(FramesID, 'FRAMES_WEAPON_SKELFIRE');
683 Animation := TAnimation.Create(FramesID, True, 5);
684 end;
685 end;
686 end;
688 Shots[find_id].Obj.X := X;
689 Shots[find_id].Obj.Y := Y;
690 Shots[find_id].Obj.Vel.X := XV;
691 Shots[find_id].Obj.Vel.Y := YV;
692 Shots[find_id].Obj.Accel.X := 0;
693 Shots[find_id].Obj.Accel.Y := 0;
694 Shots[find_id].SpawnerUID := Spawner;
695 if (ShotType = WEAPON_FLAMETHROWER) and (XV = 0) and (YV = 0) then
696 Shots[find_id].Stopped := 255
697 else
698 Shots[find_id].Stopped := 0;
699 Result := find_id;
700 end;
702 procedure throw(i, x, y, xd, yd, s: Integer);
703 var
704 a: Integer;
705 begin
706 yd := yd - y;
707 xd := xd - x;
709 a := Max(Abs(xd), Abs(yd));
710 if a = 0 then
711 a := 1;
713 Shots[i].Obj.X := x;
714 Shots[i].Obj.Y := y;
715 Shots[i].Obj.Vel.X := (xd*s) div a;
716 Shots[i].Obj.Vel.Y := (yd*s) div a;
717 Shots[i].Obj.Accel.X := 0;
718 Shots[i].Obj.Accel.Y := 0;
719 Shots[i].Stopped := 0;
720 if Shots[i].ShotType in [WEAPON_ROCKETLAUNCHER, WEAPON_BFG] then
721 Shots[i].Timeout := 900 // ~25 sec
722 else
723 begin
724 if Shots[i].ShotType = WEAPON_FLAMETHROWER then
725 Shots[i].Timeout := SHOT_FLAME_LIFETIME
726 else
727 Shots[i].Timeout := 550; // ~15 sec
728 end;
729 end;
731 function g_Weapon_Hit(obj: PObj; d: Integer; SpawnerUID: Word; t: Byte; HitCorpses: Boolean = True): Byte;
732 var
733 i, h: Integer;
735 function PlayerHit(Team: Byte = 0): Boolean;
736 var
737 i: Integer;
738 ChkTeam: Boolean;
739 p: TPlayer;
740 begin
741 Result := False;
742 h := High(gPlayers);
744 if h <> -1 then
745 for i := 0 to h do
746 if (gPlayers[i] <> nil) and gPlayers[i].Live and g_Obj_Collide(obj, @gPlayers[i].Obj) then
747 begin
748 ChkTeam := True;
749 if (Team > 0) and (g_GetUIDType(SpawnerUID) = UID_PLAYER) then
750 begin
751 p := g_Player_Get(SpawnerUID);
752 if p <> nil then
753 ChkTeam := (p.Team = gPlayers[i].Team) xor (Team = 2);
754 end;
755 if ChkTeam then
756 if HitPlayer(gPlayers[i], d, obj^.Vel.X, obj^.Vel.Y, SpawnerUID, t) then
757 begin
758 if t <> HIT_FLAME then
759 gPlayers[i].Push((obj^.Vel.X+obj^.Accel.X)*IfThen(t = HIT_BFG, 8, 1) div 4,
760 (obj^.Vel.Y+obj^.Accel.Y)*IfThen(t = HIT_BFG, 8, 1) div 4);
761 if t = HIT_BFG then
762 g_Game_DelayEvent(DE_BFGHIT, 1000, SpawnerUID);
763 Result := True;
764 break;
765 end;
766 end;
767 end;
769 function monsCheckHit (monidx: Integer; mon: TMonster): Boolean;
770 begin
771 result := false; // don't stop
772 if (mon <> nil) and mon.Live and g_Obj_Collide(obj, @mon.Obj) then
773 begin
774 if HitMonster(mon, d, obj^.Vel.X, obj^.Vel.Y, SpawnerUID, t) then
775 begin
776 if (t <> HIT_FLAME) then
777 begin
778 mon.Push((obj^.Vel.X+obj^.Accel.X)*IfThen(t = HIT_BFG, 8, 1) div 4,
779 (obj^.Vel.Y+obj^.Accel.Y)*IfThen(t = HIT_BFG, 8, 1) div 4);
780 end;
781 result := True;
782 end;
783 end;
784 end;
786 function MonsterHit(): Boolean;
787 begin
788 result := g_Mons_ForEach(monsCheckHit);
789 end;
791 begin
792 Result := 0;
794 if HitCorpses then
795 begin
796 h := High(gCorpses);
798 if gAdvCorpses and (h <> -1) then
799 for i := 0 to h do
800 if (gCorpses[i] <> nil) and (gCorpses[i].State <> CORPSE_STATE_REMOVEME) and
801 g_Obj_Collide(obj, @gCorpses[i].Obj) then
802 begin
803 // Ðàñïèëèâàåì òðóï:
804 gCorpses[i].Damage(d, (obj^.Vel.X+obj^.Accel.X) div 4,
805 (obj^.Vel.Y+obj^.Accel.Y) div 4);
806 Result := 1;
807 end;
808 end;
810 case gGameSettings.GameMode of
811 // Êàìïàíèÿ:
812 GM_COOP, GM_SINGLE:
813 begin
814 // Ñíà÷àëà áü¸ì ìîíñòðîâ, åñëè åñòü, ïîòîì ïûòàåìñÿ áèòü èãðîêîâ
815 if MonsterHit() then
816 begin
817 Result := 2;
818 Exit;
819 end;
821 if PlayerHit() then
822 begin
823 Result := 1;
824 Exit;
825 end;
826 end;
828 // Äåçìàò÷:
829 GM_DM:
830 begin
831 // Ñíà÷àëà áü¸ì èãðîêîâ, åñëè åñòü, ïîòîì ïûòàåìñÿ áèòü ìîíñòðîâ
832 if PlayerHit() then
833 begin
834 Result := 1;
835 Exit;
836 end;
838 if MonsterHit() then
839 begin
840 Result := 2;
841 Exit;
842 end;
843 end;
845 // Êîìàíäíûå:
846 GM_TDM, GM_CTF:
847 begin
848 // Ñíà÷àëà áü¸ì èãðîêîâ êîìàíäû ñîïåðíèêà
849 if PlayerHit(2) then
850 begin
851 Result := 1;
852 Exit;
853 end;
855 // Ïîòîì ìîíñòðîâ
856 if MonsterHit() then
857 begin
858 Result := 2;
859 Exit;
860 end;
862 // È â êîíöå ñâîèõ èãðîêîâ
863 if PlayerHit(1) then
864 begin
865 Result := 1;
866 Exit;
867 end;
868 end;
870 end;
871 end;
873 function g_Weapon_HitUID(UID: Word; d: Integer; SpawnerUID: Word; t: Byte): Boolean;
874 begin
875 Result := False;
877 case g_GetUIDType(UID) of
878 UID_PLAYER: Result := HitPlayer(g_Player_Get(UID), d, 0, 0, SpawnerUID, t);
879 UID_MONSTER: Result := HitMonster(g_Monsters_Get(UID), d, 0, 0, SpawnerUID, t);
880 else Exit;
881 end;
882 end;
884 function g_Weapon_Explode(X, Y: Integer; rad: Integer; SpawnerUID: Word): Boolean;
885 var
886 r: Integer;
888 function monsExCheck (monidx: Integer; mon: TMonster): Boolean;
889 var
890 dx, dy, mm: Integer;
891 begin
892 result := false; // don't stop
893 if mon <> nil then
894 begin
895 with mon do
896 begin
897 dx := Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2)-X;
898 dy := Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)-Y;
900 if dx > 1000 then dx := 1000;
901 if dy > 1000 then dy := 1000;
903 if (dx*dx+dy*dy < r) then
904 begin
905 //m := PointToRect(X, Y, Obj.X+Obj.Rect.X, Obj.Y+Obj.Rect.Y, Obj.Rect.Width, Obj.Rect.Height);
907 mm := Max(abs(dx), abs(dy));
908 if mm = 0 then mm := 1;
910 if mon.Live then
911 HitMonster(mon, ((mon.Obj.Rect.Width div 4)*10*(rad-mm)) div rad,
912 0, 0, SpawnerUID, HIT_ROCKET);
914 mon.Push((dx*7) div mm, (dy*7) div mm);
915 end;
916 end;
917 end;
918 end;
920 var
921 i, h, dx, dy, m, mm: Integer;
922 _angle: SmallInt;
924 begin
925 Result := False;
927 g_Triggers_PressC(X, Y, rad, SpawnerUID, ACTIVATE_SHOT);
929 r := rad*rad;
931 h := High(gPlayers);
933 if h <> -1 then
934 for i := 0 to h do
935 if (gPlayers[i] <> nil) and gPlayers[i].Live then
936 with gPlayers[i] do
937 begin
938 dx := Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2)-X;
939 dy := Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)-Y;
941 if dx > 1000 then dx := 1000;
942 if dy > 1000 then dy := 1000;
944 if dx*dx+dy*dy < r then
945 begin
946 //m := PointToRect(X, Y, GameX+PLAYER_RECT.X, GameY+PLAYER_RECT.Y,
947 // PLAYER_RECT.Width, PLAYER_RECT.Height);
949 mm := Max(abs(dx), abs(dy));
950 if mm = 0 then mm := 1;
952 HitPlayer(gPlayers[i], (100*(rad-mm)) div rad, (dx*10) div mm, (dy*10) div mm, SpawnerUID, HIT_ROCKET);
953 gPlayers[i].Push((dx*7) div mm, (dy*7) div mm);
954 end;
955 end;
957 g_Mons_ForEach(monsExCheck);
960 h := High(gCorpses);
962 if gAdvCorpses and (h <> -1) then
963 for i := 0 to h do
964 if (gCorpses[i] <> nil) and (gCorpses[i].State <> CORPSE_STATE_REMOVEME) then
965 with gCorpses[i] do
966 begin
967 dx := Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2)-X;
968 dy := Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)-Y;
970 if dx > 1000 then dx := 1000;
971 if dy > 1000 then dy := 1000;
973 if dx*dx+dy*dy < r then
974 begin
975 m := PointToRect(X, Y, Obj.X+Obj.Rect.X, Obj.Y+Obj.Rect.Y,
976 Obj.Rect.Width, Obj.Rect.Height);
978 mm := Max(abs(dx), abs(dy));
979 if mm = 0 then mm := 1;
981 Damage(Round(100*(rad-m)/rad), (dx*10) div mm, (dy*10) div mm);
982 end;
983 end;
985 h := High(gGibs);
987 if gAdvGibs and (h <> -1) then
988 for i := 0 to h do
989 if gGibs[i].Live then
990 with gGibs[i] do
991 begin
992 dx := Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2)-X;
993 dy := Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)-Y;
995 if dx > 1000 then dx := 1000;
996 if dy > 1000 then dy := 1000;
998 if dx*dx+dy*dy < r then
999 begin
1000 m := PointToRect(X, Y, Obj.X+Obj.Rect.X, Obj.Y+Obj.Rect.Y,
1001 Obj.Rect.Width, Obj.Rect.Height);
1002 _angle := GetAngle(Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2),
1003 Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2), X, Y);
1005 g_Obj_PushA(@Obj, Round(15*(rad-m)/rad), _angle);
1006 positionChanged(); // this updates spatial accelerators
1007 end;
1008 end;
1009 end;
1011 procedure g_Weapon_Init();
1012 begin
1013 CreateWaterMap();
1014 end;
1016 procedure g_Weapon_Free();
1017 var
1018 i: Integer;
1019 begin
1020 if Shots <> nil then
1021 begin
1022 for i := 0 to High(Shots) do
1023 if Shots[i].ShotType <> 0 then
1024 Shots[i].Animation.Free();
1026 Shots := nil;
1027 end;
1029 WaterMap := nil;
1030 end;
1032 procedure g_Weapon_LoadData();
1033 begin
1034 e_WriteLog('Loading weapons data...', MSG_NOTIFY);
1036 g_Sound_CreateWADEx('SOUND_WEAPON_HITPUNCH', GameWAD+':SOUNDS\HITPUNCH');
1037 g_Sound_CreateWADEx('SOUND_WEAPON_MISSPUNCH', GameWAD+':SOUNDS\MISSPUNCH');
1038 g_Sound_CreateWADEx('SOUND_WEAPON_HITBERSERK', GameWAD+':SOUNDS\HITBERSERK');
1039 g_Sound_CreateWADEx('SOUND_WEAPON_MISSBERSERK', GameWAD+':SOUNDS\MISSBERSERK');
1040 g_Sound_CreateWADEx('SOUND_WEAPON_SELECTSAW', GameWAD+':SOUNDS\SELECTSAW');
1041 g_Sound_CreateWADEx('SOUND_WEAPON_IDLESAW', GameWAD+':SOUNDS\IDLESAW');
1042 g_Sound_CreateWADEx('SOUND_WEAPON_HITSAW', GameWAD+':SOUNDS\HITSAW');
1043 g_Sound_CreateWADEx('SOUND_WEAPON_FIRESHOTGUN2', GameWAD+':SOUNDS\FIRESHOTGUN2');
1044 g_Sound_CreateWADEx('SOUND_WEAPON_FIRESHOTGUN', GameWAD+':SOUNDS\FIRESHOTGUN');
1045 g_Sound_CreateWADEx('SOUND_WEAPON_FIRESAW', GameWAD+':SOUNDS\FIRESAW');
1046 g_Sound_CreateWADEx('SOUND_WEAPON_FIREROCKET', GameWAD+':SOUNDS\FIREROCKET');
1047 g_Sound_CreateWADEx('SOUND_WEAPON_FIREPLASMA', GameWAD+':SOUNDS\FIREPLASMA');
1048 g_Sound_CreateWADEx('SOUND_WEAPON_FIREPISTOL', GameWAD+':SOUNDS\FIREPISTOL');
1049 g_Sound_CreateWADEx('SOUND_WEAPON_FIRECGUN', GameWAD+':SOUNDS\FIRECGUN');
1050 g_Sound_CreateWADEx('SOUND_WEAPON_FIREBFG', GameWAD+':SOUNDS\FIREBFG');
1051 g_Sound_CreateWADEx('SOUND_FIRE', GameWAD+':SOUNDS\FIRE');
1052 g_Sound_CreateWADEx('SOUND_WEAPON_STARTFIREBFG', GameWAD+':SOUNDS\STARTFIREBFG');
1053 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEROCKET', GameWAD+':SOUNDS\EXPLODEROCKET');
1054 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEBFG', GameWAD+':SOUNDS\EXPLODEBFG');
1055 g_Sound_CreateWADEx('SOUND_WEAPON_BFGWATER', GameWAD+':SOUNDS\BFGWATER');
1056 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEPLASMA', GameWAD+':SOUNDS\EXPLODEPLASMA');
1057 g_Sound_CreateWADEx('SOUND_WEAPON_PLASMAWATER', GameWAD+':SOUNDS\PLASMAWATER');
1058 g_Sound_CreateWADEx('SOUND_WEAPON_FIREBALL', GameWAD+':SOUNDS\FIREBALL');
1059 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEBALL', GameWAD+':SOUNDS\EXPLODEBALL');
1060 g_Sound_CreateWADEx('SOUND_WEAPON_FIREREV', GameWAD+':SOUNDS\FIREREV');
1061 g_Sound_CreateWADEx('SOUND_PLAYER_JETFLY', GameWAD+':SOUNDS\WORKJETPACK');
1062 g_Sound_CreateWADEx('SOUND_PLAYER_JETON', GameWAD+':SOUNDS\STARTJETPACK');
1063 g_Sound_CreateWADEx('SOUND_PLAYER_JETOFF', GameWAD+':SOUNDS\STOPJETPACK');
1064 g_Sound_CreateWADEx('SOUND_PLAYER_CASING1', GameWAD+':SOUNDS\CASING1');
1065 g_Sound_CreateWADEx('SOUND_PLAYER_CASING2', GameWAD+':SOUNDS\CASING2');
1066 g_Sound_CreateWADEx('SOUND_PLAYER_SHELL1', GameWAD+':SOUNDS\SHELL1');
1067 g_Sound_CreateWADEx('SOUND_PLAYER_SHELL2', GameWAD+':SOUNDS\SHELL2');
1069 g_Texture_CreateWADEx('TEXTURE_WEAPON_ROCKET', GameWAD+':TEXTURES\BROCKET');
1070 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_SKELFIRE', GameWAD+':TEXTURES\BSKELFIRE', 64, 16, 2);
1071 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_BFG', GameWAD+':TEXTURES\BBFG', 64, 64, 2);
1072 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_PLASMA', GameWAD+':TEXTURES\BPLASMA', 16, 16, 2);
1073 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_IMPFIRE', GameWAD+':TEXTURES\BIMPFIRE', 16, 16, 2);
1074 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_BSPFIRE', GameWAD+':TEXTURES\BBSPFIRE', 16, 16, 2);
1075 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_CACOFIRE', GameWAD+':TEXTURES\BCACOFIRE', 16, 16, 2);
1076 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_BARONFIRE', GameWAD+':TEXTURES\BBARONFIRE', 64, 16, 2);
1077 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_MANCUBFIRE', GameWAD+':TEXTURES\BMANCUBFIRE', 64, 32, 2);
1078 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_ROCKET', GameWAD+':TEXTURES\EROCKET', 128, 128, 6);
1079 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_SKELFIRE', GameWAD+':TEXTURES\ESKELFIRE', 64, 64, 3);
1080 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_BFG', GameWAD+':TEXTURES\EBFG', 128, 128, 6);
1081 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_IMPFIRE', GameWAD+':TEXTURES\EIMPFIRE', 64, 64, 3);
1082 g_Frames_CreateWAD(nil, 'FRAMES_BFGHIT', GameWAD+':TEXTURES\BFGHIT', 64, 64, 4);
1083 g_Frames_CreateWAD(nil, 'FRAMES_FIRE', GameWAD+':TEXTURES\FIRE', 64, 128, 8);
1084 g_Frames_CreateWAD(nil, 'FRAMES_FLAME', GameWAD+':TEXTURES\FLAME', 32, 32, 11);
1085 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_PLASMA', GameWAD+':TEXTURES\EPLASMA', 32, 32, 4, True);
1086 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_BSPFIRE', GameWAD+':TEXTURES\EBSPFIRE', 32, 32, 5);
1087 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_CACOFIRE', GameWAD+':TEXTURES\ECACOFIRE', 64, 64, 3);
1088 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_BARONFIRE', GameWAD+':TEXTURES\EBARONFIRE', 64, 64, 3);
1089 g_Frames_CreateWAD(nil, 'FRAMES_SMOKE', GameWAD+':TEXTURES\SMOKE', 32, 32, 10, False);
1091 g_Texture_CreateWADEx('TEXTURE_SHELL_BULLET', GameWAD+':TEXTURES\EBULLET');
1092 g_Texture_CreateWADEx('TEXTURE_SHELL_SHELL', GameWAD+':TEXTURES\ESHELL');
1093 end;
1095 procedure g_Weapon_FreeData();
1096 begin
1097 e_WriteLog('Releasing weapons data...', MSG_NOTIFY);
1099 g_Sound_Delete('SOUND_WEAPON_HITPUNCH');
1100 g_Sound_Delete('SOUND_WEAPON_MISSPUNCH');
1101 g_Sound_Delete('SOUND_WEAPON_HITBERSERK');
1102 g_Sound_Delete('SOUND_WEAPON_MISSBERSERK');
1103 g_Sound_Delete('SOUND_WEAPON_SELECTSAW');
1104 g_Sound_Delete('SOUND_WEAPON_IDLESAW');
1105 g_Sound_Delete('SOUND_WEAPON_HITSAW');
1106 g_Sound_Delete('SOUND_WEAPON_FIRESHOTGUN2');
1107 g_Sound_Delete('SOUND_WEAPON_FIRESHOTGUN');
1108 g_Sound_Delete('SOUND_WEAPON_FIRESAW');
1109 g_Sound_Delete('SOUND_WEAPON_FIREROCKET');
1110 g_Sound_Delete('SOUND_WEAPON_FIREPLASMA');
1111 g_Sound_Delete('SOUND_WEAPON_FIREPISTOL');
1112 g_Sound_Delete('SOUND_WEAPON_FIRECGUN');
1113 g_Sound_Delete('SOUND_WEAPON_FIREBFG');
1114 g_Sound_Delete('SOUND_FIRE');
1115 g_Sound_Delete('SOUND_WEAPON_STARTFIREBFG');
1116 g_Sound_Delete('SOUND_WEAPON_EXPLODEROCKET');
1117 g_Sound_Delete('SOUND_WEAPON_EXPLODEBFG');
1118 g_Sound_Delete('SOUND_WEAPON_BFGWATER');
1119 g_Sound_Delete('SOUND_WEAPON_EXPLODEPLASMA');
1120 g_Sound_Delete('SOUND_WEAPON_PLASMAWATER');
1121 g_Sound_Delete('SOUND_WEAPON_FIREBALL');
1122 g_Sound_Delete('SOUND_WEAPON_EXPLODEBALL');
1123 g_Sound_Delete('SOUND_WEAPON_FIREREV');
1124 g_Sound_Delete('SOUND_PLAYER_JETFLY');
1125 g_Sound_Delete('SOUND_PLAYER_JETON');
1126 g_Sound_Delete('SOUND_PLAYER_JETOFF');
1127 g_Sound_Delete('SOUND_PLAYER_CASING1');
1128 g_Sound_Delete('SOUND_PLAYER_CASING2');
1129 g_Sound_Delete('SOUND_PLAYER_SHELL1');
1130 g_Sound_Delete('SOUND_PLAYER_SHELL2');
1132 g_Texture_Delete('TEXTURE_WEAPON_ROCKET');
1133 g_Frames_DeleteByName('FRAMES_WEAPON_BFG');
1134 g_Frames_DeleteByName('FRAMES_WEAPON_PLASMA');
1135 g_Frames_DeleteByName('FRAMES_WEAPON_IMPFIRE');
1136 g_Frames_DeleteByName('FRAMES_WEAPON_BSPFIRE');
1137 g_Frames_DeleteByName('FRAMES_WEAPON_CACOFIRE');
1138 g_Frames_DeleteByName('FRAMES_WEAPON_MANCUBFIRE');
1139 g_Frames_DeleteByName('FRAMES_EXPLODE_ROCKET');
1140 g_Frames_DeleteByName('FRAMES_EXPLODE_BFG');
1141 g_Frames_DeleteByName('FRAMES_EXPLODE_IMPFIRE');
1142 g_Frames_DeleteByName('FRAMES_BFGHIT');
1143 g_Frames_DeleteByName('FRAMES_FIRE');
1144 g_Frames_DeleteByName('FRAMES_EXPLODE_PLASMA');
1145 g_Frames_DeleteByName('FRAMES_EXPLODE_BSPFIRE');
1146 g_Frames_DeleteByName('FRAMES_EXPLODE_CACOFIRE');
1147 g_Frames_DeleteByName('FRAMES_SMOKE');
1148 g_Frames_DeleteByName('FRAMES_WEAPON_BARONFIRE');
1149 g_Frames_DeleteByName('FRAMES_EXPLODE_BARONFIRE');
1150 end;
1152 procedure g_Weapon_gun(x, y, xd, yd, v, dmg: Integer; SpawnerUID: Word; CheckTrigger: Boolean);
1153 var
1154 a: Integer;
1155 x2, y2: Integer;
1156 dx, dy: Integer;
1157 xe, ye: Integer;
1158 xi, yi: Integer;
1159 s, c: Extended;
1160 //vx, vy: Integer;
1161 xx, yy, d: Integer;
1163 i: Integer;
1164 t1, _collide: Boolean;
1165 w, h: Word;
1166 begin
1167 a := GetAngle(x, y, xd, yd)+180;
1169 SinCos(DegToRad(-a), s, c);
1171 if Abs(s) < 0.01 then s := 0;
1172 if Abs(c) < 0.01 then c := 0;
1174 x2 := x+Round(c*gMapInfo.Width);
1175 y2 := y+Round(s*gMapInfo.Width);
1177 t1 := gWalls <> nil;
1178 _collide := False;
1179 w := gMapInfo.Width;
1180 h := gMapInfo.Height;
1182 xe := 0;
1183 ye := 0;
1184 dx := x2-x;
1185 dy := y2-y;
1187 if (xd = 0) and (yd = 0) then Exit;
1189 if dx > 0 then xi := 1 else if dx < 0 then xi := -1 else xi := 0;
1190 if dy > 0 then yi := 1 else if dy < 0 then yi := -1 else yi := 0;
1192 dx := Abs(dx);
1193 dy := Abs(dy);
1195 if dx > dy then d := dx else d := dy;
1197 //blood vel, for Monster.Damage()
1198 //vx := (dx*10 div d)*xi;
1199 //vy := (dy*10 div d)*yi;
1201 xx := x;
1202 yy := y;
1204 for i := 1 to d do
1205 begin
1206 xe := xe+dx;
1207 ye := ye+dy;
1209 if xe > d then
1210 begin
1211 xe := xe-d;
1212 xx := xx+xi;
1213 end;
1215 if ye > d then
1216 begin
1217 ye := ye-d;
1218 yy := yy+yi;
1219 end;
1221 if (yy > h) or (yy < 0) then Break;
1222 if (xx > w) or (xx < 0) then Break;
1224 if t1 then
1225 if ByteBool(gCollideMap[yy, xx] and MARK_BLOCKED) then
1226 begin
1227 _collide := True;
1228 g_GFX_Spark(xx-xi, yy-yi, 2+Random(2), 180+a, 0, 0);
1229 if g_Game_IsServer and g_Game_IsNet then
1230 MH_SEND_Effect(xx-xi, yy-yi, 180+a, NET_GFX_SPARK);
1231 end;
1233 if not _collide then
1234 _collide := GunHit(xx, yy, xi*v, yi*v, dmg, SpawnerUID, v <> 0) <> 0;
1236 if _collide then
1237 Break;
1238 end;
1240 if CheckTrigger and g_Game_IsServer then
1241 g_Triggers_PressL(X, Y, xx-xi, yy-yi, SpawnerUID, ACTIVATE_SHOT);
1242 end;
1244 procedure g_Weapon_punch(x, y: Integer; d, SpawnerUID: Word);
1245 var
1246 obj: TObj;
1247 begin
1248 obj.X := X;
1249 obj.Y := Y;
1250 obj.rect.X := 0;
1251 obj.rect.Y := 0;
1252 obj.rect.Width := 39;
1253 obj.rect.Height := 52;
1254 obj.Vel.X := 0;
1255 obj.Vel.Y := 0;
1256 obj.Accel.X := 0;
1257 obj.Accel.Y := 0;
1259 if g_Weapon_Hit(@obj, d, SpawnerUID, HIT_SOME) <> 0 then
1260 g_Sound_PlayExAt('SOUND_WEAPON_HITPUNCH', x, y)
1261 else
1262 g_Sound_PlayExAt('SOUND_WEAPON_MISSPUNCH', x, y);
1263 end;
1265 function g_Weapon_chainsaw(x, y: Integer; d, SpawnerUID: Word): Integer;
1266 var
1267 obj: TObj;
1268 begin
1269 obj.X := X;
1270 obj.Y := Y;
1271 obj.rect.X := 0;
1272 obj.rect.Y := 0;
1273 obj.rect.Width := 32;
1274 obj.rect.Height := 52;
1275 obj.Vel.X := 0;
1276 obj.Vel.Y := 0;
1277 obj.Accel.X := 0;
1278 obj.Accel.Y := 0;
1280 Result := g_Weapon_Hit(@obj, d, SpawnerUID, HIT_SOME);
1281 end;
1283 procedure g_Weapon_rocket(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1284 Silent: Boolean = False);
1285 var
1286 find_id: DWORD;
1287 dx, dy: Integer;
1288 begin
1289 if WID < 0 then
1290 find_id := FindShot()
1291 else
1292 begin
1293 find_id := WID;
1294 if Integer(find_id) >= High(Shots) then
1295 SetLength(Shots, find_id + 64)
1296 end;
1298 with Shots[find_id] do
1299 begin
1300 g_Obj_Init(@Obj);
1302 Obj.Rect.Width := SHOT_ROCKETLAUNCHER_WIDTH;
1303 Obj.Rect.Height := SHOT_ROCKETLAUNCHER_HEIGHT;
1305 dx := IfThen(xd > x, -Obj.Rect.Width, 0);
1306 dy := -(Obj.Rect.Height div 2);
1308 ShotType := WEAPON_ROCKETLAUNCHER;
1309 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 12);
1311 Animation := nil;
1312 triggers := nil;
1313 g_Texture_Get('TEXTURE_WEAPON_ROCKET', TextureID);
1314 end;
1316 Shots[find_id].SpawnerUID := SpawnerUID;
1318 if not Silent then
1319 g_Sound_PlayExAt('SOUND_WEAPON_FIREROCKET', x, y);
1320 end;
1322 procedure g_Weapon_revf(x, y, xd, yd: Integer; SpawnerUID, TargetUID: Word;
1323 WID: Integer = -1; Silent: Boolean = False);
1324 var
1325 find_id, FramesID: DWORD;
1326 dx, dy: Integer;
1327 begin
1328 if WID < 0 then
1329 find_id := FindShot()
1330 else
1331 begin
1332 find_id := WID;
1333 if Integer(find_id) >= High(Shots) then
1334 SetLength(Shots, find_id + 64)
1335 end;
1337 with Shots[find_id] do
1338 begin
1339 g_Obj_Init(@Obj);
1341 Obj.Rect.Width := SHOT_SKELFIRE_WIDTH;
1342 Obj.Rect.Height := SHOT_SKELFIRE_HEIGHT;
1344 dx := -(Obj.Rect.Width div 2);
1345 dy := -(Obj.Rect.Height div 2);
1347 ShotType := WEAPON_SKEL_FIRE;
1348 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 12);
1350 triggers := nil;
1351 target := TargetUID;
1352 g_Frames_Get(FramesID, 'FRAMES_WEAPON_SKELFIRE');
1353 Animation := TAnimation.Create(FramesID, True, 5);
1354 end;
1356 Shots[find_id].SpawnerUID := SpawnerUID;
1358 if not Silent then
1359 g_Sound_PlayExAt('SOUND_WEAPON_FIREREV', x, y);
1360 end;
1362 procedure g_Weapon_plasma(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1363 Silent: Boolean = False);
1364 var
1365 find_id, FramesID: DWORD;
1366 dx, dy: Integer;
1367 begin
1368 if WID < 0 then
1369 find_id := FindShot()
1370 else
1371 begin
1372 find_id := WID;
1373 if Integer(find_id) >= High(Shots) then
1374 SetLength(Shots, find_id + 64);
1375 end;
1377 with Shots[find_id] do
1378 begin
1379 g_Obj_Init(@Obj);
1381 Obj.Rect.Width := SHOT_PLASMA_WIDTH;
1382 Obj.Rect.Height := SHOT_PLASMA_HEIGHT;
1384 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1385 dy := -(Obj.Rect.Height div 2);
1387 ShotType := WEAPON_PLASMA;
1388 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1390 triggers := nil;
1391 g_Frames_Get(FramesID, 'FRAMES_WEAPON_PLASMA');
1392 Animation := TAnimation.Create(FramesID, True, 5);
1393 end;
1395 Shots[find_id].SpawnerUID := SpawnerUID;
1397 if not Silent then
1398 g_Sound_PlayExAt('SOUND_WEAPON_FIREPLASMA', x, y);
1399 end;
1401 procedure g_Weapon_flame(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1402 Silent: Boolean = False);
1403 var
1404 find_id: DWORD;
1405 dx, dy: Integer;
1406 begin
1407 if WID < 0 then
1408 find_id := FindShot()
1409 else
1410 begin
1411 find_id := WID;
1412 if Integer(find_id) >= High(Shots) then
1413 SetLength(Shots, find_id + 64);
1414 end;
1416 with Shots[find_id] do
1417 begin
1418 g_Obj_Init(@Obj);
1420 Obj.Rect.Width := SHOT_FLAME_WIDTH;
1421 Obj.Rect.Height := SHOT_FLAME_HEIGHT;
1423 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1424 dy := -(Obj.Rect.Height div 2);
1426 ShotType := WEAPON_FLAMETHROWER;
1427 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1429 triggers := nil;
1430 Animation := nil;
1431 TextureID := 0;
1432 g_Frames_Get(TextureID, 'FRAMES_FLAME');
1433 end;
1435 Shots[find_id].SpawnerUID := SpawnerUID;
1437 // if not Silent then
1438 // g_Sound_PlayExAt('SOUND_WEAPON_FIREPLASMA', x, y);
1439 end;
1441 procedure g_Weapon_ball1(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1442 Silent: Boolean = False);
1443 var
1444 find_id, FramesID: DWORD;
1445 dx, dy: Integer;
1446 begin
1447 if WID < 0 then
1448 find_id := FindShot()
1449 else
1450 begin
1451 find_id := WID;
1452 if Integer(find_id) >= High(Shots) then
1453 SetLength(Shots, find_id + 64)
1454 end;
1456 with Shots[find_id] do
1457 begin
1458 g_Obj_Init(@Obj);
1460 Obj.Rect.Width := 16;
1461 Obj.Rect.Height := 16;
1463 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1464 dy := -(Obj.Rect.Height div 2);
1466 ShotType := WEAPON_IMP_FIRE;
1467 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1469 triggers := nil;
1470 g_Frames_Get(FramesID, 'FRAMES_WEAPON_IMPFIRE');
1471 Animation := TAnimation.Create(FramesID, True, 4);
1472 end;
1474 Shots[find_id].SpawnerUID := SpawnerUID;
1476 if not Silent then
1477 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x, y);
1478 end;
1480 procedure g_Weapon_ball2(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1481 Silent: Boolean = False);
1482 var
1483 find_id, FramesID: DWORD;
1484 dx, dy: Integer;
1485 begin
1486 if WID < 0 then
1487 find_id := FindShot()
1488 else
1489 begin
1490 find_id := WID;
1491 if Integer(find_id) >= High(Shots) then
1492 SetLength(Shots, find_id + 64)
1493 end;
1495 with Shots[find_id] do
1496 begin
1497 g_Obj_Init(@Obj);
1499 Obj.Rect.Width := 16;
1500 Obj.Rect.Height := 16;
1502 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1503 dy := -(Obj.Rect.Height div 2);
1505 ShotType := WEAPON_CACO_FIRE;
1506 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1508 triggers := nil;
1509 g_Frames_Get(FramesID, 'FRAMES_WEAPON_CACOFIRE');
1510 Animation := TAnimation.Create(FramesID, True, 4);
1511 end;
1513 Shots[find_id].SpawnerUID := SpawnerUID;
1515 if not Silent then
1516 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x, y);
1517 end;
1519 procedure g_Weapon_ball7(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1520 Silent: Boolean = False);
1521 var
1522 find_id, FramesID: DWORD;
1523 dx, dy: Integer;
1524 begin
1525 if WID < 0 then
1526 find_id := FindShot()
1527 else
1528 begin
1529 find_id := WID;
1530 if Integer(find_id) >= High(Shots) then
1531 SetLength(Shots, find_id + 64)
1532 end;
1534 with Shots[find_id] do
1535 begin
1536 g_Obj_Init(@Obj);
1538 Obj.Rect.Width := 32;
1539 Obj.Rect.Height := 16;
1541 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1542 dy := -(Obj.Rect.Height div 2);
1544 ShotType := WEAPON_BARON_FIRE;
1545 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1547 triggers := nil;
1548 g_Frames_Get(FramesID, 'FRAMES_WEAPON_BARONFIRE');
1549 Animation := TAnimation.Create(FramesID, True, 4);
1550 end;
1552 Shots[find_id].SpawnerUID := SpawnerUID;
1554 if not Silent then
1555 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x, y);
1556 end;
1558 procedure g_Weapon_aplasma(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1559 Silent: Boolean = False);
1560 var
1561 find_id, FramesID: DWORD;
1562 dx, dy: Integer;
1563 begin
1564 if WID < 0 then
1565 find_id := FindShot()
1566 else
1567 begin
1568 find_id := WID;
1569 if Integer(find_id) >= High(Shots) then
1570 SetLength(Shots, find_id + 64)
1571 end;
1573 with Shots[find_id] do
1574 begin
1575 g_Obj_Init(@Obj);
1577 Obj.Rect.Width := 16;
1578 Obj.Rect.Height := 16;
1580 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1581 dy := -(Obj.Rect.Height div 2);
1583 ShotType := WEAPON_BSP_FIRE;
1584 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1586 triggers := nil;
1588 g_Frames_Get(FramesID, 'FRAMES_WEAPON_BSPFIRE');
1589 Animation := TAnimation.Create(FramesID, True, 4);
1590 end;
1592 Shots[find_id].SpawnerUID := SpawnerUID;
1594 if not Silent then
1595 g_Sound_PlayExAt('SOUND_WEAPON_FIREPLASMA', x, y);
1596 end;
1598 procedure g_Weapon_manfire(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1599 Silent: Boolean = False);
1600 var
1601 find_id, FramesID: DWORD;
1602 dx, dy: Integer;
1603 begin
1604 if WID < 0 then
1605 find_id := FindShot()
1606 else
1607 begin
1608 find_id := WID;
1609 if Integer(find_id) >= High(Shots) then
1610 SetLength(Shots, find_id + 64)
1611 end;
1613 with Shots[find_id] do
1614 begin
1615 g_Obj_Init(@Obj);
1617 Obj.Rect.Width := 32;
1618 Obj.Rect.Height := 32;
1620 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1621 dy := -(Obj.Rect.Height div 2);
1623 ShotType := WEAPON_MANCUB_FIRE;
1624 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1626 triggers := nil;
1628 g_Frames_Get(FramesID, 'FRAMES_WEAPON_MANCUBFIRE');
1629 Animation := TAnimation.Create(FramesID, True, 4);
1630 end;
1632 Shots[find_id].SpawnerUID := SpawnerUID;
1634 if not Silent then
1635 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x, y);
1636 end;
1638 procedure g_Weapon_bfgshot(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1639 Silent: Boolean = False);
1640 var
1641 find_id, FramesID: DWORD;
1642 dx, dy: Integer;
1643 begin
1644 if WID < 0 then
1645 find_id := FindShot()
1646 else
1647 begin
1648 find_id := WID;
1649 if Integer(find_id) >= High(Shots) then
1650 SetLength(Shots, find_id + 64)
1651 end;
1653 with Shots[find_id] do
1654 begin
1655 g_Obj_Init(@Obj);
1657 Obj.Rect.Width := SHOT_BFG_WIDTH;
1658 Obj.Rect.Height := SHOT_BFG_HEIGHT;
1660 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1661 dy := -(Obj.Rect.Height div 2);
1663 ShotType := WEAPON_BFG;
1664 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1666 triggers := nil;
1667 g_Frames_Get(FramesID, 'FRAMES_WEAPON_BFG');
1668 Animation := TAnimation.Create(FramesID, True, 6);
1669 end;
1671 Shots[find_id].SpawnerUID := SpawnerUID;
1673 if not Silent then
1674 g_Sound_PlayExAt('SOUND_WEAPON_FIREBFG', x, y);
1675 end;
1677 procedure g_Weapon_bfghit(x, y: Integer);
1678 var
1679 ID: DWORD;
1680 Anim: TAnimation;
1681 begin
1682 if g_Frames_Get(ID, 'FRAMES_BFGHIT') then
1683 begin
1684 Anim := TAnimation.Create(ID, False, 4);
1685 g_GFX_OnceAnim(x-32, y-32, Anim);
1686 Anim.Free();
1687 end;
1688 end;
1690 procedure g_Weapon_pistol(x, y, xd, yd: Integer; SpawnerUID: Word;
1691 Silent: Boolean = False);
1692 begin
1693 if not Silent then
1694 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', x, y);
1696 g_Weapon_gun(x, y, xd, yd, 1, 3, SpawnerUID, True);
1697 if gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF] then
1698 begin
1699 g_Weapon_gun(x, y+1, xd, yd+1, 1, 3, SpawnerUID, False);
1700 g_Weapon_gun(x, y-1, xd, yd-1, 1, 2, SpawnerUID, False);
1701 end;
1702 end;
1704 procedure g_Weapon_mgun(x, y, xd, yd: Integer; SpawnerUID: Word;
1705 Silent: Boolean = False);
1706 begin
1707 if not Silent then
1708 if gSoundEffectsDF then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', x, y);
1710 g_Weapon_gun(x, y, xd, yd, 1, 3, SpawnerUID, True);
1711 if (gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF]) and
1712 (g_GetUIDType(SpawnerUID) = UID_PLAYER) then
1713 begin
1714 g_Weapon_gun(x, y+1, xd, yd+1, 1, 2, SpawnerUID, False);
1715 g_Weapon_gun(x, y-1, xd, yd-1, 1, 2, SpawnerUID, False);
1716 end;
1717 end;
1719 procedure g_Weapon_shotgun(x, y, xd, yd: Integer; SpawnerUID: Word;
1720 Silent: Boolean = False);
1721 var
1722 i, j: Integer;
1723 begin
1724 if not Silent then
1725 if gSoundEffectsDF then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', x, y);
1727 for i := 0 to 9 do
1728 begin
1729 j := Random(17)-8; // -8 .. 8
1730 g_Weapon_gun(x, y+j, xd, yd+j, IfThen(i mod 2 <> 0, 1, 0), 3, SpawnerUID, i=0);
1731 end;
1732 end;
1734 procedure g_Weapon_dshotgun(x, y, xd, yd: Integer; SpawnerUID: Word;
1735 Silent: Boolean = False);
1736 var
1737 a, i, j: Integer;
1738 begin
1739 if not Silent then
1740 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', x, y);
1742 if gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF] then a := 25 else a := 20;
1743 for i := 0 to a do
1744 begin
1745 j := Random(41)-20; // -20 .. 20
1746 g_Weapon_gun(x, y+j, xd, yd+j, IfThen(i mod 3 <> 0, 0, 1), 3, SpawnerUID, i=0);
1747 end;
1748 end;
1750 procedure g_Weapon_Update();
1751 var
1752 i, a, h, cx, cy, oldvx, oldvy, tf: Integer;
1753 _id: DWORD;
1754 Anim: TAnimation;
1755 t: DWArray;
1756 st: Word;
1757 s: String;
1758 o: TObj;
1759 spl: Boolean;
1760 Loud: Boolean;
1761 tcx, tcy: Integer;
1762 begin
1763 if Shots = nil then
1764 Exit;
1766 for i := 0 to High(Shots) do
1767 begin
1768 if Shots[i].ShotType = 0 then
1769 Continue;
1771 Loud := True;
1773 with Shots[i] do
1774 begin
1775 Timeout := Timeout - 1;
1776 oldvx := Obj.Vel.X;
1777 oldvy := Obj.Vel.Y;
1778 // Àêòèâèðîâàòü òðèããåðû ïî ïóòè (êðîìå óæå àêòèâèðîâàííûõ):
1779 if (Stopped = 0) and g_Game_IsServer then
1780 t := g_Triggers_PressR(Obj.X, Obj.Y, Obj.Rect.Width, Obj.Rect.Height,
1781 SpawnerUID, ACTIVATE_SHOT, triggers)
1782 else
1783 t := nil;
1785 if t <> nil then
1786 begin
1787 // Ïîïîëíÿåì ñïèñîê àêòèâèðîâàííûõ òðèããåðîâ:
1788 if triggers = nil then
1789 triggers := t
1790 else
1791 begin
1792 h := High(t);
1794 for a := 0 to h do
1795 if not InDWArray(t[a], triggers) then
1796 begin
1797 SetLength(triggers, Length(triggers)+1);
1798 triggers[High(triggers)] := t[a];
1799 end;
1800 end;
1801 end;
1803 // Àíèìàöèÿ ñíàðÿäà:
1804 if Animation <> nil then
1805 Animation.Update();
1807 // Äâèæåíèå:
1808 spl := (ShotType <> WEAPON_PLASMA) and
1809 (ShotType <> WEAPON_BFG) and
1810 (ShotType <> WEAPON_BSP_FIRE) and
1811 (ShotType <> WEAPON_FLAMETHROWER);
1813 if Stopped = 0 then
1814 begin
1815 st := g_Obj_Move(@Obj, False, spl);
1816 end
1817 else
1818 begin
1819 st := 0;
1820 end;
1821 positionChanged(); // this updates spatial accelerators
1823 if WordBool(st and MOVE_FALLOUT) or (Obj.X < -1000) or
1824 (Obj.X > gMapInfo.Width+1000) or (Obj.Y < -1000) then
1825 begin
1826 // Íà êëèåíòå ñêîðåå âñåãî è òàê óæå âûïàë.
1827 ShotType := 0;
1828 Animation.Free();
1829 Continue;
1830 end;
1832 cx := Obj.X + (Obj.Rect.Width div 2);
1833 cy := Obj.Y + (Obj.Rect.Height div 2);
1835 case ShotType of
1836 WEAPON_ROCKETLAUNCHER, WEAPON_SKEL_FIRE: // Ðàêåòû è ñíàðÿäû Ñêåëåòà
1837 begin
1838 // Âûëåòåëà èç âîäû:
1839 if WordBool(st and MOVE_HITAIR) then
1840 g_Obj_SetSpeed(@Obj, 12);
1842 // Â âîäå øëåéô - ïóçûðè, â âîçäóõå øëåéô - äûì:
1843 if WordBool(st and MOVE_INWATER) then
1844 g_GFX_Bubbles(Obj.X+(Obj.Rect.Width div 2),
1845 Obj.Y+(Obj.Rect.Height div 2),
1846 1+Random(3), 16, 16)
1847 else
1848 if g_Frames_Get(_id, 'FRAMES_SMOKE') then
1849 begin
1850 Anim := TAnimation.Create(_id, False, 3);
1851 Anim.Alpha := 150;
1852 g_GFX_OnceAnim(Obj.X-14+Random(9),
1853 Obj.Y+(Obj.Rect.Height div 2)-20+Random(9),
1854 Anim, ONCEANIM_SMOKE);
1855 Anim.Free();
1856 end;
1858 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
1859 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL)) or
1860 (g_Weapon_Hit(@Obj, 10, SpawnerUID, HIT_SOME, False) <> 0) or
1861 (Timeout < 1) then
1862 begin
1863 Obj.Vel.X := 0;
1864 Obj.Vel.Y := 0;
1866 g_Weapon_Explode(cx, cy, 60, SpawnerUID);
1868 if ShotType = WEAPON_SKEL_FIRE then
1869 begin // Âçðûâ ñíàðÿäà Ñêåëåòà
1870 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_SKELFIRE') then
1871 begin
1872 Anim := TAnimation.Create(TextureID, False, 8);
1873 Anim.Blending := False;
1874 g_GFX_OnceAnim((Obj.X+32)-58, (Obj.Y+8)-36, Anim);
1875 g_DynLightExplosion((Obj.X+32), (Obj.Y+8), 64, 1, 0, 0);
1876 Anim.Free();
1877 end;
1878 end
1879 else
1880 begin // Âçðûâ Ðàêåòû
1881 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_ROCKET') then
1882 begin
1883 Anim := TAnimation.Create(TextureID, False, 6);
1884 Anim.Blending := False;
1885 g_GFX_OnceAnim(cx-64, cy-64, Anim);
1886 g_DynLightExplosion(cx, cy, 64, 1, 0, 0);
1887 Anim.Free();
1888 end;
1889 end;
1891 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', Obj.X, Obj.Y);
1893 ShotType := 0;
1894 end;
1896 if ShotType = WEAPON_SKEL_FIRE then
1897 begin // Ñàìîíàâîäêà ñíàðÿäà Ñêåëåòà:
1898 if GetPos(target, @o) then
1899 throw(i, Obj.X, Obj.Y,
1900 o.X+o.Rect.X+(o.Rect.Width div 2)+o.Vel.X+o.Accel.X,
1901 o.Y+o.Rect.Y+(o.Rect.Height div 2)+o.Vel.Y+o.Accel.Y,
1902 12);
1903 end;
1904 end;
1906 WEAPON_PLASMA, WEAPON_BSP_FIRE: // Ïëàçìà, ïëàçìà Àðàõíàòðîíà
1907 begin
1908 // Ïîïàëà â âîäó - ýëåêòðîøîê ïî âîäå:
1909 if WordBool(st and (MOVE_INWATER or MOVE_HITWATER)) then
1910 begin
1911 g_Sound_PlayExAt('SOUND_WEAPON_PLASMAWATER', Obj.X, Obj.Y);
1912 if g_Game_IsServer then CheckTrap(i, 10, HIT_ELECTRO);
1913 ShotType := 0;
1914 Continue;
1915 end;
1917 // Âåëè÷èíà óðîíà:
1918 if (ShotType = WEAPON_PLASMA) and
1919 (gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF]) then
1920 a := 10
1921 else
1922 a := 5;
1924 if ShotType = WEAPON_BSP_FIRE then
1925 a := 10;
1927 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
1928 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL)) or
1929 (g_Weapon_Hit(@Obj, a, SpawnerUID, HIT_SOME, False) <> 0) or
1930 (Timeout < 1) then
1931 begin
1932 if ShotType = WEAPON_PLASMA then
1933 s := 'FRAMES_EXPLODE_PLASMA'
1934 else
1935 s := 'FRAMES_EXPLODE_BSPFIRE';
1937 // Âçðûâ Ïëàçìû:
1938 if g_Frames_Get(TextureID, s) then
1939 begin
1940 Anim := TAnimation.Create(TextureID, False, 3);
1941 Anim.Blending := False;
1942 g_GFX_OnceAnim(cx-16, cy-16, Anim);
1943 Anim.Free();
1944 g_DynLightExplosion(cx, cy, 32, 0, 0.5, 0.5);
1945 end;
1947 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEPLASMA', Obj.X, Obj.Y);
1949 ShotType := 0;
1950 end;
1951 end;
1953 WEAPON_FLAMETHROWER: // Îãíåìåò
1954 begin
1955 // Ñî âðåìåíåì óìèðàåò
1956 if (Timeout < 1) then
1957 begin
1958 ShotType := 0;
1959 Continue;
1960 end;
1961 // Ïîä âîäîé òîæå
1962 if WordBool(st and (MOVE_HITWATER or MOVE_INWATER)) then
1963 begin
1964 if WordBool(st and MOVE_HITWATER) then
1965 begin
1966 if g_Frames_Get(_id, 'FRAMES_SMOKE') then
1967 begin
1968 Anim := TAnimation.Create(_id, False, 3);
1969 Anim.Alpha := 0;
1970 tcx := Random(8);
1971 tcy := Random(8);
1972 g_GFX_OnceAnim(cx-4+tcx-(Anim.Width div 2),
1973 cy-4+tcy-(Anim.Height div 2),
1974 Anim, ONCEANIM_SMOKE);
1975 Anim.Free();
1976 end;
1977 end
1978 else
1979 g_GFX_Bubbles(cx, cy, 1+Random(3), 16, 16);
1980 ShotType := 0;
1981 Continue;
1982 end;
1984 // Ãðàâèòàöèÿ
1985 if Stopped = 0 then
1986 Obj.Accel.Y := Obj.Accel.Y + 1;
1987 // Ïîïàëè â ñòåíó èëè â âîäó:
1988 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL or MOVE_HITWATER)) then
1989 begin
1990 // Ïðèëèïàåì:
1991 Obj.Vel.X := 0;
1992 Obj.Vel.Y := 0;
1993 Obj.Accel.Y := 0;
1994 if WordBool(st and MOVE_HITWALL) then
1995 Stopped := MOVE_HITWALL
1996 else if WordBool(st and MOVE_HITLAND) then
1997 Stopped := MOVE_HITLAND
1998 else if WordBool(st and MOVE_HITCEIL) then
1999 Stopped := MOVE_HITCEIL;
2000 end;
2002 a := IfThen(Stopped = 0, 3, 1);
2003 // Åñëè â êîãî-òî ïîïàëè
2004 if g_Weapon_Hit(@Obj, a, SpawnerUID, HIT_FLAME, False) <> 0 then
2005 begin
2006 // HIT_FLAME ñàì ïîäîææåò
2007 // Åñëè â ïîëåòå ïîïàëè, èñ÷åçàåì
2008 if Stopped = 0 then
2009 ShotType := 0;
2010 end;
2012 if Stopped = 0 then
2013 tf := 2
2014 else
2015 tf := 3;
2017 if (gTime mod tf = 0) then
2018 begin
2019 Anim := TAnimation.Create(TextureID, False, 2 + Random(2));
2020 Anim.Alpha := 0;
2021 case Stopped of
2022 MOVE_HITWALL: begin tcx := cx-4+Random(8); tcy := cy-12+Random(24); end;
2023 MOVE_HITLAND: begin tcx := cx-12+Random(24); tcy := cy-10+Random(8); end;
2024 MOVE_HITCEIL: begin tcx := cx-12+Random(24); tcy := cy+6+Random(8); end;
2025 else begin tcx := cx-4+Random(8); tcy := cy-4+Random(8); end;
2026 end;
2027 g_GFX_OnceAnim(tcx-(Anim.Width div 2), tcy-(Anim.Height div 2), Anim, ONCEANIM_SMOKE);
2028 Anim.Free();
2029 //g_DynLightExplosion(tcx, tcy, 1, 1, 0.8, 0.3);
2030 end;
2031 end;
2033 WEAPON_BFG: // BFG
2034 begin
2035 // Ïîïàëà â âîäó - ýëåêòðîøîê ïî âîäå:
2036 if WordBool(st and (MOVE_INWATER or MOVE_HITWATER)) then
2037 begin
2038 g_Sound_PlayExAt('SOUND_WEAPON_BFGWATER', Obj.X, Obj.Y);
2039 if g_Game_IsServer then CheckTrap(i, 1000, HIT_ELECTRO);
2040 ShotType := 0;
2041 Continue;
2042 end;
2044 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2045 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL)) or
2046 (g_Weapon_Hit(@Obj, SHOT_BFG_DAMAGE, SpawnerUID, HIT_BFG, False) <> 0) or
2047 (Timeout < 1) then
2048 begin
2049 // Ëó÷è BFG:
2050 if g_Game_IsServer then g_Weapon_BFG9000(cx, cy, SpawnerUID);
2052 // Âçðûâ BFG:
2053 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_BFG') then
2054 begin
2055 Anim := TAnimation.Create(TextureID, False, 6);
2056 Anim.Blending := False;
2057 g_GFX_OnceAnim(cx-64, cy-64, Anim);
2058 Anim.Free();
2059 g_DynLightExplosion(cx, cy, 96, 0, 1, 0);
2060 end;
2062 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', Obj.X, Obj.Y);
2064 ShotType := 0;
2065 end;
2066 end;
2068 WEAPON_IMP_FIRE, WEAPON_CACO_FIRE, WEAPON_BARON_FIRE: // Âûñòðåëû Áåñà, Êàêîäåìîíà Ðûöàðÿ/Áàðîíà àäà
2069 begin
2070 // Âûëåòåë èç âîäû:
2071 if WordBool(st and MOVE_HITAIR) then
2072 g_Obj_SetSpeed(@Obj, 16);
2074 // Âåëè÷èíà óðîíà:
2075 if ShotType = WEAPON_IMP_FIRE then
2076 a := 5
2077 else
2078 if ShotType = WEAPON_CACO_FIRE then
2079 a := 20
2080 else
2081 a := 40;
2083 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2084 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL)) or
2085 (g_Weapon_Hit(@Obj, a, SpawnerUID, HIT_SOME) <> 0) or
2086 (Timeout < 1) then
2087 begin
2088 if ShotType = WEAPON_IMP_FIRE then
2089 s := 'FRAMES_EXPLODE_IMPFIRE'
2090 else
2091 if ShotType = WEAPON_CACO_FIRE then
2092 s := 'FRAMES_EXPLODE_CACOFIRE'
2093 else
2094 s := 'FRAMES_EXPLODE_BARONFIRE';
2096 // Âçðûâ:
2097 if g_Frames_Get(TextureID, s) then
2098 begin
2099 Anim := TAnimation.Create(TextureID, False, 6);
2100 Anim.Blending := False;
2101 g_GFX_OnceAnim(cx-32, cy-32, Anim);
2102 Anim.Free();
2103 end;
2105 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj.X, Obj.Y);
2107 ShotType := 0;
2108 end;
2109 end;
2111 WEAPON_MANCUB_FIRE: // Âûñòðåë Ìàíêóáóñà
2112 begin
2113 // Âûëåòåë èç âîäû:
2114 if WordBool(st and MOVE_HITAIR) then
2115 g_Obj_SetSpeed(@Obj, 16);
2117 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2118 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL)) or
2119 (g_Weapon_Hit(@Obj, 40, SpawnerUID, HIT_SOME, False) <> 0) or
2120 (Timeout < 1) then
2121 begin
2122 // Âçðûâ:
2123 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_ROCKET') then
2124 begin
2125 Anim := TAnimation.Create(TextureID, False, 6);
2126 Anim.Blending := False;
2127 g_GFX_OnceAnim(cx-64, cy-64, Anim);
2128 Anim.Free();
2129 end;
2131 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj.X, Obj.Y);
2133 ShotType := 0;
2134 end;
2135 end;
2136 end; // case ShotType of...
2138 // Åñëè ñíàðÿäà óæå íåò, óäàëÿåì àíèìàöèþ:
2139 if (ShotType = 0) then
2140 begin
2141 if gGameSettings.GameType = GT_SERVER then
2142 MH_SEND_DeleteShot(i, Obj.X, Obj.Y, Loud);
2143 if Animation <> nil then
2144 begin
2145 Animation.Free();
2146 Animation := nil;
2147 end;
2148 end
2149 else if (ShotType <> WEAPON_FLAMETHROWER) and ((oldvx <> Obj.Vel.X) or (oldvy <> Obj.Vel.Y)) then
2150 if gGameSettings.GameType = GT_SERVER then
2151 MH_SEND_UpdateShot(i);
2152 end;
2153 end;
2154 end;
2156 procedure g_Weapon_Draw();
2157 var
2158 i: Integer;
2159 a: SmallInt;
2160 p: TPoint;
2161 begin
2162 if Shots = nil then
2163 Exit;
2165 for i := 0 to High(Shots) do
2166 if Shots[i].ShotType <> 0 then
2167 with Shots[i] do
2168 begin
2169 if (Shots[i].ShotType = WEAPON_ROCKETLAUNCHER) or
2170 (Shots[i].ShotType = WEAPON_BARON_FIRE) or
2171 (Shots[i].ShotType = WEAPON_MANCUB_FIRE) or
2172 (Shots[i].ShotType = WEAPON_SKEL_FIRE) then
2173 a := -GetAngle2(Obj.Vel.X, Obj.Vel.Y)
2174 else
2175 a := 0;
2177 p.X := Obj.Rect.Width div 2;
2178 p.Y := Obj.Rect.Height div 2;
2180 if Animation <> nil then
2181 begin
2182 if (Shots[i].ShotType = WEAPON_BARON_FIRE) or
2183 (Shots[i].ShotType = WEAPON_MANCUB_FIRE) or
2184 (Shots[i].ShotType = WEAPON_SKEL_FIRE) then
2185 Animation.DrawEx(Obj.X, Obj.Y, M_NONE, p, a)
2186 else
2187 Animation.Draw(Obj.X, Obj.Y, M_NONE);
2188 end
2189 else if TextureID <> 0 then
2190 begin
2191 if (Shots[i].ShotType = WEAPON_ROCKETLAUNCHER) then
2192 e_DrawAdv(TextureID, Obj.X, Obj.Y, 0, True, False, a, @p, M_NONE)
2193 else if (Shots[i].ShotType <> WEAPON_FLAMETHROWER) then
2194 e_Draw(TextureID, Obj.X, Obj.Y, 0, True, False);
2195 end;
2197 if g_debug_Frames then
2198 begin
2199 e_DrawQuad(Obj.X+Obj.Rect.X,
2200 Obj.Y+Obj.Rect.Y,
2201 Obj.X+Obj.Rect.X+Obj.Rect.Width-1,
2202 Obj.Y+Obj.Rect.Y+Obj.Rect.Height-1,
2203 0, 255, 0);
2204 end;
2205 end;
2206 end;
2208 function g_Weapon_Danger(UID: Word; X, Y: Integer; Width, Height: Word; Time: Byte): Boolean;
2209 var
2210 a: Integer;
2211 begin
2212 Result := False;
2214 if Shots = nil then
2215 Exit;
2217 for a := 0 to High(Shots) do
2218 if (Shots[a].ShotType <> 0) and (Shots[a].SpawnerUID <> UID) then
2219 if ((Shots[a].Obj.Vel.Y = 0) and (Shots[a].Obj.Vel.X > 0) and (Shots[a].Obj.X < X)) or
2220 (Shots[a].Obj.Vel.Y = 0) and (Shots[a].Obj.Vel.X < 0) and (Shots[a].Obj.X > X) then
2221 if (Abs(X-Shots[a].Obj.X) < Abs(Shots[a].Obj.Vel.X*Time)) and
2222 g_Collide(X, Y, Width, Height, X, Shots[a].Obj.Y,
2223 Shots[a].Obj.Rect.Width, Shots[a].Obj.Rect.Height) and
2224 g_TraceVector(X, Y, Shots[a].Obj.X, Shots[a].Obj.Y) then
2225 begin
2226 Result := True;
2227 Exit;
2228 end;
2229 end;
2231 procedure g_Weapon_SaveState(var Mem: TBinMemoryWriter);
2232 var
2233 count, i, j: Integer;
2234 dw: DWORD;
2235 begin
2236 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ ñíàðÿäîâ:
2237 count := 0;
2238 if Shots <> nil then
2239 for i := 0 to High(Shots) do
2240 if Shots[i].ShotType <> 0 then
2241 count := count + 1;
2243 Mem := TBinMemoryWriter.Create((count+1) * 80);
2245 // Êîëè÷åñòâî ñíàðÿäîâ:
2246 Mem.WriteInt(count);
2248 if count = 0 then
2249 Exit;
2251 for i := 0 to High(Shots) do
2252 if Shots[i].ShotType <> 0 then
2253 begin
2254 // Ñèãíàòóðà ñíàðÿäà:
2255 dw := SHOT_SIGNATURE; // 'SHOT'
2256 Mem.WriteDWORD(dw);
2257 // Òèï ñíàðÿäà:
2258 Mem.WriteByte(Shots[i].ShotType);
2259 // Öåëü:
2260 Mem.WriteWord(Shots[i].Target);
2261 // UID ñòðåëÿâøåãî:
2262 Mem.WriteWord(Shots[i].SpawnerUID);
2263 // Ðàçìåð ïîëÿ Triggers:
2264 dw := Length(Shots[i].Triggers);
2265 Mem.WriteDWORD(dw);
2266 // Òðèããåðû, àêòèâèðîâàííûå âûñòðåëîì:
2267 for j := 0 to Integer(dw)-1 do
2268 Mem.WriteDWORD(Shots[i].Triggers[j]);
2269 // Îáúåêò ñíàðÿäà:
2270 Obj_SaveState(@Shots[i].Obj, Mem);
2271 // Êîñòûëèíà åáàíàÿ:
2272 Mem.WriteByte(Shots[i].Stopped);
2273 end;
2274 end;
2276 procedure g_Weapon_LoadState(var Mem: TBinMemoryReader);
2277 var
2278 count, i, j: Integer;
2279 dw: DWORD;
2280 begin
2281 if Mem = nil then
2282 Exit;
2284 // Êîëè÷åñòâî ñíàðÿäîâ:
2285 Mem.ReadInt(count);
2287 SetLength(Shots, count);
2289 if count = 0 then
2290 Exit;
2292 for i := 0 to count-1 do
2293 begin
2294 // Ñèãíàòóðà ñíàðÿäà:
2295 Mem.ReadDWORD(dw);
2296 if dw <> SHOT_SIGNATURE then // 'SHOT'
2297 begin
2298 raise EBinSizeError.Create('g_Weapons_LoadState: Wrong Shot Signature');
2299 end;
2300 // Òèï ñíàðÿäà:
2301 Mem.ReadByte(Shots[i].ShotType);
2302 // Öåëü:
2303 Mem.ReadWord(Shots[i].Target);
2304 // UID ñòðåëÿâøåãî:
2305 Mem.ReadWord(Shots[i].SpawnerUID);
2306 // Ðàçìåð ïîëÿ Triggers:
2307 Mem.ReadDWORD(dw);
2308 SetLength(Shots[i].Triggers, dw);
2309 // Òðèããåðû, àêòèâèðîâàííûå âûñòðåëîì:
2310 for j := 0 to Integer(dw)-1 do
2311 Mem.ReadDWORD(Shots[i].Triggers[j]);
2312 // Îáúåêò ïðåäìåòà:
2313 Obj_LoadState(@Shots[i].Obj, Mem);
2314 // Êîñòûëèíà åáàíàÿ:
2315 Mem.ReadByte(Shots[i].Stopped);
2317 // Óñòàíîâêà òåêñòóðû èëè àíèìàöèè:
2318 Shots[i].TextureID := DWORD(-1);
2319 Shots[i].Animation := nil;
2321 case Shots[i].ShotType of
2322 WEAPON_ROCKETLAUNCHER, WEAPON_SKEL_FIRE:
2323 begin
2324 g_Texture_Get('TEXTURE_WEAPON_ROCKET', Shots[i].TextureID);
2325 end;
2326 WEAPON_PLASMA:
2327 begin
2328 g_Frames_Get(dw, 'FRAMES_WEAPON_PLASMA');
2329 Shots[i].Animation := TAnimation.Create(dw, True, 5);
2330 end;
2331 WEAPON_BFG:
2332 begin
2333 g_Frames_Get(dw, 'FRAMES_WEAPON_BFG');
2334 Shots[i].Animation := TAnimation.Create(dw, True, 6);
2335 end;
2336 WEAPON_IMP_FIRE:
2337 begin
2338 g_Frames_Get(dw, 'FRAMES_WEAPON_IMPFIRE');
2339 Shots[i].Animation := TAnimation.Create(dw, True, 4);
2340 end;
2341 WEAPON_BSP_FIRE:
2342 begin
2343 g_Frames_Get(dw, 'FRAMES_WEAPON_BSPFIRE');
2344 Shots[i].Animation := TAnimation.Create(dw, True, 4);
2345 end;
2346 WEAPON_CACO_FIRE:
2347 begin
2348 g_Frames_Get(dw, 'FRAMES_WEAPON_CACOFIRE');
2349 Shots[i].Animation := TAnimation.Create(dw, True, 4);
2350 end;
2351 WEAPON_BARON_FIRE:
2352 begin
2353 g_Frames_Get(dw, 'FRAMES_WEAPON_BARONFIRE');
2354 Shots[i].Animation := TAnimation.Create(dw, True, 4);
2355 end;
2356 WEAPON_MANCUB_FIRE:
2357 begin
2358 g_Frames_Get(dw, 'FRAMES_WEAPON_MANCUBFIRE');
2359 Shots[i].Animation := TAnimation.Create(dw, True, 4);
2360 end;
2361 end;
2362 end;
2363 end;
2365 procedure g_Weapon_DestroyShot(I: Integer; X, Y: Integer; Loud: Boolean = True);
2366 var
2367 cx, cy: Integer;
2368 Anim: TAnimation;
2369 s: string;
2370 begin
2371 if Shots = nil then
2372 Exit;
2373 if (I > High(Shots)) or (I < 0) then Exit;
2375 with Shots[I] do
2376 begin
2377 if ShotType = 0 then Exit;
2378 Obj.X := X;
2379 Obj.Y := Y;
2380 cx := Obj.X + (Obj.Rect.Width div 2);
2381 cy := Obj.Y + (Obj.Rect.Height div 2);
2383 case ShotType of
2384 WEAPON_ROCKETLAUNCHER, WEAPON_SKEL_FIRE: // Ðàêåòû è ñíàðÿäû Ñêåëåòà
2385 begin
2386 if Loud then
2387 begin
2388 if ShotType = WEAPON_SKEL_FIRE then
2389 begin // Âçðûâ ñíàðÿäà Ñêåëåòà
2390 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_SKELFIRE') then
2391 begin
2392 Anim := TAnimation.Create(TextureID, False, 8);
2393 Anim.Blending := False;
2394 g_GFX_OnceAnim((Obj.X+32)-32, (Obj.Y+8)-32, Anim);
2395 Anim.Free();
2396 end;
2397 end
2398 else
2399 begin // Âçðûâ Ðàêåòû
2400 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_ROCKET') then
2401 begin
2402 Anim := TAnimation.Create(TextureID, False, 6);
2403 Anim.Blending := False;
2404 g_GFX_OnceAnim(cx-64, cy-64, Anim);
2405 Anim.Free();
2406 end;
2407 end;
2408 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', Obj.X, Obj.Y);
2409 end;
2410 end;
2412 WEAPON_PLASMA, WEAPON_BSP_FIRE: // Ïëàçìà, ïëàçìà Àðàõíàòðîíà
2413 begin
2414 if ShotType = WEAPON_PLASMA then
2415 s := 'FRAMES_EXPLODE_PLASMA'
2416 else
2417 s := 'FRAMES_EXPLODE_BSPFIRE';
2419 if g_Frames_Get(TextureID, s) and loud then
2420 begin
2421 Anim := TAnimation.Create(TextureID, False, 3);
2422 Anim.Blending := False;
2423 g_GFX_OnceAnim(cx-16, cy-16, Anim);
2424 Anim.Free();
2426 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEPLASMA', Obj.X, Obj.Y);
2427 end;
2428 end;
2430 WEAPON_BFG: // BFG
2431 begin
2432 // Âçðûâ BFG:
2433 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_BFG') and Loud then
2434 begin
2435 Anim := TAnimation.Create(TextureID, False, 6);
2436 Anim.Blending := False;
2437 g_GFX_OnceAnim(cx-64, cy-64, Anim);
2438 Anim.Free();
2440 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', Obj.X, Obj.Y);
2441 end;
2442 end;
2444 WEAPON_IMP_FIRE, WEAPON_CACO_FIRE, WEAPON_BARON_FIRE: // Âûñòðåëû Áåñà, Êàêîäåìîíà Ðûöàðÿ/Áàðîíà àäà
2445 begin
2446 if ShotType = WEAPON_IMP_FIRE then
2447 s := 'FRAMES_EXPLODE_IMPFIRE'
2448 else
2449 if ShotType = WEAPON_CACO_FIRE then
2450 s := 'FRAMES_EXPLODE_CACOFIRE'
2451 else
2452 s := 'FRAMES_EXPLODE_BARONFIRE';
2454 if g_Frames_Get(TextureID, s) and Loud then
2455 begin
2456 Anim := TAnimation.Create(TextureID, False, 6);
2457 Anim.Blending := False;
2458 g_GFX_OnceAnim(cx-32, cy-32, Anim);
2459 Anim.Free();
2461 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj.X, Obj.Y);
2462 end;
2463 end;
2465 WEAPON_MANCUB_FIRE: // Âûñòðåë Ìàíêóáóñà
2466 begin
2467 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_ROCKET') and Loud then
2468 begin
2469 Anim := TAnimation.Create(TextureID, False, 6);
2470 Anim.Blending := False;
2471 g_GFX_OnceAnim(cx-64, cy-64, Anim);
2472 Anim.Free();
2474 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj.X, Obj.Y);
2475 end;
2476 end;
2477 end; // case ShotType of...
2479 ShotType := 0;
2480 Animation.Free();
2481 end;
2482 end;
2485 procedure g_Weapon_AddDynLights();
2486 var
2487 i: Integer;
2488 begin
2489 if Shots = nil then Exit;
2490 for i := 0 to High(Shots) do
2491 begin
2492 if Shots[i].ShotType = 0 then continue;
2493 if (Shots[i].ShotType = WEAPON_ROCKETLAUNCHER) or
2494 (Shots[i].ShotType = WEAPON_BARON_FIRE) or
2495 (Shots[i].ShotType = WEAPON_MANCUB_FIRE) or
2496 (Shots[i].ShotType = WEAPON_SKEL_FIRE) or
2497 (Shots[i].ShotType = WEAPON_IMP_FIRE) or
2498 (Shots[i].ShotType = WEAPON_CACO_FIRE) or
2499 (Shots[i].ShotType = WEAPON_MANCUB_FIRE) or
2500 (Shots[i].ShotType = WEAPON_BSP_FIRE) or
2501 (Shots[i].ShotType = WEAPON_PLASMA) or
2502 (Shots[i].ShotType = WEAPON_BFG) or
2503 (Shots[i].ShotType = WEAPON_FLAMETHROWER) or
2504 false then
2505 begin
2506 if (Shots[i].ShotType = WEAPON_PLASMA) then
2507 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)
2508 else if (Shots[i].ShotType = WEAPON_BFG) then
2509 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)
2510 else if (Shots[i].ShotType = WEAPON_FLAMETHROWER) then
2511 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)
2512 else
2513 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);
2514 end;
2515 end;
2516 end;
2519 procedure TShot.positionChanged (); begin end;
2522 end.