summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 2429544)
raw | patch | inline | side by side (parent: 2429544)
author | Ketmar Dark <ketmar@ketmar.no-ip.org> | |
Mon, 21 Aug 2017 05:12:48 +0000 (08:12 +0300) | ||
committer | Ketmar Dark <ketmar@ketmar.no-ip.org> | |
Mon, 21 Aug 2017 05:19:46 +0000 (08:19 +0300) |
src/game/g_monsters.pas | patch | blob | history | |
src/game/g_triggers.pas | patch | blob | history | |
src/game/g_weapons.pas | patch | blob | history |
index f5f69a93d5eea3b621a153db5d821dd334c49545..55a02104f4a56e602de638d507b13490936100cf 100644 (file)
--- a/src/game/g_monsters.pas
+++ b/src/game/g_monsters.pas
type
TEachMonsterCB = function (monidx: Integer; mon: TMonster): Boolean is nested; // return `true` to stop
-function g_Mons_ForEach (cb: TEachMonsterCB): Boolean;
-
// throws on invalid uid
function g_Mons_ByIdx (uid: Integer): TMonster; inline;
function g_Mons_IsAnyAliveAt (x, y: Integer; width, height: Integer): Boolean;
+function g_Mons_ForEach (cb: TEachMonsterCB): Boolean;
+function g_Mons_ForEachAlive (cb: TEachMonsterCB): Boolean;
+
function g_Mons_ForEachAt (x, y: Integer; width, height: Integer; cb: TEachMonsterCB): Boolean;
-function g_Mons_ForEachAtAlive (x, y: Integer; width, height: Integer; cb: TEachMonsterCB): Boolean;
+function g_Mons_ForEachAliveAt (x, y: Integer; width, height: Integer; cb: TEachMonsterCB): Boolean;
function g_Mons_getNewTrapFrameId (): DWord;
mon.SetState(STATE_GO);
mon.FNoRespawn := True;
Inc(gTotalMonsters);
- if g_Game_IsNet then MH_SEND_MonsterSpawn(gMonsters[sx].UID);
+ if g_Game_IsNet then MH_SEND_MonsterSpawn(mon.UID);
end;
mon := g_Monsters_Create(MONSTER_SOUL, FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
mon.SetState(STATE_GO);
mon.FNoRespawn := True;
Inc(gTotalMonsters);
- if g_Game_IsNet then MH_SEND_MonsterSpawn(gMonsters[sx].UID);
+ if g_Game_IsNet then MH_SEND_MonsterSpawn(mon.UID);
end;
mon := g_Monsters_Create(MONSTER_SOUL, FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2)-15,
mon.SetState(STATE_GO);
mon.FNoRespawn := True;
Inc(gTotalMonsters);
- if g_Game_IsNet then MH_SEND_MonsterSpawn(gMonsters[sx].UID);
+ if g_Game_IsNet then MH_SEND_MonsterSpawn(mon.UID);
end;
- if g_Game_IsNet then MH_SEND_CoopStats(gMonsters[sx].UID);
+
+ if g_Game_IsNet then MH_SEND_CoopStats();
end;
// Ó ýòèõ ìîíñòðîâ íåò òðóïîâ:
mon.shoot(@o, True);
Inc(gTotalMonsters);
- if g_Game_IsNet then MH_SEND_MonsterSpawn(gMonsters[sx].UID);
+ if g_Game_IsNet then MH_SEND_MonsterSpawn(mon.UID);
end;
end;
end;
// ////////////////////////////////////////////////////////////////////////// //
+// throws on invalid uid
+function g_Mons_ByIdx (uid: Integer): TMonster; inline;
+begin
+ result := g_Mons_ByIdx_NC(uid);
+ if (result = nil) then raise Exception.Create('g_Mons_ByIdx: invalid monster id');
+end;
+
+
+// can return null
+function g_Mons_ByIdx_NC (uid: Integer): TMonster; inline;
+begin
+ if (uid < 0) or (uid > High(gMonsters)) then begin result := nil; exit; end;
+ result := gMonsters[uid];
+end;
+
+
function g_Mons_ForEach (cb: TEachMonsterCB): Boolean;
var
idx: Integer;
+ mon: TMonster;
begin
result := false;
if (gMonsters = nil) or not assigned(cb) then exit;
for idx := 0 to High(gMonsters) do
begin
- if (gMonsters[idx] <> nil) then
+ mon := gMonsters[idx];
+ if (mon <> nil) then
begin
result := cb(idx, gMonsters[idx]);
if result then exit;
end;
-// throws on invalid uid
-function g_Mons_ByIdx (uid: Integer): TMonster; inline;
-begin
- result := g_Mons_ByIdx_NC(uid);
- if (result = nil) then raise Exception.Create('g_Mons_ByIdx: invalid monster id');
-end;
-
-
-// can return null
-function g_Mons_ByIdx_NC (uid: Integer): TMonster; inline;
+function g_Mons_ForEachAlive (cb: TEachMonsterCB): Boolean;
+var
+ idx: Integer;
+ mon: TMonster;
begin
- if (uid < 0) or (uid > High(gMonsters)) then begin result := nil; exit; end;
- result := gMonsters[uid];
+ result := false;
+ if (gMonsters = nil) or not assigned(cb) then exit;
+ for idx := 0 to High(gMonsters) do
+ begin
+ mon := gMonsters[idx];
+ if (mon <> nil) and mon.Live then
+ begin
+ result := cb(idx, gMonsters[idx]);
+ if result then exit;
+ end;
+ end;
end;
@@ -4459,10 +4482,10 @@ function g_Mons_IsAnyAliveAt (x, y: Integer; width, height: Integer): Boolean;
var
idx: Integer;
+ mon: TMonster;
begin
result := false;
if (width < 1) or (height < 1) then exit;
-
if gmon_debug_use_sqaccel then
begin
result := (monsTree.aabbQuery(x, y, width, height, monsCollCheck) <> nil);
begin
for idx := 0 to High(gMonsters) do
begin
- if (gMonsters[idx] <> nil) and gMonsters[idx].Live then
+ mon := gMonsters[idx];
+ if (mon <> nil) and mon.Live then
begin
- if g_Obj_Collide(x, y, width, height, @gMonsters[idx].Obj) then
+ if g_Obj_Collide(x, y, width, height, @mon.Obj) then
begin
result := true;
exit;
@@ -4494,10 +4518,10 @@ function g_Mons_ForEachAt (x, y: Integer; width, height: Integer; cb: TEachMonst
var
idx: Integer;
+ mon: TMonster;
begin
result := false;
if (width < 1) or (height < 1) then exit;
-
if gmon_debug_use_sqaccel then
begin
result := (monsTree.aabbQuery(x, y, width, height, monsCollCheck) <> nil);
begin
for idx := 0 to High(gMonsters) do
begin
- if (gMonsters[idx] <> nil) and gMonsters[idx].Live then
+ mon := gMonsters[idx];
+ if (mon <> nil) and mon.Live then
begin
- if g_Obj_Collide(x, y, width, height, @gMonsters[idx].Obj) then
+ if g_Obj_Collide(x, y, width, height, @mon.Obj) then
begin
- result := cb(idx, gMonsters[idx]);
+ result := cb(idx, mon);
if result then exit;
end;
end;
end;
-function g_Mons_ForEachAtAlive (x, y: Integer; width, height: Integer; cb: TEachMonsterCB): Boolean;
+function g_Mons_ForEachAliveAt (x, y: Integer; width, height: Integer; cb: TEachMonsterCB): Boolean;
function monsCollCheck (mon: TMonster; atag: Integer): Boolean;
begin
@@ -4529,10 +4554,10 @@ function g_Mons_ForEachAtAlive (x, y: Integer; width, height: Integer; cb: TEach
var
idx: Integer;
+ mon: TMonster;
begin
result := false;
if (width < 1) or (height < 1) then exit;
-
if gmon_debug_use_sqaccel then
begin
if (width = 1) and (height = 1) then
begin
for idx := 0 to High(gMonsters) do
begin
- if (gMonsters[idx] <> nil) and gMonsters[idx].Live then
+ mon := gMonsters[idx];
+ if (mon <> nil) and mon.Live then
begin
- if g_Obj_Collide(x, y, width, height, @gMonsters[idx].Obj) then
+ if g_Obj_Collide(x, y, width, height, @mon.Obj) then
begin
- result := cb(idx, gMonsters[idx]);
+ result := cb(idx, mon);
if result then exit;
end;
end;
index 8fb459082acf0a7267aadf2e46efa42c02775478..999db6b3ad32f1dad2dd127da468182a24abcdd6 100644 (file)
--- a/src/game/g_triggers.pas
+++ b/src/game/g_triggers.pas
function monsDamage (monidx: Integer; mon: TMonster): Boolean;
begin
result := false; // don't stop
- if (mon <> nil) and mon.Live and g_Obj_Collide(wx, wy, ww, wh, @mon.Obj) then
- begin
- mon.Damage(TRAP_DAMAGE, 0, 0, 0, HIT_TRAP);
- end;
+ if g_Obj_Collide(wx, wy, ww, wh, @mon.Obj) then mon.Damage(TRAP_DAMAGE, 0, 0, 0, HIT_TRAP);
end;
begin
gPlayers[a].Collide(X, Y, Width, Height) then
gPlayers[a].Damage(TRAP_DAMAGE, 0, 0, 0, HIT_TRAP);
- g_Mons_ForEach(monsDamage);
+ //g_Mons_ForEach(monsDamage);
+ g_Mons_ForEachAliveAt(wx, wy, ww, wh, monsDamage);
if not Enabled then g_Map_EnableWall(PanelID);
end;
gPlayers[a].Collide(X, Y, Width, Height) then
gPlayers[a].Damage(TRAP_DAMAGE, 0, 0, 0, HIT_TRAP);
- g_Mons_ForEach(monsDamage);
+ //g_Mons_ForEach(monsDamage);
+ g_Mons_ForEachAliveAt(wx, wy, ww, wh, monsDamage);
(*
if gMonsters <> nil then
for a := 0 to High(gMonsters) do
function monsShotTarget (monidx: Integer; mon: TMonster): Boolean;
begin
result := false; // don't stop
- if (mon <> nil) and mon.Live and tr_ShotAimCheck(Trigger, @(mon.Obj)) then
+ if mon.Live and tr_ShotAimCheck(Trigger, @(mon.Obj)) then
begin
xd := mon.GameX + mon.Obj.Rect.Width div 2;
yd := mon.GameY + mon.Obj.Rect.Height div 2;
function monsShotTargetMonPlr (monidx: Integer; mon: TMonster): Boolean;
begin
result := false; // don't stop
- if (mon <> nil) and mon.Live and tr_ShotAimCheck(Trigger, @(mon.Obj)) then
+ if mon.Live and tr_ShotAimCheck(Trigger, @(mon.Obj)) then
begin
xd := mon.GameX + mon.Obj.Rect.Width div 2;
yd := mon.GameY + mon.Obj.Rect.Height div 2;
function monShotTargetPlrMon (monidx: Integer; mon: TMonster): Boolean;
begin
result := false; // don't stop
- if (mon <> nil) and mon.Live and tr_ShotAimCheck(Trigger, @(mon.Obj)) then
+ if mon.Live and tr_ShotAimCheck(Trigger, @(mon.Obj)) then
begin
xd := mon.GameX + mon.Obj.Rect.Width div 2;
yd := mon.GameY + mon.Obj.Rect.Height div 2;
case Data.ShotTarget of
TRIGGER_SHOT_TARGET_MON: // monsters
- g_Mons_ForEach(monsShotTarget);
+ //TODO: accelerate this!
+ g_Mons_ForEachAlive(monsShotTarget);
TRIGGER_SHOT_TARGET_PLR: // players
if gPlayers <> nil then
TRIGGER_SHOT_TARGET_MONPLR: // monsters then players
begin
- g_Mons_ForEach(monsShotTargetMonPlr);
+ //TODO: accelerate this!
+ g_Mons_ForEachAlive(monsShotTargetMonPlr);
if (TargetUID = 0) and (gPlayers <> nil) then
for idx := Low(gPlayers) to High(gPlayers) do
TargetUID := gPlayers[idx].UID;
break;
end;
- if TargetUID = 0 then g_Mons_ForEach(monShotTargetPlrMon);
+ if TargetUID = 0 then
+ begin
+ //TODO: accelerate this!
+ g_Mons_ForEachAlive(monShotTargetPlrMon);
+ end;
end;
else begin
(TimeOut = 0) and (Keys = 0) then // Åñëè íå íóæíû êëþ÷è
begin
//g_Mons_ForEach(monsNear);
+ //Alive?!
g_Mons_ForEachAt(gTriggers[a].X, gTriggers[a].Y, gTriggers[a].Width, gTriggers[a].Height, monsNear);
end;
diff --git a/src/game/g_weapons.pas b/src/game/g_weapons.pas
index 9fde2f50cd63e93be392051a3dfd29760f286562..148f87c33966595f8e761c3d3bf56b5d5c73bbbf 100644 (file)
--- a/src/game/g_weapons.pas
+++ b/src/game/g_weapons.pas
end;
//g_Mons_ForEach(monsWaterCheck);
- g_Mons_ForEachAtAlive(pan.X, pan.Y, pan.Width, pan.Height, monsWaterCheck);
+ g_Mons_ForEachAliveAt(pan.X, pan.Y, pan.Width, pan.Height, monsWaterCheck);
end;
for f := 0 to plaCount-1 do gPlayers[chkTrap_pl[f]].Damage(dm, Shots[ID].SpawnerUID, 0, 0, t);
if Result <> 0 then Exit;
//if g_Mons_ForEach(monsCheck) then result := 2;
- if g_Mons_ForEachAtAlive(X, Y, 1, 1, monsCheck) then result := 2;
+ if g_Mons_ForEachAliveAt(X, Y, 1, 1, monsCheck) then result := 2;
end;
procedure g_Weapon_BFG9000(X, Y: Integer; SpawnerUID: Word);
function MonsterHit(): Boolean;
begin
//result := g_Mons_ForEach(monsCheckHit);
- result := g_Mons_ForEachAtAlive(obj.X+obj.Rect.X, obj.Y+obj.Rect.Y, obj.Rect.Width, obj.Rect.Height, monsCheckHit);
+ result := g_Mons_ForEachAliveAt(obj.X+obj.Rect.X, obj.Y+obj.Rect.Y, obj.Rect.Width, obj.Rect.Height, monsCheckHit);
end;
begin