DEADSOFTWARE

uidmap for monsters, so we don't have to do linear searches
[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);
247 var
248 a, b, c, d, i1, i2: Integer;
249 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;
263 function monsWaterCheck (monidx: Integer; mon: TMonster): Boolean;
264 begin
265 result := false; // don't stop
266 if (not InWArray(monidx, mn)) and (i2 < 1023) then //FIXME
267 begin
268 i2 += 1;
269 mn[i2] := monidx;
270 end;
271 end;
273 begin
274 if (gWater = nil) or (WaterMap = nil) then Exit;
276 i1 := -1;
277 i2 := -1;
279 SetLength(pl, 1024);
280 SetLength(mn, 1024);
281 for d := 0 to 1023 do pl[d] := $FFFF;
282 for d := 0 to 1023 do mn[d] := $FFFF;
284 for a := 0 to High(WaterMap) do
285 for b := 0 to High(WaterMap[a]) do
286 begin
287 if not g_Obj_Collide(gWater[WaterMap[a][b]].X, gWater[WaterMap[a][b]].Y,
288 gWater[WaterMap[a][b]].Width, gWater[WaterMap[a][b]].Height,
289 @Shots[ID].Obj) then Continue;
291 for c := 0 to High(WaterMap[a]) do
292 begin
293 if gPlayers <> nil then
294 begin
295 for d := 0 to High(gPlayers) do
296 if (gPlayers[d] <> nil) and (gPlayers[d].Live) then
297 if gPlayers[d].Collide(gWater[WaterMap[a][c]]) then
298 if not InWArray(d, pl) then
299 if i1 < 1023 then
300 begin
301 i1 := i1+1;
302 pl[i1] := d;
303 end;
304 end;
306 //g_Mons_ForEach(monsWaterCheck);
307 g_Mons_ForEachAtAlive(
308 gWater[WaterMap[a][c]].X, gWater[WaterMap[a][c]].Y,
309 gWater[WaterMap[a][c]].Width, gWater[WaterMap[a][c]].Height,
310 monsWaterCheck);
311 end;
313 if i1 <> -1 then
314 begin
315 for d := 0 to i1 do gPlayers[pl[d]].Damage(dm, Shots[ID].SpawnerUID, 0, 0, t);
316 end;
318 if i2 <> -1 then
319 begin
320 for d := 0 to i2 do g_Mons_ByIdx(mn[d]).Damage(dm, 0, 0, Shots[ID].SpawnerUID, t);
321 end;
322 end;
324 pl := nil;
325 mn := nil;
326 end;
328 function HitMonster(m: TMonster; d: Integer; vx, vy: Integer; SpawnerUID: Word; t: Byte): Boolean;
329 var
330 tt, mt: Byte;
331 mon: TMonster;
332 begin
333 Result := False;
335 tt := g_GetUIDType(SpawnerUID);
336 if tt = UID_MONSTER then
337 begin
338 mon := g_Monsters_ByUID(SpawnerUID);
339 if mon <> nil then
340 mt := g_Monsters_ByUID(SpawnerUID).MonsterType
341 else
342 mt := 0;
343 end
344 else
345 mt := 0;
347 if m = nil then Exit;
348 if m.UID = SpawnerUID then
349 begin
350 // Ñàì ñåáÿ ìîæåò ðàíèòü òîëüêî ðàêåòîé è òîêîì:
351 if (t <> HIT_ROCKET) and (t <> HIT_ELECTRO) then
352 Exit;
353 // Êèáåð äåìîí è áî÷êà âîîáùå íå ìîãóò ñåáÿ ðàíèòü:
354 if (m.MonsterType = MONSTER_CYBER) or
355 (m.MonsterType = MONSTER_BARREL) then
356 begin
357 Result := True;
358 Exit;
359 end;
360 end;
362 if tt = UID_MONSTER then
363 begin
364 // Lost_Soul íå ìîæåò ðàíèòü Pain_Elemental'à:
365 if (mt = MONSTER_SOUL) and (m.MonsterType = MONSTER_PAIN) then
366 Exit;
368 // Îáà ìîíñòðà îäíîãî âèäà:
369 if mt = m.MonsterType then
370 case mt of
371 MONSTER_IMP, MONSTER_DEMON, MONSTER_BARON, MONSTER_KNIGHT, MONSTER_CACO,
372 MONSTER_SOUL, MONSTER_MANCUB, MONSTER_SKEL, MONSTER_FISH:
373 Exit; // Ýòè íå áüþò ñâîèõ
374 end;
375 end;
377 if g_Game_IsServer then
378 begin
379 if (t <> HIT_FLAME) or (m.FFireTime = 0) or (vx <> 0) or (vy <> 0) then
380 Result := m.Damage(d, vx, vy, SpawnerUID, t)
381 else
382 Result := True;
383 if t = HIT_FLAME then
384 m.CatchFire(SpawnerUID);
385 end
386 else
387 Result := True;
388 end;
390 function HitPlayer(p: TPlayer; d: Integer; vx, vy: Integer; SpawnerUID: Word; t: Byte): Boolean;
391 begin
392 Result := False;
394 // Ñàì ñåáÿ ìîæåò ðàíèòü òîëüêî ðàêåòîé è òîêîì:
395 if (p.UID = SpawnerUID) and (t <> HIT_ROCKET) and (t <> HIT_ELECTRO) then
396 Exit;
398 if g_Game_IsServer then
399 begin
400 if (t <> HIT_FLAME) or (p.FFireTime = 0) or (vx <> 0) or (vy <> 0) then
401 p.Damage(d, SpawnerUID, vx, vy, t);
402 if (t = HIT_FLAME) then
403 p.CatchFire(SpawnerUID);
404 end;
406 Result := True;
407 end;
409 function GunHit(X, Y: Integer; vx, vy: Integer; dmg: Integer;
410 SpawnerUID: Word; AllowPush: Boolean): Byte;
412 {function monsCheck (monidx: Integer; mon: TMonster): Boolean;
413 begin
414 result := false; // don't stop
415 if mon.Live and mon.Collide(X, Y) then
416 begin
417 if HitMonster(mon, dmg, vx*10, vy*10-3, SpawnerUID, HIT_SOME) then
418 begin
419 if AllowPush then mon.Push(vx, vy);
420 result := true;
421 end;
422 end;
423 end;}
425 function monsCheck (monidx: Integer; mon: TMonster): Boolean;
426 begin
427 result := false; // don't stop
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;
435 var
436 i, h: Integer;
437 begin
438 Result := 0;
440 h := High(gPlayers);
442 if h <> -1 then
443 for i := 0 to h do
444 if (gPlayers[i] <> nil) and gPlayers[i].Live and gPlayers[i].Collide(X, Y) then
445 if HitPlayer(gPlayers[i], dmg, vx*10, vy*10-3, SpawnerUID, HIT_SOME) then
446 begin
447 if AllowPush then gPlayers[i].Push(vx, vy);
448 Result := 1;
449 end;
451 if Result <> 0 then Exit;
453 //if g_Mons_ForEach(monsCheck) then result := 2;
454 if g_Mons_ForEachAtAlive(X, Y, 1, 1, monsCheck) then result := 2;
455 end;
457 procedure g_Weapon_BFG9000(X, Y: Integer; SpawnerUID: Word);
459 function monsCheck (monidx: Integer; mon: TMonster): Boolean;
460 begin
461 result := false; // don't stop
462 if (mon <> nil) and (mon.Live) and (mon.UID <> SpawnerUID) then
463 begin
464 with mon do
465 begin
466 if (g_PatchLength(X, Y, Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2),
467 Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)) <= SHOT_BFG_RADIUS) and
468 g_TraceVector(X, Y, Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2),
469 Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)) then
470 begin
471 if HitMonster(mon, 50, 0, 0, SpawnerUID, HIT_SOME) then mon.BFGHit();
472 end;
473 end;
474 end;
475 end;
477 var
478 i, h: Integer;
479 st: Byte;
480 pl: TPlayer;
481 b: Boolean;
482 begin
483 //g_Sound_PlayEx('SOUND_WEAPON_EXPLODEBFG', 255);
485 h := High(gCorpses);
487 if gAdvCorpses and (h <> -1) then
488 for i := 0 to h do
489 if (gCorpses[i] <> nil) and (gCorpses[i].State <> CORPSE_STATE_REMOVEME) then
490 with gCorpses[i] do
491 if (g_PatchLength(X, Y, Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2),
492 Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)) <= SHOT_BFG_RADIUS) and
493 g_TraceVector(X, Y, Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2),
494 Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)) then
495 begin
496 Damage(50, 0, 0);
497 g_Weapon_BFGHit(Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2),
498 Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2));
499 end;
501 st := TEAM_NONE;
502 pl := g_Player_Get(SpawnerUID);
503 if pl <> nil then
504 st := pl.Team;
506 h := High(gPlayers);
508 if h <> -1 then
509 for i := 0 to h do
510 if (gPlayers[i] <> nil) and (gPlayers[i].Live) and (gPlayers[i].UID <> SpawnerUID) then
511 with gPlayers[i] do
512 if (g_PatchLength(X, Y, GameX+PLAYER_RECT.X+(PLAYER_RECT.Width div 2),
513 GameY+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)) <= SHOT_BFG_RADIUS) and
514 g_TraceVector(X, Y, GameX+PLAYER_RECT.X+(PLAYER_RECT.Width div 2),
515 GameY+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)) then
516 begin
517 if (st = TEAM_NONE) or (st <> gPlayers[i].Team) then
518 b := HitPlayer(gPlayers[i], 50, 0, 0, SpawnerUID, HIT_SOME)
519 else
520 b := HitPlayer(gPlayers[i], 25, 0, 0, SpawnerUID, HIT_SOME);
521 if b then
522 gPlayers[i].BFGHit();
523 end;
525 g_Mons_ForEach(monsCheck);
526 end;
528 function g_Weapon_CreateShot(I: Integer; ShotType: Byte; Spawner, TargetUID: Word; X, Y, XV, YV: Integer): LongWord;
529 var
530 find_id, FramesID: DWORD;
531 begin
532 if I < 0 then
533 find_id := FindShot()
534 else
535 begin
536 find_id := I;
537 if Integer(find_id) >= High(Shots) then
538 SetLength(Shots, find_id + 64)
539 end;
541 case ShotType of
542 WEAPON_ROCKETLAUNCHER:
543 begin
544 with Shots[find_id] do
545 begin
546 g_Obj_Init(@Obj);
548 Obj.Rect.Width := SHOT_ROCKETLAUNCHER_WIDTH;
549 Obj.Rect.Height := SHOT_ROCKETLAUNCHER_HEIGHT;
551 Animation := nil;
552 Triggers := nil;
553 ShotType := WEAPON_ROCKETLAUNCHER;
554 g_Texture_Get('TEXTURE_WEAPON_ROCKET', TextureID);
555 end;
556 end;
558 WEAPON_PLASMA:
559 begin
560 with Shots[find_id] do
561 begin
562 g_Obj_Init(@Obj);
564 Obj.Rect.Width := SHOT_PLASMA_WIDTH;
565 Obj.Rect.Height := SHOT_PLASMA_HEIGHT;
567 Triggers := nil;
568 ShotType := WEAPON_PLASMA;
569 g_Frames_Get(FramesID, 'FRAMES_WEAPON_PLASMA');
570 Animation := TAnimation.Create(FramesID, True, 5);
571 end;
572 end;
574 WEAPON_BFG:
575 begin
576 with Shots[find_id] do
577 begin
578 g_Obj_Init(@Obj);
580 Obj.Rect.Width := SHOT_BFG_WIDTH;
581 Obj.Rect.Height := SHOT_BFG_HEIGHT;
583 Triggers := nil;
584 ShotType := WEAPON_BFG;
585 g_Frames_Get(FramesID, 'FRAMES_WEAPON_BFG');
586 Animation := TAnimation.Create(FramesID, True, 6);
587 end;
588 end;
590 WEAPON_FLAMETHROWER:
591 begin
592 with Shots[find_id] do
593 begin
594 g_Obj_Init(@Obj);
596 Obj.Rect.Width := SHOT_FLAME_WIDTH;
597 Obj.Rect.Height := SHOT_FLAME_HEIGHT;
599 Triggers := nil;
600 ShotType := WEAPON_FLAMETHROWER;
601 Animation := nil;
602 TextureID := 0;
603 g_Frames_Get(TextureID, 'FRAMES_FLAME');
604 end;
605 end;
607 WEAPON_IMP_FIRE:
608 begin
609 with Shots[find_id] do
610 begin
611 g_Obj_Init(@Obj);
613 Obj.Rect.Width := 16;
614 Obj.Rect.Height := 16;
616 Triggers := nil;
617 ShotType := WEAPON_IMP_FIRE;
618 g_Frames_Get(FramesID, 'FRAMES_WEAPON_IMPFIRE');
619 Animation := TAnimation.Create(FramesID, True, 4);
620 end;
621 end;
623 WEAPON_CACO_FIRE:
624 begin
625 with Shots[find_id] do
626 begin
627 g_Obj_Init(@Obj);
629 Obj.Rect.Width := 16;
630 Obj.Rect.Height := 16;
632 Triggers := nil;
633 ShotType := WEAPON_CACO_FIRE;
634 g_Frames_Get(FramesID, 'FRAMES_WEAPON_CACOFIRE');
635 Animation := TAnimation.Create(FramesID, True, 4);
636 end;
637 end;
639 WEAPON_MANCUB_FIRE:
640 begin
641 with Shots[find_id] do
642 begin
643 g_Obj_Init(@Obj);
645 Obj.Rect.Width := 32;
646 Obj.Rect.Height := 32;
648 Triggers := nil;
649 ShotType := WEAPON_MANCUB_FIRE;
650 g_Frames_Get(FramesID, 'FRAMES_WEAPON_MANCUBFIRE');
651 Animation := TAnimation.Create(FramesID, True, 4);
652 end;
653 end;
655 WEAPON_BARON_FIRE:
656 begin
657 with Shots[find_id] do
658 begin
659 g_Obj_Init(@Obj);
661 Obj.Rect.Width := 32;
662 Obj.Rect.Height := 16;
664 Triggers := nil;
665 ShotType := WEAPON_BARON_FIRE;
666 g_Frames_Get(FramesID, 'FRAMES_WEAPON_BARONFIRE');
667 Animation := TAnimation.Create(FramesID, True, 4);
668 end;
669 end;
671 WEAPON_BSP_FIRE:
672 begin
673 with Shots[find_id] do
674 begin
675 g_Obj_Init(@Obj);
677 Obj.Rect.Width := 16;
678 Obj.Rect.Height := 16;
680 Triggers := nil;
681 ShotType := WEAPON_BSP_FIRE;
682 g_Frames_Get(FramesID, 'FRAMES_WEAPON_BSPFIRE');
683 Animation := TAnimation.Create(FramesID, True, 4);
684 end;
685 end;
687 WEAPON_SKEL_FIRE:
688 begin
689 with Shots[find_id] do
690 begin
691 g_Obj_Init(@Obj);
693 Obj.Rect.Width := SHOT_SKELFIRE_WIDTH;
694 Obj.Rect.Height := SHOT_SKELFIRE_HEIGHT;
696 Triggers := nil;
697 ShotType := WEAPON_SKEL_FIRE;
698 target := TargetUID;
699 g_Frames_Get(FramesID, 'FRAMES_WEAPON_SKELFIRE');
700 Animation := TAnimation.Create(FramesID, True, 5);
701 end;
702 end;
703 end;
705 Shots[find_id].Obj.X := X;
706 Shots[find_id].Obj.Y := Y;
707 Shots[find_id].Obj.Vel.X := XV;
708 Shots[find_id].Obj.Vel.Y := YV;
709 Shots[find_id].Obj.Accel.X := 0;
710 Shots[find_id].Obj.Accel.Y := 0;
711 Shots[find_id].SpawnerUID := Spawner;
712 if (ShotType = WEAPON_FLAMETHROWER) and (XV = 0) and (YV = 0) then
713 Shots[find_id].Stopped := 255
714 else
715 Shots[find_id].Stopped := 0;
716 Result := find_id;
717 end;
719 procedure throw(i, x, y, xd, yd, s: Integer);
720 var
721 a: Integer;
722 begin
723 yd := yd - y;
724 xd := xd - x;
726 a := Max(Abs(xd), Abs(yd));
727 if a = 0 then
728 a := 1;
730 Shots[i].Obj.X := x;
731 Shots[i].Obj.Y := y;
732 Shots[i].Obj.Vel.X := (xd*s) div a;
733 Shots[i].Obj.Vel.Y := (yd*s) div a;
734 Shots[i].Obj.Accel.X := 0;
735 Shots[i].Obj.Accel.Y := 0;
736 Shots[i].Stopped := 0;
737 if Shots[i].ShotType in [WEAPON_ROCKETLAUNCHER, WEAPON_BFG] then
738 Shots[i].Timeout := 900 // ~25 sec
739 else
740 begin
741 if Shots[i].ShotType = WEAPON_FLAMETHROWER then
742 Shots[i].Timeout := SHOT_FLAME_LIFETIME
743 else
744 Shots[i].Timeout := 550; // ~15 sec
745 end;
746 end;
748 function g_Weapon_Hit(obj: PObj; d: Integer; SpawnerUID: Word; t: Byte; HitCorpses: Boolean = True): Byte;
749 var
750 i, h: Integer;
752 function PlayerHit(Team: Byte = 0): Boolean;
753 var
754 i: Integer;
755 ChkTeam: Boolean;
756 p: TPlayer;
757 begin
758 Result := False;
759 h := High(gPlayers);
761 if h <> -1 then
762 for i := 0 to h do
763 if (gPlayers[i] <> nil) and gPlayers[i].Live and g_Obj_Collide(obj, @gPlayers[i].Obj) then
764 begin
765 ChkTeam := True;
766 if (Team > 0) and (g_GetUIDType(SpawnerUID) = UID_PLAYER) then
767 begin
768 p := g_Player_Get(SpawnerUID);
769 if p <> nil then
770 ChkTeam := (p.Team = gPlayers[i].Team) xor (Team = 2);
771 end;
772 if ChkTeam then
773 if HitPlayer(gPlayers[i], d, obj^.Vel.X, obj^.Vel.Y, SpawnerUID, t) then
774 begin
775 if t <> HIT_FLAME then
776 gPlayers[i].Push((obj^.Vel.X+obj^.Accel.X)*IfThen(t = HIT_BFG, 8, 1) div 4,
777 (obj^.Vel.Y+obj^.Accel.Y)*IfThen(t = HIT_BFG, 8, 1) div 4);
778 if t = HIT_BFG then
779 g_Game_DelayEvent(DE_BFGHIT, 1000, SpawnerUID);
780 Result := True;
781 break;
782 end;
783 end;
784 end;
786 function monsCheckHit (monidx: Integer; mon: TMonster): Boolean;
787 begin
788 result := false; // don't stop
789 if (mon <> nil) and mon.Live and g_Obj_Collide(obj, @mon.Obj) then
790 begin
791 if HitMonster(mon, d, obj^.Vel.X, obj^.Vel.Y, SpawnerUID, t) then
792 begin
793 if (t <> HIT_FLAME) then
794 begin
795 mon.Push((obj^.Vel.X+obj^.Accel.X)*IfThen(t = HIT_BFG, 8, 1) div 4,
796 (obj^.Vel.Y+obj^.Accel.Y)*IfThen(t = HIT_BFG, 8, 1) div 4);
797 end;
798 result := True;
799 end;
800 end;
801 end;
803 function MonsterHit(): Boolean;
804 begin
805 result := g_Mons_ForEach(monsCheckHit);
806 end;
808 begin
809 Result := 0;
811 if HitCorpses then
812 begin
813 h := High(gCorpses);
815 if gAdvCorpses and (h <> -1) then
816 for i := 0 to h do
817 if (gCorpses[i] <> nil) and (gCorpses[i].State <> CORPSE_STATE_REMOVEME) and
818 g_Obj_Collide(obj, @gCorpses[i].Obj) then
819 begin
820 // Ðàñïèëèâàåì òðóï:
821 gCorpses[i].Damage(d, (obj^.Vel.X+obj^.Accel.X) div 4,
822 (obj^.Vel.Y+obj^.Accel.Y) div 4);
823 Result := 1;
824 end;
825 end;
827 case gGameSettings.GameMode of
828 // Êàìïàíèÿ:
829 GM_COOP, GM_SINGLE:
830 begin
831 // Ñíà÷àëà áü¸ì ìîíñòðîâ, åñëè åñòü, ïîòîì ïûòàåìñÿ áèòü èãðîêîâ
832 if MonsterHit() then
833 begin
834 Result := 2;
835 Exit;
836 end;
838 if PlayerHit() then
839 begin
840 Result := 1;
841 Exit;
842 end;
843 end;
845 // Äåçìàò÷:
846 GM_DM:
847 begin
848 // Ñíà÷àëà áü¸ì èãðîêîâ, åñëè åñòü, ïîòîì ïûòàåìñÿ áèòü ìîíñòðîâ
849 if PlayerHit() then
850 begin
851 Result := 1;
852 Exit;
853 end;
855 if MonsterHit() then
856 begin
857 Result := 2;
858 Exit;
859 end;
860 end;
862 // Êîìàíäíûå:
863 GM_TDM, GM_CTF:
864 begin
865 // Ñíà÷àëà áü¸ì èãðîêîâ êîìàíäû ñîïåðíèêà
866 if PlayerHit(2) then
867 begin
868 Result := 1;
869 Exit;
870 end;
872 // Ïîòîì ìîíñòðîâ
873 if MonsterHit() then
874 begin
875 Result := 2;
876 Exit;
877 end;
879 // È â êîíöå ñâîèõ èãðîêîâ
880 if PlayerHit(1) then
881 begin
882 Result := 1;
883 Exit;
884 end;
885 end;
887 end;
888 end;
890 function g_Weapon_HitUID(UID: Word; d: Integer; SpawnerUID: Word; t: Byte): Boolean;
891 begin
892 Result := False;
894 case g_GetUIDType(UID) of
895 UID_PLAYER: Result := HitPlayer(g_Player_Get(UID), d, 0, 0, SpawnerUID, t);
896 UID_MONSTER: Result := HitMonster(g_Monsters_ByUID(UID), d, 0, 0, SpawnerUID, t);
897 else Exit;
898 end;
899 end;
901 function g_Weapon_Explode(X, Y: Integer; rad: Integer; SpawnerUID: Word): Boolean;
902 var
903 r: Integer;
905 function monsExCheck (monidx: Integer; mon: TMonster): Boolean;
906 var
907 dx, dy, mm: Integer;
908 begin
909 result := false; // don't stop
910 if mon <> nil then
911 begin
912 with mon do
913 begin
914 dx := Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2)-X;
915 dy := Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)-Y;
917 if dx > 1000 then dx := 1000;
918 if dy > 1000 then dy := 1000;
920 if (dx*dx+dy*dy < r) then
921 begin
922 //m := PointToRect(X, Y, Obj.X+Obj.Rect.X, Obj.Y+Obj.Rect.Y, Obj.Rect.Width, Obj.Rect.Height);
924 mm := Max(abs(dx), abs(dy));
925 if mm = 0 then mm := 1;
927 if mon.Live then
928 HitMonster(mon, ((mon.Obj.Rect.Width div 4)*10*(rad-mm)) div rad,
929 0, 0, SpawnerUID, HIT_ROCKET);
931 mon.Push((dx*7) div mm, (dy*7) div mm);
932 end;
933 end;
934 end;
935 end;
937 var
938 i, h, dx, dy, m, mm: Integer;
939 _angle: SmallInt;
941 begin
942 Result := False;
944 g_Triggers_PressC(X, Y, rad, SpawnerUID, ACTIVATE_SHOT);
946 r := rad*rad;
948 h := High(gPlayers);
950 if h <> -1 then
951 for i := 0 to h do
952 if (gPlayers[i] <> nil) and gPlayers[i].Live then
953 with gPlayers[i] do
954 begin
955 dx := Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2)-X;
956 dy := Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)-Y;
958 if dx > 1000 then dx := 1000;
959 if dy > 1000 then dy := 1000;
961 if dx*dx+dy*dy < r then
962 begin
963 //m := PointToRect(X, Y, GameX+PLAYER_RECT.X, GameY+PLAYER_RECT.Y,
964 // PLAYER_RECT.Width, PLAYER_RECT.Height);
966 mm := Max(abs(dx), abs(dy));
967 if mm = 0 then mm := 1;
969 HitPlayer(gPlayers[i], (100*(rad-mm)) div rad, (dx*10) div mm, (dy*10) div mm, SpawnerUID, HIT_ROCKET);
970 gPlayers[i].Push((dx*7) div mm, (dy*7) div mm);
971 end;
972 end;
974 g_Mons_ForEach(monsExCheck);
977 h := High(gCorpses);
979 if gAdvCorpses and (h <> -1) then
980 for i := 0 to h do
981 if (gCorpses[i] <> nil) and (gCorpses[i].State <> CORPSE_STATE_REMOVEME) then
982 with gCorpses[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, Obj.X+Obj.Rect.X, Obj.Y+Obj.Rect.Y,
993 Obj.Rect.Width, Obj.Rect.Height);
995 mm := Max(abs(dx), abs(dy));
996 if mm = 0 then mm := 1;
998 Damage(Round(100*(rad-m)/rad), (dx*10) div mm, (dy*10) div mm);
999 end;
1000 end;
1002 h := High(gGibs);
1004 if gAdvGibs and (h <> -1) then
1005 for i := 0 to h do
1006 if gGibs[i].Live then
1007 with gGibs[i] do
1008 begin
1009 dx := Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2)-X;
1010 dy := Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)-Y;
1012 if dx > 1000 then dx := 1000;
1013 if dy > 1000 then dy := 1000;
1015 if dx*dx+dy*dy < r then
1016 begin
1017 m := PointToRect(X, Y, Obj.X+Obj.Rect.X, Obj.Y+Obj.Rect.Y,
1018 Obj.Rect.Width, Obj.Rect.Height);
1019 _angle := GetAngle(Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2),
1020 Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2), X, Y);
1022 g_Obj_PushA(@Obj, Round(15*(rad-m)/rad), _angle);
1023 positionChanged(); // this updates spatial accelerators
1024 end;
1025 end;
1026 end;
1028 procedure g_Weapon_Init();
1029 begin
1030 CreateWaterMap();
1031 end;
1033 procedure g_Weapon_Free();
1034 var
1035 i: Integer;
1036 begin
1037 if Shots <> nil then
1038 begin
1039 for i := 0 to High(Shots) do
1040 if Shots[i].ShotType <> 0 then
1041 Shots[i].Animation.Free();
1043 Shots := nil;
1044 end;
1046 WaterMap := nil;
1047 end;
1049 procedure g_Weapon_LoadData();
1050 begin
1051 e_WriteLog('Loading weapons data...', MSG_NOTIFY);
1053 g_Sound_CreateWADEx('SOUND_WEAPON_HITPUNCH', GameWAD+':SOUNDS\HITPUNCH');
1054 g_Sound_CreateWADEx('SOUND_WEAPON_MISSPUNCH', GameWAD+':SOUNDS\MISSPUNCH');
1055 g_Sound_CreateWADEx('SOUND_WEAPON_HITBERSERK', GameWAD+':SOUNDS\HITBERSERK');
1056 g_Sound_CreateWADEx('SOUND_WEAPON_MISSBERSERK', GameWAD+':SOUNDS\MISSBERSERK');
1057 g_Sound_CreateWADEx('SOUND_WEAPON_SELECTSAW', GameWAD+':SOUNDS\SELECTSAW');
1058 g_Sound_CreateWADEx('SOUND_WEAPON_IDLESAW', GameWAD+':SOUNDS\IDLESAW');
1059 g_Sound_CreateWADEx('SOUND_WEAPON_HITSAW', GameWAD+':SOUNDS\HITSAW');
1060 g_Sound_CreateWADEx('SOUND_WEAPON_FIRESHOTGUN2', GameWAD+':SOUNDS\FIRESHOTGUN2');
1061 g_Sound_CreateWADEx('SOUND_WEAPON_FIRESHOTGUN', GameWAD+':SOUNDS\FIRESHOTGUN');
1062 g_Sound_CreateWADEx('SOUND_WEAPON_FIRESAW', GameWAD+':SOUNDS\FIRESAW');
1063 g_Sound_CreateWADEx('SOUND_WEAPON_FIREROCKET', GameWAD+':SOUNDS\FIREROCKET');
1064 g_Sound_CreateWADEx('SOUND_WEAPON_FIREPLASMA', GameWAD+':SOUNDS\FIREPLASMA');
1065 g_Sound_CreateWADEx('SOUND_WEAPON_FIREPISTOL', GameWAD+':SOUNDS\FIREPISTOL');
1066 g_Sound_CreateWADEx('SOUND_WEAPON_FIRECGUN', GameWAD+':SOUNDS\FIRECGUN');
1067 g_Sound_CreateWADEx('SOUND_WEAPON_FIREBFG', GameWAD+':SOUNDS\FIREBFG');
1068 g_Sound_CreateWADEx('SOUND_FIRE', GameWAD+':SOUNDS\FIRE');
1069 g_Sound_CreateWADEx('SOUND_WEAPON_STARTFIREBFG', GameWAD+':SOUNDS\STARTFIREBFG');
1070 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEROCKET', GameWAD+':SOUNDS\EXPLODEROCKET');
1071 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEBFG', GameWAD+':SOUNDS\EXPLODEBFG');
1072 g_Sound_CreateWADEx('SOUND_WEAPON_BFGWATER', GameWAD+':SOUNDS\BFGWATER');
1073 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEPLASMA', GameWAD+':SOUNDS\EXPLODEPLASMA');
1074 g_Sound_CreateWADEx('SOUND_WEAPON_PLASMAWATER', GameWAD+':SOUNDS\PLASMAWATER');
1075 g_Sound_CreateWADEx('SOUND_WEAPON_FIREBALL', GameWAD+':SOUNDS\FIREBALL');
1076 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEBALL', GameWAD+':SOUNDS\EXPLODEBALL');
1077 g_Sound_CreateWADEx('SOUND_WEAPON_FIREREV', GameWAD+':SOUNDS\FIREREV');
1078 g_Sound_CreateWADEx('SOUND_PLAYER_JETFLY', GameWAD+':SOUNDS\WORKJETPACK');
1079 g_Sound_CreateWADEx('SOUND_PLAYER_JETON', GameWAD+':SOUNDS\STARTJETPACK');
1080 g_Sound_CreateWADEx('SOUND_PLAYER_JETOFF', GameWAD+':SOUNDS\STOPJETPACK');
1081 g_Sound_CreateWADEx('SOUND_PLAYER_CASING1', GameWAD+':SOUNDS\CASING1');
1082 g_Sound_CreateWADEx('SOUND_PLAYER_CASING2', GameWAD+':SOUNDS\CASING2');
1083 g_Sound_CreateWADEx('SOUND_PLAYER_SHELL1', GameWAD+':SOUNDS\SHELL1');
1084 g_Sound_CreateWADEx('SOUND_PLAYER_SHELL2', GameWAD+':SOUNDS\SHELL2');
1086 g_Texture_CreateWADEx('TEXTURE_WEAPON_ROCKET', GameWAD+':TEXTURES\BROCKET');
1087 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_SKELFIRE', GameWAD+':TEXTURES\BSKELFIRE', 64, 16, 2);
1088 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_BFG', GameWAD+':TEXTURES\BBFG', 64, 64, 2);
1089 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_PLASMA', GameWAD+':TEXTURES\BPLASMA', 16, 16, 2);
1090 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_IMPFIRE', GameWAD+':TEXTURES\BIMPFIRE', 16, 16, 2);
1091 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_BSPFIRE', GameWAD+':TEXTURES\BBSPFIRE', 16, 16, 2);
1092 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_CACOFIRE', GameWAD+':TEXTURES\BCACOFIRE', 16, 16, 2);
1093 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_BARONFIRE', GameWAD+':TEXTURES\BBARONFIRE', 64, 16, 2);
1094 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_MANCUBFIRE', GameWAD+':TEXTURES\BMANCUBFIRE', 64, 32, 2);
1095 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_ROCKET', GameWAD+':TEXTURES\EROCKET', 128, 128, 6);
1096 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_SKELFIRE', GameWAD+':TEXTURES\ESKELFIRE', 64, 64, 3);
1097 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_BFG', GameWAD+':TEXTURES\EBFG', 128, 128, 6);
1098 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_IMPFIRE', GameWAD+':TEXTURES\EIMPFIRE', 64, 64, 3);
1099 g_Frames_CreateWAD(nil, 'FRAMES_BFGHIT', GameWAD+':TEXTURES\BFGHIT', 64, 64, 4);
1100 g_Frames_CreateWAD(nil, 'FRAMES_FIRE', GameWAD+':TEXTURES\FIRE', 64, 128, 8);
1101 g_Frames_CreateWAD(nil, 'FRAMES_FLAME', GameWAD+':TEXTURES\FLAME', 32, 32, 11);
1102 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_PLASMA', GameWAD+':TEXTURES\EPLASMA', 32, 32, 4, True);
1103 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_BSPFIRE', GameWAD+':TEXTURES\EBSPFIRE', 32, 32, 5);
1104 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_CACOFIRE', GameWAD+':TEXTURES\ECACOFIRE', 64, 64, 3);
1105 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_BARONFIRE', GameWAD+':TEXTURES\EBARONFIRE', 64, 64, 3);
1106 g_Frames_CreateWAD(nil, 'FRAMES_SMOKE', GameWAD+':TEXTURES\SMOKE', 32, 32, 10, False);
1108 g_Texture_CreateWADEx('TEXTURE_SHELL_BULLET', GameWAD+':TEXTURES\EBULLET');
1109 g_Texture_CreateWADEx('TEXTURE_SHELL_SHELL', GameWAD+':TEXTURES\ESHELL');
1110 end;
1112 procedure g_Weapon_FreeData();
1113 begin
1114 e_WriteLog('Releasing weapons data...', MSG_NOTIFY);
1116 g_Sound_Delete('SOUND_WEAPON_HITPUNCH');
1117 g_Sound_Delete('SOUND_WEAPON_MISSPUNCH');
1118 g_Sound_Delete('SOUND_WEAPON_HITBERSERK');
1119 g_Sound_Delete('SOUND_WEAPON_MISSBERSERK');
1120 g_Sound_Delete('SOUND_WEAPON_SELECTSAW');
1121 g_Sound_Delete('SOUND_WEAPON_IDLESAW');
1122 g_Sound_Delete('SOUND_WEAPON_HITSAW');
1123 g_Sound_Delete('SOUND_WEAPON_FIRESHOTGUN2');
1124 g_Sound_Delete('SOUND_WEAPON_FIRESHOTGUN');
1125 g_Sound_Delete('SOUND_WEAPON_FIRESAW');
1126 g_Sound_Delete('SOUND_WEAPON_FIREROCKET');
1127 g_Sound_Delete('SOUND_WEAPON_FIREPLASMA');
1128 g_Sound_Delete('SOUND_WEAPON_FIREPISTOL');
1129 g_Sound_Delete('SOUND_WEAPON_FIRECGUN');
1130 g_Sound_Delete('SOUND_WEAPON_FIREBFG');
1131 g_Sound_Delete('SOUND_FIRE');
1132 g_Sound_Delete('SOUND_WEAPON_STARTFIREBFG');
1133 g_Sound_Delete('SOUND_WEAPON_EXPLODEROCKET');
1134 g_Sound_Delete('SOUND_WEAPON_EXPLODEBFG');
1135 g_Sound_Delete('SOUND_WEAPON_BFGWATER');
1136 g_Sound_Delete('SOUND_WEAPON_EXPLODEPLASMA');
1137 g_Sound_Delete('SOUND_WEAPON_PLASMAWATER');
1138 g_Sound_Delete('SOUND_WEAPON_FIREBALL');
1139 g_Sound_Delete('SOUND_WEAPON_EXPLODEBALL');
1140 g_Sound_Delete('SOUND_WEAPON_FIREREV');
1141 g_Sound_Delete('SOUND_PLAYER_JETFLY');
1142 g_Sound_Delete('SOUND_PLAYER_JETON');
1143 g_Sound_Delete('SOUND_PLAYER_JETOFF');
1144 g_Sound_Delete('SOUND_PLAYER_CASING1');
1145 g_Sound_Delete('SOUND_PLAYER_CASING2');
1146 g_Sound_Delete('SOUND_PLAYER_SHELL1');
1147 g_Sound_Delete('SOUND_PLAYER_SHELL2');
1149 g_Texture_Delete('TEXTURE_WEAPON_ROCKET');
1150 g_Frames_DeleteByName('FRAMES_WEAPON_BFG');
1151 g_Frames_DeleteByName('FRAMES_WEAPON_PLASMA');
1152 g_Frames_DeleteByName('FRAMES_WEAPON_IMPFIRE');
1153 g_Frames_DeleteByName('FRAMES_WEAPON_BSPFIRE');
1154 g_Frames_DeleteByName('FRAMES_WEAPON_CACOFIRE');
1155 g_Frames_DeleteByName('FRAMES_WEAPON_MANCUBFIRE');
1156 g_Frames_DeleteByName('FRAMES_EXPLODE_ROCKET');
1157 g_Frames_DeleteByName('FRAMES_EXPLODE_BFG');
1158 g_Frames_DeleteByName('FRAMES_EXPLODE_IMPFIRE');
1159 g_Frames_DeleteByName('FRAMES_BFGHIT');
1160 g_Frames_DeleteByName('FRAMES_FIRE');
1161 g_Frames_DeleteByName('FRAMES_EXPLODE_PLASMA');
1162 g_Frames_DeleteByName('FRAMES_EXPLODE_BSPFIRE');
1163 g_Frames_DeleteByName('FRAMES_EXPLODE_CACOFIRE');
1164 g_Frames_DeleteByName('FRAMES_SMOKE');
1165 g_Frames_DeleteByName('FRAMES_WEAPON_BARONFIRE');
1166 g_Frames_DeleteByName('FRAMES_EXPLODE_BARONFIRE');
1167 end;
1169 procedure g_Weapon_gun(x, y, xd, yd, v, dmg: Integer; SpawnerUID: Word; CheckTrigger: Boolean);
1170 var
1171 a: Integer;
1172 x2, y2: Integer;
1173 dx, dy: Integer;
1174 xe, ye: Integer;
1175 xi, yi: Integer;
1176 s, c: Extended;
1177 //vx, vy: Integer;
1178 xx, yy, d: Integer;
1180 i: Integer;
1181 t1, _collide: Boolean;
1182 w, h: Word;
1183 begin
1184 a := GetAngle(x, y, xd, yd)+180;
1186 SinCos(DegToRad(-a), s, c);
1188 if Abs(s) < 0.01 then s := 0;
1189 if Abs(c) < 0.01 then c := 0;
1191 x2 := x+Round(c*gMapInfo.Width);
1192 y2 := y+Round(s*gMapInfo.Width);
1194 t1 := gWalls <> nil;
1195 _collide := False;
1196 w := gMapInfo.Width;
1197 h := gMapInfo.Height;
1199 xe := 0;
1200 ye := 0;
1201 dx := x2-x;
1202 dy := y2-y;
1204 if (xd = 0) and (yd = 0) then Exit;
1206 if dx > 0 then xi := 1 else if dx < 0 then xi := -1 else xi := 0;
1207 if dy > 0 then yi := 1 else if dy < 0 then yi := -1 else yi := 0;
1209 dx := Abs(dx);
1210 dy := Abs(dy);
1212 if dx > dy then d := dx else d := dy;
1214 //blood vel, for Monster.Damage()
1215 //vx := (dx*10 div d)*xi;
1216 //vy := (dy*10 div d)*yi;
1218 xx := x;
1219 yy := y;
1221 for i := 1 to d do
1222 begin
1223 xe := xe+dx;
1224 ye := ye+dy;
1226 if xe > d then
1227 begin
1228 xe := xe-d;
1229 xx := xx+xi;
1230 end;
1232 if ye > d then
1233 begin
1234 ye := ye-d;
1235 yy := yy+yi;
1236 end;
1238 if (yy > h) or (yy < 0) then Break;
1239 if (xx > w) or (xx < 0) then Break;
1241 if t1 then
1242 if ByteBool(gCollideMap[yy, xx] and MARK_BLOCKED) then
1243 begin
1244 _collide := True;
1245 g_GFX_Spark(xx-xi, yy-yi, 2+Random(2), 180+a, 0, 0);
1246 if g_Game_IsServer and g_Game_IsNet then
1247 MH_SEND_Effect(xx-xi, yy-yi, 180+a, NET_GFX_SPARK);
1248 end;
1250 if not _collide then
1251 _collide := GunHit(xx, yy, xi*v, yi*v, dmg, SpawnerUID, v <> 0) <> 0;
1253 if _collide then
1254 Break;
1255 end;
1257 if CheckTrigger and g_Game_IsServer then
1258 g_Triggers_PressL(X, Y, xx-xi, yy-yi, SpawnerUID, ACTIVATE_SHOT);
1259 end;
1261 procedure g_Weapon_punch(x, y: Integer; d, SpawnerUID: Word);
1262 var
1263 obj: TObj;
1264 begin
1265 obj.X := X;
1266 obj.Y := Y;
1267 obj.rect.X := 0;
1268 obj.rect.Y := 0;
1269 obj.rect.Width := 39;
1270 obj.rect.Height := 52;
1271 obj.Vel.X := 0;
1272 obj.Vel.Y := 0;
1273 obj.Accel.X := 0;
1274 obj.Accel.Y := 0;
1276 if g_Weapon_Hit(@obj, d, SpawnerUID, HIT_SOME) <> 0 then
1277 g_Sound_PlayExAt('SOUND_WEAPON_HITPUNCH', x, y)
1278 else
1279 g_Sound_PlayExAt('SOUND_WEAPON_MISSPUNCH', x, y);
1280 end;
1282 function g_Weapon_chainsaw(x, y: Integer; d, SpawnerUID: Word): Integer;
1283 var
1284 obj: TObj;
1285 begin
1286 obj.X := X;
1287 obj.Y := Y;
1288 obj.rect.X := 0;
1289 obj.rect.Y := 0;
1290 obj.rect.Width := 32;
1291 obj.rect.Height := 52;
1292 obj.Vel.X := 0;
1293 obj.Vel.Y := 0;
1294 obj.Accel.X := 0;
1295 obj.Accel.Y := 0;
1297 Result := g_Weapon_Hit(@obj, d, SpawnerUID, HIT_SOME);
1298 end;
1300 procedure g_Weapon_rocket(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1301 Silent: Boolean = False);
1302 var
1303 find_id: DWORD;
1304 dx, dy: Integer;
1305 begin
1306 if WID < 0 then
1307 find_id := FindShot()
1308 else
1309 begin
1310 find_id := WID;
1311 if Integer(find_id) >= High(Shots) then
1312 SetLength(Shots, find_id + 64)
1313 end;
1315 with Shots[find_id] do
1316 begin
1317 g_Obj_Init(@Obj);
1319 Obj.Rect.Width := SHOT_ROCKETLAUNCHER_WIDTH;
1320 Obj.Rect.Height := SHOT_ROCKETLAUNCHER_HEIGHT;
1322 dx := IfThen(xd > x, -Obj.Rect.Width, 0);
1323 dy := -(Obj.Rect.Height div 2);
1325 ShotType := WEAPON_ROCKETLAUNCHER;
1326 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 12);
1328 Animation := nil;
1329 triggers := nil;
1330 g_Texture_Get('TEXTURE_WEAPON_ROCKET', TextureID);
1331 end;
1333 Shots[find_id].SpawnerUID := SpawnerUID;
1335 if not Silent then
1336 g_Sound_PlayExAt('SOUND_WEAPON_FIREROCKET', x, y);
1337 end;
1339 procedure g_Weapon_revf(x, y, xd, yd: Integer; SpawnerUID, TargetUID: Word;
1340 WID: Integer = -1; Silent: Boolean = False);
1341 var
1342 find_id, FramesID: DWORD;
1343 dx, dy: Integer;
1344 begin
1345 if WID < 0 then
1346 find_id := FindShot()
1347 else
1348 begin
1349 find_id := WID;
1350 if Integer(find_id) >= High(Shots) then
1351 SetLength(Shots, find_id + 64)
1352 end;
1354 with Shots[find_id] do
1355 begin
1356 g_Obj_Init(@Obj);
1358 Obj.Rect.Width := SHOT_SKELFIRE_WIDTH;
1359 Obj.Rect.Height := SHOT_SKELFIRE_HEIGHT;
1361 dx := -(Obj.Rect.Width div 2);
1362 dy := -(Obj.Rect.Height div 2);
1364 ShotType := WEAPON_SKEL_FIRE;
1365 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 12);
1367 triggers := nil;
1368 target := TargetUID;
1369 g_Frames_Get(FramesID, 'FRAMES_WEAPON_SKELFIRE');
1370 Animation := TAnimation.Create(FramesID, True, 5);
1371 end;
1373 Shots[find_id].SpawnerUID := SpawnerUID;
1375 if not Silent then
1376 g_Sound_PlayExAt('SOUND_WEAPON_FIREREV', x, y);
1377 end;
1379 procedure g_Weapon_plasma(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1380 Silent: Boolean = False);
1381 var
1382 find_id, FramesID: DWORD;
1383 dx, dy: Integer;
1384 begin
1385 if WID < 0 then
1386 find_id := FindShot()
1387 else
1388 begin
1389 find_id := WID;
1390 if Integer(find_id) >= High(Shots) then
1391 SetLength(Shots, find_id + 64);
1392 end;
1394 with Shots[find_id] do
1395 begin
1396 g_Obj_Init(@Obj);
1398 Obj.Rect.Width := SHOT_PLASMA_WIDTH;
1399 Obj.Rect.Height := SHOT_PLASMA_HEIGHT;
1401 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1402 dy := -(Obj.Rect.Height div 2);
1404 ShotType := WEAPON_PLASMA;
1405 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1407 triggers := nil;
1408 g_Frames_Get(FramesID, 'FRAMES_WEAPON_PLASMA');
1409 Animation := TAnimation.Create(FramesID, True, 5);
1410 end;
1412 Shots[find_id].SpawnerUID := SpawnerUID;
1414 if not Silent then
1415 g_Sound_PlayExAt('SOUND_WEAPON_FIREPLASMA', x, y);
1416 end;
1418 procedure g_Weapon_flame(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1419 Silent: Boolean = False);
1420 var
1421 find_id: DWORD;
1422 dx, dy: Integer;
1423 begin
1424 if WID < 0 then
1425 find_id := FindShot()
1426 else
1427 begin
1428 find_id := WID;
1429 if Integer(find_id) >= High(Shots) then
1430 SetLength(Shots, find_id + 64);
1431 end;
1433 with Shots[find_id] do
1434 begin
1435 g_Obj_Init(@Obj);
1437 Obj.Rect.Width := SHOT_FLAME_WIDTH;
1438 Obj.Rect.Height := SHOT_FLAME_HEIGHT;
1440 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1441 dy := -(Obj.Rect.Height div 2);
1443 ShotType := WEAPON_FLAMETHROWER;
1444 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1446 triggers := nil;
1447 Animation := nil;
1448 TextureID := 0;
1449 g_Frames_Get(TextureID, 'FRAMES_FLAME');
1450 end;
1452 Shots[find_id].SpawnerUID := SpawnerUID;
1454 // if not Silent then
1455 // g_Sound_PlayExAt('SOUND_WEAPON_FIREPLASMA', x, y);
1456 end;
1458 procedure g_Weapon_ball1(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1459 Silent: Boolean = False);
1460 var
1461 find_id, FramesID: DWORD;
1462 dx, dy: Integer;
1463 begin
1464 if WID < 0 then
1465 find_id := FindShot()
1466 else
1467 begin
1468 find_id := WID;
1469 if Integer(find_id) >= High(Shots) then
1470 SetLength(Shots, find_id + 64)
1471 end;
1473 with Shots[find_id] do
1474 begin
1475 g_Obj_Init(@Obj);
1477 Obj.Rect.Width := 16;
1478 Obj.Rect.Height := 16;
1480 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1481 dy := -(Obj.Rect.Height div 2);
1483 ShotType := WEAPON_IMP_FIRE;
1484 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1486 triggers := nil;
1487 g_Frames_Get(FramesID, 'FRAMES_WEAPON_IMPFIRE');
1488 Animation := TAnimation.Create(FramesID, True, 4);
1489 end;
1491 Shots[find_id].SpawnerUID := SpawnerUID;
1493 if not Silent then
1494 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x, y);
1495 end;
1497 procedure g_Weapon_ball2(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1498 Silent: Boolean = False);
1499 var
1500 find_id, FramesID: DWORD;
1501 dx, dy: Integer;
1502 begin
1503 if WID < 0 then
1504 find_id := FindShot()
1505 else
1506 begin
1507 find_id := WID;
1508 if Integer(find_id) >= High(Shots) then
1509 SetLength(Shots, find_id + 64)
1510 end;
1512 with Shots[find_id] do
1513 begin
1514 g_Obj_Init(@Obj);
1516 Obj.Rect.Width := 16;
1517 Obj.Rect.Height := 16;
1519 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1520 dy := -(Obj.Rect.Height div 2);
1522 ShotType := WEAPON_CACO_FIRE;
1523 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1525 triggers := nil;
1526 g_Frames_Get(FramesID, 'FRAMES_WEAPON_CACOFIRE');
1527 Animation := TAnimation.Create(FramesID, True, 4);
1528 end;
1530 Shots[find_id].SpawnerUID := SpawnerUID;
1532 if not Silent then
1533 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x, y);
1534 end;
1536 procedure g_Weapon_ball7(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1537 Silent: Boolean = False);
1538 var
1539 find_id, FramesID: DWORD;
1540 dx, dy: Integer;
1541 begin
1542 if WID < 0 then
1543 find_id := FindShot()
1544 else
1545 begin
1546 find_id := WID;
1547 if Integer(find_id) >= High(Shots) then
1548 SetLength(Shots, find_id + 64)
1549 end;
1551 with Shots[find_id] do
1552 begin
1553 g_Obj_Init(@Obj);
1555 Obj.Rect.Width := 32;
1556 Obj.Rect.Height := 16;
1558 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1559 dy := -(Obj.Rect.Height div 2);
1561 ShotType := WEAPON_BARON_FIRE;
1562 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1564 triggers := nil;
1565 g_Frames_Get(FramesID, 'FRAMES_WEAPON_BARONFIRE');
1566 Animation := TAnimation.Create(FramesID, True, 4);
1567 end;
1569 Shots[find_id].SpawnerUID := SpawnerUID;
1571 if not Silent then
1572 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x, y);
1573 end;
1575 procedure g_Weapon_aplasma(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1576 Silent: Boolean = False);
1577 var
1578 find_id, FramesID: DWORD;
1579 dx, dy: Integer;
1580 begin
1581 if WID < 0 then
1582 find_id := FindShot()
1583 else
1584 begin
1585 find_id := WID;
1586 if Integer(find_id) >= High(Shots) then
1587 SetLength(Shots, find_id + 64)
1588 end;
1590 with Shots[find_id] do
1591 begin
1592 g_Obj_Init(@Obj);
1594 Obj.Rect.Width := 16;
1595 Obj.Rect.Height := 16;
1597 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1598 dy := -(Obj.Rect.Height div 2);
1600 ShotType := WEAPON_BSP_FIRE;
1601 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1603 triggers := nil;
1605 g_Frames_Get(FramesID, 'FRAMES_WEAPON_BSPFIRE');
1606 Animation := TAnimation.Create(FramesID, True, 4);
1607 end;
1609 Shots[find_id].SpawnerUID := SpawnerUID;
1611 if not Silent then
1612 g_Sound_PlayExAt('SOUND_WEAPON_FIREPLASMA', x, y);
1613 end;
1615 procedure g_Weapon_manfire(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1616 Silent: Boolean = False);
1617 var
1618 find_id, FramesID: DWORD;
1619 dx, dy: Integer;
1620 begin
1621 if WID < 0 then
1622 find_id := FindShot()
1623 else
1624 begin
1625 find_id := WID;
1626 if Integer(find_id) >= High(Shots) then
1627 SetLength(Shots, find_id + 64)
1628 end;
1630 with Shots[find_id] do
1631 begin
1632 g_Obj_Init(@Obj);
1634 Obj.Rect.Width := 32;
1635 Obj.Rect.Height := 32;
1637 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1638 dy := -(Obj.Rect.Height div 2);
1640 ShotType := WEAPON_MANCUB_FIRE;
1641 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1643 triggers := nil;
1645 g_Frames_Get(FramesID, 'FRAMES_WEAPON_MANCUBFIRE');
1646 Animation := TAnimation.Create(FramesID, True, 4);
1647 end;
1649 Shots[find_id].SpawnerUID := SpawnerUID;
1651 if not Silent then
1652 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x, y);
1653 end;
1655 procedure g_Weapon_bfgshot(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1656 Silent: Boolean = False);
1657 var
1658 find_id, FramesID: DWORD;
1659 dx, dy: Integer;
1660 begin
1661 if WID < 0 then
1662 find_id := FindShot()
1663 else
1664 begin
1665 find_id := WID;
1666 if Integer(find_id) >= High(Shots) then
1667 SetLength(Shots, find_id + 64)
1668 end;
1670 with Shots[find_id] do
1671 begin
1672 g_Obj_Init(@Obj);
1674 Obj.Rect.Width := SHOT_BFG_WIDTH;
1675 Obj.Rect.Height := SHOT_BFG_HEIGHT;
1677 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1678 dy := -(Obj.Rect.Height div 2);
1680 ShotType := WEAPON_BFG;
1681 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1683 triggers := nil;
1684 g_Frames_Get(FramesID, 'FRAMES_WEAPON_BFG');
1685 Animation := TAnimation.Create(FramesID, True, 6);
1686 end;
1688 Shots[find_id].SpawnerUID := SpawnerUID;
1690 if not Silent then
1691 g_Sound_PlayExAt('SOUND_WEAPON_FIREBFG', x, y);
1692 end;
1694 procedure g_Weapon_bfghit(x, y: Integer);
1695 var
1696 ID: DWORD;
1697 Anim: TAnimation;
1698 begin
1699 if g_Frames_Get(ID, 'FRAMES_BFGHIT') then
1700 begin
1701 Anim := TAnimation.Create(ID, False, 4);
1702 g_GFX_OnceAnim(x-32, y-32, Anim);
1703 Anim.Free();
1704 end;
1705 end;
1707 procedure g_Weapon_pistol(x, y, xd, yd: Integer; SpawnerUID: Word;
1708 Silent: Boolean = False);
1709 begin
1710 if not Silent then
1711 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', x, y);
1713 g_Weapon_gun(x, y, xd, yd, 1, 3, SpawnerUID, True);
1714 if gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF] then
1715 begin
1716 g_Weapon_gun(x, y+1, xd, yd+1, 1, 3, SpawnerUID, False);
1717 g_Weapon_gun(x, y-1, xd, yd-1, 1, 2, SpawnerUID, False);
1718 end;
1719 end;
1721 procedure g_Weapon_mgun(x, y, xd, yd: Integer; SpawnerUID: Word;
1722 Silent: Boolean = False);
1723 begin
1724 if not Silent then
1725 if gSoundEffectsDF then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', x, y);
1727 g_Weapon_gun(x, y, xd, yd, 1, 3, SpawnerUID, True);
1728 if (gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF]) and
1729 (g_GetUIDType(SpawnerUID) = UID_PLAYER) then
1730 begin
1731 g_Weapon_gun(x, y+1, xd, yd+1, 1, 2, SpawnerUID, False);
1732 g_Weapon_gun(x, y-1, xd, yd-1, 1, 2, SpawnerUID, False);
1733 end;
1734 end;
1736 procedure g_Weapon_shotgun(x, y, xd, yd: Integer; SpawnerUID: Word;
1737 Silent: Boolean = False);
1738 var
1739 i, j: Integer;
1740 begin
1741 if not Silent then
1742 if gSoundEffectsDF then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', x, y);
1744 for i := 0 to 9 do
1745 begin
1746 j := Random(17)-8; // -8 .. 8
1747 g_Weapon_gun(x, y+j, xd, yd+j, IfThen(i mod 2 <> 0, 1, 0), 3, SpawnerUID, i=0);
1748 end;
1749 end;
1751 procedure g_Weapon_dshotgun(x, y, xd, yd: Integer; SpawnerUID: Word;
1752 Silent: Boolean = False);
1753 var
1754 a, i, j: Integer;
1755 begin
1756 if not Silent then
1757 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', x, y);
1759 if gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF] then a := 25 else a := 20;
1760 for i := 0 to a do
1761 begin
1762 j := Random(41)-20; // -20 .. 20
1763 g_Weapon_gun(x, y+j, xd, yd+j, IfThen(i mod 3 <> 0, 0, 1), 3, SpawnerUID, i=0);
1764 end;
1765 end;
1767 procedure g_Weapon_Update();
1768 var
1769 i, a, h, cx, cy, oldvx, oldvy, tf: Integer;
1770 _id: DWORD;
1771 Anim: TAnimation;
1772 t: DWArray;
1773 st: Word;
1774 s: String;
1775 o: TObj;
1776 spl: Boolean;
1777 Loud: Boolean;
1778 tcx, tcy: Integer;
1779 begin
1780 if Shots = nil then
1781 Exit;
1783 for i := 0 to High(Shots) do
1784 begin
1785 if Shots[i].ShotType = 0 then
1786 Continue;
1788 Loud := True;
1790 with Shots[i] do
1791 begin
1792 Timeout := Timeout - 1;
1793 oldvx := Obj.Vel.X;
1794 oldvy := Obj.Vel.Y;
1795 // Àêòèâèðîâàòü òðèããåðû ïî ïóòè (êðîìå óæå àêòèâèðîâàííûõ):
1796 if (Stopped = 0) and g_Game_IsServer then
1797 t := g_Triggers_PressR(Obj.X, Obj.Y, Obj.Rect.Width, Obj.Rect.Height,
1798 SpawnerUID, ACTIVATE_SHOT, triggers)
1799 else
1800 t := nil;
1802 if t <> nil then
1803 begin
1804 // Ïîïîëíÿåì ñïèñîê àêòèâèðîâàííûõ òðèããåðîâ:
1805 if triggers = nil then
1806 triggers := t
1807 else
1808 begin
1809 h := High(t);
1811 for a := 0 to h do
1812 if not InDWArray(t[a], triggers) then
1813 begin
1814 SetLength(triggers, Length(triggers)+1);
1815 triggers[High(triggers)] := t[a];
1816 end;
1817 end;
1818 end;
1820 // Àíèìàöèÿ ñíàðÿäà:
1821 if Animation <> nil then
1822 Animation.Update();
1824 // Äâèæåíèå:
1825 spl := (ShotType <> WEAPON_PLASMA) and
1826 (ShotType <> WEAPON_BFG) and
1827 (ShotType <> WEAPON_BSP_FIRE) and
1828 (ShotType <> WEAPON_FLAMETHROWER);
1830 if Stopped = 0 then
1831 begin
1832 st := g_Obj_Move(@Obj, False, spl);
1833 end
1834 else
1835 begin
1836 st := 0;
1837 end;
1838 positionChanged(); // this updates spatial accelerators
1840 if WordBool(st and MOVE_FALLOUT) or (Obj.X < -1000) or
1841 (Obj.X > gMapInfo.Width+1000) or (Obj.Y < -1000) then
1842 begin
1843 // Íà êëèåíòå ñêîðåå âñåãî è òàê óæå âûïàë.
1844 ShotType := 0;
1845 Animation.Free();
1846 Continue;
1847 end;
1849 cx := Obj.X + (Obj.Rect.Width div 2);
1850 cy := Obj.Y + (Obj.Rect.Height div 2);
1852 case ShotType of
1853 WEAPON_ROCKETLAUNCHER, WEAPON_SKEL_FIRE: // Ðàêåòû è ñíàðÿäû Ñêåëåòà
1854 begin
1855 // Âûëåòåëà èç âîäû:
1856 if WordBool(st and MOVE_HITAIR) then
1857 g_Obj_SetSpeed(@Obj, 12);
1859 // Â âîäå øëåéô - ïóçûðè, â âîçäóõå øëåéô - äûì:
1860 if WordBool(st and MOVE_INWATER) then
1861 g_GFX_Bubbles(Obj.X+(Obj.Rect.Width div 2),
1862 Obj.Y+(Obj.Rect.Height div 2),
1863 1+Random(3), 16, 16)
1864 else
1865 if g_Frames_Get(_id, 'FRAMES_SMOKE') then
1866 begin
1867 Anim := TAnimation.Create(_id, False, 3);
1868 Anim.Alpha := 150;
1869 g_GFX_OnceAnim(Obj.X-14+Random(9),
1870 Obj.Y+(Obj.Rect.Height div 2)-20+Random(9),
1871 Anim, ONCEANIM_SMOKE);
1872 Anim.Free();
1873 end;
1875 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
1876 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL)) or
1877 (g_Weapon_Hit(@Obj, 10, SpawnerUID, HIT_SOME, False) <> 0) or
1878 (Timeout < 1) then
1879 begin
1880 Obj.Vel.X := 0;
1881 Obj.Vel.Y := 0;
1883 g_Weapon_Explode(cx, cy, 60, SpawnerUID);
1885 if ShotType = WEAPON_SKEL_FIRE then
1886 begin // Âçðûâ ñíàðÿäà Ñêåëåòà
1887 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_SKELFIRE') then
1888 begin
1889 Anim := TAnimation.Create(TextureID, False, 8);
1890 Anim.Blending := False;
1891 g_GFX_OnceAnim((Obj.X+32)-58, (Obj.Y+8)-36, Anim);
1892 g_DynLightExplosion((Obj.X+32), (Obj.Y+8), 64, 1, 0, 0);
1893 Anim.Free();
1894 end;
1895 end
1896 else
1897 begin // Âçðûâ Ðàêåòû
1898 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_ROCKET') then
1899 begin
1900 Anim := TAnimation.Create(TextureID, False, 6);
1901 Anim.Blending := False;
1902 g_GFX_OnceAnim(cx-64, cy-64, Anim);
1903 g_DynLightExplosion(cx, cy, 64, 1, 0, 0);
1904 Anim.Free();
1905 end;
1906 end;
1908 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', Obj.X, Obj.Y);
1910 ShotType := 0;
1911 end;
1913 if ShotType = WEAPON_SKEL_FIRE then
1914 begin // Ñàìîíàâîäêà ñíàðÿäà Ñêåëåòà:
1915 if GetPos(target, @o) then
1916 throw(i, Obj.X, Obj.Y,
1917 o.X+o.Rect.X+(o.Rect.Width div 2)+o.Vel.X+o.Accel.X,
1918 o.Y+o.Rect.Y+(o.Rect.Height div 2)+o.Vel.Y+o.Accel.Y,
1919 12);
1920 end;
1921 end;
1923 WEAPON_PLASMA, WEAPON_BSP_FIRE: // Ïëàçìà, ïëàçìà Àðàõíàòðîíà
1924 begin
1925 // Ïîïàëà â âîäó - ýëåêòðîøîê ïî âîäå:
1926 if WordBool(st and (MOVE_INWATER or MOVE_HITWATER)) then
1927 begin
1928 g_Sound_PlayExAt('SOUND_WEAPON_PLASMAWATER', Obj.X, Obj.Y);
1929 if g_Game_IsServer then CheckTrap(i, 10, HIT_ELECTRO);
1930 ShotType := 0;
1931 Continue;
1932 end;
1934 // Âåëè÷èíà óðîíà:
1935 if (ShotType = WEAPON_PLASMA) and
1936 (gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF]) then
1937 a := 10
1938 else
1939 a := 5;
1941 if ShotType = WEAPON_BSP_FIRE then
1942 a := 10;
1944 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
1945 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL)) or
1946 (g_Weapon_Hit(@Obj, a, SpawnerUID, HIT_SOME, False) <> 0) or
1947 (Timeout < 1) then
1948 begin
1949 if ShotType = WEAPON_PLASMA then
1950 s := 'FRAMES_EXPLODE_PLASMA'
1951 else
1952 s := 'FRAMES_EXPLODE_BSPFIRE';
1954 // Âçðûâ Ïëàçìû:
1955 if g_Frames_Get(TextureID, s) then
1956 begin
1957 Anim := TAnimation.Create(TextureID, False, 3);
1958 Anim.Blending := False;
1959 g_GFX_OnceAnim(cx-16, cy-16, Anim);
1960 Anim.Free();
1961 g_DynLightExplosion(cx, cy, 32, 0, 0.5, 0.5);
1962 end;
1964 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEPLASMA', Obj.X, Obj.Y);
1966 ShotType := 0;
1967 end;
1968 end;
1970 WEAPON_FLAMETHROWER: // Îãíåìåò
1971 begin
1972 // Ñî âðåìåíåì óìèðàåò
1973 if (Timeout < 1) then
1974 begin
1975 ShotType := 0;
1976 Continue;
1977 end;
1978 // Ïîä âîäîé òîæå
1979 if WordBool(st and (MOVE_HITWATER or MOVE_INWATER)) then
1980 begin
1981 if WordBool(st and MOVE_HITWATER) then
1982 begin
1983 if g_Frames_Get(_id, 'FRAMES_SMOKE') then
1984 begin
1985 Anim := TAnimation.Create(_id, False, 3);
1986 Anim.Alpha := 0;
1987 tcx := Random(8);
1988 tcy := Random(8);
1989 g_GFX_OnceAnim(cx-4+tcx-(Anim.Width div 2),
1990 cy-4+tcy-(Anim.Height div 2),
1991 Anim, ONCEANIM_SMOKE);
1992 Anim.Free();
1993 end;
1994 end
1995 else
1996 g_GFX_Bubbles(cx, cy, 1+Random(3), 16, 16);
1997 ShotType := 0;
1998 Continue;
1999 end;
2001 // Ãðàâèòàöèÿ
2002 if Stopped = 0 then
2003 Obj.Accel.Y := Obj.Accel.Y + 1;
2004 // Ïîïàëè â ñòåíó èëè â âîäó:
2005 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL or MOVE_HITWATER)) then
2006 begin
2007 // Ïðèëèïàåì:
2008 Obj.Vel.X := 0;
2009 Obj.Vel.Y := 0;
2010 Obj.Accel.Y := 0;
2011 if WordBool(st and MOVE_HITWALL) then
2012 Stopped := MOVE_HITWALL
2013 else if WordBool(st and MOVE_HITLAND) then
2014 Stopped := MOVE_HITLAND
2015 else if WordBool(st and MOVE_HITCEIL) then
2016 Stopped := MOVE_HITCEIL;
2017 end;
2019 a := IfThen(Stopped = 0, 3, 1);
2020 // Åñëè â êîãî-òî ïîïàëè
2021 if g_Weapon_Hit(@Obj, a, SpawnerUID, HIT_FLAME, False) <> 0 then
2022 begin
2023 // HIT_FLAME ñàì ïîäîææåò
2024 // Åñëè â ïîëåòå ïîïàëè, èñ÷åçàåì
2025 if Stopped = 0 then
2026 ShotType := 0;
2027 end;
2029 if Stopped = 0 then
2030 tf := 2
2031 else
2032 tf := 3;
2034 if (gTime mod tf = 0) then
2035 begin
2036 Anim := TAnimation.Create(TextureID, False, 2 + Random(2));
2037 Anim.Alpha := 0;
2038 case Stopped of
2039 MOVE_HITWALL: begin tcx := cx-4+Random(8); tcy := cy-12+Random(24); end;
2040 MOVE_HITLAND: begin tcx := cx-12+Random(24); tcy := cy-10+Random(8); end;
2041 MOVE_HITCEIL: begin tcx := cx-12+Random(24); tcy := cy+6+Random(8); end;
2042 else begin tcx := cx-4+Random(8); tcy := cy-4+Random(8); end;
2043 end;
2044 g_GFX_OnceAnim(tcx-(Anim.Width div 2), tcy-(Anim.Height div 2), Anim, ONCEANIM_SMOKE);
2045 Anim.Free();
2046 //g_DynLightExplosion(tcx, tcy, 1, 1, 0.8, 0.3);
2047 end;
2048 end;
2050 WEAPON_BFG: // BFG
2051 begin
2052 // Ïîïàëà â âîäó - ýëåêòðîøîê ïî âîäå:
2053 if WordBool(st and (MOVE_INWATER or MOVE_HITWATER)) then
2054 begin
2055 g_Sound_PlayExAt('SOUND_WEAPON_BFGWATER', Obj.X, Obj.Y);
2056 if g_Game_IsServer then CheckTrap(i, 1000, HIT_ELECTRO);
2057 ShotType := 0;
2058 Continue;
2059 end;
2061 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2062 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL)) or
2063 (g_Weapon_Hit(@Obj, SHOT_BFG_DAMAGE, SpawnerUID, HIT_BFG, False) <> 0) or
2064 (Timeout < 1) then
2065 begin
2066 // Ëó÷è BFG:
2067 if g_Game_IsServer then g_Weapon_BFG9000(cx, cy, SpawnerUID);
2069 // Âçðûâ BFG:
2070 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_BFG') then
2071 begin
2072 Anim := TAnimation.Create(TextureID, False, 6);
2073 Anim.Blending := False;
2074 g_GFX_OnceAnim(cx-64, cy-64, Anim);
2075 Anim.Free();
2076 g_DynLightExplosion(cx, cy, 96, 0, 1, 0);
2077 end;
2079 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', Obj.X, Obj.Y);
2081 ShotType := 0;
2082 end;
2083 end;
2085 WEAPON_IMP_FIRE, WEAPON_CACO_FIRE, WEAPON_BARON_FIRE: // Âûñòðåëû Áåñà, Êàêîäåìîíà Ðûöàðÿ/Áàðîíà àäà
2086 begin
2087 // Âûëåòåë èç âîäû:
2088 if WordBool(st and MOVE_HITAIR) then
2089 g_Obj_SetSpeed(@Obj, 16);
2091 // Âåëè÷èíà óðîíà:
2092 if ShotType = WEAPON_IMP_FIRE then
2093 a := 5
2094 else
2095 if ShotType = WEAPON_CACO_FIRE then
2096 a := 20
2097 else
2098 a := 40;
2100 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2101 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL)) or
2102 (g_Weapon_Hit(@Obj, a, SpawnerUID, HIT_SOME) <> 0) or
2103 (Timeout < 1) then
2104 begin
2105 if ShotType = WEAPON_IMP_FIRE then
2106 s := 'FRAMES_EXPLODE_IMPFIRE'
2107 else
2108 if ShotType = WEAPON_CACO_FIRE then
2109 s := 'FRAMES_EXPLODE_CACOFIRE'
2110 else
2111 s := 'FRAMES_EXPLODE_BARONFIRE';
2113 // Âçðûâ:
2114 if g_Frames_Get(TextureID, s) then
2115 begin
2116 Anim := TAnimation.Create(TextureID, False, 6);
2117 Anim.Blending := False;
2118 g_GFX_OnceAnim(cx-32, cy-32, Anim);
2119 Anim.Free();
2120 end;
2122 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj.X, Obj.Y);
2124 ShotType := 0;
2125 end;
2126 end;
2128 WEAPON_MANCUB_FIRE: // Âûñòðåë Ìàíêóáóñà
2129 begin
2130 // Âûëåòåë èç âîäû:
2131 if WordBool(st and MOVE_HITAIR) then
2132 g_Obj_SetSpeed(@Obj, 16);
2134 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2135 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL)) or
2136 (g_Weapon_Hit(@Obj, 40, SpawnerUID, HIT_SOME, False) <> 0) or
2137 (Timeout < 1) then
2138 begin
2139 // Âçðûâ:
2140 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_ROCKET') then
2141 begin
2142 Anim := TAnimation.Create(TextureID, False, 6);
2143 Anim.Blending := False;
2144 g_GFX_OnceAnim(cx-64, cy-64, Anim);
2145 Anim.Free();
2146 end;
2148 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj.X, Obj.Y);
2150 ShotType := 0;
2151 end;
2152 end;
2153 end; // case ShotType of...
2155 // Åñëè ñíàðÿäà óæå íåò, óäàëÿåì àíèìàöèþ:
2156 if (ShotType = 0) then
2157 begin
2158 if gGameSettings.GameType = GT_SERVER then
2159 MH_SEND_DeleteShot(i, Obj.X, Obj.Y, Loud);
2160 if Animation <> nil then
2161 begin
2162 Animation.Free();
2163 Animation := nil;
2164 end;
2165 end
2166 else if (ShotType <> WEAPON_FLAMETHROWER) and ((oldvx <> Obj.Vel.X) or (oldvy <> Obj.Vel.Y)) then
2167 if gGameSettings.GameType = GT_SERVER then
2168 MH_SEND_UpdateShot(i);
2169 end;
2170 end;
2171 end;
2173 procedure g_Weapon_Draw();
2174 var
2175 i: Integer;
2176 a: SmallInt;
2177 p: TPoint;
2178 begin
2179 if Shots = nil then
2180 Exit;
2182 for i := 0 to High(Shots) do
2183 if Shots[i].ShotType <> 0 then
2184 with Shots[i] do
2185 begin
2186 if (Shots[i].ShotType = WEAPON_ROCKETLAUNCHER) or
2187 (Shots[i].ShotType = WEAPON_BARON_FIRE) or
2188 (Shots[i].ShotType = WEAPON_MANCUB_FIRE) or
2189 (Shots[i].ShotType = WEAPON_SKEL_FIRE) then
2190 a := -GetAngle2(Obj.Vel.X, Obj.Vel.Y)
2191 else
2192 a := 0;
2194 p.X := Obj.Rect.Width div 2;
2195 p.Y := Obj.Rect.Height div 2;
2197 if Animation <> nil then
2198 begin
2199 if (Shots[i].ShotType = WEAPON_BARON_FIRE) or
2200 (Shots[i].ShotType = WEAPON_MANCUB_FIRE) or
2201 (Shots[i].ShotType = WEAPON_SKEL_FIRE) then
2202 Animation.DrawEx(Obj.X, Obj.Y, M_NONE, p, a)
2203 else
2204 Animation.Draw(Obj.X, Obj.Y, M_NONE);
2205 end
2206 else if TextureID <> 0 then
2207 begin
2208 if (Shots[i].ShotType = WEAPON_ROCKETLAUNCHER) then
2209 e_DrawAdv(TextureID, Obj.X, Obj.Y, 0, True, False, a, @p, M_NONE)
2210 else if (Shots[i].ShotType <> WEAPON_FLAMETHROWER) then
2211 e_Draw(TextureID, Obj.X, Obj.Y, 0, True, False);
2212 end;
2214 if g_debug_Frames then
2215 begin
2216 e_DrawQuad(Obj.X+Obj.Rect.X,
2217 Obj.Y+Obj.Rect.Y,
2218 Obj.X+Obj.Rect.X+Obj.Rect.Width-1,
2219 Obj.Y+Obj.Rect.Y+Obj.Rect.Height-1,
2220 0, 255, 0);
2221 end;
2222 end;
2223 end;
2225 function g_Weapon_Danger(UID: Word; X, Y: Integer; Width, Height: Word; Time: Byte): Boolean;
2226 var
2227 a: Integer;
2228 begin
2229 Result := False;
2231 if Shots = nil then
2232 Exit;
2234 for a := 0 to High(Shots) do
2235 if (Shots[a].ShotType <> 0) and (Shots[a].SpawnerUID <> UID) then
2236 if ((Shots[a].Obj.Vel.Y = 0) and (Shots[a].Obj.Vel.X > 0) and (Shots[a].Obj.X < X)) or
2237 (Shots[a].Obj.Vel.Y = 0) and (Shots[a].Obj.Vel.X < 0) and (Shots[a].Obj.X > X) then
2238 if (Abs(X-Shots[a].Obj.X) < Abs(Shots[a].Obj.Vel.X*Time)) and
2239 g_Collide(X, Y, Width, Height, X, Shots[a].Obj.Y,
2240 Shots[a].Obj.Rect.Width, Shots[a].Obj.Rect.Height) and
2241 g_TraceVector(X, Y, Shots[a].Obj.X, Shots[a].Obj.Y) then
2242 begin
2243 Result := True;
2244 Exit;
2245 end;
2246 end;
2248 procedure g_Weapon_SaveState(var Mem: TBinMemoryWriter);
2249 var
2250 count, i, j: Integer;
2251 dw: DWORD;
2252 begin
2253 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ ñíàðÿäîâ:
2254 count := 0;
2255 if Shots <> nil then
2256 for i := 0 to High(Shots) do
2257 if Shots[i].ShotType <> 0 then
2258 count := count + 1;
2260 Mem := TBinMemoryWriter.Create((count+1) * 80);
2262 // Êîëè÷åñòâî ñíàðÿäîâ:
2263 Mem.WriteInt(count);
2265 if count = 0 then
2266 Exit;
2268 for i := 0 to High(Shots) do
2269 if Shots[i].ShotType <> 0 then
2270 begin
2271 // Ñèãíàòóðà ñíàðÿäà:
2272 dw := SHOT_SIGNATURE; // 'SHOT'
2273 Mem.WriteDWORD(dw);
2274 // Òèï ñíàðÿäà:
2275 Mem.WriteByte(Shots[i].ShotType);
2276 // Öåëü:
2277 Mem.WriteWord(Shots[i].Target);
2278 // UID ñòðåëÿâøåãî:
2279 Mem.WriteWord(Shots[i].SpawnerUID);
2280 // Ðàçìåð ïîëÿ Triggers:
2281 dw := Length(Shots[i].Triggers);
2282 Mem.WriteDWORD(dw);
2283 // Òðèããåðû, àêòèâèðîâàííûå âûñòðåëîì:
2284 for j := 0 to Integer(dw)-1 do
2285 Mem.WriteDWORD(Shots[i].Triggers[j]);
2286 // Îáúåêò ñíàðÿäà:
2287 Obj_SaveState(@Shots[i].Obj, Mem);
2288 // Êîñòûëèíà åáàíàÿ:
2289 Mem.WriteByte(Shots[i].Stopped);
2290 end;
2291 end;
2293 procedure g_Weapon_LoadState(var Mem: TBinMemoryReader);
2294 var
2295 count, i, j: Integer;
2296 dw: DWORD;
2297 begin
2298 if Mem = nil then
2299 Exit;
2301 // Êîëè÷åñòâî ñíàðÿäîâ:
2302 Mem.ReadInt(count);
2304 SetLength(Shots, count);
2306 if count = 0 then
2307 Exit;
2309 for i := 0 to count-1 do
2310 begin
2311 // Ñèãíàòóðà ñíàðÿäà:
2312 Mem.ReadDWORD(dw);
2313 if dw <> SHOT_SIGNATURE then // 'SHOT'
2314 begin
2315 raise EBinSizeError.Create('g_Weapons_LoadState: Wrong Shot Signature');
2316 end;
2317 // Òèï ñíàðÿäà:
2318 Mem.ReadByte(Shots[i].ShotType);
2319 // Öåëü:
2320 Mem.ReadWord(Shots[i].Target);
2321 // UID ñòðåëÿâøåãî:
2322 Mem.ReadWord(Shots[i].SpawnerUID);
2323 // Ðàçìåð ïîëÿ Triggers:
2324 Mem.ReadDWORD(dw);
2325 SetLength(Shots[i].Triggers, dw);
2326 // Òðèããåðû, àêòèâèðîâàííûå âûñòðåëîì:
2327 for j := 0 to Integer(dw)-1 do
2328 Mem.ReadDWORD(Shots[i].Triggers[j]);
2329 // Îáúåêò ïðåäìåòà:
2330 Obj_LoadState(@Shots[i].Obj, Mem);
2331 // Êîñòûëèíà åáàíàÿ:
2332 Mem.ReadByte(Shots[i].Stopped);
2334 // Óñòàíîâêà òåêñòóðû èëè àíèìàöèè:
2335 Shots[i].TextureID := DWORD(-1);
2336 Shots[i].Animation := nil;
2338 case Shots[i].ShotType of
2339 WEAPON_ROCKETLAUNCHER, WEAPON_SKEL_FIRE:
2340 begin
2341 g_Texture_Get('TEXTURE_WEAPON_ROCKET', Shots[i].TextureID);
2342 end;
2343 WEAPON_PLASMA:
2344 begin
2345 g_Frames_Get(dw, 'FRAMES_WEAPON_PLASMA');
2346 Shots[i].Animation := TAnimation.Create(dw, True, 5);
2347 end;
2348 WEAPON_BFG:
2349 begin
2350 g_Frames_Get(dw, 'FRAMES_WEAPON_BFG');
2351 Shots[i].Animation := TAnimation.Create(dw, True, 6);
2352 end;
2353 WEAPON_IMP_FIRE:
2354 begin
2355 g_Frames_Get(dw, 'FRAMES_WEAPON_IMPFIRE');
2356 Shots[i].Animation := TAnimation.Create(dw, True, 4);
2357 end;
2358 WEAPON_BSP_FIRE:
2359 begin
2360 g_Frames_Get(dw, 'FRAMES_WEAPON_BSPFIRE');
2361 Shots[i].Animation := TAnimation.Create(dw, True, 4);
2362 end;
2363 WEAPON_CACO_FIRE:
2364 begin
2365 g_Frames_Get(dw, 'FRAMES_WEAPON_CACOFIRE');
2366 Shots[i].Animation := TAnimation.Create(dw, True, 4);
2367 end;
2368 WEAPON_BARON_FIRE:
2369 begin
2370 g_Frames_Get(dw, 'FRAMES_WEAPON_BARONFIRE');
2371 Shots[i].Animation := TAnimation.Create(dw, True, 4);
2372 end;
2373 WEAPON_MANCUB_FIRE:
2374 begin
2375 g_Frames_Get(dw, 'FRAMES_WEAPON_MANCUBFIRE');
2376 Shots[i].Animation := TAnimation.Create(dw, True, 4);
2377 end;
2378 end;
2379 end;
2380 end;
2382 procedure g_Weapon_DestroyShot(I: Integer; X, Y: Integer; Loud: Boolean = True);
2383 var
2384 cx, cy: Integer;
2385 Anim: TAnimation;
2386 s: string;
2387 begin
2388 if Shots = nil then
2389 Exit;
2390 if (I > High(Shots)) or (I < 0) then Exit;
2392 with Shots[I] do
2393 begin
2394 if ShotType = 0 then Exit;
2395 Obj.X := X;
2396 Obj.Y := Y;
2397 cx := Obj.X + (Obj.Rect.Width div 2);
2398 cy := Obj.Y + (Obj.Rect.Height div 2);
2400 case ShotType of
2401 WEAPON_ROCKETLAUNCHER, WEAPON_SKEL_FIRE: // Ðàêåòû è ñíàðÿäû Ñêåëåòà
2402 begin
2403 if Loud then
2404 begin
2405 if ShotType = WEAPON_SKEL_FIRE then
2406 begin // Âçðûâ ñíàðÿäà Ñêåëåòà
2407 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_SKELFIRE') then
2408 begin
2409 Anim := TAnimation.Create(TextureID, False, 8);
2410 Anim.Blending := False;
2411 g_GFX_OnceAnim((Obj.X+32)-32, (Obj.Y+8)-32, Anim);
2412 Anim.Free();
2413 end;
2414 end
2415 else
2416 begin // Âçðûâ Ðàêåòû
2417 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_ROCKET') then
2418 begin
2419 Anim := TAnimation.Create(TextureID, False, 6);
2420 Anim.Blending := False;
2421 g_GFX_OnceAnim(cx-64, cy-64, Anim);
2422 Anim.Free();
2423 end;
2424 end;
2425 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', Obj.X, Obj.Y);
2426 end;
2427 end;
2429 WEAPON_PLASMA, WEAPON_BSP_FIRE: // Ïëàçìà, ïëàçìà Àðàõíàòðîíà
2430 begin
2431 if ShotType = WEAPON_PLASMA then
2432 s := 'FRAMES_EXPLODE_PLASMA'
2433 else
2434 s := 'FRAMES_EXPLODE_BSPFIRE';
2436 if g_Frames_Get(TextureID, s) and loud then
2437 begin
2438 Anim := TAnimation.Create(TextureID, False, 3);
2439 Anim.Blending := False;
2440 g_GFX_OnceAnim(cx-16, cy-16, Anim);
2441 Anim.Free();
2443 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEPLASMA', Obj.X, Obj.Y);
2444 end;
2445 end;
2447 WEAPON_BFG: // BFG
2448 begin
2449 // Âçðûâ BFG:
2450 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_BFG') and Loud then
2451 begin
2452 Anim := TAnimation.Create(TextureID, False, 6);
2453 Anim.Blending := False;
2454 g_GFX_OnceAnim(cx-64, cy-64, Anim);
2455 Anim.Free();
2457 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', Obj.X, Obj.Y);
2458 end;
2459 end;
2461 WEAPON_IMP_FIRE, WEAPON_CACO_FIRE, WEAPON_BARON_FIRE: // Âûñòðåëû Áåñà, Êàêîäåìîíà Ðûöàðÿ/Áàðîíà àäà
2462 begin
2463 if ShotType = WEAPON_IMP_FIRE then
2464 s := 'FRAMES_EXPLODE_IMPFIRE'
2465 else
2466 if ShotType = WEAPON_CACO_FIRE then
2467 s := 'FRAMES_EXPLODE_CACOFIRE'
2468 else
2469 s := 'FRAMES_EXPLODE_BARONFIRE';
2471 if g_Frames_Get(TextureID, s) and Loud then
2472 begin
2473 Anim := TAnimation.Create(TextureID, False, 6);
2474 Anim.Blending := False;
2475 g_GFX_OnceAnim(cx-32, cy-32, Anim);
2476 Anim.Free();
2478 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj.X, Obj.Y);
2479 end;
2480 end;
2482 WEAPON_MANCUB_FIRE: // Âûñòðåë Ìàíêóáóñà
2483 begin
2484 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_ROCKET') and Loud then
2485 begin
2486 Anim := TAnimation.Create(TextureID, False, 6);
2487 Anim.Blending := False;
2488 g_GFX_OnceAnim(cx-64, cy-64, Anim);
2489 Anim.Free();
2491 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj.X, Obj.Y);
2492 end;
2493 end;
2494 end; // case ShotType of...
2496 ShotType := 0;
2497 Animation.Free();
2498 end;
2499 end;
2502 procedure g_Weapon_AddDynLights();
2503 var
2504 i: Integer;
2505 begin
2506 if Shots = nil then Exit;
2507 for i := 0 to High(Shots) do
2508 begin
2509 if Shots[i].ShotType = 0 then continue;
2510 if (Shots[i].ShotType = WEAPON_ROCKETLAUNCHER) or
2511 (Shots[i].ShotType = WEAPON_BARON_FIRE) or
2512 (Shots[i].ShotType = WEAPON_MANCUB_FIRE) or
2513 (Shots[i].ShotType = WEAPON_SKEL_FIRE) or
2514 (Shots[i].ShotType = WEAPON_IMP_FIRE) or
2515 (Shots[i].ShotType = WEAPON_CACO_FIRE) or
2516 (Shots[i].ShotType = WEAPON_MANCUB_FIRE) or
2517 (Shots[i].ShotType = WEAPON_BSP_FIRE) or
2518 (Shots[i].ShotType = WEAPON_PLASMA) or
2519 (Shots[i].ShotType = WEAPON_BFG) or
2520 (Shots[i].ShotType = WEAPON_FLAMETHROWER) or
2521 false then
2522 begin
2523 if (Shots[i].ShotType = WEAPON_PLASMA) then
2524 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)
2525 else if (Shots[i].ShotType = WEAPON_BFG) then
2526 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)
2527 else if (Shots[i].ShotType = WEAPON_FLAMETHROWER) then
2528 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)
2529 else
2530 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);
2531 end;
2532 end;
2533 end;
2536 procedure TShot.positionChanged (); begin end;
2539 end.