DEADSOFTWARE

turned on "SCOPEDENUMS" fpc option
[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 {.$DEFINE GWEP_HITSCAN_TRACE_BITMAP_CHECKER}
18 unit g_weapons;
20 interface
22 uses
23 SysUtils, Classes,
24 g_textures, g_basic, e_graphics, g_phys, xprofiler;
27 type
28 TShot = record
29 ShotType: Byte;
30 Target: Word;
31 SpawnerUID: Word;
32 Triggers: DWArray;
33 Obj: TObj;
34 Animation: TAnimation;
35 TextureID: DWORD;
36 Timeout: DWORD;
37 Stopped: Byte;
39 procedure positionChanged (); //WARNING! call this after monster position was changed, or coldet will not work right!
40 end;
43 var
44 Shots: array of TShot = nil;
45 LastShotID: Integer = 0;
47 procedure g_Weapon_LoadData();
48 procedure g_Weapon_FreeData();
49 procedure g_Weapon_Init();
50 procedure g_Weapon_Free();
51 function g_Weapon_Hit(obj: PObj; d: Integer; SpawnerUID: Word; t: Byte; HitCorpses: Boolean = True): Byte;
52 function g_Weapon_HitUID(UID: Word; d: Integer; SpawnerUID: Word; t: Byte): Boolean;
53 function g_Weapon_CreateShot(I: Integer; ShotType: Byte; Spawner, TargetUID: Word; X, Y, XV, YV: Integer): LongWord;
55 procedure g_Weapon_gun(const x, y, xd, yd, v, dmg: Integer; SpawnerUID: Word; CheckTrigger: Boolean);
56 procedure g_Weapon_punch(x, y: Integer; d, SpawnerUID: Word);
57 function g_Weapon_chainsaw(x, y: Integer; d, SpawnerUID: Word): Integer;
58 procedure g_Weapon_rocket(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1; Silent: Boolean = False);
59 procedure g_Weapon_revf(x, y, xd, yd: Integer; SpawnerUID, TargetUID: Word; WID: Integer = -1; Silent: Boolean = False);
60 procedure g_Weapon_flame(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1; Silent: Boolean = False);
61 procedure g_Weapon_plasma(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1; Silent: Boolean = False);
62 procedure g_Weapon_ball1(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1; Silent: Boolean = False);
63 procedure g_Weapon_ball2(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1; Silent: Boolean = False);
64 procedure g_Weapon_ball7(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1; Silent: Boolean = False);
65 procedure g_Weapon_aplasma(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1; Silent: Boolean = False);
66 procedure g_Weapon_manfire(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1; Silent: Boolean = False);
67 procedure g_Weapon_bfgshot(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1; Silent: Boolean = False);
68 procedure g_Weapon_bfghit(x, y: Integer);
69 procedure g_Weapon_pistol(x, y, xd, yd: Integer; SpawnerUID: Word; Silent: Boolean = False);
70 procedure g_Weapon_mgun(x, y, xd, yd: Integer; SpawnerUID: Word; Silent: Boolean = False);
71 procedure g_Weapon_shotgun(x, y, xd, yd: Integer; SpawnerUID: Word; Silent: Boolean = False);
72 procedure g_Weapon_dshotgun(x, y, xd, yd: Integer; SpawnerUID: Word; Silent: Boolean = False);
74 function g_Weapon_Explode(X, Y: Integer; rad: Integer; SpawnerUID: Word): Boolean;
75 procedure g_Weapon_BFG9000(X, Y: Integer; SpawnerUID: Word);
76 procedure g_Weapon_Update();
77 procedure g_Weapon_Draw();
78 function g_Weapon_Danger(UID: Word; X, Y: Integer; Width, Height: Word; Time: Byte): Boolean;
79 procedure g_Weapon_DestroyShot(I: Integer; X, Y: Integer; Loud: Boolean = True);
81 procedure g_Weapon_SaveState (st: TStream);
82 procedure g_Weapon_LoadState (st: TStream);
84 procedure g_Weapon_AddDynLights();
86 const
87 WEAPON_KASTET = 0;
88 WEAPON_SAW = 1;
89 WEAPON_PISTOL = 2;
90 WEAPON_SHOTGUN1 = 3;
91 WEAPON_SHOTGUN2 = 4;
92 WEAPON_CHAINGUN = 5;
93 WEAPON_ROCKETLAUNCHER = 6;
94 WEAPON_PLASMA = 7;
95 WEAPON_BFG = 8;
96 WEAPON_SUPERPULEMET = 9;
97 WEAPON_FLAMETHROWER = 10;
98 WEAPON_ZOMBY_PISTOL = 20;
99 WEAPON_IMP_FIRE = 21;
100 WEAPON_BSP_FIRE = 22;
101 WEAPON_CACO_FIRE = 23;
102 WEAPON_BARON_FIRE = 24;
103 WEAPON_MANCUB_FIRE = 25;
104 WEAPON_SKEL_FIRE = 26;
106 WP_FIRST = WEAPON_KASTET;
107 WP_LAST = WEAPON_FLAMETHROWER;
110 var
111 gwep_debug_fast_trace: Boolean = true;
114 implementation
116 uses
117 Math, g_map, g_player, g_gfx, g_sound, g_main, g_panel,
118 g_console, g_options, g_game,
119 g_triggers, MAPDEF, e_log, g_monsters, g_saveload,
120 g_language, g_netmsg, g_grid,
121 binheap, hashtable, utils, xstreams;
123 type
124 TWaterPanel = record
125 X, Y: Integer;
126 Width, Height: Word;
127 Active: Boolean;
128 end;
130 const
131 SHOT_ROCKETLAUNCHER_WIDTH = 14;
132 SHOT_ROCKETLAUNCHER_HEIGHT = 14;
134 SHOT_SKELFIRE_WIDTH = 14;
135 SHOT_SKELFIRE_HEIGHT = 14;
137 SHOT_PLASMA_WIDTH = 16;
138 SHOT_PLASMA_HEIGHT = 16;
140 SHOT_BFG_WIDTH = 32;
141 SHOT_BFG_HEIGHT = 32;
142 SHOT_BFG_DAMAGE = 100;
143 SHOT_BFG_RADIUS = 256;
145 SHOT_FLAME_WIDTH = 4;
146 SHOT_FLAME_HEIGHT = 4;
147 SHOT_FLAME_LIFETIME = 180;
149 SHOT_SIGNATURE = $544F4853; // 'SHOT'
151 type
152 PHitTime = ^THitTime;
153 THitTime = record
154 distSq: Integer;
155 mon: TMonster;
156 plridx: Integer; // if mon=nil
157 x, y: Integer;
158 end;
160 // indicies in `wgunHitTime` array
161 TBinaryHeapHitTimes = specialize TBinaryHeapBase<Integer>;
163 var
164 WaterMap: array of array of DWORD = nil;
165 //wgunMonHash: THashIntInt = nil;
166 wgunHitHeap: TBinaryHeapHitTimes = nil;
167 wgunHitTime: array of THitTime = nil;
168 wgunHitTimeUsed: Integer = 0;
171 function hitTimeLess (a, b: Integer): Boolean;
172 var
173 hta, htb: PHitTime;
174 begin
175 hta := @wgunHitTime[a];
176 htb := @wgunHitTime[b];
177 if (hta.distSq <> htb.distSq) then begin result := (hta.distSq < htb.distSq); exit; end;
178 if (hta.mon <> nil) then
179 begin
180 // a is monster
181 if (htb.mon = nil) then begin result := false; exit; end; // players first
182 result := (hta.mon.UID < htb.mon.UID); // why not?
183 end
184 else
185 begin
186 // a is player
187 if (htb.mon <> nil) then begin result := true; exit; end; // players first
188 result := (hta.plridx < htb.plridx); // why not?
189 end;
190 end;
193 procedure appendHitTimeMon (adistSq: Integer; amon: TMonster; ax, ay: Integer);
194 begin
195 if (wgunHitTimeUsed = Length(wgunHitTime)) then SetLength(wgunHitTime, wgunHitTimeUsed+128);
196 with wgunHitTime[wgunHitTimeUsed] do
197 begin
198 distSq := adistSq;
199 mon := amon;
200 plridx := -1;
201 x := ax;
202 y := ay;
203 end;
204 wgunHitHeap.insert(wgunHitTimeUsed);
205 Inc(wgunHitTimeUsed);
206 end;
209 procedure appendHitTimePlr (adistSq: Integer; aplridx: Integer; ax, ay: Integer);
210 begin
211 if (wgunHitTimeUsed = Length(wgunHitTime)) then SetLength(wgunHitTime, wgunHitTimeUsed+128);
212 with wgunHitTime[wgunHitTimeUsed] do
213 begin
214 distSq := adistSq;
215 mon := nil;
216 plridx := aplridx;
217 x := ax;
218 y := ay;
219 end;
220 wgunHitHeap.insert(wgunHitTimeUsed);
221 Inc(wgunHitTimeUsed);
222 end;
225 function FindShot(): DWORD;
226 var
227 i: Integer;
228 begin
229 if Shots <> nil then
230 for i := 0 to High(Shots) do
231 if Shots[i].ShotType = 0 then
232 begin
233 Result := i;
234 LastShotID := Result;
235 Exit;
236 end;
238 if Shots = nil then
239 begin
240 SetLength(Shots, 128);
241 Result := 0;
242 end
243 else
244 begin
245 Result := High(Shots) + 1;
246 SetLength(Shots, Length(Shots) + 128);
247 end;
248 LastShotID := Result;
249 end;
251 procedure CreateWaterMap();
252 var
253 WaterArray: Array of TWaterPanel;
254 a, b, c, m: Integer;
255 ok: Boolean;
256 begin
257 if gWater = nil then
258 Exit;
260 SetLength(WaterArray, Length(gWater));
262 for a := 0 to High(gWater) do
263 begin
264 WaterArray[a].X := gWater[a].X;
265 WaterArray[a].Y := gWater[a].Y;
266 WaterArray[a].Width := gWater[a].Width;
267 WaterArray[a].Height := gWater[a].Height;
268 WaterArray[a].Active := True;
269 end;
271 g_Game_SetLoadingText(_lc[I_LOAD_WATER_MAP], High(WaterArray), False);
273 for a := 0 to High(WaterArray) do
274 if WaterArray[a].Active then
275 begin
276 WaterArray[a].Active := False;
277 m := Length(WaterMap);
278 SetLength(WaterMap, m+1);
279 SetLength(WaterMap[m], 1);
280 WaterMap[m][0] := a;
281 ok := True;
283 while ok do
284 begin
285 ok := False;
286 for b := 0 to High(WaterArray) do
287 if WaterArray[b].Active then
288 for c := 0 to High(WaterMap[m]) do
289 if g_CollideAround(WaterArray[b].X,
290 WaterArray[b].Y,
291 WaterArray[b].Width,
292 WaterArray[b].Height,
293 WaterArray[WaterMap[m][c]].X,
294 WaterArray[WaterMap[m][c]].Y,
295 WaterArray[WaterMap[m][c]].Width,
296 WaterArray[WaterMap[m][c]].Height) then
297 begin
298 WaterArray[b].Active := False;
299 SetLength(WaterMap[m],
300 Length(WaterMap[m])+1);
301 WaterMap[m][High(WaterMap[m])] := b;
302 ok := True;
303 Break;
304 end;
305 end;
307 g_Game_StepLoading();
308 end;
310 WaterArray := nil;
311 end;
314 var
315 chkTrap_pl: array [0..256] of Integer;
316 chkTrap_mn: array [0..65535] of TMonster;
318 procedure CheckTrap(ID: DWORD; dm: Integer; t: Byte);
319 var
320 //a, b, c, d, i1, i2: Integer;
321 //chkTrap_pl, chkTrap_mn: WArray;
322 plaCount: Integer = 0;
323 mnaCount: Integer = 0;
324 frameId: DWord;
327 function monsWaterCheck (mon: TMonster): Boolean;
328 begin
329 result := false; // don't stop
330 if mon.alive and mon.Collide(gWater[WaterMap[a][c]]) and (not InWArray(monidx, chkTrap_mn)) and (i2 < 1023) then //FIXME
331 begin
332 i2 += 1;
333 chkTrap_mn[i2] := monidx;
334 end;
335 end;
338 function monsWaterCheck (mon: TMonster): Boolean;
339 begin
340 result := false; // don't stop
341 if (mon.trapCheckFrameId <> frameId) then
342 begin
343 mon.trapCheckFrameId := frameId;
344 chkTrap_mn[mnaCount] := mon;
345 Inc(mnaCount);
346 end;
347 end;
349 var
350 a, b, c, d, f: Integer;
351 pan: TPanel;
352 begin
353 if (gWater = nil) or (WaterMap = nil) then Exit;
355 frameId := g_Mons_getNewTrapFrameId();
357 //i1 := -1;
358 //i2 := -1;
360 //SetLength(chkTrap_pl, 1024);
361 //SetLength(chkTrap_mn, 1024);
362 //for d := 0 to 1023 do chkTrap_pl[d] := $FFFF;
363 //for d := 0 to 1023 do chkTrap_mn[d] := $FFFF;
365 for a := 0 to High(WaterMap) do
366 begin
367 for b := 0 to High(WaterMap[a]) do
368 begin
369 pan := gWater[WaterMap[a][b]];
370 if not g_Obj_Collide(pan.X, pan.Y, pan.Width, pan.Height, @Shots[ID].Obj) then continue;
372 for c := 0 to High(WaterMap[a]) do
373 begin
374 pan := gWater[WaterMap[a][c]];
375 for d := 0 to High(gPlayers) do
376 begin
377 if (gPlayers[d] <> nil) and (gPlayers[d].alive) then
378 begin
379 if gPlayers[d].Collide(pan) then
380 begin
381 f := 0;
382 while (f < plaCount) and (chkTrap_pl[f] <> d) do Inc(f);
383 if (f = plaCount) then
384 begin
385 chkTrap_pl[plaCount] := d;
386 Inc(plaCount);
387 if (plaCount = Length(chkTrap_pl)) then break;
388 end;
389 end;
390 end;
391 end;
393 //g_Mons_ForEach(monsWaterCheck);
394 g_Mons_ForEachAliveAt(pan.X, pan.Y, pan.Width, pan.Height, monsWaterCheck);
395 end;
397 for f := 0 to plaCount-1 do gPlayers[chkTrap_pl[f]].Damage(dm, Shots[ID].SpawnerUID, 0, 0, t);
398 for f := 0 to mnaCount-1 do chkTrap_mn[f].Damage(dm, 0, 0, Shots[ID].SpawnerUID, t);
399 end;
400 end;
402 //chkTrap_pl := nil;
403 //chkTrap_mn := nil;
404 end;
406 function HitMonster(m: TMonster; d: Integer; vx, vy: Integer; SpawnerUID: Word; t: Byte): Boolean;
407 var
408 tt, mt: Byte;
409 mon: TMonster;
410 begin
411 Result := False;
413 tt := g_GetUIDType(SpawnerUID);
414 if tt = UID_MONSTER then
415 begin
416 mon := g_Monsters_ByUID(SpawnerUID);
417 if mon <> nil then
418 mt := g_Monsters_ByUID(SpawnerUID).MonsterType
419 else
420 mt := 0;
421 end
422 else
423 mt := 0;
425 if m = nil then Exit;
426 if m.UID = SpawnerUID then
427 begin
428 // Ñàì ñåáÿ ìîæåò ðàíèòü òîëüêî ðàêåòîé è òîêîì:
429 if (t <> HIT_ROCKET) and (t <> HIT_ELECTRO) then
430 Exit;
431 // Êèáåð äåìîí è áî÷êà âîîáùå íå ìîãóò ñåáÿ ðàíèòü:
432 if (m.MonsterType = MONSTER_CYBER) or
433 (m.MonsterType = MONSTER_BARREL) then
434 begin
435 Result := True;
436 Exit;
437 end;
438 end;
440 if tt = UID_MONSTER then
441 begin
442 // Lost_Soul íå ìîæåò ðàíèòü Pain_Elemental'à:
443 if (mt = MONSTER_SOUL) and (m.MonsterType = MONSTER_PAIN) then
444 Exit;
446 // Îáà ìîíñòðà îäíîãî âèäà:
447 if mt = m.MonsterType then
448 case mt of
449 MONSTER_IMP, MONSTER_DEMON, MONSTER_BARON, MONSTER_KNIGHT, MONSTER_CACO,
450 MONSTER_SOUL, MONSTER_MANCUB, MONSTER_SKEL, MONSTER_FISH:
451 Exit; // Ýòè íå áüþò ñâîèõ
452 end;
453 end;
455 if g_Game_IsServer then
456 begin
457 if (t <> HIT_FLAME) or (m.FFireTime = 0) or (vx <> 0) or (vy <> 0) then
458 Result := m.Damage(d, vx, vy, SpawnerUID, t)
459 else
460 Result := True;
461 if t = HIT_FLAME then
462 m.CatchFire(SpawnerUID);
463 end
464 else
465 Result := True;
466 end;
469 function HitPlayer (p: TPlayer; d: Integer; vx, vy: Integer; SpawnerUID: Word; t: Byte): Boolean;
470 begin
471 result := False;
473 // Ñàì ñåáÿ ìîæåò ðàíèòü òîëüêî ðàêåòîé è òîêîì
474 if (p.UID = SpawnerUID) and (t <> HIT_ROCKET) and (t <> HIT_ELECTRO) then exit;
476 if g_Game_IsServer then
477 begin
478 if (t <> HIT_FLAME) or (p.FFireTime = 0) or (vx <> 0) or (vy <> 0) then p.Damage(d, SpawnerUID, vx, vy, t);
479 if (t = HIT_FLAME) then p.CatchFire(SpawnerUID);
480 end;
482 result := true;
483 end;
486 procedure g_Weapon_BFG9000(X, Y: Integer; SpawnerUID: Word);
488 function monsCheck (mon: TMonster): Boolean;
489 begin
490 result := false; // don't stop
491 if (mon.alive) and (mon.UID <> SpawnerUID) then
492 begin
493 with mon do
494 begin
495 if (g_PatchLength(X, Y, Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2),
496 Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)) <= SHOT_BFG_RADIUS) and
497 g_TraceVector(X, Y, Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2),
498 Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)) then
499 begin
500 if HitMonster(mon, 50, 0, 0, SpawnerUID, HIT_SOME) then mon.BFGHit();
501 end;
502 end;
503 end;
504 end;
506 var
507 i, h: Integer;
508 st: Byte;
509 pl: TPlayer;
510 b: Boolean;
511 begin
512 //g_Sound_PlayEx('SOUND_WEAPON_EXPLODEBFG', 255);
514 h := High(gCorpses);
516 if gAdvCorpses and (h <> -1) then
517 for i := 0 to h do
518 if (gCorpses[i] <> nil) and (gCorpses[i].State <> CORPSE_STATE_REMOVEME) then
519 with gCorpses[i] do
520 if (g_PatchLength(X, Y, Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2),
521 Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)) <= SHOT_BFG_RADIUS) and
522 g_TraceVector(X, Y, Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2),
523 Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)) then
524 begin
525 Damage(50, 0, 0);
526 g_Weapon_BFGHit(Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2),
527 Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2));
528 end;
530 st := TEAM_NONE;
531 pl := g_Player_Get(SpawnerUID);
532 if pl <> nil then
533 st := pl.Team;
535 h := High(gPlayers);
537 if h <> -1 then
538 for i := 0 to h do
539 if (gPlayers[i] <> nil) and (gPlayers[i].alive) and (gPlayers[i].UID <> SpawnerUID) then
540 with gPlayers[i] do
541 if (g_PatchLength(X, Y, GameX+PLAYER_RECT.X+(PLAYER_RECT.Width div 2),
542 GameY+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)) <= SHOT_BFG_RADIUS) and
543 g_TraceVector(X, Y, GameX+PLAYER_RECT.X+(PLAYER_RECT.Width div 2),
544 GameY+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)) then
545 begin
546 if (st = TEAM_NONE) or (st <> gPlayers[i].Team) then
547 b := HitPlayer(gPlayers[i], 50, 0, 0, SpawnerUID, HIT_SOME)
548 else
549 b := HitPlayer(gPlayers[i], 25, 0, 0, SpawnerUID, HIT_SOME);
550 if b then
551 gPlayers[i].BFGHit();
552 end;
554 //FIXME
555 g_Mons_ForEachAlive(monsCheck);
556 end;
558 function g_Weapon_CreateShot(I: Integer; ShotType: Byte; Spawner, TargetUID: Word; X, Y, XV, YV: Integer): LongWord;
559 var
560 find_id: DWord;
561 FramesID: DWORD = 0;
562 begin
563 if I < 0 then
564 find_id := FindShot()
565 else
566 begin
567 find_id := I;
568 if Integer(find_id) >= High(Shots) then
569 SetLength(Shots, find_id + 64)
570 end;
572 case ShotType of
573 WEAPON_ROCKETLAUNCHER:
574 begin
575 with Shots[find_id] do
576 begin
577 g_Obj_Init(@Obj);
579 Obj.Rect.Width := SHOT_ROCKETLAUNCHER_WIDTH;
580 Obj.Rect.Height := SHOT_ROCKETLAUNCHER_HEIGHT;
582 Animation := nil;
583 Triggers := nil;
584 ShotType := WEAPON_ROCKETLAUNCHER;
585 g_Texture_Get('TEXTURE_WEAPON_ROCKET', TextureID);
586 end;
587 end;
589 WEAPON_PLASMA:
590 begin
591 with Shots[find_id] do
592 begin
593 g_Obj_Init(@Obj);
595 Obj.Rect.Width := SHOT_PLASMA_WIDTH;
596 Obj.Rect.Height := SHOT_PLASMA_HEIGHT;
598 Triggers := nil;
599 ShotType := WEAPON_PLASMA;
600 g_Frames_Get(FramesID, 'FRAMES_WEAPON_PLASMA');
601 Animation := TAnimation.Create(FramesID, True, 5);
602 end;
603 end;
605 WEAPON_BFG:
606 begin
607 with Shots[find_id] do
608 begin
609 g_Obj_Init(@Obj);
611 Obj.Rect.Width := SHOT_BFG_WIDTH;
612 Obj.Rect.Height := SHOT_BFG_HEIGHT;
614 Triggers := nil;
615 ShotType := WEAPON_BFG;
616 g_Frames_Get(FramesID, 'FRAMES_WEAPON_BFG');
617 Animation := TAnimation.Create(FramesID, True, 6);
618 end;
619 end;
621 WEAPON_FLAMETHROWER:
622 begin
623 with Shots[find_id] do
624 begin
625 g_Obj_Init(@Obj);
627 Obj.Rect.Width := SHOT_FLAME_WIDTH;
628 Obj.Rect.Height := SHOT_FLAME_HEIGHT;
630 Triggers := nil;
631 ShotType := WEAPON_FLAMETHROWER;
632 Animation := nil;
633 TextureID := 0;
634 g_Frames_Get(TextureID, 'FRAMES_FLAME');
635 end;
636 end;
638 WEAPON_IMP_FIRE:
639 begin
640 with Shots[find_id] do
641 begin
642 g_Obj_Init(@Obj);
644 Obj.Rect.Width := 16;
645 Obj.Rect.Height := 16;
647 Triggers := nil;
648 ShotType := WEAPON_IMP_FIRE;
649 g_Frames_Get(FramesID, 'FRAMES_WEAPON_IMPFIRE');
650 Animation := TAnimation.Create(FramesID, True, 4);
651 end;
652 end;
654 WEAPON_CACO_FIRE:
655 begin
656 with Shots[find_id] do
657 begin
658 g_Obj_Init(@Obj);
660 Obj.Rect.Width := 16;
661 Obj.Rect.Height := 16;
663 Triggers := nil;
664 ShotType := WEAPON_CACO_FIRE;
665 g_Frames_Get(FramesID, 'FRAMES_WEAPON_CACOFIRE');
666 Animation := TAnimation.Create(FramesID, True, 4);
667 end;
668 end;
670 WEAPON_MANCUB_FIRE:
671 begin
672 with Shots[find_id] do
673 begin
674 g_Obj_Init(@Obj);
676 Obj.Rect.Width := 32;
677 Obj.Rect.Height := 32;
679 Triggers := nil;
680 ShotType := WEAPON_MANCUB_FIRE;
681 g_Frames_Get(FramesID, 'FRAMES_WEAPON_MANCUBFIRE');
682 Animation := TAnimation.Create(FramesID, True, 4);
683 end;
684 end;
686 WEAPON_BARON_FIRE:
687 begin
688 with Shots[find_id] do
689 begin
690 g_Obj_Init(@Obj);
692 Obj.Rect.Width := 32;
693 Obj.Rect.Height := 16;
695 Triggers := nil;
696 ShotType := WEAPON_BARON_FIRE;
697 g_Frames_Get(FramesID, 'FRAMES_WEAPON_BARONFIRE');
698 Animation := TAnimation.Create(FramesID, True, 4);
699 end;
700 end;
702 WEAPON_BSP_FIRE:
703 begin
704 with Shots[find_id] do
705 begin
706 g_Obj_Init(@Obj);
708 Obj.Rect.Width := 16;
709 Obj.Rect.Height := 16;
711 Triggers := nil;
712 ShotType := WEAPON_BSP_FIRE;
713 g_Frames_Get(FramesID, 'FRAMES_WEAPON_BSPFIRE');
714 Animation := TAnimation.Create(FramesID, True, 4);
715 end;
716 end;
718 WEAPON_SKEL_FIRE:
719 begin
720 with Shots[find_id] do
721 begin
722 g_Obj_Init(@Obj);
724 Obj.Rect.Width := SHOT_SKELFIRE_WIDTH;
725 Obj.Rect.Height := SHOT_SKELFIRE_HEIGHT;
727 Triggers := nil;
728 ShotType := WEAPON_SKEL_FIRE;
729 target := TargetUID;
730 g_Frames_Get(FramesID, 'FRAMES_WEAPON_SKELFIRE');
731 Animation := TAnimation.Create(FramesID, True, 5);
732 end;
733 end;
734 end;
736 Shots[find_id].Obj.X := X;
737 Shots[find_id].Obj.Y := Y;
738 Shots[find_id].Obj.Vel.X := XV;
739 Shots[find_id].Obj.Vel.Y := YV;
740 Shots[find_id].Obj.Accel.X := 0;
741 Shots[find_id].Obj.Accel.Y := 0;
742 Shots[find_id].SpawnerUID := Spawner;
743 if (ShotType = WEAPON_FLAMETHROWER) and (XV = 0) and (YV = 0) then
744 Shots[find_id].Stopped := 255
745 else
746 Shots[find_id].Stopped := 0;
747 Result := find_id;
748 end;
750 procedure throw(i, x, y, xd, yd, s: Integer);
751 var
752 a: Integer;
753 begin
754 yd := yd - y;
755 xd := xd - x;
757 a := Max(Abs(xd), Abs(yd));
758 if a = 0 then
759 a := 1;
761 Shots[i].Obj.X := x;
762 Shots[i].Obj.Y := y;
763 Shots[i].Obj.Vel.X := (xd*s) div a;
764 Shots[i].Obj.Vel.Y := (yd*s) div a;
765 Shots[i].Obj.Accel.X := 0;
766 Shots[i].Obj.Accel.Y := 0;
767 Shots[i].Stopped := 0;
768 if Shots[i].ShotType in [WEAPON_ROCKETLAUNCHER, WEAPON_BFG] then
769 Shots[i].Timeout := 900 // ~25 sec
770 else
771 begin
772 if Shots[i].ShotType = WEAPON_FLAMETHROWER then
773 Shots[i].Timeout := SHOT_FLAME_LIFETIME
774 else
775 Shots[i].Timeout := 550; // ~15 sec
776 end;
777 end;
779 function g_Weapon_Hit(obj: PObj; d: Integer; SpawnerUID: Word; t: Byte; HitCorpses: Boolean = True): Byte;
780 var
781 i, h: Integer;
783 function PlayerHit(Team: Byte = 0): Boolean;
784 var
785 i: Integer;
786 ChkTeam: Boolean;
787 p: TPlayer;
788 begin
789 Result := False;
790 h := High(gPlayers);
792 if h <> -1 then
793 for i := 0 to h do
794 if (gPlayers[i] <> nil) and gPlayers[i].alive and g_Obj_Collide(obj, @gPlayers[i].Obj) then
795 begin
796 ChkTeam := True;
797 if (Team > 0) and (g_GetUIDType(SpawnerUID) = UID_PLAYER) then
798 begin
799 p := g_Player_Get(SpawnerUID);
800 if p <> nil then
801 ChkTeam := (p.Team = gPlayers[i].Team) xor (Team = 2);
802 end;
803 if ChkTeam then
804 if HitPlayer(gPlayers[i], d, obj^.Vel.X, obj^.Vel.Y, SpawnerUID, t) then
805 begin
806 if t <> HIT_FLAME then
807 gPlayers[i].Push((obj^.Vel.X+obj^.Accel.X)*IfThen(t = HIT_BFG, 8, 1) div 4,
808 (obj^.Vel.Y+obj^.Accel.Y)*IfThen(t = HIT_BFG, 8, 1) div 4);
809 if t = HIT_BFG then
810 g_Game_DelayEvent(DE_BFGHIT, 1000, SpawnerUID);
811 Result := True;
812 break;
813 end;
814 end;
815 end;
818 function monsCheckHit (monidx: Integer; mon: TMonster): Boolean;
819 begin
820 result := false; // don't stop
821 if mon.alive and g_Obj_Collide(obj, @mon.Obj) then
822 begin
823 if HitMonster(mon, d, obj^.Vel.X, obj^.Vel.Y, SpawnerUID, t) then
824 begin
825 if (t <> HIT_FLAME) then
826 begin
827 mon.Push((obj^.Vel.X+obj^.Accel.X)*IfThen(t = HIT_BFG, 8, 1) div 4,
828 (obj^.Vel.Y+obj^.Accel.Y)*IfThen(t = HIT_BFG, 8, 1) div 4);
829 end;
830 result := True;
831 end;
832 end;
833 end;
836 function monsCheckHit (mon: TMonster): Boolean;
837 begin
838 result := false; // don't stop
839 if HitMonster(mon, d, obj.Vel.X, obj.Vel.Y, SpawnerUID, t) then
840 begin
841 if (t <> HIT_FLAME) then
842 begin
843 mon.Push((obj.Vel.X+obj.Accel.X)*IfThen(t = HIT_BFG, 8, 1) div 4,
844 (obj.Vel.Y+obj.Accel.Y)*IfThen(t = HIT_BFG, 8, 1) div 4);
845 end;
846 result := true;
847 end;
848 end;
850 function MonsterHit(): Boolean;
851 begin
852 //result := g_Mons_ForEach(monsCheckHit);
853 //FIXME: accelerate this!
854 result := g_Mons_ForEachAliveAt(obj.X+obj.Rect.X, obj.Y+obj.Rect.Y, obj.Rect.Width, obj.Rect.Height, monsCheckHit);
855 end;
857 begin
858 Result := 0;
860 if HitCorpses then
861 begin
862 h := High(gCorpses);
864 if gAdvCorpses and (h <> -1) then
865 for i := 0 to h do
866 if (gCorpses[i] <> nil) and (gCorpses[i].State <> CORPSE_STATE_REMOVEME) and
867 g_Obj_Collide(obj, @gCorpses[i].Obj) then
868 begin
869 // Ðàñïèëèâàåì òðóï:
870 gCorpses[i].Damage(d, (obj^.Vel.X+obj^.Accel.X) div 4,
871 (obj^.Vel.Y+obj^.Accel.Y) div 4);
872 Result := 1;
873 end;
874 end;
876 case gGameSettings.GameMode of
877 // Êàìïàíèÿ:
878 GM_COOP, GM_SINGLE:
879 begin
880 // Ñíà÷àëà áü¸ì ìîíñòðîâ, åñëè åñòü, ïîòîì ïûòàåìñÿ áèòü èãðîêîâ
881 if MonsterHit() then
882 begin
883 Result := 2;
884 Exit;
885 end;
887 if PlayerHit() then
888 begin
889 Result := 1;
890 Exit;
891 end;
892 end;
894 // Äåçìàò÷:
895 GM_DM:
896 begin
897 // Ñíà÷àëà áü¸ì èãðîêîâ, åñëè åñòü, ïîòîì ïûòàåìñÿ áèòü ìîíñòðîâ
898 if PlayerHit() then
899 begin
900 Result := 1;
901 Exit;
902 end;
904 if MonsterHit() then
905 begin
906 Result := 2;
907 Exit;
908 end;
909 end;
911 // Êîìàíäíûå:
912 GM_TDM, GM_CTF:
913 begin
914 // Ñíà÷àëà áü¸ì èãðîêîâ êîìàíäû ñîïåðíèêà
915 if PlayerHit(2) then
916 begin
917 Result := 1;
918 Exit;
919 end;
921 // Ïîòîì ìîíñòðîâ
922 if MonsterHit() then
923 begin
924 Result := 2;
925 Exit;
926 end;
928 // È â êîíöå ñâîèõ èãðîêîâ
929 if PlayerHit(1) then
930 begin
931 Result := 1;
932 Exit;
933 end;
934 end;
936 end;
937 end;
939 function g_Weapon_HitUID(UID: Word; d: Integer; SpawnerUID: Word; t: Byte): Boolean;
940 begin
941 Result := False;
943 case g_GetUIDType(UID) of
944 UID_PLAYER: Result := HitPlayer(g_Player_Get(UID), d, 0, 0, SpawnerUID, t);
945 UID_MONSTER: Result := HitMonster(g_Monsters_ByUID(UID), d, 0, 0, SpawnerUID, t);
946 else Exit;
947 end;
948 end;
950 function g_Weapon_Explode(X, Y: Integer; rad: Integer; SpawnerUID: Word): Boolean;
951 var
952 r: Integer; // squared radius
954 function monsExCheck (mon: TMonster): Boolean;
955 var
956 dx, dy, mm: Integer;
957 begin
958 result := false; // don't stop
959 begin
960 dx := mon.Obj.X+mon.Obj.Rect.X+(mon.Obj.Rect.Width div 2)-X;
961 dy := mon.Obj.Y+mon.Obj.Rect.Y+(mon.Obj.Rect.Height div 2)-Y;
963 if dx > 1000 then dx := 1000;
964 if dy > 1000 then dy := 1000;
966 if (dx*dx+dy*dy < r) then
967 begin
968 //m := PointToRect(X, Y, Obj.X+Obj.Rect.X, Obj.Y+Obj.Rect.Y, Obj.Rect.Width, Obj.Rect.Height);
969 //e_WriteLog(Format('explo monster #%d: x=%d; y=%d; rad=%d; dx=%d; dy=%d', [monidx, X, Y, rad, dx, dy]), MSG_NOTIFY);
971 mm := Max(abs(dx), abs(dy));
972 if mm = 0 then mm := 1;
974 if mon.alive then
975 begin
976 HitMonster(mon, ((mon.Obj.Rect.Width div 4)*10*(rad-mm)) div rad, 0, 0, SpawnerUID, HIT_ROCKET);
977 end;
979 mon.Push((dx*7) div mm, (dy*7) div mm);
980 end;
981 end;
982 end;
984 var
985 i, h, dx, dy, m, mm: Integer;
986 _angle: SmallInt;
987 begin
988 result := false;
990 g_Triggers_PressC(X, Y, rad, SpawnerUID, ACTIVATE_SHOT);
992 r := rad*rad;
994 h := High(gPlayers);
996 if h <> -1 then
997 for i := 0 to h do
998 if (gPlayers[i] <> nil) and gPlayers[i].alive then
999 with gPlayers[i] do
1000 begin
1001 dx := Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2)-X;
1002 dy := Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)-Y;
1004 if dx > 1000 then dx := 1000;
1005 if dy > 1000 then dy := 1000;
1007 if dx*dx+dy*dy < r then
1008 begin
1009 //m := PointToRect(X, Y, GameX+PLAYER_RECT.X, GameY+PLAYER_RECT.Y,
1010 // PLAYER_RECT.Width, PLAYER_RECT.Height);
1012 mm := Max(abs(dx), abs(dy));
1013 if mm = 0 then mm := 1;
1015 HitPlayer(gPlayers[i], (100*(rad-mm)) div rad, (dx*10) div mm, (dy*10) div mm, SpawnerUID, HIT_ROCKET);
1016 gPlayers[i].Push((dx*7) div mm, (dy*7) div mm);
1017 end;
1018 end;
1020 //g_Mons_ForEach(monsExCheck);
1021 g_Mons_ForEachAt(X-(rad+32), Y-(rad+32), (rad+32)*2, (rad+32)*2, monsExCheck);
1023 h := High(gCorpses);
1025 if gAdvCorpses and (h <> -1) then
1026 for i := 0 to h do
1027 if (gCorpses[i] <> nil) and (gCorpses[i].State <> CORPSE_STATE_REMOVEME) then
1028 with gCorpses[i] do
1029 begin
1030 dx := Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2)-X;
1031 dy := Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)-Y;
1033 if dx > 1000 then dx := 1000;
1034 if dy > 1000 then dy := 1000;
1036 if dx*dx+dy*dy < r then
1037 begin
1038 m := PointToRect(X, Y, Obj.X+Obj.Rect.X, Obj.Y+Obj.Rect.Y,
1039 Obj.Rect.Width, Obj.Rect.Height);
1041 mm := Max(abs(dx), abs(dy));
1042 if mm = 0 then mm := 1;
1044 Damage(Round(100*(rad-m)/rad), (dx*10) div mm, (dy*10) div mm);
1045 end;
1046 end;
1048 h := High(gGibs);
1050 if gAdvGibs and (h <> -1) then
1051 for i := 0 to h do
1052 if gGibs[i].alive then
1053 with gGibs[i] do
1054 begin
1055 dx := Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2)-X;
1056 dy := Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)-Y;
1058 if dx > 1000 then dx := 1000;
1059 if dy > 1000 then dy := 1000;
1061 if dx*dx+dy*dy < r then
1062 begin
1063 m := PointToRect(X, Y, Obj.X+Obj.Rect.X, Obj.Y+Obj.Rect.Y,
1064 Obj.Rect.Width, Obj.Rect.Height);
1065 _angle := GetAngle(Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2),
1066 Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2), X, Y);
1068 g_Obj_PushA(@Obj, Round(15*(rad-m)/rad), _angle);
1069 positionChanged(); // this updates spatial accelerators
1070 end;
1071 end;
1072 end;
1074 procedure g_Weapon_Init();
1075 begin
1076 CreateWaterMap();
1077 end;
1079 procedure g_Weapon_Free();
1080 var
1081 i: Integer;
1082 begin
1083 if Shots <> nil then
1084 begin
1085 for i := 0 to High(Shots) do
1086 if Shots[i].ShotType <> 0 then
1087 Shots[i].Animation.Free();
1089 Shots := nil;
1090 end;
1092 WaterMap := nil;
1093 end;
1095 procedure g_Weapon_LoadData();
1096 begin
1097 e_WriteLog('Loading weapons data...', TMsgType.Notify);
1099 g_Sound_CreateWADEx('SOUND_WEAPON_HITPUNCH', GameWAD+':SOUNDS\HITPUNCH');
1100 g_Sound_CreateWADEx('SOUND_WEAPON_MISSPUNCH', GameWAD+':SOUNDS\MISSPUNCH');
1101 g_Sound_CreateWADEx('SOUND_WEAPON_HITBERSERK', GameWAD+':SOUNDS\HITBERSERK');
1102 g_Sound_CreateWADEx('SOUND_WEAPON_MISSBERSERK', GameWAD+':SOUNDS\MISSBERSERK');
1103 g_Sound_CreateWADEx('SOUND_WEAPON_SELECTSAW', GameWAD+':SOUNDS\SELECTSAW');
1104 g_Sound_CreateWADEx('SOUND_WEAPON_IDLESAW', GameWAD+':SOUNDS\IDLESAW');
1105 g_Sound_CreateWADEx('SOUND_WEAPON_HITSAW', GameWAD+':SOUNDS\HITSAW');
1106 g_Sound_CreateWADEx('SOUND_WEAPON_FIRESHOTGUN2', GameWAD+':SOUNDS\FIRESHOTGUN2');
1107 g_Sound_CreateWADEx('SOUND_WEAPON_FIRESHOTGUN', GameWAD+':SOUNDS\FIRESHOTGUN');
1108 g_Sound_CreateWADEx('SOUND_WEAPON_FIRESAW', GameWAD+':SOUNDS\FIRESAW');
1109 g_Sound_CreateWADEx('SOUND_WEAPON_FIREROCKET', GameWAD+':SOUNDS\FIREROCKET');
1110 g_Sound_CreateWADEx('SOUND_WEAPON_FIREPLASMA', GameWAD+':SOUNDS\FIREPLASMA');
1111 g_Sound_CreateWADEx('SOUND_WEAPON_FIREPISTOL', GameWAD+':SOUNDS\FIREPISTOL');
1112 g_Sound_CreateWADEx('SOUND_WEAPON_FIRECGUN', GameWAD+':SOUNDS\FIRECGUN');
1113 g_Sound_CreateWADEx('SOUND_WEAPON_FIREBFG', GameWAD+':SOUNDS\FIREBFG');
1114 g_Sound_CreateWADEx('SOUND_FIRE', GameWAD+':SOUNDS\FIRE');
1115 g_Sound_CreateWADEx('SOUND_WEAPON_STARTFIREBFG', GameWAD+':SOUNDS\STARTFIREBFG');
1116 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEROCKET', GameWAD+':SOUNDS\EXPLODEROCKET');
1117 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEBFG', GameWAD+':SOUNDS\EXPLODEBFG');
1118 g_Sound_CreateWADEx('SOUND_WEAPON_BFGWATER', GameWAD+':SOUNDS\BFGWATER');
1119 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEPLASMA', GameWAD+':SOUNDS\EXPLODEPLASMA');
1120 g_Sound_CreateWADEx('SOUND_WEAPON_PLASMAWATER', GameWAD+':SOUNDS\PLASMAWATER');
1121 g_Sound_CreateWADEx('SOUND_WEAPON_FIREBALL', GameWAD+':SOUNDS\FIREBALL');
1122 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEBALL', GameWAD+':SOUNDS\EXPLODEBALL');
1123 g_Sound_CreateWADEx('SOUND_WEAPON_FIREREV', GameWAD+':SOUNDS\FIREREV');
1124 g_Sound_CreateWADEx('SOUND_PLAYER_JETFLY', GameWAD+':SOUNDS\WORKJETPACK');
1125 g_Sound_CreateWADEx('SOUND_PLAYER_JETON', GameWAD+':SOUNDS\STARTJETPACK');
1126 g_Sound_CreateWADEx('SOUND_PLAYER_JETOFF', GameWAD+':SOUNDS\STOPJETPACK');
1127 g_Sound_CreateWADEx('SOUND_PLAYER_CASING1', GameWAD+':SOUNDS\CASING1');
1128 g_Sound_CreateWADEx('SOUND_PLAYER_CASING2', GameWAD+':SOUNDS\CASING2');
1129 g_Sound_CreateWADEx('SOUND_PLAYER_SHELL1', GameWAD+':SOUNDS\SHELL1');
1130 g_Sound_CreateWADEx('SOUND_PLAYER_SHELL2', GameWAD+':SOUNDS\SHELL2');
1132 g_Texture_CreateWADEx('TEXTURE_WEAPON_ROCKET', GameWAD+':TEXTURES\BROCKET');
1133 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_SKELFIRE', GameWAD+':TEXTURES\BSKELFIRE', 64, 16, 2);
1134 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_BFG', GameWAD+':TEXTURES\BBFG', 64, 64, 2);
1135 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_PLASMA', GameWAD+':TEXTURES\BPLASMA', 16, 16, 2);
1136 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_IMPFIRE', GameWAD+':TEXTURES\BIMPFIRE', 16, 16, 2);
1137 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_BSPFIRE', GameWAD+':TEXTURES\BBSPFIRE', 16, 16, 2);
1138 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_CACOFIRE', GameWAD+':TEXTURES\BCACOFIRE', 16, 16, 2);
1139 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_BARONFIRE', GameWAD+':TEXTURES\BBARONFIRE', 64, 16, 2);
1140 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_MANCUBFIRE', GameWAD+':TEXTURES\BMANCUBFIRE', 64, 32, 2);
1141 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_ROCKET', GameWAD+':TEXTURES\EROCKET', 128, 128, 6);
1142 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_SKELFIRE', GameWAD+':TEXTURES\ESKELFIRE', 64, 64, 3);
1143 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_BFG', GameWAD+':TEXTURES\EBFG', 128, 128, 6);
1144 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_IMPFIRE', GameWAD+':TEXTURES\EIMPFIRE', 64, 64, 3);
1145 g_Frames_CreateWAD(nil, 'FRAMES_BFGHIT', GameWAD+':TEXTURES\BFGHIT', 64, 64, 4);
1146 g_Frames_CreateWAD(nil, 'FRAMES_FIRE', GameWAD+':TEXTURES\FIRE', 64, 128, 8);
1147 g_Frames_CreateWAD(nil, 'FRAMES_FLAME', GameWAD+':TEXTURES\FLAME', 32, 32, 11);
1148 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_PLASMA', GameWAD+':TEXTURES\EPLASMA', 32, 32, 4, True);
1149 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_BSPFIRE', GameWAD+':TEXTURES\EBSPFIRE', 32, 32, 5);
1150 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_CACOFIRE', GameWAD+':TEXTURES\ECACOFIRE', 64, 64, 3);
1151 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_BARONFIRE', GameWAD+':TEXTURES\EBARONFIRE', 64, 64, 3);
1152 g_Frames_CreateWAD(nil, 'FRAMES_SMOKE', GameWAD+':TEXTURES\SMOKE', 32, 32, 10, False);
1154 g_Texture_CreateWADEx('TEXTURE_SHELL_BULLET', GameWAD+':TEXTURES\EBULLET');
1155 g_Texture_CreateWADEx('TEXTURE_SHELL_SHELL', GameWAD+':TEXTURES\ESHELL');
1157 //wgunMonHash := hashNewIntInt();
1158 wgunHitHeap := TBinaryHeapHitTimes.Create(hitTimeLess);
1159 end;
1161 procedure g_Weapon_FreeData();
1162 begin
1163 e_WriteLog('Releasing weapons data...', TMsgType.Notify);
1165 g_Sound_Delete('SOUND_WEAPON_HITPUNCH');
1166 g_Sound_Delete('SOUND_WEAPON_MISSPUNCH');
1167 g_Sound_Delete('SOUND_WEAPON_HITBERSERK');
1168 g_Sound_Delete('SOUND_WEAPON_MISSBERSERK');
1169 g_Sound_Delete('SOUND_WEAPON_SELECTSAW');
1170 g_Sound_Delete('SOUND_WEAPON_IDLESAW');
1171 g_Sound_Delete('SOUND_WEAPON_HITSAW');
1172 g_Sound_Delete('SOUND_WEAPON_FIRESHOTGUN2');
1173 g_Sound_Delete('SOUND_WEAPON_FIRESHOTGUN');
1174 g_Sound_Delete('SOUND_WEAPON_FIRESAW');
1175 g_Sound_Delete('SOUND_WEAPON_FIREROCKET');
1176 g_Sound_Delete('SOUND_WEAPON_FIREPLASMA');
1177 g_Sound_Delete('SOUND_WEAPON_FIREPISTOL');
1178 g_Sound_Delete('SOUND_WEAPON_FIRECGUN');
1179 g_Sound_Delete('SOUND_WEAPON_FIREBFG');
1180 g_Sound_Delete('SOUND_FIRE');
1181 g_Sound_Delete('SOUND_WEAPON_STARTFIREBFG');
1182 g_Sound_Delete('SOUND_WEAPON_EXPLODEROCKET');
1183 g_Sound_Delete('SOUND_WEAPON_EXPLODEBFG');
1184 g_Sound_Delete('SOUND_WEAPON_BFGWATER');
1185 g_Sound_Delete('SOUND_WEAPON_EXPLODEPLASMA');
1186 g_Sound_Delete('SOUND_WEAPON_PLASMAWATER');
1187 g_Sound_Delete('SOUND_WEAPON_FIREBALL');
1188 g_Sound_Delete('SOUND_WEAPON_EXPLODEBALL');
1189 g_Sound_Delete('SOUND_WEAPON_FIREREV');
1190 g_Sound_Delete('SOUND_PLAYER_JETFLY');
1191 g_Sound_Delete('SOUND_PLAYER_JETON');
1192 g_Sound_Delete('SOUND_PLAYER_JETOFF');
1193 g_Sound_Delete('SOUND_PLAYER_CASING1');
1194 g_Sound_Delete('SOUND_PLAYER_CASING2');
1195 g_Sound_Delete('SOUND_PLAYER_SHELL1');
1196 g_Sound_Delete('SOUND_PLAYER_SHELL2');
1198 g_Texture_Delete('TEXTURE_WEAPON_ROCKET');
1199 g_Frames_DeleteByName('FRAMES_WEAPON_BFG');
1200 g_Frames_DeleteByName('FRAMES_WEAPON_PLASMA');
1201 g_Frames_DeleteByName('FRAMES_WEAPON_IMPFIRE');
1202 g_Frames_DeleteByName('FRAMES_WEAPON_BSPFIRE');
1203 g_Frames_DeleteByName('FRAMES_WEAPON_CACOFIRE');
1204 g_Frames_DeleteByName('FRAMES_WEAPON_MANCUBFIRE');
1205 g_Frames_DeleteByName('FRAMES_EXPLODE_ROCKET');
1206 g_Frames_DeleteByName('FRAMES_EXPLODE_BFG');
1207 g_Frames_DeleteByName('FRAMES_EXPLODE_IMPFIRE');
1208 g_Frames_DeleteByName('FRAMES_BFGHIT');
1209 g_Frames_DeleteByName('FRAMES_FIRE');
1210 g_Frames_DeleteByName('FRAMES_EXPLODE_PLASMA');
1211 g_Frames_DeleteByName('FRAMES_EXPLODE_BSPFIRE');
1212 g_Frames_DeleteByName('FRAMES_EXPLODE_CACOFIRE');
1213 g_Frames_DeleteByName('FRAMES_SMOKE');
1214 g_Frames_DeleteByName('FRAMES_WEAPON_BARONFIRE');
1215 g_Frames_DeleteByName('FRAMES_EXPLODE_BARONFIRE');
1216 end;
1219 function GunHitPlayer (X, Y: Integer; vx, vy: Integer; dmg: Integer; SpawnerUID: Word; AllowPush: Boolean): Boolean;
1220 var
1221 i: Integer;
1222 begin
1223 result := false;
1224 for i := 0 to High(gPlayers) do
1225 begin
1226 if (gPlayers[i] <> nil) and gPlayers[i].alive and gPlayers[i].Collide(X, Y) then
1227 begin
1228 if HitPlayer(gPlayers[i], dmg, vx*10, vy*10-3, SpawnerUID, HIT_SOME) then
1229 begin
1230 if AllowPush then gPlayers[i].Push(vx, vy);
1231 result := true;
1232 end;
1233 end;
1234 end;
1235 end;
1238 function GunHit (X, Y: Integer; vx, vy: Integer; dmg: Integer; SpawnerUID: Word; AllowPush: Boolean): Byte;
1240 function monsCheck (mon: TMonster): Boolean;
1241 begin
1242 result := false; // don't stop
1243 if HitMonster(mon, dmg, vx*10, vy*10-3, SpawnerUID, HIT_SOME) then
1244 begin
1245 if AllowPush then mon.Push(vx, vy);
1246 result := true;
1247 end;
1248 end;
1250 begin
1251 result := 0;
1252 if GunHitPlayer(X, Y, vx, vy, dmg, SpawnerUID, AllowPush) then result := 1
1253 else if g_Mons_ForEachAliveAt(X, Y, 1, 1, monsCheck) then result := 2;
1254 end;
1257 (*
1258 procedure g_Weapon_gunOld(const x, y, xd, yd, v, dmg: Integer; SpawnerUID: Word; CheckTrigger: Boolean);
1259 var
1260 a: Integer;
1261 x2, y2: Integer;
1262 dx, dy: Integer;
1263 xe, ye: Integer;
1264 xi, yi: Integer;
1265 s, c: Extended;
1266 //vx, vy: Integer;
1267 xx, yy, d: Integer;
1268 i: Integer;
1269 t1, _collide: Boolean;
1270 w, h: Word;
1271 {$IF DEFINED(D2F_DEBUG)}
1272 stt: UInt64;
1273 showTime: Boolean = true;
1274 {$ENDIF}
1275 begin
1276 a := GetAngle(x, y, xd, yd)+180;
1278 SinCos(DegToRad(-a), s, c);
1280 if Abs(s) < 0.01 then s := 0;
1281 if Abs(c) < 0.01 then c := 0;
1283 x2 := x+Round(c*gMapInfo.Width);
1284 y2 := y+Round(s*gMapInfo.Width);
1286 t1 := gWalls <> nil;
1287 _collide := False;
1288 w := gMapInfo.Width;
1289 h := gMapInfo.Height;
1291 xe := 0;
1292 ye := 0;
1293 dx := x2-x;
1294 dy := y2-y;
1296 if (xd = 0) and (yd = 0) then Exit;
1298 if dx > 0 then xi := 1 else if dx < 0 then xi := -1 else xi := 0;
1299 if dy > 0 then yi := 1 else if dy < 0 then yi := -1 else yi := 0;
1301 dx := Abs(dx);
1302 dy := Abs(dy);
1304 if dx > dy then d := dx else d := dy;
1306 //blood vel, for Monster.Damage()
1307 //vx := (dx*10 div d)*xi;
1308 //vy := (dy*10 div d)*yi;
1310 {$IF DEFINED(D2F_DEBUG)}
1311 stt := getTimeMicro();
1312 {$ENDIF}
1314 xx := x;
1315 yy := y;
1317 for i := 1 to d do
1318 begin
1319 xe := xe+dx;
1320 ye := ye+dy;
1322 if xe > d then
1323 begin
1324 xe := xe-d;
1325 xx := xx+xi;
1326 end;
1328 if ye > d then
1329 begin
1330 ye := ye-d;
1331 yy := yy+yi;
1332 end;
1334 if (yy > h) or (yy < 0) then Break;
1335 if (xx > w) or (xx < 0) then Break;
1337 if t1 then
1338 if ByteBool(gCollideMap[yy, xx] and MARK_BLOCKED) then
1339 begin
1340 _collide := True;
1341 {$IF DEFINED(D2F_DEBUG)}
1342 stt := getTimeMicro()-stt;
1343 e_WriteLog(Format('*** old trace time: %u microseconds', [LongWord(stt)]), MSG_NOTIFY);
1344 showTime := false;
1345 {$ENDIF}
1346 g_GFX_Spark(xx-xi, yy-yi, 2+Random(2), 180+a, 0, 0);
1347 if g_Game_IsServer and g_Game_IsNet then
1348 MH_SEND_Effect(xx-xi, yy-yi, 180+a, NET_GFX_SPARK);
1349 end;
1351 if not _collide then
1352 begin
1353 _collide := GunHit(xx, yy, xi*v, yi*v, dmg, SpawnerUID, v <> 0) <> 0;
1354 end;
1356 if _collide then Break;
1357 end;
1359 {$IF DEFINED(D2F_DEBUG)}
1360 if showTime then
1361 begin
1362 stt := getTimeMicro()-stt;
1363 e_WriteLog(Format('*** old trace time: %u microseconds', [LongWord(stt)]), MSG_NOTIFY);
1364 end;
1365 {$ENDIF}
1367 if CheckTrigger and g_Game_IsServer then
1368 g_Triggers_PressL(X, Y, xx-xi, yy-yi, SpawnerUID, ACTIVATE_SHOT);
1369 end;
1370 *)
1373 //!!!FIXME!!!
1374 procedure g_Weapon_gun (const x, y, xd, yd, v, dmg: Integer; SpawnerUID: Word; CheckTrigger: Boolean);
1375 var
1376 x0, y0: Integer;
1377 x2, y2: Integer;
1378 xi, yi: Integer;
1379 wallDistSq: Integer = $3fffffff;
1381 function doPlayerHit (idx: Integer; hx, hy: Integer): Boolean;
1382 begin
1383 result := false;
1384 if (idx < 0) or (idx > High(gPlayers)) then exit;
1385 if (gPlayers[idx] = nil) or not gPlayers[idx].alive then exit;
1386 result := HitPlayer(gPlayers[idx], dmg, (xi*v)*10, (yi*v)*10-3, SpawnerUID, HIT_SOME);
1387 if result and (v <> 0) then gPlayers[idx].Push((xi*v), (yi*v));
1388 {$IF DEFINED(D2F_DEBUG)}
1389 //if result then e_WriteLog(Format(' PLAYER #%d HIT', [idx]), MSG_NOTIFY);
1390 {$ENDIF}
1391 end;
1393 function doMonsterHit (mon: TMonster; hx, hy: Integer): Boolean;
1394 begin
1395 result := false;
1396 if (mon = nil) then exit;
1397 result := HitMonster(mon, dmg, (xi*v)*10, (yi*v)*10-3, SpawnerUID, HIT_SOME);
1398 if result and (v <> 0) then mon.Push((xi*v), (yi*v));
1399 {$IF DEFINED(D2F_DEBUG)}
1400 //if result then e_WriteLog(Format(' MONSTER #%u HIT', [LongWord(mon.UID)]), MSG_NOTIFY);
1401 {$ENDIF}
1402 end;
1404 // collect players along hitray
1405 // return `true` if instant hit was detected
1406 function playerPossibleHit (): Boolean;
1407 var
1408 i: Integer;
1409 px, py, pw, ph: Integer;
1410 inx, iny: Integer;
1411 distSq: Integer;
1412 plr: TPlayer;
1413 begin
1414 result := false;
1415 for i := 0 to High(gPlayers) do
1416 begin
1417 plr := gPlayers[i];
1418 if (plr <> nil) and plr.alive then
1419 begin
1420 plr.getMapBox(px, py, pw, ph);
1421 if lineAABBIntersects(x, y, x2, y2, px, py, pw, ph, inx, iny) then
1422 begin
1423 distSq := distanceSq(x, y, inx, iny);
1424 if (distSq = 0) then
1425 begin
1426 // contains
1427 if doPlayerHit(i, x, y) then begin result := true; exit; end;
1428 end
1429 else if (distSq < wallDistSq) then
1430 begin
1431 appendHitTimePlr(distSq, i, inx, iny);
1432 end;
1433 end;
1434 end;
1435 end;
1436 end;
1438 function sqchecker (mon: TMonster; tag: Integer): Boolean;
1439 var
1440 mx, my, mw, mh: Integer;
1441 inx, iny: Integer;
1442 distSq: Integer;
1443 begin
1444 result := false; // don't stop
1445 mon.getMapBox(mx, my, mw, mh);
1446 if lineAABBIntersects(x0, y0, x2, y2, mx, my, mw, mh, inx, iny) then
1447 begin
1448 distSq := distanceSq(x0, y0, inx, iny);
1449 if (distSq < wallDistSq) then appendHitTimeMon(distSq, mon, inx, iny);
1450 end;
1451 end;
1453 var
1454 a: Integer;
1455 dx, dy: Integer;
1456 xe, ye: Integer;
1457 s, c: Extended;
1458 i: Integer;
1459 wallHitFlag: Boolean = false;
1460 wallHitX: Integer = 0;
1461 wallHitY: Integer = 0;
1462 didHit: Boolean = false;
1463 {$IF DEFINED(D2F_DEBUG)}
1464 stt: UInt64;
1465 {$ENDIF}
1466 begin
1467 (*
1468 if not gwep_debug_fast_trace then
1469 begin
1470 g_Weapon_gunOld(x, y, xd, yd, v, dmg, SpawnerUID, CheckTrigger);
1471 exit;
1472 end;
1473 *)
1475 if (xd = 0) and (yd = 0) then exit;
1477 //wgunMonHash.reset(); //FIXME: clear hash on level change
1478 wgunHitHeap.clear();
1479 wgunHitTimeUsed := 0;
1481 a := GetAngle(x, y, xd, yd)+180;
1483 SinCos(DegToRad(-a), s, c);
1485 if Abs(s) < 0.01 then s := 0;
1486 if Abs(c) < 0.01 then c := 0;
1488 x0 := x;
1489 y0 := y;
1490 x2 := x+Round(c*gMapInfo.Width);
1491 y2 := y+Round(s*gMapInfo.Width);
1493 dx := x2-x;
1494 dy := y2-y;
1496 if (dx > 0) then xi := 1 else if (dx < 0) then xi := -1 else xi := 0;
1497 if (dy > 0) then yi := 1 else if (dy < 0) then yi := -1 else yi := 0;
1499 {$IF DEFINED(D2F_DEBUG)}
1500 e_WriteLog(Format('GUN TRACE: (%d,%d) to (%d,%d)', [x, y, x2, y2]), TMsgType.Notify);
1501 stt := getTimeMicro();
1502 {$ENDIF}
1504 wallHitFlag := (g_Map_traceToNearestWall(x, y, x2, y2, @wallHitX, @wallHitY) <> nil);
1505 if wallHitFlag then
1506 begin
1507 x2 := wallHitX;
1508 y2 := wallHitY;
1509 wallDistSq := distanceSq(x, y, wallHitX, wallHitY);
1510 end
1511 else
1512 begin
1513 wallHitX := x2;
1514 wallHitY := y2;
1515 end;
1517 if playerPossibleHit() then exit; // instant hit
1519 // collect monsters
1520 g_Mons_AlongLine(x, y, x2, y2, sqchecker);
1522 // here, we collected all monsters and players in `wgunHitHeap` and `wgunHitTime`
1523 // also, if `wallWasHit` is `true`, then `wallHitX` and `wallHitY` contains spark coords
1524 while (wgunHitHeap.count > 0) do
1525 begin
1526 // has some entities to check, do it
1527 i := wgunHitHeap.front;
1528 wgunHitHeap.popFront();
1529 // hitpoint
1530 xe := wgunHitTime[i].x;
1531 ye := wgunHitTime[i].y;
1532 // check if it is not behind the wall
1533 if (wgunHitTime[i].mon <> nil) then
1534 begin
1535 didHit := doMonsterHit(wgunHitTime[i].mon, xe, ye);
1536 end
1537 else
1538 begin
1539 didHit := doPlayerHit(wgunHitTime[i].plridx, xe, ye);
1540 end;
1541 if didHit then
1542 begin
1543 // need new coords for trigger
1544 wallHitX := xe;
1545 wallHitY := ye;
1546 wallHitFlag := false; // no sparks
1547 break;
1548 end;
1549 end;
1551 // need sparks?
1552 if wallHitFlag then
1553 begin
1554 {$IF DEFINED(D2F_DEBUG)}
1555 stt := getTimeMicro()-stt;
1556 e_WriteLog(Format('*** new trace time: %u microseconds', [LongWord(stt)]), TMsgType.Notify);
1557 {$ENDIF}
1558 g_GFX_Spark(wallHitX, wallHitY, 2+Random(2), 180+a, 0, 0);
1559 if g_Game_IsServer and g_Game_IsNet then MH_SEND_Effect(wallHitX, wallHitY, 180+a, NET_GFX_SPARK);
1560 end
1561 else
1562 begin
1563 {$IF DEFINED(D2F_DEBUG)}
1564 stt := getTimeMicro()-stt;
1565 e_WriteLog(Format('*** new trace time: %u microseconds', [LongWord(stt)]), TMsgType.Notify);
1566 {$ENDIF}
1567 end;
1569 if CheckTrigger and g_Game_IsServer then g_Triggers_PressL(X, Y, wallHitX, wallHitY, SpawnerUID, ACTIVATE_SHOT);
1570 end;
1573 procedure g_Weapon_punch(x, y: Integer; d, SpawnerUID: Word);
1574 var
1575 obj: TObj;
1576 begin
1577 obj.X := X;
1578 obj.Y := Y;
1579 obj.rect.X := 0;
1580 obj.rect.Y := 0;
1581 obj.rect.Width := 39;
1582 obj.rect.Height := 52;
1583 obj.Vel.X := 0;
1584 obj.Vel.Y := 0;
1585 obj.Accel.X := 0;
1586 obj.Accel.Y := 0;
1588 if g_Weapon_Hit(@obj, d, SpawnerUID, HIT_SOME) <> 0 then
1589 g_Sound_PlayExAt('SOUND_WEAPON_HITPUNCH', x, y)
1590 else
1591 g_Sound_PlayExAt('SOUND_WEAPON_MISSPUNCH', x, y);
1592 end;
1594 function g_Weapon_chainsaw(x, y: Integer; d, SpawnerUID: Word): Integer;
1595 var
1596 obj: TObj;
1597 begin
1598 obj.X := X;
1599 obj.Y := Y;
1600 obj.rect.X := 0;
1601 obj.rect.Y := 0;
1602 obj.rect.Width := 32;
1603 obj.rect.Height := 52;
1604 obj.Vel.X := 0;
1605 obj.Vel.Y := 0;
1606 obj.Accel.X := 0;
1607 obj.Accel.Y := 0;
1609 Result := g_Weapon_Hit(@obj, d, SpawnerUID, HIT_SOME);
1610 end;
1612 procedure g_Weapon_rocket(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1613 Silent: Boolean = False);
1614 var
1615 find_id: DWORD;
1616 dx, dy: Integer;
1617 begin
1618 if WID < 0 then
1619 find_id := FindShot()
1620 else
1621 begin
1622 find_id := WID;
1623 if Integer(find_id) >= High(Shots) then
1624 SetLength(Shots, find_id + 64)
1625 end;
1627 with Shots[find_id] do
1628 begin
1629 g_Obj_Init(@Obj);
1631 Obj.Rect.Width := SHOT_ROCKETLAUNCHER_WIDTH;
1632 Obj.Rect.Height := SHOT_ROCKETLAUNCHER_HEIGHT;
1634 dx := IfThen(xd > x, -Obj.Rect.Width, 0);
1635 dy := -(Obj.Rect.Height div 2);
1637 ShotType := WEAPON_ROCKETLAUNCHER;
1638 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 12);
1640 Animation := nil;
1641 triggers := nil;
1642 g_Texture_Get('TEXTURE_WEAPON_ROCKET', TextureID);
1643 end;
1645 Shots[find_id].SpawnerUID := SpawnerUID;
1647 if not Silent then
1648 g_Sound_PlayExAt('SOUND_WEAPON_FIREROCKET', x, y);
1649 end;
1651 procedure g_Weapon_revf(x, y, xd, yd: Integer; SpawnerUID, TargetUID: Word;
1652 WID: Integer = -1; Silent: Boolean = False);
1653 var
1654 find_id, FramesID: DWORD;
1655 dx, dy: Integer;
1656 begin
1657 if WID < 0 then
1658 find_id := FindShot()
1659 else
1660 begin
1661 find_id := WID;
1662 if Integer(find_id) >= High(Shots) then
1663 SetLength(Shots, find_id + 64)
1664 end;
1666 with Shots[find_id] do
1667 begin
1668 g_Obj_Init(@Obj);
1670 Obj.Rect.Width := SHOT_SKELFIRE_WIDTH;
1671 Obj.Rect.Height := SHOT_SKELFIRE_HEIGHT;
1673 dx := -(Obj.Rect.Width div 2);
1674 dy := -(Obj.Rect.Height div 2);
1676 ShotType := WEAPON_SKEL_FIRE;
1677 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 12);
1679 triggers := nil;
1680 target := TargetUID;
1681 g_Frames_Get(FramesID, 'FRAMES_WEAPON_SKELFIRE');
1682 Animation := TAnimation.Create(FramesID, True, 5);
1683 end;
1685 Shots[find_id].SpawnerUID := SpawnerUID;
1687 if not Silent then
1688 g_Sound_PlayExAt('SOUND_WEAPON_FIREREV', x, y);
1689 end;
1691 procedure g_Weapon_plasma(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1692 Silent: Boolean = False);
1693 var
1694 find_id, FramesID: DWORD;
1695 dx, dy: Integer;
1696 begin
1697 if WID < 0 then
1698 find_id := FindShot()
1699 else
1700 begin
1701 find_id := WID;
1702 if Integer(find_id) >= High(Shots) then
1703 SetLength(Shots, find_id + 64);
1704 end;
1706 with Shots[find_id] do
1707 begin
1708 g_Obj_Init(@Obj);
1710 Obj.Rect.Width := SHOT_PLASMA_WIDTH;
1711 Obj.Rect.Height := SHOT_PLASMA_HEIGHT;
1713 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1714 dy := -(Obj.Rect.Height div 2);
1716 ShotType := WEAPON_PLASMA;
1717 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1719 triggers := nil;
1720 g_Frames_Get(FramesID, 'FRAMES_WEAPON_PLASMA');
1721 Animation := TAnimation.Create(FramesID, True, 5);
1722 end;
1724 Shots[find_id].SpawnerUID := SpawnerUID;
1726 if not Silent then
1727 g_Sound_PlayExAt('SOUND_WEAPON_FIREPLASMA', x, y);
1728 end;
1730 procedure g_Weapon_flame(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1731 Silent: Boolean = False);
1732 var
1733 find_id: DWORD;
1734 dx, dy: Integer;
1735 begin
1736 if WID < 0 then
1737 find_id := FindShot()
1738 else
1739 begin
1740 find_id := WID;
1741 if Integer(find_id) >= High(Shots) then
1742 SetLength(Shots, find_id + 64);
1743 end;
1745 with Shots[find_id] do
1746 begin
1747 g_Obj_Init(@Obj);
1749 Obj.Rect.Width := SHOT_FLAME_WIDTH;
1750 Obj.Rect.Height := SHOT_FLAME_HEIGHT;
1752 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1753 dy := -(Obj.Rect.Height div 2);
1755 ShotType := WEAPON_FLAMETHROWER;
1756 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1758 triggers := nil;
1759 Animation := nil;
1760 TextureID := 0;
1761 g_Frames_Get(TextureID, 'FRAMES_FLAME');
1762 end;
1764 Shots[find_id].SpawnerUID := SpawnerUID;
1766 // if not Silent then
1767 // g_Sound_PlayExAt('SOUND_WEAPON_FIREPLASMA', x, y);
1768 end;
1770 procedure g_Weapon_ball1(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1771 Silent: Boolean = False);
1772 var
1773 find_id, FramesID: DWORD;
1774 dx, dy: Integer;
1775 begin
1776 if WID < 0 then
1777 find_id := FindShot()
1778 else
1779 begin
1780 find_id := WID;
1781 if Integer(find_id) >= High(Shots) then
1782 SetLength(Shots, find_id + 64)
1783 end;
1785 with Shots[find_id] do
1786 begin
1787 g_Obj_Init(@Obj);
1789 Obj.Rect.Width := 16;
1790 Obj.Rect.Height := 16;
1792 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1793 dy := -(Obj.Rect.Height div 2);
1795 ShotType := WEAPON_IMP_FIRE;
1796 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1798 triggers := nil;
1799 g_Frames_Get(FramesID, 'FRAMES_WEAPON_IMPFIRE');
1800 Animation := TAnimation.Create(FramesID, True, 4);
1801 end;
1803 Shots[find_id].SpawnerUID := SpawnerUID;
1805 if not Silent then
1806 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x, y);
1807 end;
1809 procedure g_Weapon_ball2(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1810 Silent: Boolean = False);
1811 var
1812 find_id, FramesID: DWORD;
1813 dx, dy: Integer;
1814 begin
1815 if WID < 0 then
1816 find_id := FindShot()
1817 else
1818 begin
1819 find_id := WID;
1820 if Integer(find_id) >= High(Shots) then
1821 SetLength(Shots, find_id + 64)
1822 end;
1824 with Shots[find_id] do
1825 begin
1826 g_Obj_Init(@Obj);
1828 Obj.Rect.Width := 16;
1829 Obj.Rect.Height := 16;
1831 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1832 dy := -(Obj.Rect.Height div 2);
1834 ShotType := WEAPON_CACO_FIRE;
1835 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1837 triggers := nil;
1838 g_Frames_Get(FramesID, 'FRAMES_WEAPON_CACOFIRE');
1839 Animation := TAnimation.Create(FramesID, True, 4);
1840 end;
1842 Shots[find_id].SpawnerUID := SpawnerUID;
1844 if not Silent then
1845 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x, y);
1846 end;
1848 procedure g_Weapon_ball7(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1849 Silent: Boolean = False);
1850 var
1851 find_id, FramesID: DWORD;
1852 dx, dy: Integer;
1853 begin
1854 if WID < 0 then
1855 find_id := FindShot()
1856 else
1857 begin
1858 find_id := WID;
1859 if Integer(find_id) >= High(Shots) then
1860 SetLength(Shots, find_id + 64)
1861 end;
1863 with Shots[find_id] do
1864 begin
1865 g_Obj_Init(@Obj);
1867 Obj.Rect.Width := 32;
1868 Obj.Rect.Height := 16;
1870 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1871 dy := -(Obj.Rect.Height div 2);
1873 ShotType := WEAPON_BARON_FIRE;
1874 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1876 triggers := nil;
1877 g_Frames_Get(FramesID, 'FRAMES_WEAPON_BARONFIRE');
1878 Animation := TAnimation.Create(FramesID, True, 4);
1879 end;
1881 Shots[find_id].SpawnerUID := SpawnerUID;
1883 if not Silent then
1884 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x, y);
1885 end;
1887 procedure g_Weapon_aplasma(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1888 Silent: Boolean = False);
1889 var
1890 find_id, FramesID: DWORD;
1891 dx, dy: Integer;
1892 begin
1893 if WID < 0 then
1894 find_id := FindShot()
1895 else
1896 begin
1897 find_id := WID;
1898 if Integer(find_id) >= High(Shots) then
1899 SetLength(Shots, find_id + 64)
1900 end;
1902 with Shots[find_id] do
1903 begin
1904 g_Obj_Init(@Obj);
1906 Obj.Rect.Width := 16;
1907 Obj.Rect.Height := 16;
1909 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1910 dy := -(Obj.Rect.Height div 2);
1912 ShotType := WEAPON_BSP_FIRE;
1913 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1915 triggers := nil;
1917 g_Frames_Get(FramesID, 'FRAMES_WEAPON_BSPFIRE');
1918 Animation := TAnimation.Create(FramesID, True, 4);
1919 end;
1921 Shots[find_id].SpawnerUID := SpawnerUID;
1923 if not Silent then
1924 g_Sound_PlayExAt('SOUND_WEAPON_FIREPLASMA', x, y);
1925 end;
1927 procedure g_Weapon_manfire(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1928 Silent: Boolean = False);
1929 var
1930 find_id, FramesID: DWORD;
1931 dx, dy: Integer;
1932 begin
1933 if WID < 0 then
1934 find_id := FindShot()
1935 else
1936 begin
1937 find_id := WID;
1938 if Integer(find_id) >= High(Shots) then
1939 SetLength(Shots, find_id + 64)
1940 end;
1942 with Shots[find_id] do
1943 begin
1944 g_Obj_Init(@Obj);
1946 Obj.Rect.Width := 32;
1947 Obj.Rect.Height := 32;
1949 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1950 dy := -(Obj.Rect.Height div 2);
1952 ShotType := WEAPON_MANCUB_FIRE;
1953 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1955 triggers := nil;
1957 g_Frames_Get(FramesID, 'FRAMES_WEAPON_MANCUBFIRE');
1958 Animation := TAnimation.Create(FramesID, True, 4);
1959 end;
1961 Shots[find_id].SpawnerUID := SpawnerUID;
1963 if not Silent then
1964 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x, y);
1965 end;
1967 procedure g_Weapon_bfgshot(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1968 Silent: Boolean = False);
1969 var
1970 find_id, FramesID: DWORD;
1971 dx, dy: Integer;
1972 begin
1973 if WID < 0 then
1974 find_id := FindShot()
1975 else
1976 begin
1977 find_id := WID;
1978 if Integer(find_id) >= High(Shots) then
1979 SetLength(Shots, find_id + 64)
1980 end;
1982 with Shots[find_id] do
1983 begin
1984 g_Obj_Init(@Obj);
1986 Obj.Rect.Width := SHOT_BFG_WIDTH;
1987 Obj.Rect.Height := SHOT_BFG_HEIGHT;
1989 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1990 dy := -(Obj.Rect.Height div 2);
1992 ShotType := WEAPON_BFG;
1993 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1995 triggers := nil;
1996 g_Frames_Get(FramesID, 'FRAMES_WEAPON_BFG');
1997 Animation := TAnimation.Create(FramesID, True, 6);
1998 end;
2000 Shots[find_id].SpawnerUID := SpawnerUID;
2002 if not Silent then
2003 g_Sound_PlayExAt('SOUND_WEAPON_FIREBFG', x, y);
2004 end;
2006 procedure g_Weapon_bfghit(x, y: Integer);
2007 var
2008 ID: DWORD;
2009 Anim: TAnimation;
2010 begin
2011 if g_Frames_Get(ID, 'FRAMES_BFGHIT') then
2012 begin
2013 Anim := TAnimation.Create(ID, False, 4);
2014 g_GFX_OnceAnim(x-32, y-32, Anim);
2015 Anim.Free();
2016 end;
2017 end;
2019 procedure g_Weapon_pistol(x, y, xd, yd: Integer; SpawnerUID: Word;
2020 Silent: Boolean = False);
2021 begin
2022 if not Silent then
2023 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', x, y);
2025 g_Weapon_gun(x, y, xd, yd, 1, 3, SpawnerUID, True);
2026 if gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF] then
2027 begin
2028 g_Weapon_gun(x, y+1, xd, yd+1, 1, 3, SpawnerUID, False);
2029 g_Weapon_gun(x, y-1, xd, yd-1, 1, 2, SpawnerUID, False);
2030 end;
2031 end;
2033 procedure g_Weapon_mgun(x, y, xd, yd: Integer; SpawnerUID: Word;
2034 Silent: Boolean = False);
2035 begin
2036 if not Silent then
2037 if gSoundEffectsDF then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', x, y);
2039 g_Weapon_gun(x, y, xd, yd, 1, 3, SpawnerUID, True);
2040 if (gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF]) and
2041 (g_GetUIDType(SpawnerUID) = UID_PLAYER) then
2042 begin
2043 g_Weapon_gun(x, y+1, xd, yd+1, 1, 2, SpawnerUID, False);
2044 g_Weapon_gun(x, y-1, xd, yd-1, 1, 2, SpawnerUID, False);
2045 end;
2046 end;
2048 procedure g_Weapon_shotgun(x, y, xd, yd: Integer; SpawnerUID: Word;
2049 Silent: Boolean = False);
2050 var
2051 i, j: Integer;
2052 begin
2053 if not Silent then
2054 if gSoundEffectsDF then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', x, y);
2056 for i := 0 to 9 do
2057 begin
2058 j := Random(17)-8; // -8 .. 8
2059 g_Weapon_gun(x, y+j, xd, yd+j, IfThen(i mod 2 <> 0, 1, 0), 3, SpawnerUID, i=0);
2060 end;
2061 end;
2063 procedure g_Weapon_dshotgun(x, y, xd, yd: Integer; SpawnerUID: Word;
2064 Silent: Boolean = False);
2065 var
2066 a, i, j: Integer;
2067 begin
2068 if not Silent then
2069 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', x, y);
2071 if gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF] then a := 25 else a := 20;
2072 for i := 0 to a do
2073 begin
2074 j := Random(41)-20; // -20 .. 20
2075 g_Weapon_gun(x, y+j, xd, yd+j, IfThen(i mod 3 <> 0, 0, 1), 3, SpawnerUID, i=0);
2076 end;
2077 end;
2079 procedure g_Weapon_Update();
2080 var
2081 i, a, h, cx, cy, oldvx, oldvy, tf: Integer;
2082 _id: DWORD;
2083 Anim: TAnimation;
2084 t: DWArray;
2085 st: Word;
2086 s: String;
2087 o: TObj;
2088 spl: Boolean;
2089 Loud: Boolean;
2090 tcx, tcy: Integer;
2091 begin
2092 if Shots = nil then
2093 Exit;
2095 for i := 0 to High(Shots) do
2096 begin
2097 if Shots[i].ShotType = 0 then
2098 Continue;
2100 Loud := True;
2102 with Shots[i] do
2103 begin
2104 Timeout := Timeout - 1;
2105 oldvx := Obj.Vel.X;
2106 oldvy := Obj.Vel.Y;
2107 // Àêòèâèðîâàòü òðèããåðû ïî ïóòè (êðîìå óæå àêòèâèðîâàííûõ):
2108 if (Stopped = 0) and g_Game_IsServer then
2109 t := g_Triggers_PressR(Obj.X, Obj.Y, Obj.Rect.Width, Obj.Rect.Height,
2110 SpawnerUID, ACTIVATE_SHOT, triggers)
2111 else
2112 t := nil;
2114 if t <> nil then
2115 begin
2116 // Ïîïîëíÿåì ñïèñîê àêòèâèðîâàííûõ òðèããåðîâ:
2117 if triggers = nil then
2118 triggers := t
2119 else
2120 begin
2121 h := High(t);
2123 for a := 0 to h do
2124 if not InDWArray(t[a], triggers) then
2125 begin
2126 SetLength(triggers, Length(triggers)+1);
2127 triggers[High(triggers)] := t[a];
2128 end;
2129 end;
2130 end;
2132 // Àíèìàöèÿ ñíàðÿäà:
2133 if Animation <> nil then
2134 Animation.Update();
2136 // Äâèæåíèå:
2137 spl := (ShotType <> WEAPON_PLASMA) and
2138 (ShotType <> WEAPON_BFG) and
2139 (ShotType <> WEAPON_BSP_FIRE) and
2140 (ShotType <> WEAPON_FLAMETHROWER);
2142 if Stopped = 0 then
2143 begin
2144 st := g_Obj_Move(@Obj, False, spl);
2145 end
2146 else
2147 begin
2148 st := 0;
2149 end;
2150 positionChanged(); // this updates spatial accelerators
2152 if WordBool(st and MOVE_FALLOUT) or (Obj.X < -1000) or
2153 (Obj.X > gMapInfo.Width+1000) or (Obj.Y < -1000) then
2154 begin
2155 // Íà êëèåíòå ñêîðåå âñåãî è òàê óæå âûïàë.
2156 ShotType := 0;
2157 Animation.Free();
2158 Continue;
2159 end;
2161 cx := Obj.X + (Obj.Rect.Width div 2);
2162 cy := Obj.Y + (Obj.Rect.Height div 2);
2164 case ShotType of
2165 WEAPON_ROCKETLAUNCHER, WEAPON_SKEL_FIRE: // Ðàêåòû è ñíàðÿäû Ñêåëåòà
2166 begin
2167 // Âûëåòåëà èç âîäû:
2168 if WordBool(st and MOVE_HITAIR) then
2169 g_Obj_SetSpeed(@Obj, 12);
2171 // Â âîäå øëåéô - ïóçûðè, â âîçäóõå øëåéô - äûì:
2172 if WordBool(st and MOVE_INWATER) then
2173 g_GFX_Bubbles(Obj.X+(Obj.Rect.Width div 2),
2174 Obj.Y+(Obj.Rect.Height div 2),
2175 1+Random(3), 16, 16)
2176 else
2177 if g_Frames_Get(_id, 'FRAMES_SMOKE') then
2178 begin
2179 Anim := TAnimation.Create(_id, False, 3);
2180 Anim.Alpha := 150;
2181 g_GFX_OnceAnim(Obj.X-14+Random(9),
2182 Obj.Y+(Obj.Rect.Height div 2)-20+Random(9),
2183 Anim, ONCEANIM_SMOKE);
2184 Anim.Free();
2185 end;
2187 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2188 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL)) or
2189 (g_Weapon_Hit(@Obj, 10, SpawnerUID, HIT_SOME, False) <> 0) or
2190 (Timeout < 1) then
2191 begin
2192 Obj.Vel.X := 0;
2193 Obj.Vel.Y := 0;
2195 g_Weapon_Explode(cx, cy, 60, SpawnerUID);
2197 if ShotType = WEAPON_SKEL_FIRE then
2198 begin // Âçðûâ ñíàðÿäà Ñêåëåòà
2199 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_SKELFIRE') then
2200 begin
2201 Anim := TAnimation.Create(TextureID, False, 8);
2202 Anim.Blending := False;
2203 g_GFX_OnceAnim((Obj.X+32)-58, (Obj.Y+8)-36, Anim);
2204 g_DynLightExplosion((Obj.X+32), (Obj.Y+8), 64, 1, 0, 0);
2205 Anim.Free();
2206 end;
2207 end
2208 else
2209 begin // Âçðûâ Ðàêåòû
2210 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_ROCKET') then
2211 begin
2212 Anim := TAnimation.Create(TextureID, False, 6);
2213 Anim.Blending := False;
2214 g_GFX_OnceAnim(cx-64, cy-64, Anim);
2215 g_DynLightExplosion(cx, cy, 64, 1, 0, 0);
2216 Anim.Free();
2217 end;
2218 end;
2220 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', Obj.X, Obj.Y);
2222 ShotType := 0;
2223 end;
2225 if ShotType = WEAPON_SKEL_FIRE then
2226 begin // Ñàìîíàâîäêà ñíàðÿäà Ñêåëåòà:
2227 if GetPos(target, @o) then
2228 throw(i, Obj.X, Obj.Y,
2229 o.X+o.Rect.X+(o.Rect.Width div 2)+o.Vel.X+o.Accel.X,
2230 o.Y+o.Rect.Y+(o.Rect.Height div 2)+o.Vel.Y+o.Accel.Y,
2231 12);
2232 end;
2233 end;
2235 WEAPON_PLASMA, WEAPON_BSP_FIRE: // Ïëàçìà, ïëàçìà Àðàõíàòðîíà
2236 begin
2237 // Ïîïàëà â âîäó - ýëåêòðîøîê ïî âîäå:
2238 if WordBool(st and (MOVE_INWATER or MOVE_HITWATER)) then
2239 begin
2240 g_Sound_PlayExAt('SOUND_WEAPON_PLASMAWATER', Obj.X, Obj.Y);
2241 if g_Game_IsServer then CheckTrap(i, 10, HIT_ELECTRO);
2242 ShotType := 0;
2243 Continue;
2244 end;
2246 // Âåëè÷èíà óðîíà:
2247 if (ShotType = WEAPON_PLASMA) and
2248 (gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF]) then
2249 a := 10
2250 else
2251 a := 5;
2253 if ShotType = WEAPON_BSP_FIRE then
2254 a := 10;
2256 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2257 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL)) or
2258 (g_Weapon_Hit(@Obj, a, SpawnerUID, HIT_SOME, False) <> 0) or
2259 (Timeout < 1) then
2260 begin
2261 if ShotType = WEAPON_PLASMA then
2262 s := 'FRAMES_EXPLODE_PLASMA'
2263 else
2264 s := 'FRAMES_EXPLODE_BSPFIRE';
2266 // Âçðûâ Ïëàçìû:
2267 if g_Frames_Get(TextureID, s) then
2268 begin
2269 Anim := TAnimation.Create(TextureID, False, 3);
2270 Anim.Blending := False;
2271 g_GFX_OnceAnim(cx-16, cy-16, Anim);
2272 Anim.Free();
2273 g_DynLightExplosion(cx, cy, 32, 0, 0.5, 0.5);
2274 end;
2276 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEPLASMA', Obj.X, Obj.Y);
2278 ShotType := 0;
2279 end;
2280 end;
2282 WEAPON_FLAMETHROWER: // Îãíåìåò
2283 begin
2284 // Ñî âðåìåíåì óìèðàåò
2285 if (Timeout < 1) then
2286 begin
2287 ShotType := 0;
2288 Continue;
2289 end;
2290 // Ïîä âîäîé òîæå
2291 if WordBool(st and (MOVE_HITWATER or MOVE_INWATER)) then
2292 begin
2293 if WordBool(st and MOVE_HITWATER) then
2294 begin
2295 if g_Frames_Get(_id, 'FRAMES_SMOKE') then
2296 begin
2297 Anim := TAnimation.Create(_id, False, 3);
2298 Anim.Alpha := 0;
2299 tcx := Random(8);
2300 tcy := Random(8);
2301 g_GFX_OnceAnim(cx-4+tcx-(Anim.Width div 2),
2302 cy-4+tcy-(Anim.Height div 2),
2303 Anim, ONCEANIM_SMOKE);
2304 Anim.Free();
2305 end;
2306 end
2307 else
2308 g_GFX_Bubbles(cx, cy, 1+Random(3), 16, 16);
2309 ShotType := 0;
2310 Continue;
2311 end;
2313 // Ãðàâèòàöèÿ
2314 if Stopped = 0 then
2315 Obj.Accel.Y := Obj.Accel.Y + 1;
2316 // Ïîïàëè â ñòåíó èëè â âîäó:
2317 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL or MOVE_HITWATER)) then
2318 begin
2319 // Ïðèëèïàåì:
2320 Obj.Vel.X := 0;
2321 Obj.Vel.Y := 0;
2322 Obj.Accel.Y := 0;
2323 if WordBool(st and MOVE_HITWALL) then
2324 Stopped := MOVE_HITWALL
2325 else if WordBool(st and MOVE_HITLAND) then
2326 Stopped := MOVE_HITLAND
2327 else if WordBool(st and MOVE_HITCEIL) then
2328 Stopped := MOVE_HITCEIL;
2329 end;
2331 a := IfThen(Stopped = 0, 3, 1);
2332 // Åñëè â êîãî-òî ïîïàëè
2333 if g_Weapon_Hit(@Obj, a, SpawnerUID, HIT_FLAME, False) <> 0 then
2334 begin
2335 // HIT_FLAME ñàì ïîäîææåò
2336 // Åñëè â ïîëåòå ïîïàëè, èñ÷åçàåì
2337 if Stopped = 0 then
2338 ShotType := 0;
2339 end;
2341 if Stopped = 0 then
2342 tf := 2
2343 else
2344 tf := 3;
2346 if (gTime mod LongWord(tf) = 0) then
2347 begin
2348 Anim := TAnimation.Create(TextureID, False, 2 + Random(2));
2349 Anim.Alpha := 0;
2350 case Stopped of
2351 MOVE_HITWALL: begin tcx := cx-4+Random(8); tcy := cy-12+Random(24); end;
2352 MOVE_HITLAND: begin tcx := cx-12+Random(24); tcy := cy-10+Random(8); end;
2353 MOVE_HITCEIL: begin tcx := cx-12+Random(24); tcy := cy+6+Random(8); end;
2354 else begin tcx := cx-4+Random(8); tcy := cy-4+Random(8); end;
2355 end;
2356 g_GFX_OnceAnim(tcx-(Anim.Width div 2), tcy-(Anim.Height div 2), Anim, ONCEANIM_SMOKE);
2357 Anim.Free();
2358 //g_DynLightExplosion(tcx, tcy, 1, 1, 0.8, 0.3);
2359 end;
2360 end;
2362 WEAPON_BFG: // BFG
2363 begin
2364 // Ïîïàëà â âîäó - ýëåêòðîøîê ïî âîäå:
2365 if WordBool(st and (MOVE_INWATER or MOVE_HITWATER)) then
2366 begin
2367 g_Sound_PlayExAt('SOUND_WEAPON_BFGWATER', Obj.X, Obj.Y);
2368 if g_Game_IsServer then CheckTrap(i, 1000, HIT_ELECTRO);
2369 ShotType := 0;
2370 Continue;
2371 end;
2373 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2374 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL)) or
2375 (g_Weapon_Hit(@Obj, SHOT_BFG_DAMAGE, SpawnerUID, HIT_BFG, False) <> 0) or
2376 (Timeout < 1) then
2377 begin
2378 // Ëó÷è BFG:
2379 if g_Game_IsServer then g_Weapon_BFG9000(cx, cy, SpawnerUID);
2381 // Âçðûâ BFG:
2382 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_BFG') then
2383 begin
2384 Anim := TAnimation.Create(TextureID, False, 6);
2385 Anim.Blending := False;
2386 g_GFX_OnceAnim(cx-64, cy-64, Anim);
2387 Anim.Free();
2388 g_DynLightExplosion(cx, cy, 96, 0, 1, 0);
2389 end;
2391 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', Obj.X, Obj.Y);
2393 ShotType := 0;
2394 end;
2395 end;
2397 WEAPON_IMP_FIRE, WEAPON_CACO_FIRE, WEAPON_BARON_FIRE: // Âûñòðåëû Áåñà, Êàêîäåìîíà Ðûöàðÿ/Áàðîíà àäà
2398 begin
2399 // Âûëåòåë èç âîäû:
2400 if WordBool(st and MOVE_HITAIR) then
2401 g_Obj_SetSpeed(@Obj, 16);
2403 // Âåëè÷èíà óðîíà:
2404 if ShotType = WEAPON_IMP_FIRE then
2405 a := 5
2406 else
2407 if ShotType = WEAPON_CACO_FIRE then
2408 a := 20
2409 else
2410 a := 40;
2412 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2413 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL)) or
2414 (g_Weapon_Hit(@Obj, a, SpawnerUID, HIT_SOME) <> 0) or
2415 (Timeout < 1) then
2416 begin
2417 if ShotType = WEAPON_IMP_FIRE then
2418 s := 'FRAMES_EXPLODE_IMPFIRE'
2419 else
2420 if ShotType = WEAPON_CACO_FIRE then
2421 s := 'FRAMES_EXPLODE_CACOFIRE'
2422 else
2423 s := 'FRAMES_EXPLODE_BARONFIRE';
2425 // Âçðûâ:
2426 if g_Frames_Get(TextureID, s) then
2427 begin
2428 Anim := TAnimation.Create(TextureID, False, 6);
2429 Anim.Blending := False;
2430 g_GFX_OnceAnim(cx-32, cy-32, Anim);
2431 Anim.Free();
2432 end;
2434 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj.X, Obj.Y);
2436 ShotType := 0;
2437 end;
2438 end;
2440 WEAPON_MANCUB_FIRE: // Âûñòðåë Ìàíêóáóñà
2441 begin
2442 // Âûëåòåë èç âîäû:
2443 if WordBool(st and MOVE_HITAIR) then
2444 g_Obj_SetSpeed(@Obj, 16);
2446 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2447 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL)) or
2448 (g_Weapon_Hit(@Obj, 40, SpawnerUID, HIT_SOME, False) <> 0) or
2449 (Timeout < 1) then
2450 begin
2451 // Âçðûâ:
2452 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_ROCKET') then
2453 begin
2454 Anim := TAnimation.Create(TextureID, False, 6);
2455 Anim.Blending := False;
2456 g_GFX_OnceAnim(cx-64, cy-64, Anim);
2457 Anim.Free();
2458 end;
2460 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj.X, Obj.Y);
2462 ShotType := 0;
2463 end;
2464 end;
2465 end; // case ShotType of...
2467 // Åñëè ñíàðÿäà óæå íåò, óäàëÿåì àíèìàöèþ:
2468 if (ShotType = 0) then
2469 begin
2470 if gGameSettings.GameType = GT_SERVER then
2471 MH_SEND_DeleteShot(i, Obj.X, Obj.Y, Loud);
2472 if Animation <> nil then
2473 begin
2474 Animation.Free();
2475 Animation := nil;
2476 end;
2477 end
2478 else if (ShotType <> WEAPON_FLAMETHROWER) and ((oldvx <> Obj.Vel.X) or (oldvy <> Obj.Vel.Y)) then
2479 if gGameSettings.GameType = GT_SERVER then
2480 MH_SEND_UpdateShot(i);
2481 end;
2482 end;
2483 end;
2485 procedure g_Weapon_Draw();
2486 var
2487 i: Integer;
2488 a: SmallInt;
2489 p: TDFPoint;
2490 begin
2491 if Shots = nil then
2492 Exit;
2494 for i := 0 to High(Shots) do
2495 if Shots[i].ShotType <> 0 then
2496 with Shots[i] do
2497 begin
2498 if (Shots[i].ShotType = WEAPON_ROCKETLAUNCHER) or
2499 (Shots[i].ShotType = WEAPON_BARON_FIRE) or
2500 (Shots[i].ShotType = WEAPON_MANCUB_FIRE) or
2501 (Shots[i].ShotType = WEAPON_SKEL_FIRE) then
2502 a := -GetAngle2(Obj.Vel.X, Obj.Vel.Y)
2503 else
2504 a := 0;
2506 p.X := Obj.Rect.Width div 2;
2507 p.Y := Obj.Rect.Height div 2;
2509 if Animation <> nil then
2510 begin
2511 if (Shots[i].ShotType = WEAPON_BARON_FIRE) or
2512 (Shots[i].ShotType = WEAPON_MANCUB_FIRE) or
2513 (Shots[i].ShotType = WEAPON_SKEL_FIRE) then
2514 Animation.DrawEx(Obj.X, Obj.Y, TMirrorType.None, p, a)
2515 else
2516 Animation.Draw(Obj.X, Obj.Y, TMirrorType.None);
2517 end
2518 else if TextureID <> 0 then
2519 begin
2520 if (Shots[i].ShotType = WEAPON_ROCKETLAUNCHER) then
2521 e_DrawAdv(TextureID, Obj.X, Obj.Y, 0, True, False, a, @p, TMirrorType.None)
2522 else if (Shots[i].ShotType <> WEAPON_FLAMETHROWER) then
2523 e_Draw(TextureID, Obj.X, Obj.Y, 0, True, False);
2524 end;
2526 if g_debug_Frames then
2527 begin
2528 e_DrawQuad(Obj.X+Obj.Rect.X,
2529 Obj.Y+Obj.Rect.Y,
2530 Obj.X+Obj.Rect.X+Obj.Rect.Width-1,
2531 Obj.Y+Obj.Rect.Y+Obj.Rect.Height-1,
2532 0, 255, 0);
2533 end;
2534 end;
2535 end;
2537 function g_Weapon_Danger(UID: Word; X, Y: Integer; Width, Height: Word; Time: Byte): Boolean;
2538 var
2539 a: Integer;
2540 begin
2541 Result := False;
2543 if Shots = nil then
2544 Exit;
2546 for a := 0 to High(Shots) do
2547 if (Shots[a].ShotType <> 0) and (Shots[a].SpawnerUID <> UID) then
2548 if ((Shots[a].Obj.Vel.Y = 0) and (Shots[a].Obj.Vel.X > 0) and (Shots[a].Obj.X < X)) or
2549 (Shots[a].Obj.Vel.Y = 0) and (Shots[a].Obj.Vel.X < 0) and (Shots[a].Obj.X > X) then
2550 if (Abs(X-Shots[a].Obj.X) < Abs(Shots[a].Obj.Vel.X*Time)) and
2551 g_Collide(X, Y, Width, Height, X, Shots[a].Obj.Y,
2552 Shots[a].Obj.Rect.Width, Shots[a].Obj.Rect.Height) and
2553 g_TraceVector(X, Y, Shots[a].Obj.X, Shots[a].Obj.Y) then
2554 begin
2555 Result := True;
2556 Exit;
2557 end;
2558 end;
2560 procedure g_Weapon_SaveState (st: TStream);
2561 var
2562 count, i, j: Integer;
2563 begin
2564 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ ñíàðÿäîâ
2565 count := 0;
2566 for i := 0 to High(Shots) do if (Shots[i].ShotType <> 0) then Inc(count);
2568 // Êîëè÷åñòâî ñíàðÿäîâ
2569 utils.WriteInt(st, count);
2571 if (count = 0) then exit;
2573 for i := 0 to High(Shots) do
2574 begin
2575 if Shots[i].ShotType <> 0 then
2576 begin
2577 // Ñèãíàòóðà ñíàðÿäà
2578 utils.writeSign(st, 'SHOT');
2579 utils.writeInt(st, Byte(0)); // version
2580 // Òèï ñíàðÿäà
2581 utils.writeInt(st, Byte(Shots[i].ShotType));
2582 // Öåëü
2583 utils.writeInt(st, Word(Shots[i].Target));
2584 // UID ñòðåëÿâøåãî
2585 utils.writeInt(st, Word(Shots[i].SpawnerUID));
2586 // Ðàçìåð ïîëÿ Triggers
2587 utils.writeInt(st, Integer(Length(Shots[i].Triggers)));
2588 // Òðèããåðû, àêòèâèðîâàííûå âûñòðåëîì
2589 for j := 0 to Length(Shots[i].Triggers)-1 do utils.writeInt(st, LongWord(Shots[i].Triggers[j]));
2590 // Îáúåêò ñíàðÿäà
2591 Obj_SaveState(st, @Shots[i].Obj);
2592 // Êîñòûëèíà åáàíàÿ
2593 utils.writeInt(st, Byte(Shots[i].Stopped));
2594 end;
2595 end;
2596 end;
2598 procedure g_Weapon_LoadState (st: TStream);
2599 var
2600 count, tc, i, j: Integer;
2601 dw: LongWord;
2602 begin
2603 if (st = nil) then exit;
2605 // Êîëè÷åñòâî ñíàðÿäîâ
2606 count := utils.readLongInt(st);
2607 if (count < 0) or (count > 1024*1024) then raise XStreamError.Create('invalid shots counter');
2609 SetLength(Shots, count);
2611 if (count = 0) then exit;
2613 for i := 0 to count-1 do
2614 begin
2615 // Ñèãíàòóðà ñíàðÿäà
2616 if not utils.checkSign(st, 'SHOT') then raise XStreamError.Create('invalid shot signature');
2617 if (utils.readByte(st) <> 0) then raise XStreamError.Create('invalid shot version');
2618 // Òèï ñíàðÿäà:
2619 Shots[i].ShotType := utils.readByte(st);
2620 // Öåëü
2621 Shots[i].Target := utils.readWord(st);
2622 // UID ñòðåëÿâøåãî
2623 Shots[i].SpawnerUID := utils.readWord(st);
2624 // Ðàçìåð ïîëÿ Triggers
2625 tc := utils.readLongInt(st);
2626 if (tc < 0) or (tc > 1024*1024) then raise XStreamError.Create('invalid shot triggers counter');
2627 SetLength(Shots[i].Triggers, tc);
2628 // Òðèããåðû, àêòèâèðîâàííûå âûñòðåëîì
2629 for j := 0 to tc-1 do Shots[i].Triggers[j] := utils.readLongWord(st);
2630 // Îáúåêò ïðåäìåòà
2631 Obj_LoadState(@Shots[i].Obj, st);
2632 // Êîñòûëèíà åáàíàÿ
2633 Shots[i].Stopped := utils.readByte(st);
2635 // Óñòàíîâêà òåêñòóðû èëè àíèìàöèè
2636 Shots[i].TextureID := DWORD(-1);
2637 Shots[i].Animation := nil;
2639 case Shots[i].ShotType of
2640 WEAPON_ROCKETLAUNCHER, WEAPON_SKEL_FIRE:
2641 begin
2642 g_Texture_Get('TEXTURE_WEAPON_ROCKET', Shots[i].TextureID);
2643 end;
2644 WEAPON_PLASMA:
2645 begin
2646 g_Frames_Get(dw, 'FRAMES_WEAPON_PLASMA');
2647 Shots[i].Animation := TAnimation.Create(dw, True, 5);
2648 end;
2649 WEAPON_BFG:
2650 begin
2651 g_Frames_Get(dw, 'FRAMES_WEAPON_BFG');
2652 Shots[i].Animation := TAnimation.Create(dw, True, 6);
2653 end;
2654 WEAPON_IMP_FIRE:
2655 begin
2656 g_Frames_Get(dw, 'FRAMES_WEAPON_IMPFIRE');
2657 Shots[i].Animation := TAnimation.Create(dw, True, 4);
2658 end;
2659 WEAPON_BSP_FIRE:
2660 begin
2661 g_Frames_Get(dw, 'FRAMES_WEAPON_BSPFIRE');
2662 Shots[i].Animation := TAnimation.Create(dw, True, 4);
2663 end;
2664 WEAPON_CACO_FIRE:
2665 begin
2666 g_Frames_Get(dw, 'FRAMES_WEAPON_CACOFIRE');
2667 Shots[i].Animation := TAnimation.Create(dw, True, 4);
2668 end;
2669 WEAPON_BARON_FIRE:
2670 begin
2671 g_Frames_Get(dw, 'FRAMES_WEAPON_BARONFIRE');
2672 Shots[i].Animation := TAnimation.Create(dw, True, 4);
2673 end;
2674 WEAPON_MANCUB_FIRE:
2675 begin
2676 g_Frames_Get(dw, 'FRAMES_WEAPON_MANCUBFIRE');
2677 Shots[i].Animation := TAnimation.Create(dw, True, 4);
2678 end;
2679 end;
2680 end;
2681 end;
2683 procedure g_Weapon_DestroyShot(I: Integer; X, Y: Integer; Loud: Boolean = True);
2684 var
2685 cx, cy: Integer;
2686 Anim: TAnimation;
2687 s: string;
2688 begin
2689 if Shots = nil then
2690 Exit;
2691 if (I > High(Shots)) or (I < 0) then Exit;
2693 with Shots[I] do
2694 begin
2695 if ShotType = 0 then Exit;
2696 Obj.X := X;
2697 Obj.Y := Y;
2698 cx := Obj.X + (Obj.Rect.Width div 2);
2699 cy := Obj.Y + (Obj.Rect.Height div 2);
2701 case ShotType of
2702 WEAPON_ROCKETLAUNCHER, WEAPON_SKEL_FIRE: // Ðàêåòû è ñíàðÿäû Ñêåëåòà
2703 begin
2704 if Loud then
2705 begin
2706 if ShotType = WEAPON_SKEL_FIRE then
2707 begin // Âçðûâ ñíàðÿäà Ñêåëåòà
2708 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_SKELFIRE') then
2709 begin
2710 Anim := TAnimation.Create(TextureID, False, 8);
2711 Anim.Blending := False;
2712 g_GFX_OnceAnim((Obj.X+32)-32, (Obj.Y+8)-32, Anim);
2713 Anim.Free();
2714 end;
2715 end
2716 else
2717 begin // Âçðûâ Ðàêåòû
2718 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_ROCKET') then
2719 begin
2720 Anim := TAnimation.Create(TextureID, False, 6);
2721 Anim.Blending := False;
2722 g_GFX_OnceAnim(cx-64, cy-64, Anim);
2723 Anim.Free();
2724 end;
2725 end;
2726 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', Obj.X, Obj.Y);
2727 end;
2728 end;
2730 WEAPON_PLASMA, WEAPON_BSP_FIRE: // Ïëàçìà, ïëàçìà Àðàõíàòðîíà
2731 begin
2732 if ShotType = WEAPON_PLASMA then
2733 s := 'FRAMES_EXPLODE_PLASMA'
2734 else
2735 s := 'FRAMES_EXPLODE_BSPFIRE';
2737 if g_Frames_Get(TextureID, s) and loud then
2738 begin
2739 Anim := TAnimation.Create(TextureID, False, 3);
2740 Anim.Blending := False;
2741 g_GFX_OnceAnim(cx-16, cy-16, Anim);
2742 Anim.Free();
2744 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEPLASMA', Obj.X, Obj.Y);
2745 end;
2746 end;
2748 WEAPON_BFG: // BFG
2749 begin
2750 // Âçðûâ BFG:
2751 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_BFG') and Loud then
2752 begin
2753 Anim := TAnimation.Create(TextureID, False, 6);
2754 Anim.Blending := False;
2755 g_GFX_OnceAnim(cx-64, cy-64, Anim);
2756 Anim.Free();
2758 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', Obj.X, Obj.Y);
2759 end;
2760 end;
2762 WEAPON_IMP_FIRE, WEAPON_CACO_FIRE, WEAPON_BARON_FIRE: // Âûñòðåëû Áåñà, Êàêîäåìîíà Ðûöàðÿ/Áàðîíà àäà
2763 begin
2764 if ShotType = WEAPON_IMP_FIRE then
2765 s := 'FRAMES_EXPLODE_IMPFIRE'
2766 else
2767 if ShotType = WEAPON_CACO_FIRE then
2768 s := 'FRAMES_EXPLODE_CACOFIRE'
2769 else
2770 s := 'FRAMES_EXPLODE_BARONFIRE';
2772 if g_Frames_Get(TextureID, s) and Loud then
2773 begin
2774 Anim := TAnimation.Create(TextureID, False, 6);
2775 Anim.Blending := False;
2776 g_GFX_OnceAnim(cx-32, cy-32, Anim);
2777 Anim.Free();
2779 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj.X, Obj.Y);
2780 end;
2781 end;
2783 WEAPON_MANCUB_FIRE: // Âûñòðåë Ìàíêóáóñà
2784 begin
2785 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_ROCKET') and Loud then
2786 begin
2787 Anim := TAnimation.Create(TextureID, False, 6);
2788 Anim.Blending := False;
2789 g_GFX_OnceAnim(cx-64, cy-64, Anim);
2790 Anim.Free();
2792 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj.X, Obj.Y);
2793 end;
2794 end;
2795 end; // case ShotType of...
2797 ShotType := 0;
2798 Animation.Free();
2799 end;
2800 end;
2803 procedure g_Weapon_AddDynLights();
2804 var
2805 i: Integer;
2806 begin
2807 if Shots = nil then Exit;
2808 for i := 0 to High(Shots) do
2809 begin
2810 if Shots[i].ShotType = 0 then continue;
2811 if (Shots[i].ShotType = WEAPON_ROCKETLAUNCHER) or
2812 (Shots[i].ShotType = WEAPON_BARON_FIRE) or
2813 (Shots[i].ShotType = WEAPON_MANCUB_FIRE) or
2814 (Shots[i].ShotType = WEAPON_SKEL_FIRE) or
2815 (Shots[i].ShotType = WEAPON_IMP_FIRE) or
2816 (Shots[i].ShotType = WEAPON_CACO_FIRE) or
2817 (Shots[i].ShotType = WEAPON_MANCUB_FIRE) or
2818 (Shots[i].ShotType = WEAPON_BSP_FIRE) or
2819 (Shots[i].ShotType = WEAPON_PLASMA) or
2820 (Shots[i].ShotType = WEAPON_BFG) or
2821 (Shots[i].ShotType = WEAPON_FLAMETHROWER) or
2822 false then
2823 begin
2824 if (Shots[i].ShotType = WEAPON_PLASMA) then
2825 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)
2826 else if (Shots[i].ShotType = WEAPON_BFG) then
2827 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)
2828 else if (Shots[i].ShotType = WEAPON_FLAMETHROWER) then
2829 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)
2830 else
2831 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);
2832 end;
2833 end;
2834 end;
2837 procedure TShot.positionChanged (); begin end;
2840 end.