DEADSOFTWARE

use tree to check collisions with shot projectiles
[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, g_panel,
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;
247 var
248 chkTrap_pl: array [0..256] of Integer;
249 chkTrap_mn: array [0..65535] of TMonster;
251 procedure CheckTrap(ID: DWORD; dm: Integer; t: Byte);
252 var
253 //a, b, c, d, i1, i2: Integer;
254 //chkTrap_pl, chkTrap_mn: WArray;
255 plaCount: Integer = 0;
256 mnaCount: Integer = 0;
257 frameId: DWord;
260 function monsWaterCheck (monidx: Integer; mon: TMonster): Boolean;
261 begin
262 result := false; // don't stop
263 if mon.Live and mon.Collide(gWater[WaterMap[a][c]]) and (not InWArray(monidx, chkTrap_mn)) and (i2 < 1023) then //FIXME
264 begin
265 i2 += 1;
266 chkTrap_mn[i2] := monidx;
267 end;
268 end;
271 function monsWaterCheck (monidx: Integer; mon: TMonster): Boolean;
272 begin
273 result := false; // don't stop
274 if (mon.trapCheckFrameId <> frameId) then
275 begin
276 mon.trapCheckFrameId := frameId;
277 chkTrap_mn[mnaCount] := mon;
278 Inc(mnaCount);
279 end;
280 end;
282 var
283 a, b, c, d, f: Integer;
284 pan: TPanel;
285 begin
286 if (gWater = nil) or (WaterMap = nil) then Exit;
288 frameId := g_Mons_getNewTrapFrameId();
290 //i1 := -1;
291 //i2 := -1;
293 //SetLength(chkTrap_pl, 1024);
294 //SetLength(chkTrap_mn, 1024);
295 //for d := 0 to 1023 do chkTrap_pl[d] := $FFFF;
296 //for d := 0 to 1023 do chkTrap_mn[d] := $FFFF;
298 for a := 0 to High(WaterMap) do
299 begin
300 for b := 0 to High(WaterMap[a]) do
301 begin
302 pan := gWater[WaterMap[a][b]];
303 if not g_Obj_Collide(pan.X, pan.Y, pan.Width, pan.Height, @Shots[ID].Obj) then continue;
305 for c := 0 to High(WaterMap[a]) do
306 begin
307 pan := gWater[WaterMap[a][c]];
308 for d := 0 to High(gPlayers) do
309 begin
310 if (gPlayers[d] <> nil) and (gPlayers[d].Live) then
311 begin
312 if gPlayers[d].Collide(pan) then
313 begin
314 f := 0;
315 while (f < plaCount) and (chkTrap_pl[f] <> d) do Inc(f);
316 if (f = plaCount) then
317 begin
318 chkTrap_pl[plaCount] := d;
319 Inc(plaCount);
320 if (plaCount = Length(chkTrap_pl)) then break;
321 end;
322 end;
323 end;
324 end;
326 //g_Mons_ForEach(monsWaterCheck);
327 g_Mons_ForEachAtAlive(pan.X, pan.Y, pan.Width, pan.Height, monsWaterCheck);
328 end;
330 for f := 0 to plaCount-1 do gPlayers[chkTrap_pl[f]].Damage(dm, Shots[ID].SpawnerUID, 0, 0, t);
331 for f := 0 to mnaCount-1 do chkTrap_mn[f].Damage(dm, 0, 0, Shots[ID].SpawnerUID, t);
332 end;
333 end;
335 //chkTrap_pl := nil;
336 //chkTrap_mn := nil;
337 end;
339 function HitMonster(m: TMonster; d: Integer; vx, vy: Integer; SpawnerUID: Word; t: Byte): Boolean;
340 var
341 tt, mt: Byte;
342 mon: TMonster;
343 begin
344 Result := False;
346 tt := g_GetUIDType(SpawnerUID);
347 if tt = UID_MONSTER then
348 begin
349 mon := g_Monsters_ByUID(SpawnerUID);
350 if mon <> nil then
351 mt := g_Monsters_ByUID(SpawnerUID).MonsterType
352 else
353 mt := 0;
354 end
355 else
356 mt := 0;
358 if m = nil then Exit;
359 if m.UID = SpawnerUID then
360 begin
361 // Ñàì ñåáÿ ìîæåò ðàíèòü òîëüêî ðàêåòîé è òîêîì:
362 if (t <> HIT_ROCKET) and (t <> HIT_ELECTRO) then
363 Exit;
364 // Êèáåð äåìîí è áî÷êà âîîáùå íå ìîãóò ñåáÿ ðàíèòü:
365 if (m.MonsterType = MONSTER_CYBER) or
366 (m.MonsterType = MONSTER_BARREL) then
367 begin
368 Result := True;
369 Exit;
370 end;
371 end;
373 if tt = UID_MONSTER then
374 begin
375 // Lost_Soul íå ìîæåò ðàíèòü Pain_Elemental'à:
376 if (mt = MONSTER_SOUL) and (m.MonsterType = MONSTER_PAIN) then
377 Exit;
379 // Îáà ìîíñòðà îäíîãî âèäà:
380 if mt = m.MonsterType then
381 case mt of
382 MONSTER_IMP, MONSTER_DEMON, MONSTER_BARON, MONSTER_KNIGHT, MONSTER_CACO,
383 MONSTER_SOUL, MONSTER_MANCUB, MONSTER_SKEL, MONSTER_FISH:
384 Exit; // Ýòè íå áüþò ñâîèõ
385 end;
386 end;
388 if g_Game_IsServer then
389 begin
390 if (t <> HIT_FLAME) or (m.FFireTime = 0) or (vx <> 0) or (vy <> 0) then
391 Result := m.Damage(d, vx, vy, SpawnerUID, t)
392 else
393 Result := True;
394 if t = HIT_FLAME then
395 m.CatchFire(SpawnerUID);
396 end
397 else
398 Result := True;
399 end;
401 function HitPlayer(p: TPlayer; d: Integer; vx, vy: Integer; SpawnerUID: Word; t: Byte): Boolean;
402 begin
403 Result := False;
405 // Ñàì ñåáÿ ìîæåò ðàíèòü òîëüêî ðàêåòîé è òîêîì:
406 if (p.UID = SpawnerUID) and (t <> HIT_ROCKET) and (t <> HIT_ELECTRO) then
407 Exit;
409 if g_Game_IsServer then
410 begin
411 if (t <> HIT_FLAME) or (p.FFireTime = 0) or (vx <> 0) or (vy <> 0) then
412 p.Damage(d, SpawnerUID, vx, vy, t);
413 if (t = HIT_FLAME) then
414 p.CatchFire(SpawnerUID);
415 end;
417 Result := True;
418 end;
420 function GunHit(X, Y: Integer; vx, vy: Integer; dmg: Integer;
421 SpawnerUID: Word; AllowPush: Boolean): Byte;
423 {function monsCheck (monidx: Integer; mon: TMonster): Boolean;
424 begin
425 result := false; // don't stop
426 if mon.Live and mon.Collide(X, Y) then
427 begin
428 if HitMonster(mon, dmg, vx*10, vy*10-3, SpawnerUID, HIT_SOME) then
429 begin
430 if AllowPush then mon.Push(vx, vy);
431 result := true;
432 end;
433 end;
434 end;}
436 function monsCheck (monidx: Integer; mon: TMonster): Boolean;
437 begin
438 result := false; // don't stop
439 if HitMonster(mon, dmg, vx*10, vy*10-3, SpawnerUID, HIT_SOME) then
440 begin
441 if AllowPush then mon.Push(vx, vy);
442 result := true;
443 end;
444 end;
446 var
447 i, h: Integer;
448 begin
449 Result := 0;
451 h := High(gPlayers);
453 if h <> -1 then
454 for i := 0 to h do
455 if (gPlayers[i] <> nil) and gPlayers[i].Live and gPlayers[i].Collide(X, Y) then
456 if HitPlayer(gPlayers[i], dmg, vx*10, vy*10-3, SpawnerUID, HIT_SOME) then
457 begin
458 if AllowPush then gPlayers[i].Push(vx, vy);
459 Result := 1;
460 end;
462 if Result <> 0 then Exit;
464 //if g_Mons_ForEach(monsCheck) then result := 2;
465 if g_Mons_ForEachAtAlive(X, Y, 1, 1, monsCheck) then result := 2;
466 end;
468 procedure g_Weapon_BFG9000(X, Y: Integer; SpawnerUID: Word);
470 function monsCheck (monidx: Integer; mon: TMonster): Boolean;
471 begin
472 result := false; // don't stop
473 if (mon <> nil) and (mon.Live) and (mon.UID <> SpawnerUID) then
474 begin
475 with mon do
476 begin
477 if (g_PatchLength(X, Y, Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2),
478 Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)) <= SHOT_BFG_RADIUS) and
479 g_TraceVector(X, Y, Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2),
480 Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)) then
481 begin
482 if HitMonster(mon, 50, 0, 0, SpawnerUID, HIT_SOME) then mon.BFGHit();
483 end;
484 end;
485 end;
486 end;
488 var
489 i, h: Integer;
490 st: Byte;
491 pl: TPlayer;
492 b: Boolean;
493 begin
494 //g_Sound_PlayEx('SOUND_WEAPON_EXPLODEBFG', 255);
496 h := High(gCorpses);
498 if gAdvCorpses and (h <> -1) then
499 for i := 0 to h do
500 if (gCorpses[i] <> nil) and (gCorpses[i].State <> CORPSE_STATE_REMOVEME) then
501 with gCorpses[i] do
502 if (g_PatchLength(X, Y, Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2),
503 Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)) <= SHOT_BFG_RADIUS) and
504 g_TraceVector(X, Y, Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2),
505 Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)) then
506 begin
507 Damage(50, 0, 0);
508 g_Weapon_BFGHit(Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2),
509 Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2));
510 end;
512 st := TEAM_NONE;
513 pl := g_Player_Get(SpawnerUID);
514 if pl <> nil then
515 st := pl.Team;
517 h := High(gPlayers);
519 if h <> -1 then
520 for i := 0 to h do
521 if (gPlayers[i] <> nil) and (gPlayers[i].Live) and (gPlayers[i].UID <> SpawnerUID) then
522 with gPlayers[i] do
523 if (g_PatchLength(X, Y, GameX+PLAYER_RECT.X+(PLAYER_RECT.Width div 2),
524 GameY+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)) <= SHOT_BFG_RADIUS) and
525 g_TraceVector(X, Y, GameX+PLAYER_RECT.X+(PLAYER_RECT.Width div 2),
526 GameY+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)) then
527 begin
528 if (st = TEAM_NONE) or (st <> gPlayers[i].Team) then
529 b := HitPlayer(gPlayers[i], 50, 0, 0, SpawnerUID, HIT_SOME)
530 else
531 b := HitPlayer(gPlayers[i], 25, 0, 0, SpawnerUID, HIT_SOME);
532 if b then
533 gPlayers[i].BFGHit();
534 end;
536 //FIXME
537 g_Mons_ForEach(monsCheck);
538 end;
540 function g_Weapon_CreateShot(I: Integer; ShotType: Byte; Spawner, TargetUID: Word; X, Y, XV, YV: Integer): LongWord;
541 var
542 find_id, FramesID: DWORD;
543 begin
544 if I < 0 then
545 find_id := FindShot()
546 else
547 begin
548 find_id := I;
549 if Integer(find_id) >= High(Shots) then
550 SetLength(Shots, find_id + 64)
551 end;
553 case ShotType of
554 WEAPON_ROCKETLAUNCHER:
555 begin
556 with Shots[find_id] do
557 begin
558 g_Obj_Init(@Obj);
560 Obj.Rect.Width := SHOT_ROCKETLAUNCHER_WIDTH;
561 Obj.Rect.Height := SHOT_ROCKETLAUNCHER_HEIGHT;
563 Animation := nil;
564 Triggers := nil;
565 ShotType := WEAPON_ROCKETLAUNCHER;
566 g_Texture_Get('TEXTURE_WEAPON_ROCKET', TextureID);
567 end;
568 end;
570 WEAPON_PLASMA:
571 begin
572 with Shots[find_id] do
573 begin
574 g_Obj_Init(@Obj);
576 Obj.Rect.Width := SHOT_PLASMA_WIDTH;
577 Obj.Rect.Height := SHOT_PLASMA_HEIGHT;
579 Triggers := nil;
580 ShotType := WEAPON_PLASMA;
581 g_Frames_Get(FramesID, 'FRAMES_WEAPON_PLASMA');
582 Animation := TAnimation.Create(FramesID, True, 5);
583 end;
584 end;
586 WEAPON_BFG:
587 begin
588 with Shots[find_id] do
589 begin
590 g_Obj_Init(@Obj);
592 Obj.Rect.Width := SHOT_BFG_WIDTH;
593 Obj.Rect.Height := SHOT_BFG_HEIGHT;
595 Triggers := nil;
596 ShotType := WEAPON_BFG;
597 g_Frames_Get(FramesID, 'FRAMES_WEAPON_BFG');
598 Animation := TAnimation.Create(FramesID, True, 6);
599 end;
600 end;
602 WEAPON_FLAMETHROWER:
603 begin
604 with Shots[find_id] do
605 begin
606 g_Obj_Init(@Obj);
608 Obj.Rect.Width := SHOT_FLAME_WIDTH;
609 Obj.Rect.Height := SHOT_FLAME_HEIGHT;
611 Triggers := nil;
612 ShotType := WEAPON_FLAMETHROWER;
613 Animation := nil;
614 TextureID := 0;
615 g_Frames_Get(TextureID, 'FRAMES_FLAME');
616 end;
617 end;
619 WEAPON_IMP_FIRE:
620 begin
621 with Shots[find_id] do
622 begin
623 g_Obj_Init(@Obj);
625 Obj.Rect.Width := 16;
626 Obj.Rect.Height := 16;
628 Triggers := nil;
629 ShotType := WEAPON_IMP_FIRE;
630 g_Frames_Get(FramesID, 'FRAMES_WEAPON_IMPFIRE');
631 Animation := TAnimation.Create(FramesID, True, 4);
632 end;
633 end;
635 WEAPON_CACO_FIRE:
636 begin
637 with Shots[find_id] do
638 begin
639 g_Obj_Init(@Obj);
641 Obj.Rect.Width := 16;
642 Obj.Rect.Height := 16;
644 Triggers := nil;
645 ShotType := WEAPON_CACO_FIRE;
646 g_Frames_Get(FramesID, 'FRAMES_WEAPON_CACOFIRE');
647 Animation := TAnimation.Create(FramesID, True, 4);
648 end;
649 end;
651 WEAPON_MANCUB_FIRE:
652 begin
653 with Shots[find_id] do
654 begin
655 g_Obj_Init(@Obj);
657 Obj.Rect.Width := 32;
658 Obj.Rect.Height := 32;
660 Triggers := nil;
661 ShotType := WEAPON_MANCUB_FIRE;
662 g_Frames_Get(FramesID, 'FRAMES_WEAPON_MANCUBFIRE');
663 Animation := TAnimation.Create(FramesID, True, 4);
664 end;
665 end;
667 WEAPON_BARON_FIRE:
668 begin
669 with Shots[find_id] do
670 begin
671 g_Obj_Init(@Obj);
673 Obj.Rect.Width := 32;
674 Obj.Rect.Height := 16;
676 Triggers := nil;
677 ShotType := WEAPON_BARON_FIRE;
678 g_Frames_Get(FramesID, 'FRAMES_WEAPON_BARONFIRE');
679 Animation := TAnimation.Create(FramesID, True, 4);
680 end;
681 end;
683 WEAPON_BSP_FIRE:
684 begin
685 with Shots[find_id] do
686 begin
687 g_Obj_Init(@Obj);
689 Obj.Rect.Width := 16;
690 Obj.Rect.Height := 16;
692 Triggers := nil;
693 ShotType := WEAPON_BSP_FIRE;
694 g_Frames_Get(FramesID, 'FRAMES_WEAPON_BSPFIRE');
695 Animation := TAnimation.Create(FramesID, True, 4);
696 end;
697 end;
699 WEAPON_SKEL_FIRE:
700 begin
701 with Shots[find_id] do
702 begin
703 g_Obj_Init(@Obj);
705 Obj.Rect.Width := SHOT_SKELFIRE_WIDTH;
706 Obj.Rect.Height := SHOT_SKELFIRE_HEIGHT;
708 Triggers := nil;
709 ShotType := WEAPON_SKEL_FIRE;
710 target := TargetUID;
711 g_Frames_Get(FramesID, 'FRAMES_WEAPON_SKELFIRE');
712 Animation := TAnimation.Create(FramesID, True, 5);
713 end;
714 end;
715 end;
717 Shots[find_id].Obj.X := X;
718 Shots[find_id].Obj.Y := Y;
719 Shots[find_id].Obj.Vel.X := XV;
720 Shots[find_id].Obj.Vel.Y := YV;
721 Shots[find_id].Obj.Accel.X := 0;
722 Shots[find_id].Obj.Accel.Y := 0;
723 Shots[find_id].SpawnerUID := Spawner;
724 if (ShotType = WEAPON_FLAMETHROWER) and (XV = 0) and (YV = 0) then
725 Shots[find_id].Stopped := 255
726 else
727 Shots[find_id].Stopped := 0;
728 Result := find_id;
729 end;
731 procedure throw(i, x, y, xd, yd, s: Integer);
732 var
733 a: Integer;
734 begin
735 yd := yd - y;
736 xd := xd - x;
738 a := Max(Abs(xd), Abs(yd));
739 if a = 0 then
740 a := 1;
742 Shots[i].Obj.X := x;
743 Shots[i].Obj.Y := y;
744 Shots[i].Obj.Vel.X := (xd*s) div a;
745 Shots[i].Obj.Vel.Y := (yd*s) div a;
746 Shots[i].Obj.Accel.X := 0;
747 Shots[i].Obj.Accel.Y := 0;
748 Shots[i].Stopped := 0;
749 if Shots[i].ShotType in [WEAPON_ROCKETLAUNCHER, WEAPON_BFG] then
750 Shots[i].Timeout := 900 // ~25 sec
751 else
752 begin
753 if Shots[i].ShotType = WEAPON_FLAMETHROWER then
754 Shots[i].Timeout := SHOT_FLAME_LIFETIME
755 else
756 Shots[i].Timeout := 550; // ~15 sec
757 end;
758 end;
760 function g_Weapon_Hit(obj: PObj; d: Integer; SpawnerUID: Word; t: Byte; HitCorpses: Boolean = True): Byte;
761 var
762 i, h: Integer;
764 function PlayerHit(Team: Byte = 0): Boolean;
765 var
766 i: Integer;
767 ChkTeam: Boolean;
768 p: TPlayer;
769 begin
770 Result := False;
771 h := High(gPlayers);
773 if h <> -1 then
774 for i := 0 to h do
775 if (gPlayers[i] <> nil) and gPlayers[i].Live and g_Obj_Collide(obj, @gPlayers[i].Obj) then
776 begin
777 ChkTeam := True;
778 if (Team > 0) and (g_GetUIDType(SpawnerUID) = UID_PLAYER) then
779 begin
780 p := g_Player_Get(SpawnerUID);
781 if p <> nil then
782 ChkTeam := (p.Team = gPlayers[i].Team) xor (Team = 2);
783 end;
784 if ChkTeam then
785 if HitPlayer(gPlayers[i], d, obj^.Vel.X, obj^.Vel.Y, SpawnerUID, t) then
786 begin
787 if t <> HIT_FLAME then
788 gPlayers[i].Push((obj^.Vel.X+obj^.Accel.X)*IfThen(t = HIT_BFG, 8, 1) div 4,
789 (obj^.Vel.Y+obj^.Accel.Y)*IfThen(t = HIT_BFG, 8, 1) div 4);
790 if t = HIT_BFG then
791 g_Game_DelayEvent(DE_BFGHIT, 1000, SpawnerUID);
792 Result := True;
793 break;
794 end;
795 end;
796 end;
799 function monsCheckHit (monidx: Integer; mon: TMonster): Boolean;
800 begin
801 result := false; // don't stop
802 if (mon <> nil) and mon.Live and g_Obj_Collide(obj, @mon.Obj) then
803 begin
804 if HitMonster(mon, d, obj^.Vel.X, obj^.Vel.Y, SpawnerUID, t) then
805 begin
806 if (t <> HIT_FLAME) then
807 begin
808 mon.Push((obj^.Vel.X+obj^.Accel.X)*IfThen(t = HIT_BFG, 8, 1) div 4,
809 (obj^.Vel.Y+obj^.Accel.Y)*IfThen(t = HIT_BFG, 8, 1) div 4);
810 end;
811 result := True;
812 end;
813 end;
814 end;
817 function monsCheckHit (monidx: Integer; mon: TMonster): Boolean;
818 begin
819 result := false; // don't stop
820 if HitMonster(mon, d, obj.Vel.X, obj.Vel.Y, SpawnerUID, t) then
821 begin
822 if (t <> HIT_FLAME) then
823 begin
824 mon.Push((obj.Vel.X+obj.Accel.X)*IfThen(t = HIT_BFG, 8, 1) div 4,
825 (obj.Vel.Y+obj.Accel.Y)*IfThen(t = HIT_BFG, 8, 1) div 4);
826 end;
827 result := true;
828 end;
829 end;
831 function MonsterHit(): Boolean;
832 begin
833 //result := g_Mons_ForEach(monsCheckHit);
834 result := g_Mons_ForEachAtAlive(obj.X+obj.Rect.X, obj.Y+obj.Rect.Y, obj.Rect.Width, obj.Rect.Height, monsCheckHit);
835 end;
837 begin
838 Result := 0;
840 if HitCorpses then
841 begin
842 h := High(gCorpses);
844 if gAdvCorpses and (h <> -1) then
845 for i := 0 to h do
846 if (gCorpses[i] <> nil) and (gCorpses[i].State <> CORPSE_STATE_REMOVEME) and
847 g_Obj_Collide(obj, @gCorpses[i].Obj) then
848 begin
849 // Ðàñïèëèâàåì òðóï:
850 gCorpses[i].Damage(d, (obj^.Vel.X+obj^.Accel.X) div 4,
851 (obj^.Vel.Y+obj^.Accel.Y) div 4);
852 Result := 1;
853 end;
854 end;
856 case gGameSettings.GameMode of
857 // Êàìïàíèÿ:
858 GM_COOP, GM_SINGLE:
859 begin
860 // Ñíà÷àëà áü¸ì ìîíñòðîâ, åñëè åñòü, ïîòîì ïûòàåìñÿ áèòü èãðîêîâ
861 if MonsterHit() then
862 begin
863 Result := 2;
864 Exit;
865 end;
867 if PlayerHit() then
868 begin
869 Result := 1;
870 Exit;
871 end;
872 end;
874 // Äåçìàò÷:
875 GM_DM:
876 begin
877 // Ñíà÷àëà áü¸ì èãðîêîâ, åñëè åñòü, ïîòîì ïûòàåìñÿ áèòü ìîíñòðîâ
878 if PlayerHit() then
879 begin
880 Result := 1;
881 Exit;
882 end;
884 if MonsterHit() then
885 begin
886 Result := 2;
887 Exit;
888 end;
889 end;
891 // Êîìàíäíûå:
892 GM_TDM, GM_CTF:
893 begin
894 // Ñíà÷àëà áü¸ì èãðîêîâ êîìàíäû ñîïåðíèêà
895 if PlayerHit(2) then
896 begin
897 Result := 1;
898 Exit;
899 end;
901 // Ïîòîì ìîíñòðîâ
902 if MonsterHit() then
903 begin
904 Result := 2;
905 Exit;
906 end;
908 // È â êîíöå ñâîèõ èãðîêîâ
909 if PlayerHit(1) then
910 begin
911 Result := 1;
912 Exit;
913 end;
914 end;
916 end;
917 end;
919 function g_Weapon_HitUID(UID: Word; d: Integer; SpawnerUID: Word; t: Byte): Boolean;
920 begin
921 Result := False;
923 case g_GetUIDType(UID) of
924 UID_PLAYER: Result := HitPlayer(g_Player_Get(UID), d, 0, 0, SpawnerUID, t);
925 UID_MONSTER: Result := HitMonster(g_Monsters_ByUID(UID), d, 0, 0, SpawnerUID, t);
926 else Exit;
927 end;
928 end;
930 function g_Weapon_Explode(X, Y: Integer; rad: Integer; SpawnerUID: Word): Boolean;
931 var
932 r: Integer;
934 function monsExCheck (monidx: Integer; mon: TMonster): Boolean;
935 var
936 dx, dy, mm: Integer;
937 begin
938 result := false; // don't stop
939 if mon <> nil then
940 begin
941 with mon do
942 begin
943 dx := Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2)-X;
944 dy := Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)-Y;
946 if dx > 1000 then dx := 1000;
947 if dy > 1000 then dy := 1000;
949 if (dx*dx+dy*dy < r) then
950 begin
951 //m := PointToRect(X, Y, Obj.X+Obj.Rect.X, Obj.Y+Obj.Rect.Y, Obj.Rect.Width, Obj.Rect.Height);
953 mm := Max(abs(dx), abs(dy));
954 if mm = 0 then mm := 1;
956 if mon.Live then
957 HitMonster(mon, ((mon.Obj.Rect.Width div 4)*10*(rad-mm)) div rad,
958 0, 0, SpawnerUID, HIT_ROCKET);
960 mon.Push((dx*7) div mm, (dy*7) div mm);
961 end;
962 end;
963 end;
964 end;
966 var
967 i, h, dx, dy, m, mm: Integer;
968 _angle: SmallInt;
970 begin
971 Result := False;
973 g_Triggers_PressC(X, Y, rad, SpawnerUID, ACTIVATE_SHOT);
975 r := rad*rad;
977 h := High(gPlayers);
979 if h <> -1 then
980 for i := 0 to h do
981 if (gPlayers[i] <> nil) and gPlayers[i].Live then
982 with gPlayers[i] do
983 begin
984 dx := Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2)-X;
985 dy := Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)-Y;
987 if dx > 1000 then dx := 1000;
988 if dy > 1000 then dy := 1000;
990 if dx*dx+dy*dy < r then
991 begin
992 //m := PointToRect(X, Y, GameX+PLAYER_RECT.X, GameY+PLAYER_RECT.Y,
993 // PLAYER_RECT.Width, PLAYER_RECT.Height);
995 mm := Max(abs(dx), abs(dy));
996 if mm = 0 then mm := 1;
998 HitPlayer(gPlayers[i], (100*(rad-mm)) div rad, (dx*10) div mm, (dy*10) div mm, SpawnerUID, HIT_ROCKET);
999 gPlayers[i].Push((dx*7) div mm, (dy*7) div mm);
1000 end;
1001 end;
1003 g_Mons_ForEach(monsExCheck);
1006 h := High(gCorpses);
1008 if gAdvCorpses and (h <> -1) then
1009 for i := 0 to h do
1010 if (gCorpses[i] <> nil) and (gCorpses[i].State <> CORPSE_STATE_REMOVEME) then
1011 with gCorpses[i] do
1012 begin
1013 dx := Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2)-X;
1014 dy := Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)-Y;
1016 if dx > 1000 then dx := 1000;
1017 if dy > 1000 then dy := 1000;
1019 if dx*dx+dy*dy < r then
1020 begin
1021 m := PointToRect(X, Y, Obj.X+Obj.Rect.X, Obj.Y+Obj.Rect.Y,
1022 Obj.Rect.Width, Obj.Rect.Height);
1024 mm := Max(abs(dx), abs(dy));
1025 if mm = 0 then mm := 1;
1027 Damage(Round(100*(rad-m)/rad), (dx*10) div mm, (dy*10) div mm);
1028 end;
1029 end;
1031 h := High(gGibs);
1033 if gAdvGibs and (h <> -1) then
1034 for i := 0 to h do
1035 if gGibs[i].Live then
1036 with gGibs[i] do
1037 begin
1038 dx := Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2)-X;
1039 dy := Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)-Y;
1041 if dx > 1000 then dx := 1000;
1042 if dy > 1000 then dy := 1000;
1044 if dx*dx+dy*dy < r then
1045 begin
1046 m := PointToRect(X, Y, Obj.X+Obj.Rect.X, Obj.Y+Obj.Rect.Y,
1047 Obj.Rect.Width, Obj.Rect.Height);
1048 _angle := GetAngle(Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2),
1049 Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2), X, Y);
1051 g_Obj_PushA(@Obj, Round(15*(rad-m)/rad), _angle);
1052 positionChanged(); // this updates spatial accelerators
1053 end;
1054 end;
1055 end;
1057 procedure g_Weapon_Init();
1058 begin
1059 CreateWaterMap();
1060 end;
1062 procedure g_Weapon_Free();
1063 var
1064 i: Integer;
1065 begin
1066 if Shots <> nil then
1067 begin
1068 for i := 0 to High(Shots) do
1069 if Shots[i].ShotType <> 0 then
1070 Shots[i].Animation.Free();
1072 Shots := nil;
1073 end;
1075 WaterMap := nil;
1076 end;
1078 procedure g_Weapon_LoadData();
1079 begin
1080 e_WriteLog('Loading weapons data...', MSG_NOTIFY);
1082 g_Sound_CreateWADEx('SOUND_WEAPON_HITPUNCH', GameWAD+':SOUNDS\HITPUNCH');
1083 g_Sound_CreateWADEx('SOUND_WEAPON_MISSPUNCH', GameWAD+':SOUNDS\MISSPUNCH');
1084 g_Sound_CreateWADEx('SOUND_WEAPON_HITBERSERK', GameWAD+':SOUNDS\HITBERSERK');
1085 g_Sound_CreateWADEx('SOUND_WEAPON_MISSBERSERK', GameWAD+':SOUNDS\MISSBERSERK');
1086 g_Sound_CreateWADEx('SOUND_WEAPON_SELECTSAW', GameWAD+':SOUNDS\SELECTSAW');
1087 g_Sound_CreateWADEx('SOUND_WEAPON_IDLESAW', GameWAD+':SOUNDS\IDLESAW');
1088 g_Sound_CreateWADEx('SOUND_WEAPON_HITSAW', GameWAD+':SOUNDS\HITSAW');
1089 g_Sound_CreateWADEx('SOUND_WEAPON_FIRESHOTGUN2', GameWAD+':SOUNDS\FIRESHOTGUN2');
1090 g_Sound_CreateWADEx('SOUND_WEAPON_FIRESHOTGUN', GameWAD+':SOUNDS\FIRESHOTGUN');
1091 g_Sound_CreateWADEx('SOUND_WEAPON_FIRESAW', GameWAD+':SOUNDS\FIRESAW');
1092 g_Sound_CreateWADEx('SOUND_WEAPON_FIREROCKET', GameWAD+':SOUNDS\FIREROCKET');
1093 g_Sound_CreateWADEx('SOUND_WEAPON_FIREPLASMA', GameWAD+':SOUNDS\FIREPLASMA');
1094 g_Sound_CreateWADEx('SOUND_WEAPON_FIREPISTOL', GameWAD+':SOUNDS\FIREPISTOL');
1095 g_Sound_CreateWADEx('SOUND_WEAPON_FIRECGUN', GameWAD+':SOUNDS\FIRECGUN');
1096 g_Sound_CreateWADEx('SOUND_WEAPON_FIREBFG', GameWAD+':SOUNDS\FIREBFG');
1097 g_Sound_CreateWADEx('SOUND_FIRE', GameWAD+':SOUNDS\FIRE');
1098 g_Sound_CreateWADEx('SOUND_WEAPON_STARTFIREBFG', GameWAD+':SOUNDS\STARTFIREBFG');
1099 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEROCKET', GameWAD+':SOUNDS\EXPLODEROCKET');
1100 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEBFG', GameWAD+':SOUNDS\EXPLODEBFG');
1101 g_Sound_CreateWADEx('SOUND_WEAPON_BFGWATER', GameWAD+':SOUNDS\BFGWATER');
1102 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEPLASMA', GameWAD+':SOUNDS\EXPLODEPLASMA');
1103 g_Sound_CreateWADEx('SOUND_WEAPON_PLASMAWATER', GameWAD+':SOUNDS\PLASMAWATER');
1104 g_Sound_CreateWADEx('SOUND_WEAPON_FIREBALL', GameWAD+':SOUNDS\FIREBALL');
1105 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEBALL', GameWAD+':SOUNDS\EXPLODEBALL');
1106 g_Sound_CreateWADEx('SOUND_WEAPON_FIREREV', GameWAD+':SOUNDS\FIREREV');
1107 g_Sound_CreateWADEx('SOUND_PLAYER_JETFLY', GameWAD+':SOUNDS\WORKJETPACK');
1108 g_Sound_CreateWADEx('SOUND_PLAYER_JETON', GameWAD+':SOUNDS\STARTJETPACK');
1109 g_Sound_CreateWADEx('SOUND_PLAYER_JETOFF', GameWAD+':SOUNDS\STOPJETPACK');
1110 g_Sound_CreateWADEx('SOUND_PLAYER_CASING1', GameWAD+':SOUNDS\CASING1');
1111 g_Sound_CreateWADEx('SOUND_PLAYER_CASING2', GameWAD+':SOUNDS\CASING2');
1112 g_Sound_CreateWADEx('SOUND_PLAYER_SHELL1', GameWAD+':SOUNDS\SHELL1');
1113 g_Sound_CreateWADEx('SOUND_PLAYER_SHELL2', GameWAD+':SOUNDS\SHELL2');
1115 g_Texture_CreateWADEx('TEXTURE_WEAPON_ROCKET', GameWAD+':TEXTURES\BROCKET');
1116 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_SKELFIRE', GameWAD+':TEXTURES\BSKELFIRE', 64, 16, 2);
1117 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_BFG', GameWAD+':TEXTURES\BBFG', 64, 64, 2);
1118 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_PLASMA', GameWAD+':TEXTURES\BPLASMA', 16, 16, 2);
1119 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_IMPFIRE', GameWAD+':TEXTURES\BIMPFIRE', 16, 16, 2);
1120 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_BSPFIRE', GameWAD+':TEXTURES\BBSPFIRE', 16, 16, 2);
1121 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_CACOFIRE', GameWAD+':TEXTURES\BCACOFIRE', 16, 16, 2);
1122 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_BARONFIRE', GameWAD+':TEXTURES\BBARONFIRE', 64, 16, 2);
1123 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_MANCUBFIRE', GameWAD+':TEXTURES\BMANCUBFIRE', 64, 32, 2);
1124 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_ROCKET', GameWAD+':TEXTURES\EROCKET', 128, 128, 6);
1125 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_SKELFIRE', GameWAD+':TEXTURES\ESKELFIRE', 64, 64, 3);
1126 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_BFG', GameWAD+':TEXTURES\EBFG', 128, 128, 6);
1127 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_IMPFIRE', GameWAD+':TEXTURES\EIMPFIRE', 64, 64, 3);
1128 g_Frames_CreateWAD(nil, 'FRAMES_BFGHIT', GameWAD+':TEXTURES\BFGHIT', 64, 64, 4);
1129 g_Frames_CreateWAD(nil, 'FRAMES_FIRE', GameWAD+':TEXTURES\FIRE', 64, 128, 8);
1130 g_Frames_CreateWAD(nil, 'FRAMES_FLAME', GameWAD+':TEXTURES\FLAME', 32, 32, 11);
1131 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_PLASMA', GameWAD+':TEXTURES\EPLASMA', 32, 32, 4, True);
1132 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_BSPFIRE', GameWAD+':TEXTURES\EBSPFIRE', 32, 32, 5);
1133 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_CACOFIRE', GameWAD+':TEXTURES\ECACOFIRE', 64, 64, 3);
1134 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_BARONFIRE', GameWAD+':TEXTURES\EBARONFIRE', 64, 64, 3);
1135 g_Frames_CreateWAD(nil, 'FRAMES_SMOKE', GameWAD+':TEXTURES\SMOKE', 32, 32, 10, False);
1137 g_Texture_CreateWADEx('TEXTURE_SHELL_BULLET', GameWAD+':TEXTURES\EBULLET');
1138 g_Texture_CreateWADEx('TEXTURE_SHELL_SHELL', GameWAD+':TEXTURES\ESHELL');
1139 end;
1141 procedure g_Weapon_FreeData();
1142 begin
1143 e_WriteLog('Releasing weapons data...', MSG_NOTIFY);
1145 g_Sound_Delete('SOUND_WEAPON_HITPUNCH');
1146 g_Sound_Delete('SOUND_WEAPON_MISSPUNCH');
1147 g_Sound_Delete('SOUND_WEAPON_HITBERSERK');
1148 g_Sound_Delete('SOUND_WEAPON_MISSBERSERK');
1149 g_Sound_Delete('SOUND_WEAPON_SELECTSAW');
1150 g_Sound_Delete('SOUND_WEAPON_IDLESAW');
1151 g_Sound_Delete('SOUND_WEAPON_HITSAW');
1152 g_Sound_Delete('SOUND_WEAPON_FIRESHOTGUN2');
1153 g_Sound_Delete('SOUND_WEAPON_FIRESHOTGUN');
1154 g_Sound_Delete('SOUND_WEAPON_FIRESAW');
1155 g_Sound_Delete('SOUND_WEAPON_FIREROCKET');
1156 g_Sound_Delete('SOUND_WEAPON_FIREPLASMA');
1157 g_Sound_Delete('SOUND_WEAPON_FIREPISTOL');
1158 g_Sound_Delete('SOUND_WEAPON_FIRECGUN');
1159 g_Sound_Delete('SOUND_WEAPON_FIREBFG');
1160 g_Sound_Delete('SOUND_FIRE');
1161 g_Sound_Delete('SOUND_WEAPON_STARTFIREBFG');
1162 g_Sound_Delete('SOUND_WEAPON_EXPLODEROCKET');
1163 g_Sound_Delete('SOUND_WEAPON_EXPLODEBFG');
1164 g_Sound_Delete('SOUND_WEAPON_BFGWATER');
1165 g_Sound_Delete('SOUND_WEAPON_EXPLODEPLASMA');
1166 g_Sound_Delete('SOUND_WEAPON_PLASMAWATER');
1167 g_Sound_Delete('SOUND_WEAPON_FIREBALL');
1168 g_Sound_Delete('SOUND_WEAPON_EXPLODEBALL');
1169 g_Sound_Delete('SOUND_WEAPON_FIREREV');
1170 g_Sound_Delete('SOUND_PLAYER_JETFLY');
1171 g_Sound_Delete('SOUND_PLAYER_JETON');
1172 g_Sound_Delete('SOUND_PLAYER_JETOFF');
1173 g_Sound_Delete('SOUND_PLAYER_CASING1');
1174 g_Sound_Delete('SOUND_PLAYER_CASING2');
1175 g_Sound_Delete('SOUND_PLAYER_SHELL1');
1176 g_Sound_Delete('SOUND_PLAYER_SHELL2');
1178 g_Texture_Delete('TEXTURE_WEAPON_ROCKET');
1179 g_Frames_DeleteByName('FRAMES_WEAPON_BFG');
1180 g_Frames_DeleteByName('FRAMES_WEAPON_PLASMA');
1181 g_Frames_DeleteByName('FRAMES_WEAPON_IMPFIRE');
1182 g_Frames_DeleteByName('FRAMES_WEAPON_BSPFIRE');
1183 g_Frames_DeleteByName('FRAMES_WEAPON_CACOFIRE');
1184 g_Frames_DeleteByName('FRAMES_WEAPON_MANCUBFIRE');
1185 g_Frames_DeleteByName('FRAMES_EXPLODE_ROCKET');
1186 g_Frames_DeleteByName('FRAMES_EXPLODE_BFG');
1187 g_Frames_DeleteByName('FRAMES_EXPLODE_IMPFIRE');
1188 g_Frames_DeleteByName('FRAMES_BFGHIT');
1189 g_Frames_DeleteByName('FRAMES_FIRE');
1190 g_Frames_DeleteByName('FRAMES_EXPLODE_PLASMA');
1191 g_Frames_DeleteByName('FRAMES_EXPLODE_BSPFIRE');
1192 g_Frames_DeleteByName('FRAMES_EXPLODE_CACOFIRE');
1193 g_Frames_DeleteByName('FRAMES_SMOKE');
1194 g_Frames_DeleteByName('FRAMES_WEAPON_BARONFIRE');
1195 g_Frames_DeleteByName('FRAMES_EXPLODE_BARONFIRE');
1196 end;
1198 procedure g_Weapon_gun(x, y, xd, yd, v, dmg: Integer; SpawnerUID: Word; CheckTrigger: Boolean);
1199 var
1200 a: Integer;
1201 x2, y2: Integer;
1202 dx, dy: Integer;
1203 xe, ye: Integer;
1204 xi, yi: Integer;
1205 s, c: Extended;
1206 //vx, vy: Integer;
1207 xx, yy, d: Integer;
1209 i: Integer;
1210 t1, _collide: Boolean;
1211 w, h: Word;
1212 begin
1213 a := GetAngle(x, y, xd, yd)+180;
1215 SinCos(DegToRad(-a), s, c);
1217 if Abs(s) < 0.01 then s := 0;
1218 if Abs(c) < 0.01 then c := 0;
1220 x2 := x+Round(c*gMapInfo.Width);
1221 y2 := y+Round(s*gMapInfo.Width);
1223 t1 := gWalls <> nil;
1224 _collide := False;
1225 w := gMapInfo.Width;
1226 h := gMapInfo.Height;
1228 xe := 0;
1229 ye := 0;
1230 dx := x2-x;
1231 dy := y2-y;
1233 if (xd = 0) and (yd = 0) then Exit;
1235 if dx > 0 then xi := 1 else if dx < 0 then xi := -1 else xi := 0;
1236 if dy > 0 then yi := 1 else if dy < 0 then yi := -1 else yi := 0;
1238 dx := Abs(dx);
1239 dy := Abs(dy);
1241 if dx > dy then d := dx else d := dy;
1243 //blood vel, for Monster.Damage()
1244 //vx := (dx*10 div d)*xi;
1245 //vy := (dy*10 div d)*yi;
1247 xx := x;
1248 yy := y;
1250 for i := 1 to d do
1251 begin
1252 xe := xe+dx;
1253 ye := ye+dy;
1255 if xe > d then
1256 begin
1257 xe := xe-d;
1258 xx := xx+xi;
1259 end;
1261 if ye > d then
1262 begin
1263 ye := ye-d;
1264 yy := yy+yi;
1265 end;
1267 if (yy > h) or (yy < 0) then Break;
1268 if (xx > w) or (xx < 0) then Break;
1270 if t1 then
1271 if ByteBool(gCollideMap[yy, xx] and MARK_BLOCKED) then
1272 begin
1273 _collide := True;
1274 g_GFX_Spark(xx-xi, yy-yi, 2+Random(2), 180+a, 0, 0);
1275 if g_Game_IsServer and g_Game_IsNet then
1276 MH_SEND_Effect(xx-xi, yy-yi, 180+a, NET_GFX_SPARK);
1277 end;
1279 if not _collide then
1280 _collide := GunHit(xx, yy, xi*v, yi*v, dmg, SpawnerUID, v <> 0) <> 0;
1282 if _collide then
1283 Break;
1284 end;
1286 if CheckTrigger and g_Game_IsServer then
1287 g_Triggers_PressL(X, Y, xx-xi, yy-yi, SpawnerUID, ACTIVATE_SHOT);
1288 end;
1290 procedure g_Weapon_punch(x, y: Integer; d, SpawnerUID: Word);
1291 var
1292 obj: TObj;
1293 begin
1294 obj.X := X;
1295 obj.Y := Y;
1296 obj.rect.X := 0;
1297 obj.rect.Y := 0;
1298 obj.rect.Width := 39;
1299 obj.rect.Height := 52;
1300 obj.Vel.X := 0;
1301 obj.Vel.Y := 0;
1302 obj.Accel.X := 0;
1303 obj.Accel.Y := 0;
1305 if g_Weapon_Hit(@obj, d, SpawnerUID, HIT_SOME) <> 0 then
1306 g_Sound_PlayExAt('SOUND_WEAPON_HITPUNCH', x, y)
1307 else
1308 g_Sound_PlayExAt('SOUND_WEAPON_MISSPUNCH', x, y);
1309 end;
1311 function g_Weapon_chainsaw(x, y: Integer; d, SpawnerUID: Word): Integer;
1312 var
1313 obj: TObj;
1314 begin
1315 obj.X := X;
1316 obj.Y := Y;
1317 obj.rect.X := 0;
1318 obj.rect.Y := 0;
1319 obj.rect.Width := 32;
1320 obj.rect.Height := 52;
1321 obj.Vel.X := 0;
1322 obj.Vel.Y := 0;
1323 obj.Accel.X := 0;
1324 obj.Accel.Y := 0;
1326 Result := g_Weapon_Hit(@obj, d, SpawnerUID, HIT_SOME);
1327 end;
1329 procedure g_Weapon_rocket(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1330 Silent: Boolean = False);
1331 var
1332 find_id: DWORD;
1333 dx, dy: Integer;
1334 begin
1335 if WID < 0 then
1336 find_id := FindShot()
1337 else
1338 begin
1339 find_id := WID;
1340 if Integer(find_id) >= High(Shots) then
1341 SetLength(Shots, find_id + 64)
1342 end;
1344 with Shots[find_id] do
1345 begin
1346 g_Obj_Init(@Obj);
1348 Obj.Rect.Width := SHOT_ROCKETLAUNCHER_WIDTH;
1349 Obj.Rect.Height := SHOT_ROCKETLAUNCHER_HEIGHT;
1351 dx := IfThen(xd > x, -Obj.Rect.Width, 0);
1352 dy := -(Obj.Rect.Height div 2);
1354 ShotType := WEAPON_ROCKETLAUNCHER;
1355 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 12);
1357 Animation := nil;
1358 triggers := nil;
1359 g_Texture_Get('TEXTURE_WEAPON_ROCKET', TextureID);
1360 end;
1362 Shots[find_id].SpawnerUID := SpawnerUID;
1364 if not Silent then
1365 g_Sound_PlayExAt('SOUND_WEAPON_FIREROCKET', x, y);
1366 end;
1368 procedure g_Weapon_revf(x, y, xd, yd: Integer; SpawnerUID, TargetUID: Word;
1369 WID: Integer = -1; Silent: Boolean = False);
1370 var
1371 find_id, FramesID: DWORD;
1372 dx, dy: Integer;
1373 begin
1374 if WID < 0 then
1375 find_id := FindShot()
1376 else
1377 begin
1378 find_id := WID;
1379 if Integer(find_id) >= High(Shots) then
1380 SetLength(Shots, find_id + 64)
1381 end;
1383 with Shots[find_id] do
1384 begin
1385 g_Obj_Init(@Obj);
1387 Obj.Rect.Width := SHOT_SKELFIRE_WIDTH;
1388 Obj.Rect.Height := SHOT_SKELFIRE_HEIGHT;
1390 dx := -(Obj.Rect.Width div 2);
1391 dy := -(Obj.Rect.Height div 2);
1393 ShotType := WEAPON_SKEL_FIRE;
1394 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 12);
1396 triggers := nil;
1397 target := TargetUID;
1398 g_Frames_Get(FramesID, 'FRAMES_WEAPON_SKELFIRE');
1399 Animation := TAnimation.Create(FramesID, True, 5);
1400 end;
1402 Shots[find_id].SpawnerUID := SpawnerUID;
1404 if not Silent then
1405 g_Sound_PlayExAt('SOUND_WEAPON_FIREREV', x, y);
1406 end;
1408 procedure g_Weapon_plasma(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1409 Silent: Boolean = False);
1410 var
1411 find_id, FramesID: DWORD;
1412 dx, dy: Integer;
1413 begin
1414 if WID < 0 then
1415 find_id := FindShot()
1416 else
1417 begin
1418 find_id := WID;
1419 if Integer(find_id) >= High(Shots) then
1420 SetLength(Shots, find_id + 64);
1421 end;
1423 with Shots[find_id] do
1424 begin
1425 g_Obj_Init(@Obj);
1427 Obj.Rect.Width := SHOT_PLASMA_WIDTH;
1428 Obj.Rect.Height := SHOT_PLASMA_HEIGHT;
1430 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1431 dy := -(Obj.Rect.Height div 2);
1433 ShotType := WEAPON_PLASMA;
1434 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1436 triggers := nil;
1437 g_Frames_Get(FramesID, 'FRAMES_WEAPON_PLASMA');
1438 Animation := TAnimation.Create(FramesID, True, 5);
1439 end;
1441 Shots[find_id].SpawnerUID := SpawnerUID;
1443 if not Silent then
1444 g_Sound_PlayExAt('SOUND_WEAPON_FIREPLASMA', x, y);
1445 end;
1447 procedure g_Weapon_flame(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1448 Silent: Boolean = False);
1449 var
1450 find_id: DWORD;
1451 dx, dy: Integer;
1452 begin
1453 if WID < 0 then
1454 find_id := FindShot()
1455 else
1456 begin
1457 find_id := WID;
1458 if Integer(find_id) >= High(Shots) then
1459 SetLength(Shots, find_id + 64);
1460 end;
1462 with Shots[find_id] do
1463 begin
1464 g_Obj_Init(@Obj);
1466 Obj.Rect.Width := SHOT_FLAME_WIDTH;
1467 Obj.Rect.Height := SHOT_FLAME_HEIGHT;
1469 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1470 dy := -(Obj.Rect.Height div 2);
1472 ShotType := WEAPON_FLAMETHROWER;
1473 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1475 triggers := nil;
1476 Animation := nil;
1477 TextureID := 0;
1478 g_Frames_Get(TextureID, 'FRAMES_FLAME');
1479 end;
1481 Shots[find_id].SpawnerUID := SpawnerUID;
1483 // if not Silent then
1484 // g_Sound_PlayExAt('SOUND_WEAPON_FIREPLASMA', x, y);
1485 end;
1487 procedure g_Weapon_ball1(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1488 Silent: Boolean = False);
1489 var
1490 find_id, FramesID: DWORD;
1491 dx, dy: Integer;
1492 begin
1493 if WID < 0 then
1494 find_id := FindShot()
1495 else
1496 begin
1497 find_id := WID;
1498 if Integer(find_id) >= High(Shots) then
1499 SetLength(Shots, find_id + 64)
1500 end;
1502 with Shots[find_id] do
1503 begin
1504 g_Obj_Init(@Obj);
1506 Obj.Rect.Width := 16;
1507 Obj.Rect.Height := 16;
1509 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1510 dy := -(Obj.Rect.Height div 2);
1512 ShotType := WEAPON_IMP_FIRE;
1513 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1515 triggers := nil;
1516 g_Frames_Get(FramesID, 'FRAMES_WEAPON_IMPFIRE');
1517 Animation := TAnimation.Create(FramesID, True, 4);
1518 end;
1520 Shots[find_id].SpawnerUID := SpawnerUID;
1522 if not Silent then
1523 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x, y);
1524 end;
1526 procedure g_Weapon_ball2(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1527 Silent: Boolean = False);
1528 var
1529 find_id, FramesID: DWORD;
1530 dx, dy: Integer;
1531 begin
1532 if WID < 0 then
1533 find_id := FindShot()
1534 else
1535 begin
1536 find_id := WID;
1537 if Integer(find_id) >= High(Shots) then
1538 SetLength(Shots, find_id + 64)
1539 end;
1541 with Shots[find_id] do
1542 begin
1543 g_Obj_Init(@Obj);
1545 Obj.Rect.Width := 16;
1546 Obj.Rect.Height := 16;
1548 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1549 dy := -(Obj.Rect.Height div 2);
1551 ShotType := WEAPON_CACO_FIRE;
1552 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1554 triggers := nil;
1555 g_Frames_Get(FramesID, 'FRAMES_WEAPON_CACOFIRE');
1556 Animation := TAnimation.Create(FramesID, True, 4);
1557 end;
1559 Shots[find_id].SpawnerUID := SpawnerUID;
1561 if not Silent then
1562 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x, y);
1563 end;
1565 procedure g_Weapon_ball7(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1566 Silent: Boolean = False);
1567 var
1568 find_id, FramesID: DWORD;
1569 dx, dy: Integer;
1570 begin
1571 if WID < 0 then
1572 find_id := FindShot()
1573 else
1574 begin
1575 find_id := WID;
1576 if Integer(find_id) >= High(Shots) then
1577 SetLength(Shots, find_id + 64)
1578 end;
1580 with Shots[find_id] do
1581 begin
1582 g_Obj_Init(@Obj);
1584 Obj.Rect.Width := 32;
1585 Obj.Rect.Height := 16;
1587 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1588 dy := -(Obj.Rect.Height div 2);
1590 ShotType := WEAPON_BARON_FIRE;
1591 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1593 triggers := nil;
1594 g_Frames_Get(FramesID, 'FRAMES_WEAPON_BARONFIRE');
1595 Animation := TAnimation.Create(FramesID, True, 4);
1596 end;
1598 Shots[find_id].SpawnerUID := SpawnerUID;
1600 if not Silent then
1601 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x, y);
1602 end;
1604 procedure g_Weapon_aplasma(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1605 Silent: Boolean = False);
1606 var
1607 find_id, FramesID: DWORD;
1608 dx, dy: Integer;
1609 begin
1610 if WID < 0 then
1611 find_id := FindShot()
1612 else
1613 begin
1614 find_id := WID;
1615 if Integer(find_id) >= High(Shots) then
1616 SetLength(Shots, find_id + 64)
1617 end;
1619 with Shots[find_id] do
1620 begin
1621 g_Obj_Init(@Obj);
1623 Obj.Rect.Width := 16;
1624 Obj.Rect.Height := 16;
1626 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1627 dy := -(Obj.Rect.Height div 2);
1629 ShotType := WEAPON_BSP_FIRE;
1630 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1632 triggers := nil;
1634 g_Frames_Get(FramesID, 'FRAMES_WEAPON_BSPFIRE');
1635 Animation := TAnimation.Create(FramesID, True, 4);
1636 end;
1638 Shots[find_id].SpawnerUID := SpawnerUID;
1640 if not Silent then
1641 g_Sound_PlayExAt('SOUND_WEAPON_FIREPLASMA', x, y);
1642 end;
1644 procedure g_Weapon_manfire(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1645 Silent: Boolean = False);
1646 var
1647 find_id, FramesID: DWORD;
1648 dx, dy: Integer;
1649 begin
1650 if WID < 0 then
1651 find_id := FindShot()
1652 else
1653 begin
1654 find_id := WID;
1655 if Integer(find_id) >= High(Shots) then
1656 SetLength(Shots, find_id + 64)
1657 end;
1659 with Shots[find_id] do
1660 begin
1661 g_Obj_Init(@Obj);
1663 Obj.Rect.Width := 32;
1664 Obj.Rect.Height := 32;
1666 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1667 dy := -(Obj.Rect.Height div 2);
1669 ShotType := WEAPON_MANCUB_FIRE;
1670 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1672 triggers := nil;
1674 g_Frames_Get(FramesID, 'FRAMES_WEAPON_MANCUBFIRE');
1675 Animation := TAnimation.Create(FramesID, True, 4);
1676 end;
1678 Shots[find_id].SpawnerUID := SpawnerUID;
1680 if not Silent then
1681 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x, y);
1682 end;
1684 procedure g_Weapon_bfgshot(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1685 Silent: Boolean = False);
1686 var
1687 find_id, FramesID: DWORD;
1688 dx, dy: Integer;
1689 begin
1690 if WID < 0 then
1691 find_id := FindShot()
1692 else
1693 begin
1694 find_id := WID;
1695 if Integer(find_id) >= High(Shots) then
1696 SetLength(Shots, find_id + 64)
1697 end;
1699 with Shots[find_id] do
1700 begin
1701 g_Obj_Init(@Obj);
1703 Obj.Rect.Width := SHOT_BFG_WIDTH;
1704 Obj.Rect.Height := SHOT_BFG_HEIGHT;
1706 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1707 dy := -(Obj.Rect.Height div 2);
1709 ShotType := WEAPON_BFG;
1710 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1712 triggers := nil;
1713 g_Frames_Get(FramesID, 'FRAMES_WEAPON_BFG');
1714 Animation := TAnimation.Create(FramesID, True, 6);
1715 end;
1717 Shots[find_id].SpawnerUID := SpawnerUID;
1719 if not Silent then
1720 g_Sound_PlayExAt('SOUND_WEAPON_FIREBFG', x, y);
1721 end;
1723 procedure g_Weapon_bfghit(x, y: Integer);
1724 var
1725 ID: DWORD;
1726 Anim: TAnimation;
1727 begin
1728 if g_Frames_Get(ID, 'FRAMES_BFGHIT') then
1729 begin
1730 Anim := TAnimation.Create(ID, False, 4);
1731 g_GFX_OnceAnim(x-32, y-32, Anim);
1732 Anim.Free();
1733 end;
1734 end;
1736 procedure g_Weapon_pistol(x, y, xd, yd: Integer; SpawnerUID: Word;
1737 Silent: Boolean = False);
1738 begin
1739 if not Silent then
1740 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', x, y);
1742 g_Weapon_gun(x, y, xd, yd, 1, 3, SpawnerUID, True);
1743 if gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF] then
1744 begin
1745 g_Weapon_gun(x, y+1, xd, yd+1, 1, 3, SpawnerUID, False);
1746 g_Weapon_gun(x, y-1, xd, yd-1, 1, 2, SpawnerUID, False);
1747 end;
1748 end;
1750 procedure g_Weapon_mgun(x, y, xd, yd: Integer; SpawnerUID: Word;
1751 Silent: Boolean = False);
1752 begin
1753 if not Silent then
1754 if gSoundEffectsDF then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', x, y);
1756 g_Weapon_gun(x, y, xd, yd, 1, 3, SpawnerUID, True);
1757 if (gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF]) and
1758 (g_GetUIDType(SpawnerUID) = UID_PLAYER) then
1759 begin
1760 g_Weapon_gun(x, y+1, xd, yd+1, 1, 2, SpawnerUID, False);
1761 g_Weapon_gun(x, y-1, xd, yd-1, 1, 2, SpawnerUID, False);
1762 end;
1763 end;
1765 procedure g_Weapon_shotgun(x, y, xd, yd: Integer; SpawnerUID: Word;
1766 Silent: Boolean = False);
1767 var
1768 i, j: Integer;
1769 begin
1770 if not Silent then
1771 if gSoundEffectsDF then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', x, y);
1773 for i := 0 to 9 do
1774 begin
1775 j := Random(17)-8; // -8 .. 8
1776 g_Weapon_gun(x, y+j, xd, yd+j, IfThen(i mod 2 <> 0, 1, 0), 3, SpawnerUID, i=0);
1777 end;
1778 end;
1780 procedure g_Weapon_dshotgun(x, y, xd, yd: Integer; SpawnerUID: Word;
1781 Silent: Boolean = False);
1782 var
1783 a, i, j: Integer;
1784 begin
1785 if not Silent then
1786 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', x, y);
1788 if gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF] then a := 25 else a := 20;
1789 for i := 0 to a do
1790 begin
1791 j := Random(41)-20; // -20 .. 20
1792 g_Weapon_gun(x, y+j, xd, yd+j, IfThen(i mod 3 <> 0, 0, 1), 3, SpawnerUID, i=0);
1793 end;
1794 end;
1796 procedure g_Weapon_Update();
1797 var
1798 i, a, h, cx, cy, oldvx, oldvy, tf: Integer;
1799 _id: DWORD;
1800 Anim: TAnimation;
1801 t: DWArray;
1802 st: Word;
1803 s: String;
1804 o: TObj;
1805 spl: Boolean;
1806 Loud: Boolean;
1807 tcx, tcy: Integer;
1808 begin
1809 if Shots = nil then
1810 Exit;
1812 for i := 0 to High(Shots) do
1813 begin
1814 if Shots[i].ShotType = 0 then
1815 Continue;
1817 Loud := True;
1819 with Shots[i] do
1820 begin
1821 Timeout := Timeout - 1;
1822 oldvx := Obj.Vel.X;
1823 oldvy := Obj.Vel.Y;
1824 // Àêòèâèðîâàòü òðèããåðû ïî ïóòè (êðîìå óæå àêòèâèðîâàííûõ):
1825 if (Stopped = 0) and g_Game_IsServer then
1826 t := g_Triggers_PressR(Obj.X, Obj.Y, Obj.Rect.Width, Obj.Rect.Height,
1827 SpawnerUID, ACTIVATE_SHOT, triggers)
1828 else
1829 t := nil;
1831 if t <> nil then
1832 begin
1833 // Ïîïîëíÿåì ñïèñîê àêòèâèðîâàííûõ òðèããåðîâ:
1834 if triggers = nil then
1835 triggers := t
1836 else
1837 begin
1838 h := High(t);
1840 for a := 0 to h do
1841 if not InDWArray(t[a], triggers) then
1842 begin
1843 SetLength(triggers, Length(triggers)+1);
1844 triggers[High(triggers)] := t[a];
1845 end;
1846 end;
1847 end;
1849 // Àíèìàöèÿ ñíàðÿäà:
1850 if Animation <> nil then
1851 Animation.Update();
1853 // Äâèæåíèå:
1854 spl := (ShotType <> WEAPON_PLASMA) and
1855 (ShotType <> WEAPON_BFG) and
1856 (ShotType <> WEAPON_BSP_FIRE) and
1857 (ShotType <> WEAPON_FLAMETHROWER);
1859 if Stopped = 0 then
1860 begin
1861 st := g_Obj_Move(@Obj, False, spl);
1862 end
1863 else
1864 begin
1865 st := 0;
1866 end;
1867 positionChanged(); // this updates spatial accelerators
1869 if WordBool(st and MOVE_FALLOUT) or (Obj.X < -1000) or
1870 (Obj.X > gMapInfo.Width+1000) or (Obj.Y < -1000) then
1871 begin
1872 // Íà êëèåíòå ñêîðåå âñåãî è òàê óæå âûïàë.
1873 ShotType := 0;
1874 Animation.Free();
1875 Continue;
1876 end;
1878 cx := Obj.X + (Obj.Rect.Width div 2);
1879 cy := Obj.Y + (Obj.Rect.Height div 2);
1881 case ShotType of
1882 WEAPON_ROCKETLAUNCHER, WEAPON_SKEL_FIRE: // Ðàêåòû è ñíàðÿäû Ñêåëåòà
1883 begin
1884 // Âûëåòåëà èç âîäû:
1885 if WordBool(st and MOVE_HITAIR) then
1886 g_Obj_SetSpeed(@Obj, 12);
1888 // Â âîäå øëåéô - ïóçûðè, â âîçäóõå øëåéô - äûì:
1889 if WordBool(st and MOVE_INWATER) then
1890 g_GFX_Bubbles(Obj.X+(Obj.Rect.Width div 2),
1891 Obj.Y+(Obj.Rect.Height div 2),
1892 1+Random(3), 16, 16)
1893 else
1894 if g_Frames_Get(_id, 'FRAMES_SMOKE') then
1895 begin
1896 Anim := TAnimation.Create(_id, False, 3);
1897 Anim.Alpha := 150;
1898 g_GFX_OnceAnim(Obj.X-14+Random(9),
1899 Obj.Y+(Obj.Rect.Height div 2)-20+Random(9),
1900 Anim, ONCEANIM_SMOKE);
1901 Anim.Free();
1902 end;
1904 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
1905 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL)) or
1906 (g_Weapon_Hit(@Obj, 10, SpawnerUID, HIT_SOME, False) <> 0) or
1907 (Timeout < 1) then
1908 begin
1909 Obj.Vel.X := 0;
1910 Obj.Vel.Y := 0;
1912 g_Weapon_Explode(cx, cy, 60, SpawnerUID);
1914 if ShotType = WEAPON_SKEL_FIRE then
1915 begin // Âçðûâ ñíàðÿäà Ñêåëåòà
1916 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_SKELFIRE') then
1917 begin
1918 Anim := TAnimation.Create(TextureID, False, 8);
1919 Anim.Blending := False;
1920 g_GFX_OnceAnim((Obj.X+32)-58, (Obj.Y+8)-36, Anim);
1921 g_DynLightExplosion((Obj.X+32), (Obj.Y+8), 64, 1, 0, 0);
1922 Anim.Free();
1923 end;
1924 end
1925 else
1926 begin // Âçðûâ Ðàêåòû
1927 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_ROCKET') then
1928 begin
1929 Anim := TAnimation.Create(TextureID, False, 6);
1930 Anim.Blending := False;
1931 g_GFX_OnceAnim(cx-64, cy-64, Anim);
1932 g_DynLightExplosion(cx, cy, 64, 1, 0, 0);
1933 Anim.Free();
1934 end;
1935 end;
1937 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', Obj.X, Obj.Y);
1939 ShotType := 0;
1940 end;
1942 if ShotType = WEAPON_SKEL_FIRE then
1943 begin // Ñàìîíàâîäêà ñíàðÿäà Ñêåëåòà:
1944 if GetPos(target, @o) then
1945 throw(i, Obj.X, Obj.Y,
1946 o.X+o.Rect.X+(o.Rect.Width div 2)+o.Vel.X+o.Accel.X,
1947 o.Y+o.Rect.Y+(o.Rect.Height div 2)+o.Vel.Y+o.Accel.Y,
1948 12);
1949 end;
1950 end;
1952 WEAPON_PLASMA, WEAPON_BSP_FIRE: // Ïëàçìà, ïëàçìà Àðàõíàòðîíà
1953 begin
1954 // Ïîïàëà â âîäó - ýëåêòðîøîê ïî âîäå:
1955 if WordBool(st and (MOVE_INWATER or MOVE_HITWATER)) then
1956 begin
1957 g_Sound_PlayExAt('SOUND_WEAPON_PLASMAWATER', Obj.X, Obj.Y);
1958 if g_Game_IsServer then CheckTrap(i, 10, HIT_ELECTRO);
1959 ShotType := 0;
1960 Continue;
1961 end;
1963 // Âåëè÷èíà óðîíà:
1964 if (ShotType = WEAPON_PLASMA) and
1965 (gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF]) then
1966 a := 10
1967 else
1968 a := 5;
1970 if ShotType = WEAPON_BSP_FIRE then
1971 a := 10;
1973 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
1974 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL)) or
1975 (g_Weapon_Hit(@Obj, a, SpawnerUID, HIT_SOME, False) <> 0) or
1976 (Timeout < 1) then
1977 begin
1978 if ShotType = WEAPON_PLASMA then
1979 s := 'FRAMES_EXPLODE_PLASMA'
1980 else
1981 s := 'FRAMES_EXPLODE_BSPFIRE';
1983 // Âçðûâ Ïëàçìû:
1984 if g_Frames_Get(TextureID, s) then
1985 begin
1986 Anim := TAnimation.Create(TextureID, False, 3);
1987 Anim.Blending := False;
1988 g_GFX_OnceAnim(cx-16, cy-16, Anim);
1989 Anim.Free();
1990 g_DynLightExplosion(cx, cy, 32, 0, 0.5, 0.5);
1991 end;
1993 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEPLASMA', Obj.X, Obj.Y);
1995 ShotType := 0;
1996 end;
1997 end;
1999 WEAPON_FLAMETHROWER: // Îãíåìåò
2000 begin
2001 // Ñî âðåìåíåì óìèðàåò
2002 if (Timeout < 1) then
2003 begin
2004 ShotType := 0;
2005 Continue;
2006 end;
2007 // Ïîä âîäîé òîæå
2008 if WordBool(st and (MOVE_HITWATER or MOVE_INWATER)) then
2009 begin
2010 if WordBool(st and MOVE_HITWATER) then
2011 begin
2012 if g_Frames_Get(_id, 'FRAMES_SMOKE') then
2013 begin
2014 Anim := TAnimation.Create(_id, False, 3);
2015 Anim.Alpha := 0;
2016 tcx := Random(8);
2017 tcy := Random(8);
2018 g_GFX_OnceAnim(cx-4+tcx-(Anim.Width div 2),
2019 cy-4+tcy-(Anim.Height div 2),
2020 Anim, ONCEANIM_SMOKE);
2021 Anim.Free();
2022 end;
2023 end
2024 else
2025 g_GFX_Bubbles(cx, cy, 1+Random(3), 16, 16);
2026 ShotType := 0;
2027 Continue;
2028 end;
2030 // Ãðàâèòàöèÿ
2031 if Stopped = 0 then
2032 Obj.Accel.Y := Obj.Accel.Y + 1;
2033 // Ïîïàëè â ñòåíó èëè â âîäó:
2034 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL or MOVE_HITWATER)) then
2035 begin
2036 // Ïðèëèïàåì:
2037 Obj.Vel.X := 0;
2038 Obj.Vel.Y := 0;
2039 Obj.Accel.Y := 0;
2040 if WordBool(st and MOVE_HITWALL) then
2041 Stopped := MOVE_HITWALL
2042 else if WordBool(st and MOVE_HITLAND) then
2043 Stopped := MOVE_HITLAND
2044 else if WordBool(st and MOVE_HITCEIL) then
2045 Stopped := MOVE_HITCEIL;
2046 end;
2048 a := IfThen(Stopped = 0, 3, 1);
2049 // Åñëè â êîãî-òî ïîïàëè
2050 if g_Weapon_Hit(@Obj, a, SpawnerUID, HIT_FLAME, False) <> 0 then
2051 begin
2052 // HIT_FLAME ñàì ïîäîææåò
2053 // Åñëè â ïîëåòå ïîïàëè, èñ÷åçàåì
2054 if Stopped = 0 then
2055 ShotType := 0;
2056 end;
2058 if Stopped = 0 then
2059 tf := 2
2060 else
2061 tf := 3;
2063 if (gTime mod tf = 0) then
2064 begin
2065 Anim := TAnimation.Create(TextureID, False, 2 + Random(2));
2066 Anim.Alpha := 0;
2067 case Stopped of
2068 MOVE_HITWALL: begin tcx := cx-4+Random(8); tcy := cy-12+Random(24); end;
2069 MOVE_HITLAND: begin tcx := cx-12+Random(24); tcy := cy-10+Random(8); end;
2070 MOVE_HITCEIL: begin tcx := cx-12+Random(24); tcy := cy+6+Random(8); end;
2071 else begin tcx := cx-4+Random(8); tcy := cy-4+Random(8); end;
2072 end;
2073 g_GFX_OnceAnim(tcx-(Anim.Width div 2), tcy-(Anim.Height div 2), Anim, ONCEANIM_SMOKE);
2074 Anim.Free();
2075 //g_DynLightExplosion(tcx, tcy, 1, 1, 0.8, 0.3);
2076 end;
2077 end;
2079 WEAPON_BFG: // BFG
2080 begin
2081 // Ïîïàëà â âîäó - ýëåêòðîøîê ïî âîäå:
2082 if WordBool(st and (MOVE_INWATER or MOVE_HITWATER)) then
2083 begin
2084 g_Sound_PlayExAt('SOUND_WEAPON_BFGWATER', Obj.X, Obj.Y);
2085 if g_Game_IsServer then CheckTrap(i, 1000, HIT_ELECTRO);
2086 ShotType := 0;
2087 Continue;
2088 end;
2090 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2091 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL)) or
2092 (g_Weapon_Hit(@Obj, SHOT_BFG_DAMAGE, SpawnerUID, HIT_BFG, False) <> 0) or
2093 (Timeout < 1) then
2094 begin
2095 // Ëó÷è BFG:
2096 if g_Game_IsServer then g_Weapon_BFG9000(cx, cy, SpawnerUID);
2098 // Âçðûâ BFG:
2099 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_BFG') then
2100 begin
2101 Anim := TAnimation.Create(TextureID, False, 6);
2102 Anim.Blending := False;
2103 g_GFX_OnceAnim(cx-64, cy-64, Anim);
2104 Anim.Free();
2105 g_DynLightExplosion(cx, cy, 96, 0, 1, 0);
2106 end;
2108 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', Obj.X, Obj.Y);
2110 ShotType := 0;
2111 end;
2112 end;
2114 WEAPON_IMP_FIRE, WEAPON_CACO_FIRE, WEAPON_BARON_FIRE: // Âûñòðåëû Áåñà, Êàêîäåìîíà Ðûöàðÿ/Áàðîíà àäà
2115 begin
2116 // Âûëåòåë èç âîäû:
2117 if WordBool(st and MOVE_HITAIR) then
2118 g_Obj_SetSpeed(@Obj, 16);
2120 // Âåëè÷èíà óðîíà:
2121 if ShotType = WEAPON_IMP_FIRE then
2122 a := 5
2123 else
2124 if ShotType = WEAPON_CACO_FIRE then
2125 a := 20
2126 else
2127 a := 40;
2129 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2130 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL)) or
2131 (g_Weapon_Hit(@Obj, a, SpawnerUID, HIT_SOME) <> 0) or
2132 (Timeout < 1) then
2133 begin
2134 if ShotType = WEAPON_IMP_FIRE then
2135 s := 'FRAMES_EXPLODE_IMPFIRE'
2136 else
2137 if ShotType = WEAPON_CACO_FIRE then
2138 s := 'FRAMES_EXPLODE_CACOFIRE'
2139 else
2140 s := 'FRAMES_EXPLODE_BARONFIRE';
2142 // Âçðûâ:
2143 if g_Frames_Get(TextureID, s) then
2144 begin
2145 Anim := TAnimation.Create(TextureID, False, 6);
2146 Anim.Blending := False;
2147 g_GFX_OnceAnim(cx-32, cy-32, Anim);
2148 Anim.Free();
2149 end;
2151 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj.X, Obj.Y);
2153 ShotType := 0;
2154 end;
2155 end;
2157 WEAPON_MANCUB_FIRE: // Âûñòðåë Ìàíêóáóñà
2158 begin
2159 // Âûëåòåë èç âîäû:
2160 if WordBool(st and MOVE_HITAIR) then
2161 g_Obj_SetSpeed(@Obj, 16);
2163 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2164 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL)) or
2165 (g_Weapon_Hit(@Obj, 40, SpawnerUID, HIT_SOME, False) <> 0) or
2166 (Timeout < 1) then
2167 begin
2168 // Âçðûâ:
2169 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_ROCKET') then
2170 begin
2171 Anim := TAnimation.Create(TextureID, False, 6);
2172 Anim.Blending := False;
2173 g_GFX_OnceAnim(cx-64, cy-64, Anim);
2174 Anim.Free();
2175 end;
2177 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj.X, Obj.Y);
2179 ShotType := 0;
2180 end;
2181 end;
2182 end; // case ShotType of...
2184 // Åñëè ñíàðÿäà óæå íåò, óäàëÿåì àíèìàöèþ:
2185 if (ShotType = 0) then
2186 begin
2187 if gGameSettings.GameType = GT_SERVER then
2188 MH_SEND_DeleteShot(i, Obj.X, Obj.Y, Loud);
2189 if Animation <> nil then
2190 begin
2191 Animation.Free();
2192 Animation := nil;
2193 end;
2194 end
2195 else if (ShotType <> WEAPON_FLAMETHROWER) and ((oldvx <> Obj.Vel.X) or (oldvy <> Obj.Vel.Y)) then
2196 if gGameSettings.GameType = GT_SERVER then
2197 MH_SEND_UpdateShot(i);
2198 end;
2199 end;
2200 end;
2202 procedure g_Weapon_Draw();
2203 var
2204 i: Integer;
2205 a: SmallInt;
2206 p: TPoint;
2207 begin
2208 if Shots = nil then
2209 Exit;
2211 for i := 0 to High(Shots) do
2212 if Shots[i].ShotType <> 0 then
2213 with Shots[i] do
2214 begin
2215 if (Shots[i].ShotType = WEAPON_ROCKETLAUNCHER) or
2216 (Shots[i].ShotType = WEAPON_BARON_FIRE) or
2217 (Shots[i].ShotType = WEAPON_MANCUB_FIRE) or
2218 (Shots[i].ShotType = WEAPON_SKEL_FIRE) then
2219 a := -GetAngle2(Obj.Vel.X, Obj.Vel.Y)
2220 else
2221 a := 0;
2223 p.X := Obj.Rect.Width div 2;
2224 p.Y := Obj.Rect.Height div 2;
2226 if Animation <> nil then
2227 begin
2228 if (Shots[i].ShotType = WEAPON_BARON_FIRE) or
2229 (Shots[i].ShotType = WEAPON_MANCUB_FIRE) or
2230 (Shots[i].ShotType = WEAPON_SKEL_FIRE) then
2231 Animation.DrawEx(Obj.X, Obj.Y, M_NONE, p, a)
2232 else
2233 Animation.Draw(Obj.X, Obj.Y, M_NONE);
2234 end
2235 else if TextureID <> 0 then
2236 begin
2237 if (Shots[i].ShotType = WEAPON_ROCKETLAUNCHER) then
2238 e_DrawAdv(TextureID, Obj.X, Obj.Y, 0, True, False, a, @p, M_NONE)
2239 else if (Shots[i].ShotType <> WEAPON_FLAMETHROWER) then
2240 e_Draw(TextureID, Obj.X, Obj.Y, 0, True, False);
2241 end;
2243 if g_debug_Frames then
2244 begin
2245 e_DrawQuad(Obj.X+Obj.Rect.X,
2246 Obj.Y+Obj.Rect.Y,
2247 Obj.X+Obj.Rect.X+Obj.Rect.Width-1,
2248 Obj.Y+Obj.Rect.Y+Obj.Rect.Height-1,
2249 0, 255, 0);
2250 end;
2251 end;
2252 end;
2254 function g_Weapon_Danger(UID: Word; X, Y: Integer; Width, Height: Word; Time: Byte): Boolean;
2255 var
2256 a: Integer;
2257 begin
2258 Result := False;
2260 if Shots = nil then
2261 Exit;
2263 for a := 0 to High(Shots) do
2264 if (Shots[a].ShotType <> 0) and (Shots[a].SpawnerUID <> UID) then
2265 if ((Shots[a].Obj.Vel.Y = 0) and (Shots[a].Obj.Vel.X > 0) and (Shots[a].Obj.X < X)) or
2266 (Shots[a].Obj.Vel.Y = 0) and (Shots[a].Obj.Vel.X < 0) and (Shots[a].Obj.X > X) then
2267 if (Abs(X-Shots[a].Obj.X) < Abs(Shots[a].Obj.Vel.X*Time)) and
2268 g_Collide(X, Y, Width, Height, X, Shots[a].Obj.Y,
2269 Shots[a].Obj.Rect.Width, Shots[a].Obj.Rect.Height) and
2270 g_TraceVector(X, Y, Shots[a].Obj.X, Shots[a].Obj.Y) then
2271 begin
2272 Result := True;
2273 Exit;
2274 end;
2275 end;
2277 procedure g_Weapon_SaveState(var Mem: TBinMemoryWriter);
2278 var
2279 count, i, j: Integer;
2280 dw: DWORD;
2281 begin
2282 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ ñíàðÿäîâ:
2283 count := 0;
2284 if Shots <> nil then
2285 for i := 0 to High(Shots) do
2286 if Shots[i].ShotType <> 0 then
2287 count := count + 1;
2289 Mem := TBinMemoryWriter.Create((count+1) * 80);
2291 // Êîëè÷åñòâî ñíàðÿäîâ:
2292 Mem.WriteInt(count);
2294 if count = 0 then
2295 Exit;
2297 for i := 0 to High(Shots) do
2298 if Shots[i].ShotType <> 0 then
2299 begin
2300 // Ñèãíàòóðà ñíàðÿäà:
2301 dw := SHOT_SIGNATURE; // 'SHOT'
2302 Mem.WriteDWORD(dw);
2303 // Òèï ñíàðÿäà:
2304 Mem.WriteByte(Shots[i].ShotType);
2305 // Öåëü:
2306 Mem.WriteWord(Shots[i].Target);
2307 // UID ñòðåëÿâøåãî:
2308 Mem.WriteWord(Shots[i].SpawnerUID);
2309 // Ðàçìåð ïîëÿ Triggers:
2310 dw := Length(Shots[i].Triggers);
2311 Mem.WriteDWORD(dw);
2312 // Òðèããåðû, àêòèâèðîâàííûå âûñòðåëîì:
2313 for j := 0 to Integer(dw)-1 do
2314 Mem.WriteDWORD(Shots[i].Triggers[j]);
2315 // Îáúåêò ñíàðÿäà:
2316 Obj_SaveState(@Shots[i].Obj, Mem);
2317 // Êîñòûëèíà åáàíàÿ:
2318 Mem.WriteByte(Shots[i].Stopped);
2319 end;
2320 end;
2322 procedure g_Weapon_LoadState(var Mem: TBinMemoryReader);
2323 var
2324 count, i, j: Integer;
2325 dw: DWORD;
2326 begin
2327 if Mem = nil then
2328 Exit;
2330 // Êîëè÷åñòâî ñíàðÿäîâ:
2331 Mem.ReadInt(count);
2333 SetLength(Shots, count);
2335 if count = 0 then
2336 Exit;
2338 for i := 0 to count-1 do
2339 begin
2340 // Ñèãíàòóðà ñíàðÿäà:
2341 Mem.ReadDWORD(dw);
2342 if dw <> SHOT_SIGNATURE then // 'SHOT'
2343 begin
2344 raise EBinSizeError.Create('g_Weapons_LoadState: Wrong Shot Signature');
2345 end;
2346 // Òèï ñíàðÿäà:
2347 Mem.ReadByte(Shots[i].ShotType);
2348 // Öåëü:
2349 Mem.ReadWord(Shots[i].Target);
2350 // UID ñòðåëÿâøåãî:
2351 Mem.ReadWord(Shots[i].SpawnerUID);
2352 // Ðàçìåð ïîëÿ Triggers:
2353 Mem.ReadDWORD(dw);
2354 SetLength(Shots[i].Triggers, dw);
2355 // Òðèããåðû, àêòèâèðîâàííûå âûñòðåëîì:
2356 for j := 0 to Integer(dw)-1 do
2357 Mem.ReadDWORD(Shots[i].Triggers[j]);
2358 // Îáúåêò ïðåäìåòà:
2359 Obj_LoadState(@Shots[i].Obj, Mem);
2360 // Êîñòûëèíà åáàíàÿ:
2361 Mem.ReadByte(Shots[i].Stopped);
2363 // Óñòàíîâêà òåêñòóðû èëè àíèìàöèè:
2364 Shots[i].TextureID := DWORD(-1);
2365 Shots[i].Animation := nil;
2367 case Shots[i].ShotType of
2368 WEAPON_ROCKETLAUNCHER, WEAPON_SKEL_FIRE:
2369 begin
2370 g_Texture_Get('TEXTURE_WEAPON_ROCKET', Shots[i].TextureID);
2371 end;
2372 WEAPON_PLASMA:
2373 begin
2374 g_Frames_Get(dw, 'FRAMES_WEAPON_PLASMA');
2375 Shots[i].Animation := TAnimation.Create(dw, True, 5);
2376 end;
2377 WEAPON_BFG:
2378 begin
2379 g_Frames_Get(dw, 'FRAMES_WEAPON_BFG');
2380 Shots[i].Animation := TAnimation.Create(dw, True, 6);
2381 end;
2382 WEAPON_IMP_FIRE:
2383 begin
2384 g_Frames_Get(dw, 'FRAMES_WEAPON_IMPFIRE');
2385 Shots[i].Animation := TAnimation.Create(dw, True, 4);
2386 end;
2387 WEAPON_BSP_FIRE:
2388 begin
2389 g_Frames_Get(dw, 'FRAMES_WEAPON_BSPFIRE');
2390 Shots[i].Animation := TAnimation.Create(dw, True, 4);
2391 end;
2392 WEAPON_CACO_FIRE:
2393 begin
2394 g_Frames_Get(dw, 'FRAMES_WEAPON_CACOFIRE');
2395 Shots[i].Animation := TAnimation.Create(dw, True, 4);
2396 end;
2397 WEAPON_BARON_FIRE:
2398 begin
2399 g_Frames_Get(dw, 'FRAMES_WEAPON_BARONFIRE');
2400 Shots[i].Animation := TAnimation.Create(dw, True, 4);
2401 end;
2402 WEAPON_MANCUB_FIRE:
2403 begin
2404 g_Frames_Get(dw, 'FRAMES_WEAPON_MANCUBFIRE');
2405 Shots[i].Animation := TAnimation.Create(dw, True, 4);
2406 end;
2407 end;
2408 end;
2409 end;
2411 procedure g_Weapon_DestroyShot(I: Integer; X, Y: Integer; Loud: Boolean = True);
2412 var
2413 cx, cy: Integer;
2414 Anim: TAnimation;
2415 s: string;
2416 begin
2417 if Shots = nil then
2418 Exit;
2419 if (I > High(Shots)) or (I < 0) then Exit;
2421 with Shots[I] do
2422 begin
2423 if ShotType = 0 then Exit;
2424 Obj.X := X;
2425 Obj.Y := Y;
2426 cx := Obj.X + (Obj.Rect.Width div 2);
2427 cy := Obj.Y + (Obj.Rect.Height div 2);
2429 case ShotType of
2430 WEAPON_ROCKETLAUNCHER, WEAPON_SKEL_FIRE: // Ðàêåòû è ñíàðÿäû Ñêåëåòà
2431 begin
2432 if Loud then
2433 begin
2434 if ShotType = WEAPON_SKEL_FIRE then
2435 begin // Âçðûâ ñíàðÿäà Ñêåëåòà
2436 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_SKELFIRE') then
2437 begin
2438 Anim := TAnimation.Create(TextureID, False, 8);
2439 Anim.Blending := False;
2440 g_GFX_OnceAnim((Obj.X+32)-32, (Obj.Y+8)-32, Anim);
2441 Anim.Free();
2442 end;
2443 end
2444 else
2445 begin // Âçðûâ Ðàêåòû
2446 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_ROCKET') then
2447 begin
2448 Anim := TAnimation.Create(TextureID, False, 6);
2449 Anim.Blending := False;
2450 g_GFX_OnceAnim(cx-64, cy-64, Anim);
2451 Anim.Free();
2452 end;
2453 end;
2454 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', Obj.X, Obj.Y);
2455 end;
2456 end;
2458 WEAPON_PLASMA, WEAPON_BSP_FIRE: // Ïëàçìà, ïëàçìà Àðàõíàòðîíà
2459 begin
2460 if ShotType = WEAPON_PLASMA then
2461 s := 'FRAMES_EXPLODE_PLASMA'
2462 else
2463 s := 'FRAMES_EXPLODE_BSPFIRE';
2465 if g_Frames_Get(TextureID, s) and loud then
2466 begin
2467 Anim := TAnimation.Create(TextureID, False, 3);
2468 Anim.Blending := False;
2469 g_GFX_OnceAnim(cx-16, cy-16, Anim);
2470 Anim.Free();
2472 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEPLASMA', Obj.X, Obj.Y);
2473 end;
2474 end;
2476 WEAPON_BFG: // BFG
2477 begin
2478 // Âçðûâ BFG:
2479 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_BFG') and Loud then
2480 begin
2481 Anim := TAnimation.Create(TextureID, False, 6);
2482 Anim.Blending := False;
2483 g_GFX_OnceAnim(cx-64, cy-64, Anim);
2484 Anim.Free();
2486 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', Obj.X, Obj.Y);
2487 end;
2488 end;
2490 WEAPON_IMP_FIRE, WEAPON_CACO_FIRE, WEAPON_BARON_FIRE: // Âûñòðåëû Áåñà, Êàêîäåìîíà Ðûöàðÿ/Áàðîíà àäà
2491 begin
2492 if ShotType = WEAPON_IMP_FIRE then
2493 s := 'FRAMES_EXPLODE_IMPFIRE'
2494 else
2495 if ShotType = WEAPON_CACO_FIRE then
2496 s := 'FRAMES_EXPLODE_CACOFIRE'
2497 else
2498 s := 'FRAMES_EXPLODE_BARONFIRE';
2500 if g_Frames_Get(TextureID, s) and Loud then
2501 begin
2502 Anim := TAnimation.Create(TextureID, False, 6);
2503 Anim.Blending := False;
2504 g_GFX_OnceAnim(cx-32, cy-32, Anim);
2505 Anim.Free();
2507 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj.X, Obj.Y);
2508 end;
2509 end;
2511 WEAPON_MANCUB_FIRE: // Âûñòðåë Ìàíêóáóñà
2512 begin
2513 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_ROCKET') and Loud then
2514 begin
2515 Anim := TAnimation.Create(TextureID, False, 6);
2516 Anim.Blending := False;
2517 g_GFX_OnceAnim(cx-64, cy-64, Anim);
2518 Anim.Free();
2520 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj.X, Obj.Y);
2521 end;
2522 end;
2523 end; // case ShotType of...
2525 ShotType := 0;
2526 Animation.Free();
2527 end;
2528 end;
2531 procedure g_Weapon_AddDynLights();
2532 var
2533 i: Integer;
2534 begin
2535 if Shots = nil then Exit;
2536 for i := 0 to High(Shots) do
2537 begin
2538 if Shots[i].ShotType = 0 then continue;
2539 if (Shots[i].ShotType = WEAPON_ROCKETLAUNCHER) or
2540 (Shots[i].ShotType = WEAPON_BARON_FIRE) or
2541 (Shots[i].ShotType = WEAPON_MANCUB_FIRE) or
2542 (Shots[i].ShotType = WEAPON_SKEL_FIRE) or
2543 (Shots[i].ShotType = WEAPON_IMP_FIRE) or
2544 (Shots[i].ShotType = WEAPON_CACO_FIRE) or
2545 (Shots[i].ShotType = WEAPON_MANCUB_FIRE) or
2546 (Shots[i].ShotType = WEAPON_BSP_FIRE) or
2547 (Shots[i].ShotType = WEAPON_PLASMA) or
2548 (Shots[i].ShotType = WEAPON_BFG) or
2549 (Shots[i].ShotType = WEAPON_FLAMETHROWER) or
2550 false then
2551 begin
2552 if (Shots[i].ShotType = WEAPON_PLASMA) then
2553 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)
2554 else if (Shots[i].ShotType = WEAPON_BFG) then
2555 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)
2556 else if (Shots[i].ShotType = WEAPON_FLAMETHROWER) then
2557 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)
2558 else
2559 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);
2560 end;
2561 end;
2562 end;
2565 procedure TShot.positionChanged (); begin end;
2568 end.