DEADSOFTWARE

faster `g_weapons.CheckTrap()`
[d2df-sdl.git] / src / game / g_weapons.pas
1 (* Copyright (C) DooM 2D:Forever Developers
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *)
16 {$INCLUDE ../shared/a_modes.inc}
17 unit g_weapons;
19 interface
21 uses
22 g_textures, g_basic, e_graphics, g_phys, BinEditor;
24 const
25 HIT_SOME = 0;
26 HIT_ROCKET = 1;
27 HIT_BFG = 2;
28 HIT_TRAP = 3;
29 HIT_FALL = 4;
30 HIT_WATER = 5;
31 HIT_ACID = 6;
32 HIT_ELECTRO = 7;
33 HIT_FLAME = 8;
34 HIT_SELF = 9;
35 HIT_DISCON = 10;
37 type
38 TShot = record
39 ShotType: Byte;
40 Target: Word;
41 SpawnerUID: Word;
42 Triggers: DWArray;
43 Obj: TObj;
44 Animation: TAnimation;
45 TextureID: DWORD;
46 Timeout: DWORD;
47 Stopped: Byte;
49 procedure positionChanged (); //WARNING! call this after monster position was changed, or coldet will not work right!
50 end;
53 var
54 Shots: array of TShot = nil;
55 LastShotID: Integer = 0;
57 procedure g_Weapon_LoadData();
58 procedure g_Weapon_FreeData();
59 procedure g_Weapon_Init();
60 procedure g_Weapon_Free();
61 function g_Weapon_Hit(obj: PObj; d: Integer; SpawnerUID: Word; t: Byte; HitCorpses: Boolean = True): Byte;
62 function g_Weapon_HitUID(UID: Word; d: Integer; SpawnerUID: Word; t: Byte): Boolean;
63 function g_Weapon_CreateShot(I: Integer; ShotType: Byte; Spawner, TargetUID: Word; X, Y, XV, YV: Integer): LongWord;
65 procedure g_Weapon_gun(x, y, xd, yd, v, dmg: Integer; SpawnerUID: Word; CheckTrigger: Boolean);
66 procedure g_Weapon_punch(x, y: Integer; d, SpawnerUID: Word);
67 function g_Weapon_chainsaw(x, y: Integer; d, SpawnerUID: Word): Integer;
68 procedure g_Weapon_rocket(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1; Silent: Boolean = False);
69 procedure g_Weapon_revf(x, y, xd, yd: Integer; SpawnerUID, TargetUID: Word; WID: Integer = -1; Silent: Boolean = False);
70 procedure g_Weapon_flame(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1; Silent: Boolean = False);
71 procedure g_Weapon_plasma(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1; Silent: Boolean = False);
72 procedure g_Weapon_ball1(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1; Silent: Boolean = False);
73 procedure g_Weapon_ball2(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1; Silent: Boolean = False);
74 procedure g_Weapon_ball7(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1; Silent: Boolean = False);
75 procedure g_Weapon_aplasma(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1; Silent: Boolean = False);
76 procedure g_Weapon_manfire(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1; Silent: Boolean = False);
77 procedure g_Weapon_bfgshot(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1; Silent: Boolean = False);
78 procedure g_Weapon_bfghit(x, y: Integer);
79 procedure g_Weapon_pistol(x, y, xd, yd: Integer; SpawnerUID: Word; Silent: Boolean = False);
80 procedure g_Weapon_mgun(x, y, xd, yd: Integer; SpawnerUID: Word; Silent: Boolean = False);
81 procedure g_Weapon_shotgun(x, y, xd, yd: Integer; SpawnerUID: Word; Silent: Boolean = False);
82 procedure g_Weapon_dshotgun(x, y, xd, yd: Integer; SpawnerUID: Word; Silent: Boolean = False);
84 function g_Weapon_Explode(X, Y: Integer; rad: Integer; SpawnerUID: Word): Boolean;
85 procedure g_Weapon_BFG9000(X, Y: Integer; SpawnerUID: Word);
86 procedure g_Weapon_Update();
87 procedure g_Weapon_Draw();
88 function g_Weapon_Danger(UID: Word; X, Y: Integer; Width, Height: Word; Time: Byte): Boolean;
89 procedure g_Weapon_DestroyShot(I: Integer; X, Y: Integer; Loud: Boolean = True);
91 procedure g_Weapon_SaveState(var Mem: TBinMemoryWriter);
92 procedure g_Weapon_LoadState(var Mem: TBinMemoryReader);
94 procedure g_Weapon_AddDynLights();
96 const
97 WEAPON_KASTET = 0;
98 WEAPON_SAW = 1;
99 WEAPON_PISTOL = 2;
100 WEAPON_SHOTGUN1 = 3;
101 WEAPON_SHOTGUN2 = 4;
102 WEAPON_CHAINGUN = 5;
103 WEAPON_ROCKETLAUNCHER = 6;
104 WEAPON_PLASMA = 7;
105 WEAPON_BFG = 8;
106 WEAPON_SUPERPULEMET = 9;
107 WEAPON_FLAMETHROWER = 10;
108 WEAPON_ZOMBY_PISTOL = 20;
109 WEAPON_IMP_FIRE = 21;
110 WEAPON_BSP_FIRE = 22;
111 WEAPON_CACO_FIRE = 23;
112 WEAPON_BARON_FIRE = 24;
113 WEAPON_MANCUB_FIRE = 25;
114 WEAPON_SKEL_FIRE = 26;
116 WP_FIRST = WEAPON_KASTET;
117 WP_LAST = WEAPON_FLAMETHROWER;
119 implementation
121 uses
122 Math, g_map, g_player, g_gfx, g_sound, g_main, g_panel,
123 g_console, SysUtils, g_options, g_game,
124 g_triggers, MAPDEF, e_log, g_monsters, g_saveload,
125 g_language, g_netmsg;
127 type
128 TWaterPanel = record
129 X, Y: Integer;
130 Width, Height: Word;
131 Active: Boolean;
132 end;
134 const
135 SHOT_ROCKETLAUNCHER_WIDTH = 14;
136 SHOT_ROCKETLAUNCHER_HEIGHT = 14;
138 SHOT_SKELFIRE_WIDTH = 14;
139 SHOT_SKELFIRE_HEIGHT = 14;
141 SHOT_PLASMA_WIDTH = 16;
142 SHOT_PLASMA_HEIGHT = 16;
144 SHOT_BFG_WIDTH = 32;
145 SHOT_BFG_HEIGHT = 32;
146 SHOT_BFG_DAMAGE = 100;
147 SHOT_BFG_RADIUS = 256;
149 SHOT_FLAME_WIDTH = 4;
150 SHOT_FLAME_HEIGHT = 4;
151 SHOT_FLAME_LIFETIME = 180;
153 SHOT_SIGNATURE = $544F4853; // 'SHOT'
155 var
156 WaterMap: array of array of DWORD = nil;
158 function FindShot(): DWORD;
159 var
160 i: Integer;
161 begin
162 if Shots <> nil then
163 for i := 0 to High(Shots) do
164 if Shots[i].ShotType = 0 then
165 begin
166 Result := i;
167 LastShotID := Result;
168 Exit;
169 end;
171 if Shots = nil then
172 begin
173 SetLength(Shots, 128);
174 Result := 0;
175 end
176 else
177 begin
178 Result := High(Shots) + 1;
179 SetLength(Shots, Length(Shots) + 128);
180 end;
181 LastShotID := Result;
182 end;
184 procedure CreateWaterMap();
185 var
186 WaterArray: Array of TWaterPanel;
187 a, b, c, m: Integer;
188 ok: Boolean;
189 begin
190 if gWater = nil then
191 Exit;
193 SetLength(WaterArray, Length(gWater));
195 for a := 0 to High(gWater) do
196 begin
197 WaterArray[a].X := gWater[a].X;
198 WaterArray[a].Y := gWater[a].Y;
199 WaterArray[a].Width := gWater[a].Width;
200 WaterArray[a].Height := gWater[a].Height;
201 WaterArray[a].Active := True;
202 end;
204 g_Game_SetLoadingText(_lc[I_LOAD_WATER_MAP], High(WaterArray), False);
206 for a := 0 to High(WaterArray) do
207 if WaterArray[a].Active then
208 begin
209 WaterArray[a].Active := False;
210 m := Length(WaterMap);
211 SetLength(WaterMap, m+1);
212 SetLength(WaterMap[m], 1);
213 WaterMap[m][0] := a;
214 ok := True;
216 while ok do
217 begin
218 ok := False;
219 for b := 0 to High(WaterArray) do
220 if WaterArray[b].Active then
221 for c := 0 to High(WaterMap[m]) do
222 if g_CollideAround(WaterArray[b].X,
223 WaterArray[b].Y,
224 WaterArray[b].Width,
225 WaterArray[b].Height,
226 WaterArray[WaterMap[m][c]].X,
227 WaterArray[WaterMap[m][c]].Y,
228 WaterArray[WaterMap[m][c]].Width,
229 WaterArray[WaterMap[m][c]].Height) then
230 begin
231 WaterArray[b].Active := False;
232 SetLength(WaterMap[m],
233 Length(WaterMap[m])+1);
234 WaterMap[m][High(WaterMap[m])] := b;
235 ok := True;
236 Break;
237 end;
238 end;
240 g_Game_StepLoading();
241 end;
243 WaterArray := nil;
244 end;
247 var
248 chkTrap_pl: array [0..256] of Integer;
249 chkTrap_mn: array [0..65535] of TMonster;
251 procedure CheckTrap(ID: DWORD; dm: Integer; t: Byte);
252 var
253 //a, b, c, d, i1, i2: Integer;
254 //chkTrap_pl, chkTrap_mn: WArray;
255 plaCount: Integer = 0;
256 mnaCount: Integer = 0;
257 frameId: DWord;
260 function monsWaterCheck (monidx: Integer; mon: TMonster): Boolean;
261 begin
262 result := false; // don't stop
263 if mon.Live and mon.Collide(gWater[WaterMap[a][c]]) and (not InWArray(monidx, chkTrap_mn)) and (i2 < 1023) then //FIXME
264 begin
265 i2 += 1;
266 chkTrap_mn[i2] := monidx;
267 end;
268 end;
271 function monsWaterCheck (monidx: Integer; mon: TMonster): Boolean;
272 begin
273 result := false; // don't stop
274 if (mon.trapCheckFrameId <> frameId) then
275 begin
276 mon.trapCheckFrameId := frameId;
277 chkTrap_mn[mnaCount] := mon;
278 Inc(mnaCount);
279 end;
280 end;
282 var
283 a, b, c, d, f: Integer;
284 pan: TPanel;
285 begin
286 if (gWater = nil) or (WaterMap = nil) then Exit;
288 frameId := g_Mons_getNewTrapFrameId();
290 //i1 := -1;
291 //i2 := -1;
293 //SetLength(chkTrap_pl, 1024);
294 //SetLength(chkTrap_mn, 1024);
295 //for d := 0 to 1023 do chkTrap_pl[d] := $FFFF;
296 //for d := 0 to 1023 do chkTrap_mn[d] := $FFFF;
298 for a := 0 to High(WaterMap) do
299 begin
300 for b := 0 to High(WaterMap[a]) do
301 begin
302 pan := gWater[WaterMap[a][b]];
303 if not g_Obj_Collide(pan.X, pan.Y, pan.Width, pan.Height, @Shots[ID].Obj) then continue;
305 for c := 0 to High(WaterMap[a]) do
306 begin
307 pan := gWater[WaterMap[a][c]];
308 for d := 0 to High(gPlayers) do
309 begin
310 if (gPlayers[d] <> nil) and (gPlayers[d].Live) then
311 begin
312 if gPlayers[d].Collide(pan) then
313 begin
314 f := 0;
315 while (f < plaCount) and (chkTrap_pl[f] <> d) do Inc(f);
316 if (f = plaCount) then
317 begin
318 chkTrap_pl[plaCount] := d;
319 Inc(plaCount);
320 if (plaCount = Length(chkTrap_pl)) then break;
321 end;
322 end;
323 end;
324 end;
326 //g_Mons_ForEach(monsWaterCheck);
327 g_Mons_ForEachAtAlive(pan.X, pan.Y, pan.Width, pan.Height, monsWaterCheck);
328 end;
330 for f := 0 to plaCount-1 do gPlayers[chkTrap_pl[f]].Damage(dm, Shots[ID].SpawnerUID, 0, 0, t);
331 for f := 0 to mnaCount-1 do chkTrap_mn[f].Damage(dm, 0, 0, Shots[ID].SpawnerUID, t);
332 end;
333 end;
335 //chkTrap_pl := nil;
336 //chkTrap_mn := nil;
337 end;
339 function HitMonster(m: TMonster; d: Integer; vx, vy: Integer; SpawnerUID: Word; t: Byte): Boolean;
340 var
341 tt, mt: Byte;
342 mon: TMonster;
343 begin
344 Result := False;
346 tt := g_GetUIDType(SpawnerUID);
347 if tt = UID_MONSTER then
348 begin
349 mon := g_Monsters_ByUID(SpawnerUID);
350 if mon <> nil then
351 mt := g_Monsters_ByUID(SpawnerUID).MonsterType
352 else
353 mt := 0;
354 end
355 else
356 mt := 0;
358 if m = nil then Exit;
359 if m.UID = SpawnerUID then
360 begin
361 // Ñàì ñåáÿ ìîæåò ðàíèòü òîëüêî ðàêåòîé è òîêîì:
362 if (t <> HIT_ROCKET) and (t <> HIT_ELECTRO) then
363 Exit;
364 // Êèáåð äåìîí è áî÷êà âîîáùå íå ìîãóò ñåáÿ ðàíèòü:
365 if (m.MonsterType = MONSTER_CYBER) or
366 (m.MonsterType = MONSTER_BARREL) then
367 begin
368 Result := True;
369 Exit;
370 end;
371 end;
373 if tt = UID_MONSTER then
374 begin
375 // Lost_Soul íå ìîæåò ðàíèòü Pain_Elemental'à:
376 if (mt = MONSTER_SOUL) and (m.MonsterType = MONSTER_PAIN) then
377 Exit;
379 // Îáà ìîíñòðà îäíîãî âèäà:
380 if mt = m.MonsterType then
381 case mt of
382 MONSTER_IMP, MONSTER_DEMON, MONSTER_BARON, MONSTER_KNIGHT, MONSTER_CACO,
383 MONSTER_SOUL, MONSTER_MANCUB, MONSTER_SKEL, MONSTER_FISH:
384 Exit; // Ýòè íå áüþò ñâîèõ
385 end;
386 end;
388 if g_Game_IsServer then
389 begin
390 if (t <> HIT_FLAME) or (m.FFireTime = 0) or (vx <> 0) or (vy <> 0) then
391 Result := m.Damage(d, vx, vy, SpawnerUID, t)
392 else
393 Result := True;
394 if t = HIT_FLAME then
395 m.CatchFire(SpawnerUID);
396 end
397 else
398 Result := True;
399 end;
401 function HitPlayer(p: TPlayer; d: Integer; vx, vy: Integer; SpawnerUID: Word; t: Byte): Boolean;
402 begin
403 Result := False;
405 // Ñàì ñåáÿ ìîæåò ðàíèòü òîëüêî ðàêåòîé è òîêîì:
406 if (p.UID = SpawnerUID) and (t <> HIT_ROCKET) and (t <> HIT_ELECTRO) then
407 Exit;
409 if g_Game_IsServer then
410 begin
411 if (t <> HIT_FLAME) or (p.FFireTime = 0) or (vx <> 0) or (vy <> 0) then
412 p.Damage(d, SpawnerUID, vx, vy, t);
413 if (t = HIT_FLAME) then
414 p.CatchFire(SpawnerUID);
415 end;
417 Result := True;
418 end;
420 function GunHit(X, Y: Integer; vx, vy: Integer; dmg: Integer;
421 SpawnerUID: Word; AllowPush: Boolean): Byte;
423 {function monsCheck (monidx: Integer; mon: TMonster): Boolean;
424 begin
425 result := false; // don't stop
426 if mon.Live and mon.Collide(X, Y) then
427 begin
428 if HitMonster(mon, dmg, vx*10, vy*10-3, SpawnerUID, HIT_SOME) then
429 begin
430 if AllowPush then mon.Push(vx, vy);
431 result := true;
432 end;
433 end;
434 end;}
436 function monsCheck (monidx: Integer; mon: TMonster): Boolean;
437 begin
438 result := false; // don't stop
439 if HitMonster(mon, dmg, vx*10, vy*10-3, SpawnerUID, HIT_SOME) then
440 begin
441 if AllowPush then mon.Push(vx, vy);
442 result := true;
443 end;
444 end;
446 var
447 i, h: Integer;
448 begin
449 Result := 0;
451 h := High(gPlayers);
453 if h <> -1 then
454 for i := 0 to h do
455 if (gPlayers[i] <> nil) and gPlayers[i].Live and gPlayers[i].Collide(X, Y) then
456 if HitPlayer(gPlayers[i], dmg, vx*10, vy*10-3, SpawnerUID, HIT_SOME) then
457 begin
458 if AllowPush then gPlayers[i].Push(vx, vy);
459 Result := 1;
460 end;
462 if Result <> 0 then Exit;
464 //if g_Mons_ForEach(monsCheck) then result := 2;
465 if g_Mons_ForEachAtAlive(X, Y, 1, 1, monsCheck) then result := 2;
466 end;
468 procedure g_Weapon_BFG9000(X, Y: Integer; SpawnerUID: Word);
470 function monsCheck (monidx: Integer; mon: TMonster): Boolean;
471 begin
472 result := false; // don't stop
473 if (mon <> nil) and (mon.Live) and (mon.UID <> SpawnerUID) then
474 begin
475 with mon do
476 begin
477 if (g_PatchLength(X, Y, Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2),
478 Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)) <= SHOT_BFG_RADIUS) and
479 g_TraceVector(X, Y, Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2),
480 Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)) then
481 begin
482 if HitMonster(mon, 50, 0, 0, SpawnerUID, HIT_SOME) then mon.BFGHit();
483 end;
484 end;
485 end;
486 end;
488 var
489 i, h: Integer;
490 st: Byte;
491 pl: TPlayer;
492 b: Boolean;
493 begin
494 //g_Sound_PlayEx('SOUND_WEAPON_EXPLODEBFG', 255);
496 h := High(gCorpses);
498 if gAdvCorpses and (h <> -1) then
499 for i := 0 to h do
500 if (gCorpses[i] <> nil) and (gCorpses[i].State <> CORPSE_STATE_REMOVEME) then
501 with gCorpses[i] do
502 if (g_PatchLength(X, Y, Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2),
503 Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)) <= SHOT_BFG_RADIUS) and
504 g_TraceVector(X, Y, Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2),
505 Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)) then
506 begin
507 Damage(50, 0, 0);
508 g_Weapon_BFGHit(Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2),
509 Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2));
510 end;
512 st := TEAM_NONE;
513 pl := g_Player_Get(SpawnerUID);
514 if pl <> nil then
515 st := pl.Team;
517 h := High(gPlayers);
519 if h <> -1 then
520 for i := 0 to h do
521 if (gPlayers[i] <> nil) and (gPlayers[i].Live) and (gPlayers[i].UID <> SpawnerUID) then
522 with gPlayers[i] do
523 if (g_PatchLength(X, Y, GameX+PLAYER_RECT.X+(PLAYER_RECT.Width div 2),
524 GameY+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)) <= SHOT_BFG_RADIUS) and
525 g_TraceVector(X, Y, GameX+PLAYER_RECT.X+(PLAYER_RECT.Width div 2),
526 GameY+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)) then
527 begin
528 if (st = TEAM_NONE) or (st <> gPlayers[i].Team) then
529 b := HitPlayer(gPlayers[i], 50, 0, 0, SpawnerUID, HIT_SOME)
530 else
531 b := HitPlayer(gPlayers[i], 25, 0, 0, SpawnerUID, HIT_SOME);
532 if b then
533 gPlayers[i].BFGHit();
534 end;
536 g_Mons_ForEach(monsCheck);
537 end;
539 function g_Weapon_CreateShot(I: Integer; ShotType: Byte; Spawner, TargetUID: Word; X, Y, XV, YV: Integer): LongWord;
540 var
541 find_id, FramesID: DWORD;
542 begin
543 if I < 0 then
544 find_id := FindShot()
545 else
546 begin
547 find_id := I;
548 if Integer(find_id) >= High(Shots) then
549 SetLength(Shots, find_id + 64)
550 end;
552 case ShotType of
553 WEAPON_ROCKETLAUNCHER:
554 begin
555 with Shots[find_id] do
556 begin
557 g_Obj_Init(@Obj);
559 Obj.Rect.Width := SHOT_ROCKETLAUNCHER_WIDTH;
560 Obj.Rect.Height := SHOT_ROCKETLAUNCHER_HEIGHT;
562 Animation := nil;
563 Triggers := nil;
564 ShotType := WEAPON_ROCKETLAUNCHER;
565 g_Texture_Get('TEXTURE_WEAPON_ROCKET', TextureID);
566 end;
567 end;
569 WEAPON_PLASMA:
570 begin
571 with Shots[find_id] do
572 begin
573 g_Obj_Init(@Obj);
575 Obj.Rect.Width := SHOT_PLASMA_WIDTH;
576 Obj.Rect.Height := SHOT_PLASMA_HEIGHT;
578 Triggers := nil;
579 ShotType := WEAPON_PLASMA;
580 g_Frames_Get(FramesID, 'FRAMES_WEAPON_PLASMA');
581 Animation := TAnimation.Create(FramesID, True, 5);
582 end;
583 end;
585 WEAPON_BFG:
586 begin
587 with Shots[find_id] do
588 begin
589 g_Obj_Init(@Obj);
591 Obj.Rect.Width := SHOT_BFG_WIDTH;
592 Obj.Rect.Height := SHOT_BFG_HEIGHT;
594 Triggers := nil;
595 ShotType := WEAPON_BFG;
596 g_Frames_Get(FramesID, 'FRAMES_WEAPON_BFG');
597 Animation := TAnimation.Create(FramesID, True, 6);
598 end;
599 end;
601 WEAPON_FLAMETHROWER:
602 begin
603 with Shots[find_id] do
604 begin
605 g_Obj_Init(@Obj);
607 Obj.Rect.Width := SHOT_FLAME_WIDTH;
608 Obj.Rect.Height := SHOT_FLAME_HEIGHT;
610 Triggers := nil;
611 ShotType := WEAPON_FLAMETHROWER;
612 Animation := nil;
613 TextureID := 0;
614 g_Frames_Get(TextureID, 'FRAMES_FLAME');
615 end;
616 end;
618 WEAPON_IMP_FIRE:
619 begin
620 with Shots[find_id] do
621 begin
622 g_Obj_Init(@Obj);
624 Obj.Rect.Width := 16;
625 Obj.Rect.Height := 16;
627 Triggers := nil;
628 ShotType := WEAPON_IMP_FIRE;
629 g_Frames_Get(FramesID, 'FRAMES_WEAPON_IMPFIRE');
630 Animation := TAnimation.Create(FramesID, True, 4);
631 end;
632 end;
634 WEAPON_CACO_FIRE:
635 begin
636 with Shots[find_id] do
637 begin
638 g_Obj_Init(@Obj);
640 Obj.Rect.Width := 16;
641 Obj.Rect.Height := 16;
643 Triggers := nil;
644 ShotType := WEAPON_CACO_FIRE;
645 g_Frames_Get(FramesID, 'FRAMES_WEAPON_CACOFIRE');
646 Animation := TAnimation.Create(FramesID, True, 4);
647 end;
648 end;
650 WEAPON_MANCUB_FIRE:
651 begin
652 with Shots[find_id] do
653 begin
654 g_Obj_Init(@Obj);
656 Obj.Rect.Width := 32;
657 Obj.Rect.Height := 32;
659 Triggers := nil;
660 ShotType := WEAPON_MANCUB_FIRE;
661 g_Frames_Get(FramesID, 'FRAMES_WEAPON_MANCUBFIRE');
662 Animation := TAnimation.Create(FramesID, True, 4);
663 end;
664 end;
666 WEAPON_BARON_FIRE:
667 begin
668 with Shots[find_id] do
669 begin
670 g_Obj_Init(@Obj);
672 Obj.Rect.Width := 32;
673 Obj.Rect.Height := 16;
675 Triggers := nil;
676 ShotType := WEAPON_BARON_FIRE;
677 g_Frames_Get(FramesID, 'FRAMES_WEAPON_BARONFIRE');
678 Animation := TAnimation.Create(FramesID, True, 4);
679 end;
680 end;
682 WEAPON_BSP_FIRE:
683 begin
684 with Shots[find_id] do
685 begin
686 g_Obj_Init(@Obj);
688 Obj.Rect.Width := 16;
689 Obj.Rect.Height := 16;
691 Triggers := nil;
692 ShotType := WEAPON_BSP_FIRE;
693 g_Frames_Get(FramesID, 'FRAMES_WEAPON_BSPFIRE');
694 Animation := TAnimation.Create(FramesID, True, 4);
695 end;
696 end;
698 WEAPON_SKEL_FIRE:
699 begin
700 with Shots[find_id] do
701 begin
702 g_Obj_Init(@Obj);
704 Obj.Rect.Width := SHOT_SKELFIRE_WIDTH;
705 Obj.Rect.Height := SHOT_SKELFIRE_HEIGHT;
707 Triggers := nil;
708 ShotType := WEAPON_SKEL_FIRE;
709 target := TargetUID;
710 g_Frames_Get(FramesID, 'FRAMES_WEAPON_SKELFIRE');
711 Animation := TAnimation.Create(FramesID, True, 5);
712 end;
713 end;
714 end;
716 Shots[find_id].Obj.X := X;
717 Shots[find_id].Obj.Y := Y;
718 Shots[find_id].Obj.Vel.X := XV;
719 Shots[find_id].Obj.Vel.Y := YV;
720 Shots[find_id].Obj.Accel.X := 0;
721 Shots[find_id].Obj.Accel.Y := 0;
722 Shots[find_id].SpawnerUID := Spawner;
723 if (ShotType = WEAPON_FLAMETHROWER) and (XV = 0) and (YV = 0) then
724 Shots[find_id].Stopped := 255
725 else
726 Shots[find_id].Stopped := 0;
727 Result := find_id;
728 end;
730 procedure throw(i, x, y, xd, yd, s: Integer);
731 var
732 a: Integer;
733 begin
734 yd := yd - y;
735 xd := xd - x;
737 a := Max(Abs(xd), Abs(yd));
738 if a = 0 then
739 a := 1;
741 Shots[i].Obj.X := x;
742 Shots[i].Obj.Y := y;
743 Shots[i].Obj.Vel.X := (xd*s) div a;
744 Shots[i].Obj.Vel.Y := (yd*s) div a;
745 Shots[i].Obj.Accel.X := 0;
746 Shots[i].Obj.Accel.Y := 0;
747 Shots[i].Stopped := 0;
748 if Shots[i].ShotType in [WEAPON_ROCKETLAUNCHER, WEAPON_BFG] then
749 Shots[i].Timeout := 900 // ~25 sec
750 else
751 begin
752 if Shots[i].ShotType = WEAPON_FLAMETHROWER then
753 Shots[i].Timeout := SHOT_FLAME_LIFETIME
754 else
755 Shots[i].Timeout := 550; // ~15 sec
756 end;
757 end;
759 function g_Weapon_Hit(obj: PObj; d: Integer; SpawnerUID: Word; t: Byte; HitCorpses: Boolean = True): Byte;
760 var
761 i, h: Integer;
763 function PlayerHit(Team: Byte = 0): Boolean;
764 var
765 i: Integer;
766 ChkTeam: Boolean;
767 p: TPlayer;
768 begin
769 Result := False;
770 h := High(gPlayers);
772 if h <> -1 then
773 for i := 0 to h do
774 if (gPlayers[i] <> nil) and gPlayers[i].Live and g_Obj_Collide(obj, @gPlayers[i].Obj) then
775 begin
776 ChkTeam := True;
777 if (Team > 0) and (g_GetUIDType(SpawnerUID) = UID_PLAYER) then
778 begin
779 p := g_Player_Get(SpawnerUID);
780 if p <> nil then
781 ChkTeam := (p.Team = gPlayers[i].Team) xor (Team = 2);
782 end;
783 if ChkTeam then
784 if HitPlayer(gPlayers[i], d, obj^.Vel.X, obj^.Vel.Y, SpawnerUID, t) then
785 begin
786 if t <> HIT_FLAME then
787 gPlayers[i].Push((obj^.Vel.X+obj^.Accel.X)*IfThen(t = HIT_BFG, 8, 1) div 4,
788 (obj^.Vel.Y+obj^.Accel.Y)*IfThen(t = HIT_BFG, 8, 1) div 4);
789 if t = HIT_BFG then
790 g_Game_DelayEvent(DE_BFGHIT, 1000, SpawnerUID);
791 Result := True;
792 break;
793 end;
794 end;
795 end;
797 function monsCheckHit (monidx: Integer; mon: TMonster): Boolean;
798 begin
799 result := false; // don't stop
800 if (mon <> nil) and mon.Live and g_Obj_Collide(obj, @mon.Obj) then
801 begin
802 if HitMonster(mon, d, obj^.Vel.X, obj^.Vel.Y, SpawnerUID, t) then
803 begin
804 if (t <> HIT_FLAME) then
805 begin
806 mon.Push((obj^.Vel.X+obj^.Accel.X)*IfThen(t = HIT_BFG, 8, 1) div 4,
807 (obj^.Vel.Y+obj^.Accel.Y)*IfThen(t = HIT_BFG, 8, 1) div 4);
808 end;
809 result := True;
810 end;
811 end;
812 end;
814 function MonsterHit(): Boolean;
815 begin
816 result := g_Mons_ForEach(monsCheckHit);
817 end;
819 begin
820 Result := 0;
822 if HitCorpses then
823 begin
824 h := High(gCorpses);
826 if gAdvCorpses and (h <> -1) then
827 for i := 0 to h do
828 if (gCorpses[i] <> nil) and (gCorpses[i].State <> CORPSE_STATE_REMOVEME) and
829 g_Obj_Collide(obj, @gCorpses[i].Obj) then
830 begin
831 // Ðàñïèëèâàåì òðóï:
832 gCorpses[i].Damage(d, (obj^.Vel.X+obj^.Accel.X) div 4,
833 (obj^.Vel.Y+obj^.Accel.Y) div 4);
834 Result := 1;
835 end;
836 end;
838 case gGameSettings.GameMode of
839 // Êàìïàíèÿ:
840 GM_COOP, GM_SINGLE:
841 begin
842 // Ñíà÷àëà áü¸ì ìîíñòðîâ, åñëè åñòü, ïîòîì ïûòàåìñÿ áèòü èãðîêîâ
843 if MonsterHit() then
844 begin
845 Result := 2;
846 Exit;
847 end;
849 if PlayerHit() then
850 begin
851 Result := 1;
852 Exit;
853 end;
854 end;
856 // Äåçìàò÷:
857 GM_DM:
858 begin
859 // Ñíà÷àëà áü¸ì èãðîêîâ, åñëè åñòü, ïîòîì ïûòàåìñÿ áèòü ìîíñòðîâ
860 if PlayerHit() then
861 begin
862 Result := 1;
863 Exit;
864 end;
866 if MonsterHit() then
867 begin
868 Result := 2;
869 Exit;
870 end;
871 end;
873 // Êîìàíäíûå:
874 GM_TDM, GM_CTF:
875 begin
876 // Ñíà÷àëà áü¸ì èãðîêîâ êîìàíäû ñîïåðíèêà
877 if PlayerHit(2) then
878 begin
879 Result := 1;
880 Exit;
881 end;
883 // Ïîòîì ìîíñòðîâ
884 if MonsterHit() then
885 begin
886 Result := 2;
887 Exit;
888 end;
890 // È â êîíöå ñâîèõ èãðîêîâ
891 if PlayerHit(1) then
892 begin
893 Result := 1;
894 Exit;
895 end;
896 end;
898 end;
899 end;
901 function g_Weapon_HitUID(UID: Word; d: Integer; SpawnerUID: Word; t: Byte): Boolean;
902 begin
903 Result := False;
905 case g_GetUIDType(UID) of
906 UID_PLAYER: Result := HitPlayer(g_Player_Get(UID), d, 0, 0, SpawnerUID, t);
907 UID_MONSTER: Result := HitMonster(g_Monsters_ByUID(UID), d, 0, 0, SpawnerUID, t);
908 else Exit;
909 end;
910 end;
912 function g_Weapon_Explode(X, Y: Integer; rad: Integer; SpawnerUID: Word): Boolean;
913 var
914 r: Integer;
916 function monsExCheck (monidx: Integer; mon: TMonster): Boolean;
917 var
918 dx, dy, mm: Integer;
919 begin
920 result := false; // don't stop
921 if mon <> nil then
922 begin
923 with mon do
924 begin
925 dx := Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2)-X;
926 dy := Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)-Y;
928 if dx > 1000 then dx := 1000;
929 if dy > 1000 then dy := 1000;
931 if (dx*dx+dy*dy < r) then
932 begin
933 //m := PointToRect(X, Y, Obj.X+Obj.Rect.X, Obj.Y+Obj.Rect.Y, Obj.Rect.Width, Obj.Rect.Height);
935 mm := Max(abs(dx), abs(dy));
936 if mm = 0 then mm := 1;
938 if mon.Live then
939 HitMonster(mon, ((mon.Obj.Rect.Width div 4)*10*(rad-mm)) div rad,
940 0, 0, SpawnerUID, HIT_ROCKET);
942 mon.Push((dx*7) div mm, (dy*7) div mm);
943 end;
944 end;
945 end;
946 end;
948 var
949 i, h, dx, dy, m, mm: Integer;
950 _angle: SmallInt;
952 begin
953 Result := False;
955 g_Triggers_PressC(X, Y, rad, SpawnerUID, ACTIVATE_SHOT);
957 r := rad*rad;
959 h := High(gPlayers);
961 if h <> -1 then
962 for i := 0 to h do
963 if (gPlayers[i] <> nil) and gPlayers[i].Live then
964 with gPlayers[i] do
965 begin
966 dx := Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2)-X;
967 dy := Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)-Y;
969 if dx > 1000 then dx := 1000;
970 if dy > 1000 then dy := 1000;
972 if dx*dx+dy*dy < r then
973 begin
974 //m := PointToRect(X, Y, GameX+PLAYER_RECT.X, GameY+PLAYER_RECT.Y,
975 // PLAYER_RECT.Width, PLAYER_RECT.Height);
977 mm := Max(abs(dx), abs(dy));
978 if mm = 0 then mm := 1;
980 HitPlayer(gPlayers[i], (100*(rad-mm)) div rad, (dx*10) div mm, (dy*10) div mm, SpawnerUID, HIT_ROCKET);
981 gPlayers[i].Push((dx*7) div mm, (dy*7) div mm);
982 end;
983 end;
985 g_Mons_ForEach(monsExCheck);
988 h := High(gCorpses);
990 if gAdvCorpses and (h <> -1) then
991 for i := 0 to h do
992 if (gCorpses[i] <> nil) and (gCorpses[i].State <> CORPSE_STATE_REMOVEME) then
993 with gCorpses[i] do
994 begin
995 dx := Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2)-X;
996 dy := Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)-Y;
998 if dx > 1000 then dx := 1000;
999 if dy > 1000 then dy := 1000;
1001 if dx*dx+dy*dy < r then
1002 begin
1003 m := PointToRect(X, Y, Obj.X+Obj.Rect.X, Obj.Y+Obj.Rect.Y,
1004 Obj.Rect.Width, Obj.Rect.Height);
1006 mm := Max(abs(dx), abs(dy));
1007 if mm = 0 then mm := 1;
1009 Damage(Round(100*(rad-m)/rad), (dx*10) div mm, (dy*10) div mm);
1010 end;
1011 end;
1013 h := High(gGibs);
1015 if gAdvGibs and (h <> -1) then
1016 for i := 0 to h do
1017 if gGibs[i].Live then
1018 with gGibs[i] do
1019 begin
1020 dx := Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2)-X;
1021 dy := Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)-Y;
1023 if dx > 1000 then dx := 1000;
1024 if dy > 1000 then dy := 1000;
1026 if dx*dx+dy*dy < r then
1027 begin
1028 m := PointToRect(X, Y, Obj.X+Obj.Rect.X, Obj.Y+Obj.Rect.Y,
1029 Obj.Rect.Width, Obj.Rect.Height);
1030 _angle := GetAngle(Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2),
1031 Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2), X, Y);
1033 g_Obj_PushA(@Obj, Round(15*(rad-m)/rad), _angle);
1034 positionChanged(); // this updates spatial accelerators
1035 end;
1036 end;
1037 end;
1039 procedure g_Weapon_Init();
1040 begin
1041 CreateWaterMap();
1042 end;
1044 procedure g_Weapon_Free();
1045 var
1046 i: Integer;
1047 begin
1048 if Shots <> nil then
1049 begin
1050 for i := 0 to High(Shots) do
1051 if Shots[i].ShotType <> 0 then
1052 Shots[i].Animation.Free();
1054 Shots := nil;
1055 end;
1057 WaterMap := nil;
1058 end;
1060 procedure g_Weapon_LoadData();
1061 begin
1062 e_WriteLog('Loading weapons data...', MSG_NOTIFY);
1064 g_Sound_CreateWADEx('SOUND_WEAPON_HITPUNCH', GameWAD+':SOUNDS\HITPUNCH');
1065 g_Sound_CreateWADEx('SOUND_WEAPON_MISSPUNCH', GameWAD+':SOUNDS\MISSPUNCH');
1066 g_Sound_CreateWADEx('SOUND_WEAPON_HITBERSERK', GameWAD+':SOUNDS\HITBERSERK');
1067 g_Sound_CreateWADEx('SOUND_WEAPON_MISSBERSERK', GameWAD+':SOUNDS\MISSBERSERK');
1068 g_Sound_CreateWADEx('SOUND_WEAPON_SELECTSAW', GameWAD+':SOUNDS\SELECTSAW');
1069 g_Sound_CreateWADEx('SOUND_WEAPON_IDLESAW', GameWAD+':SOUNDS\IDLESAW');
1070 g_Sound_CreateWADEx('SOUND_WEAPON_HITSAW', GameWAD+':SOUNDS\HITSAW');
1071 g_Sound_CreateWADEx('SOUND_WEAPON_FIRESHOTGUN2', GameWAD+':SOUNDS\FIRESHOTGUN2');
1072 g_Sound_CreateWADEx('SOUND_WEAPON_FIRESHOTGUN', GameWAD+':SOUNDS\FIRESHOTGUN');
1073 g_Sound_CreateWADEx('SOUND_WEAPON_FIRESAW', GameWAD+':SOUNDS\FIRESAW');
1074 g_Sound_CreateWADEx('SOUND_WEAPON_FIREROCKET', GameWAD+':SOUNDS\FIREROCKET');
1075 g_Sound_CreateWADEx('SOUND_WEAPON_FIREPLASMA', GameWAD+':SOUNDS\FIREPLASMA');
1076 g_Sound_CreateWADEx('SOUND_WEAPON_FIREPISTOL', GameWAD+':SOUNDS\FIREPISTOL');
1077 g_Sound_CreateWADEx('SOUND_WEAPON_FIRECGUN', GameWAD+':SOUNDS\FIRECGUN');
1078 g_Sound_CreateWADEx('SOUND_WEAPON_FIREBFG', GameWAD+':SOUNDS\FIREBFG');
1079 g_Sound_CreateWADEx('SOUND_FIRE', GameWAD+':SOUNDS\FIRE');
1080 g_Sound_CreateWADEx('SOUND_WEAPON_STARTFIREBFG', GameWAD+':SOUNDS\STARTFIREBFG');
1081 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEROCKET', GameWAD+':SOUNDS\EXPLODEROCKET');
1082 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEBFG', GameWAD+':SOUNDS\EXPLODEBFG');
1083 g_Sound_CreateWADEx('SOUND_WEAPON_BFGWATER', GameWAD+':SOUNDS\BFGWATER');
1084 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEPLASMA', GameWAD+':SOUNDS\EXPLODEPLASMA');
1085 g_Sound_CreateWADEx('SOUND_WEAPON_PLASMAWATER', GameWAD+':SOUNDS\PLASMAWATER');
1086 g_Sound_CreateWADEx('SOUND_WEAPON_FIREBALL', GameWAD+':SOUNDS\FIREBALL');
1087 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEBALL', GameWAD+':SOUNDS\EXPLODEBALL');
1088 g_Sound_CreateWADEx('SOUND_WEAPON_FIREREV', GameWAD+':SOUNDS\FIREREV');
1089 g_Sound_CreateWADEx('SOUND_PLAYER_JETFLY', GameWAD+':SOUNDS\WORKJETPACK');
1090 g_Sound_CreateWADEx('SOUND_PLAYER_JETON', GameWAD+':SOUNDS\STARTJETPACK');
1091 g_Sound_CreateWADEx('SOUND_PLAYER_JETOFF', GameWAD+':SOUNDS\STOPJETPACK');
1092 g_Sound_CreateWADEx('SOUND_PLAYER_CASING1', GameWAD+':SOUNDS\CASING1');
1093 g_Sound_CreateWADEx('SOUND_PLAYER_CASING2', GameWAD+':SOUNDS\CASING2');
1094 g_Sound_CreateWADEx('SOUND_PLAYER_SHELL1', GameWAD+':SOUNDS\SHELL1');
1095 g_Sound_CreateWADEx('SOUND_PLAYER_SHELL2', GameWAD+':SOUNDS\SHELL2');
1097 g_Texture_CreateWADEx('TEXTURE_WEAPON_ROCKET', GameWAD+':TEXTURES\BROCKET');
1098 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_SKELFIRE', GameWAD+':TEXTURES\BSKELFIRE', 64, 16, 2);
1099 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_BFG', GameWAD+':TEXTURES\BBFG', 64, 64, 2);
1100 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_PLASMA', GameWAD+':TEXTURES\BPLASMA', 16, 16, 2);
1101 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_IMPFIRE', GameWAD+':TEXTURES\BIMPFIRE', 16, 16, 2);
1102 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_BSPFIRE', GameWAD+':TEXTURES\BBSPFIRE', 16, 16, 2);
1103 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_CACOFIRE', GameWAD+':TEXTURES\BCACOFIRE', 16, 16, 2);
1104 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_BARONFIRE', GameWAD+':TEXTURES\BBARONFIRE', 64, 16, 2);
1105 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_MANCUBFIRE', GameWAD+':TEXTURES\BMANCUBFIRE', 64, 32, 2);
1106 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_ROCKET', GameWAD+':TEXTURES\EROCKET', 128, 128, 6);
1107 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_SKELFIRE', GameWAD+':TEXTURES\ESKELFIRE', 64, 64, 3);
1108 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_BFG', GameWAD+':TEXTURES\EBFG', 128, 128, 6);
1109 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_IMPFIRE', GameWAD+':TEXTURES\EIMPFIRE', 64, 64, 3);
1110 g_Frames_CreateWAD(nil, 'FRAMES_BFGHIT', GameWAD+':TEXTURES\BFGHIT', 64, 64, 4);
1111 g_Frames_CreateWAD(nil, 'FRAMES_FIRE', GameWAD+':TEXTURES\FIRE', 64, 128, 8);
1112 g_Frames_CreateWAD(nil, 'FRAMES_FLAME', GameWAD+':TEXTURES\FLAME', 32, 32, 11);
1113 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_PLASMA', GameWAD+':TEXTURES\EPLASMA', 32, 32, 4, True);
1114 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_BSPFIRE', GameWAD+':TEXTURES\EBSPFIRE', 32, 32, 5);
1115 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_CACOFIRE', GameWAD+':TEXTURES\ECACOFIRE', 64, 64, 3);
1116 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_BARONFIRE', GameWAD+':TEXTURES\EBARONFIRE', 64, 64, 3);
1117 g_Frames_CreateWAD(nil, 'FRAMES_SMOKE', GameWAD+':TEXTURES\SMOKE', 32, 32, 10, False);
1119 g_Texture_CreateWADEx('TEXTURE_SHELL_BULLET', GameWAD+':TEXTURES\EBULLET');
1120 g_Texture_CreateWADEx('TEXTURE_SHELL_SHELL', GameWAD+':TEXTURES\ESHELL');
1121 end;
1123 procedure g_Weapon_FreeData();
1124 begin
1125 e_WriteLog('Releasing weapons data...', MSG_NOTIFY);
1127 g_Sound_Delete('SOUND_WEAPON_HITPUNCH');
1128 g_Sound_Delete('SOUND_WEAPON_MISSPUNCH');
1129 g_Sound_Delete('SOUND_WEAPON_HITBERSERK');
1130 g_Sound_Delete('SOUND_WEAPON_MISSBERSERK');
1131 g_Sound_Delete('SOUND_WEAPON_SELECTSAW');
1132 g_Sound_Delete('SOUND_WEAPON_IDLESAW');
1133 g_Sound_Delete('SOUND_WEAPON_HITSAW');
1134 g_Sound_Delete('SOUND_WEAPON_FIRESHOTGUN2');
1135 g_Sound_Delete('SOUND_WEAPON_FIRESHOTGUN');
1136 g_Sound_Delete('SOUND_WEAPON_FIRESAW');
1137 g_Sound_Delete('SOUND_WEAPON_FIREROCKET');
1138 g_Sound_Delete('SOUND_WEAPON_FIREPLASMA');
1139 g_Sound_Delete('SOUND_WEAPON_FIREPISTOL');
1140 g_Sound_Delete('SOUND_WEAPON_FIRECGUN');
1141 g_Sound_Delete('SOUND_WEAPON_FIREBFG');
1142 g_Sound_Delete('SOUND_FIRE');
1143 g_Sound_Delete('SOUND_WEAPON_STARTFIREBFG');
1144 g_Sound_Delete('SOUND_WEAPON_EXPLODEROCKET');
1145 g_Sound_Delete('SOUND_WEAPON_EXPLODEBFG');
1146 g_Sound_Delete('SOUND_WEAPON_BFGWATER');
1147 g_Sound_Delete('SOUND_WEAPON_EXPLODEPLASMA');
1148 g_Sound_Delete('SOUND_WEAPON_PLASMAWATER');
1149 g_Sound_Delete('SOUND_WEAPON_FIREBALL');
1150 g_Sound_Delete('SOUND_WEAPON_EXPLODEBALL');
1151 g_Sound_Delete('SOUND_WEAPON_FIREREV');
1152 g_Sound_Delete('SOUND_PLAYER_JETFLY');
1153 g_Sound_Delete('SOUND_PLAYER_JETON');
1154 g_Sound_Delete('SOUND_PLAYER_JETOFF');
1155 g_Sound_Delete('SOUND_PLAYER_CASING1');
1156 g_Sound_Delete('SOUND_PLAYER_CASING2');
1157 g_Sound_Delete('SOUND_PLAYER_SHELL1');
1158 g_Sound_Delete('SOUND_PLAYER_SHELL2');
1160 g_Texture_Delete('TEXTURE_WEAPON_ROCKET');
1161 g_Frames_DeleteByName('FRAMES_WEAPON_BFG');
1162 g_Frames_DeleteByName('FRAMES_WEAPON_PLASMA');
1163 g_Frames_DeleteByName('FRAMES_WEAPON_IMPFIRE');
1164 g_Frames_DeleteByName('FRAMES_WEAPON_BSPFIRE');
1165 g_Frames_DeleteByName('FRAMES_WEAPON_CACOFIRE');
1166 g_Frames_DeleteByName('FRAMES_WEAPON_MANCUBFIRE');
1167 g_Frames_DeleteByName('FRAMES_EXPLODE_ROCKET');
1168 g_Frames_DeleteByName('FRAMES_EXPLODE_BFG');
1169 g_Frames_DeleteByName('FRAMES_EXPLODE_IMPFIRE');
1170 g_Frames_DeleteByName('FRAMES_BFGHIT');
1171 g_Frames_DeleteByName('FRAMES_FIRE');
1172 g_Frames_DeleteByName('FRAMES_EXPLODE_PLASMA');
1173 g_Frames_DeleteByName('FRAMES_EXPLODE_BSPFIRE');
1174 g_Frames_DeleteByName('FRAMES_EXPLODE_CACOFIRE');
1175 g_Frames_DeleteByName('FRAMES_SMOKE');
1176 g_Frames_DeleteByName('FRAMES_WEAPON_BARONFIRE');
1177 g_Frames_DeleteByName('FRAMES_EXPLODE_BARONFIRE');
1178 end;
1180 procedure g_Weapon_gun(x, y, xd, yd, v, dmg: Integer; SpawnerUID: Word; CheckTrigger: Boolean);
1181 var
1182 a: Integer;
1183 x2, y2: Integer;
1184 dx, dy: Integer;
1185 xe, ye: Integer;
1186 xi, yi: Integer;
1187 s, c: Extended;
1188 //vx, vy: Integer;
1189 xx, yy, d: Integer;
1191 i: Integer;
1192 t1, _collide: Boolean;
1193 w, h: Word;
1194 begin
1195 a := GetAngle(x, y, xd, yd)+180;
1197 SinCos(DegToRad(-a), s, c);
1199 if Abs(s) < 0.01 then s := 0;
1200 if Abs(c) < 0.01 then c := 0;
1202 x2 := x+Round(c*gMapInfo.Width);
1203 y2 := y+Round(s*gMapInfo.Width);
1205 t1 := gWalls <> nil;
1206 _collide := False;
1207 w := gMapInfo.Width;
1208 h := gMapInfo.Height;
1210 xe := 0;
1211 ye := 0;
1212 dx := x2-x;
1213 dy := y2-y;
1215 if (xd = 0) and (yd = 0) then Exit;
1217 if dx > 0 then xi := 1 else if dx < 0 then xi := -1 else xi := 0;
1218 if dy > 0 then yi := 1 else if dy < 0 then yi := -1 else yi := 0;
1220 dx := Abs(dx);
1221 dy := Abs(dy);
1223 if dx > dy then d := dx else d := dy;
1225 //blood vel, for Monster.Damage()
1226 //vx := (dx*10 div d)*xi;
1227 //vy := (dy*10 div d)*yi;
1229 xx := x;
1230 yy := y;
1232 for i := 1 to d do
1233 begin
1234 xe := xe+dx;
1235 ye := ye+dy;
1237 if xe > d then
1238 begin
1239 xe := xe-d;
1240 xx := xx+xi;
1241 end;
1243 if ye > d then
1244 begin
1245 ye := ye-d;
1246 yy := yy+yi;
1247 end;
1249 if (yy > h) or (yy < 0) then Break;
1250 if (xx > w) or (xx < 0) then Break;
1252 if t1 then
1253 if ByteBool(gCollideMap[yy, xx] and MARK_BLOCKED) then
1254 begin
1255 _collide := True;
1256 g_GFX_Spark(xx-xi, yy-yi, 2+Random(2), 180+a, 0, 0);
1257 if g_Game_IsServer and g_Game_IsNet then
1258 MH_SEND_Effect(xx-xi, yy-yi, 180+a, NET_GFX_SPARK);
1259 end;
1261 if not _collide then
1262 _collide := GunHit(xx, yy, xi*v, yi*v, dmg, SpawnerUID, v <> 0) <> 0;
1264 if _collide then
1265 Break;
1266 end;
1268 if CheckTrigger and g_Game_IsServer then
1269 g_Triggers_PressL(X, Y, xx-xi, yy-yi, SpawnerUID, ACTIVATE_SHOT);
1270 end;
1272 procedure g_Weapon_punch(x, y: Integer; d, SpawnerUID: Word);
1273 var
1274 obj: TObj;
1275 begin
1276 obj.X := X;
1277 obj.Y := Y;
1278 obj.rect.X := 0;
1279 obj.rect.Y := 0;
1280 obj.rect.Width := 39;
1281 obj.rect.Height := 52;
1282 obj.Vel.X := 0;
1283 obj.Vel.Y := 0;
1284 obj.Accel.X := 0;
1285 obj.Accel.Y := 0;
1287 if g_Weapon_Hit(@obj, d, SpawnerUID, HIT_SOME) <> 0 then
1288 g_Sound_PlayExAt('SOUND_WEAPON_HITPUNCH', x, y)
1289 else
1290 g_Sound_PlayExAt('SOUND_WEAPON_MISSPUNCH', x, y);
1291 end;
1293 function g_Weapon_chainsaw(x, y: Integer; d, SpawnerUID: Word): Integer;
1294 var
1295 obj: TObj;
1296 begin
1297 obj.X := X;
1298 obj.Y := Y;
1299 obj.rect.X := 0;
1300 obj.rect.Y := 0;
1301 obj.rect.Width := 32;
1302 obj.rect.Height := 52;
1303 obj.Vel.X := 0;
1304 obj.Vel.Y := 0;
1305 obj.Accel.X := 0;
1306 obj.Accel.Y := 0;
1308 Result := g_Weapon_Hit(@obj, d, SpawnerUID, HIT_SOME);
1309 end;
1311 procedure g_Weapon_rocket(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1312 Silent: Boolean = False);
1313 var
1314 find_id: DWORD;
1315 dx, dy: Integer;
1316 begin
1317 if WID < 0 then
1318 find_id := FindShot()
1319 else
1320 begin
1321 find_id := WID;
1322 if Integer(find_id) >= High(Shots) then
1323 SetLength(Shots, find_id + 64)
1324 end;
1326 with Shots[find_id] do
1327 begin
1328 g_Obj_Init(@Obj);
1330 Obj.Rect.Width := SHOT_ROCKETLAUNCHER_WIDTH;
1331 Obj.Rect.Height := SHOT_ROCKETLAUNCHER_HEIGHT;
1333 dx := IfThen(xd > x, -Obj.Rect.Width, 0);
1334 dy := -(Obj.Rect.Height div 2);
1336 ShotType := WEAPON_ROCKETLAUNCHER;
1337 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 12);
1339 Animation := nil;
1340 triggers := nil;
1341 g_Texture_Get('TEXTURE_WEAPON_ROCKET', TextureID);
1342 end;
1344 Shots[find_id].SpawnerUID := SpawnerUID;
1346 if not Silent then
1347 g_Sound_PlayExAt('SOUND_WEAPON_FIREROCKET', x, y);
1348 end;
1350 procedure g_Weapon_revf(x, y, xd, yd: Integer; SpawnerUID, TargetUID: Word;
1351 WID: Integer = -1; Silent: Boolean = False);
1352 var
1353 find_id, FramesID: DWORD;
1354 dx, dy: Integer;
1355 begin
1356 if WID < 0 then
1357 find_id := FindShot()
1358 else
1359 begin
1360 find_id := WID;
1361 if Integer(find_id) >= High(Shots) then
1362 SetLength(Shots, find_id + 64)
1363 end;
1365 with Shots[find_id] do
1366 begin
1367 g_Obj_Init(@Obj);
1369 Obj.Rect.Width := SHOT_SKELFIRE_WIDTH;
1370 Obj.Rect.Height := SHOT_SKELFIRE_HEIGHT;
1372 dx := -(Obj.Rect.Width div 2);
1373 dy := -(Obj.Rect.Height div 2);
1375 ShotType := WEAPON_SKEL_FIRE;
1376 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 12);
1378 triggers := nil;
1379 target := TargetUID;
1380 g_Frames_Get(FramesID, 'FRAMES_WEAPON_SKELFIRE');
1381 Animation := TAnimation.Create(FramesID, True, 5);
1382 end;
1384 Shots[find_id].SpawnerUID := SpawnerUID;
1386 if not Silent then
1387 g_Sound_PlayExAt('SOUND_WEAPON_FIREREV', x, y);
1388 end;
1390 procedure g_Weapon_plasma(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1391 Silent: Boolean = False);
1392 var
1393 find_id, FramesID: DWORD;
1394 dx, dy: Integer;
1395 begin
1396 if WID < 0 then
1397 find_id := FindShot()
1398 else
1399 begin
1400 find_id := WID;
1401 if Integer(find_id) >= High(Shots) then
1402 SetLength(Shots, find_id + 64);
1403 end;
1405 with Shots[find_id] do
1406 begin
1407 g_Obj_Init(@Obj);
1409 Obj.Rect.Width := SHOT_PLASMA_WIDTH;
1410 Obj.Rect.Height := SHOT_PLASMA_HEIGHT;
1412 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1413 dy := -(Obj.Rect.Height div 2);
1415 ShotType := WEAPON_PLASMA;
1416 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1418 triggers := nil;
1419 g_Frames_Get(FramesID, 'FRAMES_WEAPON_PLASMA');
1420 Animation := TAnimation.Create(FramesID, True, 5);
1421 end;
1423 Shots[find_id].SpawnerUID := SpawnerUID;
1425 if not Silent then
1426 g_Sound_PlayExAt('SOUND_WEAPON_FIREPLASMA', x, y);
1427 end;
1429 procedure g_Weapon_flame(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1430 Silent: Boolean = False);
1431 var
1432 find_id: DWORD;
1433 dx, dy: Integer;
1434 begin
1435 if WID < 0 then
1436 find_id := FindShot()
1437 else
1438 begin
1439 find_id := WID;
1440 if Integer(find_id) >= High(Shots) then
1441 SetLength(Shots, find_id + 64);
1442 end;
1444 with Shots[find_id] do
1445 begin
1446 g_Obj_Init(@Obj);
1448 Obj.Rect.Width := SHOT_FLAME_WIDTH;
1449 Obj.Rect.Height := SHOT_FLAME_HEIGHT;
1451 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1452 dy := -(Obj.Rect.Height div 2);
1454 ShotType := WEAPON_FLAMETHROWER;
1455 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1457 triggers := nil;
1458 Animation := nil;
1459 TextureID := 0;
1460 g_Frames_Get(TextureID, 'FRAMES_FLAME');
1461 end;
1463 Shots[find_id].SpawnerUID := SpawnerUID;
1465 // if not Silent then
1466 // g_Sound_PlayExAt('SOUND_WEAPON_FIREPLASMA', x, y);
1467 end;
1469 procedure g_Weapon_ball1(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1470 Silent: Boolean = False);
1471 var
1472 find_id, FramesID: DWORD;
1473 dx, dy: Integer;
1474 begin
1475 if WID < 0 then
1476 find_id := FindShot()
1477 else
1478 begin
1479 find_id := WID;
1480 if Integer(find_id) >= High(Shots) then
1481 SetLength(Shots, find_id + 64)
1482 end;
1484 with Shots[find_id] do
1485 begin
1486 g_Obj_Init(@Obj);
1488 Obj.Rect.Width := 16;
1489 Obj.Rect.Height := 16;
1491 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1492 dy := -(Obj.Rect.Height div 2);
1494 ShotType := WEAPON_IMP_FIRE;
1495 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1497 triggers := nil;
1498 g_Frames_Get(FramesID, 'FRAMES_WEAPON_IMPFIRE');
1499 Animation := TAnimation.Create(FramesID, True, 4);
1500 end;
1502 Shots[find_id].SpawnerUID := SpawnerUID;
1504 if not Silent then
1505 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x, y);
1506 end;
1508 procedure g_Weapon_ball2(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1509 Silent: Boolean = False);
1510 var
1511 find_id, FramesID: DWORD;
1512 dx, dy: Integer;
1513 begin
1514 if WID < 0 then
1515 find_id := FindShot()
1516 else
1517 begin
1518 find_id := WID;
1519 if Integer(find_id) >= High(Shots) then
1520 SetLength(Shots, find_id + 64)
1521 end;
1523 with Shots[find_id] do
1524 begin
1525 g_Obj_Init(@Obj);
1527 Obj.Rect.Width := 16;
1528 Obj.Rect.Height := 16;
1530 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1531 dy := -(Obj.Rect.Height div 2);
1533 ShotType := WEAPON_CACO_FIRE;
1534 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1536 triggers := nil;
1537 g_Frames_Get(FramesID, 'FRAMES_WEAPON_CACOFIRE');
1538 Animation := TAnimation.Create(FramesID, True, 4);
1539 end;
1541 Shots[find_id].SpawnerUID := SpawnerUID;
1543 if not Silent then
1544 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x, y);
1545 end;
1547 procedure g_Weapon_ball7(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1548 Silent: Boolean = False);
1549 var
1550 find_id, FramesID: DWORD;
1551 dx, dy: Integer;
1552 begin
1553 if WID < 0 then
1554 find_id := FindShot()
1555 else
1556 begin
1557 find_id := WID;
1558 if Integer(find_id) >= High(Shots) then
1559 SetLength(Shots, find_id + 64)
1560 end;
1562 with Shots[find_id] do
1563 begin
1564 g_Obj_Init(@Obj);
1566 Obj.Rect.Width := 32;
1567 Obj.Rect.Height := 16;
1569 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1570 dy := -(Obj.Rect.Height div 2);
1572 ShotType := WEAPON_BARON_FIRE;
1573 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1575 triggers := nil;
1576 g_Frames_Get(FramesID, 'FRAMES_WEAPON_BARONFIRE');
1577 Animation := TAnimation.Create(FramesID, True, 4);
1578 end;
1580 Shots[find_id].SpawnerUID := SpawnerUID;
1582 if not Silent then
1583 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x, y);
1584 end;
1586 procedure g_Weapon_aplasma(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1587 Silent: Boolean = False);
1588 var
1589 find_id, FramesID: DWORD;
1590 dx, dy: Integer;
1591 begin
1592 if WID < 0 then
1593 find_id := FindShot()
1594 else
1595 begin
1596 find_id := WID;
1597 if Integer(find_id) >= High(Shots) then
1598 SetLength(Shots, find_id + 64)
1599 end;
1601 with Shots[find_id] do
1602 begin
1603 g_Obj_Init(@Obj);
1605 Obj.Rect.Width := 16;
1606 Obj.Rect.Height := 16;
1608 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1609 dy := -(Obj.Rect.Height div 2);
1611 ShotType := WEAPON_BSP_FIRE;
1612 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1614 triggers := nil;
1616 g_Frames_Get(FramesID, 'FRAMES_WEAPON_BSPFIRE');
1617 Animation := TAnimation.Create(FramesID, True, 4);
1618 end;
1620 Shots[find_id].SpawnerUID := SpawnerUID;
1622 if not Silent then
1623 g_Sound_PlayExAt('SOUND_WEAPON_FIREPLASMA', x, y);
1624 end;
1626 procedure g_Weapon_manfire(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1627 Silent: Boolean = False);
1628 var
1629 find_id, FramesID: DWORD;
1630 dx, dy: Integer;
1631 begin
1632 if WID < 0 then
1633 find_id := FindShot()
1634 else
1635 begin
1636 find_id := WID;
1637 if Integer(find_id) >= High(Shots) then
1638 SetLength(Shots, find_id + 64)
1639 end;
1641 with Shots[find_id] do
1642 begin
1643 g_Obj_Init(@Obj);
1645 Obj.Rect.Width := 32;
1646 Obj.Rect.Height := 32;
1648 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1649 dy := -(Obj.Rect.Height div 2);
1651 ShotType := WEAPON_MANCUB_FIRE;
1652 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1654 triggers := nil;
1656 g_Frames_Get(FramesID, 'FRAMES_WEAPON_MANCUBFIRE');
1657 Animation := TAnimation.Create(FramesID, True, 4);
1658 end;
1660 Shots[find_id].SpawnerUID := SpawnerUID;
1662 if not Silent then
1663 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x, y);
1664 end;
1666 procedure g_Weapon_bfgshot(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1667 Silent: Boolean = False);
1668 var
1669 find_id, FramesID: DWORD;
1670 dx, dy: Integer;
1671 begin
1672 if WID < 0 then
1673 find_id := FindShot()
1674 else
1675 begin
1676 find_id := WID;
1677 if Integer(find_id) >= High(Shots) then
1678 SetLength(Shots, find_id + 64)
1679 end;
1681 with Shots[find_id] do
1682 begin
1683 g_Obj_Init(@Obj);
1685 Obj.Rect.Width := SHOT_BFG_WIDTH;
1686 Obj.Rect.Height := SHOT_BFG_HEIGHT;
1688 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1689 dy := -(Obj.Rect.Height div 2);
1691 ShotType := WEAPON_BFG;
1692 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1694 triggers := nil;
1695 g_Frames_Get(FramesID, 'FRAMES_WEAPON_BFG');
1696 Animation := TAnimation.Create(FramesID, True, 6);
1697 end;
1699 Shots[find_id].SpawnerUID := SpawnerUID;
1701 if not Silent then
1702 g_Sound_PlayExAt('SOUND_WEAPON_FIREBFG', x, y);
1703 end;
1705 procedure g_Weapon_bfghit(x, y: Integer);
1706 var
1707 ID: DWORD;
1708 Anim: TAnimation;
1709 begin
1710 if g_Frames_Get(ID, 'FRAMES_BFGHIT') then
1711 begin
1712 Anim := TAnimation.Create(ID, False, 4);
1713 g_GFX_OnceAnim(x-32, y-32, Anim);
1714 Anim.Free();
1715 end;
1716 end;
1718 procedure g_Weapon_pistol(x, y, xd, yd: Integer; SpawnerUID: Word;
1719 Silent: Boolean = False);
1720 begin
1721 if not Silent then
1722 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', x, y);
1724 g_Weapon_gun(x, y, xd, yd, 1, 3, SpawnerUID, True);
1725 if gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF] then
1726 begin
1727 g_Weapon_gun(x, y+1, xd, yd+1, 1, 3, SpawnerUID, False);
1728 g_Weapon_gun(x, y-1, xd, yd-1, 1, 2, SpawnerUID, False);
1729 end;
1730 end;
1732 procedure g_Weapon_mgun(x, y, xd, yd: Integer; SpawnerUID: Word;
1733 Silent: Boolean = False);
1734 begin
1735 if not Silent then
1736 if gSoundEffectsDF then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', x, y);
1738 g_Weapon_gun(x, y, xd, yd, 1, 3, SpawnerUID, True);
1739 if (gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF]) and
1740 (g_GetUIDType(SpawnerUID) = UID_PLAYER) then
1741 begin
1742 g_Weapon_gun(x, y+1, xd, yd+1, 1, 2, SpawnerUID, False);
1743 g_Weapon_gun(x, y-1, xd, yd-1, 1, 2, SpawnerUID, False);
1744 end;
1745 end;
1747 procedure g_Weapon_shotgun(x, y, xd, yd: Integer; SpawnerUID: Word;
1748 Silent: Boolean = False);
1749 var
1750 i, j: Integer;
1751 begin
1752 if not Silent then
1753 if gSoundEffectsDF then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', x, y);
1755 for i := 0 to 9 do
1756 begin
1757 j := Random(17)-8; // -8 .. 8
1758 g_Weapon_gun(x, y+j, xd, yd+j, IfThen(i mod 2 <> 0, 1, 0), 3, SpawnerUID, i=0);
1759 end;
1760 end;
1762 procedure g_Weapon_dshotgun(x, y, xd, yd: Integer; SpawnerUID: Word;
1763 Silent: Boolean = False);
1764 var
1765 a, i, j: Integer;
1766 begin
1767 if not Silent then
1768 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', x, y);
1770 if gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF] then a := 25 else a := 20;
1771 for i := 0 to a do
1772 begin
1773 j := Random(41)-20; // -20 .. 20
1774 g_Weapon_gun(x, y+j, xd, yd+j, IfThen(i mod 3 <> 0, 0, 1), 3, SpawnerUID, i=0);
1775 end;
1776 end;
1778 procedure g_Weapon_Update();
1779 var
1780 i, a, h, cx, cy, oldvx, oldvy, tf: Integer;
1781 _id: DWORD;
1782 Anim: TAnimation;
1783 t: DWArray;
1784 st: Word;
1785 s: String;
1786 o: TObj;
1787 spl: Boolean;
1788 Loud: Boolean;
1789 tcx, tcy: Integer;
1790 begin
1791 if Shots = nil then
1792 Exit;
1794 for i := 0 to High(Shots) do
1795 begin
1796 if Shots[i].ShotType = 0 then
1797 Continue;
1799 Loud := True;
1801 with Shots[i] do
1802 begin
1803 Timeout := Timeout - 1;
1804 oldvx := Obj.Vel.X;
1805 oldvy := Obj.Vel.Y;
1806 // Àêòèâèðîâàòü òðèããåðû ïî ïóòè (êðîìå óæå àêòèâèðîâàííûõ):
1807 if (Stopped = 0) and g_Game_IsServer then
1808 t := g_Triggers_PressR(Obj.X, Obj.Y, Obj.Rect.Width, Obj.Rect.Height,
1809 SpawnerUID, ACTIVATE_SHOT, triggers)
1810 else
1811 t := nil;
1813 if t <> nil then
1814 begin
1815 // Ïîïîëíÿåì ñïèñîê àêòèâèðîâàííûõ òðèããåðîâ:
1816 if triggers = nil then
1817 triggers := t
1818 else
1819 begin
1820 h := High(t);
1822 for a := 0 to h do
1823 if not InDWArray(t[a], triggers) then
1824 begin
1825 SetLength(triggers, Length(triggers)+1);
1826 triggers[High(triggers)] := t[a];
1827 end;
1828 end;
1829 end;
1831 // Àíèìàöèÿ ñíàðÿäà:
1832 if Animation <> nil then
1833 Animation.Update();
1835 // Äâèæåíèå:
1836 spl := (ShotType <> WEAPON_PLASMA) and
1837 (ShotType <> WEAPON_BFG) and
1838 (ShotType <> WEAPON_BSP_FIRE) and
1839 (ShotType <> WEAPON_FLAMETHROWER);
1841 if Stopped = 0 then
1842 begin
1843 st := g_Obj_Move(@Obj, False, spl);
1844 end
1845 else
1846 begin
1847 st := 0;
1848 end;
1849 positionChanged(); // this updates spatial accelerators
1851 if WordBool(st and MOVE_FALLOUT) or (Obj.X < -1000) or
1852 (Obj.X > gMapInfo.Width+1000) or (Obj.Y < -1000) then
1853 begin
1854 // Íà êëèåíòå ñêîðåå âñåãî è òàê óæå âûïàë.
1855 ShotType := 0;
1856 Animation.Free();
1857 Continue;
1858 end;
1860 cx := Obj.X + (Obj.Rect.Width div 2);
1861 cy := Obj.Y + (Obj.Rect.Height div 2);
1863 case ShotType of
1864 WEAPON_ROCKETLAUNCHER, WEAPON_SKEL_FIRE: // Ðàêåòû è ñíàðÿäû Ñêåëåòà
1865 begin
1866 // Âûëåòåëà èç âîäû:
1867 if WordBool(st and MOVE_HITAIR) then
1868 g_Obj_SetSpeed(@Obj, 12);
1870 // Â âîäå øëåéô - ïóçûðè, â âîçäóõå øëåéô - äûì:
1871 if WordBool(st and MOVE_INWATER) then
1872 g_GFX_Bubbles(Obj.X+(Obj.Rect.Width div 2),
1873 Obj.Y+(Obj.Rect.Height div 2),
1874 1+Random(3), 16, 16)
1875 else
1876 if g_Frames_Get(_id, 'FRAMES_SMOKE') then
1877 begin
1878 Anim := TAnimation.Create(_id, False, 3);
1879 Anim.Alpha := 150;
1880 g_GFX_OnceAnim(Obj.X-14+Random(9),
1881 Obj.Y+(Obj.Rect.Height div 2)-20+Random(9),
1882 Anim, ONCEANIM_SMOKE);
1883 Anim.Free();
1884 end;
1886 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
1887 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL)) or
1888 (g_Weapon_Hit(@Obj, 10, SpawnerUID, HIT_SOME, False) <> 0) or
1889 (Timeout < 1) then
1890 begin
1891 Obj.Vel.X := 0;
1892 Obj.Vel.Y := 0;
1894 g_Weapon_Explode(cx, cy, 60, SpawnerUID);
1896 if ShotType = WEAPON_SKEL_FIRE then
1897 begin // Âçðûâ ñíàðÿäà Ñêåëåòà
1898 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_SKELFIRE') then
1899 begin
1900 Anim := TAnimation.Create(TextureID, False, 8);
1901 Anim.Blending := False;
1902 g_GFX_OnceAnim((Obj.X+32)-58, (Obj.Y+8)-36, Anim);
1903 g_DynLightExplosion((Obj.X+32), (Obj.Y+8), 64, 1, 0, 0);
1904 Anim.Free();
1905 end;
1906 end
1907 else
1908 begin // Âçðûâ Ðàêåòû
1909 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_ROCKET') then
1910 begin
1911 Anim := TAnimation.Create(TextureID, False, 6);
1912 Anim.Blending := False;
1913 g_GFX_OnceAnim(cx-64, cy-64, Anim);
1914 g_DynLightExplosion(cx, cy, 64, 1, 0, 0);
1915 Anim.Free();
1916 end;
1917 end;
1919 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', Obj.X, Obj.Y);
1921 ShotType := 0;
1922 end;
1924 if ShotType = WEAPON_SKEL_FIRE then
1925 begin // Ñàìîíàâîäêà ñíàðÿäà Ñêåëåòà:
1926 if GetPos(target, @o) then
1927 throw(i, Obj.X, Obj.Y,
1928 o.X+o.Rect.X+(o.Rect.Width div 2)+o.Vel.X+o.Accel.X,
1929 o.Y+o.Rect.Y+(o.Rect.Height div 2)+o.Vel.Y+o.Accel.Y,
1930 12);
1931 end;
1932 end;
1934 WEAPON_PLASMA, WEAPON_BSP_FIRE: // Ïëàçìà, ïëàçìà Àðàõíàòðîíà
1935 begin
1936 // Ïîïàëà â âîäó - ýëåêòðîøîê ïî âîäå:
1937 if WordBool(st and (MOVE_INWATER or MOVE_HITWATER)) then
1938 begin
1939 g_Sound_PlayExAt('SOUND_WEAPON_PLASMAWATER', Obj.X, Obj.Y);
1940 if g_Game_IsServer then CheckTrap(i, 10, HIT_ELECTRO);
1941 ShotType := 0;
1942 Continue;
1943 end;
1945 // Âåëè÷èíà óðîíà:
1946 if (ShotType = WEAPON_PLASMA) and
1947 (gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF]) then
1948 a := 10
1949 else
1950 a := 5;
1952 if ShotType = WEAPON_BSP_FIRE then
1953 a := 10;
1955 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
1956 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL)) or
1957 (g_Weapon_Hit(@Obj, a, SpawnerUID, HIT_SOME, False) <> 0) or
1958 (Timeout < 1) then
1959 begin
1960 if ShotType = WEAPON_PLASMA then
1961 s := 'FRAMES_EXPLODE_PLASMA'
1962 else
1963 s := 'FRAMES_EXPLODE_BSPFIRE';
1965 // Âçðûâ Ïëàçìû:
1966 if g_Frames_Get(TextureID, s) then
1967 begin
1968 Anim := TAnimation.Create(TextureID, False, 3);
1969 Anim.Blending := False;
1970 g_GFX_OnceAnim(cx-16, cy-16, Anim);
1971 Anim.Free();
1972 g_DynLightExplosion(cx, cy, 32, 0, 0.5, 0.5);
1973 end;
1975 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEPLASMA', Obj.X, Obj.Y);
1977 ShotType := 0;
1978 end;
1979 end;
1981 WEAPON_FLAMETHROWER: // Îãíåìåò
1982 begin
1983 // Ñî âðåìåíåì óìèðàåò
1984 if (Timeout < 1) then
1985 begin
1986 ShotType := 0;
1987 Continue;
1988 end;
1989 // Ïîä âîäîé òîæå
1990 if WordBool(st and (MOVE_HITWATER or MOVE_INWATER)) then
1991 begin
1992 if WordBool(st and MOVE_HITWATER) then
1993 begin
1994 if g_Frames_Get(_id, 'FRAMES_SMOKE') then
1995 begin
1996 Anim := TAnimation.Create(_id, False, 3);
1997 Anim.Alpha := 0;
1998 tcx := Random(8);
1999 tcy := Random(8);
2000 g_GFX_OnceAnim(cx-4+tcx-(Anim.Width div 2),
2001 cy-4+tcy-(Anim.Height div 2),
2002 Anim, ONCEANIM_SMOKE);
2003 Anim.Free();
2004 end;
2005 end
2006 else
2007 g_GFX_Bubbles(cx, cy, 1+Random(3), 16, 16);
2008 ShotType := 0;
2009 Continue;
2010 end;
2012 // Ãðàâèòàöèÿ
2013 if Stopped = 0 then
2014 Obj.Accel.Y := Obj.Accel.Y + 1;
2015 // Ïîïàëè â ñòåíó èëè â âîäó:
2016 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL or MOVE_HITWATER)) then
2017 begin
2018 // Ïðèëèïàåì:
2019 Obj.Vel.X := 0;
2020 Obj.Vel.Y := 0;
2021 Obj.Accel.Y := 0;
2022 if WordBool(st and MOVE_HITWALL) then
2023 Stopped := MOVE_HITWALL
2024 else if WordBool(st and MOVE_HITLAND) then
2025 Stopped := MOVE_HITLAND
2026 else if WordBool(st and MOVE_HITCEIL) then
2027 Stopped := MOVE_HITCEIL;
2028 end;
2030 a := IfThen(Stopped = 0, 3, 1);
2031 // Åñëè â êîãî-òî ïîïàëè
2032 if g_Weapon_Hit(@Obj, a, SpawnerUID, HIT_FLAME, False) <> 0 then
2033 begin
2034 // HIT_FLAME ñàì ïîäîææåò
2035 // Åñëè â ïîëåòå ïîïàëè, èñ÷åçàåì
2036 if Stopped = 0 then
2037 ShotType := 0;
2038 end;
2040 if Stopped = 0 then
2041 tf := 2
2042 else
2043 tf := 3;
2045 if (gTime mod tf = 0) then
2046 begin
2047 Anim := TAnimation.Create(TextureID, False, 2 + Random(2));
2048 Anim.Alpha := 0;
2049 case Stopped of
2050 MOVE_HITWALL: begin tcx := cx-4+Random(8); tcy := cy-12+Random(24); end;
2051 MOVE_HITLAND: begin tcx := cx-12+Random(24); tcy := cy-10+Random(8); end;
2052 MOVE_HITCEIL: begin tcx := cx-12+Random(24); tcy := cy+6+Random(8); end;
2053 else begin tcx := cx-4+Random(8); tcy := cy-4+Random(8); end;
2054 end;
2055 g_GFX_OnceAnim(tcx-(Anim.Width div 2), tcy-(Anim.Height div 2), Anim, ONCEANIM_SMOKE);
2056 Anim.Free();
2057 //g_DynLightExplosion(tcx, tcy, 1, 1, 0.8, 0.3);
2058 end;
2059 end;
2061 WEAPON_BFG: // BFG
2062 begin
2063 // Ïîïàëà â âîäó - ýëåêòðîøîê ïî âîäå:
2064 if WordBool(st and (MOVE_INWATER or MOVE_HITWATER)) then
2065 begin
2066 g_Sound_PlayExAt('SOUND_WEAPON_BFGWATER', Obj.X, Obj.Y);
2067 if g_Game_IsServer then CheckTrap(i, 1000, HIT_ELECTRO);
2068 ShotType := 0;
2069 Continue;
2070 end;
2072 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2073 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL)) or
2074 (g_Weapon_Hit(@Obj, SHOT_BFG_DAMAGE, SpawnerUID, HIT_BFG, False) <> 0) or
2075 (Timeout < 1) then
2076 begin
2077 // Ëó÷è BFG:
2078 if g_Game_IsServer then g_Weapon_BFG9000(cx, cy, SpawnerUID);
2080 // Âçðûâ BFG:
2081 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_BFG') then
2082 begin
2083 Anim := TAnimation.Create(TextureID, False, 6);
2084 Anim.Blending := False;
2085 g_GFX_OnceAnim(cx-64, cy-64, Anim);
2086 Anim.Free();
2087 g_DynLightExplosion(cx, cy, 96, 0, 1, 0);
2088 end;
2090 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', Obj.X, Obj.Y);
2092 ShotType := 0;
2093 end;
2094 end;
2096 WEAPON_IMP_FIRE, WEAPON_CACO_FIRE, WEAPON_BARON_FIRE: // Âûñòðåëû Áåñà, Êàêîäåìîíà Ðûöàðÿ/Áàðîíà àäà
2097 begin
2098 // Âûëåòåë èç âîäû:
2099 if WordBool(st and MOVE_HITAIR) then
2100 g_Obj_SetSpeed(@Obj, 16);
2102 // Âåëè÷èíà óðîíà:
2103 if ShotType = WEAPON_IMP_FIRE then
2104 a := 5
2105 else
2106 if ShotType = WEAPON_CACO_FIRE then
2107 a := 20
2108 else
2109 a := 40;
2111 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2112 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL)) or
2113 (g_Weapon_Hit(@Obj, a, SpawnerUID, HIT_SOME) <> 0) or
2114 (Timeout < 1) then
2115 begin
2116 if ShotType = WEAPON_IMP_FIRE then
2117 s := 'FRAMES_EXPLODE_IMPFIRE'
2118 else
2119 if ShotType = WEAPON_CACO_FIRE then
2120 s := 'FRAMES_EXPLODE_CACOFIRE'
2121 else
2122 s := 'FRAMES_EXPLODE_BARONFIRE';
2124 // Âçðûâ:
2125 if g_Frames_Get(TextureID, s) then
2126 begin
2127 Anim := TAnimation.Create(TextureID, False, 6);
2128 Anim.Blending := False;
2129 g_GFX_OnceAnim(cx-32, cy-32, Anim);
2130 Anim.Free();
2131 end;
2133 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj.X, Obj.Y);
2135 ShotType := 0;
2136 end;
2137 end;
2139 WEAPON_MANCUB_FIRE: // Âûñòðåë Ìàíêóáóñà
2140 begin
2141 // Âûëåòåë èç âîäû:
2142 if WordBool(st and MOVE_HITAIR) then
2143 g_Obj_SetSpeed(@Obj, 16);
2145 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2146 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL)) or
2147 (g_Weapon_Hit(@Obj, 40, SpawnerUID, HIT_SOME, False) <> 0) or
2148 (Timeout < 1) then
2149 begin
2150 // Âçðûâ:
2151 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_ROCKET') then
2152 begin
2153 Anim := TAnimation.Create(TextureID, False, 6);
2154 Anim.Blending := False;
2155 g_GFX_OnceAnim(cx-64, cy-64, Anim);
2156 Anim.Free();
2157 end;
2159 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj.X, Obj.Y);
2161 ShotType := 0;
2162 end;
2163 end;
2164 end; // case ShotType of...
2166 // Åñëè ñíàðÿäà óæå íåò, óäàëÿåì àíèìàöèþ:
2167 if (ShotType = 0) then
2168 begin
2169 if gGameSettings.GameType = GT_SERVER then
2170 MH_SEND_DeleteShot(i, Obj.X, Obj.Y, Loud);
2171 if Animation <> nil then
2172 begin
2173 Animation.Free();
2174 Animation := nil;
2175 end;
2176 end
2177 else if (ShotType <> WEAPON_FLAMETHROWER) and ((oldvx <> Obj.Vel.X) or (oldvy <> Obj.Vel.Y)) then
2178 if gGameSettings.GameType = GT_SERVER then
2179 MH_SEND_UpdateShot(i);
2180 end;
2181 end;
2182 end;
2184 procedure g_Weapon_Draw();
2185 var
2186 i: Integer;
2187 a: SmallInt;
2188 p: TPoint;
2189 begin
2190 if Shots = nil then
2191 Exit;
2193 for i := 0 to High(Shots) do
2194 if Shots[i].ShotType <> 0 then
2195 with Shots[i] do
2196 begin
2197 if (Shots[i].ShotType = WEAPON_ROCKETLAUNCHER) or
2198 (Shots[i].ShotType = WEAPON_BARON_FIRE) or
2199 (Shots[i].ShotType = WEAPON_MANCUB_FIRE) or
2200 (Shots[i].ShotType = WEAPON_SKEL_FIRE) then
2201 a := -GetAngle2(Obj.Vel.X, Obj.Vel.Y)
2202 else
2203 a := 0;
2205 p.X := Obj.Rect.Width div 2;
2206 p.Y := Obj.Rect.Height div 2;
2208 if Animation <> nil then
2209 begin
2210 if (Shots[i].ShotType = WEAPON_BARON_FIRE) or
2211 (Shots[i].ShotType = WEAPON_MANCUB_FIRE) or
2212 (Shots[i].ShotType = WEAPON_SKEL_FIRE) then
2213 Animation.DrawEx(Obj.X, Obj.Y, M_NONE, p, a)
2214 else
2215 Animation.Draw(Obj.X, Obj.Y, M_NONE);
2216 end
2217 else if TextureID <> 0 then
2218 begin
2219 if (Shots[i].ShotType = WEAPON_ROCKETLAUNCHER) then
2220 e_DrawAdv(TextureID, Obj.X, Obj.Y, 0, True, False, a, @p, M_NONE)
2221 else if (Shots[i].ShotType <> WEAPON_FLAMETHROWER) then
2222 e_Draw(TextureID, Obj.X, Obj.Y, 0, True, False);
2223 end;
2225 if g_debug_Frames then
2226 begin
2227 e_DrawQuad(Obj.X+Obj.Rect.X,
2228 Obj.Y+Obj.Rect.Y,
2229 Obj.X+Obj.Rect.X+Obj.Rect.Width-1,
2230 Obj.Y+Obj.Rect.Y+Obj.Rect.Height-1,
2231 0, 255, 0);
2232 end;
2233 end;
2234 end;
2236 function g_Weapon_Danger(UID: Word; X, Y: Integer; Width, Height: Word; Time: Byte): Boolean;
2237 var
2238 a: Integer;
2239 begin
2240 Result := False;
2242 if Shots = nil then
2243 Exit;
2245 for a := 0 to High(Shots) do
2246 if (Shots[a].ShotType <> 0) and (Shots[a].SpawnerUID <> UID) then
2247 if ((Shots[a].Obj.Vel.Y = 0) and (Shots[a].Obj.Vel.X > 0) and (Shots[a].Obj.X < X)) or
2248 (Shots[a].Obj.Vel.Y = 0) and (Shots[a].Obj.Vel.X < 0) and (Shots[a].Obj.X > X) then
2249 if (Abs(X-Shots[a].Obj.X) < Abs(Shots[a].Obj.Vel.X*Time)) and
2250 g_Collide(X, Y, Width, Height, X, Shots[a].Obj.Y,
2251 Shots[a].Obj.Rect.Width, Shots[a].Obj.Rect.Height) and
2252 g_TraceVector(X, Y, Shots[a].Obj.X, Shots[a].Obj.Y) then
2253 begin
2254 Result := True;
2255 Exit;
2256 end;
2257 end;
2259 procedure g_Weapon_SaveState(var Mem: TBinMemoryWriter);
2260 var
2261 count, i, j: Integer;
2262 dw: DWORD;
2263 begin
2264 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ ñíàðÿäîâ:
2265 count := 0;
2266 if Shots <> nil then
2267 for i := 0 to High(Shots) do
2268 if Shots[i].ShotType <> 0 then
2269 count := count + 1;
2271 Mem := TBinMemoryWriter.Create((count+1) * 80);
2273 // Êîëè÷åñòâî ñíàðÿäîâ:
2274 Mem.WriteInt(count);
2276 if count = 0 then
2277 Exit;
2279 for i := 0 to High(Shots) do
2280 if Shots[i].ShotType <> 0 then
2281 begin
2282 // Ñèãíàòóðà ñíàðÿäà:
2283 dw := SHOT_SIGNATURE; // 'SHOT'
2284 Mem.WriteDWORD(dw);
2285 // Òèï ñíàðÿäà:
2286 Mem.WriteByte(Shots[i].ShotType);
2287 // Öåëü:
2288 Mem.WriteWord(Shots[i].Target);
2289 // UID ñòðåëÿâøåãî:
2290 Mem.WriteWord(Shots[i].SpawnerUID);
2291 // Ðàçìåð ïîëÿ Triggers:
2292 dw := Length(Shots[i].Triggers);
2293 Mem.WriteDWORD(dw);
2294 // Òðèããåðû, àêòèâèðîâàííûå âûñòðåëîì:
2295 for j := 0 to Integer(dw)-1 do
2296 Mem.WriteDWORD(Shots[i].Triggers[j]);
2297 // Îáúåêò ñíàðÿäà:
2298 Obj_SaveState(@Shots[i].Obj, Mem);
2299 // Êîñòûëèíà åáàíàÿ:
2300 Mem.WriteByte(Shots[i].Stopped);
2301 end;
2302 end;
2304 procedure g_Weapon_LoadState(var Mem: TBinMemoryReader);
2305 var
2306 count, i, j: Integer;
2307 dw: DWORD;
2308 begin
2309 if Mem = nil then
2310 Exit;
2312 // Êîëè÷åñòâî ñíàðÿäîâ:
2313 Mem.ReadInt(count);
2315 SetLength(Shots, count);
2317 if count = 0 then
2318 Exit;
2320 for i := 0 to count-1 do
2321 begin
2322 // Ñèãíàòóðà ñíàðÿäà:
2323 Mem.ReadDWORD(dw);
2324 if dw <> SHOT_SIGNATURE then // 'SHOT'
2325 begin
2326 raise EBinSizeError.Create('g_Weapons_LoadState: Wrong Shot Signature');
2327 end;
2328 // Òèï ñíàðÿäà:
2329 Mem.ReadByte(Shots[i].ShotType);
2330 // Öåëü:
2331 Mem.ReadWord(Shots[i].Target);
2332 // UID ñòðåëÿâøåãî:
2333 Mem.ReadWord(Shots[i].SpawnerUID);
2334 // Ðàçìåð ïîëÿ Triggers:
2335 Mem.ReadDWORD(dw);
2336 SetLength(Shots[i].Triggers, dw);
2337 // Òðèããåðû, àêòèâèðîâàííûå âûñòðåëîì:
2338 for j := 0 to Integer(dw)-1 do
2339 Mem.ReadDWORD(Shots[i].Triggers[j]);
2340 // Îáúåêò ïðåäìåòà:
2341 Obj_LoadState(@Shots[i].Obj, Mem);
2342 // Êîñòûëèíà åáàíàÿ:
2343 Mem.ReadByte(Shots[i].Stopped);
2345 // Óñòàíîâêà òåêñòóðû èëè àíèìàöèè:
2346 Shots[i].TextureID := DWORD(-1);
2347 Shots[i].Animation := nil;
2349 case Shots[i].ShotType of
2350 WEAPON_ROCKETLAUNCHER, WEAPON_SKEL_FIRE:
2351 begin
2352 g_Texture_Get('TEXTURE_WEAPON_ROCKET', Shots[i].TextureID);
2353 end;
2354 WEAPON_PLASMA:
2355 begin
2356 g_Frames_Get(dw, 'FRAMES_WEAPON_PLASMA');
2357 Shots[i].Animation := TAnimation.Create(dw, True, 5);
2358 end;
2359 WEAPON_BFG:
2360 begin
2361 g_Frames_Get(dw, 'FRAMES_WEAPON_BFG');
2362 Shots[i].Animation := TAnimation.Create(dw, True, 6);
2363 end;
2364 WEAPON_IMP_FIRE:
2365 begin
2366 g_Frames_Get(dw, 'FRAMES_WEAPON_IMPFIRE');
2367 Shots[i].Animation := TAnimation.Create(dw, True, 4);
2368 end;
2369 WEAPON_BSP_FIRE:
2370 begin
2371 g_Frames_Get(dw, 'FRAMES_WEAPON_BSPFIRE');
2372 Shots[i].Animation := TAnimation.Create(dw, True, 4);
2373 end;
2374 WEAPON_CACO_FIRE:
2375 begin
2376 g_Frames_Get(dw, 'FRAMES_WEAPON_CACOFIRE');
2377 Shots[i].Animation := TAnimation.Create(dw, True, 4);
2378 end;
2379 WEAPON_BARON_FIRE:
2380 begin
2381 g_Frames_Get(dw, 'FRAMES_WEAPON_BARONFIRE');
2382 Shots[i].Animation := TAnimation.Create(dw, True, 4);
2383 end;
2384 WEAPON_MANCUB_FIRE:
2385 begin
2386 g_Frames_Get(dw, 'FRAMES_WEAPON_MANCUBFIRE');
2387 Shots[i].Animation := TAnimation.Create(dw, True, 4);
2388 end;
2389 end;
2390 end;
2391 end;
2393 procedure g_Weapon_DestroyShot(I: Integer; X, Y: Integer; Loud: Boolean = True);
2394 var
2395 cx, cy: Integer;
2396 Anim: TAnimation;
2397 s: string;
2398 begin
2399 if Shots = nil then
2400 Exit;
2401 if (I > High(Shots)) or (I < 0) then Exit;
2403 with Shots[I] do
2404 begin
2405 if ShotType = 0 then Exit;
2406 Obj.X := X;
2407 Obj.Y := Y;
2408 cx := Obj.X + (Obj.Rect.Width div 2);
2409 cy := Obj.Y + (Obj.Rect.Height div 2);
2411 case ShotType of
2412 WEAPON_ROCKETLAUNCHER, WEAPON_SKEL_FIRE: // Ðàêåòû è ñíàðÿäû Ñêåëåòà
2413 begin
2414 if Loud then
2415 begin
2416 if ShotType = WEAPON_SKEL_FIRE then
2417 begin // Âçðûâ ñíàðÿäà Ñêåëåòà
2418 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_SKELFIRE') then
2419 begin
2420 Anim := TAnimation.Create(TextureID, False, 8);
2421 Anim.Blending := False;
2422 g_GFX_OnceAnim((Obj.X+32)-32, (Obj.Y+8)-32, Anim);
2423 Anim.Free();
2424 end;
2425 end
2426 else
2427 begin // Âçðûâ Ðàêåòû
2428 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_ROCKET') then
2429 begin
2430 Anim := TAnimation.Create(TextureID, False, 6);
2431 Anim.Blending := False;
2432 g_GFX_OnceAnim(cx-64, cy-64, Anim);
2433 Anim.Free();
2434 end;
2435 end;
2436 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', Obj.X, Obj.Y);
2437 end;
2438 end;
2440 WEAPON_PLASMA, WEAPON_BSP_FIRE: // Ïëàçìà, ïëàçìà Àðàõíàòðîíà
2441 begin
2442 if ShotType = WEAPON_PLASMA then
2443 s := 'FRAMES_EXPLODE_PLASMA'
2444 else
2445 s := 'FRAMES_EXPLODE_BSPFIRE';
2447 if g_Frames_Get(TextureID, s) and loud then
2448 begin
2449 Anim := TAnimation.Create(TextureID, False, 3);
2450 Anim.Blending := False;
2451 g_GFX_OnceAnim(cx-16, cy-16, Anim);
2452 Anim.Free();
2454 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEPLASMA', Obj.X, Obj.Y);
2455 end;
2456 end;
2458 WEAPON_BFG: // BFG
2459 begin
2460 // Âçðûâ BFG:
2461 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_BFG') and Loud then
2462 begin
2463 Anim := TAnimation.Create(TextureID, False, 6);
2464 Anim.Blending := False;
2465 g_GFX_OnceAnim(cx-64, cy-64, Anim);
2466 Anim.Free();
2468 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', Obj.X, Obj.Y);
2469 end;
2470 end;
2472 WEAPON_IMP_FIRE, WEAPON_CACO_FIRE, WEAPON_BARON_FIRE: // Âûñòðåëû Áåñà, Êàêîäåìîíà Ðûöàðÿ/Áàðîíà àäà
2473 begin
2474 if ShotType = WEAPON_IMP_FIRE then
2475 s := 'FRAMES_EXPLODE_IMPFIRE'
2476 else
2477 if ShotType = WEAPON_CACO_FIRE then
2478 s := 'FRAMES_EXPLODE_CACOFIRE'
2479 else
2480 s := 'FRAMES_EXPLODE_BARONFIRE';
2482 if g_Frames_Get(TextureID, s) and Loud then
2483 begin
2484 Anim := TAnimation.Create(TextureID, False, 6);
2485 Anim.Blending := False;
2486 g_GFX_OnceAnim(cx-32, cy-32, Anim);
2487 Anim.Free();
2489 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj.X, Obj.Y);
2490 end;
2491 end;
2493 WEAPON_MANCUB_FIRE: // Âûñòðåë Ìàíêóáóñà
2494 begin
2495 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_ROCKET') and Loud then
2496 begin
2497 Anim := TAnimation.Create(TextureID, False, 6);
2498 Anim.Blending := False;
2499 g_GFX_OnceAnim(cx-64, cy-64, Anim);
2500 Anim.Free();
2502 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj.X, Obj.Y);
2503 end;
2504 end;
2505 end; // case ShotType of...
2507 ShotType := 0;
2508 Animation.Free();
2509 end;
2510 end;
2513 procedure g_Weapon_AddDynLights();
2514 var
2515 i: Integer;
2516 begin
2517 if Shots = nil then Exit;
2518 for i := 0 to High(Shots) do
2519 begin
2520 if Shots[i].ShotType = 0 then continue;
2521 if (Shots[i].ShotType = WEAPON_ROCKETLAUNCHER) or
2522 (Shots[i].ShotType = WEAPON_BARON_FIRE) or
2523 (Shots[i].ShotType = WEAPON_MANCUB_FIRE) or
2524 (Shots[i].ShotType = WEAPON_SKEL_FIRE) or
2525 (Shots[i].ShotType = WEAPON_IMP_FIRE) or
2526 (Shots[i].ShotType = WEAPON_CACO_FIRE) or
2527 (Shots[i].ShotType = WEAPON_MANCUB_FIRE) or
2528 (Shots[i].ShotType = WEAPON_BSP_FIRE) or
2529 (Shots[i].ShotType = WEAPON_PLASMA) or
2530 (Shots[i].ShotType = WEAPON_BFG) or
2531 (Shots[i].ShotType = WEAPON_FLAMETHROWER) or
2532 false then
2533 begin
2534 if (Shots[i].ShotType = WEAPON_PLASMA) then
2535 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)
2536 else if (Shots[i].ShotType = WEAPON_BFG) then
2537 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)
2538 else if (Shots[i].ShotType = WEAPON_FLAMETHROWER) then
2539 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)
2540 else
2541 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);
2542 end;
2543 end;
2544 end;
2547 procedure TShot.positionChanged (); begin end;
2550 end.