DEADSOFTWARE

removed "monidx" argument from monster spatial query callback (each monster has UIDs...
[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 (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 (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_ForEachAliveAt(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 (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 (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_ForEachAliveAt(X, Y, 1, 1, monsCheck) then result := 2;
466 end;
468 procedure g_Weapon_BFG9000(X, Y: Integer; SpawnerUID: Word);
470 function monsCheck (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_ForEachAlive(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 (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 //FIXME: accelerate this!
835 result := g_Mons_ForEachAliveAt(obj.X+obj.Rect.X, obj.Y+obj.Rect.Y, obj.Rect.Width, obj.Rect.Height, monsCheckHit);
836 end;
838 begin
839 Result := 0;
841 if HitCorpses then
842 begin
843 h := High(gCorpses);
845 if gAdvCorpses and (h <> -1) then
846 for i := 0 to h do
847 if (gCorpses[i] <> nil) and (gCorpses[i].State <> CORPSE_STATE_REMOVEME) and
848 g_Obj_Collide(obj, @gCorpses[i].Obj) then
849 begin
850 // Ðàñïèëèâàåì òðóï:
851 gCorpses[i].Damage(d, (obj^.Vel.X+obj^.Accel.X) div 4,
852 (obj^.Vel.Y+obj^.Accel.Y) div 4);
853 Result := 1;
854 end;
855 end;
857 case gGameSettings.GameMode of
858 // Êàìïàíèÿ:
859 GM_COOP, GM_SINGLE:
860 begin
861 // Ñíà÷àëà áü¸ì ìîíñòðîâ, åñëè åñòü, ïîòîì ïûòàåìñÿ áèòü èãðîêîâ
862 if MonsterHit() then
863 begin
864 Result := 2;
865 Exit;
866 end;
868 if PlayerHit() then
869 begin
870 Result := 1;
871 Exit;
872 end;
873 end;
875 // Äåçìàò÷:
876 GM_DM:
877 begin
878 // Ñíà÷àëà áü¸ì èãðîêîâ, åñëè åñòü, ïîòîì ïûòàåìñÿ áèòü ìîíñòðîâ
879 if PlayerHit() then
880 begin
881 Result := 1;
882 Exit;
883 end;
885 if MonsterHit() then
886 begin
887 Result := 2;
888 Exit;
889 end;
890 end;
892 // Êîìàíäíûå:
893 GM_TDM, GM_CTF:
894 begin
895 // Ñíà÷àëà áü¸ì èãðîêîâ êîìàíäû ñîïåðíèêà
896 if PlayerHit(2) then
897 begin
898 Result := 1;
899 Exit;
900 end;
902 // Ïîòîì ìîíñòðîâ
903 if MonsterHit() then
904 begin
905 Result := 2;
906 Exit;
907 end;
909 // È â êîíöå ñâîèõ èãðîêîâ
910 if PlayerHit(1) then
911 begin
912 Result := 1;
913 Exit;
914 end;
915 end;
917 end;
918 end;
920 function g_Weapon_HitUID(UID: Word; d: Integer; SpawnerUID: Word; t: Byte): Boolean;
921 begin
922 Result := False;
924 case g_GetUIDType(UID) of
925 UID_PLAYER: Result := HitPlayer(g_Player_Get(UID), d, 0, 0, SpawnerUID, t);
926 UID_MONSTER: Result := HitMonster(g_Monsters_ByUID(UID), d, 0, 0, SpawnerUID, t);
927 else Exit;
928 end;
929 end;
931 function g_Weapon_Explode(X, Y: Integer; rad: Integer; SpawnerUID: Word): Boolean;
932 var
933 r: Integer; // squared radius
935 function monsExCheck (mon: TMonster): Boolean;
936 var
937 dx, dy, mm: Integer;
938 begin
939 result := false; // don't stop
940 begin
941 dx := mon.Obj.X+mon.Obj.Rect.X+(mon.Obj.Rect.Width div 2)-X;
942 dy := mon.Obj.Y+mon.Obj.Rect.Y+(mon.Obj.Rect.Height div 2)-Y;
944 if dx > 1000 then dx := 1000;
945 if dy > 1000 then dy := 1000;
947 if (dx*dx+dy*dy < r) then
948 begin
949 //m := PointToRect(X, Y, Obj.X+Obj.Rect.X, Obj.Y+Obj.Rect.Y, Obj.Rect.Width, Obj.Rect.Height);
950 //e_WriteLog(Format('explo monster #%d: x=%d; y=%d; rad=%d; dx=%d; dy=%d', [monidx, X, Y, rad, dx, dy]), MSG_NOTIFY);
952 mm := Max(abs(dx), abs(dy));
953 if mm = 0 then mm := 1;
955 if mon.Live then
956 begin
957 HitMonster(mon, ((mon.Obj.Rect.Width div 4)*10*(rad-mm)) div rad, 0, 0, SpawnerUID, HIT_ROCKET);
958 end;
960 mon.Push((dx*7) div mm, (dy*7) div mm);
961 end;
962 end;
963 end;
965 var
966 i, h, dx, dy, m, mm: Integer;
967 _angle: SmallInt;
968 begin
969 result := false;
971 g_Triggers_PressC(X, Y, rad, SpawnerUID, ACTIVATE_SHOT);
973 r := rad*rad;
975 h := High(gPlayers);
977 if h <> -1 then
978 for i := 0 to h do
979 if (gPlayers[i] <> nil) and gPlayers[i].Live then
980 with gPlayers[i] do
981 begin
982 dx := Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2)-X;
983 dy := Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)-Y;
985 if dx > 1000 then dx := 1000;
986 if dy > 1000 then dy := 1000;
988 if dx*dx+dy*dy < r then
989 begin
990 //m := PointToRect(X, Y, GameX+PLAYER_RECT.X, GameY+PLAYER_RECT.Y,
991 // PLAYER_RECT.Width, PLAYER_RECT.Height);
993 mm := Max(abs(dx), abs(dy));
994 if mm = 0 then mm := 1;
996 HitPlayer(gPlayers[i], (100*(rad-mm)) div rad, (dx*10) div mm, (dy*10) div mm, SpawnerUID, HIT_ROCKET);
997 gPlayers[i].Push((dx*7) div mm, (dy*7) div mm);
998 end;
999 end;
1001 //g_Mons_ForEach(monsExCheck);
1002 g_Mons_ForEachAt(X-(rad+32), Y-(rad+32), (rad+32)*2, (rad+32)*2, monsExCheck);
1004 h := High(gCorpses);
1006 if gAdvCorpses and (h <> -1) then
1007 for i := 0 to h do
1008 if (gCorpses[i] <> nil) and (gCorpses[i].State <> CORPSE_STATE_REMOVEME) then
1009 with gCorpses[i] do
1010 begin
1011 dx := Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2)-X;
1012 dy := Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)-Y;
1014 if dx > 1000 then dx := 1000;
1015 if dy > 1000 then dy := 1000;
1017 if dx*dx+dy*dy < r then
1018 begin
1019 m := PointToRect(X, Y, Obj.X+Obj.Rect.X, Obj.Y+Obj.Rect.Y,
1020 Obj.Rect.Width, Obj.Rect.Height);
1022 mm := Max(abs(dx), abs(dy));
1023 if mm = 0 then mm := 1;
1025 Damage(Round(100*(rad-m)/rad), (dx*10) div mm, (dy*10) div mm);
1026 end;
1027 end;
1029 h := High(gGibs);
1031 if gAdvGibs and (h <> -1) then
1032 for i := 0 to h do
1033 if gGibs[i].Live then
1034 with gGibs[i] do
1035 begin
1036 dx := Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2)-X;
1037 dy := Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)-Y;
1039 if dx > 1000 then dx := 1000;
1040 if dy > 1000 then dy := 1000;
1042 if dx*dx+dy*dy < r then
1043 begin
1044 m := PointToRect(X, Y, Obj.X+Obj.Rect.X, Obj.Y+Obj.Rect.Y,
1045 Obj.Rect.Width, Obj.Rect.Height);
1046 _angle := GetAngle(Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2),
1047 Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2), X, Y);
1049 g_Obj_PushA(@Obj, Round(15*(rad-m)/rad), _angle);
1050 positionChanged(); // this updates spatial accelerators
1051 end;
1052 end;
1053 end;
1055 procedure g_Weapon_Init();
1056 begin
1057 CreateWaterMap();
1058 end;
1060 procedure g_Weapon_Free();
1061 var
1062 i: Integer;
1063 begin
1064 if Shots <> nil then
1065 begin
1066 for i := 0 to High(Shots) do
1067 if Shots[i].ShotType <> 0 then
1068 Shots[i].Animation.Free();
1070 Shots := nil;
1071 end;
1073 WaterMap := nil;
1074 end;
1076 procedure g_Weapon_LoadData();
1077 begin
1078 e_WriteLog('Loading weapons data...', MSG_NOTIFY);
1080 g_Sound_CreateWADEx('SOUND_WEAPON_HITPUNCH', GameWAD+':SOUNDS\HITPUNCH');
1081 g_Sound_CreateWADEx('SOUND_WEAPON_MISSPUNCH', GameWAD+':SOUNDS\MISSPUNCH');
1082 g_Sound_CreateWADEx('SOUND_WEAPON_HITBERSERK', GameWAD+':SOUNDS\HITBERSERK');
1083 g_Sound_CreateWADEx('SOUND_WEAPON_MISSBERSERK', GameWAD+':SOUNDS\MISSBERSERK');
1084 g_Sound_CreateWADEx('SOUND_WEAPON_SELECTSAW', GameWAD+':SOUNDS\SELECTSAW');
1085 g_Sound_CreateWADEx('SOUND_WEAPON_IDLESAW', GameWAD+':SOUNDS\IDLESAW');
1086 g_Sound_CreateWADEx('SOUND_WEAPON_HITSAW', GameWAD+':SOUNDS\HITSAW');
1087 g_Sound_CreateWADEx('SOUND_WEAPON_FIRESHOTGUN2', GameWAD+':SOUNDS\FIRESHOTGUN2');
1088 g_Sound_CreateWADEx('SOUND_WEAPON_FIRESHOTGUN', GameWAD+':SOUNDS\FIRESHOTGUN');
1089 g_Sound_CreateWADEx('SOUND_WEAPON_FIRESAW', GameWAD+':SOUNDS\FIRESAW');
1090 g_Sound_CreateWADEx('SOUND_WEAPON_FIREROCKET', GameWAD+':SOUNDS\FIREROCKET');
1091 g_Sound_CreateWADEx('SOUND_WEAPON_FIREPLASMA', GameWAD+':SOUNDS\FIREPLASMA');
1092 g_Sound_CreateWADEx('SOUND_WEAPON_FIREPISTOL', GameWAD+':SOUNDS\FIREPISTOL');
1093 g_Sound_CreateWADEx('SOUND_WEAPON_FIRECGUN', GameWAD+':SOUNDS\FIRECGUN');
1094 g_Sound_CreateWADEx('SOUND_WEAPON_FIREBFG', GameWAD+':SOUNDS\FIREBFG');
1095 g_Sound_CreateWADEx('SOUND_FIRE', GameWAD+':SOUNDS\FIRE');
1096 g_Sound_CreateWADEx('SOUND_WEAPON_STARTFIREBFG', GameWAD+':SOUNDS\STARTFIREBFG');
1097 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEROCKET', GameWAD+':SOUNDS\EXPLODEROCKET');
1098 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEBFG', GameWAD+':SOUNDS\EXPLODEBFG');
1099 g_Sound_CreateWADEx('SOUND_WEAPON_BFGWATER', GameWAD+':SOUNDS\BFGWATER');
1100 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEPLASMA', GameWAD+':SOUNDS\EXPLODEPLASMA');
1101 g_Sound_CreateWADEx('SOUND_WEAPON_PLASMAWATER', GameWAD+':SOUNDS\PLASMAWATER');
1102 g_Sound_CreateWADEx('SOUND_WEAPON_FIREBALL', GameWAD+':SOUNDS\FIREBALL');
1103 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEBALL', GameWAD+':SOUNDS\EXPLODEBALL');
1104 g_Sound_CreateWADEx('SOUND_WEAPON_FIREREV', GameWAD+':SOUNDS\FIREREV');
1105 g_Sound_CreateWADEx('SOUND_PLAYER_JETFLY', GameWAD+':SOUNDS\WORKJETPACK');
1106 g_Sound_CreateWADEx('SOUND_PLAYER_JETON', GameWAD+':SOUNDS\STARTJETPACK');
1107 g_Sound_CreateWADEx('SOUND_PLAYER_JETOFF', GameWAD+':SOUNDS\STOPJETPACK');
1108 g_Sound_CreateWADEx('SOUND_PLAYER_CASING1', GameWAD+':SOUNDS\CASING1');
1109 g_Sound_CreateWADEx('SOUND_PLAYER_CASING2', GameWAD+':SOUNDS\CASING2');
1110 g_Sound_CreateWADEx('SOUND_PLAYER_SHELL1', GameWAD+':SOUNDS\SHELL1');
1111 g_Sound_CreateWADEx('SOUND_PLAYER_SHELL2', GameWAD+':SOUNDS\SHELL2');
1113 g_Texture_CreateWADEx('TEXTURE_WEAPON_ROCKET', GameWAD+':TEXTURES\BROCKET');
1114 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_SKELFIRE', GameWAD+':TEXTURES\BSKELFIRE', 64, 16, 2);
1115 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_BFG', GameWAD+':TEXTURES\BBFG', 64, 64, 2);
1116 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_PLASMA', GameWAD+':TEXTURES\BPLASMA', 16, 16, 2);
1117 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_IMPFIRE', GameWAD+':TEXTURES\BIMPFIRE', 16, 16, 2);
1118 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_BSPFIRE', GameWAD+':TEXTURES\BBSPFIRE', 16, 16, 2);
1119 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_CACOFIRE', GameWAD+':TEXTURES\BCACOFIRE', 16, 16, 2);
1120 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_BARONFIRE', GameWAD+':TEXTURES\BBARONFIRE', 64, 16, 2);
1121 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_MANCUBFIRE', GameWAD+':TEXTURES\BMANCUBFIRE', 64, 32, 2);
1122 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_ROCKET', GameWAD+':TEXTURES\EROCKET', 128, 128, 6);
1123 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_SKELFIRE', GameWAD+':TEXTURES\ESKELFIRE', 64, 64, 3);
1124 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_BFG', GameWAD+':TEXTURES\EBFG', 128, 128, 6);
1125 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_IMPFIRE', GameWAD+':TEXTURES\EIMPFIRE', 64, 64, 3);
1126 g_Frames_CreateWAD(nil, 'FRAMES_BFGHIT', GameWAD+':TEXTURES\BFGHIT', 64, 64, 4);
1127 g_Frames_CreateWAD(nil, 'FRAMES_FIRE', GameWAD+':TEXTURES\FIRE', 64, 128, 8);
1128 g_Frames_CreateWAD(nil, 'FRAMES_FLAME', GameWAD+':TEXTURES\FLAME', 32, 32, 11);
1129 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_PLASMA', GameWAD+':TEXTURES\EPLASMA', 32, 32, 4, True);
1130 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_BSPFIRE', GameWAD+':TEXTURES\EBSPFIRE', 32, 32, 5);
1131 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_CACOFIRE', GameWAD+':TEXTURES\ECACOFIRE', 64, 64, 3);
1132 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_BARONFIRE', GameWAD+':TEXTURES\EBARONFIRE', 64, 64, 3);
1133 g_Frames_CreateWAD(nil, 'FRAMES_SMOKE', GameWAD+':TEXTURES\SMOKE', 32, 32, 10, False);
1135 g_Texture_CreateWADEx('TEXTURE_SHELL_BULLET', GameWAD+':TEXTURES\EBULLET');
1136 g_Texture_CreateWADEx('TEXTURE_SHELL_SHELL', GameWAD+':TEXTURES\ESHELL');
1137 end;
1139 procedure g_Weapon_FreeData();
1140 begin
1141 e_WriteLog('Releasing weapons data...', MSG_NOTIFY);
1143 g_Sound_Delete('SOUND_WEAPON_HITPUNCH');
1144 g_Sound_Delete('SOUND_WEAPON_MISSPUNCH');
1145 g_Sound_Delete('SOUND_WEAPON_HITBERSERK');
1146 g_Sound_Delete('SOUND_WEAPON_MISSBERSERK');
1147 g_Sound_Delete('SOUND_WEAPON_SELECTSAW');
1148 g_Sound_Delete('SOUND_WEAPON_IDLESAW');
1149 g_Sound_Delete('SOUND_WEAPON_HITSAW');
1150 g_Sound_Delete('SOUND_WEAPON_FIRESHOTGUN2');
1151 g_Sound_Delete('SOUND_WEAPON_FIRESHOTGUN');
1152 g_Sound_Delete('SOUND_WEAPON_FIRESAW');
1153 g_Sound_Delete('SOUND_WEAPON_FIREROCKET');
1154 g_Sound_Delete('SOUND_WEAPON_FIREPLASMA');
1155 g_Sound_Delete('SOUND_WEAPON_FIREPISTOL');
1156 g_Sound_Delete('SOUND_WEAPON_FIRECGUN');
1157 g_Sound_Delete('SOUND_WEAPON_FIREBFG');
1158 g_Sound_Delete('SOUND_FIRE');
1159 g_Sound_Delete('SOUND_WEAPON_STARTFIREBFG');
1160 g_Sound_Delete('SOUND_WEAPON_EXPLODEROCKET');
1161 g_Sound_Delete('SOUND_WEAPON_EXPLODEBFG');
1162 g_Sound_Delete('SOUND_WEAPON_BFGWATER');
1163 g_Sound_Delete('SOUND_WEAPON_EXPLODEPLASMA');
1164 g_Sound_Delete('SOUND_WEAPON_PLASMAWATER');
1165 g_Sound_Delete('SOUND_WEAPON_FIREBALL');
1166 g_Sound_Delete('SOUND_WEAPON_EXPLODEBALL');
1167 g_Sound_Delete('SOUND_WEAPON_FIREREV');
1168 g_Sound_Delete('SOUND_PLAYER_JETFLY');
1169 g_Sound_Delete('SOUND_PLAYER_JETON');
1170 g_Sound_Delete('SOUND_PLAYER_JETOFF');
1171 g_Sound_Delete('SOUND_PLAYER_CASING1');
1172 g_Sound_Delete('SOUND_PLAYER_CASING2');
1173 g_Sound_Delete('SOUND_PLAYER_SHELL1');
1174 g_Sound_Delete('SOUND_PLAYER_SHELL2');
1176 g_Texture_Delete('TEXTURE_WEAPON_ROCKET');
1177 g_Frames_DeleteByName('FRAMES_WEAPON_BFG');
1178 g_Frames_DeleteByName('FRAMES_WEAPON_PLASMA');
1179 g_Frames_DeleteByName('FRAMES_WEAPON_IMPFIRE');
1180 g_Frames_DeleteByName('FRAMES_WEAPON_BSPFIRE');
1181 g_Frames_DeleteByName('FRAMES_WEAPON_CACOFIRE');
1182 g_Frames_DeleteByName('FRAMES_WEAPON_MANCUBFIRE');
1183 g_Frames_DeleteByName('FRAMES_EXPLODE_ROCKET');
1184 g_Frames_DeleteByName('FRAMES_EXPLODE_BFG');
1185 g_Frames_DeleteByName('FRAMES_EXPLODE_IMPFIRE');
1186 g_Frames_DeleteByName('FRAMES_BFGHIT');
1187 g_Frames_DeleteByName('FRAMES_FIRE');
1188 g_Frames_DeleteByName('FRAMES_EXPLODE_PLASMA');
1189 g_Frames_DeleteByName('FRAMES_EXPLODE_BSPFIRE');
1190 g_Frames_DeleteByName('FRAMES_EXPLODE_CACOFIRE');
1191 g_Frames_DeleteByName('FRAMES_SMOKE');
1192 g_Frames_DeleteByName('FRAMES_WEAPON_BARONFIRE');
1193 g_Frames_DeleteByName('FRAMES_EXPLODE_BARONFIRE');
1194 end;
1196 procedure g_Weapon_gun(x, y, xd, yd, v, dmg: Integer; SpawnerUID: Word; CheckTrigger: Boolean);
1197 var
1198 a: Integer;
1199 x2, y2: Integer;
1200 dx, dy: Integer;
1201 xe, ye: Integer;
1202 xi, yi: Integer;
1203 s, c: Extended;
1204 //vx, vy: Integer;
1205 xx, yy, d: Integer;
1207 i: Integer;
1208 t1, _collide: Boolean;
1209 w, h: Word;
1210 begin
1211 a := GetAngle(x, y, xd, yd)+180;
1213 SinCos(DegToRad(-a), s, c);
1215 if Abs(s) < 0.01 then s := 0;
1216 if Abs(c) < 0.01 then c := 0;
1218 x2 := x+Round(c*gMapInfo.Width);
1219 y2 := y+Round(s*gMapInfo.Width);
1221 t1 := gWalls <> nil;
1222 _collide := False;
1223 w := gMapInfo.Width;
1224 h := gMapInfo.Height;
1226 xe := 0;
1227 ye := 0;
1228 dx := x2-x;
1229 dy := y2-y;
1231 if (xd = 0) and (yd = 0) then Exit;
1233 if dx > 0 then xi := 1 else if dx < 0 then xi := -1 else xi := 0;
1234 if dy > 0 then yi := 1 else if dy < 0 then yi := -1 else yi := 0;
1236 dx := Abs(dx);
1237 dy := Abs(dy);
1239 if dx > dy then d := dx else d := dy;
1241 //blood vel, for Monster.Damage()
1242 //vx := (dx*10 div d)*xi;
1243 //vy := (dy*10 div d)*yi;
1245 xx := x;
1246 yy := y;
1248 for i := 1 to d do
1249 begin
1250 xe := xe+dx;
1251 ye := ye+dy;
1253 if xe > d then
1254 begin
1255 xe := xe-d;
1256 xx := xx+xi;
1257 end;
1259 if ye > d then
1260 begin
1261 ye := ye-d;
1262 yy := yy+yi;
1263 end;
1265 if (yy > h) or (yy < 0) then Break;
1266 if (xx > w) or (xx < 0) then Break;
1268 if t1 then
1269 if ByteBool(gCollideMap[yy, xx] and MARK_BLOCKED) then
1270 begin
1271 _collide := True;
1272 g_GFX_Spark(xx-xi, yy-yi, 2+Random(2), 180+a, 0, 0);
1273 if g_Game_IsServer and g_Game_IsNet then
1274 MH_SEND_Effect(xx-xi, yy-yi, 180+a, NET_GFX_SPARK);
1275 end;
1277 if not _collide then
1278 _collide := GunHit(xx, yy, xi*v, yi*v, dmg, SpawnerUID, v <> 0) <> 0;
1280 if _collide then
1281 Break;
1282 end;
1284 if CheckTrigger and g_Game_IsServer then
1285 g_Triggers_PressL(X, Y, xx-xi, yy-yi, SpawnerUID, ACTIVATE_SHOT);
1286 end;
1288 procedure g_Weapon_punch(x, y: Integer; d, SpawnerUID: Word);
1289 var
1290 obj: TObj;
1291 begin
1292 obj.X := X;
1293 obj.Y := Y;
1294 obj.rect.X := 0;
1295 obj.rect.Y := 0;
1296 obj.rect.Width := 39;
1297 obj.rect.Height := 52;
1298 obj.Vel.X := 0;
1299 obj.Vel.Y := 0;
1300 obj.Accel.X := 0;
1301 obj.Accel.Y := 0;
1303 if g_Weapon_Hit(@obj, d, SpawnerUID, HIT_SOME) <> 0 then
1304 g_Sound_PlayExAt('SOUND_WEAPON_HITPUNCH', x, y)
1305 else
1306 g_Sound_PlayExAt('SOUND_WEAPON_MISSPUNCH', x, y);
1307 end;
1309 function g_Weapon_chainsaw(x, y: Integer; d, SpawnerUID: Word): Integer;
1310 var
1311 obj: TObj;
1312 begin
1313 obj.X := X;
1314 obj.Y := Y;
1315 obj.rect.X := 0;
1316 obj.rect.Y := 0;
1317 obj.rect.Width := 32;
1318 obj.rect.Height := 52;
1319 obj.Vel.X := 0;
1320 obj.Vel.Y := 0;
1321 obj.Accel.X := 0;
1322 obj.Accel.Y := 0;
1324 Result := g_Weapon_Hit(@obj, d, SpawnerUID, HIT_SOME);
1325 end;
1327 procedure g_Weapon_rocket(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1328 Silent: Boolean = False);
1329 var
1330 find_id: DWORD;
1331 dx, dy: Integer;
1332 begin
1333 if WID < 0 then
1334 find_id := FindShot()
1335 else
1336 begin
1337 find_id := WID;
1338 if Integer(find_id) >= High(Shots) then
1339 SetLength(Shots, find_id + 64)
1340 end;
1342 with Shots[find_id] do
1343 begin
1344 g_Obj_Init(@Obj);
1346 Obj.Rect.Width := SHOT_ROCKETLAUNCHER_WIDTH;
1347 Obj.Rect.Height := SHOT_ROCKETLAUNCHER_HEIGHT;
1349 dx := IfThen(xd > x, -Obj.Rect.Width, 0);
1350 dy := -(Obj.Rect.Height div 2);
1352 ShotType := WEAPON_ROCKETLAUNCHER;
1353 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 12);
1355 Animation := nil;
1356 triggers := nil;
1357 g_Texture_Get('TEXTURE_WEAPON_ROCKET', TextureID);
1358 end;
1360 Shots[find_id].SpawnerUID := SpawnerUID;
1362 if not Silent then
1363 g_Sound_PlayExAt('SOUND_WEAPON_FIREROCKET', x, y);
1364 end;
1366 procedure g_Weapon_revf(x, y, xd, yd: Integer; SpawnerUID, TargetUID: Word;
1367 WID: Integer = -1; Silent: Boolean = False);
1368 var
1369 find_id, FramesID: DWORD;
1370 dx, dy: Integer;
1371 begin
1372 if WID < 0 then
1373 find_id := FindShot()
1374 else
1375 begin
1376 find_id := WID;
1377 if Integer(find_id) >= High(Shots) then
1378 SetLength(Shots, find_id + 64)
1379 end;
1381 with Shots[find_id] do
1382 begin
1383 g_Obj_Init(@Obj);
1385 Obj.Rect.Width := SHOT_SKELFIRE_WIDTH;
1386 Obj.Rect.Height := SHOT_SKELFIRE_HEIGHT;
1388 dx := -(Obj.Rect.Width div 2);
1389 dy := -(Obj.Rect.Height div 2);
1391 ShotType := WEAPON_SKEL_FIRE;
1392 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 12);
1394 triggers := nil;
1395 target := TargetUID;
1396 g_Frames_Get(FramesID, 'FRAMES_WEAPON_SKELFIRE');
1397 Animation := TAnimation.Create(FramesID, True, 5);
1398 end;
1400 Shots[find_id].SpawnerUID := SpawnerUID;
1402 if not Silent then
1403 g_Sound_PlayExAt('SOUND_WEAPON_FIREREV', x, y);
1404 end;
1406 procedure g_Weapon_plasma(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1407 Silent: Boolean = False);
1408 var
1409 find_id, FramesID: DWORD;
1410 dx, dy: Integer;
1411 begin
1412 if WID < 0 then
1413 find_id := FindShot()
1414 else
1415 begin
1416 find_id := WID;
1417 if Integer(find_id) >= High(Shots) then
1418 SetLength(Shots, find_id + 64);
1419 end;
1421 with Shots[find_id] do
1422 begin
1423 g_Obj_Init(@Obj);
1425 Obj.Rect.Width := SHOT_PLASMA_WIDTH;
1426 Obj.Rect.Height := SHOT_PLASMA_HEIGHT;
1428 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1429 dy := -(Obj.Rect.Height div 2);
1431 ShotType := WEAPON_PLASMA;
1432 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1434 triggers := nil;
1435 g_Frames_Get(FramesID, 'FRAMES_WEAPON_PLASMA');
1436 Animation := TAnimation.Create(FramesID, True, 5);
1437 end;
1439 Shots[find_id].SpawnerUID := SpawnerUID;
1441 if not Silent then
1442 g_Sound_PlayExAt('SOUND_WEAPON_FIREPLASMA', x, y);
1443 end;
1445 procedure g_Weapon_flame(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1446 Silent: Boolean = False);
1447 var
1448 find_id: DWORD;
1449 dx, dy: Integer;
1450 begin
1451 if WID < 0 then
1452 find_id := FindShot()
1453 else
1454 begin
1455 find_id := WID;
1456 if Integer(find_id) >= High(Shots) then
1457 SetLength(Shots, find_id + 64);
1458 end;
1460 with Shots[find_id] do
1461 begin
1462 g_Obj_Init(@Obj);
1464 Obj.Rect.Width := SHOT_FLAME_WIDTH;
1465 Obj.Rect.Height := SHOT_FLAME_HEIGHT;
1467 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1468 dy := -(Obj.Rect.Height div 2);
1470 ShotType := WEAPON_FLAMETHROWER;
1471 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1473 triggers := nil;
1474 Animation := nil;
1475 TextureID := 0;
1476 g_Frames_Get(TextureID, 'FRAMES_FLAME');
1477 end;
1479 Shots[find_id].SpawnerUID := SpawnerUID;
1481 // if not Silent then
1482 // g_Sound_PlayExAt('SOUND_WEAPON_FIREPLASMA', x, y);
1483 end;
1485 procedure g_Weapon_ball1(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1486 Silent: Boolean = False);
1487 var
1488 find_id, FramesID: DWORD;
1489 dx, dy: Integer;
1490 begin
1491 if WID < 0 then
1492 find_id := FindShot()
1493 else
1494 begin
1495 find_id := WID;
1496 if Integer(find_id) >= High(Shots) then
1497 SetLength(Shots, find_id + 64)
1498 end;
1500 with Shots[find_id] do
1501 begin
1502 g_Obj_Init(@Obj);
1504 Obj.Rect.Width := 16;
1505 Obj.Rect.Height := 16;
1507 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1508 dy := -(Obj.Rect.Height div 2);
1510 ShotType := WEAPON_IMP_FIRE;
1511 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1513 triggers := nil;
1514 g_Frames_Get(FramesID, 'FRAMES_WEAPON_IMPFIRE');
1515 Animation := TAnimation.Create(FramesID, True, 4);
1516 end;
1518 Shots[find_id].SpawnerUID := SpawnerUID;
1520 if not Silent then
1521 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x, y);
1522 end;
1524 procedure g_Weapon_ball2(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1525 Silent: Boolean = False);
1526 var
1527 find_id, FramesID: DWORD;
1528 dx, dy: Integer;
1529 begin
1530 if WID < 0 then
1531 find_id := FindShot()
1532 else
1533 begin
1534 find_id := WID;
1535 if Integer(find_id) >= High(Shots) then
1536 SetLength(Shots, find_id + 64)
1537 end;
1539 with Shots[find_id] do
1540 begin
1541 g_Obj_Init(@Obj);
1543 Obj.Rect.Width := 16;
1544 Obj.Rect.Height := 16;
1546 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1547 dy := -(Obj.Rect.Height div 2);
1549 ShotType := WEAPON_CACO_FIRE;
1550 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1552 triggers := nil;
1553 g_Frames_Get(FramesID, 'FRAMES_WEAPON_CACOFIRE');
1554 Animation := TAnimation.Create(FramesID, True, 4);
1555 end;
1557 Shots[find_id].SpawnerUID := SpawnerUID;
1559 if not Silent then
1560 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x, y);
1561 end;
1563 procedure g_Weapon_ball7(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1564 Silent: Boolean = False);
1565 var
1566 find_id, FramesID: DWORD;
1567 dx, dy: Integer;
1568 begin
1569 if WID < 0 then
1570 find_id := FindShot()
1571 else
1572 begin
1573 find_id := WID;
1574 if Integer(find_id) >= High(Shots) then
1575 SetLength(Shots, find_id + 64)
1576 end;
1578 with Shots[find_id] do
1579 begin
1580 g_Obj_Init(@Obj);
1582 Obj.Rect.Width := 32;
1583 Obj.Rect.Height := 16;
1585 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1586 dy := -(Obj.Rect.Height div 2);
1588 ShotType := WEAPON_BARON_FIRE;
1589 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1591 triggers := nil;
1592 g_Frames_Get(FramesID, 'FRAMES_WEAPON_BARONFIRE');
1593 Animation := TAnimation.Create(FramesID, True, 4);
1594 end;
1596 Shots[find_id].SpawnerUID := SpawnerUID;
1598 if not Silent then
1599 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x, y);
1600 end;
1602 procedure g_Weapon_aplasma(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1603 Silent: Boolean = False);
1604 var
1605 find_id, FramesID: DWORD;
1606 dx, dy: Integer;
1607 begin
1608 if WID < 0 then
1609 find_id := FindShot()
1610 else
1611 begin
1612 find_id := WID;
1613 if Integer(find_id) >= High(Shots) then
1614 SetLength(Shots, find_id + 64)
1615 end;
1617 with Shots[find_id] do
1618 begin
1619 g_Obj_Init(@Obj);
1621 Obj.Rect.Width := 16;
1622 Obj.Rect.Height := 16;
1624 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1625 dy := -(Obj.Rect.Height div 2);
1627 ShotType := WEAPON_BSP_FIRE;
1628 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1630 triggers := nil;
1632 g_Frames_Get(FramesID, 'FRAMES_WEAPON_BSPFIRE');
1633 Animation := TAnimation.Create(FramesID, True, 4);
1634 end;
1636 Shots[find_id].SpawnerUID := SpawnerUID;
1638 if not Silent then
1639 g_Sound_PlayExAt('SOUND_WEAPON_FIREPLASMA', x, y);
1640 end;
1642 procedure g_Weapon_manfire(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1643 Silent: Boolean = False);
1644 var
1645 find_id, FramesID: DWORD;
1646 dx, dy: Integer;
1647 begin
1648 if WID < 0 then
1649 find_id := FindShot()
1650 else
1651 begin
1652 find_id := WID;
1653 if Integer(find_id) >= High(Shots) then
1654 SetLength(Shots, find_id + 64)
1655 end;
1657 with Shots[find_id] do
1658 begin
1659 g_Obj_Init(@Obj);
1661 Obj.Rect.Width := 32;
1662 Obj.Rect.Height := 32;
1664 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1665 dy := -(Obj.Rect.Height div 2);
1667 ShotType := WEAPON_MANCUB_FIRE;
1668 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1670 triggers := nil;
1672 g_Frames_Get(FramesID, 'FRAMES_WEAPON_MANCUBFIRE');
1673 Animation := TAnimation.Create(FramesID, True, 4);
1674 end;
1676 Shots[find_id].SpawnerUID := SpawnerUID;
1678 if not Silent then
1679 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x, y);
1680 end;
1682 procedure g_Weapon_bfgshot(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1683 Silent: Boolean = False);
1684 var
1685 find_id, FramesID: DWORD;
1686 dx, dy: Integer;
1687 begin
1688 if WID < 0 then
1689 find_id := FindShot()
1690 else
1691 begin
1692 find_id := WID;
1693 if Integer(find_id) >= High(Shots) then
1694 SetLength(Shots, find_id + 64)
1695 end;
1697 with Shots[find_id] do
1698 begin
1699 g_Obj_Init(@Obj);
1701 Obj.Rect.Width := SHOT_BFG_WIDTH;
1702 Obj.Rect.Height := SHOT_BFG_HEIGHT;
1704 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1705 dy := -(Obj.Rect.Height div 2);
1707 ShotType := WEAPON_BFG;
1708 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1710 triggers := nil;
1711 g_Frames_Get(FramesID, 'FRAMES_WEAPON_BFG');
1712 Animation := TAnimation.Create(FramesID, True, 6);
1713 end;
1715 Shots[find_id].SpawnerUID := SpawnerUID;
1717 if not Silent then
1718 g_Sound_PlayExAt('SOUND_WEAPON_FIREBFG', x, y);
1719 end;
1721 procedure g_Weapon_bfghit(x, y: Integer);
1722 var
1723 ID: DWORD;
1724 Anim: TAnimation;
1725 begin
1726 if g_Frames_Get(ID, 'FRAMES_BFGHIT') then
1727 begin
1728 Anim := TAnimation.Create(ID, False, 4);
1729 g_GFX_OnceAnim(x-32, y-32, Anim);
1730 Anim.Free();
1731 end;
1732 end;
1734 procedure g_Weapon_pistol(x, y, xd, yd: Integer; SpawnerUID: Word;
1735 Silent: Boolean = False);
1736 begin
1737 if not Silent then
1738 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', x, y);
1740 g_Weapon_gun(x, y, xd, yd, 1, 3, SpawnerUID, True);
1741 if gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF] then
1742 begin
1743 g_Weapon_gun(x, y+1, xd, yd+1, 1, 3, SpawnerUID, False);
1744 g_Weapon_gun(x, y-1, xd, yd-1, 1, 2, SpawnerUID, False);
1745 end;
1746 end;
1748 procedure g_Weapon_mgun(x, y, xd, yd: Integer; SpawnerUID: Word;
1749 Silent: Boolean = False);
1750 begin
1751 if not Silent then
1752 if gSoundEffectsDF then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', x, y);
1754 g_Weapon_gun(x, y, xd, yd, 1, 3, SpawnerUID, True);
1755 if (gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF]) and
1756 (g_GetUIDType(SpawnerUID) = UID_PLAYER) then
1757 begin
1758 g_Weapon_gun(x, y+1, xd, yd+1, 1, 2, SpawnerUID, False);
1759 g_Weapon_gun(x, y-1, xd, yd-1, 1, 2, SpawnerUID, False);
1760 end;
1761 end;
1763 procedure g_Weapon_shotgun(x, y, xd, yd: Integer; SpawnerUID: Word;
1764 Silent: Boolean = False);
1765 var
1766 i, j: Integer;
1767 begin
1768 if not Silent then
1769 if gSoundEffectsDF then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', x, y);
1771 for i := 0 to 9 do
1772 begin
1773 j := Random(17)-8; // -8 .. 8
1774 g_Weapon_gun(x, y+j, xd, yd+j, IfThen(i mod 2 <> 0, 1, 0), 3, SpawnerUID, i=0);
1775 end;
1776 end;
1778 procedure g_Weapon_dshotgun(x, y, xd, yd: Integer; SpawnerUID: Word;
1779 Silent: Boolean = False);
1780 var
1781 a, i, j: Integer;
1782 begin
1783 if not Silent then
1784 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', x, y);
1786 if gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF] then a := 25 else a := 20;
1787 for i := 0 to a do
1788 begin
1789 j := Random(41)-20; // -20 .. 20
1790 g_Weapon_gun(x, y+j, xd, yd+j, IfThen(i mod 3 <> 0, 0, 1), 3, SpawnerUID, i=0);
1791 end;
1792 end;
1794 procedure g_Weapon_Update();
1795 var
1796 i, a, h, cx, cy, oldvx, oldvy, tf: Integer;
1797 _id: DWORD;
1798 Anim: TAnimation;
1799 t: DWArray;
1800 st: Word;
1801 s: String;
1802 o: TObj;
1803 spl: Boolean;
1804 Loud: Boolean;
1805 tcx, tcy: Integer;
1806 begin
1807 if Shots = nil then
1808 Exit;
1810 for i := 0 to High(Shots) do
1811 begin
1812 if Shots[i].ShotType = 0 then
1813 Continue;
1815 Loud := True;
1817 with Shots[i] do
1818 begin
1819 Timeout := Timeout - 1;
1820 oldvx := Obj.Vel.X;
1821 oldvy := Obj.Vel.Y;
1822 // Àêòèâèðîâàòü òðèããåðû ïî ïóòè (êðîìå óæå àêòèâèðîâàííûõ):
1823 if (Stopped = 0) and g_Game_IsServer then
1824 t := g_Triggers_PressR(Obj.X, Obj.Y, Obj.Rect.Width, Obj.Rect.Height,
1825 SpawnerUID, ACTIVATE_SHOT, triggers)
1826 else
1827 t := nil;
1829 if t <> nil then
1830 begin
1831 // Ïîïîëíÿåì ñïèñîê àêòèâèðîâàííûõ òðèããåðîâ:
1832 if triggers = nil then
1833 triggers := t
1834 else
1835 begin
1836 h := High(t);
1838 for a := 0 to h do
1839 if not InDWArray(t[a], triggers) then
1840 begin
1841 SetLength(triggers, Length(triggers)+1);
1842 triggers[High(triggers)] := t[a];
1843 end;
1844 end;
1845 end;
1847 // Àíèìàöèÿ ñíàðÿäà:
1848 if Animation <> nil then
1849 Animation.Update();
1851 // Äâèæåíèå:
1852 spl := (ShotType <> WEAPON_PLASMA) and
1853 (ShotType <> WEAPON_BFG) and
1854 (ShotType <> WEAPON_BSP_FIRE) and
1855 (ShotType <> WEAPON_FLAMETHROWER);
1857 if Stopped = 0 then
1858 begin
1859 st := g_Obj_Move(@Obj, False, spl);
1860 end
1861 else
1862 begin
1863 st := 0;
1864 end;
1865 positionChanged(); // this updates spatial accelerators
1867 if WordBool(st and MOVE_FALLOUT) or (Obj.X < -1000) or
1868 (Obj.X > gMapInfo.Width+1000) or (Obj.Y < -1000) then
1869 begin
1870 // Íà êëèåíòå ñêîðåå âñåãî è òàê óæå âûïàë.
1871 ShotType := 0;
1872 Animation.Free();
1873 Continue;
1874 end;
1876 cx := Obj.X + (Obj.Rect.Width div 2);
1877 cy := Obj.Y + (Obj.Rect.Height div 2);
1879 case ShotType of
1880 WEAPON_ROCKETLAUNCHER, WEAPON_SKEL_FIRE: // Ðàêåòû è ñíàðÿäû Ñêåëåòà
1881 begin
1882 // Âûëåòåëà èç âîäû:
1883 if WordBool(st and MOVE_HITAIR) then
1884 g_Obj_SetSpeed(@Obj, 12);
1886 // Â âîäå øëåéô - ïóçûðè, â âîçäóõå øëåéô - äûì:
1887 if WordBool(st and MOVE_INWATER) then
1888 g_GFX_Bubbles(Obj.X+(Obj.Rect.Width div 2),
1889 Obj.Y+(Obj.Rect.Height div 2),
1890 1+Random(3), 16, 16)
1891 else
1892 if g_Frames_Get(_id, 'FRAMES_SMOKE') then
1893 begin
1894 Anim := TAnimation.Create(_id, False, 3);
1895 Anim.Alpha := 150;
1896 g_GFX_OnceAnim(Obj.X-14+Random(9),
1897 Obj.Y+(Obj.Rect.Height div 2)-20+Random(9),
1898 Anim, ONCEANIM_SMOKE);
1899 Anim.Free();
1900 end;
1902 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
1903 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL)) or
1904 (g_Weapon_Hit(@Obj, 10, SpawnerUID, HIT_SOME, False) <> 0) or
1905 (Timeout < 1) then
1906 begin
1907 Obj.Vel.X := 0;
1908 Obj.Vel.Y := 0;
1910 g_Weapon_Explode(cx, cy, 60, SpawnerUID);
1912 if ShotType = WEAPON_SKEL_FIRE then
1913 begin // Âçðûâ ñíàðÿäà Ñêåëåòà
1914 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_SKELFIRE') then
1915 begin
1916 Anim := TAnimation.Create(TextureID, False, 8);
1917 Anim.Blending := False;
1918 g_GFX_OnceAnim((Obj.X+32)-58, (Obj.Y+8)-36, Anim);
1919 g_DynLightExplosion((Obj.X+32), (Obj.Y+8), 64, 1, 0, 0);
1920 Anim.Free();
1921 end;
1922 end
1923 else
1924 begin // Âçðûâ Ðàêåòû
1925 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_ROCKET') then
1926 begin
1927 Anim := TAnimation.Create(TextureID, False, 6);
1928 Anim.Blending := False;
1929 g_GFX_OnceAnim(cx-64, cy-64, Anim);
1930 g_DynLightExplosion(cx, cy, 64, 1, 0, 0);
1931 Anim.Free();
1932 end;
1933 end;
1935 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', Obj.X, Obj.Y);
1937 ShotType := 0;
1938 end;
1940 if ShotType = WEAPON_SKEL_FIRE then
1941 begin // Ñàìîíàâîäêà ñíàðÿäà Ñêåëåòà:
1942 if GetPos(target, @o) then
1943 throw(i, Obj.X, Obj.Y,
1944 o.X+o.Rect.X+(o.Rect.Width div 2)+o.Vel.X+o.Accel.X,
1945 o.Y+o.Rect.Y+(o.Rect.Height div 2)+o.Vel.Y+o.Accel.Y,
1946 12);
1947 end;
1948 end;
1950 WEAPON_PLASMA, WEAPON_BSP_FIRE: // Ïëàçìà, ïëàçìà Àðàõíàòðîíà
1951 begin
1952 // Ïîïàëà â âîäó - ýëåêòðîøîê ïî âîäå:
1953 if WordBool(st and (MOVE_INWATER or MOVE_HITWATER)) then
1954 begin
1955 g_Sound_PlayExAt('SOUND_WEAPON_PLASMAWATER', Obj.X, Obj.Y);
1956 if g_Game_IsServer then CheckTrap(i, 10, HIT_ELECTRO);
1957 ShotType := 0;
1958 Continue;
1959 end;
1961 // Âåëè÷èíà óðîíà:
1962 if (ShotType = WEAPON_PLASMA) and
1963 (gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF]) then
1964 a := 10
1965 else
1966 a := 5;
1968 if ShotType = WEAPON_BSP_FIRE then
1969 a := 10;
1971 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
1972 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL)) or
1973 (g_Weapon_Hit(@Obj, a, SpawnerUID, HIT_SOME, False) <> 0) or
1974 (Timeout < 1) then
1975 begin
1976 if ShotType = WEAPON_PLASMA then
1977 s := 'FRAMES_EXPLODE_PLASMA'
1978 else
1979 s := 'FRAMES_EXPLODE_BSPFIRE';
1981 // Âçðûâ Ïëàçìû:
1982 if g_Frames_Get(TextureID, s) then
1983 begin
1984 Anim := TAnimation.Create(TextureID, False, 3);
1985 Anim.Blending := False;
1986 g_GFX_OnceAnim(cx-16, cy-16, Anim);
1987 Anim.Free();
1988 g_DynLightExplosion(cx, cy, 32, 0, 0.5, 0.5);
1989 end;
1991 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEPLASMA', Obj.X, Obj.Y);
1993 ShotType := 0;
1994 end;
1995 end;
1997 WEAPON_FLAMETHROWER: // Îãíåìåò
1998 begin
1999 // Ñî âðåìåíåì óìèðàåò
2000 if (Timeout < 1) then
2001 begin
2002 ShotType := 0;
2003 Continue;
2004 end;
2005 // Ïîä âîäîé òîæå
2006 if WordBool(st and (MOVE_HITWATER or MOVE_INWATER)) then
2007 begin
2008 if WordBool(st and MOVE_HITWATER) then
2009 begin
2010 if g_Frames_Get(_id, 'FRAMES_SMOKE') then
2011 begin
2012 Anim := TAnimation.Create(_id, False, 3);
2013 Anim.Alpha := 0;
2014 tcx := Random(8);
2015 tcy := Random(8);
2016 g_GFX_OnceAnim(cx-4+tcx-(Anim.Width div 2),
2017 cy-4+tcy-(Anim.Height div 2),
2018 Anim, ONCEANIM_SMOKE);
2019 Anim.Free();
2020 end;
2021 end
2022 else
2023 g_GFX_Bubbles(cx, cy, 1+Random(3), 16, 16);
2024 ShotType := 0;
2025 Continue;
2026 end;
2028 // Ãðàâèòàöèÿ
2029 if Stopped = 0 then
2030 Obj.Accel.Y := Obj.Accel.Y + 1;
2031 // Ïîïàëè â ñòåíó èëè â âîäó:
2032 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL or MOVE_HITWATER)) then
2033 begin
2034 // Ïðèëèïàåì:
2035 Obj.Vel.X := 0;
2036 Obj.Vel.Y := 0;
2037 Obj.Accel.Y := 0;
2038 if WordBool(st and MOVE_HITWALL) then
2039 Stopped := MOVE_HITWALL
2040 else if WordBool(st and MOVE_HITLAND) then
2041 Stopped := MOVE_HITLAND
2042 else if WordBool(st and MOVE_HITCEIL) then
2043 Stopped := MOVE_HITCEIL;
2044 end;
2046 a := IfThen(Stopped = 0, 3, 1);
2047 // Åñëè â êîãî-òî ïîïàëè
2048 if g_Weapon_Hit(@Obj, a, SpawnerUID, HIT_FLAME, False) <> 0 then
2049 begin
2050 // HIT_FLAME ñàì ïîäîææåò
2051 // Åñëè â ïîëåòå ïîïàëè, èñ÷åçàåì
2052 if Stopped = 0 then
2053 ShotType := 0;
2054 end;
2056 if Stopped = 0 then
2057 tf := 2
2058 else
2059 tf := 3;
2061 if (gTime mod tf = 0) then
2062 begin
2063 Anim := TAnimation.Create(TextureID, False, 2 + Random(2));
2064 Anim.Alpha := 0;
2065 case Stopped of
2066 MOVE_HITWALL: begin tcx := cx-4+Random(8); tcy := cy-12+Random(24); end;
2067 MOVE_HITLAND: begin tcx := cx-12+Random(24); tcy := cy-10+Random(8); end;
2068 MOVE_HITCEIL: begin tcx := cx-12+Random(24); tcy := cy+6+Random(8); end;
2069 else begin tcx := cx-4+Random(8); tcy := cy-4+Random(8); end;
2070 end;
2071 g_GFX_OnceAnim(tcx-(Anim.Width div 2), tcy-(Anim.Height div 2), Anim, ONCEANIM_SMOKE);
2072 Anim.Free();
2073 //g_DynLightExplosion(tcx, tcy, 1, 1, 0.8, 0.3);
2074 end;
2075 end;
2077 WEAPON_BFG: // BFG
2078 begin
2079 // Ïîïàëà â âîäó - ýëåêòðîøîê ïî âîäå:
2080 if WordBool(st and (MOVE_INWATER or MOVE_HITWATER)) then
2081 begin
2082 g_Sound_PlayExAt('SOUND_WEAPON_BFGWATER', Obj.X, Obj.Y);
2083 if g_Game_IsServer then CheckTrap(i, 1000, HIT_ELECTRO);
2084 ShotType := 0;
2085 Continue;
2086 end;
2088 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2089 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL)) or
2090 (g_Weapon_Hit(@Obj, SHOT_BFG_DAMAGE, SpawnerUID, HIT_BFG, False) <> 0) or
2091 (Timeout < 1) then
2092 begin
2093 // Ëó÷è BFG:
2094 if g_Game_IsServer then g_Weapon_BFG9000(cx, cy, SpawnerUID);
2096 // Âçðûâ BFG:
2097 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_BFG') then
2098 begin
2099 Anim := TAnimation.Create(TextureID, False, 6);
2100 Anim.Blending := False;
2101 g_GFX_OnceAnim(cx-64, cy-64, Anim);
2102 Anim.Free();
2103 g_DynLightExplosion(cx, cy, 96, 0, 1, 0);
2104 end;
2106 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', Obj.X, Obj.Y);
2108 ShotType := 0;
2109 end;
2110 end;
2112 WEAPON_IMP_FIRE, WEAPON_CACO_FIRE, WEAPON_BARON_FIRE: // Âûñòðåëû Áåñà, Êàêîäåìîíà Ðûöàðÿ/Áàðîíà àäà
2113 begin
2114 // Âûëåòåë èç âîäû:
2115 if WordBool(st and MOVE_HITAIR) then
2116 g_Obj_SetSpeed(@Obj, 16);
2118 // Âåëè÷èíà óðîíà:
2119 if ShotType = WEAPON_IMP_FIRE then
2120 a := 5
2121 else
2122 if ShotType = WEAPON_CACO_FIRE then
2123 a := 20
2124 else
2125 a := 40;
2127 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2128 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL)) or
2129 (g_Weapon_Hit(@Obj, a, SpawnerUID, HIT_SOME) <> 0) or
2130 (Timeout < 1) then
2131 begin
2132 if ShotType = WEAPON_IMP_FIRE then
2133 s := 'FRAMES_EXPLODE_IMPFIRE'
2134 else
2135 if ShotType = WEAPON_CACO_FIRE then
2136 s := 'FRAMES_EXPLODE_CACOFIRE'
2137 else
2138 s := 'FRAMES_EXPLODE_BARONFIRE';
2140 // Âçðûâ:
2141 if g_Frames_Get(TextureID, s) then
2142 begin
2143 Anim := TAnimation.Create(TextureID, False, 6);
2144 Anim.Blending := False;
2145 g_GFX_OnceAnim(cx-32, cy-32, Anim);
2146 Anim.Free();
2147 end;
2149 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj.X, Obj.Y);
2151 ShotType := 0;
2152 end;
2153 end;
2155 WEAPON_MANCUB_FIRE: // Âûñòðåë Ìàíêóáóñà
2156 begin
2157 // Âûëåòåë èç âîäû:
2158 if WordBool(st and MOVE_HITAIR) then
2159 g_Obj_SetSpeed(@Obj, 16);
2161 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2162 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL)) or
2163 (g_Weapon_Hit(@Obj, 40, SpawnerUID, HIT_SOME, False) <> 0) or
2164 (Timeout < 1) then
2165 begin
2166 // Âçðûâ:
2167 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_ROCKET') then
2168 begin
2169 Anim := TAnimation.Create(TextureID, False, 6);
2170 Anim.Blending := False;
2171 g_GFX_OnceAnim(cx-64, cy-64, Anim);
2172 Anim.Free();
2173 end;
2175 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj.X, Obj.Y);
2177 ShotType := 0;
2178 end;
2179 end;
2180 end; // case ShotType of...
2182 // Åñëè ñíàðÿäà óæå íåò, óäàëÿåì àíèìàöèþ:
2183 if (ShotType = 0) then
2184 begin
2185 if gGameSettings.GameType = GT_SERVER then
2186 MH_SEND_DeleteShot(i, Obj.X, Obj.Y, Loud);
2187 if Animation <> nil then
2188 begin
2189 Animation.Free();
2190 Animation := nil;
2191 end;
2192 end
2193 else if (ShotType <> WEAPON_FLAMETHROWER) and ((oldvx <> Obj.Vel.X) or (oldvy <> Obj.Vel.Y)) then
2194 if gGameSettings.GameType = GT_SERVER then
2195 MH_SEND_UpdateShot(i);
2196 end;
2197 end;
2198 end;
2200 procedure g_Weapon_Draw();
2201 var
2202 i: Integer;
2203 a: SmallInt;
2204 p: TPoint;
2205 begin
2206 if Shots = nil then
2207 Exit;
2209 for i := 0 to High(Shots) do
2210 if Shots[i].ShotType <> 0 then
2211 with Shots[i] do
2212 begin
2213 if (Shots[i].ShotType = WEAPON_ROCKETLAUNCHER) or
2214 (Shots[i].ShotType = WEAPON_BARON_FIRE) or
2215 (Shots[i].ShotType = WEAPON_MANCUB_FIRE) or
2216 (Shots[i].ShotType = WEAPON_SKEL_FIRE) then
2217 a := -GetAngle2(Obj.Vel.X, Obj.Vel.Y)
2218 else
2219 a := 0;
2221 p.X := Obj.Rect.Width div 2;
2222 p.Y := Obj.Rect.Height div 2;
2224 if Animation <> nil then
2225 begin
2226 if (Shots[i].ShotType = WEAPON_BARON_FIRE) or
2227 (Shots[i].ShotType = WEAPON_MANCUB_FIRE) or
2228 (Shots[i].ShotType = WEAPON_SKEL_FIRE) then
2229 Animation.DrawEx(Obj.X, Obj.Y, M_NONE, p, a)
2230 else
2231 Animation.Draw(Obj.X, Obj.Y, M_NONE);
2232 end
2233 else if TextureID <> 0 then
2234 begin
2235 if (Shots[i].ShotType = WEAPON_ROCKETLAUNCHER) then
2236 e_DrawAdv(TextureID, Obj.X, Obj.Y, 0, True, False, a, @p, M_NONE)
2237 else if (Shots[i].ShotType <> WEAPON_FLAMETHROWER) then
2238 e_Draw(TextureID, Obj.X, Obj.Y, 0, True, False);
2239 end;
2241 if g_debug_Frames then
2242 begin
2243 e_DrawQuad(Obj.X+Obj.Rect.X,
2244 Obj.Y+Obj.Rect.Y,
2245 Obj.X+Obj.Rect.X+Obj.Rect.Width-1,
2246 Obj.Y+Obj.Rect.Y+Obj.Rect.Height-1,
2247 0, 255, 0);
2248 end;
2249 end;
2250 end;
2252 function g_Weapon_Danger(UID: Word; X, Y: Integer; Width, Height: Word; Time: Byte): Boolean;
2253 var
2254 a: Integer;
2255 begin
2256 Result := False;
2258 if Shots = nil then
2259 Exit;
2261 for a := 0 to High(Shots) do
2262 if (Shots[a].ShotType <> 0) and (Shots[a].SpawnerUID <> UID) then
2263 if ((Shots[a].Obj.Vel.Y = 0) and (Shots[a].Obj.Vel.X > 0) and (Shots[a].Obj.X < X)) or
2264 (Shots[a].Obj.Vel.Y = 0) and (Shots[a].Obj.Vel.X < 0) and (Shots[a].Obj.X > X) then
2265 if (Abs(X-Shots[a].Obj.X) < Abs(Shots[a].Obj.Vel.X*Time)) and
2266 g_Collide(X, Y, Width, Height, X, Shots[a].Obj.Y,
2267 Shots[a].Obj.Rect.Width, Shots[a].Obj.Rect.Height) and
2268 g_TraceVector(X, Y, Shots[a].Obj.X, Shots[a].Obj.Y) then
2269 begin
2270 Result := True;
2271 Exit;
2272 end;
2273 end;
2275 procedure g_Weapon_SaveState(var Mem: TBinMemoryWriter);
2276 var
2277 count, i, j: Integer;
2278 dw: DWORD;
2279 begin
2280 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ ñíàðÿäîâ:
2281 count := 0;
2282 if Shots <> nil then
2283 for i := 0 to High(Shots) do
2284 if Shots[i].ShotType <> 0 then
2285 count := count + 1;
2287 Mem := TBinMemoryWriter.Create((count+1) * 80);
2289 // Êîëè÷åñòâî ñíàðÿäîâ:
2290 Mem.WriteInt(count);
2292 if count = 0 then
2293 Exit;
2295 for i := 0 to High(Shots) do
2296 if Shots[i].ShotType <> 0 then
2297 begin
2298 // Ñèãíàòóðà ñíàðÿäà:
2299 dw := SHOT_SIGNATURE; // 'SHOT'
2300 Mem.WriteDWORD(dw);
2301 // Òèï ñíàðÿäà:
2302 Mem.WriteByte(Shots[i].ShotType);
2303 // Öåëü:
2304 Mem.WriteWord(Shots[i].Target);
2305 // UID ñòðåëÿâøåãî:
2306 Mem.WriteWord(Shots[i].SpawnerUID);
2307 // Ðàçìåð ïîëÿ Triggers:
2308 dw := Length(Shots[i].Triggers);
2309 Mem.WriteDWORD(dw);
2310 // Òðèããåðû, àêòèâèðîâàííûå âûñòðåëîì:
2311 for j := 0 to Integer(dw)-1 do
2312 Mem.WriteDWORD(Shots[i].Triggers[j]);
2313 // Îáúåêò ñíàðÿäà:
2314 Obj_SaveState(@Shots[i].Obj, Mem);
2315 // Êîñòûëèíà åáàíàÿ:
2316 Mem.WriteByte(Shots[i].Stopped);
2317 end;
2318 end;
2320 procedure g_Weapon_LoadState(var Mem: TBinMemoryReader);
2321 var
2322 count, i, j: Integer;
2323 dw: DWORD;
2324 begin
2325 if Mem = nil then
2326 Exit;
2328 // Êîëè÷åñòâî ñíàðÿäîâ:
2329 Mem.ReadInt(count);
2331 SetLength(Shots, count);
2333 if count = 0 then
2334 Exit;
2336 for i := 0 to count-1 do
2337 begin
2338 // Ñèãíàòóðà ñíàðÿäà:
2339 Mem.ReadDWORD(dw);
2340 if dw <> SHOT_SIGNATURE then // 'SHOT'
2341 begin
2342 raise EBinSizeError.Create('g_Weapons_LoadState: Wrong Shot Signature');
2343 end;
2344 // Òèï ñíàðÿäà:
2345 Mem.ReadByte(Shots[i].ShotType);
2346 // Öåëü:
2347 Mem.ReadWord(Shots[i].Target);
2348 // UID ñòðåëÿâøåãî:
2349 Mem.ReadWord(Shots[i].SpawnerUID);
2350 // Ðàçìåð ïîëÿ Triggers:
2351 Mem.ReadDWORD(dw);
2352 SetLength(Shots[i].Triggers, dw);
2353 // Òðèããåðû, àêòèâèðîâàííûå âûñòðåëîì:
2354 for j := 0 to Integer(dw)-1 do
2355 Mem.ReadDWORD(Shots[i].Triggers[j]);
2356 // Îáúåêò ïðåäìåòà:
2357 Obj_LoadState(@Shots[i].Obj, Mem);
2358 // Êîñòûëèíà åáàíàÿ:
2359 Mem.ReadByte(Shots[i].Stopped);
2361 // Óñòàíîâêà òåêñòóðû èëè àíèìàöèè:
2362 Shots[i].TextureID := DWORD(-1);
2363 Shots[i].Animation := nil;
2365 case Shots[i].ShotType of
2366 WEAPON_ROCKETLAUNCHER, WEAPON_SKEL_FIRE:
2367 begin
2368 g_Texture_Get('TEXTURE_WEAPON_ROCKET', Shots[i].TextureID);
2369 end;
2370 WEAPON_PLASMA:
2371 begin
2372 g_Frames_Get(dw, 'FRAMES_WEAPON_PLASMA');
2373 Shots[i].Animation := TAnimation.Create(dw, True, 5);
2374 end;
2375 WEAPON_BFG:
2376 begin
2377 g_Frames_Get(dw, 'FRAMES_WEAPON_BFG');
2378 Shots[i].Animation := TAnimation.Create(dw, True, 6);
2379 end;
2380 WEAPON_IMP_FIRE:
2381 begin
2382 g_Frames_Get(dw, 'FRAMES_WEAPON_IMPFIRE');
2383 Shots[i].Animation := TAnimation.Create(dw, True, 4);
2384 end;
2385 WEAPON_BSP_FIRE:
2386 begin
2387 g_Frames_Get(dw, 'FRAMES_WEAPON_BSPFIRE');
2388 Shots[i].Animation := TAnimation.Create(dw, True, 4);
2389 end;
2390 WEAPON_CACO_FIRE:
2391 begin
2392 g_Frames_Get(dw, 'FRAMES_WEAPON_CACOFIRE');
2393 Shots[i].Animation := TAnimation.Create(dw, True, 4);
2394 end;
2395 WEAPON_BARON_FIRE:
2396 begin
2397 g_Frames_Get(dw, 'FRAMES_WEAPON_BARONFIRE');
2398 Shots[i].Animation := TAnimation.Create(dw, True, 4);
2399 end;
2400 WEAPON_MANCUB_FIRE:
2401 begin
2402 g_Frames_Get(dw, 'FRAMES_WEAPON_MANCUBFIRE');
2403 Shots[i].Animation := TAnimation.Create(dw, True, 4);
2404 end;
2405 end;
2406 end;
2407 end;
2409 procedure g_Weapon_DestroyShot(I: Integer; X, Y: Integer; Loud: Boolean = True);
2410 var
2411 cx, cy: Integer;
2412 Anim: TAnimation;
2413 s: string;
2414 begin
2415 if Shots = nil then
2416 Exit;
2417 if (I > High(Shots)) or (I < 0) then Exit;
2419 with Shots[I] do
2420 begin
2421 if ShotType = 0 then Exit;
2422 Obj.X := X;
2423 Obj.Y := Y;
2424 cx := Obj.X + (Obj.Rect.Width div 2);
2425 cy := Obj.Y + (Obj.Rect.Height div 2);
2427 case ShotType of
2428 WEAPON_ROCKETLAUNCHER, WEAPON_SKEL_FIRE: // Ðàêåòû è ñíàðÿäû Ñêåëåòà
2429 begin
2430 if Loud then
2431 begin
2432 if ShotType = WEAPON_SKEL_FIRE then
2433 begin // Âçðûâ ñíàðÿäà Ñêåëåòà
2434 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_SKELFIRE') then
2435 begin
2436 Anim := TAnimation.Create(TextureID, False, 8);
2437 Anim.Blending := False;
2438 g_GFX_OnceAnim((Obj.X+32)-32, (Obj.Y+8)-32, Anim);
2439 Anim.Free();
2440 end;
2441 end
2442 else
2443 begin // Âçðûâ Ðàêåòû
2444 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_ROCKET') then
2445 begin
2446 Anim := TAnimation.Create(TextureID, False, 6);
2447 Anim.Blending := False;
2448 g_GFX_OnceAnim(cx-64, cy-64, Anim);
2449 Anim.Free();
2450 end;
2451 end;
2452 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', Obj.X, Obj.Y);
2453 end;
2454 end;
2456 WEAPON_PLASMA, WEAPON_BSP_FIRE: // Ïëàçìà, ïëàçìà Àðàõíàòðîíà
2457 begin
2458 if ShotType = WEAPON_PLASMA then
2459 s := 'FRAMES_EXPLODE_PLASMA'
2460 else
2461 s := 'FRAMES_EXPLODE_BSPFIRE';
2463 if g_Frames_Get(TextureID, s) and loud then
2464 begin
2465 Anim := TAnimation.Create(TextureID, False, 3);
2466 Anim.Blending := False;
2467 g_GFX_OnceAnim(cx-16, cy-16, Anim);
2468 Anim.Free();
2470 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEPLASMA', Obj.X, Obj.Y);
2471 end;
2472 end;
2474 WEAPON_BFG: // BFG
2475 begin
2476 // Âçðûâ BFG:
2477 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_BFG') and Loud then
2478 begin
2479 Anim := TAnimation.Create(TextureID, False, 6);
2480 Anim.Blending := False;
2481 g_GFX_OnceAnim(cx-64, cy-64, Anim);
2482 Anim.Free();
2484 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', Obj.X, Obj.Y);
2485 end;
2486 end;
2488 WEAPON_IMP_FIRE, WEAPON_CACO_FIRE, WEAPON_BARON_FIRE: // Âûñòðåëû Áåñà, Êàêîäåìîíà Ðûöàðÿ/Áàðîíà àäà
2489 begin
2490 if ShotType = WEAPON_IMP_FIRE then
2491 s := 'FRAMES_EXPLODE_IMPFIRE'
2492 else
2493 if ShotType = WEAPON_CACO_FIRE then
2494 s := 'FRAMES_EXPLODE_CACOFIRE'
2495 else
2496 s := 'FRAMES_EXPLODE_BARONFIRE';
2498 if g_Frames_Get(TextureID, s) and Loud then
2499 begin
2500 Anim := TAnimation.Create(TextureID, False, 6);
2501 Anim.Blending := False;
2502 g_GFX_OnceAnim(cx-32, cy-32, Anim);
2503 Anim.Free();
2505 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj.X, Obj.Y);
2506 end;
2507 end;
2509 WEAPON_MANCUB_FIRE: // Âûñòðåë Ìàíêóáóñà
2510 begin
2511 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_ROCKET') and Loud then
2512 begin
2513 Anim := TAnimation.Create(TextureID, False, 6);
2514 Anim.Blending := False;
2515 g_GFX_OnceAnim(cx-64, cy-64, Anim);
2516 Anim.Free();
2518 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj.X, Obj.Y);
2519 end;
2520 end;
2521 end; // case ShotType of...
2523 ShotType := 0;
2524 Animation.Free();
2525 end;
2526 end;
2529 procedure g_Weapon_AddDynLights();
2530 var
2531 i: Integer;
2532 begin
2533 if Shots = nil then Exit;
2534 for i := 0 to High(Shots) do
2535 begin
2536 if Shots[i].ShotType = 0 then continue;
2537 if (Shots[i].ShotType = WEAPON_ROCKETLAUNCHER) or
2538 (Shots[i].ShotType = WEAPON_BARON_FIRE) or
2539 (Shots[i].ShotType = WEAPON_MANCUB_FIRE) or
2540 (Shots[i].ShotType = WEAPON_SKEL_FIRE) or
2541 (Shots[i].ShotType = WEAPON_IMP_FIRE) or
2542 (Shots[i].ShotType = WEAPON_CACO_FIRE) or
2543 (Shots[i].ShotType = WEAPON_MANCUB_FIRE) or
2544 (Shots[i].ShotType = WEAPON_BSP_FIRE) or
2545 (Shots[i].ShotType = WEAPON_PLASMA) or
2546 (Shots[i].ShotType = WEAPON_BFG) or
2547 (Shots[i].ShotType = WEAPON_FLAMETHROWER) or
2548 false then
2549 begin
2550 if (Shots[i].ShotType = WEAPON_PLASMA) then
2551 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)
2552 else if (Shots[i].ShotType = WEAPON_BFG) then
2553 g_AddDynLight(Shots[i].Obj.X+(Shots[i].Obj.Rect.Width div 2), Shots[i].Obj.Y+(Shots[i].Obj.Rect.Height div 2), 128, 0, 1, 0, 0.5)
2554 else if (Shots[i].ShotType = WEAPON_FLAMETHROWER) then
2555 g_AddDynLight(Shots[i].Obj.X+(Shots[i].Obj.Rect.Width div 2), Shots[i].Obj.Y+(Shots[i].Obj.Rect.Height div 2), 42, 1, 0.8, 0, 0.4)
2556 else
2557 g_AddDynLight(Shots[i].Obj.X+(Shots[i].Obj.Rect.Width div 2), Shots[i].Obj.Y+(Shots[i].Obj.Rect.Height div 2), 128, 1, 0, 0, 0.4);
2558 end;
2559 end;
2560 end;
2563 procedure TShot.positionChanged (); begin end;
2566 end.