DEADSOFTWARE

accelerated explosion sq
[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.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.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; // squared radius
934 function monsExCheck (monidx: Integer; mon: TMonster): Boolean;
935 var
936 dx, dy, mm: Integer;
937 begin
938 result := false; // don't stop
939 begin
940 dx := mon.Obj.X+mon.Obj.Rect.X+(mon.Obj.Rect.Width div 2)-X;
941 dy := mon.Obj.Y+mon.Obj.Rect.Y+(mon.Obj.Rect.Height div 2)-Y;
943 if dx > 1000 then dx := 1000;
944 if dy > 1000 then dy := 1000;
946 if (dx*dx+dy*dy < r) then
947 begin
948 //m := PointToRect(X, Y, Obj.X+Obj.Rect.X, Obj.Y+Obj.Rect.Y, Obj.Rect.Width, Obj.Rect.Height);
949 //e_WriteLog(Format('explo monster #%d: x=%d; y=%d; rad=%d; dx=%d; dy=%d', [monidx, X, Y, rad, dx, dy]), MSG_NOTIFY);
951 mm := Max(abs(dx), abs(dy));
952 if mm = 0 then mm := 1;
954 if mon.Live then
955 begin
956 HitMonster(mon, ((mon.Obj.Rect.Width div 4)*10*(rad-mm)) div rad, 0, 0, SpawnerUID, HIT_ROCKET);
957 end;
959 mon.Push((dx*7) div mm, (dy*7) div mm);
960 end;
961 end;
962 end;
964 var
965 i, h, dx, dy, m, mm: Integer;
966 _angle: SmallInt;
967 begin
968 result := false;
970 g_Triggers_PressC(X, Y, rad, SpawnerUID, ACTIVATE_SHOT);
972 r := rad*rad;
974 h := High(gPlayers);
976 if h <> -1 then
977 for i := 0 to h do
978 if (gPlayers[i] <> nil) and gPlayers[i].Live then
979 with gPlayers[i] do
980 begin
981 dx := Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2)-X;
982 dy := Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)-Y;
984 if dx > 1000 then dx := 1000;
985 if dy > 1000 then dy := 1000;
987 if dx*dx+dy*dy < r then
988 begin
989 //m := PointToRect(X, Y, GameX+PLAYER_RECT.X, GameY+PLAYER_RECT.Y,
990 // PLAYER_RECT.Width, PLAYER_RECT.Height);
992 mm := Max(abs(dx), abs(dy));
993 if mm = 0 then mm := 1;
995 HitPlayer(gPlayers[i], (100*(rad-mm)) div rad, (dx*10) div mm, (dy*10) div mm, SpawnerUID, HIT_ROCKET);
996 gPlayers[i].Push((dx*7) div mm, (dy*7) div mm);
997 end;
998 end;
1000 //g_Mons_ForEach(monsExCheck);
1001 g_Mons_ForEachAt(X-(rad+32), Y-(rad+32), (rad+32)*2, (rad+32)*2, monsExCheck);
1003 h := High(gCorpses);
1005 if gAdvCorpses and (h <> -1) then
1006 for i := 0 to h do
1007 if (gCorpses[i] <> nil) and (gCorpses[i].State <> CORPSE_STATE_REMOVEME) then
1008 with gCorpses[i] do
1009 begin
1010 dx := Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2)-X;
1011 dy := Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)-Y;
1013 if dx > 1000 then dx := 1000;
1014 if dy > 1000 then dy := 1000;
1016 if dx*dx+dy*dy < r then
1017 begin
1018 m := PointToRect(X, Y, Obj.X+Obj.Rect.X, Obj.Y+Obj.Rect.Y,
1019 Obj.Rect.Width, Obj.Rect.Height);
1021 mm := Max(abs(dx), abs(dy));
1022 if mm = 0 then mm := 1;
1024 Damage(Round(100*(rad-m)/rad), (dx*10) div mm, (dy*10) div mm);
1025 end;
1026 end;
1028 h := High(gGibs);
1030 if gAdvGibs and (h <> -1) then
1031 for i := 0 to h do
1032 if gGibs[i].Live then
1033 with gGibs[i] do
1034 begin
1035 dx := Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2)-X;
1036 dy := Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)-Y;
1038 if dx > 1000 then dx := 1000;
1039 if dy > 1000 then dy := 1000;
1041 if dx*dx+dy*dy < r then
1042 begin
1043 m := PointToRect(X, Y, Obj.X+Obj.Rect.X, Obj.Y+Obj.Rect.Y,
1044 Obj.Rect.Width, Obj.Rect.Height);
1045 _angle := GetAngle(Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2),
1046 Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2), X, Y);
1048 g_Obj_PushA(@Obj, Round(15*(rad-m)/rad), _angle);
1049 positionChanged(); // this updates spatial accelerators
1050 end;
1051 end;
1052 end;
1054 procedure g_Weapon_Init();
1055 begin
1056 CreateWaterMap();
1057 end;
1059 procedure g_Weapon_Free();
1060 var
1061 i: Integer;
1062 begin
1063 if Shots <> nil then
1064 begin
1065 for i := 0 to High(Shots) do
1066 if Shots[i].ShotType <> 0 then
1067 Shots[i].Animation.Free();
1069 Shots := nil;
1070 end;
1072 WaterMap := nil;
1073 end;
1075 procedure g_Weapon_LoadData();
1076 begin
1077 e_WriteLog('Loading weapons data...', MSG_NOTIFY);
1079 g_Sound_CreateWADEx('SOUND_WEAPON_HITPUNCH', GameWAD+':SOUNDS\HITPUNCH');
1080 g_Sound_CreateWADEx('SOUND_WEAPON_MISSPUNCH', GameWAD+':SOUNDS\MISSPUNCH');
1081 g_Sound_CreateWADEx('SOUND_WEAPON_HITBERSERK', GameWAD+':SOUNDS\HITBERSERK');
1082 g_Sound_CreateWADEx('SOUND_WEAPON_MISSBERSERK', GameWAD+':SOUNDS\MISSBERSERK');
1083 g_Sound_CreateWADEx('SOUND_WEAPON_SELECTSAW', GameWAD+':SOUNDS\SELECTSAW');
1084 g_Sound_CreateWADEx('SOUND_WEAPON_IDLESAW', GameWAD+':SOUNDS\IDLESAW');
1085 g_Sound_CreateWADEx('SOUND_WEAPON_HITSAW', GameWAD+':SOUNDS\HITSAW');
1086 g_Sound_CreateWADEx('SOUND_WEAPON_FIRESHOTGUN2', GameWAD+':SOUNDS\FIRESHOTGUN2');
1087 g_Sound_CreateWADEx('SOUND_WEAPON_FIRESHOTGUN', GameWAD+':SOUNDS\FIRESHOTGUN');
1088 g_Sound_CreateWADEx('SOUND_WEAPON_FIRESAW', GameWAD+':SOUNDS\FIRESAW');
1089 g_Sound_CreateWADEx('SOUND_WEAPON_FIREROCKET', GameWAD+':SOUNDS\FIREROCKET');
1090 g_Sound_CreateWADEx('SOUND_WEAPON_FIREPLASMA', GameWAD+':SOUNDS\FIREPLASMA');
1091 g_Sound_CreateWADEx('SOUND_WEAPON_FIREPISTOL', GameWAD+':SOUNDS\FIREPISTOL');
1092 g_Sound_CreateWADEx('SOUND_WEAPON_FIRECGUN', GameWAD+':SOUNDS\FIRECGUN');
1093 g_Sound_CreateWADEx('SOUND_WEAPON_FIREBFG', GameWAD+':SOUNDS\FIREBFG');
1094 g_Sound_CreateWADEx('SOUND_FIRE', GameWAD+':SOUNDS\FIRE');
1095 g_Sound_CreateWADEx('SOUND_WEAPON_STARTFIREBFG', GameWAD+':SOUNDS\STARTFIREBFG');
1096 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEROCKET', GameWAD+':SOUNDS\EXPLODEROCKET');
1097 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEBFG', GameWAD+':SOUNDS\EXPLODEBFG');
1098 g_Sound_CreateWADEx('SOUND_WEAPON_BFGWATER', GameWAD+':SOUNDS\BFGWATER');
1099 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEPLASMA', GameWAD+':SOUNDS\EXPLODEPLASMA');
1100 g_Sound_CreateWADEx('SOUND_WEAPON_PLASMAWATER', GameWAD+':SOUNDS\PLASMAWATER');
1101 g_Sound_CreateWADEx('SOUND_WEAPON_FIREBALL', GameWAD+':SOUNDS\FIREBALL');
1102 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEBALL', GameWAD+':SOUNDS\EXPLODEBALL');
1103 g_Sound_CreateWADEx('SOUND_WEAPON_FIREREV', GameWAD+':SOUNDS\FIREREV');
1104 g_Sound_CreateWADEx('SOUND_PLAYER_JETFLY', GameWAD+':SOUNDS\WORKJETPACK');
1105 g_Sound_CreateWADEx('SOUND_PLAYER_JETON', GameWAD+':SOUNDS\STARTJETPACK');
1106 g_Sound_CreateWADEx('SOUND_PLAYER_JETOFF', GameWAD+':SOUNDS\STOPJETPACK');
1107 g_Sound_CreateWADEx('SOUND_PLAYER_CASING1', GameWAD+':SOUNDS\CASING1');
1108 g_Sound_CreateWADEx('SOUND_PLAYER_CASING2', GameWAD+':SOUNDS\CASING2');
1109 g_Sound_CreateWADEx('SOUND_PLAYER_SHELL1', GameWAD+':SOUNDS\SHELL1');
1110 g_Sound_CreateWADEx('SOUND_PLAYER_SHELL2', GameWAD+':SOUNDS\SHELL2');
1112 g_Texture_CreateWADEx('TEXTURE_WEAPON_ROCKET', GameWAD+':TEXTURES\BROCKET');
1113 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_SKELFIRE', GameWAD+':TEXTURES\BSKELFIRE', 64, 16, 2);
1114 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_BFG', GameWAD+':TEXTURES\BBFG', 64, 64, 2);
1115 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_PLASMA', GameWAD+':TEXTURES\BPLASMA', 16, 16, 2);
1116 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_IMPFIRE', GameWAD+':TEXTURES\BIMPFIRE', 16, 16, 2);
1117 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_BSPFIRE', GameWAD+':TEXTURES\BBSPFIRE', 16, 16, 2);
1118 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_CACOFIRE', GameWAD+':TEXTURES\BCACOFIRE', 16, 16, 2);
1119 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_BARONFIRE', GameWAD+':TEXTURES\BBARONFIRE', 64, 16, 2);
1120 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_MANCUBFIRE', GameWAD+':TEXTURES\BMANCUBFIRE', 64, 32, 2);
1121 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_ROCKET', GameWAD+':TEXTURES\EROCKET', 128, 128, 6);
1122 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_SKELFIRE', GameWAD+':TEXTURES\ESKELFIRE', 64, 64, 3);
1123 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_BFG', GameWAD+':TEXTURES\EBFG', 128, 128, 6);
1124 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_IMPFIRE', GameWAD+':TEXTURES\EIMPFIRE', 64, 64, 3);
1125 g_Frames_CreateWAD(nil, 'FRAMES_BFGHIT', GameWAD+':TEXTURES\BFGHIT', 64, 64, 4);
1126 g_Frames_CreateWAD(nil, 'FRAMES_FIRE', GameWAD+':TEXTURES\FIRE', 64, 128, 8);
1127 g_Frames_CreateWAD(nil, 'FRAMES_FLAME', GameWAD+':TEXTURES\FLAME', 32, 32, 11);
1128 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_PLASMA', GameWAD+':TEXTURES\EPLASMA', 32, 32, 4, True);
1129 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_BSPFIRE', GameWAD+':TEXTURES\EBSPFIRE', 32, 32, 5);
1130 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_CACOFIRE', GameWAD+':TEXTURES\ECACOFIRE', 64, 64, 3);
1131 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_BARONFIRE', GameWAD+':TEXTURES\EBARONFIRE', 64, 64, 3);
1132 g_Frames_CreateWAD(nil, 'FRAMES_SMOKE', GameWAD+':TEXTURES\SMOKE', 32, 32, 10, False);
1134 g_Texture_CreateWADEx('TEXTURE_SHELL_BULLET', GameWAD+':TEXTURES\EBULLET');
1135 g_Texture_CreateWADEx('TEXTURE_SHELL_SHELL', GameWAD+':TEXTURES\ESHELL');
1136 end;
1138 procedure g_Weapon_FreeData();
1139 begin
1140 e_WriteLog('Releasing weapons data...', MSG_NOTIFY);
1142 g_Sound_Delete('SOUND_WEAPON_HITPUNCH');
1143 g_Sound_Delete('SOUND_WEAPON_MISSPUNCH');
1144 g_Sound_Delete('SOUND_WEAPON_HITBERSERK');
1145 g_Sound_Delete('SOUND_WEAPON_MISSBERSERK');
1146 g_Sound_Delete('SOUND_WEAPON_SELECTSAW');
1147 g_Sound_Delete('SOUND_WEAPON_IDLESAW');
1148 g_Sound_Delete('SOUND_WEAPON_HITSAW');
1149 g_Sound_Delete('SOUND_WEAPON_FIRESHOTGUN2');
1150 g_Sound_Delete('SOUND_WEAPON_FIRESHOTGUN');
1151 g_Sound_Delete('SOUND_WEAPON_FIRESAW');
1152 g_Sound_Delete('SOUND_WEAPON_FIREROCKET');
1153 g_Sound_Delete('SOUND_WEAPON_FIREPLASMA');
1154 g_Sound_Delete('SOUND_WEAPON_FIREPISTOL');
1155 g_Sound_Delete('SOUND_WEAPON_FIRECGUN');
1156 g_Sound_Delete('SOUND_WEAPON_FIREBFG');
1157 g_Sound_Delete('SOUND_FIRE');
1158 g_Sound_Delete('SOUND_WEAPON_STARTFIREBFG');
1159 g_Sound_Delete('SOUND_WEAPON_EXPLODEROCKET');
1160 g_Sound_Delete('SOUND_WEAPON_EXPLODEBFG');
1161 g_Sound_Delete('SOUND_WEAPON_BFGWATER');
1162 g_Sound_Delete('SOUND_WEAPON_EXPLODEPLASMA');
1163 g_Sound_Delete('SOUND_WEAPON_PLASMAWATER');
1164 g_Sound_Delete('SOUND_WEAPON_FIREBALL');
1165 g_Sound_Delete('SOUND_WEAPON_EXPLODEBALL');
1166 g_Sound_Delete('SOUND_WEAPON_FIREREV');
1167 g_Sound_Delete('SOUND_PLAYER_JETFLY');
1168 g_Sound_Delete('SOUND_PLAYER_JETON');
1169 g_Sound_Delete('SOUND_PLAYER_JETOFF');
1170 g_Sound_Delete('SOUND_PLAYER_CASING1');
1171 g_Sound_Delete('SOUND_PLAYER_CASING2');
1172 g_Sound_Delete('SOUND_PLAYER_SHELL1');
1173 g_Sound_Delete('SOUND_PLAYER_SHELL2');
1175 g_Texture_Delete('TEXTURE_WEAPON_ROCKET');
1176 g_Frames_DeleteByName('FRAMES_WEAPON_BFG');
1177 g_Frames_DeleteByName('FRAMES_WEAPON_PLASMA');
1178 g_Frames_DeleteByName('FRAMES_WEAPON_IMPFIRE');
1179 g_Frames_DeleteByName('FRAMES_WEAPON_BSPFIRE');
1180 g_Frames_DeleteByName('FRAMES_WEAPON_CACOFIRE');
1181 g_Frames_DeleteByName('FRAMES_WEAPON_MANCUBFIRE');
1182 g_Frames_DeleteByName('FRAMES_EXPLODE_ROCKET');
1183 g_Frames_DeleteByName('FRAMES_EXPLODE_BFG');
1184 g_Frames_DeleteByName('FRAMES_EXPLODE_IMPFIRE');
1185 g_Frames_DeleteByName('FRAMES_BFGHIT');
1186 g_Frames_DeleteByName('FRAMES_FIRE');
1187 g_Frames_DeleteByName('FRAMES_EXPLODE_PLASMA');
1188 g_Frames_DeleteByName('FRAMES_EXPLODE_BSPFIRE');
1189 g_Frames_DeleteByName('FRAMES_EXPLODE_CACOFIRE');
1190 g_Frames_DeleteByName('FRAMES_SMOKE');
1191 g_Frames_DeleteByName('FRAMES_WEAPON_BARONFIRE');
1192 g_Frames_DeleteByName('FRAMES_EXPLODE_BARONFIRE');
1193 end;
1195 procedure g_Weapon_gun(x, y, xd, yd, v, dmg: Integer; SpawnerUID: Word; CheckTrigger: Boolean);
1196 var
1197 a: Integer;
1198 x2, y2: Integer;
1199 dx, dy: Integer;
1200 xe, ye: Integer;
1201 xi, yi: Integer;
1202 s, c: Extended;
1203 //vx, vy: Integer;
1204 xx, yy, d: Integer;
1206 i: Integer;
1207 t1, _collide: Boolean;
1208 w, h: Word;
1209 begin
1210 a := GetAngle(x, y, xd, yd)+180;
1212 SinCos(DegToRad(-a), s, c);
1214 if Abs(s) < 0.01 then s := 0;
1215 if Abs(c) < 0.01 then c := 0;
1217 x2 := x+Round(c*gMapInfo.Width);
1218 y2 := y+Round(s*gMapInfo.Width);
1220 t1 := gWalls <> nil;
1221 _collide := False;
1222 w := gMapInfo.Width;
1223 h := gMapInfo.Height;
1225 xe := 0;
1226 ye := 0;
1227 dx := x2-x;
1228 dy := y2-y;
1230 if (xd = 0) and (yd = 0) then Exit;
1232 if dx > 0 then xi := 1 else if dx < 0 then xi := -1 else xi := 0;
1233 if dy > 0 then yi := 1 else if dy < 0 then yi := -1 else yi := 0;
1235 dx := Abs(dx);
1236 dy := Abs(dy);
1238 if dx > dy then d := dx else d := dy;
1240 //blood vel, for Monster.Damage()
1241 //vx := (dx*10 div d)*xi;
1242 //vy := (dy*10 div d)*yi;
1244 xx := x;
1245 yy := y;
1247 for i := 1 to d do
1248 begin
1249 xe := xe+dx;
1250 ye := ye+dy;
1252 if xe > d then
1253 begin
1254 xe := xe-d;
1255 xx := xx+xi;
1256 end;
1258 if ye > d then
1259 begin
1260 ye := ye-d;
1261 yy := yy+yi;
1262 end;
1264 if (yy > h) or (yy < 0) then Break;
1265 if (xx > w) or (xx < 0) then Break;
1267 if t1 then
1268 if ByteBool(gCollideMap[yy, xx] and MARK_BLOCKED) then
1269 begin
1270 _collide := True;
1271 g_GFX_Spark(xx-xi, yy-yi, 2+Random(2), 180+a, 0, 0);
1272 if g_Game_IsServer and g_Game_IsNet then
1273 MH_SEND_Effect(xx-xi, yy-yi, 180+a, NET_GFX_SPARK);
1274 end;
1276 if not _collide then
1277 _collide := GunHit(xx, yy, xi*v, yi*v, dmg, SpawnerUID, v <> 0) <> 0;
1279 if _collide then
1280 Break;
1281 end;
1283 if CheckTrigger and g_Game_IsServer then
1284 g_Triggers_PressL(X, Y, xx-xi, yy-yi, SpawnerUID, ACTIVATE_SHOT);
1285 end;
1287 procedure g_Weapon_punch(x, y: Integer; d, SpawnerUID: Word);
1288 var
1289 obj: TObj;
1290 begin
1291 obj.X := X;
1292 obj.Y := Y;
1293 obj.rect.X := 0;
1294 obj.rect.Y := 0;
1295 obj.rect.Width := 39;
1296 obj.rect.Height := 52;
1297 obj.Vel.X := 0;
1298 obj.Vel.Y := 0;
1299 obj.Accel.X := 0;
1300 obj.Accel.Y := 0;
1302 if g_Weapon_Hit(@obj, d, SpawnerUID, HIT_SOME) <> 0 then
1303 g_Sound_PlayExAt('SOUND_WEAPON_HITPUNCH', x, y)
1304 else
1305 g_Sound_PlayExAt('SOUND_WEAPON_MISSPUNCH', x, y);
1306 end;
1308 function g_Weapon_chainsaw(x, y: Integer; d, SpawnerUID: Word): Integer;
1309 var
1310 obj: TObj;
1311 begin
1312 obj.X := X;
1313 obj.Y := Y;
1314 obj.rect.X := 0;
1315 obj.rect.Y := 0;
1316 obj.rect.Width := 32;
1317 obj.rect.Height := 52;
1318 obj.Vel.X := 0;
1319 obj.Vel.Y := 0;
1320 obj.Accel.X := 0;
1321 obj.Accel.Y := 0;
1323 Result := g_Weapon_Hit(@obj, d, SpawnerUID, HIT_SOME);
1324 end;
1326 procedure g_Weapon_rocket(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1327 Silent: Boolean = False);
1328 var
1329 find_id: DWORD;
1330 dx, dy: Integer;
1331 begin
1332 if WID < 0 then
1333 find_id := FindShot()
1334 else
1335 begin
1336 find_id := WID;
1337 if Integer(find_id) >= High(Shots) then
1338 SetLength(Shots, find_id + 64)
1339 end;
1341 with Shots[find_id] do
1342 begin
1343 g_Obj_Init(@Obj);
1345 Obj.Rect.Width := SHOT_ROCKETLAUNCHER_WIDTH;
1346 Obj.Rect.Height := SHOT_ROCKETLAUNCHER_HEIGHT;
1348 dx := IfThen(xd > x, -Obj.Rect.Width, 0);
1349 dy := -(Obj.Rect.Height div 2);
1351 ShotType := WEAPON_ROCKETLAUNCHER;
1352 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 12);
1354 Animation := nil;
1355 triggers := nil;
1356 g_Texture_Get('TEXTURE_WEAPON_ROCKET', TextureID);
1357 end;
1359 Shots[find_id].SpawnerUID := SpawnerUID;
1361 if not Silent then
1362 g_Sound_PlayExAt('SOUND_WEAPON_FIREROCKET', x, y);
1363 end;
1365 procedure g_Weapon_revf(x, y, xd, yd: Integer; SpawnerUID, TargetUID: Word;
1366 WID: Integer = -1; Silent: Boolean = False);
1367 var
1368 find_id, FramesID: DWORD;
1369 dx, dy: Integer;
1370 begin
1371 if WID < 0 then
1372 find_id := FindShot()
1373 else
1374 begin
1375 find_id := WID;
1376 if Integer(find_id) >= High(Shots) then
1377 SetLength(Shots, find_id + 64)
1378 end;
1380 with Shots[find_id] do
1381 begin
1382 g_Obj_Init(@Obj);
1384 Obj.Rect.Width := SHOT_SKELFIRE_WIDTH;
1385 Obj.Rect.Height := SHOT_SKELFIRE_HEIGHT;
1387 dx := -(Obj.Rect.Width div 2);
1388 dy := -(Obj.Rect.Height div 2);
1390 ShotType := WEAPON_SKEL_FIRE;
1391 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 12);
1393 triggers := nil;
1394 target := TargetUID;
1395 g_Frames_Get(FramesID, 'FRAMES_WEAPON_SKELFIRE');
1396 Animation := TAnimation.Create(FramesID, True, 5);
1397 end;
1399 Shots[find_id].SpawnerUID := SpawnerUID;
1401 if not Silent then
1402 g_Sound_PlayExAt('SOUND_WEAPON_FIREREV', x, y);
1403 end;
1405 procedure g_Weapon_plasma(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1406 Silent: Boolean = False);
1407 var
1408 find_id, FramesID: DWORD;
1409 dx, dy: Integer;
1410 begin
1411 if WID < 0 then
1412 find_id := FindShot()
1413 else
1414 begin
1415 find_id := WID;
1416 if Integer(find_id) >= High(Shots) then
1417 SetLength(Shots, find_id + 64);
1418 end;
1420 with Shots[find_id] do
1421 begin
1422 g_Obj_Init(@Obj);
1424 Obj.Rect.Width := SHOT_PLASMA_WIDTH;
1425 Obj.Rect.Height := SHOT_PLASMA_HEIGHT;
1427 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1428 dy := -(Obj.Rect.Height div 2);
1430 ShotType := WEAPON_PLASMA;
1431 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1433 triggers := nil;
1434 g_Frames_Get(FramesID, 'FRAMES_WEAPON_PLASMA');
1435 Animation := TAnimation.Create(FramesID, True, 5);
1436 end;
1438 Shots[find_id].SpawnerUID := SpawnerUID;
1440 if not Silent then
1441 g_Sound_PlayExAt('SOUND_WEAPON_FIREPLASMA', x, y);
1442 end;
1444 procedure g_Weapon_flame(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1445 Silent: Boolean = False);
1446 var
1447 find_id: DWORD;
1448 dx, dy: Integer;
1449 begin
1450 if WID < 0 then
1451 find_id := FindShot()
1452 else
1453 begin
1454 find_id := WID;
1455 if Integer(find_id) >= High(Shots) then
1456 SetLength(Shots, find_id + 64);
1457 end;
1459 with Shots[find_id] do
1460 begin
1461 g_Obj_Init(@Obj);
1463 Obj.Rect.Width := SHOT_FLAME_WIDTH;
1464 Obj.Rect.Height := SHOT_FLAME_HEIGHT;
1466 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1467 dy := -(Obj.Rect.Height div 2);
1469 ShotType := WEAPON_FLAMETHROWER;
1470 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1472 triggers := nil;
1473 Animation := nil;
1474 TextureID := 0;
1475 g_Frames_Get(TextureID, 'FRAMES_FLAME');
1476 end;
1478 Shots[find_id].SpawnerUID := SpawnerUID;
1480 // if not Silent then
1481 // g_Sound_PlayExAt('SOUND_WEAPON_FIREPLASMA', x, y);
1482 end;
1484 procedure g_Weapon_ball1(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1485 Silent: Boolean = False);
1486 var
1487 find_id, FramesID: DWORD;
1488 dx, dy: Integer;
1489 begin
1490 if WID < 0 then
1491 find_id := FindShot()
1492 else
1493 begin
1494 find_id := WID;
1495 if Integer(find_id) >= High(Shots) then
1496 SetLength(Shots, find_id + 64)
1497 end;
1499 with Shots[find_id] do
1500 begin
1501 g_Obj_Init(@Obj);
1503 Obj.Rect.Width := 16;
1504 Obj.Rect.Height := 16;
1506 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1507 dy := -(Obj.Rect.Height div 2);
1509 ShotType := WEAPON_IMP_FIRE;
1510 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1512 triggers := nil;
1513 g_Frames_Get(FramesID, 'FRAMES_WEAPON_IMPFIRE');
1514 Animation := TAnimation.Create(FramesID, True, 4);
1515 end;
1517 Shots[find_id].SpawnerUID := SpawnerUID;
1519 if not Silent then
1520 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x, y);
1521 end;
1523 procedure g_Weapon_ball2(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1524 Silent: Boolean = False);
1525 var
1526 find_id, FramesID: DWORD;
1527 dx, dy: Integer;
1528 begin
1529 if WID < 0 then
1530 find_id := FindShot()
1531 else
1532 begin
1533 find_id := WID;
1534 if Integer(find_id) >= High(Shots) then
1535 SetLength(Shots, find_id + 64)
1536 end;
1538 with Shots[find_id] do
1539 begin
1540 g_Obj_Init(@Obj);
1542 Obj.Rect.Width := 16;
1543 Obj.Rect.Height := 16;
1545 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1546 dy := -(Obj.Rect.Height div 2);
1548 ShotType := WEAPON_CACO_FIRE;
1549 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1551 triggers := nil;
1552 g_Frames_Get(FramesID, 'FRAMES_WEAPON_CACOFIRE');
1553 Animation := TAnimation.Create(FramesID, True, 4);
1554 end;
1556 Shots[find_id].SpawnerUID := SpawnerUID;
1558 if not Silent then
1559 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x, y);
1560 end;
1562 procedure g_Weapon_ball7(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1563 Silent: Boolean = False);
1564 var
1565 find_id, FramesID: DWORD;
1566 dx, dy: Integer;
1567 begin
1568 if WID < 0 then
1569 find_id := FindShot()
1570 else
1571 begin
1572 find_id := WID;
1573 if Integer(find_id) >= High(Shots) then
1574 SetLength(Shots, find_id + 64)
1575 end;
1577 with Shots[find_id] do
1578 begin
1579 g_Obj_Init(@Obj);
1581 Obj.Rect.Width := 32;
1582 Obj.Rect.Height := 16;
1584 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1585 dy := -(Obj.Rect.Height div 2);
1587 ShotType := WEAPON_BARON_FIRE;
1588 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1590 triggers := nil;
1591 g_Frames_Get(FramesID, 'FRAMES_WEAPON_BARONFIRE');
1592 Animation := TAnimation.Create(FramesID, True, 4);
1593 end;
1595 Shots[find_id].SpawnerUID := SpawnerUID;
1597 if not Silent then
1598 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x, y);
1599 end;
1601 procedure g_Weapon_aplasma(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1602 Silent: Boolean = False);
1603 var
1604 find_id, FramesID: DWORD;
1605 dx, dy: Integer;
1606 begin
1607 if WID < 0 then
1608 find_id := FindShot()
1609 else
1610 begin
1611 find_id := WID;
1612 if Integer(find_id) >= High(Shots) then
1613 SetLength(Shots, find_id + 64)
1614 end;
1616 with Shots[find_id] do
1617 begin
1618 g_Obj_Init(@Obj);
1620 Obj.Rect.Width := 16;
1621 Obj.Rect.Height := 16;
1623 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1624 dy := -(Obj.Rect.Height div 2);
1626 ShotType := WEAPON_BSP_FIRE;
1627 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1629 triggers := nil;
1631 g_Frames_Get(FramesID, 'FRAMES_WEAPON_BSPFIRE');
1632 Animation := TAnimation.Create(FramesID, True, 4);
1633 end;
1635 Shots[find_id].SpawnerUID := SpawnerUID;
1637 if not Silent then
1638 g_Sound_PlayExAt('SOUND_WEAPON_FIREPLASMA', x, y);
1639 end;
1641 procedure g_Weapon_manfire(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1642 Silent: Boolean = False);
1643 var
1644 find_id, FramesID: DWORD;
1645 dx, dy: Integer;
1646 begin
1647 if WID < 0 then
1648 find_id := FindShot()
1649 else
1650 begin
1651 find_id := WID;
1652 if Integer(find_id) >= High(Shots) then
1653 SetLength(Shots, find_id + 64)
1654 end;
1656 with Shots[find_id] do
1657 begin
1658 g_Obj_Init(@Obj);
1660 Obj.Rect.Width := 32;
1661 Obj.Rect.Height := 32;
1663 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1664 dy := -(Obj.Rect.Height div 2);
1666 ShotType := WEAPON_MANCUB_FIRE;
1667 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1669 triggers := nil;
1671 g_Frames_Get(FramesID, 'FRAMES_WEAPON_MANCUBFIRE');
1672 Animation := TAnimation.Create(FramesID, True, 4);
1673 end;
1675 Shots[find_id].SpawnerUID := SpawnerUID;
1677 if not Silent then
1678 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x, y);
1679 end;
1681 procedure g_Weapon_bfgshot(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1682 Silent: Boolean = False);
1683 var
1684 find_id, FramesID: DWORD;
1685 dx, dy: Integer;
1686 begin
1687 if WID < 0 then
1688 find_id := FindShot()
1689 else
1690 begin
1691 find_id := WID;
1692 if Integer(find_id) >= High(Shots) then
1693 SetLength(Shots, find_id + 64)
1694 end;
1696 with Shots[find_id] do
1697 begin
1698 g_Obj_Init(@Obj);
1700 Obj.Rect.Width := SHOT_BFG_WIDTH;
1701 Obj.Rect.Height := SHOT_BFG_HEIGHT;
1703 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1704 dy := -(Obj.Rect.Height div 2);
1706 ShotType := WEAPON_BFG;
1707 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1709 triggers := nil;
1710 g_Frames_Get(FramesID, 'FRAMES_WEAPON_BFG');
1711 Animation := TAnimation.Create(FramesID, True, 6);
1712 end;
1714 Shots[find_id].SpawnerUID := SpawnerUID;
1716 if not Silent then
1717 g_Sound_PlayExAt('SOUND_WEAPON_FIREBFG', x, y);
1718 end;
1720 procedure g_Weapon_bfghit(x, y: Integer);
1721 var
1722 ID: DWORD;
1723 Anim: TAnimation;
1724 begin
1725 if g_Frames_Get(ID, 'FRAMES_BFGHIT') then
1726 begin
1727 Anim := TAnimation.Create(ID, False, 4);
1728 g_GFX_OnceAnim(x-32, y-32, Anim);
1729 Anim.Free();
1730 end;
1731 end;
1733 procedure g_Weapon_pistol(x, y, xd, yd: Integer; SpawnerUID: Word;
1734 Silent: Boolean = False);
1735 begin
1736 if not Silent then
1737 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', x, y);
1739 g_Weapon_gun(x, y, xd, yd, 1, 3, SpawnerUID, True);
1740 if gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF] then
1741 begin
1742 g_Weapon_gun(x, y+1, xd, yd+1, 1, 3, SpawnerUID, False);
1743 g_Weapon_gun(x, y-1, xd, yd-1, 1, 2, SpawnerUID, False);
1744 end;
1745 end;
1747 procedure g_Weapon_mgun(x, y, xd, yd: Integer; SpawnerUID: Word;
1748 Silent: Boolean = False);
1749 begin
1750 if not Silent then
1751 if gSoundEffectsDF then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', x, y);
1753 g_Weapon_gun(x, y, xd, yd, 1, 3, SpawnerUID, True);
1754 if (gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF]) and
1755 (g_GetUIDType(SpawnerUID) = UID_PLAYER) then
1756 begin
1757 g_Weapon_gun(x, y+1, xd, yd+1, 1, 2, SpawnerUID, False);
1758 g_Weapon_gun(x, y-1, xd, yd-1, 1, 2, SpawnerUID, False);
1759 end;
1760 end;
1762 procedure g_Weapon_shotgun(x, y, xd, yd: Integer; SpawnerUID: Word;
1763 Silent: Boolean = False);
1764 var
1765 i, j: Integer;
1766 begin
1767 if not Silent then
1768 if gSoundEffectsDF then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', x, y);
1770 for i := 0 to 9 do
1771 begin
1772 j := Random(17)-8; // -8 .. 8
1773 g_Weapon_gun(x, y+j, xd, yd+j, IfThen(i mod 2 <> 0, 1, 0), 3, SpawnerUID, i=0);
1774 end;
1775 end;
1777 procedure g_Weapon_dshotgun(x, y, xd, yd: Integer; SpawnerUID: Word;
1778 Silent: Boolean = False);
1779 var
1780 a, i, j: Integer;
1781 begin
1782 if not Silent then
1783 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', x, y);
1785 if gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF] then a := 25 else a := 20;
1786 for i := 0 to a do
1787 begin
1788 j := Random(41)-20; // -20 .. 20
1789 g_Weapon_gun(x, y+j, xd, yd+j, IfThen(i mod 3 <> 0, 0, 1), 3, SpawnerUID, i=0);
1790 end;
1791 end;
1793 procedure g_Weapon_Update();
1794 var
1795 i, a, h, cx, cy, oldvx, oldvy, tf: Integer;
1796 _id: DWORD;
1797 Anim: TAnimation;
1798 t: DWArray;
1799 st: Word;
1800 s: String;
1801 o: TObj;
1802 spl: Boolean;
1803 Loud: Boolean;
1804 tcx, tcy: Integer;
1805 begin
1806 if Shots = nil then
1807 Exit;
1809 for i := 0 to High(Shots) do
1810 begin
1811 if Shots[i].ShotType = 0 then
1812 Continue;
1814 Loud := True;
1816 with Shots[i] do
1817 begin
1818 Timeout := Timeout - 1;
1819 oldvx := Obj.Vel.X;
1820 oldvy := Obj.Vel.Y;
1821 // Àêòèâèðîâàòü òðèããåðû ïî ïóòè (êðîìå óæå àêòèâèðîâàííûõ):
1822 if (Stopped = 0) and g_Game_IsServer then
1823 t := g_Triggers_PressR(Obj.X, Obj.Y, Obj.Rect.Width, Obj.Rect.Height,
1824 SpawnerUID, ACTIVATE_SHOT, triggers)
1825 else
1826 t := nil;
1828 if t <> nil then
1829 begin
1830 // Ïîïîëíÿåì ñïèñîê àêòèâèðîâàííûõ òðèããåðîâ:
1831 if triggers = nil then
1832 triggers := t
1833 else
1834 begin
1835 h := High(t);
1837 for a := 0 to h do
1838 if not InDWArray(t[a], triggers) then
1839 begin
1840 SetLength(triggers, Length(triggers)+1);
1841 triggers[High(triggers)] := t[a];
1842 end;
1843 end;
1844 end;
1846 // Àíèìàöèÿ ñíàðÿäà:
1847 if Animation <> nil then
1848 Animation.Update();
1850 // Äâèæåíèå:
1851 spl := (ShotType <> WEAPON_PLASMA) and
1852 (ShotType <> WEAPON_BFG) and
1853 (ShotType <> WEAPON_BSP_FIRE) and
1854 (ShotType <> WEAPON_FLAMETHROWER);
1856 if Stopped = 0 then
1857 begin
1858 st := g_Obj_Move(@Obj, False, spl);
1859 end
1860 else
1861 begin
1862 st := 0;
1863 end;
1864 positionChanged(); // this updates spatial accelerators
1866 if WordBool(st and MOVE_FALLOUT) or (Obj.X < -1000) or
1867 (Obj.X > gMapInfo.Width+1000) or (Obj.Y < -1000) then
1868 begin
1869 // Íà êëèåíòå ñêîðåå âñåãî è òàê óæå âûïàë.
1870 ShotType := 0;
1871 Animation.Free();
1872 Continue;
1873 end;
1875 cx := Obj.X + (Obj.Rect.Width div 2);
1876 cy := Obj.Y + (Obj.Rect.Height div 2);
1878 case ShotType of
1879 WEAPON_ROCKETLAUNCHER, WEAPON_SKEL_FIRE: // Ðàêåòû è ñíàðÿäû Ñêåëåòà
1880 begin
1881 // Âûëåòåëà èç âîäû:
1882 if WordBool(st and MOVE_HITAIR) then
1883 g_Obj_SetSpeed(@Obj, 12);
1885 // Â âîäå øëåéô - ïóçûðè, â âîçäóõå øëåéô - äûì:
1886 if WordBool(st and MOVE_INWATER) then
1887 g_GFX_Bubbles(Obj.X+(Obj.Rect.Width div 2),
1888 Obj.Y+(Obj.Rect.Height div 2),
1889 1+Random(3), 16, 16)
1890 else
1891 if g_Frames_Get(_id, 'FRAMES_SMOKE') then
1892 begin
1893 Anim := TAnimation.Create(_id, False, 3);
1894 Anim.Alpha := 150;
1895 g_GFX_OnceAnim(Obj.X-14+Random(9),
1896 Obj.Y+(Obj.Rect.Height div 2)-20+Random(9),
1897 Anim, ONCEANIM_SMOKE);
1898 Anim.Free();
1899 end;
1901 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
1902 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL)) or
1903 (g_Weapon_Hit(@Obj, 10, SpawnerUID, HIT_SOME, False) <> 0) or
1904 (Timeout < 1) then
1905 begin
1906 Obj.Vel.X := 0;
1907 Obj.Vel.Y := 0;
1909 g_Weapon_Explode(cx, cy, 60, SpawnerUID);
1911 if ShotType = WEAPON_SKEL_FIRE then
1912 begin // Âçðûâ ñíàðÿäà Ñêåëåòà
1913 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_SKELFIRE') then
1914 begin
1915 Anim := TAnimation.Create(TextureID, False, 8);
1916 Anim.Blending := False;
1917 g_GFX_OnceAnim((Obj.X+32)-58, (Obj.Y+8)-36, Anim);
1918 g_DynLightExplosion((Obj.X+32), (Obj.Y+8), 64, 1, 0, 0);
1919 Anim.Free();
1920 end;
1921 end
1922 else
1923 begin // Âçðûâ Ðàêåòû
1924 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_ROCKET') then
1925 begin
1926 Anim := TAnimation.Create(TextureID, False, 6);
1927 Anim.Blending := False;
1928 g_GFX_OnceAnim(cx-64, cy-64, Anim);
1929 g_DynLightExplosion(cx, cy, 64, 1, 0, 0);
1930 Anim.Free();
1931 end;
1932 end;
1934 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', Obj.X, Obj.Y);
1936 ShotType := 0;
1937 end;
1939 if ShotType = WEAPON_SKEL_FIRE then
1940 begin // Ñàìîíàâîäêà ñíàðÿäà Ñêåëåòà:
1941 if GetPos(target, @o) then
1942 throw(i, Obj.X, Obj.Y,
1943 o.X+o.Rect.X+(o.Rect.Width div 2)+o.Vel.X+o.Accel.X,
1944 o.Y+o.Rect.Y+(o.Rect.Height div 2)+o.Vel.Y+o.Accel.Y,
1945 12);
1946 end;
1947 end;
1949 WEAPON_PLASMA, WEAPON_BSP_FIRE: // Ïëàçìà, ïëàçìà Àðàõíàòðîíà
1950 begin
1951 // Ïîïàëà â âîäó - ýëåêòðîøîê ïî âîäå:
1952 if WordBool(st and (MOVE_INWATER or MOVE_HITWATER)) then
1953 begin
1954 g_Sound_PlayExAt('SOUND_WEAPON_PLASMAWATER', Obj.X, Obj.Y);
1955 if g_Game_IsServer then CheckTrap(i, 10, HIT_ELECTRO);
1956 ShotType := 0;
1957 Continue;
1958 end;
1960 // Âåëè÷èíà óðîíà:
1961 if (ShotType = WEAPON_PLASMA) and
1962 (gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF]) then
1963 a := 10
1964 else
1965 a := 5;
1967 if ShotType = WEAPON_BSP_FIRE then
1968 a := 10;
1970 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
1971 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL)) or
1972 (g_Weapon_Hit(@Obj, a, SpawnerUID, HIT_SOME, False) <> 0) or
1973 (Timeout < 1) then
1974 begin
1975 if ShotType = WEAPON_PLASMA then
1976 s := 'FRAMES_EXPLODE_PLASMA'
1977 else
1978 s := 'FRAMES_EXPLODE_BSPFIRE';
1980 // Âçðûâ Ïëàçìû:
1981 if g_Frames_Get(TextureID, s) then
1982 begin
1983 Anim := TAnimation.Create(TextureID, False, 3);
1984 Anim.Blending := False;
1985 g_GFX_OnceAnim(cx-16, cy-16, Anim);
1986 Anim.Free();
1987 g_DynLightExplosion(cx, cy, 32, 0, 0.5, 0.5);
1988 end;
1990 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEPLASMA', Obj.X, Obj.Y);
1992 ShotType := 0;
1993 end;
1994 end;
1996 WEAPON_FLAMETHROWER: // Îãíåìåò
1997 begin
1998 // Ñî âðåìåíåì óìèðàåò
1999 if (Timeout < 1) then
2000 begin
2001 ShotType := 0;
2002 Continue;
2003 end;
2004 // Ïîä âîäîé òîæå
2005 if WordBool(st and (MOVE_HITWATER or MOVE_INWATER)) then
2006 begin
2007 if WordBool(st and MOVE_HITWATER) then
2008 begin
2009 if g_Frames_Get(_id, 'FRAMES_SMOKE') then
2010 begin
2011 Anim := TAnimation.Create(_id, False, 3);
2012 Anim.Alpha := 0;
2013 tcx := Random(8);
2014 tcy := Random(8);
2015 g_GFX_OnceAnim(cx-4+tcx-(Anim.Width div 2),
2016 cy-4+tcy-(Anim.Height div 2),
2017 Anim, ONCEANIM_SMOKE);
2018 Anim.Free();
2019 end;
2020 end
2021 else
2022 g_GFX_Bubbles(cx, cy, 1+Random(3), 16, 16);
2023 ShotType := 0;
2024 Continue;
2025 end;
2027 // Ãðàâèòàöèÿ
2028 if Stopped = 0 then
2029 Obj.Accel.Y := Obj.Accel.Y + 1;
2030 // Ïîïàëè â ñòåíó èëè â âîäó:
2031 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL or MOVE_HITWATER)) then
2032 begin
2033 // Ïðèëèïàåì:
2034 Obj.Vel.X := 0;
2035 Obj.Vel.Y := 0;
2036 Obj.Accel.Y := 0;
2037 if WordBool(st and MOVE_HITWALL) then
2038 Stopped := MOVE_HITWALL
2039 else if WordBool(st and MOVE_HITLAND) then
2040 Stopped := MOVE_HITLAND
2041 else if WordBool(st and MOVE_HITCEIL) then
2042 Stopped := MOVE_HITCEIL;
2043 end;
2045 a := IfThen(Stopped = 0, 3, 1);
2046 // Åñëè â êîãî-òî ïîïàëè
2047 if g_Weapon_Hit(@Obj, a, SpawnerUID, HIT_FLAME, False) <> 0 then
2048 begin
2049 // HIT_FLAME ñàì ïîäîææåò
2050 // Åñëè â ïîëåòå ïîïàëè, èñ÷åçàåì
2051 if Stopped = 0 then
2052 ShotType := 0;
2053 end;
2055 if Stopped = 0 then
2056 tf := 2
2057 else
2058 tf := 3;
2060 if (gTime mod tf = 0) then
2061 begin
2062 Anim := TAnimation.Create(TextureID, False, 2 + Random(2));
2063 Anim.Alpha := 0;
2064 case Stopped of
2065 MOVE_HITWALL: begin tcx := cx-4+Random(8); tcy := cy-12+Random(24); end;
2066 MOVE_HITLAND: begin tcx := cx-12+Random(24); tcy := cy-10+Random(8); end;
2067 MOVE_HITCEIL: begin tcx := cx-12+Random(24); tcy := cy+6+Random(8); end;
2068 else begin tcx := cx-4+Random(8); tcy := cy-4+Random(8); end;
2069 end;
2070 g_GFX_OnceAnim(tcx-(Anim.Width div 2), tcy-(Anim.Height div 2), Anim, ONCEANIM_SMOKE);
2071 Anim.Free();
2072 //g_DynLightExplosion(tcx, tcy, 1, 1, 0.8, 0.3);
2073 end;
2074 end;
2076 WEAPON_BFG: // BFG
2077 begin
2078 // Ïîïàëà â âîäó - ýëåêòðîøîê ïî âîäå:
2079 if WordBool(st and (MOVE_INWATER or MOVE_HITWATER)) then
2080 begin
2081 g_Sound_PlayExAt('SOUND_WEAPON_BFGWATER', Obj.X, Obj.Y);
2082 if g_Game_IsServer then CheckTrap(i, 1000, HIT_ELECTRO);
2083 ShotType := 0;
2084 Continue;
2085 end;
2087 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2088 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL)) or
2089 (g_Weapon_Hit(@Obj, SHOT_BFG_DAMAGE, SpawnerUID, HIT_BFG, False) <> 0) or
2090 (Timeout < 1) then
2091 begin
2092 // Ëó÷è BFG:
2093 if g_Game_IsServer then g_Weapon_BFG9000(cx, cy, SpawnerUID);
2095 // Âçðûâ BFG:
2096 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_BFG') then
2097 begin
2098 Anim := TAnimation.Create(TextureID, False, 6);
2099 Anim.Blending := False;
2100 g_GFX_OnceAnim(cx-64, cy-64, Anim);
2101 Anim.Free();
2102 g_DynLightExplosion(cx, cy, 96, 0, 1, 0);
2103 end;
2105 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', Obj.X, Obj.Y);
2107 ShotType := 0;
2108 end;
2109 end;
2111 WEAPON_IMP_FIRE, WEAPON_CACO_FIRE, WEAPON_BARON_FIRE: // Âûñòðåëû Áåñà, Êàêîäåìîíà Ðûöàðÿ/Áàðîíà àäà
2112 begin
2113 // Âûëåòåë èç âîäû:
2114 if WordBool(st and MOVE_HITAIR) then
2115 g_Obj_SetSpeed(@Obj, 16);
2117 // Âåëè÷èíà óðîíà:
2118 if ShotType = WEAPON_IMP_FIRE then
2119 a := 5
2120 else
2121 if ShotType = WEAPON_CACO_FIRE then
2122 a := 20
2123 else
2124 a := 40;
2126 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2127 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL)) or
2128 (g_Weapon_Hit(@Obj, a, SpawnerUID, HIT_SOME) <> 0) or
2129 (Timeout < 1) then
2130 begin
2131 if ShotType = WEAPON_IMP_FIRE then
2132 s := 'FRAMES_EXPLODE_IMPFIRE'
2133 else
2134 if ShotType = WEAPON_CACO_FIRE then
2135 s := 'FRAMES_EXPLODE_CACOFIRE'
2136 else
2137 s := 'FRAMES_EXPLODE_BARONFIRE';
2139 // Âçðûâ:
2140 if g_Frames_Get(TextureID, s) then
2141 begin
2142 Anim := TAnimation.Create(TextureID, False, 6);
2143 Anim.Blending := False;
2144 g_GFX_OnceAnim(cx-32, cy-32, Anim);
2145 Anim.Free();
2146 end;
2148 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj.X, Obj.Y);
2150 ShotType := 0;
2151 end;
2152 end;
2154 WEAPON_MANCUB_FIRE: // Âûñòðåë Ìàíêóáóñà
2155 begin
2156 // Âûëåòåë èç âîäû:
2157 if WordBool(st and MOVE_HITAIR) then
2158 g_Obj_SetSpeed(@Obj, 16);
2160 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2161 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL)) or
2162 (g_Weapon_Hit(@Obj, 40, SpawnerUID, HIT_SOME, False) <> 0) or
2163 (Timeout < 1) then
2164 begin
2165 // Âçðûâ:
2166 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_ROCKET') then
2167 begin
2168 Anim := TAnimation.Create(TextureID, False, 6);
2169 Anim.Blending := False;
2170 g_GFX_OnceAnim(cx-64, cy-64, Anim);
2171 Anim.Free();
2172 end;
2174 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj.X, Obj.Y);
2176 ShotType := 0;
2177 end;
2178 end;
2179 end; // case ShotType of...
2181 // Åñëè ñíàðÿäà óæå íåò, óäàëÿåì àíèìàöèþ:
2182 if (ShotType = 0) then
2183 begin
2184 if gGameSettings.GameType = GT_SERVER then
2185 MH_SEND_DeleteShot(i, Obj.X, Obj.Y, Loud);
2186 if Animation <> nil then
2187 begin
2188 Animation.Free();
2189 Animation := nil;
2190 end;
2191 end
2192 else if (ShotType <> WEAPON_FLAMETHROWER) and ((oldvx <> Obj.Vel.X) or (oldvy <> Obj.Vel.Y)) then
2193 if gGameSettings.GameType = GT_SERVER then
2194 MH_SEND_UpdateShot(i);
2195 end;
2196 end;
2197 end;
2199 procedure g_Weapon_Draw();
2200 var
2201 i: Integer;
2202 a: SmallInt;
2203 p: TPoint;
2204 begin
2205 if Shots = nil then
2206 Exit;
2208 for i := 0 to High(Shots) do
2209 if Shots[i].ShotType <> 0 then
2210 with Shots[i] do
2211 begin
2212 if (Shots[i].ShotType = WEAPON_ROCKETLAUNCHER) or
2213 (Shots[i].ShotType = WEAPON_BARON_FIRE) or
2214 (Shots[i].ShotType = WEAPON_MANCUB_FIRE) or
2215 (Shots[i].ShotType = WEAPON_SKEL_FIRE) then
2216 a := -GetAngle2(Obj.Vel.X, Obj.Vel.Y)
2217 else
2218 a := 0;
2220 p.X := Obj.Rect.Width div 2;
2221 p.Y := Obj.Rect.Height div 2;
2223 if Animation <> nil then
2224 begin
2225 if (Shots[i].ShotType = WEAPON_BARON_FIRE) or
2226 (Shots[i].ShotType = WEAPON_MANCUB_FIRE) or
2227 (Shots[i].ShotType = WEAPON_SKEL_FIRE) then
2228 Animation.DrawEx(Obj.X, Obj.Y, M_NONE, p, a)
2229 else
2230 Animation.Draw(Obj.X, Obj.Y, M_NONE);
2231 end
2232 else if TextureID <> 0 then
2233 begin
2234 if (Shots[i].ShotType = WEAPON_ROCKETLAUNCHER) then
2235 e_DrawAdv(TextureID, Obj.X, Obj.Y, 0, True, False, a, @p, M_NONE)
2236 else if (Shots[i].ShotType <> WEAPON_FLAMETHROWER) then
2237 e_Draw(TextureID, Obj.X, Obj.Y, 0, True, False);
2238 end;
2240 if g_debug_Frames then
2241 begin
2242 e_DrawQuad(Obj.X+Obj.Rect.X,
2243 Obj.Y+Obj.Rect.Y,
2244 Obj.X+Obj.Rect.X+Obj.Rect.Width-1,
2245 Obj.Y+Obj.Rect.Y+Obj.Rect.Height-1,
2246 0, 255, 0);
2247 end;
2248 end;
2249 end;
2251 function g_Weapon_Danger(UID: Word; X, Y: Integer; Width, Height: Word; Time: Byte): Boolean;
2252 var
2253 a: Integer;
2254 begin
2255 Result := False;
2257 if Shots = nil then
2258 Exit;
2260 for a := 0 to High(Shots) do
2261 if (Shots[a].ShotType <> 0) and (Shots[a].SpawnerUID <> UID) then
2262 if ((Shots[a].Obj.Vel.Y = 0) and (Shots[a].Obj.Vel.X > 0) and (Shots[a].Obj.X < X)) or
2263 (Shots[a].Obj.Vel.Y = 0) and (Shots[a].Obj.Vel.X < 0) and (Shots[a].Obj.X > X) then
2264 if (Abs(X-Shots[a].Obj.X) < Abs(Shots[a].Obj.Vel.X*Time)) and
2265 g_Collide(X, Y, Width, Height, X, Shots[a].Obj.Y,
2266 Shots[a].Obj.Rect.Width, Shots[a].Obj.Rect.Height) and
2267 g_TraceVector(X, Y, Shots[a].Obj.X, Shots[a].Obj.Y) then
2268 begin
2269 Result := True;
2270 Exit;
2271 end;
2272 end;
2274 procedure g_Weapon_SaveState(var Mem: TBinMemoryWriter);
2275 var
2276 count, i, j: Integer;
2277 dw: DWORD;
2278 begin
2279 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ ñíàðÿäîâ:
2280 count := 0;
2281 if Shots <> nil then
2282 for i := 0 to High(Shots) do
2283 if Shots[i].ShotType <> 0 then
2284 count := count + 1;
2286 Mem := TBinMemoryWriter.Create((count+1) * 80);
2288 // Êîëè÷åñòâî ñíàðÿäîâ:
2289 Mem.WriteInt(count);
2291 if count = 0 then
2292 Exit;
2294 for i := 0 to High(Shots) do
2295 if Shots[i].ShotType <> 0 then
2296 begin
2297 // Ñèãíàòóðà ñíàðÿäà:
2298 dw := SHOT_SIGNATURE; // 'SHOT'
2299 Mem.WriteDWORD(dw);
2300 // Òèï ñíàðÿäà:
2301 Mem.WriteByte(Shots[i].ShotType);
2302 // Öåëü:
2303 Mem.WriteWord(Shots[i].Target);
2304 // UID ñòðåëÿâøåãî:
2305 Mem.WriteWord(Shots[i].SpawnerUID);
2306 // Ðàçìåð ïîëÿ Triggers:
2307 dw := Length(Shots[i].Triggers);
2308 Mem.WriteDWORD(dw);
2309 // Òðèããåðû, àêòèâèðîâàííûå âûñòðåëîì:
2310 for j := 0 to Integer(dw)-1 do
2311 Mem.WriteDWORD(Shots[i].Triggers[j]);
2312 // Îáúåêò ñíàðÿäà:
2313 Obj_SaveState(@Shots[i].Obj, Mem);
2314 // Êîñòûëèíà åáàíàÿ:
2315 Mem.WriteByte(Shots[i].Stopped);
2316 end;
2317 end;
2319 procedure g_Weapon_LoadState(var Mem: TBinMemoryReader);
2320 var
2321 count, i, j: Integer;
2322 dw: DWORD;
2323 begin
2324 if Mem = nil then
2325 Exit;
2327 // Êîëè÷åñòâî ñíàðÿäîâ:
2328 Mem.ReadInt(count);
2330 SetLength(Shots, count);
2332 if count = 0 then
2333 Exit;
2335 for i := 0 to count-1 do
2336 begin
2337 // Ñèãíàòóðà ñíàðÿäà:
2338 Mem.ReadDWORD(dw);
2339 if dw <> SHOT_SIGNATURE then // 'SHOT'
2340 begin
2341 raise EBinSizeError.Create('g_Weapons_LoadState: Wrong Shot Signature');
2342 end;
2343 // Òèï ñíàðÿäà:
2344 Mem.ReadByte(Shots[i].ShotType);
2345 // Öåëü:
2346 Mem.ReadWord(Shots[i].Target);
2347 // UID ñòðåëÿâøåãî:
2348 Mem.ReadWord(Shots[i].SpawnerUID);
2349 // Ðàçìåð ïîëÿ Triggers:
2350 Mem.ReadDWORD(dw);
2351 SetLength(Shots[i].Triggers, dw);
2352 // Òðèããåðû, àêòèâèðîâàííûå âûñòðåëîì:
2353 for j := 0 to Integer(dw)-1 do
2354 Mem.ReadDWORD(Shots[i].Triggers[j]);
2355 // Îáúåêò ïðåäìåòà:
2356 Obj_LoadState(@Shots[i].Obj, Mem);
2357 // Êîñòûëèíà åáàíàÿ:
2358 Mem.ReadByte(Shots[i].Stopped);
2360 // Óñòàíîâêà òåêñòóðû èëè àíèìàöèè:
2361 Shots[i].TextureID := DWORD(-1);
2362 Shots[i].Animation := nil;
2364 case Shots[i].ShotType of
2365 WEAPON_ROCKETLAUNCHER, WEAPON_SKEL_FIRE:
2366 begin
2367 g_Texture_Get('TEXTURE_WEAPON_ROCKET', Shots[i].TextureID);
2368 end;
2369 WEAPON_PLASMA:
2370 begin
2371 g_Frames_Get(dw, 'FRAMES_WEAPON_PLASMA');
2372 Shots[i].Animation := TAnimation.Create(dw, True, 5);
2373 end;
2374 WEAPON_BFG:
2375 begin
2376 g_Frames_Get(dw, 'FRAMES_WEAPON_BFG');
2377 Shots[i].Animation := TAnimation.Create(dw, True, 6);
2378 end;
2379 WEAPON_IMP_FIRE:
2380 begin
2381 g_Frames_Get(dw, 'FRAMES_WEAPON_IMPFIRE');
2382 Shots[i].Animation := TAnimation.Create(dw, True, 4);
2383 end;
2384 WEAPON_BSP_FIRE:
2385 begin
2386 g_Frames_Get(dw, 'FRAMES_WEAPON_BSPFIRE');
2387 Shots[i].Animation := TAnimation.Create(dw, True, 4);
2388 end;
2389 WEAPON_CACO_FIRE:
2390 begin
2391 g_Frames_Get(dw, 'FRAMES_WEAPON_CACOFIRE');
2392 Shots[i].Animation := TAnimation.Create(dw, True, 4);
2393 end;
2394 WEAPON_BARON_FIRE:
2395 begin
2396 g_Frames_Get(dw, 'FRAMES_WEAPON_BARONFIRE');
2397 Shots[i].Animation := TAnimation.Create(dw, True, 4);
2398 end;
2399 WEAPON_MANCUB_FIRE:
2400 begin
2401 g_Frames_Get(dw, 'FRAMES_WEAPON_MANCUBFIRE');
2402 Shots[i].Animation := TAnimation.Create(dw, True, 4);
2403 end;
2404 end;
2405 end;
2406 end;
2408 procedure g_Weapon_DestroyShot(I: Integer; X, Y: Integer; Loud: Boolean = True);
2409 var
2410 cx, cy: Integer;
2411 Anim: TAnimation;
2412 s: string;
2413 begin
2414 if Shots = nil then
2415 Exit;
2416 if (I > High(Shots)) or (I < 0) then Exit;
2418 with Shots[I] do
2419 begin
2420 if ShotType = 0 then Exit;
2421 Obj.X := X;
2422 Obj.Y := Y;
2423 cx := Obj.X + (Obj.Rect.Width div 2);
2424 cy := Obj.Y + (Obj.Rect.Height div 2);
2426 case ShotType of
2427 WEAPON_ROCKETLAUNCHER, WEAPON_SKEL_FIRE: // Ðàêåòû è ñíàðÿäû Ñêåëåòà
2428 begin
2429 if Loud then
2430 begin
2431 if ShotType = WEAPON_SKEL_FIRE then
2432 begin // Âçðûâ ñíàðÿäà Ñêåëåòà
2433 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_SKELFIRE') then
2434 begin
2435 Anim := TAnimation.Create(TextureID, False, 8);
2436 Anim.Blending := False;
2437 g_GFX_OnceAnim((Obj.X+32)-32, (Obj.Y+8)-32, Anim);
2438 Anim.Free();
2439 end;
2440 end
2441 else
2442 begin // Âçðûâ Ðàêåòû
2443 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_ROCKET') then
2444 begin
2445 Anim := TAnimation.Create(TextureID, False, 6);
2446 Anim.Blending := False;
2447 g_GFX_OnceAnim(cx-64, cy-64, Anim);
2448 Anim.Free();
2449 end;
2450 end;
2451 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', Obj.X, Obj.Y);
2452 end;
2453 end;
2455 WEAPON_PLASMA, WEAPON_BSP_FIRE: // Ïëàçìà, ïëàçìà Àðàõíàòðîíà
2456 begin
2457 if ShotType = WEAPON_PLASMA then
2458 s := 'FRAMES_EXPLODE_PLASMA'
2459 else
2460 s := 'FRAMES_EXPLODE_BSPFIRE';
2462 if g_Frames_Get(TextureID, s) and loud then
2463 begin
2464 Anim := TAnimation.Create(TextureID, False, 3);
2465 Anim.Blending := False;
2466 g_GFX_OnceAnim(cx-16, cy-16, Anim);
2467 Anim.Free();
2469 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEPLASMA', Obj.X, Obj.Y);
2470 end;
2471 end;
2473 WEAPON_BFG: // BFG
2474 begin
2475 // Âçðûâ BFG:
2476 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_BFG') and Loud then
2477 begin
2478 Anim := TAnimation.Create(TextureID, False, 6);
2479 Anim.Blending := False;
2480 g_GFX_OnceAnim(cx-64, cy-64, Anim);
2481 Anim.Free();
2483 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', Obj.X, Obj.Y);
2484 end;
2485 end;
2487 WEAPON_IMP_FIRE, WEAPON_CACO_FIRE, WEAPON_BARON_FIRE: // Âûñòðåëû Áåñà, Êàêîäåìîíà Ðûöàðÿ/Áàðîíà àäà
2488 begin
2489 if ShotType = WEAPON_IMP_FIRE then
2490 s := 'FRAMES_EXPLODE_IMPFIRE'
2491 else
2492 if ShotType = WEAPON_CACO_FIRE then
2493 s := 'FRAMES_EXPLODE_CACOFIRE'
2494 else
2495 s := 'FRAMES_EXPLODE_BARONFIRE';
2497 if g_Frames_Get(TextureID, s) and Loud then
2498 begin
2499 Anim := TAnimation.Create(TextureID, False, 6);
2500 Anim.Blending := False;
2501 g_GFX_OnceAnim(cx-32, cy-32, Anim);
2502 Anim.Free();
2504 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj.X, Obj.Y);
2505 end;
2506 end;
2508 WEAPON_MANCUB_FIRE: // Âûñòðåë Ìàíêóáóñà
2509 begin
2510 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_ROCKET') and Loud then
2511 begin
2512 Anim := TAnimation.Create(TextureID, False, 6);
2513 Anim.Blending := False;
2514 g_GFX_OnceAnim(cx-64, cy-64, Anim);
2515 Anim.Free();
2517 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj.X, Obj.Y);
2518 end;
2519 end;
2520 end; // case ShotType of...
2522 ShotType := 0;
2523 Animation.Free();
2524 end;
2525 end;
2528 procedure g_Weapon_AddDynLights();
2529 var
2530 i: Integer;
2531 begin
2532 if Shots = nil then Exit;
2533 for i := 0 to High(Shots) do
2534 begin
2535 if Shots[i].ShotType = 0 then continue;
2536 if (Shots[i].ShotType = WEAPON_ROCKETLAUNCHER) or
2537 (Shots[i].ShotType = WEAPON_BARON_FIRE) or
2538 (Shots[i].ShotType = WEAPON_MANCUB_FIRE) or
2539 (Shots[i].ShotType = WEAPON_SKEL_FIRE) or
2540 (Shots[i].ShotType = WEAPON_IMP_FIRE) or
2541 (Shots[i].ShotType = WEAPON_CACO_FIRE) or
2542 (Shots[i].ShotType = WEAPON_MANCUB_FIRE) or
2543 (Shots[i].ShotType = WEAPON_BSP_FIRE) or
2544 (Shots[i].ShotType = WEAPON_PLASMA) or
2545 (Shots[i].ShotType = WEAPON_BFG) or
2546 (Shots[i].ShotType = WEAPON_FLAMETHROWER) or
2547 false then
2548 begin
2549 if (Shots[i].ShotType = WEAPON_PLASMA) then
2550 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)
2551 else if (Shots[i].ShotType = WEAPON_BFG) then
2552 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)
2553 else if (Shots[i].ShotType = WEAPON_FLAMETHROWER) then
2554 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)
2555 else
2556 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);
2557 end;
2558 end;
2559 end;
2562 procedure TShot.positionChanged (); begin end;
2565 end.