diff --git a/src/game/g_weapons.pas b/src/game/g_weapons.pas
index fc9db75ca5576da7fd02a0acec6b20a7c7cab88b..aa78ebd94e7ddae5fa7f224eada8b21f0cf3f79e 100644 (file)
--- a/src/game/g_weapons.pas
+++ b/src/game/g_weapons.pas
wgunHitTimeUsed: Integer = 0;
wgunHitTimeUsed: Integer = 0;
-function hitTimeCompare (a, b: Integer): Boolean;
+function hitTimeLess (a, b: Integer): Boolean;
+var
+ hta, htb: PHitTime;
begin
begin
- if (wgunHitTime[a].distSq < wgunHitTime[b].distSq) then begin result := true; exit; end;
- if (wgunHitTime[a].distSq > wgunHitTime[b].distSq) then begin result := false; exit; end;
- if (wgunHitTime[a].mon <> nil) then
+ hta := @wgunHitTime[a];
+ htb := @wgunHitTime[b];
+ if (hta.distSq <> htb.distSq) then begin result := (hta.distSq < htb.distSq); exit; end;
+ if (hta.mon <> nil) then
begin
// a is monster
begin
// a is monster
- if (wgunHitTime[b].mon = nil) then begin result := false; exit; end; // players first
- result := (wgunHitTime[a].mon.UID < wgunHitTime[b].mon.UID); // why not?
+ if (htb.mon = nil) then begin result := false; exit; end; // players first
+ result := (hta.mon.UID < htb.mon.UID); // why not?
end
else
begin
// a is player
end
else
begin
// a is player
- if (wgunHitTime[b].mon <> nil) then begin result := true; exit; end; // players first
- result := (wgunHitTime[a].plridx < wgunHitTime[b].plridx); // why not?
+ if (htb.mon <> nil) then begin result := true; exit; end; // players first
+ result := (hta.plridx < htb.plridx); // why not?
end;
end;
end;
end;
g_Texture_CreateWADEx('TEXTURE_SHELL_SHELL', GameWAD+':TEXTURES\ESHELL');
//wgunMonHash := hashNewIntInt();
g_Texture_CreateWADEx('TEXTURE_SHELL_SHELL', GameWAD+':TEXTURES\ESHELL');
//wgunMonHash := hashNewIntInt();
- wgunHitHeap := TBinaryHeapHitTimes.Create(hitTimeCompare);
+ wgunHitHeap := TBinaryHeapHitTimes.Create(hitTimeLess);
end;
procedure g_Weapon_FreeData();
end;
procedure g_Weapon_FreeData();
//!!!FIXME!!!
procedure g_Weapon_gun (const x, y, xd, yd, v, dmg: Integer; SpawnerUID: Word; CheckTrigger: Boolean);
var
//!!!FIXME!!!
procedure g_Weapon_gun (const x, y, xd, yd, v, dmg: Integer; SpawnerUID: Word; CheckTrigger: Boolean);
var
+ x0, y0: Integer;
x2, y2: Integer;
xi, yi: Integer;
wallDistSq: Integer = $3fffffff;
x2, y2: Integer;
xi, yi: Integer;
wallDistSq: Integer = $3fffffff;
begin
result := false; // don't stop
mon.getMapBox(mx, my, mw, mh);
begin
result := false; // don't stop
mon.getMapBox(mx, my, mw, mh);
- if lineAABBIntersects(x, y, x2, y2, mx, my, mw, mh, inx, iny) then
+ if lineAABBIntersects(x0, y0, x2, y2, mx, my, mw, mh, inx, iny) then
begin
begin
- distSq := distanceSq(x, y, inx, iny);
- if (distSq < wallDistSq) then appendHitTimeMon(distanceSq(x, y, inx, iny), mon, inx, iny);
+ distSq := distanceSq(x0, y0, inx, iny);
+ if (distSq < wallDistSq) then appendHitTimeMon(distSq, mon, inx, iny);
end;
end;
end;
end;
end;
*)
end;
*)
+ if (xd = 0) and (yd = 0) then exit;
+
//wgunMonHash.reset(); //FIXME: clear hash on level change
wgunHitHeap.clear();
wgunHitTimeUsed := 0;
//wgunMonHash.reset(); //FIXME: clear hash on level change
wgunHitHeap.clear();
wgunHitTimeUsed := 0;
if Abs(s) < 0.01 then s := 0;
if Abs(c) < 0.01 then c := 0;
if Abs(s) < 0.01 then s := 0;
if Abs(c) < 0.01 then c := 0;
+ x0 := x;
+ y0 := y;
x2 := x+Round(c*gMapInfo.Width);
y2 := y+Round(s*gMapInfo.Width);
dx := x2-x;
dy := y2-y;
x2 := x+Round(c*gMapInfo.Width);
y2 := y+Round(s*gMapInfo.Width);
dx := x2-x;
dy := y2-y;
- if (xd = 0) and (yd = 0) then exit;
-
- if dx > 0 then xi := 1 else if dx < 0 then xi := -1 else xi := 0;
- if dy > 0 then yi := 1 else if dy < 0 then yi := -1 else yi := 0;
+ if (dx > 0) then xi := 1 else if (dx < 0) then xi := -1 else xi := 0;
+ if (dy > 0) then yi := 1 else if (dy < 0) then yi := -1 else yi := 0;
{$IF DEFINED(D2F_DEBUG)}
e_WriteLog(Format('GUN TRACE: (%d,%d) to (%d,%d)', [x, y, x2, y2]), MSG_NOTIFY);
stt := curTimeMicro();
{$ENDIF}
{$IF DEFINED(D2F_DEBUG)}
e_WriteLog(Format('GUN TRACE: (%d,%d) to (%d,%d)', [x, y, x2, y2]), MSG_NOTIFY);
stt := curTimeMicro();
{$ENDIF}
- wallHitFlag := g_Map_traceToNearestWall(x, y, x2, y2, @wallHitX, @wallHitY);
+ wallHitFlag := (g_Map_traceToNearestWall(x, y, x2, y2, @wallHitX, @wallHitY) <> nil);
if wallHitFlag then
begin
x2 := wallHitX;
if wallHitFlag then
begin
x2 := wallHitX;
if playerPossibleHit() then exit; // instant hit
// collect monsters
if playerPossibleHit() then exit; // instant hit
// collect monsters
- g_Mons_alongLine(x, y, x2, y2, sqchecker);
+ g_Mons_AlongLine(x, y, x2, y2, sqchecker);
// here, we collected all monsters and players in `wgunHitHeap` and `wgunHitTime`
// here, we collected all monsters and players in `wgunHitHeap` and `wgunHitTime`
- // also, if `wallWasHit` >= 0, then `wallHitX` and `wallHitY` contains spark coords
+ // also, if `wallWasHit` is `true`, then `wallHitX` and `wallHitY` contains spark coords
while (wgunHitHeap.count > 0) do
begin
// has some entities to check, do it
i := wgunHitHeap.front;
wgunHitHeap.popFront();
while (wgunHitHeap.count > 0) do
begin
// has some entities to check, do it
i := wgunHitHeap.front;
wgunHitHeap.popFront();
+ // hitpoint
xe := wgunHitTime[i].x;
ye := wgunHitTime[i].y;
// check if it is not behind the wall
xe := wgunHitTime[i].x;
ye := wgunHitTime[i].y;
// check if it is not behind the wall