X-Git-Url: http://deadsoftware.ru/gitweb?a=blobdiff_plain;ds=inline;f=src%2Fgame%2Fg_monsters.pas;h=2b70da642e49892257507eadf3da63de2a0d32db;hb=b4a2614636a9cc12ce9766ec1e2bf04cd5bec0ea;hp=a52ddf1738be26e9b78ebd1e22cbd34ba76cbc55;hpb=b79ddd98d923ee15f4bfd1db5111e669fc19964a;p=d2df-sdl.git
diff --git a/src/game/g_monsters.pas b/src/game/g_monsters.pas
index a52ddf1..2b70da6 100644
--- a/src/game/g_monsters.pas
+++ b/src/game/g_monsters.pas
@@ -14,12 +14,13 @@
* along with this program. If not, see .
*)
{$INCLUDE ../shared/a_modes.inc}
+{.$DEFINE D2F_DEBUG_MONS_MOVE}
unit g_monsters;
interface
uses
- g_basic, e_graphics, g_phys, g_textures,
+ g_basic, e_graphics, g_phys, g_textures, g_grid,
g_saveload, BinEditor, g_panel, xprofiler;
const
@@ -79,9 +80,8 @@ type
FFirePainTime: Integer;
FFireAttacker: Word;
vilefire: TAnimation;
-
- proxyId: Integer; // node in dyntree or -1
- arrIdx: Integer; // in gMonsters
+ mProxyId: Integer; // node in dyntree or -1
+ mArrIdx: Integer; // in gMonsters
FDieTriggers: Array of Integer;
FSpawnTrigger: Integer;
@@ -161,6 +161,9 @@ type
property GameDirection: TDirection read FDirection write FDirection;
property StartID: Integer read FStartID;
+
+ property proxyId: Integer read mProxyId;
+ property arrIdx: Integer read mArrIdx;
end;
@@ -170,7 +173,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 ();
@@ -194,6 +197,8 @@ function g_Mons_ByIdx (uid: Integer): TMonster; inline;
// can return null
function g_Mons_ByIdx_NC (uid: Integer): TMonster; inline;
+function g_Mons_TotalCount (): Integer; inline;
+
function g_Mons_IsAnyAliveAt (x, y: Integer; width, height: Integer): Boolean;
function g_Mons_ForEach (cb: TEachMonsterCB): Boolean;
@@ -226,13 +231,25 @@ var
profMonsLOS: TProfiler = nil; //WARNING: FOR DEBUGGING ONLY!
+type
+ TMonsterGrid = specialize TBodyGridBase;
+
+var
+ monsGrid: TMonsterGrid = nil; // DO NOT USE! public for debugging only!
+
+
+var
+ gmon_debug_think: Boolean = true;
+ gmon_debug_one_think_step: Boolean = false;
+
+
implementation
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_grid;
+ g_language, g_netmsg, idpool;
// ////////////////////////////////////////////////////////////////////////// //
@@ -278,13 +295,6 @@ end;
// ////////////////////////////////////////////////////////////////////////// //
-type
- TMonsterGrid = specialize TBodyGridBase;
-
-var
- monsGrid: TMonsterGrid = nil;
-
-
function g_Mons_AlongLine (x0, y0, x1, y1: Integer; cb: TMonsAlongLineCB; log: Boolean=false): TMonster;
begin
if not assigned(cb) then begin result := nil; exit; end;
@@ -295,35 +305,46 @@ 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)', [arrIdx, UID, FObj.X, FObj.Y, FObj.Rect.X, FObj.Rect.Y]), MSG_NOTIFY);
+ //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);
{$ENDIF}
- if (proxyId = -1) then
+ if (mProxyId = -1) then
begin
- proxyId := monsGrid.insertBody(self, FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, FObj.Rect.Width, FObj.Rect.Height);
+ 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(proxyId, x, y);
- e_WriteLog(Format('monster #%d(%u): inserted into the grid; proxyid=%d; x=%d; y=%d', [arrIdx, UID, proxyId, x, y]), MSG_NOTIFY);
+ monsGrid.getBodyXY(mProxyId, x, y);
+ 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(proxyId, 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; proxyid=%d; x=%d; y=%d', [arrIdx, UID, proxyId, x, y]), MSG_NOTIFY);{$ENDIF}
-
- {$IF TRUE}
- monsGrid.moveBody(proxyId, FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y);
- {$ELSE}
- monsGrid.removeBody(proxyId);
- proxyId := 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(proxyId, x, y);
- e_WriteLog(Format('monster #%d(%u): updated tree; proxyid=%d; x=%d; y=%d', [arrIdx, UID, proxyId, x, y]), MSG_NOTIFY);
+ monsGrid.getBodyXY(mProxyId, x, y);
+ 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;
@@ -339,19 +360,6 @@ const
ANIM_ATTACK2 = 5;
ANIM_PAIN = 6;
- STATE_SLEEP = 0;
- STATE_GO = 1;
- STATE_RUN = 2;
- STATE_CLIMB = 3;
- STATE_DIE = 4;
- STATE_DEAD = 5;
- STATE_ATTACK = 6;
- STATE_SHOOT = 7;
- STATE_PAIN = 8;
- STATE_WAIT = 9;
- STATE_REVIVE = 10;
- STATE_RUNOUT = 11;
-
MONSTER_SIGNATURE = $534E4F4D; // 'MONS'
// Òàáëèöà òèïîâ àíèìàöèè ìîíñòðîâ:
@@ -534,6 +542,7 @@ const
var
gMonsters: array of TMonster;
uidMap: array [0..65535] of TMonster; // monster knows it's index
+ freeInds: TIdPool = nil;
procedure clearUidMap ();
@@ -541,6 +550,7 @@ var
idx: Integer;
begin
for idx := 0 to High(uidMap) do uidMap[idx] := nil;
+ freeInds.clear();
end;
@@ -570,29 +580,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;
@@ -674,7 +671,7 @@ function isCorpse (o: PObj; immediately: Boolean): Integer;
begin
atag := atag; // shut up, fpc!
result := false; // don't stop
- if (mon.FState = STATE_DEAD) and g_Obj_Collide(o, @mon.FObj) then
+ if (mon.FState = MONSTATE_DEAD) and g_Obj_Collide(o, @mon.FObj) then
begin
case mon.FMonsterType of // Íå âîñêðåñèòü:
MONSTER_SOUL, MONSTER_PAIN, MONSTER_CYBER, MONSTER_SPIDER,
@@ -698,13 +695,13 @@ begin
if gmon_debug_use_sqaccel then
begin
mon := monsGrid.forEachInAABB(o.X+o.Rect.X, o.Y+o.Rect.Y, o.Rect.Width, o.Rect.Height, monsCollCheck);
- if (mon <> nil) then result := mon.arrIdx;
+ if (mon <> nil) then result := mon.mArrIdx;
end
else
begin
for a := 0 to High(gMonsters) do
begin
- if (gMonsters[a] <> nil) and (gMonsters[a].FState = STATE_DEAD) and g_Obj_Collide(o, @gMonsters[a].FObj) then
+ if (gMonsters[a] <> nil) and (gMonsters[a].FState = MONSTATE_DEAD) and g_Obj_Collide(o, @gMonsters[a].FObj) then
begin
case gMonsters[a].FMonsterType of // Íå âîñêðåñèòü:
MONSTER_SOUL, MONSTER_PAIN, MONSTER_CYBER, MONSTER_SPIDER,
@@ -958,6 +955,7 @@ begin
g_Sound_CreateWADEx('SOUND_MONSTER_FISH_ATTACK', GameWAD+':MSOUNDS\FISH_ATTACK');
+ freeInds := TIdPool.Create();
clearUidMap();
monCheckTrapLastFrameId := 0;
end;
@@ -1176,6 +1174,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();
@@ -1183,12 +1184,16 @@ 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();
@@ -1201,6 +1206,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;
@@ -1226,8 +1233,8 @@ begin
mon := TMonster.Create(MonsterType, find_id, ForcedUID);
gMonsters[find_id] := mon;
- mon.arrIdx := find_id;
- mon.proxyId := -1;
+ mon.mArrIdx := find_id;
+ mon.mProxyId := -1;
uidMap[mon.FUID] := mon;
@@ -1263,19 +1270,25 @@ 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 <> STATE_DEAD) and
- (FState <> STATE_SLEEP) and
- (FState <> STATE_DIE) then
+ (FState <> MONSTATE_DEAD) and
+ (FState <> MONSTATE_SLEEP) and
+ (FState <> MONSTATE_DIE) then
begin
g_Sound_PlayExAt('SOUND_MONSTER_TRUP', FObj.X, FObj.Y);
Exit;
end;
+ end;
+ end;
+ end;
end;
procedure g_Monsters_Update();
@@ -1293,20 +1306,24 @@ begin
gMon := True; // Äëÿ ðàáîòû BlockMon'à
- for a := 0 to High(gMonsters) do
+ if gmon_debug_think or gmon_debug_one_think_step then
begin
- if (gMonsters[a] = nil) then continue;
- if not gMonsters[a].FRemoved then
+ gmon_debug_one_think_step := false;
+ for a := 0 to High(gMonsters) do
begin
- if g_Game_IsClient then
- gMonsters[a].ClientUpdate()
+ if (gMonsters[a] = nil) then continue;
+ if not gMonsters[a].FRemoved then
+ begin
+ if g_Game_IsClient then
+ gMonsters[a].ClientUpdate()
+ else
+ gMonsters[a].Update();
+ end
else
- gMonsters[a].Update();
- end
- else
- begin
- gMonsters[a].Free();
- gMonsters[a] := nil;
+ begin
+ gMonsters[a].Free();
+ gMonsters[a] := nil;
+ end;
end;
end;
@@ -1318,9 +1335,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 +1352,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 +1374,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 +1401,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 +1424,7 @@ var
begin
if Mem = nil then exit;
- g_Monsters_Free();
+ g_Monsters_Free(false);
// Çàãðóæàåì èíôîðìàöèþ öåëåóêàçàòåëÿ
Mem.ReadInt(pt_x);
@@ -1669,7 +1688,7 @@ begin
FChainFire := False;
FShellTimer := -1;
- FState := STATE_SLEEP;
+ FState := MONSTATE_SLEEP;
FCurAnim := ANIM_SLEEP;
positionChanged(); // this updates spatial accelerators
@@ -1697,7 +1716,7 @@ begin
g_Obj_Init(@FObj);
- FState := STATE_SLEEP;
+ FState := MONSTATE_SLEEP;
FCurAnim := ANIM_SLEEP;
FHealth := MONSTERTABLE[MonsterType].Health;
FMaxHealth := FHealth;
@@ -1714,8 +1733,8 @@ begin
FFirePainTime := 0;
FFireAttacker := 0;
- proxyId := -1;
- arrIdx := -1;
+ mProxyId := -1;
+ mArrIdx := -1;
trapCheckFrameId := 0;
if FMonsterType in [MONSTER_ROBO, MONSTER_BARREL] then
@@ -1813,7 +1832,7 @@ begin
Result := False;
// Óìèðàåò, óìåð èëè âîñêðåøàåòñÿ => óðîí äåëàòü íåêîìó:
- if (FState = STATE_DEAD) or (FState = STATE_DIE) or (FState = STATE_REVIVE) then
+ if (FState = MONSTATE_DEAD) or (FState = MONSTATE_DIE) or (FState = MONSTATE_REVIVE) then
Exit;
// Ðûáó â âîäå áüåò òîêîì => ïàíèêà áåç óðîíà:
@@ -1825,7 +1844,7 @@ begin
else
FDirection := D_LEFT;
Result := True;
- SetState(STATE_RUN);
+ SetState(MONSTATE_RUN);
Exit;
end;
@@ -1846,10 +1865,10 @@ begin
FPain := FPain+aDamage;
// Åñëè áîëü ñóùåñòâåííàÿ, òî ìåíÿåì ñîñòîÿíèå íà áîëåâîå:
- if FState <> STATE_PAIN then
+ if FState <> MONSTATE_PAIN then
if (FPain >= MONSTERTABLE[FMonsterType].MinPain) and
(FMonsterType <> MONSTER_BARREL) then
- SetState(STATE_PAIN);
+ SetState(MONSTATE_PAIN);
// Åñëè ðàçðåøåíà êðîâü - ñîçäàåì áðûçãè êðîâè:
if (gBloodCount > 0) then
@@ -1929,6 +1948,7 @@ begin
begin
FObj.Rect.Y := FObj.Rect.Y + FObj.Rect.Height-12;
FObj.Rect.Height := 12;
+ positionChanged();
end;
// Óðîí áûë ñèëüíûì => ñëàáûå - â êàøó:
@@ -1938,12 +1958,12 @@ begin
(FMonsterType = MONSTER_MAN)) then
begin
g_Sound_PlayExAt('SOUND_MONSTER_SLOP', FObj.X, FObj.Y);
- SetState(STATE_DIE, ANIM_MESS);
+ SetState(MONSTATE_DIE, ANIM_MESS);
end
else
begin
DieSound();
- SetState(STATE_DIE);
+ SetState(MONSTATE_DIE);
end;
// Àêòèâèðîâàòü òðèããåðû, æäóùèå ñìåðòè ýòîãî ìîíñòðà:
@@ -1952,10 +1972,10 @@ begin
FHealth := 0;
end
else
- if FState = STATE_SLEEP then
+ if FState = MONSTATE_SLEEP then
begin // Ñïàë, ðàçáóäèëè íåñìåðòåëüíûì óäàðîì:
FPain := MONSTERTABLE[FMonsterType].Pain;
- SetState(STATE_GO);
+ SetState(MONSTATE_GO);
end;
if g_Game_IsServer and g_Game_IsNet then MH_SEND_MonsterState(FUID);
@@ -1990,20 +2010,24 @@ begin
vilefire.Free();
- if (proxyId <> -1) then
+ if (mProxyId <> -1) then
begin
if (monsGrid <> nil) then
begin
- monsGrid.removeBody(proxyId);
+ monsGrid.removeBody(mProxyId);
{$IF DEFINED(D2F_DEBUG_MONS_MOVE)}
- e_WriteLog(Format('monster #%d(%u): removed from tree; proxyid=%d', [arrIdx, UID, proxyId]), MSG_NOTIFY);
+ e_WriteLog(Format('monster #%d:(%u): removed from grid; mProxyid=%d', [mArrIdx, UID, mProxyId]), MSG_NOTIFY);
{$ENDIF}
end;
- proxyId := -1;
+ mProxyId := -1;
end;
- if (arrIdx <> -1) and (arrIdx < Length(gMonsters)) then gMonsters[arrIdx] := nil;
- arrIdx := -1;
+ if (mArrIdx <> -1) and (mArrIdx < Length(gMonsters)) then
+ begin
+ freeInds.release(mArrIdx);
+ gMonsters[mArrIdx] := nil;
+ end;
+ mArrIdx := -1;
uidMap[FUID] := nil;
@@ -2021,7 +2045,7 @@ begin
// Åñëè êîëäóí ñòðåëÿåò, òî ðèñóåì îãîíü:
if FMonsterType = MONSTER_VILE then
- if FState = STATE_SHOOT then
+ if FState = MONSTATE_SHOOT then
if GetPos(FTargetUID, @o) then
vilefire.Draw(o.X+o.Rect.X+(o.Rect.Width div 2)-32,
o.Y+o.Rect.Y+o.Rect.Height-128, M_NONE);
@@ -2032,7 +2056,7 @@ begin
Exit;
// Ýòè ìîíñòðû, óìèðàÿ, íå îñòàâëÿþò òðóïîâ:
- if FState = STATE_DEAD then
+ if FState = MONSTATE_DEAD then
case FMonsterType of
MONSTER_BARREL, MONSTER_SOUL, MONSTER_PAIN: Exit;
end;
@@ -2120,14 +2144,14 @@ var
begin
// Åñëè ñîñòîÿíèå = íà÷àëè óìèðàòü, à ýòîò ìîíñòð = Lost_Soul,
// òî ñîáëþäàåì îãðàíè÷åíèå êîëè÷åñòâà Lost_Soul'îâ:
- if (State = STATE_DIE) and (MonsterType = MONSTER_SOUL) then
+ if (State = MONSTATE_DIE) and (MonsterType = MONSTER_SOUL) then
soulcount := soulcount-1;
// Ïðèñìåðòè - íåëüçÿ ñðàçó íà÷èíàòü àòàêîâàòü èëè áåãàòü:
case FState of
- STATE_DIE, STATE_DEAD, STATE_REVIVE:
- if (State <> STATE_DEAD) and (State <> STATE_REVIVE) and
- (State <> STATE_GO) then
+ MONSTATE_DIE, MONSTATE_DEAD, MONSTATE_REVIVE:
+ if (State <> MONSTATE_DEAD) and (State <> MONSTATE_REVIVE) and
+ (State <> MONSTATE_GO) then
Exit;
end;
@@ -2138,14 +2162,14 @@ begin
// Íîâàÿ àíèìàöèÿ ïðè íîâîì ñîñòîÿíèè:
case FState of
- STATE_SLEEP: Anim := ANIM_SLEEP;
- STATE_PAIN: Anim := ANIM_PAIN;
- STATE_WAIT: Anim := ANIM_SLEEP;
- STATE_CLIMB, STATE_RUN, STATE_RUNOUT, STATE_GO: Anim := ANIM_GO;
- STATE_SHOOT: Anim := ANIM_ATTACK;
- STATE_ATTACK: Anim := ANIM_ATTACK;
- STATE_DIE: Anim := ANIM_DIE;
- STATE_REVIVE:
+ MONSTATE_SLEEP: Anim := ANIM_SLEEP;
+ MONSTATE_PAIN: Anim := ANIM_PAIN;
+ MONSTATE_WAIT: Anim := ANIM_SLEEP;
+ MONSTATE_CLIMB, MONSTATE_RUN, MONSTATE_RUNOUT, MONSTATE_GO: Anim := ANIM_GO;
+ MONSTATE_SHOOT: Anim := ANIM_ATTACK;
+ MONSTATE_ATTACK: Anim := ANIM_ATTACK;
+ MONSTATE_DIE: Anim := ANIM_DIE;
+ MONSTATE_REVIVE:
begin // íà÷àëè âîñðåøàòüñÿ
Anim := FCurAnim;
FAnim[Anim, FDirection].Revert(True);
@@ -2254,15 +2278,15 @@ begin
// Ðûáû "ëåòàþò" òîëüêî â âîäå:
if FMonsterType = MONSTER_FISH then
if g_Obj_CollidePanel(@FObj, 0, 0, PANEL_WATER or PANEL_ACID1 or PANEL_ACID2) then
- if (FState <> STATE_DIE) and (FState <> STATE_DEAD) then
+ if (FState <> MONSTATE_DIE) and (FState <> MONSTATE_DEAD) then
fall := False;
// Ëåòàþùèå ìîíòñðû:
if ((FMonsterType = MONSTER_SOUL) or
(FMonsterType = MONSTER_PAIN) or
(FMonsterType = MONSTER_CACO)) and
- (FState <> STATE_DIE) and
- (FState <> STATE_DEAD) then
+ (FState <> MONSTATE_DIE) and
+ (FState <> MONSTATE_DEAD) then
fall := False;
// Ìåíÿåì ñêîðîñòü òîëüêî ïî ÷åòíûì êàäðàì:
@@ -2300,7 +2324,7 @@ begin
oldvelx := FObj.Vel.X;
// Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
- if (FState = STATE_DIE) or (FState = STATE_DEAD) then
+ if (FState = MONSTATE_DIE) or (FState = MONSTATE_DEAD) then
FObj.Vel.X := z_dec(FObj.Vel.X, 1);
if FFireTime > 0 then
@@ -2311,7 +2335,7 @@ begin
begin
OnFireFlame(1);
FFireTime := FFireTime - 1;
- if (FState <> STATE_DIE) and (FState <> STATE_DEAD) then
+ if (FState <> MONSTATE_DIE) and (FState <> MONSTATE_DEAD) then
if FFirePainTime = 0 then
begin
Damage(5, FFireAttacker, 0, 0, HIT_FLAME);
@@ -2323,15 +2347,15 @@ begin
end;
// Ìåðòâûé íè÷åãî íå äåëàåò:
- if (FState = STATE_DEAD) then
+ if (FState = MONSTATE_DEAD) then
goto _end;
// AI ìîíñòðîâ âûêëþ÷åí:
if g_debug_MonsterOff then
begin
FSleep := 1;
- if FState <> STATE_SLEEP then
- SetState(STATE_SLEEP);
+ if FState <> MONSTATE_SLEEP then
+ SetState(MONSTATE_SLEEP);
end;
// Âîçìîæíî, ñîçäàåì ïóçûðüêè â âîäå:
@@ -2357,7 +2381,7 @@ begin
// Åñëè ïðîøåë ïåðâûé êàäð àíèìàöèè âçðûâà áî÷êè, òî âçðûâ:
if FMonsterType = MONSTER_BARREL then
begin
- if (FState = STATE_DIE) and (FAnim[FCurAnim, FDirection].CurrentFrame = 1) and
+ if (FState = MONSTATE_DIE) and (FAnim[FCurAnim, FDirection].CurrentFrame = 1) and
(FAnim[FCurAnim, FDirection].Counter = 0) then
g_Weapon_Explode(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
FObj.Y+FObj.Rect.Y+FObj.Rect.Height-16,
@@ -2402,8 +2426,8 @@ begin
// Ïðîáóåì óâåðíóòüñÿ îò ëåòÿùåé ïóëè:
if fall then
- if (FState in [STATE_GO, STATE_RUN, STATE_RUNOUT,
- STATE_ATTACK, STATE_SHOOT]) then
+ if (FState in [MONSTATE_GO, MONSTATE_RUN, MONSTATE_RUNOUT,
+ MONSTATE_ATTACK, MONSTATE_SHOOT]) then
if g_Weapon_Danger(FUID, FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y,
FObj.Rect.Width, FObj.Rect.Height, 50) then
if (g_Obj_CollideLevel(@FObj, 0, 1) or g_Obj_StayOnStep(@FObj)) and
@@ -2411,7 +2435,7 @@ begin
FObj.Vel.Y := -MONSTERTABLE[FMonsterType].Jump;
case FState of
- STATE_PAIN: // Ñîñòîÿíèå - Áîëü
+ MONSTATE_PAIN: // Ñîñòîÿíèå - Áîëü
begin
// Áîëü ñèëüíàÿ => ìîíñòð êðè÷èò:
if FPain >= MONSTERTABLE[FMonsterType].Pain then
@@ -2430,11 +2454,11 @@ begin
begin
FPain := 0;
FAmmo := -9;
- SetState(STATE_GO);
+ SetState(MONSTATE_GO);
end;
end;
- STATE_SLEEP: // Ñîñòîÿíèå - Ñîí
+ MONSTATE_SLEEP: // Ñîñòîÿíèå - Ñîí
begin
// Ñïèì:
FSleep := FSleep + 1;
@@ -2458,7 +2482,7 @@ begin
FTargetUID := gPlayers[a].UID;
FTargetTime := 0;
WakeUpSound();
- SetState(STATE_GO);
+ SetState(MONSTATE_GO);
Break;
end;
@@ -2487,30 +2511,30 @@ begin
FTargetUID := gMonsters[a].UID;
FTargetTime := 0;
WakeUpSound();
- SetState(STATE_GO);
+ SetState(MONSTATE_GO);
Break;
end;
end;
end;
- STATE_WAIT: // Ñîñòîÿíèå - Îæèäàíèå
+ MONSTATE_WAIT: // Ñîñòîÿíèå - Îæèäàíèå
begin
// Æäåì:
FSleep := FSleep - 1;
// Âûæäàëè äîñòàòî÷íî - èäåì:
if FSleep < 0 then
- SetState(STATE_GO);
+ SetState(MONSTATE_GO);
end;
- STATE_GO: // Ñîñòîÿíèå - Äâèæåíèå (ñ îñìîòðîì ñèòóàöèè)
+ MONSTATE_GO: // Ñîñòîÿíèå - Äâèæåíèå (ñ îñìîòðîì ñèòóàöèè)
begin
// Åñëè íàòêíóëèñü íà ÁëîêÌîí - óáåãàåì îò íåãî:
if WordBool(st and MOVE_BLOCK) then
begin
Turn();
FSleep := 40;
- SetState(STATE_RUNOUT);
+ SetState(MONSTATE_RUNOUT);
goto _end;
end;
@@ -2520,7 +2544,7 @@ begin
if isCorpse(@FObj, False) <> -1 then
begin
FObj.Vel.X := 0;
- SetState(STATE_ATTACK, ANIM_ATTACK2);
+ SetState(MONSTATE_ATTACK, ANIM_ATTACK2);
goto _end;
end;
@@ -2573,7 +2597,7 @@ begin
if FMonsterType <> MONSTER_FISH then
begin
FSleep := 15;
- SetState(STATE_RUN);
+ SetState(MONSTATE_RUN);
if Random(2) = 0 then
FDirection := D_LEFT
else
@@ -2589,7 +2613,7 @@ begin
FObj.Rect.Height, FUID, ACTIVATE_MONSTERPRESS) <> nil then
begin // Ñìîãëè íàæàòü êíîïêó - íåáîëüøîå îæèäàíèå
FSleep := 4;
- SetState(STATE_WAIT);
+ SetState(MONSTATE_WAIT);
goto _end;
end;
@@ -2602,7 +2626,7 @@ begin
begin // Ñòîèì íà òâåðäîì ïîëó èëè ñòóïåíè
// Ïðûæîê ÷åðåç ñòåíó:
FObj.Vel.Y := -MONSTERTABLE[FMonsterType].Jump;
- SetState(STATE_CLIMB);
+ SetState(MONSTATE_CLIMB);
end;
end;
@@ -2625,7 +2649,7 @@ begin
end;
// Ðûáå áîëüíî:
- SetState(STATE_PAIN);
+ SetState(MONSTATE_PAIN);
FPain := FPain + 50;
end
else // Ðûáà â âîäå
@@ -2648,7 +2672,7 @@ begin
else
FDirection := D_RIGHT;
FSleep := 20;
- SetState(STATE_RUN);
+ SetState(MONSTATE_RUN);
end;
end;
end
@@ -2737,14 +2761,14 @@ begin
FObj.Vel.X := 0;
end;
- STATE_RUN: // Ñîñòîÿíèå - Áåã
+ MONSTATE_RUN: // Ñîñòîÿíèå - Áåã
begin
// Åñëè íàòêíóëèñü íà ÁëîêÌîí - óáåãàåì îò íåãî:
if WordBool(st and MOVE_BLOCK) then
begin
Turn();
FSleep := 40;
- SetState(STATE_RUNOUT);
+ SetState(MONSTATE_RUNOUT);
goto _end;
end;
@@ -2755,7 +2779,7 @@ begin
if (FSleep <= 0) or (WordBool(st and MOVE_HITWALL) and ((FObj.Vel.Y+FObj.Accel.Y) = 0)) then
begin
FSleep := 0;
- SetState(STATE_GO);
+ SetState(MONSTATE_GO);
// Ñòåíà - èäåì îáðàòíî:
if WordBool(st and (MOVE_HITWALL or MOVE_BLOCK)) then
Turn();
@@ -2778,7 +2802,7 @@ begin
FObj.Vel.X := 0;
end;
- STATE_RUNOUT: // Ñîñòîÿíèå - Óáåãàåò îò ÷åãî-òî
+ MONSTATE_RUNOUT: // Ñîñòîÿíèå - Óáåãàåò îò ÷åãî-òî
begin
// Âûøëè èç ÁëîêÌîíà:
if (not WordBool(st and MOVE_BLOCK)) and (FSleep > 0) then
@@ -2790,7 +2814,7 @@ begin
if FSleep <= -18 then
begin
FSleep := 0;
- SetState(STATE_GO);
+ SetState(MONSTATE_GO);
// Ñòåíà/ÁëîêÌîí - èäåì îáðàòíî:
if WordBool(st and (MOVE_HITWALL or MOVE_BLOCK)) then
Turn();
@@ -2813,21 +2837,21 @@ begin
FObj.Vel.X := 0;
end;
- STATE_CLIMB: // Ñîñòîÿíèå - Ïðûæîê (÷òîáû îáîéòè ñòåíó)
+ MONSTATE_CLIMB: // Ñîñòîÿíèå - Ïðûæîê (÷òîáû îáîéòè ñòåíó)
begin
// Äîñòèãëè âûñøåé òî÷êè ïðûæêà èëè ñòåíà êîí÷èëàñü => ïåðåõîäèì íà øàã:
if ((FObj.Vel.Y+FObj.Accel.Y) >= 0) or
(not WordBool(st and MOVE_HITWALL)) then
begin
FSleep := 0;
- SetState(STATE_GO);
+ SetState(MONSTATE_GO);
// Ñòåíà íå êîí÷èëàñü => áåæèì îò íåå:
if WordBool(st and (MOVE_HITWALL or MOVE_BLOCK)) then
begin
Turn();
FSleep := 15;
- SetState(STATE_RUN);
+ SetState(MONSTATE_RUN);
end;
end;
@@ -2845,14 +2869,14 @@ begin
FObj.Vel.X := 0;
end;
- STATE_ATTACK, // Ñîñòîÿíèå - Àòàêà
- STATE_SHOOT: // Ñîñòîÿíèå - Ñòðåëüáà
+ MONSTATE_ATTACK, // Ñîñòîÿíèå - Àòàêà
+ MONSTATE_SHOOT: // Ñîñòîÿíèå - Ñòðåëüáà
begin
// Lost_Soul âðåçàëñÿ â ñòåíó ïðè àòàêå => ïåðåõîäèò íà øàã:
if FMonsterType = MONSTER_SOUL then
begin
if WordBool(st and (MOVE_HITWALL or MOVE_HITCEIL or MOVE_HITLAND)) then
- SetState(STATE_GO);
+ SetState(MONSTATE_GO);
goto _end;
end;
@@ -2862,12 +2886,12 @@ begin
FObj.Vel.X := z_dec(FObj.Vel.X, 1);
// Íóæíî ñòðåëÿòü, à ìîíñòð - êîëäóí:
- if (FMonsterType = MONSTER_VILE) and (FState = STATE_SHOOT) then
+ if (FMonsterType = MONSTER_VILE) and (FState = MONSTATE_SHOOT) then
begin
// Öåëü ïîãèáëà => èäåì äàëüøå:
if not GetPos(FTargetUID, @o) then
begin
- SetState(STATE_GO);
+ SetState(MONSTATE_GO);
goto _end;
end;
@@ -2875,7 +2899,7 @@ begin
// Öåëü íå âèäíî => èäåì äàëüøå:
if not g_Look(@FObj, @o, FDirection) then
begin
- SetState(STATE_GO);
+ SetState(MONSTATE_GO);
goto _end;
end;
@@ -2883,7 +2907,7 @@ begin
// Öåëü â âîäå - íå çàãîðèòñÿ => èäåì äàëüøå:
if g_Obj_CollideWater(@o, 0, 0) then
begin
- SetState(STATE_GO);
+ SetState(MONSTATE_GO);
goto _end;
end;
@@ -2899,11 +2923,11 @@ begin
_end:
// Ñîñòîÿíèå - Âîñêðåøåíèå:
- if FState = STATE_REVIVE then
+ if FState = MONSTATE_REVIVE then
if FAnim[FCurAnim, FDirection].Played then
begin // Îáðàòíàÿ àíèìàöèÿ óìèðàíèÿ çàêîí÷èëàñü - èäåì äàëüøå:
FAnim[FCurAnim, FDirection].Revert(False);
- SetState(STATE_GO);
+ SetState(MONSTATE_GO);
end;
// Åñëè åñòü àíèìàöèÿ îãíÿ êîëäóíà - ïóñòü îíà èäåò:
@@ -2911,12 +2935,12 @@ _end:
vilefire.Update();
// Ñîñòîÿíèå - Óìèðàåò è òåêóùàÿ àíèìàöèÿ ïðîèãðàíà:
- if (FState = STATE_DIE) and
+ if (FState = MONSTATE_DIE) and
(FAnim[FCurAnim, FDirection] <> nil) and
(FAnim[FCurAnim, FDirection].Played) then
begin
// Óìåð:
- SetState(STATE_DEAD);
+ SetState(MONSTATE_DEAD);
// Pain_Elemental ïðè ñìåðòè âûïóñêàåò 3 Lost_Soul'à:
if (FMonsterType = MONSTER_PAIN) then
@@ -2925,7 +2949,7 @@ _end:
FObj.Y+FObj.Rect.Y+20, D_LEFT);
if mon <> nil then
begin
- mon.SetState(STATE_GO);
+ mon.SetState(MONSTATE_GO);
mon.FNoRespawn := True;
Inc(gTotalMonsters);
if g_Game_IsNet then MH_SEND_MonsterSpawn(mon.UID);
@@ -2935,7 +2959,7 @@ _end:
FObj.Y+FObj.Rect.Y+20, D_RIGHT);
if mon <> nil then
begin
- mon.SetState(STATE_GO);
+ mon.SetState(MONSTATE_GO);
mon.FNoRespawn := True;
Inc(gTotalMonsters);
if g_Game_IsNet then MH_SEND_MonsterSpawn(mon.UID);
@@ -2945,7 +2969,7 @@ _end:
FObj.Y+FObj.Rect.Y, D_RIGHT);
if mon <> nil then
begin
- mon.SetState(STATE_GO);
+ mon.SetState(MONSTATE_GO);
mon.FNoRespawn := True;
Inc(gTotalMonsters);
if g_Game_IsNet then MH_SEND_MonsterSpawn(mon.UID);
@@ -2962,22 +2986,22 @@ _end:
end;
// Ñîâåðøåíèå àòàêè è ñòðåëüáû:
- if (FState = STATE_ATTACK) or (FState = STATE_SHOOT) then
+ if (FState = MONSTATE_ATTACK) or (FState = MONSTATE_SHOOT) then
if (FAnim[FCurAnim, FDirection] <> nil) then
// Àíèìàöèÿ àòàêè åñòü - ìîæíî àòàêîâàòü
if (FAnim[FCurAnim, FDirection].Played) then
begin // Àíèìàöèÿ àòàêè çàêîí÷èëàñü => ïåðåõîäèì íà øàã
- if FState = STATE_ATTACK then
+ if FState = MONSTATE_ATTACK then
begin // Ñîñòîÿíèå - Àòàêà
// Åñëè ìîíñòð íå Lost_Soul, òî ïîñëå àòàêè ïåðåõîäèì íà øàã:
if FMonsterType <> MONSTER_SOUL then
- SetState(STATE_GO);
+ SetState(MONSTATE_GO);
end
else // Ñîñòîÿíèå - Ñòðåëüáà
begin
// Ïåðåõîäèì íà øàã, åñëè íå íàäî ñòðåëÿòü åùå ðàç:
if not FChainFire then
- SetState(STATE_GO)
+ SetState(MONSTATE_GO)
else
begin // Íàäî ñòðåëÿòü åùå
FChainFire := False;
@@ -2997,7 +3021,7 @@ _end:
(FAnim[FCurAnim, FDirection].TotalFrames div 2))
) then
begin // Àòàêè åùå íå áûëî è ýòî ñåðåäèíà àíèìàöèè àòàêè
- if FState = STATE_ATTACK then
+ if FState = MONSTATE_ATTACK then
begin // Ñîñòîÿíèå - Àòàêà
// Åñëè ýòî Lost_Soul, òî ñáðàñûâàåì àíèìàöèþ àòàêè:
if FMonsterType = MONSTER_SOUL then
@@ -3009,7 +3033,7 @@ _end:
if g_Weapon_Hit(@FObj, 15, FUID, HIT_SOME) <> 0 then
// Lost_Soul óêóñèë êîãî-òî => ïåðåõîäèò íà øàã:
if FMonsterType = MONSTER_SOUL then
- SetState(STATE_GO);
+ SetState(MONSTATE_GO);
MONSTER_FISH:
// Ðûáà êóñàåò ïåðâîãî ïîïàâøåãîñÿ ñî çâóêîì:
@@ -3033,7 +3057,7 @@ _end:
sx := isCorpse(@FObj, True);
if sx <> -1 then
begin // Íàøëè, êîãî âîñêðåñèòü
- gMonsters[sx].SetState(STATE_REVIVE);
+ gMonsters[sx].SetState(MONSTATE_REVIVE);
g_Sound_PlayExAt('SOUND_MONSTER_SLOP', FObj.X, FObj.Y);
// Âîñêðåøàòü - ñåáå âðåäèòü:
{g_Weapon_HitUID(FUID, 5, 0, HIT_SOME);}
@@ -3120,7 +3144,7 @@ _end:
GetPos(FTargetUID, @o);
mon.FTargetTime := 0;
mon.FNoRespawn := True;
- mon.SetState(STATE_GO);
+ mon.SetState(MONSTATE_GO);
mon.shoot(@o, True);
Inc(gTotalMonsters);
@@ -3154,7 +3178,7 @@ _end:
// Ïîñëåäíèé êàäð òåêóùåé àíèìàöèè:
if FAnim[FCurAnim, FDirection].Counter = FAnim[FCurAnim, FDirection].Speed-1 then
case FState of
- STATE_GO, STATE_RUN, STATE_CLIMB, STATE_RUNOUT:
+ MONSTATE_GO, MONSTATE_RUN, MONSTATE_CLIMB, MONSTATE_RUNOUT:
// Çâóêè ïðè ïåðåäâèæåíèè:
case FMonsterType of
MONSTER_CYBER:
@@ -3177,7 +3201,7 @@ _end:
end;
if g_Obj_CollidePanel(@FObj, 0, 0, PANEL_LIFTLEFT or PANEL_LIFTRIGHT) and
- not ((FState = STATE_DEAD) or (FState = STATE_DIE)) then
+ not ((FState = MONSTATE_DEAD) or (FState = MONSTATE_DIE)) then
FObj.Vel.X := oldvelx;
// Åñëè åñòü àíèìàöèÿ, òî ïóñòü îíà èäåò:
@@ -3221,15 +3245,15 @@ begin
// Ðûáû "ëåòàþò" òîëüêî â âîäå:
if FMonsterType = MONSTER_FISH then
if g_Obj_CollidePanel(@FObj, 0, 0, PANEL_WATER or PANEL_ACID1 or PANEL_ACID2) then
- if (FState <> STATE_DIE) and (FState <> STATE_DEAD) then
+ if (FState <> MONSTATE_DIE) and (FState <> MONSTATE_DEAD) then
fall := False;
// Ëåòàþùèå ìîíòñðû:
if ((FMonsterType = MONSTER_SOUL) or
(FMonsterType = MONSTER_PAIN) or
(FMonsterType = MONSTER_CACO)) and
- (FState <> STATE_DIE) and
- (FState <> STATE_DEAD) then
+ (FState <> MONSTATE_DIE) and
+ (FState <> MONSTATE_DEAD) then
fall := False;
// Ìåíÿåì ñêîðîñòü òîëüêî ïî ÷åòíûì êàäðàì:
@@ -3260,7 +3284,7 @@ begin
oldvelx := FObj.Vel.X;
// Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
- if (FState = STATE_DIE) or (FState = STATE_DEAD) then
+ if (FState = MONSTATE_DIE) or (FState = MONSTATE_DEAD) then
FObj.Vel.X := z_dec(FObj.Vel.X, 1);
if FFireTime > 0 then
@@ -3275,7 +3299,7 @@ begin
end;
// Ìåðòâûé íè÷åãî íå äåëàåò:
- if (FState = STATE_DEAD) then
+ if (FState = MONSTATE_DEAD) then
goto _end;
// Âîçìîæíî, ñîçäàåì ïóçûðüêè â âîäå:
@@ -3301,7 +3325,7 @@ begin
// Åñëè ïðîøåë ïåðâûé êàäð àíèìàöèè âçðûâà áî÷êè, òî âçðûâ:
if FMonsterType = MONSTER_BARREL then
begin
- if (FState = STATE_DIE) and (FAnim[FCurAnim, FDirection].CurrentFrame = 1) and
+ if (FState = MONSTATE_DIE) and (FAnim[FCurAnim, FDirection].CurrentFrame = 1) and
(FAnim[FCurAnim, FDirection].Counter = 0) then
g_Weapon_Explode(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
FObj.Y+FObj.Rect.Y+FObj.Rect.Height-16,
@@ -3345,8 +3369,8 @@ begin
// Ïðîáóåì óâåðíóòüñÿ îò ëåòÿùåé ïóëè:
if fall then
- if (FState in [STATE_GO, STATE_RUN, STATE_RUNOUT,
- STATE_ATTACK, STATE_SHOOT]) then
+ if (FState in [MONSTATE_GO, MONSTATE_RUN, MONSTATE_RUNOUT,
+ MONSTATE_ATTACK, MONSTATE_SHOOT]) then
if g_Weapon_Danger(FUID, FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y,
FObj.Rect.Width, FObj.Rect.Height, 50) then
if (g_Obj_CollideLevel(@FObj, 0, 1) or g_Obj_StayOnStep(@FObj)) and
@@ -3354,7 +3378,7 @@ begin
FObj.Vel.Y := -MONSTERTABLE[FMonsterType].Jump;
case FState of
- STATE_PAIN: // Ñîñòîÿíèå - Áîëü
+ MONSTATE_PAIN: // Ñîñòîÿíèå - Áîëü
begin
// Áîëü ñèëüíàÿ => ìîíñòð êðè÷èò:
if FPain >= MONSTERTABLE[FMonsterType].Pain then
@@ -3371,12 +3395,12 @@ begin
// Áîëü óæå íå îøóòèìàÿ => èäåì äàëüøå:
if FPain <= MONSTERTABLE[FMonsterType].MinPain then
begin
- SetState(STATE_GO);
+ SetState(MONSTATE_GO);
FPain := 0;
end;
end;
- STATE_SLEEP: // Ñîñòîÿíèå - Ñîí
+ MONSTATE_SLEEP: // Ñîñòîÿíèå - Ñîí
begin
// Ñïèì:
FSleep := FSleep + 1;
@@ -3388,20 +3412,20 @@ begin
goto _end;
end;
- STATE_WAIT: // Ñîñòîÿíèå - Îæèäàíèå
+ MONSTATE_WAIT: // Ñîñòîÿíèå - Îæèäàíèå
begin
// Æäåì:
FSleep := FSleep - 1;
end;
- STATE_GO: // Ñîñòîÿíèå - Äâèæåíèå (ñ îñìîòðîì ñèòóàöèè)
+ MONSTATE_GO: // Ñîñòîÿíèå - Äâèæåíèå (ñ îñìîòðîì ñèòóàöèè)
begin
// Åñëè íàòêíóëèñü íà ÁëîêÌîí - óáåãàåì îò íåãî:
if WordBool(st and MOVE_BLOCK) then
begin
Turn();
FSleep := 40;
- SetState(STATE_RUNOUT);
+ SetState(MONSTATE_RUNOUT);
goto _end;
end;
@@ -3410,7 +3434,7 @@ begin
if (FMonsterType = MONSTER_VILE) then
if isCorpse(@FObj, False) <> -1 then
begin
- SetState(STATE_ATTACK, ANIM_ATTACK2);
+ SetState(MONSTATE_ATTACK, ANIM_ATTACK2);
FObj.Vel.X := 0;
goto _end;
@@ -3420,7 +3444,7 @@ begin
if Abs(sx) < 40 then
if FMonsterType <> MONSTER_FISH then
begin
- SetState(STATE_RUN);
+ SetState(MONSTATE_RUN);
FSleep := 15;
goto _end;
@@ -3437,7 +3461,7 @@ begin
begin // Ñòîèì íà òâåðäîì ïîëó èëè ñòóïåíè
// Ïðûæîê ÷åðåç ñòåíó:
FObj.Vel.Y := -MONSTERTABLE[FMonsterType].Jump;
- SetState(STATE_CLIMB);
+ SetState(MONSTATE_CLIMB);
end;
end;
@@ -3461,7 +3485,7 @@ begin
end;
// Ðûáå áîëüíî:
- SetState(STATE_PAIN);
+ SetState(MONSTATE_PAIN);
FPain := FPain + 50;
end
else // Ðûáà â âîäå
@@ -3479,7 +3503,7 @@ begin
// Âñïëûëè äî ïîâåðõíîñòè - ñòîï:
FObj.Vel.Y := 0;
// Ïëàâàåì òóäà-ñþäà:
- SetState(STATE_RUN);
+ SetState(MONSTATE_RUN);
FSleep := 20;
end;
end;
@@ -3564,12 +3588,12 @@ begin
FObj.Vel.X := 0;
end;
- STATE_RUN: // Ñîñòîÿíèå - Áåã
+ MONSTATE_RUN: // Ñîñòîÿíèå - Áåã
begin
// Åñëè íàòêíóëèñü íà ÁëîêÌîí - óáåãàåì îò íåãî:
if WordBool(st and MOVE_BLOCK) then
begin
- SetState(STATE_RUNOUT);
+ SetState(MONSTATE_RUNOUT);
FSleep := 40;
goto _end;
@@ -3580,7 +3604,7 @@ begin
// Ïðîáåæàëè äîñòàòî÷íî èëè âðåçàëèñü â ñòåíó => ïåðåõîäèì íà øàã:
if (FSleep <= 0) or (WordBool(st and MOVE_HITWALL) and ((FObj.Vel.Y+FObj.Accel.Y) = 0)) then
begin
- SetState(STATE_GO);
+ SetState(MONSTATE_GO);
FSleep := 0;
// Èíîãäà ðû÷èì:
@@ -3602,7 +3626,7 @@ begin
FObj.Vel.X := 0;
end;
- STATE_RUNOUT: // Ñîñòîÿíèå - Óáåãàåò îò ÷åãî-òî
+ MONSTATE_RUNOUT: // Ñîñòîÿíèå - Óáåãàåò îò ÷åãî-òî
begin
// Âûøëè èç ÁëîêÌîíà:
if (not WordBool(st and MOVE_BLOCK)) and (FSleep > 0) then
@@ -3613,7 +3637,7 @@ begin
// Óáàæåëè äîñòàòî÷íî äàëåêî => ïåðåõîäèì íà øàã:
if FSleep <= -18 then
begin
- SetState(STATE_GO);
+ SetState(MONSTATE_GO);
FSleep := 0;
// Èíîãäà ðû÷èì:
@@ -3635,19 +3659,19 @@ begin
FObj.Vel.X := 0;
end;
- STATE_CLIMB: // Ñîñòîÿíèå - Ïðûæîê (÷òîáû îáîéòè ñòåíó)
+ MONSTATE_CLIMB: // Ñîñòîÿíèå - Ïðûæîê (÷òîáû îáîéòè ñòåíó)
begin
// Äîñòèãëè âûñøåé òî÷êè ïðûæêà èëè ñòåíà êîí÷èëàñü => ïåðåõîäèì íà øàã:
if ((FObj.Vel.Y+FObj.Accel.Y) >= 0) or
(not WordBool(st and MOVE_HITWALL)) then
begin
- SetState(STATE_GO);
+ SetState(MONSTATE_GO);
FSleep := 0;
// Ñòåíà íå êîí÷èëàñü => áåæèì îò íåå:
if WordBool(st and (MOVE_HITWALL or MOVE_BLOCK)) then
begin
- SetState(STATE_RUN);
+ SetState(MONSTATE_RUN);
FSleep := 15;
end;
end;
@@ -3666,14 +3690,14 @@ begin
FObj.Vel.X := 0;
end;
- STATE_ATTACK, // Ñîñòîÿíèå - Àòàêà
- STATE_SHOOT: // Ñîñòîÿíèå - Ñòðåëüáà
+ MONSTATE_ATTACK, // Ñîñòîÿíèå - Àòàêà
+ MONSTATE_SHOOT: // Ñîñòîÿíèå - Ñòðåëüáà
begin
// Lost_Soul âðåçàëñÿ â ñòåíó ïðè àòàêå => ïåðåõîäèò íà øàã:
if FMonsterType = MONSTER_SOUL then
begin
if WordBool(st and (MOVE_HITWALL or MOVE_HITCEIL or MOVE_HITLAND)) then
- SetState(STATE_GO);
+ SetState(MONSTATE_GO);
goto _end;
end;
@@ -3683,12 +3707,12 @@ begin
FObj.Vel.X := z_dec(FObj.Vel.X, 1);
// Íóæíî ñòðåëÿòü, à ìîíñòð - êîëäóí:
- if (FMonsterType = MONSTER_VILE) and (FState = STATE_SHOOT) then
+ if (FMonsterType = MONSTER_VILE) and (FState = MONSTATE_SHOOT) then
begin
// Öåëü ïîãèáëà => èäåì äàëüøå:
if not GetPos(FTargetUID, @o) then
begin
- SetState(STATE_GO);
+ SetState(MONSTATE_GO);
goto _end;
end;
@@ -3696,7 +3720,7 @@ begin
// Öåëü íå âèäíî => èäåì äàëüøå:
if not g_Look(@FObj, @o, FDirection) then
begin
- SetState(STATE_GO);
+ SetState(MONSTATE_GO);
goto _end;
end;
@@ -3704,7 +3728,7 @@ begin
// Öåëü â âîäå - íå çàãîðèòñÿ => èäåì äàëüøå:
if g_Obj_CollideWater(@o, 0, 0) then
begin
- SetState(STATE_GO);
+ SetState(MONSTATE_GO);
goto _end;
end;
@@ -3715,11 +3739,11 @@ begin
_end:
// Ñîñòîÿíèå - Âîñêðåøåíèå:
- if FState = STATE_REVIVE then
+ if FState = MONSTATE_REVIVE then
if FAnim[FCurAnim, FDirection].Played then
begin // Îáðàòíàÿ àíèìàöèÿ óìèðàíèÿ çàêîí÷èëàñü - èäåì äàëüøå:
FAnim[FCurAnim, FDirection].Revert(False);
- SetState(STATE_GO);
+ SetState(MONSTATE_GO);
end;
// Åñëè åñòü àíèìàöèÿ îãíÿ êîëäóíà - ïóñòü îíà èäåò:
@@ -3727,12 +3751,12 @@ _end:
vilefire.Update();
// Ñîñòîÿíèå - Óìèðàåò è òåêóùàÿ àíèìàöèÿ ïðîèãðàíà:
- if (FState = STATE_DIE) and
+ if (FState = MONSTATE_DIE) and
(FAnim[FCurAnim, FDirection] <> nil) and
(FAnim[FCurAnim, FDirection].Played) then
begin
// Óìåð:
- SetState(STATE_DEAD);
+ SetState(MONSTATE_DEAD);
// Ó ýòèõ ìîíñòðîâ íåò òðóïîâ:
if (FMonsterType = MONSTER_PAIN) or
@@ -3744,22 +3768,22 @@ _end:
end;
// Ñîâåðøåíèå àòàêè è ñòðåëüáû:
- if (FState = STATE_ATTACK) or (FState = STATE_SHOOT) then
+ if (FState = MONSTATE_ATTACK) or (FState = MONSTATE_SHOOT) then
if (FAnim[FCurAnim, FDirection] <> nil) then
// Àíèìàöèÿ àòàêè åñòü - ìîæíî àòàêîâàòü
if (FAnim[FCurAnim, FDirection].Played) then
begin // Àíèìàöèÿ àòàêè çàêîí÷èëàñü => ïåðåõîäèì íà øàã
- if FState = STATE_ATTACK then
+ if FState = MONSTATE_ATTACK then
begin // Ñîñòîÿíèå - Àòàêà
// Åñëè ìîíñòð íå Lost_Soul, òî ïîñëå àòàêè ïåðåõîäèì íà øàã:
if FMonsterType <> MONSTER_SOUL then
- SetState(STATE_GO);
+ SetState(MONSTATE_GO);
end
else // Ñîñòîÿíèå - Ñòðåëüáà
begin
// Ïåðåõîäèì íà øàã, åñëè íå íàäî ñòðåëÿòü åùå ðàç:
if not FChainFire then
- SetState(STATE_GO)
+ SetState(MONSTATE_GO)
else
begin // Íàäî ñòðåëÿòü åùå
FChainFire := False;
@@ -3779,7 +3803,7 @@ _end:
(FAnim[FCurAnim, FDirection].TotalFrames div 2))
) then
begin // Àòàêè åùå íå áûëî è ýòî ñåðåäèíà àíèìàöèè àòàêè
- if FState = STATE_ATTACK then
+ if FState = MONSTATE_ATTACK then
begin // Ñîñòîÿíèå - Àòàêà
// Åñëè ýòî Lost_Soul, òî ñáðàñûâàåì àíèìàöèþ àòàêè:
if FMonsterType = MONSTER_SOUL then
@@ -3791,7 +3815,7 @@ _end:
if g_Weapon_Hit(@FObj, 15, FUID, HIT_SOME) <> 0 then
// Lost_Soul óêóñèë êîãî-òî => ïåðåõîäèò íà øàã:
if FMonsterType = MONSTER_SOUL then
- SetState(STATE_GO);
+ SetState(MONSTATE_GO);
MONSTER_FISH:
g_Weapon_Hit(@FObj, 10, FUID, HIT_SOME);
@@ -3843,7 +3867,7 @@ _end:
// Ïîñëåäíèé êàäð òåêóùåé àíèìàöèè:
if FAnim[FCurAnim, FDirection].Counter = FAnim[FCurAnim, FDirection].Speed-1 then
case FState of
- STATE_GO, STATE_RUN, STATE_CLIMB, STATE_RUNOUT:
+ MONSTATE_GO, MONSTATE_RUN, MONSTATE_CLIMB, MONSTATE_RUNOUT:
// Çâóêè ïðè ïåðåäâèæåíèè:
case FMonsterType of
MONSTER_CYBER:
@@ -3867,7 +3891,7 @@ _end:
// Êîñòûëü äëÿ ïîòîêîâ
if g_Obj_CollidePanel(@FObj, 0, 0, PANEL_LIFTLEFT or PANEL_LIFTRIGHT) and
- not ((FState = STATE_DEAD) or (FState = STATE_DIE)) then
+ not ((FState = MONSTATE_DEAD) or (FState = MONSTATE_DIE)) then
FObj.Vel.X := oldvelx;
// Åñëè åñòü àíèìàöèÿ, òî ïóñòü îíà èäåò:
@@ -4078,24 +4102,24 @@ begin
case FMonsterType of
MONSTER_FISH:
begin
- SetState(STATE_ATTACK);
+ SetState(MONSTATE_ATTACK);
Result := True;
end;
MONSTER_DEMON:
begin
- SetState(STATE_ATTACK);
+ SetState(MONSTATE_ATTACK);
g_Sound_PlayExAt('SOUND_MONSTER_DEMON_ATTACK', FObj.X, FObj.Y);
Result := True;
end;
MONSTER_IMP:
begin
- SetState(STATE_ATTACK);
+ SetState(MONSTATE_ATTACK);
g_Sound_PlayExAt('SOUND_MONSTER_IMP_ATTACK', FObj.X, FObj.Y);
Result := True;
end;
MONSTER_SKEL, MONSTER_ROBO, MONSTER_CYBER:
begin
- SetState(STATE_ATTACK, ANIM_ATTACK2);
+ SetState(MONSTATE_ATTACK, ANIM_ATTACK2);
g_Sound_PlayExAt('SOUND_MONSTER_SKEL_ATTACK', FObj.X, FObj.Y);
Result := True;
end;
@@ -4178,19 +4202,19 @@ begin
case FMonsterType of
MONSTER_IMP, MONSTER_BARON, MONSTER_KNIGHT, MONSTER_CACO:
begin
- SetState(STATE_SHOOT);
+ SetState(MONSTATE_SHOOT);
{nn}
end;
MONSTER_SKEL:
begin
- SetState(STATE_SHOOT);
+ SetState(MONSTATE_SHOOT);
{nn}
end;
MONSTER_VILE:
begin // Çàæèãàåì îãîíü
tx := o^.X+o^.Rect.X+(o^.Rect.Width div 2);
ty := o^.Y+o^.Rect.Y;
- SetState(STATE_SHOOT);
+ SetState(MONSTATE_SHOOT);
vilefire.Reset();
@@ -4199,7 +4223,7 @@ begin
end;
MONSTER_SOUL:
begin // Ëåòèò â ñòîðîíó öåëè:
- SetState(STATE_ATTACK);
+ SetState(MONSTATE_ATTACK);
g_Sound_PlayExAt('SOUND_MONSTER_SOUL_ATTACK', FObj.X, FObj.Y);
xd := tx-(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2));
@@ -4219,7 +4243,7 @@ begin
if FAmmo = 1 then
g_Sound_PlayExAt('SOUND_MONSTER_MANCUB_ATTACK', FObj.X, FObj.Y);
- SetState(STATE_SHOOT);
+ SetState(MONSTATE_SHOOT);
end;
else Exit;
end;
@@ -4229,7 +4253,7 @@ end;
function TMonster.Live(): Boolean;
begin
- Result := (FState <> STATE_DIE) and (FState <> STATE_DEAD) and (FHealth > 0);
+ Result := (FState <> MONSTATE_DIE) and (FState <> MONSTATE_DEAD) and (FHealth > 0);
end;
procedure TMonster.SetHealth(aH: Integer);
@@ -4245,7 +4269,7 @@ end;
procedure TMonster.WakeUp();
begin
if g_Game_IsClient then Exit;
- SetState(STATE_GO);
+ SetState(MONSTATE_GO);
FTargetTime := MAX_ATM;
WakeUpSound();
end;
@@ -4332,6 +4356,7 @@ begin
end;
end;
+
procedure TMonster.LoadState(var Mem: TBinMemoryReader);
var
i: Integer;
@@ -4348,8 +4373,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
@@ -4472,7 +4502,7 @@ begin
Anim := TAnimation.Create(id, False, 3);
Anim.Alpha := 0;
g_GFX_OnceAnim(Obj.X+Obj.Rect.X+Random(Obj.Rect.Width+Times*2)-(Anim.Width div 2),
- Obj.Y+8+Random(8+Times*2)+IfThen(FState = STATE_DEAD, 16, 0), Anim, ONCEANIM_SMOKE);
+ Obj.Y+8+Random(8+Times*2)+IfThen(FState = MONSTATE_DEAD, 16, 0), Anim, ONCEANIM_SMOKE);
Anim.Free();
end;
end;
@@ -4487,7 +4517,6 @@ begin
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
@@ -4495,6 +4524,11 @@ begin
result := gMonsters[uid];
end;
+function g_Mons_TotalCount (): Integer; inline;
+begin
+ result := Length(gMonsters);
+end;
+
function g_Mons_ForEach (cb: TEachMonsterCB): Boolean;
var
@@ -4569,13 +4603,10 @@ begin
end;
-///!!!FIXME!!!
function g_Mons_ForEachAt (x, y: Integer; width, height: Integer; cb: TEachMonsterCB): Boolean;
function monsCollCheck (mon: TMonster; atag: Integer): Boolean;
begin
- //result := false;
- //if g_Obj_Collide(x, y, width, height, @mon.Obj) then result := cb(mon);
result := cb(mon);
end;