DEADSOFTWARE

8fdde869c0bcda1b9a175a3805bc0c2bc528be53
[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, version 3 of the License ONLY.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14 *)
15 {$INCLUDE ../shared/a_modes.inc}
16 {.$DEFINE GWEP_HITSCAN_TRACE_BITMAP_CHECKER}
17 unit g_weapons;
19 interface
21 uses
22 SysUtils, Classes, mempool,
23 g_basic, g_phys, xprofiler;
26 type
27 TShot = record
28 ShotType: Byte;
29 Target: Word;
30 SpawnerUID: Word;
31 Triggers: DWArray;
32 Obj: TObj;
33 time: LongWord;
34 Timeout: DWORD;
35 Stopped: Byte;
37 procedure positionChanged (); //WARNING! call this after monster position was changed, or coldet will not work right!
38 end;
41 var
42 Shots: array of TShot = nil;
43 LastShotID: Integer = 0;
45 procedure g_Weapon_LoadData();
46 procedure g_Weapon_FreeData();
47 procedure g_Weapon_Init();
48 procedure g_Weapon_Free();
49 function g_Weapon_Hit(obj: PObj; d: Integer; SpawnerUID: Word; t: Byte; HitCorpses: Boolean = True): Byte;
50 function g_Weapon_HitUID(UID: Word; d: Integer; SpawnerUID: Word; t: Byte): Boolean;
51 function g_Weapon_CreateShot(I: Integer; ShotType: Byte; Spawner, TargetUID: Word; X, Y, XV, YV: Integer): LongWord;
53 procedure g_Weapon_gun(const x, y, xd, yd, v, indmg: Integer; SpawnerUID: Word; CheckTrigger: Boolean);
54 procedure g_Weapon_punch(x, y: Integer; d, SpawnerUID: Word);
55 function g_Weapon_chainsaw(x, y: Integer; d, SpawnerUID: Word): Integer;
56 procedure g_Weapon_rocket(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1; Silent: Boolean = False; compat: Boolean = true);
57 procedure g_Weapon_revf(x, y, xd, yd: Integer; SpawnerUID, TargetUID: Word; WID: Integer = -1; Silent: Boolean = False);
58 procedure g_Weapon_flame(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1; Silent: Boolean = False; compat: Boolean = true);
59 procedure g_Weapon_plasma(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1; Silent: Boolean = False; compat: Boolean = true);
60 procedure g_Weapon_ball1(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1; Silent: Boolean = False; compat: Boolean = true);
61 procedure g_Weapon_ball2(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1; Silent: Boolean = False; compat: Boolean = true);
62 procedure g_Weapon_ball7(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1; Silent: Boolean = False; compat: Boolean = true);
63 procedure g_Weapon_aplasma(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1; Silent: Boolean = False; compat: Boolean = true);
64 procedure g_Weapon_manfire(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1; Silent: Boolean = False; compat: Boolean = true);
65 procedure g_Weapon_bfgshot(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1; Silent: Boolean = False; compat: Boolean = true);
66 procedure g_Weapon_bfghit(x, y: Integer);
67 procedure g_Weapon_pistol(x, y, xd, yd: Integer; SpawnerUID: Word; Silent: Boolean = False);
68 procedure g_Weapon_mgun(x, y, xd, yd: Integer; SpawnerUID: Word; Silent: Boolean = False);
69 procedure g_Weapon_shotgun(x, y, xd, yd: Integer; SpawnerUID: Word; Silent: Boolean = False);
70 procedure g_Weapon_dshotgun(x, y, xd, yd: Integer; SpawnerUID: Word; Silent: Boolean = False);
72 function g_Weapon_Explode(X, Y: Integer; rad: Integer; SpawnerUID: Word): Boolean;
73 procedure g_Weapon_BFG9000(X, Y: Integer; SpawnerUID: Word);
74 procedure g_Weapon_PreUpdate();
75 procedure g_Weapon_Update();
76 function g_Weapon_Danger(UID: Word; X, Y: Integer; Width, Height: Word; Time: Byte): Boolean;
77 procedure g_Weapon_DestroyShot(I: Integer; X, Y: Integer; Loud: Boolean = True);
79 procedure g_Weapon_SaveState (st: TStream);
80 procedure g_Weapon_LoadState (st: TStream);
82 procedure g_Weapon_AddDynLights();
84 const
85 WEAPON_KASTET = 0;
86 WEAPON_SAW = 1;
87 WEAPON_PISTOL = 2;
88 WEAPON_SHOTGUN1 = 3;
89 WEAPON_SHOTGUN2 = 4;
90 WEAPON_CHAINGUN = 5;
91 WEAPON_ROCKETLAUNCHER = 6;
92 WEAPON_PLASMA = 7;
93 WEAPON_BFG = 8;
94 WEAPON_SUPERPULEMET = 9;
95 WEAPON_FLAMETHROWER = 10;
96 WEAPON_ZOMBY_PISTOL = 20;
97 WEAPON_IMP_FIRE = 21;
98 WEAPON_BSP_FIRE = 22;
99 WEAPON_CACO_FIRE = 23;
100 WEAPON_BARON_FIRE = 24;
101 WEAPON_MANCUB_FIRE = 25;
102 WEAPON_SKEL_FIRE = 26;
103 WEAPON_LAST = WEAPON_SKEL_FIRE;
105 WP_FIRST = WEAPON_KASTET;
106 WP_LAST = WEAPON_FLAMETHROWER;
108 var
109 gwep_debug_fast_trace: Boolean = true;
112 implementation
114 uses
115 {$IFDEF ENABLE_GFX}
116 g_gfx,
117 {$ENDIF}
118 {$IFDEF ENABLE_GIBS}
119 g_gibs,
120 {$ENDIF}
121 {$IFDEF ENABLE_CORPSES}
122 g_corpses,
123 {$ENDIF}
124 Math, g_map, g_player, g_sound, g_panel,
125 g_console, g_options, g_game,
126 g_triggers, MAPDEF, e_log, g_monsters, g_saveload,
127 g_language, g_netmsg, g_grid,
128 geom, binheap, hashtable, utils, xstreams
131 type
132 TWaterPanel = record
133 X, Y: Integer;
134 Width, Height: Word;
135 Active: Boolean;
136 end;
138 const
139 SHOT_ROCKETLAUNCHER_WIDTH = 14;
140 SHOT_ROCKETLAUNCHER_HEIGHT = 14;
142 SHOT_SKELFIRE_WIDTH = 14;
143 SHOT_SKELFIRE_HEIGHT = 14;
145 SHOT_PLASMA_WIDTH = 16;
146 SHOT_PLASMA_HEIGHT = 16;
148 SHOT_BFG_WIDTH = 32;
149 SHOT_BFG_HEIGHT = 32;
150 SHOT_BFG_DAMAGE = 100;
151 SHOT_BFG_RADIUS = 256;
153 SHOT_FLAME_WIDTH = 4;
154 SHOT_FLAME_HEIGHT = 4;
155 SHOT_FLAME_LIFETIME = 180;
157 SHOT_SIGNATURE = $544F4853; // 'SHOT'
159 type
160 PHitTime = ^THitTime;
161 THitTime = record
162 distSq: Integer;
163 mon: TMonster;
164 plridx: Integer; // if mon=nil
165 x, y: Integer;
166 end;
168 TBinHeapKeyHitTime = class
169 public
170 class function less (const a, b: Integer): Boolean; inline;
171 end;
173 // indicies in `wgunHitTime` array
174 TBinaryHeapHitTimes = specialize TBinaryHeapBase<Integer, TBinHeapKeyHitTime>;
176 var
177 WaterMap: array of array of DWORD = nil;
178 //wgunMonHash: THashIntInt = nil;
179 wgunHitHeap: TBinaryHeapHitTimes = nil;
180 wgunHitTime: array of THitTime = nil;
181 wgunHitTimeUsed: Integer = 0;
184 class function TBinHeapKeyHitTime.less (const a, b: Integer): Boolean;
185 var
186 hta, htb: PHitTime;
187 begin
188 hta := @wgunHitTime[a];
189 htb := @wgunHitTime[b];
190 if (hta.distSq <> htb.distSq) then begin result := (hta.distSq < htb.distSq); exit; end;
191 if (hta.mon <> nil) then
192 begin
193 // a is monster
194 if (htb.mon = nil) then begin result := false; exit; end; // players first
195 result := (hta.mon.UID < htb.mon.UID); // why not?
196 end
197 else
198 begin
199 // a is player
200 if (htb.mon <> nil) then begin result := true; exit; end; // players first
201 result := (hta.plridx < htb.plridx); // why not?
202 end;
203 end;
206 procedure appendHitTimeMon (adistSq: Integer; amon: TMonster; ax, ay: Integer);
207 begin
208 if (wgunHitTimeUsed = Length(wgunHitTime)) then SetLength(wgunHitTime, wgunHitTimeUsed+128);
209 with wgunHitTime[wgunHitTimeUsed] do
210 begin
211 distSq := adistSq;
212 mon := amon;
213 plridx := -1;
214 x := ax;
215 y := ay;
216 end;
217 wgunHitHeap.insert(wgunHitTimeUsed);
218 Inc(wgunHitTimeUsed);
219 end;
222 procedure appendHitTimePlr (adistSq: Integer; aplridx: Integer; ax, ay: Integer);
223 begin
224 if (wgunHitTimeUsed = Length(wgunHitTime)) then SetLength(wgunHitTime, wgunHitTimeUsed+128);
225 with wgunHitTime[wgunHitTimeUsed] do
226 begin
227 distSq := adistSq;
228 mon := nil;
229 plridx := aplridx;
230 x := ax;
231 y := ay;
232 end;
233 wgunHitHeap.insert(wgunHitTimeUsed);
234 Inc(wgunHitTimeUsed);
235 end;
238 function FindShot(): DWORD;
239 var
240 i: Integer;
241 begin
242 if Shots <> nil then
243 for i := 0 to High(Shots) do
244 if Shots[i].ShotType = 0 then
245 begin
246 Result := i;
247 LastShotID := Result;
248 Exit;
249 end;
251 if Shots = nil then
252 begin
253 SetLength(Shots, 128);
254 Result := 0;
255 end
256 else
257 begin
258 Result := High(Shots) + 1;
259 SetLength(Shots, Length(Shots) + 128);
260 end;
261 LastShotID := Result;
262 end;
264 procedure CreateWaterMap();
265 var
266 WaterArray: Array of TWaterPanel;
267 a, b, c, m: Integer;
268 ok: Boolean;
269 begin
270 if gWater = nil then
271 Exit;
273 SetLength(WaterArray, Length(gWater));
275 for a := 0 to High(gWater) do
276 begin
277 WaterArray[a].X := gWater[a].X;
278 WaterArray[a].Y := gWater[a].Y;
279 WaterArray[a].Width := gWater[a].Width;
280 WaterArray[a].Height := gWater[a].Height;
281 WaterArray[a].Active := True;
282 end;
284 g_Game_SetLoadingText(_lc[I_LOAD_WATER_MAP], High(WaterArray), False);
286 for a := 0 to High(WaterArray) do
287 if WaterArray[a].Active then
288 begin
289 WaterArray[a].Active := False;
290 m := Length(WaterMap);
291 SetLength(WaterMap, m+1);
292 SetLength(WaterMap[m], 1);
293 WaterMap[m][0] := a;
294 ok := True;
296 while ok do
297 begin
298 ok := False;
299 for b := 0 to High(WaterArray) do
300 if WaterArray[b].Active then
301 for c := 0 to High(WaterMap[m]) do
302 if g_CollideAround(WaterArray[b].X,
303 WaterArray[b].Y,
304 WaterArray[b].Width,
305 WaterArray[b].Height,
306 WaterArray[WaterMap[m][c]].X,
307 WaterArray[WaterMap[m][c]].Y,
308 WaterArray[WaterMap[m][c]].Width,
309 WaterArray[WaterMap[m][c]].Height) then
310 begin
311 WaterArray[b].Active := False;
312 SetLength(WaterMap[m],
313 Length(WaterMap[m])+1);
314 WaterMap[m][High(WaterMap[m])] := b;
315 ok := True;
316 Break;
317 end;
318 end;
320 g_Game_StepLoading();
321 end;
323 WaterArray := nil;
324 end;
327 var
328 chkTrap_pl: array [0..256] of Integer;
329 chkTrap_mn: array [0..65535] of TMonster;
331 procedure CheckTrap(ID: DWORD; dm: Integer; t: Byte);
332 var
333 //a, b, c, d, i1, i2: Integer;
334 //chkTrap_pl, chkTrap_mn: WArray;
335 plaCount: Integer = 0;
336 mnaCount: Integer = 0;
337 frameId: DWord;
340 function monsWaterCheck (mon: TMonster): Boolean;
341 begin
342 result := false; // don't stop
343 if mon.alive and mon.Collide(gWater[WaterMap[a][c]]) and (not InWArray(monidx, chkTrap_mn)) and (i2 < 1023) then //FIXME
344 begin
345 i2 += 1;
346 chkTrap_mn[i2] := monidx;
347 end;
348 end;
351 function monsWaterCheck (mon: TMonster): Boolean;
352 begin
353 result := false; // don't stop
354 if (mon.trapCheckFrameId <> frameId) then
355 begin
356 mon.trapCheckFrameId := frameId;
357 chkTrap_mn[mnaCount] := mon;
358 Inc(mnaCount);
359 end;
360 end;
362 var
363 a, b, c, d, f: Integer;
364 pan: TPanel;
365 begin
366 if (gWater = nil) or (WaterMap = nil) then Exit;
368 frameId := g_Mons_getNewTrapFrameId();
370 //i1 := -1;
371 //i2 := -1;
373 //SetLength(chkTrap_pl, 1024);
374 //SetLength(chkTrap_mn, 1024);
375 //for d := 0 to 1023 do chkTrap_pl[d] := $FFFF;
376 //for d := 0 to 1023 do chkTrap_mn[d] := $FFFF;
378 for a := 0 to High(WaterMap) do
379 begin
380 for b := 0 to High(WaterMap[a]) do
381 begin
382 pan := gWater[WaterMap[a][b]];
383 if not g_Obj_Collide(pan.X, pan.Y, pan.Width, pan.Height, @Shots[ID].Obj) then continue;
385 for c := 0 to High(WaterMap[a]) do
386 begin
387 pan := gWater[WaterMap[a][c]];
388 for d := 0 to High(gPlayers) do
389 begin
390 if (gPlayers[d] <> nil) and (gPlayers[d].alive) then
391 begin
392 if gPlayers[d].Collide(pan) then
393 begin
394 f := 0;
395 while (f < plaCount) and (chkTrap_pl[f] <> d) do Inc(f);
396 if (f = plaCount) then
397 begin
398 chkTrap_pl[plaCount] := d;
399 Inc(plaCount);
400 if (plaCount = Length(chkTrap_pl)) then break;
401 end;
402 end;
403 end;
404 end;
406 //g_Mons_ForEach(monsWaterCheck);
407 g_Mons_ForEachAliveAt(pan.X, pan.Y, pan.Width, pan.Height, monsWaterCheck);
408 end;
410 for f := 0 to plaCount-1 do gPlayers[chkTrap_pl[f]].Damage(dm, Shots[ID].SpawnerUID, 0, 0, t);
411 for f := 0 to mnaCount-1 do chkTrap_mn[f].Damage(dm, 0, 0, Shots[ID].SpawnerUID, t);
412 end;
413 end;
415 //chkTrap_pl := nil;
416 //chkTrap_mn := nil;
417 end;
419 function HitMonster(m: TMonster; d: Integer; vx, vy: Integer; SpawnerUID: Word; t: Byte): Boolean;
420 var
421 tt, mt: Byte;
422 mon: TMonster;
423 begin
424 Result := False;
426 tt := g_GetUIDType(SpawnerUID);
427 if tt = UID_MONSTER then
428 begin
429 mon := g_Monsters_ByUID(SpawnerUID);
430 if mon <> nil then
431 mt := g_Monsters_ByUID(SpawnerUID).MonsterType
432 else
433 mt := 0;
434 end
435 else
436 mt := 0;
438 if m = nil then Exit;
439 if m.UID = SpawnerUID then
440 begin
441 // Ñàì ñåáÿ ìîæåò ðàíèòü òîëüêî ðàêåòîé è òîêîì:
442 if (t <> HIT_ROCKET) and (t <> HIT_ELECTRO) then
443 Exit;
444 // Êèáåð äåìîí è áî÷êà âîîáùå íå ìîãóò ñåáÿ ðàíèòü:
445 if (m.MonsterType = MONSTER_CYBER) or
446 (m.MonsterType = MONSTER_BARREL) then
447 begin
448 Result := True;
449 Exit;
450 end;
451 end;
453 if tt = UID_MONSTER then
454 begin
455 // Lost_Soul íå ìîæåò ðàíèòü Pain_Elemental'à:
456 if (mt = MONSTER_SOUL) and (m.MonsterType = MONSTER_PAIN) then
457 Exit;
459 // Îáà ìîíñòðà îäíîãî âèäà:
460 if mt = m.MonsterType then
461 case mt of
462 MONSTER_IMP, MONSTER_DEMON, MONSTER_BARON, MONSTER_KNIGHT, MONSTER_CACO,
463 MONSTER_SOUL, MONSTER_MANCUB, MONSTER_SKEL, MONSTER_FISH:
464 Exit; // Ýòè íå áüþò ñâîèõ
465 end;
466 end;
468 if g_Game_IsServer then
469 begin
470 if (t <> HIT_FLAME) or (m.FFireTime = 0) or (vx <> 0) or (vy <> 0) then
471 Result := m.Damage(d, vx, vy, SpawnerUID, t)
472 else
473 Result := (gLMSRespawn = LMS_RESPAWN_NONE); // don't hit monsters when it's warmup time
474 if t = HIT_FLAME then
475 m.CatchFire(SpawnerUID);
476 end
477 else
478 Result := (gLMSRespawn = LMS_RESPAWN_NONE); // don't hit monsters when it's warmup time
479 end;
482 function HitPlayer (p: TPlayer; d: Integer; vx, vy: Integer; SpawnerUID: Word; t: Byte): Boolean;
483 begin
484 result := False;
486 // Ñàì ñåáÿ ìîæåò ðàíèòü òîëüêî ðàêåòîé è òîêîì
487 if (p.UID = SpawnerUID) and (t <> HIT_ROCKET) and (t <> HIT_ELECTRO) then exit;
489 if g_Game_IsServer then
490 begin
491 if (t <> HIT_FLAME) or (p.FFireTime = 0) or (vx <> 0) or (vy <> 0) then p.Damage(d, SpawnerUID, vx, vy, t);
492 if (t = HIT_FLAME) then p.CatchFire(SpawnerUID);
493 end;
495 result := true;
496 end;
499 procedure g_Weapon_BFG9000(X, Y: Integer; SpawnerUID: Word);
501 function monsCheck (mon: TMonster): Boolean;
502 begin
503 result := false; // don't stop
504 if (mon.alive) and (mon.UID <> SpawnerUID) then
505 begin
506 with mon do
507 begin
508 if (g_PatchLength(X, Y, Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2),
509 Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)) <= SHOT_BFG_RADIUS) and
510 g_TraceVector(X, Y, Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2),
511 Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)) then
512 begin
513 if HitMonster(mon, 50, 0, 0, SpawnerUID, HIT_SOME) then mon.BFGHit();
514 end;
515 end;
516 end;
517 end;
519 var
520 i, h: Integer;
521 st: Byte;
522 pl: TPlayer;
523 b: Boolean;
524 begin
525 //g_Sound_PlayEx('SOUND_WEAPON_EXPLODEBFG', 255);
527 {$IFDEF ENABLE_CORPSES}
528 h := High(gCorpses);
529 if gAdvCorpses and (h <> -1) then
530 begin
531 for i := 0 to h do
532 begin
533 if (gCorpses[i] <> nil) and (gCorpses[i].State <> CORPSE_STATE_REMOVEME) then
534 begin
535 with gCorpses[i] do
536 begin
537 if (g_PatchLength(X, Y, Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2),
538 Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)) <= SHOT_BFG_RADIUS) and
539 g_TraceVector(X, Y, Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2),
540 Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)) then
541 begin
542 Damage(50, SpawnerUID, 0, 0);
543 g_Weapon_BFGHit(Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2), Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2));
544 end;
545 end;
546 end;
547 end;
548 end;
549 {$ENDIF}
551 st := TEAM_NONE;
552 pl := g_Player_Get(SpawnerUID);
553 if pl <> nil then
554 st := pl.Team;
556 h := High(gPlayers);
558 if h <> -1 then
559 for i := 0 to h do
560 if (gPlayers[i] <> nil) and (gPlayers[i].alive) and (gPlayers[i].UID <> SpawnerUID) then
561 with gPlayers[i] do
562 if (g_PatchLength(X, Y, GameX+PLAYER_RECT.X+(PLAYER_RECT.Width div 2),
563 GameY+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)) <= SHOT_BFG_RADIUS) and
564 g_TraceVector(X, Y, GameX+PLAYER_RECT.X+(PLAYER_RECT.Width div 2),
565 GameY+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)) then
566 begin
567 if (st = TEAM_NONE) or (st <> gPlayers[i].Team) then
568 b := HitPlayer(gPlayers[i], 50, 0, 0, SpawnerUID, HIT_SOME)
569 else
570 b := HitPlayer(gPlayers[i], 25, 0, 0, SpawnerUID, HIT_SOME);
571 if b then
572 gPlayers[i].BFGHit();
573 end;
575 //FIXME
576 g_Mons_ForEachAlive(monsCheck);
577 end;
579 function g_Weapon_CreateShot(I: Integer; ShotType: Byte; Spawner, TargetUID: Word; X, Y, XV, YV: Integer): LongWord;
580 var
581 find_id: DWord;
582 begin
583 if I < 0 then
584 find_id := FindShot()
585 else
586 begin
587 find_id := I;
588 if Integer(find_id) >= High(Shots) then
589 SetLength(Shots, find_id + 64)
590 end;
592 shots[find_id].time := gTime;
594 case ShotType of
595 WEAPON_ROCKETLAUNCHER:
596 begin
597 with Shots[find_id] do
598 begin
599 g_Obj_Init(@Obj);
601 Obj.Rect.Width := SHOT_ROCKETLAUNCHER_WIDTH;
602 Obj.Rect.Height := SHOT_ROCKETLAUNCHER_HEIGHT;
604 Triggers := nil;
605 ShotType := WEAPON_ROCKETLAUNCHER;
606 end;
607 end;
609 WEAPON_PLASMA:
610 begin
611 with Shots[find_id] do
612 begin
613 g_Obj_Init(@Obj);
615 Obj.Rect.Width := SHOT_PLASMA_WIDTH;
616 Obj.Rect.Height := SHOT_PLASMA_HEIGHT;
618 Triggers := nil;
619 ShotType := WEAPON_PLASMA;
620 end;
621 end;
623 WEAPON_BFG:
624 begin
625 with Shots[find_id] do
626 begin
627 g_Obj_Init(@Obj);
629 Obj.Rect.Width := SHOT_BFG_WIDTH;
630 Obj.Rect.Height := SHOT_BFG_HEIGHT;
632 Triggers := nil;
633 ShotType := WEAPON_BFG;
634 end;
635 end;
637 WEAPON_FLAMETHROWER:
638 begin
639 with Shots[find_id] do
640 begin
641 g_Obj_Init(@Obj);
643 Obj.Rect.Width := SHOT_FLAME_WIDTH;
644 Obj.Rect.Height := SHOT_FLAME_HEIGHT;
646 Triggers := nil;
647 ShotType := WEAPON_FLAMETHROWER;
648 end;
649 end;
651 WEAPON_IMP_FIRE:
652 begin
653 with Shots[find_id] do
654 begin
655 g_Obj_Init(@Obj);
657 Obj.Rect.Width := 16;
658 Obj.Rect.Height := 16;
660 Triggers := nil;
661 ShotType := WEAPON_IMP_FIRE;
662 end;
663 end;
665 WEAPON_CACO_FIRE:
666 begin
667 with Shots[find_id] do
668 begin
669 g_Obj_Init(@Obj);
671 Obj.Rect.Width := 16;
672 Obj.Rect.Height := 16;
674 Triggers := nil;
675 ShotType := WEAPON_CACO_FIRE;
676 end;
677 end;
679 WEAPON_MANCUB_FIRE:
680 begin
681 with Shots[find_id] do
682 begin
683 g_Obj_Init(@Obj);
685 Obj.Rect.Width := 32;
686 Obj.Rect.Height := 32;
688 Triggers := nil;
689 ShotType := WEAPON_MANCUB_FIRE;
690 end;
691 end;
693 WEAPON_BARON_FIRE:
694 begin
695 with Shots[find_id] do
696 begin
697 g_Obj_Init(@Obj);
699 Obj.Rect.Width := 16;
700 Obj.Rect.Height := 16;
702 Triggers := nil;
703 ShotType := WEAPON_BARON_FIRE;
704 end;
705 end;
707 WEAPON_BSP_FIRE:
708 begin
709 with Shots[find_id] do
710 begin
711 g_Obj_Init(@Obj);
713 Obj.Rect.Width := 16;
714 Obj.Rect.Height := 16;
716 Triggers := nil;
717 ShotType := WEAPON_BSP_FIRE;
718 end;
719 end;
721 WEAPON_SKEL_FIRE:
722 begin
723 with Shots[find_id] do
724 begin
725 g_Obj_Init(@Obj);
727 Obj.Rect.Width := SHOT_SKELFIRE_WIDTH;
728 Obj.Rect.Height := SHOT_SKELFIRE_HEIGHT;
730 Triggers := nil;
731 ShotType := WEAPON_SKEL_FIRE;
732 target := TargetUID;
733 end;
734 end;
735 end;
737 Shots[find_id].Obj.oldX := X;
738 Shots[find_id].Obj.oldY := Y;
739 Shots[find_id].Obj.X := X;
740 Shots[find_id].Obj.Y := Y;
741 Shots[find_id].Obj.Vel.X := XV;
742 Shots[find_id].Obj.Vel.Y := YV;
743 Shots[find_id].Obj.Accel.X := 0;
744 Shots[find_id].Obj.Accel.Y := 0;
745 Shots[find_id].SpawnerUID := Spawner;
746 if (ShotType = WEAPON_FLAMETHROWER) and (XV = 0) and (YV = 0) then
747 Shots[find_id].Stopped := 255
748 else
749 Shots[find_id].Stopped := 0;
750 Result := find_id;
751 end;
753 procedure throw(i, x, y, xd, yd, s: Integer);
754 var
755 a: Integer;
756 begin
757 yd := yd - y;
758 xd := xd - x;
760 a := Max(Abs(xd), Abs(yd));
761 if a = 0 then
762 a := 1;
764 Shots[i].Obj.oldX := x;
765 Shots[i].Obj.oldY := y;
766 Shots[i].Obj.X := x;
767 Shots[i].Obj.Y := y;
768 Shots[i].Obj.Vel.X := (xd*s) div a;
769 Shots[i].Obj.Vel.Y := (yd*s) div a;
770 Shots[i].Obj.Accel.X := 0;
771 Shots[i].Obj.Accel.Y := 0;
772 Shots[i].Stopped := 0;
773 if Shots[i].ShotType in [WEAPON_ROCKETLAUNCHER, WEAPON_BFG] then
774 Shots[i].Timeout := 900 // ~25 sec
775 else
776 begin
777 if Shots[i].ShotType = WEAPON_FLAMETHROWER then
778 Shots[i].Timeout := SHOT_FLAME_LIFETIME
779 else
780 Shots[i].Timeout := 550; // ~15 sec
781 end;
782 end;
784 function g_Weapon_Hit(obj: PObj; d: Integer; SpawnerUID: Word; t: Byte; HitCorpses: Boolean = True): Byte;
785 {$IFDEF ENABLE_CORPSES}
786 var i: Integer;
787 {$ENDIF}
788 var h: Integer;
790 function PlayerHit(Team: Byte = 0): Boolean;
791 var
792 i: Integer;
793 ChkTeam: Boolean;
794 p: TPlayer;
795 begin
796 Result := False;
797 h := High(gPlayers);
799 if h <> -1 then
800 for i := 0 to h do
801 if (gPlayers[i] <> nil) and gPlayers[i].alive and g_Obj_Collide(obj, @gPlayers[i].Obj) then
802 begin
803 ChkTeam := True;
804 if (Team > 0) and (g_GetUIDType(SpawnerUID) = UID_PLAYER) then
805 begin
806 p := g_Player_Get(SpawnerUID);
807 if p <> nil then
808 ChkTeam := (p.Team = gPlayers[i].Team) xor (Team = 2);
809 end;
810 if ChkTeam then
811 if HitPlayer(gPlayers[i], d, obj^.Vel.X, obj^.Vel.Y, SpawnerUID, t) then
812 begin
813 if t <> HIT_FLAME then
814 gPlayers[i].Push((obj^.Vel.X+obj^.Accel.X)*IfThen(t = HIT_BFG, 8, 1) div 4,
815 (obj^.Vel.Y+obj^.Accel.Y)*IfThen(t = HIT_BFG, 8, 1) div 4);
816 if t = HIT_BFG then
817 g_Game_DelayEvent(DE_BFGHIT, 1000, SpawnerUID);
818 Result := True;
819 break;
820 end;
821 end;
822 end;
825 function monsCheckHit (monidx: Integer; mon: TMonster): Boolean;
826 begin
827 result := false; // don't stop
828 if mon.alive and g_Obj_Collide(obj, @mon.Obj) then
829 begin
830 if HitMonster(mon, d, obj^.Vel.X, obj^.Vel.Y, SpawnerUID, t) then
831 begin
832 if (t <> HIT_FLAME) then
833 begin
834 mon.Push((obj^.Vel.X+obj^.Accel.X)*IfThen(t = HIT_BFG, 8, 1) div 4,
835 (obj^.Vel.Y+obj^.Accel.Y)*IfThen(t = HIT_BFG, 8, 1) div 4);
836 end;
837 result := True;
838 end;
839 end;
840 end;
843 function monsCheckHit (mon: TMonster): Boolean;
844 begin
845 result := false; // don't stop
846 if HitMonster(mon, d, obj.Vel.X, obj.Vel.Y, SpawnerUID, t) then
847 begin
848 if (t <> HIT_FLAME) then
849 begin
850 mon.Push((obj.Vel.X+obj.Accel.X)*IfThen(t = HIT_BFG, 8, 1) div 4,
851 (obj.Vel.Y+obj.Accel.Y)*IfThen(t = HIT_BFG, 8, 1) div 4);
852 end;
853 result := true;
854 end;
855 end;
857 function MonsterHit(): Boolean;
858 begin
859 //result := g_Mons_ForEach(monsCheckHit);
860 //FIXME: accelerate this!
861 result := g_Mons_ForEachAliveAt(obj.X+obj.Rect.X, obj.Y+obj.Rect.Y, obj.Rect.Width, obj.Rect.Height, monsCheckHit);
862 end;
864 begin
865 Result := 0;
867 {$IFDEF ENABLE_CORPSES}
868 if HitCorpses then
869 begin
870 h := High(gCorpses);
871 if gAdvCorpses and (h <> -1) then
872 begin
873 for i := 0 to h do
874 begin
875 if (gCorpses[i] <> nil) and (gCorpses[i].State <> CORPSE_STATE_REMOVEME) and
876 g_Obj_Collide(obj, @gCorpses[i].Obj) then
877 begin
878 // Ðàñïèëèâàåì òðóï:
879 gCorpses[i].Damage(d, SpawnerUID, (obj^.Vel.X+obj^.Accel.X) div 4,
880 (obj^.Vel.Y+obj^.Accel.Y) div 4);
881 Result := 1;
882 end;
883 end;
884 end;
885 end;
886 {$ENDIF}
888 case gGameSettings.GameMode of
889 // Êàìïàíèÿ:
890 GM_COOP, GM_SINGLE:
891 begin
892 // Ñíà÷àëà áü¸ì ìîíñòðîâ, åñëè åñòü, ïîòîì ïûòàåìñÿ áèòü èãðîêîâ
893 if MonsterHit() then
894 begin
895 Result := 2;
896 Exit;
897 end;
899 // È â êîíöå èãðîêîâ, íî òîëüêî åñëè ïîëîæåíî
900 // (èëè ñíàðÿä îò ìîíñòðà, èëè friendlyfire, èëè friendly_hit_projectile)
901 if (g_GetUIDType(SpawnerUID) <> UID_PLAYER) or
902 LongBool(gGameSettings.Options and (GAME_OPTION_TEAMDAMAGE or GAME_OPTION_TEAMHITPROJECTILE)) then
903 begin
904 if PlayerHit() then
905 begin
906 Result := 1;
907 Exit;
908 end;
909 end;
910 end;
912 // Äåçìàò÷:
913 GM_DM:
914 begin
915 // Ñíà÷àëà áü¸ì èãðîêîâ, åñëè åñòü, ïîòîì ïûòàåìñÿ áèòü ìîíñòðîâ
916 if PlayerHit() then
917 begin
918 Result := 1;
919 Exit;
920 end;
922 if MonsterHit() then
923 begin
924 Result := 2;
925 Exit;
926 end;
927 end;
929 // Êîìàíäíûå:
930 GM_TDM, GM_CTF:
931 begin
932 // Ñíà÷àëà áü¸ì èãðîêîâ êîìàíäû ñîïåðíèêà
933 if PlayerHit(2) then
934 begin
935 Result := 1;
936 Exit;
937 end;
939 // Ïîòîì ìîíñòðîâ
940 if MonsterHit() then
941 begin
942 Result := 2;
943 Exit;
944 end;
946 // È â êîíöå ñâîèõ èãðîêîâ, íî òîëüêî åñëè ïîëîæåíî
947 // (èëè friendlyfire, èëè friendly_hit_projectile)
948 if LongBool(gGameSettings.Options and (GAME_OPTION_TEAMDAMAGE or GAME_OPTION_TEAMHITPROJECTILE)) then
949 begin
950 if PlayerHit(1) then
951 begin
952 Result := 1;
953 Exit;
954 end;
955 end;
956 end;
958 end;
959 end;
961 function g_Weapon_HitUID(UID: Word; d: Integer; SpawnerUID: Word; t: Byte): Boolean;
962 begin
963 Result := False;
965 case g_GetUIDType(UID) of
966 UID_PLAYER: Result := HitPlayer(g_Player_Get(UID), d, 0, 0, SpawnerUID, t);
967 UID_MONSTER: Result := HitMonster(g_Monsters_ByUID(UID), d, 0, 0, SpawnerUID, t);
968 else Exit;
969 end;
970 end;
972 function g_Weapon_Explode(X, Y: Integer; rad: Integer; SpawnerUID: Word): Boolean;
973 var
974 r: Integer; // squared radius
976 function monsExCheck (mon: TMonster): Boolean;
977 var
978 dx, dy, mm: Integer;
979 begin
980 result := false; // don't stop
981 begin
982 dx := mon.Obj.X+mon.Obj.Rect.X+(mon.Obj.Rect.Width div 2)-X;
983 dy := mon.Obj.Y+mon.Obj.Rect.Y+(mon.Obj.Rect.Height div 2)-Y;
985 if dx > 1000 then dx := 1000;
986 if dy > 1000 then dy := 1000;
988 if (dx*dx+dy*dy < r) then
989 begin
990 //m := PointToRect(X, Y, Obj.X+Obj.Rect.X, Obj.Y+Obj.Rect.Y, Obj.Rect.Width, Obj.Rect.Height);
991 //e_WriteLog(Format('explo monster #%d: x=%d; y=%d; rad=%d; dx=%d; dy=%d', [monidx, X, Y, rad, dx, dy]), MSG_NOTIFY);
993 mm := Max(abs(dx), abs(dy));
994 if mm = 0 then mm := 1;
996 if mon.alive then
997 begin
998 HitMonster(mon, ((mon.Obj.Rect.Width div 4)*10*(rad-mm)) div rad, 0, 0, SpawnerUID, HIT_ROCKET);
999 end;
1001 mon.Push((dx*7) div mm, (dy*7) div mm);
1002 end;
1003 end;
1004 end;
1006 var i, h, dx, dy, mm: Integer;
1007 {$IFDEF ENABLE_GIBS}
1008 var _angle: SmallInt;
1009 {$ENDIF}
1010 {$IF DEFINED(ENABLE_GIBS) OR DEFINED(ENABLE_CORPSES)}
1011 var m: Integer;
1012 {$ENDIF}
1013 begin
1014 result := false;
1016 g_Triggers_PressC(X, Y, rad, SpawnerUID, ACTIVATE_SHOT);
1018 r := rad*rad;
1020 h := High(gPlayers);
1022 if h <> -1 then
1023 for i := 0 to h do
1024 if (gPlayers[i] <> nil) and gPlayers[i].alive then
1025 with gPlayers[i] do
1026 begin
1027 dx := Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2)-X;
1028 dy := Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)-Y;
1030 if dx > 1000 then dx := 1000;
1031 if dy > 1000 then dy := 1000;
1033 if dx*dx+dy*dy < r then
1034 begin
1035 //m := PointToRect(X, Y, GameX+PLAYER_RECT.X, GameY+PLAYER_RECT.Y,
1036 // PLAYER_RECT.Width, PLAYER_RECT.Height);
1038 mm := Max(abs(dx), abs(dy));
1039 if mm = 0 then mm := 1;
1041 HitPlayer(gPlayers[i], (100*(rad-mm)) div rad, (dx*10) div mm, (dy*10) div mm, SpawnerUID, HIT_ROCKET);
1042 gPlayers[i].Push((dx*7) div mm, (dy*7) div mm);
1043 end;
1044 end;
1046 //g_Mons_ForEach(monsExCheck);
1047 g_Mons_ForEachAt(X-(rad+32), Y-(rad+32), (rad+32)*2, (rad+32)*2, monsExCheck);
1049 {$IFDEF ENABLE_CORPSES}
1050 h := High(gCorpses);
1051 if gAdvCorpses and (h <> -1) then
1052 begin
1053 for i := 0 to h do
1054 begin
1055 if (gCorpses[i] <> nil) and (gCorpses[i].State <> CORPSE_STATE_REMOVEME) then
1056 begin
1057 with gCorpses[i] do
1058 begin
1059 dx := Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2)-X;
1060 dy := Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)-Y;
1061 if dx > 1000 then dx := 1000;
1062 if dy > 1000 then dy := 1000;
1063 if dx*dx+dy*dy < r then
1064 begin
1065 m := PointToRect(X, Y, Obj.X+Obj.Rect.X, Obj.Y+Obj.Rect.Y, Obj.Rect.Width, Obj.Rect.Height);
1066 mm := Max(abs(dx), abs(dy));
1067 if mm = 0 then
1068 mm := 1;
1069 Damage(Round(100*(rad-m)/rad), SpawnerUID, (dx*10) div mm, (dy*10) div mm);
1070 end;
1071 end;
1072 end;
1073 end;
1074 end;
1075 {$ENDIF}
1077 {$IFDEF ENABLE_GIBS}
1078 h := High(gGibs);
1079 if gAdvGibs and (h <> -1) then
1080 for i := 0 to h do
1081 if gGibs[i].alive then
1082 with gGibs[i] do
1083 begin
1084 dx := Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2)-X;
1085 dy := Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)-Y;
1086 if dx > 1000 then dx := 1000;
1087 if dy > 1000 then dy := 1000;
1088 if dx*dx+dy*dy < r then
1089 begin
1090 m := PointToRect(X, Y, Obj.X+Obj.Rect.X, Obj.Y+Obj.Rect.Y,
1091 Obj.Rect.Width, Obj.Rect.Height);
1092 _angle := GetAngle(Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2),
1093 Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2), X, Y);
1094 g_Obj_PushA(@Obj, Round(15*(rad-m)/rad), _angle);
1095 positionChanged(); // this updates spatial accelerators
1096 end;
1097 end;
1098 {$ENDIF}
1099 end;
1101 procedure g_Weapon_Init();
1102 begin
1103 CreateWaterMap();
1104 end;
1106 procedure g_Weapon_Free();
1107 begin
1108 Shots := nil;
1109 WaterMap := nil;
1110 end;
1112 procedure g_Weapon_LoadData();
1113 begin
1114 e_WriteLog('Loading weapons data...', TMsgType.Notify);
1116 g_Sound_CreateWADEx('SOUND_WEAPON_HITPUNCH', GameWAD+':SOUNDS\HITPUNCH');
1117 g_Sound_CreateWADEx('SOUND_WEAPON_MISSPUNCH', GameWAD+':SOUNDS\MISSPUNCH');
1118 g_Sound_CreateWADEx('SOUND_WEAPON_HITBERSERK', GameWAD+':SOUNDS\HITBERSERK');
1119 g_Sound_CreateWADEx('SOUND_WEAPON_MISSBERSERK', GameWAD+':SOUNDS\MISSBERSERK');
1120 g_Sound_CreateWADEx('SOUND_WEAPON_SELECTSAW', GameWAD+':SOUNDS\SELECTSAW');
1121 g_Sound_CreateWADEx('SOUND_WEAPON_IDLESAW', GameWAD+':SOUNDS\IDLESAW');
1122 g_Sound_CreateWADEx('SOUND_WEAPON_HITSAW', GameWAD+':SOUNDS\HITSAW');
1123 g_Sound_CreateWADEx('SOUND_WEAPON_FIRESHOTGUN2', GameWAD+':SOUNDS\FIRESHOTGUN2');
1124 g_Sound_CreateWADEx('SOUND_WEAPON_FIRESHOTGUN', GameWAD+':SOUNDS\FIRESHOTGUN');
1125 g_Sound_CreateWADEx('SOUND_WEAPON_FIRESAW', GameWAD+':SOUNDS\FIRESAW');
1126 g_Sound_CreateWADEx('SOUND_WEAPON_FIREROCKET', GameWAD+':SOUNDS\FIREROCKET');
1127 g_Sound_CreateWADEx('SOUND_WEAPON_FIREPLASMA', GameWAD+':SOUNDS\FIREPLASMA');
1128 g_Sound_CreateWADEx('SOUND_WEAPON_FIREPISTOL', GameWAD+':SOUNDS\FIREPISTOL');
1129 g_Sound_CreateWADEx('SOUND_WEAPON_FIRECGUN', GameWAD+':SOUNDS\FIRECGUN');
1130 g_Sound_CreateWADEx('SOUND_WEAPON_FIREBFG', GameWAD+':SOUNDS\FIREBFG');
1131 g_Sound_CreateWADEx('SOUND_FIRE', GameWAD+':SOUNDS\FIRE');
1132 g_Sound_CreateWADEx('SOUND_IGNITE', GameWAD+':SOUNDS\IGNITE');
1133 g_Sound_CreateWADEx('SOUND_WEAPON_STARTFIREBFG', GameWAD+':SOUNDS\STARTFIREBFG');
1134 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEROCKET', GameWAD+':SOUNDS\EXPLODEROCKET');
1135 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEBFG', GameWAD+':SOUNDS\EXPLODEBFG');
1136 g_Sound_CreateWADEx('SOUND_WEAPON_BFGWATER', GameWAD+':SOUNDS\BFGWATER');
1137 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEPLASMA', GameWAD+':SOUNDS\EXPLODEPLASMA');
1138 g_Sound_CreateWADEx('SOUND_WEAPON_PLASMAWATER', GameWAD+':SOUNDS\PLASMAWATER');
1139 g_Sound_CreateWADEx('SOUND_WEAPON_FIREBALL', GameWAD+':SOUNDS\FIREBALL');
1140 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEBALL', GameWAD+':SOUNDS\EXPLODEBALL');
1141 g_Sound_CreateWADEx('SOUND_WEAPON_FIREREV', GameWAD+':SOUNDS\FIREREV');
1142 g_Sound_CreateWADEx('SOUND_WEAPON_FLAMEON', GameWAD+':SOUNDS\STARTFLM');
1143 g_Sound_CreateWADEx('SOUND_WEAPON_FLAMEOFF', GameWAD+':SOUNDS\STOPFLM');
1144 g_Sound_CreateWADEx('SOUND_WEAPON_FLAMEWORK', GameWAD+':SOUNDS\WORKFLM');
1145 g_Sound_CreateWADEx('SOUND_PLAYER_JETFLY', GameWAD+':SOUNDS\WORKJETPACK');
1146 g_Sound_CreateWADEx('SOUND_PLAYER_JETON', GameWAD+':SOUNDS\STARTJETPACK');
1147 g_Sound_CreateWADEx('SOUND_PLAYER_JETOFF', GameWAD+':SOUNDS\STOPJETPACK');
1148 g_Sound_CreateWADEx('SOUND_PLAYER_CASING1', GameWAD+':SOUNDS\CASING1');
1149 g_Sound_CreateWADEx('SOUND_PLAYER_CASING2', GameWAD+':SOUNDS\CASING2');
1150 g_Sound_CreateWADEx('SOUND_PLAYER_SHELL1', GameWAD+':SOUNDS\SHELL1');
1151 g_Sound_CreateWADEx('SOUND_PLAYER_SHELL2', GameWAD+':SOUNDS\SHELL2');
1153 //wgunMonHash := hashNewIntInt();
1154 wgunHitHeap := TBinaryHeapHitTimes.Create();
1155 end;
1157 procedure g_Weapon_FreeData();
1158 begin
1159 e_WriteLog('Releasing weapons data...', TMsgType.Notify);
1161 g_Sound_Delete('SOUND_WEAPON_HITPUNCH');
1162 g_Sound_Delete('SOUND_WEAPON_MISSPUNCH');
1163 g_Sound_Delete('SOUND_WEAPON_HITBERSERK');
1164 g_Sound_Delete('SOUND_WEAPON_MISSBERSERK');
1165 g_Sound_Delete('SOUND_WEAPON_SELECTSAW');
1166 g_Sound_Delete('SOUND_WEAPON_IDLESAW');
1167 g_Sound_Delete('SOUND_WEAPON_HITSAW');
1168 g_Sound_Delete('SOUND_WEAPON_FIRESHOTGUN2');
1169 g_Sound_Delete('SOUND_WEAPON_FIRESHOTGUN');
1170 g_Sound_Delete('SOUND_WEAPON_FIRESAW');
1171 g_Sound_Delete('SOUND_WEAPON_FIREROCKET');
1172 g_Sound_Delete('SOUND_WEAPON_FIREPLASMA');
1173 g_Sound_Delete('SOUND_WEAPON_FIREPISTOL');
1174 g_Sound_Delete('SOUND_WEAPON_FIRECGUN');
1175 g_Sound_Delete('SOUND_WEAPON_FIREBFG');
1176 g_Sound_Delete('SOUND_FIRE');
1177 g_Sound_Delete('SOUND_IGNITE');
1178 g_Sound_Delete('SOUND_WEAPON_STARTFIREBFG');
1179 g_Sound_Delete('SOUND_WEAPON_EXPLODEROCKET');
1180 g_Sound_Delete('SOUND_WEAPON_EXPLODEBFG');
1181 g_Sound_Delete('SOUND_WEAPON_BFGWATER');
1182 g_Sound_Delete('SOUND_WEAPON_EXPLODEPLASMA');
1183 g_Sound_Delete('SOUND_WEAPON_PLASMAWATER');
1184 g_Sound_Delete('SOUND_WEAPON_FIREBALL');
1185 g_Sound_Delete('SOUND_WEAPON_EXPLODEBALL');
1186 g_Sound_Delete('SOUND_WEAPON_FIREREV');
1187 g_Sound_Delete('SOUND_WEAPON_FLAMEON');
1188 g_Sound_Delete('SOUND_WEAPON_FLAMEOFF');
1189 g_Sound_Delete('SOUND_WEAPON_FLAMEWORK');
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');
1197 end;
1200 function GunHitPlayer (X, Y: Integer; vx, vy: Integer; dmg: Integer; SpawnerUID: Word; AllowPush: Boolean): Boolean;
1201 var
1202 i: Integer;
1203 begin
1204 result := false;
1205 for i := 0 to High(gPlayers) do
1206 begin
1207 if (gPlayers[i] <> nil) and gPlayers[i].alive and gPlayers[i].Collide(X, Y) then
1208 begin
1209 if HitPlayer(gPlayers[i], dmg, vx*10, vy*10-3, SpawnerUID, HIT_SOME) then
1210 begin
1211 if AllowPush then gPlayers[i].Push(vx, vy);
1212 result := true;
1213 end;
1214 end;
1215 end;
1216 end;
1219 function GunHit (X, Y: Integer; vx, vy: Integer; dmg: Integer; SpawnerUID: Word; AllowPush: Boolean): Byte;
1221 function monsCheck (mon: TMonster): Boolean;
1222 begin
1223 result := false; // don't stop
1224 if HitMonster(mon, dmg, vx*10, vy*10-3, SpawnerUID, HIT_SOME) then
1225 begin
1226 if AllowPush then mon.Push(vx, vy);
1227 result := true;
1228 end;
1229 end;
1231 begin
1232 result := 0;
1233 if GunHitPlayer(X, Y, vx, vy, dmg, SpawnerUID, AllowPush) then result := 1
1234 else if g_Mons_ForEachAliveAt(X, Y, 1, 1, monsCheck) then result := 2;
1235 end;
1238 (*
1239 procedure g_Weapon_gunOld(const x, y, xd, yd, v, dmg: Integer; SpawnerUID: Word; CheckTrigger: Boolean);
1240 var
1241 a: Integer;
1242 x2, y2: Integer;
1243 dx, dy: Integer;
1244 xe, ye: Integer;
1245 xi, yi: Integer;
1246 s, c: Extended;
1247 //vx, vy: Integer;
1248 xx, yy, d: Integer;
1249 i: Integer;
1250 t1, _collide: Boolean;
1251 w, h: Word;
1252 {$IF DEFINED(D2F_DEBUG)}
1253 stt: UInt64;
1254 showTime: Boolean = true;
1255 {$ENDIF}
1256 begin
1257 a := GetAngle(x, y, xd, yd)+180;
1259 SinCos(DegToRad(-a), s, c);
1261 if Abs(s) < 0.01 then s := 0;
1262 if Abs(c) < 0.01 then c := 0;
1264 x2 := x+Round(c*gMapInfo.Width);
1265 y2 := y+Round(s*gMapInfo.Width);
1267 t1 := gWalls <> nil;
1268 _collide := False;
1269 w := gMapInfo.Width;
1270 h := gMapInfo.Height;
1272 xe := 0;
1273 ye := 0;
1274 dx := x2-x;
1275 dy := y2-y;
1277 if (xd = 0) and (yd = 0) then Exit;
1279 if dx > 0 then xi := 1 else if dx < 0 then xi := -1 else xi := 0;
1280 if dy > 0 then yi := 1 else if dy < 0 then yi := -1 else yi := 0;
1282 dx := Abs(dx);
1283 dy := Abs(dy);
1285 if dx > dy then d := dx else d := dy;
1287 //blood vel, for Monster.Damage()
1288 //vx := (dx*10 div d)*xi;
1289 //vy := (dy*10 div d)*yi;
1291 {$IF DEFINED(D2F_DEBUG)}
1292 stt := getTimeMicro();
1293 {$ENDIF}
1295 xx := x;
1296 yy := y;
1298 for i := 1 to d do
1299 begin
1300 xe := xe+dx;
1301 ye := ye+dy;
1303 if xe > d then
1304 begin
1305 xe := xe-d;
1306 xx := xx+xi;
1307 end;
1309 if ye > d then
1310 begin
1311 ye := ye-d;
1312 yy := yy+yi;
1313 end;
1315 if (yy > h) or (yy < 0) then Break;
1316 if (xx > w) or (xx < 0) then Break;
1318 if t1 then
1319 if ByteBool(gCollideMap[yy, xx] and MARK_BLOCKED) then
1320 begin
1321 _collide := True;
1322 {$IF DEFINED(D2F_DEBUG)}
1323 stt := getTimeMicro()-stt;
1324 e_WriteLog(Format('*** old trace time: %u microseconds', [LongWord(stt)]), MSG_NOTIFY);
1325 showTime := false;
1326 {$ENDIF}
1327 g_GFX_Spark(xx-xi, yy-yi, 2+Random(2), 180+a, 0, 0);
1328 if g_Game_IsServer and g_Game_IsNet then
1329 MH_SEND_Effect(xx-xi, yy-yi, 180+a, NET_GFX_SPARK);
1330 end;
1332 if not _collide then
1333 begin
1334 _collide := GunHit(xx, yy, xi*v, yi*v, dmg, SpawnerUID, v <> 0) <> 0;
1335 end;
1337 if _collide then Break;
1338 end;
1340 {$IF DEFINED(D2F_DEBUG)}
1341 if showTime then
1342 begin
1343 stt := getTimeMicro()-stt;
1344 e_WriteLog(Format('*** old trace time: %u microseconds', [LongWord(stt)]), MSG_NOTIFY);
1345 end;
1346 {$ENDIF}
1348 if CheckTrigger and g_Game_IsServer then
1349 g_Triggers_PressL(X, Y, xx-xi, yy-yi, SpawnerUID, ACTIVATE_SHOT);
1350 end;
1351 *)
1354 //!!!FIXME!!!
1355 procedure g_Weapon_gun (const x, y, xd, yd, v, indmg: Integer; SpawnerUID: Word; CheckTrigger: Boolean);
1356 var
1357 x0, y0: Integer;
1358 x2, y2: Integer;
1359 xi, yi: Integer;
1360 wallDistSq: Integer = $3fffffff;
1361 spawnerPlr: TPlayer = nil;
1362 dmg: Integer;
1364 function doPlayerHit (idx: Integer; hx, hy: Integer): Boolean;
1365 begin
1366 result := false;
1367 if (idx < 0) or (idx > High(gPlayers)) then exit;
1368 if (gPlayers[idx] = nil) or not gPlayers[idx].alive then exit;
1369 if (spawnerPlr <> nil) then
1370 begin
1371 if ((gGameSettings.Options and (GAME_OPTION_TEAMHITTRACE or GAME_OPTION_TEAMDAMAGE)) = 0) and
1372 (spawnerPlr.Team <> TEAM_NONE) and (spawnerPlr.Team = gPlayers[idx].Team) then
1373 begin
1374 if (spawnerPlr <> gPlayers[idx]) and ((gGameSettings.Options and GAME_OPTION_TEAMABSORBDAMAGE) = 0) then
1375 dmg := Max(1, dmg div 2);
1376 exit;
1377 end;
1378 end;
1379 result := HitPlayer(gPlayers[idx], dmg, (xi*v)*10, (yi*v)*10-3, SpawnerUID, HIT_SOME);
1380 if result and (v <> 0) then gPlayers[idx].Push((xi*v), (yi*v));
1381 {$IF DEFINED(D2F_DEBUG)}
1382 //if result then e_WriteLog(Format(' PLAYER #%d HIT', [idx]), MSG_NOTIFY);
1383 {$ENDIF}
1384 end;
1386 function doMonsterHit (mon: TMonster; hx, hy: Integer): Boolean;
1387 begin
1388 result := false;
1389 if (mon = nil) then exit;
1390 result := HitMonster(mon, dmg, (xi*v)*10, (yi*v)*10-3, SpawnerUID, HIT_SOME);
1391 if result and (v <> 0) then mon.Push((xi*v), (yi*v));
1392 {$IF DEFINED(D2F_DEBUG)}
1393 //if result then e_WriteLog(Format(' MONSTER #%u HIT', [LongWord(mon.UID)]), MSG_NOTIFY);
1394 {$ENDIF}
1395 end;
1397 // collect players along hitray
1398 // return `true` if instant hit was detected
1399 function playerPossibleHit (): Boolean;
1400 var
1401 i: Integer;
1402 px, py, pw, ph: Integer;
1403 inx, iny: Integer;
1404 distSq: Integer;
1405 plr: TPlayer;
1406 begin
1407 result := false;
1408 for i := 0 to High(gPlayers) do
1409 begin
1410 plr := gPlayers[i];
1411 if (plr <> nil) and plr.alive then
1412 begin
1413 plr.getMapBox(px, py, pw, ph);
1414 if lineAABBIntersects(x, y, x2, y2, px, py, pw, ph, inx, iny) then
1415 begin
1416 distSq := distanceSq(x, y, inx, iny);
1417 if (distSq = 0) then
1418 begin
1419 // contains
1420 if doPlayerHit(i, x, y) then begin result := true; exit; end;
1421 end
1422 else if (distSq < wallDistSq) then
1423 begin
1424 appendHitTimePlr(distSq, i, inx, iny);
1425 end;
1426 end;
1427 end;
1428 end;
1429 end;
1431 procedure sqchecker (mon: TMonster);
1432 var
1433 mx, my, mw, mh: Integer;
1434 inx, iny: Integer;
1435 distSq: Integer;
1436 begin
1437 mon.getMapBox(mx, my, mw, mh);
1438 if lineAABBIntersects(x0, y0, x2, y2, mx, my, mw, mh, inx, iny) then
1439 begin
1440 distSq := distanceSq(x0, y0, inx, iny);
1441 if (distSq < wallDistSq) then appendHitTimeMon(distSq, mon, inx, iny);
1442 end;
1443 end;
1445 var
1446 a: Integer;
1447 dx, dy: Integer;
1448 xe, ye: Integer;
1449 s, c: Extended;
1450 i: Integer;
1451 wallHitFlag: Boolean = false;
1452 wallHitX: Integer = 0;
1453 wallHitY: Integer = 0;
1454 didHit: Boolean = false;
1455 {$IF DEFINED(D2F_DEBUG)}
1456 stt: UInt64;
1457 {$ENDIF}
1458 mit: PMonster;
1459 it: TMonsterGrid.Iter;
1460 begin
1461 (*
1462 if not gwep_debug_fast_trace then
1463 begin
1464 g_Weapon_gunOld(x, y, xd, yd, v, dmg, SpawnerUID, CheckTrigger);
1465 exit;
1466 end;
1467 *)
1469 if (xd = 0) and (yd = 0) then exit;
1471 if (g_GetUIDType(SpawnerUID) = UID_PLAYER) then
1472 spawnerPlr := g_Player_Get(SpawnerUID);
1474 dmg := indmg;
1476 //wgunMonHash.reset(); //FIXME: clear hash on level change
1477 wgunHitHeap.clear();
1478 wgunHitTimeUsed := 0;
1480 a := GetAngle(x, y, xd, yd)+180;
1482 SinCos(DegToRad(-a), s, c);
1484 if Abs(s) < 0.01 then s := 0;
1485 if Abs(c) < 0.01 then c := 0;
1487 x0 := x;
1488 y0 := y;
1489 x2 := x+Round(c*gMapInfo.Width);
1490 y2 := y+Round(s*gMapInfo.Width);
1492 dx := x2-x;
1493 dy := y2-y;
1495 if (dx > 0) then xi := 1 else if (dx < 0) then xi := -1 else xi := 0;
1496 if (dy > 0) then yi := 1 else if (dy < 0) then yi := -1 else yi := 0;
1498 {$IF DEFINED(D2F_DEBUG)}
1499 e_WriteLog(Format('GUN TRACE: (%d,%d) to (%d,%d)', [x, y, x2, y2]), TMsgType.Notify);
1500 stt := getTimeMicro();
1501 {$ENDIF}
1503 wallHitFlag := (g_Map_traceToNearestWall(x, y, x2, y2, @wallHitX, @wallHitY) <> nil);
1504 if wallHitFlag then
1505 begin
1506 x2 := wallHitX;
1507 y2 := wallHitY;
1508 wallDistSq := distanceSq(x, y, wallHitX, wallHitY);
1509 end
1510 else
1511 begin
1512 wallHitX := x2;
1513 wallHitY := y2;
1514 end;
1516 if playerPossibleHit() then exit; // instant hit
1518 // collect monsters
1519 //g_Mons_AlongLine(x, y, x2, y2, sqchecker);
1521 it := monsGrid.forEachAlongLine(x, y, x2, y2, -1);
1522 for mit in it do sqchecker(mit^);
1523 it.release();
1525 // here, we collected all monsters and players in `wgunHitHeap` and `wgunHitTime`
1526 // also, if `wallWasHit` is `true`, then `wallHitX` and `wallHitY` contains spark coords
1527 while (wgunHitHeap.count > 0) do
1528 begin
1529 // has some entities to check, do it
1530 i := wgunHitHeap.front;
1531 wgunHitHeap.popFront();
1532 // hitpoint
1533 xe := wgunHitTime[i].x;
1534 ye := wgunHitTime[i].y;
1535 // check if it is not behind the wall
1536 if (wgunHitTime[i].mon <> nil) then
1537 begin
1538 didHit := doMonsterHit(wgunHitTime[i].mon, xe, ye);
1539 end
1540 else
1541 begin
1542 didHit := doPlayerHit(wgunHitTime[i].plridx, xe, ye);
1543 end;
1544 if didHit then
1545 begin
1546 // need new coords for trigger
1547 wallHitX := xe;
1548 wallHitY := ye;
1549 wallHitFlag := false; // no sparks
1550 break;
1551 end;
1552 end;
1554 // need sparks?
1555 if wallHitFlag then
1556 begin
1557 {$IF DEFINED(D2F_DEBUG)}
1558 stt := getTimeMicro()-stt;
1559 e_WriteLog(Format('*** new trace time: %u microseconds', [LongWord(stt)]), TMsgType.Notify);
1560 {$ENDIF}
1561 {$IFDEF ENABLE_GFX}
1562 g_GFX_Spark(wallHitX, wallHitY, 2+Random(2), 180+a, 0, 0);
1563 {$ENDIF}
1564 if g_Game_IsServer and g_Game_IsNet then MH_SEND_Effect(wallHitX, wallHitY, 180+a, NET_GFX_SPARK);
1565 end
1566 else
1567 begin
1568 {$IF DEFINED(D2F_DEBUG)}
1569 stt := getTimeMicro()-stt;
1570 e_WriteLog(Format('*** new trace time: %u microseconds', [LongWord(stt)]), TMsgType.Notify);
1571 {$ENDIF}
1572 end;
1574 if CheckTrigger and g_Game_IsServer then g_Triggers_PressL(X, Y, wallHitX, wallHitY, SpawnerUID, ACTIVATE_SHOT);
1575 end;
1578 procedure g_Weapon_punch(x, y: Integer; d, SpawnerUID: Word);
1579 var
1580 obj: TObj;
1581 begin
1582 obj.X := X;
1583 obj.Y := Y;
1584 obj.rect.X := 0;
1585 obj.rect.Y := 0;
1586 obj.rect.Width := 39;
1587 obj.rect.Height := 52;
1588 obj.Vel.X := 0;
1589 obj.Vel.Y := 0;
1590 obj.Accel.X := 0;
1591 obj.Accel.Y := 0;
1593 if g_Weapon_Hit(@obj, d, SpawnerUID, HIT_SOME) <> 0 then
1594 g_Sound_PlayExAt('SOUND_WEAPON_HITPUNCH', x, y)
1595 else
1596 g_Sound_PlayExAt('SOUND_WEAPON_MISSPUNCH', x, y);
1597 end;
1599 function g_Weapon_chainsaw(x, y: Integer; d, SpawnerUID: Word): Integer;
1600 var
1601 obj: TObj;
1602 begin
1603 obj.X := X;
1604 obj.Y := Y;
1605 obj.rect.X := 0;
1606 obj.rect.Y := 0;
1607 obj.rect.Width := 32;
1608 obj.rect.Height := 52;
1609 obj.Vel.X := 0;
1610 obj.Vel.Y := 0;
1611 obj.Accel.X := 0;
1612 obj.Accel.Y := 0;
1614 Result := g_Weapon_Hit(@obj, d, SpawnerUID, HIT_SOME);
1615 end;
1617 procedure g_Weapon_rocket(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1618 Silent: Boolean = False; compat: Boolean = true);
1619 var
1620 find_id: DWORD;
1621 dx, dy: Integer;
1622 begin
1623 if WID < 0 then
1624 find_id := FindShot()
1625 else
1626 begin
1627 find_id := WID;
1628 if Integer(find_id) >= High(Shots) then
1629 SetLength(Shots, find_id + 64)
1630 end;
1632 with Shots[find_id] do
1633 begin
1634 g_Obj_Init(@Obj);
1636 Obj.Rect.Width := SHOT_ROCKETLAUNCHER_WIDTH;
1637 Obj.Rect.Height := SHOT_ROCKETLAUNCHER_HEIGHT;
1639 if compat then
1640 dx := IfThen(xd > x, -Obj.Rect.Width, 0)
1641 else
1642 dx := -(Obj.Rect.Width div 2);
1643 dy := -(Obj.Rect.Height div 2);
1645 ShotType := WEAPON_ROCKETLAUNCHER;
1646 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 12);
1648 triggers := nil;
1649 time := gTime;
1650 end;
1652 Shots[find_id].SpawnerUID := SpawnerUID;
1654 if not Silent then
1655 g_Sound_PlayExAt('SOUND_WEAPON_FIREROCKET', x, y);
1656 end;
1658 procedure g_Weapon_revf(x, y, xd, yd: Integer; SpawnerUID, TargetUID: Word;
1659 WID: Integer = -1; Silent: Boolean = False);
1660 var
1661 find_id: DWORD;
1662 dx, dy: Integer;
1663 begin
1664 if WID < 0 then
1665 find_id := FindShot()
1666 else
1667 begin
1668 find_id := WID;
1669 if Integer(find_id) >= High(Shots) then
1670 SetLength(Shots, find_id + 64)
1671 end;
1673 with Shots[find_id] do
1674 begin
1675 g_Obj_Init(@Obj);
1677 Obj.Rect.Width := SHOT_SKELFIRE_WIDTH;
1678 Obj.Rect.Height := SHOT_SKELFIRE_HEIGHT;
1680 dx := -(Obj.Rect.Width div 2);
1681 dy := -(Obj.Rect.Height div 2);
1683 ShotType := WEAPON_SKEL_FIRE;
1684 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 12);
1686 triggers := nil;
1687 target := TargetUID;
1688 time := gTime;
1689 end;
1691 Shots[find_id].SpawnerUID := SpawnerUID;
1693 if not Silent then
1694 g_Sound_PlayExAt('SOUND_WEAPON_FIREREV', x, y);
1695 end;
1697 procedure g_Weapon_plasma(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1698 Silent: Boolean = False; compat: Boolean = true);
1699 var
1700 find_id: DWORD;
1701 dx, dy: Integer;
1702 begin
1703 if WID < 0 then
1704 find_id := FindShot()
1705 else
1706 begin
1707 find_id := WID;
1708 if Integer(find_id) >= High(Shots) then
1709 SetLength(Shots, find_id + 64);
1710 end;
1712 with Shots[find_id] do
1713 begin
1714 g_Obj_Init(@Obj);
1716 Obj.Rect.Width := SHOT_PLASMA_WIDTH;
1717 Obj.Rect.Height := SHOT_PLASMA_HEIGHT;
1719 if compat then
1720 dx := IfThen(xd > x, -Obj.Rect.Width, 0)
1721 else
1722 dx := -(Obj.Rect.Width div 2);
1723 dy := -(Obj.Rect.Height div 2);
1725 ShotType := WEAPON_PLASMA;
1726 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1728 triggers := nil;
1729 time := gTime;
1730 end;
1732 Shots[find_id].SpawnerUID := SpawnerUID;
1734 if not Silent then
1735 g_Sound_PlayExAt('SOUND_WEAPON_FIREPLASMA', x, y);
1736 end;
1738 procedure g_Weapon_flame(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1739 Silent: Boolean = False; compat: Boolean = true);
1740 var
1741 find_id: DWORD;
1742 dx, dy: Integer;
1743 begin
1744 if WID < 0 then
1745 find_id := FindShot()
1746 else
1747 begin
1748 find_id := WID;
1749 if Integer(find_id) >= High(Shots) then
1750 SetLength(Shots, find_id + 64);
1751 end;
1753 with Shots[find_id] do
1754 begin
1755 g_Obj_Init(@Obj);
1757 Obj.Rect.Width := SHOT_FLAME_WIDTH;
1758 Obj.Rect.Height := SHOT_FLAME_HEIGHT;
1760 if compat then
1761 dx := IfThen(xd > x, -Obj.Rect.Width, 0)
1762 else
1763 dx := -(Obj.Rect.Width div 2);
1764 dy := -(Obj.Rect.Height div 2);
1766 ShotType := WEAPON_FLAMETHROWER;
1767 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1769 triggers := nil;
1770 time := gTime;
1771 end;
1773 Shots[find_id].SpawnerUID := SpawnerUID;
1775 // if not Silent then
1776 // g_Sound_PlayExAt('SOUND_WEAPON_FIREPLASMA', x, y);
1777 end;
1779 procedure g_Weapon_ball1(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1780 Silent: Boolean = False; compat: Boolean = true);
1781 var
1782 find_id: DWORD;
1783 dx, dy: Integer;
1784 begin
1785 if WID < 0 then
1786 find_id := FindShot()
1787 else
1788 begin
1789 find_id := WID;
1790 if Integer(find_id) >= High(Shots) then
1791 SetLength(Shots, find_id + 64)
1792 end;
1794 with Shots[find_id] do
1795 begin
1796 g_Obj_Init(@Obj);
1798 Obj.Rect.Width := 16;
1799 Obj.Rect.Height := 16;
1801 if compat then
1802 dx := IfThen(xd > x, -Obj.Rect.Width, 0)
1803 else
1804 dx := -(Obj.Rect.Width div 2);
1805 dy := -(Obj.Rect.Height div 2);
1807 ShotType := WEAPON_IMP_FIRE;
1808 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1810 triggers := nil;
1811 time := gTime;
1812 end;
1814 Shots[find_id].SpawnerUID := SpawnerUID;
1816 if not Silent then
1817 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x, y);
1818 end;
1820 procedure g_Weapon_ball2(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1821 Silent: Boolean = False; compat: Boolean = true);
1822 var
1823 find_id: DWORD;
1824 dx, dy: Integer;
1825 begin
1826 if WID < 0 then
1827 find_id := FindShot()
1828 else
1829 begin
1830 find_id := WID;
1831 if Integer(find_id) >= High(Shots) then
1832 SetLength(Shots, find_id + 64)
1833 end;
1835 with Shots[find_id] do
1836 begin
1837 g_Obj_Init(@Obj);
1839 Obj.Rect.Width := 16;
1840 Obj.Rect.Height := 16;
1842 if compat then
1843 dx := IfThen(xd > x, -Obj.Rect.Width, 0)
1844 else
1845 dx := -(Obj.Rect.Width div 2);
1846 dy := -(Obj.Rect.Height div 2);
1848 ShotType := WEAPON_CACO_FIRE;
1849 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1851 triggers := nil;
1852 time := gTime;
1853 end;
1855 Shots[find_id].SpawnerUID := SpawnerUID;
1857 if not Silent then
1858 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x, y);
1859 end;
1861 procedure g_Weapon_ball7(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1862 Silent: Boolean = False; compat: Boolean = true);
1863 var
1864 find_id: DWORD;
1865 dx, dy: Integer;
1866 begin
1867 if WID < 0 then
1868 find_id := FindShot()
1869 else
1870 begin
1871 find_id := WID;
1872 if Integer(find_id) >= High(Shots) then
1873 SetLength(Shots, find_id + 64)
1874 end;
1876 with Shots[find_id] do
1877 begin
1878 g_Obj_Init(@Obj);
1880 Obj.Rect.Width := 32;
1881 Obj.Rect.Height := 16;
1883 if compat then
1884 dx := IfThen(xd > x, -Obj.Rect.Width, 0)
1885 else
1886 dx := -(Obj.Rect.Width div 2);
1887 dy := -(Obj.Rect.Height div 2);
1889 ShotType := WEAPON_BARON_FIRE;
1890 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1892 triggers := nil;
1893 time := gTime;
1894 end;
1896 Shots[find_id].SpawnerUID := SpawnerUID;
1898 if not Silent then
1899 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x, y);
1900 end;
1902 procedure g_Weapon_aplasma(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1903 Silent: Boolean = False; compat: Boolean = true);
1904 var
1905 find_id: DWORD;
1906 dx, dy: Integer;
1907 begin
1908 if WID < 0 then
1909 find_id := FindShot()
1910 else
1911 begin
1912 find_id := WID;
1913 if Integer(find_id) >= High(Shots) then
1914 SetLength(Shots, find_id + 64)
1915 end;
1917 with Shots[find_id] do
1918 begin
1919 g_Obj_Init(@Obj);
1921 Obj.Rect.Width := 16;
1922 Obj.Rect.Height := 16;
1924 if compat then
1925 dx := IfThen(xd > x, -Obj.Rect.Width, 0)
1926 else
1927 dx := -(Obj.Rect.Width div 2);
1928 dy := -(Obj.Rect.Height div 2);
1930 ShotType := WEAPON_BSP_FIRE;
1931 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1933 triggers := nil;
1934 time := gTime;
1935 end;
1937 Shots[find_id].SpawnerUID := SpawnerUID;
1939 if not Silent then
1940 g_Sound_PlayExAt('SOUND_WEAPON_FIREPLASMA', x, y);
1941 end;
1943 procedure g_Weapon_manfire(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1944 Silent: Boolean = False; compat: Boolean = true);
1945 var
1946 find_id: DWORD;
1947 dx, dy: Integer;
1948 begin
1949 if WID < 0 then
1950 find_id := FindShot()
1951 else
1952 begin
1953 find_id := WID;
1954 if Integer(find_id) >= High(Shots) then
1955 SetLength(Shots, find_id + 64)
1956 end;
1958 with Shots[find_id] do
1959 begin
1960 g_Obj_Init(@Obj);
1962 Obj.Rect.Width := 32;
1963 Obj.Rect.Height := 32;
1965 if compat then
1966 dx := IfThen(xd > x, -Obj.Rect.Width, 0)
1967 else
1968 dx := -(Obj.Rect.Width div 2);
1969 dy := -(Obj.Rect.Height div 2);
1971 ShotType := WEAPON_MANCUB_FIRE;
1972 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1974 triggers := nil;
1975 time := gTime;
1976 end;
1978 Shots[find_id].SpawnerUID := SpawnerUID;
1980 if not Silent then
1981 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x, y);
1982 end;
1984 procedure g_Weapon_bfgshot(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1985 Silent: Boolean = False; compat: Boolean = true);
1986 var
1987 find_id: DWORD;
1988 dx, dy: Integer;
1989 begin
1990 if WID < 0 then
1991 find_id := FindShot()
1992 else
1993 begin
1994 find_id := WID;
1995 if Integer(find_id) >= High(Shots) then
1996 SetLength(Shots, find_id + 64)
1997 end;
1999 with Shots[find_id] do
2000 begin
2001 g_Obj_Init(@Obj);
2003 Obj.Rect.Width := SHOT_BFG_WIDTH;
2004 Obj.Rect.Height := SHOT_BFG_HEIGHT;
2006 if compat then
2007 dx := IfThen(xd > x, -Obj.Rect.Width, 0)
2008 else
2009 dx := -(Obj.Rect.Width div 2);
2010 dy := -(Obj.Rect.Height div 2);
2012 ShotType := WEAPON_BFG;
2013 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
2015 triggers := nil;
2016 time := gTime;
2017 end;
2019 Shots[find_id].SpawnerUID := SpawnerUID;
2021 if not Silent then
2022 g_Sound_PlayExAt('SOUND_WEAPON_FIREBFG', x, y);
2023 end;
2025 procedure g_Weapon_bfghit(x, y: Integer);
2026 begin
2027 {$IFDEF ENABLE_GFX}
2028 g_GFX_QueueEffect(R_GFX_BFG_HIT, x - 32, y - 32);
2029 {$ENDIF}
2030 end;
2032 procedure g_Weapon_pistol(x, y, xd, yd: Integer; SpawnerUID: Word;
2033 Silent: Boolean = False);
2034 begin
2035 if not Silent then
2036 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', x, y);
2038 g_Weapon_gun(x, y, xd, yd, 1, 3, SpawnerUID, True);
2039 if gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF] then
2040 begin
2041 if ABS(x-xd) >= ABS(y-yd) then
2042 begin
2043 g_Weapon_gun(x, y+1, xd, yd+1, 1, 3, SpawnerUID, False);
2044 g_Weapon_gun(x, y-1, xd, yd-1, 1, 2, SpawnerUID, False);
2045 end
2046 else
2047 begin
2048 g_Weapon_gun(x+1, y, xd+1, yd, 1, 3, SpawnerUID, False);
2049 g_Weapon_gun(x-1, y, xd-1, yd, 1, 2, SpawnerUID, False);
2050 end;
2051 end;
2052 end;
2054 procedure g_Weapon_mgun(x, y, xd, yd: Integer; SpawnerUID: Word;
2055 Silent: Boolean = False);
2056 begin
2057 if not Silent then
2058 if gSoundEffectsDF then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', x, y);
2060 g_Weapon_gun(x, y, xd, yd, 1, 3, SpawnerUID, True);
2061 if (gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF]) and
2062 (g_GetUIDType(SpawnerUID) = UID_PLAYER) then
2063 begin
2064 if ABS(x-xd) >= ABS(y-yd) then
2065 begin
2066 g_Weapon_gun(x, y+1, xd, yd+1, 1, 2, SpawnerUID, False);
2067 g_Weapon_gun(x, y-1, xd, yd-1, 1, 2, SpawnerUID, False);
2068 end
2069 else
2070 begin
2071 g_Weapon_gun(x+1, y, xd+1, yd, 1, 2, SpawnerUID, False);
2072 g_Weapon_gun(x-1, y, xd-1, yd, 1, 2, SpawnerUID, False);
2073 end;
2074 end;
2075 end;
2077 procedure g_Weapon_shotgun(x, y, xd, yd: Integer; SpawnerUID: Word;
2078 Silent: Boolean = False);
2079 var
2080 i, j, k: Integer;
2081 begin
2082 if not Silent then
2083 if gSoundEffectsDF then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', x, y);
2085 for i := 0 to 9 do
2086 begin
2087 j := 0; k := 0;
2088 if ABS(x-xd) >= ABS(y-yd) then j := Random(17) - 8 else k := Random(17) - 8; // -8 .. 8
2089 g_Weapon_gun(x+k, y+j, xd+k, yd+j, IfThen(i mod 2 <> 0, 1, 0), 3, SpawnerUID, i=0);
2090 end;
2091 end;
2093 procedure g_Weapon_dshotgun(x, y, xd, yd: Integer; SpawnerUID: Word;
2094 Silent: Boolean = False);
2095 var
2096 a, i, j, k: Integer;
2097 begin
2098 if not Silent then
2099 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', x, y);
2101 if gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF] then a := 25 else a := 20;
2102 for i := 0 to a do
2103 begin
2104 j := 0; k := 0;
2105 if ABS(x-xd) >= ABS(y-yd) then j := Random(41) - 20 else k := Random(41) - 20; // -20 .. 20
2106 g_Weapon_gun(x+k, y+j, xd+k, yd+j, IfThen(i mod 3 <> 0, 0, 1), 3, SpawnerUID, i=0);
2107 end;
2108 end;
2110 procedure g_Weapon_PreUpdate();
2111 var
2112 i: Integer;
2113 begin
2114 if Shots = nil then Exit;
2115 for i := 0 to High(Shots) do
2116 if Shots[i].ShotType <> 0 then
2117 begin
2118 Shots[i].Obj.oldX := Shots[i].Obj.X;
2119 Shots[i].Obj.oldY := Shots[i].Obj.Y;
2120 end;
2121 end;
2123 procedure g_Weapon_Update();
2124 var
2125 i, a, h, cx, cy, oldvx, oldvy, tf: Integer;
2126 t: DWArray;
2127 st: Word;
2128 o: TObj;
2129 spl: Boolean;
2130 Loud: Boolean;
2131 {$IFDEF ENABLE_GFX}
2132 var tcx, tcy: Integer;
2133 {$ENDIF}
2134 begin
2135 if Shots = nil then
2136 Exit;
2138 for i := 0 to High(Shots) do
2139 begin
2140 if Shots[i].ShotType = 0 then
2141 Continue;
2143 Loud := True;
2145 with Shots[i] do
2146 begin
2147 Timeout := Timeout - 1;
2148 oldvx := Obj.Vel.X;
2149 oldvy := Obj.Vel.Y;
2150 // Àêòèâèðîâàòü òðèããåðû ïî ïóòè (êðîìå óæå àêòèâèðîâàííûõ):
2151 if (Stopped = 0) and g_Game_IsServer then
2152 t := g_Triggers_PressR(Obj.X, Obj.Y, Obj.Rect.Width, Obj.Rect.Height,
2153 SpawnerUID, ACTIVATE_SHOT, triggers)
2154 else
2155 t := nil;
2157 if t <> nil then
2158 begin
2159 // Ïîïîëíÿåì ñïèñîê àêòèâèðîâàííûõ òðèããåðîâ:
2160 if triggers = nil then
2161 triggers := t
2162 else
2163 begin
2164 h := High(t);
2166 for a := 0 to h do
2167 if not InDWArray(t[a], triggers) then
2168 begin
2169 SetLength(triggers, Length(triggers)+1);
2170 triggers[High(triggers)] := t[a];
2171 end;
2172 end;
2173 end;
2175 // Äâèæåíèå:
2176 spl := (ShotType <> WEAPON_PLASMA) and
2177 (ShotType <> WEAPON_BFG) and
2178 (ShotType <> WEAPON_BSP_FIRE) and
2179 (ShotType <> WEAPON_FLAMETHROWER);
2181 if Stopped = 0 then
2182 begin
2183 st := g_Obj_Move_Projectile(@Obj, False, spl);
2184 end
2185 else
2186 begin
2187 st := 0;
2188 end;
2189 positionChanged(); // this updates spatial accelerators
2191 if WordBool(st and MOVE_FALLOUT) or (Obj.X < -1000) or
2192 (Obj.X > gMapInfo.Width+1000) or (Obj.Y < -1000) then
2193 begin
2194 // Íà êëèåíòå ñêîðåå âñåãî è òàê óæå âûïàë.
2195 ShotType := 0;
2196 time := 0;
2197 Continue;
2198 end;
2200 cx := Obj.X + (Obj.Rect.Width div 2);
2201 cy := Obj.Y + (Obj.Rect.Height div 2);
2203 case ShotType of
2204 WEAPON_ROCKETLAUNCHER, WEAPON_SKEL_FIRE: // Ðàêåòû è ñíàðÿäû Ñêåëåòà
2205 begin
2206 // Âûëåòåëà èç âîäû:
2207 if WordBool(st and MOVE_HITAIR) then
2208 g_Obj_SetSpeed(@Obj, 12);
2210 // Â âîäå øëåéô - ïóçûðè, â âîçäóõå øëåéô - äûì:
2211 if WordBool(st and MOVE_INWATER) then
2212 begin
2213 {$IFDEF ENABLE_GFX}
2214 g_GFX_Bubbles(cx, cy, 1+Random(3), 16, 16);
2215 {$ENDIF}
2216 if Random(2) = 0
2217 then g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', cx, cy)
2218 else g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', cx, cy);
2219 end
2220 else
2221 begin
2222 {$IFDEF ENABLE_GFX}
2223 g_GFX_QueueEffect(R_GFX_SMOKE_TRANS, Obj.X-14+Random(9), cy-20+Random(9));
2224 {$ENDIF}
2225 end;
2227 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2228 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL)) or
2229 (g_Weapon_Hit(@Obj, 10, SpawnerUID, HIT_SOME, False) <> 0) or
2230 (Timeout < 1) then
2231 begin
2232 Obj.Vel.X := 0;
2233 Obj.Vel.Y := 0;
2235 g_Weapon_Explode(cx, cy, 60, SpawnerUID);
2237 if ShotType = WEAPON_SKEL_FIRE then
2238 begin // Âçðûâ ñíàðÿäà Ñêåëåòà
2239 {$IFDEF ENABLE_GFX}
2240 g_GFX_QueueEffect(R_GFX_EXPLODE_SKELFIRE, Obj.X + 32 - 58, Obj.Y + 8 - 36);
2241 g_DynLightExplosion((Obj.X+32), (Obj.Y+8), 64, 1, 0, 0);
2242 {$ENDIF}
2243 end
2244 else
2245 begin // Âçðûâ Ðàêåòû
2246 {$IFDEF ENABLE_GFX}
2247 g_GFX_QueueEffect(R_GFX_EXPLODE_ROCKET, cx - 64, cy - 64);
2248 g_DynLightExplosion(cx, cy, 64, 1, 0, 0);
2249 {$ENDIF}
2250 end;
2252 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', Obj.X, Obj.Y);
2254 ShotType := 0;
2255 end;
2257 if ShotType = WEAPON_SKEL_FIRE then
2258 begin // Ñàìîíàâîäêà ñíàðÿäà Ñêåëåòà:
2259 if GetPos(target, @o) then
2260 throw(i, Obj.X, Obj.Y,
2261 o.X+o.Rect.X+(o.Rect.Width div 2)+o.Vel.X+o.Accel.X,
2262 o.Y+o.Rect.Y+(o.Rect.Height div 2)+o.Vel.Y+o.Accel.Y,
2263 12);
2264 end;
2265 end;
2267 WEAPON_PLASMA, WEAPON_BSP_FIRE: // Ïëàçìà, ïëàçìà Àðàõíàòðîíà
2268 begin
2269 // Ïîïàëà â âîäó - ýëåêòðîøîê ïî âîäå:
2270 if WordBool(st and (MOVE_INWATER or MOVE_HITWATER)) then
2271 begin
2272 g_Sound_PlayExAt('SOUND_WEAPON_PLASMAWATER', Obj.X, Obj.Y);
2273 if g_Game_IsServer then CheckTrap(i, 10, HIT_ELECTRO);
2274 ShotType := 0;
2275 Continue;
2276 end;
2278 // Âåëè÷èíà óðîíà:
2279 if (ShotType = WEAPON_PLASMA) and
2280 (gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF]) then
2281 a := 10
2282 else
2283 a := 5;
2285 if ShotType = WEAPON_BSP_FIRE then
2286 a := 10;
2288 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2289 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL)) or
2290 (g_Weapon_Hit(@Obj, a, SpawnerUID, HIT_SOME, False) <> 0) or
2291 (Timeout < 1) then
2292 begin
2293 {$IFDEF ENABLE_GFX}
2294 if ShotType = WEAPON_PLASMA then
2295 g_GFX_QueueEffect(R_GFX_EXPLODE_PLASMA, cx - 16, cy - 16)
2296 else
2297 g_GFX_QueueEffect(R_GFX_EXPLODE_BSPFIRE, cx - 16, cy - 16);
2298 g_DynLightExplosion(cx, cy, 32, 0, 0.5, 0.5);
2299 {$ENDIF}
2300 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEPLASMA', Obj.X, Obj.Y);
2301 ShotType := 0;
2302 end;
2303 end;
2305 WEAPON_FLAMETHROWER: // Îãíåìåò
2306 begin
2307 // Ñî âðåìåíåì óìèðàåò
2308 if (Timeout < 1) then
2309 begin
2310 ShotType := 0;
2311 Continue;
2312 end;
2313 // Ïîä âîäîé òîæå
2314 if WordBool(st and (MOVE_HITWATER or MOVE_INWATER)) then
2315 begin
2316 if WordBool(st and MOVE_HITWATER) then
2317 begin
2318 {$IFDEF ENABLE_GFX}
2319 tcx := Random(8);
2320 tcy := Random(8);
2321 g_GFX_QueueEffect(R_GFX_SMOKE, cx-4+tcx-(R_GFX_SMOKE_WIDTH div 2), cy-4+tcy-(R_GFX_SMOKE_HEIGHT div 2));
2322 {$ENDIF}
2323 end
2324 else
2325 begin
2326 {$IFDEF ENABLE_GFX}
2327 g_GFX_Bubbles(cx, cy, 1+Random(3), 16, 16);
2328 {$ENDIF}
2329 if Random(2) = 0
2330 then g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', cx, cy)
2331 else g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', cx, cy);
2332 end;
2333 ShotType := 0;
2334 Continue;
2335 end;
2337 // Ãðàâèòàöèÿ
2338 if Stopped = 0 then
2339 Obj.Accel.Y := Obj.Accel.Y + 1;
2340 // Ïîïàëè â ñòåíó èëè â âîäó:
2341 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL or MOVE_HITWATER)) then
2342 begin
2343 // Ïðèëèïàåì:
2344 Obj.Vel.X := 0;
2345 Obj.Vel.Y := 0;
2346 Obj.Accel.Y := 0;
2347 if WordBool(st and MOVE_HITWALL) then
2348 Stopped := MOVE_HITWALL
2349 else if WordBool(st and MOVE_HITLAND) then
2350 Stopped := MOVE_HITLAND
2351 else if WordBool(st and MOVE_HITCEIL) then
2352 Stopped := MOVE_HITCEIL;
2353 end;
2355 a := IfThen(Stopped = 0, 10, 1);
2356 // Åñëè â êîãî-òî ïîïàëè
2357 if g_Weapon_Hit(@Obj, a, SpawnerUID, HIT_FLAME, False) <> 0 then
2358 begin
2359 // HIT_FLAME ñàì ïîäîææåò
2360 // Åñëè â ïîëåòå ïîïàëè, èñ÷åçàåì
2361 if Stopped = 0 then
2362 ShotType := 0;
2363 end;
2365 if Stopped = 0 then
2366 tf := 2
2367 else
2368 tf := 3;
2370 if (gTime mod LongWord(tf) = 0) then
2371 begin
2372 {$IFDEF ENABLE_GFX}
2373 case Stopped of
2374 MOVE_HITWALL: begin tcx := cx-4+Random(8); tcy := cy-12+Random(24); end;
2375 MOVE_HITLAND: begin tcx := cx-12+Random(24); tcy := cy-10+Random(8); end;
2376 MOVE_HITCEIL: begin tcx := cx-12+Random(24); tcy := cy+6+Random(8); end;
2377 else begin tcx := cx-4+Random(8); tcy := cy-4+Random(8); end;
2378 end;
2379 g_GFX_QueueEffect(R_GFX_FLAME_RAND, tcx - (R_GFX_FLAME_WIDTH div 2), tcy - (R_GFX_FLAME_HEIGHT div 2));
2380 //g_DynLightExplosion(tcx, tcy, 1, 1, 0.8, 0.3);
2381 {$ENDIF}
2382 end;
2383 end;
2385 WEAPON_BFG: // BFG
2386 begin
2387 // Ïîïàëà â âîäó - ýëåêòðîøîê ïî âîäå:
2388 if WordBool(st and (MOVE_INWATER or MOVE_HITWATER)) then
2389 begin
2390 g_Sound_PlayExAt('SOUND_WEAPON_BFGWATER', Obj.X, Obj.Y);
2391 if g_Game_IsServer then CheckTrap(i, 1000, HIT_ELECTRO);
2392 ShotType := 0;
2393 Continue;
2394 end;
2396 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2397 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL)) or
2398 (g_Weapon_Hit(@Obj, SHOT_BFG_DAMAGE, SpawnerUID, HIT_BFG, False) <> 0) or
2399 (Timeout < 1) then
2400 begin
2401 // Ëó÷è BFG:
2402 if g_Game_IsServer then g_Weapon_BFG9000(cx, cy, SpawnerUID);
2403 {$IFDEF ENABLE_GFX}
2404 g_GFX_QueueEffect(R_GFX_EXPLODE_BFG, cx - 64, cy - 64);
2405 g_DynLightExplosion(cx, cy, 96, 0, 1, 0);
2406 {$ENDIF}
2407 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', Obj.X, Obj.Y);
2408 ShotType := 0;
2409 end;
2410 end;
2412 WEAPON_IMP_FIRE, WEAPON_CACO_FIRE, WEAPON_BARON_FIRE: // Âûñòðåëû Áåñà, Êàêîäåìîíà Ðûöàðÿ/Áàðîíà àäà
2413 begin
2414 // Âûëåòåë èç âîäû:
2415 if WordBool(st and MOVE_HITAIR) then
2416 g_Obj_SetSpeed(@Obj, 16);
2418 // Âåëè÷èíà óðîíà:
2419 if ShotType = WEAPON_IMP_FIRE then
2420 a := 5
2421 else
2422 if ShotType = WEAPON_CACO_FIRE then
2423 a := 20
2424 else
2425 a := 40;
2427 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2428 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL)) or
2429 (g_Weapon_Hit(@Obj, a, SpawnerUID, HIT_SOME) <> 0) or
2430 (Timeout < 1) then
2431 begin
2432 {$IFDEF ENABLE_GFX}
2433 case ShotType of
2434 WEAPON_IMP_FIRE: g_GFX_QueueEffect(R_GFX_EXPLODE_IMPFIRE, cx - 32, cy - 32);
2435 WEAPON_CACO_FIRE: g_GFX_QueueEffect(R_GFX_EXPLODE_CACOFIRE, cx - 32, cy - 32);
2436 WEAPON_BARON_FIRE: g_GFX_QueueEffect(R_GFX_EXPLODE_BARONFIRE, cx - 32, cy - 32);
2437 end;
2438 {$ENDIF}
2439 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj.X, Obj.Y);
2440 ShotType := 0;
2441 end;
2442 end;
2444 WEAPON_MANCUB_FIRE: // Âûñòðåë Ìàíêóáóñà
2445 begin
2446 // Âûëåòåë èç âîäû:
2447 if WordBool(st and MOVE_HITAIR) then
2448 g_Obj_SetSpeed(@Obj, 16);
2450 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2451 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL)) or
2452 (g_Weapon_Hit(@Obj, 40, SpawnerUID, HIT_SOME, False) <> 0) or
2453 (Timeout < 1) then
2454 begin
2455 // Âçðûâ:
2456 {$IFDEF ENABLE_GFX}
2457 g_GFX_QueueEffect(R_GFX_EXPLODE_ROCKET, cx - 64, cy - 64);
2458 {$ENDIF}
2459 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj.X, Obj.Y);
2460 ShotType := 0;
2461 end;
2462 end;
2463 end; // case ShotType of...
2465 // Åñëè ñíàðÿäà óæå íåò, óäàëÿåì àíèìàöèþ:
2466 if (ShotType = 0) then
2467 begin
2468 if gGameSettings.GameType = GT_SERVER then
2469 MH_SEND_DeleteShot(i, Obj.X, Obj.Y, Loud);
2470 time := 0;
2471 end
2472 else if (ShotType <> WEAPON_FLAMETHROWER) and ((oldvx <> Obj.Vel.X) or (oldvy <> Obj.Vel.Y)) then
2473 if gGameSettings.GameType = GT_SERVER then
2474 MH_SEND_UpdateShot(i);
2475 end;
2476 end;
2477 end;
2479 function g_Weapon_Danger(UID: Word; X, Y: Integer; Width, Height: Word; Time: Byte): Boolean;
2480 var
2481 a: Integer;
2482 begin
2483 Result := False;
2485 if Shots = nil then
2486 Exit;
2488 for a := 0 to High(Shots) do
2489 if (Shots[a].ShotType <> 0) and (Shots[a].SpawnerUID <> UID) then
2490 if ((Shots[a].Obj.Vel.Y = 0) and (Shots[a].Obj.Vel.X > 0) and (Shots[a].Obj.X < X)) or
2491 (Shots[a].Obj.Vel.Y = 0) and (Shots[a].Obj.Vel.X < 0) and (Shots[a].Obj.X > X) then
2492 if (Abs(X-Shots[a].Obj.X) < Abs(Shots[a].Obj.Vel.X*Time)) and
2493 g_Collide(X, Y, Width, Height, X, Shots[a].Obj.Y,
2494 Shots[a].Obj.Rect.Width, Shots[a].Obj.Rect.Height) and
2495 g_TraceVector(X, Y, Shots[a].Obj.X, Shots[a].Obj.Y) then
2496 begin
2497 Result := True;
2498 Exit;
2499 end;
2500 end;
2502 procedure g_Weapon_SaveState (st: TStream);
2503 var
2504 count, i, j: Integer;
2505 begin
2506 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ ñíàðÿäîâ
2507 count := 0;
2508 for i := 0 to High(Shots) do if (Shots[i].ShotType <> 0) then Inc(count);
2510 // Êîëè÷åñòâî ñíàðÿäîâ
2511 utils.WriteInt(st, count);
2513 if (count = 0) then exit;
2515 for i := 0 to High(Shots) do
2516 begin
2517 if Shots[i].ShotType <> 0 then
2518 begin
2519 // Ñèãíàòóðà ñíàðÿäà
2520 utils.writeSign(st, 'SHOT');
2521 utils.writeInt(st, Byte(0)); // version
2522 // Òèï ñíàðÿäà
2523 utils.writeInt(st, Byte(Shots[i].ShotType));
2524 // Öåëü
2525 utils.writeInt(st, Word(Shots[i].Target));
2526 // UID ñòðåëÿâøåãî
2527 utils.writeInt(st, Word(Shots[i].SpawnerUID));
2528 // Ðàçìåð ïîëÿ Triggers
2529 utils.writeInt(st, Integer(Length(Shots[i].Triggers)));
2530 // Òðèããåðû, àêòèâèðîâàííûå âûñòðåëîì
2531 for j := 0 to Length(Shots[i].Triggers)-1 do utils.writeInt(st, LongWord(Shots[i].Triggers[j]));
2532 // Îáúåêò ñíàðÿäà
2533 Obj_SaveState(st, @Shots[i].Obj);
2534 // Êîñòûëèíà åáàíàÿ
2535 utils.writeInt(st, Byte(Shots[i].Stopped));
2536 end;
2537 end;
2538 end;
2540 procedure g_Weapon_LoadState (st: TStream);
2541 var
2542 count, tc, i, j: Integer;
2543 begin
2544 if (st = nil) then exit;
2546 // Êîëè÷åñòâî ñíàðÿäîâ
2547 count := utils.readLongInt(st);
2548 if (count < 0) or (count > 1024*1024) then raise XStreamError.Create('invalid shots counter');
2550 SetLength(Shots, count);
2552 if (count = 0) then exit;
2554 for i := 0 to count-1 do
2555 begin
2556 // Ñèãíàòóðà ñíàðÿäà
2557 if not utils.checkSign(st, 'SHOT') then raise XStreamError.Create('invalid shot signature');
2558 if (utils.readByte(st) <> 0) then raise XStreamError.Create('invalid shot version');
2559 // Òèï ñíàðÿäà:
2560 Shots[i].ShotType := utils.readByte(st);
2561 // Öåëü
2562 Shots[i].Target := utils.readWord(st);
2563 // UID ñòðåëÿâøåãî
2564 Shots[i].SpawnerUID := utils.readWord(st);
2565 // Ðàçìåð ïîëÿ Triggers
2566 tc := utils.readLongInt(st);
2567 if (tc < 0) or (tc > 1024*1024) then raise XStreamError.Create('invalid shot triggers counter');
2568 SetLength(Shots[i].Triggers, tc);
2569 // Òðèããåðû, àêòèâèðîâàííûå âûñòðåëîì
2570 for j := 0 to tc-1 do Shots[i].Triggers[j] := utils.readLongWord(st);
2571 // Îáúåêò ïðåäìåòà
2572 Obj_LoadState(@Shots[i].Obj, st);
2573 // Êîñòûëèíà åáàíàÿ
2574 Shots[i].Stopped := utils.readByte(st);
2576 Shots[i].time := gTime; // TODO save time?
2577 end;
2578 end;
2580 procedure g_Weapon_DestroyShot(I: Integer; X, Y: Integer; Loud: Boolean = True);
2581 {$IFDEF ENABLE_GFX}
2582 var cx, cy: Integer;
2583 {$ENDIF}
2584 begin
2585 if Shots = nil then
2586 Exit;
2587 if (I > High(Shots)) or (I < 0) then Exit;
2589 with Shots[I] do
2590 begin
2591 if ShotType = 0 then Exit;
2592 Obj.X := X;
2593 Obj.Y := Y;
2594 {$IFDEF ENABLE_GFX}
2595 cx := Obj.X + (Obj.Rect.Width div 2);
2596 cy := Obj.Y + (Obj.Rect.Height div 2);
2597 {$ENDIF}
2599 case ShotType of
2600 WEAPON_ROCKETLAUNCHER, WEAPON_SKEL_FIRE: // Ðàêåòû è ñíàðÿäû Ñêåëåòà
2601 begin
2602 if Loud then
2603 begin
2604 {$IFDEF ENABLE_GFX}
2605 if ShotType = WEAPON_SKEL_FIRE then
2606 g_GFX_QueueEffect(R_GFX_EXPLODE_SKELFIRE, (Obj.X + 32) - 32, (Obj.Y + 8) - 32)
2607 else
2608 g_GFX_QueueEffect(R_GFX_EXPLODE_ROCKET, cx - 64, cy - 64);
2609 {$ENDIF}
2610 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', Obj.X, Obj.Y);
2611 end;
2612 end;
2614 WEAPON_PLASMA, WEAPON_BSP_FIRE: // Ïëàçìà, ïëàçìà Àðàõíàòðîíà
2615 begin
2616 if loud then
2617 begin
2618 {$IFDEF ENABLE_GFX}
2619 if ShotType = WEAPON_PLASMA then
2620 g_GFX_QueueEffect(R_GFX_EXPLODE_PLASMA, cx - 16, cy - 16)
2621 else
2622 g_GFX_QueueEffect(R_GFX_EXPLODE_BSPFIRE, cx - 16, cy - 16);
2623 {$ENDIF}
2624 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEPLASMA', Obj.X, Obj.Y);
2625 end;
2626 end;
2628 WEAPON_BFG: // BFG
2629 begin
2630 {$IFDEF ENABLE_GFX}
2631 g_GFX_QueueEffect(R_GFX_EXPLODE_BFG, cx - 64, cy - 64);
2632 {$ENDIF}
2633 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', Obj.X, Obj.Y);
2634 end;
2636 WEAPON_IMP_FIRE, WEAPON_CACO_FIRE, WEAPON_BARON_FIRE: // Âûñòðåëû Áåñà, Êàêîäåìîíà Ðûöàðÿ/Áàðîíà àäà
2637 begin
2638 if loud then
2639 begin
2640 {$IFDEF ENABLE_GFX}
2641 case ShotType of
2642 WEAPON_IMP_FIRE: g_GFX_QueueEffect(R_GFX_EXPLODE_IMPFIRE, cx - 32, cy - 32);
2643 WEAPON_CACO_FIRE: g_GFX_QueueEffect(R_GFX_EXPLODE_CACOFIRE, cx - 32, cy - 32);
2644 WEAPON_BARON_FIRE: g_GFX_QueueEffect(R_GFX_EXPLODE_BARONFIRE, cx - 32, cy - 32);
2645 end;
2646 {$ENDIF}
2647 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj.X, Obj.Y);
2648 end;
2649 end;
2651 WEAPON_MANCUB_FIRE: // Âûñòðåë Ìàíêóáóñà
2652 begin
2653 {$IFDEF ENABLE_GFX}
2654 g_GFX_QueueEffect(R_GFX_EXPLODE_ROCKET, cx - 64, cy - 64);
2655 {$ENDIF}
2656 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj.X, Obj.Y);
2657 end;
2658 end; // case ShotType of...
2660 ShotType := 0;
2661 end;
2662 end;
2665 procedure g_Weapon_AddDynLights();
2666 var
2667 i: Integer;
2668 begin
2669 if Shots = nil then Exit;
2670 for i := 0 to High(Shots) do
2671 begin
2672 if Shots[i].ShotType = 0 then continue;
2673 if (Shots[i].ShotType = WEAPON_ROCKETLAUNCHER) or
2674 (Shots[i].ShotType = WEAPON_BARON_FIRE) or
2675 (Shots[i].ShotType = WEAPON_MANCUB_FIRE) or
2676 (Shots[i].ShotType = WEAPON_SKEL_FIRE) or
2677 (Shots[i].ShotType = WEAPON_IMP_FIRE) or
2678 (Shots[i].ShotType = WEAPON_CACO_FIRE) or
2679 (Shots[i].ShotType = WEAPON_MANCUB_FIRE) or
2680 (Shots[i].ShotType = WEAPON_BSP_FIRE) or
2681 (Shots[i].ShotType = WEAPON_PLASMA) or
2682 (Shots[i].ShotType = WEAPON_BFG) or
2683 (Shots[i].ShotType = WEAPON_FLAMETHROWER) or
2684 false then
2685 begin
2686 if (Shots[i].ShotType = WEAPON_PLASMA) then
2687 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)
2688 else if (Shots[i].ShotType = WEAPON_BFG) then
2689 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)
2690 else if (Shots[i].ShotType = WEAPON_FLAMETHROWER) then
2691 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)
2692 else
2693 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);
2694 end;
2695 end;
2696 end;
2699 procedure TShot.positionChanged (); begin end;
2702 end.