DEADSOFTWARE

gl: draw weapon with player model
[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_textures, 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 Animation: TAnimState;
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;
104 WP_FIRST = WEAPON_KASTET;
105 WP_LAST = WEAPON_FLAMETHROWER;
107 var
108 gwep_debug_fast_trace: Boolean = true;
111 implementation
113 uses
114 {$IFDEF ENABLE_GFX}
115 g_gfx,
116 {$ENDIF}
117 {$IFDEF ENABLE_GIBS}
118 g_gibs,
119 {$ENDIF}
120 {$IFDEF ENABLE_CORPSES}
121 g_corpses,
122 {$ENDIF}
123 Math, g_map, g_player, g_sound, g_panel,
124 g_console, g_options, g_game,
125 g_triggers, MAPDEF, e_log, g_monsters, g_saveload,
126 g_language, g_netmsg, g_grid,
127 geom, binheap, hashtable, utils, xstreams
130 type
131 TWaterPanel = record
132 X, Y: Integer;
133 Width, Height: Word;
134 Active: Boolean;
135 end;
137 const
138 SHOT_ROCKETLAUNCHER_WIDTH = 14;
139 SHOT_ROCKETLAUNCHER_HEIGHT = 14;
141 SHOT_SKELFIRE_WIDTH = 14;
142 SHOT_SKELFIRE_HEIGHT = 14;
144 SHOT_PLASMA_WIDTH = 16;
145 SHOT_PLASMA_HEIGHT = 16;
147 SHOT_BFG_WIDTH = 32;
148 SHOT_BFG_HEIGHT = 32;
149 SHOT_BFG_DAMAGE = 100;
150 SHOT_BFG_RADIUS = 256;
152 SHOT_FLAME_WIDTH = 4;
153 SHOT_FLAME_HEIGHT = 4;
154 SHOT_FLAME_LIFETIME = 180;
156 SHOT_SIGNATURE = $544F4853; // 'SHOT'
158 type
159 PHitTime = ^THitTime;
160 THitTime = record
161 distSq: Integer;
162 mon: TMonster;
163 plridx: Integer; // if mon=nil
164 x, y: Integer;
165 end;
167 TBinHeapKeyHitTime = class
168 public
169 class function less (const a, b: Integer): Boolean; inline;
170 end;
172 // indicies in `wgunHitTime` array
173 TBinaryHeapHitTimes = specialize TBinaryHeapBase<Integer, TBinHeapKeyHitTime>;
175 var
176 WaterMap: array of array of DWORD = nil;
177 //wgunMonHash: THashIntInt = nil;
178 wgunHitHeap: TBinaryHeapHitTimes = nil;
179 wgunHitTime: array of THitTime = nil;
180 wgunHitTimeUsed: Integer = 0;
183 class function TBinHeapKeyHitTime.less (const a, b: Integer): Boolean;
184 var
185 hta, htb: PHitTime;
186 begin
187 hta := @wgunHitTime[a];
188 htb := @wgunHitTime[b];
189 if (hta.distSq <> htb.distSq) then begin result := (hta.distSq < htb.distSq); exit; end;
190 if (hta.mon <> nil) then
191 begin
192 // a is monster
193 if (htb.mon = nil) then begin result := false; exit; end; // players first
194 result := (hta.mon.UID < htb.mon.UID); // why not?
195 end
196 else
197 begin
198 // a is player
199 if (htb.mon <> nil) then begin result := true; exit; end; // players first
200 result := (hta.plridx < htb.plridx); // why not?
201 end;
202 end;
205 procedure appendHitTimeMon (adistSq: Integer; amon: TMonster; ax, ay: Integer);
206 begin
207 if (wgunHitTimeUsed = Length(wgunHitTime)) then SetLength(wgunHitTime, wgunHitTimeUsed+128);
208 with wgunHitTime[wgunHitTimeUsed] do
209 begin
210 distSq := adistSq;
211 mon := amon;
212 plridx := -1;
213 x := ax;
214 y := ay;
215 end;
216 wgunHitHeap.insert(wgunHitTimeUsed);
217 Inc(wgunHitTimeUsed);
218 end;
221 procedure appendHitTimePlr (adistSq: Integer; aplridx: Integer; ax, ay: Integer);
222 begin
223 if (wgunHitTimeUsed = Length(wgunHitTime)) then SetLength(wgunHitTime, wgunHitTimeUsed+128);
224 with wgunHitTime[wgunHitTimeUsed] do
225 begin
226 distSq := adistSq;
227 mon := nil;
228 plridx := aplridx;
229 x := ax;
230 y := ay;
231 end;
232 wgunHitHeap.insert(wgunHitTimeUsed);
233 Inc(wgunHitTimeUsed);
234 end;
237 function FindShot(): DWORD;
238 var
239 i: Integer;
240 begin
241 if Shots <> nil then
242 for i := 0 to High(Shots) do
243 if Shots[i].ShotType = 0 then
244 begin
245 Result := i;
246 LastShotID := Result;
247 Exit;
248 end;
250 if Shots = nil then
251 begin
252 SetLength(Shots, 128);
253 Result := 0;
254 end
255 else
256 begin
257 Result := High(Shots) + 1;
258 SetLength(Shots, Length(Shots) + 128);
259 end;
260 LastShotID := Result;
261 end;
263 procedure CreateWaterMap();
264 var
265 WaterArray: Array of TWaterPanel;
266 a, b, c, m: Integer;
267 ok: Boolean;
268 begin
269 if gWater = nil then
270 Exit;
272 SetLength(WaterArray, Length(gWater));
274 for a := 0 to High(gWater) do
275 begin
276 WaterArray[a].X := gWater[a].X;
277 WaterArray[a].Y := gWater[a].Y;
278 WaterArray[a].Width := gWater[a].Width;
279 WaterArray[a].Height := gWater[a].Height;
280 WaterArray[a].Active := True;
281 end;
283 g_Game_SetLoadingText(_lc[I_LOAD_WATER_MAP], High(WaterArray), False);
285 for a := 0 to High(WaterArray) do
286 if WaterArray[a].Active then
287 begin
288 WaterArray[a].Active := False;
289 m := Length(WaterMap);
290 SetLength(WaterMap, m+1);
291 SetLength(WaterMap[m], 1);
292 WaterMap[m][0] := a;
293 ok := True;
295 while ok do
296 begin
297 ok := False;
298 for b := 0 to High(WaterArray) do
299 if WaterArray[b].Active then
300 for c := 0 to High(WaterMap[m]) do
301 if g_CollideAround(WaterArray[b].X,
302 WaterArray[b].Y,
303 WaterArray[b].Width,
304 WaterArray[b].Height,
305 WaterArray[WaterMap[m][c]].X,
306 WaterArray[WaterMap[m][c]].Y,
307 WaterArray[WaterMap[m][c]].Width,
308 WaterArray[WaterMap[m][c]].Height) then
309 begin
310 WaterArray[b].Active := False;
311 SetLength(WaterMap[m],
312 Length(WaterMap[m])+1);
313 WaterMap[m][High(WaterMap[m])] := b;
314 ok := True;
315 Break;
316 end;
317 end;
319 g_Game_StepLoading();
320 end;
322 WaterArray := nil;
323 end;
326 var
327 chkTrap_pl: array [0..256] of Integer;
328 chkTrap_mn: array [0..65535] of TMonster;
330 procedure CheckTrap(ID: DWORD; dm: Integer; t: Byte);
331 var
332 //a, b, c, d, i1, i2: Integer;
333 //chkTrap_pl, chkTrap_mn: WArray;
334 plaCount: Integer = 0;
335 mnaCount: Integer = 0;
336 frameId: DWord;
339 function monsWaterCheck (mon: TMonster): Boolean;
340 begin
341 result := false; // don't stop
342 if mon.alive and mon.Collide(gWater[WaterMap[a][c]]) and (not InWArray(monidx, chkTrap_mn)) and (i2 < 1023) then //FIXME
343 begin
344 i2 += 1;
345 chkTrap_mn[i2] := monidx;
346 end;
347 end;
350 function monsWaterCheck (mon: TMonster): Boolean;
351 begin
352 result := false; // don't stop
353 if (mon.trapCheckFrameId <> frameId) then
354 begin
355 mon.trapCheckFrameId := frameId;
356 chkTrap_mn[mnaCount] := mon;
357 Inc(mnaCount);
358 end;
359 end;
361 var
362 a, b, c, d, f: Integer;
363 pan: TPanel;
364 begin
365 if (gWater = nil) or (WaterMap = nil) then Exit;
367 frameId := g_Mons_getNewTrapFrameId();
369 //i1 := -1;
370 //i2 := -1;
372 //SetLength(chkTrap_pl, 1024);
373 //SetLength(chkTrap_mn, 1024);
374 //for d := 0 to 1023 do chkTrap_pl[d] := $FFFF;
375 //for d := 0 to 1023 do chkTrap_mn[d] := $FFFF;
377 for a := 0 to High(WaterMap) do
378 begin
379 for b := 0 to High(WaterMap[a]) do
380 begin
381 pan := gWater[WaterMap[a][b]];
382 if not g_Obj_Collide(pan.X, pan.Y, pan.Width, pan.Height, @Shots[ID].Obj) then continue;
384 for c := 0 to High(WaterMap[a]) do
385 begin
386 pan := gWater[WaterMap[a][c]];
387 for d := 0 to High(gPlayers) do
388 begin
389 if (gPlayers[d] <> nil) and (gPlayers[d].alive) then
390 begin
391 if gPlayers[d].Collide(pan) then
392 begin
393 f := 0;
394 while (f < plaCount) and (chkTrap_pl[f] <> d) do Inc(f);
395 if (f = plaCount) then
396 begin
397 chkTrap_pl[plaCount] := d;
398 Inc(plaCount);
399 if (plaCount = Length(chkTrap_pl)) then break;
400 end;
401 end;
402 end;
403 end;
405 //g_Mons_ForEach(monsWaterCheck);
406 g_Mons_ForEachAliveAt(pan.X, pan.Y, pan.Width, pan.Height, monsWaterCheck);
407 end;
409 for f := 0 to plaCount-1 do gPlayers[chkTrap_pl[f]].Damage(dm, Shots[ID].SpawnerUID, 0, 0, t);
410 for f := 0 to mnaCount-1 do chkTrap_mn[f].Damage(dm, 0, 0, Shots[ID].SpawnerUID, t);
411 end;
412 end;
414 //chkTrap_pl := nil;
415 //chkTrap_mn := nil;
416 end;
418 function HitMonster(m: TMonster; d: Integer; vx, vy: Integer; SpawnerUID: Word; t: Byte): Boolean;
419 var
420 tt, mt: Byte;
421 mon: TMonster;
422 begin
423 Result := False;
425 tt := g_GetUIDType(SpawnerUID);
426 if tt = UID_MONSTER then
427 begin
428 mon := g_Monsters_ByUID(SpawnerUID);
429 if mon <> nil then
430 mt := g_Monsters_ByUID(SpawnerUID).MonsterType
431 else
432 mt := 0;
433 end
434 else
435 mt := 0;
437 if m = nil then Exit;
438 if m.UID = SpawnerUID then
439 begin
440 // Ñàì ñåáÿ ìîæåò ðàíèòü òîëüêî ðàêåòîé è òîêîì:
441 if (t <> HIT_ROCKET) and (t <> HIT_ELECTRO) then
442 Exit;
443 // Êèáåð äåìîí è áî÷êà âîîáùå íå ìîãóò ñåáÿ ðàíèòü:
444 if (m.MonsterType = MONSTER_CYBER) or
445 (m.MonsterType = MONSTER_BARREL) then
446 begin
447 Result := True;
448 Exit;
449 end;
450 end;
452 if tt = UID_MONSTER then
453 begin
454 // Lost_Soul íå ìîæåò ðàíèòü Pain_Elemental'à:
455 if (mt = MONSTER_SOUL) and (m.MonsterType = MONSTER_PAIN) then
456 Exit;
458 // Îáà ìîíñòðà îäíîãî âèäà:
459 if mt = m.MonsterType then
460 case mt of
461 MONSTER_IMP, MONSTER_DEMON, MONSTER_BARON, MONSTER_KNIGHT, MONSTER_CACO,
462 MONSTER_SOUL, MONSTER_MANCUB, MONSTER_SKEL, MONSTER_FISH:
463 Exit; // Ýòè íå áüþò ñâîèõ
464 end;
465 end;
467 if g_Game_IsServer then
468 begin
469 if (t <> HIT_FLAME) or (m.FFireTime = 0) or (vx <> 0) or (vy <> 0) then
470 Result := m.Damage(d, vx, vy, SpawnerUID, t)
471 else
472 Result := (gLMSRespawn = LMS_RESPAWN_NONE); // don't hit monsters when it's warmup time
473 if t = HIT_FLAME then
474 m.CatchFire(SpawnerUID);
475 end
476 else
477 Result := (gLMSRespawn = LMS_RESPAWN_NONE); // don't hit monsters when it's warmup time
478 end;
481 function HitPlayer (p: TPlayer; d: Integer; vx, vy: Integer; SpawnerUID: Word; t: Byte): Boolean;
482 begin
483 result := False;
485 // Ñàì ñåáÿ ìîæåò ðàíèòü òîëüêî ðàêåòîé è òîêîì
486 if (p.UID = SpawnerUID) and (t <> HIT_ROCKET) and (t <> HIT_ELECTRO) then exit;
488 if g_Game_IsServer then
489 begin
490 if (t <> HIT_FLAME) or (p.FFireTime = 0) or (vx <> 0) or (vy <> 0) then p.Damage(d, SpawnerUID, vx, vy, t);
491 if (t = HIT_FLAME) then p.CatchFire(SpawnerUID);
492 end;
494 result := true;
495 end;
498 procedure g_Weapon_BFG9000(X, Y: Integer; SpawnerUID: Word);
500 function monsCheck (mon: TMonster): Boolean;
501 begin
502 result := false; // don't stop
503 if (mon.alive) and (mon.UID <> SpawnerUID) then
504 begin
505 with mon do
506 begin
507 if (g_PatchLength(X, Y, Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2),
508 Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)) <= SHOT_BFG_RADIUS) and
509 g_TraceVector(X, Y, Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2),
510 Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)) then
511 begin
512 if HitMonster(mon, 50, 0, 0, SpawnerUID, HIT_SOME) then mon.BFGHit();
513 end;
514 end;
515 end;
516 end;
518 var
519 i, h: Integer;
520 st: Byte;
521 pl: TPlayer;
522 b: Boolean;
523 begin
524 //g_Sound_PlayEx('SOUND_WEAPON_EXPLODEBFG', 255);
526 {$IFDEF ENABLE_CORPSES}
527 h := High(gCorpses);
528 if gAdvCorpses and (h <> -1) then
529 begin
530 for i := 0 to h do
531 begin
532 if (gCorpses[i] <> nil) and (gCorpses[i].State <> CORPSE_STATE_REMOVEME) then
533 begin
534 with gCorpses[i] do
535 begin
536 if (g_PatchLength(X, Y, Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2),
537 Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)) <= SHOT_BFG_RADIUS) and
538 g_TraceVector(X, Y, Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2),
539 Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)) then
540 begin
541 Damage(50, SpawnerUID, 0, 0);
542 g_Weapon_BFGHit(Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2), Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2));
543 end;
544 end;
545 end;
546 end;
547 end;
548 {$ENDIF}
550 st := TEAM_NONE;
551 pl := g_Player_Get(SpawnerUID);
552 if pl <> nil then
553 st := pl.Team;
555 h := High(gPlayers);
557 if h <> -1 then
558 for i := 0 to h do
559 if (gPlayers[i] <> nil) and (gPlayers[i].alive) and (gPlayers[i].UID <> SpawnerUID) then
560 with gPlayers[i] do
561 if (g_PatchLength(X, Y, GameX+PLAYER_RECT.X+(PLAYER_RECT.Width div 2),
562 GameY+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)) <= SHOT_BFG_RADIUS) and
563 g_TraceVector(X, Y, GameX+PLAYER_RECT.X+(PLAYER_RECT.Width div 2),
564 GameY+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)) then
565 begin
566 if (st = TEAM_NONE) or (st <> gPlayers[i].Team) then
567 b := HitPlayer(gPlayers[i], 50, 0, 0, SpawnerUID, HIT_SOME)
568 else
569 b := HitPlayer(gPlayers[i], 25, 0, 0, SpawnerUID, HIT_SOME);
570 if b then
571 gPlayers[i].BFGHit();
572 end;
574 //FIXME
575 g_Mons_ForEachAlive(monsCheck);
576 end;
578 function g_Weapon_CreateShot(I: Integer; ShotType: Byte; Spawner, TargetUID: Word; X, Y, XV, YV: Integer): LongWord;
579 var
580 find_id: DWord;
581 begin
582 if I < 0 then
583 find_id := FindShot()
584 else
585 begin
586 find_id := I;
587 if Integer(find_id) >= High(Shots) then
588 SetLength(Shots, find_id + 64)
589 end;
591 case ShotType of
592 WEAPON_ROCKETLAUNCHER:
593 begin
594 with Shots[find_id] do
595 begin
596 g_Obj_Init(@Obj);
598 Obj.Rect.Width := SHOT_ROCKETLAUNCHER_WIDTH;
599 Obj.Rect.Height := SHOT_ROCKETLAUNCHER_HEIGHT;
601 Triggers := nil;
602 ShotType := WEAPON_ROCKETLAUNCHER;
603 Animation.Invalidate;
604 end;
605 end;
607 WEAPON_PLASMA:
608 begin
609 with Shots[find_id] do
610 begin
611 g_Obj_Init(@Obj);
613 Obj.Rect.Width := SHOT_PLASMA_WIDTH;
614 Obj.Rect.Height := SHOT_PLASMA_HEIGHT;
616 Triggers := nil;
617 ShotType := WEAPON_PLASMA;
618 Animation := TAnimState.Create(True, 5, 2); // !!! put values into table
619 end;
620 end;
622 WEAPON_BFG:
623 begin
624 with Shots[find_id] do
625 begin
626 g_Obj_Init(@Obj);
628 Obj.Rect.Width := SHOT_BFG_WIDTH;
629 Obj.Rect.Height := SHOT_BFG_HEIGHT;
631 Triggers := nil;
632 ShotType := WEAPON_BFG;
633 Animation := TAnimState.Create(True, 6, 2); // !!! put values into table
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 Animation.Invalidate;
649 // Animation := TAnimState.Create(True, 6, 0); // drawed as gfx
650 end;
651 end;
653 WEAPON_IMP_FIRE:
654 begin
655 with Shots[find_id] do
656 begin
657 g_Obj_Init(@Obj);
659 Obj.Rect.Width := 16;
660 Obj.Rect.Height := 16;
662 Triggers := nil;
663 ShotType := WEAPON_IMP_FIRE;
664 Animation := TAnimState.Create(True, 4, 2); // !!! put values into table
665 end;
666 end;
668 WEAPON_CACO_FIRE:
669 begin
670 with Shots[find_id] do
671 begin
672 g_Obj_Init(@Obj);
674 Obj.Rect.Width := 16;
675 Obj.Rect.Height := 16;
677 Triggers := nil;
678 ShotType := WEAPON_CACO_FIRE;
679 Animation := TAnimState.Create(True, 4, 2); // !!! put values into table
680 end;
681 end;
683 WEAPON_MANCUB_FIRE:
684 begin
685 with Shots[find_id] do
686 begin
687 g_Obj_Init(@Obj);
689 Obj.Rect.Width := 32;
690 Obj.Rect.Height := 32;
692 Triggers := nil;
693 ShotType := WEAPON_MANCUB_FIRE;
694 Animation := TAnimState.Create(True, 4, 2); // !!! put values into table
695 end;
696 end;
698 WEAPON_BARON_FIRE:
699 begin
700 with Shots[find_id] do
701 begin
702 g_Obj_Init(@Obj);
704 Obj.Rect.Width := 16;
705 Obj.Rect.Height := 16;
707 Triggers := nil;
708 ShotType := WEAPON_BARON_FIRE;
709 Animation := TAnimState.Create(True, 4, 2); // !!! put values into table
710 end;
711 end;
713 WEAPON_BSP_FIRE:
714 begin
715 with Shots[find_id] do
716 begin
717 g_Obj_Init(@Obj);
719 Obj.Rect.Width := 16;
720 Obj.Rect.Height := 16;
722 Triggers := nil;
723 ShotType := WEAPON_BSP_FIRE;
724 Animation := TAnimState.Create(True, 4, 2); // !!! put values into table
725 end;
726 end;
728 WEAPON_SKEL_FIRE:
729 begin
730 with Shots[find_id] do
731 begin
732 g_Obj_Init(@Obj);
734 Obj.Rect.Width := SHOT_SKELFIRE_WIDTH;
735 Obj.Rect.Height := SHOT_SKELFIRE_HEIGHT;
737 Triggers := nil;
738 ShotType := WEAPON_SKEL_FIRE;
739 target := TargetUID;
740 Animation := TAnimState.Create(True, 5, 2); // !!! put values into table
741 end;
742 end;
743 end;
745 Shots[find_id].Obj.oldX := X;
746 Shots[find_id].Obj.oldY := Y;
747 Shots[find_id].Obj.X := X;
748 Shots[find_id].Obj.Y := Y;
749 Shots[find_id].Obj.Vel.X := XV;
750 Shots[find_id].Obj.Vel.Y := YV;
751 Shots[find_id].Obj.Accel.X := 0;
752 Shots[find_id].Obj.Accel.Y := 0;
753 Shots[find_id].SpawnerUID := Spawner;
754 if (ShotType = WEAPON_FLAMETHROWER) and (XV = 0) and (YV = 0) then
755 Shots[find_id].Stopped := 255
756 else
757 Shots[find_id].Stopped := 0;
758 Result := find_id;
759 end;
761 procedure throw(i, x, y, xd, yd, s: Integer);
762 var
763 a: Integer;
764 begin
765 yd := yd - y;
766 xd := xd - x;
768 a := Max(Abs(xd), Abs(yd));
769 if a = 0 then
770 a := 1;
772 Shots[i].Obj.oldX := x;
773 Shots[i].Obj.oldY := y;
774 Shots[i].Obj.X := x;
775 Shots[i].Obj.Y := y;
776 Shots[i].Obj.Vel.X := (xd*s) div a;
777 Shots[i].Obj.Vel.Y := (yd*s) div a;
778 Shots[i].Obj.Accel.X := 0;
779 Shots[i].Obj.Accel.Y := 0;
780 Shots[i].Stopped := 0;
781 if Shots[i].ShotType in [WEAPON_ROCKETLAUNCHER, WEAPON_BFG] then
782 Shots[i].Timeout := 900 // ~25 sec
783 else
784 begin
785 if Shots[i].ShotType = WEAPON_FLAMETHROWER then
786 Shots[i].Timeout := SHOT_FLAME_LIFETIME
787 else
788 Shots[i].Timeout := 550; // ~15 sec
789 end;
790 end;
792 function g_Weapon_Hit(obj: PObj; d: Integer; SpawnerUID: Word; t: Byte; HitCorpses: Boolean = True): Byte;
793 {$IFDEF ENABLE_CORPSES}
794 var i: Integer;
795 {$ENDIF}
796 var h: Integer;
798 function PlayerHit(Team: Byte = 0): Boolean;
799 var
800 i: Integer;
801 ChkTeam: Boolean;
802 p: TPlayer;
803 begin
804 Result := False;
805 h := High(gPlayers);
807 if h <> -1 then
808 for i := 0 to h do
809 if (gPlayers[i] <> nil) and gPlayers[i].alive and g_Obj_Collide(obj, @gPlayers[i].Obj) then
810 begin
811 ChkTeam := True;
812 if (Team > 0) and (g_GetUIDType(SpawnerUID) = UID_PLAYER) then
813 begin
814 p := g_Player_Get(SpawnerUID);
815 if p <> nil then
816 ChkTeam := (p.Team = gPlayers[i].Team) xor (Team = 2);
817 end;
818 if ChkTeam then
819 if HitPlayer(gPlayers[i], d, obj^.Vel.X, obj^.Vel.Y, SpawnerUID, t) then
820 begin
821 if t <> HIT_FLAME then
822 gPlayers[i].Push((obj^.Vel.X+obj^.Accel.X)*IfThen(t = HIT_BFG, 8, 1) div 4,
823 (obj^.Vel.Y+obj^.Accel.Y)*IfThen(t = HIT_BFG, 8, 1) div 4);
824 if t = HIT_BFG then
825 g_Game_DelayEvent(DE_BFGHIT, 1000, SpawnerUID);
826 Result := True;
827 break;
828 end;
829 end;
830 end;
833 function monsCheckHit (monidx: Integer; mon: TMonster): Boolean;
834 begin
835 result := false; // don't stop
836 if mon.alive and g_Obj_Collide(obj, @mon.Obj) then
837 begin
838 if HitMonster(mon, d, obj^.Vel.X, obj^.Vel.Y, SpawnerUID, t) then
839 begin
840 if (t <> HIT_FLAME) then
841 begin
842 mon.Push((obj^.Vel.X+obj^.Accel.X)*IfThen(t = HIT_BFG, 8, 1) div 4,
843 (obj^.Vel.Y+obj^.Accel.Y)*IfThen(t = HIT_BFG, 8, 1) div 4);
844 end;
845 result := True;
846 end;
847 end;
848 end;
851 function monsCheckHit (mon: TMonster): Boolean;
852 begin
853 result := false; // don't stop
854 if HitMonster(mon, d, obj.Vel.X, obj.Vel.Y, SpawnerUID, t) then
855 begin
856 if (t <> HIT_FLAME) then
857 begin
858 mon.Push((obj.Vel.X+obj.Accel.X)*IfThen(t = HIT_BFG, 8, 1) div 4,
859 (obj.Vel.Y+obj.Accel.Y)*IfThen(t = HIT_BFG, 8, 1) div 4);
860 end;
861 result := true;
862 end;
863 end;
865 function MonsterHit(): Boolean;
866 begin
867 //result := g_Mons_ForEach(monsCheckHit);
868 //FIXME: accelerate this!
869 result := g_Mons_ForEachAliveAt(obj.X+obj.Rect.X, obj.Y+obj.Rect.Y, obj.Rect.Width, obj.Rect.Height, monsCheckHit);
870 end;
872 begin
873 Result := 0;
875 {$IFDEF ENABLE_CORPSES}
876 if HitCorpses then
877 begin
878 h := High(gCorpses);
879 if gAdvCorpses and (h <> -1) then
880 begin
881 for i := 0 to h do
882 begin
883 if (gCorpses[i] <> nil) and (gCorpses[i].State <> CORPSE_STATE_REMOVEME) and
884 g_Obj_Collide(obj, @gCorpses[i].Obj) then
885 begin
886 // Ðàñïèëèâàåì òðóï:
887 gCorpses[i].Damage(d, SpawnerUID, (obj^.Vel.X+obj^.Accel.X) div 4,
888 (obj^.Vel.Y+obj^.Accel.Y) div 4);
889 Result := 1;
890 end;
891 end;
892 end;
893 end;
894 {$ENDIF}
896 case gGameSettings.GameMode of
897 // Êàìïàíèÿ:
898 GM_COOP, GM_SINGLE:
899 begin
900 // Ñíà÷àëà áü¸ì ìîíñòðîâ, åñëè åñòü, ïîòîì ïûòàåìñÿ áèòü èãðîêîâ
901 if MonsterHit() then
902 begin
903 Result := 2;
904 Exit;
905 end;
907 // È â êîíöå èãðîêîâ, íî òîëüêî åñëè ïîëîæåíî
908 // (èëè ñíàðÿä îò ìîíñòðà, èëè friendlyfire, èëè friendly_hit_projectile)
909 if (g_GetUIDType(SpawnerUID) <> UID_PLAYER) or
910 LongBool(gGameSettings.Options and (GAME_OPTION_TEAMDAMAGE or GAME_OPTION_TEAMHITPROJECTILE)) then
911 begin
912 if PlayerHit() then
913 begin
914 Result := 1;
915 Exit;
916 end;
917 end;
918 end;
920 // Äåçìàò÷:
921 GM_DM:
922 begin
923 // Ñíà÷àëà áü¸ì èãðîêîâ, åñëè åñòü, ïîòîì ïûòàåìñÿ áèòü ìîíñòðîâ
924 if PlayerHit() then
925 begin
926 Result := 1;
927 Exit;
928 end;
930 if MonsterHit() then
931 begin
932 Result := 2;
933 Exit;
934 end;
935 end;
937 // Êîìàíäíûå:
938 GM_TDM, GM_CTF:
939 begin
940 // Ñíà÷àëà áü¸ì èãðîêîâ êîìàíäû ñîïåðíèêà
941 if PlayerHit(2) then
942 begin
943 Result := 1;
944 Exit;
945 end;
947 // Ïîòîì ìîíñòðîâ
948 if MonsterHit() then
949 begin
950 Result := 2;
951 Exit;
952 end;
954 // È â êîíöå ñâîèõ èãðîêîâ, íî òîëüêî åñëè ïîëîæåíî
955 // (èëè friendlyfire, èëè friendly_hit_projectile)
956 if LongBool(gGameSettings.Options and (GAME_OPTION_TEAMDAMAGE or GAME_OPTION_TEAMHITPROJECTILE)) then
957 begin
958 if PlayerHit(1) then
959 begin
960 Result := 1;
961 Exit;
962 end;
963 end;
964 end;
966 end;
967 end;
969 function g_Weapon_HitUID(UID: Word; d: Integer; SpawnerUID: Word; t: Byte): Boolean;
970 begin
971 Result := False;
973 case g_GetUIDType(UID) of
974 UID_PLAYER: Result := HitPlayer(g_Player_Get(UID), d, 0, 0, SpawnerUID, t);
975 UID_MONSTER: Result := HitMonster(g_Monsters_ByUID(UID), d, 0, 0, SpawnerUID, t);
976 else Exit;
977 end;
978 end;
980 function g_Weapon_Explode(X, Y: Integer; rad: Integer; SpawnerUID: Word): Boolean;
981 var
982 r: Integer; // squared radius
984 function monsExCheck (mon: TMonster): Boolean;
985 var
986 dx, dy, mm: Integer;
987 begin
988 result := false; // don't stop
989 begin
990 dx := mon.Obj.X+mon.Obj.Rect.X+(mon.Obj.Rect.Width div 2)-X;
991 dy := mon.Obj.Y+mon.Obj.Rect.Y+(mon.Obj.Rect.Height div 2)-Y;
993 if dx > 1000 then dx := 1000;
994 if dy > 1000 then dy := 1000;
996 if (dx*dx+dy*dy < r) then
997 begin
998 //m := PointToRect(X, Y, Obj.X+Obj.Rect.X, Obj.Y+Obj.Rect.Y, Obj.Rect.Width, Obj.Rect.Height);
999 //e_WriteLog(Format('explo monster #%d: x=%d; y=%d; rad=%d; dx=%d; dy=%d', [monidx, X, Y, rad, dx, dy]), MSG_NOTIFY);
1001 mm := Max(abs(dx), abs(dy));
1002 if mm = 0 then mm := 1;
1004 if mon.alive then
1005 begin
1006 HitMonster(mon, ((mon.Obj.Rect.Width div 4)*10*(rad-mm)) div rad, 0, 0, SpawnerUID, HIT_ROCKET);
1007 end;
1009 mon.Push((dx*7) div mm, (dy*7) div mm);
1010 end;
1011 end;
1012 end;
1014 var i, h, dx, dy, mm: Integer;
1015 {$IFDEF ENABLE_GIBS}
1016 var _angle: SmallInt;
1017 {$ENDIF}
1018 {$IF DEFINED(ENABLE_GIBS) OR DEFINED(ENABLE_CORPSES)}
1019 var m: Integer;
1020 {$ENDIF}
1021 begin
1022 result := false;
1024 g_Triggers_PressC(X, Y, rad, SpawnerUID, ACTIVATE_SHOT);
1026 r := rad*rad;
1028 h := High(gPlayers);
1030 if h <> -1 then
1031 for i := 0 to h do
1032 if (gPlayers[i] <> nil) and gPlayers[i].alive then
1033 with gPlayers[i] do
1034 begin
1035 dx := Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2)-X;
1036 dy := Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)-Y;
1038 if dx > 1000 then dx := 1000;
1039 if dy > 1000 then dy := 1000;
1041 if dx*dx+dy*dy < r then
1042 begin
1043 //m := PointToRect(X, Y, GameX+PLAYER_RECT.X, GameY+PLAYER_RECT.Y,
1044 // PLAYER_RECT.Width, PLAYER_RECT.Height);
1046 mm := Max(abs(dx), abs(dy));
1047 if mm = 0 then mm := 1;
1049 HitPlayer(gPlayers[i], (100*(rad-mm)) div rad, (dx*10) div mm, (dy*10) div mm, SpawnerUID, HIT_ROCKET);
1050 gPlayers[i].Push((dx*7) div mm, (dy*7) div mm);
1051 end;
1052 end;
1054 //g_Mons_ForEach(monsExCheck);
1055 g_Mons_ForEachAt(X-(rad+32), Y-(rad+32), (rad+32)*2, (rad+32)*2, monsExCheck);
1057 {$IFDEF ENABLE_CORPSES}
1058 h := High(gCorpses);
1059 if gAdvCorpses and (h <> -1) then
1060 begin
1061 for i := 0 to h do
1062 begin
1063 if (gCorpses[i] <> nil) and (gCorpses[i].State <> CORPSE_STATE_REMOVEME) then
1064 begin
1065 with gCorpses[i] do
1066 begin
1067 dx := Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2)-X;
1068 dy := Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)-Y;
1069 if dx > 1000 then dx := 1000;
1070 if dy > 1000 then dy := 1000;
1071 if dx*dx+dy*dy < r then
1072 begin
1073 m := PointToRect(X, Y, Obj.X+Obj.Rect.X, Obj.Y+Obj.Rect.Y, Obj.Rect.Width, Obj.Rect.Height);
1074 mm := Max(abs(dx), abs(dy));
1075 if mm = 0 then
1076 mm := 1;
1077 Damage(Round(100*(rad-m)/rad), SpawnerUID, (dx*10) div mm, (dy*10) div mm);
1078 end;
1079 end;
1080 end;
1081 end;
1082 end;
1083 {$ENDIF}
1085 {$IFDEF ENABLE_GIBS}
1086 h := High(gGibs);
1087 if gAdvGibs and (h <> -1) then
1088 for i := 0 to h do
1089 if gGibs[i].alive then
1090 with gGibs[i] do
1091 begin
1092 dx := Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2)-X;
1093 dy := Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)-Y;
1094 if dx > 1000 then dx := 1000;
1095 if dy > 1000 then dy := 1000;
1096 if dx*dx+dy*dy < r then
1097 begin
1098 m := PointToRect(X, Y, Obj.X+Obj.Rect.X, Obj.Y+Obj.Rect.Y,
1099 Obj.Rect.Width, Obj.Rect.Height);
1100 _angle := GetAngle(Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2),
1101 Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2), X, Y);
1102 g_Obj_PushA(@Obj, Round(15*(rad-m)/rad), _angle);
1103 positionChanged(); // this updates spatial accelerators
1104 end;
1105 end;
1106 {$ENDIF}
1107 end;
1109 procedure g_Weapon_Init();
1110 begin
1111 CreateWaterMap();
1112 end;
1114 procedure g_Weapon_Free();
1115 begin
1116 Shots := nil;
1117 WaterMap := nil;
1118 end;
1120 procedure g_Weapon_LoadData();
1121 begin
1122 e_WriteLog('Loading weapons data...', TMsgType.Notify);
1124 g_Sound_CreateWADEx('SOUND_WEAPON_HITPUNCH', GameWAD+':SOUNDS\HITPUNCH');
1125 g_Sound_CreateWADEx('SOUND_WEAPON_MISSPUNCH', GameWAD+':SOUNDS\MISSPUNCH');
1126 g_Sound_CreateWADEx('SOUND_WEAPON_HITBERSERK', GameWAD+':SOUNDS\HITBERSERK');
1127 g_Sound_CreateWADEx('SOUND_WEAPON_MISSBERSERK', GameWAD+':SOUNDS\MISSBERSERK');
1128 g_Sound_CreateWADEx('SOUND_WEAPON_SELECTSAW', GameWAD+':SOUNDS\SELECTSAW');
1129 g_Sound_CreateWADEx('SOUND_WEAPON_IDLESAW', GameWAD+':SOUNDS\IDLESAW');
1130 g_Sound_CreateWADEx('SOUND_WEAPON_HITSAW', GameWAD+':SOUNDS\HITSAW');
1131 g_Sound_CreateWADEx('SOUND_WEAPON_FIRESHOTGUN2', GameWAD+':SOUNDS\FIRESHOTGUN2');
1132 g_Sound_CreateWADEx('SOUND_WEAPON_FIRESHOTGUN', GameWAD+':SOUNDS\FIRESHOTGUN');
1133 g_Sound_CreateWADEx('SOUND_WEAPON_FIRESAW', GameWAD+':SOUNDS\FIRESAW');
1134 g_Sound_CreateWADEx('SOUND_WEAPON_FIREROCKET', GameWAD+':SOUNDS\FIREROCKET');
1135 g_Sound_CreateWADEx('SOUND_WEAPON_FIREPLASMA', GameWAD+':SOUNDS\FIREPLASMA');
1136 g_Sound_CreateWADEx('SOUND_WEAPON_FIREPISTOL', GameWAD+':SOUNDS\FIREPISTOL');
1137 g_Sound_CreateWADEx('SOUND_WEAPON_FIRECGUN', GameWAD+':SOUNDS\FIRECGUN');
1138 g_Sound_CreateWADEx('SOUND_WEAPON_FIREBFG', GameWAD+':SOUNDS\FIREBFG');
1139 g_Sound_CreateWADEx('SOUND_FIRE', GameWAD+':SOUNDS\FIRE');
1140 g_Sound_CreateWADEx('SOUND_IGNITE', GameWAD+':SOUNDS\IGNITE');
1141 g_Sound_CreateWADEx('SOUND_WEAPON_STARTFIREBFG', GameWAD+':SOUNDS\STARTFIREBFG');
1142 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEROCKET', GameWAD+':SOUNDS\EXPLODEROCKET');
1143 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEBFG', GameWAD+':SOUNDS\EXPLODEBFG');
1144 g_Sound_CreateWADEx('SOUND_WEAPON_BFGWATER', GameWAD+':SOUNDS\BFGWATER');
1145 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEPLASMA', GameWAD+':SOUNDS\EXPLODEPLASMA');
1146 g_Sound_CreateWADEx('SOUND_WEAPON_PLASMAWATER', GameWAD+':SOUNDS\PLASMAWATER');
1147 g_Sound_CreateWADEx('SOUND_WEAPON_FIREBALL', GameWAD+':SOUNDS\FIREBALL');
1148 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEBALL', GameWAD+':SOUNDS\EXPLODEBALL');
1149 g_Sound_CreateWADEx('SOUND_WEAPON_FIREREV', GameWAD+':SOUNDS\FIREREV');
1150 g_Sound_CreateWADEx('SOUND_WEAPON_FLAMEON', GameWAD+':SOUNDS\STARTFLM');
1151 g_Sound_CreateWADEx('SOUND_WEAPON_FLAMEOFF', GameWAD+':SOUNDS\STOPFLM');
1152 g_Sound_CreateWADEx('SOUND_WEAPON_FLAMEWORK', GameWAD+':SOUNDS\WORKFLM');
1153 g_Sound_CreateWADEx('SOUND_PLAYER_JETFLY', GameWAD+':SOUNDS\WORKJETPACK');
1154 g_Sound_CreateWADEx('SOUND_PLAYER_JETON', GameWAD+':SOUNDS\STARTJETPACK');
1155 g_Sound_CreateWADEx('SOUND_PLAYER_JETOFF', GameWAD+':SOUNDS\STOPJETPACK');
1156 g_Sound_CreateWADEx('SOUND_PLAYER_CASING1', GameWAD+':SOUNDS\CASING1');
1157 g_Sound_CreateWADEx('SOUND_PLAYER_CASING2', GameWAD+':SOUNDS\CASING2');
1158 g_Sound_CreateWADEx('SOUND_PLAYER_SHELL1', GameWAD+':SOUNDS\SHELL1');
1159 g_Sound_CreateWADEx('SOUND_PLAYER_SHELL2', GameWAD+':SOUNDS\SHELL2');
1161 //wgunMonHash := hashNewIntInt();
1162 wgunHitHeap := TBinaryHeapHitTimes.Create();
1163 end;
1165 procedure g_Weapon_FreeData();
1166 begin
1167 e_WriteLog('Releasing weapons data...', TMsgType.Notify);
1169 g_Sound_Delete('SOUND_WEAPON_HITPUNCH');
1170 g_Sound_Delete('SOUND_WEAPON_MISSPUNCH');
1171 g_Sound_Delete('SOUND_WEAPON_HITBERSERK');
1172 g_Sound_Delete('SOUND_WEAPON_MISSBERSERK');
1173 g_Sound_Delete('SOUND_WEAPON_SELECTSAW');
1174 g_Sound_Delete('SOUND_WEAPON_IDLESAW');
1175 g_Sound_Delete('SOUND_WEAPON_HITSAW');
1176 g_Sound_Delete('SOUND_WEAPON_FIRESHOTGUN2');
1177 g_Sound_Delete('SOUND_WEAPON_FIRESHOTGUN');
1178 g_Sound_Delete('SOUND_WEAPON_FIRESAW');
1179 g_Sound_Delete('SOUND_WEAPON_FIREROCKET');
1180 g_Sound_Delete('SOUND_WEAPON_FIREPLASMA');
1181 g_Sound_Delete('SOUND_WEAPON_FIREPISTOL');
1182 g_Sound_Delete('SOUND_WEAPON_FIRECGUN');
1183 g_Sound_Delete('SOUND_WEAPON_FIREBFG');
1184 g_Sound_Delete('SOUND_FIRE');
1185 g_Sound_Delete('SOUND_IGNITE');
1186 g_Sound_Delete('SOUND_WEAPON_STARTFIREBFG');
1187 g_Sound_Delete('SOUND_WEAPON_EXPLODEROCKET');
1188 g_Sound_Delete('SOUND_WEAPON_EXPLODEBFG');
1189 g_Sound_Delete('SOUND_WEAPON_BFGWATER');
1190 g_Sound_Delete('SOUND_WEAPON_EXPLODEPLASMA');
1191 g_Sound_Delete('SOUND_WEAPON_PLASMAWATER');
1192 g_Sound_Delete('SOUND_WEAPON_FIREBALL');
1193 g_Sound_Delete('SOUND_WEAPON_EXPLODEBALL');
1194 g_Sound_Delete('SOUND_WEAPON_FIREREV');
1195 g_Sound_Delete('SOUND_WEAPON_FLAMEON');
1196 g_Sound_Delete('SOUND_WEAPON_FLAMEOFF');
1197 g_Sound_Delete('SOUND_WEAPON_FLAMEWORK');
1198 g_Sound_Delete('SOUND_PLAYER_JETFLY');
1199 g_Sound_Delete('SOUND_PLAYER_JETON');
1200 g_Sound_Delete('SOUND_PLAYER_JETOFF');
1201 g_Sound_Delete('SOUND_PLAYER_CASING1');
1202 g_Sound_Delete('SOUND_PLAYER_CASING2');
1203 g_Sound_Delete('SOUND_PLAYER_SHELL1');
1204 g_Sound_Delete('SOUND_PLAYER_SHELL2');
1205 end;
1208 function GunHitPlayer (X, Y: Integer; vx, vy: Integer; dmg: Integer; SpawnerUID: Word; AllowPush: Boolean): Boolean;
1209 var
1210 i: Integer;
1211 begin
1212 result := false;
1213 for i := 0 to High(gPlayers) do
1214 begin
1215 if (gPlayers[i] <> nil) and gPlayers[i].alive and gPlayers[i].Collide(X, Y) then
1216 begin
1217 if HitPlayer(gPlayers[i], dmg, vx*10, vy*10-3, SpawnerUID, HIT_SOME) then
1218 begin
1219 if AllowPush then gPlayers[i].Push(vx, vy);
1220 result := true;
1221 end;
1222 end;
1223 end;
1224 end;
1227 function GunHit (X, Y: Integer; vx, vy: Integer; dmg: Integer; SpawnerUID: Word; AllowPush: Boolean): Byte;
1229 function monsCheck (mon: TMonster): Boolean;
1230 begin
1231 result := false; // don't stop
1232 if HitMonster(mon, dmg, vx*10, vy*10-3, SpawnerUID, HIT_SOME) then
1233 begin
1234 if AllowPush then mon.Push(vx, vy);
1235 result := true;
1236 end;
1237 end;
1239 begin
1240 result := 0;
1241 if GunHitPlayer(X, Y, vx, vy, dmg, SpawnerUID, AllowPush) then result := 1
1242 else if g_Mons_ForEachAliveAt(X, Y, 1, 1, monsCheck) then result := 2;
1243 end;
1246 (*
1247 procedure g_Weapon_gunOld(const x, y, xd, yd, v, dmg: Integer; SpawnerUID: Word; CheckTrigger: Boolean);
1248 var
1249 a: Integer;
1250 x2, y2: Integer;
1251 dx, dy: Integer;
1252 xe, ye: Integer;
1253 xi, yi: Integer;
1254 s, c: Extended;
1255 //vx, vy: Integer;
1256 xx, yy, d: Integer;
1257 i: Integer;
1258 t1, _collide: Boolean;
1259 w, h: Word;
1260 {$IF DEFINED(D2F_DEBUG)}
1261 stt: UInt64;
1262 showTime: Boolean = true;
1263 {$ENDIF}
1264 begin
1265 a := GetAngle(x, y, xd, yd)+180;
1267 SinCos(DegToRad(-a), s, c);
1269 if Abs(s) < 0.01 then s := 0;
1270 if Abs(c) < 0.01 then c := 0;
1272 x2 := x+Round(c*gMapInfo.Width);
1273 y2 := y+Round(s*gMapInfo.Width);
1275 t1 := gWalls <> nil;
1276 _collide := False;
1277 w := gMapInfo.Width;
1278 h := gMapInfo.Height;
1280 xe := 0;
1281 ye := 0;
1282 dx := x2-x;
1283 dy := y2-y;
1285 if (xd = 0) and (yd = 0) then Exit;
1287 if dx > 0 then xi := 1 else if dx < 0 then xi := -1 else xi := 0;
1288 if dy > 0 then yi := 1 else if dy < 0 then yi := -1 else yi := 0;
1290 dx := Abs(dx);
1291 dy := Abs(dy);
1293 if dx > dy then d := dx else d := dy;
1295 //blood vel, for Monster.Damage()
1296 //vx := (dx*10 div d)*xi;
1297 //vy := (dy*10 div d)*yi;
1299 {$IF DEFINED(D2F_DEBUG)}
1300 stt := getTimeMicro();
1301 {$ENDIF}
1303 xx := x;
1304 yy := y;
1306 for i := 1 to d do
1307 begin
1308 xe := xe+dx;
1309 ye := ye+dy;
1311 if xe > d then
1312 begin
1313 xe := xe-d;
1314 xx := xx+xi;
1315 end;
1317 if ye > d then
1318 begin
1319 ye := ye-d;
1320 yy := yy+yi;
1321 end;
1323 if (yy > h) or (yy < 0) then Break;
1324 if (xx > w) or (xx < 0) then Break;
1326 if t1 then
1327 if ByteBool(gCollideMap[yy, xx] and MARK_BLOCKED) then
1328 begin
1329 _collide := True;
1330 {$IF DEFINED(D2F_DEBUG)}
1331 stt := getTimeMicro()-stt;
1332 e_WriteLog(Format('*** old trace time: %u microseconds', [LongWord(stt)]), MSG_NOTIFY);
1333 showTime := false;
1334 {$ENDIF}
1335 g_GFX_Spark(xx-xi, yy-yi, 2+Random(2), 180+a, 0, 0);
1336 if g_Game_IsServer and g_Game_IsNet then
1337 MH_SEND_Effect(xx-xi, yy-yi, 180+a, NET_GFX_SPARK);
1338 end;
1340 if not _collide then
1341 begin
1342 _collide := GunHit(xx, yy, xi*v, yi*v, dmg, SpawnerUID, v <> 0) <> 0;
1343 end;
1345 if _collide then Break;
1346 end;
1348 {$IF DEFINED(D2F_DEBUG)}
1349 if showTime then
1350 begin
1351 stt := getTimeMicro()-stt;
1352 e_WriteLog(Format('*** old trace time: %u microseconds', [LongWord(stt)]), MSG_NOTIFY);
1353 end;
1354 {$ENDIF}
1356 if CheckTrigger and g_Game_IsServer then
1357 g_Triggers_PressL(X, Y, xx-xi, yy-yi, SpawnerUID, ACTIVATE_SHOT);
1358 end;
1359 *)
1362 //!!!FIXME!!!
1363 procedure g_Weapon_gun (const x, y, xd, yd, v, indmg: Integer; SpawnerUID: Word; CheckTrigger: Boolean);
1364 var
1365 x0, y0: Integer;
1366 x2, y2: Integer;
1367 xi, yi: Integer;
1368 wallDistSq: Integer = $3fffffff;
1369 spawnerPlr: TPlayer = nil;
1370 dmg: Integer;
1372 function doPlayerHit (idx: Integer; hx, hy: Integer): Boolean;
1373 begin
1374 result := false;
1375 if (idx < 0) or (idx > High(gPlayers)) then exit;
1376 if (gPlayers[idx] = nil) or not gPlayers[idx].alive then exit;
1377 if (spawnerPlr <> nil) then
1378 begin
1379 if ((gGameSettings.Options and (GAME_OPTION_TEAMHITTRACE or GAME_OPTION_TEAMDAMAGE)) = 0) and
1380 (spawnerPlr.Team <> TEAM_NONE) and (spawnerPlr.Team = gPlayers[idx].Team) then
1381 begin
1382 if (spawnerPlr <> gPlayers[idx]) and ((gGameSettings.Options and GAME_OPTION_TEAMABSORBDAMAGE) = 0) then
1383 dmg := Max(1, dmg div 2);
1384 exit;
1385 end;
1386 end;
1387 result := HitPlayer(gPlayers[idx], dmg, (xi*v)*10, (yi*v)*10-3, SpawnerUID, HIT_SOME);
1388 if result and (v <> 0) then gPlayers[idx].Push((xi*v), (yi*v));
1389 {$IF DEFINED(D2F_DEBUG)}
1390 //if result then e_WriteLog(Format(' PLAYER #%d HIT', [idx]), MSG_NOTIFY);
1391 {$ENDIF}
1392 end;
1394 function doMonsterHit (mon: TMonster; hx, hy: Integer): Boolean;
1395 begin
1396 result := false;
1397 if (mon = nil) then exit;
1398 result := HitMonster(mon, dmg, (xi*v)*10, (yi*v)*10-3, SpawnerUID, HIT_SOME);
1399 if result and (v <> 0) then mon.Push((xi*v), (yi*v));
1400 {$IF DEFINED(D2F_DEBUG)}
1401 //if result then e_WriteLog(Format(' MONSTER #%u HIT', [LongWord(mon.UID)]), MSG_NOTIFY);
1402 {$ENDIF}
1403 end;
1405 // collect players along hitray
1406 // return `true` if instant hit was detected
1407 function playerPossibleHit (): Boolean;
1408 var
1409 i: Integer;
1410 px, py, pw, ph: Integer;
1411 inx, iny: Integer;
1412 distSq: Integer;
1413 plr: TPlayer;
1414 begin
1415 result := false;
1416 for i := 0 to High(gPlayers) do
1417 begin
1418 plr := gPlayers[i];
1419 if (plr <> nil) and plr.alive then
1420 begin
1421 plr.getMapBox(px, py, pw, ph);
1422 if lineAABBIntersects(x, y, x2, y2, px, py, pw, ph, inx, iny) then
1423 begin
1424 distSq := distanceSq(x, y, inx, iny);
1425 if (distSq = 0) then
1426 begin
1427 // contains
1428 if doPlayerHit(i, x, y) then begin result := true; exit; end;
1429 end
1430 else if (distSq < wallDistSq) then
1431 begin
1432 appendHitTimePlr(distSq, i, inx, iny);
1433 end;
1434 end;
1435 end;
1436 end;
1437 end;
1439 procedure sqchecker (mon: TMonster);
1440 var
1441 mx, my, mw, mh: Integer;
1442 inx, iny: Integer;
1443 distSq: Integer;
1444 begin
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 mit: PMonster;
1467 it: TMonsterGrid.Iter;
1468 begin
1469 (*
1470 if not gwep_debug_fast_trace then
1471 begin
1472 g_Weapon_gunOld(x, y, xd, yd, v, dmg, SpawnerUID, CheckTrigger);
1473 exit;
1474 end;
1475 *)
1477 if (xd = 0) and (yd = 0) then exit;
1479 if (g_GetUIDType(SpawnerUID) = UID_PLAYER) then
1480 spawnerPlr := g_Player_Get(SpawnerUID);
1482 dmg := indmg;
1484 //wgunMonHash.reset(); //FIXME: clear hash on level change
1485 wgunHitHeap.clear();
1486 wgunHitTimeUsed := 0;
1488 a := GetAngle(x, y, xd, yd)+180;
1490 SinCos(DegToRad(-a), s, c);
1492 if Abs(s) < 0.01 then s := 0;
1493 if Abs(c) < 0.01 then c := 0;
1495 x0 := x;
1496 y0 := y;
1497 x2 := x+Round(c*gMapInfo.Width);
1498 y2 := y+Round(s*gMapInfo.Width);
1500 dx := x2-x;
1501 dy := y2-y;
1503 if (dx > 0) then xi := 1 else if (dx < 0) then xi := -1 else xi := 0;
1504 if (dy > 0) then yi := 1 else if (dy < 0) then yi := -1 else yi := 0;
1506 {$IF DEFINED(D2F_DEBUG)}
1507 e_WriteLog(Format('GUN TRACE: (%d,%d) to (%d,%d)', [x, y, x2, y2]), TMsgType.Notify);
1508 stt := getTimeMicro();
1509 {$ENDIF}
1511 wallHitFlag := (g_Map_traceToNearestWall(x, y, x2, y2, @wallHitX, @wallHitY) <> nil);
1512 if wallHitFlag then
1513 begin
1514 x2 := wallHitX;
1515 y2 := wallHitY;
1516 wallDistSq := distanceSq(x, y, wallHitX, wallHitY);
1517 end
1518 else
1519 begin
1520 wallHitX := x2;
1521 wallHitY := y2;
1522 end;
1524 if playerPossibleHit() then exit; // instant hit
1526 // collect monsters
1527 //g_Mons_AlongLine(x, y, x2, y2, sqchecker);
1529 it := monsGrid.forEachAlongLine(x, y, x2, y2, -1);
1530 for mit in it do sqchecker(mit^);
1531 it.release();
1533 // here, we collected all monsters and players in `wgunHitHeap` and `wgunHitTime`
1534 // also, if `wallWasHit` is `true`, then `wallHitX` and `wallHitY` contains spark coords
1535 while (wgunHitHeap.count > 0) do
1536 begin
1537 // has some entities to check, do it
1538 i := wgunHitHeap.front;
1539 wgunHitHeap.popFront();
1540 // hitpoint
1541 xe := wgunHitTime[i].x;
1542 ye := wgunHitTime[i].y;
1543 // check if it is not behind the wall
1544 if (wgunHitTime[i].mon <> nil) then
1545 begin
1546 didHit := doMonsterHit(wgunHitTime[i].mon, xe, ye);
1547 end
1548 else
1549 begin
1550 didHit := doPlayerHit(wgunHitTime[i].plridx, xe, ye);
1551 end;
1552 if didHit then
1553 begin
1554 // need new coords for trigger
1555 wallHitX := xe;
1556 wallHitY := ye;
1557 wallHitFlag := false; // no sparks
1558 break;
1559 end;
1560 end;
1562 // need sparks?
1563 if wallHitFlag then
1564 begin
1565 {$IF DEFINED(D2F_DEBUG)}
1566 stt := getTimeMicro()-stt;
1567 e_WriteLog(Format('*** new trace time: %u microseconds', [LongWord(stt)]), TMsgType.Notify);
1568 {$ENDIF}
1569 {$IFDEF ENABLE_GFX}
1570 g_GFX_Spark(wallHitX, wallHitY, 2+Random(2), 180+a, 0, 0);
1571 {$ENDIF}
1572 if g_Game_IsServer and g_Game_IsNet then MH_SEND_Effect(wallHitX, wallHitY, 180+a, NET_GFX_SPARK);
1573 end
1574 else
1575 begin
1576 {$IF DEFINED(D2F_DEBUG)}
1577 stt := getTimeMicro()-stt;
1578 e_WriteLog(Format('*** new trace time: %u microseconds', [LongWord(stt)]), TMsgType.Notify);
1579 {$ENDIF}
1580 end;
1582 if CheckTrigger and g_Game_IsServer then g_Triggers_PressL(X, Y, wallHitX, wallHitY, SpawnerUID, ACTIVATE_SHOT);
1583 end;
1586 procedure g_Weapon_punch(x, y: Integer; d, SpawnerUID: Word);
1587 var
1588 obj: TObj;
1589 begin
1590 obj.X := X;
1591 obj.Y := Y;
1592 obj.rect.X := 0;
1593 obj.rect.Y := 0;
1594 obj.rect.Width := 39;
1595 obj.rect.Height := 52;
1596 obj.Vel.X := 0;
1597 obj.Vel.Y := 0;
1598 obj.Accel.X := 0;
1599 obj.Accel.Y := 0;
1601 if g_Weapon_Hit(@obj, d, SpawnerUID, HIT_SOME) <> 0 then
1602 g_Sound_PlayExAt('SOUND_WEAPON_HITPUNCH', x, y)
1603 else
1604 g_Sound_PlayExAt('SOUND_WEAPON_MISSPUNCH', x, y);
1605 end;
1607 function g_Weapon_chainsaw(x, y: Integer; d, SpawnerUID: Word): Integer;
1608 var
1609 obj: TObj;
1610 begin
1611 obj.X := X;
1612 obj.Y := Y;
1613 obj.rect.X := 0;
1614 obj.rect.Y := 0;
1615 obj.rect.Width := 32;
1616 obj.rect.Height := 52;
1617 obj.Vel.X := 0;
1618 obj.Vel.Y := 0;
1619 obj.Accel.X := 0;
1620 obj.Accel.Y := 0;
1622 Result := g_Weapon_Hit(@obj, d, SpawnerUID, HIT_SOME);
1623 end;
1625 procedure g_Weapon_rocket(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1626 Silent: Boolean = False; compat: Boolean = true);
1627 var
1628 find_id: DWORD;
1629 dx, dy: Integer;
1630 begin
1631 if WID < 0 then
1632 find_id := FindShot()
1633 else
1634 begin
1635 find_id := WID;
1636 if Integer(find_id) >= High(Shots) then
1637 SetLength(Shots, find_id + 64)
1638 end;
1640 with Shots[find_id] do
1641 begin
1642 g_Obj_Init(@Obj);
1644 Obj.Rect.Width := SHOT_ROCKETLAUNCHER_WIDTH;
1645 Obj.Rect.Height := SHOT_ROCKETLAUNCHER_HEIGHT;
1647 if compat then
1648 dx := IfThen(xd > x, -Obj.Rect.Width, 0)
1649 else
1650 dx := -(Obj.Rect.Width div 2);
1651 dy := -(Obj.Rect.Height div 2);
1653 ShotType := WEAPON_ROCKETLAUNCHER;
1654 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 12);
1656 Animation.Invalidate;
1657 triggers := nil;
1658 end;
1660 Shots[find_id].SpawnerUID := SpawnerUID;
1662 if not Silent then
1663 g_Sound_PlayExAt('SOUND_WEAPON_FIREROCKET', x, y);
1664 end;
1666 procedure g_Weapon_revf(x, y, xd, yd: Integer; SpawnerUID, TargetUID: Word;
1667 WID: Integer = -1; Silent: Boolean = False);
1668 var
1669 find_id: DWORD;
1670 dx, dy: Integer;
1671 begin
1672 if WID < 0 then
1673 find_id := FindShot()
1674 else
1675 begin
1676 find_id := WID;
1677 if Integer(find_id) >= High(Shots) then
1678 SetLength(Shots, find_id + 64)
1679 end;
1681 with Shots[find_id] do
1682 begin
1683 g_Obj_Init(@Obj);
1685 Obj.Rect.Width := SHOT_SKELFIRE_WIDTH;
1686 Obj.Rect.Height := SHOT_SKELFIRE_HEIGHT;
1688 dx := -(Obj.Rect.Width div 2);
1689 dy := -(Obj.Rect.Height div 2);
1691 ShotType := WEAPON_SKEL_FIRE;
1692 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 12);
1694 triggers := nil;
1695 target := TargetUID;
1696 Animation := TAnimState.Create(True, 5, 2); // !!! put values into table
1697 end;
1699 Shots[find_id].SpawnerUID := SpawnerUID;
1701 if not Silent then
1702 g_Sound_PlayExAt('SOUND_WEAPON_FIREREV', x, y);
1703 end;
1705 procedure g_Weapon_plasma(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1706 Silent: Boolean = False; compat: Boolean = true);
1707 var
1708 find_id: DWORD;
1709 dx, dy: Integer;
1710 begin
1711 if WID < 0 then
1712 find_id := FindShot()
1713 else
1714 begin
1715 find_id := WID;
1716 if Integer(find_id) >= High(Shots) then
1717 SetLength(Shots, find_id + 64);
1718 end;
1720 with Shots[find_id] do
1721 begin
1722 g_Obj_Init(@Obj);
1724 Obj.Rect.Width := SHOT_PLASMA_WIDTH;
1725 Obj.Rect.Height := SHOT_PLASMA_HEIGHT;
1727 if compat then
1728 dx := IfThen(xd > x, -Obj.Rect.Width, 0)
1729 else
1730 dx := -(Obj.Rect.Width div 2);
1731 dy := -(Obj.Rect.Height div 2);
1733 ShotType := WEAPON_PLASMA;
1734 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1736 triggers := nil;
1737 Animation := TAnimState.Create(True, 5, 2); // !!! put values into table
1738 end;
1740 Shots[find_id].SpawnerUID := SpawnerUID;
1742 if not Silent then
1743 g_Sound_PlayExAt('SOUND_WEAPON_FIREPLASMA', x, y);
1744 end;
1746 procedure g_Weapon_flame(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1747 Silent: Boolean = False; compat: Boolean = true);
1748 var
1749 find_id: DWORD;
1750 dx, dy: Integer;
1751 begin
1752 if WID < 0 then
1753 find_id := FindShot()
1754 else
1755 begin
1756 find_id := WID;
1757 if Integer(find_id) >= High(Shots) then
1758 SetLength(Shots, find_id + 64);
1759 end;
1761 with Shots[find_id] do
1762 begin
1763 g_Obj_Init(@Obj);
1765 Obj.Rect.Width := SHOT_FLAME_WIDTH;
1766 Obj.Rect.Height := SHOT_FLAME_HEIGHT;
1768 if compat then
1769 dx := IfThen(xd > x, -Obj.Rect.Width, 0)
1770 else
1771 dx := -(Obj.Rect.Width div 2);
1772 dy := -(Obj.Rect.Height div 2);
1774 ShotType := WEAPON_FLAMETHROWER;
1775 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1777 triggers := nil;
1778 Animation.Invalidate;
1779 end;
1781 Shots[find_id].SpawnerUID := SpawnerUID;
1783 // if not Silent then
1784 // g_Sound_PlayExAt('SOUND_WEAPON_FIREPLASMA', x, y);
1785 end;
1787 procedure g_Weapon_ball1(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1788 Silent: Boolean = False; compat: Boolean = true);
1789 var
1790 find_id: DWORD;
1791 dx, dy: Integer;
1792 begin
1793 if WID < 0 then
1794 find_id := FindShot()
1795 else
1796 begin
1797 find_id := WID;
1798 if Integer(find_id) >= High(Shots) then
1799 SetLength(Shots, find_id + 64)
1800 end;
1802 with Shots[find_id] do
1803 begin
1804 g_Obj_Init(@Obj);
1806 Obj.Rect.Width := 16;
1807 Obj.Rect.Height := 16;
1809 if compat then
1810 dx := IfThen(xd > x, -Obj.Rect.Width, 0)
1811 else
1812 dx := -(Obj.Rect.Width div 2);
1813 dy := -(Obj.Rect.Height div 2);
1815 ShotType := WEAPON_IMP_FIRE;
1816 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1818 triggers := nil;
1819 Animation := TAnimState.Create(True, 4, 2); // !!! put values into table
1820 end;
1822 Shots[find_id].SpawnerUID := SpawnerUID;
1824 if not Silent then
1825 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x, y);
1826 end;
1828 procedure g_Weapon_ball2(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1829 Silent: Boolean = False; compat: Boolean = true);
1830 var
1831 find_id: DWORD;
1832 dx, dy: Integer;
1833 begin
1834 if WID < 0 then
1835 find_id := FindShot()
1836 else
1837 begin
1838 find_id := WID;
1839 if Integer(find_id) >= High(Shots) then
1840 SetLength(Shots, find_id + 64)
1841 end;
1843 with Shots[find_id] do
1844 begin
1845 g_Obj_Init(@Obj);
1847 Obj.Rect.Width := 16;
1848 Obj.Rect.Height := 16;
1850 if compat then
1851 dx := IfThen(xd > x, -Obj.Rect.Width, 0)
1852 else
1853 dx := -(Obj.Rect.Width div 2);
1854 dy := -(Obj.Rect.Height div 2);
1856 ShotType := WEAPON_CACO_FIRE;
1857 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1859 triggers := nil;
1860 Animation := TAnimState.Create(True, 4, 2); // !!! put values into table
1861 end;
1863 Shots[find_id].SpawnerUID := SpawnerUID;
1865 if not Silent then
1866 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x, y);
1867 end;
1869 procedure g_Weapon_ball7(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1870 Silent: Boolean = False; compat: Boolean = true);
1871 var
1872 find_id: DWORD;
1873 dx, dy: Integer;
1874 begin
1875 if WID < 0 then
1876 find_id := FindShot()
1877 else
1878 begin
1879 find_id := WID;
1880 if Integer(find_id) >= High(Shots) then
1881 SetLength(Shots, find_id + 64)
1882 end;
1884 with Shots[find_id] do
1885 begin
1886 g_Obj_Init(@Obj);
1888 Obj.Rect.Width := 32;
1889 Obj.Rect.Height := 16;
1891 if compat then
1892 dx := IfThen(xd > x, -Obj.Rect.Width, 0)
1893 else
1894 dx := -(Obj.Rect.Width div 2);
1895 dy := -(Obj.Rect.Height div 2);
1897 ShotType := WEAPON_BARON_FIRE;
1898 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1900 triggers := nil;
1901 Animation := TAnimState.Create(True, 4, 2); // !!! put values into table
1902 end;
1904 Shots[find_id].SpawnerUID := SpawnerUID;
1906 if not Silent then
1907 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x, y);
1908 end;
1910 procedure g_Weapon_aplasma(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1911 Silent: Boolean = False; compat: Boolean = true);
1912 var
1913 find_id: DWORD;
1914 dx, dy: Integer;
1915 begin
1916 if WID < 0 then
1917 find_id := FindShot()
1918 else
1919 begin
1920 find_id := WID;
1921 if Integer(find_id) >= High(Shots) then
1922 SetLength(Shots, find_id + 64)
1923 end;
1925 with Shots[find_id] do
1926 begin
1927 g_Obj_Init(@Obj);
1929 Obj.Rect.Width := 16;
1930 Obj.Rect.Height := 16;
1932 if compat then
1933 dx := IfThen(xd > x, -Obj.Rect.Width, 0)
1934 else
1935 dx := -(Obj.Rect.Width div 2);
1936 dy := -(Obj.Rect.Height div 2);
1938 ShotType := WEAPON_BSP_FIRE;
1939 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1941 triggers := nil;
1943 Animation := TAnimState.Create(True, 4, 2); // !!! put values into table
1944 end;
1946 Shots[find_id].SpawnerUID := SpawnerUID;
1948 if not Silent then
1949 g_Sound_PlayExAt('SOUND_WEAPON_FIREPLASMA', x, y);
1950 end;
1952 procedure g_Weapon_manfire(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1953 Silent: Boolean = False; compat: Boolean = true);
1954 var
1955 find_id: DWORD;
1956 dx, dy: Integer;
1957 begin
1958 if WID < 0 then
1959 find_id := FindShot()
1960 else
1961 begin
1962 find_id := WID;
1963 if Integer(find_id) >= High(Shots) then
1964 SetLength(Shots, find_id + 64)
1965 end;
1967 with Shots[find_id] do
1968 begin
1969 g_Obj_Init(@Obj);
1971 Obj.Rect.Width := 32;
1972 Obj.Rect.Height := 32;
1974 if compat then
1975 dx := IfThen(xd > x, -Obj.Rect.Width, 0)
1976 else
1977 dx := -(Obj.Rect.Width div 2);
1978 dy := -(Obj.Rect.Height div 2);
1980 ShotType := WEAPON_MANCUB_FIRE;
1981 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1983 triggers := nil;
1985 Animation := TAnimState.Create(True, 4, 2); // !!! put values into table
1986 end;
1988 Shots[find_id].SpawnerUID := SpawnerUID;
1990 if not Silent then
1991 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x, y);
1992 end;
1994 procedure g_Weapon_bfgshot(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1995 Silent: Boolean = False; compat: Boolean = true);
1996 var
1997 find_id: DWORD;
1998 dx, dy: Integer;
1999 begin
2000 if WID < 0 then
2001 find_id := FindShot()
2002 else
2003 begin
2004 find_id := WID;
2005 if Integer(find_id) >= High(Shots) then
2006 SetLength(Shots, find_id + 64)
2007 end;
2009 with Shots[find_id] do
2010 begin
2011 g_Obj_Init(@Obj);
2013 Obj.Rect.Width := SHOT_BFG_WIDTH;
2014 Obj.Rect.Height := SHOT_BFG_HEIGHT;
2016 if compat then
2017 dx := IfThen(xd > x, -Obj.Rect.Width, 0)
2018 else
2019 dx := -(Obj.Rect.Width div 2);
2020 dy := -(Obj.Rect.Height div 2);
2022 ShotType := WEAPON_BFG;
2023 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
2025 triggers := nil;
2026 Animation := TAnimState.Create(True, 6, 2); // !!! put values into table
2027 end;
2029 Shots[find_id].SpawnerUID := SpawnerUID;
2031 if not Silent then
2032 g_Sound_PlayExAt('SOUND_WEAPON_FIREBFG', x, y);
2033 end;
2035 procedure g_Weapon_bfghit(x, y: Integer);
2036 begin
2037 {$IFDEF ENABLE_GFX}
2038 g_GFX_QueueEffect(R_GFX_BFG_HIT, x - 32, y - 32);
2039 {$ENDIF}
2040 end;
2042 procedure g_Weapon_pistol(x, y, xd, yd: Integer; SpawnerUID: Word;
2043 Silent: Boolean = False);
2044 begin
2045 if not Silent then
2046 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', x, y);
2048 g_Weapon_gun(x, y, xd, yd, 1, 3, SpawnerUID, True);
2049 if gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF] then
2050 begin
2051 if ABS(x-xd) >= ABS(y-yd) then
2052 begin
2053 g_Weapon_gun(x, y+1, xd, yd+1, 1, 3, SpawnerUID, False);
2054 g_Weapon_gun(x, y-1, xd, yd-1, 1, 2, SpawnerUID, False);
2055 end
2056 else
2057 begin
2058 g_Weapon_gun(x+1, y, xd+1, yd, 1, 3, SpawnerUID, False);
2059 g_Weapon_gun(x-1, y, xd-1, yd, 1, 2, SpawnerUID, False);
2060 end;
2061 end;
2062 end;
2064 procedure g_Weapon_mgun(x, y, xd, yd: Integer; SpawnerUID: Word;
2065 Silent: Boolean = False);
2066 begin
2067 if not Silent then
2068 if gSoundEffectsDF then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', x, y);
2070 g_Weapon_gun(x, y, xd, yd, 1, 3, SpawnerUID, True);
2071 if (gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF]) and
2072 (g_GetUIDType(SpawnerUID) = UID_PLAYER) then
2073 begin
2074 if ABS(x-xd) >= ABS(y-yd) then
2075 begin
2076 g_Weapon_gun(x, y+1, xd, yd+1, 1, 2, SpawnerUID, False);
2077 g_Weapon_gun(x, y-1, xd, yd-1, 1, 2, SpawnerUID, False);
2078 end
2079 else
2080 begin
2081 g_Weapon_gun(x+1, y, xd+1, yd, 1, 2, SpawnerUID, False);
2082 g_Weapon_gun(x-1, y, xd-1, yd, 1, 2, SpawnerUID, False);
2083 end;
2084 end;
2085 end;
2087 procedure g_Weapon_shotgun(x, y, xd, yd: Integer; SpawnerUID: Word;
2088 Silent: Boolean = False);
2089 var
2090 i, j, k: Integer;
2091 begin
2092 if not Silent then
2093 if gSoundEffectsDF then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', x, y);
2095 for i := 0 to 9 do
2096 begin
2097 j := 0; k := 0;
2098 if ABS(x-xd) >= ABS(y-yd) then j := Random(17) - 8 else k := Random(17) - 8; // -8 .. 8
2099 g_Weapon_gun(x+k, y+j, xd+k, yd+j, IfThen(i mod 2 <> 0, 1, 0), 3, SpawnerUID, i=0);
2100 end;
2101 end;
2103 procedure g_Weapon_dshotgun(x, y, xd, yd: Integer; SpawnerUID: Word;
2104 Silent: Boolean = False);
2105 var
2106 a, i, j, k: Integer;
2107 begin
2108 if not Silent then
2109 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', x, y);
2111 if gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF] then a := 25 else a := 20;
2112 for i := 0 to a do
2113 begin
2114 j := 0; k := 0;
2115 if ABS(x-xd) >= ABS(y-yd) then j := Random(41) - 20 else k := Random(41) - 20; // -20 .. 20
2116 g_Weapon_gun(x+k, y+j, xd+k, yd+j, IfThen(i mod 3 <> 0, 0, 1), 3, SpawnerUID, i=0);
2117 end;
2118 end;
2120 procedure g_Weapon_PreUpdate();
2121 var
2122 i: Integer;
2123 begin
2124 if Shots = nil then Exit;
2125 for i := 0 to High(Shots) do
2126 if Shots[i].ShotType <> 0 then
2127 begin
2128 Shots[i].Obj.oldX := Shots[i].Obj.X;
2129 Shots[i].Obj.oldY := Shots[i].Obj.Y;
2130 end;
2131 end;
2133 procedure g_Weapon_Update();
2134 var
2135 i, a, h, cx, cy, oldvx, oldvy, tf: Integer;
2136 t: DWArray;
2137 st: Word;
2138 o: TObj;
2139 spl: Boolean;
2140 Loud: Boolean;
2141 {$IFDEF ENABLE_GFX}
2142 var tcx, tcy: Integer;
2143 {$ENDIF}
2144 begin
2145 if Shots = nil then
2146 Exit;
2148 for i := 0 to High(Shots) do
2149 begin
2150 if Shots[i].ShotType = 0 then
2151 Continue;
2153 Loud := True;
2155 with Shots[i] do
2156 begin
2157 Timeout := Timeout - 1;
2158 oldvx := Obj.Vel.X;
2159 oldvy := Obj.Vel.Y;
2160 // Àêòèâèðîâàòü òðèããåðû ïî ïóòè (êðîìå óæå àêòèâèðîâàííûõ):
2161 if (Stopped = 0) and g_Game_IsServer then
2162 t := g_Triggers_PressR(Obj.X, Obj.Y, Obj.Rect.Width, Obj.Rect.Height,
2163 SpawnerUID, ACTIVATE_SHOT, triggers)
2164 else
2165 t := nil;
2167 if t <> nil then
2168 begin
2169 // Ïîïîëíÿåì ñïèñîê àêòèâèðîâàííûõ òðèããåðîâ:
2170 if triggers = nil then
2171 triggers := t
2172 else
2173 begin
2174 h := High(t);
2176 for a := 0 to h do
2177 if not InDWArray(t[a], triggers) then
2178 begin
2179 SetLength(triggers, Length(triggers)+1);
2180 triggers[High(triggers)] := t[a];
2181 end;
2182 end;
2183 end;
2185 // Àíèìàöèÿ ñíàðÿäà:
2186 if Animation.IsValid() then
2187 Animation.Update();
2189 // Äâèæåíèå:
2190 spl := (ShotType <> WEAPON_PLASMA) and
2191 (ShotType <> WEAPON_BFG) and
2192 (ShotType <> WEAPON_BSP_FIRE) and
2193 (ShotType <> WEAPON_FLAMETHROWER);
2195 if Stopped = 0 then
2196 begin
2197 st := g_Obj_Move_Projectile(@Obj, False, spl);
2198 end
2199 else
2200 begin
2201 st := 0;
2202 end;
2203 positionChanged(); // this updates spatial accelerators
2205 if WordBool(st and MOVE_FALLOUT) or (Obj.X < -1000) or
2206 (Obj.X > gMapInfo.Width+1000) or (Obj.Y < -1000) then
2207 begin
2208 // Íà êëèåíòå ñêîðåå âñåãî è òàê óæå âûïàë.
2209 ShotType := 0;
2210 Animation.Invalidate();
2211 Continue;
2212 end;
2214 cx := Obj.X + (Obj.Rect.Width div 2);
2215 cy := Obj.Y + (Obj.Rect.Height div 2);
2217 case ShotType of
2218 WEAPON_ROCKETLAUNCHER, WEAPON_SKEL_FIRE: // Ðàêåòû è ñíàðÿäû Ñêåëåòà
2219 begin
2220 // Âûëåòåëà èç âîäû:
2221 if WordBool(st and MOVE_HITAIR) then
2222 g_Obj_SetSpeed(@Obj, 12);
2224 // Â âîäå øëåéô - ïóçûðè, â âîçäóõå øëåéô - äûì:
2225 if WordBool(st and MOVE_INWATER) then
2226 begin
2227 {$IFDEF ENABLE_GFX}
2228 g_GFX_Bubbles(cx, cy, 1+Random(3), 16, 16);
2229 {$ENDIF}
2230 if Random(2) = 0
2231 then g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', cx, cy)
2232 else g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', cx, cy);
2233 end
2234 else
2235 begin
2236 {$IFDEF ENABLE_GFX}
2237 g_GFX_QueueEffect(R_GFX_SMOKE_TRANS, Obj.X-14+Random(9), cy-20+Random(9));
2238 {$ENDIF}
2239 end;
2241 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2242 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL)) or
2243 (g_Weapon_Hit(@Obj, 10, SpawnerUID, HIT_SOME, False) <> 0) or
2244 (Timeout < 1) then
2245 begin
2246 Obj.Vel.X := 0;
2247 Obj.Vel.Y := 0;
2249 g_Weapon_Explode(cx, cy, 60, SpawnerUID);
2251 if ShotType = WEAPON_SKEL_FIRE then
2252 begin // Âçðûâ ñíàðÿäà Ñêåëåòà
2253 {$IFDEF ENABLE_GFX}
2254 g_GFX_QueueEffect(R_GFX_EXPLODE_SKELFIRE, Obj.X + 32 - 58, Obj.Y + 8 - 36);
2255 g_DynLightExplosion((Obj.X+32), (Obj.Y+8), 64, 1, 0, 0);
2256 {$ENDIF}
2257 end
2258 else
2259 begin // Âçðûâ Ðàêåòû
2260 {$IFDEF ENABLE_GFX}
2261 g_GFX_QueueEffect(R_GFX_EXPLODE_ROCKET, cx - 64, cy - 64);
2262 g_DynLightExplosion(cx, cy, 64, 1, 0, 0);
2263 {$ENDIF}
2264 end;
2266 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', Obj.X, Obj.Y);
2268 ShotType := 0;
2269 end;
2271 if ShotType = WEAPON_SKEL_FIRE then
2272 begin // Ñàìîíàâîäêà ñíàðÿäà Ñêåëåòà:
2273 if GetPos(target, @o) then
2274 throw(i, Obj.X, Obj.Y,
2275 o.X+o.Rect.X+(o.Rect.Width div 2)+o.Vel.X+o.Accel.X,
2276 o.Y+o.Rect.Y+(o.Rect.Height div 2)+o.Vel.Y+o.Accel.Y,
2277 12);
2278 end;
2279 end;
2281 WEAPON_PLASMA, WEAPON_BSP_FIRE: // Ïëàçìà, ïëàçìà Àðàõíàòðîíà
2282 begin
2283 // Ïîïàëà â âîäó - ýëåêòðîøîê ïî âîäå:
2284 if WordBool(st and (MOVE_INWATER or MOVE_HITWATER)) then
2285 begin
2286 g_Sound_PlayExAt('SOUND_WEAPON_PLASMAWATER', Obj.X, Obj.Y);
2287 if g_Game_IsServer then CheckTrap(i, 10, HIT_ELECTRO);
2288 ShotType := 0;
2289 Continue;
2290 end;
2292 // Âåëè÷èíà óðîíà:
2293 if (ShotType = WEAPON_PLASMA) and
2294 (gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF]) then
2295 a := 10
2296 else
2297 a := 5;
2299 if ShotType = WEAPON_BSP_FIRE then
2300 a := 10;
2302 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2303 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL)) or
2304 (g_Weapon_Hit(@Obj, a, SpawnerUID, HIT_SOME, False) <> 0) or
2305 (Timeout < 1) then
2306 begin
2307 {$IFDEF ENABLE_GFX}
2308 if ShotType = WEAPON_PLASMA then
2309 g_GFX_QueueEffect(R_GFX_EXPLODE_PLASMA, cx - 16, cy - 16)
2310 else
2311 g_GFX_QueueEffect(R_GFX_EXPLODE_BSPFIRE, cx - 16, cy - 16);
2312 g_DynLightExplosion(cx, cy, 32, 0, 0.5, 0.5);
2313 {$ENDIF}
2314 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEPLASMA', Obj.X, Obj.Y);
2315 ShotType := 0;
2316 end;
2317 end;
2319 WEAPON_FLAMETHROWER: // Îãíåìåò
2320 begin
2321 // Ñî âðåìåíåì óìèðàåò
2322 if (Timeout < 1) then
2323 begin
2324 ShotType := 0;
2325 Continue;
2326 end;
2327 // Ïîä âîäîé òîæå
2328 if WordBool(st and (MOVE_HITWATER or MOVE_INWATER)) then
2329 begin
2330 if WordBool(st and MOVE_HITWATER) then
2331 begin
2332 {$IFDEF ENABLE_GFX}
2333 tcx := Random(8);
2334 tcy := Random(8);
2335 g_GFX_QueueEffect(R_GFX_SMOKE, cx-4+tcx-(R_GFX_SMOKE_WIDTH div 2), cy-4+tcy-(R_GFX_SMOKE_HEIGHT div 2));
2336 {$ENDIF}
2337 end
2338 else
2339 begin
2340 {$IFDEF ENABLE_GFX}
2341 g_GFX_Bubbles(cx, cy, 1+Random(3), 16, 16);
2342 {$ENDIF}
2343 if Random(2) = 0
2344 then g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', cx, cy)
2345 else g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', cx, cy);
2346 end;
2347 ShotType := 0;
2348 Continue;
2349 end;
2351 // Ãðàâèòàöèÿ
2352 if Stopped = 0 then
2353 Obj.Accel.Y := Obj.Accel.Y + 1;
2354 // Ïîïàëè â ñòåíó èëè â âîäó:
2355 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL or MOVE_HITWATER)) then
2356 begin
2357 // Ïðèëèïàåì:
2358 Obj.Vel.X := 0;
2359 Obj.Vel.Y := 0;
2360 Obj.Accel.Y := 0;
2361 if WordBool(st and MOVE_HITWALL) then
2362 Stopped := MOVE_HITWALL
2363 else if WordBool(st and MOVE_HITLAND) then
2364 Stopped := MOVE_HITLAND
2365 else if WordBool(st and MOVE_HITCEIL) then
2366 Stopped := MOVE_HITCEIL;
2367 end;
2369 a := IfThen(Stopped = 0, 10, 1);
2370 // Åñëè â êîãî-òî ïîïàëè
2371 if g_Weapon_Hit(@Obj, a, SpawnerUID, HIT_FLAME, False) <> 0 then
2372 begin
2373 // HIT_FLAME ñàì ïîäîææåò
2374 // Åñëè â ïîëåòå ïîïàëè, èñ÷åçàåì
2375 if Stopped = 0 then
2376 ShotType := 0;
2377 end;
2379 if Stopped = 0 then
2380 tf := 2
2381 else
2382 tf := 3;
2384 if (gTime mod LongWord(tf) = 0) then
2385 begin
2386 {$IFDEF ENABLE_GFX}
2387 case Stopped of
2388 MOVE_HITWALL: begin tcx := cx-4+Random(8); tcy := cy-12+Random(24); end;
2389 MOVE_HITLAND: begin tcx := cx-12+Random(24); tcy := cy-10+Random(8); end;
2390 MOVE_HITCEIL: begin tcx := cx-12+Random(24); tcy := cy+6+Random(8); end;
2391 else begin tcx := cx-4+Random(8); tcy := cy-4+Random(8); end;
2392 end;
2393 g_GFX_QueueEffect(R_GFX_FLAME_RAND, tcx - (R_GFX_FLAME_WIDTH div 2), tcy - (R_GFX_FLAME_HEIGHT div 2));
2394 //g_DynLightExplosion(tcx, tcy, 1, 1, 0.8, 0.3);
2395 {$ENDIF}
2396 end;
2397 end;
2399 WEAPON_BFG: // BFG
2400 begin
2401 // Ïîïàëà â âîäó - ýëåêòðîøîê ïî âîäå:
2402 if WordBool(st and (MOVE_INWATER or MOVE_HITWATER)) then
2403 begin
2404 g_Sound_PlayExAt('SOUND_WEAPON_BFGWATER', Obj.X, Obj.Y);
2405 if g_Game_IsServer then CheckTrap(i, 1000, HIT_ELECTRO);
2406 ShotType := 0;
2407 Continue;
2408 end;
2410 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2411 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL)) or
2412 (g_Weapon_Hit(@Obj, SHOT_BFG_DAMAGE, SpawnerUID, HIT_BFG, False) <> 0) or
2413 (Timeout < 1) then
2414 begin
2415 // Ëó÷è BFG:
2416 if g_Game_IsServer then g_Weapon_BFG9000(cx, cy, SpawnerUID);
2417 {$IFDEF ENABLE_GFX}
2418 g_GFX_QueueEffect(R_GFX_EXPLODE_BFG, cx - 64, cy - 64);
2419 g_DynLightExplosion(cx, cy, 96, 0, 1, 0);
2420 {$ENDIF}
2421 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', Obj.X, Obj.Y);
2422 ShotType := 0;
2423 end;
2424 end;
2426 WEAPON_IMP_FIRE, WEAPON_CACO_FIRE, WEAPON_BARON_FIRE: // Âûñòðåëû Áåñà, Êàêîäåìîíà Ðûöàðÿ/Áàðîíà àäà
2427 begin
2428 // Âûëåòåë èç âîäû:
2429 if WordBool(st and MOVE_HITAIR) then
2430 g_Obj_SetSpeed(@Obj, 16);
2432 // Âåëè÷èíà óðîíà:
2433 if ShotType = WEAPON_IMP_FIRE then
2434 a := 5
2435 else
2436 if ShotType = WEAPON_CACO_FIRE then
2437 a := 20
2438 else
2439 a := 40;
2441 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2442 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL)) or
2443 (g_Weapon_Hit(@Obj, a, SpawnerUID, HIT_SOME) <> 0) or
2444 (Timeout < 1) then
2445 begin
2446 {$IFDEF ENABLE_GFX}
2447 case ShotType of
2448 WEAPON_IMP_FIRE: g_GFX_QueueEffect(R_GFX_EXPLODE_IMPFIRE, cx - 32, cy - 32);
2449 WEAPON_CACO_FIRE: g_GFX_QueueEffect(R_GFX_EXPLODE_CACOFIRE, cx - 32, cy - 32);
2450 WEAPON_BARON_FIRE: g_GFX_QueueEffect(R_GFX_EXPLODE_BARONFIRE, cx - 32, cy - 32);
2451 end;
2452 {$ENDIF}
2453 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj.X, Obj.Y);
2454 ShotType := 0;
2455 end;
2456 end;
2458 WEAPON_MANCUB_FIRE: // Âûñòðåë Ìàíêóáóñà
2459 begin
2460 // Âûëåòåë èç âîäû:
2461 if WordBool(st and MOVE_HITAIR) then
2462 g_Obj_SetSpeed(@Obj, 16);
2464 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2465 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL)) or
2466 (g_Weapon_Hit(@Obj, 40, SpawnerUID, HIT_SOME, False) <> 0) or
2467 (Timeout < 1) then
2468 begin
2469 // Âçðûâ:
2470 {$IFDEF ENABLE_GFX}
2471 g_GFX_QueueEffect(R_GFX_EXPLODE_ROCKET, cx - 64, cy - 64);
2472 {$ENDIF}
2473 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj.X, Obj.Y);
2474 ShotType := 0;
2475 end;
2476 end;
2477 end; // case ShotType of...
2479 // Åñëè ñíàðÿäà óæå íåò, óäàëÿåì àíèìàöèþ:
2480 if (ShotType = 0) then
2481 begin
2482 if gGameSettings.GameType = GT_SERVER then
2483 MH_SEND_DeleteShot(i, Obj.X, Obj.Y, Loud);
2484 Animation.Invalidate;
2485 end
2486 else if (ShotType <> WEAPON_FLAMETHROWER) and ((oldvx <> Obj.Vel.X) or (oldvy <> Obj.Vel.Y)) then
2487 if gGameSettings.GameType = GT_SERVER then
2488 MH_SEND_UpdateShot(i);
2489 end;
2490 end;
2491 end;
2493 function g_Weapon_Danger(UID: Word; X, Y: Integer; Width, Height: Word; Time: Byte): Boolean;
2494 var
2495 a: Integer;
2496 begin
2497 Result := False;
2499 if Shots = nil then
2500 Exit;
2502 for a := 0 to High(Shots) do
2503 if (Shots[a].ShotType <> 0) and (Shots[a].SpawnerUID <> UID) then
2504 if ((Shots[a].Obj.Vel.Y = 0) and (Shots[a].Obj.Vel.X > 0) and (Shots[a].Obj.X < X)) or
2505 (Shots[a].Obj.Vel.Y = 0) and (Shots[a].Obj.Vel.X < 0) and (Shots[a].Obj.X > X) then
2506 if (Abs(X-Shots[a].Obj.X) < Abs(Shots[a].Obj.Vel.X*Time)) and
2507 g_Collide(X, Y, Width, Height, X, Shots[a].Obj.Y,
2508 Shots[a].Obj.Rect.Width, Shots[a].Obj.Rect.Height) and
2509 g_TraceVector(X, Y, Shots[a].Obj.X, Shots[a].Obj.Y) then
2510 begin
2511 Result := True;
2512 Exit;
2513 end;
2514 end;
2516 procedure g_Weapon_SaveState (st: TStream);
2517 var
2518 count, i, j: Integer;
2519 begin
2520 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ ñíàðÿäîâ
2521 count := 0;
2522 for i := 0 to High(Shots) do if (Shots[i].ShotType <> 0) then Inc(count);
2524 // Êîëè÷åñòâî ñíàðÿäîâ
2525 utils.WriteInt(st, count);
2527 if (count = 0) then exit;
2529 for i := 0 to High(Shots) do
2530 begin
2531 if Shots[i].ShotType <> 0 then
2532 begin
2533 // Ñèãíàòóðà ñíàðÿäà
2534 utils.writeSign(st, 'SHOT');
2535 utils.writeInt(st, Byte(0)); // version
2536 // Òèï ñíàðÿäà
2537 utils.writeInt(st, Byte(Shots[i].ShotType));
2538 // Öåëü
2539 utils.writeInt(st, Word(Shots[i].Target));
2540 // UID ñòðåëÿâøåãî
2541 utils.writeInt(st, Word(Shots[i].SpawnerUID));
2542 // Ðàçìåð ïîëÿ Triggers
2543 utils.writeInt(st, Integer(Length(Shots[i].Triggers)));
2544 // Òðèããåðû, àêòèâèðîâàííûå âûñòðåëîì
2545 for j := 0 to Length(Shots[i].Triggers)-1 do utils.writeInt(st, LongWord(Shots[i].Triggers[j]));
2546 // Îáúåêò ñíàðÿäà
2547 Obj_SaveState(st, @Shots[i].Obj);
2548 // Êîñòûëèíà åáàíàÿ
2549 utils.writeInt(st, Byte(Shots[i].Stopped));
2550 end;
2551 end;
2552 end;
2554 procedure g_Weapon_LoadState (st: TStream);
2555 var
2556 count, tc, i, j: Integer;
2557 begin
2558 if (st = nil) then exit;
2560 // Êîëè÷åñòâî ñíàðÿäîâ
2561 count := utils.readLongInt(st);
2562 if (count < 0) or (count > 1024*1024) then raise XStreamError.Create('invalid shots counter');
2564 SetLength(Shots, count);
2566 if (count = 0) then exit;
2568 for i := 0 to count-1 do
2569 begin
2570 // Ñèãíàòóðà ñíàðÿäà
2571 if not utils.checkSign(st, 'SHOT') then raise XStreamError.Create('invalid shot signature');
2572 if (utils.readByte(st) <> 0) then raise XStreamError.Create('invalid shot version');
2573 // Òèï ñíàðÿäà:
2574 Shots[i].ShotType := utils.readByte(st);
2575 // Öåëü
2576 Shots[i].Target := utils.readWord(st);
2577 // UID ñòðåëÿâøåãî
2578 Shots[i].SpawnerUID := utils.readWord(st);
2579 // Ðàçìåð ïîëÿ Triggers
2580 tc := utils.readLongInt(st);
2581 if (tc < 0) or (tc > 1024*1024) then raise XStreamError.Create('invalid shot triggers counter');
2582 SetLength(Shots[i].Triggers, tc);
2583 // Òðèããåðû, àêòèâèðîâàííûå âûñòðåëîì
2584 for j := 0 to tc-1 do Shots[i].Triggers[j] := utils.readLongWord(st);
2585 // Îáúåêò ïðåäìåòà
2586 Obj_LoadState(@Shots[i].Obj, st);
2587 // Êîñòûëèíà åáàíàÿ
2588 Shots[i].Stopped := utils.readByte(st);
2590 // Óñòàíîâêà òåêñòóðû èëè àíèìàöèè
2591 Shots[i].Animation.Invalidate;
2593 case Shots[i].ShotType of
2594 WEAPON_ROCKETLAUNCHER, WEAPON_SKEL_FIRE:
2595 begin
2596 end;
2597 WEAPON_PLASMA:
2598 begin
2599 Shots[i].Animation := TAnimState.Create(True, 5, 2); // !!! put values into table
2600 end;
2601 WEAPON_BFG:
2602 begin
2603 Shots[i].Animation := TAnimState.Create(True, 6, 2); // !!! put values into table
2604 end;
2605 WEAPON_IMP_FIRE:
2606 begin
2607 Shots[i].Animation := TAnimState.Create(True, 4, 2); // !!! put values into table
2608 end;
2609 WEAPON_BSP_FIRE:
2610 begin
2611 Shots[i].Animation := TAnimState.Create(True, 4, 2); // !!! put values into table
2612 end;
2613 WEAPON_CACO_FIRE:
2614 begin
2615 Shots[i].Animation := TAnimState.Create(True, 4, 2); // !!! put values into table
2616 end;
2617 WEAPON_BARON_FIRE:
2618 begin
2619 Shots[i].Animation := TAnimState.Create(True, 4, 2); // !!! put values into table
2620 end;
2621 WEAPON_MANCUB_FIRE:
2622 begin
2623 Shots[i].Animation := TAnimState.Create(True, 4, 2); // !!! put values into table
2624 end;
2625 end;
2626 end;
2627 end;
2629 procedure g_Weapon_DestroyShot(I: Integer; X, Y: Integer; Loud: Boolean = True);
2630 {$IFDEF ENABLE_GFX}
2631 var cx, cy: Integer;
2632 {$ENDIF}
2633 begin
2634 if Shots = nil then
2635 Exit;
2636 if (I > High(Shots)) or (I < 0) then Exit;
2638 with Shots[I] do
2639 begin
2640 if ShotType = 0 then Exit;
2641 Obj.X := X;
2642 Obj.Y := Y;
2643 {$IFDEF ENABLE_GFX}
2644 cx := Obj.X + (Obj.Rect.Width div 2);
2645 cy := Obj.Y + (Obj.Rect.Height div 2);
2646 {$ENDIF}
2648 case ShotType of
2649 WEAPON_ROCKETLAUNCHER, WEAPON_SKEL_FIRE: // Ðàêåòû è ñíàðÿäû Ñêåëåòà
2650 begin
2651 if Loud then
2652 begin
2653 {$IFDEF ENABLE_GFX}
2654 if ShotType = WEAPON_SKEL_FIRE then
2655 g_GFX_QueueEffect(R_GFX_EXPLODE_SKELFIRE, (Obj.X + 32) - 32, (Obj.Y + 8) - 32)
2656 else
2657 g_GFX_QueueEffect(R_GFX_EXPLODE_ROCKET, cx - 64, cy - 64);
2658 {$ENDIF}
2659 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', Obj.X, Obj.Y);
2660 end;
2661 end;
2663 WEAPON_PLASMA, WEAPON_BSP_FIRE: // Ïëàçìà, ïëàçìà Àðàõíàòðîíà
2664 begin
2665 if loud then
2666 begin
2667 {$IFDEF ENABLE_GFX}
2668 if ShotType = WEAPON_PLASMA then
2669 g_GFX_QueueEffect(R_GFX_EXPLODE_PLASMA, cx - 16, cy - 16)
2670 else
2671 g_GFX_QueueEffect(R_GFX_EXPLODE_BSPFIRE, cx - 16, cy - 16);
2672 {$ENDIF}
2673 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEPLASMA', Obj.X, Obj.Y);
2674 end;
2675 end;
2677 WEAPON_BFG: // BFG
2678 begin
2679 {$IFDEF ENABLE_GFX}
2680 g_GFX_QueueEffect(R_GFX_EXPLODE_BFG, cx - 64, cy - 64);
2681 {$ENDIF}
2682 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', Obj.X, Obj.Y);
2683 end;
2685 WEAPON_IMP_FIRE, WEAPON_CACO_FIRE, WEAPON_BARON_FIRE: // Âûñòðåëû Áåñà, Êàêîäåìîíà Ðûöàðÿ/Áàðîíà àäà
2686 begin
2687 if loud then
2688 begin
2689 {$IFDEF ENABLE_GFX}
2690 case ShotType of
2691 WEAPON_IMP_FIRE: g_GFX_QueueEffect(R_GFX_EXPLODE_IMPFIRE, cx - 32, cy - 32);
2692 WEAPON_CACO_FIRE: g_GFX_QueueEffect(R_GFX_EXPLODE_CACOFIRE, cx - 32, cy - 32);
2693 WEAPON_BARON_FIRE: g_GFX_QueueEffect(R_GFX_EXPLODE_BARONFIRE, cx - 32, cy - 32);
2694 end;
2695 {$ENDIF}
2696 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj.X, Obj.Y);
2697 end;
2698 end;
2700 WEAPON_MANCUB_FIRE: // Âûñòðåë Ìàíêóáóñà
2701 begin
2702 {$IFDEF ENABLE_GFX}
2703 g_GFX_QueueEffect(R_GFX_EXPLODE_ROCKET, cx - 64, cy - 64);
2704 {$ENDIF}
2705 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj.X, Obj.Y);
2706 end;
2707 end; // case ShotType of...
2709 ShotType := 0;
2710 Animation.Invalidate;
2711 end;
2712 end;
2715 procedure g_Weapon_AddDynLights();
2716 var
2717 i: Integer;
2718 begin
2719 if Shots = nil then Exit;
2720 for i := 0 to High(Shots) do
2721 begin
2722 if Shots[i].ShotType = 0 then continue;
2723 if (Shots[i].ShotType = WEAPON_ROCKETLAUNCHER) or
2724 (Shots[i].ShotType = WEAPON_BARON_FIRE) or
2725 (Shots[i].ShotType = WEAPON_MANCUB_FIRE) or
2726 (Shots[i].ShotType = WEAPON_SKEL_FIRE) or
2727 (Shots[i].ShotType = WEAPON_IMP_FIRE) or
2728 (Shots[i].ShotType = WEAPON_CACO_FIRE) or
2729 (Shots[i].ShotType = WEAPON_MANCUB_FIRE) or
2730 (Shots[i].ShotType = WEAPON_BSP_FIRE) or
2731 (Shots[i].ShotType = WEAPON_PLASMA) or
2732 (Shots[i].ShotType = WEAPON_BFG) or
2733 (Shots[i].ShotType = WEAPON_FLAMETHROWER) or
2734 false then
2735 begin
2736 if (Shots[i].ShotType = WEAPON_PLASMA) then
2737 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)
2738 else if (Shots[i].ShotType = WEAPON_BFG) then
2739 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)
2740 else if (Shots[i].ShotType = WEAPON_FLAMETHROWER) then
2741 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)
2742 else
2743 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);
2744 end;
2745 end;
2746 end;
2749 procedure TShot.positionChanged (); begin end;
2752 end.