From 91547a4c32733ddebebd278c42f290489daffa4e Mon Sep 17 00:00:00 2001 From: Ketmar Dark Date: Mon, 21 Aug 2017 08:18:32 +0300 Subject: [PATCH] removed "monidx" argument from monster spatial query callback (each monster has UIDs, use UID to get monster object later!) --- src/game/g_game.pas | 6 +++--- src/game/g_map.pas | 2 +- src/game/g_monsters.pas | 19 +++++++++++-------- src/game/g_netmsg.pas | 2 +- src/game/g_player.pas | 4 ++-- src/game/g_triggers.pas | 12 ++++++------ src/game/g_weapons.pas | 17 +++++++++-------- 7 files changed, 33 insertions(+), 29 deletions(-) diff --git a/src/game/g_game.pas b/src/game/g_game.pas index c09158d..ad2a0f7 100644 --- a/src/game/g_game.pas +++ b/src/game/g_game.pas @@ -1440,7 +1440,7 @@ var w: Word; i, b: Integer; - function sendMonsPos (monidx: Integer; mon: TMonster): Boolean; + function sendMonsPos (mon: TMonster): Boolean; begin result := false; // don't stop if (mon.MonsterType = MONSTER_BARREL) then @@ -2442,7 +2442,7 @@ procedure DrawMinimap(p: TPlayer; RenderRect: e_graphics.TRect); var a, aX, aY, aX2, aY2, Scale, ScaleSz: Integer; - function monDraw (monidx: Integer; mon: TMonster): Boolean; + function monDraw (mon: TMonster): Boolean; begin result := false; // don't stop with mon do @@ -4171,7 +4171,7 @@ procedure g_Game_RestartRound(NoMapRestart: Boolean = False); var i, n, nb, nr: Integer; - function monRespawn (monidx: Integer; mon: TMonster): Boolean; + function monRespawn (mon: TMonster): Boolean; begin result := false; // don't stop if not mon.FNoRespawn then mon.Respawn(); diff --git a/src/game/g_map.pas b/src/game/g_map.pas index f063f74..52713fd 100644 --- a/src/game/g_map.pas +++ b/src/game/g_map.pas @@ -962,7 +962,7 @@ end; procedure g_Map_ReAdd_DieTriggers(); - function monsDieTrig (monidx: Integer; mon: TMonster): Boolean; + function monsDieTrig (mon: TMonster): Boolean; var a: Integer; begin diff --git a/src/game/g_monsters.pas b/src/game/g_monsters.pas index 55a0210..d577b23 100644 --- a/src/game/g_monsters.pas +++ b/src/game/g_monsters.pas @@ -181,7 +181,7 @@ function g_Monsters_GetKilledBy (MonsterType: Byte): String; type - TEachMonsterCB = function (monidx: Integer; mon: TMonster): Boolean is nested; // return `true` to stop + TEachMonsterCB = function (mon: TMonster): Boolean is nested; // return `true` to stop // throws on invalid uid function g_Mons_ByIdx (uid: Integer): TMonster; inline; @@ -573,6 +573,7 @@ begin Result := False; end; + function BehaviourDamage(SpawnerUID: Word; BH, SelfType: Byte): Boolean; var m: TMonster; @@ -602,6 +603,7 @@ begin end; end; + function canShoot(m: Byte): Boolean; begin Result := False; @@ -614,7 +616,8 @@ begin end; end; -function isCorpse(o: PObj; immediately: Boolean): Integer; + +function isCorpse (o: PObj; immediately: Boolean): Integer; function monsCollCheck (mon: TMonster; atag: Integer): Boolean; begin @@ -4447,7 +4450,7 @@ begin mon := gMonsters[idx]; if (mon <> nil) then begin - result := cb(idx, gMonsters[idx]); + result := cb(mon); if result then exit; end; end; @@ -4466,7 +4469,7 @@ begin mon := gMonsters[idx]; if (mon <> nil) and mon.Live then begin - result := cb(idx, gMonsters[idx]); + result := cb(mon); if result then exit; end; end; @@ -4513,7 +4516,7 @@ function g_Mons_ForEachAt (x, y: Integer; width, height: Integer; cb: TEachMonst function monsCollCheck (mon: TMonster; atag: Integer): Boolean; begin result := false; - if g_Obj_Collide(x, y, width, height, @mon.Obj) then result := cb(mon.arrIdx, mon); + if g_Obj_Collide(x, y, width, height, @mon.Obj) then result := cb(mon); end; var @@ -4535,7 +4538,7 @@ begin begin if g_Obj_Collide(x, y, width, height, @mon.Obj) then begin - result := cb(idx, mon); + result := cb(mon); if result then exit; end; end; @@ -4549,7 +4552,7 @@ function g_Mons_ForEachAliveAt (x, y: Integer; width, height: Integer; cb: TEach function monsCollCheck (mon: TMonster; atag: Integer): Boolean; begin result := false; - if mon.Live and g_Obj_Collide(x, y, width, height, @mon.Obj) then result := cb(mon.arrIdx, mon); + if mon.Live and g_Obj_Collide(x, y, width, height, @mon.Obj) then result := cb(mon); end; var @@ -4578,7 +4581,7 @@ begin begin if g_Obj_Collide(x, y, width, height, @mon.Obj) then begin - result := cb(idx, mon); + result := cb(mon); if result then exit; end; end; diff --git a/src/game/g_netmsg.pas b/src/game/g_netmsg.pas index 213669e..936141a 100644 --- a/src/game/g_netmsg.pas +++ b/src/game/g_netmsg.pas @@ -634,7 +634,7 @@ procedure MH_SEND_Everything(CreatePlayers: Boolean = False; ID: Integer = NET_E MH_SEND_ItemSpawn(True, it.myid, ID); end; - function sendMonSpawn (monidx: Integer; mon: TMonster): Boolean; + function sendMonSpawn (mon: TMonster): Boolean; begin result := false; // don't stop MH_SEND_MonsterSpawn(mon.UID, ID); diff --git a/src/game/g_player.pas b/src/game/g_player.pas index 612a4fb..2b7fec9 100644 --- a/src/game/g_player.pas +++ b/src/game/g_player.pas @@ -6304,10 +6304,10 @@ var vsPlayer, vsMonster, ok: Boolean; - function monsUpdate (monidx: Integer; mon: TMonster): Boolean; + function monsUpdate (mon: TMonster): Boolean; begin result := false; // don't stop - if (mon <> nil) and (mon.Live) and (mon.MonsterType <> MONSTER_BARREL) then + if mon.Live and (mon.MonsterType <> MONSTER_BARREL) then begin if not TargetOnScreen(mon.Obj.X+mon.Obj.Rect.X, mon.Obj.Y+mon.Obj.Rect.Y) then exit; diff --git a/src/game/g_triggers.pas b/src/game/g_triggers.pas index 999db6b..e39b8c6 100644 --- a/src/game/g_triggers.pas +++ b/src/game/g_triggers.pas @@ -211,7 +211,7 @@ var a, b, c: Integer; wx, wy, wh, ww: Integer; - function monsDamage (monidx: Integer; mon: TMonster): Boolean; + function monsDamage (mon: TMonster): Boolean; begin result := false; // don't stop if g_Obj_Collide(wx, wy, ww, wh, @mon.Obj) then mon.Damage(TRAP_DAMAGE, 0, 0, 0, HIT_TRAP); @@ -985,7 +985,7 @@ var it: PItem; mon: TMonster; - function monsShotTarget (monidx: Integer; mon: TMonster): Boolean; + function monsShotTarget (mon: TMonster): Boolean; begin result := false; // don't stop if mon.Live and tr_ShotAimCheck(Trigger, @(mon.Obj)) then @@ -997,7 +997,7 @@ var end; end; - function monsShotTargetMonPlr (monidx: Integer; mon: TMonster): Boolean; + function monsShotTargetMonPlr (mon: TMonster): Boolean; begin result := false; // don't stop if mon.Live and tr_ShotAimCheck(Trigger, @(mon.Obj)) then @@ -1009,7 +1009,7 @@ var end; end; - function monShotTargetPlrMon (monidx: Integer; mon: TMonster): Boolean; + function monShotTargetPlrMon (mon: TMonster): Boolean; begin result := false; // don't stop if mon.Live and tr_ShotAimCheck(Trigger, @(mon.Obj)) then @@ -2201,7 +2201,7 @@ var a, b, i: Integer; Affected: array of Integer; - {function monsNear (monidx: Integer; mon: TMonster): Boolean; + {function monsNear (mon: TMonster): Boolean; begin result := false; // don't stop if mon.Collide(gTriggers[a].X, gTriggers[a].Y, gTriggers[a].Width, gTriggers[a].Height) then @@ -2211,7 +2211,7 @@ var end; end;} - function monsNear (monidx: Integer; mon: TMonster): Boolean; + function monsNear (mon: TMonster): Boolean; begin result := false; // don't stop gTriggers[a].ActivateUID := mon.UID; diff --git a/src/game/g_weapons.pas b/src/game/g_weapons.pas index 148f87c..d9c20e6 100644 --- a/src/game/g_weapons.pas +++ b/src/game/g_weapons.pas @@ -257,7 +257,7 @@ var frameId: DWord; { - function monsWaterCheck (monidx: Integer; mon: TMonster): Boolean; + function monsWaterCheck (mon: TMonster): Boolean; begin result := false; // don't stop if mon.Live and mon.Collide(gWater[WaterMap[a][c]]) and (not InWArray(monidx, chkTrap_mn)) and (i2 < 1023) then //FIXME @@ -268,7 +268,7 @@ var end; } - function monsWaterCheck (monidx: Integer; mon: TMonster): Boolean; + function monsWaterCheck (mon: TMonster): Boolean; begin result := false; // don't stop if (mon.trapCheckFrameId <> frameId) then @@ -420,7 +420,7 @@ end; function GunHit(X, Y: Integer; vx, vy: Integer; dmg: Integer; SpawnerUID: Word; AllowPush: Boolean): Byte; - {function monsCheck (monidx: Integer; mon: TMonster): Boolean; + {function monsCheck (mon: TMonster): Boolean; begin result := false; // don't stop if mon.Live and mon.Collide(X, Y) then @@ -433,7 +433,7 @@ function GunHit(X, Y: Integer; vx, vy: Integer; dmg: Integer; end; end;} - function monsCheck (monidx: Integer; mon: TMonster): Boolean; + function monsCheck (mon: TMonster): Boolean; begin result := false; // don't stop if HitMonster(mon, dmg, vx*10, vy*10-3, SpawnerUID, HIT_SOME) then @@ -467,7 +467,7 @@ end; procedure g_Weapon_BFG9000(X, Y: Integer; SpawnerUID: Word); - function monsCheck (monidx: Integer; mon: TMonster): Boolean; + function monsCheck (mon: TMonster): Boolean; begin result := false; // don't stop if (mon.Live) and (mon.UID <> SpawnerUID) then @@ -534,7 +534,7 @@ begin end; //FIXME - g_Mons_ForEach(monsCheck); + g_Mons_ForEachAlive(monsCheck); end; function g_Weapon_CreateShot(I: Integer; ShotType: Byte; Spawner, TargetUID: Word; X, Y, XV, YV: Integer): LongWord; @@ -814,7 +814,7 @@ var end; } - function monsCheckHit (monidx: Integer; mon: TMonster): Boolean; + function monsCheckHit (mon: TMonster): Boolean; begin result := false; // don't stop if HitMonster(mon, d, obj.Vel.X, obj.Vel.Y, SpawnerUID, t) then @@ -831,6 +831,7 @@ var function MonsterHit(): Boolean; begin //result := g_Mons_ForEach(monsCheckHit); + //FIXME: accelerate this! result := g_Mons_ForEachAliveAt(obj.X+obj.Rect.X, obj.Y+obj.Rect.Y, obj.Rect.Width, obj.Rect.Height, monsCheckHit); end; @@ -931,7 +932,7 @@ function g_Weapon_Explode(X, Y: Integer; rad: Integer; SpawnerUID: Word): Boolea var r: Integer; // squared radius - function monsExCheck (monidx: Integer; mon: TMonster): Boolean; + function monsExCheck (mon: TMonster): Boolean; var dx, dy, mm: Integer; begin -- 2.29.2