DEADSOFTWARE

Player: Propagate valid SpawnerUID for corpse kills
[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, e_graphics, 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: TAnimation;
34 TextureID: DWORD;
35 Timeout: DWORD;
36 Stopped: Byte;
38 procedure positionChanged (); //WARNING! call this after monster position was changed, or coldet will not work right!
39 end;
42 var
43 Shots: array of TShot = nil;
44 LastShotID: Integer = 0;
46 procedure g_Weapon_LoadData();
47 procedure g_Weapon_FreeData();
48 procedure g_Weapon_Init();
49 procedure g_Weapon_Free();
50 function g_Weapon_Hit(obj: PObj; d: Integer; SpawnerUID: Word; t: Byte; HitCorpses: Boolean = True): Byte;
51 function g_Weapon_HitUID(UID: Word; d: Integer; SpawnerUID: Word; t: Byte): Boolean;
52 function g_Weapon_CreateShot(I: Integer; ShotType: Byte; Spawner, TargetUID: Word; X, Y, XV, YV: Integer): LongWord;
54 procedure g_Weapon_gun(const x, y, xd, yd, v, dmg: Integer; SpawnerUID: Word; CheckTrigger: Boolean);
55 procedure g_Weapon_punch(x, y: Integer; d, SpawnerUID: Word);
56 function g_Weapon_chainsaw(x, y: Integer; d, SpawnerUID: Word): Integer;
57 procedure g_Weapon_rocket(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1; Silent: Boolean = False);
58 procedure g_Weapon_revf(x, y, xd, yd: Integer; SpawnerUID, TargetUID: Word; WID: Integer = -1; Silent: Boolean = False);
59 procedure g_Weapon_flame(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1; Silent: Boolean = False);
60 procedure g_Weapon_plasma(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1; Silent: Boolean = False);
61 procedure g_Weapon_ball1(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1; Silent: Boolean = False);
62 procedure g_Weapon_ball2(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1; Silent: Boolean = False);
63 procedure g_Weapon_ball7(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1; Silent: Boolean = False);
64 procedure g_Weapon_aplasma(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1; Silent: Boolean = False);
65 procedure g_Weapon_manfire(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1; Silent: Boolean = False);
66 procedure g_Weapon_bfgshot(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1; Silent: Boolean = False);
67 procedure g_Weapon_bfghit(x, y: Integer);
68 procedure g_Weapon_pistol(x, y, xd, yd: Integer; SpawnerUID: Word; Silent: Boolean = False);
69 procedure g_Weapon_mgun(x, y, xd, yd: Integer; SpawnerUID: Word; Silent: Boolean = False);
70 procedure g_Weapon_shotgun(x, y, xd, yd: Integer; SpawnerUID: Word; Silent: Boolean = False);
71 procedure g_Weapon_dshotgun(x, y, xd, yd: Integer; SpawnerUID: Word; Silent: Boolean = False);
73 function g_Weapon_Explode(X, Y: Integer; rad: Integer; SpawnerUID: Word): Boolean;
74 procedure g_Weapon_BFG9000(X, Y: Integer; SpawnerUID: Word);
75 procedure g_Weapon_PreUpdate();
76 procedure g_Weapon_Update();
77 procedure g_Weapon_Draw();
78 function g_Weapon_Danger(UID: Word; X, Y: Integer; Width, Height: Word; Time: Byte): Boolean;
79 procedure g_Weapon_DestroyShot(I: Integer; X, Y: Integer; Loud: Boolean = True);
81 procedure g_Weapon_SaveState (st: TStream);
82 procedure g_Weapon_LoadState (st: TStream);
84 procedure g_Weapon_AddDynLights();
86 const
87 WEAPON_KASTET = 0;
88 WEAPON_SAW = 1;
89 WEAPON_PISTOL = 2;
90 WEAPON_SHOTGUN1 = 3;
91 WEAPON_SHOTGUN2 = 4;
92 WEAPON_CHAINGUN = 5;
93 WEAPON_ROCKETLAUNCHER = 6;
94 WEAPON_PLASMA = 7;
95 WEAPON_BFG = 8;
96 WEAPON_SUPERPULEMET = 9;
97 WEAPON_FLAMETHROWER = 10;
98 WEAPON_ZOMBY_PISTOL = 20;
99 WEAPON_IMP_FIRE = 21;
100 WEAPON_BSP_FIRE = 22;
101 WEAPON_CACO_FIRE = 23;
102 WEAPON_BARON_FIRE = 24;
103 WEAPON_MANCUB_FIRE = 25;
104 WEAPON_SKEL_FIRE = 26;
106 WP_FIRST = WEAPON_KASTET;
107 WP_LAST = WEAPON_FLAMETHROWER;
110 var
111 gwep_debug_fast_trace: Boolean = true;
114 implementation
116 uses
117 Math, g_map, g_player, g_gfx, g_sound, g_main, g_panel,
118 g_console, g_options, g_game,
119 g_triggers, MAPDEF, e_log, g_monsters, g_saveload,
120 g_language, g_netmsg, g_grid,
121 geom, binheap, hashtable, utils, xstreams;
123 type
124 TWaterPanel = record
125 X, Y: Integer;
126 Width, Height: Word;
127 Active: Boolean;
128 end;
130 const
131 SHOT_ROCKETLAUNCHER_WIDTH = 14;
132 SHOT_ROCKETLAUNCHER_HEIGHT = 14;
134 SHOT_SKELFIRE_WIDTH = 14;
135 SHOT_SKELFIRE_HEIGHT = 14;
137 SHOT_PLASMA_WIDTH = 16;
138 SHOT_PLASMA_HEIGHT = 16;
140 SHOT_BFG_WIDTH = 32;
141 SHOT_BFG_HEIGHT = 32;
142 SHOT_BFG_DAMAGE = 100;
143 SHOT_BFG_RADIUS = 256;
145 SHOT_FLAME_WIDTH = 4;
146 SHOT_FLAME_HEIGHT = 4;
147 SHOT_FLAME_LIFETIME = 180;
149 SHOT_SIGNATURE = $544F4853; // 'SHOT'
151 type
152 PHitTime = ^THitTime;
153 THitTime = record
154 distSq: Integer;
155 mon: TMonster;
156 plridx: Integer; // if mon=nil
157 x, y: Integer;
158 end;
160 TBinHeapKeyHitTime = class
161 public
162 class function less (const a, b: Integer): Boolean; inline;
163 end;
165 // indicies in `wgunHitTime` array
166 TBinaryHeapHitTimes = specialize TBinaryHeapBase<Integer, TBinHeapKeyHitTime>;
168 var
169 WaterMap: array of array of DWORD = nil;
170 //wgunMonHash: THashIntInt = nil;
171 wgunHitHeap: TBinaryHeapHitTimes = nil;
172 wgunHitTime: array of THitTime = nil;
173 wgunHitTimeUsed: Integer = 0;
176 class function TBinHeapKeyHitTime.less (const a, b: Integer): Boolean;
177 var
178 hta, htb: PHitTime;
179 begin
180 hta := @wgunHitTime[a];
181 htb := @wgunHitTime[b];
182 if (hta.distSq <> htb.distSq) then begin result := (hta.distSq < htb.distSq); exit; end;
183 if (hta.mon <> nil) then
184 begin
185 // a is monster
186 if (htb.mon = nil) then begin result := false; exit; end; // players first
187 result := (hta.mon.UID < htb.mon.UID); // why not?
188 end
189 else
190 begin
191 // a is player
192 if (htb.mon <> nil) then begin result := true; exit; end; // players first
193 result := (hta.plridx < htb.plridx); // why not?
194 end;
195 end;
198 procedure appendHitTimeMon (adistSq: Integer; amon: TMonster; ax, ay: Integer);
199 begin
200 if (wgunHitTimeUsed = Length(wgunHitTime)) then SetLength(wgunHitTime, wgunHitTimeUsed+128);
201 with wgunHitTime[wgunHitTimeUsed] do
202 begin
203 distSq := adistSq;
204 mon := amon;
205 plridx := -1;
206 x := ax;
207 y := ay;
208 end;
209 wgunHitHeap.insert(wgunHitTimeUsed);
210 Inc(wgunHitTimeUsed);
211 end;
214 procedure appendHitTimePlr (adistSq: Integer; aplridx: Integer; ax, ay: Integer);
215 begin
216 if (wgunHitTimeUsed = Length(wgunHitTime)) then SetLength(wgunHitTime, wgunHitTimeUsed+128);
217 with wgunHitTime[wgunHitTimeUsed] do
218 begin
219 distSq := adistSq;
220 mon := nil;
221 plridx := aplridx;
222 x := ax;
223 y := ay;
224 end;
225 wgunHitHeap.insert(wgunHitTimeUsed);
226 Inc(wgunHitTimeUsed);
227 end;
230 function FindShot(): DWORD;
231 var
232 i: Integer;
233 begin
234 if Shots <> nil then
235 for i := 0 to High(Shots) do
236 if Shots[i].ShotType = 0 then
237 begin
238 Result := i;
239 LastShotID := Result;
240 Exit;
241 end;
243 if Shots = nil then
244 begin
245 SetLength(Shots, 128);
246 Result := 0;
247 end
248 else
249 begin
250 Result := High(Shots) + 1;
251 SetLength(Shots, Length(Shots) + 128);
252 end;
253 LastShotID := Result;
254 end;
256 procedure CreateWaterMap();
257 var
258 WaterArray: Array of TWaterPanel;
259 a, b, c, m: Integer;
260 ok: Boolean;
261 begin
262 if gWater = nil then
263 Exit;
265 SetLength(WaterArray, Length(gWater));
267 for a := 0 to High(gWater) do
268 begin
269 WaterArray[a].X := gWater[a].X;
270 WaterArray[a].Y := gWater[a].Y;
271 WaterArray[a].Width := gWater[a].Width;
272 WaterArray[a].Height := gWater[a].Height;
273 WaterArray[a].Active := True;
274 end;
276 g_Game_SetLoadingText(_lc[I_LOAD_WATER_MAP], High(WaterArray), False);
278 for a := 0 to High(WaterArray) do
279 if WaterArray[a].Active then
280 begin
281 WaterArray[a].Active := False;
282 m := Length(WaterMap);
283 SetLength(WaterMap, m+1);
284 SetLength(WaterMap[m], 1);
285 WaterMap[m][0] := a;
286 ok := True;
288 while ok do
289 begin
290 ok := False;
291 for b := 0 to High(WaterArray) do
292 if WaterArray[b].Active then
293 for c := 0 to High(WaterMap[m]) do
294 if g_CollideAround(WaterArray[b].X,
295 WaterArray[b].Y,
296 WaterArray[b].Width,
297 WaterArray[b].Height,
298 WaterArray[WaterMap[m][c]].X,
299 WaterArray[WaterMap[m][c]].Y,
300 WaterArray[WaterMap[m][c]].Width,
301 WaterArray[WaterMap[m][c]].Height) then
302 begin
303 WaterArray[b].Active := False;
304 SetLength(WaterMap[m],
305 Length(WaterMap[m])+1);
306 WaterMap[m][High(WaterMap[m])] := b;
307 ok := True;
308 Break;
309 end;
310 end;
312 g_Game_StepLoading();
313 end;
315 WaterArray := nil;
316 end;
319 var
320 chkTrap_pl: array [0..256] of Integer;
321 chkTrap_mn: array [0..65535] of TMonster;
323 procedure CheckTrap(ID: DWORD; dm: Integer; t: Byte);
324 var
325 //a, b, c, d, i1, i2: Integer;
326 //chkTrap_pl, chkTrap_mn: WArray;
327 plaCount: Integer = 0;
328 mnaCount: Integer = 0;
329 frameId: DWord;
332 function monsWaterCheck (mon: TMonster): Boolean;
333 begin
334 result := false; // don't stop
335 if mon.alive and mon.Collide(gWater[WaterMap[a][c]]) and (not InWArray(monidx, chkTrap_mn)) and (i2 < 1023) then //FIXME
336 begin
337 i2 += 1;
338 chkTrap_mn[i2] := monidx;
339 end;
340 end;
343 function monsWaterCheck (mon: TMonster): Boolean;
344 begin
345 result := false; // don't stop
346 if (mon.trapCheckFrameId <> frameId) then
347 begin
348 mon.trapCheckFrameId := frameId;
349 chkTrap_mn[mnaCount] := mon;
350 Inc(mnaCount);
351 end;
352 end;
354 var
355 a, b, c, d, f: Integer;
356 pan: TPanel;
357 begin
358 if (gWater = nil) or (WaterMap = nil) then Exit;
360 frameId := g_Mons_getNewTrapFrameId();
362 //i1 := -1;
363 //i2 := -1;
365 //SetLength(chkTrap_pl, 1024);
366 //SetLength(chkTrap_mn, 1024);
367 //for d := 0 to 1023 do chkTrap_pl[d] := $FFFF;
368 //for d := 0 to 1023 do chkTrap_mn[d] := $FFFF;
370 for a := 0 to High(WaterMap) do
371 begin
372 for b := 0 to High(WaterMap[a]) do
373 begin
374 pan := gWater[WaterMap[a][b]];
375 if not g_Obj_Collide(pan.X, pan.Y, pan.Width, pan.Height, @Shots[ID].Obj) then continue;
377 for c := 0 to High(WaterMap[a]) do
378 begin
379 pan := gWater[WaterMap[a][c]];
380 for d := 0 to High(gPlayers) do
381 begin
382 if (gPlayers[d] <> nil) and (gPlayers[d].alive) then
383 begin
384 if gPlayers[d].Collide(pan) then
385 begin
386 f := 0;
387 while (f < plaCount) and (chkTrap_pl[f] <> d) do Inc(f);
388 if (f = plaCount) then
389 begin
390 chkTrap_pl[plaCount] := d;
391 Inc(plaCount);
392 if (plaCount = Length(chkTrap_pl)) then break;
393 end;
394 end;
395 end;
396 end;
398 //g_Mons_ForEach(monsWaterCheck);
399 g_Mons_ForEachAliveAt(pan.X, pan.Y, pan.Width, pan.Height, monsWaterCheck);
400 end;
402 for f := 0 to plaCount-1 do gPlayers[chkTrap_pl[f]].Damage(dm, Shots[ID].SpawnerUID, 0, 0, t);
403 for f := 0 to mnaCount-1 do chkTrap_mn[f].Damage(dm, 0, 0, Shots[ID].SpawnerUID, t);
404 end;
405 end;
407 //chkTrap_pl := nil;
408 //chkTrap_mn := nil;
409 end;
411 function HitMonster(m: TMonster; d: Integer; vx, vy: Integer; SpawnerUID: Word; t: Byte): Boolean;
412 var
413 tt, mt: Byte;
414 mon: TMonster;
415 begin
416 Result := False;
418 tt := g_GetUIDType(SpawnerUID);
419 if tt = UID_MONSTER then
420 begin
421 mon := g_Monsters_ByUID(SpawnerUID);
422 if mon <> nil then
423 mt := g_Monsters_ByUID(SpawnerUID).MonsterType
424 else
425 mt := 0;
426 end
427 else
428 mt := 0;
430 if m = nil then Exit;
431 if m.UID = SpawnerUID then
432 begin
433 // Ñàì ñåáÿ ìîæåò ðàíèòü òîëüêî ðàêåòîé è òîêîì:
434 if (t <> HIT_ROCKET) and (t <> HIT_ELECTRO) then
435 Exit;
436 // Êèáåð äåìîí è áî÷êà âîîáùå íå ìîãóò ñåáÿ ðàíèòü:
437 if (m.MonsterType = MONSTER_CYBER) or
438 (m.MonsterType = MONSTER_BARREL) then
439 begin
440 Result := True;
441 Exit;
442 end;
443 end;
445 if tt = UID_MONSTER then
446 begin
447 // Lost_Soul íå ìîæåò ðàíèòü Pain_Elemental'à:
448 if (mt = MONSTER_SOUL) and (m.MonsterType = MONSTER_PAIN) then
449 Exit;
451 // Îáà ìîíñòðà îäíîãî âèäà:
452 if mt = m.MonsterType then
453 case mt of
454 MONSTER_IMP, MONSTER_DEMON, MONSTER_BARON, MONSTER_KNIGHT, MONSTER_CACO,
455 MONSTER_SOUL, MONSTER_MANCUB, MONSTER_SKEL, MONSTER_FISH:
456 Exit; // Ýòè íå áüþò ñâîèõ
457 end;
458 end;
460 if g_Game_IsServer then
461 begin
462 if (t <> HIT_FLAME) or (m.FFireTime = 0) or (vx <> 0) or (vy <> 0) then
463 Result := m.Damage(d, vx, vy, SpawnerUID, t)
464 else
465 Result := (gLMSRespawn = LMS_RESPAWN_NONE); // don't hit monsters when it's warmup time
466 if t = HIT_FLAME then
467 m.CatchFire(SpawnerUID);
468 end
469 else
470 Result := (gLMSRespawn = LMS_RESPAWN_NONE); // don't hit monsters when it's warmup time
471 end;
474 function HitPlayer (p: TPlayer; d: Integer; vx, vy: Integer; SpawnerUID: Word; t: Byte): Boolean;
475 begin
476 result := False;
478 // Ñàì ñåáÿ ìîæåò ðàíèòü òîëüêî ðàêåòîé è òîêîì
479 if (p.UID = SpawnerUID) and (t <> HIT_ROCKET) and (t <> HIT_ELECTRO) then exit;
481 if g_Game_IsServer then
482 begin
483 if (t <> HIT_FLAME) or (p.FFireTime = 0) or (vx <> 0) or (vy <> 0) then p.Damage(d, SpawnerUID, vx, vy, t);
484 if (t = HIT_FLAME) then p.CatchFire(SpawnerUID);
485 end;
487 result := true;
488 end;
491 procedure g_Weapon_BFG9000(X, Y: Integer; SpawnerUID: Word);
493 function monsCheck (mon: TMonster): Boolean;
494 begin
495 result := false; // don't stop
496 if (mon.alive) and (mon.UID <> SpawnerUID) then
497 begin
498 with mon do
499 begin
500 if (g_PatchLength(X, Y, Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2),
501 Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)) <= SHOT_BFG_RADIUS) and
502 g_TraceVector(X, Y, Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2),
503 Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)) then
504 begin
505 if HitMonster(mon, 50, 0, 0, SpawnerUID, HIT_SOME) then mon.BFGHit();
506 end;
507 end;
508 end;
509 end;
511 var
512 i, h: Integer;
513 st: Byte;
514 pl: TPlayer;
515 b: Boolean;
516 begin
517 //g_Sound_PlayEx('SOUND_WEAPON_EXPLODEBFG', 255);
519 h := High(gCorpses);
521 if gAdvCorpses and (h <> -1) then
522 for i := 0 to h do
523 if (gCorpses[i] <> nil) and (gCorpses[i].State <> CORPSE_STATE_REMOVEME) then
524 with gCorpses[i] do
525 if (g_PatchLength(X, Y, Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2),
526 Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)) <= SHOT_BFG_RADIUS) and
527 g_TraceVector(X, Y, Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2),
528 Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)) then
529 begin
530 Damage(50, SpawnerUID, 0, 0);
531 g_Weapon_BFGHit(Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2),
532 Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2));
533 end;
535 st := TEAM_NONE;
536 pl := g_Player_Get(SpawnerUID);
537 if pl <> nil then
538 st := pl.Team;
540 h := High(gPlayers);
542 if h <> -1 then
543 for i := 0 to h do
544 if (gPlayers[i] <> nil) and (gPlayers[i].alive) and (gPlayers[i].UID <> SpawnerUID) then
545 with gPlayers[i] do
546 if (g_PatchLength(X, Y, GameX+PLAYER_RECT.X+(PLAYER_RECT.Width div 2),
547 GameY+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)) <= SHOT_BFG_RADIUS) and
548 g_TraceVector(X, Y, GameX+PLAYER_RECT.X+(PLAYER_RECT.Width div 2),
549 GameY+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)) then
550 begin
551 if (st = TEAM_NONE) or (st <> gPlayers[i].Team) then
552 b := HitPlayer(gPlayers[i], 50, 0, 0, SpawnerUID, HIT_SOME)
553 else
554 b := HitPlayer(gPlayers[i], 25, 0, 0, SpawnerUID, HIT_SOME);
555 if b then
556 gPlayers[i].BFGHit();
557 end;
559 //FIXME
560 g_Mons_ForEachAlive(monsCheck);
561 end;
563 function g_Weapon_CreateShot(I: Integer; ShotType: Byte; Spawner, TargetUID: Word; X, Y, XV, YV: Integer): LongWord;
564 var
565 find_id: DWord;
566 FramesID: DWORD = 0;
567 begin
568 if I < 0 then
569 find_id := FindShot()
570 else
571 begin
572 find_id := I;
573 if Integer(find_id) >= High(Shots) then
574 SetLength(Shots, find_id + 64)
575 end;
577 case ShotType of
578 WEAPON_ROCKETLAUNCHER:
579 begin
580 with Shots[find_id] do
581 begin
582 g_Obj_Init(@Obj);
584 Obj.Rect.Width := SHOT_ROCKETLAUNCHER_WIDTH;
585 Obj.Rect.Height := SHOT_ROCKETLAUNCHER_HEIGHT;
587 Animation := nil;
588 Triggers := nil;
589 ShotType := WEAPON_ROCKETLAUNCHER;
590 g_Texture_Get('TEXTURE_WEAPON_ROCKET', TextureID);
591 end;
592 end;
594 WEAPON_PLASMA:
595 begin
596 with Shots[find_id] do
597 begin
598 g_Obj_Init(@Obj);
600 Obj.Rect.Width := SHOT_PLASMA_WIDTH;
601 Obj.Rect.Height := SHOT_PLASMA_HEIGHT;
603 Triggers := nil;
604 ShotType := WEAPON_PLASMA;
605 g_Frames_Get(FramesID, 'FRAMES_WEAPON_PLASMA');
606 Animation := TAnimation.Create(FramesID, True, 5);
607 end;
608 end;
610 WEAPON_BFG:
611 begin
612 with Shots[find_id] do
613 begin
614 g_Obj_Init(@Obj);
616 Obj.Rect.Width := SHOT_BFG_WIDTH;
617 Obj.Rect.Height := SHOT_BFG_HEIGHT;
619 Triggers := nil;
620 ShotType := WEAPON_BFG;
621 g_Frames_Get(FramesID, 'FRAMES_WEAPON_BFG');
622 Animation := TAnimation.Create(FramesID, True, 6);
623 end;
624 end;
626 WEAPON_FLAMETHROWER:
627 begin
628 with Shots[find_id] do
629 begin
630 g_Obj_Init(@Obj);
632 Obj.Rect.Width := SHOT_FLAME_WIDTH;
633 Obj.Rect.Height := SHOT_FLAME_HEIGHT;
635 Triggers := nil;
636 ShotType := WEAPON_FLAMETHROWER;
637 Animation := nil;
638 TextureID := 0;
639 g_Frames_Get(TextureID, 'FRAMES_FLAME');
640 end;
641 end;
643 WEAPON_IMP_FIRE:
644 begin
645 with Shots[find_id] do
646 begin
647 g_Obj_Init(@Obj);
649 Obj.Rect.Width := 16;
650 Obj.Rect.Height := 16;
652 Triggers := nil;
653 ShotType := WEAPON_IMP_FIRE;
654 g_Frames_Get(FramesID, 'FRAMES_WEAPON_IMPFIRE');
655 Animation := TAnimation.Create(FramesID, True, 4);
656 end;
657 end;
659 WEAPON_CACO_FIRE:
660 begin
661 with Shots[find_id] do
662 begin
663 g_Obj_Init(@Obj);
665 Obj.Rect.Width := 16;
666 Obj.Rect.Height := 16;
668 Triggers := nil;
669 ShotType := WEAPON_CACO_FIRE;
670 g_Frames_Get(FramesID, 'FRAMES_WEAPON_CACOFIRE');
671 Animation := TAnimation.Create(FramesID, True, 4);
672 end;
673 end;
675 WEAPON_MANCUB_FIRE:
676 begin
677 with Shots[find_id] do
678 begin
679 g_Obj_Init(@Obj);
681 Obj.Rect.Width := 32;
682 Obj.Rect.Height := 32;
684 Triggers := nil;
685 ShotType := WEAPON_MANCUB_FIRE;
686 g_Frames_Get(FramesID, 'FRAMES_WEAPON_MANCUBFIRE');
687 Animation := TAnimation.Create(FramesID, True, 4);
688 end;
689 end;
691 WEAPON_BARON_FIRE:
692 begin
693 with Shots[find_id] do
694 begin
695 g_Obj_Init(@Obj);
697 Obj.Rect.Width := 32;
698 Obj.Rect.Height := 16;
700 Triggers := nil;
701 ShotType := WEAPON_BARON_FIRE;
702 g_Frames_Get(FramesID, 'FRAMES_WEAPON_BARONFIRE');
703 Animation := TAnimation.Create(FramesID, True, 4);
704 end;
705 end;
707 WEAPON_BSP_FIRE:
708 begin
709 with Shots[find_id] do
710 begin
711 g_Obj_Init(@Obj);
713 Obj.Rect.Width := 16;
714 Obj.Rect.Height := 16;
716 Triggers := nil;
717 ShotType := WEAPON_BSP_FIRE;
718 g_Frames_Get(FramesID, 'FRAMES_WEAPON_BSPFIRE');
719 Animation := TAnimation.Create(FramesID, True, 4);
720 end;
721 end;
723 WEAPON_SKEL_FIRE:
724 begin
725 with Shots[find_id] do
726 begin
727 g_Obj_Init(@Obj);
729 Obj.Rect.Width := SHOT_SKELFIRE_WIDTH;
730 Obj.Rect.Height := SHOT_SKELFIRE_HEIGHT;
732 Triggers := nil;
733 ShotType := WEAPON_SKEL_FIRE;
734 target := TargetUID;
735 g_Frames_Get(FramesID, 'FRAMES_WEAPON_SKELFIRE');
736 Animation := TAnimation.Create(FramesID, True, 5);
737 end;
738 end;
739 end;
741 Shots[find_id].Obj.oldX := X;
742 Shots[find_id].Obj.oldY := Y;
743 Shots[find_id].Obj.X := X;
744 Shots[find_id].Obj.Y := Y;
745 Shots[find_id].Obj.Vel.X := XV;
746 Shots[find_id].Obj.Vel.Y := YV;
747 Shots[find_id].Obj.Accel.X := 0;
748 Shots[find_id].Obj.Accel.Y := 0;
749 Shots[find_id].SpawnerUID := Spawner;
750 if (ShotType = WEAPON_FLAMETHROWER) and (XV = 0) and (YV = 0) then
751 Shots[find_id].Stopped := 255
752 else
753 Shots[find_id].Stopped := 0;
754 Result := find_id;
755 end;
757 procedure throw(i, x, y, xd, yd, s: Integer);
758 var
759 a: Integer;
760 begin
761 yd := yd - y;
762 xd := xd - x;
764 a := Max(Abs(xd), Abs(yd));
765 if a = 0 then
766 a := 1;
768 Shots[i].Obj.oldX := x;
769 Shots[i].Obj.oldY := y;
770 Shots[i].Obj.X := x;
771 Shots[i].Obj.Y := y;
772 Shots[i].Obj.Vel.X := (xd*s) div a;
773 Shots[i].Obj.Vel.Y := (yd*s) div a;
774 Shots[i].Obj.Accel.X := 0;
775 Shots[i].Obj.Accel.Y := 0;
776 Shots[i].Stopped := 0;
777 if Shots[i].ShotType in [WEAPON_ROCKETLAUNCHER, WEAPON_BFG] then
778 Shots[i].Timeout := 900 // ~25 sec
779 else
780 begin
781 if Shots[i].ShotType = WEAPON_FLAMETHROWER then
782 Shots[i].Timeout := SHOT_FLAME_LIFETIME
783 else
784 Shots[i].Timeout := 550; // ~15 sec
785 end;
786 end;
788 function g_Weapon_Hit(obj: PObj; d: Integer; SpawnerUID: Word; t: Byte; HitCorpses: Boolean = True): Byte;
789 var
790 i, h: Integer;
792 function PlayerHit(Team: Byte = 0): Boolean;
793 var
794 i: Integer;
795 ChkTeam: Boolean;
796 p: TPlayer;
797 begin
798 Result := False;
799 h := High(gPlayers);
801 if h <> -1 then
802 for i := 0 to h do
803 if (gPlayers[i] <> nil) and gPlayers[i].alive and g_Obj_Collide(obj, @gPlayers[i].Obj) then
804 begin
805 ChkTeam := True;
806 if (Team > 0) and (g_GetUIDType(SpawnerUID) = UID_PLAYER) then
807 begin
808 p := g_Player_Get(SpawnerUID);
809 if p <> nil then
810 ChkTeam := (p.Team = gPlayers[i].Team) xor (Team = 2);
811 end;
812 if ChkTeam then
813 if HitPlayer(gPlayers[i], d, obj^.Vel.X, obj^.Vel.Y, SpawnerUID, t) then
814 begin
815 if t <> HIT_FLAME then
816 gPlayers[i].Push((obj^.Vel.X+obj^.Accel.X)*IfThen(t = HIT_BFG, 8, 1) div 4,
817 (obj^.Vel.Y+obj^.Accel.Y)*IfThen(t = HIT_BFG, 8, 1) div 4);
818 if t = HIT_BFG then
819 g_Game_DelayEvent(DE_BFGHIT, 1000, SpawnerUID);
820 Result := True;
821 break;
822 end;
823 end;
824 end;
827 function monsCheckHit (monidx: Integer; mon: TMonster): Boolean;
828 begin
829 result := false; // don't stop
830 if mon.alive and g_Obj_Collide(obj, @mon.Obj) then
831 begin
832 if HitMonster(mon, d, obj^.Vel.X, obj^.Vel.Y, SpawnerUID, t) then
833 begin
834 if (t <> HIT_FLAME) then
835 begin
836 mon.Push((obj^.Vel.X+obj^.Accel.X)*IfThen(t = HIT_BFG, 8, 1) div 4,
837 (obj^.Vel.Y+obj^.Accel.Y)*IfThen(t = HIT_BFG, 8, 1) div 4);
838 end;
839 result := True;
840 end;
841 end;
842 end;
845 function monsCheckHit (mon: TMonster): Boolean;
846 begin
847 result := false; // don't stop
848 if HitMonster(mon, d, obj.Vel.X, obj.Vel.Y, SpawnerUID, t) then
849 begin
850 if (t <> HIT_FLAME) then
851 begin
852 mon.Push((obj.Vel.X+obj.Accel.X)*IfThen(t = HIT_BFG, 8, 1) div 4,
853 (obj.Vel.Y+obj.Accel.Y)*IfThen(t = HIT_BFG, 8, 1) div 4);
854 end;
855 result := true;
856 end;
857 end;
859 function MonsterHit(): Boolean;
860 begin
861 //result := g_Mons_ForEach(monsCheckHit);
862 //FIXME: accelerate this!
863 result := g_Mons_ForEachAliveAt(obj.X+obj.Rect.X, obj.Y+obj.Rect.Y, obj.Rect.Width, obj.Rect.Height, monsCheckHit);
864 end;
866 begin
867 Result := 0;
869 if HitCorpses then
870 begin
871 h := High(gCorpses);
873 if gAdvCorpses and (h <> -1) then
874 for i := 0 to h do
875 if (gCorpses[i] <> nil) and (gCorpses[i].State <> CORPSE_STATE_REMOVEME) and
876 g_Obj_Collide(obj, @gCorpses[i].Obj) then
877 begin
878 // Ðàñïèëèâàåì òðóï:
879 gCorpses[i].Damage(d, SpawnerUID, (obj^.Vel.X+obj^.Accel.X) div 4,
880 (obj^.Vel.Y+obj^.Accel.Y) div 4);
881 Result := 1;
882 end;
883 end;
885 case gGameSettings.GameMode of
886 // Êàìïàíèÿ:
887 GM_COOP, GM_SINGLE:
888 begin
889 // Ñíà÷àëà áü¸ì ìîíñòðîâ, åñëè åñòü, ïîòîì ïûòàåìñÿ áèòü èãðîêîâ
890 if MonsterHit() then
891 begin
892 Result := 2;
893 Exit;
894 end;
896 if PlayerHit() then
897 begin
898 Result := 1;
899 Exit;
900 end;
901 end;
903 // Äåçìàò÷:
904 GM_DM:
905 begin
906 // Ñíà÷àëà áü¸ì èãðîêîâ, åñëè åñòü, ïîòîì ïûòàåìñÿ áèòü ìîíñòðîâ
907 if PlayerHit() then
908 begin
909 Result := 1;
910 Exit;
911 end;
913 if MonsterHit() then
914 begin
915 Result := 2;
916 Exit;
917 end;
918 end;
920 // Êîìàíäíûå:
921 GM_TDM, GM_CTF:
922 begin
923 // Ñíà÷àëà áü¸ì èãðîêîâ êîìàíäû ñîïåðíèêà
924 if PlayerHit(2) then
925 begin
926 Result := 1;
927 Exit;
928 end;
930 // Ïîòîì ìîíñòðîâ
931 if MonsterHit() then
932 begin
933 Result := 2;
934 Exit;
935 end;
937 // È â êîíöå ñâîèõ èãðîêîâ
938 if PlayerHit(1) then
939 begin
940 Result := 1;
941 Exit;
942 end;
943 end;
945 end;
946 end;
948 function g_Weapon_HitUID(UID: Word; d: Integer; SpawnerUID: Word; t: Byte): Boolean;
949 begin
950 Result := False;
952 case g_GetUIDType(UID) of
953 UID_PLAYER: Result := HitPlayer(g_Player_Get(UID), d, 0, 0, SpawnerUID, t);
954 UID_MONSTER: Result := HitMonster(g_Monsters_ByUID(UID), d, 0, 0, SpawnerUID, t);
955 else Exit;
956 end;
957 end;
959 function g_Weapon_Explode(X, Y: Integer; rad: Integer; SpawnerUID: Word): Boolean;
960 var
961 r: Integer; // squared radius
963 function monsExCheck (mon: TMonster): Boolean;
964 var
965 dx, dy, mm: Integer;
966 begin
967 result := false; // don't stop
968 begin
969 dx := mon.Obj.X+mon.Obj.Rect.X+(mon.Obj.Rect.Width div 2)-X;
970 dy := mon.Obj.Y+mon.Obj.Rect.Y+(mon.Obj.Rect.Height div 2)-Y;
972 if dx > 1000 then dx := 1000;
973 if dy > 1000 then dy := 1000;
975 if (dx*dx+dy*dy < r) then
976 begin
977 //m := PointToRect(X, Y, Obj.X+Obj.Rect.X, Obj.Y+Obj.Rect.Y, Obj.Rect.Width, Obj.Rect.Height);
978 //e_WriteLog(Format('explo monster #%d: x=%d; y=%d; rad=%d; dx=%d; dy=%d', [monidx, X, Y, rad, dx, dy]), MSG_NOTIFY);
980 mm := Max(abs(dx), abs(dy));
981 if mm = 0 then mm := 1;
983 if mon.alive then
984 begin
985 HitMonster(mon, ((mon.Obj.Rect.Width div 4)*10*(rad-mm)) div rad, 0, 0, SpawnerUID, HIT_ROCKET);
986 end;
988 mon.Push((dx*7) div mm, (dy*7) div mm);
989 end;
990 end;
991 end;
993 var
994 i, h, dx, dy, m, mm: Integer;
995 _angle: SmallInt;
996 begin
997 result := false;
999 g_Triggers_PressC(X, Y, rad, SpawnerUID, ACTIVATE_SHOT);
1001 r := rad*rad;
1003 h := High(gPlayers);
1005 if h <> -1 then
1006 for i := 0 to h do
1007 if (gPlayers[i] <> nil) and gPlayers[i].alive then
1008 with gPlayers[i] do
1009 begin
1010 dx := Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2)-X;
1011 dy := Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)-Y;
1013 if dx > 1000 then dx := 1000;
1014 if dy > 1000 then dy := 1000;
1016 if dx*dx+dy*dy < r then
1017 begin
1018 //m := PointToRect(X, Y, GameX+PLAYER_RECT.X, GameY+PLAYER_RECT.Y,
1019 // PLAYER_RECT.Width, PLAYER_RECT.Height);
1021 mm := Max(abs(dx), abs(dy));
1022 if mm = 0 then mm := 1;
1024 HitPlayer(gPlayers[i], (100*(rad-mm)) div rad, (dx*10) div mm, (dy*10) div mm, SpawnerUID, HIT_ROCKET);
1025 gPlayers[i].Push((dx*7) div mm, (dy*7) div mm);
1026 end;
1027 end;
1029 //g_Mons_ForEach(monsExCheck);
1030 g_Mons_ForEachAt(X-(rad+32), Y-(rad+32), (rad+32)*2, (rad+32)*2, monsExCheck);
1032 h := High(gCorpses);
1034 if gAdvCorpses and (h <> -1) then
1035 for i := 0 to h do
1036 if (gCorpses[i] <> nil) and (gCorpses[i].State <> CORPSE_STATE_REMOVEME) then
1037 with gCorpses[i] do
1038 begin
1039 dx := Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2)-X;
1040 dy := Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)-Y;
1042 if dx > 1000 then dx := 1000;
1043 if dy > 1000 then dy := 1000;
1045 if dx*dx+dy*dy < r then
1046 begin
1047 m := PointToRect(X, Y, Obj.X+Obj.Rect.X, Obj.Y+Obj.Rect.Y,
1048 Obj.Rect.Width, Obj.Rect.Height);
1050 mm := Max(abs(dx), abs(dy));
1051 if mm = 0 then mm := 1;
1053 Damage(Round(100*(rad-m)/rad), SpawnerUID, (dx*10) div mm, (dy*10) div mm);
1054 end;
1055 end;
1057 h := High(gGibs);
1059 if gAdvGibs and (h <> -1) then
1060 for i := 0 to h do
1061 if gGibs[i].alive then
1062 with gGibs[i] do
1063 begin
1064 dx := Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2)-X;
1065 dy := Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)-Y;
1067 if dx > 1000 then dx := 1000;
1068 if dy > 1000 then dy := 1000;
1070 if dx*dx+dy*dy < r then
1071 begin
1072 m := PointToRect(X, Y, Obj.X+Obj.Rect.X, Obj.Y+Obj.Rect.Y,
1073 Obj.Rect.Width, Obj.Rect.Height);
1074 _angle := GetAngle(Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2),
1075 Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2), X, Y);
1077 g_Obj_PushA(@Obj, Round(15*(rad-m)/rad), _angle);
1078 positionChanged(); // this updates spatial accelerators
1079 end;
1080 end;
1081 end;
1083 procedure g_Weapon_Init();
1084 begin
1085 CreateWaterMap();
1086 end;
1088 procedure g_Weapon_Free();
1089 var
1090 i: Integer;
1091 begin
1092 if Shots <> nil then
1093 begin
1094 for i := 0 to High(Shots) do
1095 if Shots[i].ShotType <> 0 then
1096 Shots[i].Animation.Free();
1098 Shots := nil;
1099 end;
1101 WaterMap := nil;
1102 end;
1104 procedure g_Weapon_LoadData();
1105 begin
1106 e_WriteLog('Loading weapons data...', TMsgType.Notify);
1108 g_Sound_CreateWADEx('SOUND_WEAPON_HITPUNCH', GameWAD+':SOUNDS\HITPUNCH');
1109 g_Sound_CreateWADEx('SOUND_WEAPON_MISSPUNCH', GameWAD+':SOUNDS\MISSPUNCH');
1110 g_Sound_CreateWADEx('SOUND_WEAPON_HITBERSERK', GameWAD+':SOUNDS\HITBERSERK');
1111 g_Sound_CreateWADEx('SOUND_WEAPON_MISSBERSERK', GameWAD+':SOUNDS\MISSBERSERK');
1112 g_Sound_CreateWADEx('SOUND_WEAPON_SELECTSAW', GameWAD+':SOUNDS\SELECTSAW');
1113 g_Sound_CreateWADEx('SOUND_WEAPON_IDLESAW', GameWAD+':SOUNDS\IDLESAW');
1114 g_Sound_CreateWADEx('SOUND_WEAPON_HITSAW', GameWAD+':SOUNDS\HITSAW');
1115 g_Sound_CreateWADEx('SOUND_WEAPON_FIRESHOTGUN2', GameWAD+':SOUNDS\FIRESHOTGUN2');
1116 g_Sound_CreateWADEx('SOUND_WEAPON_FIRESHOTGUN', GameWAD+':SOUNDS\FIRESHOTGUN');
1117 g_Sound_CreateWADEx('SOUND_WEAPON_FIRESAW', GameWAD+':SOUNDS\FIRESAW');
1118 g_Sound_CreateWADEx('SOUND_WEAPON_FIREROCKET', GameWAD+':SOUNDS\FIREROCKET');
1119 g_Sound_CreateWADEx('SOUND_WEAPON_FIREPLASMA', GameWAD+':SOUNDS\FIREPLASMA');
1120 g_Sound_CreateWADEx('SOUND_WEAPON_FIREPISTOL', GameWAD+':SOUNDS\FIREPISTOL');
1121 g_Sound_CreateWADEx('SOUND_WEAPON_FIRECGUN', GameWAD+':SOUNDS\FIRECGUN');
1122 g_Sound_CreateWADEx('SOUND_WEAPON_FIREBFG', GameWAD+':SOUNDS\FIREBFG');
1123 g_Sound_CreateWADEx('SOUND_FIRE', GameWAD+':SOUNDS\FIRE');
1124 g_Sound_CreateWADEx('SOUND_IGNITE', GameWAD+':SOUNDS\IGNITE');
1125 g_Sound_CreateWADEx('SOUND_WEAPON_STARTFIREBFG', GameWAD+':SOUNDS\STARTFIREBFG');
1126 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEROCKET', GameWAD+':SOUNDS\EXPLODEROCKET');
1127 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEBFG', GameWAD+':SOUNDS\EXPLODEBFG');
1128 g_Sound_CreateWADEx('SOUND_WEAPON_BFGWATER', GameWAD+':SOUNDS\BFGWATER');
1129 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEPLASMA', GameWAD+':SOUNDS\EXPLODEPLASMA');
1130 g_Sound_CreateWADEx('SOUND_WEAPON_PLASMAWATER', GameWAD+':SOUNDS\PLASMAWATER');
1131 g_Sound_CreateWADEx('SOUND_WEAPON_FIREBALL', GameWAD+':SOUNDS\FIREBALL');
1132 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEBALL', GameWAD+':SOUNDS\EXPLODEBALL');
1133 g_Sound_CreateWADEx('SOUND_WEAPON_FIREREV', GameWAD+':SOUNDS\FIREREV');
1134 g_Sound_CreateWADEx('SOUND_WEAPON_FLAMEON', GameWAD+':SOUNDS\STARTFLM');
1135 g_Sound_CreateWADEx('SOUND_WEAPON_FLAMEOFF', GameWAD+':SOUNDS\STOPFLM');
1136 g_Sound_CreateWADEx('SOUND_WEAPON_FLAMEWORK', GameWAD+':SOUNDS\WORKFLM');
1137 g_Sound_CreateWADEx('SOUND_PLAYER_JETFLY', GameWAD+':SOUNDS\WORKJETPACK');
1138 g_Sound_CreateWADEx('SOUND_PLAYER_JETON', GameWAD+':SOUNDS\STARTJETPACK');
1139 g_Sound_CreateWADEx('SOUND_PLAYER_JETOFF', GameWAD+':SOUNDS\STOPJETPACK');
1140 g_Sound_CreateWADEx('SOUND_PLAYER_CASING1', GameWAD+':SOUNDS\CASING1');
1141 g_Sound_CreateWADEx('SOUND_PLAYER_CASING2', GameWAD+':SOUNDS\CASING2');
1142 g_Sound_CreateWADEx('SOUND_PLAYER_SHELL1', GameWAD+':SOUNDS\SHELL1');
1143 g_Sound_CreateWADEx('SOUND_PLAYER_SHELL2', GameWAD+':SOUNDS\SHELL2');
1145 g_Texture_CreateWADEx('TEXTURE_WEAPON_ROCKET', GameWAD+':TEXTURES\BROCKET');
1146 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_SKELFIRE', GameWAD+':TEXTURES\BSKELFIRE', 64, 16, 2);
1147 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_BFG', GameWAD+':TEXTURES\BBFG', 64, 64, 2);
1148 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_PLASMA', GameWAD+':TEXTURES\BPLASMA', 16, 16, 2);
1149 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_IMPFIRE', GameWAD+':TEXTURES\BIMPFIRE', 16, 16, 2);
1150 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_BSPFIRE', GameWAD+':TEXTURES\BBSPFIRE', 16, 16, 2);
1151 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_CACOFIRE', GameWAD+':TEXTURES\BCACOFIRE', 16, 16, 2);
1152 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_BARONFIRE', GameWAD+':TEXTURES\BBARONFIRE', 64, 16, 2);
1153 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_MANCUBFIRE', GameWAD+':TEXTURES\BMANCUBFIRE', 64, 32, 2);
1154 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_ROCKET', GameWAD+':TEXTURES\EROCKET', 128, 128, 6);
1155 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_SKELFIRE', GameWAD+':TEXTURES\ESKELFIRE', 64, 64, 3);
1156 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_BFG', GameWAD+':TEXTURES\EBFG', 128, 128, 6);
1157 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_IMPFIRE', GameWAD+':TEXTURES\EIMPFIRE', 64, 64, 3);
1158 g_Frames_CreateWAD(nil, 'FRAMES_BFGHIT', GameWAD+':TEXTURES\BFGHIT', 64, 64, 4);
1159 g_Frames_CreateWAD(nil, 'FRAMES_FIRE', GameWAD+':TEXTURES\FIRE', 64, 128, 8);
1160 g_Frames_CreateWAD(nil, 'FRAMES_FLAME', GameWAD+':TEXTURES\FLAME', 32, 32, 11);
1161 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_PLASMA', GameWAD+':TEXTURES\EPLASMA', 32, 32, 4, True);
1162 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_BSPFIRE', GameWAD+':TEXTURES\EBSPFIRE', 32, 32, 5);
1163 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_CACOFIRE', GameWAD+':TEXTURES\ECACOFIRE', 64, 64, 3);
1164 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_BARONFIRE', GameWAD+':TEXTURES\EBARONFIRE', 64, 64, 3);
1165 g_Frames_CreateWAD(nil, 'FRAMES_SMOKE', GameWAD+':TEXTURES\SMOKE', 32, 32, 10, False);
1167 g_Texture_CreateWADEx('TEXTURE_SHELL_BULLET', GameWAD+':TEXTURES\EBULLET');
1168 g_Texture_CreateWADEx('TEXTURE_SHELL_SHELL', GameWAD+':TEXTURES\ESHELL');
1170 //wgunMonHash := hashNewIntInt();
1171 wgunHitHeap := TBinaryHeapHitTimes.Create();
1172 end;
1174 procedure g_Weapon_FreeData();
1175 begin
1176 e_WriteLog('Releasing weapons data...', TMsgType.Notify);
1178 g_Sound_Delete('SOUND_WEAPON_HITPUNCH');
1179 g_Sound_Delete('SOUND_WEAPON_MISSPUNCH');
1180 g_Sound_Delete('SOUND_WEAPON_HITBERSERK');
1181 g_Sound_Delete('SOUND_WEAPON_MISSBERSERK');
1182 g_Sound_Delete('SOUND_WEAPON_SELECTSAW');
1183 g_Sound_Delete('SOUND_WEAPON_IDLESAW');
1184 g_Sound_Delete('SOUND_WEAPON_HITSAW');
1185 g_Sound_Delete('SOUND_WEAPON_FIRESHOTGUN2');
1186 g_Sound_Delete('SOUND_WEAPON_FIRESHOTGUN');
1187 g_Sound_Delete('SOUND_WEAPON_FIRESAW');
1188 g_Sound_Delete('SOUND_WEAPON_FIREROCKET');
1189 g_Sound_Delete('SOUND_WEAPON_FIREPLASMA');
1190 g_Sound_Delete('SOUND_WEAPON_FIREPISTOL');
1191 g_Sound_Delete('SOUND_WEAPON_FIRECGUN');
1192 g_Sound_Delete('SOUND_WEAPON_FIREBFG');
1193 g_Sound_Delete('SOUND_FIRE');
1194 g_Sound_Delete('SOUND_IGNITE');
1195 g_Sound_Delete('SOUND_WEAPON_STARTFIREBFG');
1196 g_Sound_Delete('SOUND_WEAPON_EXPLODEROCKET');
1197 g_Sound_Delete('SOUND_WEAPON_EXPLODEBFG');
1198 g_Sound_Delete('SOUND_WEAPON_BFGWATER');
1199 g_Sound_Delete('SOUND_WEAPON_EXPLODEPLASMA');
1200 g_Sound_Delete('SOUND_WEAPON_PLASMAWATER');
1201 g_Sound_Delete('SOUND_WEAPON_FIREBALL');
1202 g_Sound_Delete('SOUND_WEAPON_EXPLODEBALL');
1203 g_Sound_Delete('SOUND_WEAPON_FIREREV');
1204 g_Sound_Delete('SOUND_WEAPON_FLAMEON');
1205 g_Sound_Delete('SOUND_WEAPON_FLAMEOFF');
1206 g_Sound_Delete('SOUND_WEAPON_FLAMEWORK');
1207 g_Sound_Delete('SOUND_PLAYER_JETFLY');
1208 g_Sound_Delete('SOUND_PLAYER_JETON');
1209 g_Sound_Delete('SOUND_PLAYER_JETOFF');
1210 g_Sound_Delete('SOUND_PLAYER_CASING1');
1211 g_Sound_Delete('SOUND_PLAYER_CASING2');
1212 g_Sound_Delete('SOUND_PLAYER_SHELL1');
1213 g_Sound_Delete('SOUND_PLAYER_SHELL2');
1215 g_Texture_Delete('TEXTURE_WEAPON_ROCKET');
1216 g_Frames_DeleteByName('FRAMES_WEAPON_BFG');
1217 g_Frames_DeleteByName('FRAMES_WEAPON_PLASMA');
1218 g_Frames_DeleteByName('FRAMES_WEAPON_IMPFIRE');
1219 g_Frames_DeleteByName('FRAMES_WEAPON_BSPFIRE');
1220 g_Frames_DeleteByName('FRAMES_WEAPON_CACOFIRE');
1221 g_Frames_DeleteByName('FRAMES_WEAPON_MANCUBFIRE');
1222 g_Frames_DeleteByName('FRAMES_EXPLODE_ROCKET');
1223 g_Frames_DeleteByName('FRAMES_EXPLODE_BFG');
1224 g_Frames_DeleteByName('FRAMES_EXPLODE_IMPFIRE');
1225 g_Frames_DeleteByName('FRAMES_BFGHIT');
1226 g_Frames_DeleteByName('FRAMES_FIRE');
1227 g_Frames_DeleteByName('FRAMES_EXPLODE_PLASMA');
1228 g_Frames_DeleteByName('FRAMES_EXPLODE_BSPFIRE');
1229 g_Frames_DeleteByName('FRAMES_EXPLODE_CACOFIRE');
1230 g_Frames_DeleteByName('FRAMES_SMOKE');
1231 g_Frames_DeleteByName('FRAMES_WEAPON_BARONFIRE');
1232 g_Frames_DeleteByName('FRAMES_EXPLODE_BARONFIRE');
1233 end;
1236 function GunHitPlayer (X, Y: Integer; vx, vy: Integer; dmg: Integer; SpawnerUID: Word; AllowPush: Boolean): Boolean;
1237 var
1238 i: Integer;
1239 begin
1240 result := false;
1241 for i := 0 to High(gPlayers) do
1242 begin
1243 if (gPlayers[i] <> nil) and gPlayers[i].alive and gPlayers[i].Collide(X, Y) then
1244 begin
1245 if HitPlayer(gPlayers[i], dmg, vx*10, vy*10-3, SpawnerUID, HIT_SOME) then
1246 begin
1247 if AllowPush then gPlayers[i].Push(vx, vy);
1248 result := true;
1249 end;
1250 end;
1251 end;
1252 end;
1255 function GunHit (X, Y: Integer; vx, vy: Integer; dmg: Integer; SpawnerUID: Word; AllowPush: Boolean): Byte;
1257 function monsCheck (mon: TMonster): Boolean;
1258 begin
1259 result := false; // don't stop
1260 if HitMonster(mon, dmg, vx*10, vy*10-3, SpawnerUID, HIT_SOME) then
1261 begin
1262 if AllowPush then mon.Push(vx, vy);
1263 result := true;
1264 end;
1265 end;
1267 begin
1268 result := 0;
1269 if GunHitPlayer(X, Y, vx, vy, dmg, SpawnerUID, AllowPush) then result := 1
1270 else if g_Mons_ForEachAliveAt(X, Y, 1, 1, monsCheck) then result := 2;
1271 end;
1274 (*
1275 procedure g_Weapon_gunOld(const x, y, xd, yd, v, dmg: Integer; SpawnerUID: Word; CheckTrigger: Boolean);
1276 var
1277 a: Integer;
1278 x2, y2: Integer;
1279 dx, dy: Integer;
1280 xe, ye: Integer;
1281 xi, yi: Integer;
1282 s, c: Extended;
1283 //vx, vy: Integer;
1284 xx, yy, d: Integer;
1285 i: Integer;
1286 t1, _collide: Boolean;
1287 w, h: Word;
1288 {$IF DEFINED(D2F_DEBUG)}
1289 stt: UInt64;
1290 showTime: Boolean = true;
1291 {$ENDIF}
1292 begin
1293 a := GetAngle(x, y, xd, yd)+180;
1295 SinCos(DegToRad(-a), s, c);
1297 if Abs(s) < 0.01 then s := 0;
1298 if Abs(c) < 0.01 then c := 0;
1300 x2 := x+Round(c*gMapInfo.Width);
1301 y2 := y+Round(s*gMapInfo.Width);
1303 t1 := gWalls <> nil;
1304 _collide := False;
1305 w := gMapInfo.Width;
1306 h := gMapInfo.Height;
1308 xe := 0;
1309 ye := 0;
1310 dx := x2-x;
1311 dy := y2-y;
1313 if (xd = 0) and (yd = 0) then Exit;
1315 if dx > 0 then xi := 1 else if dx < 0 then xi := -1 else xi := 0;
1316 if dy > 0 then yi := 1 else if dy < 0 then yi := -1 else yi := 0;
1318 dx := Abs(dx);
1319 dy := Abs(dy);
1321 if dx > dy then d := dx else d := dy;
1323 //blood vel, for Monster.Damage()
1324 //vx := (dx*10 div d)*xi;
1325 //vy := (dy*10 div d)*yi;
1327 {$IF DEFINED(D2F_DEBUG)}
1328 stt := getTimeMicro();
1329 {$ENDIF}
1331 xx := x;
1332 yy := y;
1334 for i := 1 to d do
1335 begin
1336 xe := xe+dx;
1337 ye := ye+dy;
1339 if xe > d then
1340 begin
1341 xe := xe-d;
1342 xx := xx+xi;
1343 end;
1345 if ye > d then
1346 begin
1347 ye := ye-d;
1348 yy := yy+yi;
1349 end;
1351 if (yy > h) or (yy < 0) then Break;
1352 if (xx > w) or (xx < 0) then Break;
1354 if t1 then
1355 if ByteBool(gCollideMap[yy, xx] and MARK_BLOCKED) then
1356 begin
1357 _collide := True;
1358 {$IF DEFINED(D2F_DEBUG)}
1359 stt := getTimeMicro()-stt;
1360 e_WriteLog(Format('*** old trace time: %u microseconds', [LongWord(stt)]), MSG_NOTIFY);
1361 showTime := false;
1362 {$ENDIF}
1363 g_GFX_Spark(xx-xi, yy-yi, 2+Random(2), 180+a, 0, 0);
1364 if g_Game_IsServer and g_Game_IsNet then
1365 MH_SEND_Effect(xx-xi, yy-yi, 180+a, NET_GFX_SPARK);
1366 end;
1368 if not _collide then
1369 begin
1370 _collide := GunHit(xx, yy, xi*v, yi*v, dmg, SpawnerUID, v <> 0) <> 0;
1371 end;
1373 if _collide then Break;
1374 end;
1376 {$IF DEFINED(D2F_DEBUG)}
1377 if showTime then
1378 begin
1379 stt := getTimeMicro()-stt;
1380 e_WriteLog(Format('*** old trace time: %u microseconds', [LongWord(stt)]), MSG_NOTIFY);
1381 end;
1382 {$ENDIF}
1384 if CheckTrigger and g_Game_IsServer then
1385 g_Triggers_PressL(X, Y, xx-xi, yy-yi, SpawnerUID, ACTIVATE_SHOT);
1386 end;
1387 *)
1390 //!!!FIXME!!!
1391 procedure g_Weapon_gun (const x, y, xd, yd, v, dmg: Integer; SpawnerUID: Word; CheckTrigger: Boolean);
1392 var
1393 x0, y0: Integer;
1394 x2, y2: Integer;
1395 xi, yi: Integer;
1396 wallDistSq: Integer = $3fffffff;
1398 function doPlayerHit (idx: Integer; hx, hy: Integer): Boolean;
1399 begin
1400 result := false;
1401 if (idx < 0) or (idx > High(gPlayers)) then exit;
1402 if (gPlayers[idx] = nil) or not gPlayers[idx].alive then exit;
1403 result := HitPlayer(gPlayers[idx], dmg, (xi*v)*10, (yi*v)*10-3, SpawnerUID, HIT_SOME);
1404 if result and (v <> 0) then gPlayers[idx].Push((xi*v), (yi*v));
1405 {$IF DEFINED(D2F_DEBUG)}
1406 //if result then e_WriteLog(Format(' PLAYER #%d HIT', [idx]), MSG_NOTIFY);
1407 {$ENDIF}
1408 end;
1410 function doMonsterHit (mon: TMonster; hx, hy: Integer): Boolean;
1411 begin
1412 result := false;
1413 if (mon = nil) then exit;
1414 result := HitMonster(mon, dmg, (xi*v)*10, (yi*v)*10-3, SpawnerUID, HIT_SOME);
1415 if result and (v <> 0) then mon.Push((xi*v), (yi*v));
1416 {$IF DEFINED(D2F_DEBUG)}
1417 //if result then e_WriteLog(Format(' MONSTER #%u HIT', [LongWord(mon.UID)]), MSG_NOTIFY);
1418 {$ENDIF}
1419 end;
1421 // collect players along hitray
1422 // return `true` if instant hit was detected
1423 function playerPossibleHit (): Boolean;
1424 var
1425 i: Integer;
1426 px, py, pw, ph: Integer;
1427 inx, iny: Integer;
1428 distSq: Integer;
1429 plr: TPlayer;
1430 begin
1431 result := false;
1432 for i := 0 to High(gPlayers) do
1433 begin
1434 plr := gPlayers[i];
1435 if (plr <> nil) and plr.alive then
1436 begin
1437 plr.getMapBox(px, py, pw, ph);
1438 if lineAABBIntersects(x, y, x2, y2, px, py, pw, ph, inx, iny) then
1439 begin
1440 distSq := distanceSq(x, y, inx, iny);
1441 if (distSq = 0) then
1442 begin
1443 // contains
1444 if doPlayerHit(i, x, y) then begin result := true; exit; end;
1445 end
1446 else if (distSq < wallDistSq) then
1447 begin
1448 appendHitTimePlr(distSq, i, inx, iny);
1449 end;
1450 end;
1451 end;
1452 end;
1453 end;
1455 procedure sqchecker (mon: TMonster);
1456 var
1457 mx, my, mw, mh: Integer;
1458 inx, iny: Integer;
1459 distSq: Integer;
1460 begin
1461 mon.getMapBox(mx, my, mw, mh);
1462 if lineAABBIntersects(x0, y0, x2, y2, mx, my, mw, mh, inx, iny) then
1463 begin
1464 distSq := distanceSq(x0, y0, inx, iny);
1465 if (distSq < wallDistSq) then appendHitTimeMon(distSq, mon, inx, iny);
1466 end;
1467 end;
1469 var
1470 a: Integer;
1471 dx, dy: Integer;
1472 xe, ye: Integer;
1473 s, c: Extended;
1474 i: Integer;
1475 wallHitFlag: Boolean = false;
1476 wallHitX: Integer = 0;
1477 wallHitY: Integer = 0;
1478 didHit: Boolean = false;
1479 {$IF DEFINED(D2F_DEBUG)}
1480 stt: UInt64;
1481 {$ENDIF}
1482 mit: PMonster;
1483 it: TMonsterGrid.Iter;
1484 begin
1485 (*
1486 if not gwep_debug_fast_trace then
1487 begin
1488 g_Weapon_gunOld(x, y, xd, yd, v, dmg, SpawnerUID, CheckTrigger);
1489 exit;
1490 end;
1491 *)
1493 if (xd = 0) and (yd = 0) then exit;
1495 //wgunMonHash.reset(); //FIXME: clear hash on level change
1496 wgunHitHeap.clear();
1497 wgunHitTimeUsed := 0;
1499 a := GetAngle(x, y, xd, yd)+180;
1501 SinCos(DegToRad(-a), s, c);
1503 if Abs(s) < 0.01 then s := 0;
1504 if Abs(c) < 0.01 then c := 0;
1506 x0 := x;
1507 y0 := y;
1508 x2 := x+Round(c*gMapInfo.Width);
1509 y2 := y+Round(s*gMapInfo.Width);
1511 dx := x2-x;
1512 dy := y2-y;
1514 if (dx > 0) then xi := 1 else if (dx < 0) then xi := -1 else xi := 0;
1515 if (dy > 0) then yi := 1 else if (dy < 0) then yi := -1 else yi := 0;
1517 {$IF DEFINED(D2F_DEBUG)}
1518 e_WriteLog(Format('GUN TRACE: (%d,%d) to (%d,%d)', [x, y, x2, y2]), TMsgType.Notify);
1519 stt := getTimeMicro();
1520 {$ENDIF}
1522 wallHitFlag := (g_Map_traceToNearestWall(x, y, x2, y2, @wallHitX, @wallHitY) <> nil);
1523 if wallHitFlag then
1524 begin
1525 x2 := wallHitX;
1526 y2 := wallHitY;
1527 wallDistSq := distanceSq(x, y, wallHitX, wallHitY);
1528 end
1529 else
1530 begin
1531 wallHitX := x2;
1532 wallHitY := y2;
1533 end;
1535 if playerPossibleHit() then exit; // instant hit
1537 // collect monsters
1538 //g_Mons_AlongLine(x, y, x2, y2, sqchecker);
1540 it := monsGrid.forEachAlongLine(x, y, x2, y2, -1);
1541 for mit in it do sqchecker(mit^);
1542 it.release();
1544 // here, we collected all monsters and players in `wgunHitHeap` and `wgunHitTime`
1545 // also, if `wallWasHit` is `true`, then `wallHitX` and `wallHitY` contains spark coords
1546 while (wgunHitHeap.count > 0) do
1547 begin
1548 // has some entities to check, do it
1549 i := wgunHitHeap.front;
1550 wgunHitHeap.popFront();
1551 // hitpoint
1552 xe := wgunHitTime[i].x;
1553 ye := wgunHitTime[i].y;
1554 // check if it is not behind the wall
1555 if (wgunHitTime[i].mon <> nil) then
1556 begin
1557 didHit := doMonsterHit(wgunHitTime[i].mon, xe, ye);
1558 end
1559 else
1560 begin
1561 didHit := doPlayerHit(wgunHitTime[i].plridx, xe, ye);
1562 end;
1563 if didHit then
1564 begin
1565 // need new coords for trigger
1566 wallHitX := xe;
1567 wallHitY := ye;
1568 wallHitFlag := false; // no sparks
1569 break;
1570 end;
1571 end;
1573 // need sparks?
1574 if wallHitFlag then
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 g_GFX_Spark(wallHitX, wallHitY, 2+Random(2), 180+a, 0, 0);
1581 if g_Game_IsServer and g_Game_IsNet then MH_SEND_Effect(wallHitX, wallHitY, 180+a, NET_GFX_SPARK);
1582 end
1583 else
1584 begin
1585 {$IF DEFINED(D2F_DEBUG)}
1586 stt := getTimeMicro()-stt;
1587 e_WriteLog(Format('*** new trace time: %u microseconds', [LongWord(stt)]), TMsgType.Notify);
1588 {$ENDIF}
1589 end;
1591 if CheckTrigger and g_Game_IsServer then g_Triggers_PressL(X, Y, wallHitX, wallHitY, SpawnerUID, ACTIVATE_SHOT);
1592 end;
1595 procedure g_Weapon_punch(x, y: Integer; d, SpawnerUID: Word);
1596 var
1597 obj: TObj;
1598 begin
1599 obj.X := X;
1600 obj.Y := Y;
1601 obj.rect.X := 0;
1602 obj.rect.Y := 0;
1603 obj.rect.Width := 39;
1604 obj.rect.Height := 52;
1605 obj.Vel.X := 0;
1606 obj.Vel.Y := 0;
1607 obj.Accel.X := 0;
1608 obj.Accel.Y := 0;
1610 if g_Weapon_Hit(@obj, d, SpawnerUID, HIT_SOME) <> 0 then
1611 g_Sound_PlayExAt('SOUND_WEAPON_HITPUNCH', x, y)
1612 else
1613 g_Sound_PlayExAt('SOUND_WEAPON_MISSPUNCH', x, y);
1614 end;
1616 function g_Weapon_chainsaw(x, y: Integer; d, SpawnerUID: Word): Integer;
1617 var
1618 obj: TObj;
1619 begin
1620 obj.X := X;
1621 obj.Y := Y;
1622 obj.rect.X := 0;
1623 obj.rect.Y := 0;
1624 obj.rect.Width := 32;
1625 obj.rect.Height := 52;
1626 obj.Vel.X := 0;
1627 obj.Vel.Y := 0;
1628 obj.Accel.X := 0;
1629 obj.Accel.Y := 0;
1631 Result := g_Weapon_Hit(@obj, d, SpawnerUID, HIT_SOME);
1632 end;
1634 procedure g_Weapon_rocket(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1635 Silent: Boolean = False);
1636 var
1637 find_id: DWORD;
1638 dx, dy: Integer;
1639 begin
1640 if WID < 0 then
1641 find_id := FindShot()
1642 else
1643 begin
1644 find_id := WID;
1645 if Integer(find_id) >= High(Shots) then
1646 SetLength(Shots, find_id + 64)
1647 end;
1649 with Shots[find_id] do
1650 begin
1651 g_Obj_Init(@Obj);
1653 Obj.Rect.Width := SHOT_ROCKETLAUNCHER_WIDTH;
1654 Obj.Rect.Height := SHOT_ROCKETLAUNCHER_HEIGHT;
1656 dx := IfThen(xd > x, -Obj.Rect.Width, 0);
1657 dy := -(Obj.Rect.Height div 2);
1659 ShotType := WEAPON_ROCKETLAUNCHER;
1660 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 12);
1662 Animation := nil;
1663 triggers := nil;
1664 g_Texture_Get('TEXTURE_WEAPON_ROCKET', TextureID);
1665 end;
1667 Shots[find_id].SpawnerUID := SpawnerUID;
1669 if not Silent then
1670 g_Sound_PlayExAt('SOUND_WEAPON_FIREROCKET', x, y);
1671 end;
1673 procedure g_Weapon_revf(x, y, xd, yd: Integer; SpawnerUID, TargetUID: Word;
1674 WID: Integer = -1; Silent: Boolean = False);
1675 var
1676 find_id, FramesID: DWORD;
1677 dx, dy: Integer;
1678 begin
1679 if WID < 0 then
1680 find_id := FindShot()
1681 else
1682 begin
1683 find_id := WID;
1684 if Integer(find_id) >= High(Shots) then
1685 SetLength(Shots, find_id + 64)
1686 end;
1688 with Shots[find_id] do
1689 begin
1690 g_Obj_Init(@Obj);
1692 Obj.Rect.Width := SHOT_SKELFIRE_WIDTH;
1693 Obj.Rect.Height := SHOT_SKELFIRE_HEIGHT;
1695 dx := -(Obj.Rect.Width div 2);
1696 dy := -(Obj.Rect.Height div 2);
1698 ShotType := WEAPON_SKEL_FIRE;
1699 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 12);
1701 triggers := nil;
1702 target := TargetUID;
1703 g_Frames_Get(FramesID, 'FRAMES_WEAPON_SKELFIRE');
1704 Animation := TAnimation.Create(FramesID, True, 5);
1705 end;
1707 Shots[find_id].SpawnerUID := SpawnerUID;
1709 if not Silent then
1710 g_Sound_PlayExAt('SOUND_WEAPON_FIREREV', x, y);
1711 end;
1713 procedure g_Weapon_plasma(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1714 Silent: Boolean = False);
1715 var
1716 find_id, FramesID: DWORD;
1717 dx, dy: Integer;
1718 begin
1719 if WID < 0 then
1720 find_id := FindShot()
1721 else
1722 begin
1723 find_id := WID;
1724 if Integer(find_id) >= High(Shots) then
1725 SetLength(Shots, find_id + 64);
1726 end;
1728 with Shots[find_id] do
1729 begin
1730 g_Obj_Init(@Obj);
1732 Obj.Rect.Width := SHOT_PLASMA_WIDTH;
1733 Obj.Rect.Height := SHOT_PLASMA_HEIGHT;
1735 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1736 dy := -(Obj.Rect.Height div 2);
1738 ShotType := WEAPON_PLASMA;
1739 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1741 triggers := nil;
1742 g_Frames_Get(FramesID, 'FRAMES_WEAPON_PLASMA');
1743 Animation := TAnimation.Create(FramesID, True, 5);
1744 end;
1746 Shots[find_id].SpawnerUID := SpawnerUID;
1748 if not Silent then
1749 g_Sound_PlayExAt('SOUND_WEAPON_FIREPLASMA', x, y);
1750 end;
1752 procedure g_Weapon_flame(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1753 Silent: Boolean = False);
1754 var
1755 find_id: DWORD;
1756 dx, dy: Integer;
1757 begin
1758 if WID < 0 then
1759 find_id := FindShot()
1760 else
1761 begin
1762 find_id := WID;
1763 if Integer(find_id) >= High(Shots) then
1764 SetLength(Shots, find_id + 64);
1765 end;
1767 with Shots[find_id] do
1768 begin
1769 g_Obj_Init(@Obj);
1771 Obj.Rect.Width := SHOT_FLAME_WIDTH;
1772 Obj.Rect.Height := SHOT_FLAME_HEIGHT;
1774 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1775 dy := -(Obj.Rect.Height div 2);
1777 ShotType := WEAPON_FLAMETHROWER;
1778 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1780 triggers := nil;
1781 Animation := nil;
1782 TextureID := 0;
1783 g_Frames_Get(TextureID, 'FRAMES_FLAME');
1784 end;
1786 Shots[find_id].SpawnerUID := SpawnerUID;
1788 // if not Silent then
1789 // g_Sound_PlayExAt('SOUND_WEAPON_FIREPLASMA', x, y);
1790 end;
1792 procedure g_Weapon_ball1(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1793 Silent: Boolean = False);
1794 var
1795 find_id, FramesID: DWORD;
1796 dx, dy: Integer;
1797 begin
1798 if WID < 0 then
1799 find_id := FindShot()
1800 else
1801 begin
1802 find_id := WID;
1803 if Integer(find_id) >= High(Shots) then
1804 SetLength(Shots, find_id + 64)
1805 end;
1807 with Shots[find_id] do
1808 begin
1809 g_Obj_Init(@Obj);
1811 Obj.Rect.Width := 16;
1812 Obj.Rect.Height := 16;
1814 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1815 dy := -(Obj.Rect.Height div 2);
1817 ShotType := WEAPON_IMP_FIRE;
1818 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1820 triggers := nil;
1821 g_Frames_Get(FramesID, 'FRAMES_WEAPON_IMPFIRE');
1822 Animation := TAnimation.Create(FramesID, True, 4);
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_ball2(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1832 Silent: Boolean = False);
1833 var
1834 find_id, FramesID: 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 := 16;
1851 Obj.Rect.Height := 16;
1853 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
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 g_Frames_Get(FramesID, 'FRAMES_WEAPON_CACOFIRE');
1861 Animation := TAnimation.Create(FramesID, True, 4);
1862 end;
1864 Shots[find_id].SpawnerUID := SpawnerUID;
1866 if not Silent then
1867 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x, y);
1868 end;
1870 procedure g_Weapon_ball7(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1871 Silent: Boolean = False);
1872 var
1873 find_id, FramesID: DWORD;
1874 dx, dy: Integer;
1875 begin
1876 if WID < 0 then
1877 find_id := FindShot()
1878 else
1879 begin
1880 find_id := WID;
1881 if Integer(find_id) >= High(Shots) then
1882 SetLength(Shots, find_id + 64)
1883 end;
1885 with Shots[find_id] do
1886 begin
1887 g_Obj_Init(@Obj);
1889 Obj.Rect.Width := 32;
1890 Obj.Rect.Height := 16;
1892 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1893 dy := -(Obj.Rect.Height div 2);
1895 ShotType := WEAPON_BARON_FIRE;
1896 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1898 triggers := nil;
1899 g_Frames_Get(FramesID, 'FRAMES_WEAPON_BARONFIRE');
1900 Animation := TAnimation.Create(FramesID, True, 4);
1901 end;
1903 Shots[find_id].SpawnerUID := SpawnerUID;
1905 if not Silent then
1906 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x, y);
1907 end;
1909 procedure g_Weapon_aplasma(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1910 Silent: Boolean = False);
1911 var
1912 find_id, FramesID: DWORD;
1913 dx, dy: Integer;
1914 begin
1915 if WID < 0 then
1916 find_id := FindShot()
1917 else
1918 begin
1919 find_id := WID;
1920 if Integer(find_id) >= High(Shots) then
1921 SetLength(Shots, find_id + 64)
1922 end;
1924 with Shots[find_id] do
1925 begin
1926 g_Obj_Init(@Obj);
1928 Obj.Rect.Width := 16;
1929 Obj.Rect.Height := 16;
1931 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1932 dy := -(Obj.Rect.Height div 2);
1934 ShotType := WEAPON_BSP_FIRE;
1935 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1937 triggers := nil;
1939 g_Frames_Get(FramesID, 'FRAMES_WEAPON_BSPFIRE');
1940 Animation := TAnimation.Create(FramesID, True, 4);
1941 end;
1943 Shots[find_id].SpawnerUID := SpawnerUID;
1945 if not Silent then
1946 g_Sound_PlayExAt('SOUND_WEAPON_FIREPLASMA', x, y);
1947 end;
1949 procedure g_Weapon_manfire(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1950 Silent: Boolean = False);
1951 var
1952 find_id, FramesID: DWORD;
1953 dx, dy: Integer;
1954 begin
1955 if WID < 0 then
1956 find_id := FindShot()
1957 else
1958 begin
1959 find_id := WID;
1960 if Integer(find_id) >= High(Shots) then
1961 SetLength(Shots, find_id + 64)
1962 end;
1964 with Shots[find_id] do
1965 begin
1966 g_Obj_Init(@Obj);
1968 Obj.Rect.Width := 32;
1969 Obj.Rect.Height := 32;
1971 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1972 dy := -(Obj.Rect.Height div 2);
1974 ShotType := WEAPON_MANCUB_FIRE;
1975 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1977 triggers := nil;
1979 g_Frames_Get(FramesID, 'FRAMES_WEAPON_MANCUBFIRE');
1980 Animation := TAnimation.Create(FramesID, True, 4);
1981 end;
1983 Shots[find_id].SpawnerUID := SpawnerUID;
1985 if not Silent then
1986 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x, y);
1987 end;
1989 procedure g_Weapon_bfgshot(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1990 Silent: Boolean = False);
1991 var
1992 find_id, FramesID: DWORD;
1993 dx, dy: Integer;
1994 begin
1995 if WID < 0 then
1996 find_id := FindShot()
1997 else
1998 begin
1999 find_id := WID;
2000 if Integer(find_id) >= High(Shots) then
2001 SetLength(Shots, find_id + 64)
2002 end;
2004 with Shots[find_id] do
2005 begin
2006 g_Obj_Init(@Obj);
2008 Obj.Rect.Width := SHOT_BFG_WIDTH;
2009 Obj.Rect.Height := SHOT_BFG_HEIGHT;
2011 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
2012 dy := -(Obj.Rect.Height div 2);
2014 ShotType := WEAPON_BFG;
2015 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
2017 triggers := nil;
2018 g_Frames_Get(FramesID, 'FRAMES_WEAPON_BFG');
2019 Animation := TAnimation.Create(FramesID, True, 6);
2020 end;
2022 Shots[find_id].SpawnerUID := SpawnerUID;
2024 if not Silent then
2025 g_Sound_PlayExAt('SOUND_WEAPON_FIREBFG', x, y);
2026 end;
2028 procedure g_Weapon_bfghit(x, y: Integer);
2029 var
2030 ID: DWORD;
2031 Anim: TAnimation;
2032 begin
2033 if g_Frames_Get(ID, 'FRAMES_BFGHIT') then
2034 begin
2035 Anim := TAnimation.Create(ID, False, 4);
2036 g_GFX_OnceAnim(x-32, y-32, Anim);
2037 Anim.Free();
2038 end;
2039 end;
2041 procedure g_Weapon_pistol(x, y, xd, yd: Integer; SpawnerUID: Word;
2042 Silent: Boolean = False);
2043 begin
2044 if not Silent then
2045 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', x, y);
2047 g_Weapon_gun(x, y, xd, yd, 1, 3, SpawnerUID, True);
2048 if gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF] then
2049 begin
2050 g_Weapon_gun(x, y+1, xd, yd+1, 1, 3, SpawnerUID, False);
2051 g_Weapon_gun(x, y-1, xd, yd-1, 1, 2, SpawnerUID, False);
2052 end;
2053 end;
2055 procedure g_Weapon_mgun(x, y, xd, yd: Integer; SpawnerUID: Word;
2056 Silent: Boolean = False);
2057 begin
2058 if not Silent then
2059 if gSoundEffectsDF then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', x, y);
2061 g_Weapon_gun(x, y, xd, yd, 1, 3, SpawnerUID, True);
2062 if (gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF]) and
2063 (g_GetUIDType(SpawnerUID) = UID_PLAYER) then
2064 begin
2065 g_Weapon_gun(x, y+1, xd, yd+1, 1, 2, SpawnerUID, False);
2066 g_Weapon_gun(x, y-1, xd, yd-1, 1, 2, SpawnerUID, False);
2067 end;
2068 end;
2070 procedure g_Weapon_shotgun(x, y, xd, yd: Integer; SpawnerUID: Word;
2071 Silent: Boolean = False);
2072 var
2073 i, j: Integer;
2074 begin
2075 if not Silent then
2076 if gSoundEffectsDF then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', x, y);
2078 for i := 0 to 9 do
2079 begin
2080 j := Random(17)-8; // -8 .. 8
2081 g_Weapon_gun(x, y+j, xd, yd+j, IfThen(i mod 2 <> 0, 1, 0), 3, SpawnerUID, i=0);
2082 end;
2083 end;
2085 procedure g_Weapon_dshotgun(x, y, xd, yd: Integer; SpawnerUID: Word;
2086 Silent: Boolean = False);
2087 var
2088 a, i, j: Integer;
2089 begin
2090 if not Silent then
2091 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', x, y);
2093 if gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF] then a := 25 else a := 20;
2094 for i := 0 to a do
2095 begin
2096 j := Random(41)-20; // -20 .. 20
2097 g_Weapon_gun(x, y+j, xd, yd+j, IfThen(i mod 3 <> 0, 0, 1), 3, SpawnerUID, i=0);
2098 end;
2099 end;
2101 procedure g_Weapon_PreUpdate();
2102 var
2103 i: Integer;
2104 begin
2105 if Shots = nil then Exit;
2106 for i := 0 to High(Shots) do
2107 if Shots[i].ShotType <> 0 then
2108 begin
2109 Shots[i].Obj.oldX := Shots[i].Obj.X;
2110 Shots[i].Obj.oldY := Shots[i].Obj.Y;
2111 end;
2112 end;
2114 procedure g_Weapon_Update();
2115 var
2116 i, a, h, cx, cy, oldvx, oldvy, tf: Integer;
2117 _id: DWORD;
2118 Anim: TAnimation;
2119 t: DWArray;
2120 st: Word;
2121 s: String;
2122 o: TObj;
2123 spl: Boolean;
2124 Loud: Boolean;
2125 tcx, tcy: Integer;
2126 begin
2127 if Shots = nil then
2128 Exit;
2130 for i := 0 to High(Shots) do
2131 begin
2132 if Shots[i].ShotType = 0 then
2133 Continue;
2135 Loud := True;
2137 with Shots[i] do
2138 begin
2139 Timeout := Timeout - 1;
2140 oldvx := Obj.Vel.X;
2141 oldvy := Obj.Vel.Y;
2142 // Àêòèâèðîâàòü òðèããåðû ïî ïóòè (êðîìå óæå àêòèâèðîâàííûõ):
2143 if (Stopped = 0) and g_Game_IsServer then
2144 t := g_Triggers_PressR(Obj.X, Obj.Y, Obj.Rect.Width, Obj.Rect.Height,
2145 SpawnerUID, ACTIVATE_SHOT, triggers)
2146 else
2147 t := nil;
2149 if t <> nil then
2150 begin
2151 // Ïîïîëíÿåì ñïèñîê àêòèâèðîâàííûõ òðèããåðîâ:
2152 if triggers = nil then
2153 triggers := t
2154 else
2155 begin
2156 h := High(t);
2158 for a := 0 to h do
2159 if not InDWArray(t[a], triggers) then
2160 begin
2161 SetLength(triggers, Length(triggers)+1);
2162 triggers[High(triggers)] := t[a];
2163 end;
2164 end;
2165 end;
2167 // Àíèìàöèÿ ñíàðÿäà:
2168 if Animation <> nil then
2169 Animation.Update();
2171 // Äâèæåíèå:
2172 spl := (ShotType <> WEAPON_PLASMA) and
2173 (ShotType <> WEAPON_BFG) and
2174 (ShotType <> WEAPON_BSP_FIRE) and
2175 (ShotType <> WEAPON_FLAMETHROWER);
2177 if Stopped = 0 then
2178 begin
2179 st := g_Obj_Move_Projectile(@Obj, False, spl);
2180 end
2181 else
2182 begin
2183 st := 0;
2184 end;
2185 positionChanged(); // this updates spatial accelerators
2187 if WordBool(st and MOVE_FALLOUT) or (Obj.X < -1000) or
2188 (Obj.X > gMapInfo.Width+1000) or (Obj.Y < -1000) then
2189 begin
2190 // Íà êëèåíòå ñêîðåå âñåãî è òàê óæå âûïàë.
2191 ShotType := 0;
2192 Animation.Free();
2193 Continue;
2194 end;
2196 cx := Obj.X + (Obj.Rect.Width div 2);
2197 cy := Obj.Y + (Obj.Rect.Height div 2);
2199 case ShotType of
2200 WEAPON_ROCKETLAUNCHER, WEAPON_SKEL_FIRE: // Ðàêåòû è ñíàðÿäû Ñêåëåòà
2201 begin
2202 // Âûëåòåëà èç âîäû:
2203 if WordBool(st and MOVE_HITAIR) then
2204 g_Obj_SetSpeed(@Obj, 12);
2206 // Â âîäå øëåéô - ïóçûðè, â âîçäóõå øëåéô - äûì:
2207 if WordBool(st and MOVE_INWATER) then
2208 g_GFX_Bubbles(Obj.X+(Obj.Rect.Width div 2),
2209 Obj.Y+(Obj.Rect.Height div 2),
2210 1+Random(3), 16, 16)
2211 else
2212 if g_Frames_Get(_id, 'FRAMES_SMOKE') then
2213 begin
2214 Anim := TAnimation.Create(_id, False, 3);
2215 Anim.Alpha := 150;
2216 g_GFX_OnceAnim(Obj.X-14+Random(9),
2217 Obj.Y+(Obj.Rect.Height div 2)-20+Random(9),
2218 Anim, ONCEANIM_SMOKE);
2219 Anim.Free();
2220 end;
2222 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2223 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL)) or
2224 (g_Weapon_Hit(@Obj, 10, SpawnerUID, HIT_SOME, False) <> 0) or
2225 (Timeout < 1) then
2226 begin
2227 Obj.Vel.X := 0;
2228 Obj.Vel.Y := 0;
2230 g_Weapon_Explode(cx, cy, 60, SpawnerUID);
2232 if ShotType = WEAPON_SKEL_FIRE then
2233 begin // Âçðûâ ñíàðÿäà Ñêåëåòà
2234 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_SKELFIRE') then
2235 begin
2236 Anim := TAnimation.Create(TextureID, False, 8);
2237 Anim.Blending := False;
2238 g_GFX_OnceAnim((Obj.X+32)-58, (Obj.Y+8)-36, Anim);
2239 g_DynLightExplosion((Obj.X+32), (Obj.Y+8), 64, 1, 0, 0);
2240 Anim.Free();
2241 end;
2242 end
2243 else
2244 begin // Âçðûâ Ðàêåòû
2245 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_ROCKET') then
2246 begin
2247 Anim := TAnimation.Create(TextureID, False, 6);
2248 Anim.Blending := False;
2249 g_GFX_OnceAnim(cx-64, cy-64, Anim);
2250 g_DynLightExplosion(cx, cy, 64, 1, 0, 0);
2251 Anim.Free();
2252 end;
2253 end;
2255 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', Obj.X, Obj.Y);
2257 ShotType := 0;
2258 end;
2260 if ShotType = WEAPON_SKEL_FIRE then
2261 begin // Ñàìîíàâîäêà ñíàðÿäà Ñêåëåòà:
2262 if GetPos(target, @o) then
2263 throw(i, Obj.X, Obj.Y,
2264 o.X+o.Rect.X+(o.Rect.Width div 2)+o.Vel.X+o.Accel.X,
2265 o.Y+o.Rect.Y+(o.Rect.Height div 2)+o.Vel.Y+o.Accel.Y,
2266 12);
2267 end;
2268 end;
2270 WEAPON_PLASMA, WEAPON_BSP_FIRE: // Ïëàçìà, ïëàçìà Àðàõíàòðîíà
2271 begin
2272 // Ïîïàëà â âîäó - ýëåêòðîøîê ïî âîäå:
2273 if WordBool(st and (MOVE_INWATER or MOVE_HITWATER)) then
2274 begin
2275 g_Sound_PlayExAt('SOUND_WEAPON_PLASMAWATER', Obj.X, Obj.Y);
2276 if g_Game_IsServer then CheckTrap(i, 10, HIT_ELECTRO);
2277 ShotType := 0;
2278 Continue;
2279 end;
2281 // Âåëè÷èíà óðîíà:
2282 if (ShotType = WEAPON_PLASMA) and
2283 (gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF]) then
2284 a := 10
2285 else
2286 a := 5;
2288 if ShotType = WEAPON_BSP_FIRE then
2289 a := 10;
2291 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2292 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL)) or
2293 (g_Weapon_Hit(@Obj, a, SpawnerUID, HIT_SOME, False) <> 0) or
2294 (Timeout < 1) then
2295 begin
2296 if ShotType = WEAPON_PLASMA then
2297 s := 'FRAMES_EXPLODE_PLASMA'
2298 else
2299 s := 'FRAMES_EXPLODE_BSPFIRE';
2301 // Âçðûâ Ïëàçìû:
2302 if g_Frames_Get(TextureID, s) then
2303 begin
2304 Anim := TAnimation.Create(TextureID, False, 3);
2305 Anim.Blending := False;
2306 g_GFX_OnceAnim(cx-16, cy-16, Anim);
2307 Anim.Free();
2308 g_DynLightExplosion(cx, cy, 32, 0, 0.5, 0.5);
2309 end;
2311 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEPLASMA', Obj.X, Obj.Y);
2313 ShotType := 0;
2314 end;
2315 end;
2317 WEAPON_FLAMETHROWER: // Îãíåìåò
2318 begin
2319 // Ñî âðåìåíåì óìèðàåò
2320 if (Timeout < 1) then
2321 begin
2322 ShotType := 0;
2323 Continue;
2324 end;
2325 // Ïîä âîäîé òîæå
2326 if WordBool(st and (MOVE_HITWATER or MOVE_INWATER)) then
2327 begin
2328 if WordBool(st and MOVE_HITWATER) then
2329 begin
2330 if g_Frames_Get(_id, 'FRAMES_SMOKE') then
2331 begin
2332 Anim := TAnimation.Create(_id, False, 3);
2333 Anim.Alpha := 0;
2334 tcx := Random(8);
2335 tcy := Random(8);
2336 g_GFX_OnceAnim(cx-4+tcx-(Anim.Width div 2),
2337 cy-4+tcy-(Anim.Height div 2),
2338 Anim, ONCEANIM_SMOKE);
2339 Anim.Free();
2340 end;
2341 end
2342 else
2343 g_GFX_Bubbles(cx, cy, 1+Random(3), 16, 16);
2344 ShotType := 0;
2345 Continue;
2346 end;
2348 // Ãðàâèòàöèÿ
2349 if Stopped = 0 then
2350 Obj.Accel.Y := Obj.Accel.Y + 1;
2351 // Ïîïàëè â ñòåíó èëè â âîäó:
2352 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL or MOVE_HITWATER)) then
2353 begin
2354 // Ïðèëèïàåì:
2355 Obj.Vel.X := 0;
2356 Obj.Vel.Y := 0;
2357 Obj.Accel.Y := 0;
2358 if WordBool(st and MOVE_HITWALL) then
2359 Stopped := MOVE_HITWALL
2360 else if WordBool(st and MOVE_HITLAND) then
2361 Stopped := MOVE_HITLAND
2362 else if WordBool(st and MOVE_HITCEIL) then
2363 Stopped := MOVE_HITCEIL;
2364 end;
2366 a := IfThen(Stopped = 0, 10, 1);
2367 // Åñëè â êîãî-òî ïîïàëè
2368 if g_Weapon_Hit(@Obj, a, SpawnerUID, HIT_FLAME, False) <> 0 then
2369 begin
2370 // HIT_FLAME ñàì ïîäîææåò
2371 // Åñëè â ïîëåòå ïîïàëè, èñ÷åçàåì
2372 if Stopped = 0 then
2373 ShotType := 0;
2374 end;
2376 if Stopped = 0 then
2377 tf := 2
2378 else
2379 tf := 3;
2381 if (gTime mod LongWord(tf) = 0) then
2382 begin
2383 Anim := TAnimation.Create(TextureID, False, 2 + Random(2));
2384 Anim.Alpha := 0;
2385 case Stopped of
2386 MOVE_HITWALL: begin tcx := cx-4+Random(8); tcy := cy-12+Random(24); end;
2387 MOVE_HITLAND: begin tcx := cx-12+Random(24); tcy := cy-10+Random(8); end;
2388 MOVE_HITCEIL: begin tcx := cx-12+Random(24); tcy := cy+6+Random(8); end;
2389 else begin tcx := cx-4+Random(8); tcy := cy-4+Random(8); end;
2390 end;
2391 g_GFX_OnceAnim(tcx-(Anim.Width div 2), tcy-(Anim.Height div 2), Anim, ONCEANIM_SMOKE);
2392 Anim.Free();
2393 //g_DynLightExplosion(tcx, tcy, 1, 1, 0.8, 0.3);
2394 end;
2395 end;
2397 WEAPON_BFG: // BFG
2398 begin
2399 // Ïîïàëà â âîäó - ýëåêòðîøîê ïî âîäå:
2400 if WordBool(st and (MOVE_INWATER or MOVE_HITWATER)) then
2401 begin
2402 g_Sound_PlayExAt('SOUND_WEAPON_BFGWATER', Obj.X, Obj.Y);
2403 if g_Game_IsServer then CheckTrap(i, 1000, HIT_ELECTRO);
2404 ShotType := 0;
2405 Continue;
2406 end;
2408 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2409 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL)) or
2410 (g_Weapon_Hit(@Obj, SHOT_BFG_DAMAGE, SpawnerUID, HIT_BFG, False) <> 0) or
2411 (Timeout < 1) then
2412 begin
2413 // Ëó÷è BFG:
2414 if g_Game_IsServer then g_Weapon_BFG9000(cx, cy, SpawnerUID);
2416 // Âçðûâ BFG:
2417 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_BFG') then
2418 begin
2419 Anim := TAnimation.Create(TextureID, False, 6);
2420 Anim.Blending := False;
2421 g_GFX_OnceAnim(cx-64, cy-64, Anim);
2422 Anim.Free();
2423 g_DynLightExplosion(cx, cy, 96, 0, 1, 0);
2424 end;
2426 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', Obj.X, Obj.Y);
2428 ShotType := 0;
2429 end;
2430 end;
2432 WEAPON_IMP_FIRE, WEAPON_CACO_FIRE, WEAPON_BARON_FIRE: // Âûñòðåëû Áåñà, Êàêîäåìîíà Ðûöàðÿ/Áàðîíà àäà
2433 begin
2434 // Âûëåòåë èç âîäû:
2435 if WordBool(st and MOVE_HITAIR) then
2436 g_Obj_SetSpeed(@Obj, 16);
2438 // Âåëè÷èíà óðîíà:
2439 if ShotType = WEAPON_IMP_FIRE then
2440 a := 5
2441 else
2442 if ShotType = WEAPON_CACO_FIRE then
2443 a := 20
2444 else
2445 a := 40;
2447 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2448 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL)) or
2449 (g_Weapon_Hit(@Obj, a, SpawnerUID, HIT_SOME) <> 0) or
2450 (Timeout < 1) then
2451 begin
2452 if ShotType = WEAPON_IMP_FIRE then
2453 s := 'FRAMES_EXPLODE_IMPFIRE'
2454 else
2455 if ShotType = WEAPON_CACO_FIRE then
2456 s := 'FRAMES_EXPLODE_CACOFIRE'
2457 else
2458 s := 'FRAMES_EXPLODE_BARONFIRE';
2460 // Âçðûâ:
2461 if g_Frames_Get(TextureID, s) then
2462 begin
2463 Anim := TAnimation.Create(TextureID, False, 6);
2464 Anim.Blending := False;
2465 g_GFX_OnceAnim(cx-32, cy-32, Anim);
2466 Anim.Free();
2467 end;
2469 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj.X, Obj.Y);
2471 ShotType := 0;
2472 end;
2473 end;
2475 WEAPON_MANCUB_FIRE: // Âûñòðåë Ìàíêóáóñà
2476 begin
2477 // Âûëåòåë èç âîäû:
2478 if WordBool(st and MOVE_HITAIR) then
2479 g_Obj_SetSpeed(@Obj, 16);
2481 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
2482 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL)) or
2483 (g_Weapon_Hit(@Obj, 40, SpawnerUID, HIT_SOME, False) <> 0) or
2484 (Timeout < 1) then
2485 begin
2486 // Âçðûâ:
2487 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_ROCKET') then
2488 begin
2489 Anim := TAnimation.Create(TextureID, False, 6);
2490 Anim.Blending := False;
2491 g_GFX_OnceAnim(cx-64, cy-64, Anim);
2492 Anim.Free();
2493 end;
2495 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj.X, Obj.Y);
2497 ShotType := 0;
2498 end;
2499 end;
2500 end; // case ShotType of...
2502 // Åñëè ñíàðÿäà óæå íåò, óäàëÿåì àíèìàöèþ:
2503 if (ShotType = 0) then
2504 begin
2505 if gGameSettings.GameType = GT_SERVER then
2506 MH_SEND_DeleteShot(i, Obj.X, Obj.Y, Loud);
2507 if Animation <> nil then
2508 begin
2509 Animation.Free();
2510 Animation := nil;
2511 end;
2512 end
2513 else if (ShotType <> WEAPON_FLAMETHROWER) and ((oldvx <> Obj.Vel.X) or (oldvy <> Obj.Vel.Y)) then
2514 if gGameSettings.GameType = GT_SERVER then
2515 MH_SEND_UpdateShot(i);
2516 end;
2517 end;
2518 end;
2520 procedure g_Weapon_Draw();
2521 var
2522 i, fX, fY: Integer;
2523 a: SmallInt;
2524 p: TDFPoint;
2525 begin
2526 if Shots = nil then
2527 Exit;
2529 for i := 0 to High(Shots) do
2530 if Shots[i].ShotType <> 0 then
2531 with Shots[i] do
2532 begin
2533 if (Shots[i].ShotType = WEAPON_ROCKETLAUNCHER) or
2534 (Shots[i].ShotType = WEAPON_BARON_FIRE) or
2535 (Shots[i].ShotType = WEAPON_MANCUB_FIRE) or
2536 (Shots[i].ShotType = WEAPON_SKEL_FIRE) then
2537 a := -GetAngle2(Obj.Vel.X, Obj.Vel.Y)
2538 else
2539 a := 0;
2541 Obj.lerp(gLerpFactor, fX, fY);
2542 p.X := Obj.Rect.Width div 2;
2543 p.Y := Obj.Rect.Height div 2;
2545 if Animation <> nil then
2546 begin
2547 if (Shots[i].ShotType = WEAPON_BARON_FIRE) or
2548 (Shots[i].ShotType = WEAPON_MANCUB_FIRE) or
2549 (Shots[i].ShotType = WEAPON_SKEL_FIRE) then
2550 Animation.DrawEx(fX, fY, TMirrorType.None, p, a)
2551 else
2552 Animation.Draw(fX, fY, TMirrorType.None);
2553 end
2554 else if TextureID <> 0 then
2555 begin
2556 if (Shots[i].ShotType = WEAPON_ROCKETLAUNCHER) then
2557 e_DrawAdv(TextureID, fX, fY, 0, True, False, a, @p, TMirrorType.None)
2558 else if (Shots[i].ShotType <> WEAPON_FLAMETHROWER) then
2559 e_Draw(TextureID, fX, fY, 0, True, False);
2560 end;
2562 if g_debug_Frames then
2563 begin
2564 e_DrawQuad(Obj.X+Obj.Rect.X,
2565 Obj.Y+Obj.Rect.Y,
2566 Obj.X+Obj.Rect.X+Obj.Rect.Width-1,
2567 Obj.Y+Obj.Rect.Y+Obj.Rect.Height-1,
2568 0, 255, 0);
2569 end;
2570 end;
2571 end;
2573 function g_Weapon_Danger(UID: Word; X, Y: Integer; Width, Height: Word; Time: Byte): Boolean;
2574 var
2575 a: Integer;
2576 begin
2577 Result := False;
2579 if Shots = nil then
2580 Exit;
2582 for a := 0 to High(Shots) do
2583 if (Shots[a].ShotType <> 0) and (Shots[a].SpawnerUID <> UID) then
2584 if ((Shots[a].Obj.Vel.Y = 0) and (Shots[a].Obj.Vel.X > 0) and (Shots[a].Obj.X < X)) or
2585 (Shots[a].Obj.Vel.Y = 0) and (Shots[a].Obj.Vel.X < 0) and (Shots[a].Obj.X > X) then
2586 if (Abs(X-Shots[a].Obj.X) < Abs(Shots[a].Obj.Vel.X*Time)) and
2587 g_Collide(X, Y, Width, Height, X, Shots[a].Obj.Y,
2588 Shots[a].Obj.Rect.Width, Shots[a].Obj.Rect.Height) and
2589 g_TraceVector(X, Y, Shots[a].Obj.X, Shots[a].Obj.Y) then
2590 begin
2591 Result := True;
2592 Exit;
2593 end;
2594 end;
2596 procedure g_Weapon_SaveState (st: TStream);
2597 var
2598 count, i, j: Integer;
2599 begin
2600 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ ñíàðÿäîâ
2601 count := 0;
2602 for i := 0 to High(Shots) do if (Shots[i].ShotType <> 0) then Inc(count);
2604 // Êîëè÷åñòâî ñíàðÿäîâ
2605 utils.WriteInt(st, count);
2607 if (count = 0) then exit;
2609 for i := 0 to High(Shots) do
2610 begin
2611 if Shots[i].ShotType <> 0 then
2612 begin
2613 // Ñèãíàòóðà ñíàðÿäà
2614 utils.writeSign(st, 'SHOT');
2615 utils.writeInt(st, Byte(0)); // version
2616 // Òèï ñíàðÿäà
2617 utils.writeInt(st, Byte(Shots[i].ShotType));
2618 // Öåëü
2619 utils.writeInt(st, Word(Shots[i].Target));
2620 // UID ñòðåëÿâøåãî
2621 utils.writeInt(st, Word(Shots[i].SpawnerUID));
2622 // Ðàçìåð ïîëÿ Triggers
2623 utils.writeInt(st, Integer(Length(Shots[i].Triggers)));
2624 // Òðèããåðû, àêòèâèðîâàííûå âûñòðåëîì
2625 for j := 0 to Length(Shots[i].Triggers)-1 do utils.writeInt(st, LongWord(Shots[i].Triggers[j]));
2626 // Îáúåêò ñíàðÿäà
2627 Obj_SaveState(st, @Shots[i].Obj);
2628 // Êîñòûëèíà åáàíàÿ
2629 utils.writeInt(st, Byte(Shots[i].Stopped));
2630 end;
2631 end;
2632 end;
2634 procedure g_Weapon_LoadState (st: TStream);
2635 var
2636 count, tc, i, j: Integer;
2637 dw: LongWord;
2638 begin
2639 if (st = nil) then exit;
2641 // Êîëè÷åñòâî ñíàðÿäîâ
2642 count := utils.readLongInt(st);
2643 if (count < 0) or (count > 1024*1024) then raise XStreamError.Create('invalid shots counter');
2645 SetLength(Shots, count);
2647 if (count = 0) then exit;
2649 for i := 0 to count-1 do
2650 begin
2651 // Ñèãíàòóðà ñíàðÿäà
2652 if not utils.checkSign(st, 'SHOT') then raise XStreamError.Create('invalid shot signature');
2653 if (utils.readByte(st) <> 0) then raise XStreamError.Create('invalid shot version');
2654 // Òèï ñíàðÿäà:
2655 Shots[i].ShotType := utils.readByte(st);
2656 // Öåëü
2657 Shots[i].Target := utils.readWord(st);
2658 // UID ñòðåëÿâøåãî
2659 Shots[i].SpawnerUID := utils.readWord(st);
2660 // Ðàçìåð ïîëÿ Triggers
2661 tc := utils.readLongInt(st);
2662 if (tc < 0) or (tc > 1024*1024) then raise XStreamError.Create('invalid shot triggers counter');
2663 SetLength(Shots[i].Triggers, tc);
2664 // Òðèããåðû, àêòèâèðîâàííûå âûñòðåëîì
2665 for j := 0 to tc-1 do Shots[i].Triggers[j] := utils.readLongWord(st);
2666 // Îáúåêò ïðåäìåòà
2667 Obj_LoadState(@Shots[i].Obj, st);
2668 // Êîñòûëèíà åáàíàÿ
2669 Shots[i].Stopped := utils.readByte(st);
2671 // Óñòàíîâêà òåêñòóðû èëè àíèìàöèè
2672 Shots[i].TextureID := DWORD(-1);
2673 Shots[i].Animation := nil;
2675 case Shots[i].ShotType of
2676 WEAPON_ROCKETLAUNCHER, WEAPON_SKEL_FIRE:
2677 begin
2678 g_Texture_Get('TEXTURE_WEAPON_ROCKET', Shots[i].TextureID);
2679 end;
2680 WEAPON_PLASMA:
2681 begin
2682 g_Frames_Get(dw, 'FRAMES_WEAPON_PLASMA');
2683 Shots[i].Animation := TAnimation.Create(dw, True, 5);
2684 end;
2685 WEAPON_BFG:
2686 begin
2687 g_Frames_Get(dw, 'FRAMES_WEAPON_BFG');
2688 Shots[i].Animation := TAnimation.Create(dw, True, 6);
2689 end;
2690 WEAPON_IMP_FIRE:
2691 begin
2692 g_Frames_Get(dw, 'FRAMES_WEAPON_IMPFIRE');
2693 Shots[i].Animation := TAnimation.Create(dw, True, 4);
2694 end;
2695 WEAPON_BSP_FIRE:
2696 begin
2697 g_Frames_Get(dw, 'FRAMES_WEAPON_BSPFIRE');
2698 Shots[i].Animation := TAnimation.Create(dw, True, 4);
2699 end;
2700 WEAPON_CACO_FIRE:
2701 begin
2702 g_Frames_Get(dw, 'FRAMES_WEAPON_CACOFIRE');
2703 Shots[i].Animation := TAnimation.Create(dw, True, 4);
2704 end;
2705 WEAPON_BARON_FIRE:
2706 begin
2707 g_Frames_Get(dw, 'FRAMES_WEAPON_BARONFIRE');
2708 Shots[i].Animation := TAnimation.Create(dw, True, 4);
2709 end;
2710 WEAPON_MANCUB_FIRE:
2711 begin
2712 g_Frames_Get(dw, 'FRAMES_WEAPON_MANCUBFIRE');
2713 Shots[i].Animation := TAnimation.Create(dw, True, 4);
2714 end;
2715 end;
2716 end;
2717 end;
2719 procedure g_Weapon_DestroyShot(I: Integer; X, Y: Integer; Loud: Boolean = True);
2720 var
2721 cx, cy: Integer;
2722 Anim: TAnimation;
2723 s: string;
2724 begin
2725 if Shots = nil then
2726 Exit;
2727 if (I > High(Shots)) or (I < 0) then Exit;
2729 with Shots[I] do
2730 begin
2731 if ShotType = 0 then Exit;
2732 Obj.X := X;
2733 Obj.Y := Y;
2734 cx := Obj.X + (Obj.Rect.Width div 2);
2735 cy := Obj.Y + (Obj.Rect.Height div 2);
2737 case ShotType of
2738 WEAPON_ROCKETLAUNCHER, WEAPON_SKEL_FIRE: // Ðàêåòû è ñíàðÿäû Ñêåëåòà
2739 begin
2740 if Loud then
2741 begin
2742 if ShotType = WEAPON_SKEL_FIRE then
2743 begin // Âçðûâ ñíàðÿäà Ñêåëåòà
2744 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_SKELFIRE') then
2745 begin
2746 Anim := TAnimation.Create(TextureID, False, 8);
2747 Anim.Blending := False;
2748 g_GFX_OnceAnim((Obj.X+32)-32, (Obj.Y+8)-32, Anim);
2749 Anim.Free();
2750 end;
2751 end
2752 else
2753 begin // Âçðûâ Ðàêåòû
2754 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_ROCKET') then
2755 begin
2756 Anim := TAnimation.Create(TextureID, False, 6);
2757 Anim.Blending := False;
2758 g_GFX_OnceAnim(cx-64, cy-64, Anim);
2759 Anim.Free();
2760 end;
2761 end;
2762 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', Obj.X, Obj.Y);
2763 end;
2764 end;
2766 WEAPON_PLASMA, WEAPON_BSP_FIRE: // Ïëàçìà, ïëàçìà Àðàõíàòðîíà
2767 begin
2768 if ShotType = WEAPON_PLASMA then
2769 s := 'FRAMES_EXPLODE_PLASMA'
2770 else
2771 s := 'FRAMES_EXPLODE_BSPFIRE';
2773 if g_Frames_Get(TextureID, s) and loud then
2774 begin
2775 Anim := TAnimation.Create(TextureID, False, 3);
2776 Anim.Blending := False;
2777 g_GFX_OnceAnim(cx-16, cy-16, Anim);
2778 Anim.Free();
2780 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEPLASMA', Obj.X, Obj.Y);
2781 end;
2782 end;
2784 WEAPON_BFG: // BFG
2785 begin
2786 // Âçðûâ BFG:
2787 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_BFG') and Loud then
2788 begin
2789 Anim := TAnimation.Create(TextureID, False, 6);
2790 Anim.Blending := False;
2791 g_GFX_OnceAnim(cx-64, cy-64, Anim);
2792 Anim.Free();
2794 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', Obj.X, Obj.Y);
2795 end;
2796 end;
2798 WEAPON_IMP_FIRE, WEAPON_CACO_FIRE, WEAPON_BARON_FIRE: // Âûñòðåëû Áåñà, Êàêîäåìîíà Ðûöàðÿ/Áàðîíà àäà
2799 begin
2800 if ShotType = WEAPON_IMP_FIRE then
2801 s := 'FRAMES_EXPLODE_IMPFIRE'
2802 else
2803 if ShotType = WEAPON_CACO_FIRE then
2804 s := 'FRAMES_EXPLODE_CACOFIRE'
2805 else
2806 s := 'FRAMES_EXPLODE_BARONFIRE';
2808 if g_Frames_Get(TextureID, s) and Loud then
2809 begin
2810 Anim := TAnimation.Create(TextureID, False, 6);
2811 Anim.Blending := False;
2812 g_GFX_OnceAnim(cx-32, cy-32, Anim);
2813 Anim.Free();
2815 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj.X, Obj.Y);
2816 end;
2817 end;
2819 WEAPON_MANCUB_FIRE: // Âûñòðåë Ìàíêóáóñà
2820 begin
2821 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_ROCKET') and Loud then
2822 begin
2823 Anim := TAnimation.Create(TextureID, False, 6);
2824 Anim.Blending := False;
2825 g_GFX_OnceAnim(cx-64, cy-64, Anim);
2826 Anim.Free();
2828 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj.X, Obj.Y);
2829 end;
2830 end;
2831 end; // case ShotType of...
2833 ShotType := 0;
2834 Animation.Free();
2835 end;
2836 end;
2839 procedure g_Weapon_AddDynLights();
2840 var
2841 i: Integer;
2842 begin
2843 if Shots = nil then Exit;
2844 for i := 0 to High(Shots) do
2845 begin
2846 if Shots[i].ShotType = 0 then continue;
2847 if (Shots[i].ShotType = WEAPON_ROCKETLAUNCHER) or
2848 (Shots[i].ShotType = WEAPON_BARON_FIRE) or
2849 (Shots[i].ShotType = WEAPON_MANCUB_FIRE) or
2850 (Shots[i].ShotType = WEAPON_SKEL_FIRE) or
2851 (Shots[i].ShotType = WEAPON_IMP_FIRE) or
2852 (Shots[i].ShotType = WEAPON_CACO_FIRE) or
2853 (Shots[i].ShotType = WEAPON_MANCUB_FIRE) or
2854 (Shots[i].ShotType = WEAPON_BSP_FIRE) or
2855 (Shots[i].ShotType = WEAPON_PLASMA) or
2856 (Shots[i].ShotType = WEAPON_BFG) or
2857 (Shots[i].ShotType = WEAPON_FLAMETHROWER) or
2858 false then
2859 begin
2860 if (Shots[i].ShotType = WEAPON_PLASMA) then
2861 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)
2862 else if (Shots[i].ShotType = WEAPON_BFG) then
2863 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)
2864 else if (Shots[i].ShotType = WEAPON_FLAMETHROWER) then
2865 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)
2866 else
2867 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);
2868 end;
2869 end;
2870 end;
2873 procedure TShot.positionChanged (); begin end;
2876 end.