X-Git-Url: https://deadsoftware.ru/gitweb?a=blobdiff_plain;ds=inline;f=src%2Fgame%2Fg_monsters.pas;h=92ee2f66a84b55c4d83e904d4705f584ced54a9d;hb=0944e70467355a7771d42015b6e548050e6fa3b7;hp=5fb769dbdab703eb9daff973c5877a6ea556025b;hpb=3cde28288f16b317ae049cc692aa95536f297d2d;p=d2df-sdl.git
diff --git a/src/game/g_monsters.pas b/src/game/g_monsters.pas
index 5fb769d..92ee2f6 100644
--- a/src/game/g_monsters.pas
+++ b/src/game/g_monsters.pas
@@ -14,6 +14,8 @@
* along with this program. If not, see .
*)
{$INCLUDE ../shared/a_modes.inc}
+{$M+}
+{.$DEFINE D2F_DEBUG_MONS_MOVE}
unit g_monsters;
interface
@@ -89,10 +91,14 @@ type
function findNewPrey(): Boolean;
procedure ActivateTriggers();
+ procedure setGameX (v: Integer); inline;
+ procedure setGameY (v: Integer); inline;
+
public
FNoRespawn: Boolean;
FFireTime: Integer;
trapCheckFrameId: DWord; // for `g_weapons.CheckTrap()`
+ mplatCheckFrameId: LongWord;
constructor Create(MonsterType: Byte; aID: Integer; ForcedUID: Integer = -1);
destructor Destroy(); override;
@@ -100,7 +106,7 @@ type
function Collide(Panel: TPanel): Boolean; overload;
function Collide(X, Y: Integer): Boolean; overload;
function TeleportTo(X, Y: Integer; silent: Boolean; dir: Byte): Boolean;
- function Live(): Boolean;
+ function alive(): Boolean;
procedure SetHealth(aH: Integer);
procedure Push(vx, vy: Integer);
function Damage(aDamage: Word; VelX, VelY: Integer; SpawnerUID: Word; t: Byte): Boolean;
@@ -133,8 +139,18 @@ type
procedure positionChanged (); //WARNING! call this after monster position was changed, or coldet will not work right!
+ procedure setPosition (ax, ay: Integer; callPosChanged: Boolean=true); inline;
+ procedure moveBy (dx, dy: Integer); inline;
+
procedure getMapBox (out x, y, w, h: Integer); inline;
+ public
+ property Obj: TObj read FObj;
+
+ property proxyId: Integer read mProxyId;
+ property arrIdx: Integer read mArrIdx;
+
+ published
property MonsterType: Byte read FMonsterType;
property MonsterHealth: Integer read FHealth write FHealth;
property MonsterAmmo: Integer read FAmmo write FAmmo;
@@ -147,12 +163,11 @@ type
property MonsterPain: Integer read FPain write FPain;
property MonsterAnim: Byte read FCurAnim write FCurAnim;
- property Obj: TObj read FObj;
property UID: Word read FUID write FUID;
property SpawnTrigger: Integer read FSpawnTrigger write FSpawnTrigger;
- property GameX: Integer read FObj.X write FObj.X;
- property GameY: Integer read FObj.Y write FObj.Y;
+ property GameX: Integer read FObj.X write setGameX;
+ property GameY: Integer read FObj.Y write setGameY;
property GameVelX: Integer read FObj.Vel.X write FObj.Vel.X;
property GameVelY: Integer read FObj.Vel.Y write FObj.Vel.Y;
property GameAccelX: Integer read FObj.Accel.X write FObj.Accel.X;
@@ -160,9 +175,6 @@ type
property GameDirection: TDirection read FDirection write FDirection;
property StartID: Integer read FStartID;
-
- property proxyId: Integer read mProxyId;
- property arrIdx: Integer read mArrIdx;
end;
@@ -172,7 +184,7 @@ procedure g_Mons_InitTree (x, y, w, h: Integer);
procedure g_Monsters_LoadData ();
procedure g_Monsters_FreeData ();
procedure g_Monsters_Init ();
-procedure g_Monsters_Free ();
+procedure g_Monsters_Free (clearGrid: Boolean=true);
function g_Monsters_Create (MonsterType: Byte; X, Y: Integer; Direction: TDirection;
AdjCoord: Boolean = False; ForcedUID: Integer = -1): TMonster;
procedure g_Monsters_Update ();
@@ -182,9 +194,16 @@ function g_Monsters_ByUID (UID: Word): TMonster;
procedure g_Monsters_killedp ();
procedure g_Monsters_SaveState (var Mem: TBinMemoryWriter);
procedure g_Monsters_LoadState (var Mem: TBinMemoryReader);
-function g_Monsters_GetIDByName (name: String): Integer;
-function g_Monsters_GetNameByID (MonsterType: Byte): String;
-function g_Monsters_GetKilledBy (MonsterType: Byte): String;
+
+function g_Mons_SpawnAt (monType: Integer; x, y: Integer; dir: TDirection=D_LEFT): TMonster; overload;
+function g_Mons_SpawnAt (const typeName: AnsiString; x, y: Integer; dir: TDirection=D_LEFT): TMonster; overload;
+
+function g_Mons_TypeLo (): Integer; inline;
+function g_Mons_TypeHi (): Integer; inline;
+
+function g_Mons_TypeIdByName (const name: AnsiString): Integer;
+function g_Mons_NameByTypeId (monType: Integer): AnsiString;
+function g_Mons_GetKilledByTypeId (monType: Integer): AnsiString;
type
@@ -206,7 +225,8 @@ function g_Mons_ForEachAlive (cb: TEachMonsterCB): Boolean;
function g_Mons_ForEachAt (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;
+function g_Mons_getNewTrapFrameId (): DWord; inline;
+function g_Mons_getNewMPlatFrameId (): LongWord; inline;
type
@@ -234,7 +254,7 @@ type
TMonsterGrid = specialize TBodyGridBase;
var
- monsGrid: TMonsterGrid = nil;
+ monsGrid: TMonsterGrid = nil; // DO NOT USE! public for debugging only!
var
@@ -248,7 +268,8 @@ uses
e_log, g_main, g_sound, g_gfx, g_player, g_game,
g_weapons, g_triggers, MAPDEF, g_items, g_options,
g_console, g_map, Math, SysUtils, g_menu, wadreader,
- g_language, g_netmsg;
+ g_language, g_netmsg, idpool;
+
// ////////////////////////////////////////////////////////////////////////// //
@@ -281,7 +302,8 @@ end;
// ////////////////////////////////////////////////////////////////////////// //
var
- monCheckTrapLastFrameId: DWord;
+ monCheckTrapLastFrameId: DWord = 0;
+ monCheckMPlatLastFrameId: LongWord = 0;
procedure TMonster.getMapBox (out x, y, w, h: Integer); inline;
@@ -304,7 +326,8 @@ end;
//WARNING! call this after monster position was changed, or coldet will not work right!
procedure TMonster.positionChanged ();
var
- x, y: Integer;
+ x, y, w, h: Integer;
+ nx, ny, nw, nh: Integer;
begin
{$IF DEFINED(D2F_DEBUG_MONS_MOVE)}
//e_WriteLog(Format('monster #%d(%u): pos=(%d,%d); rpos=(%d,%d)', [mArrIdx, UID, FObj.X, FObj.Y, FObj.Rect.X, FObj.Rect.Y]), MSG_NOTIFY);
@@ -314,25 +337,35 @@ begin
mProxyId := monsGrid.insertBody(self, FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, FObj.Rect.Width, FObj.Rect.Height);
{$IF DEFINED(D2F_DEBUG_MONS_MOVE)}
monsGrid.getBodyXY(mProxyId, x, y);
- e_WriteLog(Format('monster #%d(%u): inserted into the grid; mProxyid=%d; x=%d; y=%d', [mArrIdx, UID, mProxyId, x, y]), MSG_NOTIFY);
+ e_WriteLog(Format('monster #%d:(%u): inserted into the grid; mProxyid=%d; gx=%d; gy=%d', [mArrIdx, UID, mProxyId, x-monsGrid.gridX0, y-monsGrid.gridY0]), MSG_NOTIFY);
{$ENDIF}
end
else
begin
- monsGrid.getBodyXY(mProxyId, x, y);
- if (FObj.X+FObj.Rect.X = x) and (FObj.Y+FObj.Rect.Y = y) then exit; // nothing to do
- {$IF DEFINED(D2F_DEBUG_MONS_MOVE)}e_WriteLog(Format('monster #%d(%u): updating tree; mProxyid=%d; x=%d; y=%d', [mArrIdx, UID, mProxyId, x, y]), MSG_NOTIFY);{$ENDIF}
-
- {$IF TRUE}
- monsGrid.moveBody(mProxyId, FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y);
- {$ELSE}
- monsGrid.removeBody(mProxyId);
- mProxyId := monsGrid.insertBody(self, FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, FObj.Rect.Width, FObj.Rect.Height);
- {$ENDIF}
+ monsGrid.getBodyDims(mProxyId, x, y, w, h);
+ getMapBox(nx, ny, nw, nh);
+ if (w <> nw) or (h <> nh) then
+ begin
+ {$IF DEFINED(D2F_DEBUG_MONS_MOVE)}
+ e_WriteLog(Format('monster #%d:(%u): resized; mProxyid=%d; gx=%d; gy=%d', [mArrIdx, UID, mProxyId, x-monsGrid.gridX0, y-monsGrid.gridY0]), MSG_NOTIFY);
+ {$ENDIF}
+ monsGrid.moveResizeBody(mProxyId, nx, ny, nw, nh);
+ end
+ else if (x <> nx) or (y <> ny) then
+ begin
+ {$IF DEFINED(D2F_DEBUG_MONS_MOVE)}
+ e_WriteLog(Format('monster #%d:(%u): updating grid; mProxyid=%d; gx=%d; gy=%d', [mArrIdx, UID, mProxyId, x-monsGrid.gridX0, y-monsGrid.gridY0]), MSG_NOTIFY);
+ {$ENDIF}
+ monsGrid.moveBody(mProxyId, nx, ny);
+ end
+ else
+ begin
+ exit; // nothing to do
+ end;
{$IF DEFINED(D2F_DEBUG_MONS_MOVE)}
monsGrid.getBodyXY(mProxyId, x, y);
- e_WriteLog(Format('monster #%d(%u): updated tree; mProxyid=%d; x=%d; y=%d', [mArrIdx, UID, mProxyId, x, y]), MSG_NOTIFY);
+ e_WriteLog(Format('monster #%d:(%u): updated grid; mProxyid=%d; gx=%d; gy=%d', [mArrIdx, UID, mProxyId, x-monsGrid.gridX0, y-monsGrid.gridY0]), MSG_NOTIFY);
{$ENDIF}
end;
end;
@@ -440,8 +473,8 @@ const
LeftAnim: Boolean;
wX, wY: Integer; // Îòêóäà âûëåòèò ïóëÿ
AnimSpeed: Array [ANIM_SLEEP..ANIM_PAIN] of Byte;
- AnimDeltaRight: Array [ANIM_SLEEP..ANIM_PAIN] of TPoint;
- AnimDeltaLeft: Array [ANIM_SLEEP..ANIM_PAIN] of TPoint;
+ AnimDeltaRight: Array [ANIM_SLEEP..ANIM_PAIN] of TDFPoint;
+ AnimDeltaLeft: Array [ANIM_SLEEP..ANIM_PAIN] of TDFPoint;
end = // SLEEP GO DIE MESS ATTACK ATTACK2 PAIN
((LeftAnim: False; wX: 54; wY: 32; AnimSpeed:(3, 2, 3, 2, 3, 0, 4); //DEMON
AnimDeltaRight: ((X: 1; Y: 4), (X: 1; Y: 4), (X: 0; Y: 4), (X: 0; Y: 4), (X: 2; Y: 6), (X: 2; Y: 6), (X: 2; Y: 5));
@@ -527,9 +560,11 @@ const
MAX_SOUL = 512; // Îãðàíè÷åíèå Lost_Soul'îâ
+// ////////////////////////////////////////////////////////////////////////// //
var
gMonsters: array of TMonster;
uidMap: array [0..65535] of TMonster; // monster knows it's index
+ freeInds: TIdPool = nil;
procedure clearUidMap ();
@@ -537,15 +572,16 @@ var
idx: Integer;
begin
for idx := 0 to High(uidMap) do uidMap[idx] := nil;
+ freeInds.clear();
end;
-function g_Mons_getNewTrapFrameId (): DWord;
+function g_Mons_getNewTrapFrameId (): DWord; inline;
var
f: Integer;
begin
Inc(monCheckTrapLastFrameId);
- if monCheckTrapLastFrameId = 0 then
+ if (monCheckTrapLastFrameId = 0) then
begin
// wraparound
monCheckTrapLastFrameId := 1;
@@ -558,6 +594,24 @@ begin
end;
+function g_Mons_getNewMPlatFrameId (): LongWord; inline;
+var
+ f: Integer;
+begin
+ Inc(monCheckMPlatLastFrameId);
+ if (monCheckMPlatLastFrameId = 0) then
+ begin
+ // wraparound
+ monCheckMPlatLastFrameId := 1;
+ for f := 0 to High(gMonsters) do
+ begin
+ if (gMonsters[f] <> nil) then gMonsters[f].mplatCheckFrameId := 0;
+ end;
+ end;
+ result := monCheckMPlatLastFrameId;
+end;
+
+
var
pt_x: Integer = 0;
pt_xs: Integer = 1;
@@ -566,29 +620,16 @@ var
soulcount: Integer = 0;
-function allocMonster(): DWORD;
+function allocMonster (): DWORD;
var
- i, olen: Integer;
+ f, olen: Integer;
begin
- for i := 0 to High(gMonsters) do
- begin
- if (gMonsters[i] = nil) then
- begin
- result := i;
- exit;
- end;
- end;
-
- olen := Length(gMonsters);
- if (olen = 0) then
- begin
- SetLength(gMonsters, 64);
- result := 0;
- end
- else
+ result := freeInds.alloc();
+ if (result > High(gMonsters)) then
begin
- result := olen;
- SetLength(gMonsters, Length(gMonsters)+32);
+ olen := Length(gMonsters);
+ SetLength(gMonsters, result+64);
+ for f := olen to High(gMonsters) do gMonsters[f] := nil;
end;
end;
@@ -954,8 +995,10 @@ begin
g_Sound_CreateWADEx('SOUND_MONSTER_FISH_ATTACK', GameWAD+':MSOUNDS\FISH_ATTACK');
+ freeInds := TIdPool.Create();
clearUidMap();
monCheckTrapLastFrameId := 0;
+ monCheckMPlatLastFrameId := 0;
end;
procedure g_Monsters_FreeData();
@@ -1172,6 +1215,9 @@ begin
g_Sound_Delete('SOUND_MONSTER_SPIDER_WALK');
g_Sound_Delete('SOUND_MONSTER_FISH_ATTACK');
+
+ freeInds.Free();
+ freeInds := nil;
end;
procedure g_Monsters_Init();
@@ -1179,16 +1225,21 @@ begin
soulcount := 0;
end;
-procedure g_Monsters_Free();
+procedure g_Monsters_Free (clearGrid: Boolean=true);
var
a: Integer;
begin
- monsGrid.Free();
- monsGrid := nil;
+ e_LogWritefln('Cleared monster data (clearGrid=%s)', [clearGrid]);
+ if (clearGrid) then
+ begin
+ monsGrid.Free();
+ monsGrid := nil;
+ end;
for a := 0 to High(gMonsters) do gMonsters[a].Free();
gMonsters := nil;
clearUidMap();
monCheckTrapLastFrameId := 0;
+ monCheckMPlatLastFrameId := 0;
end;
@@ -1197,6 +1248,8 @@ procedure g_Mons_InitTree (x, y, w, h: Integer);
begin
monsGrid.Free();
monsGrid := TMonsterGrid.Create(x, y, w, h);
+ //clearUidMap(); // why not?
+ e_LogWritefln('%s', ['Recreated monster tree']);
end;
@@ -1259,11 +1312,14 @@ begin
if gMonsters = nil then
Exit;
-// Ïðèêîëèñò ñìååòñÿ íàä ñìåðòüþ èãðîêà:
+ // Ïðèêîëèñò ñìååòñÿ íàä ñìåðòüþ èãðîêà:
h := High(gMonsters);
for a := 0 to h do
+ begin
if (gMonsters[a] <> nil) then
+ begin
with gMonsters[a] do
+ begin
if (FMonsterType = MONSTER_MAN) and
(FState <> MONSTATE_DEAD) and
(FState <> MONSTATE_SLEEP) and
@@ -1272,6 +1328,9 @@ begin
g_Sound_PlayExAt('SOUND_MONSTER_TRUP', FObj.X, FObj.Y);
Exit;
end;
+ end;
+ end;
+ end;
end;
procedure g_Monsters_Update();
@@ -1318,9 +1377,12 @@ var
a: Integer;
begin
if gMonsters <> nil then
+ begin
for a := 0 to High(gMonsters) do
- if gMonsters[a] <> nil then
- gMonsters[a].Draw();
+ begin
+ if (gMonsters[a] <> nil) then gMonsters[a].Draw();
+ end;
+ end;
end;
procedure g_Monsters_DrawHealth();
@@ -1332,29 +1394,19 @@ begin
e_TextureFontGetSize(gStdFont, fW, fH);
for a := 0 to High(gMonsters) do
+ begin
if gMonsters[a] <> nil then
begin
e_TextureFontPrint(gMonsters[a].FObj.X + gMonsters[a].FObj.Rect.X,
gMonsters[a].FObj.Y + gMonsters[a].FObj.Rect.Y + gMonsters[a].FObj.Rect.Height - fH,
IntToStr(gMonsters[a].FHealth), gStdFont);
end;
+ end;
end;
function g_Monsters_ByUID (UID: Word): TMonster;
-//var a: Integer;
begin
result := uidMap[UID];
- {
- Result := nil;
- if gMonsters <> nil then
- for a := 0 to High(gMonsters) do
- if (gMonsters[a] <> nil) and
- (gMonsters[a].FUID = UID) then
- begin
- Result := gMonsters[a];
- Break;
- end;
- }
end;
procedure g_Monsters_SaveState(var Mem: TBinMemoryWriter);
@@ -1364,11 +1416,16 @@ var
begin
// Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ ìîíñòðîâ:
count := 0;
- if gMonsters <> nil then
+ if (gMonsters <> nil) then
+ begin
for i := 0 to High(gMonsters) do
- if gMonsters[i] <> nil then
- if gMonsters[i].FMonsterType <> MONSTER_NONE then
- count := count + 1;
+ begin
+ if (gMonsters[i] <> nil) then
+ begin
+ if (gMonsters[i].FMonsterType <> MONSTER_NONE) then count += 1;
+ end;
+ end;
+ end;
Mem := TBinMemoryWriter.Create((count+1) * 350);
@@ -1386,15 +1443,19 @@ begin
// Ñîõðàíÿåì ìîíñòðîâ:
for i := 0 to High(gMonsters) do
- if gMonsters[i] <> nil then
- if gMonsters[i].FMonsterType <> MONSTER_NONE then
+ begin
+ if (gMonsters[i] <> nil) then
+ begin
+ if (gMonsters[i].FMonsterType <> MONSTER_NONE) then
begin
- // Òèï ìîíñòðà:
+ // Òèï ìîíñòðà:
b := gMonsters[i].MonsterType;
Mem.WriteByte(b);
- // Ñîõðàíÿåì äàííûå ìîíñòðà:
+ // Ñîõðàíÿåì äàííûå ìîíñòðà:
gMonsters[i].SaveState(Mem);
end;
+ end;
+ end;
end;
procedure g_Monsters_LoadState(var Mem: TBinMemoryReader);
@@ -1405,7 +1466,7 @@ var
begin
if Mem = nil then exit;
- g_Monsters_Free();
+ g_Monsters_Free(false);
// Çàãðóæàåì èíôîðìàöèþ öåëåóêàçàòåëÿ
Mem.ReadInt(pt_x);
@@ -1431,43 +1492,87 @@ begin
end;
end;
-function g_Monsters_GetIDByName(name: String): Integer;
+
+// ////////////////////////////////////////////////////////////////////////// //
+function g_Mons_SpawnAt (monType: Integer; x, y: Integer; dir: TDirection=D_LEFT): TMonster; overload;
+begin
+ result := nil;
+ if (monType >= MONSTER_DEMON) and (monType <= MONSTER_MAN) then
+ begin
+ result := g_Monsters_Create(monType, x, y, dir);
+ end;
+end;
+
+
+function g_Mons_SpawnAt (const typeName: AnsiString; x, y: Integer; dir: TDirection=D_LEFT): TMonster; overload;
+begin
+ result := g_Mons_SpawnAt(g_Mons_TypeIdByName(typeName), x, y, dir);
+end;
+
+
+
+// ////////////////////////////////////////////////////////////////////////// //
+function g_Mons_TypeLo (): Integer; inline; begin result := Low(MONSTERTABLE); end;
+function g_Mons_TypeHi (): Integer; inline; begin result := High(MONSTERTABLE); end;
+
+
+function g_Mons_TypeIdByName (const name: String): Integer;
var
i: Integer;
begin
- name := UpperCase(name);
i := MONSTER_DEMON;
while (i <= MONSTER_MAN) do
begin
- if name = MONSTERTABLE[i].Name then
+ if (CompareText(name, MONSTERTABLE[i].Name) = 0) then
begin
- Result := i;
- Exit;
+ result := i;
+ exit;
end;
Inc(i);
end;
-
- Result := -1;
+ result := -1;
+ // HACK!
+ if (CompareText(name, 'zombie') = 0) then result := MONSTER_ZOMBY;
end;
-function g_Monsters_GetNameByID(MonsterType: Byte): String;
+
+function g_Mons_NameByTypeId (monType: Integer): AnsiString;
begin
- if MonsterType in [MONSTER_DEMON..MONSTER_MAN] then
- Result := MONSTERTABLE[MonsterType].Name
+ if (monType >= MONSTER_DEMON) and (monType <= MONSTER_MAN) then
+ result := MONSTERTABLE[monType].Name
else
- Result := '?';
+ result := '?';
end;
-function g_Monsters_GetKilledBy(MonsterType: Byte): String;
+
+function g_Mons_GetKilledByTypeId (monType: Integer): AnsiString;
begin
- if MonsterType in [MONSTER_DEMON..MONSTER_MAN] then
- Result := KilledByMonster[MonsterType]
+ if (monType >= MONSTER_DEMON) and (monType <= MONSTER_MAN) then
+ Result := KilledByMonster[monType]
else
Result := '?';
end;
+
+// ////////////////////////////////////////////////////////////////////////// //
{ T M o n s t e r : }
+procedure TMonster.setGameX (v: Integer); inline; begin FObj.X := v; positionChanged(); end;
+procedure TMonster.setGameY (v: Integer); inline; begin FObj.Y := v; positionChanged(); end;
+
+procedure TMonster.setPosition (ax, ay: Integer; callPosChanged: Boolean=true); inline; begin FObj.X := ax; FObj.Y := ay; if callPosChanged then positionChanged(); end;
+
+procedure TMonster.moveBy (dx, dy: Integer); inline;
+begin
+ if (dx <> 0) or (dy <> 0) then
+ begin
+ FObj.X += dx;
+ FObj.Y += dy;
+ positionChanged();
+ end;
+end;
+
+
procedure TMonster.ActionSound();
begin
case FMonsterType of
@@ -1656,8 +1761,8 @@ begin
FObj.Accel.X := 0;
FObj.Accel.Y := 0;
FDirection := FStartDirection;
- GameX := FStartX;
- GameY := FStartY;
+ {GameX}FObj.X := FStartX;
+ {GameY}FObj.Y := FStartY;
FObj.Rect := MONSTERTABLE[FMonsterType].Rect;
FHealth := MONSTERTABLE[FMonsterType].Health;
FAmmo := 0;
@@ -1717,6 +1822,7 @@ begin
mProxyId := -1;
mArrIdx := -1;
trapCheckFrameId := 0;
+ mplatCheckFrameId := 0;
if FMonsterType in [MONSTER_ROBO, MONSTER_BARREL] then
FBloodKind := BLOOD_SPARKS
@@ -1929,6 +2035,7 @@ begin
begin
FObj.Rect.Y := FObj.Rect.Y + FObj.Rect.Height-12;
FObj.Rect.Height := 12;
+ positionChanged();
end;
// Óðîí áûë ñèëüíûì => ñëàáûå - â êàøó:
@@ -1967,7 +2074,7 @@ begin
Result := False;
if g_Game_IsClient then
Exit;
- if not Live then
+ if not alive then
Exit;
if FHealth < FMaxHealth then
@@ -1996,13 +2103,17 @@ begin
begin
monsGrid.removeBody(mProxyId);
{$IF DEFINED(D2F_DEBUG_MONS_MOVE)}
- e_WriteLog(Format('monster #%d(%u): removed from tree; mProxyid=%d', [mArrIdx, UID, mProxyId]), MSG_NOTIFY);
+ e_WriteLog(Format('monster #%d:(%u): removed from grid; mProxyid=%d', [mArrIdx, UID, mProxyId]), MSG_NOTIFY);
{$ENDIF}
end;
mProxyId := -1;
end;
- if (mArrIdx <> -1) and (mArrIdx < Length(gMonsters)) then gMonsters[mArrIdx] := nil;
+ if (mArrIdx <> -1) and (mArrIdx < Length(gMonsters)) then
+ begin
+ freeInds.release(mArrIdx);
+ gMonsters[mArrIdx] := nil;
+ end;
mArrIdx := -1;
uidMap[FUID] := nil;
@@ -2027,9 +2138,12 @@ begin
o.Y+o.Rect.Y+o.Rect.Height-128, M_NONE);
// Íå â îáëàñòè ðèñîâàíèÿ íå ðåñóåì:
- if not g_Collide(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, FObj.Rect.Width, FObj.Rect.Height,
- sX-128, sY-128, sWidth+256, sHeight+256) then
- Exit;
+ if (g_dbg_scale = 1.0) then
+ begin
+ if not g_Collide(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, FObj.Rect.Width, FObj.Rect.Height,
+ sX-128, sY-128, sWidth+256, sHeight+256) then
+ Exit;
+ end;
// Ýòè ìîíñòðû, óìèðàÿ, íå îñòàâëÿþò òðóïîâ:
if FState = MONSTATE_DEAD then
@@ -2287,7 +2401,7 @@ begin
(FObj.X > gMapInfo.Width+1000) or (FObj.Y < -1000) then
begin
FRemoved := True;
- if Live and (gLMSRespawn = LMS_RESPAWN_NONE) then
+ if alive and (gLMSRespawn = LMS_RESPAWN_NONE) then
begin
Inc(gCoopMonstersKilled);
if g_Game_IsNet then
@@ -2450,7 +2564,7 @@ begin
// Åñëè åñòü èãðîê ðÿäîì, ïðîñûïàåìñÿ è èäåì ê íåìó:
if (gPlayers <> nil) then
for a := 0 to High(gPlayers) do
- if (gPlayers[a] <> nil) and (gPlayers[a].Live)
+ if (gPlayers[a] <> nil) and (gPlayers[a].alive)
and (not gPlayers[a].NoTarget) and (gPlayers[a].FMegaRulez[MR_INVIS] < gTime) then
with gPlayers[a] do
if g_Look(@FObj, @Obj, FDirection) then
@@ -2468,7 +2582,7 @@ begin
// Åñëè åñòü ïîäõîäÿùèé ìîíñòð ðÿäîì:
if gMonsters <> nil then
for a := 0 to High(gMonsters) do
- if (gMonsters[a] <> nil) and (gMonsters[a].Live) and
+ if (gMonsters[a] <> nil) and (gMonsters[a].alive) and
(gMonsters[a].FUID <> FUID) then
begin
// Ìàíüÿêè íàïàäàþò íà âñåõ ìîíñòðîâ, êðîìå äðóçåé
@@ -2670,7 +2784,7 @@ begin
if b > 1 then b := b * (Random(8 div b) + 1);
for a := 0 to High(gGibs) do
begin
- if gGibs[a].Live and
+ if gGibs[a].alive and
g_Obj_Collide(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y+FObj.Rect.Height-4,
FObj.Rect.Width, 8, @gGibs[a].Obj) and (Random(3) = 0) then
begin
@@ -3502,7 +3616,7 @@ begin
if b > 1 then b := b * (Random(8 div b) + 1);
for a := 0 to High(gGibs) do
begin
- if gGibs[a].Live and
+ if gGibs[a].alive and
g_Obj_Collide(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y+FObj.Rect.Height-4,
FObj.Rect.Width, 8, @gGibs[a].Obj) and (Random(3) = 0) then
begin
@@ -3954,7 +4068,7 @@ begin
if (gPlayers <> nil) and (FBehaviour <> BH_INSANE) and
(FBehaviour <> BH_CANNIBAL) and (FBehaviour <> BH_GOOD) then
for a := 0 to High(gPlayers) do
- if (gPlayers[a] <> nil) and (gPlayers[a].Live)
+ if (gPlayers[a] <> nil) and (gPlayers[a].alive)
and (not gPlayers[a].NoTarget) and (gPlayers[a].FMegaRulez[MR_INVIS] < gTime) then
begin
if g_Look(@FObj, @gPlayers[a].Obj, FDirection) then
@@ -3974,7 +4088,7 @@ begin
// Êèëëåðû è äîáðûå íå òðîãàþò ìîíñòðîâ
if (gMonsters <> nil) and (FBehaviour <> BH_KILLER) and (FBehaviour <> BH_GOOD) then
for a := 0 to High(gMonsters) do
- if (gMonsters[a] <> nil) and (gMonsters[a].Live) and
+ if (gMonsters[a] <> nil) and (gMonsters[a].alive) and
(gMonsters[a].FUID <> FUID) then
begin
if (FBehaviour = BH_CANNIBAL) and (gMonsters[a].FMonsterType <> FMonsterType) then
@@ -4227,7 +4341,7 @@ begin
Result := True;
end;
-function TMonster.Live(): Boolean;
+function TMonster.alive(): Boolean;
begin
Result := (FState <> MONSTATE_DIE) and (FState <> MONSTATE_DEAD) and (FHealth > 0);
end;
@@ -4332,6 +4446,7 @@ begin
end;
end;
+
procedure TMonster.LoadState(var Mem: TBinMemoryReader);
var
i: Integer;
@@ -4348,8 +4463,13 @@ begin
begin
raise EBinSizeError.Create('TMonster.LoadState: Wrong Monster Signature');
end;
+ if (uidMap[FUID] <> nil) and (uidMap[FUID] <> self) then raise Exception.Create('internal error in monster loader (0)');
+ uidMap[FUID] := nil;
// UID ìîíñòðà:
Mem.ReadWord(FUID);
+ //if (arrIdx = -1) then raise Exception.Create('internal error in monster loader');
+ if (uidMap[FUID] <> nil) then raise Exception.Create('internal error in monster loader (1)');
+ uidMap[FUID] := self;
// Íàïðàâëåíèå:
Mem.ReadByte(b);
if b = 1 then
@@ -4529,7 +4649,7 @@ begin
for idx := 0 to High(gMonsters) do
begin
mon := gMonsters[idx];
- if (mon <> nil) and mon.Live then
+ if (mon <> nil) and mon.alive then
begin
result := cb(mon);
if result then exit;
@@ -4542,7 +4662,7 @@ function g_Mons_IsAnyAliveAt (x, y: Integer; width, height: Integer): Boolean;
function monsCollCheck (mon: TMonster; atag: Integer): Boolean;
begin
- result := mon.Live;// and g_Obj_Collide(x, y, width, height, @mon.Obj));
+ result := mon.alive;// and g_Obj_Collide(x, y, width, height, @mon.Obj));
end;
var
@@ -4560,7 +4680,7 @@ begin
for idx := 0 to High(gMonsters) do
begin
mon := gMonsters[idx];
- if (mon <> nil) and mon.Live then
+ if (mon <> nil) and mon.alive then
begin
if g_Obj_Collide(x, y, width, height, @mon.Obj) then
begin
@@ -4595,7 +4715,7 @@ begin
for idx := 0 to High(gMonsters) do
begin
mon := gMonsters[idx];
- if (mon <> nil) and mon.Live then
+ if (mon <> nil) and mon.alive then
begin
if g_Obj_Collide(x, y, width, height, @mon.Obj) then
begin
@@ -4613,8 +4733,8 @@ 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);
- if mon.Live then result := cb(mon) else result := false;
+ //if mon.alive and g_Obj_Collide(x, y, width, height, @mon.Obj) then result := cb(mon);
+ if mon.alive then result := cb(mon) else result := false;
end;
var
@@ -4639,7 +4759,7 @@ begin
for idx := 0 to High(gMonsters) do
begin
mon := gMonsters[idx];
- if (mon <> nil) and mon.Live then
+ if (mon <> nil) and mon.alive then
begin
if g_Obj_Collide(x, y, width, height, @mon.Obj) then
begin