DEADSOFTWARE

put "{$MODE ...}" directive in each source file; removed trailing spaces, and convert...
[d2df-sdl.git] / src / game / g_weapons.pas
1 {$MODE DELPHI}
2 unit g_weapons;
4 interface
6 uses
7 g_textures, g_basic, e_graphics, g_phys, BinEditor;
9 const
10 HIT_SOME = 0;
11 HIT_ROCKET = 1;
12 HIT_BFG = 2;
13 HIT_TRAP = 3;
14 HIT_FALL = 4;
15 HIT_WATER = 5;
16 HIT_ACID = 6;
17 HIT_ELECTRO = 7;
18 HIT_FLAME = 8;
19 HIT_SELF = 9;
20 HIT_DISCON = 10;
22 type
23 TShot = record
24 ShotType: Byte;
25 Target: Word;
26 SpawnerUID: Word;
27 Triggers: DWArray;
28 Obj: TObj;
29 Animation: TAnimation;
30 TextureID: DWORD;
31 Timeout: DWORD;
32 end;
34 var
35 Shots: array of TShot = nil;
36 LastShotID: Integer = 0;
38 procedure g_Weapon_LoadData();
39 procedure g_Weapon_FreeData();
40 procedure g_Weapon_Init();
41 procedure g_Weapon_Free();
42 function g_Weapon_Hit(obj: PObj; d: Integer; SpawnerUID: Word; t: Byte; HitCorpses: Boolean = True): Byte;
43 function g_Weapon_HitUID(UID: Word; d: Integer; SpawnerUID: Word; t: Byte): Boolean;
44 function g_Weapon_CreateShot(I: Integer; ShotType: Byte; Spawner, TargetUID: Word; X, Y, XV, YV: Integer): LongWord;
46 procedure g_Weapon_gun(x, y, xd, yd, v, dmg: Integer; SpawnerUID: Word; CheckTrigger: Boolean);
47 procedure g_Weapon_punch(x, y: Integer; d, SpawnerUID: Word);
48 function g_Weapon_chainsaw(x, y: Integer; d, SpawnerUID: Word): Integer;
49 procedure g_Weapon_rocket(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1; Silent: Boolean = False);
50 procedure g_Weapon_revf(x, y, xd, yd: Integer; SpawnerUID, TargetUID: Word; WID: Integer = -1; Silent: Boolean = False);
51 procedure g_Weapon_plasma(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1; Silent: Boolean = False);
52 procedure g_Weapon_ball1(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1; Silent: Boolean = False);
53 procedure g_Weapon_ball2(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1; Silent: Boolean = False);
54 procedure g_Weapon_ball7(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1; Silent: Boolean = False);
55 procedure g_Weapon_aplasma(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1; Silent: Boolean = False);
56 procedure g_Weapon_manfire(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1; Silent: Boolean = False);
57 procedure g_Weapon_bfgshot(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1; Silent: Boolean = False);
58 procedure g_Weapon_bfghit(x, y: Integer);
59 procedure g_Weapon_pistol(x, y, xd, yd: Integer; SpawnerUID: Word; Silent: Boolean = False);
60 procedure g_Weapon_mgun(x, y, xd, yd: Integer; SpawnerUID: Word; Silent: Boolean = False);
61 procedure g_Weapon_shotgun(x, y, xd, yd: Integer; SpawnerUID: Word; Silent: Boolean = False);
62 procedure g_Weapon_dshotgun(x, y, xd, yd: Integer; SpawnerUID: Word; Silent: Boolean = False);
64 function g_Weapon_Explode(X, Y: Integer; rad: Integer; SpawnerUID: Word): Boolean;
65 procedure g_Weapon_BFG9000(X, Y: Integer; SpawnerUID: Word);
66 procedure g_Weapon_Update();
67 procedure g_Weapon_Draw();
68 function g_Weapon_Danger(UID: Word; X, Y: Integer; Width, Height: Word; Time: Byte): Boolean;
69 procedure g_Weapon_DestroyShot(I: Integer; X, Y: Integer; Loud: Boolean = True);
71 procedure g_Weapon_SaveState(var Mem: TBinMemoryWriter);
72 procedure g_Weapon_LoadState(var Mem: TBinMemoryReader);
74 const
75 WEAPON_KASTET = 0;
76 WEAPON_SAW = 1;
77 WEAPON_PISTOL = 2;
78 WEAPON_SHOTGUN1 = 3;
79 WEAPON_SHOTGUN2 = 4;
80 WEAPON_CHAINGUN = 5;
81 WEAPON_ROCKETLAUNCHER = 6;
82 WEAPON_PLASMA = 7;
83 WEAPON_BFG = 8;
84 WEAPON_SUPERPULEMET = 9;
85 WEAPON_MEGAKASTET = 10;
86 WEAPON_ZOMBY_PISTOL = 20;
87 WEAPON_IMP_FIRE = 21;
88 WEAPON_BSP_FIRE = 22;
89 WEAPON_CACO_FIRE = 23;
90 WEAPON_BARON_FIRE = 24;
91 WEAPON_MANCUB_FIRE = 25;
92 WEAPON_SKEL_FIRE = 26;
94 implementation
96 uses
97 Math, g_map, g_player, g_gfx, g_sound, g_main,
98 g_console, SysUtils, g_options, g_game,
99 g_triggers, MAPDEF, e_log, g_monsters, g_saveload,
100 g_language, g_netmsg;
102 type
103 TWaterPanel = record
104 X, Y: Integer;
105 Width, Height: Word;
106 Active: Boolean;
107 end;
109 const
110 SHOT_ROCKETLAUNCHER_WIDTH = 27;
111 SHOT_ROCKETLAUNCHER_HEIGHT = 12;
113 SHOT_SKELFIRE_WIDTH = 32;
114 SHOT_SKELFIRE_HEIGHT = 16;
116 SHOT_PLASMA_WIDTH = 16;
117 SHOT_PLASMA_HEIGHT = 16;
119 SHOT_BFG_WIDTH = 32;
120 SHOT_BFG_HEIGHT = 32;
121 SHOT_BFG_DAMAGE = 100;
122 SHOT_BFG_RADIUS = 256;
124 SHOT_SIGNATURE = $544F4853; // 'SHOT'
126 var
127 WaterMap: array of array of DWORD = nil;
129 function FindShot(): DWORD;
130 var
131 i: Integer;
132 begin
133 if Shots <> nil then
134 for i := 0 to High(Shots) do
135 if Shots[i].ShotType = 0 then
136 begin
137 Result := i;
138 LastShotID := Result;
139 Exit;
140 end;
142 if Shots = nil then
143 begin
144 SetLength(Shots, 128);
145 Result := 0;
146 end
147 else
148 begin
149 Result := High(Shots) + 1;
150 SetLength(Shots, Length(Shots) + 128);
151 end;
152 LastShotID := Result;
153 end;
155 procedure CreateWaterMap();
156 var
157 WaterArray: Array of TWaterPanel;
158 a, b, c, m: Integer;
159 ok: Boolean;
160 begin
161 if gWater = nil then
162 Exit;
164 SetLength(WaterArray, Length(gWater));
166 for a := 0 to High(gWater) do
167 begin
168 WaterArray[a].X := gWater[a].X;
169 WaterArray[a].Y := gWater[a].Y;
170 WaterArray[a].Width := gWater[a].Width;
171 WaterArray[a].Height := gWater[a].Height;
172 WaterArray[a].Active := True;
173 end;
175 g_Game_SetLoadingText(_lc[I_LOAD_WATER_MAP], High(WaterArray), False);
177 for a := 0 to High(WaterArray) do
178 if WaterArray[a].Active then
179 begin
180 WaterArray[a].Active := False;
181 m := Length(WaterMap);
182 SetLength(WaterMap, m+1);
183 SetLength(WaterMap[m], 1);
184 WaterMap[m][0] := a;
185 ok := True;
187 while ok do
188 begin
189 ok := False;
190 for b := 0 to High(WaterArray) do
191 if WaterArray[b].Active then
192 for c := 0 to High(WaterMap[m]) do
193 if g_CollideAround(WaterArray[b].X,
194 WaterArray[b].Y,
195 WaterArray[b].Width,
196 WaterArray[b].Height,
197 WaterArray[WaterMap[m][c]].X,
198 WaterArray[WaterMap[m][c]].Y,
199 WaterArray[WaterMap[m][c]].Width,
200 WaterArray[WaterMap[m][c]].Height) then
201 begin
202 WaterArray[b].Active := False;
203 SetLength(WaterMap[m],
204 Length(WaterMap[m])+1);
205 WaterMap[m][High(WaterMap[m])] := b;
206 ok := True;
207 Break;
208 end;
209 end;
211 g_Game_StepLoading();
212 end;
214 WaterArray := nil;
215 end;
217 procedure CheckTrap(ID: DWORD; dm: Integer; t: Byte);
218 var
219 a, b, c, d, i1, i2: Integer;
220 pl, mn: WArray;
221 begin
222 if (gWater = nil) or (WaterMap = nil) then Exit;
224 i1 := -1;
225 i2 := -1;
227 SetLength(pl, 1024);
228 SetLength(mn, 1024);
229 for d := 0 to 1023 do pl[d] := $FFFF;
230 for d := 0 to 1023 do mn[d] := $FFFF;
232 for a := 0 to High(WaterMap) do
233 for b := 0 to High(WaterMap[a]) do
234 begin
235 if not g_Obj_Collide(gWater[WaterMap[a][b]].X, gWater[WaterMap[a][b]].Y,
236 gWater[WaterMap[a][b]].Width, gWater[WaterMap[a][b]].Height,
237 @Shots[ID].Obj) then Continue;
239 for c := 0 to High(WaterMap[a]) do
240 begin
241 if gPlayers <> nil then
242 begin
243 for d := 0 to High(gPlayers) do
244 if (gPlayers[d] <> nil) and (gPlayers[d].Live) then
245 if gPlayers[d].Collide(gWater[WaterMap[a][c]]) then
246 if not InWArray(d, pl) then
247 if i1 < 1023 then
248 begin
249 i1 := i1+1;
250 pl[i1] := d;
251 end;
252 end;
254 if gMonsters <> nil then
255 begin
256 for d := 0 to High(gMonsters) do
257 if (gMonsters[d] <> nil) and (gMonsters[d].Live) then
258 if gMonsters[d].Collide(gWater[WaterMap[a][c]]) then
259 if not InWArray(d, mn) then
260 if i2 < 1023 then
261 begin
262 i2 := i2+1;
263 mn[i2] := d;
264 end;
265 end;
266 end;
268 if i1 <> -1 then
269 for d := 0 to i1 do
270 gPlayers[pl[d]].Damage(dm, Shots[ID].SpawnerUID, 0, 0, t);
272 if i2 <> -1 then
273 for d := 0 to i2 do
274 gMonsters[mn[d]].Damage(dm, 0, 0, Shots[ID].SpawnerUID, t);
275 end;
277 pl := nil;
278 mn := nil;
279 end;
281 function HitMonster(m: TMonster; d: Integer; vx, vy: Integer; SpawnerUID: Word; t: Byte): Boolean;
282 var
283 tt, mt: Byte;
284 mon: TMonster;
285 begin
286 Result := False;
288 tt := g_GetUIDType(SpawnerUID);
289 if tt = UID_MONSTER then
290 begin
291 mon := g_Monsters_Get(SpawnerUID);
292 if mon <> nil then
293 mt := g_Monsters_Get(SpawnerUID).MonsterType
294 else
295 mt := 0;
296 end
297 else
298 mt := 0;
300 if m = nil then Exit;
301 if m.UID = SpawnerUID then
302 begin
303 // Ñàì ñåáÿ ìîæåò ðàíèòü òîëüêî ðàêåòîé è òîêîì:
304 if (t <> HIT_ROCKET) and (t <> HIT_ELECTRO) then
305 Exit;
306 // Êèáåð äåìîí è áî÷êà âîîáùå íå ìîãóò ñåáÿ ðàíèòü:
307 if (m.MonsterType = MONSTER_CYBER) or
308 (m.MonsterType = MONSTER_BARREL) then
309 begin
310 Result := True;
311 Exit;
312 end;
313 end;
315 if tt = UID_MONSTER then
316 begin
317 // Lost_Soul íå ìîæåò ðàíèòü Pain_Elemental'à:
318 if (mt = MONSTER_SOUL) and (m.MonsterType = MONSTER_PAIN) then
319 Exit;
321 // Îáà ìîíñòðà îäíîãî âèäà:
322 if mt = m.MonsterType then
323 case mt of
324 MONSTER_IMP, MONSTER_DEMON, MONSTER_BARON, MONSTER_KNIGHT, MONSTER_CACO,
325 MONSTER_SOUL, MONSTER_MANCUB, MONSTER_SKEL, MONSTER_FISH:
326 Exit; // Ýòè íå áüþò ñâîèõ
327 end;
328 end;
330 if g_Game_IsServer then
331 Result := m.Damage(d, vx, vy, SpawnerUID, t)
332 else
333 Result := True;
334 end;
336 function HitPlayer(p: TPlayer; d: Integer; vx, vy: Integer; SpawnerUID: Word; t: Byte): Boolean;
337 begin
338 Result := False;
340 // Ñàì ñåáÿ ìîæåò ðàíèòü òîëüêî ðàêåòîé è òîêîì:
341 if (p.UID = SpawnerUID) and (t <> HIT_ROCKET) and (t <> HIT_ELECTRO) then
342 Exit;
344 if g_Game_IsServer then p.Damage(d, SpawnerUID, vx, vy, t);
346 Result := True;
347 end;
349 function GunHit(X, Y: Integer; vx, vy: Integer; dmg: Integer;
350 SpawnerUID: Word; AllowPush: Boolean): Byte;
351 var
352 i, h: Integer;
353 begin
354 Result := 0;
356 h := High(gPlayers);
358 if h <> -1 then
359 for i := 0 to h do
360 if (gPlayers[i] <> nil) and gPlayers[i].Live and gPlayers[i].Collide(X, Y) then
361 if HitPlayer(gPlayers[i], dmg, vx*10, vy*10-3, SpawnerUID, HIT_SOME) then
362 begin
363 if AllowPush then gPlayers[i].Push(vx, vy);
364 Result := 1;
365 end;
367 if Result <> 0 then Exit;
369 h := High(gMonsters);
371 if h <> -1 then
372 for i := 0 to h do
373 if (gMonsters[i] <> nil) and gMonsters[i].Live and gMonsters[i].Collide(X, Y) then
374 if HitMonster(gMonsters[i], dmg, vx*10, vy*10-3, SpawnerUID, HIT_SOME) then
375 begin
376 if AllowPush then gMonsters[i].Push(vx, vy);
377 Result := 2;
378 Exit;
379 end;
380 end;
382 procedure g_Weapon_BFG9000(X, Y: Integer; SpawnerUID: Word);
383 var
384 i, h: Integer;
385 st: Byte;
386 pl: TPlayer;
387 b: Boolean;
388 begin
389 //g_Sound_PlayEx('SOUND_WEAPON_EXPLODEBFG', 255);
391 h := High(gCorpses);
393 if gAdvCorpses and (h <> -1) then
394 for i := 0 to h do
395 if (gCorpses[i] <> nil) and (gCorpses[i].State <> CORPSE_STATE_REMOVEME) then
396 with gCorpses[i] do
397 if (g_PatchLength(X, Y, Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2),
398 Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)) <= SHOT_BFG_RADIUS) and
399 g_TraceVector(X, Y, Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2),
400 Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)) then
401 begin
402 Damage(50, 0, 0);
403 g_Weapon_BFGHit(Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2),
404 Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2));
405 end;
407 st := TEAM_NONE;
408 pl := g_Player_Get(SpawnerUID);
409 if pl <> nil then
410 st := pl.Team;
412 h := High(gPlayers);
414 if h <> -1 then
415 for i := 0 to h do
416 if (gPlayers[i] <> nil) and (gPlayers[i].Live) and (gPlayers[i].UID <> SpawnerUID) then
417 with gPlayers[i] do
418 if (g_PatchLength(X, Y, GameX+PLAYER_RECT.X+(PLAYER_RECT.Width div 2),
419 GameY+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)) <= SHOT_BFG_RADIUS) and
420 g_TraceVector(X, Y, GameX+PLAYER_RECT.X+(PLAYER_RECT.Width div 2),
421 GameY+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)) then
422 begin
423 if (st = TEAM_NONE) or (st <> gPlayers[i].Team) then
424 b := HitPlayer(gPlayers[i], 50, 0, 0, SpawnerUID, HIT_SOME)
425 else
426 b := HitPlayer(gPlayers[i], 25, 0, 0, SpawnerUID, HIT_SOME);
427 if b then
428 gPlayers[i].BFGHit();
429 end;
431 h := High(gMonsters);
433 if h <> -1 then
434 for i := 0 to h do
435 if (gMonsters[i] <> nil) and (gMonsters[i].Live) and (gMonsters[i].UID <> SpawnerUID) then
436 with gMonsters[i] do
437 if (g_PatchLength(X, Y, Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2),
438 Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)) <= SHOT_BFG_RADIUS) and
439 g_TraceVector(X, Y, Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2),
440 Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)) then
441 if HitMonster(gMonsters[i], 50, 0, 0, SpawnerUID, HIT_SOME) then gMonsters[i].BFGHit();
442 end;
444 function g_Weapon_CreateShot(I: Integer; ShotType: Byte; Spawner, TargetUID: Word; X, Y, XV, YV: Integer): LongWord;
445 var
446 find_id, FramesID: DWORD;
447 begin
448 if I < 0 then
449 find_id := FindShot()
450 else
451 begin
452 find_id := I;
453 if Integer(find_id) >= High(Shots) then
454 SetLength(Shots, find_id + 64)
455 end;
457 case ShotType of
458 WEAPON_ROCKETLAUNCHER:
459 begin
460 with Shots[find_id] do
461 begin
462 g_Obj_Init(@Obj);
464 Obj.Rect.Width := SHOT_ROCKETLAUNCHER_WIDTH;
465 Obj.Rect.Height := SHOT_ROCKETLAUNCHER_HEIGHT;
467 Animation := nil;
468 Triggers := nil;
469 ShotType := WEAPON_ROCKETLAUNCHER;
470 g_Texture_Get('TEXTURE_WEAPON_ROCKET', TextureID);
471 end;
472 end;
474 WEAPON_PLASMA:
475 begin
476 with Shots[find_id] do
477 begin
478 g_Obj_Init(@Obj);
480 Obj.Rect.Width := SHOT_PLASMA_WIDTH;
481 Obj.Rect.Height := SHOT_PLASMA_HEIGHT;
483 Triggers := nil;
484 ShotType := WEAPON_PLASMA;
485 g_Frames_Get(FramesID, 'FRAMES_WEAPON_PLASMA');
486 Animation := TAnimation.Create(FramesID, True, 5);
487 end;
488 end;
490 WEAPON_BFG:
491 begin
492 with Shots[find_id] do
493 begin
494 g_Obj_Init(@Obj);
496 Obj.Rect.Width := SHOT_BFG_WIDTH;
497 Obj.Rect.Height := SHOT_BFG_HEIGHT;
499 Triggers := nil;
500 ShotType := WEAPON_BFG;
501 g_Frames_Get(FramesID, 'FRAMES_WEAPON_BFG');
502 Animation := TAnimation.Create(FramesID, True, 6);
503 end;
504 end;
506 WEAPON_IMP_FIRE:
507 begin
508 with Shots[find_id] do
509 begin
510 g_Obj_Init(@Obj);
512 Obj.Rect.Width := 16;
513 Obj.Rect.Height := 16;
515 Triggers := nil;
516 ShotType := WEAPON_IMP_FIRE;
517 g_Frames_Get(FramesID, 'FRAMES_WEAPON_IMPFIRE');
518 Animation := TAnimation.Create(FramesID, True, 4);
519 end;
520 end;
522 WEAPON_CACO_FIRE:
523 begin
524 with Shots[find_id] do
525 begin
526 g_Obj_Init(@Obj);
528 Obj.Rect.Width := 16;
529 Obj.Rect.Height := 16;
531 Triggers := nil;
532 ShotType := WEAPON_CACO_FIRE;
533 g_Frames_Get(FramesID, 'FRAMES_WEAPON_CACOFIRE');
534 Animation := TAnimation.Create(FramesID, True, 4);
535 end;
536 end;
538 WEAPON_MANCUB_FIRE:
539 begin
540 with Shots[find_id] do
541 begin
542 g_Obj_Init(@Obj);
544 Obj.Rect.Width := 32;
545 Obj.Rect.Height := 32;
547 Triggers := nil;
548 ShotType := WEAPON_MANCUB_FIRE;
549 g_Frames_Get(FramesID, 'FRAMES_WEAPON_MANCUBFIRE');
550 Animation := TAnimation.Create(FramesID, True, 4);
551 end;
552 end;
554 WEAPON_BARON_FIRE:
555 begin
556 with Shots[find_id] do
557 begin
558 g_Obj_Init(@Obj);
560 Obj.Rect.Width := 32;
561 Obj.Rect.Height := 16;
563 Triggers := nil;
564 ShotType := WEAPON_BARON_FIRE;
565 g_Frames_Get(FramesID, 'FRAMES_WEAPON_BARONFIRE');
566 Animation := TAnimation.Create(FramesID, True, 4);
567 end;
568 end;
570 WEAPON_BSP_FIRE:
571 begin
572 with Shots[find_id] do
573 begin
574 g_Obj_Init(@Obj);
576 Obj.Rect.Width := 16;
577 Obj.Rect.Height := 16;
579 Triggers := nil;
580 ShotType := WEAPON_BSP_FIRE;
581 g_Frames_Get(FramesID, 'FRAMES_WEAPON_BSPFIRE');
582 Animation := TAnimation.Create(FramesID, True, 4);
583 end;
584 end;
586 WEAPON_SKEL_FIRE:
587 begin
588 with Shots[find_id] do
589 begin
590 g_Obj_Init(@Obj);
592 Obj.Rect.Width := SHOT_SKELFIRE_WIDTH;
593 Obj.Rect.Height := SHOT_SKELFIRE_HEIGHT;
595 Triggers := nil;
596 ShotType := WEAPON_SKEL_FIRE;
597 target := TargetUID;
598 g_Frames_Get(FramesID, 'FRAMES_WEAPON_SKELFIRE');
599 Animation := TAnimation.Create(FramesID, True, 5);
600 end;
601 end;
602 end;
604 Shots[find_id].Obj.X := X;
605 Shots[find_id].Obj.Y := Y;
606 Shots[find_id].Obj.Vel.X := XV;
607 Shots[find_id].Obj.Vel.Y := YV;
608 Shots[find_id].Obj.Accel.X := 0;
609 Shots[find_id].Obj.Accel.Y := 0;
610 Shots[find_id].SpawnerUID := Spawner;
611 Result := find_id;
612 end;
614 procedure throw(i, x, y, xd, yd, s: Integer);
615 var
616 a: Integer;
617 begin
618 yd := yd - y;
619 xd := xd - x;
621 a := Max(Abs(xd), Abs(yd));
622 if a = 0 then
623 a := 1;
625 Shots[i].Obj.X := x;
626 Shots[i].Obj.Y := y;
627 Shots[i].Obj.Vel.X := (xd*s) div a;
628 Shots[i].Obj.Vel.Y := (yd*s) div a;
629 Shots[i].Obj.Accel.X := 0;
630 Shots[i].Obj.Accel.Y := 0;
631 if Shots[i].ShotType in [WEAPON_ROCKETLAUNCHER, WEAPON_BFG] then
632 Shots[i].Timeout := 900 // ~25 sec
633 else
634 Shots[i].Timeout := 550 // ~15 sec
635 end;
637 function g_Weapon_Hit(obj: PObj; d: Integer; SpawnerUID: Word; t: Byte; HitCorpses: Boolean = True): Byte;
638 var
639 i, h: Integer;
641 function PlayerHit(Team: Byte = 0): Boolean;
642 var
643 i: Integer;
644 ChkTeam: Boolean;
645 p: TPlayer;
646 begin
647 Result := False;
648 h := High(gPlayers);
650 if h <> -1 then
651 for i := 0 to h do
652 if (gPlayers[i] <> nil) and gPlayers[i].Live and g_Obj_Collide(obj, @gPlayers[i].Obj) then
653 begin
654 ChkTeam := True;
655 if (Team > 0) and (g_GetUIDType(SpawnerUID) = UID_PLAYER) then
656 begin
657 p := g_Player_Get(SpawnerUID);
658 if p <> nil then
659 ChkTeam := (p.Team = gPlayers[i].Team) xor (Team = 2);
660 end;
661 if ChkTeam then
662 if HitPlayer(gPlayers[i], d, obj^.Vel.X, obj^.Vel.Y, SpawnerUID, t) then
663 begin
664 gPlayers[i].Push((obj^.Vel.X+obj^.Accel.X)*IfThen(t = HIT_BFG, 8, 1) div 4,
665 (obj^.Vel.Y+obj^.Accel.Y)*IfThen(t = HIT_BFG, 8, 1) div 4);
666 if t = HIT_BFG then
667 g_Game_DelayEvent(DE_BFGHIT, 1000, SpawnerUID);
668 Result := True;
669 break;
670 end;
671 end;
672 end;
673 function MonsterHit(): Boolean;
674 var
675 i: Integer;
676 begin
677 Result := False;
678 h := High(gMonsters);
680 if h <> -1 then
681 for i := 0 to h do
682 if (gMonsters[i] <> nil) and gMonsters[i].Live and g_Obj_Collide(obj, @gMonsters[i].Obj) then
683 if HitMonster(gMonsters[i], d, obj^.Vel.X, obj^.Vel.Y, SpawnerUID, t) then
684 begin
685 gMonsters[i].Push((obj^.Vel.X+obj^.Accel.X)*IfThen(t = HIT_BFG, 8, 1) div 4,
686 (obj^.Vel.Y+obj^.Accel.Y)*IfThen(t = HIT_BFG, 8, 1) div 4);
687 Result := True;
688 break;
689 end;
690 end;
691 begin
692 Result := 0;
694 if HitCorpses then
695 begin
696 h := High(gCorpses);
698 if gAdvCorpses and (h <> -1) then
699 for i := 0 to h do
700 if (gCorpses[i] <> nil) and (gCorpses[i].State <> CORPSE_STATE_REMOVEME) and
701 g_Obj_Collide(obj, @gCorpses[i].Obj) then
702 begin
703 // Ðàñïèëèâàåì òðóï:
704 gCorpses[i].Damage(d, (obj^.Vel.X+obj^.Accel.X) div 4,
705 (obj^.Vel.Y+obj^.Accel.Y) div 4);
706 Result := 1;
707 end;
708 end;
710 case gGameSettings.GameMode of
711 // Êàìïàíèÿ:
712 GM_COOP, GM_SINGLE:
713 begin
714 // Ñíà÷àëà áü¸ì ìîíñòðîâ, åñëè åñòü, ïîòîì ïûòàåìñÿ áèòü èãðîêîâ
715 if MonsterHit() then
716 begin
717 Result := 2;
718 Exit;
719 end;
721 if PlayerHit() then
722 begin
723 Result := 1;
724 Exit;
725 end;
726 end;
728 // Äåçìàò÷:
729 GM_DM:
730 begin
731 // Ñíà÷àëà áü¸ì èãðîêîâ, åñëè åñòü, ïîòîì ïûòàåìñÿ áèòü ìîíñòðîâ
732 if PlayerHit() then
733 begin
734 Result := 1;
735 Exit;
736 end;
738 if MonsterHit() then
739 begin
740 Result := 2;
741 Exit;
742 end;
743 end;
745 // Êîìàíäíûå:
746 GM_TDM, GM_CTF:
747 begin
748 // Ñíà÷àëà áü¸ì èãðîêîâ êîìàíäû ñîïåðíèêà
749 if PlayerHit(2) then
750 begin
751 Result := 1;
752 Exit;
753 end;
755 // Ïîòîì ìîíñòðîâ
756 if MonsterHit() then
757 begin
758 Result := 2;
759 Exit;
760 end;
762 // È â êîíöå ñâîèõ èãðîêîâ
763 if PlayerHit(1) then
764 begin
765 Result := 1;
766 Exit;
767 end;
768 end;
770 end;
771 end;
773 function g_Weapon_HitUID(UID: Word; d: Integer; SpawnerUID: Word; t: Byte): Boolean;
774 begin
775 Result := False;
777 case g_GetUIDType(UID) of
778 UID_PLAYER: Result := HitPlayer(g_Player_Get(UID), d, 0, 0, SpawnerUID, t);
779 UID_MONSTER: Result := HitMonster(g_Monsters_Get(UID), d, 0, 0, SpawnerUID, t);
780 else Exit;
781 end;
782 end;
784 function g_Weapon_Explode(X, Y: Integer; rad: Integer; SpawnerUID: Word): Boolean;
785 var
786 i, h, r, dx, dy, m, mm: Integer;
787 _angle: SmallInt;
788 begin
789 Result := False;
791 g_Triggers_PressC(X, Y, rad, SpawnerUID, ACTIVATE_SHOT);
793 r := rad*rad;
795 h := High(gPlayers);
797 if h <> -1 then
798 for i := 0 to h do
799 if (gPlayers[i] <> nil) and gPlayers[i].Live then
800 with gPlayers[i] do
801 begin
802 dx := Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2)-X;
803 dy := Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)-Y;
805 if dx > 1000 then dx := 1000;
806 if dy > 1000 then dy := 1000;
808 if dx*dx+dy*dy < r then
809 begin
810 //m := PointToRect(X, Y, GameX+PLAYER_RECT.X, GameY+PLAYER_RECT.Y,
811 // PLAYER_RECT.Width, PLAYER_RECT.Height);
813 mm := Max(abs(dx), abs(dy));
814 if mm = 0 then mm := 1;
816 HitPlayer(gPlayers[i], (100*(rad-mm)) div rad, (dx*10) div mm, (dy*10) div mm, SpawnerUID, HIT_ROCKET);
817 gPlayers[i].Push((dx*7) div mm, (dy*7) div mm);
818 end;
819 end;
821 h := High(gMonsters);
823 if h <> -1 then
824 for i := 0 to h do
825 if gMonsters[i] <> nil then
826 with gMonsters[i] do
827 begin
828 dx := Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2)-X;
829 dy := Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)-Y;
831 if dx > 1000 then dx := 1000;
832 if dy > 1000 then dy := 1000;
834 if dx*dx+dy*dy < r then
835 begin
836 //m := PointToRect(X, Y, Obj.X+Obj.Rect.X, Obj.Y+Obj.Rect.Y,
837 // Obj.Rect.Width, Obj.Rect.Height);
839 mm := Max(abs(dx), abs(dy));
840 if mm = 0 then mm := 1;
842 if gMonsters[i].Live then
843 HitMonster(gMonsters[i], ((gMonsters[i].Obj.Rect.Width div 4)*10*(rad-mm)) div rad,
844 0, 0, SpawnerUID, HIT_ROCKET);
846 gMonsters[i].Push((dx*7) div mm, (dy*7) div mm);
847 end;
848 end;
850 h := High(gCorpses);
852 if gAdvCorpses and (h <> -1) then
853 for i := 0 to h do
854 if (gCorpses[i] <> nil) and (gCorpses[i].State <> CORPSE_STATE_REMOVEME) then
855 with gCorpses[i] do
856 begin
857 dx := Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2)-X;
858 dy := Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)-Y;
860 if dx > 1000 then dx := 1000;
861 if dy > 1000 then dy := 1000;
863 if dx*dx+dy*dy < r then
864 begin
865 m := PointToRect(X, Y, Obj.X+Obj.Rect.X, Obj.Y+Obj.Rect.Y,
866 Obj.Rect.Width, Obj.Rect.Height);
868 mm := Max(abs(dx), abs(dy));
869 if mm = 0 then mm := 1;
871 Damage(Round(100*(rad-m)/rad), (dx*10) div mm, (dy*10) div mm);
872 end;
873 end;
875 h := High(gGibs);
877 if gAdvGibs and (h <> -1) then
878 for i := 0 to h do
879 if gGibs[i].Live then
880 with gGibs[i] do
881 begin
882 dx := Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2)-X;
883 dy := Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2)-Y;
885 if dx > 1000 then dx := 1000;
886 if dy > 1000 then dy := 1000;
888 if dx*dx+dy*dy < r then
889 begin
890 m := PointToRect(X, Y, Obj.X+Obj.Rect.X, Obj.Y+Obj.Rect.Y,
891 Obj.Rect.Width, Obj.Rect.Height);
892 _angle := GetAngle(Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2),
893 Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2), X, Y);
895 g_Obj_PushA(@Obj, Round(15*(rad-m)/rad), _angle);
896 end;
897 end;
898 end;
900 procedure g_Weapon_Init();
901 begin
902 CreateWaterMap();
903 end;
905 procedure g_Weapon_Free();
906 var
907 i: Integer;
908 begin
909 if Shots <> nil then
910 begin
911 for i := 0 to High(Shots) do
912 if Shots[i].ShotType <> 0 then
913 Shots[i].Animation.Free();
915 Shots := nil;
916 end;
918 WaterMap := nil;
919 end;
921 procedure g_Weapon_LoadData();
922 begin
923 e_WriteLog('Loading weapons data...', MSG_NOTIFY);
925 g_Sound_CreateWADEx('SOUND_WEAPON_HITPUNCH', GameWAD+':SOUNDS\HITPUNCH');
926 g_Sound_CreateWADEx('SOUND_WEAPON_MISSPUNCH', GameWAD+':SOUNDS\MISSPUNCH');
927 g_Sound_CreateWADEx('SOUND_WEAPON_HITBERSERK', GameWAD+':SOUNDS\HITBERSERK');
928 g_Sound_CreateWADEx('SOUND_WEAPON_MISSBERSERK', GameWAD+':SOUNDS\MISSBERSERK');
929 g_Sound_CreateWADEx('SOUND_WEAPON_SELECTSAW', GameWAD+':SOUNDS\SELECTSAW');
930 g_Sound_CreateWADEx('SOUND_WEAPON_IDLESAW', GameWAD+':SOUNDS\IDLESAW');
931 g_Sound_CreateWADEx('SOUND_WEAPON_HITSAW', GameWAD+':SOUNDS\HITSAW');
932 g_Sound_CreateWADEx('SOUND_WEAPON_FIRESHOTGUN2', GameWAD+':SOUNDS\FIRESHOTGUN2');
933 g_Sound_CreateWADEx('SOUND_WEAPON_FIRESHOTGUN', GameWAD+':SOUNDS\FIRESHOTGUN');
934 g_Sound_CreateWADEx('SOUND_WEAPON_FIRESAW', GameWAD+':SOUNDS\FIRESAW');
935 g_Sound_CreateWADEx('SOUND_WEAPON_FIREROCKET', GameWAD+':SOUNDS\FIREROCKET');
936 g_Sound_CreateWADEx('SOUND_WEAPON_FIREPLASMA', GameWAD+':SOUNDS\FIREPLASMA');
937 g_Sound_CreateWADEx('SOUND_WEAPON_FIREPISTOL', GameWAD+':SOUNDS\FIREPISTOL');
938 g_Sound_CreateWADEx('SOUND_WEAPON_FIRECGUN', GameWAD+':SOUNDS\FIRECGUN');
939 g_Sound_CreateWADEx('SOUND_WEAPON_FIREBFG', GameWAD+':SOUNDS\FIREBFG');
940 g_Sound_CreateWADEx('SOUND_FIRE', GameWAD+':SOUNDS\FIRE');
941 g_Sound_CreateWADEx('SOUND_WEAPON_STARTFIREBFG', GameWAD+':SOUNDS\STARTFIREBFG');
942 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEROCKET', GameWAD+':SOUNDS\EXPLODEROCKET');
943 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEBFG', GameWAD+':SOUNDS\EXPLODEBFG');
944 g_Sound_CreateWADEx('SOUND_WEAPON_BFGWATER', GameWAD+':SOUNDS\BFGWATER');
945 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEPLASMA', GameWAD+':SOUNDS\EXPLODEPLASMA');
946 g_Sound_CreateWADEx('SOUND_WEAPON_PLASMAWATER', GameWAD+':SOUNDS\PLASMAWATER');
947 g_Sound_CreateWADEx('SOUND_WEAPON_FIREBALL', GameWAD+':SOUNDS\FIREBALL');
948 g_Sound_CreateWADEx('SOUND_WEAPON_EXPLODEBALL', GameWAD+':SOUNDS\EXPLODEBALL');
949 g_Sound_CreateWADEx('SOUND_WEAPON_FIREREV', GameWAD+':SOUNDS\FIREREV');
950 g_Sound_CreateWADEx('SOUND_PLAYER_JETFLY', GameWAD+':SOUNDS\WORKJETPACK');
951 g_Sound_CreateWADEx('SOUND_PLAYER_JETON', GameWAD+':SOUNDS\STARTJETPACK');
952 g_Sound_CreateWADEx('SOUND_PLAYER_JETOFF', GameWAD+':SOUNDS\STOPJETPACK');
953 g_Sound_CreateWADEx('SOUND_PLAYER_CASING1', GameWAD+':SOUNDS\CASING1');
954 g_Sound_CreateWADEx('SOUND_PLAYER_CASING2', GameWAD+':SOUNDS\CASING2');
955 g_Sound_CreateWADEx('SOUND_PLAYER_SHELL1', GameWAD+':SOUNDS\SHELL1');
956 g_Sound_CreateWADEx('SOUND_PLAYER_SHELL2', GameWAD+':SOUNDS\SHELL2');
958 g_Texture_CreateWADEx('TEXTURE_WEAPON_ROCKET', GameWAD+':TEXTURES\BROCKET');
959 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_SKELFIRE', GameWAD+':TEXTURES\BSKELFIRE', 64, 16, 2);
960 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_BFG', GameWAD+':TEXTURES\BBFG', 64, 64, 2);
961 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_PLASMA', GameWAD+':TEXTURES\BPLASMA', 16, 16, 2);
962 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_IMPFIRE', GameWAD+':TEXTURES\BIMPFIRE', 16, 16, 2);
963 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_BSPFIRE', GameWAD+':TEXTURES\BBSPFIRE', 16, 16, 2);
964 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_CACOFIRE', GameWAD+':TEXTURES\BCACOFIRE', 16, 16, 2);
965 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_BARONFIRE', GameWAD+':TEXTURES\BBARONFIRE', 64, 16, 2);
966 g_Frames_CreateWAD(nil, 'FRAMES_WEAPON_MANCUBFIRE', GameWAD+':TEXTURES\BMANCUBFIRE', 64, 32, 2);
967 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_ROCKET', GameWAD+':TEXTURES\EROCKET', 128, 128, 6);
968 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_SKELFIRE', GameWAD+':TEXTURES\ESKELFIRE', 64, 64, 3);
969 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_BFG', GameWAD+':TEXTURES\EBFG', 128, 128, 6);
970 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_IMPFIRE', GameWAD+':TEXTURES\EIMPFIRE', 64, 64, 3);
971 g_Frames_CreateWAD(nil, 'FRAMES_BFGHIT', GameWAD+':TEXTURES\BFGHIT', 64, 64, 4);
972 g_Frames_CreateWAD(nil, 'FRAMES_FIRE', GameWAD+':TEXTURES\FIRE', 64, 128, 8);
973 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_PLASMA', GameWAD+':TEXTURES\EPLASMA', 32, 32, 4, True);
974 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_BSPFIRE', GameWAD+':TEXTURES\EBSPFIRE', 32, 32, 5);
975 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_CACOFIRE', GameWAD+':TEXTURES\ECACOFIRE', 64, 64, 3);
976 g_Frames_CreateWAD(nil, 'FRAMES_EXPLODE_BARONFIRE', GameWAD+':TEXTURES\EBARONFIRE', 64, 64, 3);
977 g_Frames_CreateWAD(nil, 'FRAMES_SMOKE', GameWAD+':TEXTURES\SMOKE', 32, 32, 10, False);
979 g_Texture_CreateWADEx('TEXTURE_SHELL_BULLET', GameWAD+':TEXTURES\EBULLET');
980 g_Texture_CreateWADEx('TEXTURE_SHELL_SHELL', GameWAD+':TEXTURES\ESHELL');
981 end;
983 procedure g_Weapon_FreeData();
984 begin
985 e_WriteLog('Releasing weapons data...', MSG_NOTIFY);
987 g_Sound_Delete('SOUND_WEAPON_HITPUNCH');
988 g_Sound_Delete('SOUND_WEAPON_MISSPUNCH');
989 g_Sound_Delete('SOUND_WEAPON_HITBERSERK');
990 g_Sound_Delete('SOUND_WEAPON_MISSBERSERK');
991 g_Sound_Delete('SOUND_WEAPON_SELECTSAW');
992 g_Sound_Delete('SOUND_WEAPON_IDLESAW');
993 g_Sound_Delete('SOUND_WEAPON_HITSAW');
994 g_Sound_Delete('SOUND_WEAPON_FIRESHOTGUN2');
995 g_Sound_Delete('SOUND_WEAPON_FIRESHOTGUN');
996 g_Sound_Delete('SOUND_WEAPON_FIRESAW');
997 g_Sound_Delete('SOUND_WEAPON_FIREROCKET');
998 g_Sound_Delete('SOUND_WEAPON_FIREPLASMA');
999 g_Sound_Delete('SOUND_WEAPON_FIREPISTOL');
1000 g_Sound_Delete('SOUND_WEAPON_FIRECGUN');
1001 g_Sound_Delete('SOUND_WEAPON_FIREBFG');
1002 g_Sound_Delete('SOUND_FIRE');
1003 g_Sound_Delete('SOUND_WEAPON_STARTFIREBFG');
1004 g_Sound_Delete('SOUND_WEAPON_EXPLODEROCKET');
1005 g_Sound_Delete('SOUND_WEAPON_EXPLODEBFG');
1006 g_Sound_Delete('SOUND_WEAPON_BFGWATER');
1007 g_Sound_Delete('SOUND_WEAPON_EXPLODEPLASMA');
1008 g_Sound_Delete('SOUND_WEAPON_PLASMAWATER');
1009 g_Sound_Delete('SOUND_WEAPON_FIREBALL');
1010 g_Sound_Delete('SOUND_WEAPON_EXPLODEBALL');
1011 g_Sound_Delete('SOUND_WEAPON_FIREREV');
1012 g_Sound_Delete('SOUND_PLAYER_JETFLY');
1013 g_Sound_Delete('SOUND_PLAYER_JETON');
1014 g_Sound_Delete('SOUND_PLAYER_JETOFF');
1015 g_Sound_Delete('SOUND_PLAYER_CASING1');
1016 g_Sound_Delete('SOUND_PLAYER_CASING2');
1017 g_Sound_Delete('SOUND_PLAYER_SHELL1');
1018 g_Sound_Delete('SOUND_PLAYER_SHELL2');
1020 g_Texture_Delete('TEXTURE_WEAPON_ROCKET');
1021 g_Frames_DeleteByName('FRAMES_WEAPON_BFG');
1022 g_Frames_DeleteByName('FRAMES_WEAPON_PLASMA');
1023 g_Frames_DeleteByName('FRAMES_WEAPON_IMPFIRE');
1024 g_Frames_DeleteByName('FRAMES_WEAPON_BSPFIRE');
1025 g_Frames_DeleteByName('FRAMES_WEAPON_CACOFIRE');
1026 g_Frames_DeleteByName('FRAMES_WEAPON_MANCUBFIRE');
1027 g_Frames_DeleteByName('FRAMES_EXPLODE_ROCKET');
1028 g_Frames_DeleteByName('FRAMES_EXPLODE_BFG');
1029 g_Frames_DeleteByName('FRAMES_EXPLODE_IMPFIRE');
1030 g_Frames_DeleteByName('FRAMES_BFGHIT');
1031 g_Frames_DeleteByName('FRAMES_FIRE');
1032 g_Frames_DeleteByName('FRAMES_EXPLODE_PLASMA');
1033 g_Frames_DeleteByName('FRAMES_EXPLODE_BSPFIRE');
1034 g_Frames_DeleteByName('FRAMES_EXPLODE_CACOFIRE');
1035 g_Frames_DeleteByName('FRAMES_SMOKE');
1036 g_Frames_DeleteByName('FRAMES_WEAPON_BARONFIRE');
1037 g_Frames_DeleteByName('FRAMES_EXPLODE_BARONFIRE');
1038 end;
1040 procedure g_Weapon_gun(x, y, xd, yd, v, dmg: Integer; SpawnerUID: Word; CheckTrigger: Boolean);
1041 var
1042 a: Integer;
1043 x2, y2: Integer;
1044 dx, dy: Integer;
1045 xe, ye: Integer;
1046 xi, yi: Integer;
1047 s, c: Extended;
1048 //vx, vy: Integer;
1049 xx, yy, d: Integer;
1051 i: Integer;
1052 t1, _collide: Boolean;
1053 w, h: Word;
1054 begin
1055 a := GetAngle(x, y, xd, yd)+180;
1057 SinCos(DegToRad(-a), s, c);
1059 if Abs(s) < 0.01 then s := 0;
1060 if Abs(c) < 0.01 then c := 0;
1062 x2 := x+Round(c*gMapInfo.Width);
1063 y2 := y+Round(s*gMapInfo.Width);
1065 t1 := gWalls <> nil;
1066 _collide := False;
1067 w := gMapInfo.Width;
1068 h := gMapInfo.Height;
1070 xe := 0;
1071 ye := 0;
1072 dx := x2-x;
1073 dy := y2-y;
1075 if (xd = 0) and (yd = 0) then Exit;
1077 if dx > 0 then xi := 1 else if dx < 0 then xi := -1 else xi := 0;
1078 if dy > 0 then yi := 1 else if dy < 0 then yi := -1 else yi := 0;
1080 dx := Abs(dx);
1081 dy := Abs(dy);
1083 if dx > dy then d := dx else d := dy;
1085 //blood vel, for Monster.Damage()
1086 //vx := (dx*10 div d)*xi;
1087 //vy := (dy*10 div d)*yi;
1089 xx := x;
1090 yy := y;
1092 for i := 1 to d do
1093 begin
1094 xe := xe+dx;
1095 ye := ye+dy;
1097 if xe > d then
1098 begin
1099 xe := xe-d;
1100 xx := xx+xi;
1101 end;
1103 if ye > d then
1104 begin
1105 ye := ye-d;
1106 yy := yy+yi;
1107 end;
1109 if (yy > h) or (yy < 0) then Break;
1110 if (xx > w) or (xx < 0) then Break;
1112 if t1 then
1113 if ByteBool(gCollideMap[yy, xx] and MARK_BLOCKED) then
1114 begin
1115 _collide := True;
1116 g_GFX_Spark(xx-xi, yy-yi, 2+Random(2), 180+a, 0, 0);
1117 if g_Game_IsServer and g_Game_IsNet then
1118 MH_SEND_Effect(xx-xi, yy-yi, 180+a, NET_GFX_SPARK);
1119 end;
1121 if not _collide then
1122 _collide := GunHit(xx, yy, xi*v, yi*v, dmg, SpawnerUID, v <> 0) <> 0;
1124 if _collide then
1125 Break;
1126 end;
1128 if CheckTrigger and g_Game_IsServer then
1129 g_Triggers_PressL(X, Y, xx-xi, yy-yi, SpawnerUID, ACTIVATE_SHOT);
1130 end;
1132 procedure g_Weapon_punch(x, y: Integer; d, SpawnerUID: Word);
1133 var
1134 obj: TObj;
1135 begin
1136 obj.X := X;
1137 obj.Y := Y;
1138 obj.rect.X := 0;
1139 obj.rect.Y := 0;
1140 obj.rect.Width := 39;
1141 obj.rect.Height := 52;
1142 obj.Vel.X := 0;
1143 obj.Vel.Y := 0;
1144 obj.Accel.X := 0;
1145 obj.Accel.Y := 0;
1147 if g_Weapon_Hit(@obj, d, SpawnerUID, HIT_SOME) <> 0 then
1148 g_Sound_PlayExAt('SOUND_WEAPON_HITPUNCH', x, y)
1149 else
1150 g_Sound_PlayExAt('SOUND_WEAPON_MISSPUNCH', x, y);
1151 end;
1153 function g_Weapon_chainsaw(x, y: Integer; d, SpawnerUID: Word): Integer;
1154 var
1155 obj: TObj;
1156 begin
1157 obj.X := X;
1158 obj.Y := Y;
1159 obj.rect.X := 0;
1160 obj.rect.Y := 0;
1161 obj.rect.Width := 32;
1162 obj.rect.Height := 52;
1163 obj.Vel.X := 0;
1164 obj.Vel.Y := 0;
1165 obj.Accel.X := 0;
1166 obj.Accel.Y := 0;
1168 Result := g_Weapon_Hit(@obj, d, SpawnerUID, HIT_SOME);
1169 end;
1171 procedure g_Weapon_rocket(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1172 Silent: Boolean = False);
1173 var
1174 find_id: DWORD;
1175 dx, dy: Integer;
1176 begin
1177 if WID < 0 then
1178 find_id := FindShot()
1179 else
1180 begin
1181 find_id := WID;
1182 if Integer(find_id) >= High(Shots) then
1183 SetLength(Shots, find_id + 64)
1184 end;
1186 with Shots[find_id] do
1187 begin
1188 g_Obj_Init(@Obj);
1190 Obj.Rect.Width := SHOT_ROCKETLAUNCHER_WIDTH;
1191 Obj.Rect.Height := SHOT_ROCKETLAUNCHER_HEIGHT;
1193 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1194 dy := -(Obj.Rect.Height div 2);
1195 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 12);
1197 Animation := nil;
1198 triggers := nil;
1199 ShotType := WEAPON_ROCKETLAUNCHER;
1200 g_Texture_Get('TEXTURE_WEAPON_ROCKET', TextureID);
1201 end;
1203 Shots[find_id].SpawnerUID := SpawnerUID;
1205 if not Silent then
1206 g_Sound_PlayExAt('SOUND_WEAPON_FIREROCKET', x, y);
1207 end;
1209 procedure g_Weapon_revf(x, y, xd, yd: Integer; SpawnerUID, TargetUID: Word;
1210 WID: Integer = -1; Silent: Boolean = False);
1211 var
1212 find_id, FramesID: DWORD;
1213 dx, dy: Integer;
1214 begin
1215 if WID < 0 then
1216 find_id := FindShot()
1217 else
1218 begin
1219 find_id := WID;
1220 if Integer(find_id) >= High(Shots) then
1221 SetLength(Shots, find_id + 64)
1222 end;
1224 with Shots[find_id] do
1225 begin
1226 g_Obj_Init(@Obj);
1228 Obj.Rect.Width := SHOT_SKELFIRE_WIDTH;
1229 Obj.Rect.Height := SHOT_SKELFIRE_HEIGHT;
1231 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1232 dy := -(Obj.Rect.Height div 2);
1233 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 12);
1235 triggers := nil;
1236 ShotType := WEAPON_SKEL_FIRE;
1237 target := TargetUID;
1238 g_Frames_Get(FramesID, 'FRAMES_WEAPON_SKELFIRE');
1239 Animation := TAnimation.Create(FramesID, True, 5);
1240 end;
1242 Shots[find_id].SpawnerUID := SpawnerUID;
1244 if not Silent then
1245 g_Sound_PlayExAt('SOUND_WEAPON_FIREREV', x, y);
1246 end;
1248 procedure g_Weapon_plasma(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1249 Silent: Boolean = False);
1250 var
1251 find_id, FramesID: DWORD;
1252 dx, dy: Integer;
1253 begin
1254 if WID < 0 then
1255 find_id := FindShot()
1256 else
1257 begin
1258 find_id := WID;
1259 if Integer(find_id) >= High(Shots) then
1260 SetLength(Shots, find_id + 64);
1261 end;
1263 with Shots[find_id] do
1264 begin
1265 g_Obj_Init(@Obj);
1267 Obj.Rect.Width := SHOT_PLASMA_WIDTH;
1268 Obj.Rect.Height := SHOT_PLASMA_HEIGHT;
1270 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1271 dy := -(Obj.Rect.Height div 2);
1272 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1274 triggers := nil;
1275 ShotType := WEAPON_PLASMA;
1276 g_Frames_Get(FramesID, 'FRAMES_WEAPON_PLASMA');
1277 Animation := TAnimation.Create(FramesID, True, 5);
1278 end;
1280 Shots[find_id].SpawnerUID := SpawnerUID;
1282 if not Silent then
1283 g_Sound_PlayExAt('SOUND_WEAPON_FIREPLASMA', x, y);
1284 end;
1286 procedure g_Weapon_ball1(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1287 Silent: Boolean = False);
1288 var
1289 find_id, FramesID: DWORD;
1290 dx, dy: Integer;
1291 begin
1292 if WID < 0 then
1293 find_id := FindShot()
1294 else
1295 begin
1296 find_id := WID;
1297 if Integer(find_id) >= High(Shots) then
1298 SetLength(Shots, find_id + 64)
1299 end;
1301 with Shots[find_id] do
1302 begin
1303 g_Obj_Init(@Obj);
1305 Obj.Rect.Width := 16;
1306 Obj.Rect.Height := 16;
1308 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1309 dy := -(Obj.Rect.Height div 2);
1310 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1312 triggers := nil;
1313 ShotType := WEAPON_IMP_FIRE;
1314 g_Frames_Get(FramesID, 'FRAMES_WEAPON_IMPFIRE');
1315 Animation := TAnimation.Create(FramesID, True, 4);
1316 end;
1318 Shots[find_id].SpawnerUID := SpawnerUID;
1320 if not Silent then
1321 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x, y);
1322 end;
1324 procedure g_Weapon_ball2(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1325 Silent: Boolean = False);
1326 var
1327 find_id, FramesID: DWORD;
1328 dx, dy: Integer;
1329 begin
1330 if WID < 0 then
1331 find_id := FindShot()
1332 else
1333 begin
1334 find_id := WID;
1335 if Integer(find_id) >= High(Shots) then
1336 SetLength(Shots, find_id + 64)
1337 end;
1339 with Shots[find_id] do
1340 begin
1341 g_Obj_Init(@Obj);
1343 Obj.Rect.Width := 16;
1344 Obj.Rect.Height := 16;
1346 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1347 dy := -(Obj.Rect.Height div 2);
1348 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1350 triggers := nil;
1351 ShotType := WEAPON_CACO_FIRE;
1352 g_Frames_Get(FramesID, 'FRAMES_WEAPON_CACOFIRE');
1353 Animation := TAnimation.Create(FramesID, True, 4);
1354 end;
1356 Shots[find_id].SpawnerUID := SpawnerUID;
1358 if not Silent then
1359 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x, y);
1360 end;
1362 procedure g_Weapon_ball7(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1363 Silent: Boolean = False);
1364 var
1365 find_id, FramesID: DWORD;
1366 dx, dy: Integer;
1367 begin
1368 if WID < 0 then
1369 find_id := FindShot()
1370 else
1371 begin
1372 find_id := WID;
1373 if Integer(find_id) >= High(Shots) then
1374 SetLength(Shots, find_id + 64)
1375 end;
1377 with Shots[find_id] do
1378 begin
1379 g_Obj_Init(@Obj);
1381 Obj.Rect.Width := 32;
1382 Obj.Rect.Height := 16;
1384 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1385 dy := -(Obj.Rect.Height div 2);
1386 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1388 triggers := nil;
1389 ShotType := WEAPON_BARON_FIRE;
1390 g_Frames_Get(FramesID, 'FRAMES_WEAPON_BARONFIRE');
1391 Animation := TAnimation.Create(FramesID, True, 4);
1392 end;
1394 Shots[find_id].SpawnerUID := SpawnerUID;
1396 if not Silent then
1397 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x, y);
1398 end;
1400 procedure g_Weapon_aplasma(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1401 Silent: Boolean = False);
1402 var
1403 find_id, FramesID: DWORD;
1404 dx, dy: Integer;
1405 begin
1406 if WID < 0 then
1407 find_id := FindShot()
1408 else
1409 begin
1410 find_id := WID;
1411 if Integer(find_id) >= High(Shots) then
1412 SetLength(Shots, find_id + 64)
1413 end;
1415 with Shots[find_id] do
1416 begin
1417 g_Obj_Init(@Obj);
1419 Obj.Rect.Width := 16;
1420 Obj.Rect.Height := 16;
1422 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1423 dy := -(Obj.Rect.Height div 2);
1424 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1426 triggers := nil;
1427 ShotType := WEAPON_BSP_FIRE;
1428 g_Frames_Get(FramesID, 'FRAMES_WEAPON_BSPFIRE');
1429 Animation := TAnimation.Create(FramesID, True, 4);
1430 end;
1432 Shots[find_id].SpawnerUID := SpawnerUID;
1434 if not Silent then
1435 g_Sound_PlayExAt('SOUND_WEAPON_FIREPLASMA', x, y);
1436 end;
1438 procedure g_Weapon_manfire(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1439 Silent: Boolean = False);
1440 var
1441 find_id, FramesID: DWORD;
1442 dx, dy: Integer;
1443 begin
1444 if WID < 0 then
1445 find_id := FindShot()
1446 else
1447 begin
1448 find_id := WID;
1449 if Integer(find_id) >= High(Shots) then
1450 SetLength(Shots, find_id + 64)
1451 end;
1453 with Shots[find_id] do
1454 begin
1455 g_Obj_Init(@Obj);
1457 Obj.Rect.Width := 32;
1458 Obj.Rect.Height := 32;
1460 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1461 dy := -(Obj.Rect.Height div 2);
1462 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1464 triggers := nil;
1465 ShotType := WEAPON_MANCUB_FIRE;
1466 g_Frames_Get(FramesID, 'FRAMES_WEAPON_MANCUBFIRE');
1467 Animation := TAnimation.Create(FramesID, True, 4);
1468 end;
1470 Shots[find_id].SpawnerUID := SpawnerUID;
1472 if not Silent then
1473 g_Sound_PlayExAt('SOUND_WEAPON_FIREBALL', x, y);
1474 end;
1476 procedure g_Weapon_bfgshot(x, y, xd, yd: Integer; SpawnerUID: Word; WID: Integer = -1;
1477 Silent: Boolean = False);
1478 var
1479 find_id, FramesID: DWORD;
1480 dx, dy: Integer;
1481 begin
1482 if WID < 0 then
1483 find_id := FindShot()
1484 else
1485 begin
1486 find_id := WID;
1487 if Integer(find_id) >= High(Shots) then
1488 SetLength(Shots, find_id + 64)
1489 end;
1491 with Shots[find_id] do
1492 begin
1493 g_Obj_Init(@Obj);
1495 Obj.Rect.Width := SHOT_BFG_WIDTH;
1496 Obj.Rect.Height := SHOT_BFG_HEIGHT;
1498 dx := IfThen(xd>x, -Obj.Rect.Width, 0);
1499 dy := -(Obj.Rect.Height div 2);
1500 throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16);
1502 triggers := nil;
1503 ShotType := WEAPON_BFG;
1504 g_Frames_Get(FramesID, 'FRAMES_WEAPON_BFG');
1505 Animation := TAnimation.Create(FramesID, True, 6);
1506 end;
1508 Shots[find_id].SpawnerUID := SpawnerUID;
1510 if not Silent then
1511 g_Sound_PlayExAt('SOUND_WEAPON_FIREBFG', x, y);
1512 end;
1514 procedure g_Weapon_bfghit(x, y: Integer);
1515 var
1516 ID: DWORD;
1517 Anim: TAnimation;
1518 begin
1519 if g_Frames_Get(ID, 'FRAMES_BFGHIT') then
1520 begin
1521 Anim := TAnimation.Create(ID, False, 4);
1522 g_GFX_OnceAnim(x-32, y-32, Anim);
1523 Anim.Free();
1524 end;
1525 end;
1527 procedure g_Weapon_pistol(x, y, xd, yd: Integer; SpawnerUID: Word;
1528 Silent: Boolean = False);
1529 begin
1530 if not Silent then
1531 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', x, y);
1533 g_Weapon_gun(x, y, xd, yd, 1, 3, SpawnerUID, True);
1534 if gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF] then
1535 begin
1536 g_Weapon_gun(x, y+1, xd, yd+1, 1, 3, SpawnerUID, False);
1537 g_Weapon_gun(x, y-1, xd, yd-1, 1, 2, SpawnerUID, False);
1538 end;
1539 end;
1541 procedure g_Weapon_mgun(x, y, xd, yd: Integer; SpawnerUID: Word;
1542 Silent: Boolean = False);
1543 begin
1544 if not Silent then
1545 if gSoundEffectsDF then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', x, y);
1547 g_Weapon_gun(x, y, xd, yd, 1, 3, SpawnerUID, True);
1548 if (gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF]) and
1549 (g_GetUIDType(SpawnerUID) = UID_PLAYER) then
1550 begin
1551 g_Weapon_gun(x, y+1, xd, yd+1, 1, 2, SpawnerUID, False);
1552 g_Weapon_gun(x, y-1, xd, yd-1, 1, 2, SpawnerUID, False);
1553 end;
1554 end;
1556 procedure g_Weapon_shotgun(x, y, xd, yd: Integer; SpawnerUID: Word;
1557 Silent: Boolean = False);
1558 var
1559 i, j: Integer;
1560 begin
1561 if not Silent then
1562 if gSoundEffectsDF then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', x, y);
1564 for i := 0 to 9 do
1565 begin
1566 j := Random(17)-8; // -8 .. 8
1567 g_Weapon_gun(x, y+j, xd, yd+j, IfThen(i mod 2 <> 0, 1, 0), 3, SpawnerUID, i=0);
1568 end;
1569 end;
1571 procedure g_Weapon_dshotgun(x, y, xd, yd: Integer; SpawnerUID: Word;
1572 Silent: Boolean = False);
1573 var
1574 a, i, j: Integer;
1575 begin
1576 if not Silent then
1577 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', x, y);
1579 if gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF] then a := 25 else a := 20;
1580 for i := 0 to a do
1581 begin
1582 j := Random(41)-20; // -20 .. 20
1583 g_Weapon_gun(x, y+j, xd, yd+j, IfThen(i mod 3 <> 0, 0, 1), 3, SpawnerUID, i=0);
1584 end;
1585 end;
1587 procedure g_Weapon_Update();
1588 var
1589 i, a, h, cx, cy, oldvx, oldvy: Integer;
1590 _id: DWORD;
1591 Anim: TAnimation;
1592 t: DWArray;
1593 st: Word;
1594 s: String;
1595 o: TObj;
1596 spl: Boolean;
1597 Loud: Boolean;
1598 begin
1599 if Shots = nil then
1600 Exit;
1602 for i := 0 to High(Shots) do
1603 begin
1604 if Shots[i].ShotType = 0 then
1605 Continue;
1607 Loud := True;
1609 with Shots[i] do
1610 begin
1611 Timeout := Timeout - 1;
1612 oldvx := Obj.Vel.X;
1613 oldvy := Obj.Vel.Y;
1614 // Àêòèâèðîâàòü òðèããåðû ïî ïóòè (êðîìå óæå àêòèâèðîâàííûõ):
1615 if g_Game_IsServer then
1616 t := g_Triggers_PressR(Obj.X, Obj.Y, Obj.Rect.Width, Obj.Rect.Height,
1617 SpawnerUID, ACTIVATE_SHOT, triggers)
1618 else
1619 t := nil;
1621 if t <> nil then
1622 begin
1623 // Ïîïîëíÿåì ñïèñîê àêòèâèðîâàííûõ òðèããåðîâ:
1624 if triggers = nil then
1625 triggers := t
1626 else
1627 begin
1628 h := High(t);
1630 for a := 0 to h do
1631 if not InDWArray(t[a], triggers) then
1632 begin
1633 SetLength(triggers, Length(triggers)+1);
1634 triggers[High(triggers)] := t[a];
1635 end;
1636 end;
1637 end;
1639 // Àíèìàöèÿ ñíàðÿäà:
1640 if Animation <> nil then
1641 Animation.Update();
1643 // Äâèæåíèå:
1644 spl := (ShotType <> WEAPON_PLASMA) and
1645 (ShotType <> WEAPON_BFG) and
1646 (ShotType <> WEAPON_BSP_FIRE);
1648 st := g_Obj_Move(@Obj, False, spl);
1650 if WordBool(st and MOVE_FALLOUT) or (Obj.X < -1000) or
1651 (Obj.X > gMapInfo.Width+1000) or (Obj.Y < -1000) then
1652 begin
1653 // Íà êëèåíòå ñêîðåå âñåãî è òàê óæå âûïàë.
1654 ShotType := 0;
1655 Animation.Free();
1656 Continue;
1657 end;
1659 cx := Obj.X + (Obj.Rect.Width div 2);
1660 cy := Obj.Y + (Obj.Rect.Height div 2);
1662 case ShotType of
1663 WEAPON_ROCKETLAUNCHER, WEAPON_SKEL_FIRE: // Ðàêåòû è ñíàðÿäû Ñêåëåòà
1664 begin
1665 // Âûëåòåëà èç âîäû:
1666 if WordBool(st and MOVE_HITAIR) then
1667 g_Obj_SetSpeed(@Obj, 12);
1669 // Â âîäå øëåéô - ïóçûðè, â âîçäóõå øëåéô - äûì:
1670 if WordBool(st and MOVE_INWATER) then
1671 g_GFX_Bubbles(Obj.X+(Obj.Rect.Width div 2),
1672 Obj.Y+(Obj.Rect.Height div 2),
1673 1+Random(3), 16, 16)
1674 else
1675 if g_Frames_Get(_id, 'FRAMES_SMOKE') then
1676 begin
1677 Anim := TAnimation.Create(_id, False, 3);
1678 Anim.Alpha := 150;
1679 g_GFX_OnceAnim(Obj.X-8+Random(9),
1680 Obj.Y+(Obj.Rect.Height div 2)-20+Random(9),
1681 Anim, ONCEANIM_SMOKE);
1682 Anim.Free();
1683 end;
1685 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
1686 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL)) or
1687 (g_Weapon_Hit(@Obj, 10, SpawnerUID, HIT_SOME, False) <> 0) or
1688 (Timeout < 1) then
1689 begin
1690 Obj.Vel.X := 0;
1691 Obj.Vel.Y := 0;
1693 g_Weapon_Explode(cx, cy, 60, SpawnerUID);
1695 if ShotType = WEAPON_SKEL_FIRE then
1696 begin // Âçðûâ ñíàðÿäà Ñêåëåòà
1697 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_SKELFIRE') then
1698 begin
1699 Anim := TAnimation.Create(TextureID, False, 8);
1700 Anim.Blending := False;
1701 g_GFX_OnceAnim((Obj.X+32)-32, (Obj.Y+8)-32, Anim);
1702 Anim.Free();
1703 end;
1704 end
1705 else
1706 begin // Âçðûâ Ðàêåòû
1707 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_ROCKET') then
1708 begin
1709 Anim := TAnimation.Create(TextureID, False, 6);
1710 Anim.Blending := False;
1711 g_GFX_OnceAnim(cx-64, cy-64, Anim);
1712 Anim.Free();
1713 end;
1714 end;
1716 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', Obj.X, Obj.Y);
1718 ShotType := 0;
1719 end;
1721 if ShotType = WEAPON_SKEL_FIRE then
1722 begin // Ñàìîíàâîäêà ñíàðÿäà Ñêåëåòà:
1723 if GetPos(target, @o) then
1724 throw(i, Obj.X, Obj.Y,
1725 o.X+o.Rect.X+(o.Rect.Width div 2)+o.Vel.X+o.Accel.X,
1726 o.Y+o.Rect.Y+(o.Rect.Height div 2)+o.Vel.Y+o.Accel.Y,
1727 12);
1728 end;
1729 end;
1731 WEAPON_PLASMA, WEAPON_BSP_FIRE: // Ïëàçìà, ïëàçìà Àðàõíàòðîíà
1732 begin
1733 // Ïîïàëà â âîäó - ýëåêòðîøîê ïî âîäå:
1734 if WordBool(st and (MOVE_INWATER or MOVE_HITWATER)) then
1735 begin
1736 g_Sound_PlayExAt('SOUND_WEAPON_PLASMAWATER', Obj.X, Obj.Y);
1737 if g_Game_IsServer then CheckTrap(i, 10, HIT_ELECTRO);
1738 ShotType := 0;
1739 Continue;
1740 end;
1742 // Âåëè÷èíà óðîíà:
1743 if (ShotType = WEAPON_PLASMA) and
1744 (gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF]) then
1745 a := 10
1746 else
1747 a := 5;
1749 if ShotType = WEAPON_BSP_FIRE then
1750 a := 10;
1752 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
1753 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL)) or
1754 (g_Weapon_Hit(@Obj, a, SpawnerUID, HIT_SOME, False) <> 0) or
1755 (Timeout < 1) then
1756 begin
1757 if ShotType = WEAPON_PLASMA then
1758 s := 'FRAMES_EXPLODE_PLASMA'
1759 else
1760 s := 'FRAMES_EXPLODE_BSPFIRE';
1762 // Âçðûâ Ïëàçìû:
1763 if g_Frames_Get(TextureID, s) then
1764 begin
1765 Anim := TAnimation.Create(TextureID, False, 3);
1766 Anim.Blending := False;
1767 g_GFX_OnceAnim(cx-16, cy-16, Anim);
1768 Anim.Free();
1769 end;
1771 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEPLASMA', Obj.X, Obj.Y);
1773 ShotType := 0;
1774 end;
1775 end;
1777 WEAPON_BFG: // BFG
1778 begin
1779 // Ïîïàëà â âîäó - ýëåêòðîøîê ïî âîäå:
1780 if WordBool(st and (MOVE_INWATER or MOVE_HITWATER)) then
1781 begin
1782 g_Sound_PlayExAt('SOUND_WEAPON_BFGWATER', Obj.X, Obj.Y);
1783 if g_Game_IsServer then CheckTrap(i, 1000, HIT_ELECTRO);
1784 ShotType := 0;
1785 Continue;
1786 end;
1788 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
1789 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL)) or
1790 (g_Weapon_Hit(@Obj, SHOT_BFG_DAMAGE, SpawnerUID, HIT_BFG, False) <> 0) or
1791 (Timeout < 1) then
1792 begin
1793 // Ëó÷è BFG:
1794 if g_Game_IsServer then g_Weapon_BFG9000(cx, cy, SpawnerUID);
1796 // Âçðûâ BFG:
1797 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_BFG') then
1798 begin
1799 Anim := TAnimation.Create(TextureID, False, 6);
1800 Anim.Blending := False;
1801 g_GFX_OnceAnim(cx-64, cy-64, Anim);
1802 Anim.Free();
1803 end;
1805 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', Obj.X, Obj.Y);
1807 ShotType := 0;
1808 end;
1809 end;
1811 WEAPON_IMP_FIRE, WEAPON_CACO_FIRE, WEAPON_BARON_FIRE: // Âûñòðåëû Áåñà, Êàêîäåìîíà Ðûöàðÿ/Áàðîíà àäà
1812 begin
1813 // Âûëåòåë èç âîäû:
1814 if WordBool(st and MOVE_HITAIR) then
1815 g_Obj_SetSpeed(@Obj, 16);
1817 // Âåëè÷èíà óðîíà:
1818 if ShotType = WEAPON_IMP_FIRE then
1819 a := 5
1820 else
1821 if ShotType = WEAPON_CACO_FIRE then
1822 a := 20
1823 else
1824 a := 40;
1826 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
1827 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL)) or
1828 (g_Weapon_Hit(@Obj, a, SpawnerUID, HIT_SOME) <> 0) or
1829 (Timeout < 1) then
1830 begin
1831 if ShotType = WEAPON_IMP_FIRE then
1832 s := 'FRAMES_EXPLODE_IMPFIRE'
1833 else
1834 if ShotType = WEAPON_CACO_FIRE then
1835 s := 'FRAMES_EXPLODE_CACOFIRE'
1836 else
1837 s := 'FRAMES_EXPLODE_BARONFIRE';
1839 // Âçðûâ:
1840 if g_Frames_Get(TextureID, s) then
1841 begin
1842 Anim := TAnimation.Create(TextureID, False, 6);
1843 Anim.Blending := False;
1844 g_GFX_OnceAnim(cx-32, cy-32, Anim);
1845 Anim.Free();
1846 end;
1848 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj.X, Obj.Y);
1850 ShotType := 0;
1851 end;
1852 end;
1854 WEAPON_MANCUB_FIRE: // Âûñòðåë Ìàíêóáóñà
1855 begin
1856 // Âûëåòåë èç âîäû:
1857 if WordBool(st and MOVE_HITAIR) then
1858 g_Obj_SetSpeed(@Obj, 16);
1860 // Ïîïàëè â êîãî-òî èëè â ñòåíó:
1861 if WordBool(st and (MOVE_HITWALL or MOVE_HITLAND or MOVE_HITCEIL)) or
1862 (g_Weapon_Hit(@Obj, 40, SpawnerUID, HIT_SOME, False) <> 0) or
1863 (Timeout < 1) then
1864 begin
1865 // Âçðûâ:
1866 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_ROCKET') then
1867 begin
1868 Anim := TAnimation.Create(TextureID, False, 6);
1869 Anim.Blending := False;
1870 g_GFX_OnceAnim(cx-64, cy-64, Anim);
1871 Anim.Free();
1872 end;
1874 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj.X, Obj.Y);
1876 ShotType := 0;
1877 end;
1878 end;
1879 end; // case ShotType of...
1881 // Åñëè ñíàðÿäà óæå íåò, óäàëÿåì àíèìàöèþ:
1882 if (ShotType = 0) then
1883 begin
1884 if gGameSettings.GameType = GT_SERVER then
1885 MH_SEND_DeleteShot(i, Obj.X, Obj.Y, Loud);
1886 Animation.Free();
1887 Animation := nil;
1888 end
1889 else if (oldvx <> Obj.Vel.X) or (oldvy <> Obj.Vel.Y) then
1890 if gGameSettings.GameType = GT_SERVER then
1891 MH_SEND_UpdateShot(i);
1892 end;
1893 end;
1894 end;
1896 procedure g_Weapon_Draw();
1897 var
1898 i: Integer;
1899 a: SmallInt;
1900 p: TPoint;
1901 begin
1902 if Shots = nil then
1903 Exit;
1905 for i := 0 to High(Shots) do
1906 if Shots[i].ShotType <> 0 then
1907 with Shots[i] do
1908 begin
1909 if (Shots[i].ShotType = WEAPON_ROCKETLAUNCHER) or
1910 (Shots[i].ShotType = WEAPON_BARON_FIRE) or
1911 (Shots[i].ShotType = WEAPON_MANCUB_FIRE) or
1912 (Shots[i].ShotType = WEAPON_SKEL_FIRE) then
1913 a := -GetAngle2(Obj.Vel.X, Obj.Vel.Y)
1914 else
1915 a := 0;
1917 p.X := Obj.Rect.Width div 2;
1918 p.Y := Obj.Rect.Height div 2;
1920 if Animation <> nil then
1921 begin
1922 if (Shots[i].ShotType = WEAPON_BARON_FIRE) or
1923 (Shots[i].ShotType = WEAPON_MANCUB_FIRE) or
1924 (Shots[i].ShotType = WEAPON_SKEL_FIRE) then
1925 Animation.DrawEx(Obj.X, Obj.Y, M_NONE, p, a)
1926 else
1927 Animation.Draw(Obj.X, Obj.Y, M_NONE);
1928 end
1929 else
1930 begin
1931 if (Shots[i].ShotType = WEAPON_ROCKETLAUNCHER) then
1932 e_DrawAdv(TextureID, Obj.X, Obj.Y, 0, True, False, a, @p, M_NONE)
1933 else
1934 e_Draw(TextureID, Obj.X, Obj.Y, 0, True, False);
1935 end;
1937 if g_debug_Frames then
1938 begin
1939 e_DrawQuad(Obj.X+Obj.Rect.X,
1940 Obj.Y+Obj.Rect.Y,
1941 Obj.X+Obj.Rect.X+Obj.Rect.Width-1,
1942 Obj.Y+Obj.Rect.Y+Obj.Rect.Height-1,
1943 0, 255, 0);
1944 end;
1945 end;
1946 end;
1948 function g_Weapon_Danger(UID: Word; X, Y: Integer; Width, Height: Word; Time: Byte): Boolean;
1949 var
1950 a: Integer;
1951 begin
1952 Result := False;
1954 if Shots = nil then
1955 Exit;
1957 for a := 0 to High(Shots) do
1958 if (Shots[a].ShotType <> 0) and (Shots[a].SpawnerUID <> UID) then
1959 if ((Shots[a].Obj.Vel.Y = 0) and (Shots[a].Obj.Vel.X > 0) and (Shots[a].Obj.X < X)) or
1960 (Shots[a].Obj.Vel.Y = 0) and (Shots[a].Obj.Vel.X < 0) and (Shots[a].Obj.X > X) then
1961 if (Abs(X-Shots[a].Obj.X) < Abs(Shots[a].Obj.Vel.X*Time)) and
1962 g_Collide(X, Y, Width, Height, X, Shots[a].Obj.Y,
1963 Shots[a].Obj.Rect.Width, Shots[a].Obj.Rect.Height) and
1964 g_TraceVector(X, Y, Shots[a].Obj.X, Shots[a].Obj.Y) then
1965 begin
1966 Result := True;
1967 Exit;
1968 end;
1969 end;
1971 procedure g_Weapon_SaveState(var Mem: TBinMemoryWriter);
1972 var
1973 count, i, j: Integer;
1974 dw: DWORD;
1975 begin
1976 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ ñíàðÿäîâ:
1977 count := 0;
1978 if Shots <> nil then
1979 for i := 0 to High(Shots) do
1980 if Shots[i].ShotType <> 0 then
1981 count := count + 1;
1983 Mem := TBinMemoryWriter.Create((count+1) * 80);
1985 // Êîëè÷åñòâî ñíàðÿäîâ:
1986 Mem.WriteInt(count);
1988 if count = 0 then
1989 Exit;
1991 for i := 0 to High(Shots) do
1992 if Shots[i].ShotType <> 0 then
1993 begin
1994 // Ñèãíàòóðà ñíàðÿäà:
1995 dw := SHOT_SIGNATURE; // 'SHOT'
1996 Mem.WriteDWORD(dw);
1997 // Òèï ñíàðÿäà:
1998 Mem.WriteByte(Shots[i].ShotType);
1999 // Öåëü:
2000 Mem.WriteWord(Shots[i].Target);
2001 // UID ñòðåëÿâøåãî:
2002 Mem.WriteWord(Shots[i].SpawnerUID);
2003 // Ðàçìåð ïîëÿ Triggers:
2004 dw := Length(Shots[i].Triggers);
2005 Mem.WriteDWORD(dw);
2006 // Òðèããåðû, àêòèâèðîâàííûå âûñòðåëîì:
2007 for j := 0 to Integer(dw)-1 do
2008 Mem.WriteDWORD(Shots[i].Triggers[j]);
2009 // Îáúåêò ñíàðÿäà:
2010 Obj_SaveState(@Shots[i].Obj, Mem);
2011 end;
2012 end;
2014 procedure g_Weapon_LoadState(var Mem: TBinMemoryReader);
2015 var
2016 count, i, j: Integer;
2017 dw: DWORD;
2018 begin
2019 if Mem = nil then
2020 Exit;
2022 // Êîëè÷åñòâî ñíàðÿäîâ:
2023 Mem.ReadInt(count);
2025 SetLength(Shots, count);
2027 if count = 0 then
2028 Exit;
2030 for i := 0 to count-1 do
2031 begin
2032 // Ñèãíàòóðà ñíàðÿäà:
2033 Mem.ReadDWORD(dw);
2034 if dw <> SHOT_SIGNATURE then // 'SHOT'
2035 begin
2036 raise EBinSizeError.Create('g_Weapons_LoadState: Wrong Shot Signature');
2037 end;
2038 // Òèï ñíàðÿäà:
2039 Mem.ReadByte(Shots[i].ShotType);
2040 // Öåëü:
2041 Mem.ReadWord(Shots[i].Target);
2042 // UID ñòðåëÿâøåãî:
2043 Mem.ReadWord(Shots[i].SpawnerUID);
2044 // Ðàçìåð ïîëÿ Triggers:
2045 Mem.ReadDWORD(dw);
2046 SetLength(Shots[i].Triggers, dw);
2047 // Òðèããåðû, àêòèâèðîâàííûå âûñòðåëîì:
2048 for j := 0 to Integer(dw)-1 do
2049 Mem.ReadDWORD(Shots[i].Triggers[j]);
2050 // Îáúåêò ïðåäìåòà:
2051 Obj_LoadState(@Shots[i].Obj, Mem);
2053 // Óñòàíîâêà òåêñòóðû èëè àíèìàöèè:
2054 Shots[i].TextureID := DWORD(-1);
2055 Shots[i].Animation := nil;
2057 case Shots[i].ShotType of
2058 WEAPON_ROCKETLAUNCHER, WEAPON_SKEL_FIRE:
2059 begin
2060 g_Texture_Get('TEXTURE_WEAPON_ROCKET', Shots[i].TextureID);
2061 end;
2062 WEAPON_PLASMA:
2063 begin
2064 g_Frames_Get(dw, 'FRAMES_WEAPON_PLASMA');
2065 Shots[i].Animation := TAnimation.Create(dw, True, 5);
2066 end;
2067 WEAPON_BFG:
2068 begin
2069 g_Frames_Get(dw, 'FRAMES_WEAPON_BFG');
2070 Shots[i].Animation := TAnimation.Create(dw, True, 6);
2071 end;
2072 WEAPON_IMP_FIRE:
2073 begin
2074 g_Frames_Get(dw, 'FRAMES_WEAPON_IMPFIRE');
2075 Shots[i].Animation := TAnimation.Create(dw, True, 4);
2076 end;
2077 WEAPON_BSP_FIRE:
2078 begin
2079 g_Frames_Get(dw, 'FRAMES_WEAPON_BSPFIRE');
2080 Shots[i].Animation := TAnimation.Create(dw, True, 4);
2081 end;
2082 WEAPON_CACO_FIRE:
2083 begin
2084 g_Frames_Get(dw, 'FRAMES_WEAPON_CACOFIRE');
2085 Shots[i].Animation := TAnimation.Create(dw, True, 4);
2086 end;
2087 WEAPON_BARON_FIRE:
2088 begin
2089 g_Frames_Get(dw, 'FRAMES_WEAPON_BARONFIRE');
2090 Shots[i].Animation := TAnimation.Create(dw, True, 4);
2091 end;
2092 WEAPON_MANCUB_FIRE:
2093 begin
2094 g_Frames_Get(dw, 'FRAMES_WEAPON_MANCUBFIRE');
2095 Shots[i].Animation := TAnimation.Create(dw, True, 4);
2096 end;
2097 end;
2098 end;
2099 end;
2101 procedure g_Weapon_DestroyShot(I: Integer; X, Y: Integer; Loud: Boolean = True);
2102 var
2103 cx, cy: Integer;
2104 Anim: TAnimation;
2105 s: string;
2106 begin
2107 if Shots = nil then
2108 Exit;
2109 if (I > High(Shots)) or (I < 0) then Exit;
2111 with Shots[I] do
2112 begin
2113 if ShotType = 0 then Exit;
2114 Obj.X := X;
2115 Obj.Y := Y;
2116 cx := Obj.X + (Obj.Rect.Width div 2);
2117 cy := Obj.Y + (Obj.Rect.Height div 2);
2119 case ShotType of
2120 WEAPON_ROCKETLAUNCHER, WEAPON_SKEL_FIRE: // Ðàêåòû è ñíàðÿäû Ñêåëåòà
2121 begin
2122 if Loud then
2123 begin
2124 if ShotType = WEAPON_SKEL_FIRE then
2125 begin // Âçðûâ ñíàðÿäà Ñêåëåòà
2126 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_SKELFIRE') then
2127 begin
2128 Anim := TAnimation.Create(TextureID, False, 8);
2129 Anim.Blending := False;
2130 g_GFX_OnceAnim((Obj.X+32)-32, (Obj.Y+8)-32, Anim);
2131 Anim.Free();
2132 end;
2133 end
2134 else
2135 begin // Âçðûâ Ðàêåòû
2136 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_ROCKET') then
2137 begin
2138 Anim := TAnimation.Create(TextureID, False, 6);
2139 Anim.Blending := False;
2140 g_GFX_OnceAnim(cx-64, cy-64, Anim);
2141 Anim.Free();
2142 end;
2143 end;
2144 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', Obj.X, Obj.Y);
2145 end;
2146 end;
2148 WEAPON_PLASMA, WEAPON_BSP_FIRE: // Ïëàçìà, ïëàçìà Àðàõíàòðîíà
2149 begin
2150 if ShotType = WEAPON_PLASMA then
2151 s := 'FRAMES_EXPLODE_PLASMA'
2152 else
2153 s := 'FRAMES_EXPLODE_BSPFIRE';
2155 if g_Frames_Get(TextureID, s) and loud then
2156 begin
2157 Anim := TAnimation.Create(TextureID, False, 3);
2158 Anim.Blending := False;
2159 g_GFX_OnceAnim(cx-16, cy-16, Anim);
2160 Anim.Free();
2162 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEPLASMA', Obj.X, Obj.Y);
2163 end;
2164 end;
2166 WEAPON_BFG: // BFG
2167 begin
2168 // Âçðûâ BFG:
2169 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_BFG') and Loud then
2170 begin
2171 Anim := TAnimation.Create(TextureID, False, 6);
2172 Anim.Blending := False;
2173 g_GFX_OnceAnim(cx-64, cy-64, Anim);
2174 Anim.Free();
2176 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', Obj.X, Obj.Y);
2177 end;
2178 end;
2180 WEAPON_IMP_FIRE, WEAPON_CACO_FIRE, WEAPON_BARON_FIRE: // Âûñòðåëû Áåñà, Êàêîäåìîíà Ðûöàðÿ/Áàðîíà àäà
2181 begin
2182 if ShotType = WEAPON_IMP_FIRE then
2183 s := 'FRAMES_EXPLODE_IMPFIRE'
2184 else
2185 if ShotType = WEAPON_CACO_FIRE then
2186 s := 'FRAMES_EXPLODE_CACOFIRE'
2187 else
2188 s := 'FRAMES_EXPLODE_BARONFIRE';
2190 if g_Frames_Get(TextureID, s) and Loud then
2191 begin
2192 Anim := TAnimation.Create(TextureID, False, 6);
2193 Anim.Blending := False;
2194 g_GFX_OnceAnim(cx-32, cy-32, Anim);
2195 Anim.Free();
2197 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj.X, Obj.Y);
2198 end;
2199 end;
2201 WEAPON_MANCUB_FIRE: // Âûñòðåë Ìàíêóáóñà
2202 begin
2203 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_ROCKET') and Loud then
2204 begin
2205 Anim := TAnimation.Create(TextureID, False, 6);
2206 Anim.Blending := False;
2207 g_GFX_OnceAnim(cx-64, cy-64, Anim);
2208 Anim.Free();
2210 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBALL', Obj.X, Obj.Y);
2211 end;
2212 end;
2213 end; // case ShotType of...
2215 ShotType := 0;
2216 Animation.Free();
2217 end;
2218 end;
2220 end.