DEADSOFTWARE

game: remove unneded render imports
[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: TAnimationState;
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);
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);
59 procedure g_Weapon_plasma(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1; Silent: Boolean = False);
60 procedure g_Weapon_ball1(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1; Silent: Boolean = False);
61 procedure g_Weapon_ball2(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1; Silent: Boolean = False);
62 procedure g_Weapon_ball7(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1; Silent: Boolean = False);
63 procedure g_Weapon_aplasma(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1; Silent: Boolean = False);
64 procedure g_Weapon_manfire(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1; Silent: Boolean = False);
65 procedure g_Weapon_bfgshot(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1; Silent: Boolean = False);
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 Math, g_map, g_player, g_gfx, g_sound, g_panel,
115 g_console, g_options, g_game, r_gfx,
116 g_triggers, MAPDEF, e_log, g_monsters, g_saveload,
117 g_language, g_netmsg, g_grid,
118 geom, binheap, hashtable, utils, xstreams;
120 type
121 TWaterPanel = record
122 X, Y: Integer;
123 Width, Height: Word;
124 Active: Boolean;
125 end;
127 const
128 SHOT_ROCKETLAUNCHER_WIDTH = 14;
129 SHOT_ROCKETLAUNCHER_HEIGHT = 14;
131 SHOT_SKELFIRE_WIDTH = 14;
132 SHOT_SKELFIRE_HEIGHT = 14;
134 SHOT_PLASMA_WIDTH = 16;
135 SHOT_PLASMA_HEIGHT = 16;
137 SHOT_BFG_WIDTH = 32;
138 SHOT_BFG_HEIGHT = 32;
139 SHOT_BFG_DAMAGE = 100;
140 SHOT_BFG_RADIUS = 256;
142 SHOT_FLAME_WIDTH = 4;
143 SHOT_FLAME_HEIGHT = 4;
144 SHOT_FLAME_LIFETIME = 180;
146 SHOT_SIGNATURE = $544F4853; // 'SHOT'
148 type
149 PHitTime = ^THitTime;
150 THitTime = record
151 distSq: Integer;
152 mon: TMonster;
153 plridx: Integer; // if mon=nil
154 x, y: Integer;
155 end;
157 TBinHeapKeyHitTime = class
158 public
159 class function less (const a, b: Integer): Boolean; inline;
160 end;
162 // indicies in `wgunHitTime` array
163 TBinaryHeapHitTimes = specialize TBinaryHeapBase<Integer, TBinHeapKeyHitTime>;
165 var
166 WaterMap: array of array of DWORD = nil;
167 //wgunMonHash: THashIntInt = nil;
168 wgunHitHeap: TBinaryHeapHitTimes = nil;
169 wgunHitTime: array of THitTime = nil;
170 wgunHitTimeUsed: Integer = 0;
173 class function TBinHeapKeyHitTime.less (const a, b: Integer): Boolean;
174 var
175 hta, htb: PHitTime;
176 begin
177 hta := @wgunHitTime[a];
178 htb := @wgunHitTime[b];
179 if (hta.distSq <> htb.distSq) then begin result := (hta.distSq < htb.distSq); exit; end;
180 if (hta.mon <> nil) then
181 begin
182 // a is monster
183 if (htb.mon = nil) then begin result := false; exit; end; // players first
184 result := (hta.mon.UID < htb.mon.UID); // why not?
185 end
186 else
187 begin
188 // a is player
189 if (htb.mon <> nil) then begin result := true; exit; end; // players first
190 result := (hta.plridx < htb.plridx); // why not?
191 end;
192 end;
195 procedure appendHitTimeMon (adistSq: Integer; amon: TMonster; ax, ay: Integer);
196 begin
197 if (wgunHitTimeUsed = Length(wgunHitTime)) then SetLength(wgunHitTime, wgunHitTimeUsed+128);
198 with wgunHitTime[wgunHitTimeUsed] do
199 begin
200 distSq := adistSq;
201 mon := amon;
202 plridx := -1;
203 x := ax;
204 y := ay;
205 end;
206 wgunHitHeap.insert(wgunHitTimeUsed);
207 Inc(wgunHitTimeUsed);
208 end;
211 procedure appendHitTimePlr (adistSq: Integer; aplridx: Integer; ax, ay: Integer);
212 begin
213 if (wgunHitTimeUsed = Length(wgunHitTime)) then SetLength(wgunHitTime, wgunHitTimeUsed+128);
214 with wgunHitTime[wgunHitTimeUsed] do
215 begin
216 distSq := adistSq;
217 mon := nil;
218 plridx := aplridx;
219 x := ax;
220 y := ay;
221 end;
222 wgunHitHeap.insert(wgunHitTimeUsed);
223 Inc(wgunHitTimeUsed);
224 end;
227 function FindShot(): DWORD;
228 var
229 i: Integer;
230 begin
231 if Shots <> nil then
232 for i := 0 to High(Shots) do
233 if Shots[i].ShotType = 0 then
234 begin
235 Result := i;
236 LastShotID := Result;
237 Exit;
238 end;
240 if Shots = nil then
241 begin
242 SetLength(Shots, 128);
243 Result := 0;
244 end
245 else
246 begin
247 Result := High(Shots) + 1;
248 SetLength(Shots, Length(Shots) + 128);
249 end;
250 LastShotID := Result;
251 end;
253 procedure CreateWaterMap();
254 var
255 WaterArray: Array of TWaterPanel;
256 a, b, c, m: Integer;
257 ok: Boolean;
258 begin
259 if gWater = nil then
260 Exit;
262 SetLength(WaterArray, Length(gWater));
264 for a := 0 to High(gWater) do
265 begin
266 WaterArray[a].X := gWater[a].X;
267 WaterArray[a].Y := gWater[a].Y;
268 WaterArray[a].Width := gWater[a].Width;
269 WaterArray[a].Height := gWater[a].Height;
270 WaterArray[a].Active := True;
271 end;
273 g_Game_SetLoadingText(_lc[I_LOAD_WATER_MAP], High(WaterArray), False);
275 for a := 0 to High(WaterArray) do
276 if WaterArray[a].Active then
277 begin
278 WaterArray[a].Active := False;
279 m := Length(WaterMap);
280 SetLength(WaterMap, m+1);
281 SetLength(WaterMap[m], 1);
282 WaterMap[m][0] := a;
283 ok := True;
285 while ok do
286 begin
287 ok := False;
288 for b := 0 to High(WaterArray) do
289 if WaterArray[b].Active then
290 for c := 0 to High(WaterMap[m]) do
291 if g_CollideAround(WaterArray[b].X,
292 WaterArray[b].Y,
293 WaterArray[b].Width,
294 WaterArray[b].Height,
295 WaterArray[WaterMap[m][c]].X,
296 WaterArray[WaterMap[m][c]].Y,
297 WaterArray[WaterMap[m][c]].Width,
298 WaterArray[WaterMap[m][c]].Height) then
299 begin
300 WaterArray[b].Active := False;
301 SetLength(WaterMap[m],
302 Length(WaterMap[m])+1);
303 WaterMap[m][High(WaterMap[m])] := b;
304 ok := True;
305 Break;
306 end;
307 end;
309 g_Game_StepLoading();
310 end;
312 WaterArray := nil;
313 end;
316 var
317 chkTrap_pl: array [0..256] of Integer;
318 chkTrap_mn: array [0..65535] of TMonster;
320 procedure CheckTrap(ID: DWORD; dm: Integer; t: Byte);
321 var
322 //a, b, c, d, i1, i2: Integer;
323 //chkTrap_pl, chkTrap_mn: WArray;
324 plaCount: Integer = 0;
325 mnaCount: Integer = 0;
326 frameId: DWord;
329 function monsWaterCheck (mon: TMonster): Boolean;
330 begin
331 result := false; // don't stop
332 if mon.alive and mon.Collide(gWater[WaterMap[a][c]]) and (not InWArray(monidx, chkTrap_mn)) and (i2 < 1023) then //FIXME
333 begin
334 i2 += 1;
335 chkTrap_mn[i2] := monidx;
336 end;
337 end;
340 function monsWaterCheck (mon: TMonster): Boolean;
341 begin
342 result := false; // don't stop
343 if (mon.trapCheckFrameId <> frameId) then
344 begin
345 mon.trapCheckFrameId := frameId;
346 chkTrap_mn[mnaCount] := mon;
347 Inc(mnaCount);
348 end;
349 end;
351 var
352 a, b, c, d, f: Integer;
353 pan: TPanel;
354 begin
355 if (gWater = nil) or (WaterMap = nil) then Exit;
357 frameId := g_Mons_getNewTrapFrameId();
359 //i1 := -1;
360 //i2 := -1;
362 //SetLength(chkTrap_pl, 1024);
363 //SetLength(chkTrap_mn, 1024);
364 //for d := 0 to 1023 do chkTrap_pl[d] := $FFFF;
365 //for d := 0 to 1023 do chkTrap_mn[d] := $FFFF;
367 for a := 0 to High(WaterMap) do
368 begin
369 for b := 0 to High(WaterMap[a]) do
370 begin
371 pan := gWater[WaterMap[a][b]];
372 if not g_Obj_Collide(pan.X, pan.Y, pan.Width, pan.Height, @Shots[ID].Obj) then continue;
374 for c := 0 to High(WaterMap[a]) do
375 begin
376 pan := gWater[WaterMap[a][c]];
377 for d := 0 to High(gPlayers) do
378 begin
379 if (gPlayers[d] <> nil) and (gPlayers[d].alive) then
380 begin
381 if gPlayers[d].Collide(pan) then
382 begin
383 f := 0;
384 while (f < plaCount) and (chkTrap_pl[f] <> d) do Inc(f);
385 if (f = plaCount) then
386 begin
387 chkTrap_pl[plaCount] := d;
388 Inc(plaCount);
389 if (plaCount = Length(chkTrap_pl)) then break;
390 end;
391 end;
392 end;
393 end;
395 //g_Mons_ForEach(monsWaterCheck);
396 g_Mons_ForEachAliveAt(pan.X, pan.Y, pan.Width, pan.Height, monsWaterCheck);
397 end;
399 for f := 0 to plaCount-1 do gPlayers[chkTrap_pl[f]].Damage(dm, Shots[ID].SpawnerUID, 0, 0, t);
400 for f := 0 to mnaCount-1 do chkTrap_mn[f].Damage(dm, 0, 0, Shots[ID].SpawnerUID, t);
401 end;
402 end;
404 //chkTrap_pl := nil;
405 //chkTrap_mn := nil;
406 end;
408 function HitMonster(m: TMonster; d: Integer; vx, vy: Integer; SpawnerUID: Word; t: Byte): Boolean;
409 var
410 tt, mt: Byte;
411 mon: TMonster;
412 begin
413 Result := False;
415 tt := g_GetUIDType(SpawnerUID);
416 if tt = UID_MONSTER then
417 begin
418 mon := g_Monsters_ByUID(SpawnerUID);
419 if mon <> nil then
420 mt := g_Monsters_ByUID(SpawnerUID).MonsterType
421 else
422 mt := 0;
423 end
424 else
425 mt := 0;
427 if m = nil then Exit;
428 if m.UID = SpawnerUID then
429 begin
430 // Ñàì ñåáÿ ìîæåò ðàíèòü òîëüêî ðàêåòîé è òîêîì:
431 if (t <> HIT_ROCKET) and (t <> HIT_ELECTRO) then
432 Exit;
433 // Êèáåð äåìîí è áî÷êà âîîáùå íå ìîãóò ñåáÿ ðàíèòü:
434 if (m.MonsterType = MONSTER_CYBER) or
435 (m.MonsterType = MONSTER_BARREL) then
436 begin
437 Result := True;
438 Exit;
439 end;
440 end;
442 if tt = UID_MONSTER then
443 begin
444 // Lost_Soul íå ìîæåò ðàíèòü Pain_Elemental'à:
445 if (mt = MONSTER_SOUL) and (m.MonsterType = MONSTER_PAIN) then
446 Exit;
448 // Îáà ìîíñòðà îäíîãî âèäà:
449 if mt = m.MonsterType then
450 case mt of
451 MONSTER_IMP, MONSTER_DEMON, MONSTER_BARON, MONSTER_KNIGHT, MONSTER_CACO,
452 MONSTER_SOUL, MONSTER_MANCUB, MONSTER_SKEL, MONSTER_FISH:
453 Exit; // Ýòè íå áüþò ñâîèõ
454 end;
455 end;
457 if g_Game_IsServer then
458 begin
459 if (t <> HIT_FLAME) or (m.FFireTime = 0) or (vx <> 0) or (vy <> 0) then
460 Result := m.Damage(d, vx, vy, SpawnerUID, t)
461 else
462 Result := (gLMSRespawn = LMS_RESPAWN_NONE); // don't hit monsters when it's warmup time
463 if t = HIT_FLAME then
464 m.CatchFire(SpawnerUID);
465 end
466 else
467 Result := (gLMSRespawn = LMS_RESPAWN_NONE); // don't hit monsters when it's warmup time
468 end;
471 function HitPlayer (p: TPlayer; d: Integer; vx, vy: Integer; SpawnerUID: Word; t: Byte): Boolean;
472 begin
473 result := False;
475 // Ñàì ñåáÿ ìîæåò ðàíèòü òîëüêî ðàêåòîé è òîêîì
476 if (p.UID = SpawnerUID) and (t <> HIT_ROCKET) and (t <> HIT_ELECTRO) then exit;
478 if g_Game_IsServer then
479 begin
480 if (t <> HIT_FLAME) or (p.FFireTime = 0) or (vx <> 0) or (vy <> 0) then p.Damage(d, SpawnerUID, vx, vy, t);
481 if (t = HIT_FLAME) then p.CatchFire(SpawnerUID);
482 end;
484 result := true;
485 end;
488 procedure g_Weapon_BFG9000(X, Y: Integer; SpawnerUID: Word);
490 function monsCheck (mon: TMonster): Boolean;
491 begin
492 result := false; // don't stop
493 if (mon.alive) and (mon.UID <> SpawnerUID) then
494 begin
495 with mon do
496 begin
497 if (g_PatchLength(X, Y, Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2),
498 Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)) <= SHOT_BFG_RADIUS) and
499 g_TraceVector(X, Y, Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2),
500 Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)) then
501 begin
502 if HitMonster(mon, 50, 0, 0, SpawnerUID, HIT_SOME) then mon.BFGHit();
503 end;
504 end;
505 end;
506 end;
508 var
509 i, h: Integer;
510 st: Byte;
511 pl: TPlayer;
512 b: Boolean;
513 begin
514 //g_Sound_PlayEx('SOUND_WEAPON_EXPLODEBFG', 255);
516 h := High(gCorpses);
518 if gAdvCorpses and (h <> -1) then
519 for i := 0 to h do
520 if (gCorpses[i] <> nil) and (gCorpses[i].State <> CORPSE_STATE_REMOVEME) then
521 with gCorpses[i] do
522 if (g_PatchLength(X, Y, Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2),
523 Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)) <= SHOT_BFG_RADIUS) and
524 g_TraceVector(X, Y, Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2),
525 Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)) then
526 begin
527 Damage(50, SpawnerUID, 0, 0);
528 g_Weapon_BFGHit(Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2),
529 Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2));
530 end;
532 st := TEAM_NONE;
533 pl := g_Player_Get(SpawnerUID);
534 if pl <> nil then
535 st := pl.Team;
537 h := High(gPlayers);
539 if h <> -1 then
540 for i := 0 to h do
541 if (gPlayers[i] <> nil) and (gPlayers[i].alive) and (gPlayers[i].UID <> SpawnerUID) then
542 with gPlayers[i] do
543 if (g_PatchLength(X, Y, GameX+PLAYER_RECT.X+(PLAYER_RECT.Width div 2),
544 GameY+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)) <= SHOT_BFG_RADIUS) and
545 g_TraceVector(X, Y, GameX+PLAYER_RECT.X+(PLAYER_RECT.Width div 2),
546 GameY+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)) then
547 begin
548 if (st = TEAM_NONE) or (st <> gPlayers[i].Team) then
549 b := HitPlayer(gPlayers[i], 50, 0, 0, SpawnerUID, HIT_SOME)
550 else
551 b := HitPlayer(gPlayers[i], 25, 0, 0, SpawnerUID, HIT_SOME);
552 if b then
553 gPlayers[i].BFGHit();
554 end;
556 //FIXME
557 g_Mons_ForEachAlive(monsCheck);
558 end;
560 function g_Weapon_CreateShot(I: Integer; ShotType: Byte; Spawner, TargetUID: Word; X, Y, XV, YV: Integer): LongWord;
561 var
562 find_id: DWord;
563 begin
564 if I < 0 then
565 find_id := FindShot()
566 else
567 begin
568 find_id := I;
569 if Integer(find_id) >= High(Shots) then
570 SetLength(Shots, find_id + 64)
571 end;
573 case ShotType of
574 WEAPON_ROCKETLAUNCHER:
575 begin
576 with Shots[find_id] do
577 begin
578 g_Obj_Init(@Obj);
580 Obj.Rect.Width := SHOT_ROCKETLAUNCHER_WIDTH;
581 Obj.Rect.Height := SHOT_ROCKETLAUNCHER_HEIGHT;
583 Animation := nil;
584 Triggers := nil;
585 ShotType := WEAPON_ROCKETLAUNCHER;
586 end;
587 end;
589 WEAPON_PLASMA:
590 begin
591 with Shots[find_id] do
592 begin
593 g_Obj_Init(@Obj);
595 Obj.Rect.Width := SHOT_PLASMA_WIDTH;
596 Obj.Rect.Height := SHOT_PLASMA_HEIGHT;
598 Triggers := nil;
599 ShotType := WEAPON_PLASMA;
600 Animation := TAnimationState.Create(True, 5, 2); // !!! put values into table
601 end;
602 end;
604 WEAPON_BFG:
605 begin
606 with Shots[find_id] do
607 begin
608 g_Obj_Init(@Obj);
610 Obj.Rect.Width := SHOT_BFG_WIDTH;
611 Obj.Rect.Height := SHOT_BFG_HEIGHT;
613 Triggers := nil;
614 ShotType := WEAPON_BFG;
615 Animation := TAnimationState.Create(True, 6, 2); // !!! put values into table
616 end;
617 end;
619 WEAPON_FLAMETHROWER:
620 begin
621 with Shots[find_id] do
622 begin
623 g_Obj_Init(@Obj);
625 Obj.Rect.Width := SHOT_FLAME_WIDTH;
626 Obj.Rect.Height := SHOT_FLAME_HEIGHT;
628 Triggers := nil;
629 ShotType := WEAPON_FLAMETHROWER;
630 // Animation := TAnimationState.Create(True, 6, 0); // drawed as gfx
631 end;
632 end;
634 WEAPON_IMP_FIRE:
635 begin
636 with Shots[find_id] do
637 begin
638 g_Obj_Init(@Obj);
640 Obj.Rect.Width := 16;
641 Obj.Rect.Height := 16;
643 Triggers := nil;
644 ShotType := WEAPON_IMP_FIRE;
645 Animation := TAnimationState.Create(True, 4, 2); // !!! put values into table
646 end;
647 end;
649 WEAPON_CACO_FIRE:
650 begin
651 with Shots[find_id] do
652 begin
653 g_Obj_Init(@Obj);
655 Obj.Rect.Width := 16;
656 Obj.Rect.Height := 16;
658 Triggers := nil;
659 ShotType := WEAPON_CACO_FIRE;
660 Animation := TAnimationState.Create(True, 4, 2); // !!! put values into table
661 end;
662 end;
664 WEAPON_MANCUB_FIRE:
665 begin
666 with Shots[find_id] do
667 begin
668 g_Obj_Init(@Obj);
670 Obj.Rect.Width := 32;
671 Obj.Rect.Height := 32;
673 Triggers := nil;
674 ShotType := WEAPON_MANCUB_FIRE;
675 Animation := TAnimationState.Create(True, 4, 2); // !!! put values into table
676 end;
677 end;
679 WEAPON_BARON_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 := 16;
688 Triggers := nil;
689 ShotType := WEAPON_BARON_FIRE;
690 Animation := TAnimationState.Create(True, 4, 2); // !!! put values into table
691 end;
692 end;
694 WEAPON_BSP_FIRE:
695 begin
696 with Shots[find_id] do
697 begin
698 g_Obj_Init(@Obj);
700 Obj.Rect.Width := 16;
701 Obj.Rect.Height := 16;
703 Triggers := nil;
704 ShotType := WEAPON_BSP_FIRE;
705 Animation := TAnimationState.Create(True, 4, 2); // !!! put values into table
706 end;
707 end;
709 WEAPON_SKEL_FIRE:
710 begin
711 with Shots[find_id] do
712 begin
713 g_Obj_Init(@Obj);
715 Obj.Rect.Width := SHOT_SKELFIRE_WIDTH;
716 Obj.Rect.Height := SHOT_SKELFIRE_HEIGHT;
718 Triggers := nil;
719 ShotType := WEAPON_SKEL_FIRE;
720 target := TargetUID;
721 Animation := TAnimationState.Create(True, 5, 2); // !!! put values into table
722 end;
723 end;
724 end;
726 Shots[find_id].Obj.oldX := X;
727 Shots[find_id].Obj.oldY := Y;
728 Shots[find_id].Obj.X := X;
729 Shots[find_id].Obj.Y := Y;
730 Shots[find_id].Obj.Vel.X := XV;
731 Shots[find_id].Obj.Vel.Y := YV;
732 Shots[find_id].Obj.Accel.X := 0;
733 Shots[find_id].Obj.Accel.Y := 0;
734 Shots[find_id].SpawnerUID := Spawner;
735 if (ShotType = WEAPON_FLAMETHROWER) and (XV = 0) and (YV = 0) then
736 Shots[find_id].Stopped := 255
737 else
738 Shots[find_id].Stopped := 0;
739 Result := find_id;
740 end;
742 procedure throw(i, x, y, xd, yd, s: Integer);
743 var
744 a: Integer;
745 begin
746 yd := yd - y;
747 xd := xd - x;
749 a := Max(Abs(xd), Abs(yd));
750 if a = 0 then
751 a := 1;
753 Shots[i].Obj.oldX := x;
754 Shots[i].Obj.oldY := y;
755 Shots[i].Obj.X := x;
756 Shots[i].Obj.Y := y;
757 Shots[i].Obj.Vel.X := (xd*s) div a;
758 Shots[i].Obj.Vel.Y := (yd*s) div a;
759 Shots[i].Obj.Accel.X := 0;
760 Shots[i].Obj.Accel.Y := 0;
761 Shots[i].Stopped := 0;
762 if Shots[i].ShotType in [WEAPON_ROCKETLAUNCHER, WEAPON_BFG] then
763 Shots[i].Timeout := 900 // ~25 sec
764 else
765 begin
766 if Shots[i].ShotType = WEAPON_FLAMETHROWER then
767 Shots[i].Timeout := SHOT_FLAME_LIFETIME
768 else
769 Shots[i].Timeout := 550; // ~15 sec
770 end;
771 end;
773 function g_Weapon_Hit(obj: PObj; d: Integer; SpawnerUID: Word; t: Byte; HitCorpses: Boolean = True): Byte;
774 var
775 i, h: Integer;
777 function PlayerHit(Team: Byte = 0): Boolean;
778 var
779 i: Integer;
780 ChkTeam: Boolean;
781 p: TPlayer;
782 begin
783 Result := False;
784 h := High(gPlayers);
786 if h <> -1 then
787 for i := 0 to h do
788 if (gPlayers[i] <> nil) and gPlayers[i].alive and g_Obj_Collide(obj, @gPlayers[i].Obj) then
789 begin
790 ChkTeam := True;
791 if (Team > 0) and (g_GetUIDType(SpawnerUID) = UID_PLAYER) then
792 begin
793 p := g_Player_Get(SpawnerUID);
794 if p <> nil then
795 ChkTeam := (p.Team = gPlayers[i].Team) xor (Team = 2);
796 end;
797 if ChkTeam then
798 if HitPlayer(gPlayers[i], d, obj^.Vel.X, obj^.Vel.Y, SpawnerUID, t) then
799 begin
800 if t <> HIT_FLAME then
801 gPlayers[i].Push((obj^.Vel.X+obj^.Accel.X)*IfThen(t = HIT_BFG, 8, 1) div 4,
802 (obj^.Vel.Y+obj^.Accel.Y)*IfThen(t = HIT_BFG, 8, 1) div 4);
803 if t = HIT_BFG then
804 g_Game_DelayEvent(DE_BFGHIT, 1000, SpawnerUID);
805 Result := True;
806 break;
807 end;
808 end;
809 end;
812 function monsCheckHit (monidx: Integer; mon: TMonster): Boolean;
813 begin
814 result := false; // don't stop
815 if mon.alive and g_Obj_Collide(obj, @mon.Obj) then
816 begin
817 if HitMonster(mon, d, obj^.Vel.X, obj^.Vel.Y, SpawnerUID, t) then
818 begin
819 if (t <> HIT_FLAME) then
820 begin
821 mon.Push((obj^.Vel.X+obj^.Accel.X)*IfThen(t = HIT_BFG, 8, 1) div 4,
822 (obj^.Vel.Y+obj^.Accel.Y)*IfThen(t = HIT_BFG, 8, 1) div 4);
823 end;
824 result := True;
825 end;
826 end;
827 end;
830 function monsCheckHit (mon: TMonster): Boolean;
831 begin
832 result := false; // don't stop
833 if HitMonster(mon, d, obj.Vel.X, obj.Vel.Y, SpawnerUID, t) then
834 begin
835 if (t <> HIT_FLAME) then
836 begin
837 mon.Push((obj.Vel.X+obj.Accel.X)*IfThen(t = HIT_BFG, 8, 1) div 4,
838 (obj.Vel.Y+obj.Accel.Y)*IfThen(t = HIT_BFG, 8, 1) div 4);
839 end;
840 result := true;
841 end;
842 end;
844 function MonsterHit(): Boolean;
845 begin
846 //result := g_Mons_ForEach(monsCheckHit);
847 //FIXME: accelerate this!
848 result := g_Mons_ForEachAliveAt(obj.X+obj.Rect.X, obj.Y+obj.Rect.Y, obj.Rect.Width, obj.Rect.Height, monsCheckHit);
849 end;
851 begin
852 Result := 0;
854 if HitCorpses then
855 begin
856 h := High(gCorpses);
858 if gAdvCorpses and (h <> -1) then
859 for i := 0 to h do
860 if (gCorpses[i] <> nil) and (gCorpses[i].State <> CORPSE_STATE_REMOVEME) and
861 g_Obj_Collide(obj, @gCorpses[i].Obj) then
862 begin
863 // Ðàñïèëèâàåì òðóï:
864 gCorpses[i].Damage(d, SpawnerUID, (obj^.Vel.X+obj^.Accel.X) div 4,
865 (obj^.Vel.Y+obj^.Accel.Y) div 4);
866 Result := 1;
867 end;
868 end;
870 case gGameSettings.GameMode of
871 // Êàìïàíèÿ:
872 GM_COOP, GM_SINGLE:
873 begin
874 // Ñíà÷àëà áü¸ì ìîíñòðîâ, åñëè åñòü, ïîòîì ïûòàåìñÿ áèòü èãðîêîâ
875 if MonsterHit() then
876 begin
877 Result := 2;
878 Exit;
879 end;
881 // È â êîíöå èãðîêîâ, íî òîëüêî åñëè ïîëîæåíî
882 // (èëè ñíàðÿä îò ìîíñòðà, èëè friendlyfire, èëè friendly_hit_projectile)
883 if (g_GetUIDType(SpawnerUID) <> UID_PLAYER) or
884 LongBool(gGameSettings.Options and (GAME_OPTION_TEAMDAMAGE or GAME_OPTION_TEAMHITPROJECTILE)) then
885 begin
886 if PlayerHit() then
887 begin
888 Result := 1;
889 Exit;
890 end;
891 end;
892 end;
894 // Äåçìàò÷:
895 GM_DM:
896 begin
897 // Ñíà÷àëà áü¸ì èãðîêîâ, åñëè åñòü, ïîòîì ïûòàåìñÿ áèòü ìîíñòðîâ
898 if PlayerHit() then
899 begin
900 Result := 1;
901 Exit;
902 end;
904 if MonsterHit() then
905 begin
906 Result := 2;
907 Exit;
908 end;
909 end;
911 // Êîìàíäíûå:
912 GM_TDM, GM_CTF:
913 begin
914 // Ñíà÷àëà áü¸ì èãðîêîâ êîìàíäû ñîïåðíèêà
915 if PlayerHit(2) then
916 begin
917 Result := 1;
918 Exit;
919 end;
921 // Ïîòîì ìîíñòðîâ
922 if MonsterHit() then
923 begin
924 Result := 2;
925 Exit;
926 end;
928 // È â êîíöå ñâîèõ èãðîêîâ, íî òîëüêî åñëè ïîëîæåíî
929 // (èëè friendlyfire, èëè friendly_hit_projectile)
930 if LongBool(gGameSettings.Options and (GAME_OPTION_TEAMDAMAGE or GAME_OPTION_TEAMHITPROJECTILE)) then
931 begin
932 if PlayerHit(1) then
933 begin
934 Result := 1;
935 Exit;
936 end;
937 end;
938 end;
940 end;
941 end;
943 function g_Weapon_HitUID(UID: Word; d: Integer; SpawnerUID: Word; t: Byte): Boolean;
944 begin
945 Result := False;
947 case g_GetUIDType(UID) of
948 UID_PLAYER: Result := HitPlayer(g_Player_Get(UID), d, 0, 0, SpawnerUID, t);
949 UID_MONSTER: Result := HitMonster(g_Monsters_ByUID(UID), d, 0, 0, SpawnerUID, t);
950 else Exit;
951 end;
952 end;
954 function g_Weapon_Explode(X, Y: Integer; rad: Integer; SpawnerUID: Word): Boolean;
955 var
956 r: Integer; // squared radius
958 function monsExCheck (mon: TMonster): Boolean;
959 var
960 dx, dy, mm: Integer;
961 begin
962 result := false; // don't stop
963 begin
964 dx := mon.Obj.X+mon.Obj.Rect.X+(mon.Obj.Rect.Width div 2)-X;
965 dy := mon.Obj.Y+mon.Obj.Rect.Y+(mon.Obj.Rect.Height div 2)-Y;
967 if dx > 1000 then dx := 1000;
968 if dy > 1000 then dy := 1000;
970 if (dx*dx+dy*dy < r) then
971 begin
972 //m := PointToRect(X, Y, Obj.X+Obj.Rect.X, Obj.Y+Obj.Rect.Y, Obj.Rect.Width, Obj.Rect.Height);
973 //e_WriteLog(Format('explo monster #%d: x=%d; y=%d; rad=%d; dx=%d; dy=%d', [monidx, X, Y, rad, dx, dy]), MSG_NOTIFY);
975 mm := Max(abs(dx), abs(dy));
976 if mm = 0 then mm := 1;
978 if mon.alive then
979 begin
980 HitMonster(mon, ((mon.Obj.Rect.Width div 4)*10*(rad-mm)) div rad, 0, 0, SpawnerUID, HIT_ROCKET);
981 end;
983 mon.Push((dx*7) div mm, (dy*7) div mm);
984 end;
985 end;
986 end;
988 var
989 i, h, dx, dy, m, mm: Integer;
990 _angle: SmallInt;
991 begin
992 result := false;
994 g_Triggers_PressC(X, Y, rad, SpawnerUID, ACTIVATE_SHOT);
996 r := rad*rad;
998 h := High(gPlayers);
1000 if h <> -1 then
1001 for i := 0 to h do
1002 if (gPlayers[i] <> nil) and gPlayers[i].alive then
1003 with gPlayers[i] do
1004 begin
1005 dx := Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2)-X;
1006 dy := Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)-Y;
1008 if dx > 1000 then dx := 1000;
1009 if dy > 1000 then dy := 1000;
1011 if dx*dx+dy*dy < r then
1012 begin
1013 //m := PointToRect(X, Y, GameX+PLAYER_RECT.X, GameY+PLAYER_RECT.Y,
1014 // PLAYER_RECT.Width, PLAYER_RECT.Height);
1016 mm := Max(abs(dx), abs(dy));
1017 if mm = 0 then mm := 1;
1019 HitPlayer(gPlayers[i], (100*(rad-mm)) div rad, (dx*10) div mm, (dy*10) div mm, SpawnerUID, HIT_ROCKET);
1020 gPlayers[i].Push((dx*7) div mm, (dy*7) div mm);
1021 end;
1022 end;
1024 //g_Mons_ForEach(monsExCheck);
1025 g_Mons_ForEachAt(X-(rad+32), Y-(rad+32), (rad+32)*2, (rad+32)*2, monsExCheck);
1027 h := High(gCorpses);
1029 if gAdvCorpses and (h <> -1) then
1030 for i := 0 to h do
1031 if (gCorpses[i] <> nil) and (gCorpses[i].State <> CORPSE_STATE_REMOVEME) then
1032 with gCorpses[i] do
1033 begin
1034 dx := Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2)-X;
1035 dy := Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)-Y;
1037 if dx > 1000 then dx := 1000;
1038 if dy > 1000 then dy := 1000;
1040 if dx*dx+dy*dy < r then
1041 begin
1042 m := PointToRect(X, Y, Obj.X+Obj.Rect.X, Obj.Y+Obj.Rect.Y,
1043 Obj.Rect.Width, Obj.Rect.Height);
1045 mm := Max(abs(dx), abs(dy));
1046 if mm = 0 then mm := 1;
1048 Damage(Round(100*(rad-m)/rad), SpawnerUID, (dx*10) div mm, (dy*10) div mm);
1049 end;
1050 end;
1052 h := High(gGibs);
1054 if gAdvGibs and (h <> -1) then
1055 for i := 0 to h do
1056 if gGibs[i].alive then
1057 with gGibs[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;
1062 if dx > 1000 then dx := 1000;
1063 if dy > 1000 then dy := 1000;
1065 if dx*dx+dy*dy < r then
1066 begin
1067 m := PointToRect(X, Y, Obj.X+Obj.Rect.X, Obj.Y+Obj.Rect.Y,
1068 Obj.Rect.Width, Obj.Rect.Height);
1069 _angle := GetAngle(Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2),
1070 Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2), X, Y);
1072 g_Obj_PushA(@Obj, Round(15*(rad-m)/rad), _angle);
1073 positionChanged(); // this updates spatial accelerators
1074 end;
1075 end;
1076 end;
1078 procedure g_Weapon_Init();
1079 begin
1080 CreateWaterMap();
1081 end;
1083 procedure g_Weapon_Free();
1084 var
1085 i: Integer;
1086 begin
1087 if Shots <> nil then
1088 begin
1089 for i := 0 to High(Shots) do
1090 if Shots[i].ShotType <> 0 then
1091 Shots[i].Animation.Free();
1093 Shots := nil;
1094 end;
1096 WaterMap := nil;
1097 end;
1099 procedure g_Weapon_LoadData();
1100 begin
1101 e_WriteLog('Loading weapons data...', TMsgType.Notify);
1103 g_Sound_CreateWADEx('SOUND_WEAPON_HITPUNCH', GameWAD+':SOUNDS\HITPUNCH');
1104 g_Sound_CreateWADEx('SOUND_WEAPON_MISSPUNCH', GameWAD+':SOUNDS\MISSPUNCH');
1105 g_Sound_CreateWADEx('SOUND_WEAPON_HITBERSERK', GameWAD+':SOUNDS\HITBERSERK');
1106 g_Sound_CreateWADEx('SOUND_WEAPON_MISSBERSERK', GameWAD+':SOUNDS\MISSBERSERK');
1107 g_Sound_CreateWADEx('SOUND_WEAPON_SELECTSAW', GameWAD+':SOUNDS\SELECTSAW');
1108 g_Sound_CreateWADEx('SOUND_WEAPON_IDLESAW', GameWAD+':SOUNDS\IDLESAW');
1109 g_Sound_CreateWADEx('SOUND_WEAPON_HITSAW', GameWAD+':SOUNDS\HITSAW');
1110 g_Sound_CreateWADEx('SOUND_WEAPON_FIRESHOTGUN2', GameWAD+':SOUNDS\FIRESHOTGUN2');
1111 g_Sound_CreateWADEx('SOUND_WEAPON_FIRESHOTGUN', GameWAD+':SOUNDS\FIRESHOTGUN');
1112 g_Sound_CreateWADEx('SOUND_WEAPON_FIRESAW', GameWAD+':SOUNDS\FIRESAW');
1113 g_Sound_CreateWADEx('SOUND_WEAPON_FIREROCKET', GameWAD+':SOUNDS\FIREROCKET');
1114 g_Sound_CreateWADEx('SOUND_WEAPON_FIREPLASMA', GameWAD+':SOUNDS\FIREPLASMA');
1115 g_Sound_CreateWADEx('SOUND_WEAPON_FIREPISTOL', GameWAD+':SOUNDS\FIREPISTOL');
1116 g_Sound_CreateWADEx('SOUND_WEAPON_FIRECGUN', GameWAD+':SOUNDS\FIRECGUN');
1117 g_Sound_CreateWADEx('SOUND_WEAPON_FIREBFG', GameWAD+':SOUNDS\FIREBFG');
1118 g_Sound_CreateWADEx('SOUND_FIRE', GameWAD+':SOUNDS\FIRE');
1119 g_Sound_CreateWADEx('SOUND_IGNITE', GameWAD+':SOUNDS\IGNITE');
1120 g_Sound_CreateWADEx('SOUND_WEAPON_STARTFIREBFG', GameWAD+':SOUNDS\STARTFIREBFG');
1121 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEROCKET', GameWAD+':SOUNDS\EXPLODEROCKET');
1122 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEBFG', GameWAD+':SOUNDS\EXPLODEBFG');
1123 g_Sound_CreateWADEx('SOUND_WEAPON_BFGWATER', GameWAD+':SOUNDS\BFGWATER');
1124 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEPLASMA', GameWAD+':SOUNDS\EXPLODEPLASMA');
1125 g_Sound_CreateWADEx('SOUND_WEAPON_PLASMAWATER', GameWAD+':SOUNDS\PLASMAWATER');
1126 g_Sound_CreateWADEx('SOUND_WEAPON_FIREBALL', GameWAD+':SOUNDS\FIREBALL');
1127 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEBALL', GameWAD+':SOUNDS\EXPLODEBALL');
1128 g_Sound_CreateWADEx('SOUND_WEAPON_FIREREV', GameWAD+':SOUNDS\FIREREV');
1129 g_Sound_CreateWADEx('SOUND_WEAPON_FLAMEON', GameWAD+':SOUNDS\STARTFLM');
1130 g_Sound_CreateWADEx('SOUND_WEAPON_FLAMEOFF', GameWAD+':SOUNDS\STOPFLM');
1131 g_Sound_CreateWADEx('SOUND_WEAPON_FLAMEWORK', GameWAD+':SOUNDS\WORKFLM');
1132 g_Sound_CreateWADEx('SOUND_PLAYER_JETFLY', GameWAD+':SOUNDS\WORKJETPACK');
1133 g_Sound_CreateWADEx('SOUND_PLAYER_JETON', GameWAD+':SOUNDS\STARTJETPACK');
1134 g_Sound_CreateWADEx('SOUND_PLAYER_JETOFF', GameWAD+':SOUNDS\STOPJETPACK');
1135 g_Sound_CreateWADEx('SOUND_PLAYER_CASING1', GameWAD+':SOUNDS\CASING1');
1136 g_Sound_CreateWADEx('SOUND_PLAYER_CASING2', GameWAD+':SOUNDS\CASING2');
1137 g_Sound_CreateWADEx('SOUND_PLAYER_SHELL1', GameWAD+':SOUNDS\SHELL1');
1138 g_Sound_CreateWADEx('SOUND_PLAYER_SHELL2', GameWAD+':SOUNDS\SHELL2');
1140 //wgunMonHash := hashNewIntInt();
1141 wgunHitHeap := TBinaryHeapHitTimes.Create();
1142 end;
1144 procedure g_Weapon_FreeData();
1145 begin
1146 e_WriteLog('Releasing weapons data...', TMsgType.Notify);
1148 g_Sound_Delete('SOUND_WEAPON_HITPUNCH');
1149 g_Sound_Delete('SOUND_WEAPON_MISSPUNCH');
1150 g_Sound_Delete('SOUND_WEAPON_HITBERSERK');
1151 g_Sound_Delete('SOUND_WEAPON_MISSBERSERK');
1152 g_Sound_Delete('SOUND_WEAPON_SELECTSAW');
1153 g_Sound_Delete('SOUND_WEAPON_IDLESAW');
1154 g_Sound_Delete('SOUND_WEAPON_HITSAW');
1155 g_Sound_Delete('SOUND_WEAPON_FIRESHOTGUN2');
1156 g_Sound_Delete('SOUND_WEAPON_FIRESHOTGUN');
1157 g_Sound_Delete('SOUND_WEAPON_FIRESAW');
1158 g_Sound_Delete('SOUND_WEAPON_FIREROCKET');
1159 g_Sound_Delete('SOUND_WEAPON_FIREPLASMA');
1160 g_Sound_Delete('SOUND_WEAPON_FIREPISTOL');
1161 g_Sound_Delete('SOUND_WEAPON_FIRECGUN');
1162 g_Sound_Delete('SOUND_WEAPON_FIREBFG');
1163 g_Sound_Delete('SOUND_FIRE');
1164 g_Sound_Delete('SOUND_IGNITE');
1165 g_Sound_Delete('SOUND_WEAPON_STARTFIREBFG');
1166 g_Sound_Delete('SOUND_WEAPON_EXPLODEROCKET');
1167 g_Sound_Delete('SOUND_WEAPON_EXPLODEBFG');
1168 g_Sound_Delete('SOUND_WEAPON_BFGWATER');
1169 g_Sound_Delete('SOUND_WEAPON_EXPLODEPLASMA');
1170 g_Sound_Delete('SOUND_WEAPON_PLASMAWATER');
1171 g_Sound_Delete('SOUND_WEAPON_FIREBALL');
1172 g_Sound_Delete('SOUND_WEAPON_EXPLODEBALL');
1173 g_Sound_Delete('SOUND_WEAPON_FIREREV');
1174 g_Sound_Delete('SOUND_WEAPON_FLAMEON');
1175 g_Sound_Delete('SOUND_WEAPON_FLAMEOFF');
1176 g_Sound_Delete('SOUND_WEAPON_FLAMEWORK');
1177 g_Sound_Delete('SOUND_PLAYER_JETFLY');
1178 g_Sound_Delete('SOUND_PLAYER_JETON');
1179 g_Sound_Delete('SOUND_PLAYER_JETOFF');
1180 g_Sound_Delete('SOUND_PLAYER_CASING1');
1181 g_Sound_Delete('SOUND_PLAYER_CASING2');
1182 g_Sound_Delete('SOUND_PLAYER_SHELL1');
1183 g_Sound_Delete('SOUND_PLAYER_SHELL2');
1184 end;
1187 function GunHitPlayer (X, Y: Integer; vx, vy: Integer; dmg: Integer; SpawnerUID: Word; AllowPush: Boolean): Boolean;
1188 var
1189 i: Integer;
1190 begin
1191 result := false;
1192 for i := 0 to High(gPlayers) do
1193 begin
1194 if (gPlayers[i] <> nil) and gPlayers[i].alive and gPlayers[i].Collide(X, Y) then
1195 begin
1196 if HitPlayer(gPlayers[i], dmg, vx*10, vy*10-3, SpawnerUID, HIT_SOME) then
1197 begin
1198 if AllowPush then gPlayers[i].Push(vx, vy);
1199 result := true;
1200 end;
1201 end;
1202 end;
1203 end;
1206 function GunHit (X, Y: Integer; vx, vy: Integer; dmg: Integer; SpawnerUID: Word; AllowPush: Boolean): Byte;
1208 function monsCheck (mon: TMonster): Boolean;
1209 begin
1210 result := false; // don't stop
1211 if HitMonster(mon, dmg, vx*10, vy*10-3, SpawnerUID, HIT_SOME) then
1212 begin
1213 if AllowPush then mon.Push(vx, vy);
1214 result := true;
1215 end;
1216 end;
1218 begin
1219 result := 0;
1220 if GunHitPlayer(X, Y, vx, vy, dmg, SpawnerUID, AllowPush) then result := 1
1221 else if g_Mons_ForEachAliveAt(X, Y, 1, 1, monsCheck) then result := 2;
1222 end;
1225 (*
1226 procedure g_Weapon_gunOld(const x, y, xd, yd, v, dmg: Integer; SpawnerUID: Word; CheckTrigger: Boolean);
1227 var
1228 a: Integer;
1229 x2, y2: Integer;
1230 dx, dy: Integer;
1231 xe, ye: Integer;
1232 xi, yi: Integer;
1233 s, c: Extended;
1234 //vx, vy: Integer;
1235 xx, yy, d: Integer;
1236 i: Integer;
1237 t1, _collide: Boolean;
1238 w, h: Word;
1239 {$IF DEFINED(D2F_DEBUG)}
1240 stt: UInt64;
1241 showTime: Boolean = true;
1242 {$ENDIF}
1243 begin
1244 a := GetAngle(x, y, xd, yd)+180;
1246 SinCos(DegToRad(-a), s, c);
1248 if Abs(s) < 0.01 then s := 0;
1249 if Abs(c) < 0.01 then c := 0;
1251 x2 := x+Round(c*gMapInfo.Width);
1252 y2 := y+Round(s*gMapInfo.Width);
1254 t1 := gWalls <> nil;
1255 _collide := False;
1256 w := gMapInfo.Width;
1257 h := gMapInfo.Height;
1259 xe := 0;
1260 ye := 0;
1261 dx := x2-x;
1262 dy := y2-y;
1264 if (xd = 0) and (yd = 0) then Exit;
1266 if dx > 0 then xi := 1 else if dx < 0 then xi := -1 else xi := 0;
1267 if dy > 0 then yi := 1 else if dy < 0 then yi := -1 else yi := 0;
1269 dx := Abs(dx);
1270 dy := Abs(dy);
1272 if dx > dy then d := dx else d := dy;
1274 //blood vel, for Monster.Damage()
1275 //vx := (dx*10 div d)*xi;
1276 //vy := (dy*10 div d)*yi;
1278 {$IF DEFINED(D2F_DEBUG)}
1279 stt := getTimeMicro();
1280 {$ENDIF}
1282 xx := x;
1283 yy := y;
1285 for i := 1 to d do
1286 begin
1287 xe := xe+dx;
1288 ye := ye+dy;
1290 if xe > d then
1291 begin
1292 xe := xe-d;
1293 xx := xx+xi;
1294 end;
1296 if ye > d then
1297 begin
1298 ye := ye-d;
1299 yy := yy+yi;
1300 end;
1302 if (yy > h) or (yy < 0) then Break;
1303 if (xx > w) or (xx < 0) then Break;
1305 if t1 then
1306 if ByteBool(gCollideMap[yy, xx] and MARK_BLOCKED) then
1307 begin
1308 _collide := True;
1309 {$IF DEFINED(D2F_DEBUG)}
1310 stt := getTimeMicro()-stt;
1311 e_WriteLog(Format('*** old trace time: %u microseconds', [LongWord(stt)]), MSG_NOTIFY);
1312 showTime := false;
1313 {$ENDIF}
1314 g_GFX_Spark(xx-xi, yy-yi, 2+Random(2), 180+a, 0, 0);
1315 if g_Game_IsServer and g_Game_IsNet then
1316 MH_SEND_Effect(xx-xi, yy-yi, 180+a, NET_GFX_SPARK);
1317 end;
1319 if not _collide then
1320 begin
1321 _collide := GunHit(xx, yy, xi*v, yi*v, dmg, SpawnerUID, v <> 0) <> 0;
1322 end;
1324 if _collide then Break;
1325 end;
1327 {$IF DEFINED(D2F_DEBUG)}
1328 if showTime then
1329 begin
1330 stt := getTimeMicro()-stt;
1331 e_WriteLog(Format('*** old trace time: %u microseconds', [LongWord(stt)]), MSG_NOTIFY);
1332 end;
1333 {$ENDIF}
1335 if CheckTrigger and g_Game_IsServer then
1336 g_Triggers_PressL(X, Y, xx-xi, yy-yi, SpawnerUID, ACTIVATE_SHOT);
1337 end;
1338 *)
1341 //!!!FIXME!!!
1342 procedure g_Weapon_gun (const x, y, xd, yd, v, indmg: Integer; SpawnerUID: Word; CheckTrigger: Boolean);
1343 var
1344 x0, y0: Integer;
1345 x2, y2: Integer;
1346 xi, yi: Integer;
1347 wallDistSq: Integer = $3fffffff;
1348 spawnerPlr: TPlayer = nil;
1349 dmg: Integer;
1351 function doPlayerHit (idx: Integer; hx, hy: Integer): Boolean;
1352 begin
1353 result := false;
1354 if (idx < 0) or (idx > High(gPlayers)) then exit;
1355 if (gPlayers[idx] = nil) or not gPlayers[idx].alive then exit;
1356 if (spawnerPlr <> nil) then
1357 begin
1358 if ((gGameSettings.Options and (GAME_OPTION_TEAMHITTRACE or GAME_OPTION_TEAMDAMAGE)) = 0) and
1359 (spawnerPlr.Team <> TEAM_NONE) and (spawnerPlr.Team = gPlayers[idx].Team) then
1360 begin
1361 if (spawnerPlr <> gPlayers[idx]) and ((gGameSettings.Options and GAME_OPTION_TEAMABSORBDAMAGE) = 0) then
1362 dmg := Max(1, dmg div 2);
1363 exit;
1364 end;
1365 end;
1366 result := HitPlayer(gPlayers[idx], dmg, (xi*v)*10, (yi*v)*10-3, SpawnerUID, HIT_SOME);
1367 if result and (v <> 0) then gPlayers[idx].Push((xi*v), (yi*v));
1368 {$IF DEFINED(D2F_DEBUG)}
1369 //if result then e_WriteLog(Format(' PLAYER #%d HIT', [idx]), MSG_NOTIFY);
1370 {$ENDIF}
1371 end;
1373 function doMonsterHit (mon: TMonster; hx, hy: Integer): Boolean;
1374 begin
1375 result := false;
1376 if (mon = nil) then exit;
1377 result := HitMonster(mon, dmg, (xi*v)*10, (yi*v)*10-3, SpawnerUID, HIT_SOME);
1378 if result and (v <> 0) then mon.Push((xi*v), (yi*v));
1379 {$IF DEFINED(D2F_DEBUG)}
1380 //if result then e_WriteLog(Format(' MONSTER #%u HIT', [LongWord(mon.UID)]), MSG_NOTIFY);
1381 {$ENDIF}
1382 end;
1384 // collect players along hitray
1385 // return `true` if instant hit was detected
1386 function playerPossibleHit (): Boolean;
1387 var
1388 i: Integer;
1389 px, py, pw, ph: Integer;
1390 inx, iny: Integer;
1391 distSq: Integer;
1392 plr: TPlayer;
1393 begin
1394 result := false;
1395 for i := 0 to High(gPlayers) do
1396 begin
1397 plr := gPlayers[i];
1398 if (plr <> nil) and plr.alive then
1399 begin
1400 plr.getMapBox(px, py, pw, ph);
1401 if lineAABBIntersects(x, y, x2, y2, px, py, pw, ph, inx, iny) then
1402 begin
1403 distSq := distanceSq(x, y, inx, iny);
1404 if (distSq = 0) then
1405 begin
1406 // contains
1407 if doPlayerHit(i, x, y) then begin result := true; exit; end;
1408 end
1409 else if (distSq < wallDistSq) then
1410 begin
1411 appendHitTimePlr(distSq, i, inx, iny);
1412 end;
1413 end;
1414 end;
1415 end;
1416 end;
1418 procedure sqchecker (mon: TMonster);
1419 var
1420 mx, my, mw, mh: Integer;
1421 inx, iny: Integer;
1422 distSq: Integer;
1423 begin
1424 mon.getMapBox(mx, my, mw, mh);
1425 if lineAABBIntersects(x0, y0, x2, y2, mx, my, mw, mh, inx, iny) then
1426 begin
1427 distSq := distanceSq(x0, y0, inx, iny);
1428 if (distSq < wallDistSq) then appendHitTimeMon(distSq, mon, inx, iny);
1429 end;
1430 end;
1432 var
1433 a: Integer;
1434 dx, dy: Integer;
1435 xe, ye: Integer;
1436 s, c: Extended;
1437 i: Integer;
1438 wallHitFlag: Boolean = false;
1439 wallHitX: Integer = 0;
1440 wallHitY: Integer = 0;
1441 didHit: Boolean = false;
1442 {$IF DEFINED(D2F_DEBUG)}
1443 stt: UInt64;
1444 {$ENDIF}
1445 mit: PMonster;
1446 it: TMonsterGrid.Iter;
1447 begin
1448 (*
1449 if not gwep_debug_fast_trace then
1450 begin
1451 g_Weapon_gunOld(x, y, xd, yd, v, dmg, SpawnerUID, CheckTrigger);
1452 exit;
1453 end;
1454 *)
1456 if (xd = 0) and (yd = 0) then exit;
1458 if (g_GetUIDType(SpawnerUID) = UID_PLAYER) then
1459 spawnerPlr := g_Player_Get(SpawnerUID);
1461 dmg := indmg;
1463 //wgunMonHash.reset(); //FIXME: clear hash on level change
1464 wgunHitHeap.clear();
1465 wgunHitTimeUsed := 0;
1467 a := GetAngle(x, y, xd, yd)+180;
1469 SinCos(DegToRad(-a), s, c);
1471 if Abs(s) < 0.01 then s := 0;
1472 if Abs(c) < 0.01 then c := 0;
1474 x0 := x;
1475 y0 := y;
1476 x2 := x+Round(c*gMapInfo.Width);
1477 y2 := y+Round(s*gMapInfo.Width);
1479 dx := x2-x;
1480 dy := y2-y;
1482 if (dx > 0) then xi := 1 else if (dx < 0) then xi := -1 else xi := 0;
1483 if (dy > 0) then yi := 1 else if (dy < 0) then yi := -1 else yi := 0;
1485 {$IF DEFINED(D2F_DEBUG)}
1486 e_WriteLog(Format('GUN TRACE: (%d,%d) to (%d,%d)', [x, y, x2, y2]), TMsgType.Notify);
1487 stt := getTimeMicro();
1488 {$ENDIF}
1490 wallHitFlag := (g_Map_traceToNearestWall(x, y, x2, y2, @wallHitX, @wallHitY) <> nil);
1491 if wallHitFlag then
1492 begin
1493 x2 := wallHitX;
1494 y2 := wallHitY;
1495 wallDistSq := distanceSq(x, y, wallHitX, wallHitY);
1496 end
1497 else
1498 begin
1499 wallHitX := x2;
1500 wallHitY := y2;
1501 end;
1503 if playerPossibleHit() then exit; // instant hit
1505 // collect monsters
1506 //g_Mons_AlongLine(x, y, x2, y2, sqchecker);
1508 it := monsGrid.forEachAlongLine(x, y, x2, y2, -1);
1509 for mit in it do sqchecker(mit^);
1510 it.release();
1512 // here, we collected all monsters and players in `wgunHitHeap` and `wgunHitTime`
1513 // also, if `wallWasHit` is `true`, then `wallHitX` and `wallHitY` contains spark coords
1514 while (wgunHitHeap.count > 0) do
1515 begin
1516 // has some entities to check, do it
1517 i := wgunHitHeap.front;
1518 wgunHitHeap.popFront();
1519 // hitpoint
1520 xe := wgunHitTime[i].x;
1521 ye := wgunHitTime[i].y;
1522 // check if it is not behind the wall
1523 if (wgunHitTime[i].mon <> nil) then
1524 begin
1525 didHit := doMonsterHit(wgunHitTime[i].mon, xe, ye);
1526 end
1527 else
1528 begin
1529 didHit := doPlayerHit(wgunHitTime[i].plridx, xe, ye);
1530 end;
1531 if didHit then
1532 begin
1533 // need new coords for trigger
1534 wallHitX := xe;
1535 wallHitY := ye;
1536 wallHitFlag := false; // no sparks
1537 break;
1538 end;
1539 end;
1541 // need sparks?
1542 if wallHitFlag then
1543 begin
1544 {$IF DEFINED(D2F_DEBUG)}
1545 stt := getTimeMicro()-stt;
1546 e_WriteLog(Format('*** new trace time: %u microseconds', [LongWord(stt)]), TMsgType.Notify);
1547 {$ENDIF}
1548 g_GFX_Spark(wallHitX, wallHitY, 2+Random(2), 180+a, 0, 0);
1549 if g_Game_IsServer and g_Game_IsNet then MH_SEND_Effect(wallHitX, wallHitY, 180+a, NET_GFX_SPARK);
1550 end
1551 else
1552 begin
1553 {$IF DEFINED(D2F_DEBUG)}
1554 stt := getTimeMicro()-stt;
1555 e_WriteLog(Format('*** new trace time: %u microseconds', [LongWord(stt)]), TMsgType.Notify);
1556 {$ENDIF}
1557 end;
1559 if CheckTrigger and g_Game_IsServer then g_Triggers_PressL(X, Y, wallHitX, wallHitY, SpawnerUID, ACTIVATE_SHOT);
1560 end;
1563 procedure g_Weapon_punch(x, y: Integer; d, SpawnerUID: Word);
1564 var
1565 obj: TObj;
1566 begin
1567 obj.X := X;
1568 obj.Y := Y;
1569 obj.rect.X := 0;
1570 obj.rect.Y := 0;
1571 obj.rect.Width := 39;
1572 obj.rect.Height := 52;
1573 obj.Vel.X := 0;
1574 obj.Vel.Y := 0;
1575 obj.Accel.X := 0;
1576 obj.Accel.Y := 0;
1578 if g_Weapon_Hit(@obj, d, SpawnerUID, HIT_SOME) <> 0 then
1579 g_Sound_PlayExAt('SOUND_WEAPON_HITPUNCH', x, y)
1580 else
1581 g_Sound_PlayExAt('SOUND_WEAPON_MISSPUNCH', x, y);
1582 end;
1584 function g_Weapon_chainsaw(x, y: Integer; d, SpawnerUID: Word): Integer;
1585 var
1586 obj: TObj;
1587 begin
1588 obj.X := X;
1589 obj.Y := Y;
1590 obj.rect.X := 0;
1591 obj.rect.Y := 0;
1592 obj.rect.Width := 32;
1593 obj.rect.Height := 52;
1594 obj.Vel.X := 0;
1595 obj.Vel.Y := 0;
1596 obj.Accel.X := 0;
1597 obj.Accel.Y := 0;
1599 Result := g_Weapon_Hit(@obj, d, SpawnerUID, HIT_SOME);
1600 end;
1602 procedure g_Weapon_rocket(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1603 Silent: Boolean = False);
1604 var
1605 find_id: DWORD;
1606 dx, dy: Integer;
1607 begin
1608 if WID < 0 then
1609 find_id := FindShot()
1610 else
1611 begin
1612 find_id := WID;
1613 if Integer(find_id) >= High(Shots) then
1614 SetLength(Shots, find_id + 64)
1615 end;
1617 with Shots[find_id] do
1618 begin
1619 g_Obj_Init(@Obj);
1621 Obj.Rect.Width := SHOT_ROCKETLAUNCHER_WIDTH;
1622 Obj.Rect.Height := SHOT_ROCKETLAUNCHER_HEIGHT;
1624 dx := IfThen(xd > x, -Obj.Rect.Width, 0);
1625 dy := -(Obj.Rect.Height div 2);
1627 ShotType := WEAPON_ROCKETLAUNCHER;
1628 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 12);
1630 Animation := nil;
1631 triggers := nil;
1632 end;
1634 Shots[find_id].SpawnerUID := SpawnerUID;
1636 if not Silent then
1637 g_Sound_PlayExAt('SOUND_WEAPON_FIREROCKET', x, y);
1638 end;
1640 procedure g_Weapon_revf(x, y, xd, yd: Integer; SpawnerUID, TargetUID: Word;
1641 WID: Integer = -1; Silent: Boolean = False);
1642 var
1643 find_id: DWORD;
1644 dx, dy: Integer;
1645 begin
1646 if WID < 0 then
1647 find_id := FindShot()
1648 else
1649 begin
1650 find_id := WID;
1651 if Integer(find_id) >= High(Shots) then
1652 SetLength(Shots, find_id + 64)
1653 end;
1655 with Shots[find_id] do
1656 begin
1657 g_Obj_Init(@Obj);
1659 Obj.Rect.Width := SHOT_SKELFIRE_WIDTH;
1660 Obj.Rect.Height := SHOT_SKELFIRE_HEIGHT;
1662 dx := -(Obj.Rect.Width div 2);
1663 dy := -(Obj.Rect.Height div 2);
1665 ShotType := WEAPON_SKEL_FIRE;
1666 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 12);
1668 triggers := nil;
1669 target := TargetUID;
1670 Animation := TAnimationState.Create(True, 5, 2); // !!! put values into table
1671 end;
1673 Shots[find_id].SpawnerUID := SpawnerUID;
1675 if not Silent then
1676 g_Sound_PlayExAt('SOUND_WEAPON_FIREREV', x, y);
1677 end;
1679 procedure g_Weapon_plasma(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1680 Silent: Boolean = False);
1681 var
1682 find_id: DWORD;
1683 dx, dy: Integer;
1684 begin
1685 if WID < 0 then
1686 find_id := FindShot()
1687 else
1688 begin
1689 find_id := WID;
1690 if Integer(find_id) >= High(Shots) then
1691 SetLength(Shots, find_id + 64);
1692 end;
1694 with Shots[find_id] do
1695 begin
1696 g_Obj_Init(@Obj);
1698 Obj.Rect.Width := SHOT_PLASMA_WIDTH;
1699 Obj.Rect.Height := SHOT_PLASMA_HEIGHT;
1701 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1702 dy := -(Obj.Rect.Height div 2);
1704 ShotType := WEAPON_PLASMA;
1705 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1707 triggers := nil;
1708 Animation := TAnimationState.Create(True, 5, 2); // !!! put values into table
1709 end;
1711 Shots[find_id].SpawnerUID := SpawnerUID;
1713 if not Silent then
1714 g_Sound_PlayExAt('SOUND_WEAPON_FIREPLASMA', x, y);
1715 end;
1717 procedure g_Weapon_flame(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1718 Silent: Boolean = False);
1719 var
1720 find_id: DWORD;
1721 dx, dy: Integer;
1722 begin
1723 if WID < 0 then
1724 find_id := FindShot()
1725 else
1726 begin
1727 find_id := WID;
1728 if Integer(find_id) >= High(Shots) then
1729 SetLength(Shots, find_id + 64);
1730 end;
1732 with Shots[find_id] do
1733 begin
1734 g_Obj_Init(@Obj);
1736 Obj.Rect.Width := SHOT_FLAME_WIDTH;
1737 Obj.Rect.Height := SHOT_FLAME_HEIGHT;
1739 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1740 dy := -(Obj.Rect.Height div 2);
1742 ShotType := WEAPON_FLAMETHROWER;
1743 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1745 triggers := nil;
1746 Animation := nil;
1747 end;
1749 Shots[find_id].SpawnerUID := SpawnerUID;
1751 // if not Silent then
1752 // g_Sound_PlayExAt('SOUND_WEAPON_FIREPLASMA', x, y);
1753 end;
1755 procedure g_Weapon_ball1(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1756 Silent: Boolean = False);
1757 var
1758 find_id: DWORD;
1759 dx, dy: Integer;
1760 begin
1761 if WID < 0 then
1762 find_id := FindShot()
1763 else
1764 begin
1765 find_id := WID;
1766 if Integer(find_id) >= High(Shots) then
1767 SetLength(Shots, find_id + 64)
1768 end;
1770 with Shots[find_id] do
1771 begin
1772 g_Obj_Init(@Obj);
1774 Obj.Rect.Width := 16;
1775 Obj.Rect.Height := 16;
1777 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1778 dy := -(Obj.Rect.Height div 2);
1780 ShotType := WEAPON_IMP_FIRE;
1781 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1783 triggers := nil;
1784 Animation := TAnimationState.Create(True, 4, 2); // !!! put values into table
1785 end;
1787 Shots[find_id].SpawnerUID := SpawnerUID;
1789 if not Silent then
1790 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x, y);
1791 end;
1793 procedure g_Weapon_ball2(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1794 Silent: Boolean = False);
1795 var
1796 find_id: DWORD;
1797 dx, dy: Integer;
1798 begin
1799 if WID < 0 then
1800 find_id := FindShot()
1801 else
1802 begin
1803 find_id := WID;
1804 if Integer(find_id) >= High(Shots) then
1805 SetLength(Shots, find_id + 64)
1806 end;
1808 with Shots[find_id] do
1809 begin
1810 g_Obj_Init(@Obj);
1812 Obj.Rect.Width := 16;
1813 Obj.Rect.Height := 16;
1815 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1816 dy := -(Obj.Rect.Height div 2);
1818 ShotType := WEAPON_CACO_FIRE;
1819 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1821 triggers := nil;
1822 Animation := TAnimationState.Create(True, 4, 2); // !!! put values into table
1823 end;
1825 Shots[find_id].SpawnerUID := SpawnerUID;
1827 if not Silent then
1828 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x, y);
1829 end;
1831 procedure g_Weapon_ball7(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1832 Silent: Boolean = False);
1833 var
1834 find_id: DWORD;
1835 dx, dy: Integer;
1836 begin
1837 if WID < 0 then
1838 find_id := FindShot()
1839 else
1840 begin
1841 find_id := WID;
1842 if Integer(find_id) >= High(Shots) then
1843 SetLength(Shots, find_id + 64)
1844 end;
1846 with Shots[find_id] do
1847 begin
1848 g_Obj_Init(@Obj);
1850 Obj.Rect.Width := 32;
1851 Obj.Rect.Height := 16;
1853 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1854 dy := -(Obj.Rect.Height div 2);
1856 ShotType := WEAPON_BARON_FIRE;
1857 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1859 triggers := nil;
1860 Animation := TAnimationState.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_aplasma(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1870 Silent: Boolean = False);
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 := 16;
1889 Obj.Rect.Height := 16;
1891 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1892 dy := -(Obj.Rect.Height div 2);
1894 ShotType := WEAPON_BSP_FIRE;
1895 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1897 triggers := nil;
1899 Animation := TAnimationState.Create(True, 4, 2); // !!! put values into table
1900 end;
1902 Shots[find_id].SpawnerUID := SpawnerUID;
1904 if not Silent then
1905 g_Sound_PlayExAt('SOUND_WEAPON_FIREPLASMA', x, y);
1906 end;
1908 procedure g_Weapon_manfire(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1909 Silent: Boolean = False);
1910 var
1911 find_id: DWORD;
1912 dx, dy: Integer;
1913 begin
1914 if WID < 0 then
1915 find_id := FindShot()
1916 else
1917 begin
1918 find_id := WID;
1919 if Integer(find_id) >= High(Shots) then
1920 SetLength(Shots, find_id + 64)
1921 end;
1923 with Shots[find_id] do
1924 begin
1925 g_Obj_Init(@Obj);
1927 Obj.Rect.Width := 32;
1928 Obj.Rect.Height := 32;
1930 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1931 dy := -(Obj.Rect.Height div 2);
1933 ShotType := WEAPON_MANCUB_FIRE;
1934 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1936 triggers := nil;
1938 Animation := TAnimationState.Create(True, 4, 2); // !!! put values into table
1939 end;
1941 Shots[find_id].SpawnerUID := SpawnerUID;
1943 if not Silent then
1944 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x, y);
1945 end;
1947 procedure g_Weapon_bfgshot(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1948 Silent: Boolean = False);
1949 var
1950 find_id: DWORD;
1951 dx, dy: Integer;
1952 begin
1953 if WID < 0 then
1954 find_id := FindShot()
1955 else
1956 begin
1957 find_id := WID;
1958 if Integer(find_id) >= High(Shots) then
1959 SetLength(Shots, find_id + 64)
1960 end;
1962 with Shots[find_id] do
1963 begin
1964 g_Obj_Init(@Obj);
1966 Obj.Rect.Width := SHOT_BFG_WIDTH;
1967 Obj.Rect.Height := SHOT_BFG_HEIGHT;
1969 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1970 dy := -(Obj.Rect.Height div 2);
1972 ShotType := WEAPON_BFG;
1973 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1975 triggers := nil;
1976 Animation := TAnimationState.Create(True, 6, 2); // !!! put values into table
1977 end;
1979 Shots[find_id].SpawnerUID := SpawnerUID;
1981 if not Silent then
1982 g_Sound_PlayExAt('SOUND_WEAPON_FIREBFG', x, y);
1983 end;
1985 procedure g_Weapon_bfghit(x, y: Integer);
1986 begin
1987 r_GFX_OnceAnim(R_GFX_BFG_HIT, x - 32, y - 32);
1988 end;
1990 procedure g_Weapon_pistol(x, y, xd, yd: Integer; SpawnerUID: Word;
1991 Silent: Boolean = False);
1992 begin
1993 if not Silent then
1994 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', x, y);
1996 g_Weapon_gun(x, y, xd, yd, 1, 3, SpawnerUID, True);
1997 if gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF] then
1998 begin
1999 g_Weapon_gun(x, y+1, xd, yd+1, 1, 3, SpawnerUID, False);
2000 g_Weapon_gun(x, y-1, xd, yd-1, 1, 2, SpawnerUID, False);
2001 end;
2002 end;
2004 procedure g_Weapon_mgun(x, y, xd, yd: Integer; SpawnerUID: Word;
2005 Silent: Boolean = False);
2006 begin
2007 if not Silent then
2008 if gSoundEffectsDF then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', x, y);
2010 g_Weapon_gun(x, y, xd, yd, 1, 3, SpawnerUID, True);
2011 if (gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF]) and
2012 (g_GetUIDType(SpawnerUID) = UID_PLAYER) then
2013 begin
2014 g_Weapon_gun(x, y+1, xd, yd+1, 1, 2, SpawnerUID, False);
2015 g_Weapon_gun(x, y-1, xd, yd-1, 1, 2, SpawnerUID, False);
2016 end;
2017 end;
2019 procedure g_Weapon_shotgun(x, y, xd, yd: Integer; SpawnerUID: Word;
2020 Silent: Boolean = False);
2021 var
2022 i, j: Integer;
2023 begin
2024 if not Silent then
2025 if gSoundEffectsDF then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', x, y);
2027 for i := 0 to 9 do
2028 begin
2029 j := Random(17)-8; // -8 .. 8
2030 g_Weapon_gun(x, y+j, xd, yd+j, IfThen(i mod 2 <> 0, 1, 0), 3, SpawnerUID, i=0);
2031 end;
2032 end;
2034 procedure g_Weapon_dshotgun(x, y, xd, yd: Integer; SpawnerUID: Word;
2035 Silent: Boolean = False);
2036 var
2037 a, i, j: Integer;
2038 begin
2039 if not Silent then
2040 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', x, y);
2042 if gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF] then a := 25 else a := 20;
2043 for i := 0 to a do
2044 begin
2045 j := Random(41)-20; // -20 .. 20
2046 g_Weapon_gun(x, y+j, xd, yd+j, IfThen(i mod 3 <> 0, 0, 1), 3, SpawnerUID, i=0);
2047 end;
2048 end;
2050 procedure g_Weapon_PreUpdate();
2051 var
2052 i: Integer;
2053 begin
2054 if Shots = nil then Exit;
2055 for i := 0 to High(Shots) do
2056 if Shots[i].ShotType <> 0 then
2057 begin
2058 Shots[i].Obj.oldX := Shots[i].Obj.X;
2059 Shots[i].Obj.oldY := Shots[i].Obj.Y;
2060 end;
2061 end;
2063 procedure g_Weapon_Update();
2064 var
2065 i, a, h, cx, cy, oldvx, oldvy, tf: Integer;
2066 t: DWArray;
2067 st: Word;
2068 o: TObj;
2069 spl: Boolean;
2070 Loud: Boolean;
2071 tcx, tcy: Integer;
2072 begin
2073 if Shots = nil then
2074 Exit;
2076 for i := 0 to High(Shots) do
2077 begin
2078 if Shots[i].ShotType = 0 then
2079 Continue;
2081 Loud := True;
2083 with Shots[i] do
2084 begin
2085 Timeout := Timeout - 1;
2086 oldvx := Obj.Vel.X;
2087 oldvy := Obj.Vel.Y;
2088 // Àêòèâèðîâàòü òðèããåðû ïî ïóòè (êðîìå óæå àêòèâèðîâàííûõ):
2089 if (Stopped = 0) and g_Game_IsServer then
2090 t := g_Triggers_PressR(Obj.X, Obj.Y, Obj.Rect.Width, Obj.Rect.Height,
2091 SpawnerUID, ACTIVATE_SHOT, triggers)
2092 else
2093 t := nil;
2095 if t <> nil then
2096 begin
2097 // Ïîïîëíÿåì ñïèñîê àêòèâèðîâàííûõ òðèããåðîâ:
2098 if triggers = nil then
2099 triggers := t
2100 else
2101 begin
2102 h := High(t);
2104 for a := 0 to h do
2105 if not InDWArray(t[a], triggers) then
2106 begin
2107 SetLength(triggers, Length(triggers)+1);
2108 triggers[High(triggers)] := t[a];
2109 end;
2110 end;
2111 end;
2113 // Àíèìàöèÿ ñíàðÿäà:
2114 if Animation <> nil then
2115 Animation.Update();
2117 // Äâèæåíèå:
2118 spl := (ShotType <> WEAPON_PLASMA) and
2119 (ShotType <> WEAPON_BFG) and
2120 (ShotType <> WEAPON_BSP_FIRE) and
2121 (ShotType <> WEAPON_FLAMETHROWER);
2123 if Stopped = 0 then
2124 begin
2125 st := g_Obj_Move_Projectile(@Obj, False, spl);
2126 end
2127 else
2128 begin
2129 st := 0;
2130 end;
2131 positionChanged(); // this updates spatial accelerators
2133 if WordBool(st and MOVE_FALLOUT) or (Obj.X < -1000) or
2134 (Obj.X > gMapInfo.Width+1000) or (Obj.Y < -1000) then
2135 begin
2136 // Íà êëèåíòå ñêîðåå âñåãî è òàê óæå âûïàë.
2137 ShotType := 0;
2138 Animation.Free();
2139 Continue;
2140 end;
2142 cx := Obj.X + (Obj.Rect.Width div 2);
2143 cy := Obj.Y + (Obj.Rect.Height div 2);
2145 case ShotType of
2146 WEAPON_ROCKETLAUNCHER, WEAPON_SKEL_FIRE: // Ðàêåòû è ñíàðÿäû Ñêåëåòà
2147 begin
2148 // Âûëåòåëà èç âîäû:
2149 if WordBool(st and MOVE_HITAIR) then
2150 g_Obj_SetSpeed(@Obj, 12);
2152 // Â âîäå øëåéô - ïóçûðè, â âîçäóõå øëåéô - äûì:
2153 if WordBool(st and MOVE_INWATER) then
2154 g_GFX_Bubbles(Obj.X+(Obj.Rect.Width div 2),
2155 Obj.Y+(Obj.Rect.Height div 2),
2156 1+Random(3), 16, 16)
2157 else
2158 r_GFX_OnceAnim(R_GFX_SMOKE_TRANS, Obj.X-14+Random(9), Obj.Y+(Obj.Rect.Height div 2)-20+Random(9));
2160 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2161 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL)) or
2162 (g_Weapon_Hit(@Obj, 10, SpawnerUID, HIT_SOME, False) <> 0) or
2163 (Timeout < 1) then
2164 begin
2165 Obj.Vel.X := 0;
2166 Obj.Vel.Y := 0;
2168 g_Weapon_Explode(cx, cy, 60, SpawnerUID);
2170 if ShotType = WEAPON_SKEL_FIRE then
2171 begin // Âçðûâ ñíàðÿäà Ñêåëåòà
2172 r_GFX_OnceAnim(R_GFX_EXPLODE_SKELFIRE, Obj.X + 32 - 58, Obj.Y + 8 - 36);
2173 g_DynLightExplosion((Obj.X+32), (Obj.Y+8), 64, 1, 0, 0);
2174 end
2175 else
2176 begin // Âçðûâ Ðàêåòû
2177 r_GFX_OnceAnim(R_GFX_EXPLODE_ROCKET, cx - 64, cy - 64);
2178 g_DynLightExplosion(cx, cy, 64, 1, 0, 0);
2179 end;
2181 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', Obj.X, Obj.Y);
2183 ShotType := 0;
2184 end;
2186 if ShotType = WEAPON_SKEL_FIRE then
2187 begin // Ñàìîíàâîäêà ñíàðÿäà Ñêåëåòà:
2188 if GetPos(target, @o) then
2189 throw(i, Obj.X, Obj.Y,
2190 o.X+o.Rect.X+(o.Rect.Width div 2)+o.Vel.X+o.Accel.X,
2191 o.Y+o.Rect.Y+(o.Rect.Height div 2)+o.Vel.Y+o.Accel.Y,
2192 12);
2193 end;
2194 end;
2196 WEAPON_PLASMA, WEAPON_BSP_FIRE: // Ïëàçìà, ïëàçìà Àðàõíàòðîíà
2197 begin
2198 // Ïîïàëà â âîäó - ýëåêòðîøîê ïî âîäå:
2199 if WordBool(st and (MOVE_INWATER or MOVE_HITWATER)) then
2200 begin
2201 g_Sound_PlayExAt('SOUND_WEAPON_PLASMAWATER', Obj.X, Obj.Y);
2202 if g_Game_IsServer then CheckTrap(i, 10, HIT_ELECTRO);
2203 ShotType := 0;
2204 Continue;
2205 end;
2207 // Âåëè÷èíà óðîíà:
2208 if (ShotType = WEAPON_PLASMA) and
2209 (gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF]) then
2210 a := 10
2211 else
2212 a := 5;
2214 if ShotType = WEAPON_BSP_FIRE then
2215 a := 10;
2217 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2218 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL)) or
2219 (g_Weapon_Hit(@Obj, a, SpawnerUID, HIT_SOME, False) <> 0) or
2220 (Timeout < 1) then
2221 begin
2222 if ShotType = WEAPON_PLASMA then
2223 r_GFX_OnceAnim(R_GFX_EXPLODE_PLASMA, cx - 16, cy - 16)
2224 else
2225 r_GFX_OnceAnim(R_GFX_EXPLODE_BSPFIRE, cx - 16, cy - 16);
2226 g_DynLightExplosion(cx, cy, 32, 0, 0.5, 0.5);
2227 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEPLASMA', Obj.X, Obj.Y);
2228 ShotType := 0;
2229 end;
2230 end;
2232 WEAPON_FLAMETHROWER: // Îãíåìåò
2233 begin
2234 // Ñî âðåìåíåì óìèðàåò
2235 if (Timeout < 1) then
2236 begin
2237 ShotType := 0;
2238 Continue;
2239 end;
2240 // Ïîä âîäîé òîæå
2241 if WordBool(st and (MOVE_HITWATER or MOVE_INWATER)) then
2242 begin
2243 if WordBool(st and MOVE_HITWATER) then
2244 begin
2245 tcx := Random(8);
2246 tcy := Random(8);
2247 r_GFX_OnceAnim(R_GFX_SMOKE, cx-4+tcx-(R_GFX_SMOKE_WIDTH div 2), cy-4+tcy-(R_GFX_SMOKE_HEIGHT div 2));
2248 end
2249 else
2250 g_GFX_Bubbles(cx, cy, 1+Random(3), 16, 16);
2251 ShotType := 0;
2252 Continue;
2253 end;
2255 // Ãðàâèòàöèÿ
2256 if Stopped = 0 then
2257 Obj.Accel.Y := Obj.Accel.Y + 1;
2258 // Ïîïàëè â ñòåíó èëè â âîäó:
2259 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL or MOVE_HITWATER)) then
2260 begin
2261 // Ïðèëèïàåì:
2262 Obj.Vel.X := 0;
2263 Obj.Vel.Y := 0;
2264 Obj.Accel.Y := 0;
2265 if WordBool(st and MOVE_HITWALL) then
2266 Stopped := MOVE_HITWALL
2267 else if WordBool(st and MOVE_HITLAND) then
2268 Stopped := MOVE_HITLAND
2269 else if WordBool(st and MOVE_HITCEIL) then
2270 Stopped := MOVE_HITCEIL;
2271 end;
2273 a := IfThen(Stopped = 0, 10, 1);
2274 // Åñëè â êîãî-òî ïîïàëè
2275 if g_Weapon_Hit(@Obj, a, SpawnerUID, HIT_FLAME, False) <> 0 then
2276 begin
2277 // HIT_FLAME ñàì ïîäîææåò
2278 // Åñëè â ïîëåòå ïîïàëè, èñ÷åçàåì
2279 if Stopped = 0 then
2280 ShotType := 0;
2281 end;
2283 if Stopped = 0 then
2284 tf := 2
2285 else
2286 tf := 3;
2288 if (gTime mod LongWord(tf) = 0) then
2289 begin
2290 case Stopped of
2291 MOVE_HITWALL: begin tcx := cx-4+Random(8); tcy := cy-12+Random(24); end;
2292 MOVE_HITLAND: begin tcx := cx-12+Random(24); tcy := cy-10+Random(8); end;
2293 MOVE_HITCEIL: begin tcx := cx-12+Random(24); tcy := cy+6+Random(8); end;
2294 else begin tcx := cx-4+Random(8); tcy := cy-4+Random(8); end;
2295 end;
2296 r_GFX_OnceAnim(R_GFX_FLAME_RAND, tcx - (R_GFX_FLAME_WIDTH div 2), tcy - (R_GFX_FLAME_HEIGHT div 2));
2297 //g_DynLightExplosion(tcx, tcy, 1, 1, 0.8, 0.3);
2298 end;
2299 end;
2301 WEAPON_BFG: // BFG
2302 begin
2303 // Ïîïàëà â âîäó - ýëåêòðîøîê ïî âîäå:
2304 if WordBool(st and (MOVE_INWATER or MOVE_HITWATER)) then
2305 begin
2306 g_Sound_PlayExAt('SOUND_WEAPON_BFGWATER', Obj.X, Obj.Y);
2307 if g_Game_IsServer then CheckTrap(i, 1000, HIT_ELECTRO);
2308 ShotType := 0;
2309 Continue;
2310 end;
2312 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2313 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL)) or
2314 (g_Weapon_Hit(@Obj, SHOT_BFG_DAMAGE, SpawnerUID, HIT_BFG, False) <> 0) or
2315 (Timeout < 1) then
2316 begin
2317 // Ëó÷è BFG:
2318 if g_Game_IsServer then g_Weapon_BFG9000(cx, cy, SpawnerUID);
2319 r_GFX_OnceAnim(R_GFX_EXPLODE_BFG, cx - 64, cy - 64);
2320 g_DynLightExplosion(cx, cy, 96, 0, 1, 0);
2321 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', Obj.X, Obj.Y);
2322 ShotType := 0;
2323 end;
2324 end;
2326 WEAPON_IMP_FIRE, WEAPON_CACO_FIRE, WEAPON_BARON_FIRE: // Âûñòðåëû Áåñà, Êàêîäåìîíà Ðûöàðÿ/Áàðîíà àäà
2327 begin
2328 // Âûëåòåë èç âîäû:
2329 if WordBool(st and MOVE_HITAIR) then
2330 g_Obj_SetSpeed(@Obj, 16);
2332 // Âåëè÷èíà óðîíà:
2333 if ShotType = WEAPON_IMP_FIRE then
2334 a := 5
2335 else
2336 if ShotType = WEAPON_CACO_FIRE then
2337 a := 20
2338 else
2339 a := 40;
2341 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2342 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL)) or
2343 (g_Weapon_Hit(@Obj, a, SpawnerUID, HIT_SOME) <> 0) or
2344 (Timeout < 1) then
2345 begin
2346 case ShotType of
2347 WEAPON_IMP_FIRE: r_GFX_OnceAnim(R_GFX_EXPLODE_IMPFIRE, cx - 32, cy - 32);
2348 WEAPON_CACO_FIRE: r_GFX_OnceAnim(R_GFX_EXPLODE_CACOFIRE, cx - 32, cy - 32);
2349 WEAPON_BARON_FIRE: r_GFX_OnceAnim(R_GFX_EXPLODE_BARONFIRE, cx - 32, cy - 32);
2350 end;
2351 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj.X, Obj.Y);
2352 ShotType := 0;
2353 end;
2354 end;
2356 WEAPON_MANCUB_FIRE: // Âûñòðåë Ìàíêóáóñà
2357 begin
2358 // Âûëåòåë èç âîäû:
2359 if WordBool(st and MOVE_HITAIR) then
2360 g_Obj_SetSpeed(@Obj, 16);
2362 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2363 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL)) or
2364 (g_Weapon_Hit(@Obj, 40, SpawnerUID, HIT_SOME, False) <> 0) or
2365 (Timeout < 1) then
2366 begin
2367 // Âçðûâ:
2368 r_GFX_OnceAnim(R_GFX_EXPLODE_ROCKET, cx - 64, cy - 64);
2369 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj.X, Obj.Y);
2370 ShotType := 0;
2371 end;
2372 end;
2373 end; // case ShotType of...
2375 // Åñëè ñíàðÿäà óæå íåò, óäàëÿåì àíèìàöèþ:
2376 if (ShotType = 0) then
2377 begin
2378 if gGameSettings.GameType = GT_SERVER then
2379 MH_SEND_DeleteShot(i, Obj.X, Obj.Y, Loud);
2380 if Animation <> nil then
2381 begin
2382 Animation.Free();
2383 Animation := nil;
2384 end;
2385 end
2386 else if (ShotType <> WEAPON_FLAMETHROWER) and ((oldvx <> Obj.Vel.X) or (oldvy <> Obj.Vel.Y)) then
2387 if gGameSettings.GameType = GT_SERVER then
2388 MH_SEND_UpdateShot(i);
2389 end;
2390 end;
2391 end;
2393 function g_Weapon_Danger(UID: Word; X, Y: Integer; Width, Height: Word; Time: Byte): Boolean;
2394 var
2395 a: Integer;
2396 begin
2397 Result := False;
2399 if Shots = nil then
2400 Exit;
2402 for a := 0 to High(Shots) do
2403 if (Shots[a].ShotType <> 0) and (Shots[a].SpawnerUID <> UID) then
2404 if ((Shots[a].Obj.Vel.Y = 0) and (Shots[a].Obj.Vel.X > 0) and (Shots[a].Obj.X < X)) or
2405 (Shots[a].Obj.Vel.Y = 0) and (Shots[a].Obj.Vel.X < 0) and (Shots[a].Obj.X > X) then
2406 if (Abs(X-Shots[a].Obj.X) < Abs(Shots[a].Obj.Vel.X*Time)) and
2407 g_Collide(X, Y, Width, Height, X, Shots[a].Obj.Y,
2408 Shots[a].Obj.Rect.Width, Shots[a].Obj.Rect.Height) and
2409 g_TraceVector(X, Y, Shots[a].Obj.X, Shots[a].Obj.Y) then
2410 begin
2411 Result := True;
2412 Exit;
2413 end;
2414 end;
2416 procedure g_Weapon_SaveState (st: TStream);
2417 var
2418 count, i, j: Integer;
2419 begin
2420 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ ñíàðÿäîâ
2421 count := 0;
2422 for i := 0 to High(Shots) do if (Shots[i].ShotType <> 0) then Inc(count);
2424 // Êîëè÷åñòâî ñíàðÿäîâ
2425 utils.WriteInt(st, count);
2427 if (count = 0) then exit;
2429 for i := 0 to High(Shots) do
2430 begin
2431 if Shots[i].ShotType <> 0 then
2432 begin
2433 // Ñèãíàòóðà ñíàðÿäà
2434 utils.writeSign(st, 'SHOT');
2435 utils.writeInt(st, Byte(0)); // version
2436 // Òèï ñíàðÿäà
2437 utils.writeInt(st, Byte(Shots[i].ShotType));
2438 // Öåëü
2439 utils.writeInt(st, Word(Shots[i].Target));
2440 // UID ñòðåëÿâøåãî
2441 utils.writeInt(st, Word(Shots[i].SpawnerUID));
2442 // Ðàçìåð ïîëÿ Triggers
2443 utils.writeInt(st, Integer(Length(Shots[i].Triggers)));
2444 // Òðèããåðû, àêòèâèðîâàííûå âûñòðåëîì
2445 for j := 0 to Length(Shots[i].Triggers)-1 do utils.writeInt(st, LongWord(Shots[i].Triggers[j]));
2446 // Îáúåêò ñíàðÿäà
2447 Obj_SaveState(st, @Shots[i].Obj);
2448 // Êîñòûëèíà åáàíàÿ
2449 utils.writeInt(st, Byte(Shots[i].Stopped));
2450 end;
2451 end;
2452 end;
2454 procedure g_Weapon_LoadState (st: TStream);
2455 var
2456 count, tc, i, j: Integer;
2457 begin
2458 if (st = nil) then exit;
2460 // Êîëè÷åñòâî ñíàðÿäîâ
2461 count := utils.readLongInt(st);
2462 if (count < 0) or (count > 1024*1024) then raise XStreamError.Create('invalid shots counter');
2464 SetLength(Shots, count);
2466 if (count = 0) then exit;
2468 for i := 0 to count-1 do
2469 begin
2470 // Ñèãíàòóðà ñíàðÿäà
2471 if not utils.checkSign(st, 'SHOT') then raise XStreamError.Create('invalid shot signature');
2472 if (utils.readByte(st) <> 0) then raise XStreamError.Create('invalid shot version');
2473 // Òèï ñíàðÿäà:
2474 Shots[i].ShotType := utils.readByte(st);
2475 // Öåëü
2476 Shots[i].Target := utils.readWord(st);
2477 // UID ñòðåëÿâøåãî
2478 Shots[i].SpawnerUID := utils.readWord(st);
2479 // Ðàçìåð ïîëÿ Triggers
2480 tc := utils.readLongInt(st);
2481 if (tc < 0) or (tc > 1024*1024) then raise XStreamError.Create('invalid shot triggers counter');
2482 SetLength(Shots[i].Triggers, tc);
2483 // Òðèããåðû, àêòèâèðîâàííûå âûñòðåëîì
2484 for j := 0 to tc-1 do Shots[i].Triggers[j] := utils.readLongWord(st);
2485 // Îáúåêò ïðåäìåòà
2486 Obj_LoadState(@Shots[i].Obj, st);
2487 // Êîñòûëèíà åáàíàÿ
2488 Shots[i].Stopped := utils.readByte(st);
2490 // Óñòàíîâêà òåêñòóðû èëè àíèìàöèè
2491 Shots[i].Animation := nil;
2493 case Shots[i].ShotType of
2494 WEAPON_ROCKETLAUNCHER, WEAPON_SKEL_FIRE:
2495 begin
2496 end;
2497 WEAPON_PLASMA:
2498 begin
2499 Shots[i].Animation := TAnimationState.Create(True, 5, 2); // !!! put values into table
2500 end;
2501 WEAPON_BFG:
2502 begin
2503 Shots[i].Animation := TAnimationState.Create(True, 6, 2); // !!! put values into table
2504 end;
2505 WEAPON_IMP_FIRE:
2506 begin
2507 Shots[i].Animation := TAnimationState.Create(True, 4, 2); // !!! put values into table
2508 end;
2509 WEAPON_BSP_FIRE:
2510 begin
2511 Shots[i].Animation := TAnimationState.Create(True, 4, 2); // !!! put values into table
2512 end;
2513 WEAPON_CACO_FIRE:
2514 begin
2515 Shots[i].Animation := TAnimationState.Create(True, 4, 2); // !!! put values into table
2516 end;
2517 WEAPON_BARON_FIRE:
2518 begin
2519 Shots[i].Animation := TAnimationState.Create(True, 4, 2); // !!! put values into table
2520 end;
2521 WEAPON_MANCUB_FIRE:
2522 begin
2523 Shots[i].Animation := TAnimationState.Create(True, 4, 2); // !!! put values into table
2524 end;
2525 end;
2526 end;
2527 end;
2529 procedure g_Weapon_DestroyShot(I: Integer; X, Y: Integer; Loud: Boolean = True);
2530 var cx, cy: Integer;
2531 begin
2532 if Shots = nil then
2533 Exit;
2534 if (I > High(Shots)) or (I < 0) then Exit;
2536 with Shots[I] do
2537 begin
2538 if ShotType = 0 then Exit;
2539 Obj.X := X;
2540 Obj.Y := Y;
2541 cx := Obj.X + (Obj.Rect.Width div 2);
2542 cy := Obj.Y + (Obj.Rect.Height div 2);
2544 case ShotType of
2545 WEAPON_ROCKETLAUNCHER, WEAPON_SKEL_FIRE: // Ðàêåòû è ñíàðÿäû Ñêåëåòà
2546 begin
2547 if Loud then
2548 begin
2549 if ShotType = WEAPON_SKEL_FIRE then
2550 r_GFX_OnceAnim(R_GFX_EXPLODE_SKELFIRE, (Obj.X + 32) - 32, (Obj.Y + 8) - 32)
2551 else
2552 r_GFX_OnceAnim(R_GFX_EXPLODE_ROCKET, cx - 64, cy - 64);
2553 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', Obj.X, Obj.Y);
2554 end;
2555 end;
2557 WEAPON_PLASMA, WEAPON_BSP_FIRE: // Ïëàçìà, ïëàçìà Àðàõíàòðîíà
2558 begin
2559 if loud then
2560 begin
2561 if ShotType = WEAPON_PLASMA then
2562 r_GFX_OnceAnim(R_GFX_EXPLODE_PLASMA, cx - 16, cy - 16)
2563 else
2564 r_GFX_OnceAnim(R_GFX_EXPLODE_BSPFIRE, cx - 16, cy - 16);
2565 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEPLASMA', Obj.X, Obj.Y);
2566 end;
2567 end;
2569 WEAPON_BFG: // BFG
2570 begin
2571 r_GFX_OnceAnim(R_GFX_EXPLODE_BFG, cx - 64, cy - 64);
2572 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', Obj.X, Obj.Y);
2573 end;
2575 WEAPON_IMP_FIRE, WEAPON_CACO_FIRE, WEAPON_BARON_FIRE: // Âûñòðåëû Áåñà, Êàêîäåìîíà Ðûöàðÿ/Áàðîíà àäà
2576 begin
2577 if loud then
2578 begin
2579 case ShotType of
2580 WEAPON_IMP_FIRE: r_GFX_OnceAnim(R_GFX_EXPLODE_IMPFIRE, cx - 32, cy - 32);
2581 WEAPON_CACO_FIRE: r_GFX_OnceAnim(R_GFX_EXPLODE_CACOFIRE, cx - 32, cy - 32);
2582 WEAPON_BARON_FIRE: r_GFX_OnceAnim(R_GFX_EXPLODE_BARONFIRE, cx - 32, cy - 32);
2583 end;
2584 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj.X, Obj.Y);
2585 end;
2586 end;
2588 WEAPON_MANCUB_FIRE: // Âûñòðåë Ìàíêóáóñà
2589 begin
2590 r_GFX_OnceAnim(R_GFX_EXPLODE_ROCKET, cx - 64, cy - 64);
2591 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj.X, Obj.Y);
2592 end;
2593 end; // case ShotType of...
2595 ShotType := 0;
2596 Animation.Free();
2597 end;
2598 end;
2601 procedure g_Weapon_AddDynLights();
2602 var
2603 i: Integer;
2604 begin
2605 if Shots = nil then Exit;
2606 for i := 0 to High(Shots) do
2607 begin
2608 if Shots[i].ShotType = 0 then continue;
2609 if (Shots[i].ShotType = WEAPON_ROCKETLAUNCHER) or
2610 (Shots[i].ShotType = WEAPON_BARON_FIRE) or
2611 (Shots[i].ShotType = WEAPON_MANCUB_FIRE) or
2612 (Shots[i].ShotType = WEAPON_SKEL_FIRE) or
2613 (Shots[i].ShotType = WEAPON_IMP_FIRE) or
2614 (Shots[i].ShotType = WEAPON_CACO_FIRE) or
2615 (Shots[i].ShotType = WEAPON_MANCUB_FIRE) or
2616 (Shots[i].ShotType = WEAPON_BSP_FIRE) or
2617 (Shots[i].ShotType = WEAPON_PLASMA) or
2618 (Shots[i].ShotType = WEAPON_BFG) or
2619 (Shots[i].ShotType = WEAPON_FLAMETHROWER) or
2620 false then
2621 begin
2622 if (Shots[i].ShotType = WEAPON_PLASMA) then
2623 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)
2624 else if (Shots[i].ShotType = WEAPON_BFG) then
2625 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)
2626 else if (Shots[i].ShotType = WEAPON_FLAMETHROWER) then
2627 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)
2628 else
2629 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);
2630 end;
2631 end;
2632 end;
2635 procedure TShot.positionChanged (); begin end;
2638 end.