X-Git-Url: http://deadsoftware.ru/gitweb?a=blobdiff_plain;f=src%2Fgame%2Fg_monsters.pas;h=d8adad853402974c802ba9bfbd3f58761809835e;hb=22f00c44f3473ea1823ae8c7e85ed175a4c884cf;hp=e47c0ff04ce80b2193e689bbf434b359e4318465;hpb=844441154d1220d6c83f75043300c2851ec87109;p=d2df-sdl.git
diff --git a/src/game/g_monsters.pas b/src/game/g_monsters.pas
index e47c0ff..d8adad8 100644
--- a/src/game/g_monsters.pas
+++ b/src/game/g_monsters.pas
@@ -1,10 +1,29 @@
+(* Copyright (C) Doom 2D: Forever Developers
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3 of the License ONLY.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *)
+{$INCLUDE ../shared/a_modes.inc}
+{$M+}
+{.$DEFINE D2F_DEBUG_MONS_MOVE}
unit g_monsters;
interface
uses
- g_basic, e_graphics, g_phys, g_textures,
- g_saveload, BinEditor, g_panel;
+ SysUtils, Classes,
+ mempool,
+ g_basic, e_graphics, g_phys, g_textures, g_grid,
+ g_saveload, g_panel, xprofiler;
const
MONSTATE_SLEEP = 0;
@@ -20,15 +39,20 @@ const
MONSTATE_REVIVE = 10;
MONSTATE_RUNOUT = 11;
+ MON_BURN_TIME = 100;
+
+{ in mapdef now
BH_NORMAL = 0;
BH_KILLER = 1;
BH_MANIAC = 2;
BH_INSANE = 3;
BH_CANNIBAL = 4;
BH_GOOD = 5;
+}
type
- TMonster = Class (TObject)
+ PMonster = ^TMonster;
+ TMonster = class{$IFDEF USE_MEMPOOL}(TPoolObject){$ENDIF}
private
FMonsterType: Byte;
FUID: Word;
@@ -40,7 +64,7 @@ type
FMaxHealth: Integer;
FState: Byte;
FCurAnim: Byte;
- FAnim: Array of Array [D_LEFT..D_RIGHT] of TAnimation;
+ FAnim: Array of Array [TDirection.D_LEFT..TDirection.D_RIGHT] of TAnimation;
FTargetUID: Word;
FTargetTime: Integer;
FBehaviour: Byte;
@@ -48,6 +72,7 @@ type
FPain: Integer;
FSleep: Integer;
FPainSound: Boolean;
+ FPainTicks: Integer;
FWaitAttackAnim: Boolean;
FChainFire: Boolean;
tx, ty: Integer;
@@ -59,17 +84,33 @@ type
FBloodKind: Byte;
FShellTimer: Integer;
FShellType: Byte;
+ FFirePainTime: Integer;
+ FFireAttacker: Word;
vilefire: TAnimation;
+ mProxyId: Integer; // node in dyntree or -1
+ mArrIdx: Integer; // in gMonsters
FDieTriggers: Array of Integer;
FSpawnTrigger: Integer;
+ mNeedSend: Boolean; // for network
+
+ mEDamageType: Integer;
+
procedure Turn();
function findNewPrey(): Boolean;
procedure ActivateTriggers();
+ procedure setGameX (v: Integer); inline;
+ procedure setGameY (v: Integer); inline;
+
+ procedure doDamage (v: Integer);
+
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;
@@ -77,15 +118,16 @@ 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(Damage: Word; VelX, VelY: Integer; SpawnerUID: Word; t: Byte): Boolean;
+ function Damage(aDamage: Word; VelX, VelY: Integer; SpawnerUID: Word; t: Byte): Boolean;
function Heal(Value: Word): Boolean;
procedure BFGHit();
+ procedure PreUpdate();
procedure Update();
procedure ClientUpdate();
- procedure ClientAttack(wx, wy, tx, ty: Integer);
+ procedure ClientAttack(wx, wy, atx, aty: Integer);
procedure SetDeadAnim;
procedure Draw();
procedure WakeUp();
@@ -96,8 +138,8 @@ type
procedure AddTrigger(t: Integer);
procedure ClearTriggers();
procedure Respawn();
- procedure SaveState(var Mem: TBinMemoryWriter);
- procedure LoadState(var Mem: TBinMemoryReader);
+ procedure SaveState (st: TStream);
+ procedure LoadState (st: TStream);
procedure SetState(State: Byte; ForceAnim: Byte = 255);
procedure MakeBloodVector(Count: Word; VelX, VelY: Integer);
procedure MakeBloodSimple(Count: Word);
@@ -105,6 +147,25 @@ type
function AnimIsReverse: Boolean;
function shoot(o: PObj; immediately: Boolean): Boolean;
function kick(o: PObj): Boolean;
+ procedure CatchFire(Attacker: Word; Timeout: Integer = MON_BURN_TIME);
+ procedure OnFireFlame(Times: DWORD = 1);
+
+ 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;
+
+ // get-and-clear
+ function gncNeedSend (): Boolean; inline;
+ procedure setDirty (); inline; // why `dirty`? 'cause i may introduce property `needSend` later
+
+ public
+ property Obj: TObj read FObj;
+
+ property proxyId: Integer read mProxyId;
+ property arrIdx: Integer read mArrIdx;
property MonsterType: Byte read FMonsterType;
property MonsterHealth: Integer read FHealth write FHealth;
@@ -118,12 +179,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;
@@ -131,36 +191,245 @@ type
property GameDirection: TDirection read FDirection write FDirection;
property StartID: Integer read FStartID;
+
+ published
+ property eMonsterType: Byte read FMonsterType;
+ property eMonsterHealth: Integer read FHealth write FHealth;
+ property eMonsterAmmo: Integer read FAmmo write FAmmo;
+ property eMonsterTargetUID: Word read FTargetUID write FTargetUID;
+ property eMonsterTargetTime: Integer read FTargetTime write FTargetTime;
+ property eMonsterBehaviour: Byte read FBehaviour write FBehaviour;
+ property eMonsterSleep: Integer read FSleep write FSleep;
+ property eMonsterState: Byte read FState write FState;
+ property eMonsterRemoved: Boolean read FRemoved;
+ property eMonsterPain: Integer read FPain write FPain;
+ property eMonsterAnim: Byte read FCurAnim;
+
+ property eUID: Word read FUID;
+ property eSpawnTrigger: Integer read FSpawnTrigger;
+
+ property eGameX: Integer read FObj.X write setGameX;
+ property eGameY: Integer read FObj.Y write setGameY;
+ property eGameVelX: Integer read FObj.Vel.X write FObj.Vel.X;
+ property eGameVelY: Integer read FObj.Vel.Y write FObj.Vel.Y;
+ property eGameAccelX: Integer read FObj.Accel.X write FObj.Accel.X;
+ property eGameAccelY: Integer read FObj.Accel.Y write FObj.Accel.Y;
+ property eGameDirection: TDirection read FDirection write FDirection;
+
+ property eStartID: Integer read FStartID;
+
+ // set this before assigning something to `eDamage`
+ property eDamageType: Integer read mEDamageType write mEDamageType;
+ property eDamage: Integer write doDamage;
end;
-procedure g_Monsters_LoadData();
-procedure g_Monsters_FreeData();
-procedure g_Monsters_Init();
-procedure g_Monsters_Free();
-function g_Monsters_Create(MonsterType: Byte; X, Y: Integer;
- Direction: TDirection; AdjCoord: Boolean = False; ForcedUID: Integer = -1): Integer;
-procedure g_Monsters_Update();
-procedure g_Monsters_Draw();
-procedure g_Monsters_DrawHealth();
-function g_Monsters_Get(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;
+
+// will be called from map loader
+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 (clearGrid: Boolean=true);
+function g_Monsters_Create (MonsterType: Byte; X, Y: Integer; Direction: TDirection;
+ AdjCoord: Boolean = False; ForcedUID: Integer = -1): TMonster;
+procedure g_Monsters_PreUpdate ();
+procedure g_Monsters_Update ();
+procedure g_Monsters_Draw ();
+procedure g_Monsters_DrawHealth ();
+function g_Monsters_ByUID (UID: Word): TMonster;
+procedure g_Monsters_killedp ();
+procedure g_Monsters_SaveState (st: TStream);
+procedure g_Monsters_LoadState (st: TStream);
+
+function g_Mons_SpawnAt (monType: Integer; x, y: Integer; dir: TDirection=TDirection.D_LEFT): TMonster; overload;
+function g_Mons_SpawnAt (const typeName: AnsiString; x, y: Integer; dir: TDirection=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
+ TEachMonsterCB = function (mon: TMonster): Boolean is nested; // return `true` to stop
+
+// throws on invalid uid
+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;
+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; inline;
+function g_Mons_getNewMPlatFrameId (): LongWord; inline;
+
+
+{
+type
+ TMonsAlongLineCB = function (mon: TMonster; tag: Integer): Boolean is nested;
+
+function g_Mons_AlongLine (x0, y0, x1, y1: Integer; cb: TMonsAlongLineCB; log: Boolean=false): TMonster;
+}
+
var
- gMonsters: array of TMonster;
+ gmon_debug_use_sqaccel: Boolean = true;
+
+
+//HACK!
+procedure g_Mons_ProfilersBegin ();
+procedure g_Mons_ProfilersEnd ();
+
+procedure g_Mons_LOS_Start (); inline;
+procedure g_Mons_LOS_End (); inline;
+
+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,
+ e_log, e_texture, 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_console, g_map, Math, g_menu, wadreader,
+ g_language, g_netmsg, idpool, utils, xstreams;
+
+
+
+// ////////////////////////////////////////////////////////////////////////// //
+procedure g_Mons_ProfilersBegin ();
+begin
+ if (profMonsLOS = nil) then profMonsLOS := TProfiler.Create('LOS CALC', g_profile_history_size);
+ if (profMonsLOS <> nil) then profMonsLOS.mainBegin(g_profile_los);
+ if g_profile_los and (profMonsLOS <> nil) then
+ begin
+ profMonsLOS.sectionBegin('loscalc');
+ profMonsLOS.sectionEnd();
+ end;
+end;
+
+procedure g_Mons_ProfilersEnd ();
+begin
+ if (profMonsLOS <> nil) and (g_profile_los) then profMonsLOS.mainEnd();
+end;
+
+procedure g_Mons_LOS_Start (); inline;
+begin
+ if (profMonsLOS <> nil) then profMonsLOS.sectionBeginAccum('loscalc');
+end;
+procedure g_Mons_LOS_End (); inline;
+begin
+ if (profMonsLOS <> nil) then profMonsLOS.sectionEnd();
+end;
+
+
+// ////////////////////////////////////////////////////////////////////////// //
+var
+ monCheckTrapLastFrameId: DWord = 0;
+ monCheckMPlatLastFrameId: LongWord = 0;
+
+
+procedure TMonster.getMapBox (out x, y, w, h: Integer); inline;
+begin
+ x := FObj.X+FObj.Rect.X;
+ y := FObj.Y+FObj.Rect.Y;
+ w := FObj.Rect.Width;
+ h := FObj.Rect.Height;
+end;
+
+function TMonster.gncNeedSend (): Boolean; inline; begin result := mNeedSend; mNeedSend := false; end;
+
+procedure TMonster.setDirty (); inline; begin mNeedSend := true; end;
+
+
+// ////////////////////////////////////////////////////////////////////////// //
+{
+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;
+ result := monsGrid.forEachAlongLine(x0, y0, x1, y1, cb, -1, log);
+end;
+}
+
+
+//WARNING! call this after monster position was changed, or coldet will not work right!
+procedure TMonster.positionChanged ();
+var
+ 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);
+ {$ENDIF}
+ if (mProxyId = -1) then
+ begin
+ //mNeedSend := true;
+ 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; gx=%d; gy=%d', [mArrIdx, UID, mProxyId, x-monsGrid.gridX0, y-monsGrid.gridY0]), MSG_NOTIFY);
+ {$ENDIF}
+ end
+ else
+ begin
+ monsGrid.getBodyDims(mProxyId, x, y, w, h);
+ getMapBox(nx, ny, nw, nh);
+
+ if (w <> nw) or (h <> nh) then
+ begin
+ //mNeedSend := true;
+ {$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
+ //mNeedSend := true;
+ {$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 grid; mProxyid=%d; gx=%d; gy=%d', [mArrIdx, UID, mProxyId, x-monsGrid.gridX0, y-monsGrid.gridY0]), MSG_NOTIFY);
+ {$ENDIF}
+ end;
+end;
+
+
+// ////////////////////////////////////////////////////////////////////////// //
const
ANIM_SLEEP = 0;
ANIM_GO = 1;
@@ -170,19 +439,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'
// Òàáëèöà òèïîâ àíèìàöèè ìîíñòðîâ:
@@ -275,8 +531,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));
@@ -286,17 +542,17 @@ const
AnimDeltaRight: ((X: 8; Y: -4), (X: 8; Y: -4), (X: -2; Y: -1), (X: 3; Y: -2), (X: 14; Y: -4), (X: 14; Y: -4), (X: -5; Y: -4));
AnimDeltaLeft: ((X: 8; Y: -4), (X: 8; Y: -4), (X: -2; Y: -1), (X: 3; Y: -2), (X: 14; Y: -4), (X: 14; Y: -4), (X: -5; Y: -4))),
- (LeftAnim: False; wX: 32; wY: 32; AnimSpeed:(3, 2, 3, 2, 3, 0, 4); //ZOMBY
+ (LeftAnim: True; wX: 32; wY: 32; AnimSpeed:(3, 2, 3, 2, 3, 0, 4); //ZOMBY
AnimDeltaRight: ((X: 1; Y: -4), (X: 1; Y: -4), (X: 3; Y: -1), (X: 2; Y: -1), (X: 2; Y: -4), (X: 2; Y: -4), (X: 1; Y: -4));
AnimDeltaLeft: ((X: 1; Y: -4), (X: 1; Y: -4), (X: 3; Y: -1), (X: 2; Y: -1), (X: 2; Y: -4), (X: 2; Y: -4), (X: 1; Y: -4))),
- (LeftAnim: False; wX: 32; wY: 32; AnimSpeed:(3, 2, 3, 2, 3, 0, 4); //SERG
+ (LeftAnim: True; wX: 32; wY: 32; AnimSpeed:(3, 2, 3, 2, 3, 0, 4); //SERG
AnimDeltaRight: ((X: 0; Y: -4), (X: 0; Y: -4), (X: -3; Y: -1), (X: -4; Y: -1), (X: 1; Y: -4), (X: 1; Y: -4), (X: 0; Y: -4));
AnimDeltaLeft: ((X: 0; Y: -4), (X: 0; Y: -4), (X: -3; Y: -1), (X: -4; Y: -1), (X: 1; Y: -4), (X: 1; Y: -4), (X: 0; Y: -4))),
- (LeftAnim: True; wX: 70; wY: 73; AnimSpeed:(3, 3, 3, 3, 3, 0, 3); //CYBER
- AnimDeltaRight: ((X: 2; Y: -6), (X: 2; Y: -6), (X: -3; Y: -4), (X: -3; Y: -4), (X: 25; Y: -6), (X: 25; Y: -6), (X: -2; Y: -6));
- AnimDeltaLeft: ((X: 3; Y: -3), (X: 3; Y: -3), (X: -3; Y: -4), (X: -3; Y: -4), (X:-26; Y: -3), (X:-26; Y: -3), (X: 1; Y: -3))),
+ (LeftAnim: True; wX: 70; wY: 73; AnimSpeed:(3, 3, 3, 3, 3, 4, 3); //CYBER
+ AnimDeltaRight: ((X: 2; Y: -6), (X: 2; Y: -6), (X: -3; Y: -4), (X: -3; Y: -4), (X: 25; Y: -6), (X: 0; Y: -6), (X: -2; Y: -6));
+ AnimDeltaLeft: ((X: 3; Y: -3), (X: 3; Y: -3), (X: -3; Y: -4), (X: -3; Y: -4), (X:-26; Y: -3), (X:-1; Y: -3), (X: 1; Y: -3))),
(LeftAnim: True; wX: 32; wY: 32; AnimSpeed:(3, 2, 2, 2, 1, 0, 4); //CGUN
AnimDeltaRight: ((X: -1; Y: -2), (X: -1; Y: -2), (X: -2; Y: 0), (X: -2; Y: 0), (X: 0; Y: -3), (X: 0; Y: -3), (X: -1; Y: -2));
@@ -361,6 +617,59 @@ const
MAX_ATM = 89; // Âðåìÿ îæèäàíèÿ ïîñëå ïîòåðè öåëè
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 ();
+var
+ idx: Integer;
+begin
+ for idx := 0 to High(uidMap) do uidMap[idx] := nil;
+ freeInds.clear();
+end;
+
+
+function g_Mons_getNewTrapFrameId (): DWord; inline;
+var
+ f: Integer;
+begin
+ Inc(monCheckTrapLastFrameId);
+ if (monCheckTrapLastFrameId = 0) then
+ begin
+ // wraparound
+ monCheckTrapLastFrameId := 1;
+ for f := 0 to High(gMonsters) do
+ begin
+ if (gMonsters[f] <> nil) then gMonsters[f].trapCheckFrameId := 0;
+ end;
+ end;
+ result := monCheckTrapLastFrameId;
+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;
@@ -368,30 +677,21 @@ var
pt_ys: Integer = 1;
soulcount: Integer = 0;
-function FindMonster(): DWORD;
+
+function allocMonster (): DWORD;
var
- i: Integer;
+ f, olen: Integer;
begin
- if gMonsters <> nil then
- for i := 0 to High(gMonsters) do
- if gMonsters[i] = nil then
- begin
- Result := i;
- Exit;
- end;
-
- if gMonsters = nil then
- begin
- SetLength(gMonsters, 32);
- Result := 0;
- end
- else
- begin
- Result := High(gMonsters) + 1;
- SetLength(gMonsters, Length(gMonsters) + 32);
- end;
+ result := freeInds.alloc();
+ if (result > High(gMonsters)) then
+ begin
+ olen := Length(gMonsters);
+ SetLength(gMonsters, result+64);
+ for f := olen to High(gMonsters) do gMonsters[f] := nil;
+ end;
end;
+
function IsFriend(a, b: Byte): Boolean;
begin
Result := True;
@@ -419,6 +719,7 @@ begin
Result := False;
end;
+
function BehaviourDamage(SpawnerUID: Word; BH, SelfType: Byte): Boolean;
var
m: TMonster;
@@ -430,7 +731,7 @@ begin
UIDType := g_GetUIDType(SpawnerUID);
if UIDType = UID_MONSTER then
begin
- m := g_Monsters_Get(SpawnerUID);
+ m := g_Monsters_ByUID(SpawnerUID);
if m = nil then Exit;
MonsterType := m.FMonsterType;
end;
@@ -448,6 +749,7 @@ begin
end;
end;
+
function canShoot(m: Byte): Boolean;
begin
Result := False;
@@ -460,24 +762,62 @@ 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
+ atag := atag; // shut up, fpc!
+ result := false; // don't stop
+ 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,
+ MONSTER_VILE, MONSTER_BARREL, MONSTER_ROBO: exit;
+ end;
+ // Îñòàëüíûõ ìîæíî âîñêðåñèòü
+ result := true;
+ end;
+ end;
+ *)
+
var
a: Integer;
+ mon: PMonster;
+ mres: TMonster = nil;
+ it: TMonsterGrid.Iter;
begin
- Result := -1;
+ result := -1;
-// Åñëè íóæíà âåðîÿòíîñòü:
- if not immediately then
- if Random(8) <> 0 then
- Exit;
+ // Åñëè íóæíà âåðîÿòíîñòü
+ if not immediately and (Random(8) <> 0) then exit;
- if gMonsters = nil then
- Exit;
-
-// Èùåì ìåðòâûõ ìîíñòðîâ ïîáëèçîñòè:
- for a := 0 to High(gMonsters) do
- if (gMonsters[a] <> nil) and (gMonsters[a].FState = STATE_DEAD) then
- if g_Obj_Collide(o, @gMonsters[a].FObj) then
+ // Èùåì ìåðòâûõ ìîíñòðîâ ïîáëèçîñòè
+ 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.mArrIdx;
+ it := monsGrid.forEachInAABB(o.X+o.Rect.X, o.Y+o.Rect.Y, o.Rect.Width, o.Rect.Height);
+ for mon in it do
+ begin
+ case mon.FMonsterType of // Íå âîñêðåñèòü:
+ MONSTER_SOUL, MONSTER_PAIN, MONSTER_CYBER, MONSTER_SPIDER,
+ MONSTER_VILE, MONSTER_BARREL, MONSTER_ROBO: begin end;
+ // Îñòàëüíûõ ìîæíî âîñêðåñèòü
+ else mres := mon^;
+ end;
+ if (mres <> nil) then break;
+ end;
+ it.release();
+ if (mres <> nil) then result := mres.mArrIdx;
+ end
+ else
+ begin
+ for a := 0 to High(gMonsters) do
+ begin
+ 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,
MONSTER_VILE, MONSTER_BARREL, MONSTER_ROBO: Continue;
@@ -487,162 +827,171 @@ begin
Exit;
end;
end;
+ end;
+ end;
+ end;
end;
procedure g_Monsters_LoadData();
begin
- e_WriteLog('Loading monsters data...', MSG_NOTIFY);
+ e_WriteLog('Loading monsters data...', TMsgType.Notify);
- g_Game_SetLoadingText(_lc[I_LOAD_MONSTER_TEXTURES]+' 0%', 0, False);
+ g_Game_SetLoadingText(_lc[I_LOAD_MONSTER_TEXTURES], 133, False);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BARREL_SLEEP', GameWAD+':MTEXTURES\BARREL_SLEEP', 64, 64, 3);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BARREL_DIE', GameWAD+':MTEXTURES\BARREL_DIE', 64, 64, 4);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BARREL_PAIN', GameWAD+':MTEXTURES\BARREL_PAIN', 64, 64, 1);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_ZOMBY_SLEEP', GameWAD+':MTEXTURES\ZOMBY_SLEEP', 64, 64, 2);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_ZOMBY_GO', GameWAD+':MTEXTURES\ZOMBY_GO', 64, 64, 4);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_ZOMBY_DIE', GameWAD+':MTEXTURES\ZOMBY_DIE', 64, 64, 6);
- g_Game_SetLoadingText(_lc[I_LOAD_MONSTER_TEXTURES]+' 5%', 0, True);
+ g_Game_StepLoading(6);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_ZOMBY_MESS', GameWAD+':MTEXTURES\ZOMBY_MESS', 64, 64, 9);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_ZOMBY_ATTACK', GameWAD+':MTEXTURES\ZOMBY_ATTACK', 64, 64, 2);
+ g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_ZOMBY_ATTACK_L', GameWAD+':MTEXTURES\ZOMBY_ATTACK_L', 64, 64, 2);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_ZOMBY_PAIN', GameWAD+':MTEXTURES\ZOMBY_PAIN', 64, 64, 1);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SERG_SLEEP', GameWAD+':MTEXTURES\SERG_SLEEP', 64, 64, 2);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SERG_GO', GameWAD+':MTEXTURES\SERG_GO', 64, 64, 4);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SERG_DIE', GameWAD+':MTEXTURES\SERG_DIE', 64, 64, 5);
- g_Game_SetLoadingText(_lc[I_LOAD_MONSTER_TEXTURES]+' 10%', 0, True);
+ g_Game_StepLoading(13);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SERG_MESS', GameWAD+':MTEXTURES\SERG_MESS', 64, 64, 9);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SERG_ATTACK', GameWAD+':MTEXTURES\SERG_ATTACK', 64, 64, 2);
+ g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SERG_ATTACK_L', GameWAD+':MTEXTURES\SERG_ATTACK_L', 64, 64, 2);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SERG_PAIN', GameWAD+':MTEXTURES\SERG_PAIN', 64, 64, 1);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_MAN_SLEEP', GameWAD+':MTEXTURES\MAN_SLEEP', 64, 64, 2);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_MAN_GO', GameWAD+':MTEXTURES\MAN_GO', 64, 64, 4);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_MAN_DIE', GameWAD+':MTEXTURES\MAN_DIE', 64, 64, 7);
- g_Game_SetLoadingText(_lc[I_LOAD_MONSTER_TEXTURES]+' 15%', 0, True);
+ g_Game_StepLoading(20);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_MAN_MESS', GameWAD+':MTEXTURES\MAN_MESS', 64, 64, 9);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_MAN_ATTACK', GameWAD+':MTEXTURES\MAN_ATTACK', 64, 64, 2);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_MAN_PAIN', GameWAD+':MTEXTURES\MAN_PAIN', 64, 64, 1);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CGUN_SLEEP', GameWAD+':MTEXTURES\CGUN_SLEEP', 64, 64, 2);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CGUN_SLEEP_L', GameWAD+':MTEXTURES\CGUN_SLEEP_L', 64, 64, 2);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CGUN_GO', GameWAD+':MTEXTURES\CGUN_GO', 64, 64, 4);
- g_Game_SetLoadingText(_lc[I_LOAD_MONSTER_TEXTURES]+' 20%', 0, True);
+ g_Game_StepLoading(26);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CGUN_GO_L', GameWAD+':MTEXTURES\CGUN_GO_L', 64, 64, 4);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CGUN_DIE', GameWAD+':MTEXTURES\CGUN_DIE', 64, 64, 7);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CGUN_MESS', GameWAD+':MTEXTURES\CGUN_MESS', 64, 64, 6);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CGUN_ATTACK', GameWAD+':MTEXTURES\CGUN_ATTACK', 64, 64, 2);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CGUN_ATTACK_L', GameWAD+':MTEXTURES\CGUN_ATTACK_L', 64, 64, 2);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CGUN_PAIN', GameWAD+':MTEXTURES\CGUN_PAIN', 64, 64, 1);
- g_Game_SetLoadingText(_lc[I_LOAD_MONSTER_TEXTURES]+' 25%', 0, True);
+ g_Game_StepLoading(32);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CGUN_PAIN_L', GameWAD+':MTEXTURES\CGUN_PAIN_L', 64, 64, 1);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_IMP_SLEEP', GameWAD+':MTEXTURES\IMP_SLEEP', 64, 64, 2);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_IMP_GO', GameWAD+':MTEXTURES\IMP_GO', 64, 64, 4);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_IMP_DIE', GameWAD+':MTEXTURES\IMP_DIE', 64, 64, 5);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_IMP_MESS', GameWAD+':MTEXTURES\IMP_MESS', 64, 64, 8);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_IMP_ATTACK', GameWAD+':MTEXTURES\IMP_ATTACK', 64, 64, 3);
- g_Game_SetLoadingText(_lc[I_LOAD_MONSTER_TEXTURES]+' 30%', 0, True);
+ g_Game_StepLoading(38);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_IMP_PAIN', GameWAD+':MTEXTURES\IMP_PAIN', 64, 64, 1);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_DEMON_SLEEP', GameWAD+':MTEXTURES\DEMON_SLEEP', 64, 64, 2);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_DEMON_GO', GameWAD+':MTEXTURES\DEMON_GO', 64, 64, 4);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_DEMON_DIE', GameWAD+':MTEXTURES\DEMON_DIE', 64, 64, 6);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_DEMON_ATTACK', GameWAD+':MTEXTURES\DEMON_ATTACK', 64, 64, 3);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_DEMON_PAIN', GameWAD+':MTEXTURES\DEMON_PAIN', 64, 64, 1);
- g_Game_SetLoadingText(_lc[I_LOAD_MONSTER_TEXTURES]+' 35%', 0, True);
+ g_Game_StepLoading(44);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SOUL_SLEEP', GameWAD+':MTEXTURES\SOUL_SLEEP', 64, 64, 2);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SOUL_GO', GameWAD+':MTEXTURES\SOUL_GO', 64, 64, 2);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SOUL_PAIN', GameWAD+':MTEXTURES\SOUL_PAIN', 64, 64, 1);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SOUL_ATTACK', GameWAD+':MTEXTURES\SOUL_ATTACK', 64, 64, 2);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SOUL_DIE', GameWAD+':MTEXTURES\SOUL_DIE', 128, 128, 7);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_FISH_SLEEP', GameWAD+':MTEXTURES\FISH_SLEEP', 32, 32, 2);
- g_Game_SetLoadingText(_lc[I_LOAD_MONSTER_TEXTURES]+' 40%', 0, True);
+ g_Game_StepLoading(50);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_FISH_GO', GameWAD+':MTEXTURES\FISH_GO', 32, 32, 4);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_FISH_PAIN', GameWAD+':MTEXTURES\FISH_PAIN', 32, 32, 3);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_FISH_ATTACK', GameWAD+':MTEXTURES\FISH_ATTACK', 32, 32, 2);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_FISH_DIE', GameWAD+':MTEXTURES\FISH_DIE', 32, 32, 1);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SPIDER_SLEEP', GameWAD+':MTEXTURES\SPIDER_SLEEP', 256, 128, 2);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SPIDER_GO', GameWAD+':MTEXTURES\SPIDER_GO', 256, 128, 6);
- g_Game_SetLoadingText(_lc[I_LOAD_MONSTER_TEXTURES]+' 45%', 0, True);
+ g_Game_StepLoading(56);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SPIDER_PAIN', GameWAD+':MTEXTURES\SPIDER_PAIN', 256, 128, 1);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SPIDER_PAIN_L', GameWAD+':MTEXTURES\SPIDER_PAIN_L', 256, 128, 1);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SPIDER_ATTACK', GameWAD+':MTEXTURES\SPIDER_ATTACK', 256, 128, 2);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SPIDER_DIE', GameWAD+':MTEXTURES\SPIDER_DIE', 256, 128, 10);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BSP_SLEEP', GameWAD+':MTEXTURES\BSP_SLEEP', 128, 64, 2);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BSP_GO', GameWAD+':MTEXTURES\BSP_GO', 128, 64, 6);
- g_Game_SetLoadingText(_lc[I_LOAD_MONSTER_TEXTURES]+' 50%', 0, True);
+ g_Game_StepLoading(62);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BSP_PAIN', GameWAD+':MTEXTURES\BSP_PAIN', 128, 64, 1);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BSP_PAIN_L', GameWAD+':MTEXTURES\BSP_PAIN_L', 128, 64, 1);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BSP_ATTACK', GameWAD+':MTEXTURES\BSP_ATTACK', 128, 64, 2);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BSP_DIE', GameWAD+':MTEXTURES\BSP_DIE', 128, 64, 7);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CACO_SLEEP', GameWAD+':MTEXTURES\CACO_SLEEP', 128, 128, 1);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CACO_GO', GameWAD+':MTEXTURES\CACO_GO', 128, 128, 1);
- g_Game_SetLoadingText(_lc[I_LOAD_MONSTER_TEXTURES]+' 55%', 0, True);
+ g_Game_StepLoading(68);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CACO_PAIN', GameWAD+':MTEXTURES\CACO_PAIN', 128, 128, 1);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CACO_ATTACK', GameWAD+':MTEXTURES\CACO_ATTACK', 128, 128, 6);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CACO_DIE', GameWAD+':MTEXTURES\CACO_DIE', 128, 128, 7);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_PAIN_SLEEP', GameWAD+':MTEXTURES\PAIN_SLEEP', 128, 128, 4);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_PAIN_GO', GameWAD+':MTEXTURES\PAIN_GO', 128, 128, 4);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_PAIN_PAIN', GameWAD+':MTEXTURES\PAIN_PAIN', 128, 128, 1);
- g_Game_SetLoadingText(_lc[I_LOAD_MONSTER_TEXTURES]+' 60%', 0, True);
+ g_Game_StepLoading(74);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_PAIN_ATTACK', GameWAD+':MTEXTURES\PAIN_ATTACK', 128, 128, 4);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_PAIN_DIE', GameWAD+':MTEXTURES\PAIN_DIE', 128, 128, 7);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BARON_SLEEP', GameWAD+':MTEXTURES\BARON_SLEEP', 128, 128, 2);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BARON_SLEEP_L', GameWAD+':MTEXTURES\BARON_SLEEP_L', 128, 128, 2);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BARON_GO', GameWAD+':MTEXTURES\BARON_GO', 128, 128, 4);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BARON_PAIN', GameWAD+':MTEXTURES\BARON_PAIN', 128, 128, 1);
- g_Game_SetLoadingText(_lc[I_LOAD_MONSTER_TEXTURES]+' 65%', 0, True);
+ g_Game_StepLoading(80);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BARON_PAIN_L', GameWAD+':MTEXTURES\BARON_PAIN_L', 128, 128, 1);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BARON_ATTACK', GameWAD+':MTEXTURES\BARON_ATTACK', 128, 128, 3);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BARON_ATTACK_L', GameWAD+':MTEXTURES\BARON_ATTACK_L', 128, 128, 3);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_BARON_DIE', GameWAD+':MTEXTURES\BARON_DIE', 128, 128, 7);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_KNIGHT_SLEEP', GameWAD+':MTEXTURES\KNIGHT_SLEEP', 128, 128, 2);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_KNIGHT_SLEEP_L', GameWAD+':MTEXTURES\KNIGHT_SLEEP_L', 128, 128, 2);
- g_Game_SetLoadingText(_lc[I_LOAD_MONSTER_TEXTURES]+' 70%', 0, True);
+ g_Game_StepLoading(86);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_KNIGHT_GO', GameWAD+':MTEXTURES\KNIGHT_GO', 128, 128, 4);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_KNIGHT_PAIN', GameWAD+':MTEXTURES\KNIGHT_PAIN', 128, 128, 1);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_KNIGHT_PAIN_L', GameWAD+':MTEXTURES\KNIGHT_PAIN_L', 128, 128, 1);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_KNIGHT_ATTACK', GameWAD+':MTEXTURES\KNIGHT_ATTACK', 128, 128, 3);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_KNIGHT_ATTACK_L', GameWAD+':MTEXTURES\KNIGHT_ATTACK_L', 128, 128, 3);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_KNIGHT_DIE', GameWAD+':MTEXTURES\KNIGHT_DIE', 128, 128, 7);
- g_Game_SetLoadingText(_lc[I_LOAD_MONSTER_TEXTURES]+' 75%', 0, True);
+ g_Game_StepLoading(92);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_MANCUB_SLEEP', GameWAD+':MTEXTURES\MANCUB_SLEEP', 128, 128, 2);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_MANCUB_GO', GameWAD+':MTEXTURES\MANCUB_GO', 128, 128, 6);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_MANCUB_PAIN', GameWAD+':MTEXTURES\MANCUB_PAIN', 128, 128, 1);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_MANCUB_ATTACK', GameWAD+':MTEXTURES\MANCUB_ATTACK', 128, 128, 3);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_MANCUB_DIE', GameWAD+':MTEXTURES\MANCUB_DIE', 128, 128, 10);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SKEL_SLEEP', GameWAD+':MTEXTURES\SKEL_SLEEP', 128, 128, 2);
- g_Game_SetLoadingText(_lc[I_LOAD_MONSTER_TEXTURES]+' 80%', 0, True);
+ g_Game_StepLoading(98);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SKEL_SLEEP_L', GameWAD+':MTEXTURES\SKEL_SLEEP_L', 128, 128, 2);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SKEL_GO', GameWAD+':MTEXTURES\SKEL_GO', 128, 128, 6);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SKEL_PAIN', GameWAD+':MTEXTURES\SKEL_PAIN', 128, 128, 1);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SKEL_PAIN_L', GameWAD+':MTEXTURES\SKEL_PAIN_L', 128, 128, 1);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SKEL_ATTACK', GameWAD+':MTEXTURES\SKEL_ATTACK', 128, 128, 2);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SKEL_ATTACK_L', GameWAD+':MTEXTURES\SKEL_ATTACK_L', 128, 128, 2);
- g_Game_SetLoadingText(_lc[I_LOAD_MONSTER_TEXTURES]+' 85%', 0, True);
+ g_Game_StepLoading(104);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SKEL_ATTACK2', GameWAD+':MTEXTURES\SKEL_ATTACK2', 128, 128, 2);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SKEL_ATTACK2_L', GameWAD+':MTEXTURES\SKEL_ATTACK2_L', 128, 128, 2);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_SKEL_DIE', GameWAD+':MTEXTURES\SKEL_DIE', 128, 128, 5);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_VILE_SLEEP', GameWAD+':MTEXTURES\VILE_SLEEP', 128, 128, 2);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_VILE_SLEEP_L', GameWAD+':MTEXTURES\VILE_SLEEP_L', 128, 128, 2);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_VILE_GO', GameWAD+':MTEXTURES\VILE_GO', 128, 128, 6);
- g_Game_SetLoadingText(_lc[I_LOAD_MONSTER_TEXTURES]+' 90%', 0, True);
+ g_Game_StepLoading(110);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_VILE_PAIN', GameWAD+':MTEXTURES\VILE_PAIN', 128, 128, 1);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_VILE_PAIN_L', GameWAD+':MTEXTURES\VILE_PAIN_L', 128, 128, 1);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_VILE_ATTACK', GameWAD+':MTEXTURES\VILE_ATTACK', 128, 128, 10);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_VILE_ATTACK_L', GameWAD+':MTEXTURES\VILE_ATTACK_L', 128, 128, 10);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_VILE_ATTACK2', GameWAD+':MTEXTURES\VILE_ATTACK2', 128, 128, 3);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_VILE_ATTACK2_L', GameWAD+':MTEXTURES\VILE_ATTACK2_L', 128, 128, 3);
- g_Game_SetLoadingText(_lc[I_LOAD_MONSTER_TEXTURES]+' 95%', 0, True);
+ g_Game_StepLoading(116);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_VILE_DIE', GameWAD+':MTEXTURES\VILE_DIE', 128, 128, 9);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_ROBO_SLEEP', GameWAD+':MTEXTURES\ROBO_SLEEP', 128, 128, 1);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_ROBO_GO', GameWAD+':MTEXTURES\ROBO_GO', 128, 128, 12);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_ROBO_ATTACK', GameWAD+':MTEXTURES\ROBO_ATTACK', 128, 128, 2);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_ROBO_ATTACK2', GameWAD+':MTEXTURES\ROBO_ATTACK2', 128, 128, 4);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_ROBO_DIE', GameWAD+':MTEXTURES\ROBO_DIE', 128, 128, 1);
- g_Game_SetLoadingText(_lc[I_LOAD_MONSTER_TEXTURES]+' 100%', 0, True);
+ g_Game_StepLoading(122);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CYBER_SLEEP', GameWAD+':MTEXTURES\CYBER_SLEEP', 128, 128, 2);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CYBER_SLEEP_L', GameWAD+':MTEXTURES\CYBER_SLEEP_L', 128, 128, 2);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CYBER_GO', GameWAD+':MTEXTURES\CYBER_GO', 128, 128, 4);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CYBER_GO_L', GameWAD+':MTEXTURES\CYBER_GO_L', 128, 128, 4);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CYBER_PAIN', GameWAD+':MTEXTURES\CYBER_PAIN', 128, 128, 1);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CYBER_PAIN_L', GameWAD+':MTEXTURES\CYBER_PAIN_L', 128, 128, 1);
+ g_Game_StepLoading(128);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CYBER_ATTACK', GameWAD+':MTEXTURES\CYBER_ATTACK', 128, 128, 2);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CYBER_ATTACK_L', GameWAD+':MTEXTURES\CYBER_ATTACK_L', 128, 128, 2);
+ g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CYBER_ATTACK2', GameWAD+':MTEXTURES\CYBER_ATTACK2', 128, 128, 2);
+ g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CYBER_ATTACK2_L', GameWAD+':MTEXTURES\CYBER_ATTACK2_L', 128, 128, 2);
g_Frames_CreateWAD(nil, 'FRAMES_MONSTER_CYBER_DIE', GameWAD+':MTEXTURES\CYBER_DIE', 128, 128, 9);
+ g_Game_StepLoading(133);
g_Game_SetLoadingText(_lc[I_LOAD_MONSTER_SOUNDS], 0, False);
@@ -724,11 +1073,16 @@ begin
g_Sound_CreateWADEx('SOUND_MONSTER_SPIDER_WALK', GameWAD+':MSOUNDS\SPIDER_WALK');
g_Sound_CreateWADEx('SOUND_MONSTER_FISH_ATTACK', GameWAD+':MSOUNDS\FISH_ATTACK');
+
+ freeInds := TIdPool.Create();
+ clearUidMap();
+ monCheckTrapLastFrameId := 0;
+ monCheckMPlatLastFrameId := 0;
end;
procedure g_Monsters_FreeData();
begin
- e_WriteLog('Releasing monsters data...', MSG_NOTIFY);
+ e_WriteLog('Releasing monsters data...', TMsgType.Notify);
g_Frames_DeleteByName('FRAMES_MONSTER_BARREL_SLEEP');
g_Frames_DeleteByName('FRAMES_MONSTER_BARREL_PAIN');
@@ -738,12 +1092,14 @@ begin
g_Frames_DeleteByName('FRAMES_MONSTER_ZOMBY_DIE');
g_Frames_DeleteByName('FRAMES_MONSTER_ZOMBY_MESS');
g_Frames_DeleteByName('FRAMES_MONSTER_ZOMBY_ATTACK');
+ g_Frames_DeleteByName('FRAMES_MONSTER_ZOMBY_ATTACK_L');
g_Frames_DeleteByName('FRAMES_MONSTER_ZOMBY_PAIN');
g_Frames_DeleteByName('FRAMES_MONSTER_SERG_SLEEP');
g_Frames_DeleteByName('FRAMES_MONSTER_SERG_GO');
g_Frames_DeleteByName('FRAMES_MONSTER_SERG_DIE');
g_Frames_DeleteByName('FRAMES_MONSTER_SERG_MESS');
g_Frames_DeleteByName('FRAMES_MONSTER_SERG_ATTACK');
+ g_Frames_DeleteByName('FRAMES_MONSTER_SERG_ATTACK_L');
g_Frames_DeleteByName('FRAMES_MONSTER_SERG_PAIN');
g_Frames_DeleteByName('FRAMES_MONSTER_MAN_SLEEP');
g_Frames_DeleteByName('FRAMES_MONSTER_MAN_GO');
@@ -858,6 +1214,8 @@ begin
g_Frames_DeleteByName('FRAMES_MONSTER_CYBER_PAIN_L');
g_Frames_DeleteByName('FRAMES_MONSTER_CYBER_ATTACK');
g_Frames_DeleteByName('FRAMES_MONSTER_CYBER_ATTACK_L');
+ g_Frames_DeleteByName('FRAMES_MONSTER_CYBER_ATTACK2');
+ g_Frames_DeleteByName('FRAMES_MONSTER_CYBER_ATTACK2_L');
g_Frames_DeleteByName('FRAMES_MONSTER_CYBER_DIE');
g_Sound_Delete('SOUND_MONSTER_BARREL_DIE');
@@ -938,6 +1296,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();
@@ -945,60 +1306,86 @@ begin
soulcount := 0;
end;
-procedure g_Monsters_Free();
+procedure g_Monsters_Free (clearGrid: Boolean=true);
var
a: Integer;
begin
- if gMonsters <> nil then
- for a := 0 to High(gMonsters) do
- gMonsters[a].Free();
-
+ 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;
+
+// will be called from map loader
+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;
+
+
function g_Monsters_Create(MonsterType: Byte; X, Y: Integer;
- Direction: TDirection; AdjCoord: Boolean = False; ForcedUID: Integer = -1): Integer;
+ Direction: TDirection; AdjCoord: Boolean = False; ForcedUID: Integer = -1): TMonster;
var
find_id: DWORD;
+ mon: TMonster;
begin
- Result := -1;
+ result := nil;
-// Íåò òàêîãî ìîíñòðà:
- if (MonsterType > MONSTER_MAN) or (MonsterType = 0) then
- Exit;
+ // Íåò òàêîãî ìîíñòðà
+ if (MonsterType > MONSTER_MAN) or (MonsterType = 0) then exit;
-// Ñîáëþäàåì îãðàíè÷åíèå Lost_Soul'îâ:
+ // Ñîáëþäàåì îãðàíè÷åíèå Lost_Soul'îâ
if MonsterType = MONSTER_SOUL then
- if soulcount > MAX_SOUL then
- Exit
- else
- soulcount := soulcount + 1;
+ begin
+ if soulcount > MAX_SOUL then exit;
+ soulcount := soulcount + 1;
+ end;
- find_id := FindMonster();
+ find_id := allocMonster();
- gMonsters[find_id] := TMonster.Create(MonsterType, find_id, ForcedUID);
+ mon := TMonster.Create(MonsterType, find_id, ForcedUID);
+ gMonsters[find_id] := mon;
+ mon.mArrIdx := find_id;
+ mon.mProxyId := -1;
-// Íàñòðàèâàåì ïîëîæåíèå:
- with gMonsters[find_id] do
+ uidMap[mon.FUID] := mon;
+
+ // Íàñòðàèâàåì ïîëîæåíèå
+ with mon do
begin
if AdjCoord then
- begin
- FObj.X := X-FObj.Rect.X - (FObj.Rect.Width div 2);
- FObj.Y := Y-FObj.Rect.Y - FObj.Rect.Height;
- end
+ begin
+ FObj.X := X-FObj.Rect.X - (FObj.Rect.Width div 2);
+ FObj.Y := Y-FObj.Rect.Y - FObj.Rect.Height;
+ end
else
- begin
- FObj.X := X-FObj.Rect.X;
- FObj.Y := Y-FObj.Rect.Y;
- end;
+ begin
+ FObj.X := X-FObj.Rect.X;
+ FObj.Y := Y-FObj.Rect.Y;
+ end;
FDirection := Direction;
FStartDirection := Direction;
FStartX := GameX;
FStartY := GameY;
+ FObj.oldX := FObj.X;
+ FObj.oldY := FObj.Y;
end;
- Result := find_id;
+ mon.positionChanged();
+
+ result := mon;
end;
procedure g_Monsters_killedp();
@@ -1008,53 +1395,72 @@ 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_PreUpdate();
+var
+ a: Integer;
+begin
+ if gMonsters = nil then Exit;
+ for a := 0 to High(gMonsters) do
+ if (gMonsters[a] <> nil) and (not gMonsters[a].FRemoved) then
+ gMonsters[a].PreUpdate();
end;
procedure g_Monsters_Update();
var
a: Integer;
begin
-// Öåëåóêàçàòåëü:
+ // Öåëåóêàçàòåëü
if gTime mod (GAME_TICK*2) = 0 then
begin
pt_x := pt_x+pt_xs;
pt_y := pt_y+pt_ys;
- if Abs(pt_x) > 246 then
- pt_xs := -pt_xs;
- if Abs(pt_y) > 100 then
- pt_ys := -pt_ys;
+ if abs(pt_x) > 246 then pt_xs := -pt_xs;
+ if abs(pt_y) > 100 then pt_ys := -pt_ys;
end;
gMon := True; // Äëÿ ðàáîòû BlockMon'à
- if gMonsters <> nil then
+ if gmon_debug_think or gmon_debug_one_think_step then
+ begin
+ gmon_debug_one_think_step := false;
for a := 0 to High(gMonsters) do
- if (gMonsters[a] <> nil) then
- if not gMonsters[a].FRemoved then
- begin
- if g_Game_IsClient then
- gMonsters[a].ClientUpdate()
- else
- gMonsters[a].Update();
- end
+ begin
+ if (gMonsters[a] = nil) then continue;
+ if not gMonsters[a].FRemoved then
+ begin
+ if g_Game_IsClient then
+ gMonsters[a].ClientUpdate()
else
- begin
- gMonsters[a].Free();
- gMonsters[a] := nil;
- end;
+ gMonsters[a].Update();
+ end
+ else
+ begin
+ gMonsters[a].Free();
+ gMonsters[a] := nil;
+ end;
+ end;
+ end;
gMon := False;
end;
@@ -1064,9 +1470,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();
@@ -1078,145 +1487,179 @@ 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_Get(UID: Word): TMonster;
-var
- a: Integer;
+function g_Monsters_ByUID (UID: Word): TMonster;
begin
- 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;
+ result := uidMap[UID];
end;
-procedure g_Monsters_SaveState(var Mem: TBinMemoryWriter);
+procedure g_Monsters_SaveState (st: TStream);
var
count, i: Integer;
- b: Byte;
begin
-// Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ ìîíñòðîâ:
+ // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ ìîíñòðîâ
count := 0;
- if gMonsters <> nil then
- for i := 0 to High(gMonsters) do
- if gMonsters[i] <> nil then
- if gMonsters[i].FMonsterType <> MONSTER_NONE then
- count := count + 1;
-
- Mem := TBinMemoryWriter.Create((count+1) * 350);
+ for i := 0 to High(gMonsters) do
+ begin
+ if (gMonsters[i] <> nil) and (gMonsters[i].FMonsterType <> MONSTER_NONE) then count += 1;
+ end;
-// Ñîõðàíÿåì èíôîðìàöèþ öåëåóêàçàòåëÿ:
- Mem.WriteInt(pt_x);
- Mem.WriteInt(pt_xs);
- Mem.WriteInt(pt_y);
- Mem.WriteInt(pt_ys);
+ // Ñîõðàíÿåì èíôîðìàöèþ öåëåóêàçàòåëÿ
+ utils.writeInt(st, LongInt(pt_x));
+ utils.writeInt(st, LongInt(pt_xs));
+ utils.writeInt(st, LongInt(pt_y));
+ utils.writeInt(st, LongInt(pt_ys));
-// Êîëè÷åñòâî ìîíñòðîâ:
- Mem.WriteInt(count);
+ // Êîëè÷åñòâî ìîíñòðîâ
+ utils.writeInt(st, LongInt(count));
- if count = 0 then
- Exit;
+ if (count = 0) then exit;
-// Ñîõðàíÿåì ìîíñòðîâ:
+ // Ñîõðàíÿåì ìîíñòðîâ
for i := 0 to High(gMonsters) do
- if gMonsters[i] <> nil then
- if gMonsters[i].FMonsterType <> MONSTER_NONE then
- begin
- // Òèï ìîíñòðà:
- b := gMonsters[i].MonsterType;
- Mem.WriteByte(b);
+ begin
+ if (gMonsters[i] <> nil) and (gMonsters[i].FMonsterType <> MONSTER_NONE) then
+ begin
+ // Òèï ìîíñòðà
+ utils.writeInt(st, Byte(gMonsters[i].MonsterType));
// Ñîõðàíÿåì äàííûå ìîíñòðà:
- gMonsters[i].SaveState(Mem);
- end;
+ gMonsters[i].SaveState(st);
+ end;
+ end;
+end;
+
+
+procedure g_Monsters_LoadState (st: TStream);
+var
+ count, a: Integer;
+ b: Byte;
+ mon: TMonster;
+begin
+ assert(st <> nil);
+
+ g_Monsters_Free(false);
+
+ // Çàãðóæàåì èíôîðìàöèþ öåëåóêàçàòåëÿ
+ pt_x := utils.readLongInt(st);
+ pt_xs := utils.readLongInt(st);
+ pt_y := utils.readLongInt(st);
+ pt_ys := utils.readLongInt(st);
+
+ // Êîëè÷åñòâî ìîíñòðîâ
+ count := utils.readLongInt(st);
+
+ if (count = 0) then exit;
+ if (count < 0) or (count > 1024*1024) then raise XStreamError.Create('invalid monster count');
+
+ // Çàãðóæàåì ìîíñòðîâ
+ for a := 0 to count-1 do
+ begin
+ // Òèï ìîíñòðà
+ b := utils.readByte(st);
+ // Ñîçäàåì ìîíñòðà
+ mon := g_Monsters_Create(b, 0, 0, TDirection.D_LEFT);
+ if (mon = nil) then raise XStreamError.Create('g_Monsters_LoadState: ID = -1 (can''t create)');
+ // Çàãðóæàåì äàííûå ìîíñòðà
+ mon.LoadState(st);
+ end;
+end;
+
+
+// ////////////////////////////////////////////////////////////////////////// //
+function g_Mons_SpawnAt (monType: Integer; x, y: Integer; dir: TDirection=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;
-procedure g_Monsters_LoadState(var Mem: TBinMemoryReader);
-var
- count, i, a: Integer;
- b: Byte;
-begin
- if Mem = nil then
- Exit;
- g_Monsters_Free();
+function g_Mons_SpawnAt (const typeName: AnsiString; x, y: Integer; dir: TDirection=TDirection.D_LEFT): TMonster; overload;
+begin
+ result := g_Mons_SpawnAt(g_Mons_TypeIdByName(typeName), x, y, dir);
+end;
-// Çàãðóæàåì èíôîðìàöèþ öåëåóêàçàòåëÿ:
- Mem.ReadInt(pt_x);
- Mem.ReadInt(pt_xs);
- Mem.ReadInt(pt_y);
- Mem.ReadInt(pt_ys);
-// Êîëè÷åñòâî ìîíñòðîâ:
- Mem.ReadInt(count);
- if count = 0 then
- Exit;
+// ////////////////////////////////////////////////////////////////////////// //
+function g_Mons_TypeLo (): Integer; inline; begin result := Low(MONSTERTABLE); end;
+function g_Mons_TypeHi (): Integer; inline; begin result := High(MONSTERTABLE); end;
-// Çàãðóæàåì ìîíñòðîâ:
- for a := 0 to count-1 do
- begin
- // Òèï ìîíñòðà:
- Mem.ReadByte(b);
- // Ñîçäàåì ìîíñòðà:
- i := g_Monsters_Create(b, 0, 0, D_LEFT);
- if i < 0 then
- begin
- raise EBinSizeError.Create('g_Monsters_LoadState: ID = -1 (Can''t create)');
- end;
- // Çàãðóæàåì äàííûå ìîíñòðà:
- gMonsters[i].LoadState(Mem);
- end;
-end;
-function g_Monsters_GetIDByName(name: String): Integer;
+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.doDamage (v: Integer);
+begin
+ if (v <= 0) then exit;
+ if (v > 32767) then v := 32767;
+ Damage(v, 0, 0, 0, mEDamageType);
+end;
+
procedure TMonster.ActionSound();
begin
case FMonsterType of
@@ -1248,6 +1691,7 @@ begin
Exit;
FPainSound := True;
+ FPainTicks := 20;
case FMonsterType of
MONSTER_IMP, MONSTER_ZOMBY, MONSTER_SERG,
@@ -1255,7 +1699,7 @@ begin
g_Sound_PlayExAt('SOUND_MONSTER_PAIN', FObj.X, FObj.Y);
MONSTER_SOUL, MONSTER_BARON, MONSTER_CACO,
MONSTER_KNIGHT, MONSTER_DEMON, MONSTER_SPIDER,
- MONSTER_CYBER:
+ MONSTER_BSP, MONSTER_CYBER:
g_Sound_PlayExAt('SOUND_MONSTER_PAIN2', FObj.X, FObj.Y);
MONSTER_VILE:
g_Sound_PlayExAt('SOUND_MONSTER_VILE_PAIN', FObj.X, FObj.Y);
@@ -1404,8 +1848,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;
@@ -1417,9 +1861,11 @@ begin
FChainFire := False;
FShellTimer := -1;
- FState := STATE_SLEEP;
+ FState := MONSTATE_SLEEP;
FCurAnim := ANIM_SLEEP;
+ positionChanged(); // this updates spatial accelerators
+
if g_Game_IsNet and g_Game_IsServer then
begin
MH_SEND_MonsterPos(FUID);
@@ -1430,7 +1876,7 @@ end;
constructor TMonster.Create(MonsterType: Byte; aID: Integer; ForcedUID: Integer = -1);
var
a: Integer;
- FramesID: DWORD;
+ FramesID: DWORD = 0;
s: String;
res: Boolean;
begin
@@ -1443,7 +1889,7 @@ begin
g_Obj_Init(@FObj);
- FState := STATE_SLEEP;
+ FState := MONSTATE_SLEEP;
FCurAnim := ANIM_SLEEP;
FHealth := MONSTERTABLE[MonsterType].Health;
FMaxHealth := FHealth;
@@ -1456,6 +1902,16 @@ begin
FNoRespawn := False;
FShellTimer := -1;
FBehaviour := BH_NORMAL;
+ FFireTime := 0;
+ FFirePainTime := 0;
+ FFireAttacker := 0;
+ mEDamageType := HIT_SOME;
+
+ mProxyId := -1;
+ mArrIdx := -1;
+ trapCheckFrameId := 0;
+ mplatCheckFrameId := 0;
+ mNeedSend := false;
if FMonsterType in [MONSTER_ROBO, MONSTER_BARREL] then
FBloodKind := BLOOD_SPARKS
@@ -1484,8 +1940,8 @@ begin
for a := 0 to High(FAnim) do
begin
- FAnim[a, D_LEFT] := nil;
- FAnim[a, D_RIGHT] := nil;
+ FAnim[a, TDirection.D_LEFT] := nil;
+ FAnim[a, TDirection.D_RIGHT] := nil;
end;
for a := ANIM_SLEEP to ANIM_PAIN do
@@ -1510,15 +1966,15 @@ begin
if g_Frames_Get(FramesID, 'FRAMES_MONSTER_'+MONSTERTABLE[MonsterType].Name+
'_'+ANIMTABLE[ANIM_DIE].name) then
begin
- FAnim[a, D_RIGHT] := TAnimation.Create(FramesID, ANIMTABLE[ANIM_DIE].loop,
+ FAnim[a, TDirection.D_RIGHT] := TAnimation.Create(FramesID, ANIMTABLE[ANIM_DIE].loop,
MONSTER_ANIMTABLE[MonsterType].AnimSpeed[ANIM_DIE]);
- FAnim[a, D_LEFT] := TAnimation.Create(FramesID, ANIMTABLE[ANIM_DIE].loop,
+ FAnim[a, TDirection.D_LEFT] := TAnimation.Create(FramesID, ANIMTABLE[ANIM_DIE].loop,
MONSTER_ANIMTABLE[MonsterType].AnimSpeed[ANIM_DIE]);
Continue;
end;
end;
- FAnim[a, D_RIGHT] := TAnimation.Create(FramesID, ANIMTABLE[a].loop,
+ FAnim[a, TDirection.D_RIGHT] := TAnimation.Create(FramesID, ANIMTABLE[a].loop,
MONSTER_ANIMTABLE[MonsterType].AnimSpeed[a]);
// Åñëè åñòü îòäåëüíàÿ ëåâàÿ àíèìàöèÿ - çàãðóæàåì:
@@ -1530,7 +1986,7 @@ begin
g_Frames_Get(FramesID, s);
end;
- FAnim[a, D_LEFT] := TAnimation.Create(FramesID, ANIMTABLE[a].loop,
+ FAnim[a, TDirection.D_LEFT] := TAnimation.Create(FramesID, ANIMTABLE[a].loop,
MONSTER_ANIMTABLE[MonsterType].AnimSpeed[a]);
end;
@@ -1544,27 +2000,36 @@ begin
vilefire := nil;
end;
-function TMonster.Damage(Damage: Word; VelX, VelY: Integer; SpawnerUID: Word; t: Byte): Boolean;
+function TMonster.Damage(aDamage: Word; VelX, VelY: Integer; SpawnerUID: Word; t: Byte): Boolean;
var
c, it: Integer;
p: TPlayer;
begin
Result := False;
+// Ìîíñòð ñòàòè÷åí ïîêà èäåò warmup
+ if (gLMSRespawn > LMS_RESPAWN_NONE) then exit;
+
// Óìèðàåò, óìåð èëè âîñêðåøàåòñÿ => óðîí äåëàòü íåêîìó:
- 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;
// Ðûáó â âîäå áüåò òîêîì => ïàíèêà áåç óðîíà:
if (t = HIT_ELECTRO) and (FMonsterType = MONSTER_FISH) and g_Game_IsServer then
begin
FSleep := 20;
- if Random(2) = 0 then
- FDirection := D_RIGHT
- else
- FDirection := D_LEFT;
+ if Random(2) = 0 then FDirection := TDirection.D_RIGHT else FDirection := TDirection.D_LEFT;
Result := True;
- SetState(STATE_RUN);
+ SetState(MONSTATE_RUN);
+ Exit;
+ end;
+
+// Àð÷è íå ãîðÿò, ÷åðåïà óæå ãîðÿò
+ if (t = HIT_FLAME) and (FMonsterType in [MONSTER_VILE, MONSTER_SOUL]) then
+ begin
+ // Ïðîñíóòüñÿ âñå-òàêè ñòîèò
+ if FState = MONSTATE_SLEEP then
+ SetState(MONSTATE_GO);
Exit;
end;
@@ -1574,27 +2039,27 @@ begin
// Ðîáîòó óðîíà íåò:
if FMonsterType = MONSTER_ROBO then
- Damage := 0;
+ aDamage := 0;
// Íàíîñèì óðîí:
- if g_Game_IsServer then Dec(FHealth, Damage);
+ if g_Game_IsServer then Dec(FHealth, aDamage);
// Óñèëèâàåì áîëü ìîíñòðà îò óðîíà:
if FPain = 0 then
FPain := 3;
- FPain := FPain+Damage;
+ 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
begin
- c := Min(Damage, 200);
- c := c*gBloodCount - (Damage div 4) + Random(c div 2);
+ c := Min(aDamage, 200);
+ c := c*gBloodCount - (aDamage div 4) + Random(c div 2);
if (VelX = 0) and (VelY = 0) then
MakeBloodSimple(c)
@@ -1606,8 +2071,7 @@ begin
end;
// Òåïåðü öåëü - óäàðèâøèé, åñëè òîëüêî íå ñàì ñåáÿ:
- if (SpawnerUID <> FUID) and
- (BehaviourDamage(SpawnerUID, FBehaviour, FMonsterType)) then
+ if (SpawnerUID <> FUID) and (BehaviourDamage(SpawnerUID, FBehaviour, FMonsterType)) then
begin
FTargetUID := SpawnerUID;
FTargetTime := 0;
@@ -1654,8 +2118,10 @@ begin
it := g_Items_Create(FObj.X + (FObj.Rect.Width div 2),
FObj.Y + (FObj.Rect.Height div 2),
c, True, False);
- g_Obj_Push(@gItems[it].Obj, (FObj.Vel.X div 2)-3+Random(7),
- (FObj.Vel.Y div 2)-Random(4));
+ g_Items_SetDrop(it); // mark it as monster drop
+ g_Obj_Push(g_Items_ObjByIdx(it), (FObj.Vel.X div 2)-3+Random(7),
+ (FObj.Vel.Y div 2)-Random(4));
+ //positionChanged(); // this updates spatial accelerators
if g_Game_IsServer and g_Game_IsNet then
MH_SEND_ItemSpawn(True, it);
end;
@@ -1668,6 +2134,7 @@ begin
begin
FObj.Rect.Y := FObj.Rect.Y + FObj.Rect.Height-12;
FObj.Rect.Height := 12;
+ positionChanged();
end;
// Óðîí áûë ñèëüíûì => ñëàáûå - â êàøó:
@@ -1677,12 +2144,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;
// Àêòèâèðîâàòü òðèããåðû, æäóùèå ñìåðòè ýòîãî ìîíñòðà:
@@ -1691,10 +2158,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);
@@ -1706,14 +2173,13 @@ begin
Result := False;
if g_Game_IsClient then
Exit;
- if not Live then
+ if not alive then
Exit;
if FHealth < FMaxHealth then
begin
IncMax(FHealth, Value, FMaxHealth);
- if g_Game_IsServer and g_Game_IsNet then
- MH_SEND_MonsterState(FUID);
+ if g_Game_IsServer and g_Game_IsNet then MH_SEND_MonsterState(FUID);
Result := True;
end;
end;
@@ -1724,38 +2190,65 @@ var
begin
for a := 0 to High(FAnim) do
begin
- FAnim[a, D_LEFT].Free();
- FAnim[a, D_RIGHT].Free();
+ FAnim[a, TDirection.D_LEFT].Free();
+ FAnim[a, TDirection.D_RIGHT].Free();
end;
vilefire.Free();
+ if (mProxyId <> -1) then
+ begin
+ if (monsGrid <> nil) then
+ begin
+ monsGrid.removeBody(mProxyId);
+ {$IF DEFINED(D2F_DEBUG_MONS_MOVE)}
+ 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
+ begin
+ freeInds.release(mArrIdx);
+ gMonsters[mArrIdx] := nil;
+ end;
+ mArrIdx := -1;
+
+ uidMap[FUID] := nil;
+
inherited Destroy();
end;
procedure TMonster.Draw();
var
m: TMirrorType;
- dx, dy, c: Integer;
+ dx, dy, c, fX, fY: Integer;
o: TObj;
begin
//e_CharFont_Print(gMenuSmallFont, Obj.X+Obj.Rect.X, Obj.Y+Obj.Rect.Y, 'TYPE: '+IntToStr(FMonsterType));
//e_CharFont_Print(gMenuSmallFont, Obj.X+Obj.Rect.X, Obj.Y+Obj.Rect.Y+16, 'STATE: '+IntToStr(FState));
+ FObj.lerp(gLerpFactor, fX, fY);
+
// Åñëè êîëäóí ñòðåëÿåò, òî ðèñóåì îãîíü:
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);
+ o.Y+o.Rect.Y+o.Rect.Height-128, TMirrorType.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;
+//FIXME!
+ 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 = STATE_DEAD then
+ if FState = MONSTATE_DEAD then
case FMonsterType of
MONSTER_BARREL, MONSTER_SOUL, MONSTER_PAIN: Exit;
end;
@@ -1764,22 +2257,22 @@ begin
if FAnim[FCurAnim, FDirection] <> nil then
begin
// Åñëè íåò ëåâîé àíèìàöèè èëè îíà ñîâïàäàåò ñ ïðàâîé => îòðàæàåì ïðàâóþ:
- if (FDirection = D_LEFT) and
+ if (FDirection = TDirection.D_LEFT) and
((not MONSTER_ANIMTABLE[FMonsterType].LeftAnim) or
- (FAnim[FCurAnim, D_LEFT].FramesID = FAnim[FCurAnim, D_RIGHT].FramesID)) and
+ (FAnim[FCurAnim, TDirection.D_LEFT].FramesID = FAnim[FCurAnim, TDirection.D_RIGHT].FramesID)) and
(FMonsterType <> MONSTER_BARREL) then
- m := M_HORIZONTAL
+ m := TMirrorType.Horizontal
else
- m := M_NONE;
+ m := TMirrorType.None;
// Ëåâàÿ àíèìàöèÿ => ìåíÿåì ñìåùåíèå îòíîñèòåëüíî öåíòðà:
- if (FDirection = D_LEFT) and
+ if (FDirection = TDirection.D_LEFT) and
(FMonsterType <> MONSTER_BARREL) then
begin
dx := MONSTER_ANIMTABLE[FMonsterType].AnimDeltaLeft[FCurAnim].X;
dy := MONSTER_ANIMTABLE[FMonsterType].AnimDeltaLeft[FCurAnim].Y;
- if m = M_HORIZONTAL then
+ if m = TMirrorType.Horizontal then
begin // Íåò îòäåëüíîé ëåâîé àíèìàöèè
// Ðàññòîÿíèå îò êðàÿ òåêñòóðû äî êðàÿ âèçóàëüíîãî ïîëîæåíèÿ îáúåêòà íà òåêñòóðå:
c := (MONSTERTABLE[FMonsterType].Rect.X - dx) + MONSTERTABLE[FMonsterType].Rect.Width;
@@ -1797,7 +2290,7 @@ begin
end;
// Ðèñóåì:
- FAnim[FCurAnim, FDirection].Draw(Obj.X+dx, Obj.Y+dy, m);
+ FAnim[FCurAnim, FDirection].Draw(fX+dx, fY+dy, m);
end;
if g_debug_Frames then
@@ -1834,8 +2327,7 @@ procedure TMonster.Push(vx, vy: Integer);
begin
FObj.Accel.X := FObj.Accel.X + vx;
FObj.Accel.Y := FObj.Accel.Y + vy;
- if g_Game_IsServer and g_Game_IsNet then
- MH_SEND_MonsterPos(FUID);
+ if g_Game_IsServer and g_Game_IsNet then MH_SEND_MonsterPos(FUID);
end;
procedure TMonster.SetState(State: Byte; ForceAnim: Byte = 255);
@@ -1844,14 +2336,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;
@@ -1862,14 +2354,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);
@@ -1930,19 +2422,22 @@ begin
FObj.X := X - FObj.Rect.X;
FObj.Y := Y - FObj.Rect.Y;
+ FObj.oldX := FObj.X; // don't interpolate after teleport
+ FObj.oldY := FObj.Y;
+ positionChanged();
if dir = 1 then
- FDirection := D_LEFT
+ FDirection := TDirection.D_LEFT
else
if dir = 2 then
- FDirection := D_RIGHT
+ FDirection := TDirection.D_RIGHT
else
if dir = 3 then
begin // îáðàòíîå
- if FDirection = D_RIGHT then
- FDirection := D_LEFT
+ if FDirection = TDirection.D_RIGHT then
+ FDirection := TDirection.D_LEFT
else
- FDirection := D_RIGHT;
+ FDirection := TDirection.D_RIGHT;
end;
// Ýôôåêò òåëåïîðòà â òî÷êå íàçíà÷åíèÿ:
@@ -1958,54 +2453,80 @@ begin
NET_GFX_TELE);
end;
- if g_Game_IsServer and g_Game_IsNet then
- MH_SEND_MonsterPos(FUID);
+ if g_Game_IsServer and g_Game_IsNet then MH_SEND_MonsterPos(FUID);
Result := True;
end;
+procedure TMonster.PreUpdate();
+begin
+ FObj.oldX := FObj.X;
+ FObj.oldY := FObj.Y;
+end;
+
procedure TMonster.Update();
var
a, b, sx, sy, wx, wy, oldvelx: Integer;
st: Word;
o, co: TObj;
- fall: Boolean;
+ fall, bubbles: Boolean;
+ mon: TMonster;
+ mit: PMonster;
+ it: TMonsterGrid.Iter;
label
_end;
begin
fall := True;
+ bubbles := True;
+
+// Ìîíñòð ñòàòè÷åí ïîêà èäåò warmup
+ if (gLMSRespawn > LMS_RESPAWN_NONE) then exit;
// Ðûáû "ëåòàþò" òîëüêî â âîäå:
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;
// Ìåíÿåì ñêîðîñòü òîëüêî ïî ÷åòíûì êàäðàì:
if gTime mod (GAME_TICK*2) <> 0 then
begin
g_Obj_Move(@FObj, fall, True, True);
+ positionChanged(); // this updates spatial accelerators
Exit;
end;
- FPainSound := False;
+ if FPainTicks > 0 then
+ Dec(FPainTicks)
+ else
+ FPainSound := False;
// Äâèãàåìñÿ:
st := g_Obj_Move(@FObj, fall, True, True);
+ positionChanged(); // this updates spatial accelerators
+
+// Åñëè ãîðèì - ïîäæèãàåì äðóãèõ ìîíñòðîâ, íî íå íà 100 òèêîâ êàæäûé ðàç:
+ if FFireTime > 0 then
+ begin
+ it := monsGrid.forEachInAABB(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, FObj.Rect.Width, FObj.Rect.Height);
+ for mit in it do
+ if mit.UID <> FUID then
+ mit.CatchFire(FFireAttacker, FFireTime);
+ end;
// Âûëåòåë çà êàðòó - óäàëÿåì è çàïóñêàåì òðèããåðû:
if WordBool(st and MOVE_FALLOUT) or (FObj.X < -1000) or
(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
@@ -2018,45 +2539,64 @@ 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
+ begin
+ if WordBool(st and MOVE_INWATER) then
+ FFireTime := 0
+ else
+ begin
+ OnFireFlame(1);
+ FFireTime := FFireTime - 1;
+ if (FState <> MONSTATE_DIE) and (FState <> MONSTATE_DEAD) then
+ if FFirePainTime = 0 then
+ begin
+ Damage(5, FFireAttacker, 0, 0, HIT_FLAME);
+ FFirePainTime := 18;
+ end
+ else
+ FFirePainTime := FFirePainTime - 1;
+ end;
+ 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;
// Âîçìîæíî, ñîçäàåì ïóçûðüêè â âîäå:
if WordBool(st and MOVE_INWATER) and (Random(32) = 0) then
+ begin
case FMonsterType of
MONSTER_FISH:
- if Random(4) = 0 then
+ if Random(4) <> 0 then bubbles := False else
g_GFX_Bubbles(FObj.X+FObj.Rect.X + Random(FObj.Rect.Width),
FObj.Y+FObj.Rect.Y + Random(4), 1, 0, 0);
MONSTER_ROBO, MONSTER_BARREL:
g_GFX_Bubbles(FObj.X+FObj.Rect.X + Random(FObj.Rect.Width),
FObj.Y+FObj.Rect.Y + Random(4), 1, 0, 0);
- else begin
+ else
g_GFX_Bubbles(FObj.X+FObj.Rect.X + Random(FObj.Rect.Width-4),
FObj.Y+FObj.Rect.Y + Random(4), 5, 4, 4);
- if Random(2) = 0 then
- g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj.X, FObj.Y)
- else
- g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj.X, FObj.Y);
- end;
end;
+ if bubbles then if Random(2) = 0
+ then g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj.X, FObj.Y)
+ else g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj.X, FObj.Y);
+ end;
// Åñëè ïðîøåë ïåðâûé êàäð àíèìàöèè âçðûâà áî÷êè, òî âçðûâ:
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,
@@ -2101,8 +2641,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
@@ -2110,7 +2650,7 @@ begin
FObj.Vel.Y := -MONSTERTABLE[FMonsterType].Jump;
case FState of
- STATE_PAIN: // Ñîñòîÿíèå - Áîëü
+ MONSTATE_PAIN: // Ñîñòîÿíèå - Áîëü
begin
// Áîëü ñèëüíàÿ => ìîíñòð êðè÷èò:
if FPain >= MONSTERTABLE[FMonsterType].Pain then
@@ -2118,6 +2658,8 @@ begin
FPain := MONSTERTABLE[FMonsterType].Pain;
if gSoundEffectsDF then PainSound();
end;
+ if (not gSoundEffectsDF) and (FPain >= MONSTERTABLE[FMonsterType].MinPain) then
+ PainSound();
// Ñíèæàåì áîëü ñî âðåìåíåì:
FPain := FPain - 5;
@@ -2127,11 +2669,11 @@ begin
begin
FPain := 0;
FAmmo := -9;
- SetState(STATE_GO);
+ SetState(MONSTATE_GO);
end;
end;
- STATE_SLEEP: // Ñîñòîÿíèå - Ñîí
+ MONSTATE_SLEEP: // Ñîñòîÿíèå - Ñîí
begin
// Ñïèì:
FSleep := FSleep + 1;
@@ -2147,7 +2689,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
@@ -2155,7 +2697,7 @@ begin
FTargetUID := gPlayers[a].UID;
FTargetTime := 0;
WakeUpSound();
- SetState(STATE_GO);
+ SetState(MONSTATE_GO);
Break;
end;
@@ -2165,7 +2707,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
// Ìàíüÿêè íàïàäàþò íà âñåõ ìîíñòðîâ, êðîìå äðóçåé
@@ -2184,30 +2726,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;
@@ -2217,7 +2759,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;
@@ -2242,8 +2784,11 @@ begin
if g_Obj_Collide(@FObj, @o) and (FTargetUID <> 0) then
begin
FTargetTime := 0;
- if kick(@o) then
- goto _end;
+ if (FMonsterType <> MONSTER_CYBER) or (Random(2) = 0) then
+ begin
+ if kick(@o) then
+ goto _end;
+ end;
end;
// Ðàññòîÿíèå äî öåëè:
@@ -2252,9 +2797,9 @@ begin
// Ïîâîðà÷èâàåìñÿ â ñòîðîíó öåëè:
if sx > 0 then
- FDirection := D_RIGHT
+ FDirection := TDirection.D_RIGHT
else
- FDirection := D_LEFT;
+ FDirection := TDirection.D_LEFT;
// Åñëè ìîíñòð óìååò ñòðåëÿòü è åñòü ïî êîìó - ñòðåëÿåì:
if canShoot(FMonsterType) and (FTargetUID <> 0) then
@@ -2267,11 +2812,11 @@ begin
if FMonsterType <> MONSTER_FISH then
begin
FSleep := 15;
- SetState(STATE_RUN);
+ SetState(MONSTATE_RUN);
if Random(2) = 0 then
- FDirection := D_LEFT
+ FDirection := TDirection.D_LEFT
else
- FDirection := D_RIGHT;
+ FDirection := TDirection.D_RIGHT;
goto _end;
end;
@@ -2283,7 +2828,7 @@ begin
FObj.Rect.Height, FUID, ACTIVATE_MONSTERPRESS) <> nil then
begin // Ñìîãëè íàæàòü êíîïêó - íåáîëüøîå îæèäàíèå
FSleep := 4;
- SetState(STATE_WAIT);
+ SetState(MONSTATE_WAIT);
goto _end;
end;
@@ -2296,7 +2841,7 @@ begin
begin // Ñòîèì íà òâåðäîì ïîëó èëè ñòóïåíè
// Ïðûæîê ÷åðåç ñòåíó:
FObj.Vel.Y := -MONSTERTABLE[FMonsterType].Jump;
- SetState(STATE_CLIMB);
+ SetState(MONSTATE_CLIMB);
end;
end;
@@ -2314,13 +2859,12 @@ begin
if g_Obj_CollideLevel(@FObj, 0, 1) or g_Obj_StayOnStep(@FObj) then
begin // "Ñòîèò" òâåðäî
// Ðûáà òðåïûõàåòñÿ íà ïîâåðõíîñòè:
- if FObj.Accel.Y = 0 then
- FObj.Vel.Y := -6;
+ if FObj.Accel.Y = 0 then FObj.Vel.Y := -6;
FObj.Accel.X := FObj.Accel.X - 8 + Random(17);
end;
// Ðûáå áîëüíî:
- SetState(STATE_PAIN);
+ SetState(MONSTATE_PAIN);
FPain := FPain + 50;
end
else // Ðûáà â âîäå
@@ -2333,17 +2877,17 @@ begin
// Ðûáà ïëûâåò ââåðõ:
if FObj.Vel.Y < 0 then
- if not g_Obj_CollideWater(@FObj, 0, -16) then
+ if not g_Obj_CollideLiquid(@FObj, 0, -16) then
begin
// Âñïëûëè äî ïîâåðõíîñòè - ñòîï:
FObj.Vel.Y := 0;
// Ïëàâàåì òóäà-ñþäà:
if Random(2) = 0 then
- FDirection := D_LEFT
+ FDirection := TDirection.D_LEFT
else
- FDirection := D_RIGHT;
+ FDirection := TDirection.D_RIGHT;
FSleep := 20;
- SetState(STATE_RUN);
+ SetState(MONSTATE_RUN);
end;
end;
end
@@ -2364,14 +2908,22 @@ begin
b := Abs(FObj.Vel.X);
if b > 1 then b := b * (Random(8 div b) + 1);
for a := 0 to High(gGibs) do
- if gGibs[a].Live and
+ begin
+ 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
// Ïèíàåì êóñêè
if FObj.Vel.X < 0 then
- g_Obj_PushA(@gGibs[a].Obj, b, Random(61)+120) // íàëåâî
+ begin
+ g_Obj_PushA(@gGibs[a].Obj, b, Random(61)+120); // íàëåâî
+ end
else
+ begin
g_Obj_PushA(@gGibs[a].Obj, b, Random(61)); // íàïðàâî
+ end;
+ end;
+ end;
end;
// Áîññû ìîãóò ïèíàòü òðóïû:
if (FMonsterType in [MONSTER_CYBER, MONSTER_SPIDER, MONSTER_ROBO]) and
@@ -2387,9 +2939,9 @@ begin
FObj.Rect.Width, 8, @co) and (Random(3) = 0) then
// Ïèíàåì òðóïû
if FObj.Vel.X < 0 then
- gCorpses[a].Damage(b*2, -b, Random(7)) // íàëåâî
+ gCorpses[a].Damage(b*2, FUID, -b, Random(7)) // íàëåâî
else
- gCorpses[a].Damage(b*2, b, Random(7)); // íàïðàâî
+ gCorpses[a].Damage(b*2, FUID, b, Random(7)); // íàïðàâî
end;
end;
// Åñëè öåëü âûñîêî, òî, âîçìîæíî, ïðûãàåì:
@@ -2411,7 +2963,7 @@ begin
end;
// Áåæèì â âûáðàííóþ ñòîðîíó:
- if FDirection = D_RIGHT then
+ if FDirection = TDirection.D_RIGHT then
FObj.Vel.X := MONSTERTABLE[FMonsterType].RunVel
else
FObj.Vel.X := -MONSTERTABLE[FMonsterType].RunVel;
@@ -2424,14 +2976,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;
@@ -2442,7 +2994,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();
@@ -2452,7 +3004,7 @@ begin
end;
// Áåæèì â âûáðàííóþ ñòîðîíó:
- if FDirection = D_RIGHT then
+ if FDirection = TDirection.D_RIGHT then
FObj.Vel.X := MONSTERTABLE[FMonsterType].RunVel
else
FObj.Vel.X := -MONSTERTABLE[FMonsterType].RunVel;
@@ -2465,7 +3017,7 @@ begin
FObj.Vel.X := 0;
end;
- STATE_RUNOUT: // Ñîñòîÿíèå - Óáåãàåò îò ÷åãî-òî
+ MONSTATE_RUNOUT: // Ñîñòîÿíèå - Óáåãàåò îò ÷åãî-òî
begin
// Âûøëè èç ÁëîêÌîíà:
if (not WordBool(st and MOVE_BLOCK)) and (FSleep > 0) then
@@ -2477,7 +3029,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();
@@ -2487,7 +3039,7 @@ begin
end;
// Áåæèì â âûáðàííóþ ñòîðîíó:
- if FDirection = D_RIGHT then
+ if FDirection = TDirection.D_RIGHT then
FObj.Vel.X := MONSTERTABLE[FMonsterType].RunVel
else
FObj.Vel.X := -MONSTERTABLE[FMonsterType].RunVel;
@@ -2500,26 +3052,26 @@ 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;
// Áåæèì â âûáðàííóþ ñòîðîíó:
- if FDirection = D_RIGHT then
+ if FDirection = TDirection.D_RIGHT then
FObj.Vel.X := MONSTERTABLE[FMonsterType].RunVel
else
FObj.Vel.X := -MONSTERTABLE[FMonsterType].RunVel;
@@ -2532,14 +3084,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;
@@ -2549,12 +3101,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;
@@ -2562,7 +3114,7 @@ begin
// Öåëü íå âèäíî => èäåì äàëüøå:
if not g_Look(@FObj, @o, FDirection) then
begin
- SetState(STATE_GO);
+ SetState(MONSTATE_GO);
goto _end;
end;
@@ -2570,7 +3122,7 @@ begin
// Öåëü â âîäå - íå çàãîðèòñÿ => èäåì äàëüøå:
if g_Obj_CollideWater(@o, 0, 0) then
begin
- SetState(STATE_GO);
+ SetState(MONSTATE_GO);
goto _end;
end;
@@ -2586,11 +3138,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;
// Åñëè åñòü àíèìàöèÿ îãíÿ êîëäóíà - ïóñòü îíà èäåò:
@@ -2598,46 +3150,47 @@ _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
begin
- sx := g_Monsters_Create(MONSTER_SOUL, FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2)-30,
- FObj.Y+FObj.Rect.Y+20, D_LEFT);
- if sx <> -1 then
+ mon := g_Monsters_Create(MONSTER_SOUL, FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2)-30,
+ FObj.Y+FObj.Rect.Y+20, TDirection.D_LEFT);
+ if mon <> nil then
begin
- gMonsters[sx].SetState(STATE_GO);
- gMonsters[sx].FNoRespawn := True;
+ mon.SetState(MONSTATE_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;
- sx := g_Monsters_Create(MONSTER_SOUL, FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
- FObj.Y+FObj.Rect.Y+20, D_RIGHT);
- if sx <> -1 then
+ mon := g_Monsters_Create(MONSTER_SOUL, FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
+ FObj.Y+FObj.Rect.Y+20, TDirection.D_RIGHT);
+ if mon <> nil then
begin
- gMonsters[sx].SetState(STATE_GO);
- gMonsters[sx].FNoRespawn := True;
+ mon.SetState(MONSTATE_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;
- sx := g_Monsters_Create(MONSTER_SOUL, FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2)-15,
- FObj.Y+FObj.Rect.Y, D_RIGHT);
- if sx <> -1 then
+ mon := g_Monsters_Create(MONSTER_SOUL, FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2)-15,
+ FObj.Y+FObj.Rect.Y, TDirection.D_RIGHT);
+ if mon <> nil then
begin
- gMonsters[sx].SetState(STATE_GO);
- gMonsters[sx].FNoRespawn := True;
+ mon.SetState(MONSTATE_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;
// Ó ýòèõ ìîíñòðîâ íåò òðóïîâ:
@@ -2648,22 +3201,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;
@@ -2683,7 +3236,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
@@ -2695,20 +3248,20 @@ _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:
// Ðûáà êóñàåò ïåðâîãî ïîïàâøåãîñÿ ñî çâóêîì:
if g_Weapon_Hit(@FObj, 10, FUID, HIT_SOME) <> 0 then
g_Sound_PlayExAt('SOUND_MONSTER_FISH_ATTACK', FObj.X, FObj.Y);
- MONSTER_SKEL, MONSTER_ROBO:
- // Ðîáîò èëè ñêåëåò ñèëüíî ïèíàþòñÿ:
+ MONSTER_SKEL, MONSTER_ROBO, MONSTER_CYBER:
+ // Ðîáîò, êèáåð èëè ñêåëåò ñèëüíî ïèíàþòñÿ:
if FCurAnim = ANIM_ATTACK2 then
begin
o := FObj;
- o.Vel.X := IfThen(FDirection = D_RIGHT, 1, -1)*50;
- if g_Weapon_Hit(@o, 50, FUID, HIT_SOME) <> 0 then
+ o.Vel.X := IfThen(FDirection = TDirection.D_RIGHT, 1, -1)*IfThen(FMonsterType = MONSTER_CYBER, 60, 50);
+ if g_Weapon_Hit(@o, IfThen(FMonsterType = MONSTER_CYBER, 33, 50), FUID, HIT_SOME) <> 0 then
g_Sound_PlayExAt('SOUND_MONSTER_SKEL_HIT', FObj.X, FObj.Y);
end;
@@ -2719,7 +3272,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);}
@@ -2733,7 +3286,7 @@ _end:
// Âû÷èñëÿåì êîîðäèíàòû, îòêóäà âûëåòèò ïóëÿ:
wx := MONSTER_ANIMTABLE[FMonsterType].wX;
- if FDirection = D_LEFT then
+ if FDirection = TDirection.D_LEFT then
begin
wx := MONSTER_ANIMTABLE[FMonsterType].wX-(MONSTERTABLE[FMonsterType].Rect.X+(MONSTERTABLE[FMonsterType].Rect.Width div 2));
wx := MONSTERTABLE[FMonsterType].Rect.X+(MONSTERTABLE[FMonsterType].Rect.Width div 2)-wx;
@@ -2742,6 +3295,19 @@ _end:
wx := FObj.X + wx;
wy := FObj.Y + MONSTER_ANIMTABLE[FMonsterType].wY;
+ // Ìîíñòð íå ìîæåò öåëèòüñÿ â îáúåêò çà ñïèíîé, ñòðåëÿÿ âëåâî:
+ if (FDirection = TDirection.D_LEFT) and (tx > wx) then
+ begin
+ tx := wx - 32;
+ ty := wy + Random(11) - 5;
+ end;
+ // È àíàëîãè÷íî, ñòðåëÿÿ âïðàâî:
+ if (FDirection = TDirection.D_RIGHT) and (tx < wx) then
+ begin
+ tx := wx + 32;
+ ty := wy + Random(11) - 5;
+ end;
+
// Äåëàåì âûñòðåë íóæíûì îðóæèåì:
case FMonsterType of
MONSTER_IMP:
@@ -2749,7 +3315,7 @@ _end:
MONSTER_ZOMBY:
begin
g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx, wy);
- g_Weapon_gun(wx, wy, tx, ty, 1, 3, FUID, False);
+ g_Weapon_gun(wx, wy, tx, ty, 1, 3, FUID, True);
g_Player_CreateShell(wx, wy, 0, -2, SHELL_BULLET);
end;
MONSTER_SERG:
@@ -2797,20 +3363,20 @@ _end:
g_Weapon_ball2(wx, wy, tx, ty, FUID);
MONSTER_PAIN:
begin // Ñîçäàåì Lost_Soul:
- sx := g_Monsters_Create(MONSTER_SOUL, FObj.X+(FObj.Rect.Width div 2),
- FObj.Y+FObj.Rect.Y, FDirection);
+ mon := g_Monsters_Create(MONSTER_SOUL, FObj.X+(FObj.Rect.Width div 2),
+ FObj.Y+FObj.Rect.Y, FDirection);
- if sx <> -1 then
+ if mon <> nil then
begin // Öåëü - öåëü Pain_Elemental'à. Ëåòèì ê íåé:
- gMonsters[sx].FTargetUID := FTargetUID;
+ mon.FTargetUID := FTargetUID;
GetPos(FTargetUID, @o);
- gMonsters[sx].FTargetTime := 0;
- gMonsters[sx].FNoRespawn := True;
- gMonsters[sx].SetState(STATE_GO);
- gMonsters[sx].shoot(@o, True);
+ mon.FTargetTime := 0;
+ mon.FNoRespawn := True;
+ mon.SetState(MONSTATE_GO);
+ 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;
@@ -2840,7 +3406,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:
@@ -2863,7 +3429,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;
// Åñëè åñòü àíèìàöèÿ, òî ïóñòü îíà èäåò:
@@ -2897,38 +3463,48 @@ var
a, b, sx, sy, oldvelx: Integer;
st: Word;
o, co: TObj;
- fall: Boolean;
+ fall, bubbles: Boolean;
label
_end;
begin
sx := 0; // SHUT UP COMPILER
sy := 0;
fall := True;
+ bubbles := True;
+
+// Ìîíñòð ñòàòè÷åí ïîêà èäåò warmup
+ if (gLMSRespawn > LMS_RESPAWN_NONE) then exit;
+
// Ðûáû "ëåòàþò" òîëüêî â âîäå:
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;
// Ìåíÿåì ñêîðîñòü òîëüêî ïî ÷åòíûì êàäðàì:
if gTime mod (GAME_TICK*2) <> 0 then
begin
g_Obj_Move(@FObj, fall, True, True);
+ positionChanged(); // this updates spatial accelerators
Exit;
end;
- FPainSound := False;
+ if FPainTicks > 0 then
+ Dec(FPainTicks)
+ else
+ FPainSound := False;
// Äâèãàåìñÿ:
st := g_Obj_Move(@FObj, fall, True, True);
+ positionChanged(); // this updates spatial accelerators
// Âûëåòåë çà êàðòó - óäàëÿåì è çàïóñêàåì òðèããåðû:
if WordBool(st and MOVE_FALLOUT) or (FObj.X < -1000) or
@@ -2941,37 +3517,48 @@ 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
+ begin
+ if WordBool(st and MOVE_INWATER) then
+ FFireTime := 0
+ else
+ begin
+ OnFireFlame(1);
+ FFireTime := FFireTime - 1;
+ end;
+ end;
+
// Ìåðòâûé íè÷åãî íå äåëàåò:
- if (FState = STATE_DEAD) then
+ if (FState = MONSTATE_DEAD) then
goto _end;
// Âîçìîæíî, ñîçäàåì ïóçûðüêè â âîäå:
if WordBool(st and MOVE_INWATER) and (Random(32) = 0) then
+ begin
case FMonsterType of
MONSTER_FISH:
- if Random(4) = 0 then
+ if Random(4) <> 0 then bubbles := False else
g_GFX_Bubbles(FObj.X+FObj.Rect.X + Random(FObj.Rect.Width),
FObj.Y+FObj.Rect.Y + Random(4), 1, 0, 0);
MONSTER_ROBO, MONSTER_BARREL:
g_GFX_Bubbles(FObj.X+FObj.Rect.X + Random(FObj.Rect.Width),
FObj.Y+FObj.Rect.Y + Random(4), 1, 0, 0);
- else begin
+ else
g_GFX_Bubbles(FObj.X+FObj.Rect.X + Random(FObj.Rect.Width-4),
FObj.Y+FObj.Rect.Y + Random(4), 5, 4, 4);
- if Random(2) = 0 then
- g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj.X, FObj.Y)
- else
- g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj.X, FObj.Y);
- end;
end;
+ if bubbles then if Random(2) = 0
+ then g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj.X, FObj.Y)
+ else g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj.X, FObj.Y);
+ end;
// Åñëè ïðîøåë ïåðâûé êàäð àíèìàöèè âçðûâà áî÷êè, òî âçðûâ:
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,
@@ -3015,8 +3602,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
@@ -3024,14 +3611,16 @@ begin
FObj.Vel.Y := -MONSTERTABLE[FMonsterType].Jump;
case FState of
- STATE_PAIN: // Ñîñòîÿíèå - Áîëü
+ MONSTATE_PAIN: // Ñîñòîÿíèå - Áîëü
begin
// Áîëü ñèëüíàÿ => ìîíñòð êðè÷èò:
if FPain >= MONSTERTABLE[FMonsterType].Pain then
begin
FPain := MONSTERTABLE[FMonsterType].Pain;
- PainSound();
+ if gSoundEffectsDF then PainSound();
end;
+ if (not gSoundEffectsDF) and (FPain >= MONSTERTABLE[FMonsterType].MinPain) then
+ PainSound();
// Ñíèæàåì áîëü ñî âðåìåíåì:
FPain := FPain - 5;
@@ -3039,12 +3628,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;
@@ -3056,20 +3645,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;
@@ -3078,7 +3667,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;
@@ -3088,7 +3677,7 @@ begin
if Abs(sx) < 40 then
if FMonsterType <> MONSTER_FISH then
begin
- SetState(STATE_RUN);
+ SetState(MONSTATE_RUN);
FSleep := 15;
goto _end;
@@ -3105,7 +3694,7 @@ begin
begin // Ñòîèì íà òâåðäîì ïîëó èëè ñòóïåíè
// Ïðûæîê ÷åðåç ñòåíó:
FObj.Vel.Y := -MONSTERTABLE[FMonsterType].Jump;
- SetState(STATE_CLIMB);
+ SetState(MONSTATE_CLIMB);
end;
end;
@@ -3129,7 +3718,7 @@ begin
end;
// Ðûáå áîëüíî:
- SetState(STATE_PAIN);
+ SetState(MONSTATE_PAIN);
FPain := FPain + 50;
end
else // Ðûáà â âîäå
@@ -3142,12 +3731,12 @@ begin
// Ðûáà ïëûâåò ââåðõ:
if FObj.Vel.Y < 0 then
- if not g_Obj_CollideWater(@FObj, 0, -16) then
+ if not g_Obj_CollideLiquid(@FObj, 0, -16) then
begin
// Âñïëûëè äî ïîâåðõíîñòè - ñòîï:
FObj.Vel.Y := 0;
// Ïëàâàåì òóäà-ñþäà:
- SetState(STATE_RUN);
+ SetState(MONSTATE_RUN);
FSleep := 20;
end;
end;
@@ -3169,14 +3758,23 @@ begin
b := Abs(FObj.Vel.X);
if b > 1 then b := b * (Random(8 div b) + 1);
for a := 0 to High(gGibs) do
- if gGibs[a].Live and
+ begin
+ 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
// Ïèíàåì êóñêè
if FObj.Vel.X < 0 then
- g_Obj_PushA(@gGibs[a].Obj, b, Random(61)+120) // íàëåâî
+ begin
+ g_Obj_PushA(@gGibs[a].Obj, b, Random(61)+120); // íàëåâî
+ end
else
+ begin
g_Obj_PushA(@gGibs[a].Obj, b, Random(61)); // íàïðàâî
+ end;
+ positionChanged(); // this updates spatial accelerators
+ end;
+ end;
end;
// Áîññû ìîãóò ïèíàòü òðóïû:
if (FMonsterType in [MONSTER_CYBER, MONSTER_SPIDER, MONSTER_ROBO]) and
@@ -3192,9 +3790,9 @@ begin
FObj.Rect.Width, 8, @co) and (Random(3) = 0) then
// Ïèíàåì òðóïû
if FObj.Vel.X < 0 then
- gCorpses[a].Damage(b*2, -b, Random(7)) // íàëåâî
+ gCorpses[a].Damage(b*2, FUID, -b, Random(7)) // íàëåâî
else
- gCorpses[a].Damage(b*2, b, Random(7)); // íàïðàâî
+ gCorpses[a].Damage(b*2, FUID, b, Random(7)); // íàïðàâî
end;
end;
end;
@@ -3210,7 +3808,7 @@ begin
end;
// Áåæèì â âûáðàííóþ ñòîðîíó:
- if FDirection = D_RIGHT then
+ if FDirection = TDirection.D_RIGHT then
FObj.Vel.X := MONSTERTABLE[FMonsterType].RunVel
else
FObj.Vel.X := -MONSTERTABLE[FMonsterType].RunVel;
@@ -3223,12 +3821,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;
@@ -3239,7 +3837,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;
// Èíîãäà ðû÷èì:
@@ -3248,7 +3846,7 @@ begin
end;
// Áåæèì â âûáðàííóþ ñòîðîíó:
- if FDirection = D_RIGHT then
+ if FDirection = TDirection.D_RIGHT then
FObj.Vel.X := MONSTERTABLE[FMonsterType].RunVel
else
FObj.Vel.X := -MONSTERTABLE[FMonsterType].RunVel;
@@ -3261,7 +3859,7 @@ begin
FObj.Vel.X := 0;
end;
- STATE_RUNOUT: // Ñîñòîÿíèå - Óáåãàåò îò ÷åãî-òî
+ MONSTATE_RUNOUT: // Ñîñòîÿíèå - Óáåãàåò îò ÷åãî-òî
begin
// Âûøëè èç ÁëîêÌîíà:
if (not WordBool(st and MOVE_BLOCK)) and (FSleep > 0) then
@@ -3272,7 +3870,7 @@ begin
// Óáàæåëè äîñòàòî÷íî äàëåêî => ïåðåõîäèì íà øàã:
if FSleep <= -18 then
begin
- SetState(STATE_GO);
+ SetState(MONSTATE_GO);
FSleep := 0;
// Èíîãäà ðû÷èì:
@@ -3281,7 +3879,7 @@ begin
end;
// Áåæèì â âûáðàííóþ ñòîðîíó:
- if FDirection = D_RIGHT then
+ if FDirection = TDirection.D_RIGHT then
FObj.Vel.X := MONSTERTABLE[FMonsterType].RunVel
else
FObj.Vel.X := -MONSTERTABLE[FMonsterType].RunVel;
@@ -3294,25 +3892,25 @@ 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;
// Áåæèì â âûáðàííóþ ñòîðîíó:
- if FDirection = D_RIGHT then
+ if FDirection = TDirection.D_RIGHT then
FObj.Vel.X := MONSTERTABLE[FMonsterType].RunVel
else
FObj.Vel.X := -MONSTERTABLE[FMonsterType].RunVel;
@@ -3325,14 +3923,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;
@@ -3342,12 +3940,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;
@@ -3355,7 +3953,7 @@ begin
// Öåëü íå âèäíî => èäåì äàëüøå:
if not g_Look(@FObj, @o, FDirection) then
begin
- SetState(STATE_GO);
+ SetState(MONSTATE_GO);
goto _end;
end;
@@ -3363,7 +3961,7 @@ begin
// Öåëü â âîäå - íå çàãîðèòñÿ => èäåì äàëüøå:
if g_Obj_CollideWater(@o, 0, 0) then
begin
- SetState(STATE_GO);
+ SetState(MONSTATE_GO);
goto _end;
end;
@@ -3374,11 +3972,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;
// Åñëè åñòü àíèìàöèÿ îãíÿ êîëäóíà - ïóñòü îíà èäåò:
@@ -3386,12 +3984,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
@@ -3403,22 +4001,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;
@@ -3438,7 +4036,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
@@ -3450,18 +4048,18 @@ _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);
- MONSTER_SKEL, MONSTER_ROBO:
- // Ðîáîò èëè ñêåëåò ñèëüíî ïèíàþòñÿ:
+ MONSTER_SKEL, MONSTER_ROBO, MONSTER_CYBER:
+ // Ðîáîò, êèáåð èëè ñêåëåò ñèëüíî ïèíàþòñÿ:
if FCurAnim = ANIM_ATTACK2 then
begin
o := FObj;
- o.Vel.X := IfThen(FDirection = D_RIGHT, 1, -1)*50;
- g_Weapon_Hit(@o, 50, FUID, HIT_SOME);
+ o.Vel.X := IfThen(FDirection = TDirection.D_RIGHT, 1, -1)*IfThen(FMonsterType = MONSTER_CYBER, 60, 50);
+ g_Weapon_Hit(@o, IfThen(FMonsterType = MONSTER_CYBER, 33, 50), FUID, HIT_SOME);
end;
MONSTER_VILE:
@@ -3502,7 +4100,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:
@@ -3526,7 +4124,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;
// Åñëè åñòü àíèìàöèÿ, òî ïóñòü îíà èäåò:
@@ -3534,7 +4132,7 @@ _end:
FAnim[FCurAnim, FDirection].Update();
end;
-procedure TMonster.ClientAttack(wx, wy, tx, ty: Integer);
+procedure TMonster.ClientAttack(wx, wy, atx, aty: Integer);
begin
case FMonsterType of
MONSTER_ZOMBY:
@@ -3560,34 +4158,31 @@ begin
g_Player_CreateShell(wx, wy, 0, -2, SHELL_BULLET);
end;
MONSTER_IMP:
- g_Weapon_ball1(wx, wy, tx, ty, FUID);
+ g_Weapon_ball1(wx, wy, atx, aty, FUID);
MONSTER_CYBER:
- g_Weapon_rocket(wx, wy, tx, ty, FUID);
+ g_Weapon_rocket(wx, wy, atx, aty, FUID);
MONSTER_SKEL:
- g_Weapon_revf(wx, wy, tx, ty, FUID, FTargetUID);
+ g_Weapon_revf(wx, wy, atx, aty, FUID, FTargetUID);
MONSTER_BSP:
- g_Weapon_aplasma(wx, wy, tx, ty, FUID);
+ g_Weapon_aplasma(wx, wy, atx, aty, FUID);
MONSTER_ROBO:
- g_Weapon_plasma(wx, wy, tx, ty, FUID);
+ g_Weapon_plasma(wx, wy, atx, aty, FUID);
MONSTER_MANCUB:
- g_Weapon_manfire(wx, wy, tx, ty, FUID);
+ g_Weapon_manfire(wx, wy, atx, aty, FUID);
MONSTER_BARON, MONSTER_KNIGHT:
- g_Weapon_ball7(wx, wy, tx, ty, FUID);
+ g_Weapon_ball7(wx, wy, atx, aty, FUID);
MONSTER_CACO:
- g_Weapon_ball2(wx, wy, tx, ty, FUID);
+ g_Weapon_ball2(wx, wy, atx, aty, FUID);
end;
end;
procedure TMonster.Turn();
begin
// Ðàçâîðà÷èâàåìñÿ:
- if FDirection = D_LEFT then
- FDirection := D_RIGHT
- else
- FDirection := D_LEFT;
+ if FDirection = TDirection.D_LEFT then FDirection := TDirection.D_RIGHT else FDirection := TDirection.D_LEFT;
// Áåæèì â âûáðàííóþ ñòîðîíó:
- if FDirection = D_RIGHT then
+ if FDirection = TDirection.D_RIGHT then
FObj.Vel.X := MONSTERTABLE[FMonsterType].RunVel
else
FObj.Vel.X := -MONSTERTABLE[FMonsterType].RunVel;
@@ -3613,7 +4208,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
@@ -3633,7 +4228,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
@@ -3737,30 +4332,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:
- begin
- SetState(STATE_ATTACK, ANIM_ATTACK2);
- g_Sound_PlayExAt('SOUND_MONSTER_SKEL_ATTACK', FObj.X, FObj.Y);
- Result := True;
- end;
- MONSTER_ROBO:
+ 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;
@@ -3843,19 +4432,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();
@@ -3864,7 +4453,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));
@@ -3884,7 +4473,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;
@@ -3892,9 +4481,9 @@ begin
Result := True;
end;
-function TMonster.Live(): Boolean;
+function TMonster.alive(): 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);
@@ -3910,186 +4499,177 @@ end;
procedure TMonster.WakeUp();
begin
if g_Game_IsClient then Exit;
- SetState(STATE_GO);
+ SetState(MONSTATE_GO);
FTargetTime := MAX_ATM;
WakeUpSound();
end;
-procedure TMonster.SaveState(var Mem: TBinMemoryWriter);
+procedure TMonster.SaveState (st: TStream);
var
i: Integer;
- sig: DWORD;
b: Byte;
anim: Boolean;
begin
- if Mem = nil then
- Exit;
-
-// Ñèãíàòóðà ìîíñòðà:
- sig := MONSTER_SIGNATURE; // 'MONS'
- Mem.WriteDWORD(sig);
-// UID ìîíñòðà:
- Mem.WriteWord(FUID);
-// Íàïðàâëåíèå:
- if FDirection = D_LEFT then
- b := 1
- else // D_RIGHT
- b := 2;
- Mem.WriteByte(b);
-// Íàäî ëè óäàëèòü åãî:
- Mem.WriteBoolean(FRemoved);
-// Îñòàëîñü çäîðîâüÿ:
- Mem.WriteInt(FHealth);
-// Ñîñòîÿíèå:
- Mem.WriteByte(FState);
-// Òåêóùàÿ àíèìàöèÿ:
- Mem.WriteByte(FCurAnim);
-// UID öåëè:
- Mem.WriteWord(FTargetUID);
-// Âðåìÿ ïîñëå ïîòåðè öåëè:
- Mem.WriteInt(FTargetTime);
-// Ïîâåäåíèå ìîíñòðà:
- Mem.WriteByte(FBehaviour);
-// Ãîòîâíîñòü ê âûñòðåëó:
- Mem.WriteInt(FAmmo);
-// Áîëü:
- Mem.WriteInt(FPain);
-// Âðåìÿ îæèäàíèÿ:
- Mem.WriteInt(FSleep);
-// Îçâó÷èâàòü ëè áîëü:
- Mem.WriteBoolean(FPainSound);
-// Áûëà ëè àòàêà âî âðåìÿ àíèìàöèè àòàêè:
- Mem.WriteBoolean(FWaitAttackAnim);
-// Íàäî ëè ñòðåëÿòü íà ñëåäóþùåì øàãå:
- Mem.WriteBoolean(FChainFire);
-// Ïîäëåæèò ëè ðåñïàâíó:
- Mem.WriteBoolean(FNoRespawn);
-// Êîîðäèíàòû öåëè:
- Mem.WriteInt(tx);
- Mem.WriteInt(ty);
-// ID ìîíñòðà ïðè ñòàðòå êàðòû:
- Mem.WriteInt(FStartID);
-// Èíäåêñ òðèããåðà, ñîçäàâøåãî ìîíñòðà:
- Mem.WriteInt(FSpawnTrigger);
-// Îáúåêò ìîíñòðà:
- Obj_SaveState(@FObj, Mem);
-// Åñòü ëè àíèìàöèÿ îãíÿ êîëäóíà:
- anim := vilefire <> nil;
- Mem.WriteBoolean(anim);
-// Åñëè åñòü - ñîõðàíÿåì:
- if anim then
- vilefire.SaveState(Mem);
-// Àíèìàöèè:
+ assert(st <> nil);
+
+ // Ñèãíàòóðà ìîíñòðà:
+ utils.writeSign(st, 'MONS');
+ utils.writeInt(st, Byte(0)); // version
+ // UID ìîíñòðà:
+ utils.writeInt(st, Word(FUID));
+ // Íàïðàâëåíèå
+ if FDirection = TDirection.D_LEFT then b := 1 else b := 2; // D_RIGHT
+ utils.writeInt(st, Byte(b));
+ // Íàäî ëè óäàëèòü åãî
+ utils.writeBool(st, FRemoved);
+ // Îñòàëîñü çäîðîâüÿ
+ utils.writeInt(st, LongInt(FHealth));
+ // Ñîñòîÿíèå
+ utils.writeInt(st, Byte(FState));
+ // Òåêóùàÿ àíèìàöèÿ
+ utils.writeInt(st, Byte(FCurAnim));
+ // UID öåëè
+ utils.writeInt(st, Word(FTargetUID));
+ // Âðåìÿ ïîñëå ïîòåðè öåëè
+ utils.writeInt(st, LongInt(FTargetTime));
+ // Ïîâåäåíèå ìîíñòðà
+ utils.writeInt(st, Byte(FBehaviour));
+ // Ãîòîâíîñòü ê âûñòðåëó
+ utils.writeInt(st, LongInt(FAmmo));
+ // Áîëü
+ utils.writeInt(st, LongInt(FPain));
+ // Âðåìÿ îæèäàíèÿ
+ utils.writeInt(st, LongInt(FSleep));
+ // Îçâó÷èâàòü ëè áîëü
+ utils.writeBool(st, FPainSound);
+ // Áûëà ëè àòàêà âî âðåìÿ àíèìàöèè àòàêè
+ utils.writeBool(st, FWaitAttackAnim);
+ // Íàäî ëè ñòðåëÿòü íà ñëåäóþùåì øàãå
+ utils.writeBool(st, FChainFire);
+ // Ïîäëåæèò ëè ðåñïàâíó
+ utils.writeBool(st, FNoRespawn);
+ // Êîîðäèíàòû öåëè
+ utils.writeInt(st, LongInt(tx));
+ utils.writeInt(st, LongInt(ty));
+ // ID ìîíñòðà ïðè ñòàðòå êàðòû
+ utils.writeInt(st, LongInt(FStartID));
+ // Èíäåêñ òðèããåðà, ñîçäàâøåãî ìîíñòðà
+ utils.writeInt(st, LongInt(FSpawnTrigger));
+ // Îáúåêò ìîíñòðà
+ Obj_SaveState(st, @FObj);
+ // Åñòü ëè àíèìàöèÿ îãíÿ êîëäóíà
+ anim := (vilefire <> nil);
+ utils.writeBool(st, anim);
+ // Åñëè åñòü - ñîõðàíÿåì:
+ if anim then vilefire.SaveState(st);
+ // Àíèìàöèè
for i := ANIM_SLEEP to ANIM_PAIN do
begin
- // Åñòü ëè ëåâàÿ àíèìàöèÿ:
- anim := FAnim[i, D_LEFT] <> nil;
- Mem.WriteBoolean(anim);
- // Åñëè åñòü - ñîõðàíÿåì:
- if anim then
- FAnim[i, D_LEFT].SaveState(Mem);
- // Åñòü ëè ïðàâàÿ àíèìàöèÿ:
- anim := FAnim[i, D_RIGHT] <> nil;
- Mem.WriteBoolean(anim);
- // Åñëè åñòü - ñîõðàíÿåì:
- if anim then
- FAnim[i, D_RIGHT].SaveState(Mem);
+ // Åñòü ëè ëåâàÿ àíèìàöèÿ
+ anim := (FAnim[i, TDirection.D_LEFT] <> nil);
+ utils.writeBool(st, anim);
+ // Åñëè åñòü - ñîõðàíÿåì
+ if anim then FAnim[i, TDirection.D_LEFT].SaveState(st);
+ // Åñòü ëè ïðàâàÿ àíèìàöèÿ
+ anim := (FAnim[i, TDirection.D_RIGHT] <> nil);
+ utils.writeBool(st, anim);
+ // Åñëè åñòü - ñîõðàíÿåì
+ if anim then FAnim[i, TDirection.D_RIGHT].SaveState(st);
end;
end;
-procedure TMonster.LoadState(var Mem: TBinMemoryReader);
+
+procedure TMonster.LoadState (st: TStream);
var
i: Integer;
- sig: DWORD;
b: Byte;
anim: Boolean;
begin
- if Mem = nil then
- Exit;
-
-// Ñèãíàòóðà ìîíñòðà:
- Mem.ReadDWORD(sig);
- if sig <> MONSTER_SIGNATURE then // 'MONS'
- begin
- raise EBinSizeError.Create('TMonster.LoadState: Wrong Monster Signature');
- end;
-// UID ìîíñòðà:
- Mem.ReadWord(FUID);
-// Íàïðàâëåíèå:
- Mem.ReadByte(b);
- if b = 1 then
- FDirection := D_LEFT
- else // b = 2
- FDirection := D_RIGHT;
-// Íàäî ëè óäàëèòü åãî:
- Mem.ReadBoolean(FRemoved);
-// Îñòàëîñü çäîðîâüÿ:
- Mem.ReadInt(FHealth);
-// Ñîñòîÿíèå:
- Mem.ReadByte(FState);
-// Òåêóùàÿ àíèìàöèÿ:
- Mem.ReadByte(FCurAnim);
-// UID öåëè:
- Mem.ReadWord(FTargetUID);
-// Âðåìÿ ïîñëå ïîòåðè öåëè:
- Mem.ReadInt(FTargetTime);
-// Ïîâåäåíèå ìîíñòðà:
- Mem.ReadByte(FBehaviour);
-// Ãîòîâíîñòü ê âûñòðåëó:
- Mem.ReadInt(FAmmo);
-// Áîëü:
- Mem.ReadInt(FPain);
-// Âðåìÿ îæèäàíèÿ:
- Mem.ReadInt(FSleep);
-// Îçâó÷èâàòü ëè áîëü:
- Mem.ReadBoolean(FPainSound);
-// Áûëà ëè àòàêà âî âðåìÿ àíèìàöèè àòàêè:
- Mem.ReadBoolean(FWaitAttackAnim);
-// Íàäî ëè ñòðåëÿòü íà ñëåäóþùåì øàãå:
- Mem.ReadBoolean(FChainFire);
-// Ïîäëåæèò ëè ðåñïàâíó
- Mem.ReadBoolean(FNoRespawn);
-// Êîîðäèíàòû öåëè:
- Mem.ReadInt(tx);
- Mem.ReadInt(ty);
-// ID ìîíñòðà ïðè ñòàðòå êàðòû:
- Mem.ReadInt(FStartID);
-// Èíäåêñ òðèããåðà, ñîçäàâøåãî ìîíñòðà:
- Mem.ReadInt(FSpawnTrigger);
-// Îáúåêò ìîíñòðà:
- Obj_LoadState(@FObj, Mem);
-// Åñòü ëè àíèìàöèÿ îãíÿ êîëäóíà:
- Mem.ReadBoolean(anim);
-// Åñëè åñòü - çàãðóæàåì:
+ assert(st <> nil);
+
+ // Ñèãíàòóðà ìîíñòðà:
+ if not utils.checkSign(st, 'MONS') then raise XStreamError.Create('invalid monster signature');
+ if (utils.readByte(st) <> 0) then raise XStreamError.Create('invalid monster version');
+ if (uidMap[FUID] <> nil) and (uidMap[FUID] <> self) then raise Exception.Create('internal error in monster loader (0)');
+ uidMap[FUID] := nil;
+ // UID ìîíñòðà:
+ FUID := utils.readWord(st);
+ //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;
+ // Íàïðàâëåíèå
+ b := utils.readByte(st);
+ if b = 1 then FDirection := TDirection.D_LEFT else FDirection := TDirection.D_RIGHT; // b = 2
+ // Íàäî ëè óäàëèòü åãî
+ FRemoved := utils.readBool(st);
+ // Îñòàëîñü çäîðîâüÿ
+ FHealth := utils.readLongInt(st);
+ // Ñîñòîÿíèå
+ FState := utils.readByte(st);
+ // Òåêóùàÿ àíèìàöèÿ
+ FCurAnim := utils.readByte(st);
+ // UID öåëè
+ FTargetUID := utils.readWord(st);
+ // Âðåìÿ ïîñëå ïîòåðè öåëè
+ FTargetTime := utils.readLongInt(st);
+ // Ïîâåäåíèå ìîíñòðà
+ FBehaviour := utils.readByte(st);
+ // Ãîòîâíîñòü ê âûñòðåëó
+ FAmmo := utils.readLongInt(st);
+ // Áîëü
+ FPain := utils.readLongInt(st);
+ // Âðåìÿ îæèäàíèÿ
+ FSleep := utils.readLongInt(st);
+ // Îçâó÷èâàòü ëè áîëü
+ FPainSound := utils.readBool(st);
+ // Áûëà ëè àòàêà âî âðåìÿ àíèìàöèè àòàêè
+ FWaitAttackAnim := utils.readBool(st);
+ // Íàäî ëè ñòðåëÿòü íà ñëåäóþùåì øàãå
+ FChainFire := utils.readBool(st);
+ // Ïîäëåæèò ëè ðåñïàâíó
+ FNoRespawn := utils.readBool(st);
+ // Êîîðäèíàòû öåëè
+ tx := utils.readLongInt(st);
+ ty := utils.readLongInt(st);
+ // ID ìîíñòðà ïðè ñòàðòå êàðòû
+ FStartID := utils.readLongInt(st);
+ // Èíäåêñ òðèããåðà, ñîçäàâøåãî ìîíñòðà
+ FSpawnTrigger := utils.readLongInt(st);
+ // Îáúåêò ìîíñòðà
+ Obj_LoadState(@FObj, st);
+ // Åñòü ëè àíèìàöèÿ îãíÿ êîëäóíà
+ anim := utils.readBool(st);
+ // Åñëè åñòü - çàãðóæàåì:
if anim then
begin
Assert(vilefire <> nil, 'TMonster.LoadState: no vilefire anim');
- vilefire.LoadState(Mem);
+ vilefire.LoadState(st);
end;
-// Àíèìàöèè:
+ // Àíèìàöèè
for i := ANIM_SLEEP to ANIM_PAIN do
begin
- // Åñòü ëè ëåâàÿ àíèìàöèÿ:
- Mem.ReadBoolean(anim);
- // Åñëè åñòü - çàãðóæàåì:
+ // Åñòü ëè ëåâàÿ àíèìàöèÿ
+ anim := utils.readBool(st);
+ // Åñëè åñòü - çàãðóæàåì
if anim then
begin
- Assert(FAnim[i, D_LEFT] <> nil,
- 'TMonster.LoadState: no '+IntToStr(i)+'_left anim');
- FAnim[i, D_LEFT].LoadState(Mem);
+ Assert(FAnim[i, TDirection.D_LEFT] <> nil, 'TMonster.LoadState: no '+IntToStr(i)+'_left anim');
+ FAnim[i, TDirection.D_LEFT].LoadState(st);
end;
- // Åñòü ëè ïðàâàÿ àíèìàöèÿ:
- Mem.ReadBoolean(anim);
- // Åñëè åñòü - çàãðóæàåì:
+ // Åñòü ëè ïðàâàÿ àíèìàöèÿ
+ anim := utils.readBool(st);
+ // Åñëè åñòü - çàãðóæàåì
if anim then
begin
- Assert(FAnim[i, D_RIGHT] <> nil,
- 'TMonster.LoadState: no '+IntToStr(i)+'_right anim');
- FAnim[i, D_RIGHT].LoadState(Mem);
+ Assert(FAnim[i, TDirection.D_RIGHT] <> nil, 'TMonster.LoadState: no '+IntToStr(i)+'_right anim');
+ FAnim[i, TDirection.D_RIGHT].LoadState(st);
end;
end;
+ // update cache
+ self.positionChanged
end;
+
procedure TMonster.ActivateTriggers();
var
a: Integer;
@@ -4115,4 +4695,236 @@ begin
SetLength(FDieTriggers, 0);
end;
+procedure TMonster.CatchFire(Attacker: Word; Timeout: Integer = MON_BURN_TIME);
+begin
+ if FMonsterType in [MONSTER_SOUL, MONSTER_VILE] then
+ exit; // àð÷è íå ãîðÿò, ÷åðåïà óæå ãîðÿò
+ if Timeout <= 0 then exit;
+ if g_Obj_CollidePanel(@FObj, 0, 0, PANEL_WATER or PANEL_ACID1 or PANEL_ACID2) then
+ exit; // íå ïîäãîðàåì â âîäå íà âñÿêèé ñëó÷àé
+ if FFireTime <= 0 then
+ g_Sound_PlayExAt('SOUND_IGNITE', FObj.X, FObj.Y);
+ FFireTime := Timeout;
+ FFireAttacker := Attacker;
+ if g_Game_IsNet and g_Game_IsServer then MH_SEND_MonsterState(FUID);
+end;
+
+procedure TMonster.OnFireFlame(Times: DWORD = 1);
+var
+ id, i: DWORD;
+ Anim: TAnimation;
+begin
+ if (Random(10) = 1) and (Times = 1) then
+ Exit;
+
+ if g_Frames_Get(id, 'FRAMES_FLAME') then
+ begin
+ for i := 1 to Times do
+ 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 = MONSTATE_DEAD, 16, 0), Anim, ONCEANIM_SMOKE);
+ Anim.Free();
+ 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_TotalCount (): Integer; inline;
+begin
+ result := Length(gMonsters);
+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
+ mon := gMonsters[idx];
+ if (mon <> nil) then
+ begin
+ result := cb(mon);
+ if result then exit;
+ end;
+ end;
+end;
+
+
+function g_Mons_ForEachAlive (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
+ mon := gMonsters[idx];
+ if (mon <> nil) and mon.alive then
+ begin
+ result := cb(mon);
+ if result then exit;
+ end;
+ end;
+end;
+
+
+function g_Mons_IsAnyAliveAt (x, y: Integer; width, height: Integer): Boolean;
+ (*
+ function monsCollCheck (mon: TMonster; atag: Integer): Boolean;
+ begin
+ result := mon.alive;// and g_Obj_Collide(x, y, width, height, @mon.Obj));
+ end;
+ *)
+var
+ idx: Integer;
+ mon: TMonster;
+ mit: PMonster;
+ it: TMonsterGrid.Iter;
+begin
+ result := false;
+ if (width < 1) or (height < 1) then exit;
+ if gmon_debug_use_sqaccel then
+ begin
+ //result := (monsGrid.forEachInAABB(x, y, width, height, monsCollCheck) <> nil);
+ it := monsGrid.forEachInAABB(x, y, width, height);
+ for mit in it do if (mit.alive) then begin result := true; break; end;
+ it.release();
+ end
+ else
+ begin
+ for idx := 0 to High(gMonsters) do
+ begin
+ mon := gMonsters[idx];
+ if (mon <> nil) and mon.alive then
+ begin
+ if g_Obj_Collide(x, y, width, height, @mon.Obj) then
+ begin
+ result := true;
+ exit;
+ end;
+ end;
+ end;
+ end;
+end;
+
+
+function g_Mons_ForEachAt (x, y: Integer; width, height: Integer; cb: TEachMonsterCB): Boolean;
+ (*
+ function monsCollCheck (mon: TMonster; atag: Integer): Boolean;
+ begin
+ result := cb(mon);
+ end;
+ *)
+var
+ idx: Integer;
+ mon: TMonster;
+ mit: PMonster;
+ it: TMonsterGrid.Iter;
+begin
+ result := false;
+ if (width < 1) or (height < 1) then exit;
+ if gmon_debug_use_sqaccel then
+ begin
+ //result := (monsGrid.forEachInAABB(x, y, width, height, monsCollCheck) <> nil);
+ it := monsGrid.forEachInAABB(x, y, width, height);
+ for mit in it do if (cb(mit^)) then begin result := true; break; end;
+ it.release();
+ end
+ else
+ begin
+ for idx := 0 to High(gMonsters) do
+ begin
+ mon := gMonsters[idx];
+ if (mon <> nil) and mon.alive then
+ begin
+ if g_Obj_Collide(x, y, width, height, @mon.Obj) then
+ begin
+ result := cb(mon);
+ if result then exit;
+ end;
+ end;
+ end;
+ end;
+end;
+
+
+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.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
+ idx: Integer;
+ mon: TMonster;
+ mit: PMonster;
+ it: TMonsterGrid.Iter;
+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
+ result := (monsGrid.forEachAtPoint(x, y, monsCollCheck) <> nil);
+ end
+ else
+ begin
+ result := (monsGrid.forEachInAABB(x, y, width, height, monsCollCheck) <> nil);
+ end;
+ }
+ it := monsGrid.forEachInAABB(x, y, width, height);
+ for mit in it do
+ begin
+ if (mit^.alive) then
+ begin
+ if (cb(mit^)) then begin result := true; break; end;
+ end;
+ end;
+ it.release();
+ end
+ else
+ begin
+ for idx := 0 to High(gMonsters) do
+ begin
+ mon := gMonsters[idx];
+ if (mon <> nil) and mon.alive then
+ begin
+ if g_Obj_Collide(x, y, width, height, @mon.Obj) then
+ begin
+ result := cb(mon);
+ if result then exit;
+ end;
+ end;
+ end;
+ end;
+end;
+
+
end.