X-Git-Url: http://deadsoftware.ru/gitweb?a=blobdiff_plain;f=src%2Fgame%2Fg_monsters.pas;h=d577b235b946c5d6ff143ba4c7930c34af7446e0;hb=77620b19e88e8eb4884be54475632754d8a4014e;hp=f5f69a93d5eea3b621a153db5d821dd334c49545;hpb=2281a9384c7d29ae85f32a746fa748e000a7870f;p=d2df-sdl.git diff --git a/src/game/g_monsters.pas b/src/game/g_monsters.pas index f5f69a9..d577b23 100644 --- a/src/game/g_monsters.pas +++ b/src/game/g_monsters.pas @@ -181,9 +181,7 @@ function g_Monsters_GetKilledBy (MonsterType: Byte): String; type - TEachMonsterCB = function (monidx: Integer; mon: TMonster): Boolean is nested; // return `true` to stop - -function g_Mons_ForEach (cb: TEachMonsterCB): Boolean; + TEachMonsterCB = function (mon: TMonster): Boolean is nested; // return `true` to stop // throws on invalid uid function g_Mons_ByIdx (uid: Integer): TMonster; inline; @@ -193,8 +191,11 @@ function g_Mons_ByIdx_NC (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; @@ -572,6 +573,7 @@ begin Result := False; end; + function BehaviourDamage(SpawnerUID: Word; BH, SelfType: Byte): Boolean; var m: TMonster; @@ -601,6 +603,7 @@ begin end; end; + function canShoot(m: Byte): Boolean; begin Result := False; @@ -613,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 @@ -2866,7 +2870,7 @@ _end: 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), @@ -2876,7 +2880,7 @@ _end: 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, @@ -2886,9 +2890,10 @@ _end: 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; // Ó ýòèõ ìîíñòðîâ íåò òðóïîâ: @@ -3061,7 +3066,7 @@ _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; @@ -4417,36 +4422,57 @@ 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]); + result := cb(mon); if result then exit; 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; +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(mon); + if result then exit; + end; + end; end; @@ -4459,10 +4485,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); @@ -4471,9 +4497,10 @@ begin 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; @@ -4489,15 +4516,15 @@ 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 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); @@ -4506,11 +4533,12 @@ begin 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(mon); if result then exit; end; end; @@ -4519,20 +4547,20 @@ begin 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 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 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 @@ -4548,11 +4576,12 @@ begin 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(mon); if result then exit; end; end;